@jayyuen66/dsh-zvec-grep 0.1.1 → 0.1.3
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 +87 -0
- package/README.md +22 -152
- package/README.zh-CN.md +165 -0
- package/THIRD_PARTY_NOTICES.md +37 -0
- package/client.js +35 -14
- package/cordis.patch.yml +2 -2
- package/host.js +91 -21
- package/package.json +64 -38
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
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.3
|
|
6
|
+
|
|
7
|
+
修复一处**跟着真实宿主语义失效的作业身份判据**(它让重建轮询恒 404、卸载只杀进程不摘作业 ⇒ 官方环缓冲留在宿主内存),并给 `ignoreFiles` 补上起进程之前的**存在性 + 可读性**预检(一条读不成的忽略文件会永久弄坏整棵工作区索引)。测试面从「单测 + mock 宿主」扩到三层:新增真宿主半栈的集成层与直怼真 zg CLI 的点对点层。
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **作业身份改用投影值,不再比注册表实例引用**。旧 `sameJob` 的一半判据是 `state.owner === ctx.get("jobs")`,而真实 cordis 每读一次服务都新建一枚 traceable 代理 ⇒ 同一枚注册表的两次读也不 `===`,该判据在真实宿主上**恒为假**(mock 上下文里恒真,故单测全绿、线上全崩)。后果有三:轮询端点对每条活着的重建恒回 404;卸载 / 超时臂只 `killProc` 而从不 `jobs.remove` ⇒ 官方环缓冲留在宿主内存里(内存泄露);「同根第二条启动复用在跑那条」的 follow 恒不生效。现改用官方 `JobView` 上三段**值稳定**的投影(`kind` / `label` / `startedAt`)做身份——`JobView` 虽每次新建对象,这三个原始值却跨读恒定。`startedAt` 未盖章时用占位 `0`(官方签的是 `Date.now()`,永不为 0),保证 `start` 同步跑第一拍时不会把同 id 的另一条作业误认成自己的。
|
|
12
|
+
- **`ignoreFiles` 预检补上「可读性」这半段,并与「是否存在」合成一次判定**。原判据只查 `statSync().isFile()`,而它对 mode 000 / 他人属主的文件照样返回 `true`(stat 只要父目录可搜索、不要文件本身可读);真 zg 去 open 它会 `EACCES` ⇒ 整次索引失败并把这条坏路径**写进工作区索引状态**,此后这棵树上的 `zg index` / `zg status` 都报同一个错,`--reset-paths` 清不掉,只有 `zg_index drop` 能救——与「文件不存在」是同一种永久损坏,却漏过了预检。现以 `accessSync(R_OK)` 在前、`isFile()` 在后合成一次 try:`accessSync` 与 zg 的读权限同 uid 同源(root 下两者都放行、非 root 下两者都拒),只查权限位、不读内容,没有 `readFileSync` 那种把大文件整段读进内存的代价。**刻意不拆成「不存在」与「读不了」两条独立分支 / 两句文案**:可读性那一档在 windows(chmod 只翻只读位、属主仍读得了)与 root(绕过 DAC)下造不出文件来触发,拆成独立分支会让 CI 的 windows 那格在 100% 覆盖率门禁下无从而钉(本仓不用 coverage-ignore 逃生口);合成一条 catch 后由跨平台的「不存在」这一档钉住,三种成因(ENOENT / EISDIR / EACCES)共用一句「不是一份存在且当前进程可读的文件」文案。
|
|
13
|
+
- **`drop` 那一臂不再被 `ignoreFiles` 预检误拒**。`--drop` 的命令只有 `zg index <root> --drop --yes`,`ignoreFiles` 被 `buildIndexCommand` 静默丢掉、根本不进 zg(也就无从损坏索引);而预检原先无条件先跑,于是 `drop:true` + 一条坏 `ignoreFiles` 会被「请给一个真实存在的忽略文件」这句误导文案拦下一次合法的删索引。现 `drop` 为真时整段跳过预检,判 `drop` 用与构造器**同一个** `boolOf`,两处口径不漂。
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **`ignoreFiles` 可用性预检(`assertIgnoreFilesExist`)**:模型够得着 `ignoreFiles` 这个参数,而一条读不成的忽略文件会永久弄坏工作区索引,属于必须在起进程之前拦下的那一类。前台索引、模型侧后台索引、设置卡重建这三条起 `zg index` 的路径共用同一道预检(卡片那条不带 `ignoreFiles`,天然空转);`drop` 为真时整段跳过(见上)。三种不可用成因合成一句「不是存在且可读的文件」文案,双语,并写明代价与出路。
|
|
18
|
+
- **测试分三层**。原来只有 `test/*.test.ts`(单测 + 一枚 mock 宿主上下文)。新增:
|
|
19
|
+
- `test/integration/*`:真宿主半栈——官方 cordis `Context` + `dsh-tools` 的 `ToolRuntime`(含 pre-execute 瀑布与官方 JSON Schema 子集校验)+ `dsh-subprocess-local` / `dsh-bash-local` 的本地 bash 执行器(真 spawn / 真 deadline / 真 stdout 上限与 spill / 真凭据擦除)+ `dsh-jobs-local` 的 `LocalJobRegistry`(真环 / 真泵 / 真容量)+ 真 `node:http` 监听的 `dsh-host-webserver` + timer + approval,把插件挂进官方调用管线(`ctx.tools.execute()` / 真 `fetch`)驱动。宿主契约的缺陷都出在这一层:mock 上下文只会同意本包已经相信的事(`ctx.get("jobs") === ctx.get("jobs")` 在替身里恒真、真实 cordis 恒假,正是上面那条 Fixed 的成因)。
|
|
20
|
+
- `test/e2e/zg-cli.test.ts`:既无插件也无替身,只把 `lib/cli.ts` 造出的命令行喂给**真 zg CLI**,钉它的旗标面、输出形状、错误码,以及「坏 `ignoreFiles` 会弄坏整棵树」这类上游事实(含 ENOENT 与 EACCES 两档)。
|
|
21
|
+
- **两层按环境 gate,而非无条件跑**:真-zg 的 integration + e2e 整体 `describe.skipIf(!zgAvailable())`——CI 的干净 runner 没装真 zg,硬跑会以「command not found」变红而不是跳过;本机装了 zg 才跑。本包自己的判据另由 `test/host.test.ts` 的 mock 宿主独立钉到 100%(`assertIgnoreFilesExist`:drop 跳过 / 不存在 / 读不了 / 放行,绝对与相对两种写法都覆盖),所以这两层在 CI 跳过后覆盖率不塌;「读不了」那档再按 `canMakeUnreadableFile()`(root 或 windows 造不出属主读不了的文件)单独跳过,也不依赖它保覆盖率。
|
|
22
|
+
- 两份 README 各补一段「测试分三层」的说明。
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- `devDependencies` 补 `@deepseek-ai/dsh-bash-local` / `dsh-http-proxy` / `dsh-subprocess-local` / `dsh-timeout`(真宿主台架的传递依赖,均**不进** `dependencies`)。
|
|
27
|
+
- `pnpm-workspace.yaml` 的 `allowBuilds` 把 `@deepseek-ai/dsh-subprocess-local` / `koffi` / `node-pty` 显式记为 `false`。这三枚是集测台架经 `dsh-subprocess-local` 传递引入的原生模块(各带安装脚本),而 pnpm 12 默认拦截未声明的构建脚本 ⇒ CI 那步 `pnpm install --frozen-lockfile` 以 `ERR_PNPM_IGNORED_BUILDS` 退出 1(本机因 `.modules.yaml` 早记下 ignoredBuilds 决定反而不报)。但本包根本用不到它们的构建产物:`dsh-subprocess-local` 经 `dsh-lazy-require` 惰性加载 `node-pty` / `koffi`,集成用例走的是 bash 执行路径、从不 require(本机 `.modules.yaml` 记的正是 ignoredBuilds,600 用例照绿)。显式 `false` 让 pnpm 跳过构建且不计入 ignoredBuilds(源码实测:唯有 `allowBuild()` 返回 `undefined` 的未声明档才报错),CI 也因此不必为用不到的原生模块在 windows 那一格背上 node-gyp 编译。`esbuild: true` 那条不动(vite 传递引入,确实要它落平台二进制)。
|
|
28
|
+
- `oxlint.config.ts` 的 `syncWrites` 声明 `chmodSync`(用例造 mode 000 的不可读忽略文件)与 `accessSync`(只读权限探针;共享基线的只读豁免表恰好没收录它,故经本包这唯一的 sync 例外口子声明)。
|
|
29
|
+
|
|
30
|
+
## 0.1.2
|
|
31
|
+
|
|
32
|
+
宿主生态跟到 `0.2.1-alpha.2`,并把一处**跟着宿主变更而失效的安全判据**改回可用。这一版还补上了发布面与装载面的门禁,以及中英两份 README。
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- **`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。
|
|
37
|
+
- **装载期缺包**。`@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`**。
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- `@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。
|
|
42
|
+
- `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 比声明还旧,锁文件已过期)。
|
|
43
|
+
- `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 已按实测写明。
|
|
44
|
+
- README 拆成中英两份:`README.md` 为英文、`README.zh-CN.md` 为中文,两份顶部互链。原来是一份文件里的 `## 中文` / `## English` 两段,正文一字未改地按语言切开。
|
|
45
|
+
- 注释里「钉进依赖 `.d.ts` 的行号」全量换成文件 + 符号/原文锚点。抽查即见腐坏:`dsh-tools` 那组(`ToolDefinition` / `ToolGuard` / `ToolRuntime`)随 alpha.2 整体漂了 7–17 行,`tool.execute` 的调用点也是。测试夹具里的 `src/beta.ts:1-3` 那类是 **数据**(zg 的输出形态),不在射程内。
|
|
46
|
+
- `.github/workflows/publish.yml` 跟 `dsh-danger-guard` 同款加固:`concurrency` 防两次 dispatch 并行、action 钉 commit SHA、预检加「读本包」这一档(只查依赖就发现不了「版本号没进 main 就触发」)、发布用的 `NODE_AUTH_TOKEN` 走与预检同款清洗、加 `--provenance` 与 `--publish-wait-timeout 600000`,并且不再把凭据长度打进日志。
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
- 新增 `.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` 随包且在。上一轮那两起「全绿但装出去炸」的故障,判据只能落在这里。
|
|
51
|
+
- `test/publish-manifest.test.ts` 的门禁集合补齐:
|
|
52
|
+
- `ALWAYS_SHIPPED` 改成实测清单。旧集合把 `CHANGELOG.md` 也算成「npm 无条件附带」,于是门禁比 npm 的真实语义更宽松、自己先失效。实测办法:包根临时放一份 `CHANGELOG.md` 与一份 `THIRD_PARTY_NOTICES.md` 且不写进 `files`,`npm pack --dry-run` 只回 `package.json`、`README*`、`LICENSE`。
|
|
53
|
+
- 注释禁面加**本机绝对路径**(`/Users/…`、`/home/…`):注释里的举例路径会被打包器原样搬进随包发布的产物,那是把本机用户名发到公共 tarball 的路。
|
|
54
|
+
- 「包根的每一份 `.md` 都必须在发布面里」——一次性封住「新增文档忘了写进 `files` ⇒ 静默不随包分发」这一类,而不是每加一份补一条断言。
|
|
55
|
+
- 产物面内部指涉扫描(本机绝对路径、`node_modules/.pnpm/` 内容寻址布局)。注释门读不到产物,因为 rolldown 剥注释;而 `//#region` 标记里的路径恰恰会进产物。
|
|
56
|
+
- `shapeOf` 精确文件名条目的回归防线:把 `host.js` 误读成「收所有 `.js`」会让 `files` 覆盖那道断言的集合虚高,而它对失效毫无反应。
|
|
57
|
+
- 「shared 出货产物值导入的宿主包,本包一律在 peer ∪ dev 里提供」——判面取**产物**而非 shared 声明的 peer 全集(纯类型面的成员本包不引就不该钉)。
|
|
58
|
+
- `test/dist-size.test.ts`:产物体积预算闸(host 半 240,000 B、client 半 54,000 B,取实测值上浮约 25%)。体积不是行为,不会让任何现有用例变红,所以得单独有把尺子。刻意不开 minify:压缩后产物里的跨包说明符字符串会消失,而「依赖必须外部化」那几条断言正是靠检索这些字符串来判的。
|
|
59
|
+
- `test/readme-parity.test.ts`:中英两份 README 的骨架对等门(标题层级序列、首行包名、顶部互链三处)。一侧加了节而另一侧没跟,不会有任何用例变红。
|
|
60
|
+
- `build-client.mjs` 产出前把 `//#region` 标记里的 pnpm 内容寻址段折成普通的 `node_modules/` 一层。client 半必须把 shared 的 `record.js` / `errors.js` **内联**(浏览器解析不了裸说明符),于是标记里烙着依赖版本与本机 store 哈希:既外泄安装布局,又让同一份源码在不同机器上产出不同字节。
|
|
61
|
+
- `.gitattributes`(`* text=auto eol=lf`):Windows runner 上 Git for Windows 的机器级 `core.autocrlf=true` 会把工作树换成 CRLF,而 oxfmt 的 `endOfLine` 默认 lf —— 没有这份文件,新加的 windows 那一格会把每个文件都判成未格式化。
|
|
62
|
+
- `scripts.fmt`(`oxfmt .`),与既有的 `fmt:check` 配对。
|
|
63
|
+
- npm 发布元数据补齐 `keywords` / `bugs` / `homepage`(对照 plugin-shared 实测缺这三项)。`sideEffects: false` **不**照抄:client.js 是往 `window.__ModuleLoader__` 注册,属于真实副作用,标 false 等于授权打包器把它摇掉。新增「发布元数据面」两道门:description/keywords/license/author 齐备,以及 repository / bugs / homepage 三处按 `<账号>/<仓库>` 归一后必须同源——抄兄弟包的这一段再只改一处是必然会犯的错,那样 npm 页面上的「报告问题」会跳到别人的仓库。
|
|
64
|
+
- 上游归属信息(本包是在第三方 `@zvec/zvec-grep` 之上做二次开发):两份 README 的「外部依赖」一节写清上游包名、仓库、**Apache-2.0** 许可、`0.2.2` 版本契约,以及「本包不含上游代码、不替上游分发」这条边界;新增 `THIRD_PARTY_NOTICES.md` 并写进 `files`(实测 npm 不自动附带 NOTICE 类文件,漏写等于没随包分发);新增「开发」与「许可」两节,与 dsh-ocr-review 的双语 README 骨架对齐。
|
|
65
|
+
|
|
66
|
+
## 0.1.1
|
|
67
|
+
|
|
68
|
+
评审收口:索引重建、宿主版本门与远程 embedding 的边界。
|
|
69
|
+
|
|
70
|
+
### Added
|
|
71
|
+
|
|
72
|
+
- 后台重建作业走官方注册表(`ctx.jobs`):环、留存、容量与生命周期都在宿主侧,本包不再自带并发上限;模型侧 `job_list` / `job_output` / `job_kill` 因此看得见这次重建。
|
|
73
|
+
- 索引版本门(`lib/zg-version.ts`)与 zg 错误分类(`lib/zg-errors.ts`)、重建状态盒(`lib/rebuild-state.ts`)。
|
|
74
|
+
- 远程 embedding 的开关与端点/凭据来源边界,缺席即明确报错而不是静默降级。
|
|
75
|
+
|
|
76
|
+
## 0.1.0
|
|
77
|
+
|
|
78
|
+
`@jayyuen66` 作用域下的第一个发布版本。
|
|
79
|
+
|
|
80
|
+
### Changed
|
|
81
|
+
|
|
82
|
+
- 索引根判据改认 `manifest.json`,修掉「全局 home 被当成索引根」导致的门禁误判。
|
|
83
|
+
- 发布凭据改走 `NODE_AUTH_TOKEN`(`setup-node` 配了 `registry-url` 之后 npm 只读它自己生成的那份 `.npmrc`,`$HOME/.npmrc` 会被完全忽略)。
|
|
84
|
+
|
|
85
|
+
### Earlier
|
|
86
|
+
|
|
87
|
+
`0.1.0` 之前那段(`@jayyuen666` 作用域、`0.3.1`、作用域迁移那次误发的 `1.0.0`)压进了本仓的第一条提交记录,要旨逐条写在那条 message 里——早期那几枚提交号已随这次历史重写失效,别再按 SHA 去找。npm 上那几个已发布的版本号则永久留存,不随仓库历史回收。
|
package/README.md
CHANGED
|
@@ -1,154 +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 组,单条 <= 4000 字符)。
|
|
33
|
-
- 可加 globs / insensitiveGlobs / fileTypes / excludedFileTypes / symbolTypes / preferSymbol / modifiedAfter / modifiedBefore / fuse / limit / preview / refresh / device。
|
|
34
|
-
- `globs` / `insensitiveGlobs` / `fileTypes` / `excludedFileTypes` 既收**单个字符串**也收字符串数组(与上游 zg 对这几项的对外契约一致,最多 128 项、单项 <= 1024 字符)。
|
|
35
|
-
- `symbolTypes` 绑定 zg 的真实闭集,取值**只认小写**:`module` / `class` / `interface` / `function` / `value` / `alias`。zg 侧 `--symbol-type Class` 会以非零码退出(`Unsupported symbol type: Class`),插件在构造命令前就拦下并列出合法取值;不做大小写折叠——悄悄改成小写等于替模型改了它没写的约束。
|
|
36
|
-
- `preview` 三档:`none` 只给锚点行 / `short` 锚点加一段有界上下文 / `full` 整段源码,**默认 short**,每条命中自带有界源码片段。
|
|
37
|
-
- `refresh` 三档:`wait` 等索引刷到最新(**默认**)/ `off` 不刷新 / `background` 交给守护进程后台刷新。`background` 只在守护进程模式下成立:直连模式下 zg 不报错,而是降级成 `off` 并往 stderr 打一行 `warning: --refresh background requires Server mode; Direct mode uses --refresh off`——本包把 stderr 原样回显,那一行会自己到模型眼前。
|
|
38
|
-
- 输出尾部附一行**命中摘要**,两栏口径分开给:`分组计数合计`(各查询组 `hits:` 之和)与`去重后 N 个不同位置`(按「相对路径 + 行号范围」去重)。分栏是因为同一处代码会被多组各命中一次(名次与匹配来源逐组变化),直接求和会把同一处位置重复计入、冒充命中总数。
|
|
39
|
-
- 某组命中数正好等于 `--limit` 时只作**观察陈述**并显式说明「zg 不提供截断信号,此处不作断言」——zg 的输出没有任何截断标记,不能把"可能还有未显示的命中"说成事实。输出被宿主按 stdout 上限截尾时另附「只含保留部分」。
|
|
40
|
-
- zg_index:confirm 必填且必须为 true(required 校验 + guard 双层拒绝)。
|
|
41
|
-
- `background=true` 走**模型侧后台索引**:一次调用把「起 zg 进程 + 登记进官方作业注册表 + 挂超时回收」全做完,把可轮询的作业号交回后**立即返回**。建索引可能要下载 embedding 权重、等很久,后台执行免得工具调用一直挂着。
|
|
42
|
-
- 不依赖宿主作业工具:宿主作业工具在 web 平面已停用,模型侧那条路根本不可走。插件复用与设置卡**完全相同**的 spawn/登记/占位三步(同一个函数,不是复制品),所以两条入口起的作业在名册、状态投影、轮询端点上完全同形——卡片能看见模型起的索引,反之亦然。
|
|
43
|
-
- 占位与设置卡的重建互斥,且跨入口成立:同根已在跑索引写时,模型侧与卡片侧都只会跟随那一条,不会各起一条 zg 去啃同一份索引。
|
|
44
|
-
- 官方作业注册表缺席时**根本不起进程**并直接报错:起一条没有环、没有容量、也没人能收的 zg 比不起更糟——它会一直占着同根的写锁,把这棵树的后续索引全堵死。
|
|
45
|
-
- 落定前该根的语义检索会等它完成再自动重试,期间 grep/rg 不受门禁限制。
|
|
46
|
-
- 另有 embedding / rebuild / drop / resetPaths / globs / insensitiveGlobs / fileTypes / excludedFileTypes / ignoreFiles / excludeSecrets / hidden / noIgnore / maxDepth / maxFileSizeBytes / follow / embeddingConcurrency / device;其中五个路径过滤项同样收单值或数组。
|
|
47
|
-
- 切换 embedding 必须 rebuild=true 才生效。
|
|
48
|
-
- **显式 embedding 走构造期 allowlist**:只接受本地候选清单(与设置卡下拉同一份)里的模型,其余引用在命令构造前就被拒并给出可行动文案。理由是能力面的性质——远程 embedding 会把工作区内容送到外部端点,而模型能凭空写出一个任意前缀的引用;这是「工作区内容会不会被送出本机」的闸门,只能由用户在部署配置里开(见部署值一节)。
|
|
49
|
-
- `resetPaths=true` 透传 `--reset-paths`,清掉这个根**继承来的**文件选择设置(globs/fileTypes/hidden/…)。它与 globs/fileTypes **不互斥**(上游是先清、再按本次请求盖上去),与 `drop` 互斥(构造期直接拒,不静默丢弃)。
|
|
50
|
-
- zg_status:root + checkReady,用于索引缺失/失败/取消后的诊断或显式看进度。
|
|
51
|
-
- `checkReady=true` 透传 `--check-ready`。注意它的真实契约:**就绪报告照常打在 stdout,只用退出码表达就绪与否**。所以未就绪不是执行失败,插件把报告原样交回,另附一行「索引未就绪……这不是执行失败,而是 checkReady=true 要的那个结论」并带上 zg 的原始判据。走普通失败路径只会留下 stderr 那一句,恰好把用户最需要的报告扔掉。
|
|
52
|
-
- 报告为空时的非零退出仍按失败抛,不凭空造一份报告;未开 `checkReady` 时非零退出照旧抛错。
|
|
53
|
-
- 与后台重建作业状态整合:同根正在重建时(作业已登记)直接给重建投影,**不启子进程**——此刻「索引是否就绪」的答案本就是否定的,报一个 `not ready` 反而不如直接告诉它「重建中,作业 X,落定后再问」。
|
|
54
|
-
- **无索引时的首选路径**:`zg_search` 带 `rg` 开关走 zg 的穷举词法通道(`zg query --rg`),不需要索引。
|
|
55
|
-
- `rg` 留空(缺省):工作区**及其向上各级**都没有索引时自动改走穷举检索,有索引则照常走索引检索。自动改道会在结果前加一条前置声明,说明「这是逐行字面匹配,不是语义相关度排序,需要语义检索请先 zg_index」——不声明就等于把与请求不符的答案当成语义结论递出去。
|
|
56
|
-
- `rg=true` 强制穷举;`rg=false` 拒绝改道,只用索引检索(无索引时由 zg 报 `WORKSPACE_INDEX_NOT_FOUND` 并附建索引提示)。
|
|
57
|
-
- 穷举检索**不发放** grep/rg 配额:它不读索引,不构成「先用过语义检索」的证据。有索引的工作区想用 grep/rg,仍要先走一次索引检索。
|
|
58
|
-
- 穷举通道的合法旗标与索引通道不同。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` 照常生效。
|
|
59
|
-
- 穷举输出没有 `hits:` 计数行,故命中摘要按「不数就不谎称」自动不出。
|
|
60
|
-
- `trace` 透传 `--trace`(排障用):每条命中附一行检索轨迹,说明它被哪几路召回、在各组里的名次,并给出分值。输出会明显变长;穷举模式不支持该参数(构造阶段即拒绝)。
|
|
61
|
-
- 开 `trace` 时条目头行会多出 `score=` 与选择理由标记;命中摘要的**去重键会剥掉这两段**——实测同一处位置在两个组里分值可以不同(`src/beta.ts:1-2` 在 fts 组是 0.0164、在 vector 组是 0.0161),带分值入键会让每条命中都成「新位置」,去重直接失效、位置数虚高一倍。
|
|
62
|
-
- 三者的 root 都可省略(缺省=当前会话工作区);输出为纯文本;超时分别为 5 分钟 / 10 分钟 / 60 秒,stdout 上限 400000 字节(超限截尾并提示)。
|
|
63
|
-
|
|
64
|
-
### 设置项与检索根
|
|
65
|
-
|
|
66
|
-
- 命名空间 `zvec-grep` 由宿主**隐式**注册(0.1.7 起 = profile 条目 id,插件侧不再有 `settings.register`);schema 共十四个字段,其中卡上那六枚标 `.volatile()`,内置默认逐字段写在 `.default()` 上。
|
|
67
|
-
- defaultEmbedding=local/qwen3-embedding-0.6b、defaultLimit=10(1-50)、hfEndpoint=国内可达的 HF 兼容镜像基址(可改成别的镜像或留空走官方 HF)。
|
|
68
|
-
- enforceSearchFirst=true、grepBudgetPerSearch=3(1-20)、unlockWindowMin=10(1-240)。
|
|
69
|
-
- 另有**非 volatile 部署值**(不进设置卡,只在 cordis.yml 的行 config 里改值;上面工具一节的「5 分钟 / 10 分钟 / 60 秒 / 400000 字节」就是它们的默认):searchTimeoutMs=300000、statusTimeoutMs=60000、indexTimeoutMs=600000(也是后台重建 kill 定时器的时长)、stdoutMaxBytes=400000、clientMode=auto、rebuildWaitMs=120000,超时/缓冲几项均最小 1。
|
|
70
|
-
- 远程 embedding 三件套,默认**全关**:`allowRemoteEmbedding=false`、`remoteEmbeddingEndpoint=""`、`remoteEmbeddingApiKeyFrom=""`。
|
|
71
|
-
- 关着的时候,显式 embedding 引用在**命令构造期**就必须落在本地候选清单里。
|
|
72
|
-
- 打开后端点与凭据**只经环境变量**下发给 zg 子进程(`ZVEC_GREP_ENDPOINT` / `ZVEC_GREP_API_KEY`),**绝不进 argv**——本包把整条命令当作业 label 回显给卡片,argv 里的密钥会进界面、进日志、进 `ps` 的进程表。
|
|
73
|
-
- 凭据那项填的是**宿主进程里那个装凭据的环境变量名**(如 `ZVEC_GREP_API_KEY`),不是密钥本身:宿主 subprocess 层会把名字含 KEY/SECRET/TOKEN 的继承变量剔掉,必须由本插件显式转发才到得了 zg;只记名字也让密钥不必落进插件配置文件。
|
|
74
|
-
- 本插件**不自动传 `--allow-remote`**:zg 还要用户自己跑一次 `zg auth grant <root> --capability embedding --scope workspace` 才肯发请求,那道按 root 的授权本插件不代劳。
|
|
75
|
-
- `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 即便「用户已批准」照旧被拒。
|
|
76
|
-
- 优先级:设置里的运行时值 > 组合包层/用户层行的 config > schema 的 `.default()`;行 config 中显式缺省的字段不覆盖默认。读侧是 `config.<field>.get()`(volatile 引用,卡上改完下一个事件即生效);非 volatile 部署值是普通值形态,不经 `.get()`。
|
|
77
|
-
- root 校验:必须是以 `/` 开头的绝对路径,词典归一折叠空段与 `.`。
|
|
78
|
-
- 拒绝空串、非字符串、含 NUL、相对路径、越出文件系统根的 `..`,归一后为 `/` 也拒。
|
|
79
|
-
- 目录不存在时单报「root 目录不存在」,不冒成 spawn ENOENT。
|
|
80
|
-
- guard 与 execute 用同一套 root 判据,避免「guard 放行、execute 抛错」说两遍。
|
|
81
|
-
- 解锁按「会话 × 索引根」计:每次成功 zg_search 重置为 grepBudgetPerSearch 次、unlockWindowMin 分钟有效;索引根是 root 自身或含索引的最近祖先(最多上溯 8 层)。
|
|
82
|
-
- 分片用的会话是**根会话**:沿 `header.parentSession` 一路上溯到最顶层那一跳。故同一棵委派树上的主代理与子代理**共享一份额度**——主代理搜过一次,子代理随即就能用那几次 grep/rg,不必各自再搜一次(它们搜的往往是同一棵树)。
|
|
83
|
-
- 上溯的降级是三级的,都不抛错:自身即顶层就用自己;某一跳查不到它的父(会话已落定,或宿主没装会话存储)就停在**已知的最后一跳**;链成环就停在首次重复前。跳数有上限。
|
|
84
|
-
- 「含索引」的判据是 `<root>/.zvec-grep/manifest.json` 在盘上,**只判 `.zvec-grep` 目录名不够**:这个名字同时是 zg 自己的全局 home(`ZVEC_GREP_HOME ?? ~/.zvec-grep`,装的是 config.json / locks / models),只判目录名会让一个从未建索引、只是祖先目录撞名的普通工作区也被门禁拦下。
|
|
85
|
-
- enforceSearchFirst=false 只关掉门禁,zg_* 的安全兜底(confirm、root 判据)不受影响。
|
|
86
|
-
|
|
87
|
-
### 外部依赖(rg)
|
|
88
|
-
|
|
89
|
-
- 真正的二进制依赖是 zg(由 `npm install -g @zvec/zvec-grep` 提供):不在 PATH 时 shell 回 exit 127,工具据此回「zg 未安装或不在 PATH」,与「沙箱 runner 没起来」分开归因。
|
|
90
|
-
- 本地 embedding 由 zg 侧后端加载:qwen3/embeddinggemma 走 llama-cpp(device=auto 时试 Metal、失败回退 CPU),potion-* 走 model2vec,其余走 transformers-js 纯 JS。
|
|
91
|
-
- 权重按 hfEndpoint 注入 HF_ENDPOINT 后下载。
|
|
92
|
-
- 本包不依赖也不调用 ripgrep:rg 只出现在门禁判据里。
|
|
93
|
-
- bash/pwsh 命令串经引号/注释感知切词后,命令位上的 grep/egrep/fgrep/rg 与原生 grep 工具才算检索。
|
|
94
|
-
- `--help`/`--version`/`-V`、`echo "grep x"`、`git commit -m "use rg"` 不算。
|
|
95
|
-
- 有沙箱执行器时会区分 runner 失败、策略拒绝与 zg 自身失败,并在结果里显式打「可能不完整」标记。
|
|
96
|
-
|
|
97
|
-
### 对外接口
|
|
98
|
-
|
|
99
|
-
- 三条路由的 handler 第一句都是 `guardTrust(req, res, { servingNonLoopback })`(`shared/lib/trust`),任一判据不过即 `403` + `{ ok:false, error: ... }`。
|
|
100
|
-
- 判据次序:Host 权威 → `sec-fetch-site` 白名单 → `origin` 与 Host 逐字比对;两句错误文本是 `"untrusted host authority"` 与 `"cross-origin request rejected"`。
|
|
101
|
-
- `servingNonLoopback` 只取 `webServer.host === "0.0.0.0"`;非本方法的 `405` 带 `Allow` 与 `{ ok:false, error:"GET only" | "POST only" }`,不再是空回显。
|
|
102
|
-
- `GET /_dsh/zvec-grep/rebuild-roots`:只回本包自己的数据(每次 apply 重新生成的 CSRF token + 已观测工作区列表),允许 GET/HEAD,过不了上面那道闸门即 403。
|
|
103
|
-
- `POST /_dsh/zvec-grep/rebuild?root=...`:闸门 + 头 `x-zvec-grep-csrf` + body <= 4096 字节 + root 命中白名单 + 目录存在,成功回 `{ ok, jobId }`;否则 405/403/400/500。
|
|
104
|
-
- `/_dsh/zvec-grep/rebuild-status?jobId=...`:闸门后轮询(卡片每 2 秒一次),回 status/exitCode/root/output(有沙箱时带 sandbox),未知 jobId 回 404 并说明多半是出了本包那条 10 条落定窗口。
|
|
105
|
-
- 另有 systemPrompt 段 `zvec-grep-routing`(order 1550)与 settings 命名空间 `zvec-grep`。
|
|
106
|
-
- 白名单只记本 daemon 真实观测到的会话工作区,容量 64(超出按插入序淘汰)。
|
|
107
|
-
- 同时能跑几个重建由**宿主注册表**决定(实测默认未拥有桶 10),本包不再自带并发上限;
|
|
108
|
-
满员时 `POST /rebuild` 直接回 500 并带上官方的点名文案,**不会**再杀掉已经在跑的重建。
|
|
109
|
-
- `rebuild-status` 的 `jobId` 只在本包侧表里查得到:本包保留最近 10 条**已结束**的记录
|
|
110
|
-
(超出即从注册表 remove ⇒ 404),进行中的记录永不被动。
|
|
111
|
-
|
|
112
|
-
### 后台作业面(官方 `ctx.jobs`)
|
|
113
|
-
|
|
114
|
-
本包不自带任务注册表了:一次「工作区重建」是宿主 `ctx.jobs` 里的一枚**未拥有**作业
|
|
115
|
-
(`kind: "zvec-grep-rebuild"` ⇒ id `zvec-grep-rebuild-N`)。这带来三件看得见的变化:
|
|
116
|
-
|
|
117
|
-
| 面 | 事实 |
|
|
118
|
-
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
119
|
-
| 模型侧能看见了 | 官方 `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` 那一瞬挂、摘掉即恢复官方拒绝(见跨包纪律) |
|
|
120
|
-
| 未拥有 ⇒ 对全部会话可见 | 官方件按 owner 隔离,未拥有作业任何 caller 都能 `list`/`read`/`kill`。这是本波**已知并接受**的暴露面(卡片是会话外的 webServer 生产者,受有作业则要 `dsh-agent` 注册表,实测不可得)。要收回去只有一条路:回滚这次换装。注意 `/_dsh/zvec-grep/rebuild-status` 仍只认本包侧表里的 id,别人的作业(如宿主的 `bash-1`)经这个端点读不到 |
|
|
121
|
-
| 多了两个状态词 | `stopping`(取消已发出、进程还没收完 ⇒ 卡片按「仍在跑」显示)与 `failed`(注册表侧判定失败 ⇒ 给专门文案,不显示成「退出码 null」) |
|
|
122
|
-
|
|
123
|
-
不留存的东西也写清楚:输出环按 **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` ⇒ 卡片会进终止态并停轮询,那条还在跑的重建就再也看不见)。
|
|
124
|
-
|
|
125
|
-
### 数据与隐私
|
|
126
|
-
|
|
127
|
-
- 索引的唯一落盘形状是被检索 root 下的 `.zvec-grep/` 目录,由 zg 写入(read-only 沙箱下写不了它,会明确报索引可能不完整)。
|
|
128
|
-
- 重建有两条路:模型侧 `zg_index`(rebuild=true、confirm=true),或设置卡「工作区重建」走上面的 rebuild 路由;删除是 `zg_index` drop=true(拼成 `zg index <root> --drop --yes`)。
|
|
129
|
-
- 本包自身不写任何文件(唯一的 fs 调用是索引探测:existsSync + 读一次清单),也不向宿主数据目录 `$DSH_HOME`(`<dsh 数据目录>`)落数据。
|
|
130
|
-
- 索引探测不只判「`.zvec-grep/manifest.json` 在不在」:还要**解析清单**并确认它的 `rootPaths` 真的覆盖这个目录。两种实况会被「只判存在」误判成有索引,而实际检索必然失败——文件在但不是一份清单(半截写入/同名占用),以及清单在但根路径指向别处。此时门禁若还按「已建索引」拦着 grep/rg,就等于把检索与门禁双向堵死。
|
|
131
|
-
- 认的结构只有 `manifestVersion`(**严格等于 1**)与 `rootPaths`(非空数组、每项带非空 `absolutePath`)两处——版本不等时上游读它会直接抛 `MANIFEST.INVALID`,此时这个目录一次检索都做不了,宽松放行只会把用户卡在「门禁拦着、检索又必失败」的死角里。刻意不校验 embedding / policy 等字段——那些变了索引照样能用,判成「无索引」反而是错的。
|
|
132
|
-
- 覆盖判据是归一后相等;macOS 上清单里写的是**未解析**路径(`/tmp/x`)而 `path` 字段才是解析过的(`/private/tmp/x`),故两边都再剥一次 `/private` 前缀再比,两种写法都能对上。
|
|
133
|
-
- 白名单/解锁表都在内存、有界,且淘汰策略与语义相符:**命中即触摸**(挪到队尾),淘汰时先按**有效期**丢过期项、再按**最近使用**丢最冷的一条到上限之内——不是按插入序。纯插入序对一张「每次成功检索都重置同一批键」的表等于不淘汰:真正冷掉的项永远留着,而很久没被碰过的键一直占位。白名单条目另有一条有效期(一天),一个月前顺手开过的一个目录不该今天还占名额。容量上界(白名单 64 条 / 会话分片 256 个)保持不变,故常驻内存依旧有界。
|
|
134
|
-
- 重建**作业本体**住在宿主注册表里(见上一节),插件卸载时本包侧表随 effect 回收、在跑的作业经注册表 kill 掉。
|
|
135
|
-
- 默认不进索引的:`*.pem` / `*.key` / `*.p12` / `*.pfx` / `*.keystore` / `id_rsa*` / `id_ed25519*`(excludeSecrets=false 可关)。这些规则按**大小写不敏感**匹配,`Server.PEM` 同样被排除;且排在用户自己的路径规则之后生效,用户写一条宽泛的正向规则也覆盖不掉它们。
|
|
136
|
-
- 残留缺口:**无扩展名**的密钥文件(如 `myprivatekey`、`rsa_private`)扩展名规则覆盖不到,`id_rsa*` / `id_ed25519*` 只覆盖 OpenSSH 默认命名;这类文件请走 ignoreFiles(`--ignore-file`)显式声明。
|
|
137
|
-
- 隐藏文件默认不收,ignore 文件默认生效(noIgnore 可关)。
|
|
138
|
-
- 本包只在本机拼 zg 命令并透传输出,不上传代码。
|
|
139
|
-
- 唯一的外连是 embedding 权重按 hfEndpoint 下载。
|
|
140
|
-
- 结果回显有界:stdout 超限截尾(有 spill 路径会给出)、stderr 尾部 400 字符一并回显,免得「退化成纯词法」被当成完整语义结果。
|
|
141
|
-
|
|
142
|
-
### 常见问题
|
|
143
|
-
|
|
144
|
-
- grep/rg 被拒且提示「尚未执行过 zg_search」:这是 search-first 门禁,先 zg_search;配额用尽或过期同理,换个更准的 query/fts 重搜即可续上,不必关插件。
|
|
145
|
-
- 检索超时:默认 `--refresh wait` 会同步刷新既有索引,大工作区请用 globs/fileTypes 缩小范围或调小 limit,也可先手写字面检索。
|
|
146
|
-
- 重建按钮回 403「root 不在本 daemon 观测到的工作区白名单内」:该目录从未在本 daemon 开过会话;先在该目录起会话,或让模型带 confirm=true 调 zg_index。
|
|
147
|
-
- 卡片显示重建失败而 zg 看着像跑完了:成功判据是 completed 且 exit 0——exit 127(zg 没装)也落在 completed,看输出尾部原因。
|
|
148
|
-
- 从未建索引的 root:zg_search 明确报错而不是静默建索引;建索引只在用户明确要求时由 zg_index 做。
|
|
149
|
-
- 换了 embedding 却搜不到语义结果:切换 embedding 必须 rebuild=true 重建后才生效。
|
|
150
|
-
|
|
151
|
-
## English
|
|
3
|
+
[English](./README.md) · [简体中文](./README.zh-CN.md)
|
|
152
4
|
|
|
153
5
|
### What it does
|
|
154
6
|
|
|
@@ -163,13 +15,17 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
|
163
15
|
```
|
|
164
16
|
|
|
165
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).
|
|
166
|
-
- 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.
|
|
167
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`.
|
|
168
22
|
|
|
169
23
|
### Enabling it in dsh
|
|
170
24
|
|
|
171
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.
|
|
172
|
-
-
|
|
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.
|
|
173
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).
|
|
174
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: …)`).
|
|
175
31
|
- The guard inside apply is the second layer: a malformed ctx throws `required services … missing`.
|
|
@@ -238,6 +94,8 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
|
238
94
|
### External dependency (rg)
|
|
239
95
|
|
|
240
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.
|
|
241
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.
|
|
242
100
|
- Weights are downloaded with HF_ENDPOINT injected from hfEndpoint.
|
|
243
101
|
- This package neither depends on nor calls ripgrep: rg appears only in the gate predicate.
|
|
@@ -249,7 +107,7 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
|
249
107
|
|
|
250
108
|
- Every handler opens with `guardTrust(req, res, { servingNonLoopback })` (`shared/lib/trust`); failing any leg yields `403` with `{ ok:false, error: ... }`.
|
|
251
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"`.
|
|
252
|
-
- `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.
|
|
253
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.
|
|
254
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.
|
|
255
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.
|
|
@@ -297,3 +155,15 @@ What is not retained, stated plainly: the output ring keeps **UTF-8 bytes** (mea
|
|
|
297
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.
|
|
298
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.
|
|
299
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
|
+
- Tests come in three tiers. `test/*.test.ts` (unit + a mocked host context) pins this package's own pure logic; `test/integration/*` boots **real** host services (`dsh-tools` ToolRuntime, `dsh-subprocess-local` + `dsh-bash-local`, `dsh-jobs-local`, `dsh-host-webserver` over real HTTP, the timer and approval services) and drives the plugin through `ctx.tools.execute()` / actual `fetch`; `test/e2e/zg-cli.test.ts` has no plugin and no mock at all - it feeds the commands `lib/cli.ts` builds to the **real zg CLI** and pins its output shapes, error codes and flag surface. The middle tier is where host-contract bugs surface: a mocked context can only agree with what this package already believes (e.g. `ctx.get("jobs") === ctx.get("jobs")` holds for a mock but is false in real cordis, which reads a service through a fresh traceable proxy per call).
|
|
162
|
+
- `npm run check` is the single gate to run before publishing: typecheck (both tsconfigs) + `oxlint` + rebuild both bundles + `vitest run --coverage` + `oxfmt --check`.
|
|
163
|
+
- 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.
|
|
164
|
+
- `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`.
|
|
165
|
+
- 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.
|
|
166
|
+
|
|
167
|
+
### License
|
|
168
|
+
|
|
169
|
+
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,165 @@
|
|
|
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
|
+
- 测试分三层。`test/*.test.ts`(单测 + mock 宿主上下文)钉本包自己的纯逻辑;`test/integration/*` 起**真**宿主服务(`dsh-tools` 的 ToolRuntime、`dsh-subprocess-local` + `dsh-bash-local`、`dsh-jobs-local`、真 HTTP 的 `dsh-host-webserver`、timer 与 approval),把插件挂进官方调用管线(`ctx.tools.execute()` / 真 `fetch`)驱动;`test/e2e/zg-cli.test.ts` 既没有插件也没有替身,只把 `lib/cli.ts` 造出的命令行喂给**真 zg CLI**,钉它的输出形状、错误码与旗标面。宿主契约的缺陷都出在中间那层:mock 上下文只会同意本包已经相信的事(例如 `ctx.get("jobs") === ctx.get("jobs")` 在替身里恒真,而真实 cordis 每次读服务都新建一枚 traceable 代理,该等式恒假)。
|
|
158
|
+
- `npm run check` 是发布前的一条门:typecheck(两侧 tsconfig)+ `oxlint` + 重建两个 bundle + `vitest run --coverage` + `oxfmt --check`。
|
|
159
|
+
- 覆盖率按**全局 100% 阈值**跑(stmts/branches/funcs/lines):任何一行或分支没被用例钉住,套件当场红——这是本仓的既定质量门,不是巧合。
|
|
160
|
+
- `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` 直接拒绝类型剥离。
|
|
161
|
+
- 行为之外还有一族 manifest 门守着发布面(`test/publish-manifest.test.ts`):每个入口目标都要被 `files` 覆盖、宿主包一律不进 `dependencies`、`dsh-*` 精确钉且与 peer 同版本、随包产物里不许出现本机路径与 store 布局、shared 出货产物值导入的宿主包必须由本包提供。`test/dist-size.test.ts` 给产物体积设预算,`test/readme-parity.test.ts` 钉中英两份的结构对等。
|
|
162
|
+
|
|
163
|
+
### 许可
|
|
164
|
+
|
|
165
|
+
MIT,见 [LICENSE](LICENSE)。本插件驱动的 `zg` CLI 属上游 `@zvec/zvec-grep`,许可为 **Apache-2.0**。本包不含上游源码,因此也不随包附其许可文本;若把两者放在一起再分发,请按各自许可分别保留完整声明。
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
本包自身编写的代码以 MIT 发布,见 [`LICENSE`](./LICENSE)。本文件说清本包与第三方的**关系性质**:
|
|
4
|
+
按命令行为调用外部工具,而不是把第三方代码搬进来。
|
|
5
|
+
|
|
6
|
+
## 运行期调用的上游 CLI:`@zvec/zvec-grep`(提供 `zg`)
|
|
7
|
+
|
|
8
|
+
- 上游仓库:https://github.com/zvec-ai/zvec-grep
|
|
9
|
+
- 上游 npm 包:https://www.npmjs.com/package/@zvec/zvec-grep
|
|
10
|
+
- 上游许可:**Apache-2.0**(版权归上游仓库所有)
|
|
11
|
+
- 关系:本包是 dsh 侧的适配层——经宿主 shell 以 `--mode direct` 起 `zg` 子进程、构造其 argv、
|
|
12
|
+
透传并按自己的口径解释其输出。本包**不**含上游源码、不内联上游产物、不重分发上游程序;
|
|
13
|
+
上游由用户自行 `npm install -g @zvec/zvec-grep` 安装。正因如此,本包不随包附上游的许可文本:
|
|
14
|
+
Apache-2.0 第 4 条的再分发条件挂在「被再分发的第三方代码」上,而本包里没有那段代码。若把两者
|
|
15
|
+
打包在一起再分发,请按各自许可分别保留声明。
|
|
16
|
+
- 版本契约:命令形态与旗标名按 `0.2.2` 书写;低于该版本本包在下发任何命令之前停住并点名实际版本
|
|
17
|
+
(判据在 `lib/zg-version.ts`)。这是本包自负的责任边界——上游改了旗标语义却没升主版本时,只有
|
|
18
|
+
这一族用例与那道版本门能发现。
|
|
19
|
+
- 数据边界:索引与向量库(`.zvec-grep/`、`manifest.json`)由上游读写,本包只判它是否存在、是否覆盖
|
|
20
|
+
目标根,不解析也不改写其内部结构。
|
|
21
|
+
|
|
22
|
+
## 编译期与运行期依赖:`@jayyuen66/dsh-plugin-shared`
|
|
23
|
+
|
|
24
|
+
- 同作者的共享工具库(MIT),是本包 `dependencies` 里唯一一枚,随包从公共 npm 安装。
|
|
25
|
+
- 它自己的宿主包 peer(含 `@deepseek-ai/dsh-output-retention`)由 dsh 运行时提供——本包必须把这
|
|
26
|
+
几枚也声明在 peer ∪ dev 上,否则装出去即 `ERR_MODULE_NOT_FOUND`(判据见
|
|
27
|
+
`test/publish-manifest.test.ts`)。
|
|
28
|
+
|
|
29
|
+
## 宿主:dsh 与 `@deepseek-ai/*`
|
|
30
|
+
|
|
31
|
+
- 本包只按 dsh 公开的插件面(cordis 注册面与 `dsh-*` 的服务类型)编写,不复制宿主代码;宿主包
|
|
32
|
+
一律走 peer,绝不进 `dependencies`(理由是消费侧安装布局会物化出第二份宿主类型面,同文件里那条
|
|
33
|
+
门禁写着)。
|
|
34
|
+
|
|
35
|
+
## embedding 权重
|
|
36
|
+
|
|
37
|
+
- 权重由上游 `zg` 按其 `hfEndpoint` 自行下载。本包不经手、不缓存、不重分发任何模型文件。
|
package/client.js
CHANGED
|
@@ -92,10 +92,9 @@ function numberText(raw, fallback) {
|
|
|
92
92
|
return typeof raw === "number" && Number.isFinite(raw) ? String(raw) : fallback;
|
|
93
93
|
}
|
|
94
94
|
//#endregion
|
|
95
|
-
//#region node_modules
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
95
|
+
//#region node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
|
|
96
|
+
function e$1(e) {
|
|
97
|
+
return typeof e == `object` && !!e && !Array.isArray(e);
|
|
99
98
|
}
|
|
100
99
|
//#endregion
|
|
101
100
|
//#region lib/card-logic.ts
|
|
@@ -204,7 +203,7 @@ function limitDraftOf(raw, t) {
|
|
|
204
203
|
/**
|
|
205
204
|
* 轮询应答 → 卡片状态。
|
|
206
205
|
* 关键:harness 的 bash-local 对**任何自然退出**都置 `status:'completed'`
|
|
207
|
-
* (packages/shell/bash-local/src/index.ts
|
|
206
|
+
* (packages/shell/bash-local/src/index.ts 给 `proc.status` 的那一分支:只在信号终止/调用方 abort 时给
|
|
208
207
|
* 'killed'),exit 127「zg 没装」也是 completed。只看 status 会把失败显示成
|
|
209
208
|
* 「重建完成」,故成功判据 = completed 且 exit 0。
|
|
210
209
|
* 状态词现取自官方作业注册表(ctx.jobs),比原先的进程态多两枚:
|
|
@@ -252,7 +251,7 @@ function parseJsonRecord(text) {
|
|
|
252
251
|
} catch {
|
|
253
252
|
return null;
|
|
254
253
|
}
|
|
255
|
-
return
|
|
254
|
+
return e$1(parsed) ? parsed : null;
|
|
256
255
|
}
|
|
257
256
|
/** 端点统一应答形状:`{ ok: true, … }` 才算成功。 */
|
|
258
257
|
function isOkBody(body) {
|
|
@@ -363,10 +362,32 @@ const UI_MESSAGES = {
|
|
|
363
362
|
}
|
|
364
363
|
};
|
|
365
364
|
//#endregion
|
|
366
|
-
//#region node_modules
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
return
|
|
365
|
+
//#region node_modules/@jayyuen66/dsh-plugin-shared/dist/errors.js
|
|
366
|
+
function e(e) {
|
|
367
|
+
let t = Object.getOwnPropertyDescriptor(e, `message`);
|
|
368
|
+
return t !== void 0 && `value` in t && typeof t.value == `string` ? t.value : void 0;
|
|
369
|
+
}
|
|
370
|
+
function t(n, r) {
|
|
371
|
+
if (r.has(n)) return `<circular cause>`;
|
|
372
|
+
r.add(n);
|
|
373
|
+
try {
|
|
374
|
+
if (!(n instanceof Error)) {
|
|
375
|
+
if (typeof n == `object` && n) {
|
|
376
|
+
let t = e(n);
|
|
377
|
+
if (t !== void 0) return t;
|
|
378
|
+
}
|
|
379
|
+
return String(n);
|
|
380
|
+
}
|
|
381
|
+
let i = n.message === `` ? n.name : n.message, a = n instanceof AggregateError && n.errors.length > 0 ? ` [${n.errors.map((e) => t(e, r)).join(`; `)}]` : ``, o = n.cause === void 0 || n.cause === null ? `` : t(n.cause, r);
|
|
382
|
+
return `${i}${a}${o === `` || o === i ? `` : `: ${o}`}`;
|
|
383
|
+
} catch {
|
|
384
|
+
return `<unrenderable value>`;
|
|
385
|
+
} finally {
|
|
386
|
+
r.delete(n);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function n(e) {
|
|
390
|
+
return t(e, /* @__PURE__ */ new Set());
|
|
370
391
|
}
|
|
371
392
|
//#endregion
|
|
372
393
|
//#region src/client-entry.ts
|
|
@@ -378,7 +399,7 @@ const NS = "zvec-grep";
|
|
|
378
399
|
* { view: "page" }, { entryKey: pkg.name })`——pkg.name 是 bundle 包名;
|
|
379
400
|
* · 同文件 :2698 `configured: ledger.bundles.has(openPkg.name)`,:306/:320 的
|
|
380
401
|
* `packageView()` 里 `name: bundle.name`(= bundle 包),所以没有第二条可匹配的 key;
|
|
381
|
-
* · 同包 lib/types/client/slot-contract.d.ts
|
|
402
|
+
* · 同包 lib/types/client/slot-contract.d.ts「A bundle's own configuration,
|
|
382
403
|
* **keyed by the bundle's package name**」,且 kind 为 `keyed` → `key` 必填;
|
|
383
404
|
* · dsh-client-ui-renderer/lib/client.js:1154 逐字相等匹配 `entry.options.key === entryKey`,
|
|
384
405
|
* 错一个字符就是「整张卡不渲染」(不是回落、不是报错);
|
|
@@ -825,7 +846,7 @@ function useRebuild(t) {
|
|
|
825
846
|
stopPolling();
|
|
826
847
|
setRebuild({
|
|
827
848
|
phase: "error",
|
|
828
|
-
output:
|
|
849
|
+
output: n(error)
|
|
829
850
|
});
|
|
830
851
|
}
|
|
831
852
|
}
|
|
@@ -867,7 +888,7 @@ function useRebuild(t) {
|
|
|
867
888
|
stopPolling();
|
|
868
889
|
setRebuild({
|
|
869
890
|
phase: "error",
|
|
870
|
-
output:
|
|
891
|
+
output: n(error)
|
|
871
892
|
});
|
|
872
893
|
}
|
|
873
894
|
}
|
|
@@ -916,7 +937,7 @@ function ZgCard(props) {
|
|
|
916
937
|
}
|
|
917
938
|
} catch (error) {
|
|
918
939
|
setBusy(false);
|
|
919
|
-
setSaveError(t("saveFailed", { reason:
|
|
940
|
+
setSaveError(t("saveFailed", { reason: n(error) }));
|
|
920
941
|
return;
|
|
921
942
|
}
|
|
922
943
|
const savedKeys = new Set(keys);
|
package/cordis.patch.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# zvec-grep
|
|
1
|
+
# zvec-grep:工作区语义检索插件(zg)。
|
|
2
2
|
# 3 个工具:zg_search(语义/混合检索,需已建索引)/ zg_index(建/重建/删索引,
|
|
3
3
|
# confirm 强制 true)/ zg_status(索引状态)。后端 zg CLI --mode direct(不经
|
|
4
4
|
# 守护进程),经 ctx.shell 调用;root 走 workdir/转义位置参数,防注入。
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
# 卡片(defaultEmbedding 默认 local/qwen3-embedding-0.6b,qwen3 需 node-llama-cpp)。
|
|
7
7
|
# hfEndpoint 默认 https://modelscope.cn/models(国内 HF 不可达,已实测可下载 qwen3)。
|
|
8
8
|
#
|
|
9
|
-
#
|
|
9
|
+
# 组合包层:本文件由 package.json 的 dsh.bundle.patch
|
|
10
10
|
# 指向,随 `dsh plugin --profile web add/remove ./plugins/zvec-grep` 维护。
|
|
11
11
|
# 行按裸包名引用本包(client-modules 只扫描裸包名条目的 dsh.client 声明)。
|
|
12
12
|
# 注意 pnpm ≥12.3.0:12.0.0 的 add 本地目录有 #14437 bug。
|
package/host.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// GENERATED by build-host.mjs — edit host.ts / lib/*.ts, then run `node build-host.mjs`.
|
|
2
2
|
import Schema from "@deepseek-ai/schemastery";
|
|
3
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { accessSync, constants, existsSync, readFileSync, statSync } from "node:fs";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
6
6
|
import { guardBody, queryParam, sendJson } from "@jayyuen66/dsh-plugin-shared/lib/http";
|
|
7
|
-
import { guardTrust } from "@jayyuen66/dsh-plugin-shared/lib/trust";
|
|
7
|
+
import { guardTrust, isNonLoopbackBindHost } from "@jayyuen66/dsh-plugin-shared/lib/trust";
|
|
8
8
|
import { isRecord } from "@jayyuen66/dsh-plugin-shared/lib/record";
|
|
9
9
|
import { errorText } from "@jayyuen66/dsh-plugin-shared/lib/errors";
|
|
10
10
|
import { LOCALE_SETTINGS_NAMESPACE, messagesFor, resolveLocalePreference } from "@jayyuen66/dsh-plugin-shared/lib/locale";
|
|
@@ -230,6 +230,7 @@ const MESSAGES = {
|
|
|
230
230
|
exhaustiveConflicts: "穷举检索(rg=true)与下列索引侧参数互斥:{names}。穷举是纯词法匹配,不支持这些参数;把它们去掉,或先建索引(zg_index)再用索引检索",
|
|
231
231
|
embeddingNotAllowed: "embedding 引用 {reference} 不在本地候选清单内,而本部署未开放远程 embedding。远程 embedding 会把工作区内容送到外部端点,必须由用户在部署配置里显式开放(allowRemoteEmbedding),本插件不接受模型侧开启。可选本地模型:{choices}。若用户确已自行配好远程凭据(zg config provider set / zg auth grant <root> --capability embedding --scope workspace),请在插件部署配置里打开对应开关后重试。",
|
|
232
232
|
dropWithResetPaths: "drop 与 resetPaths 互斥:--drop 整条命令只有删除索引一件事,resetPaths 无处安放(上游 zg 也拒这一对)。要清继承的文件选择设置,请不要传 drop。",
|
|
233
|
+
ignoreFileMissing: "ignoreFiles 里的 {path} 在 {root} 下不是一份「存在且当前进程可读的文件」(不存在、是目录、或有文件但读不了都算)。上游 zg 遇到读不成的忽略文件不会按「没有这条规则」继续,而是整次索引失败(ENOENT / EISDIR / EACCES),并把这条坏路径写进工作区索引状态——此后这条树上的 zg index / zg status 都会报同一个错,--reset-paths 也清不掉,只有 zg_index drop 能救。请给一个真实存在、当前用户可读的忽略文件路径。",
|
|
233
234
|
exhaustiveFallbackNote: "[zvec-grep] 该工作区(含向上各级)尚无 zg 索引,已自动改用穷举词法检索(rg 模式)。结果是逐行字面匹配,不是语义相关度排序;需要语义检索请先 zg_index 建索引。",
|
|
234
235
|
rgDescription: "穷举词法检索(对应 zg query --rg):不需要索引,逐行字面匹配。留空则在工作区无索引时自动改用它、有索引时照常走索引检索。显式 false 可要求只用索引检索(无索引即报错)。它不支持 preview / refresh / fuse / symbolTypes / preferSymbol / fts / vector / queries,且不发放 grep/rg 配额",
|
|
235
236
|
intWithReceived: "{name} 必须是 >= {min} 的整数(收到 {received})",
|
|
@@ -377,6 +378,7 @@ const MESSAGES = {
|
|
|
377
378
|
exhaustiveConflicts: "exhaustive search (rg=true) conflicts with these indexed-search parameters: {names}. Exhaustive search is pure lexical matching and does not support them; drop them, or build an index first (zg_index) and search the index",
|
|
378
379
|
embeddingNotAllowed: "embedding reference {reference} is not in the local catalog, and this deployment has not enabled remote embedding. Remote embedding sends workspace content to an external endpoint and must be turned on explicitly by the user in the deployment config (allowRemoteEmbedding); this plugin never lets the model side enable it. Local choices: {choices}. If the user has already set up remote credentials themselves (zg config provider set / zg auth grant <root> --capability embedding --scope workspace), enable the matching deployment setting and retry.",
|
|
379
380
|
dropWithResetPaths: "drop conflicts with resetPaths: --drop does nothing but delete the index, so resetPaths has nowhere to go (upstream zg rejects the pair too). To clear inherited file-selection settings, do not pass drop.",
|
|
381
|
+
ignoreFileMissing: "{path} under {root} is not an existing file the current process can read (missing, a directory, or present-but-unreadable all count). Upstream zg does not treat a failed ignore-file read as \"no such rule\": the whole indexing run fails (ENOENT / EISDIR / EACCES) and the bad path is written into the workspace index state, after which every zg index / zg status on that tree reports the same error — even --reset-paths cannot clear it, only zg_index drop can. Give a path that really exists and that the current user can read.",
|
|
380
382
|
exhaustiveFallbackNote: "[zvec-grep] This workspace (and every directory above it) has no zg index, so the search fell back to exhaustive lexical matching (rg mode). Results are literal line matches, not ranked by semantic relevance; run zg_index first if you need semantic search.",
|
|
381
383
|
rgDescription: "Exhaustive lexical search (zg query --rg): needs no index, matches literal text line by line. Leave it unset to fall back to it automatically when the workspace has no index, and to use the index when one exists. An explicit false demands indexed search only (an error when there is no index). It does not support preview / refresh / fuse / symbolTypes / preferSymbol / fts / vector / queries, and it grants no grep/rg quota",
|
|
382
384
|
intWithReceived: "{name} must be an integer >= {min} (received {received})",
|
|
@@ -2235,7 +2237,8 @@ function define(host, spec) {
|
|
|
2235
2237
|
* 0.1.7 迁移要点(两处都是静默失效,写错不报错):
|
|
2236
2238
|
* - `.volatile()` 决定字段是否进设置表单。宿主 `describe()` 只投影 volatile 字段
|
|
2237
2239
|
* (packages/settings/settings/src/schema.ts 的 volatileForm),全漏标则整条被跳过
|
|
2238
|
-
* (settings/src/index.ts
|
|
2240
|
+
* (settings/src/index.ts 里 `volatileForm(schema)` 空判即 `return []` 的那一处)、写入抛
|
|
2241
|
+
* `has no volatile fields`(同文件的那句 throw)。
|
|
2239
2242
|
* - `settings.register(ns, schema, { base })` 的「底座」层已被宿主移除:内置默认逐字段
|
|
2240
2243
|
* 落成下面的 `.default()`(原 BUILTIN_BASE 原样搬来,单一来源),cordis 装载期按同一
|
|
2241
2244
|
* 份 schema 校验行 config 并填默认,再把 volatile 字段包成引用交给 apply。
|
|
@@ -2277,18 +2280,38 @@ const REBUILD_JOB_KIND = "zvec-grep-rebuild";
|
|
|
2277
2280
|
const REBUILD_HISTORY_MAX = 10;
|
|
2278
2281
|
/** 卡片视图的尾部长度(打标文案在 lib/messages.ts,随语言走)。 */
|
|
2279
2282
|
const JOB_OUT_VIEW_CHARS = 4e3;
|
|
2283
|
+
/** 从名册投影推导身份证(官方 `JobView` 的三段稳定事实)。 */
|
|
2284
|
+
function identityOf(view) {
|
|
2285
|
+
return {
|
|
2286
|
+
kind: view.kind,
|
|
2287
|
+
label: view.label,
|
|
2288
|
+
startedAt: view.startedAt
|
|
2289
|
+
};
|
|
2290
|
+
}
|
|
2291
|
+
/** 两段身份证是否同一回事(三段全同才算)。 */
|
|
2292
|
+
function sameIdentity(left, right) {
|
|
2293
|
+
return left.kind === right.kind && left.label === right.label && left.startedAt === right.startedAt;
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* 身份证尚未盖章时的占位出生时刻。
|
|
2297
|
+
*
|
|
2298
|
+
* `startedAt` 由官方签发(`Date.now()`,永不为 0),而 kind/label 在 `start` 之前就已
|
|
2299
|
+
* 已知——那正是本包递给官方的那份规格。于是"start 的同步块里就跑到了 `run()`"那一档读取
|
|
2300
|
+
* (官方 `start` 会同步跑第一拍)比对时必然落到"对不上":那一刻还没有可比的出生时刻,
|
|
2301
|
+
* 不该把同 id 的另一条作业当成自己的收走。
|
|
2302
|
+
*/
|
|
2303
|
+
const UNSIGNED_STARTED_AT = 0;
|
|
2280
2304
|
/**
|
|
2281
2305
|
* 名册里那条 id 是不是**我们**的那条作业。
|
|
2282
2306
|
*
|
|
2283
2307
|
* 只比 id 不够:计数器是注册表的实例字段(实测两枚实例对同一 kind 都从 1 开始),换一枚
|
|
2284
|
-
*
|
|
2285
|
-
* 一毫秒内又起一次重建"同阶,而那已经是另一次用户意图,卡片 404 重来即可。
|
|
2308
|
+
* 实例就重名;那时同 id 指向的是另一条作业(另一棵树/另一条命令),旧卡片跟上去就是串台。
|
|
2286
2309
|
* @param state 这条记录的状态盒
|
|
2287
2310
|
* @param view 名册里同 id 的那条投影
|
|
2288
2311
|
* @returns 同一条作业
|
|
2289
2312
|
*/
|
|
2290
|
-
function sameJob(state, view
|
|
2291
|
-
return state.
|
|
2313
|
+
function sameJob(state, view) {
|
|
2314
|
+
return sameIdentity(state.identity, identityOf(view));
|
|
2292
2315
|
}
|
|
2293
2316
|
/** 终止重建进程:kill 异常忽略(进程可能已自然退出/已被回收)。 */
|
|
2294
2317
|
function killProc(proc) {
|
|
@@ -2301,7 +2324,7 @@ function killProc(proc) {
|
|
|
2301
2324
|
* 拖垮泵"的兜。选 pull 而不是生产者 push(`JobHandle.append`)是复核
|
|
2302
2325
|
* 后按实测定下的:
|
|
2303
2326
|
* - `proc.observed[*].readFrom` 是**非消费**的独立观察者面(installed dsh-shell
|
|
2304
|
-
* types.d.ts
|
|
2327
|
+
* types.d.ts:"without stealing bytes from `readOutput`"),与本包前台用的
|
|
2305
2328
|
* 消费式游标互不干扰——此前本仓写的"官方泵会与 readOutput 争同一份游标"是错的;
|
|
2306
2329
|
* - 泵按注册表自己的节拍跑(实测默认 150ms,落定前再排最后一次)⇒ **卡片关着环也前进**,
|
|
2307
2330
|
* 模型侧 job_output 随时看得见进度;push 形态把可见性绑在了轮询上。
|
|
@@ -2395,7 +2418,7 @@ function capacityLimitOf(error) {
|
|
|
2395
2418
|
* 「工作区重建」动作端点的四道前置校验:绝对路径 + 归一化、本 daemon 观测过的白名单、
|
|
2396
2419
|
* 目录此刻仍存在。不过就把错误就地答完并返回 undefined(错误文本全走双语字典)。
|
|
2397
2420
|
*
|
|
2398
|
-
* 这四道是**动作**端点的闸门:webServer
|
|
2421
|
+
* 这四道是**动作**端点的闸门:webServer 可被绑到本机网卡的具体地址,没有白名单的话任何能连上
|
|
2399
2422
|
* 服务面的一方都能拿任意绝对路径去 `zg index --rebuild`——读遍那棵树、写 `.zvec-grep/`,
|
|
2400
2423
|
* 还可能把其中的非隐藏敏感文件灌进向量库并回显到上下文。
|
|
2401
2424
|
* @param req 请求对象
|
|
@@ -2448,7 +2471,7 @@ function followRunningRebuild(jobs, records, res, root) {
|
|
|
2448
2471
|
const following = [...records.values()].find((record) => {
|
|
2449
2472
|
if (record.root !== root) return false;
|
|
2450
2473
|
const view = jobView(jobs, record.id);
|
|
2451
|
-
return view !== null && sameJob(record.state, view
|
|
2474
|
+
return view !== null && sameJob(record.state, view) && isLiveStatus(view.status);
|
|
2452
2475
|
});
|
|
2453
2476
|
if (following === void 0) return false;
|
|
2454
2477
|
sendJson(res, 200, {
|
|
@@ -2662,7 +2685,7 @@ function rebuildJobSpec(routes, proc, state, command, root) {
|
|
|
2662
2685
|
const live = jobsOf();
|
|
2663
2686
|
if (live === void 0) return null;
|
|
2664
2687
|
const view = jobView(live, handle.id);
|
|
2665
|
-
if (view === null || !sameJob(state, view
|
|
2688
|
+
if (view === null || !sameJob(state, view)) return null;
|
|
2666
2689
|
return {
|
|
2667
2690
|
jobs: live,
|
|
2668
2691
|
status: view.status
|
|
@@ -2698,6 +2721,49 @@ function rebuildJobSpec(routes, proc, state, command, root) {
|
|
|
2698
2721
|
};
|
|
2699
2722
|
}
|
|
2700
2723
|
/**
|
|
2724
|
+
* `ignoreFiles` 的可用性预检:模型给的第 N 条忽略文件必须是**当前进程读得了的普通文件**。
|
|
2725
|
+
*
|
|
2726
|
+
* 为什么必须预检(全部实测,见 test/e2e/zg-cli.test.ts):真 zg 遇到读不成的 ignore 文件
|
|
2727
|
+
* **不是**按"没有这条规则"继续,而是整次索引失败(`ZVEC_GREP.ENGINE.INDEXING.WORKSPACE_FAILED`,
|
|
2728
|
+
* 原因是 ENOENT / EACCES / EISDIR),并且那个坏路径会**写进工作区索引的状态**——此后这条树上的
|
|
2729
|
+
* `zg index` 与 `zg status` 都报同一个错,`--reset-paths` 清不掉,只有 `zg_index drop`(整棵
|
|
2730
|
+
* 索引删掉重来)能救。一个拼错的文件名、一个存在但读不了的文件(mode 000 / 他人属主,用绝对路径
|
|
2731
|
+
* 还够得着系统文件)、或一个目录,就把用户的工作区索引弄坏,属于必须在起进程之前拦下的那一类。
|
|
2732
|
+
*
|
|
2733
|
+
* 判据「读得了 + 是文件」合成**一次** try(accessSync 在前):`statSync().isFile()` 对 mode 000
|
|
2734
|
+
* 的文件照样返回 true(stat 只要父目录可搜索、不要文件本身可读),故先 `accessSync(R_OK)` 补上
|
|
2735
|
+
* "当前进程真能 open 来读"这半段——它与 zg 的读权限同 uid 同源(root 下两者都放行、非 root 下
|
|
2736
|
+
* 两者都拒);再用 `isFile()` 挡掉目录。**不拆成「不存在」与「读不了」两条独立分支**:可读性那
|
|
2737
|
+
* 一档在 windows(chmod 只翻只读位,属主仍读得了)与 root(绕过 DAC)下根本造不出来,拆成独立
|
|
2738
|
+
* 分支会让 CI 的 windows 那格在 100% 覆盖率门禁下无从而钉(本仓不用 coverage-ignore 逃生口)。
|
|
2739
|
+
* 合成一句「不是存在且可读的文件」文案,三种成因都准确覆盖,且 catch 由「不存在」这一档跨平台钉住。
|
|
2740
|
+
*
|
|
2741
|
+
* drop 那一臂整段跳过:`--drop` 的命令只有 `zg index <root> --drop --yes`,ignoreFiles 被
|
|
2742
|
+
* buildIndexCommand 静默丢掉、根本不进 zg(见 lib/cli.ts 的 drop 分支),预检它没有意义,还会
|
|
2743
|
+
* 拿"给一个真实存在的忽略文件"这句误导文案把一次合法的删索引拦下。判 drop 用与构造器**同一个**
|
|
2744
|
+
* `boolOf`,两处口径不会漂。
|
|
2745
|
+
* @param args 索引入参(`ignoreFiles` 单值或数组;`drop` 为真时整段跳过)
|
|
2746
|
+
* @param root 已归一的工作区根(相对路径按它解析)
|
|
2747
|
+
* @param messages 文案表
|
|
2748
|
+
* @returns {void}
|
|
2749
|
+
* @throws Error 指向第一个不可用的条目(不静默丢弃用户给的那一项)
|
|
2750
|
+
*/
|
|
2751
|
+
function assertIgnoreFilesExist(args, root, messages) {
|
|
2752
|
+
if (boolOf(args.drop, "drop", messages)) return;
|
|
2753
|
+
for (const entry of singleOrList(args.ignoreFiles, "ignoreFiles", messages)) {
|
|
2754
|
+
const target = entry.startsWith("/") ? entry : `${root}/${entry}`;
|
|
2755
|
+
let usable = false;
|
|
2756
|
+
try {
|
|
2757
|
+
accessSync(target, constants.R_OK);
|
|
2758
|
+
usable = statSync(target).isFile();
|
|
2759
|
+
} catch {}
|
|
2760
|
+
if (!usable) throw new Error(fill(messages.ignoreFileMissing, {
|
|
2761
|
+
path: entry,
|
|
2762
|
+
root
|
|
2763
|
+
}));
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
/**
|
|
2701
2767
|
* 起一条 `zg index`:命令构造 + resolve + execute 三步。
|
|
2702
2768
|
*
|
|
2703
2769
|
* 设置卡重建端点与模型侧后台索引**共用**这一个函数(不是复制品),所以两条入口起的作业
|
|
@@ -2720,6 +2786,7 @@ async function spawnIndexWrite(routes, started, indexArgs, embedding) {
|
|
|
2720
2786
|
let spawned;
|
|
2721
2787
|
try {
|
|
2722
2788
|
await routes.versionGate.ensure(started);
|
|
2789
|
+
assertIgnoreFilesExist(indexArgs, assertAbsoluteRoot(indexArgs.root, started), started);
|
|
2723
2790
|
const built = buildIndexCommand(indexArgs, embedding, started, readClientMode(config, started), allowRemoteEmbedding(config));
|
|
2724
2791
|
const env = zgEnv(config);
|
|
2725
2792
|
const spec = host.shell.resolve({
|
|
@@ -2766,18 +2833,20 @@ function attachIndexWrite(routes, root, started, spawned) {
|
|
|
2766
2833
|
}
|
|
2767
2834
|
pruneRebuildHistory(starting, records);
|
|
2768
2835
|
const state = {
|
|
2769
|
-
|
|
2770
|
-
|
|
2836
|
+
identity: {
|
|
2837
|
+
kind: REBUILD_JOB_KIND,
|
|
2838
|
+
label: command,
|
|
2839
|
+
startedAt: UNSIGNED_STARTED_AT
|
|
2840
|
+
},
|
|
2771
2841
|
lost: false,
|
|
2772
2842
|
timeoutNote: null
|
|
2773
2843
|
};
|
|
2774
2844
|
let jobId;
|
|
2775
2845
|
try {
|
|
2776
2846
|
jobId = startUnderController(starting, rebuildJobSpec(routes, proc, state, command, root));
|
|
2777
|
-
state.
|
|
2778
|
-
state.owner = starting;
|
|
2847
|
+
state.identity = identityOf(starting.get(jobId));
|
|
2779
2848
|
const clashed = records.get(jobId);
|
|
2780
|
-
if (clashed !== void 0 && clashed.state.
|
|
2849
|
+
if (clashed !== void 0 && !sameIdentity(clashed.state.identity, state.identity)) {
|
|
2781
2850
|
killProc(proc);
|
|
2782
2851
|
return {
|
|
2783
2852
|
error: started.endpointRegistryReplaced,
|
|
@@ -2895,7 +2964,7 @@ function handleRebuildStatus(routes, req, res) {
|
|
|
2895
2964
|
});
|
|
2896
2965
|
return;
|
|
2897
2966
|
}
|
|
2898
|
-
if (!sameJob(record.state, output.view
|
|
2967
|
+
if (!sameJob(record.state, output.view)) {
|
|
2899
2968
|
sendJson(res, 404, {
|
|
2900
2969
|
ok: false,
|
|
2901
2970
|
error: fill(marks.unknownJobId, { maxJobs: REBUILD_HISTORY_MAX })
|
|
@@ -2930,7 +2999,7 @@ function releaseRebuildRecords(routes) {
|
|
|
2930
2999
|
if (jobs === void 0) for (const record of records.values()) killProc(record.proc);
|
|
2931
3000
|
else for (const record of records.values()) {
|
|
2932
3001
|
const view = jobView(jobs, record.id);
|
|
2933
|
-
if (view === null || !sameJob(record.state, view
|
|
3002
|
+
if (view === null || !sameJob(record.state, view)) killProc(record.proc);
|
|
2934
3003
|
else if (isLiveStatus(view.status)) jobs.kill(record.id, void 0, unloadReason);
|
|
2935
3004
|
else jobs.remove(record.id);
|
|
2936
3005
|
}
|
|
@@ -2941,7 +3010,7 @@ function registerRebuildEndpoints(deps) {
|
|
|
2941
3010
|
const { ctx, host, config, csrf, ledger, messages, rebuilds, versionGate } = deps;
|
|
2942
3011
|
const webServer = host.get("webServer");
|
|
2943
3012
|
if (!webServer) return;
|
|
2944
|
-
const servingNonLoopback = webServer.host
|
|
3013
|
+
const servingNonLoopback = isNonLoopbackBindHost(webServer.host);
|
|
2945
3014
|
const { jobsOf } = deps;
|
|
2946
3015
|
const { records } = deps;
|
|
2947
3016
|
const routes = {
|
|
@@ -3381,6 +3450,7 @@ async function runIndexTool(runtime, args, exec, messages) {
|
|
|
3381
3450
|
if (rewriting && rebuilds.claim(root, "tool") === null) return { text: fill(messages.indexRebuildInFlight, { root }) };
|
|
3382
3451
|
if (background) return startBackgroundIndex(runtime, root, indexArgs, messages);
|
|
3383
3452
|
try {
|
|
3453
|
+
assertIgnoreFilesExist(indexArgs, root, messages);
|
|
3384
3454
|
const { command, workdir } = buildIndexCommand(indexArgs, readDefaultEmbedding(config), messages, readClientMode(config, messages), allowRemoteEmbedding(config));
|
|
3385
3455
|
return { text: await runForeground(host, command, workdir, config.indexTimeoutMs, {
|
|
3386
3456
|
signal: exec.signal,
|
|
@@ -3583,11 +3653,11 @@ function registerToolGuards(runtime) {
|
|
|
3583
3653
|
* 设置卡片的「工作区重建」端点组(引导 + 后台进程 + 轮询状态)。
|
|
3584
3654
|
*
|
|
3585
3655
|
* ⚠ 这三条路由的归属方必须对 webServer **建立依赖**,不能在 apply 里读一次就算完:
|
|
3586
|
-
* `ctx.get` 是无 inject 语义的存储读(官方 reflect.d.ts
|
|
3656
|
+
* `ctx.get` 是无 inject 语义的存储读(官方 reflect.d.ts 明写 "or `undefined`
|
|
3587
3657
|
* when not (yet) provided"),而真实宿主上 webServer 比本条目晚到位——隔离 DSH_HOME
|
|
3588
3658
|
* 实测 apply 当场读到 undefined、+1.3s 才交得出实例。旧写法的结果是三条路由在任何
|
|
3589
3659
|
* web profile 上都不注册,卡片的「工作区重建」永远 404。子 fiber 只在依赖到位时激活、
|
|
3590
|
-
* 依赖换实例时先卸后装(registry.d.ts
|
|
3660
|
+
* 依赖换实例时先卸后装(registry.d.ts),故效应挂在**子上下文**上即得「后到即注册、
|
|
3591
3661
|
* 重启即重注册」。不写进插件级 inject:那会让没有 webServer 的宿主(TUI)连三个工具
|
|
3592
3662
|
* 一并失活。
|
|
3593
3663
|
* @param runtime apply 的运行时依赖(host / config / 白名单 / 文案读取器)
|
package/package.json
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayyuen66/dsh-zvec-grep",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "dsh 工作区语义检索插件(zg):zg_search / zg_index / zg_status + 本地 embedding 设置卡片 + systemPrompt 路由规则 + guard 安全兜底。",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cordis",
|
|
7
|
+
"dsh",
|
|
8
|
+
"embedding",
|
|
9
|
+
"plugin",
|
|
10
|
+
"semantic-search",
|
|
11
|
+
"workspace",
|
|
12
|
+
"zvec"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/JayYuen666/dsh-zvec-grep#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/JayYuen666/dsh-zvec-grep/issues"
|
|
17
|
+
},
|
|
5
18
|
"license": "MIT",
|
|
6
19
|
"author": "JayYuen",
|
|
7
20
|
"repository": {
|
|
@@ -10,6 +23,10 @@
|
|
|
10
23
|
},
|
|
11
24
|
"files": [
|
|
12
25
|
"icon.svg",
|
|
26
|
+
"README.md",
|
|
27
|
+
"README.zh-CN.md",
|
|
28
|
+
"CHANGELOG.md",
|
|
29
|
+
"THIRD_PARTY_NOTICES.md",
|
|
13
30
|
"host.js",
|
|
14
31
|
"client.js",
|
|
15
32
|
"cordis.patch.yml"
|
|
@@ -27,50 +44,57 @@
|
|
|
27
44
|
"registry": "https://registry.npmjs.org"
|
|
28
45
|
},
|
|
29
46
|
"dependencies": {
|
|
30
|
-
"@
|
|
31
|
-
"@jayyuen66/dsh-plugin-shared": "^0.1.0"
|
|
47
|
+
"@jayyuen66/dsh-plugin-shared": "^0.1.4"
|
|
32
48
|
},
|
|
33
49
|
"devDependencies": {
|
|
34
|
-
"@deepseek-ai/cordis": "4.0.
|
|
35
|
-
"@deepseek-ai/cordis-plugin-timer": "1.1.
|
|
36
|
-
"@deepseek-ai/dsh-api-remotes": "0.2.
|
|
37
|
-
"@deepseek-ai/dsh-
|
|
38
|
-
"@deepseek-ai/dsh-client-
|
|
39
|
-
"@deepseek-ai/dsh-client-
|
|
40
|
-
"@deepseek-ai/dsh-client-ui-
|
|
41
|
-
"@deepseek-ai/dsh-client-ui-
|
|
42
|
-
"@deepseek-ai/dsh-client-ui-
|
|
43
|
-
"@deepseek-ai/dsh-client-ui-
|
|
44
|
-
"@deepseek-ai/dsh-
|
|
45
|
-
"@deepseek-ai/dsh-
|
|
46
|
-
"@deepseek-ai/dsh-
|
|
47
|
-
"@deepseek-ai/dsh-
|
|
48
|
-
"@deepseek-ai/dsh-
|
|
49
|
-
"@deepseek-ai/dsh-
|
|
50
|
-
"@deepseek-ai/dsh-
|
|
51
|
-
"@deepseek-ai/dsh-
|
|
52
|
-
"@deepseek-ai/dsh-
|
|
53
|
-
"@deepseek-ai/dsh-
|
|
54
|
-
"@deepseek-ai/dsh-
|
|
55
|
-
"@deepseek-ai/dsh-
|
|
56
|
-
"@deepseek-ai/dsh-
|
|
57
|
-
"@deepseek-ai/dsh-
|
|
58
|
-
"@deepseek-ai/dsh-
|
|
59
|
-
"@
|
|
50
|
+
"@deepseek-ai/cordis": "4.0.5-alpha.1",
|
|
51
|
+
"@deepseek-ai/cordis-plugin-timer": "1.1.7-alpha.1",
|
|
52
|
+
"@deepseek-ai/dsh-api-remotes": "0.2.1-alpha.2",
|
|
53
|
+
"@deepseek-ai/dsh-bash-local": "0.2.1-alpha.2",
|
|
54
|
+
"@deepseek-ai/dsh-client-locale": "0.2.1-alpha.2",
|
|
55
|
+
"@deepseek-ai/dsh-client-store": "0.2.1-alpha.2",
|
|
56
|
+
"@deepseek-ai/dsh-client-ui-layout": "0.2.1-alpha.2",
|
|
57
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.1-alpha.2",
|
|
58
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.1-alpha.2",
|
|
59
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.2.1-alpha.2",
|
|
60
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.1-alpha.2",
|
|
61
|
+
"@deepseek-ai/dsh-host-webserver": "0.2.1-alpha.2",
|
|
62
|
+
"@deepseek-ai/dsh-http-proxy": "0.2.1-alpha.2",
|
|
63
|
+
"@deepseek-ai/dsh-jobs": "0.2.1-alpha.2",
|
|
64
|
+
"@deepseek-ai/dsh-jobs-local": "0.2.1-alpha.2",
|
|
65
|
+
"@deepseek-ai/dsh-llm": "0.2.1-alpha.2",
|
|
66
|
+
"@deepseek-ai/dsh-output-retention": "0.2.1-alpha.2",
|
|
67
|
+
"@deepseek-ai/dsh-package-manifest": "0.2.1-alpha.2",
|
|
68
|
+
"@deepseek-ai/dsh-ptc-runtime": "0.2.1-alpha.2",
|
|
69
|
+
"@deepseek-ai/dsh-sandbox": "0.2.1-alpha.2",
|
|
70
|
+
"@deepseek-ai/dsh-scope": "0.2.1-alpha.2",
|
|
71
|
+
"@deepseek-ai/dsh-session": "0.2.1-alpha.2",
|
|
72
|
+
"@deepseek-ai/dsh-settings": "0.2.1-alpha.2",
|
|
73
|
+
"@deepseek-ai/dsh-shell": "0.2.1-alpha.2",
|
|
74
|
+
"@deepseek-ai/dsh-subprocess": "0.2.1-alpha.2",
|
|
75
|
+
"@deepseek-ai/dsh-subprocess-local": "0.2.1-alpha.2",
|
|
76
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.1-alpha.2",
|
|
77
|
+
"@deepseek-ai/dsh-timeout": "0.2.1-alpha.2",
|
|
78
|
+
"@deepseek-ai/dsh-tools": "0.2.1-alpha.2",
|
|
79
|
+
"@deepseek-ai/dsh-user-approval": "0.2.1-alpha.2",
|
|
80
|
+
"@deepseek-ai/schemastery": "3.18.5-alpha.1",
|
|
81
|
+
"@types/node": "26.6.5",
|
|
60
82
|
"@types/react": "19.3.0",
|
|
61
|
-
"@vitest/coverage-v8": "5.0.
|
|
83
|
+
"@vitest/coverage-v8": "5.0.3",
|
|
62
84
|
"eslint-plugin-sonarjs": "4.2.2",
|
|
63
|
-
"oxfmt": "0.
|
|
64
|
-
"oxlint": "1.
|
|
65
|
-
"oxlint-tsgolint": "7.0.
|
|
85
|
+
"oxfmt": "0.72.0",
|
|
86
|
+
"oxlint": "1.87.0",
|
|
87
|
+
"oxlint-tsgolint": "7.0.2004",
|
|
66
88
|
"react": "^19.3.0",
|
|
67
|
-
"rolldown": "1.2.
|
|
89
|
+
"rolldown": "1.2.13",
|
|
68
90
|
"typescript": "7.0.2",
|
|
69
|
-
"vite": "8.3.
|
|
70
|
-
"vitest": "5.0.
|
|
91
|
+
"vite": "8.3.4",
|
|
92
|
+
"vitest": "5.0.3"
|
|
71
93
|
},
|
|
72
94
|
"peerDependencies": {
|
|
73
|
-
"@deepseek-ai/dsh": "^0.2.
|
|
95
|
+
"@deepseek-ai/dsh": "^0.2.1-alpha.2",
|
|
96
|
+
"@deepseek-ai/dsh-output-retention": "0.2.1-alpha.2",
|
|
97
|
+
"@deepseek-ai/schemastery": "3.18.5-alpha.1"
|
|
74
98
|
},
|
|
75
99
|
"peerDependenciesMeta": {
|
|
76
100
|
"@deepseek-ai/dsh": {
|
|
@@ -79,7 +103,8 @@
|
|
|
79
103
|
},
|
|
80
104
|
"icon": "icon.svg",
|
|
81
105
|
"engines": {
|
|
82
|
-
"dsh": ">=0.2.
|
|
106
|
+
"dsh": ">=0.2.1-alpha.2",
|
|
107
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
83
108
|
},
|
|
84
109
|
"dsh": {
|
|
85
110
|
"manifestVersion": 1,
|
|
@@ -99,6 +124,7 @@
|
|
|
99
124
|
"test": "vitest run --coverage",
|
|
100
125
|
"test:watch": "vitest",
|
|
101
126
|
"check": "npm run --loglevel=warn typecheck && npm run --loglevel=warn lint && npm run --loglevel=warn build:client && npm run --loglevel=warn build && npm run --loglevel=warn test && npm run --loglevel=warn fmt:check",
|
|
127
|
+
"fmt": "oxfmt .",
|
|
102
128
|
"fmt:check": "oxfmt --check ."
|
|
103
129
|
}
|
|
104
130
|
}
|