fix(fs-search): direct-open for pasted paths + fragment path matching (#879)

A query carrying a path separator can never match an entry NAME — names
never contain separators — so pasting any path into the search box was
structurally guaranteed to return {matches:[],truncated:true} while the
walk burned its full 100k-visit budget (measured: 1.9s on a Rust repo
whose two worktree forests alone held 97k entries; real directories were
never reached).

searchFiles now routes by query shape, all three modalities sharing one
result contract:

- A query naming one path (absolute, ~/…, ./x, ../x) resolves through
  resolveTarget — the SAME primitive fs.read uses, so ~ expands (#713),
  dot-anchored spellings join onto the session cwd, and win32
  WSL/dsh-remote namespaces reinterpret — then stats the target. The hit
  is the RESOLVED path (resolve() strips shell-completion trailing
  separators, which the client's exact-string row comparisons could never
  match); a missing target answers empty immediately. Directory targets
  ride the #801 dirs contract. The exclude pref does not apply: a pasted
  path is explicit intent, same as the fs.read the click performs.
- A separator-carrying relative fragment (records/exp1) matches by
  root-relative PATH in the walk; the engines are name matchers (fd has
  no --full-path here, rg's globs are single-segment) so argv
  construction is untouched.
- Plain name queries are unchanged, and no NAME query is stolen: on
  POSIX a backslash is a name character (the ~\ gesture counts only on
  win32; util.ts~ / ~$doc.docx / .env stay name queries).

SKIP_DIR_NAMES gains the budget-eating forests seen in the wild:
.worktrees/.worktree (git worktree layouts), target, venv/.venv and
__pycache__ — shared by the walk and both engine argvs as before.

Client: a directory hit OUTSIDE the cwd (newly reachable via the paste
branch) only clears the query — the tree is cwd-rooted, and the old
ancestorDirs call synthesized junk expanded entries for foreign paths.

Verified: vitest fs-search/smoke/search-persist suites green; full run
2171 passed with one failure proven pre-existing on the clean tree
(git.spec checkout case, host git lacks --end-of-options; #841);
typecheck/lint clean.
This commit is contained in:
NolanHo committed 2026-10-06 08:25:30 -07:00
1 parent 4e51e0789c
commit 0d9fee85b8
12 files changed
+471 -56

No files matched your search

+1 -1
View File
@@ -1217,7 +1217,7 @@ better-sidebar 的内置 tab 和 viewer 就是参考实现("吃狗粮"),
- **`src/client/SideCardSection.tsx`**:声明式设置页(注册表驱动清单 + 嵌套设置行 + 开关持久化)
- **`src/client/api.ts`**:`/sidebar` API 的封装(复制其 fetch 模式到你的插件)
- **`src/client/plugins-tabs.ts`** / **`plugins-viewers.ts`**:推荐插件目录(「添加插件」弹窗数据源;加一条数据即上架,`tests/plugin-list.spec.ts` 守护)
- **`src/client/FileTree.tsx`** / **`TreePanel.tsx`** / **`src/fs-search.ts`** / **`src/search-engines.ts`**:文件树 / 树面板 / host 文件名搜索(`fs.search`)。搜索优先探测本机 fd / rg(DSH 自带 ripgrep 优先),缺失或运行失败回退 JS 遍历,两条路径共用同一份 `exclude` 探针(引擎侧是输出后置过滤:匹配条目不出现、被排除目录不下钻);`dirs` 让目录命中行导航文件树而不是当文件打开;调试插桩 `DSH_SEARCH_DEBUG=1` 写 `$DSH_HOME/search-debug.log`,缺省 `~/.dsh`。host 的 `listDirectory` 给目录行标记 `compact`(仅一个非 symlink 有效子项;POSIX 隐藏与 `explorerExclude` 排除条目不计入),client 的 `file-tree-compact.ts` 把单目录链折叠成 `a/b/c` 面包屑行并整链展开/折叠;`explorerExclude`(VS Code `files.exclude` 风格 glob 子集,见 `exclude-patterns.ts`;editor 卡片的声明式 patterns 行可编辑)把匹配条目从树与搜索中彻底移除,两个界面共用同一 host 侧编译好的 matcher;host 侧目录缓存按「路径 + 行额 + 模式集身份」分键,改排除列表即换键。测试:`tests/fs-tree-compact.spec.ts` / `file-tree-compact.spec.ts` / `fs-tree-exclude.spec.ts` / `exclude-patterns.spec.ts` / `fs-search.spec.ts` / `search-engines.spec.ts`
- **`src/client/FileTree.tsx`** / **`TreePanel.tsx`** / **`src/fs-search.ts`** / **`src/search-engines.ts`**:文件树 / 树面板 / host 文件搜索(`fs.search`)。查询分三态(#879):**普通名字**走引擎链——优先探测本机 fd / rg(DSH 自带 ripgrep 优先),缺失或运行失败回退 JS 遍历,两条路径共用同一份 `exclude` 探针(引擎侧是输出后置过滤:匹配条目不出现、被排除目录不下钻);**带分隔符的相对片段**(如 `records/exp1`,名字永不包含分隔符)由 JS 遍历按根相对路径匹配、不进引擎;**指名单一目标的查询**(绝对路径、`~/…`、`./x`、`../x`)经 `resolveTarget`(与 fs.read 同一解析原语:`~` 展开、会话 cwd 拼接、win32 WSL/dsh-remote 命名空间改写、词法 resolve)stat 直取,命中返回解析后的绝对路径、目标缺失立即空结果(不烧遍历预算,exclude 不作用于显式路径意图)。`dirs` 让目录命中行导航文件树而不是当文件打开;调试插桩 `DSH_SEARCH_DEBUG=1` 写 `$DSH_HOME/search-debug.log`,缺省 `~/.dsh`。host 的 `listDirectory` 给目录行标记 `compact`(仅一个非 symlink 有效子项;POSIX 隐藏与 `explorerExclude` 排除条目不计入),client 的 `file-tree-compact.ts` 把单目录链折叠成 `a/b/c` 面包屑行并整链展开/折叠;`explorerExclude`(VS Code `files.exclude` 风格 glob 子集,见 `exclude-patterns.ts`;editor 卡片的声明式 patterns 行可编辑)把匹配条目从树与搜索中彻底移除,两个界面共用同一 host 侧编译好的 matcher;host 侧目录缓存按「路径 + 行额 + 模式集身份」分键,改排除列表即换键。测试:`tests/fs-tree-compact.spec.ts` / `file-tree-compact.spec.ts` / `fs-tree-exclude.spec.ts` / `exclude-patterns.spec.ts` / `fs-search.spec.ts` / `search-engines.spec.ts`
- **`src/client/markdown-html.ts`** / **`MarkdownHtml.tsx`** / **`md-toc.tsx`**:markdown 内嵌 HTML 管线与目录大纲(注意 `md-toc.tsx` 头注释的「子组件读父 ref 为 null」时序陷阱)
- **`src/agent-opens.ts`** / **`/sidebar/ws/agent-opens`**:模型主动打开(`sidebar_open` 工具 + `agentOpenTools` 设置,默认关闭);文件夹窗口 = `meta.dir: true` 的 editor tab([设计文档](plans/2026-08-23-agent-open-tools-design.md))
- **`tests/service.spec.ts`** / **`tests/builtins.spec.ts`**:注册表生命周期 / 匹配算法 / dedupe / createTab / 启用态 gating;内置清单断言(6 tab + 3 viewer + 声明式元数据,并显式断言 image / pdf / binary-download **不在**内置清单里、但作为公开契约仍可被第三方注册)