@jayyuen66/dsh-zvec-grep 0.1.0 → 0.1.2
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 +62 -0
- package/README.md +72 -128
- package/README.zh-CN.md +164 -0
- package/THIRD_PARTY_NOTICES.md +37 -0
- package/client.js +35 -14
- package/cordis.patch.yml +2 -2
- package/host.js +1467 -267
- package/package.json +60 -38
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
4
|
+
|
|
5
|
+
## 0.1.2
|
|
6
|
+
|
|
7
|
+
宿主生态跟到 `0.2.1-alpha.2`,并把一处**跟着宿主变更而失效的安全判据**改回可用。这一版还补上了发布面与装载面的门禁,以及中英两份 README。
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **`servingNonLoopback` 不再比字面量**。`@deepseek-ai/dsh-host-webserver` 的 `Config.host` 从两值联合(`'127.0.0.1' | '0.0.0.0'`)变成「本机任一网卡的具体地址」,而通配绑定(`0.0.0.0`、`::` 及其映射形)现在**在加载期就被拒**。于是每条路由的第一道信任闸门里那句 `webServer.host === "0.0.0.0"` 恒为 `false`:非回环服务面换了形态,判据还在找那枚绑不上的字面量,结果把服务在真实网卡地址上这一面当成回环服务——同一网段一方拿着网卡权威,`Host` 那条腿就不再收紧。现在改取 shared 导出的 `isNonLoopbackBindHost(webServer.host)`(它是 0.1.4 为这件事专门加的出口,JSDoc 明写「不要再自己比字面量」),判据同时覆盖 IPv6 回环的多种拼法。用例按四档钉:未声明绑定、`127.0.0.1`、`0.0.0.0`、本机网卡具体 IPv4。
|
|
12
|
+
- **装载期缺包**。`@jayyuen66/dsh-plugin-shared@0.1.4` 的 `dist/text.js` 值导入 `@deepseek-ai/dsh-output-retention`,而本包只用它的 `truncateEnd` / `truncateStart`,从不直接引那枚宿主包——升级后 `test/host.test.ts` 立刻以 `Cannot find package` 倒下,而类型检查、构建与其余 282 条用例全部照绿。按本包对宿主包的一贯口径补上:非 optional `peerDependencies` + `devDependencies` 同枚精确版本,**不进 `dependencies`**。
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- `@deepseek-ai/dsh-*` 家族与 peer 的 `@deepseek-ai/dsh` 从 `0.2.1-alpha.1` 升到 `0.2.1-alpha.2`;`@deepseek-ai/cordis` `4.0.5-alpha.1`、`@deepseek-ai/schemastery` `3.18.5-alpha.1`、`@deepseek-ai/cordis-plugin-timer` `1.1.7-alpha.1` **不动**——那是 alpha.2 自己钉的那几枚,registry 上没有更新的 alpha。
|
|
17
|
+
- `pnpm-workspace.yaml` 整体换成与 `dsh-danger-guard` / `dsh-plugin-shared` 逐字节相同的那一份:`dsh-*` 86 枚 override 跟到 alpha.2,工具链跟到 registry 现行头(`@types/node` 26.6.3→26.6.5、`vitest` 与 `@vitest/coverage-v8` 5.0.2→5.0.3、`vite` 8.3.1→8.3.4、`rolldown` 1.2.11→1.2.13、`oxlint` 1.86.0→1.87.0、`oxfmt` 0.71.0→0.72.0、`oxlint-tsgolint` 7.0.2003→7.0.2004、`happy-dom` 20.14.5→20.14.6、`jsdom` 30.1.1→30.1.2)。`@jayyuen66/dsh-plugin-shared` `^0.1.3`→`^0.1.4`(实装的 0.1.2 比声明还旧,锁文件已过期)。
|
|
18
|
+
- `engines` 取严格口径:`dsh: >=0.2.1-alpha.2`(shared 0.1.4 自己的 `engines.dsh` 就是这个下限,声明得更宽等于撒谎)、`node: ^22.19.0 || >=24.0.0`(同取自 shared)。宿主按 **peer 声明**判兼容、不读 `engines.dsh`,且逐条比对每一枚 `@deepseek-ai/dsh*`——本包的精确钉因此意味着**高于 0.2.1-alpha.2 的宿主也需要 `dsh plugin allow-version … --accept-risk`**,两份 README 已按实测写明。
|
|
19
|
+
- README 拆成中英两份:`README.md` 为英文、`README.zh-CN.md` 为中文,两份顶部互链。原来是一份文件里的 `## 中文` / `## English` 两段,正文一字未改地按语言切开。
|
|
20
|
+
- 注释里「钉进依赖 `.d.ts` 的行号」全量换成文件 + 符号/原文锚点。抽查即见腐坏:`dsh-tools` 那组(`ToolDefinition` / `ToolGuard` / `ToolRuntime`)随 alpha.2 整体漂了 7–17 行,`tool.execute` 的调用点也是。测试夹具里的 `src/beta.ts:1-3` 那类是 **数据**(zg 的输出形态),不在射程内。
|
|
21
|
+
- `.github/workflows/publish.yml` 跟 `dsh-danger-guard` 同款加固:`concurrency` 防两次 dispatch 并行、action 钉 commit SHA、预检加「读本包」这一档(只查依赖就发现不了「版本号没进 main 就触发」)、发布用的 `NODE_AUTH_TOKEN` 走与预检同款清洗、加 `--provenance` 与 `--publish-wait-timeout 600000`,并且不再把凭据长度打进日志。
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- 新增 `.github/workflows/ci.yml`:`push` / `pull_request` 门禁跑 ubuntu×windows × node 22/24 的 `pnpm run check` 四格;另有一道**装载探针**——两个发布器各打一次包,进干净目录用 `npm install`(不带任何 flag)与 `npm pack` 的产物、`pnpm add` 与 `pnpm pack` 的产物各装一次,然后真 `import` 入口并断言它交出 cordis 插件形状(`apply` / `Config` / `inject`)、`cordis.patch.yml` 随包且在。上一轮那两起「全绿但装出去炸」的故障,判据只能落在这里。
|
|
26
|
+
- `test/publish-manifest.test.ts` 的门禁集合补齐:
|
|
27
|
+
- `ALWAYS_SHIPPED` 改成实测清单。旧集合把 `CHANGELOG.md` 也算成「npm 无条件附带」,于是门禁比 npm 的真实语义更宽松、自己先失效。实测办法:包根临时放一份 `CHANGELOG.md` 与一份 `THIRD_PARTY_NOTICES.md` 且不写进 `files`,`npm pack --dry-run` 只回 `package.json`、`README*`、`LICENSE`。
|
|
28
|
+
- 注释禁面加**本机绝对路径**(`/Users/…`、`/home/…`):注释里的举例路径会被打包器原样搬进随包发布的产物,那是把本机用户名发到公共 tarball 的路。
|
|
29
|
+
- 「包根的每一份 `.md` 都必须在发布面里」——一次性封住「新增文档忘了写进 `files` ⇒ 静默不随包分发」这一类,而不是每加一份补一条断言。
|
|
30
|
+
- 产物面内部指涉扫描(本机绝对路径、`node_modules/.pnpm/` 内容寻址布局)。注释门读不到产物,因为 rolldown 剥注释;而 `//#region` 标记里的路径恰恰会进产物。
|
|
31
|
+
- `shapeOf` 精确文件名条目的回归防线:把 `host.js` 误读成「收所有 `.js`」会让 `files` 覆盖那道断言的集合虚高,而它对失效毫无反应。
|
|
32
|
+
- 「shared 出货产物值导入的宿主包,本包一律在 peer ∪ dev 里提供」——判面取**产物**而非 shared 声明的 peer 全集(纯类型面的成员本包不引就不该钉)。
|
|
33
|
+
- `test/dist-size.test.ts`:产物体积预算闸(host 半 240,000 B、client 半 54,000 B,取实测值上浮约 25%)。体积不是行为,不会让任何现有用例变红,所以得单独有把尺子。刻意不开 minify:压缩后产物里的跨包说明符字符串会消失,而「依赖必须外部化」那几条断言正是靠检索这些字符串来判的。
|
|
34
|
+
- `test/readme-parity.test.ts`:中英两份 README 的骨架对等门(标题层级序列、首行包名、顶部互链三处)。一侧加了节而另一侧没跟,不会有任何用例变红。
|
|
35
|
+
- `build-client.mjs` 产出前把 `//#region` 标记里的 pnpm 内容寻址段折成普通的 `node_modules/` 一层。client 半必须把 shared 的 `record.js` / `errors.js` **内联**(浏览器解析不了裸说明符),于是标记里烙着依赖版本与本机 store 哈希:既外泄安装布局,又让同一份源码在不同机器上产出不同字节。
|
|
36
|
+
- `.gitattributes`(`* text=auto eol=lf`):Windows runner 上 Git for Windows 的机器级 `core.autocrlf=true` 会把工作树换成 CRLF,而 oxfmt 的 `endOfLine` 默认 lf —— 没有这份文件,新加的 windows 那一格会把每个文件都判成未格式化。
|
|
37
|
+
- `scripts.fmt`(`oxfmt .`),与既有的 `fmt:check` 配对。
|
|
38
|
+
- npm 发布元数据补齐 `keywords` / `bugs` / `homepage`(对照 plugin-shared 实测缺这三项)。`sideEffects: false` **不**照抄:client.js 是往 `window.__ModuleLoader__` 注册,属于真实副作用,标 false 等于授权打包器把它摇掉。新增「发布元数据面」两道门:description/keywords/license/author 齐备,以及 repository / bugs / homepage 三处按 `<账号>/<仓库>` 归一后必须同源——抄兄弟包的这一段再只改一处是必然会犯的错,那样 npm 页面上的「报告问题」会跳到别人的仓库。
|
|
39
|
+
- 上游归属信息(本包是在第三方 `@zvec/zvec-grep` 之上做二次开发):两份 README 的「外部依赖」一节写清上游包名、仓库、**Apache-2.0** 许可、`0.2.2` 版本契约,以及「本包不含上游代码、不替上游分发」这条边界;新增 `THIRD_PARTY_NOTICES.md` 并写进 `files`(实测 npm 不自动附带 NOTICE 类文件,漏写等于没随包分发);新增「开发」与「许可」两节,与 dsh-ocr-review 的双语 README 骨架对齐。
|
|
40
|
+
|
|
41
|
+
## 0.1.1
|
|
42
|
+
|
|
43
|
+
评审收口:索引重建、宿主版本门与远程 embedding 的边界。
|
|
44
|
+
|
|
45
|
+
### Added
|
|
46
|
+
|
|
47
|
+
- 后台重建作业走官方注册表(`ctx.jobs`):环、留存、容量与生命周期都在宿主侧,本包不再自带并发上限;模型侧 `job_list` / `job_output` / `job_kill` 因此看得见这次重建。
|
|
48
|
+
- 索引版本门(`lib/zg-version.ts`)与 zg 错误分类(`lib/zg-errors.ts`)、重建状态盒(`lib/rebuild-state.ts`)。
|
|
49
|
+
- 远程 embedding 的开关与端点/凭据来源边界,缺席即明确报错而不是静默降级。
|
|
50
|
+
|
|
51
|
+
## 0.1.0
|
|
52
|
+
|
|
53
|
+
`@jayyuen66` 作用域下的第一个发布版本。
|
|
54
|
+
|
|
55
|
+
### Changed
|
|
56
|
+
|
|
57
|
+
- 索引根判据改认 `manifest.json`,修掉「全局 home 被当成索引根」导致的门禁误判。
|
|
58
|
+
- 发布凭据改走 `NODE_AUTH_TOKEN`(`setup-node` 配了 `registry-url` 之后 npm 只读它自己生成的那份 `.npmrc`,`$HOME/.npmrc` 会被完全忽略)。
|
|
59
|
+
|
|
60
|
+
### Earlier
|
|
61
|
+
|
|
62
|
+
`0.1.0` 之前那段(`@jayyuen666` 作用域、`0.3.1`、作用域迁移那次误发的 `1.0.0`)压进了本仓的第一条提交记录,要旨逐条写在那条 message 里——早期那几枚提交号已随这次历史重写失效,别再按 SHA 去找。npm 上那几个已发布的版本号则永久留存,不随仓库历史回收。
|
package/README.md
CHANGED
|
@@ -1,117 +1,6 @@
|
|
|
1
1
|
# @jayyuen66/dsh-zvec-grep
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
|
|
5
|
-
## 中文
|
|
6
|
-
|
|
7
|
-
### 它做什么
|
|
8
|
-
|
|
9
|
-
- 给 dsh 会话接上工作区语义检索:注册 zg_search / zg_index / zg_status 三个模型工具,底层经宿主 shell 以 `--mode direct` 调 zg CLI(BM25 + 向量 + RRF 混合检索)。
|
|
10
|
-
- 注入一段 systemPrompt 硬规则(`zvec-grep-routing`,order 1550)+ 两道 tools.guard:zg_* 安全兜底与 search-first 门禁(已建索引的工作区里,grep/rg 前必须先有一次成功的 zg_search)。
|
|
11
|
-
- 附带 web 端设置卡:默认 embedding、limit、search-first 配额/时效,以及「工作区重建」按钮。
|
|
12
|
-
|
|
13
|
-
### 安装
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
- 包在公共 npm 上,安装不需要凭据;发布态产物只有 host.js、client.js、cordis.patch.yml(package.json 的 files)。
|
|
20
|
-
- 运行期值 import `@jayyuen66/dsh-plugin-shared`(lib/http、lib/locale)与 `@deepseek-ai/schemastery`(宿主 fork:0.1.7 的 `.volatile()` 解析只有它有实现,公共 schemastery 既没这个方法、解析出的也仍是普通值),两者都在 dependencies 里,装不上就是 ERR_MODULE_NOT_FOUND。
|
|
21
|
-
|
|
22
|
-
### 在 dsh 里启用
|
|
23
|
-
|
|
24
|
-
- add/remove 按包内 cordis.patch.yml 维护注册行 `- id: zvec-grep`(name 指向本包);该文件由 `package.json` 的 `dsh.bundle.patch` 指向。
|
|
25
|
-
- 宿主版本要求 `>=0.2.0-rc.2`:写在 `peerDependencies`(0.1.7-rc 起宿主装插件时校验它;alpha.1 还没有这道门)与 `engines.dsh`(同值、无人读)。
|
|
26
|
-
- `dsh.client.platform` 为 web 且 immediately,设置卡的 client 半随宿主下发;bundle 安装走 pnpm(>= 12.3.0)。
|
|
27
|
-
- apply 需要 settings/shell/tools/systemPrompt/timer 五个服务面:它们都在 `inject` 里,缺任一 cordis 就不激活本条目(宿主启动诊断点名 `pending (waiting for service: …)`);apply 里的守卫再兜一层,ctx 形状不对时抛 `required services … missing`。
|
|
28
|
-
- 三条 `/_dsh/zvec-grep/*` 端点挂在 `inject(["webServer"])` 的子 fiber 上:宿主没有 webServer(如 TUI)时子 fiber 不激活,端点不存在而工具照常。真实宿主上 webServer 比本条目晚到位约 1 秒,所以这里必须是依赖、不能只在 apply 里 `ctx.get` 读一次。
|
|
29
|
-
|
|
30
|
-
### 提供给模型的工具
|
|
31
|
-
|
|
32
|
-
- zg_search:query / queries / fts / vector 至少其一(合计 <= 32 组)。
|
|
33
|
-
- 可加 globs / insensitiveGlobs / fileTypes / excludedFileTypes / symbolTypes / preferSymbol / modifiedAfter / modifiedBefore / fuse / limit / device。
|
|
34
|
-
- 固定带 `--preview short --refresh wait`,每条命中自带有界源码片段。
|
|
35
|
-
- zg_index:confirm 必填且必须为 true(required 校验 + guard 双层拒绝)。
|
|
36
|
-
- 另有 embedding / rebuild / drop / ignoreFiles / excludeSecrets / hidden / noIgnore / maxDepth / maxFileSizeBytes / follow / embeddingConcurrency / device。
|
|
37
|
-
- 切换 embedding 必须 rebuild=true 才生效。
|
|
38
|
-
- zg_status:只有 root,用于索引缺失/失败/取消后的诊断或显式看进度。
|
|
39
|
-
- 三者的 root 都可省略(缺省=当前会话工作区);输出为纯文本;超时分别为 5 分钟 / 10 分钟 / 60 秒,stdout 上限 400000 字节(超限截尾并提示)。
|
|
40
|
-
|
|
41
|
-
### 设置项与检索根
|
|
42
|
-
|
|
43
|
-
- 命名空间 `zvec-grep` 由宿主**隐式**注册(0.1.7 起 = profile 条目 id,插件侧不再有 `settings.register`);schema 共十个字段,其中卡上那六枚标 `.volatile()`,内置默认逐字段写在 `.default()` 上。
|
|
44
|
-
- defaultEmbedding=local/qwen3-embedding-0.6b、defaultLimit=10(1-50)、hfEndpoint=国内可达的 HF 兼容镜像基址(可改成别的镜像或留空走官方 HF)。
|
|
45
|
-
- enforceSearchFirst=true、grepBudgetPerSearch=3(1-20)、unlockWindowMin=10(1-240)。
|
|
46
|
-
- 另有四个**非 volatile 部署值**(不进设置卡,只在 cordis.yml 的行 config 里改值;上面工具一节的「5 分钟 / 10 分钟 / 60 秒 / 400000 字节」就是它们的默认):searchTimeoutMs=300000、statusTimeoutMs=60000、indexTimeoutMs=600000(也是后台重建 kill 定时器的时长)、stdoutMaxBytes=400000,均最小 1。
|
|
47
|
-
- 优先级:设置里的运行时值 > 组合包层/用户层行的 config > schema 的 `.default()`;行 config 中显式缺省的字段不覆盖默认。读侧是 `config.<field>.get()`(volatile 引用,卡上改完下一个事件即生效);四个部署值是普通值形态,不经 `.get()`。
|
|
48
|
-
- root 校验:必须是以 `/` 开头的绝对路径,词典归一折叠空段与 `.`。
|
|
49
|
-
- 拒绝空串、非字符串、含 NUL、相对路径、越出文件系统根的 `..`,归一后为 `/` 也拒。
|
|
50
|
-
- 目录不存在时单报「root 目录不存在」,不冒成 spawn ENOENT。
|
|
51
|
-
- guard 与 execute 用同一套 root 判据,避免「guard 放行、execute 抛错」说两遍。
|
|
52
|
-
- 解锁按「会话 × 索引根」计:每次成功 zg_search 重置为 grepBudgetPerSearch 次、unlockWindowMin 分钟有效;索引根是 root 自身或含索引的最近祖先(最多上溯 8 层)。
|
|
53
|
-
- 「含索引」的判据是 `<root>/.zvec-grep/manifest.json` 在盘上,**只判 `.zvec-grep` 目录名不够**:这个名字同时是 zg 自己的全局 home(`ZVEC_GREP_HOME ?? ~/.zvec-grep`,装的是 config.json / locks / models),只判目录名会让一个从未建索引、只是祖先目录撞名的普通工作区也被门禁拦下。
|
|
54
|
-
- enforceSearchFirst=false 只关掉门禁,zg_* 的安全兜底(confirm、root 判据)不受影响。
|
|
55
|
-
|
|
56
|
-
### 外部依赖(rg)
|
|
57
|
-
|
|
58
|
-
- 真正的二进制依赖是 zg(由 `npm install -g @zvec/zvec-grep` 提供):不在 PATH 时 shell 回 exit 127,工具据此回「zg 未安装或不在 PATH」,与「沙箱 runner 没起来」分开归因。
|
|
59
|
-
- 本地 embedding 由 zg 侧后端加载:qwen3/embeddinggemma 走 llama-cpp(device=auto 时试 Metal、失败回退 CPU),potion-* 走 model2vec,其余走 transformers-js 纯 JS。
|
|
60
|
-
- 权重按 hfEndpoint 注入 HF_ENDPOINT 后下载。
|
|
61
|
-
- 本包不依赖也不调用 ripgrep:rg 只出现在门禁判据里。
|
|
62
|
-
- bash/pwsh 命令串经引号/注释感知切词后,命令位上的 grep/egrep/fgrep/rg 与原生 grep 工具才算检索。
|
|
63
|
-
- `--help`/`--version`/`-V`、`echo "grep x"`、`git commit -m "use rg"` 不算。
|
|
64
|
-
- 有沙箱执行器时会区分 runner 失败、策略拒绝与 zg 自身失败,并在结果里显式打「可能不完整」标记。
|
|
65
|
-
|
|
66
|
-
### 对外接口
|
|
67
|
-
|
|
68
|
-
- 三条路由的 handler 第一句都是 `guardTrust(req, res, { servingNonLoopback })`(`shared/lib/trust`),任一判据不过即 `403` + `{ ok:false, error: ... }`。
|
|
69
|
-
- 判据次序:Host 权威 → `sec-fetch-site` 白名单 → `origin` 与 Host 逐字比对;两句错误文本是 `"untrusted host authority"` 与 `"cross-origin request rejected"`。
|
|
70
|
-
- `servingNonLoopback` 只取 `webServer.host === "0.0.0.0"`;非本方法的 `405` 带 `Allow` 与 `{ ok:false, error:"GET only" | "POST only" }`,不再是空回显。
|
|
71
|
-
- `GET /_dsh/zvec-grep/rebuild-roots`:只回本包自己的数据(每次 apply 重新生成的 CSRF token + 已观测工作区列表),允许 GET/HEAD,过不了上面那道闸门即 403。
|
|
72
|
-
- `POST /_dsh/zvec-grep/rebuild?root=...`:闸门 + 头 `x-zvec-grep-csrf` + body <= 4096 字节 + root 命中白名单 + 目录存在,成功回 `{ ok, jobId }`;否则 405/403/400/500。
|
|
73
|
-
- `/_dsh/zvec-grep/rebuild-status?jobId=...`:闸门后轮询(卡片每 2 秒一次),回 status/exitCode/root/output(有沙箱时带 sandbox),未知 jobId 回 404 并说明多半是出了本包那条 10 条落定窗口。
|
|
74
|
-
- 另有 systemPrompt 段 `zvec-grep-routing`(order 1550)与 settings 命名空间 `zvec-grep`。
|
|
75
|
-
- 白名单只记本 daemon 真实观测到的会话工作区,容量 64(超出按插入序淘汰)。
|
|
76
|
-
- 同时能跑几个重建由**宿主注册表**决定(实测默认未拥有桶 10),本包不再自带并发上限;
|
|
77
|
-
满员时 `POST /rebuild` 直接回 500 并带上官方的点名文案,**不会**再杀掉已经在跑的重建。
|
|
78
|
-
- `rebuild-status` 的 `jobId` 只在本包侧表里查得到:本包保留最近 10 条**已结束**的记录
|
|
79
|
-
(超出即从注册表 remove ⇒ 404),进行中的记录永不被动。
|
|
80
|
-
|
|
81
|
-
### 后台作业面(官方 `ctx.jobs`)
|
|
82
|
-
|
|
83
|
-
本包不自带任务注册表了:一次「工作区重建」是宿主 `ctx.jobs` 里的一枚**未拥有**作业
|
|
84
|
-
(`kind: "zvec-grep-rebuild"` ⇒ id `zvec-grep-rebuild-N`)。这带来三件看得见的变化:
|
|
85
|
-
|
|
86
|
-
| 面 | 事实 |
|
|
87
|
-
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
88
|
-
| 模型侧能看见了 | 官方 `job_list` / `job_output` / `job_kill` 现在列得出这次重建,退出码与信号名走作业的 `detail`(口径与宿主的 bash 工具同形,实测 `plugins/docs/harness/f3-equiv/probe-jobs.mjs`)。输出走官方 **pull source**(`proc.observed[*].readFrom`)⇒ 环由注册表按它自己的节拍推进,**设置面板关着也照样前进**;官方那条观察者面与 `readOutput()` 互不偷字节(d.ts 原文 "without stealing bytes from `readOutput`")。controller 只在 `start` 那一瞬挂、摘掉即恢复官方拒绝(见跨包纪律) |
|
|
89
|
-
| 未拥有 ⇒ 对全部会话可见 | 官方件按 owner 隔离,未拥有作业任何 caller 都能 `list`/`read`/`kill`。这是本波**已知并接受**的暴露面(卡片是会话外的 webServer 生产者,受有作业则要 `dsh-agent` 注册表,实测不可得)。要收回去只有一条路:回滚这次换装。注意 `/_dsh/zvec-grep/rebuild-status` 仍只认本包侧表里的 id,别人的作业(如宿主的 `bash-1`)经这个端点读不到 |
|
|
90
|
-
| 多了两个状态词 | `stopping`(取消已发出、进程还没收完 ⇒ 卡片按「仍在跑」显示)与 `failed`(注册表侧判定失败 ⇒ 给专门文案,不显示成「退出码 null」) |
|
|
91
|
-
|
|
92
|
-
不留存的东西也写清楚:输出环按 **UTF-8 字节**留存(实测宿主默认 262144 字节),卡片的 4000 字符尾窗与 `shown/total` 按 **UTF-16 码元**计——两套单位各管各的。因此 `total` 说的是**留存窗内**的码元数(官方那个字节真值在 `view.output.total`,单位不同不混用),而中文输出下这只窗比换装前(按码元留 256 KiB)**小约 1/3**,这是采用官方件的代价。两条丢失标记各说一件事:`已截断` = 环按留存窗裁掉了头部(`view.output.earliest > 0`,看不见了);`缓冲区溢出` = 执行器的读者报 lossy 或干脆抛了(真少了字节,可能有 spill 文件)。超时说明与沙箱事实**不进环**:环的写权归注册表的泵,而它在落定之后丢弃一切写入(实测),所以这两条由端点在投影时合成,永远不会因为"写晚了"而消失。注册表被重载或记录被别人收走时轮询答 **404**(官方 `get`/`readAt` 对未知 id 抛错,而宿主对 handler 抛出的兜法是记一条日志再写一枚没有 body、没有 content-type 的 **400**,只有头已发时才断掉 socket —— installed dsh-host-webserver `lib/index.js:246-256` ⇒ 卡片会进终止态并停轮询,那条还在跑的重建就再也看不见)。
|
|
93
|
-
|
|
94
|
-
### 数据与隐私
|
|
95
|
-
|
|
96
|
-
- 索引的唯一落盘形状是被检索 root 下的 `.zvec-grep/` 目录,由 zg 写入(read-only 沙箱下写不了它,会明确报索引可能不完整)。
|
|
97
|
-
- 重建有两条路:模型侧 `zg_index`(rebuild=true、confirm=true),或设置卡「工作区重建」走上面的 rebuild 路由;删除是 `zg_index` drop=true(拼成 `zg index <root> --drop --yes`)。
|
|
98
|
-
- 本包自身不写任何文件(唯一的 fs 调用是 existsSync 探测),也不向宿主数据目录 `$DSH_HOME`(`<dsh 数据目录>`)落数据。
|
|
99
|
-
- 白名单/解锁表都在内存、有界;重建**作业本体**住在宿主注册表里(见上一节),插件卸载时本包侧表随 effect 回收、在跑的作业经注册表 kill 掉。
|
|
100
|
-
- 默认不进索引的:*.pem / *.key / *.p12 / _.pfx / *.keystore / id_rsa* / id_ed25519_(excludeSecrets=false 可关);隐藏文件默认不收,ignore 文件默认生效(noIgnore 可关)。
|
|
101
|
-
- 本包只在本机拼 zg 命令并透传输出,不上传代码。
|
|
102
|
-
- 唯一的外连是 embedding 权重按 hfEndpoint 下载。
|
|
103
|
-
- 结果回显有界:stdout 超限截尾(有 spill 路径会给出)、stderr 尾部 400 字符一并回显,免得「退化成纯词法」被当成完整语义结果。
|
|
104
|
-
|
|
105
|
-
### 常见问题
|
|
106
|
-
|
|
107
|
-
- grep/rg 被拒且提示「尚未执行过 zg_search」:这是 search-first 门禁,先 zg_search;配额用尽或过期同理,换个更准的 query/fts 重搜即可续上,不必关插件。
|
|
108
|
-
- 检索超时:默认 `--refresh wait` 会同步刷新既有索引,大工作区请用 globs/fileTypes 缩小范围或调小 limit,也可先手写字面检索。
|
|
109
|
-
- 重建按钮回 403「root 不在本 daemon 观测到的工作区白名单内」:该目录从未在本 daemon 开过会话;先在该目录起会话,或让模型带 confirm=true 调 zg_index。
|
|
110
|
-
- 卡片显示重建失败而 zg 看着像跑完了:成功判据是 completed 且 exit 0——exit 127(zg 没装)也落在 completed,看输出尾部原因。
|
|
111
|
-
- 从未建索引的 root:zg_search 明确报错而不是静默建索引;建索引只在用户明确要求时由 zg_index 做。
|
|
112
|
-
- 换了 embedding 却搜不到语义结果:切换 embedding 必须 rebuild=true 重建后才生效。
|
|
113
|
-
|
|
114
|
-
## English
|
|
3
|
+
[English](./README.md) · [简体中文](./README.zh-CN.md)
|
|
115
4
|
|
|
116
5
|
### What it does
|
|
117
6
|
|
|
@@ -126,13 +15,17 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
|
126
15
|
```
|
|
127
16
|
|
|
128
17
|
- The packages are on the public npm registry, so no credentials are needed; the published artifact only carries host.js, client.js and cordis.patch.yml (the files field in package.json).
|
|
129
|
-
- Runtime value imports are `@jayyuen66/dsh-plugin-shared` (lib/http, lib/locale) and `@deepseek-ai/schemastery` (the host's fork — the only one whose resolve wraps `.volatile()` fields into `Volatile` references)
|
|
18
|
+
- Runtime value imports are `@jayyuen66/dsh-plugin-shared` (lib/http, lib/locale, lib/text) and `@deepseek-ai/schemastery` (the host's fork — the only one whose resolve wraps `.volatile()` fields into `Volatile` references).
|
|
19
|
+
- shared's own `lib/text` value-imports `@deepseek-ai/dsh-output-retention`, so that host package has to be supplied too, on the same terms as `schemastery`: a required `peerDependency` plus the same exact pin in `devDependencies`, **never** in `dependencies`. Only a gate can hold this line - with the entry missing, typecheck, build and tests are all green and the failure shows up after installation as ERR_MODULE_NOT_FOUND.
|
|
130
20
|
- Missing either one is `ERR_MODULE_NOT_FOUND` at load, not a graceful downgrade — that is also why the fork cannot be swapped for public `schemastery`.
|
|
21
|
+
- Only the shared package sits in `dependencies`. `@deepseek-ai/schemastery` is a host package, so it is declared as a **required `peerDependency`** and repeated at the same exact pin in `devDependencies` for this repository's own typecheck/build/tests — never in `dependencies`. That is not a style preference: consumer profiles install with `nodeLinker: hoisted` and `autoInstallPeers: false`, so a host package listed under `dependencies` is written into the profile as a **real directory**, coexisting with the copy the host process already loaded. `@deepseek-ai/dsh-tools` keys its `TOOL_RUNTIME_SCHEDULER` with a plain `Symbol` (not `Symbol.for`), so symbol identity is per module instance: the host's `dsh-agent-loop` gets `undefined` and **every native tool call throws** `Cannot read properties of undefined (reading 'prepare')` — the whole profile loses its tools. Build, typecheck and tests all stay green right up to that point, which is why the invariant is pinned in `test/publish-manifest.test.ts`.
|
|
131
22
|
|
|
132
23
|
### Enabling it in dsh
|
|
133
24
|
|
|
134
25
|
- add/remove maintain the registration line `- id: zvec-grep` (name points at this package) from the in-package cordis.patch.yml, which `dsh.bundle.patch` in `package.json` points at.
|
|
135
|
-
-
|
|
26
|
+
- Host compatibility is judged on the **peer declarations**, not on `engines.dsh`: before composition the host compares `@deepseek-ai/dsh` and every `@deepseek-ai/dsh-*` range against the current runtime version, prereleases included (the rule is owned by the dsh-app-boot README). A mismatch denies that entry; a bundle without an exemption is skipped whole and listed under `skippedBundles`.
|
|
27
|
+
- This package pins every `dsh-*` **exactly** (a requirement of `test/publish-manifest.test.ts`, because "a second copy of the host type surface" is worse than a version conflict), so a host **newer than `0.2.1-alpha.2` also needs approval**. The escape hatch is the one the host prints: `dsh plugin --profile web allow-version @jayyuen66/dsh-zvec-grep@<version> --dsh-version <exact version> --accept-risk`.
|
|
28
|
+
- `engines.dsh` is a declaration that nothing reads; keeping it at `>= 0.2.1-alpha.2` only avoids leaving two contradictory numbers behind.
|
|
136
29
|
- `dsh.client.platform` is web with immediately set, so the card's client half is delivered by the host; bundle installation goes through pnpm (>= 12.3.0).
|
|
137
30
|
- apply needs the settings/shell/tools/systemPrompt/timer surfaces: all five sit in `inject`, so a missing one keeps cordis from activating the entry (the startup diagnostic prints `pending (waiting for service: …)`).
|
|
138
31
|
- The guard inside apply is the second layer: a malformed ctx throws `required services … missing`.
|
|
@@ -141,36 +34,68 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
|
141
34
|
|
|
142
35
|
### Tools exposed to the model
|
|
143
36
|
|
|
144
|
-
- zg_search: at least one of query / queries / fts / vector (32 routes max).
|
|
145
|
-
- Plus globs / insensitiveGlobs / fileTypes / excludedFileTypes / symbolTypes / preferSymbol / modifiedAfter / modifiedBefore / fuse / limit / device.
|
|
146
|
-
-
|
|
37
|
+
- zg_search: at least one of query / queries / fts / vector (32 routes max, 4000 chars per query).
|
|
38
|
+
- Plus globs / insensitiveGlobs / fileTypes / excludedFileTypes / symbolTypes / preferSymbol / modifiedAfter / modifiedBefore / fuse / limit / preview / refresh / device.
|
|
39
|
+
- `globs` / `insensitiveGlobs` / `fileTypes` / `excludedFileTypes` accept a **single string** as well as an array of strings, matching zg's own contract for those fields (128 items max, 1024 chars per item).
|
|
40
|
+
- `symbolTypes` is bound to zg's real closed set and accepts **lowercase only**: `module` / `class` / `interface` / `function` / `value` / `alias`. zg itself exits non-zero on `--symbol-type Class` (`Unsupported symbol type: Class`); the plugin refuses before assembling the command and lists the allowed values. It does not fold case — silently lowercasing would rewrite a constraint the model did not write.
|
|
41
|
+
- `preview` has three levels: `none` anchor line only / `short` anchor plus a bounded context window / `full` the whole chunk. **Default short**, so every hit carries a bounded source snippet.
|
|
42
|
+
- `refresh` has three levels: `wait` refresh to the latest before searching (**default**) / `off` do not refresh / `background` hand it to the daemon. `background` only holds in daemon mode: in direct mode zg does not fail, it degrades to `off` and writes `warning: --refresh background requires Server mode; Direct mode uses --refresh off` to stderr — this package echoes stderr verbatim, so that line reaches the model on its own.
|
|
43
|
+
- A **hit summary** is appended at the end of the output with two separately reported counts: `grouped` (the sum of each query group's `hits:`) and `N distinct location(s) after dedup` (keyed by relative path + line range). They are split because one location is hit by several groups at once (rank and `matchedBy` differ per group), so a plain sum counts the same location repeatedly and passes itself off as the hit total.
|
|
44
|
+
- When some group's hit count equals `--limit`, that is reported as an **observation only**, with an explicit note that zg provides no truncation signal and the summary does not assert one. When the host truncates stdout at its cap, a "covers only the kept part" note is added.
|
|
147
45
|
- zg_index: confirm is required and must be true (rejected twice, by the required check and by the guard).
|
|
148
|
-
-
|
|
46
|
+
- `background=true` runs a **model-side background index**: one call spawns the zg process, registers it in the host job registry, attaches the timeout reaper, hands back a pollable job id and **returns immediately**. Building an index may download embedding weights and take a long time, so background execution keeps the tool call from hanging.
|
|
47
|
+
- It does not depend on a host job tool: that tool is disabled in the web plane, so the model-side route is simply unavailable. The plugin reuses the **same** spawn/register/claim steps as the settings card (one shared function, not a copy), so jobs started from either side are identical in the registry, the status projection and the polling endpoint — the card sees model-started indexing and vice versa.
|
|
48
|
+
- The claim is mutually exclusive with the card's rebuild, across both entry points: while an index write is running for a root, the model side and the card side both follow that one instead of each starting a second zg against the same index.
|
|
49
|
+
- When the host job registry is absent it **does not spawn at all** and fails immediately: a zg with no ring, no capacity and nobody to reap it is worse than not starting — it would hold the root's write lock forever and block every later index operation on that tree.
|
|
50
|
+
- Until it settles, semantic search on that root waits for it and retries automatically, and grep/rg are not subject to the gate during that window.
|
|
51
|
+
- Also embedding / rebuild / drop / resetPaths / globs / insensitiveGlobs / fileTypes / excludedFileTypes / ignoreFiles / excludeSecrets / hidden / noIgnore / maxDepth / maxFileSizeBytes / follow / embeddingConcurrency / device; its five path filters likewise take a single value or an array.
|
|
149
52
|
- Switching embedding only takes effect with rebuild=true.
|
|
150
|
-
-
|
|
53
|
+
- **An explicit embedding goes through an assembly-time allowlist**: only models in the local catalog (the same list the settings card's dropdown renders) are accepted; anything else is refused before the command is assembled, with actionable wording. The reason is the nature of the capability — remote embedding sends workspace content to an external endpoint, and the model can invent an arbitrary prefixed reference. Whether workspace content may leave the machine is a gate only the user opens in the deployment config (see the deployment values below).
|
|
54
|
+
- `resetPaths=true` passes through `--reset-paths`, clearing the file-selection settings this root **inherited** (globs/fileTypes/hidden/…). It is **not** mutually exclusive with globs/fileTypes (upstream clears first, then applies this call's rules on top); it is mutually exclusive with `drop`, which is refused at assembly time rather than silently dropped.
|
|
55
|
+
- zg_status: root + checkReady, for diagnosing a missing/failed/cancelled index or watching progress explicitly.
|
|
56
|
+
- `checkReady=true` passes through `--check-ready`. Its real contract: **the readiness report still goes to stdout, and only the exit code expresses readiness**. So not-ready is not an execution failure — the plugin returns the report verbatim and appends one line saying the index is not ready and that this is the conclusion `checkReady=true` asked for, together with zg's own wording. The ordinary failure path would keep only the stderr line and throw away exactly the report the user needed.
|
|
57
|
+
- A non-zero exit with an empty report still throws; without `checkReady` a non-zero exit throws as before.
|
|
58
|
+
- Integrated with the background rebuild state: while a rebuild of the same root is running (job registered) the tool returns the rebuild projection and **starts no subprocess** — the answer to "is the index ready" is negative by definition at that moment, so reporting `not ready` is worse than saying "rebuilding, job X, ask again once it settles".
|
|
59
|
+
- **First-choice path when there is no index**: `zg_search` takes an `rg` switch that routes through zg's exhaustive lexical channel (`zg query --rg`), which needs no index.
|
|
60
|
+
- `rg` unset (default): when the workspace **and every directory above it** has no index, the search falls back to exhaustive matching; when an index exists, the indexed search runs as usual. An automatic fallback prepends a note saying the results are literal line matches rather than semantic relevance ranking, and that `zg_index` is needed for semantic search — without that note a mismatched answer is handed over as if it were a semantic conclusion.
|
|
61
|
+
- `rg=true` forces exhaustive search; `rg=false` refuses the fallback and uses indexed search only (with no index, zg reports `WORKSPACE_INDEX_NOT_FOUND` and points at building one).
|
|
62
|
+
- Exhaustive search grants **no** grep/rg quota: it reads no index, so it is not evidence that semantic search has been used. In an indexed workspace, still run one indexed search before reaching for grep/rg.
|
|
63
|
+
- The legal flag set differs from the indexed channel. zg rejects `preview` / `refresh` / `symbol-type` / `prefer-symbol` / `fuse` / `fts` / `vector` (observed: `--preview is not supported with --rg; use -A/-B/-C for rg context`); the plugin refuses at command-assembly time and lists the conflicts rather than dropping them silently. `limit` / `glob` / `iglob` / `type` / `type-not` / `modified-after` / `modified-before` / `device` / `mode` all still work.
|
|
64
|
+
- Exhaustive output has no `hits:` count lines, so the hit summary is automatically omitted under the "if it is not counted, do not claim it" rule.
|
|
65
|
+
- `trace` passes through `--trace` (troubleshooting): every hit carries a search trace saying which routes recalled it, its rank in each group, and its score. Output gets noticeably longer; exhaustive mode rejects the parameter at assembly time.
|
|
66
|
+
- With `trace` on, the hit header gains a `score=` field and a selection marker; the hit summary's **dedup key strips both**. Observed: the same location can score differently across groups (`src/beta.ts:1-2` is 0.0164 in the fts group and 0.0161 in the vector group), so putting the score in the key makes every hit a "new location", dedup stops working, and the location count is overstated twofold.
|
|
151
67
|
- root may be omitted in all three (defaults to the current session workspace); output is plain text; timeouts are 5 minutes / 10 minutes / 60 seconds, stdout capped at 400000 bytes (truncated to the tail with a note).
|
|
152
68
|
|
|
153
69
|
### Settings and search roots
|
|
154
70
|
|
|
155
|
-
- Namespace `zvec-grep`,
|
|
71
|
+
- Namespace `zvec-grep`, fourteen fields with built-in defaults, six of them volatile and on the card.
|
|
156
72
|
- defaultEmbedding=local/qwen3-embedding-0.6b, defaultLimit=10 (1-50), hfEndpoint=a China-reachable HF-compatible mirror base (set another mirror or leave empty for the official HF).
|
|
157
73
|
- enforceSearchFirst=true, grepBudgetPerSearch=3 (1-20), unlockWindowMin=10 (1-240).
|
|
158
|
-
-
|
|
159
|
-
- searchTimeoutMs=300000
|
|
160
|
-
-
|
|
74
|
+
- Additional **non-volatile deployment values** are not on the settings card: change them only via the line config in cordis.yml. The "5 minutes / 10 minutes / 60 seconds / 400000 bytes" in the tools section are their defaults.
|
|
75
|
+
- searchTimeoutMs=300000, statusTimeoutMs=60000, indexTimeoutMs=600000 (also the background rebuild kill-timer duration), stdoutMaxBytes=400000 (each with a minimum of 1), clientMode=auto, rebuildWaitMs=120000.
|
|
76
|
+
- Remote embedding, three values, all **off by default**: `allowRemoteEmbedding=false`, `remoteEmbeddingEndpoint=""`, `remoteEmbeddingApiKeyFrom=""`.
|
|
77
|
+
- While it is off, an explicit embedding reference must be in the local catalog at **command-assembly time**.
|
|
78
|
+
- Once open, the endpoint and the credential reach the zg child process **only through environment variables** (`ZVEC_GREP_ENDPOINT` / `ZVEC_GREP_API_KEY`) and **never through argv** — this plugin reuses the whole command string as a background-job label that is echoed on the card, so a key in argv would land in the UI, in logs, and in the process table.
|
|
79
|
+
- The credential value holds the **name** of the environment variable in the host process that holds the credential (e.g. `ZVEC_GREP_API_KEY`), not the credential itself: the host's subprocess layer scrubs inherited names matching KEY/SECRET/TOKEN, so only an explicit forward from this plugin reaches zg — and recording just the name also keeps the secret out of the plugin's own config file.
|
|
80
|
+
- This plugin does **not** pass `--allow-remote` for you: zg still requires the user to run `zg auth grant <root> --capability embedding --scope workspace` once, and that per-root authorization is not something a plugin should do on the user's behalf.
|
|
81
|
+
- `requireApprovalForExplicitRoot=false`: when on, an explicit `root` on any of the three zg tools that is neither the current session workspace nor already registered in this session triggers one user confirmation through the official `tools/pre-execute → {kind:'ask'} → ctx.approval` seam. It defaults to off, and three boundaries are known in advance: the `danger-full-access` preset sets `approval/policy` to `never` (the ask is deterministically rejected), delegated subagents are pinned to `approvalPolicy: 'never'` (**the switch has no effect inside a subagent**), and with no approval service installed the ask fails closed to a denial. This confirmation **only ever adds** a step: `rootOf`'s authorization predicate is unchanged, so an out-of-scope root is still refused even after the user approves.
|
|
161
82
|
- Precedence: runtime settings values > the line config of the bundle/user layer > built-in base; explicitly absent fields in the line config do not override the base.
|
|
162
|
-
- Volatile fields are read via `config.<field>.get()`; the
|
|
83
|
+
- Volatile fields are read via `config.<field>.get()`; the non-volatile deployment values are plain values and skip `.get()`.
|
|
163
84
|
- Root validation: must be an absolute path starting with `/`, lexically normalised (empty and `.` segments folded).
|
|
164
85
|
- Rejects empty strings, non-strings, NUL bytes, relative paths and `..` segments escaping the filesystem root, and `/` itself after normalisation.
|
|
165
86
|
- A missing directory is reported as "root does not exist" instead of a bare spawn ENOENT.
|
|
166
87
|
- The guard and execute share exactly this root predicate, so nothing is refused twice with different wording.
|
|
167
88
|
- Unlocks are counted per "session x index root": each successful zg_search resets to grepBudgetPerSearch calls valid for unlockWindowMin minutes; the index root is the root itself or its nearest indexed ancestor (up to 8 levels up).
|
|
89
|
+
- The session used for partitioning is the **root session**: the chain is walked up `header.parentSession` to the topmost hop. So the main agent and its subagents under one delegation tree **share one quota** — once the main agent has searched, its subagents can immediately spend those grep/rg calls instead of each searching again (they are usually searching the same tree).
|
|
90
|
+
- Degradation along the chain is three-level and never throws: a top-level session uses itself; when a hop's parent cannot be found (the session has settled, or the host has no session store) the walk stops at the **last known hop**; a cycle stops before the first repeat. The hop count is bounded.
|
|
168
91
|
- "Indexed" means `<root>/.zvec-grep/manifest.json` is on disk; **the directory name alone is not enough**: the same `.zvec-grep` name is also zg's own global home (`ZVEC_GREP_HOME ?? ~/.zvec-grep`, holding config.json / locks / models), so a plain workspace that never built an index but merely collides on an ancestor's name would get gated too.
|
|
169
92
|
- enforceSearchFirst=false disables only the gate; the zg_* backstop (confirm, root rules) is unaffected.
|
|
170
93
|
|
|
171
94
|
### External dependency (rg)
|
|
172
95
|
|
|
173
96
|
- The real binary dependency is zg (installed via `npm install -g @zvec/zvec-grep`): when it is not on PATH the shell reports exit 127 and the tool answers "zg is not installed or not on PATH", kept separate from "the sandbox runner never started".
|
|
97
|
+
- Upstream is `@zvec/zvec-grep` (it provides the `zg` bin), repository https://github.com/zvec-ai/zvec-grep, licensed **Apache-2.0**. This package is a dsh adaptation layer on top of it: it shells out to the CLI, and contains no upstream source, nor does it redistribute it on anyone's behalf.
|
|
98
|
+
- Version floor `0.2.2` (`MINIMUM_ZG_VERSION` in lib/zg-version.ts). Below that the plugin stops before dispatching a command and names the actual version, because the command shapes and flag names are written against that release - an older zg can parse the same argv as something else entirely and return results that look fine but searched nothing.
|
|
174
99
|
- Local embeddings are loaded by zg's backends: qwen3/embeddinggemma need llama-cpp (device=auto tries Metal and falls back to CPU), potion-* use model2vec, the rest use transformers-js in plain JS.
|
|
175
100
|
- Weights are downloaded with HF_ENDPOINT injected from hfEndpoint.
|
|
176
101
|
- This package neither depends on nor calls ripgrep: rg appears only in the gate predicate.
|
|
@@ -182,7 +107,7 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
|
182
107
|
|
|
183
108
|
- Every handler opens with `guardTrust(req, res, { servingNonLoopback })` (`shared/lib/trust`); failing any leg yields `403` with `{ ok:false, error: ... }`.
|
|
184
109
|
- Order of legs: Host authority -> the `sec-fetch-site` allowlist -> a verbatim `origin` vs Host compare. The two rejection sentences are `"untrusted host authority"` and `"cross-origin request rejected"`.
|
|
185
|
-
- `servingNonLoopback`
|
|
110
|
+
- `servingNonLoopback` is computed by `isNonLoopbackBindHost(webServer.host)` from the bound address itself - the host only rejects wildcard listeners, while binding a concrete IPv4/IPv6 of a local interface is a legitimate configuration, and a literal comparison would read that surface as loopback. A wrong method yields `405` carrying `Allow` plus `{ ok:false, error:"GET only" | "POST only" }` - no longer an empty reply.
|
|
186
111
|
- `GET /_dsh/zvec-grep/rebuild-roots`: returns only this plugin's own data (a CSRF token regenerated on every apply, plus the observed workspace list); GET/HEAD allowed, 403 when the gate above rejects it.
|
|
187
112
|
- `POST /_dsh/zvec-grep/rebuild?root=...`: gate + header `x-zvec-grep-csrf` + body <= 4096 bytes + root in the whitelist + directory exists; returns `{ ok, jobId }`, otherwise 405/403/400/500.
|
|
188
113
|
- `/_dsh/zvec-grep/rebuild-status?jobId=...`: polled behind the gate (the card polls every 2 seconds); returns status/exitCode/root/output (plus sandbox when present); an unknown jobId gets a 404 explaining it left the 10-record settled window.
|
|
@@ -207,12 +132,20 @@ What is not retained, stated plainly: the output ring keeps **UTF-8 bytes** (mea
|
|
|
207
132
|
|
|
208
133
|
- The only on-disk shape of the index is the `.zvec-grep/` directory under the searched root, written by zg (a read-only sandbox cannot write it, and the result says the index may be incomplete).
|
|
209
134
|
- Two rebuild paths: the model-side `zg_index` (rebuild=true, confirm=true), or the card's "rebuild workspace" button through the rebuild route above; deleting is `zg_index` with drop=true (assembled as `zg index <root> --drop --yes`).
|
|
210
|
-
- The package itself writes no files (its only fs
|
|
211
|
-
- The
|
|
212
|
-
-
|
|
135
|
+
- The package itself writes no files (its only fs calls are the index probe: existsSync plus one manifest read) and puts nothing in the host data directory `$DSH_HOME` (`<dsh data dir>`).
|
|
136
|
+
- The probe does not merely check that `.zvec-grep/manifest.json` exists: it **parses** the manifest and confirms its `rootPaths` really covers this directory. Two real situations are misread as "indexed" by an existence-only check while search would necessarily fail — the file is there but is not a manifest (a truncated write, or something else occupying the name), and the manifest is there but its root path points elsewhere. If the gate still blocked grep/rg on that basis, both search and the gate would be deadlocked.
|
|
137
|
+
- Only two fields are checked: `manifestVersion` (**strictly equal to 1**) and `rootPaths` (a non-empty array whose entries each carry a non-empty `absolutePath`). A version mismatch makes upstream throw `MANIFEST.INVALID` on read, meaning not a single search can succeed in that directory — a lenient check would only trap the user in a corner where the gate blocks grep/rg while every search is bound to fail. Embedding / policy fields are deliberately **not** checked — when those change the index still works, so calling it "no index" would be wrong.
|
|
138
|
+
- Coverage is decided by normalised equality. On macOS the manifest records the **unresolved** path (`/tmp/x`) while its `path` field is the resolved one (`/private/tmp/x`), so the `/private` prefix is stripped from both sides before comparing; either spelling matches.
|
|
139
|
+
- The whitelist and unlock table live in bounded memory, and their eviction matches their meaning: a **hit touches** the entry (moving it to the tail), and eviction first drops **expired** entries, then drops the coldest one by **least-recently-used** until back under the cap — not by insertion order. Plain insertion order is no eviction at all for a table where every successful search resets the same keys: the genuinely cold entries stay forever while a long-untouched key keeps its slot. Whitelist entries additionally carry a one-day validity, so a directory opened casually a month ago should not still hold a slot today. The capacity caps (64 whitelist roots / 256 session partitions) are unchanged, so resident memory stays bounded.
|
|
140
|
+
- The rebuild **jobs themselves** live in the host registry (section above) - on unload this package's side table is reclaimed with the effect and running jobs are killed through the registry.
|
|
141
|
+
- Excluded from indexing by default: `*.pem` / `*.key` / `*.p12` / `*.pfx` / `*.keystore` / `id_rsa*` / `id_ed25519*` (set excludeSecrets=false to allow). These rules match **case-insensitively**, so `Server.PEM` is excluded too, and they are applied after the caller's own path rules, so a broad positive rule of yours cannot re-include them.
|
|
142
|
+
- Residual gap: extension rules cannot cover **extensionless** key files (e.g. `myprivatekey`, `rsa_private`); `id_rsa*` / `id_ed25519*` only cover the OpenSSH default names. Declare such files through ignoreFiles (`--ignore-file`).
|
|
143
|
+
- Hidden files are skipped and ignore files honoured unless noIgnore is set.
|
|
213
144
|
- Nothing is uploaded: the package only assembles zg commands on the local machine and passes output through.
|
|
214
145
|
- The only outbound traffic is the embedding weight download driven by hfEndpoint.
|
|
215
146
|
- Echoes are bounded — stdout over the cap keeps the tail (with the spill path when present), and the last 400 characters of stderr are appended so a "degraded to pure lexical" notice is not mistaken for a full semantic result.
|
|
147
|
+
- stderr is **classified** before it is echoed: only recognised indexing progress is dropped (`Scanning files…` / `Indexing files…` / `Indexing complete` / `Preparing <model>` / `Downloading <model> · …` / `Model ready: <model>` — written line by line when stderr is not a TTY, present on every index build), while degradation notices, lock conflicts, sandbox facts and any **unrecognised** new warning are all kept. When the whole stream is noise no note is added at all. The test is "drop only what is recognised", never "keep only what is recognised" — the latter would silently swallow anything new zg starts emitting, which is the worst possible failure mode.
|
|
148
|
+
- `Indexing complete` matches on **whole-line equality**, not a prefix: `Indexing completed with 3 failed files` (the partial-failure signal) literally starts with it, so a prefix match would drop exactly the information that matters.
|
|
216
149
|
|
|
217
150
|
### FAQ
|
|
218
151
|
|
|
@@ -222,3 +155,14 @@ What is not retained, stated plainly: the output ring keeps **UTF-8 bytes** (mea
|
|
|
222
155
|
- The card reports a failed rebuild although zg looks finished: success is "completed with exit 0" — exit 127 (zg not installed) also lands in completed, so read the tail of the output.
|
|
223
156
|
- A root that was never indexed: zg_search fails loudly instead of silently building the index; building happens only via zg_index on an explicit user request.
|
|
224
157
|
- Changed the embedding but semantic hits are missing: switching embedding only takes effect after a rebuild with rebuild=true.
|
|
158
|
+
|
|
159
|
+
### Development
|
|
160
|
+
|
|
161
|
+
- `npm run check` is the single gate to run before publishing: typecheck (both tsconfigs) + `oxlint` + rebuild both bundles + `vitest run --coverage` + `oxfmt --check`.
|
|
162
|
+
- Coverage runs under a **100% global threshold** (statements/branches/functions/lines): any line or branch that no test pins turns the suite red by design.
|
|
163
|
+
- `npm run build` / `npm run build:client` produce `host.js` / `client.js`, and neither is committed - `prepare` and `prepack` rebuild them, while `test/build-host.test.ts` / `test/build-client.test.ts` compare the on-disk bundle against an in-memory build byte for byte, so a stale bundle fails the suite. Never hand-edit the bundles: the published entry *is* the built artifact, because Node refuses to strip types for a `.ts` sitting inside `node_modules`.
|
|
164
|
+
- Beyond behaviour, a family of manifest gates guards the published surface (`test/publish-manifest.test.ts`): every entry target covered by `files`, host packages kept out of `dependencies`, `dsh-*` pinned exactly and at the peer version, no local paths or store layout inside the shipped artifacts, and every host package that shared's own shipped code value-imports supplied by this package. `test/dist-size.test.ts` budgets bundle bytes; `test/readme-parity.test.ts` keeps the English and Chinese halves structurally in sync.
|
|
165
|
+
|
|
166
|
+
### License
|
|
167
|
+
|
|
168
|
+
MIT - see [LICENSE](LICENSE). The `zg` CLI this plugin drives is upstream `@zvec/zvec-grep`, licensed **Apache-2.0**. This package contains no upstream source, so no upstream license text is bundled with it; if you redistribute the two together, keep each project's notices separate and intact.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# @jayyuen66/dsh-zvec-grep
|
|
2
|
+
|
|
3
|
+
[English](./README.md) · [简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
### 它做什么
|
|
6
|
+
|
|
7
|
+
- 给 dsh 会话接上工作区语义检索:注册 zg_search / zg_index / zg_status 三个模型工具,底层经宿主 shell 以 `--mode direct` 调 zg CLI(BM25 + 向量 + RRF 混合检索)。
|
|
8
|
+
- 注入一段 systemPrompt 硬规则(`zvec-grep-routing`,order 1550)+ 两道 tools.guard:zg_* 安全兜底与 search-first 门禁(已建索引的工作区里,grep/rg 前必须先有一次成功的 zg_search)。
|
|
9
|
+
- 附带 web 端设置卡:默认 embedding、limit、search-first 配额/时效,以及「工作区重建」按钮。
|
|
10
|
+
|
|
11
|
+
### 安装
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- 包在公共 npm 上,安装不需要凭据;发布态产物只有 host.js、client.js、cordis.patch.yml(package.json 的 files)。
|
|
18
|
+
- 运行期值 import `@jayyuen66/dsh-plugin-shared`(lib/http、lib/locale、lib/text)与 `@deepseek-ai/schemastery`(宿主 fork:0.1.7 的 `.volatile()` 解析只有它有实现,公共 schemastery 既没这个方法、解析出的也仍是普通值),装不上就是 ERR_MODULE_NOT_FOUND。
|
|
19
|
+
- shared 的 `lib/text` 自己值导入 `@deepseek-ai/dsh-output-retention`,所以那枚宿主包也得在提供面上:本包按 `schemastery` 同一口径处理(非 optional `peerDependencies` + `devDependencies` 同枚精确版本,**不进 `dependencies`**)。这条只能靠门禁钉:漏它时本包的类型检查、构建与测试全绿,故障只在装出去之后以 ERR_MODULE_NOT_FOUND 出现。
|
|
20
|
+
- 只有 shared 那枚在 `dependencies` 里。`@deepseek-ai/schemastery` 是宿主包:声明为**非 optional 的 `peerDependencies`**,并在 `devDependencies` 里以同一枚精确版本再写一份给本包的编译与测试用——它**不进 `dependencies`**。这条不是风格偏好:消费侧 profile 的安装布局是 `nodeLinker: hoisted` 且 `autoInstallPeers: false`,宿主包一旦进了 `dependencies` 就会被落成真实目录,与宿主进程已加载的那份并存;而 `@deepseek-ai/dsh-tools` 的 `TOOL_RUNTIME_SCHEDULER` 是普通 `Symbol`(不是 `Symbol.for`),符号身份按模块实例计算,宿主 `dsh-agent-loop` 于是读到 `undefined`,每一次原生工具调用都抛 `Cannot read properties of undefined (reading 'prepare')`,整个 profile 的工具一起失效——本包的构建、类型检查与测试在这之前全部照绿。判据钉在 `test/publish-manifest.test.ts`。
|
|
21
|
+
|
|
22
|
+
### 在 dsh 里启用
|
|
23
|
+
|
|
24
|
+
- add/remove 按包内 cordis.patch.yml 维护注册行 `- id: zvec-grep`(name 指向本包);该文件由 `package.json` 的 `dsh.bundle.patch` 指向。
|
|
25
|
+
- 宿主兼容性按 **peer 声明**判,不按 `engines.dsh`:装配前逐条比对 `@deepseek-ai/dsh` 与每一枚 `@deepseek-ai/dsh-*` 的区间与当前 runtime 版本,prerelease 也参与匹配(官方口径见 dsh-app-boot README)。不符即该条目被拒;组合包(bundle)没有豁免时整枚跳过并列进 `skippedBundles`。
|
|
26
|
+
- 本包把 `dsh-*` 一律**精确钉**(`test/publish-manifest.test.ts` 的要求,理由是「装出第二份宿主类型面」比版本冲突更坏),所以**高于 `0.2.1-alpha.2` 的宿主同样需要授权**,出路是宿主点名的那句:`dsh plugin --profile web allow-version @jayyuen66/dsh-zvec-grep@<版本> --dsh-version <确切版本> --accept-risk`。
|
|
27
|
+
- `engines.dsh` 只是声明,无人读;`>= 0.2.1-alpha.2` 与 peer 同值仅为不留下互相矛盾的数。
|
|
28
|
+
- `dsh.client.platform` 为 web 且 immediately,设置卡的 client 半随宿主下发;bundle 安装走 pnpm(>= 12.3.0)。
|
|
29
|
+
- apply 需要 settings/shell/tools/systemPrompt/timer 五个服务面:它们都在 `inject` 里,缺任一 cordis 就不激活本条目(宿主启动诊断点名 `pending (waiting for service: …)`);apply 里的守卫再兜一层,ctx 形状不对时抛 `required services … missing`。
|
|
30
|
+
- 三条 `/_dsh/zvec-grep/*` 端点挂在 `inject(["webServer"])` 的子 fiber 上:宿主没有 webServer(如 TUI)时子 fiber 不激活,端点不存在而工具照常。真实宿主上 webServer 比本条目晚到位约 1 秒,所以这里必须是依赖、不能只在 apply 里 `ctx.get` 读一次。
|
|
31
|
+
|
|
32
|
+
### 提供给模型的工具
|
|
33
|
+
|
|
34
|
+
- zg_search:query / queries / fts / vector 至少其一(合计 <= 32 组,单条 <= 4000 字符)。
|
|
35
|
+
- 可加 globs / insensitiveGlobs / fileTypes / excludedFileTypes / symbolTypes / preferSymbol / modifiedAfter / modifiedBefore / fuse / limit / preview / refresh / device。
|
|
36
|
+
- `globs` / `insensitiveGlobs` / `fileTypes` / `excludedFileTypes` 既收**单个字符串**也收字符串数组(与上游 zg 对这几项的对外契约一致,最多 128 项、单项 <= 1024 字符)。
|
|
37
|
+
- `symbolTypes` 绑定 zg 的真实闭集,取值**只认小写**:`module` / `class` / `interface` / `function` / `value` / `alias`。zg 侧 `--symbol-type Class` 会以非零码退出(`Unsupported symbol type: Class`),插件在构造命令前就拦下并列出合法取值;不做大小写折叠——悄悄改成小写等于替模型改了它没写的约束。
|
|
38
|
+
- `preview` 三档:`none` 只给锚点行 / `short` 锚点加一段有界上下文 / `full` 整段源码,**默认 short**,每条命中自带有界源码片段。
|
|
39
|
+
- `refresh` 三档:`wait` 等索引刷到最新(**默认**)/ `off` 不刷新 / `background` 交给守护进程后台刷新。`background` 只在守护进程模式下成立:直连模式下 zg 不报错,而是降级成 `off` 并往 stderr 打一行 `warning: --refresh background requires Server mode; Direct mode uses --refresh off`——本包把 stderr 原样回显,那一行会自己到模型眼前。
|
|
40
|
+
- 输出尾部附一行**命中摘要**,两栏口径分开给:`分组计数合计`(各查询组 `hits:` 之和)与`去重后 N 个不同位置`(按「相对路径 + 行号范围」去重)。分栏是因为同一处代码会被多组各命中一次(名次与匹配来源逐组变化),直接求和会把同一处位置重复计入、冒充命中总数。
|
|
41
|
+
- 某组命中数正好等于 `--limit` 时只作**观察陈述**并显式说明「zg 不提供截断信号,此处不作断言」——zg 的输出没有任何截断标记,不能把"可能还有未显示的命中"说成事实。输出被宿主按 stdout 上限截尾时另附「只含保留部分」。
|
|
42
|
+
- zg_index:confirm 必填且必须为 true(required 校验 + guard 双层拒绝)。
|
|
43
|
+
- `background=true` 走**模型侧后台索引**:一次调用把「起 zg 进程 + 登记进官方作业注册表 + 挂超时回收」全做完,把可轮询的作业号交回后**立即返回**。建索引可能要下载 embedding 权重、等很久,后台执行免得工具调用一直挂着。
|
|
44
|
+
- 不依赖宿主作业工具:宿主作业工具在 web 平面已停用,模型侧那条路根本不可走。插件复用与设置卡**完全相同**的 spawn/登记/占位三步(同一个函数,不是复制品),所以两条入口起的作业在名册、状态投影、轮询端点上完全同形——卡片能看见模型起的索引,反之亦然。
|
|
45
|
+
- 占位与设置卡的重建互斥,且跨入口成立:同根已在跑索引写时,模型侧与卡片侧都只会跟随那一条,不会各起一条 zg 去啃同一份索引。
|
|
46
|
+
- 官方作业注册表缺席时**根本不起进程**并直接报错:起一条没有环、没有容量、也没人能收的 zg 比不起更糟——它会一直占着同根的写锁,把这棵树的后续索引全堵死。
|
|
47
|
+
- 落定前该根的语义检索会等它完成再自动重试,期间 grep/rg 不受门禁限制。
|
|
48
|
+
- 另有 embedding / rebuild / drop / resetPaths / globs / insensitiveGlobs / fileTypes / excludedFileTypes / ignoreFiles / excludeSecrets / hidden / noIgnore / maxDepth / maxFileSizeBytes / follow / embeddingConcurrency / device;其中五个路径过滤项同样收单值或数组。
|
|
49
|
+
- 切换 embedding 必须 rebuild=true 才生效。
|
|
50
|
+
- **显式 embedding 走构造期 allowlist**:只接受本地候选清单(与设置卡下拉同一份)里的模型,其余引用在命令构造前就被拒并给出可行动文案。理由是能力面的性质——远程 embedding 会把工作区内容送到外部端点,而模型能凭空写出一个任意前缀的引用;这是「工作区内容会不会被送出本机」的闸门,只能由用户在部署配置里开(见部署值一节)。
|
|
51
|
+
- `resetPaths=true` 透传 `--reset-paths`,清掉这个根**继承来的**文件选择设置(globs/fileTypes/hidden/…)。它与 globs/fileTypes **不互斥**(上游是先清、再按本次请求盖上去),与 `drop` 互斥(构造期直接拒,不静默丢弃)。
|
|
52
|
+
- zg_status:root + checkReady,用于索引缺失/失败/取消后的诊断或显式看进度。
|
|
53
|
+
- `checkReady=true` 透传 `--check-ready`。注意它的真实契约:**就绪报告照常打在 stdout,只用退出码表达就绪与否**。所以未就绪不是执行失败,插件把报告原样交回,另附一行「索引未就绪……这不是执行失败,而是 checkReady=true 要的那个结论」并带上 zg 的原始判据。走普通失败路径只会留下 stderr 那一句,恰好把用户最需要的报告扔掉。
|
|
54
|
+
- 报告为空时的非零退出仍按失败抛,不凭空造一份报告;未开 `checkReady` 时非零退出照旧抛错。
|
|
55
|
+
- 与后台重建作业状态整合:同根正在重建时(作业已登记)直接给重建投影,**不启子进程**——此刻「索引是否就绪」的答案本就是否定的,报一个 `not ready` 反而不如直接告诉它「重建中,作业 X,落定后再问」。
|
|
56
|
+
- **无索引时的首选路径**:`zg_search` 带 `rg` 开关走 zg 的穷举词法通道(`zg query --rg`),不需要索引。
|
|
57
|
+
- `rg` 留空(缺省):工作区**及其向上各级**都没有索引时自动改走穷举检索,有索引则照常走索引检索。自动改道会在结果前加一条前置声明,说明「这是逐行字面匹配,不是语义相关度排序,需要语义检索请先 zg_index」——不声明就等于把与请求不符的答案当成语义结论递出去。
|
|
58
|
+
- `rg=true` 强制穷举;`rg=false` 拒绝改道,只用索引检索(无索引时由 zg 报 `WORKSPACE_INDEX_NOT_FOUND` 并附建索引提示)。
|
|
59
|
+
- 穷举检索**不发放** grep/rg 配额:它不读索引,不构成「先用过语义检索」的证据。有索引的工作区想用 grep/rg,仍要先走一次索引检索。
|
|
60
|
+
- 穷举通道的合法旗标与索引通道不同。zg 会拒绝 `preview` / `refresh` / `symbol-type` / `prefer-symbol` / `fuse` / `fts` / `vector`(实测报错如 `--preview is not supported with --rg; use -A/-B/-C for rg context`),插件在构造阶段就拦下并列出冲突项,不静默丢弃。`limit` / `glob` / `iglob` / `type` / `type-not` / `modified-after` / `modified-before` / `device` / `mode` 照常生效。
|
|
61
|
+
- 穷举输出没有 `hits:` 计数行,故命中摘要按「不数就不谎称」自动不出。
|
|
62
|
+
- `trace` 透传 `--trace`(排障用):每条命中附一行检索轨迹,说明它被哪几路召回、在各组里的名次,并给出分值。输出会明显变长;穷举模式不支持该参数(构造阶段即拒绝)。
|
|
63
|
+
- 开 `trace` 时条目头行会多出 `score=` 与选择理由标记;命中摘要的**去重键会剥掉这两段**——实测同一处位置在两个组里分值可以不同(`src/beta.ts:1-2` 在 fts 组是 0.0164、在 vector 组是 0.0161),带分值入键会让每条命中都成「新位置」,去重直接失效、位置数虚高一倍。
|
|
64
|
+
- 三者的 root 都可省略(缺省=当前会话工作区);输出为纯文本;超时分别为 5 分钟 / 10 分钟 / 60 秒,stdout 上限 400000 字节(超限截尾并提示)。
|
|
65
|
+
|
|
66
|
+
### 设置项与检索根
|
|
67
|
+
|
|
68
|
+
- 命名空间 `zvec-grep` 由宿主**隐式**注册(0.1.7 起 = profile 条目 id,插件侧不再有 `settings.register`);schema 共十四个字段,其中卡上那六枚标 `.volatile()`,内置默认逐字段写在 `.default()` 上。
|
|
69
|
+
- defaultEmbedding=local/qwen3-embedding-0.6b、defaultLimit=10(1-50)、hfEndpoint=国内可达的 HF 兼容镜像基址(可改成别的镜像或留空走官方 HF)。
|
|
70
|
+
- enforceSearchFirst=true、grepBudgetPerSearch=3(1-20)、unlockWindowMin=10(1-240)。
|
|
71
|
+
- 另有**非 volatile 部署值**(不进设置卡,只在 cordis.yml 的行 config 里改值;上面工具一节的「5 分钟 / 10 分钟 / 60 秒 / 400000 字节」就是它们的默认):searchTimeoutMs=300000、statusTimeoutMs=60000、indexTimeoutMs=600000(也是后台重建 kill 定时器的时长)、stdoutMaxBytes=400000、clientMode=auto、rebuildWaitMs=120000,超时/缓冲几项均最小 1。
|
|
72
|
+
- 远程 embedding 三件套,默认**全关**:`allowRemoteEmbedding=false`、`remoteEmbeddingEndpoint=""`、`remoteEmbeddingApiKeyFrom=""`。
|
|
73
|
+
- 关着的时候,显式 embedding 引用在**命令构造期**就必须落在本地候选清单里。
|
|
74
|
+
- 打开后端点与凭据**只经环境变量**下发给 zg 子进程(`ZVEC_GREP_ENDPOINT` / `ZVEC_GREP_API_KEY`),**绝不进 argv**——本包把整条命令当作业 label 回显给卡片,argv 里的密钥会进界面、进日志、进 `ps` 的进程表。
|
|
75
|
+
- 凭据那项填的是**宿主进程里那个装凭据的环境变量名**(如 `ZVEC_GREP_API_KEY`),不是密钥本身:宿主 subprocess 层会把名字含 KEY/SECRET/TOKEN 的继承变量剔掉,必须由本插件显式转发才到得了 zg;只记名字也让密钥不必落进插件配置文件。
|
|
76
|
+
- 本插件**不自动传 `--allow-remote`**:zg 还要用户自己跑一次 `zg auth grant <root> --capability embedding --scope workspace` 才肯发请求,那道按 root 的授权本插件不代劳。
|
|
77
|
+
- `requireApprovalForExplicitRoot=false`:打开后,三个 zg 工具里**显式给了 root**、且那个 root 既不是本会话工作区、也不在本会话已登记范围内时,会经官方 `tools/pre-execute → {kind:'ask'} → ctx.approval` 弹一次用户确认。默认关,且有三个已知边界:`danger-full-access` 预设把 `approval/policy` 写成 `never`(ask 会被确定性拒绝)、委派子代理被钉死 `approvalPolicy: 'never'`(**该开关对子代理无效**)、宿主没装 approval 服务时 fail-closed 成拒绝。这道确认**只加不减**:`rootOf` 的授权判据一字未改,越界的 root 即便「用户已批准」照旧被拒。
|
|
78
|
+
- 优先级:设置里的运行时值 > 组合包层/用户层行的 config > schema 的 `.default()`;行 config 中显式缺省的字段不覆盖默认。读侧是 `config.<field>.get()`(volatile 引用,卡上改完下一个事件即生效);非 volatile 部署值是普通值形态,不经 `.get()`。
|
|
79
|
+
- root 校验:必须是以 `/` 开头的绝对路径,词典归一折叠空段与 `.`。
|
|
80
|
+
- 拒绝空串、非字符串、含 NUL、相对路径、越出文件系统根的 `..`,归一后为 `/` 也拒。
|
|
81
|
+
- 目录不存在时单报「root 目录不存在」,不冒成 spawn ENOENT。
|
|
82
|
+
- guard 与 execute 用同一套 root 判据,避免「guard 放行、execute 抛错」说两遍。
|
|
83
|
+
- 解锁按「会话 × 索引根」计:每次成功 zg_search 重置为 grepBudgetPerSearch 次、unlockWindowMin 分钟有效;索引根是 root 自身或含索引的最近祖先(最多上溯 8 层)。
|
|
84
|
+
- 分片用的会话是**根会话**:沿 `header.parentSession` 一路上溯到最顶层那一跳。故同一棵委派树上的主代理与子代理**共享一份额度**——主代理搜过一次,子代理随即就能用那几次 grep/rg,不必各自再搜一次(它们搜的往往是同一棵树)。
|
|
85
|
+
- 上溯的降级是三级的,都不抛错:自身即顶层就用自己;某一跳查不到它的父(会话已落定,或宿主没装会话存储)就停在**已知的最后一跳**;链成环就停在首次重复前。跳数有上限。
|
|
86
|
+
- 「含索引」的判据是 `<root>/.zvec-grep/manifest.json` 在盘上,**只判 `.zvec-grep` 目录名不够**:这个名字同时是 zg 自己的全局 home(`ZVEC_GREP_HOME ?? ~/.zvec-grep`,装的是 config.json / locks / models),只判目录名会让一个从未建索引、只是祖先目录撞名的普通工作区也被门禁拦下。
|
|
87
|
+
- enforceSearchFirst=false 只关掉门禁,zg_* 的安全兜底(confirm、root 判据)不受影响。
|
|
88
|
+
|
|
89
|
+
### 外部依赖(rg)
|
|
90
|
+
|
|
91
|
+
- 真正的二进制依赖是 zg(由 `npm install -g @zvec/zvec-grep` 提供):不在 PATH 时 shell 回 exit 127,工具据此回「zg 未安装或不在 PATH」,与「沙箱 runner 没起来」分开归因。
|
|
92
|
+
- 上游即 `@zvec/zvec-grep`(它提供 `zg` 这枚 bin),仓库 https://github.com/zvec-ai/zvec-grep,许可 **Apache-2.0**。本包是它之上的 dsh 适配层:只经宿主 shell 调那枚 CLI,不含上游源码,也不替上游做任何形式的分发。
|
|
93
|
+
- 版本下限 `0.2.2`(`lib/zg-version.ts` 的 `MINIMUM_ZG_VERSION`)。低于它就在**下发命令之前**停住并点名实际版本:命令形态与旗标名是按那个版本写的,更老的 zg 可能把同一串 argv 解成别的东西,给出「看着正常、其实什么都没查」的结果。
|
|
94
|
+
- 本地 embedding 由 zg 侧后端加载:qwen3/embeddinggemma 走 llama-cpp(device=auto 时试 Metal、失败回退 CPU),potion-* 走 model2vec,其余走 transformers-js 纯 JS。
|
|
95
|
+
- 权重按 hfEndpoint 注入 HF_ENDPOINT 后下载。
|
|
96
|
+
- 本包不依赖也不调用 ripgrep:rg 只出现在门禁判据里。
|
|
97
|
+
- bash/pwsh 命令串经引号/注释感知切词后,命令位上的 grep/egrep/fgrep/rg 与原生 grep 工具才算检索。
|
|
98
|
+
- `--help`/`--version`/`-V`、`echo "grep x"`、`git commit -m "use rg"` 不算。
|
|
99
|
+
- 有沙箱执行器时会区分 runner 失败、策略拒绝与 zg 自身失败,并在结果里显式打「可能不完整」标记。
|
|
100
|
+
|
|
101
|
+
### 对外接口
|
|
102
|
+
|
|
103
|
+
- 三条路由的 handler 第一句都是 `guardTrust(req, res, { servingNonLoopback })`(`shared/lib/trust`),任一判据不过即 `403` + `{ ok:false, error: ... }`。
|
|
104
|
+
- 判据次序:Host 权威 → `sec-fetch-site` 白名单 → `origin` 与 Host 逐字比对;两句错误文本是 `"untrusted host authority"` 与 `"cross-origin request rejected"`。
|
|
105
|
+
- `servingNonLoopback` 由 `isNonLoopbackBindHost(webServer.host)` 按**绑定地址本身**算出(宿主只拒通配地址,绑本机网卡的具体 IPv4/IPv6 是合法配置,比字面量会漏判这一面);非本方法的 `405` 带 `Allow` 与 `{ ok:false, error:"GET only" | "POST only" }`,不再是空回显。
|
|
106
|
+
- `GET /_dsh/zvec-grep/rebuild-roots`:只回本包自己的数据(每次 apply 重新生成的 CSRF token + 已观测工作区列表),允许 GET/HEAD,过不了上面那道闸门即 403。
|
|
107
|
+
- `POST /_dsh/zvec-grep/rebuild?root=...`:闸门 + 头 `x-zvec-grep-csrf` + body <= 4096 字节 + root 命中白名单 + 目录存在,成功回 `{ ok, jobId }`;否则 405/403/400/500。
|
|
108
|
+
- `/_dsh/zvec-grep/rebuild-status?jobId=...`:闸门后轮询(卡片每 2 秒一次),回 status/exitCode/root/output(有沙箱时带 sandbox),未知 jobId 回 404 并说明多半是出了本包那条 10 条落定窗口。
|
|
109
|
+
- 另有 systemPrompt 段 `zvec-grep-routing`(order 1550)与 settings 命名空间 `zvec-grep`。
|
|
110
|
+
- 白名单只记本 daemon 真实观测到的会话工作区,容量 64(超出按插入序淘汰)。
|
|
111
|
+
- 同时能跑几个重建由**宿主注册表**决定(实测默认未拥有桶 10),本包不再自带并发上限;
|
|
112
|
+
满员时 `POST /rebuild` 直接回 500 并带上官方的点名文案,**不会**再杀掉已经在跑的重建。
|
|
113
|
+
- `rebuild-status` 的 `jobId` 只在本包侧表里查得到:本包保留最近 10 条**已结束**的记录
|
|
114
|
+
(超出即从注册表 remove ⇒ 404),进行中的记录永不被动。
|
|
115
|
+
|
|
116
|
+
### 后台作业面(官方 `ctx.jobs`)
|
|
117
|
+
|
|
118
|
+
本包不自带任务注册表了:一次「工作区重建」是宿主 `ctx.jobs` 里的一枚**未拥有**作业
|
|
119
|
+
(`kind: "zvec-grep-rebuild"` ⇒ id `zvec-grep-rebuild-N`)。这带来三件看得见的变化:
|
|
120
|
+
|
|
121
|
+
| 面 | 事实 |
|
|
122
|
+
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
123
|
+
| 模型侧能看见了 | 官方 `job_list` / `job_output` / `job_kill` 现在列得出这次重建,退出码与信号名走作业的 `detail`(口径与宿主的 bash 工具同形,实测 `plugins/docs/harness/f3-equiv/probe-jobs.mjs`)。输出走官方 **pull source**(`proc.observed[*].readFrom`)⇒ 环由注册表按它自己的节拍推进,**设置面板关着也照样前进**;官方那条观察者面与 `readOutput()` 互不偷字节(d.ts 原文 "without stealing bytes from `readOutput`")。controller 只在 `start` 那一瞬挂、摘掉即恢复官方拒绝(见跨包纪律) |
|
|
124
|
+
| 未拥有 ⇒ 对全部会话可见 | 官方件按 owner 隔离,未拥有作业任何 caller 都能 `list`/`read`/`kill`。这是本波**已知并接受**的暴露面(卡片是会话外的 webServer 生产者,受有作业则要 `dsh-agent` 注册表,实测不可得)。要收回去只有一条路:回滚这次换装。注意 `/_dsh/zvec-grep/rebuild-status` 仍只认本包侧表里的 id,别人的作业(如宿主的 `bash-1`)经这个端点读不到 |
|
|
125
|
+
| 多了两个状态词 | `stopping`(取消已发出、进程还没收完 ⇒ 卡片按「仍在跑」显示)与 `failed`(注册表侧判定失败 ⇒ 给专门文案,不显示成「退出码 null」) |
|
|
126
|
+
|
|
127
|
+
不留存的东西也写清楚:输出环按 **UTF-8 字节**留存(实测宿主默认 262144 字节),卡片的 4000 字符尾窗与 `shown/total` 按 **UTF-16 码元**计——两套单位各管各的。因此 `total` 说的是**留存窗内**的码元数(官方那个字节真值在 `view.output.total`,单位不同不混用),而中文输出下这只窗比换装前(按码元留 256 KiB)**小约 1/3**,这是采用官方件的代价。两条丢失标记各说一件事:`已截断` = 环按留存窗裁掉了头部(`view.output.earliest > 0`,看不见了);`缓冲区溢出` = 执行器的读者报 lossy 或干脆抛了(真少了字节,可能有 spill 文件)。超时说明与沙箱事实**不进环**:环的写权归注册表的泵,而它在落定之后丢弃一切写入(实测),所以这两条由端点在投影时合成,永远不会因为"写晚了"而消失。注册表被重载或记录被别人收走时轮询答 **404**(官方 `get`/`readAt` 对未知 id 抛错,而宿主对 handler 抛出的兜法是记一条日志再写一枚没有 body、没有 content-type 的 **400**,只有头已发时才断掉 socket —— installed dsh-host-webserver `lib/index.js:246-256` ⇒ 卡片会进终止态并停轮询,那条还在跑的重建就再也看不见)。
|
|
128
|
+
|
|
129
|
+
### 数据与隐私
|
|
130
|
+
|
|
131
|
+
- 索引的唯一落盘形状是被检索 root 下的 `.zvec-grep/` 目录,由 zg 写入(read-only 沙箱下写不了它,会明确报索引可能不完整)。
|
|
132
|
+
- 重建有两条路:模型侧 `zg_index`(rebuild=true、confirm=true),或设置卡「工作区重建」走上面的 rebuild 路由;删除是 `zg_index` drop=true(拼成 `zg index <root> --drop --yes`)。
|
|
133
|
+
- 本包自身不写任何文件(唯一的 fs 调用是索引探测:existsSync + 读一次清单),也不向宿主数据目录 `$DSH_HOME`(`<dsh 数据目录>`)落数据。
|
|
134
|
+
- 索引探测不只判「`.zvec-grep/manifest.json` 在不在」:还要**解析清单**并确认它的 `rootPaths` 真的覆盖这个目录。两种实况会被「只判存在」误判成有索引,而实际检索必然失败——文件在但不是一份清单(半截写入/同名占用),以及清单在但根路径指向别处。此时门禁若还按「已建索引」拦着 grep/rg,就等于把检索与门禁双向堵死。
|
|
135
|
+
- 认的结构只有 `manifestVersion`(**严格等于 1**)与 `rootPaths`(非空数组、每项带非空 `absolutePath`)两处——版本不等时上游读它会直接抛 `MANIFEST.INVALID`,此时这个目录一次检索都做不了,宽松放行只会把用户卡在「门禁拦着、检索又必失败」的死角里。刻意不校验 embedding / policy 等字段——那些变了索引照样能用,判成「无索引」反而是错的。
|
|
136
|
+
- 覆盖判据是归一后相等;macOS 上清单里写的是**未解析**路径(`/tmp/x`)而 `path` 字段才是解析过的(`/private/tmp/x`),故两边都再剥一次 `/private` 前缀再比,两种写法都能对上。
|
|
137
|
+
- 白名单/解锁表都在内存、有界,且淘汰策略与语义相符:**命中即触摸**(挪到队尾),淘汰时先按**有效期**丢过期项、再按**最近使用**丢最冷的一条到上限之内——不是按插入序。纯插入序对一张「每次成功检索都重置同一批键」的表等于不淘汰:真正冷掉的项永远留着,而很久没被碰过的键一直占位。白名单条目另有一条有效期(一天),一个月前顺手开过的一个目录不该今天还占名额。容量上界(白名单 64 条 / 会话分片 256 个)保持不变,故常驻内存依旧有界。
|
|
138
|
+
- 重建**作业本体**住在宿主注册表里(见上一节),插件卸载时本包侧表随 effect 回收、在跑的作业经注册表 kill 掉。
|
|
139
|
+
- 默认不进索引的:`*.pem` / `*.key` / `*.p12` / `*.pfx` / `*.keystore` / `id_rsa*` / `id_ed25519*`(excludeSecrets=false 可关)。这些规则按**大小写不敏感**匹配,`Server.PEM` 同样被排除;且排在用户自己的路径规则之后生效,用户写一条宽泛的正向规则也覆盖不掉它们。
|
|
140
|
+
- 残留缺口:**无扩展名**的密钥文件(如 `myprivatekey`、`rsa_private`)扩展名规则覆盖不到,`id_rsa*` / `id_ed25519*` 只覆盖 OpenSSH 默认命名;这类文件请走 ignoreFiles(`--ignore-file`)显式声明。
|
|
141
|
+
- 隐藏文件默认不收,ignore 文件默认生效(noIgnore 可关)。
|
|
142
|
+
- 本包只在本机拼 zg 命令并透传输出,不上传代码。
|
|
143
|
+
- 唯一的外连是 embedding 权重按 hfEndpoint 下载。
|
|
144
|
+
- 结果回显有界:stdout 超限截尾(有 spill 路径会给出)、stderr 尾部 400 字符一并回显,免得「退化成纯词法」被当成完整语义结果。
|
|
145
|
+
|
|
146
|
+
### 常见问题
|
|
147
|
+
|
|
148
|
+
- grep/rg 被拒且提示「尚未执行过 zg_search」:这是 search-first 门禁,先 zg_search;配额用尽或过期同理,换个更准的 query/fts 重搜即可续上,不必关插件。
|
|
149
|
+
- 检索超时:默认 `--refresh wait` 会同步刷新既有索引,大工作区请用 globs/fileTypes 缩小范围或调小 limit,也可先手写字面检索。
|
|
150
|
+
- 重建按钮回 403「root 不在本 daemon 观测到的工作区白名单内」:该目录从未在本 daemon 开过会话;先在该目录起会话,或让模型带 confirm=true 调 zg_index。
|
|
151
|
+
- 卡片显示重建失败而 zg 看着像跑完了:成功判据是 completed 且 exit 0——exit 127(zg 没装)也落在 completed,看输出尾部原因。
|
|
152
|
+
- 从未建索引的 root:zg_search 明确报错而不是静默建索引;建索引只在用户明确要求时由 zg_index 做。
|
|
153
|
+
- 换了 embedding 却搜不到语义结果:切换 embedding 必须 rebuild=true 重建后才生效。
|
|
154
|
+
|
|
155
|
+
### 开发
|
|
156
|
+
|
|
157
|
+
- `npm run check` 是发布前的一条门:typecheck(两侧 tsconfig)+ `oxlint` + 重建两个 bundle + `vitest run --coverage` + `oxfmt --check`。
|
|
158
|
+
- 覆盖率按**全局 100% 阈值**跑(stmts/branches/funcs/lines):任何一行或分支没被用例钉住,套件当场红——这是本仓的既定质量门,不是巧合。
|
|
159
|
+
- `npm run build` / `npm run build:client` 产出 `host.js` / `client.js`,两者**都不入库**:`prepare` 与 `prepack` 现产,而 `test/build-host.test.ts` / `test/build-client.test.ts` 拿磁盘产物与内存构建逐字节比,产物过期即变红。发布物不手改——发布入口本就是构建产物,因为 Node 对躺在 `node_modules` 里的 `.ts` 直接拒绝类型剥离。
|
|
160
|
+
- 行为之外还有一族 manifest 门守着发布面(`test/publish-manifest.test.ts`):每个入口目标都要被 `files` 覆盖、宿主包一律不进 `dependencies`、`dsh-*` 精确钉且与 peer 同版本、随包产物里不许出现本机路径与 store 布局、shared 出货产物值导入的宿主包必须由本包提供。`test/dist-size.test.ts` 给产物体积设预算,`test/readme-parity.test.ts` 钉中英两份的结构对等。
|
|
161
|
+
|
|
162
|
+
### 许可
|
|
163
|
+
|
|
164
|
+
MIT,见 [LICENSE](LICENSE)。本插件驱动的 `zg` CLI 属上游 `@zvec/zvec-grep`,许可为 **Apache-2.0**。本包不含上游源码,因此也不随包附其许可文本;若把两者放在一起再分发,请按各自许可分别保留完整声明。
|