dsh-vscode-mode 0.1.27 → 0.1.29

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/lib/index.js CHANGED
@@ -106,11 +106,37 @@ async function refreshMcp(ctx, id) {
106
106
  return serverOf(ctx, loader.resolve(entry.id));
107
107
  }
108
108
  //#endregion
109
+ //#region src/shared/keybindings.ts
110
+ /**
111
+ * dsh-vscode-mode shared — 快捷键命令目录与默认键位(双面契约)。
112
+ * 纯数据模块:host(settings schema 默认值)与 client(执行匹配/设置页)共用。
113
+ * 键位格式:修饰符 + 主键,`+` 连接,如 `Ctrl+Shift+F`;空串 = 未绑定。
114
+ * 作者 ddj 2026年08月26号
115
+ */
116
+ /** 命令 id → 默认键位。命令目录以此为准,新增命令只需加一项。 */
117
+ const KEYBINDING_DEFAULTS = {
118
+ "edrv.save": "Ctrl+S",
119
+ "edrv.quickOpen": "Ctrl+P",
120
+ "edrv.toggleSidebar": "Ctrl+B",
121
+ "edrv.searchInFiles": "Ctrl+Shift+F"
122
+ };
123
+ //#endregion
109
124
  //#region src/fileOpenSettings.ts
110
125
  const FILE_OPEN_SETTINGS_NS = "dsh-vscode-mode";
111
126
  const FILE_OPEN_DEFAULT = "auto";
112
127
  let depsPromise;
113
128
  /**
129
+ * 按命令目录构建 keybindings 显式键形状(每键独立默认值)。
130
+ * @author ddj 2026年08月26号
131
+ * @param z schemastery 命名空间
132
+ * @returns keybindings 字段形状
133
+ */
134
+ function keybindingsShape(z) {
135
+ const shape = {};
136
+ for (const [id, chord] of Object.entries(KEYBINDING_DEFAULTS)) shape[id] = z.string().default(chord);
137
+ return shape;
138
+ }
139
+ /**
114
140
  * 动态加载设置依赖(模块级缓存;任一缺失返回 null 而非抛错)。
115
141
  * @author ddj 2026年08月24号
116
142
  * @returns 设置依赖或 null
@@ -142,7 +168,10 @@ function configValue(config) {
142
168
  async function installOpenSettingsSection(ctx, ns, entry, hooks, loader = loadSettingsDeps) {
143
169
  const deps = await loader();
144
170
  if (!deps) return false;
145
- const schema = deps.z.object({ fileOpenTool: deps.z.string().default(FILE_OPEN_DEFAULT) });
171
+ const schema = deps.z.object({
172
+ fileOpenTool: deps.z.string().default(FILE_OPEN_DEFAULT),
173
+ keybindings: deps.z.object(keybindingsShape(deps.z)).default({ ...KEYBINDING_DEFAULTS })
174
+ });
146
175
  deps.installSettingsSection(ctx, ns, schema, entry, hooks);
147
176
  return true;
148
177
  }
@@ -1457,9 +1486,10 @@ function pathMatch(value, query) {
1457
1486
  * 通过独立 argv 调用打包 rg,避免先构建巨型全量文件数组。
1458
1487
  * 作者 ddj 2026年08月24号
1459
1488
  */
1460
- const STDOUT_CAP = 4 << 20;
1461
- const STDERR_CAP = 65536;
1462
- const GRACE_MS = 2e4;
1489
+ const STDOUT_CAP$1 = 4 << 20;
1490
+ const STDERR_CAP$1 = 65536;
1491
+ const GRACE_MS$1 = 2e4;
1492
+ /** 默认排除目录(文件/内容搜索共用,导出供 provider 复用)。 */
1463
1493
  const EXCLUDES = [
1464
1494
  "node_modules",
1465
1495
  ".git",
@@ -1469,7 +1499,22 @@ const EXCLUDES = [
1469
1499
  "build",
1470
1500
  "vendor",
1471
1501
  "coverage",
1472
- "__pycache__"
1502
+ "__pycache__",
1503
+ ".pnpm-store",
1504
+ ".npm-cache",
1505
+ ".codegraph",
1506
+ ".workbuddy"
1507
+ ];
1508
+ /**
1509
+ * 默认排除文件(glob 模式,文件/内容搜索共用)。
1510
+ * 插件自身 sidecar(内容搜索会命中其历史编辑文本,且单行巨型 JSON 会撑爆输出上限);
1511
+ * *.map 源映射(纯构建产物,内容搜索无意义且常为单行巨文件)。
1512
+ */
1513
+ const FILE_EXCLUDES = [
1514
+ "**/.dsh-edit-review.json",
1515
+ "**/.dsh-edit-review-archive.json",
1516
+ "**/.dsh-edit-review-debug.log",
1517
+ "**/*.map"
1473
1518
  ];
1474
1519
  /**
1475
1520
  * 将 query 转成 rg 的字面 glob。
@@ -1556,16 +1601,17 @@ async function searchRipgrep(input) {
1556
1601
  queryGlob(prepareQuery(input.query).text)
1557
1602
  ];
1558
1603
  for (const excluded of EXCLUDES) argv.push("--glob", "!**/" + excluded + "/**");
1604
+ for (const excluded of FILE_EXCLUDES) argv.push("--glob", "!" + excluded);
1559
1605
  argv.push("--", root);
1560
1606
  const handle = sub.spawn({
1561
1607
  argv,
1562
1608
  cwd: root,
1563
1609
  stdio: {
1564
1610
  stdin: "ignore",
1565
- stdout: { maxBytes: STDOUT_CAP },
1566
- stderr: { maxBytes: STDERR_CAP }
1611
+ stdout: { maxBytes: STDOUT_CAP$1 },
1612
+ stderr: { maxBytes: STDERR_CAP$1 }
1567
1613
  },
1568
- graceMs: GRACE_MS,
1614
+ graceMs: GRACE_MS$1,
1569
1615
  signal: input.signal
1570
1616
  });
1571
1617
  let outcome;
@@ -1603,7 +1649,14 @@ const EXCLUDED = /* @__PURE__ */ new Set([
1603
1649
  "build",
1604
1650
  "vendor",
1605
1651
  "coverage",
1606
- "__pycache__"
1652
+ "__pycache__",
1653
+ ".pnpm-store",
1654
+ ".npm-cache",
1655
+ ".codegraph",
1656
+ ".workbuddy",
1657
+ ".dsh-edit-review.json",
1658
+ ".dsh-edit-review-archive.json",
1659
+ ".dsh-edit-review-debug.log"
1607
1660
  ]);
1608
1661
  /**
1609
1662
  * 在一个目录树中递归查找匹配文件。
@@ -1710,16 +1763,25 @@ function rankCandidates(candidates, query) {
1710
1763
  const CACHE_TTL = 6e4;
1711
1764
  const CACHE_LIMIT = 100;
1712
1765
  const RESULT_LIMIT = 50;
1713
- const PROVIDER_VERSION = "ripgrep-v1";
1766
+ const PROVIDER_VERSION$1 = "ripgrep-v1";
1714
1767
  const POLICY_VERSION = "search-policy-v1";
1715
1768
  /**
1716
- * 短期有界搜索缓存。
1769
+ * 短期有界搜索缓存(泛型:文件/内容搜索共用;clone 由调用方保证写隔离)。
1717
1770
  * @author ddj 2026年08月24号
1718
- * @returns 缓存对象
1771
+ * @param clone 结果写隔离克隆(缺省恒等)
1719
1772
  */
1720
1773
  var SearchCache = class {
1774
+ clone;
1721
1775
  entries = /* @__PURE__ */ new Map();
1722
1776
  /**
1777
+ * 创建缓存。
1778
+ * @author ddj 2026年08月24号
1779
+ * @param clone 结果克隆函数(缺省直接引用)
1780
+ */
1781
+ constructor(clone = (value) => value) {
1782
+ this.clone = clone;
1783
+ }
1784
+ /**
1723
1785
  * 读取未过期条目。
1724
1786
  * @author ddj 2026年08月24号
1725
1787
  * @param key 缓存 key
@@ -1735,10 +1797,7 @@ var SearchCache = class {
1735
1797
  }
1736
1798
  this.entries.delete(key);
1737
1799
  this.entries.set(key, entry);
1738
- return {
1739
- ...entry.result,
1740
- files: [...entry.result.files]
1741
- };
1800
+ return this.clone(entry.result);
1742
1801
  }
1743
1802
  /**
1744
1803
  * 写入成功 provider 结果。
@@ -1751,10 +1810,7 @@ var SearchCache = class {
1751
1810
  this.entries.delete(key);
1752
1811
  this.entries.set(key, {
1753
1812
  at: now,
1754
- result: {
1755
- ...result,
1756
- files: [...result.files]
1757
- }
1813
+ result: this.clone(result)
1758
1814
  });
1759
1815
  while (this.entries.size > CACHE_LIMIT) this.entries.delete(this.entries.keys().next().value);
1760
1816
  }
@@ -1841,7 +1897,10 @@ function mergeCandidates(result, activePaths, root, query) {
1841
1897
  */
1842
1898
  var SearchOrchestrator = class {
1843
1899
  ctx;
1844
- cache = new SearchCache();
1900
+ cache = new SearchCache((r) => ({
1901
+ ...r,
1902
+ files: [...r.files]
1903
+ }));
1845
1904
  inflight = /* @__PURE__ */ new Map();
1846
1905
  rootsByCwd = /* @__PURE__ */ new Map();
1847
1906
  provider;
@@ -1887,7 +1946,7 @@ var SearchOrchestrator = class {
1887
1946
  rootKey,
1888
1947
  query.text,
1889
1948
  policyVersion(this.ctx, request.session),
1890
- PROVIDER_VERSION
1949
+ PROVIDER_VERSION$1
1891
1950
  ].join("|");
1892
1951
  const cached = this.cache.get(key);
1893
1952
  if (cached) return this.finish(cached, request.activePaths, root, query);
@@ -2004,6 +2063,331 @@ function newSearcher(ctx) {
2004
2063
  return new SearchOrchestrator(ctx);
2005
2064
  }
2006
2065
  //#endregion
2066
+ //#region src/search/content.ts
2067
+ const STDOUT_CAP = 16 << 20;
2068
+ const STDERR_CAP = 65536;
2069
+ const GRACE_MS = 2e4;
2070
+ const DEFAULT_MAX_MATCHES = 500;
2071
+ const DEFAULT_MAX_FILES = 100;
2072
+ const PROVIDER_VERSION = "content-ripgrep-v1";
2073
+ /** 单行 JSON 记录上限:巨型单行文件(源映射/打包产物)的命中行对搜索 UI 无意义,直接跳过。 */
2074
+ const MAX_RECORD_LINE = 1 << 20;
2075
+ /**
2076
+ * 把行内字节偏移转成 UTF-16 列(1-based;越界钳到行尾)。
2077
+ * @author ddj 2026年08月26号
2078
+ * @param text 行文本
2079
+ * @param byteOffset 行内字节偏移(rg submatches.start/end,实测为行相对)
2080
+ * @returns 1-based UTF-16 列
2081
+ */
2082
+ function byteToUtf16Col(text, byteOffset) {
2083
+ let bytes = 0;
2084
+ let col = 1;
2085
+ for (const char of text) {
2086
+ if (bytes >= byteOffset) break;
2087
+ bytes += Buffer.byteLength(char);
2088
+ col++;
2089
+ }
2090
+ return col;
2091
+ }
2092
+ /**
2093
+ * 根内绝对路径 → 工作区相对显示路径(供 edrv.read 与面板展示)。
2094
+ * @author ddj 2026年08月26号
2095
+ * @param value rg 输出路径
2096
+ * @param root 搜索根(subprocess 执行世界)
2097
+ * @returns 相对路径(根外路径原样返回)
2098
+ */
2099
+ function displayPathOf(value, root) {
2100
+ const path = pathText(String(value ?? ""));
2101
+ if (!path) return path;
2102
+ const base = pathText(root).replace(/\/$/, "");
2103
+ const lowerPath = path.toLocaleLowerCase("en-US");
2104
+ const lowerBase = base.toLocaleLowerCase("en-US");
2105
+ if (lowerPath === lowerBase) return ".";
2106
+ if (lowerPath.startsWith(lowerBase + "/")) return path.slice(base.length + 1);
2107
+ return path;
2108
+ }
2109
+ /**
2110
+ * 解析 rg --json 输出为扁平命中列表(多子匹配展开,列转 UTF-16)。
2111
+ * @author ddj 2026年08月26号
2112
+ * @param text stdout 文本
2113
+ * @param root 搜索根
2114
+ * @returns 命中列表
2115
+ */
2116
+ function parseRgJsonLines(text, root) {
2117
+ const matches = [];
2118
+ for (const line of text.split(/\r?\n/)) {
2119
+ const trimmed = line.trim();
2120
+ if (!trimmed) continue;
2121
+ let item;
2122
+ try {
2123
+ item = JSON.parse(trimmed);
2124
+ } catch {
2125
+ continue;
2126
+ }
2127
+ if (item?.type !== "match" || !item.data) continue;
2128
+ const data = item.data;
2129
+ const path = displayPathOf(data.path?.text, root);
2130
+ const lineText = (data.lines?.text ?? "").replace(/\r?\n$/, "").replace(/\r$/, "");
2131
+ if (lineText.length > MAX_RECORD_LINE) continue;
2132
+ const lineNumber = data.line_number ?? 0;
2133
+ for (const sub of data.submatches ?? []) matches.push({
2134
+ path,
2135
+ line: lineNumber,
2136
+ startColumn: byteToUtf16Col(lineText, sub.start ?? 0),
2137
+ endColumn: byteToUtf16Col(lineText, sub.end ?? 0),
2138
+ text: lineText
2139
+ });
2140
+ }
2141
+ return matches;
2142
+ }
2143
+ /**
2144
+ * 命中截断:匹配数/文件数双上限,超限标记 truncated。
2145
+ * @author ddj 2026年08月26号
2146
+ * @param matches 全部命中
2147
+ * @param maxMatches 匹配数上限
2148
+ * @param maxFiles 文件数上限
2149
+ * @returns 截断后的命中与标志
2150
+ */
2151
+ function applyCaps(matches, maxMatches, maxFiles) {
2152
+ const seen = /* @__PURE__ */ new Set();
2153
+ const out = [];
2154
+ let truncated = false;
2155
+ for (const match of matches) {
2156
+ if (out.length >= maxMatches) {
2157
+ truncated = true;
2158
+ break;
2159
+ }
2160
+ if (!seen.has(match.path)) {
2161
+ if (seen.size >= maxFiles) {
2162
+ truncated = true;
2163
+ break;
2164
+ }
2165
+ seen.add(match.path);
2166
+ }
2167
+ out.push(match);
2168
+ }
2169
+ return {
2170
+ matches: out,
2171
+ truncated
2172
+ };
2173
+ }
2174
+ /**
2175
+ * 构造 rg 内容搜索 argv(pattern 放 `--` 后首位置,支持前导 `-` 的查询)。
2176
+ * include/exclude 为用户 glob(gitignore 式,原样透传不转义),
2177
+ * 分别转正选 `--glob` 与排除 `--glob !`。
2178
+ * @author ddj 2026年08月26号
2179
+ * @param binary rg 路径
2180
+ * @param root 搜索根
2181
+ * @param input 搜索输入
2182
+ * @returns argv 数组
2183
+ */
2184
+ function contentArgv(binary, root, input) {
2185
+ const argv = [
2186
+ binary,
2187
+ "--no-config",
2188
+ "--json",
2189
+ "--line-number",
2190
+ "--no-heading",
2191
+ "--color",
2192
+ "never",
2193
+ "--hidden",
2194
+ "--no-ignore"
2195
+ ];
2196
+ if (input.matchCase === true) argv.push("--case-sensitive");
2197
+ if (input.wholeWord === true) argv.push("--word-regexp");
2198
+ if (input.regex !== true) argv.push("--fixed-strings");
2199
+ for (const excluded of EXCLUDES) argv.push("--glob", "!**/" + excluded + "/**");
2200
+ for (const excluded of FILE_EXCLUDES) argv.push("--glob", "!" + excluded);
2201
+ for (const pattern of input.include ?? []) {
2202
+ const glob = String(pattern).trim();
2203
+ if (glob) argv.push("--glob", glob);
2204
+ }
2205
+ for (const pattern of input.exclude ?? []) {
2206
+ const glob = String(pattern).trim();
2207
+ if (glob) argv.push("--glob", "!" + glob);
2208
+ }
2209
+ argv.push("--", input.query, root);
2210
+ return argv;
2211
+ }
2212
+ /**
2213
+ * 使用打包 ripgrep 搜索文件内容。
2214
+ * @author ddj 2026年08月26号
2215
+ * @param input provider 输入
2216
+ * @returns 有界内容搜索结果
2217
+ */
2218
+ async function searchRipgrepContent(input) {
2219
+ const sub = input.ctx.get("subprocess");
2220
+ if (!sub) throw new Error("缺少 subprocess");
2221
+ const binary = ripgrepPath();
2222
+ if (!binary) throw new Error("ripgrep 不可用");
2223
+ const root = input.root ?? await searchRoot(input.ctx, input.session);
2224
+ const handle = sub.spawn({
2225
+ argv: contentArgv(binary, root, input),
2226
+ cwd: root,
2227
+ stdio: {
2228
+ stdin: "ignore",
2229
+ stdout: { maxBytes: STDOUT_CAP },
2230
+ stderr: { maxBytes: STDERR_CAP }
2231
+ },
2232
+ graceMs: GRACE_MS,
2233
+ signal: input.signal
2234
+ });
2235
+ let outcome;
2236
+ try {
2237
+ outcome = await handle.done;
2238
+ } catch (error) {
2239
+ throw new Error("ripgrep 启动失败:" + String(error));
2240
+ }
2241
+ const code = outcome.exitCode ?? outcome.code;
2242
+ if (code !== 0 && code !== 1) throw new Error("ripgrep 退出码:" + String(code));
2243
+ const reader = handle.collected?.stdout;
2244
+ if (!reader) throw new Error("ripgrep stdout 不可用");
2245
+ const output = reader.readFrom(0);
2246
+ const capped = applyCaps(parseRgJsonLines(output.text, root), Math.max(1, Math.min(input.maxResults ?? DEFAULT_MAX_MATCHES, DEFAULT_MAX_MATCHES)), DEFAULT_MAX_FILES);
2247
+ const truncated = Boolean(output.lossy) || capped.truncated;
2248
+ return {
2249
+ ...capped,
2250
+ complete: !truncated,
2251
+ source: "ripgrep"
2252
+ };
2253
+ }
2254
+ /**
2255
+ * 内容搜索编排器:短期缓存 + 同根在途取消 + 会话清理。
2256
+ * @author ddj 2026年08月26号
2257
+ */
2258
+ var ContentSearcher = class {
2259
+ ctx;
2260
+ provider;
2261
+ cache = new SearchCache((r) => ({
2262
+ ...r,
2263
+ matches: [...r.matches]
2264
+ }));
2265
+ inflight = /* @__PURE__ */ new Map();
2266
+ rootsByCwd = /* @__PURE__ */ new Map();
2267
+ /**
2268
+ * 创建内容搜索编排器。
2269
+ * @author ddj 2026年08月26号
2270
+ * @param ctx DSH 上下文
2271
+ * @param provider 内容搜索 provider(测试可替换)
2272
+ */
2273
+ constructor(ctx, provider = { search: searchRipgrepContent }) {
2274
+ this.ctx = ctx;
2275
+ this.provider = provider;
2276
+ }
2277
+ /**
2278
+ * 执行一次工作区内容搜索。
2279
+ * @author ddj 2026年08月26号
2280
+ * @param request 搜索请求
2281
+ * @returns RPC 响应字段(provider 失败抛错,abort 返回空)
2282
+ */
2283
+ async search(request) {
2284
+ const query = String(request.query ?? "").trim();
2285
+ if (query.length < 2) return {
2286
+ matches: [],
2287
+ truncated: false
2288
+ };
2289
+ let root;
2290
+ try {
2291
+ root = await searchRoot(this.ctx, request.session);
2292
+ } catch {
2293
+ return {
2294
+ matches: [],
2295
+ truncated: false
2296
+ };
2297
+ }
2298
+ const rootKey = pathText(root);
2299
+ const roots = this.rootsByCwd.get(request.cwd) ?? /* @__PURE__ */ new Set();
2300
+ roots.add(rootKey);
2301
+ this.rootsByCwd.set(request.cwd, roots);
2302
+ const includeKey = (request.include ?? []).join(",");
2303
+ const excludeKey = (request.exclude ?? []).join(",");
2304
+ const key = [
2305
+ rootKey,
2306
+ query,
2307
+ request.matchCase ? "mc" : "",
2308
+ request.wholeWord ? "ww" : "",
2309
+ request.regex ? "rx" : "",
2310
+ includeKey,
2311
+ excludeKey,
2312
+ PROVIDER_VERSION
2313
+ ].join("|");
2314
+ const cached = this.cache.get(key);
2315
+ if (cached) return {
2316
+ matches: cached.matches,
2317
+ truncated: cached.truncated
2318
+ };
2319
+ this.inflight.get(root)?.abort();
2320
+ const controller = new AbortController();
2321
+ this.inflight.set(root, controller);
2322
+ try {
2323
+ const result = await this.provider.search({
2324
+ ctx: this.ctx,
2325
+ session: request.session,
2326
+ cwd: request.cwd,
2327
+ query,
2328
+ matchCase: request.matchCase,
2329
+ wholeWord: request.wholeWord,
2330
+ regex: request.regex,
2331
+ maxResults: request.maxResults,
2332
+ include: request.include,
2333
+ exclude: request.exclude,
2334
+ signal: controller.signal,
2335
+ root
2336
+ });
2337
+ if (controller.signal.aborted) return {
2338
+ matches: [],
2339
+ truncated: false
2340
+ };
2341
+ this.cache.set(key, result);
2342
+ return {
2343
+ matches: result.matches,
2344
+ truncated: result.truncated
2345
+ };
2346
+ } catch (error) {
2347
+ if (controller.signal.aborted) return {
2348
+ matches: [],
2349
+ truncated: false
2350
+ };
2351
+ throw error;
2352
+ } finally {
2353
+ if (this.inflight.get(root) === controller) this.inflight.delete(root);
2354
+ }
2355
+ }
2356
+ /**
2357
+ * 清理会话对应根目录的缓存和在途搜索。
2358
+ * @author ddj 2026年08月26号
2359
+ * @param cwd 会话工作区
2360
+ */
2361
+ dispose(cwd) {
2362
+ const roots = this.rootsByCwd.get(cwd) ?? /* @__PURE__ */ new Set([cwd]);
2363
+ for (const root of roots) {
2364
+ this.inflight.get(root)?.abort();
2365
+ this.inflight.delete(root);
2366
+ this.cache.clearRoot(root);
2367
+ }
2368
+ this.rootsByCwd.delete(cwd);
2369
+ }
2370
+ /**
2371
+ * 清理全部状态。
2372
+ * @author ddj 2026年08月26号
2373
+ */
2374
+ disposeAll() {
2375
+ for (const controller of this.inflight.values()) controller.abort();
2376
+ this.inflight.clear();
2377
+ this.rootsByCwd.clear();
2378
+ this.cache.clear();
2379
+ }
2380
+ };
2381
+ /**
2382
+ * 创建默认内容搜索编排器。
2383
+ * @author ddj 2026年08月26号
2384
+ * @param ctx DSH 上下文
2385
+ * @returns 内容搜索编排器
2386
+ */
2387
+ function newContentSearcher(ctx) {
2388
+ return new ContentSearcher(ctx);
2389
+ }
2390
+ //#endregion
2007
2391
  //#region src/revert.ts
2008
2392
  /**
2009
2393
  * 删除新建文件(拒绝创建时):subprocess 删除,路径先经 fs.contains 校验工作区边界。
@@ -2627,7 +3011,7 @@ async function applyDecisions(ctx, session, cwd, bucket, items) {
2627
3011
  return results;
2628
3012
  }
2629
3013
  /** 各方法 handler 表(类型由 shared/rpc 的 RpcHandlerMap 约束)。 */
2630
- function buildHandlers(ctx, registry, searcher = newSearcher(ctx)) {
3014
+ function buildHandlers(ctx, registry, searcher = newSearcher(ctx), contentSearcher = newContentSearcher(ctx)) {
2631
3015
  return {
2632
3016
  "edrv.list": async (args) => {
2633
3017
  const sc = await requireSession(ctx, args.sessionId);
@@ -2978,6 +3362,34 @@ function buildHandlers(ctx, registry, searcher = newSearcher(ctx)) {
2978
3362
  })
2979
3363
  };
2980
3364
  },
3365
+ "edrv.searchContent": async (args) => {
3366
+ const sc = await requireSession(ctx, args.sessionId);
3367
+ if ("err" in sc) return {
3368
+ ok: false,
3369
+ error: sc.err
3370
+ };
3371
+ try {
3372
+ return {
3373
+ ok: true,
3374
+ ...await contentSearcher.search({
3375
+ session: sc.session,
3376
+ cwd: sc.cwd,
3377
+ query: args.query,
3378
+ matchCase: args.matchCase,
3379
+ wholeWord: args.wholeWord,
3380
+ regex: args.regex,
3381
+ maxResults: args.maxResults,
3382
+ include: args.include,
3383
+ exclude: args.exclude
3384
+ })
3385
+ };
3386
+ } catch (error) {
3387
+ return {
3388
+ ok: false,
3389
+ error: "搜索失败:" + String(error)
3390
+ };
3391
+ }
3392
+ },
2981
3393
  "edrv.listDir": async (args) => {
2982
3394
  const sc = await requireSession(ctx, args.sessionId);
2983
3395
  if ("err" in sc) return {
@@ -3240,10 +3652,10 @@ function buildHandlers(ctx, registry, searcher = newSearcher(ctx)) {
3240
3652
  }
3241
3653
  /**
3242
3654
  * 统一入口:按方法分发到 handler 表。
3243
- * @author ddj 2026年08月20号
3655
+ * @author ddj 2026年08月20号 / 2026年08月26号
3244
3656
  */
3245
- async function handleRpc(ctx, registry, method, args, searcher = newSearcher(ctx)) {
3246
- const handler = buildHandlers(ctx, registry, searcher)[method];
3657
+ async function handleRpc(ctx, registry, method, args, searcher = newSearcher(ctx), contentSearcher = newContentSearcher(ctx)) {
3658
+ const handler = buildHandlers(ctx, registry, searcher, contentSearcher)[method];
3247
3659
  if (!handler) return {
3248
3660
  ok: false,
3249
3661
  error: "未知方法: " + String(method)
@@ -3414,6 +3826,7 @@ const inject = [
3414
3826
  function apply(ctx, config) {
3415
3827
  const registry = /* @__PURE__ */ new Map();
3416
3828
  const searcher = newSearcher(ctx);
3829
+ const contentSearcher = newContentSearcher(ctx);
3417
3830
  /** 兼容性警告收集(route 护栏等写入,启动日志一并输出)。 */
3418
3831
  const warnings = [];
3419
3832
  setupOpenSettings(ctx, config, () => {});
@@ -3426,9 +3839,10 @@ function apply(ctx, config) {
3426
3839
  registry.delete(cwd);
3427
3840
  dropFileIndex(cwd);
3428
3841
  searcher.dispose(cwd);
3842
+ contentSearcher.dispose(cwd);
3429
3843
  }
3430
3844
  });
3431
- registerRoutes(ctx, config, (method, args) => handleRpc(ctx, registry, method, args, searcher), (warning) => warnings.push(warning));
3845
+ registerRoutes(ctx, config, (method, args) => handleRpc(ctx, registry, method, args, searcher, contentSearcher), (warning) => warnings.push(warning));
3432
3846
  installIsolation(ctx);
3433
3847
  logCompatSummary(ctx, warnings);
3434
3848
  ctx.logger?.info?.("[dsh-vscode-mode] 编辑差异审查已装配(/edrv/rpc 路由就绪,项目 MCP 隔离已启用)");