dsh-locator 0.0.0-stage → 0.1.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 — 2026-11-09
4
+
5
+ First working release.
6
+
7
+ * Go engine (`indexd`) with a persistent file index, parallel query matching and top-K selection.
8
+ * Serve-during-scan: a cold start answers searches from the partially built index (`indexing: true`) instead of blocking until the scan finishes; incomplete snapshots are marked and rescanned on the next start.
9
+ * Parallel scanner (bounded queue, per-directory batches, inline fallback) with exclude globs, progress and cancellation; snapshot save/load; tombstone compaction. Warm scan of 1.23 M entries dropped from 11.8 s to 6.5 s on the test machine.
10
+ * Linux inotify watcher (recursive) and Windows `ReadDirectoryChangesW` watcher (recursive, no admin).
11
+ * macOS gets a kqueue vnode watcher (directory-level creates/deletes/renames, capped at 4,096 watched directories) plus the periodic rebuild fallback; FSEvents is next.
12
+ * USN change feed: after MFT enumeration the engine polls the journal every two seconds and applies creates, deletes and renames through a tested pure applier (`usn.ApplyChanges`), updating the FRN path map in place.
13
+ * USN decoder and opt-in fast path (`internal/usn`): USN_RECORD_V2 parsing, FRN parent-map path reconstruction, journal read, `windowsUsn` / `--usn` MFT enumeration with automatic portable-walk fallback, page-level metadata fill for names-only records, and an `indexd usn-probe` elevated acceptance command. Off by default until the elevated probe is validated.
14
+ * Everything-style query language: bare terms, `!` negation, quotes, `*`/`?`, `ext:`, `path:`, `size:`, `dm:`, `folder:`, `file:`, `case:`, `wholeword:`.
15
+ * DSH plugin with `locator_search`, `locator_status`, `locator_rebuild`, a path-search result card and configurable roots/excludes/state.
16
+ * Global Web GUI search panel (`Ctrl+Shift+F`, sidebar magnifier): debounced live search, sortable columns, kind filters, keyboard selection, path copy, status footer. Served through same-origin host routes with the Web connection's own trust check; headless profiles simply omit it.
17
+ * Prebuilt engines for linux-x64, linux-arm64, win32-x64, win32-arm64, darwin-x64 and darwin-arm64.
18
+ * Go unit tests, plugin integration tests and a package verification script.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 PerryLink contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README-zh.md ADDED
@@ -0,0 +1,212 @@
1
+ # dsh-locator
2
+
3
+ 中文 | [English](README.md)
4
+
5
+ 给 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 用的全盘毫秒级文件搜索,**自建索引**:不装 Everything、不用 `es.exe`、不需要 Everything 服务。
6
+
7
+ `dsh-locator` 扫描你指定的目录,把文件名、路径、大小、修改时间写进一个紧凑的快照;之后按文件系统事件增量更新,百万条目上的名字/路径查询在几十毫秒内返回。模型拿到 `locator_search`、`locator_status`、`locator_rebuild` 三个工具;人则有一个 Web GUI 全局**搜索面板**(`Ctrl+Shift+F`,或侧栏底部的放大镜),支持列排序、过滤、键盘操作和一键复制路径。
8
+
9
+ 思路借鉴 Everything:常驻的文件名索引、带 `ext:` / `size:` / `dm:` 过滤的查询语法、直接消费文件系统的变更流。实现是独立的,并且跨平台。
10
+
11
+ ## 为什么再做一个
12
+
13
+ `glob` / `grep` 每次调用都要遍历工作区——知道目录时很快,只记得名字的一部分时很慢。Everything 在 Windows 上很好用,但它只支持 Windows;包一层 Everything 仍然覆盖不了 macOS、Linux、WSL 和远程主机。`dsh-locator` 自己拥有索引,所以同一套工具在哪都能用。
14
+
15
+ ## 安装
16
+
17
+ ```sh
18
+ # npm(发布后)
19
+ dsh plugin --profile web add dsh-locator
20
+
21
+ # 从源码
22
+ pnpm install
23
+ pnpm build # TypeScript 插件
24
+ pnpm build:engine # 本机平台的 Go 引擎
25
+ dsh plugin --profile web add /绝对路径/dsh-locator
26
+
27
+ # 从打包 tarball(已实测的安装路径)
28
+ npm pack
29
+ dsh plugin --profile web add /绝对路径/dsh-locator-0.1.0.tgz
30
+ ```
31
+
32
+ npm 包内置 `linux-x64`、`linux-arm64`、`win32-x64`、`win32-arm64`、`darwin-x64`、`darwin-arm64` 六个平台的预编译引擎。
33
+
34
+ 装进**已经在运行**的 Web profile 后,请**刷新页面**(`F5`):宿主工具可能立即热挂载,但浏览器面板(`client.js`)是在页面加载时从 boot graph 取的。headless/TUI profile 不会挂面板。
35
+
36
+ ## 首次运行
37
+
38
+ 首次挂载时引擎扫描配置的根目录(默认:用户主目录),快照写到平台缓存目录:
39
+
40
+ | 平台 | 默认状态目录 |
41
+ |---|---|
42
+ | Windows | `%LOCALAPPDATA%\dsh-locator` |
43
+ | macOS | `~/Library/Application Support/dsh-locator` |
44
+ | Linux | `$XDG_CACHE_HOME/dsh-locator` 或 `~/.cache/dsh-locator` |
45
+
46
+ 大目录首次扫描会读盘;之后启动直接加载快照。首次扫描**期间也照常响应**:搜索返回已索引的部分并带 `indexing: true`,面板底栏提示索引构建中,不会被冷扫描卡住。默认排除 `node_modules`、`.git`、`.svn`、`.hg`、`.cache`、`__pycache__`、`.venv`、`venv`、`.next`。
47
+
48
+ ## Web 搜索面板
49
+
50
+ 在 Web GUI 里按 `Ctrl+Shift+F`,或点侧栏底部的放大镜。浮层通过两个同源宿主路由(`POST /dsh-locator/search`、`POST /dsh-locator/status`)查询同一个索引,不另起服务、不加端口。
51
+
52
+ * 空查询按修改时间倒序列出最近条目;输入后 110 ms 防抖,走和工具完全相同的 Everything 风格语法。
53
+ * 点列头按名称、大小、修改时间、路径排序,再点切换升降序。
54
+ * `只看文件` / `只看目录` 过滤类型;底栏显示命中数、分页上限和查询耗时。
55
+ * `↑`/`↓` 选择,`Enter` 复制选中路径,`Esc` 关闭。
56
+ * 面板是可选的:没有 Web server 的 profile 不会挂载它,三个工具照常工作。
57
+
58
+ ## 工具
59
+
60
+ | 工具 | 作用 |
61
+ |---|---|
62
+ | `locator_search` | 查询索引,返回路径、大小、修改时间、扩展名、类型,并给出 total/truncated,截断页面不会被当成完整结果。 |
63
+ | `locator_status` | 根目录、条目数、监听状态、状态目录与引擎路径。用来解释覆盖范围或排查结果过期。 |
64
+ | `locator_rebuild` | 后台重建索引;新索引就绪前,搜索继续用旧索引。 |
65
+
66
+ ### 查询语法
67
+
68
+ 裸词是文件名子串,多个词取 AND;可叠加 Everything 风格过滤:
69
+
70
+ | 例子 | 含义 |
71
+ |---|---|
72
+ | `report` | 文件名含 `report` |
73
+ | `report ext:pdf` | 且扩展名是 `pdf` |
74
+ | `ext:ts,js` / `ext:!tmp` | 包含/排除扩展名 |
75
+ | `*.sln` / `?ata` | `*`、`?` 通配 |
76
+ | `"annual report"` | 带空格的短语 |
77
+ | `!archive` | 取反 |
78
+ | `path:src` | 完整路径含 `src` |
79
+ | `size:>10mb` / `size:1kb..2mb` | 大小比较 |
80
+ | `dm:today` / `dm:thisweek` / `dm:2026-01-01` | 修改时间 |
81
+ | `folder:` / `file:` | 只看目录 / 只看文件 |
82
+ | `case:1` / `wholeword:1` | 区分大小写 / 全词匹配 |
83
+
84
+ `locator_search` 还接受 `sort`(`name`、`path`、`size`、`mtime`、`ext`)、`desc`、`offset`、`limit`、`regex`、`caseSensitive`、`wholeWord`。
85
+
86
+ ## 配置
87
+
88
+ 所有字段都是 Schemastery 配置;改 profile patch 里的 `dsh-locator` 条目,或改包内 `cordis.patch.yml` 的默认值。
89
+
90
+ | 键 | 默认 | 含义 |
91
+ |---|---|---|
92
+ | `enabled` | `true` | 关掉后不挂工具、不起引擎。 |
93
+ | `roots` | `[]` | 要索引的目录;空 = 用户主目录。 |
94
+ | `excludes` | 开发/缓存目录 | 扫描与监听都跳过的基础名 glob。 |
95
+ | `watch` | `true` | 启用原生文件系统通知。 |
96
+ | `refreshIntervalMs` | `1800000` | 没有原生监听时(目前是 macOS)的重建周期;0 关闭。 |
97
+ | `scanWorkers` | `0` | 扫描时的目录读取并发;0 = CPU 数。 |
98
+ | `windowsUsn` | `false` | 扫描时先试 NTFS USN/MFT 枚举(Windows,需管理员;失败自动回退)。 |
99
+ | `stateDir` | `''` | 快照目录;空 = 平台缓存目录。 |
100
+ | `binaryPath` | `''` | 覆盖内置引擎路径(开发用)。 |
101
+ | `maxResults` | `100` | 单页硬上限。 |
102
+ | `startupTimeoutMs` | `120000` | 冷启动建索引的容忍时间。 |
103
+ | `requestTimeoutMs` | `15000` | 单次请求超时。 |
104
+
105
+ 主目录太大就收窄 `roots`:`~/Documents`、`~/Downloads` 加一两棵代码树,通常比全盘更划算。
106
+
107
+ ## 平台支持
108
+
109
+ | 平台 | 扫描 + 快照 | 实时更新 | 说明 |
110
+ |---|---|---|---|
111
+ | Linux | 是 | inotify,递归 | 每个目录一个 watch;极大目录树可能撞 `fs.inotify.max_user_watches`。 |
112
+ | Windows | 是 | `ReadDirectoryChangesW`,递归 | 不需要管理员,不需要 Everything。提权时可选用 USN/MFT 枚举。WSL 写 `/mnt/<盘>` 可能不产生 Windows 通知,用 `locator_rebuild` 补。 |
113
+ | macOS | 是 | kqueue vnode 监听(最多 4,096 个目录)+ 周期性重建 | 目录级事件覆盖新建、删除、重命名;文件内容变化不产生 vnode 事件,大小/时间由 `refreshIntervalMs` 或 `locator_rebuild` 刷新。 |
114
+
115
+ 引擎是纯 Go、无 cgo,一台机器交叉编译全部平台;运行时从不需要管理员权限。
116
+
117
+ ### Windows 与 USN 日志
118
+
119
+ 引擎里已经有 USN 解码器、可选的快路径和探针。快路径**默认关闭**(`windowsUsn: false`):卷 ioctl 需要管理员权限,而当前开发机没有提权,探针就是验收步骤:
120
+
121
+ ```powershell
122
+ # 管理员 PowerShell(或:Start-Process -Verb RunAs <路径> ...)
123
+ & ".\bin\win32-x64\indexd.exe" usn-probe --volume C: --root "C:\Windows" --limit 5 --journal 5
124
+ ```
125
+
126
+ 它会打印日志 id/USN、枚举 MFT(每秒记录数、根目录下文件/目录数、样例路径),并解码最近几条变更日志。非管理员运行会明确报 `Access is denied`;解析与路径重建在 Linux 上有单元测试覆盖。
127
+
128
+ 打开 `windowsUsn: true`(或 `indexd scan --usn`)后,引擎用 MFT 枚举代替目录遍历,再按 FRN 父表重建路径。引擎保留卷句柄,每 2 秒轮询变更日志,按同一张 FRN 表就地应用新建、删除、重命名(`usn.ApplyChanges`)。USN 记录**没有大小和修改时间**:名字/路径是准的,`locator_status` 会把这种索引标成 `USN`,守护进程会对返回页现场 stat,所以面板/模型看到的行仍有真实大小和日期;但全库的 `size:`/`dm:` 过滤在元数据补齐前是近似的。任何失败(没提权、卷不支持、记录过多)都会带警告回退到目录遍历,绝不会让搜索不可用。运行中日志轮询失败会报警并停止该监视器,可移植的 `ReadDirectoryChangesW` 监听和 `locator_rebuild` 仍然可用。变更应用逻辑有合成记录测试,但 ioctl 本身仍待提权探针验收。
129
+
130
+ Everything 之所以首次索引近乎瞬时,是因为它通过 USN 日志直接读 NTFS 主文件表。`dsh-locator` v0.1 刻意先做可移植的目录遍历 + 变更通知:不需要服务、不需要 UAC、任何文件系统都能用。USN/MFT 枚举会作为可选快路径加入路线图(需要进程对卷持有 `GENERIC_READ`,通常意味着管理员权限),可移植路径始终保留为回退。
131
+
132
+ ## 性能
133
+
134
+ 开发者 WSL2 机器、Linux 主目录实测(1,234,757 条目:1,128,288 文件、106,469 目录,排除 `node_modules`、`.git`、`.cache`、`.venv`):
135
+
136
+ | 指标 | 结果 |
137
+ |---|---|
138
+ | 冷扫描(未命中页缓存) | 50.3 s |
139
+ | 热扫描(页缓存命中,8 个读取协程) | 4.6–6.5 s(约 190–265k 条目/秒) |
140
+ | 快照大小 | 133 MB |
141
+ | 扫描峰值 RSS | 约 490 MB |
142
+ | 首次扫描进行中的第一次搜索 | 2 ms(部分结果,`indexing: true`) |
143
+ | `locator_search "report"`(981 命中) | 34 ms |
144
+ | `locator_search "package.json"`(1,287 命中) | 25 ms |
145
+ | 查询进程 RSS(120 万条目) | 约 197 MB |
146
+ | 小目录树(3.9 万条目)扫描 | 0.47 s |
147
+
148
+ 查询阶段按记录分片并行;冷扫描慢在磁盘。数字随文件系统、缓存和 CPU 变化。
149
+
150
+ ## 设计
151
+
152
+ ```
153
+ DeepSeek Harness
154
+ └─ dsh-locator(TypeScript 插件)
155
+ ├─ locator_search / locator_status / locator_rebuild
156
+ ├─ client.js:Ctrl+Shift+F 浮层(shell.overlay slot)
157
+ ├─ POST /dsh-locator/{search,status}(同源、仅回环宿主)
158
+ └─ 子进程:indexd serve(Go,stdio 上的 NDJSON)
159
+ ├─ 扫描器:递归遍历、排除、进度
160
+ ├─ 索引:名字 arena + 定长记录 + 开放寻址路径表
161
+ ├─ 查询:解析、匹配、Top-K 选择、排序、分页
162
+ ├─ 监听:inotify(Linux)/ ReadDirectoryChangesW(Windows)
163
+ └─ 快照:单文件、原子重命名
164
+ ```
165
+
166
+ * **并行扫描**:目录读取协程消费一个有界任务队列,每个目录批量调用 `AddBatch` 落库,保证父记录先于子记录;队列满时改为在当前协程内联扫描,永不阻塞。
167
+ * **内存布局**:记录只存名字在 arena 中的偏移/长度和父记录 id,完整路径只在结果页和 `path:` 过滤时重建,避免每个文件一个字符串头。
168
+ * **路径表**:开放寻址、槽位存 `id+1`,每条约 12 字节,而 `map[string]int32` 约 50 字节。
169
+ * **查询引擎**:裸词与过滤只编译一次,分片并行匹配,再用有界大顶堆选出 `offset+limit` 行,不排序上百万命中。
170
+ * **持久化**:先写临时文件再重命名;generation 计数让守护进程只在索引变化时自动保存;墓碑超过阈值后压缩。
171
+ * **协议**:stdio 上一行一个 JSON 请求/响应,另有 `scan`、`stats`、`warning`、`error`、`rebuilt` 事件。不开端口、无网络监听面。
172
+ * **只读**:引擎只读元数据,绝不修改被索引的文件。
173
+
174
+ ## 从源码构建
175
+
176
+ 需要 Node `^22.19 || >=24.9`、pnpm、Go 1.22+。
177
+
178
+ ```sh
179
+ pnpm install
180
+ pnpm typecheck
181
+ pnpm test
182
+ pnpm build
183
+ pnpm build:engine:all # 或 build:engine 只构建本机
184
+ ```
185
+
186
+ 引擎是 `engine/` 下的独立 Go module;`cd engine && go test ./...`。
187
+
188
+ ## v0.1 的限制
189
+
190
+ * 只索引文件名、路径、大小、修改时间,**不索引内容**;内容检索请用 `grep`。
191
+ * 只覆盖配置的根目录,不是文件系统驱动。
192
+ * Linux inotify 每个目录一个描述符;几十万目录的主目录可能超过内核上限。插件会报警告,快照仍可用,重建可以补齐。
193
+ * WSL 写 `/mnt/c` 可能不产生 Windows 侧通知(Windows 监听看不到 9p 写入方的变更流),需显式重建。
194
+ * 网络共享只有在能当普通目录访问时才会被扫描;没有 SMB 专用变更源。
195
+ * macOS 是目录级监听(kqueue,每目录一个描述符,上限 4,096):新建/删除/重命名即时生效;文件内容变化靠周期重建。无上限、文件级的 FSEvents 仍在路线图。
196
+ * 还没有 USN/MFT 快速枚举(见上)。
197
+
198
+ ## 路线图
199
+
200
+ 1. macOS FSEvents 监听。
201
+ 2. 有卷读取权限时的 Windows USN/MFT 快速枚举;停机后按 USN 日志补齐。
202
+ 3. 专用 Web GUI 面板(表格、列排序、过滤、预览、插入为 `@file`)。
203
+ 4. 可选的小写名字 arena 与 trigram 预筛。
204
+ 5. 增量快照压缩与按根目录的日志。
205
+
206
+ ## 安全与隐私
207
+
208
+ 索引完全本地:不联网、不埋点、不上传。快照里是文件名和路径,请把状态目录当私有数据;介意的话别把它纳入备份。插件绝不修改、移动或删除被索引的文件。
209
+
210
+ ## 许可证
211
+
212
+ Apache-2.0。
package/README.md CHANGED
@@ -1,3 +1,212 @@
1
- # Temporary Holding Version
1
+ # dsh-locator
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [中文](README-zh.md) | English
4
+
5
+ A whole-disk, millisecond file search for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) that builds its **own** index. No Everything installation, no `es.exe`, no Everything service.
6
+
7
+ `dsh-locator` scans the directories you choose once, keeps the result in a compact snapshot, applies filesystem changes as they happen, and answers name/path queries in tens of milliseconds across a million entries. The agent gets `locator_search`, `locator_status` and `locator_rebuild`; people get a global **search panel** in the Web GUI (`Ctrl+Shift+F` or the magnifier at the sidebar foot) with sortable columns, filters, keyboard navigation and one-key path copy.
8
+
9
+ Everything inspired the *ideas*: a persistent index of file names, a query language with `ext:` / `size:` / `dm:` filters, and an updater that consumes the filesystem's own change stream. The implementation is independent and cross-platform.
10
+
11
+ ## Why another file search
12
+
13
+ `glob` and `grep` walk the workspace on every call — fine when you know the directory, slow when you remember only part of a name. Everything is excellent on Windows but is Windows-only, and wrapping it leaves macOS, Linux, WSL and remote hosts uncovered. `dsh-locator` owns the index, so the same tools work everywhere Node and Go run.
14
+
15
+ ## Install
16
+
17
+ ```sh
18
+ # from npm (once published)
19
+ dsh plugin --profile web add dsh-locator
20
+
21
+ # from a checkout
22
+ pnpm install
23
+ pnpm build # TypeScript plugin
24
+ pnpm build:engine # Go engine for the host platform
25
+ dsh plugin --profile web add /absolute/path/to/dsh-locator
26
+
27
+ # from a packed tarball (verified install path)
28
+ npm pack
29
+ dsh plugin --profile web add /absolute/path/to/dsh-locator-0.1.0.tgz
30
+ ```
31
+
32
+ The npm package ships prebuilt engines for `linux-x64`, `linux-arm64`, `win32-x64`, `win32-arm64`, `darwin-x64` and `darwin-arm64`.
33
+
34
+ After installing into a Web profile that is already running, **reload the page** (`F5`): the host tools may mount immediately, but the browser panel (`client.js`) is loaded from the boot graph at page load. Headless/TUI profiles never mount the panel.
35
+
36
+ ## First run
37
+
38
+ On first mount the engine indexes the configured roots (default: your home directory) and writes a snapshot to the platform cache directory:
39
+
40
+ | Platform | Default state directory |
41
+ |---|---|
42
+ | Windows | `%LOCALAPPDATA%\dsh-locator` |
43
+ | macOS | `~/Library/Application Support/dsh-locator` |
44
+ | Linux | `$XDG_CACHE_HOME/dsh-locator` or `~/.cache/dsh-locator` |
45
+
46
+ The first scan of a large home directory reads the disk; later starts load the snapshot instead. Requests are served **during** that first scan: search returns the entries indexed so far with `indexing: true`, and the panel footer says the index is still building. Nothing blocks on the cold scan. A default exclude list skips `node_modules`, `.git`, `.svn`, `.hg`, `.cache`, `__pycache__`, `.venv`, `venv` and `.next`.
47
+
48
+ ## Web search panel
49
+
50
+ Press `Ctrl+Shift+F` anywhere in the Web GUI, or click the magnifier at the sidebar foot. The overlay queries the same index through two same-origin host routes (`POST /dsh-locator/search`, `POST /dsh-locator/status`), so it needs no second server and no extra port.
51
+
52
+ * Empty query lists the most recently modified entries; typing runs the same Everything-style syntax as the tool after a 110 ms debounce.
53
+ * Click a column header to sort by name, size, modification time or path; toggle ascending/descending.
54
+ * `只看文件` / `只看目录` filter the kind; the footer reports matches, the page cap and query latency.
55
+ * `↑`/`↓` select, `Enter` copies the selected path, `Esc` closes.
56
+ * The panel is optional: profiles without a Web server never mount it, and the three tools keep working.
57
+
58
+ ## Tools
59
+
60
+ | Tool | What it does |
61
+ |---|---|
62
+ | `locator_search` | Query the index. Returns path, size, modification time, extension and kind, plus total/truncated so a capped page is never presented as complete. |
63
+ | `locator_status` | Roots, entry counts, watcher state, state directory and engine path. Use it to explain coverage or diagnose a stale result. |
64
+ | `locator_rebuild` | Replace the index with a fresh background scan. Searches keep using the old index until the new one is ready. |
65
+
66
+ ### Query language
67
+
68
+ Bare words are ANDed substrings of the file name. Everything-style filters combine with them:
69
+
70
+ | Example | Meaning |
71
+ |---|---|
72
+ | `report` | name contains `report` |
73
+ | `report ext:pdf` | …and the extension is `pdf` |
74
+ | `ext:ts,js` / `ext:!tmp` | include or exclude extensions |
75
+ | `*.sln` / `?ata` | `*` and `?` wildcards |
76
+ | `"annual report"` | phrase with a space |
77
+ | `!archive` | negate a term |
78
+ | `path:src` | the full path contains `src` |
79
+ | `size:>10mb` / `size:1kb..2mb` | size comparisons |
80
+ | `dm:today` / `dm:thisweek` / `dm:2026-01-01` | modification time |
81
+ | `folder:` / `file:` | directories or files only |
82
+ | `case:1` / `wholeword:1` | case-sensitive / word boundaries |
83
+
84
+ `locator_search` also takes `sort` (`name`, `path`, `size`, `mtime`, `ext`), `desc`, `offset`, `limit`, `regex`, `caseSensitive` and `wholeWord` parameters.
85
+
86
+ ## Configuration
87
+
88
+ Every field is a Schemastery config field; edit the `dsh-locator` entry in the profile patch (or the bundled `cordis.patch.yml` defaults).
89
+
90
+ | Key | Default | Meaning |
91
+ |---|---|---|
92
+ | `enabled` | `true` | Mount no tools and start no engine when `false`. |
93
+ | `roots` | `[]` | Directories to index; empty means the home directory. |
94
+ | `excludes` | dev/cache directories | Base-name globs skipped by scanner and watcher. |
95
+ | `watch` | `true` | Apply native filesystem notifications. |
96
+ | `refreshIntervalMs` | `1800000` | Rebuild cadence when no native watcher exists (macOS today); `0` disables. |
97
+ | `scanWorkers` | `0` | Directory reader concurrency during scans; `0` uses the CPU count. |
98
+ | `windowsUsn` | `false` | Try the NTFS USN/MFT enumeration before the walk (Windows, administrator; falls back automatically). |
99
+ | `stateDir` | `''` | Snapshot directory; empty means the platform cache directory. |
100
+ | `binaryPath` | `''` | Override the bundled engine (development). |
101
+ | `maxResults` | `100` | Hard cap for one search page. |
102
+ | `startupTimeoutMs` | `120000` | How long a cold build may take before the plugin reports failure. |
103
+ | `requestTimeoutMs` | `15000` | Per-request deadline. |
104
+
105
+ Narrow `roots` if indexing the whole home directory is too much I/O. A small, focused set (`~/Documents`, `~/Downloads`, one code tree) is usually the best trade-off.
106
+
107
+ ## Platform support
108
+
109
+ | Platform | Scan + snapshot | Live updates | Notes |
110
+ |---|---|---|---|
111
+ | Linux | yes | inotify, recursive | Watch descriptors are per directory; very large trees can hit `fs.inotify.max_user_watches`. |
112
+ | Windows | yes | `ReadDirectoryChangesW`, recursive | No admin rights and no Everything needed. Optional USN/MFT enumeration when running elevated. Changes made by WSL to `/mnt/<drive>` may not raise notifications; use `locator_rebuild` for those. |
113
+ | macOS | yes | kqueue vnode watches for up to 4,096 directories, plus periodic rebuild | Directory-level events cover creates, deletes and renames. File content changes do not raise vnode events, so size/mtime refresh comes from `refreshIntervalMs` or `locator_rebuild`. |
114
+
115
+ The engine is pure Go with no cgo, cross-compiled from one machine. It never needs admin privileges.
116
+
117
+ ### Windows and the USN journal
118
+
119
+ The engine carries a USN decoder, an opt-in fast path and a probe. The path is **off by default** (`windowsUsn: false`) because the volume ioctl needs administrator rights and the development machine here has no elevation; the probe is the acceptance step:
120
+
121
+ ```powershell
122
+ # Elevated PowerShell (or: Start-Process -Verb RunAs <path> ...)
123
+ & ".\bin\win32-x64\indexd.exe" usn-probe --volume C: --root "C:\Windows" --limit 5 --journal 5
124
+ ```
125
+
126
+ It prints the journal id/USNs, enumerates the MFT (records per second, files/dirs below the root, sample paths) and decodes the last few change-journal records. A non-elevated run fails with `Access is denied` — the parser and path reconstruction are covered by unit tests on every platform.
127
+
128
+ With `windowsUsn: true` (or `indexd scan --usn`) the engine enumerates the MFT instead of walking directories, then builds paths from the FRN parent map. It keeps the volume handle and polls the change journal every two seconds, applying creates, deletes and renames through `usn.ApplyChanges` (the same FRN map, updated in place). USN records carry **no size or modification time**: results are correct for names and paths, `locator_status` marks such an index with `USN`, and the daemon stats the returned page so the rows the panel/model sees still show real sizes and dates. `size:`/`dm:` filters over the whole index stay approximate until a metadata pass runs. Any failure (no elevation, unsupported volume, too many records) falls back to the portable walk with a warning; it never disables search. If journal polling fails mid-session, the watcher reports it and stops; the portable `ReadDirectoryChangesW` watcher and `locator_rebuild` are still there. The journal applier is covered by synthetic-record tests, but the ioctl path itself still awaits the elevated probe.
129
+
130
+ Everything reads the NTFS Master File Table through the USN journal, which is why its first index is nearly instant. `dsh-locator` v0.1 deliberately starts with a portable directory walk plus change notifications: it works without a service, without UAC and on every filesystem. USN/MFT enumeration is on the roadmap as an opt-in fast path for volumes where the process holds `GENERIC_READ` (admin) — the portable path stays the fallback.
131
+
132
+ ## Performance
133
+
134
+ Measured on a developer WSL2 machine with a Linux home directory (1,234,757 entries: 1,128,288 files, 106,469 directories), excluding `node_modules`, `.git`, `.cache` and `.venv`:
135
+
136
+ | Metric | Result |
137
+ |---|---|
138
+ | Cold scan (uncached I/O) | 50.3 s |
139
+ | Warm scan (page cache, 8 readers) | 4.6–6.5 s (~190–265k entries/s) |
140
+ | Snapshot size | 133 MB |
141
+ | Peak scan RSS | ~490 MB |
142
+ | First search during the initial scan | 2 ms (partial, `indexing: true`) |
143
+ | `locator_search "report"` (981 matches) | 34 ms |
144
+ | `locator_search "package.json"` (1,287 matches) | 25 ms |
145
+ | Query process RSS (1.2 M entries) | ~197 MB |
146
+ | Small tree (39k entries) scan | 0.47 s |
147
+
148
+ Search is parallel over the record array; the slower cold scan is disk-bound. Numbers vary with the filesystem, cache state and CPU.
149
+
150
+ ## Design
151
+
152
+ ```
153
+ DeepSeek Harness
154
+ └─ dsh-locator (TypeScript plugin)
155
+ ├─ locator_search / locator_status / locator_rebuild
156
+ ├─ client.js: Ctrl+Shift+F overlay (shell.overlay slot)
157
+ ├─ POST /dsh-locator/{search,status} (same-origin, loopback-hosted)
158
+ └─ child process: indexd serve (Go, NDJSON over stdio)
159
+ ├─ scanner: recursive walk, excludes, progress
160
+ ├─ index: names arena + fixed records + open-addressing path table
161
+ ├─ query: parser, matcher, top-K selection, sort, pagination
162
+ ├─ watcher: inotify (Linux) / ReadDirectoryChangesW (Windows)
163
+ └─ snapshot: single file, mmap-friendly, atomic rename
164
+ ```
165
+
166
+ * **Parallel scanner.** Directory readers drain a bounded work queue and flush one batch per directory (`AddBatch`), so a parent record exists before its children are enqueued. The queue never blocks: a full queue falls back to scanning that subtree inline.
167
+ * **Memory layout.** Records store a name offset/length into one byte arena plus a parent id; full paths are reconstructed only for the result page and for `path:` filters. That avoids one string header per file.
168
+ * **Path table.** An open-addressing table of `id+1` slots keeps lookup/update near 12 bytes per entry instead of the ~50 bytes a `map[string]int32` costs.
169
+ * **Query engine.** Bare terms and filters are compiled once, matched in parallel chunks, then reduced with a bounded max-heap: the top `offset+limit` rows are selected without sorting a million matches.
170
+ * **Persistence.** The snapshot is written to a temporary file and renamed; a generation counter lets the daemon autosave only when the index changed. Tombstones are compacted when deletions exceed a threshold.
171
+ * **Protocol.** One JSON request/response per line on stdio, with unsolicited `scan`, `stats`, `warning`, `error` and `rebuilt` events. No ports, no auth surface, no network listeners.
172
+ * **Read-only.** The engine opens files for metadata only; it never writes to indexed paths.
173
+
174
+ ## Build from source
175
+
176
+ Requirements: Node `^22.19 || >=24.9`, pnpm, Go 1.22+ for the engine.
177
+
178
+ ```sh
179
+ pnpm install
180
+ pnpm typecheck
181
+ pnpm test
182
+ pnpm build
183
+ pnpm build:engine:all # or build:engine for the host target
184
+ ```
185
+
186
+ The engine is a separate Go module under `engine/`; run its tests with `cd engine && go test ./...`.
187
+
188
+ ## Limitations (v0.1)
189
+
190
+ * File names, paths, sizes and modification times only — **no content indexing**. Use `grep` for contents.
191
+ * The index covers configured roots; it is not a filesystem driver.
192
+ * Linux inotify watches one descriptor per directory; a home directory with hundreds of thousands of directories can exceed the kernel limit. The plugin reports the warning and the snapshot stays usable; rebuilds catch up.
193
+ * WSL writes into `/mnt/c` may not produce Windows notifications (the Windows watcher cannot see the 9p writer's change stream). Rebuild those roots explicitly.
194
+ * Network shares are scanned only if they are reachable as ordinary directories; no SMB-specific change feed.
195
+ * macOS watches are directory-level (kqueue, one descriptor per directory, capped at 4,096). Creates/deletes/renames land immediately; file content changes rely on the periodic rebuild. FSEvents remains the roadmap item for an uncapped, file-level feed.
196
+ * No USN/MFT fast enumeration yet (see above).
197
+
198
+ ## Roadmap
199
+
200
+ 1. macOS FSEvents watcher.
201
+ 2. Windows USN/MFT fast enumeration when the process can read the volume; journal-based catch-up after downtime.
202
+ 3. Dedicated Web GUI panel (table, sortable columns, filters, preview, insert-as-`@file`).
203
+ 4. Optional lowercase-name arena and trigram prefilter for large indexes.
204
+ 5. Incremental snapshot compaction and per-root journals.
205
+
206
+ ## Security and privacy
207
+
208
+ The index is local: no network calls, no telemetry, no uploads. The snapshot contains file names and paths, so treat the state directory as private data and exclude it from backups if that matters to you. The plugin never modifies, moves or deletes indexed files.
209
+
210
+ ## License
211
+
212
+ Apache-2.0.