context-mode 2.0.0-next.20 → 2.0.0-next.21
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/SHA256SUMS +11 -11
- package/cli.mjs +24 -9
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/opencode/plugin.js +48 -23
- package/package.json +1 -1
- package/pi/index.js +48 -23
- package/qwen-extension.json +1 -1
- package/server.mjs +48 -23
package/SHA256SUMS
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
170d72bc88b1f2568f8fd4c7d67908029522f7ff8bbb190433307cdbd83a2b4a .claude-plugin/marketplace.json
|
|
2
|
+
0139fba3ed537d7a809009224217d3f92069643a524dd37b753e38c32d21ef25 .claude-plugin/plugin.json
|
|
3
3
|
187503e1455560d4ab5a72e3b8cd2f274abd4ccc5faa60dd66c37e44bb5f10c2 .codex-plugin/hooks.json
|
|
4
4
|
4edea851775bc3f0418f8d9cf6ead74f2767c3a9e3b8c05749eacb78ebb3b896 .codex-plugin/mcp.json
|
|
5
|
-
|
|
5
|
+
75afc997fab549f8449953ae6fccb5499a6d0c0242ceec505d54968e507fecb6 .codex-plugin/plugin.json
|
|
6
6
|
1773e40a89384dd1af9023ba533da1908f3e2435dbaaa7cc941edf0514148313 claude-code/skills/ctx-doctor/SKILL.md
|
|
7
7
|
34fffb9c76d69c551f07036230bec0fbaca7a69177a5a47f89ddb9a9990a1fa2 claude-code/skills/ctx-stats/SKILL.md
|
|
8
8
|
d8f835d2f2b3eb70c5902f8707e7c5857977cec9e20ace76c499378a04e178e0 claude-code/skills/ctx-upgrade/SKILL.md
|
|
9
|
-
|
|
9
|
+
a69c0fac9c978267f9e8676a6fe9c754a72a3e898975be5e78d90698c7142961 cli.mjs
|
|
10
10
|
83c297020ed0c592fc68c9c482546a6999d41df5d06d8a329498f10edb1bd38e codex/skills/ctx-doctor/SKILL.md
|
|
11
11
|
adc2c374f699d3698110920bb48411965de09fc6e7232ce59c913f6d58c0d738 codex/skills/ctx-stats/SKILL.md
|
|
12
12
|
5c12cdd19a5e3ed7d9ba3a47b24d03864a28d36cf7006876284ee07cd4221ec4 codex/skills/ctx-upgrade/SKILL.md
|
|
13
|
-
|
|
13
|
+
55b1e5099b525366b8869a400eca087bc61d10fc5444f7f9404e818b44dbc49c copilot/plugin.json
|
|
14
14
|
e3bc6cae0bd51b806d81631879711bbc48c679fc929b2642ed4634438364167d fixtures/hook-roundtrip.json
|
|
15
|
-
|
|
15
|
+
53c5491ef8519eb1527a410009d0db0bed868a4c832f2f5b900a3f85a6aebd56 gemini-extension.json
|
|
16
16
|
b58303ab9c463e36c85ad20ecf375080c049d82f7dd1e2dd5fbcff4b8830a72c hook.mjs
|
|
17
17
|
1f8d8650d2b38737522cab6b875878e8baf84a74acf98cd924c7af22852d873f hooks/claude-code.json
|
|
18
18
|
2524a0eb52683b65c65943c5097db513e9845ba14e84324b39e9a8ea2bb43193 hooks/codex.json
|
|
@@ -22,16 +22,16 @@ f336d1db67de49e641687bbd41ba1a9424e31dfe2377b2284bf44358288ebd8b hooks/kiro.jso
|
|
|
22
22
|
017c9cc3997dd53231b8548b1a1609fddc51177af53501565a4f334602039860 hooks/qwen.json
|
|
23
23
|
33f69267645338d0dc392ce551dcd7c69a0b508113469d6ea637d3f34239ef1d hooks/vscode.json
|
|
24
24
|
085630bccf2073ac9a62be24ef91dfc47d106092dc82c822db70890b7d3ae1c0 hooks/zcode.json
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
67c46292af5625a4da9ce3b357d26564bcafeac2575238defa55d4f4547e223f opencode/plugin.js
|
|
26
|
+
f70d5caf68c1120422c88db6d94bd988bedc2fb192c2cecaf71c91528efe4d7a package.json
|
|
27
|
+
0ec19c55e2aaea9d42117fffe9044f0a5e388ccc3b49a04da678cc1d84945fd8 pi/index.js
|
|
28
28
|
8712881622c9905aa4836af50d903042d34a91506264e459bc7839331f6f0192 pi/skills/ctx-doctor/SKILL.md
|
|
29
29
|
8d6e8e2a82eb079bddc60727f52d9f9a6e0bf9e15391357fed82ee76ab5fe76c pi/skills/ctx-stats/SKILL.md
|
|
30
30
|
db6f9c006bc864a7271f1eeffb1e316ebb537a3414f1c22f8b9de0a896e8e3c5 pi/skills/ctx-upgrade/SKILL.md
|
|
31
|
-
|
|
31
|
+
b5d6f8633de23fab124c0b6bce74656adb25b1b966d32d513fe5543250ed4b0b qwen-extension.json
|
|
32
32
|
28a957921c1dd24aef587fc0f8c6835de1cbbe49eff18104c5d1dd70c0297aad run.mjs
|
|
33
33
|
28a957921c1dd24aef587fc0f8c6835de1cbbe49eff18104c5d1dd70c0297aad search.mjs
|
|
34
|
-
|
|
34
|
+
0a71c81e65e586c7336baa0705848bb98528957064fbf1cbabb429ed10d2c52d server.mjs
|
|
35
35
|
e5503a22a6238901484d123efc11d2d933aa9a54c6ac2018812cfa65ec4e53e3 skills/ctx-doctor/SKILL.md
|
|
36
36
|
1044587a1906c69f2467c089a25e19819a290ea5728389bd1f086c6dfc0d0c51 skills/ctx-stats/SKILL.md
|
|
37
37
|
c1cac75b7506ee0d06089ce611ac6dc9314cf12435da318ce88ad50e2c5debbf skills/ctx-upgrade/SKILL.md
|
package/cli.mjs
CHANGED
|
@@ -8652,11 +8652,16 @@ function isStaleOwnPlugin(e, entry2) {
|
|
|
8652
8652
|
if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
|
|
8653
8653
|
return n3 >= 2 && seg[n3 - 1] === "context-mode" && seg[n3 - 2] === "node_modules";
|
|
8654
8654
|
}
|
|
8655
|
-
function wantedPluginList(list2, entry2) {
|
|
8656
|
-
const native = list2.some(isNativeSpec);
|
|
8655
|
+
function wantedPluginList(list2, entry2, nativeElsewhere = false) {
|
|
8656
|
+
const native = nativeElsewhere || list2.some(isNativeSpec);
|
|
8657
8657
|
const kept = list2.filter((e) => !(native && e === entry2) && !isStaleOwnPlugin(e, entry2));
|
|
8658
8658
|
return native || kept.includes(entry2) ? kept : [...kept, entry2];
|
|
8659
8659
|
}
|
|
8660
|
+
var OC2_NATIVE_KEY = "plugins";
|
|
8661
|
+
function nativePluginsKey(doc) {
|
|
8662
|
+
const v = isObj5(doc) ? doc[OC2_NATIVE_KEY] : void 0;
|
|
8663
|
+
return Array.isArray(v) && v.some(isNativeSpec);
|
|
8664
|
+
}
|
|
8660
8665
|
function pluginListIssue(h2) {
|
|
8661
8666
|
const text2 = readOr(h2.file);
|
|
8662
8667
|
if (text2 === void 0) return void 0;
|
|
@@ -8668,7 +8673,7 @@ function pluginListIssue(h2) {
|
|
|
8668
8673
|
}
|
|
8669
8674
|
const cur = isObj5(doc) ? doc[h2.key[0]] : void 0;
|
|
8670
8675
|
const list2 = Array.isArray(cur) ? cur : [];
|
|
8671
|
-
if (list2.some(isNativeSpec) && list2.includes(h2.entry)) return `${h2.file}: context-mode loads twice (native entry and ${h2.entry}), every hook fires twice; run: context-mode setup`;
|
|
8676
|
+
if ((list2.some(isNativeSpec) || nativePluginsKey(doc)) && list2.includes(h2.entry)) return `${h2.file}: context-mode loads twice (native entry and ${h2.entry}), every hook fires twice; run: context-mode setup`;
|
|
8672
8677
|
const stale = list2.find((e) => isStaleOwnPlugin(e, h2.entry));
|
|
8673
8678
|
if (stale !== void 0) return `${h2.file}: plugin file missing, so OpenCode never loads the hooks (${String(stale)}); run: context-mode setup`;
|
|
8674
8679
|
return void 0;
|
|
@@ -8695,7 +8700,8 @@ function planHookInstall(row, edits, env) {
|
|
|
8695
8700
|
planJsonKeys(row, edits, h2.file, fileFormat(row, h2.file), (doc) => {
|
|
8696
8701
|
const cur = doc[h2.key[0]];
|
|
8697
8702
|
const list2 = Array.isArray(cur) ? cur : [];
|
|
8698
|
-
const want = wantedPluginList(list2, h2.entry);
|
|
8703
|
+
const want = wantedPluginList(list2, h2.entry, nativePluginsKey(doc));
|
|
8704
|
+
if (cur === void 0 && want.length === 0) return [];
|
|
8699
8705
|
return [[h2.key, want.length === list2.length && want.every((e, i2) => e === list2[i2]) ? list2 : want]];
|
|
8700
8706
|
});
|
|
8701
8707
|
}
|
|
@@ -8758,12 +8764,14 @@ function statusOf(row, text2) {
|
|
|
8758
8764
|
}
|
|
8759
8765
|
return void 0;
|
|
8760
8766
|
}
|
|
8761
|
-
function
|
|
8767
|
+
function opencodeMajor(bin, env) {
|
|
8762
8768
|
const r2 = runBin(bin, ["--version"], env);
|
|
8763
8769
|
const text2 = `${r2.stdout}${r2.stderr}`;
|
|
8764
8770
|
const digits = text2.split("").filter((c3) => c3 >= "0" && c3 <= "9" || c3 === ".").join("");
|
|
8765
|
-
|
|
8766
|
-
|
|
8771
|
+
return Number(digits.split(".")[0]);
|
|
8772
|
+
}
|
|
8773
|
+
function opencodeListArgs(bin, env) {
|
|
8774
|
+
return opencodeMajor(bin, env) >= 2 ? ["mcp", "list", "--standalone"] : ["mcp", "list", "--pure"];
|
|
8767
8775
|
}
|
|
8768
8776
|
function listState(row, env) {
|
|
8769
8777
|
const l0 = row.listCommand;
|
|
@@ -8950,7 +8958,8 @@ function hookRegisteredCheck(row, env, list2) {
|
|
|
8950
8958
|
const trust = h2.kind === "file" ? h2.trust : void 0;
|
|
8951
8959
|
if (trust && edits.every((e) => e.file === trust && e.changes.every((c3) => isTrust(row, c3)))) return { name: "hook-registered", ok: false, detail: `${h2.file}: the context-mode hooks are not trusted in ${trust}; re-run setup` };
|
|
8952
8960
|
const issue = h2.kind === "plugin-list" ? pluginListIssue(h2) : h2.kind === "file" && row.id === "kiro" ? kiroDisabledIssue(h2) : void 0;
|
|
8953
|
-
|
|
8961
|
+
const oc2 = issue === void 0 && row.id === "opencode" && h2.kind === "plugin-list" && hostBin("opencode", env).file !== void 0 && opencodeMajor("opencode", env) >= 2;
|
|
8962
|
+
return { name: "hook-registered", ok: false, detail: issue ?? `${h2.file} lacks the context-mode hook entry${oc2 ? "; run: opencode plugin add context-mode@next" : ""}` };
|
|
8954
8963
|
}
|
|
8955
8964
|
function hookRunsCheck(row, env) {
|
|
8956
8965
|
const root = mkdtempSync(path12.join(tmpdir2(), "cm-doctor-runs-"));
|
|
@@ -9411,7 +9420,7 @@ async function runDoctor(opts) {
|
|
|
9411
9420
|
res.reason = V1_FORM_REASON;
|
|
9412
9421
|
} else if (res.changes.length && !onlyTrust(row, res.changes) && !hasPluginIssue(row)) {
|
|
9413
9422
|
res.status = "FAIL";
|
|
9414
|
-
res.reason =
|
|
9423
|
+
res.reason = notSetUpReason(row, res, ctx.env);
|
|
9415
9424
|
} else {
|
|
9416
9425
|
res.checks = await verifyRow(row, ctx);
|
|
9417
9426
|
const bad = res.checks.filter((c3) => !c3.ok);
|
|
@@ -9426,6 +9435,12 @@ async function runDoctor(opts) {
|
|
|
9426
9435
|
}
|
|
9427
9436
|
return { exitCode: agents.some((a2) => a2.status === "FAIL") ? 1 : 0, agents };
|
|
9428
9437
|
}
|
|
9438
|
+
function notSetUpReason(row, res, env) {
|
|
9439
|
+
const h2 = row.hookInstall;
|
|
9440
|
+
const missing = row.id === "opencode" && h2.kind === "plugin-list" && res.changes.some((c3) => c3.path === h2.key[0]);
|
|
9441
|
+
const oc2 = missing && hostBin("opencode", env).file !== void 0 && opencodeMajor("opencode", env) >= 2;
|
|
9442
|
+
return oc2 ? `${NOT_SET_UP_REASON}, or run: opencode plugin add context-mode@next` : NOT_SET_UP_REASON;
|
|
9443
|
+
}
|
|
9429
9444
|
function hasPluginIssue(row) {
|
|
9430
9445
|
const h2 = row.hookInstall;
|
|
9431
9446
|
if (h2.kind === "file") return row.id === "kiro" && kiroDisabledIssue(h2) !== void 0;
|
package/copilot/plugin.json
CHANGED
package/gemini-extension.json
CHANGED
package/opencode/plugin.js
CHANGED
|
@@ -362,7 +362,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
362
362
|
var DECISION_LABEL_JOIN = " | ";
|
|
363
363
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
364
364
|
var RELEASE_BRANCH = "release";
|
|
365
|
-
var BUNDLE_SHA = true ? "
|
|
365
|
+
var BUNDLE_SHA = true ? "fa9bffea6220e2da2a37f2568e1fa96671f5b7c7" : void 0;
|
|
366
366
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
367
367
|
var DOCTOR_LABEL = Object.freeze({
|
|
368
368
|
D1: "version",
|
|
@@ -19965,8 +19965,8 @@ function decisionQueries(input) {
|
|
|
19965
19965
|
function pageSize(input) {
|
|
19966
19966
|
return input.source === DECISION_SOURCE ? SEARCH_PAGE_SIZE : SEARCH_REPLY_HITS;
|
|
19967
19967
|
}
|
|
19968
|
-
function page(db, q, input, scope, ctx, offset) {
|
|
19969
|
-
const size = pageSize(input);
|
|
19968
|
+
function page(db, q, input, scope, ctx, offset, extra = 0) {
|
|
19969
|
+
const size = pageSize(input) + extra;
|
|
19970
19970
|
if (input.source === DECISION_SOURCE && q.trim() === "") {
|
|
19971
19971
|
return ftsListSource(db, DECISION_SOURCE, scope, ctx.project, ctx.sessionId, size, offset);
|
|
19972
19972
|
}
|
|
@@ -20015,51 +20015,76 @@ function jsonRowsReply(db, input, scope, ctx) {
|
|
|
20015
20015
|
}
|
|
20016
20016
|
return shown2 === 0 && !more ? null : reply(out.join("\n"), false);
|
|
20017
20017
|
}
|
|
20018
|
+
var SMALL_SOURCE_SHARE = 0.5;
|
|
20019
|
+
var SOURCE_BYTES = "SELECT id, bytes_total FROM sources WHERE id IN (SELECT value FROM json_each(:ids))";
|
|
20020
|
+
function sourceBytes(db, ids) {
|
|
20021
|
+
const out = /* @__PURE__ */ new Map();
|
|
20022
|
+
if (ids.length === 0) return out;
|
|
20023
|
+
for (const r of db.raw.prepare(SOURCE_BYTES).all({ ids: JSON.stringify(ids) })) {
|
|
20024
|
+
out.set(Number(r.id), Number(r.bytes_total));
|
|
20025
|
+
}
|
|
20026
|
+
return out;
|
|
20027
|
+
}
|
|
20018
20028
|
function relevance(db, given, scope, ctx) {
|
|
20019
20029
|
const input = { ...given, queries: decisionQueries(given) };
|
|
20020
20030
|
const offset = input.offset ?? 0;
|
|
20021
20031
|
const size = pageSize(input);
|
|
20022
|
-
const
|
|
20023
|
-
const
|
|
20024
|
-
|
|
20025
|
-
input.queries.forEach((q, qi) => {
|
|
20026
|
-
const hits = page(db, q, input, scope, ctx, offset);
|
|
20027
|
-
if (hits.length === size) full.add(qi);
|
|
20028
|
-
hits.forEach((hit, i) => {
|
|
20029
|
-
const key = hit.sourceId + ":" + hit.ord;
|
|
20030
|
-
if (seen.has(key)) return;
|
|
20031
|
-
seen.add(key);
|
|
20032
|
-
entries.push({ qi, pos: offset + i, hit });
|
|
20033
|
-
});
|
|
20034
|
-
});
|
|
20035
|
-
if (entries.length === 0) return zeroHits(db, scope, ctx, input.source);
|
|
20032
|
+
const fetched = input.queries.map((q) => page(db, q, input, scope, ctx, offset, 1));
|
|
20033
|
+
const pages = fetched.map((h) => h.slice(0, size));
|
|
20034
|
+
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source);
|
|
20036
20035
|
const moreLine3 = (q, pos) => "More: " + callText([q], scope, input.source, "offset:" + pos);
|
|
20037
20036
|
let reserve = 0;
|
|
20038
20037
|
for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
|
|
20038
|
+
const total = input.source === DECISION_SOURCE ? /* @__PURE__ */ new Map() : sourceBytes(db, [...new Set(pages.flat().map((h) => h.sourceId))]);
|
|
20039
|
+
const spent = /* @__PURE__ */ new Map();
|
|
20039
20040
|
const lines = [];
|
|
20040
20041
|
const more = [];
|
|
20042
|
+
const shown2 = /* @__PURE__ */ new Set();
|
|
20041
20043
|
let used = 0;
|
|
20042
20044
|
let stopped = false;
|
|
20043
20045
|
input.queries.forEach((q, qi) => {
|
|
20044
|
-
const
|
|
20046
|
+
const hits = pages[qi];
|
|
20045
20047
|
if (stopped) {
|
|
20046
|
-
more.push(moreLine3(q,
|
|
20048
|
+
more.push(moreLine3(q, offset));
|
|
20047
20049
|
return;
|
|
20048
20050
|
}
|
|
20049
20051
|
const head = "Query " + JSON.stringify(q) + ":";
|
|
20050
20052
|
lines.push(head);
|
|
20051
20053
|
used += bytes2(head) + 1;
|
|
20052
|
-
|
|
20053
|
-
|
|
20054
|
+
const again = /* @__PURE__ */ new Map();
|
|
20055
|
+
const mine = /* @__PURE__ */ new Set();
|
|
20056
|
+
let cut = -1;
|
|
20057
|
+
for (let i = 0; i < hits.length; i++) {
|
|
20058
|
+
const hit = hits[i];
|
|
20059
|
+
const key = hit.sourceId + ":" + hit.ord;
|
|
20060
|
+
if (shown2.has(key)) {
|
|
20061
|
+
again.set(hit.label, [...again.get(hit.label) ?? [], hit.ord]);
|
|
20062
|
+
continue;
|
|
20063
|
+
}
|
|
20064
|
+
const line = hit.label + " #" + hit.ord + ": " + hit.snippet;
|
|
20054
20065
|
if (used + bytes2(line) + 1 + reserve > OUTPUT_CAP) {
|
|
20055
|
-
|
|
20066
|
+
cut = offset + i;
|
|
20056
20067
|
stopped = true;
|
|
20057
20068
|
break;
|
|
20058
20069
|
}
|
|
20070
|
+
const room = total.get(hit.sourceId);
|
|
20071
|
+
if (room !== void 0 && mine.has(hit.sourceId) && (spent.get(hit.sourceId) ?? 0) + bytes2(line) + 1 > room * SMALL_SOURCE_SHARE * (qi + 1) / input.queries.length) {
|
|
20072
|
+
cut = offset + i;
|
|
20073
|
+
break;
|
|
20074
|
+
}
|
|
20075
|
+
lines.push(line);
|
|
20076
|
+
shown2.add(key);
|
|
20077
|
+
used += bytes2(line) + 1;
|
|
20078
|
+
spent.set(hit.sourceId, (spent.get(hit.sourceId) ?? 0) + bytes2(line) + 1);
|
|
20079
|
+
mine.add(hit.sourceId);
|
|
20080
|
+
}
|
|
20081
|
+
if (again.size > 0) {
|
|
20082
|
+
const line = "Same as above: " + [...again].map(([label, ords]) => label + " (chunk " + ords.join(",") + ")").join("; ");
|
|
20059
20083
|
lines.push(line);
|
|
20060
20084
|
used += bytes2(line) + 1;
|
|
20061
20085
|
}
|
|
20062
|
-
if (
|
|
20086
|
+
if (cut >= 0) more.push(moreLine3(q, cut));
|
|
20087
|
+
else if (fetched[qi].length > size) more.push(moreLine3(q, offset + size));
|
|
20063
20088
|
});
|
|
20064
20089
|
return reply(lines.concat(more).join("\n"), false);
|
|
20065
20090
|
}
|
package/package.json
CHANGED
package/pi/index.js
CHANGED
|
@@ -11508,7 +11508,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
11508
11508
|
var DECISION_LABEL_JOIN = " | ";
|
|
11509
11509
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
11510
11510
|
var RELEASE_BRANCH = "release";
|
|
11511
|
-
var BUNDLE_SHA = true ? "
|
|
11511
|
+
var BUNDLE_SHA = true ? "fa9bffea6220e2da2a37f2568e1fa96671f5b7c7" : void 0;
|
|
11512
11512
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
11513
11513
|
var DOCTOR_LABEL = Object.freeze({
|
|
11514
11514
|
D1: "version",
|
|
@@ -19972,8 +19972,8 @@ function decisionQueries(input) {
|
|
|
19972
19972
|
function pageSize(input) {
|
|
19973
19973
|
return input.source === DECISION_SOURCE ? SEARCH_PAGE_SIZE : SEARCH_REPLY_HITS;
|
|
19974
19974
|
}
|
|
19975
|
-
function page(db, q, input, scope, ctx, offset) {
|
|
19976
|
-
const size = pageSize(input);
|
|
19975
|
+
function page(db, q, input, scope, ctx, offset, extra = 0) {
|
|
19976
|
+
const size = pageSize(input) + extra;
|
|
19977
19977
|
if (input.source === DECISION_SOURCE && q.trim() === "") {
|
|
19978
19978
|
return ftsListSource(db, DECISION_SOURCE, scope, ctx.project, ctx.sessionId, size, offset);
|
|
19979
19979
|
}
|
|
@@ -20022,51 +20022,76 @@ function jsonRowsReply(db, input, scope, ctx) {
|
|
|
20022
20022
|
}
|
|
20023
20023
|
return shown2 === 0 && !more ? null : reply(out.join("\n"), false);
|
|
20024
20024
|
}
|
|
20025
|
+
var SMALL_SOURCE_SHARE = 0.5;
|
|
20026
|
+
var SOURCE_BYTES = "SELECT id, bytes_total FROM sources WHERE id IN (SELECT value FROM json_each(:ids))";
|
|
20027
|
+
function sourceBytes(db, ids) {
|
|
20028
|
+
const out = /* @__PURE__ */ new Map();
|
|
20029
|
+
if (ids.length === 0) return out;
|
|
20030
|
+
for (const r of db.raw.prepare(SOURCE_BYTES).all({ ids: JSON.stringify(ids) })) {
|
|
20031
|
+
out.set(Number(r.id), Number(r.bytes_total));
|
|
20032
|
+
}
|
|
20033
|
+
return out;
|
|
20034
|
+
}
|
|
20025
20035
|
function relevance(db, given, scope, ctx) {
|
|
20026
20036
|
const input = { ...given, queries: decisionQueries(given) };
|
|
20027
20037
|
const offset = input.offset ?? 0;
|
|
20028
20038
|
const size = pageSize(input);
|
|
20029
|
-
const
|
|
20030
|
-
const
|
|
20031
|
-
|
|
20032
|
-
input.queries.forEach((q, qi) => {
|
|
20033
|
-
const hits = page(db, q, input, scope, ctx, offset);
|
|
20034
|
-
if (hits.length === size) full.add(qi);
|
|
20035
|
-
hits.forEach((hit, i) => {
|
|
20036
|
-
const key = hit.sourceId + ":" + hit.ord;
|
|
20037
|
-
if (seen.has(key)) return;
|
|
20038
|
-
seen.add(key);
|
|
20039
|
-
entries.push({ qi, pos: offset + i, hit });
|
|
20040
|
-
});
|
|
20041
|
-
});
|
|
20042
|
-
if (entries.length === 0) return zeroHits(db, scope, ctx, input.source);
|
|
20039
|
+
const fetched = input.queries.map((q) => page(db, q, input, scope, ctx, offset, 1));
|
|
20040
|
+
const pages = fetched.map((h) => h.slice(0, size));
|
|
20041
|
+
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source);
|
|
20043
20042
|
const moreLine3 = (q, pos) => "More: " + callText([q], scope, input.source, "offset:" + pos);
|
|
20044
20043
|
let reserve = 0;
|
|
20045
20044
|
for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
|
|
20045
|
+
const total = input.source === DECISION_SOURCE ? /* @__PURE__ */ new Map() : sourceBytes(db, [...new Set(pages.flat().map((h) => h.sourceId))]);
|
|
20046
|
+
const spent = /* @__PURE__ */ new Map();
|
|
20046
20047
|
const lines = [];
|
|
20047
20048
|
const more = [];
|
|
20049
|
+
const shown2 = /* @__PURE__ */ new Set();
|
|
20048
20050
|
let used = 0;
|
|
20049
20051
|
let stopped = false;
|
|
20050
20052
|
input.queries.forEach((q, qi) => {
|
|
20051
|
-
const
|
|
20053
|
+
const hits = pages[qi];
|
|
20052
20054
|
if (stopped) {
|
|
20053
|
-
more.push(moreLine3(q,
|
|
20055
|
+
more.push(moreLine3(q, offset));
|
|
20054
20056
|
return;
|
|
20055
20057
|
}
|
|
20056
20058
|
const head = "Query " + JSON.stringify(q) + ":";
|
|
20057
20059
|
lines.push(head);
|
|
20058
20060
|
used += bytes2(head) + 1;
|
|
20059
|
-
|
|
20060
|
-
|
|
20061
|
+
const again = /* @__PURE__ */ new Map();
|
|
20062
|
+
const mine = /* @__PURE__ */ new Set();
|
|
20063
|
+
let cut = -1;
|
|
20064
|
+
for (let i = 0; i < hits.length; i++) {
|
|
20065
|
+
const hit = hits[i];
|
|
20066
|
+
const key = hit.sourceId + ":" + hit.ord;
|
|
20067
|
+
if (shown2.has(key)) {
|
|
20068
|
+
again.set(hit.label, [...again.get(hit.label) ?? [], hit.ord]);
|
|
20069
|
+
continue;
|
|
20070
|
+
}
|
|
20071
|
+
const line = hit.label + " #" + hit.ord + ": " + hit.snippet;
|
|
20061
20072
|
if (used + bytes2(line) + 1 + reserve > OUTPUT_CAP) {
|
|
20062
|
-
|
|
20073
|
+
cut = offset + i;
|
|
20063
20074
|
stopped = true;
|
|
20064
20075
|
break;
|
|
20065
20076
|
}
|
|
20077
|
+
const room = total.get(hit.sourceId);
|
|
20078
|
+
if (room !== void 0 && mine.has(hit.sourceId) && (spent.get(hit.sourceId) ?? 0) + bytes2(line) + 1 > room * SMALL_SOURCE_SHARE * (qi + 1) / input.queries.length) {
|
|
20079
|
+
cut = offset + i;
|
|
20080
|
+
break;
|
|
20081
|
+
}
|
|
20082
|
+
lines.push(line);
|
|
20083
|
+
shown2.add(key);
|
|
20084
|
+
used += bytes2(line) + 1;
|
|
20085
|
+
spent.set(hit.sourceId, (spent.get(hit.sourceId) ?? 0) + bytes2(line) + 1);
|
|
20086
|
+
mine.add(hit.sourceId);
|
|
20087
|
+
}
|
|
20088
|
+
if (again.size > 0) {
|
|
20089
|
+
const line = "Same as above: " + [...again].map(([label, ords]) => label + " (chunk " + ords.join(",") + ")").join("; ");
|
|
20066
20090
|
lines.push(line);
|
|
20067
20091
|
used += bytes2(line) + 1;
|
|
20068
20092
|
}
|
|
20069
|
-
if (
|
|
20093
|
+
if (cut >= 0) more.push(moreLine3(q, cut));
|
|
20094
|
+
else if (fetched[qi].length > size) more.push(moreLine3(q, offset + size));
|
|
20070
20095
|
});
|
|
20071
20096
|
return reply(lines.concat(more).join("\n"), false);
|
|
20072
20097
|
}
|
package/qwen-extension.json
CHANGED
package/server.mjs
CHANGED
|
@@ -28343,7 +28343,7 @@ var DECISION_SOURCE = "decision";
|
|
|
28343
28343
|
var DECISION_USER_LABEL = "decision (user)";
|
|
28344
28344
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
28345
28345
|
var RELEASE_BRANCH = "release";
|
|
28346
|
-
var BUNDLE_SHA = true ? "
|
|
28346
|
+
var BUNDLE_SHA = true ? "fa9bffea6220e2da2a37f2568e1fa96671f5b7c7" : void 0;
|
|
28347
28347
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
28348
28348
|
var DOCTOR_LABEL = Object.freeze({
|
|
28349
28349
|
D1: "version",
|
|
@@ -43914,8 +43914,8 @@ function decisionQueries(input) {
|
|
|
43914
43914
|
function pageSize(input) {
|
|
43915
43915
|
return input.source === DECISION_SOURCE ? SEARCH_PAGE_SIZE : SEARCH_REPLY_HITS;
|
|
43916
43916
|
}
|
|
43917
|
-
function page(db, q, input, scope, ctx, offset) {
|
|
43918
|
-
const size = pageSize(input);
|
|
43917
|
+
function page(db, q, input, scope, ctx, offset, extra = 0) {
|
|
43918
|
+
const size = pageSize(input) + extra;
|
|
43919
43919
|
if (input.source === DECISION_SOURCE && q.trim() === "") {
|
|
43920
43920
|
return ftsListSource(db, DECISION_SOURCE, scope, ctx.project, ctx.sessionId, size, offset);
|
|
43921
43921
|
}
|
|
@@ -43964,51 +43964,76 @@ function jsonRowsReply(db, input, scope, ctx) {
|
|
|
43964
43964
|
}
|
|
43965
43965
|
return shown2 === 0 && !more ? null : reply(out.join("\n"), false);
|
|
43966
43966
|
}
|
|
43967
|
+
var SMALL_SOURCE_SHARE = 0.5;
|
|
43968
|
+
var SOURCE_BYTES = "SELECT id, bytes_total FROM sources WHERE id IN (SELECT value FROM json_each(:ids))";
|
|
43969
|
+
function sourceBytes(db, ids) {
|
|
43970
|
+
const out = /* @__PURE__ */ new Map();
|
|
43971
|
+
if (ids.length === 0) return out;
|
|
43972
|
+
for (const r of db.raw.prepare(SOURCE_BYTES).all({ ids: JSON.stringify(ids) })) {
|
|
43973
|
+
out.set(Number(r.id), Number(r.bytes_total));
|
|
43974
|
+
}
|
|
43975
|
+
return out;
|
|
43976
|
+
}
|
|
43967
43977
|
function relevance(db, given, scope, ctx) {
|
|
43968
43978
|
const input = { ...given, queries: decisionQueries(given) };
|
|
43969
43979
|
const offset = input.offset ?? 0;
|
|
43970
43980
|
const size = pageSize(input);
|
|
43971
|
-
const
|
|
43972
|
-
const
|
|
43973
|
-
|
|
43974
|
-
input.queries.forEach((q, qi) => {
|
|
43975
|
-
const hits = page(db, q, input, scope, ctx, offset);
|
|
43976
|
-
if (hits.length === size) full.add(qi);
|
|
43977
|
-
hits.forEach((hit, i) => {
|
|
43978
|
-
const key = hit.sourceId + ":" + hit.ord;
|
|
43979
|
-
if (seen.has(key)) return;
|
|
43980
|
-
seen.add(key);
|
|
43981
|
-
entries.push({ qi, pos: offset + i, hit });
|
|
43982
|
-
});
|
|
43983
|
-
});
|
|
43984
|
-
if (entries.length === 0) return zeroHits(db, scope, ctx, input.source);
|
|
43981
|
+
const fetched = input.queries.map((q) => page(db, q, input, scope, ctx, offset, 1));
|
|
43982
|
+
const pages = fetched.map((h) => h.slice(0, size));
|
|
43983
|
+
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source);
|
|
43985
43984
|
const moreLine3 = (q, pos) => "More: " + callText([q], scope, input.source, "offset:" + pos);
|
|
43986
43985
|
let reserve = 0;
|
|
43987
43986
|
for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
|
|
43987
|
+
const total = input.source === DECISION_SOURCE ? /* @__PURE__ */ new Map() : sourceBytes(db, [...new Set(pages.flat().map((h) => h.sourceId))]);
|
|
43988
|
+
const spent = /* @__PURE__ */ new Map();
|
|
43988
43989
|
const lines = [];
|
|
43989
43990
|
const more = [];
|
|
43991
|
+
const shown2 = /* @__PURE__ */ new Set();
|
|
43990
43992
|
let used = 0;
|
|
43991
43993
|
let stopped = false;
|
|
43992
43994
|
input.queries.forEach((q, qi) => {
|
|
43993
|
-
const
|
|
43995
|
+
const hits = pages[qi];
|
|
43994
43996
|
if (stopped) {
|
|
43995
|
-
more.push(moreLine3(q,
|
|
43997
|
+
more.push(moreLine3(q, offset));
|
|
43996
43998
|
return;
|
|
43997
43999
|
}
|
|
43998
44000
|
const head = "Query " + JSON.stringify(q) + ":";
|
|
43999
44001
|
lines.push(head);
|
|
44000
44002
|
used += bytes2(head) + 1;
|
|
44001
|
-
|
|
44002
|
-
|
|
44003
|
+
const again = /* @__PURE__ */ new Map();
|
|
44004
|
+
const mine = /* @__PURE__ */ new Set();
|
|
44005
|
+
let cut = -1;
|
|
44006
|
+
for (let i = 0; i < hits.length; i++) {
|
|
44007
|
+
const hit = hits[i];
|
|
44008
|
+
const key = hit.sourceId + ":" + hit.ord;
|
|
44009
|
+
if (shown2.has(key)) {
|
|
44010
|
+
again.set(hit.label, [...again.get(hit.label) ?? [], hit.ord]);
|
|
44011
|
+
continue;
|
|
44012
|
+
}
|
|
44013
|
+
const line = hit.label + " #" + hit.ord + ": " + hit.snippet;
|
|
44003
44014
|
if (used + bytes2(line) + 1 + reserve > OUTPUT_CAP) {
|
|
44004
|
-
|
|
44015
|
+
cut = offset + i;
|
|
44005
44016
|
stopped = true;
|
|
44006
44017
|
break;
|
|
44007
44018
|
}
|
|
44019
|
+
const room = total.get(hit.sourceId);
|
|
44020
|
+
if (room !== void 0 && mine.has(hit.sourceId) && (spent.get(hit.sourceId) ?? 0) + bytes2(line) + 1 > room * SMALL_SOURCE_SHARE * (qi + 1) / input.queries.length) {
|
|
44021
|
+
cut = offset + i;
|
|
44022
|
+
break;
|
|
44023
|
+
}
|
|
44024
|
+
lines.push(line);
|
|
44025
|
+
shown2.add(key);
|
|
44026
|
+
used += bytes2(line) + 1;
|
|
44027
|
+
spent.set(hit.sourceId, (spent.get(hit.sourceId) ?? 0) + bytes2(line) + 1);
|
|
44028
|
+
mine.add(hit.sourceId);
|
|
44029
|
+
}
|
|
44030
|
+
if (again.size > 0) {
|
|
44031
|
+
const line = "Same as above: " + [...again].map(([label, ords]) => label + " (chunk " + ords.join(",") + ")").join("; ");
|
|
44008
44032
|
lines.push(line);
|
|
44009
44033
|
used += bytes2(line) + 1;
|
|
44010
44034
|
}
|
|
44011
|
-
if (
|
|
44035
|
+
if (cut >= 0) more.push(moreLine3(q, cut));
|
|
44036
|
+
else if (fetched[qi].length > size) more.push(moreLine3(q, offset + size));
|
|
44012
44037
|
});
|
|
44013
44038
|
return reply(lines.concat(more).join("\n"), false);
|
|
44014
44039
|
}
|