context-mode 2.0.0-next.38 → 2.0.0-next.39
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/README.md +73 -73
- package/SHA256SUMS +12 -12
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +6 -6
- package/opencode/plugin.js +49 -24
- package/package.json +1 -1
- package/pi/index.js +77 -52
- package/qwen-extension.json +1 -1
- package/server.mjs +77 -52
package/opencode/plugin.js
CHANGED
|
@@ -34,6 +34,7 @@ function REPLACE_HANDLE_LINE(intent, handle, bytes5, prefix = "", asked = "") {
|
|
|
34
34
|
var HANDLE_PROMPT_WORDS = 3;
|
|
35
35
|
var MAX_CHUNK_BYTES = 4096;
|
|
36
36
|
var SEARCH_PAGE_SIZE = 20;
|
|
37
|
+
var MEMORY_LABEL_PREFIX = "memory ";
|
|
37
38
|
var SEARCH_REPLY_HITS = 5;
|
|
38
39
|
var SNIPPET_MAX_BYTES = 800;
|
|
39
40
|
var SNIPPET_CODE_MAX_BYTES = 2048;
|
|
@@ -425,7 +426,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
425
426
|
var DECISION_LABEL_JOIN = " | ";
|
|
426
427
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
427
428
|
var RELEASE_BRANCH = "release";
|
|
428
|
-
var BUNDLE_SHA = true ? "
|
|
429
|
+
var BUNDLE_SHA = true ? "1fdd9889d173fa80227ade07d30705291f097df5" : void 0;
|
|
429
430
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
430
431
|
var DOCTOR_LABEL = Object.freeze({
|
|
431
432
|
D1: "version",
|
|
@@ -7076,7 +7077,7 @@ function ftsQueryTimeline(db, scope, ctx, sessionId, limit, after, source, memor
|
|
|
7076
7077
|
}
|
|
7077
7078
|
}
|
|
7078
7079
|
for (const m of memory) {
|
|
7079
|
-
if (m.ts > from && (source === void 0 || m.label === source)) merged.push(m);
|
|
7080
|
+
if (m.ts > from && (source === void 0 || m.label === source || MEMORY_LABEL_PREFIX + m.label === source)) merged.push(m);
|
|
7080
7081
|
}
|
|
7081
7082
|
merged.sort(timelineOrder);
|
|
7082
7083
|
let end = Math.min(limit, merged.length);
|
|
@@ -20264,6 +20265,10 @@ function readAutoMemory(project) {
|
|
|
20264
20265
|
}
|
|
20265
20266
|
return rows;
|
|
20266
20267
|
}
|
|
20268
|
+
function memoryFileNamed(rows, value) {
|
|
20269
|
+
const v = value.split("\\").join("/");
|
|
20270
|
+
return rows.find((r) => r.label === v || MEMORY_LABEL_PREFIX + r.label === v) ?? null;
|
|
20271
|
+
}
|
|
20267
20272
|
function memoryChunks(rows) {
|
|
20268
20273
|
const out = [];
|
|
20269
20274
|
rows.forEach((r, i) => {
|
|
@@ -20276,7 +20281,7 @@ function memoryHits(chunks, q, limit) {
|
|
|
20276
20281
|
const texts = chunks.map((c) => c.text);
|
|
20277
20282
|
const any2 = rankTexts(texts, q, "any");
|
|
20278
20283
|
const all = rankTexts(texts, q, "all");
|
|
20279
|
-
return chunks.map((c, i) => ({ c, s: any2[i], full: all[i] > 0 })).filter((e) => e.s > 0).sort((a, b) => Number(b.full) - Number(a.full) || b.s - a.s || a.c.fileNo - b.c.fileNo || a.c.ord - b.c.ord).slice(0, limit).map((e) => ({ sourceId: -e.c.fileNo, label:
|
|
20284
|
+
return chunks.map((c, i) => ({ c, s: any2[i], full: all[i] > 0 })).filter((e) => e.s > 0).sort((a, b) => Number(b.full) - Number(a.full) || b.s - a.s || a.c.fileNo - b.c.fileNo || a.c.ord - b.c.ord).slice(0, limit).map((e) => ({ sourceId: -e.c.fileNo, label: MEMORY_LABEL_PREFIX + e.c.label, ord: e.c.ord, snippet: highlight(e.c.text, q, SNIPPET_MAX_BYTES), score: e.s, full: e.full }));
|
|
20280
20285
|
}
|
|
20281
20286
|
|
|
20282
20287
|
// src/core/tools/search.ts
|
|
@@ -20314,8 +20319,8 @@ function sourceCount(db, scope, ctx, source) {
|
|
|
20314
20319
|
});
|
|
20315
20320
|
return Number(row5.n);
|
|
20316
20321
|
}
|
|
20317
|
-
function zeroHits(db, scope, ctx, source, offset = 0) {
|
|
20318
|
-
const n = sourceCount(db, scope, ctx, source);
|
|
20322
|
+
function zeroHits(db, scope, ctx, source, mem, offset = 0) {
|
|
20323
|
+
const n = sourceCount(db, scope, ctx, source) + mem.rows.length;
|
|
20319
20324
|
if (offset > 0) return reply("No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
20320
20325
|
return reply('No hits in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
20321
20326
|
}
|
|
@@ -20338,7 +20343,7 @@ function sourceCard(db, id2, input, scope, arg) {
|
|
|
20338
20343
|
}
|
|
20339
20344
|
function callText(queries, scope, source, cursor) {
|
|
20340
20345
|
const src = source === void 0 ? "" : ", source:" + JSON.stringify(source);
|
|
20341
|
-
return "ctx_search({queries:" + JSON.stringify(queries) + ", scope:" + JSON.stringify(scope) + src + ", " + cursor + "})";
|
|
20346
|
+
return "ctx_search({queries:" + JSON.stringify(queries) + ", scope:" + JSON.stringify(scope) + src + (cursor === "" ? "" : ", " + cursor) + "})";
|
|
20342
20347
|
}
|
|
20343
20348
|
function decisionQueries(input) {
|
|
20344
20349
|
return input.source === DECISION_SOURCE && input.queries.length === 0 ? [""] : input.queries;
|
|
@@ -20437,18 +20442,24 @@ function mergeMemory(content, memory) {
|
|
|
20437
20442
|
return out;
|
|
20438
20443
|
}
|
|
20439
20444
|
var contentIn = (hits, n) => hits.slice(0, n).filter((h) => h.sourceId > 0).length;
|
|
20440
|
-
function relevance(db, given, scope, ctx, nm) {
|
|
20445
|
+
function relevance(db, given, scope, ctx, nm, ms, indexed) {
|
|
20441
20446
|
const input = { ...given, queries: decisionQueries(given) };
|
|
20442
20447
|
const offset = input.offset ?? 0;
|
|
20443
20448
|
const size = pageSize(input);
|
|
20444
|
-
const mem =
|
|
20449
|
+
const mem = ms.named || offset === 0 ? memoryChunks(ms.rows) : [];
|
|
20450
|
+
const count2 = (hits, n) => ms.named ? Math.min(n, hits.length) : contentIn(hits, n);
|
|
20445
20451
|
const fetched = input.queries.map((q) => {
|
|
20452
|
+
if (ms.named) {
|
|
20453
|
+
const want = offset + size + 1;
|
|
20454
|
+
const content2 = indexed ? ftsQuery(db, q, scope, ctx.project, ctx.sessionId, want, 0, input.source) : [];
|
|
20455
|
+
return mergeMemory(content2, memoryHits(mem, q, want)).slice(offset, want);
|
|
20456
|
+
}
|
|
20446
20457
|
const content = page(db, q, input, scope, ctx, offset, 1);
|
|
20447
20458
|
return mem.length === 0 ? content : mergeMemory(content, memoryHits(mem, q, MEMORY_HITS));
|
|
20448
20459
|
});
|
|
20449
20460
|
const take = fetched.map((h) => replyHits(h, size));
|
|
20450
20461
|
const pages = fetched.map((h, i) => h.slice(0, take[i]));
|
|
20451
|
-
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, offset);
|
|
20462
|
+
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, offset);
|
|
20452
20463
|
const moreLine3 = (q, pos) => "More: " + callText([q], scope, nm.arg, "offset:" + pos);
|
|
20453
20464
|
let reserve = 0;
|
|
20454
20465
|
for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
|
|
@@ -20481,13 +20492,13 @@ function relevance(db, given, scope, ctx, nm) {
|
|
|
20481
20492
|
}
|
|
20482
20493
|
const line = shownLabel(hit.label, hit.sourceId) + " #" + hit.ord + ": " + hit.snippet;
|
|
20483
20494
|
if (used + bytes2(line) + 1 + reserve > OUTPUT_CAP) {
|
|
20484
|
-
cut = offset +
|
|
20495
|
+
cut = offset + count2(hits, i);
|
|
20485
20496
|
stopped = true;
|
|
20486
20497
|
break;
|
|
20487
20498
|
}
|
|
20488
20499
|
const room = total.get(hit.sourceId);
|
|
20489
20500
|
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) {
|
|
20490
|
-
cut = offset +
|
|
20501
|
+
cut = offset + count2(hits, i);
|
|
20491
20502
|
break;
|
|
20492
20503
|
}
|
|
20493
20504
|
lines.push(line);
|
|
@@ -20502,7 +20513,7 @@ function relevance(db, given, scope, ctx, nm) {
|
|
|
20502
20513
|
used += bytes2(line) + 1;
|
|
20503
20514
|
}
|
|
20504
20515
|
if (cut >= 0) more.push({ q, pos: cut });
|
|
20505
|
-
else if (
|
|
20516
|
+
else if (count2(fetched[qi], fetched[qi].length) > count2(fetched[qi], take[qi])) more.push({ q, pos: offset + count2(fetched[qi], take[qi]) });
|
|
20506
20517
|
});
|
|
20507
20518
|
const moreLines = [];
|
|
20508
20519
|
const byPos = /* @__PURE__ */ new Map();
|
|
@@ -20516,10 +20527,9 @@ function timelineLine(r) {
|
|
|
20516
20527
|
const seq = r.seq === null ? "" : " #" + r.seq;
|
|
20517
20528
|
return "[" + new Date(r.ts).toISOString() + "] " + shownLabel(r.label, r.sourceId) + seq + " " + first;
|
|
20518
20529
|
}
|
|
20519
|
-
function timeline(db, input, scope, ctx, nm) {
|
|
20520
|
-
const
|
|
20521
|
-
|
|
20522
|
-
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source);
|
|
20530
|
+
function timeline(db, input, scope, ctx, nm, ms) {
|
|
20531
|
+
const page2 = ftsQueryTimeline(db, scope, ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, input.after ?? null, input.source, ms.rows);
|
|
20532
|
+
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms);
|
|
20523
20533
|
const moreLine3 = (ts) => "more: " + callText(input.queries, scope, nm.arg, 'sort:"timeline", after:' + ts);
|
|
20524
20534
|
const reserve = bytes2(moreLine3(page2.rows[page2.rows.length - 1].ts)) + 1;
|
|
20525
20535
|
const lines = nm.note === null ? [] : [nm.note];
|
|
@@ -20548,6 +20558,15 @@ function timeline(db, input, scope, ctx, nm) {
|
|
|
20548
20558
|
if (more && lastTs !== null) lines.push(moreLine3(lastTs));
|
|
20549
20559
|
return reply(lines.join("\n"), false);
|
|
20550
20560
|
}
|
|
20561
|
+
function answer(db, input, scope, ctx, nm, ms, indexed, sort, pick2) {
|
|
20562
|
+
if (sort === "timeline") return timeline(db, input, scope, ctx, nm, ms);
|
|
20563
|
+
if (pick2 !== null && pick2.id !== null && input.queries.length === 0) {
|
|
20564
|
+
const card = sourceCard(db, pick2.id, input, scope, nm.arg);
|
|
20565
|
+
if (card !== null) return card;
|
|
20566
|
+
}
|
|
20567
|
+
const rows = ms.named ? null : jsonRowsReply(db, input, scope, ctx, nm);
|
|
20568
|
+
return rows ?? relevance(db, input, scope, ctx, nm, ms, indexed);
|
|
20569
|
+
}
|
|
20551
20570
|
async function handler(input, ctx) {
|
|
20552
20571
|
const sort = input.sort ?? "relevance";
|
|
20553
20572
|
if (sort === "timeline" && input.offset !== void 0) {
|
|
@@ -20563,12 +20582,18 @@ async function handler(input, ctx) {
|
|
|
20563
20582
|
const pick2 = given !== void 0 && given !== DECISION_SOURCE ? pickSource(db, given) : null;
|
|
20564
20583
|
if (pick2 !== null) input = { ...input, source: pick2.label };
|
|
20565
20584
|
const nm = named(given, pick2);
|
|
20566
|
-
|
|
20567
|
-
|
|
20568
|
-
|
|
20569
|
-
|
|
20570
|
-
|
|
20571
|
-
|
|
20585
|
+
const indexed = pick2 !== null && pick2.id !== null;
|
|
20586
|
+
const files = scope !== "session" || given !== void 0 ? readAutoMemory(ctx.project) : [];
|
|
20587
|
+
const file2 = given === void 0 || given === DECISION_SOURCE ? null : memoryFileNamed(files, given);
|
|
20588
|
+
const ms = { rows: scope === "session" ? [] : file2 !== null ? [file2] : given === void 0 ? files : [], named: file2 !== null };
|
|
20589
|
+
if (file2 !== null && indexed && scope !== "session") {
|
|
20590
|
+
const both = "Source " + JSON.stringify(given) + ": searched the indexed source " + shownLabel(pick2.label, pick2.id) + " and the memory file " + file2.label + ".";
|
|
20591
|
+
nm.note = nm.note === null ? both : nm.note + "\n" + both;
|
|
20592
|
+
}
|
|
20593
|
+
const out = answer(db, input, scope, ctx, nm, ms, indexed, sort, pick2);
|
|
20594
|
+
if (file2 === null || scope !== "session") return out;
|
|
20595
|
+
const call = callText(input.queries, "worktree", nm.arg, sort === "timeline" ? 'sort:"timeline"' : "");
|
|
20596
|
+
return reply(out.text + "\nMemory file " + file2.label + ' is in scope "worktree": ' + call + " searches it.", out.isError);
|
|
20572
20597
|
} finally {
|
|
20573
20598
|
closeDb(db);
|
|
20574
20599
|
}
|
|
@@ -20704,7 +20729,7 @@ function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
|
20704
20729
|
function bytes3(s) {
|
|
20705
20730
|
return Buffer.byteLength(s, "utf8");
|
|
20706
20731
|
}
|
|
20707
|
-
function
|
|
20732
|
+
function answer2(db, ctx, ownIds, queries, share, own2) {
|
|
20708
20733
|
const seen = /* @__PURE__ */ new Set();
|
|
20709
20734
|
const lines = [];
|
|
20710
20735
|
for (const [qi, q] of queries.entries()) {
|
|
@@ -20767,7 +20792,7 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
20767
20792
|
notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
|
|
20768
20793
|
const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
|
|
20769
20794
|
const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
|
|
20770
|
-
const answered =
|
|
20795
|
+
const answered = answer2(db, ctx, idx.ids, queries, share, idx.bodies);
|
|
20771
20796
|
sections = answered.lines;
|
|
20772
20797
|
const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
|
|
20773
20798
|
const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
|
package/package.json
CHANGED
package/pi/index.js
CHANGED
|
@@ -11173,6 +11173,7 @@ function REPLACE_HANDLE_LINE(intent, handle, bytes5, prefix = "", asked = "") {
|
|
|
11173
11173
|
var HANDLE_PROMPT_WORDS = 3;
|
|
11174
11174
|
var MAX_CHUNK_BYTES = 4096;
|
|
11175
11175
|
var SEARCH_PAGE_SIZE = 20;
|
|
11176
|
+
var MEMORY_LABEL_PREFIX = "memory ";
|
|
11176
11177
|
var SEARCH_REPLY_HITS = 5;
|
|
11177
11178
|
var SNIPPET_MAX_BYTES = 800;
|
|
11178
11179
|
var SNIPPET_CODE_MAX_BYTES = 2048;
|
|
@@ -11570,7 +11571,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
11570
11571
|
var DECISION_LABEL_JOIN = " | ";
|
|
11571
11572
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
11572
11573
|
var RELEASE_BRANCH = "release";
|
|
11573
|
-
var BUNDLE_SHA = true ? "
|
|
11574
|
+
var BUNDLE_SHA = true ? "1fdd9889d173fa80227ade07d30705291f097df5" : void 0;
|
|
11574
11575
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
11575
11576
|
var DOCTOR_LABEL = Object.freeze({
|
|
11576
11577
|
D1: "version",
|
|
@@ -18225,7 +18226,7 @@ function ftsQueryTimeline(db, scope, ctx, sessionId, limit, after, source, memor
|
|
|
18225
18226
|
}
|
|
18226
18227
|
}
|
|
18227
18228
|
for (const m of memory) {
|
|
18228
|
-
if (m.ts > from && (source === void 0 || m.label === source)) merged.push(m);
|
|
18229
|
+
if (m.ts > from && (source === void 0 || m.label === source || MEMORY_LABEL_PREFIX + m.label === source)) merged.push(m);
|
|
18229
18230
|
}
|
|
18230
18231
|
merged.sort(timelineOrder);
|
|
18231
18232
|
let end = Math.min(limit, merged.length);
|
|
@@ -20274,6 +20275,10 @@ function readAutoMemory(project) {
|
|
|
20274
20275
|
}
|
|
20275
20276
|
return rows;
|
|
20276
20277
|
}
|
|
20278
|
+
function memoryFileNamed(rows, value) {
|
|
20279
|
+
const v = value.split("\\").join("/");
|
|
20280
|
+
return rows.find((r) => r.label === v || MEMORY_LABEL_PREFIX + r.label === v) ?? null;
|
|
20281
|
+
}
|
|
20277
20282
|
function memoryChunks(rows) {
|
|
20278
20283
|
const out = [];
|
|
20279
20284
|
rows.forEach((r, i) => {
|
|
@@ -20286,7 +20291,7 @@ function memoryHits(chunks, q, limit) {
|
|
|
20286
20291
|
const texts = chunks.map((c) => c.text);
|
|
20287
20292
|
const any3 = rankTexts(texts, q, "any");
|
|
20288
20293
|
const all = rankTexts(texts, q, "all");
|
|
20289
|
-
return chunks.map((c, i) => ({ c, s: any3[i], full: all[i] > 0 })).filter((e) => e.s > 0).sort((a, b) => Number(b.full) - Number(a.full) || b.s - a.s || a.c.fileNo - b.c.fileNo || a.c.ord - b.c.ord).slice(0, limit).map((e) => ({ sourceId: -e.c.fileNo, label:
|
|
20294
|
+
return chunks.map((c, i) => ({ c, s: any3[i], full: all[i] > 0 })).filter((e) => e.s > 0).sort((a, b) => Number(b.full) - Number(a.full) || b.s - a.s || a.c.fileNo - b.c.fileNo || a.c.ord - b.c.ord).slice(0, limit).map((e) => ({ sourceId: -e.c.fileNo, label: MEMORY_LABEL_PREFIX + e.c.label, ord: e.c.ord, snippet: highlight(e.c.text, q, SNIPPET_MAX_BYTES), score: e.s, full: e.full }));
|
|
20290
20295
|
}
|
|
20291
20296
|
|
|
20292
20297
|
// src/core/tools/search.ts
|
|
@@ -20324,8 +20329,8 @@ function sourceCount(db, scope, ctx, source) {
|
|
|
20324
20329
|
});
|
|
20325
20330
|
return Number(row5.n);
|
|
20326
20331
|
}
|
|
20327
|
-
function zeroHits(db, scope, ctx, source, offset = 0) {
|
|
20328
|
-
const n = sourceCount(db, scope, ctx, source);
|
|
20332
|
+
function zeroHits(db, scope, ctx, source, mem, offset = 0) {
|
|
20333
|
+
const n = sourceCount(db, scope, ctx, source) + mem.rows.length;
|
|
20329
20334
|
if (offset > 0) return reply("No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
20330
20335
|
return reply('No hits in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
20331
20336
|
}
|
|
@@ -20348,7 +20353,7 @@ function sourceCard(db, id, input, scope, arg) {
|
|
|
20348
20353
|
}
|
|
20349
20354
|
function callText(queries, scope, source, cursor) {
|
|
20350
20355
|
const src = source === void 0 ? "" : ", source:" + JSON.stringify(source);
|
|
20351
|
-
return "ctx_search({queries:" + JSON.stringify(queries) + ", scope:" + JSON.stringify(scope) + src + ", " + cursor + "})";
|
|
20356
|
+
return "ctx_search({queries:" + JSON.stringify(queries) + ", scope:" + JSON.stringify(scope) + src + (cursor === "" ? "" : ", " + cursor) + "})";
|
|
20352
20357
|
}
|
|
20353
20358
|
function decisionQueries(input) {
|
|
20354
20359
|
return input.source === DECISION_SOURCE && input.queries.length === 0 ? [""] : input.queries;
|
|
@@ -20447,18 +20452,24 @@ function mergeMemory(content, memory) {
|
|
|
20447
20452
|
return out;
|
|
20448
20453
|
}
|
|
20449
20454
|
var contentIn = (hits, n) => hits.slice(0, n).filter((h) => h.sourceId > 0).length;
|
|
20450
|
-
function relevance(db, given, scope, ctx, nm) {
|
|
20455
|
+
function relevance(db, given, scope, ctx, nm, ms, indexed) {
|
|
20451
20456
|
const input = { ...given, queries: decisionQueries(given) };
|
|
20452
20457
|
const offset = input.offset ?? 0;
|
|
20453
20458
|
const size = pageSize(input);
|
|
20454
|
-
const mem =
|
|
20459
|
+
const mem = ms.named || offset === 0 ? memoryChunks(ms.rows) : [];
|
|
20460
|
+
const count2 = (hits, n) => ms.named ? Math.min(n, hits.length) : contentIn(hits, n);
|
|
20455
20461
|
const fetched = input.queries.map((q) => {
|
|
20462
|
+
if (ms.named) {
|
|
20463
|
+
const want = offset + size + 1;
|
|
20464
|
+
const content2 = indexed ? ftsQuery(db, q, scope, ctx.project, ctx.sessionId, want, 0, input.source) : [];
|
|
20465
|
+
return mergeMemory(content2, memoryHits(mem, q, want)).slice(offset, want);
|
|
20466
|
+
}
|
|
20456
20467
|
const content = page(db, q, input, scope, ctx, offset, 1);
|
|
20457
20468
|
return mem.length === 0 ? content : mergeMemory(content, memoryHits(mem, q, MEMORY_HITS));
|
|
20458
20469
|
});
|
|
20459
20470
|
const take = fetched.map((h) => replyHits(h, size));
|
|
20460
20471
|
const pages = fetched.map((h, i) => h.slice(0, take[i]));
|
|
20461
|
-
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, offset);
|
|
20472
|
+
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, offset);
|
|
20462
20473
|
const moreLine3 = (q, pos) => "More: " + callText([q], scope, nm.arg, "offset:" + pos);
|
|
20463
20474
|
let reserve = 0;
|
|
20464
20475
|
for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
|
|
@@ -20491,13 +20502,13 @@ function relevance(db, given, scope, ctx, nm) {
|
|
|
20491
20502
|
}
|
|
20492
20503
|
const line = shownLabel(hit.label, hit.sourceId) + " #" + hit.ord + ": " + hit.snippet;
|
|
20493
20504
|
if (used + bytes2(line) + 1 + reserve > OUTPUT_CAP) {
|
|
20494
|
-
cut = offset +
|
|
20505
|
+
cut = offset + count2(hits, i);
|
|
20495
20506
|
stopped = true;
|
|
20496
20507
|
break;
|
|
20497
20508
|
}
|
|
20498
20509
|
const room = total.get(hit.sourceId);
|
|
20499
20510
|
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) {
|
|
20500
|
-
cut = offset +
|
|
20511
|
+
cut = offset + count2(hits, i);
|
|
20501
20512
|
break;
|
|
20502
20513
|
}
|
|
20503
20514
|
lines.push(line);
|
|
@@ -20512,7 +20523,7 @@ function relevance(db, given, scope, ctx, nm) {
|
|
|
20512
20523
|
used += bytes2(line) + 1;
|
|
20513
20524
|
}
|
|
20514
20525
|
if (cut >= 0) more.push({ q, pos: cut });
|
|
20515
|
-
else if (
|
|
20526
|
+
else if (count2(fetched[qi], fetched[qi].length) > count2(fetched[qi], take[qi])) more.push({ q, pos: offset + count2(fetched[qi], take[qi]) });
|
|
20516
20527
|
});
|
|
20517
20528
|
const moreLines = [];
|
|
20518
20529
|
const byPos = /* @__PURE__ */ new Map();
|
|
@@ -20526,10 +20537,9 @@ function timelineLine(r) {
|
|
|
20526
20537
|
const seq = r.seq === null ? "" : " #" + r.seq;
|
|
20527
20538
|
return "[" + new Date(r.ts).toISOString() + "] " + shownLabel(r.label, r.sourceId) + seq + " " + first;
|
|
20528
20539
|
}
|
|
20529
|
-
function timeline(db, input, scope, ctx, nm) {
|
|
20530
|
-
const
|
|
20531
|
-
|
|
20532
|
-
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source);
|
|
20540
|
+
function timeline(db, input, scope, ctx, nm, ms) {
|
|
20541
|
+
const page2 = ftsQueryTimeline(db, scope, ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, input.after ?? null, input.source, ms.rows);
|
|
20542
|
+
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms);
|
|
20533
20543
|
const moreLine3 = (ts) => "more: " + callText(input.queries, scope, nm.arg, 'sort:"timeline", after:' + ts);
|
|
20534
20544
|
const reserve = bytes2(moreLine3(page2.rows[page2.rows.length - 1].ts)) + 1;
|
|
20535
20545
|
const lines = nm.note === null ? [] : [nm.note];
|
|
@@ -20558,6 +20568,15 @@ function timeline(db, input, scope, ctx, nm) {
|
|
|
20558
20568
|
if (more && lastTs !== null) lines.push(moreLine3(lastTs));
|
|
20559
20569
|
return reply(lines.join("\n"), false);
|
|
20560
20570
|
}
|
|
20571
|
+
function answer(db, input, scope, ctx, nm, ms, indexed, sort, pick4) {
|
|
20572
|
+
if (sort === "timeline") return timeline(db, input, scope, ctx, nm, ms);
|
|
20573
|
+
if (pick4 !== null && pick4.id !== null && input.queries.length === 0) {
|
|
20574
|
+
const card = sourceCard(db, pick4.id, input, scope, nm.arg);
|
|
20575
|
+
if (card !== null) return card;
|
|
20576
|
+
}
|
|
20577
|
+
const rows = ms.named ? null : jsonRowsReply(db, input, scope, ctx, nm);
|
|
20578
|
+
return rows ?? relevance(db, input, scope, ctx, nm, ms, indexed);
|
|
20579
|
+
}
|
|
20561
20580
|
async function handler(input, ctx) {
|
|
20562
20581
|
const sort = input.sort ?? "relevance";
|
|
20563
20582
|
if (sort === "timeline" && input.offset !== void 0) {
|
|
@@ -20573,12 +20592,18 @@ async function handler(input, ctx) {
|
|
|
20573
20592
|
const pick4 = given !== void 0 && given !== DECISION_SOURCE ? pickSource(db, given) : null;
|
|
20574
20593
|
if (pick4 !== null) input = { ...input, source: pick4.label };
|
|
20575
20594
|
const nm = named(given, pick4);
|
|
20576
|
-
|
|
20577
|
-
|
|
20578
|
-
|
|
20579
|
-
|
|
20580
|
-
|
|
20581
|
-
|
|
20595
|
+
const indexed = pick4 !== null && pick4.id !== null;
|
|
20596
|
+
const files = scope !== "session" || given !== void 0 ? readAutoMemory(ctx.project) : [];
|
|
20597
|
+
const file2 = given === void 0 || given === DECISION_SOURCE ? null : memoryFileNamed(files, given);
|
|
20598
|
+
const ms = { rows: scope === "session" ? [] : file2 !== null ? [file2] : given === void 0 ? files : [], named: file2 !== null };
|
|
20599
|
+
if (file2 !== null && indexed && scope !== "session") {
|
|
20600
|
+
const both = "Source " + JSON.stringify(given) + ": searched the indexed source " + shownLabel(pick4.label, pick4.id) + " and the memory file " + file2.label + ".";
|
|
20601
|
+
nm.note = nm.note === null ? both : nm.note + "\n" + both;
|
|
20602
|
+
}
|
|
20603
|
+
const out = answer(db, input, scope, ctx, nm, ms, indexed, sort, pick4);
|
|
20604
|
+
if (file2 === null || scope !== "session") return out;
|
|
20605
|
+
const call = callText(input.queries, "worktree", nm.arg, sort === "timeline" ? 'sort:"timeline"' : "");
|
|
20606
|
+
return reply(out.text + "\nMemory file " + file2.label + ' is in scope "worktree": ' + call + " searches it.", out.isError);
|
|
20582
20607
|
} finally {
|
|
20583
20608
|
closeDb(db);
|
|
20584
20609
|
}
|
|
@@ -20714,7 +20739,7 @@ function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
|
20714
20739
|
function bytes3(s) {
|
|
20715
20740
|
return Buffer.byteLength(s, "utf8");
|
|
20716
20741
|
}
|
|
20717
|
-
function
|
|
20742
|
+
function answer2(db, ctx, ownIds, queries, share, own4) {
|
|
20718
20743
|
const seen = /* @__PURE__ */ new Set();
|
|
20719
20744
|
const lines = [];
|
|
20720
20745
|
for (const [qi, q] of queries.entries()) {
|
|
@@ -20777,7 +20802,7 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
20777
20802
|
notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
|
|
20778
20803
|
const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
|
|
20779
20804
|
const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
|
|
20780
|
-
const answered =
|
|
20805
|
+
const answered = answer2(db, ctx, idx.ids, queries, share, idx.bodies);
|
|
20781
20806
|
sections = answered.lines;
|
|
20782
20807
|
const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
|
|
20783
20808
|
const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
|
|
@@ -34216,26 +34241,26 @@ function isRecursive(inst, stack2, resolve8) {
|
|
|
34216
34241
|
let result = NONE3;
|
|
34217
34242
|
const check2 = (child) => {
|
|
34218
34243
|
if (result !== PROVEN && child?._zod) {
|
|
34219
|
-
const
|
|
34220
|
-
if (
|
|
34221
|
-
result =
|
|
34244
|
+
const answer3 = isRecursive(child, stack2, resolve8);
|
|
34245
|
+
if (answer3 > result)
|
|
34246
|
+
result = answer3;
|
|
34222
34247
|
}
|
|
34223
34248
|
};
|
|
34224
34249
|
const shape = (sh, spread) => {
|
|
34225
|
-
let
|
|
34250
|
+
let answer3 = NONE3;
|
|
34226
34251
|
for (const key of Reflect.ownKeys(sh)) {
|
|
34227
34252
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
34228
34253
|
if (spread && !desc.enumerable)
|
|
34229
34254
|
continue;
|
|
34230
34255
|
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack2, resolve8) : NONE3;
|
|
34231
|
-
if (child >
|
|
34232
|
-
|
|
34256
|
+
if (child > answer3)
|
|
34257
|
+
answer3 = child;
|
|
34233
34258
|
}
|
|
34234
|
-
return
|
|
34259
|
+
return answer3;
|
|
34235
34260
|
};
|
|
34236
|
-
const merge5 = (
|
|
34237
|
-
if (
|
|
34238
|
-
result =
|
|
34261
|
+
const merge5 = (answer3) => {
|
|
34262
|
+
if (answer3 > result)
|
|
34263
|
+
result = answer3;
|
|
34239
34264
|
};
|
|
34240
34265
|
const def = inst._zod.def;
|
|
34241
34266
|
const kind = def.type;
|
|
@@ -34338,10 +34363,10 @@ function isRecursive(inst, stack2, resolve8) {
|
|
|
34338
34363
|
stack2.delete(inst);
|
|
34339
34364
|
return settle(inst, result);
|
|
34340
34365
|
}
|
|
34341
|
-
function settle(inst,
|
|
34342
|
-
if (
|
|
34343
|
-
recursive.set(inst,
|
|
34344
|
-
return
|
|
34366
|
+
function settle(inst, answer3) {
|
|
34367
|
+
if (answer3 !== ASSUMED)
|
|
34368
|
+
recursive.set(inst, answer3 === PROVEN);
|
|
34369
|
+
return answer3;
|
|
34345
34370
|
}
|
|
34346
34371
|
function bucketFor(state, inst) {
|
|
34347
34372
|
let bucket = state.buckets.get(inst);
|
|
@@ -41745,26 +41770,26 @@ function isRecursive2(inst, stack2, resolve8) {
|
|
|
41745
41770
|
let result = NONE4;
|
|
41746
41771
|
const check2 = (child) => {
|
|
41747
41772
|
if (result !== PROVEN2 && child?._zod) {
|
|
41748
|
-
const
|
|
41749
|
-
if (
|
|
41750
|
-
result =
|
|
41773
|
+
const answer3 = isRecursive2(child, stack2, resolve8);
|
|
41774
|
+
if (answer3 > result)
|
|
41775
|
+
result = answer3;
|
|
41751
41776
|
}
|
|
41752
41777
|
};
|
|
41753
41778
|
const shape = (sh, spread) => {
|
|
41754
|
-
let
|
|
41779
|
+
let answer3 = NONE4;
|
|
41755
41780
|
for (const key of Reflect.ownKeys(sh)) {
|
|
41756
41781
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
41757
41782
|
if (spread && !desc.enumerable)
|
|
41758
41783
|
continue;
|
|
41759
41784
|
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack2, resolve8) : NONE4;
|
|
41760
|
-
if (child >
|
|
41761
|
-
|
|
41785
|
+
if (child > answer3)
|
|
41786
|
+
answer3 = child;
|
|
41762
41787
|
}
|
|
41763
|
-
return
|
|
41788
|
+
return answer3;
|
|
41764
41789
|
};
|
|
41765
|
-
const merge5 = (
|
|
41766
|
-
if (
|
|
41767
|
-
result =
|
|
41790
|
+
const merge5 = (answer3) => {
|
|
41791
|
+
if (answer3 > result)
|
|
41792
|
+
result = answer3;
|
|
41768
41793
|
};
|
|
41769
41794
|
const def = inst._zod.def;
|
|
41770
41795
|
const kind = def.type;
|
|
@@ -41867,10 +41892,10 @@ function isRecursive2(inst, stack2, resolve8) {
|
|
|
41867
41892
|
stack2.delete(inst);
|
|
41868
41893
|
return settle2(inst, result);
|
|
41869
41894
|
}
|
|
41870
|
-
function settle2(inst,
|
|
41871
|
-
if (
|
|
41872
|
-
recursive2.set(inst,
|
|
41873
|
-
return
|
|
41895
|
+
function settle2(inst, answer3) {
|
|
41896
|
+
if (answer3 !== ASSUMED2)
|
|
41897
|
+
recursive2.set(inst, answer3 === PROVEN2);
|
|
41898
|
+
return answer3;
|
|
41874
41899
|
}
|
|
41875
41900
|
function bucketFor2(state, inst) {
|
|
41876
41901
|
let bucket = state.buckets.get(inst);
|
package/qwen-extension.json
CHANGED