context-mode 2.0.0-next.38 → 2.0.0-next.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/.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 +16 -16
- package/cli.mjs +17 -12
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +82 -82
- package/hooks/claude-code.json +2 -2
- package/opencode/plugin.js +66 -36
- package/package.json +1 -1
- package/pi/index.js +94 -64
- package/qwen-extension.json +1 -1
- package/run.mjs +17 -12
- package/search.mjs +17 -12
- package/server.mjs +94 -64
package/hooks/claude-code.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"type": "command"
|
|
10
10
|
}
|
|
11
11
|
],
|
|
12
|
-
"matcher": "^(Bash|Read|Grep|WebFetch|Write|Edit|NotebookEdit|mcp__plugin_context-mode_context-mode__ctx_.*|mcp__.*)$"
|
|
12
|
+
"matcher": "^(Bash|PowerShell|Read|Grep|WebFetch|Write|Edit|NotebookEdit|mcp__plugin_context-mode_context-mode__ctx_.*|mcp__.*)$"
|
|
13
13
|
}
|
|
14
14
|
],
|
|
15
15
|
"PreToolUse": [
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"type": "command"
|
|
22
22
|
}
|
|
23
23
|
],
|
|
24
|
-
"matcher": "^(Bash|Read|Grep|WebFetch|Write|Edit|NotebookEdit|mcp__plugin_context-mode_context-mode__ctx_.*)$"
|
|
24
|
+
"matcher": "^(Bash|PowerShell|Read|Grep|WebFetch|Write|Edit|NotebookEdit|mcp__plugin_context-mode_context-mode__ctx_.*)$"
|
|
25
25
|
}
|
|
26
26
|
],
|
|
27
27
|
"SessionStart": [
|
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 ? "f65e531334ad61c4f55cda02d1a370587e1d59cc" : 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",
|
|
@@ -1011,6 +1012,9 @@ var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscod
|
|
|
1011
1012
|
|
|
1012
1013
|
// src/adapters/claude-code.ts
|
|
1013
1014
|
var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
1015
|
+
var SHELL_TOOL_NAMES = Object.freeze(["Bash", "PowerShell"]);
|
|
1016
|
+
var POWERSHELL_TOOL = "PowerShell";
|
|
1017
|
+
var SHELL_CANONICAL = "Bash";
|
|
1014
1018
|
var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
|
|
1015
1019
|
var MCP_PREFIX = "mcp__";
|
|
1016
1020
|
var MCP_SEP = "__";
|
|
@@ -1136,6 +1140,7 @@ function requireFields(raw) {
|
|
|
1136
1140
|
function decode(raw) {
|
|
1137
1141
|
requireFields(raw);
|
|
1138
1142
|
const ev = decodeClaudeShape(raw, "claude-code", TOOL_NAME_PREFIX, CLAUDE_SOURCES);
|
|
1143
|
+
if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
|
|
1139
1144
|
if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
1140
1145
|
if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
|
|
1141
1146
|
const cmd = typeof ev.tool.input.command === "string" ? ev.tool.input.command : JSON.stringify(ev.tool.input);
|
|
@@ -1285,8 +1290,8 @@ var RESULT_SUCCESS = "success";
|
|
|
1285
1290
|
function isRecord(v) {
|
|
1286
1291
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1287
1292
|
}
|
|
1288
|
-
var
|
|
1289
|
-
var NATIVE_TO_CANONICAL3 = Object.fromEntries(
|
|
1293
|
+
var SHELL_TOOL_NAMES2 = Object.freeze(["bash", "powershell"]);
|
|
1294
|
+
var NATIVE_TO_CANONICAL3 = Object.fromEntries(SHELL_TOOL_NAMES2.map((n) => [n, "Bash"]));
|
|
1290
1295
|
function canonicalName3(name) {
|
|
1291
1296
|
if (name.startsWith(TOOL_NAME_PREFIX5)) return name.slice(TOOL_NAME_PREFIX5.length);
|
|
1292
1297
|
if (Object.hasOwn(NATIVE_TO_CANONICAL3, name)) return NATIVE_TO_CANONICAL3[name];
|
|
@@ -1367,11 +1372,11 @@ var VSCODE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostTool
|
|
|
1367
1372
|
var MCP_PREFIX2 = "mcp_";
|
|
1368
1373
|
var MCP_SEP2 = "_";
|
|
1369
1374
|
var SESSION_START_NEW = "new";
|
|
1370
|
-
var
|
|
1375
|
+
var SHELL_TOOL_NAMES3 = Object.freeze(["run_in_terminal", "runTerminalCommand", "bash", "powershell"]);
|
|
1371
1376
|
var READ_TOOL_NAMES = Object.freeze(["read_file", "view"]);
|
|
1372
1377
|
var WEBFETCH_TOOL_NAMES = Object.freeze(["fetch_webpage", "web_fetch"]);
|
|
1373
1378
|
var NATIVE_TO_CANONICAL4 = Object.fromEntries([
|
|
1374
|
-
...
|
|
1379
|
+
...SHELL_TOOL_NAMES3.map((n) => [n, "Bash"]),
|
|
1375
1380
|
...READ_TOOL_NAMES.map((n) => [n, "Read"]),
|
|
1376
1381
|
...WEBFETCH_TOOL_NAMES.map((n) => [n, "WebFetch"])
|
|
1377
1382
|
]);
|
|
@@ -1499,8 +1504,8 @@ var KIRO_EVENTS = {
|
|
|
1499
1504
|
};
|
|
1500
1505
|
var PROMPT_ENV = "USER_PROMPT";
|
|
1501
1506
|
var MCP_PREFIX3 = "mcp_";
|
|
1502
|
-
var
|
|
1503
|
-
var NATIVE_TO_CANONICAL5 = Object.fromEntries(
|
|
1507
|
+
var SHELL_TOOL_NAMES4 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
|
|
1508
|
+
var NATIVE_TO_CANONICAL5 = Object.fromEntries(SHELL_TOOL_NAMES4.map((n) => [n, "Bash"]));
|
|
1504
1509
|
var MCP_SEP3 = "_";
|
|
1505
1510
|
var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
1506
1511
|
function canonicalName5(name) {
|
|
@@ -1642,8 +1647,8 @@ var OPENCODE_EVENTS = {
|
|
|
1642
1647
|
"step-finish": "Usage"
|
|
1643
1648
|
};
|
|
1644
1649
|
var SHELL_TOOL_NAME = "bash";
|
|
1645
|
-
var
|
|
1646
|
-
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", ...Object.fromEntries(
|
|
1650
|
+
var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
1651
|
+
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
|
|
1647
1652
|
function toCanonicalTool(name) {
|
|
1648
1653
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
1649
1654
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -1691,13 +1696,14 @@ function encode10(ev, d, _extra) {
|
|
|
1691
1696
|
// src/adapters/table.ts
|
|
1692
1697
|
var CLAUDE_EVENTS = { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" };
|
|
1693
1698
|
var CLAUDE_TOOLS = { shell: ["Bash"], read: ["Read"], grep: ["Grep"], webfetch: ["WebFetch"], edit: ["Write", "Edit", "NotebookEdit"] };
|
|
1699
|
+
var CLAUDE_CODE_TOOLS = { ...CLAUDE_TOOLS, shell: [...SHELL_TOOL_NAMES] };
|
|
1694
1700
|
var ADAPTERS = Object.freeze([
|
|
1695
1701
|
{
|
|
1696
1702
|
id: "claude-code",
|
|
1697
1703
|
installMode: "marketplace",
|
|
1698
1704
|
projectSource: "env:CLAUDE_PROJECT_DIR",
|
|
1699
1705
|
toolNamePrefix: TOOL_NAME_PREFIX,
|
|
1700
|
-
nativeTools:
|
|
1706
|
+
nativeTools: CLAUDE_CODE_TOOLS,
|
|
1701
1707
|
execReadOnlyHint: false,
|
|
1702
1708
|
eventMap: CLAUDE_EVENTS,
|
|
1703
1709
|
compactDelivery: "sessionstart",
|
|
@@ -1773,7 +1779,7 @@ var ADAPTERS = Object.freeze([
|
|
|
1773
1779
|
installMode: "plugin",
|
|
1774
1780
|
projectSource: "arg:--agent+cwd",
|
|
1775
1781
|
toolNamePrefix: TOOL_NAME_PREFIX5,
|
|
1776
|
-
nativeTools: { shell: [...
|
|
1782
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES2] },
|
|
1777
1783
|
execReadOnlyHint: false,
|
|
1778
1784
|
// D-PWSH-DUMP-1
|
|
1779
1785
|
eventMap: { SessionStart: "sessionStart", UserPromptSubmit: "userPromptSubmitted", PreToolUse: "preToolUse", PostToolUse: "postToolUse" },
|
|
@@ -1793,7 +1799,7 @@ var ADAPTERS = Object.freeze([
|
|
|
1793
1799
|
projectSource: "arg:workspaceFolder",
|
|
1794
1800
|
toolNamePrefix: TOOL_NAME_PREFIX6,
|
|
1795
1801
|
// PreCompact sets the pending flag (ADR-0009 §6, DEVIATIONS D-M3-A4-1).
|
|
1796
|
-
nativeTools: { shell: [...
|
|
1802
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES3], read: [...READ_TOOL_NAMES], webfetch: [...WEBFETCH_TOOL_NAMES] },
|
|
1797
1803
|
// D-HF-VSCODE-PROJECT-1, D-N7-VSCODE-TOOLS-1
|
|
1798
1804
|
execReadOnlyHint: false,
|
|
1799
1805
|
eventMap: { ...CLAUDE_EVENTS, PreCompact: "PreCompact" },
|
|
@@ -1812,7 +1818,7 @@ var ADAPTERS = Object.freeze([
|
|
|
1812
1818
|
installMode: "mcp-entry",
|
|
1813
1819
|
projectSource: "arg:--agent+cwd",
|
|
1814
1820
|
toolNamePrefix: TOOL_NAME_PREFIX7,
|
|
1815
|
-
nativeTools: { shell: [...
|
|
1821
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES4] },
|
|
1816
1822
|
execReadOnlyHint: false,
|
|
1817
1823
|
// D-HF-KIRO-SHELL-1, D-N7-KIRO-1
|
|
1818
1824
|
eventMap: { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" },
|
|
@@ -7076,7 +7082,7 @@ function ftsQueryTimeline(db, scope, ctx, sessionId, limit, after, source, memor
|
|
|
7076
7082
|
}
|
|
7077
7083
|
}
|
|
7078
7084
|
for (const m of memory) {
|
|
7079
|
-
if (m.ts > from && (source === void 0 || m.label === source)) merged.push(m);
|
|
7085
|
+
if (m.ts > from && (source === void 0 || m.label === source || MEMORY_LABEL_PREFIX + m.label === source)) merged.push(m);
|
|
7080
7086
|
}
|
|
7081
7087
|
merged.sort(timelineOrder);
|
|
7082
7088
|
let end = Math.min(limit, merged.length);
|
|
@@ -20264,6 +20270,10 @@ function readAutoMemory(project) {
|
|
|
20264
20270
|
}
|
|
20265
20271
|
return rows;
|
|
20266
20272
|
}
|
|
20273
|
+
function memoryFileNamed(rows, value) {
|
|
20274
|
+
const v = value.split("\\").join("/");
|
|
20275
|
+
return rows.find((r) => r.label === v || MEMORY_LABEL_PREFIX + r.label === v) ?? null;
|
|
20276
|
+
}
|
|
20267
20277
|
function memoryChunks(rows) {
|
|
20268
20278
|
const out = [];
|
|
20269
20279
|
rows.forEach((r, i) => {
|
|
@@ -20276,7 +20286,7 @@ function memoryHits(chunks, q, limit) {
|
|
|
20276
20286
|
const texts = chunks.map((c) => c.text);
|
|
20277
20287
|
const any2 = rankTexts(texts, q, "any");
|
|
20278
20288
|
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:
|
|
20289
|
+
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
20290
|
}
|
|
20281
20291
|
|
|
20282
20292
|
// src/core/tools/search.ts
|
|
@@ -20314,8 +20324,8 @@ function sourceCount(db, scope, ctx, source) {
|
|
|
20314
20324
|
});
|
|
20315
20325
|
return Number(row5.n);
|
|
20316
20326
|
}
|
|
20317
|
-
function zeroHits(db, scope, ctx, source, offset = 0) {
|
|
20318
|
-
const n = sourceCount(db, scope, ctx, source);
|
|
20327
|
+
function zeroHits(db, scope, ctx, source, mem, offset = 0) {
|
|
20328
|
+
const n = sourceCount(db, scope, ctx, source) + mem.rows.length;
|
|
20319
20329
|
if (offset > 0) return reply("No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
20320
20330
|
return reply('No hits in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
20321
20331
|
}
|
|
@@ -20338,7 +20348,7 @@ function sourceCard(db, id2, input, scope, arg) {
|
|
|
20338
20348
|
}
|
|
20339
20349
|
function callText(queries, scope, source, cursor) {
|
|
20340
20350
|
const src = source === void 0 ? "" : ", source:" + JSON.stringify(source);
|
|
20341
|
-
return "ctx_search({queries:" + JSON.stringify(queries) + ", scope:" + JSON.stringify(scope) + src + ", " + cursor + "})";
|
|
20351
|
+
return "ctx_search({queries:" + JSON.stringify(queries) + ", scope:" + JSON.stringify(scope) + src + (cursor === "" ? "" : ", " + cursor) + "})";
|
|
20342
20352
|
}
|
|
20343
20353
|
function decisionQueries(input) {
|
|
20344
20354
|
return input.source === DECISION_SOURCE && input.queries.length === 0 ? [""] : input.queries;
|
|
@@ -20437,18 +20447,24 @@ function mergeMemory(content, memory) {
|
|
|
20437
20447
|
return out;
|
|
20438
20448
|
}
|
|
20439
20449
|
var contentIn = (hits, n) => hits.slice(0, n).filter((h) => h.sourceId > 0).length;
|
|
20440
|
-
function relevance(db, given, scope, ctx, nm) {
|
|
20450
|
+
function relevance(db, given, scope, ctx, nm, ms, indexed) {
|
|
20441
20451
|
const input = { ...given, queries: decisionQueries(given) };
|
|
20442
20452
|
const offset = input.offset ?? 0;
|
|
20443
20453
|
const size = pageSize(input);
|
|
20444
|
-
const mem =
|
|
20454
|
+
const mem = ms.named || offset === 0 ? memoryChunks(ms.rows) : [];
|
|
20455
|
+
const count2 = (hits, n) => ms.named ? Math.min(n, hits.length) : contentIn(hits, n);
|
|
20445
20456
|
const fetched = input.queries.map((q) => {
|
|
20457
|
+
if (ms.named) {
|
|
20458
|
+
const want = offset + size + 1;
|
|
20459
|
+
const content2 = indexed ? ftsQuery(db, q, scope, ctx.project, ctx.sessionId, want, 0, input.source) : [];
|
|
20460
|
+
return mergeMemory(content2, memoryHits(mem, q, want)).slice(offset, want);
|
|
20461
|
+
}
|
|
20446
20462
|
const content = page(db, q, input, scope, ctx, offset, 1);
|
|
20447
20463
|
return mem.length === 0 ? content : mergeMemory(content, memoryHits(mem, q, MEMORY_HITS));
|
|
20448
20464
|
});
|
|
20449
20465
|
const take = fetched.map((h) => replyHits(h, size));
|
|
20450
20466
|
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);
|
|
20467
|
+
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, offset);
|
|
20452
20468
|
const moreLine3 = (q, pos) => "More: " + callText([q], scope, nm.arg, "offset:" + pos);
|
|
20453
20469
|
let reserve = 0;
|
|
20454
20470
|
for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
|
|
@@ -20481,13 +20497,13 @@ function relevance(db, given, scope, ctx, nm) {
|
|
|
20481
20497
|
}
|
|
20482
20498
|
const line = shownLabel(hit.label, hit.sourceId) + " #" + hit.ord + ": " + hit.snippet;
|
|
20483
20499
|
if (used + bytes2(line) + 1 + reserve > OUTPUT_CAP) {
|
|
20484
|
-
cut = offset +
|
|
20500
|
+
cut = offset + count2(hits, i);
|
|
20485
20501
|
stopped = true;
|
|
20486
20502
|
break;
|
|
20487
20503
|
}
|
|
20488
20504
|
const room = total.get(hit.sourceId);
|
|
20489
20505
|
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 +
|
|
20506
|
+
cut = offset + count2(hits, i);
|
|
20491
20507
|
break;
|
|
20492
20508
|
}
|
|
20493
20509
|
lines.push(line);
|
|
@@ -20502,7 +20518,7 @@ function relevance(db, given, scope, ctx, nm) {
|
|
|
20502
20518
|
used += bytes2(line) + 1;
|
|
20503
20519
|
}
|
|
20504
20520
|
if (cut >= 0) more.push({ q, pos: cut });
|
|
20505
|
-
else if (
|
|
20521
|
+
else if (count2(fetched[qi], fetched[qi].length) > count2(fetched[qi], take[qi])) more.push({ q, pos: offset + count2(fetched[qi], take[qi]) });
|
|
20506
20522
|
});
|
|
20507
20523
|
const moreLines = [];
|
|
20508
20524
|
const byPos = /* @__PURE__ */ new Map();
|
|
@@ -20516,10 +20532,9 @@ function timelineLine(r) {
|
|
|
20516
20532
|
const seq = r.seq === null ? "" : " #" + r.seq;
|
|
20517
20533
|
return "[" + new Date(r.ts).toISOString() + "] " + shownLabel(r.label, r.sourceId) + seq + " " + first;
|
|
20518
20534
|
}
|
|
20519
|
-
function timeline(db, input, scope, ctx, nm) {
|
|
20520
|
-
const
|
|
20521
|
-
|
|
20522
|
-
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source);
|
|
20535
|
+
function timeline(db, input, scope, ctx, nm, ms) {
|
|
20536
|
+
const page2 = ftsQueryTimeline(db, scope, ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, input.after ?? null, input.source, ms.rows);
|
|
20537
|
+
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms);
|
|
20523
20538
|
const moreLine3 = (ts) => "more: " + callText(input.queries, scope, nm.arg, 'sort:"timeline", after:' + ts);
|
|
20524
20539
|
const reserve = bytes2(moreLine3(page2.rows[page2.rows.length - 1].ts)) + 1;
|
|
20525
20540
|
const lines = nm.note === null ? [] : [nm.note];
|
|
@@ -20548,6 +20563,15 @@ function timeline(db, input, scope, ctx, nm) {
|
|
|
20548
20563
|
if (more && lastTs !== null) lines.push(moreLine3(lastTs));
|
|
20549
20564
|
return reply(lines.join("\n"), false);
|
|
20550
20565
|
}
|
|
20566
|
+
function answer(db, input, scope, ctx, nm, ms, indexed, sort, pick2) {
|
|
20567
|
+
if (sort === "timeline") return timeline(db, input, scope, ctx, nm, ms);
|
|
20568
|
+
if (pick2 !== null && pick2.id !== null && input.queries.length === 0) {
|
|
20569
|
+
const card = sourceCard(db, pick2.id, input, scope, nm.arg);
|
|
20570
|
+
if (card !== null) return card;
|
|
20571
|
+
}
|
|
20572
|
+
const rows = ms.named ? null : jsonRowsReply(db, input, scope, ctx, nm);
|
|
20573
|
+
return rows ?? relevance(db, input, scope, ctx, nm, ms, indexed);
|
|
20574
|
+
}
|
|
20551
20575
|
async function handler(input, ctx) {
|
|
20552
20576
|
const sort = input.sort ?? "relevance";
|
|
20553
20577
|
if (sort === "timeline" && input.offset !== void 0) {
|
|
@@ -20563,12 +20587,18 @@ async function handler(input, ctx) {
|
|
|
20563
20587
|
const pick2 = given !== void 0 && given !== DECISION_SOURCE ? pickSource(db, given) : null;
|
|
20564
20588
|
if (pick2 !== null) input = { ...input, source: pick2.label };
|
|
20565
20589
|
const nm = named(given, pick2);
|
|
20566
|
-
|
|
20567
|
-
|
|
20568
|
-
|
|
20569
|
-
|
|
20570
|
-
|
|
20571
|
-
|
|
20590
|
+
const indexed = pick2 !== null && pick2.id !== null;
|
|
20591
|
+
const files = scope !== "session" || given !== void 0 ? readAutoMemory(ctx.project) : [];
|
|
20592
|
+
const file2 = given === void 0 || given === DECISION_SOURCE ? null : memoryFileNamed(files, given);
|
|
20593
|
+
const ms = { rows: scope === "session" ? [] : file2 !== null ? [file2] : given === void 0 ? files : [], named: file2 !== null };
|
|
20594
|
+
if (file2 !== null && indexed && scope !== "session") {
|
|
20595
|
+
const both = "Source " + JSON.stringify(given) + ": searched the indexed source " + shownLabel(pick2.label, pick2.id) + " and the memory file " + file2.label + ".";
|
|
20596
|
+
nm.note = nm.note === null ? both : nm.note + "\n" + both;
|
|
20597
|
+
}
|
|
20598
|
+
const out = answer(db, input, scope, ctx, nm, ms, indexed, sort, pick2);
|
|
20599
|
+
if (file2 === null || scope !== "session") return out;
|
|
20600
|
+
const call = callText(input.queries, "worktree", nm.arg, sort === "timeline" ? 'sort:"timeline"' : "");
|
|
20601
|
+
return reply(out.text + "\nMemory file " + file2.label + ' is in scope "worktree": ' + call + " searches it.", out.isError);
|
|
20572
20602
|
} finally {
|
|
20573
20603
|
closeDb(db);
|
|
20574
20604
|
}
|
|
@@ -20704,7 +20734,7 @@ function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
|
20704
20734
|
function bytes3(s) {
|
|
20705
20735
|
return Buffer.byteLength(s, "utf8");
|
|
20706
20736
|
}
|
|
20707
|
-
function
|
|
20737
|
+
function answer2(db, ctx, ownIds, queries, share, own2) {
|
|
20708
20738
|
const seen = /* @__PURE__ */ new Set();
|
|
20709
20739
|
const lines = [];
|
|
20710
20740
|
for (const [qi, q] of queries.entries()) {
|
|
@@ -20767,7 +20797,7 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
20767
20797
|
notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
|
|
20768
20798
|
const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
|
|
20769
20799
|
const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
|
|
20770
|
-
const answered =
|
|
20800
|
+
const answered = answer2(db, ctx, idx.ids, queries, share, idx.bodies);
|
|
20771
20801
|
sections = answered.lines;
|
|
20772
20802
|
const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
|
|
20773
20803
|
const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
|
package/package.json
CHANGED