@jayyuen66/dsh-zvec-grep 0.1.0 → 0.1.1
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/README.md +99 -24
- package/host.js +1459 -260
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,27 +29,58 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
|
29
29
|
|
|
30
30
|
### 提供给模型的工具
|
|
31
31
|
|
|
32
|
-
- zg_search:query / queries / fts / vector 至少其一(合计 <= 32
|
|
33
|
-
- 可加 globs / insensitiveGlobs / fileTypes / excludedFileTypes / symbolTypes / preferSymbol / modifiedAfter / modifiedBefore / fuse / limit / device。
|
|
34
|
-
-
|
|
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 上限截尾时另附「只含保留部分」。
|
|
35
40
|
- zg_index:confirm 必填且必须为 true(required 校验 + guard 双层拒绝)。
|
|
36
|
-
-
|
|
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;其中五个路径过滤项同样收单值或数组。
|
|
37
47
|
- 切换 embedding 必须 rebuild=true 才生效。
|
|
38
|
-
-
|
|
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),带分值入键会让每条命中都成「新位置」,去重直接失效、位置数虚高一倍。
|
|
39
62
|
- 三者的 root 都可省略(缺省=当前会话工作区);输出为纯文本;超时分别为 5 分钟 / 10 分钟 / 60 秒,stdout 上限 400000 字节(超限截尾并提示)。
|
|
40
63
|
|
|
41
64
|
### 设置项与检索根
|
|
42
65
|
|
|
43
|
-
- 命名空间 `zvec-grep` 由宿主**隐式**注册(0.1.7 起 = profile 条目 id,插件侧不再有 `settings.register`);schema
|
|
66
|
+
- 命名空间 `zvec-grep` 由宿主**隐式**注册(0.1.7 起 = profile 条目 id,插件侧不再有 `settings.register`);schema 共十四个字段,其中卡上那六枚标 `.volatile()`,内置默认逐字段写在 `.default()` 上。
|
|
44
67
|
- defaultEmbedding=local/qwen3-embedding-0.6b、defaultLimit=10(1-50)、hfEndpoint=国内可达的 HF 兼容镜像基址(可改成别的镜像或留空走官方 HF)。
|
|
45
68
|
- enforceSearchFirst=true、grepBudgetPerSearch=3(1-20)、unlockWindowMin=10(1-240)。
|
|
46
|
-
-
|
|
47
|
-
-
|
|
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()`。
|
|
48
77
|
- root 校验:必须是以 `/` 开头的绝对路径,词典归一折叠空段与 `.`。
|
|
49
78
|
- 拒绝空串、非字符串、含 NUL、相对路径、越出文件系统根的 `..`,归一后为 `/` 也拒。
|
|
50
79
|
- 目录不存在时单报「root 目录不存在」,不冒成 spawn ENOENT。
|
|
51
80
|
- guard 与 execute 用同一套 root 判据,避免「guard 放行、execute 抛错」说两遍。
|
|
52
81
|
- 解锁按「会话 × 索引根」计:每次成功 zg_search 重置为 grepBudgetPerSearch 次、unlockWindowMin 分钟有效;索引根是 root 自身或含索引的最近祖先(最多上溯 8 层)。
|
|
82
|
+
- 分片用的会话是**根会话**:沿 `header.parentSession` 一路上溯到最顶层那一跳。故同一棵委派树上的主代理与子代理**共享一份额度**——主代理搜过一次,子代理随即就能用那几次 grep/rg,不必各自再搜一次(它们搜的往往是同一棵树)。
|
|
83
|
+
- 上溯的降级是三级的,都不抛错:自身即顶层就用自己;某一跳查不到它的父(会话已落定,或宿主没装会话存储)就停在**已知的最后一跳**;链成环就停在首次重复前。跳数有上限。
|
|
53
84
|
- 「含索引」的判据是 `<root>/.zvec-grep/manifest.json` 在盘上,**只判 `.zvec-grep` 目录名不够**:这个名字同时是 zg 自己的全局 home(`ZVEC_GREP_HOME ?? ~/.zvec-grep`,装的是 config.json / locks / models),只判目录名会让一个从未建索引、只是祖先目录撞名的普通工作区也被门禁拦下。
|
|
54
85
|
- enforceSearchFirst=false 只关掉门禁,zg_* 的安全兜底(confirm、root 判据)不受影响。
|
|
55
86
|
|
|
@@ -95,9 +126,15 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
|
95
126
|
|
|
96
127
|
- 索引的唯一落盘形状是被检索 root 下的 `.zvec-grep/` 目录,由 zg 写入(read-only 沙箱下写不了它,会明确报索引可能不完整)。
|
|
97
128
|
- 重建有两条路:模型侧 `zg_index`(rebuild=true、confirm=true),或设置卡「工作区重建」走上面的 rebuild 路由;删除是 `zg_index` drop=true(拼成 `zg index <root> --drop --yes`)。
|
|
98
|
-
- 本包自身不写任何文件(唯一的 fs
|
|
99
|
-
-
|
|
100
|
-
-
|
|
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 可关)。
|
|
101
138
|
- 本包只在本机拼 zg 命令并透传输出,不上传代码。
|
|
102
139
|
- 唯一的外连是 embedding 权重按 hfEndpoint 下载。
|
|
103
140
|
- 结果回显有界:stdout 超限截尾(有 spill 路径会给出)、stderr 尾部 400 字符一并回显,免得「退化成纯词法」被当成完整语义结果。
|
|
@@ -141,30 +178,60 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
|
141
178
|
|
|
142
179
|
### Tools exposed to the model
|
|
143
180
|
|
|
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
|
-
-
|
|
181
|
+
- zg_search: at least one of query / queries / fts / vector (32 routes max, 4000 chars per query).
|
|
182
|
+
- Plus globs / insensitiveGlobs / fileTypes / excludedFileTypes / symbolTypes / preferSymbol / modifiedAfter / modifiedBefore / fuse / limit / preview / refresh / device.
|
|
183
|
+
- `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).
|
|
184
|
+
- `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.
|
|
185
|
+
- `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.
|
|
186
|
+
- `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.
|
|
187
|
+
- 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.
|
|
188
|
+
- 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
189
|
- zg_index: confirm is required and must be true (rejected twice, by the required check and by the guard).
|
|
148
|
-
-
|
|
190
|
+
- `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.
|
|
191
|
+
- 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.
|
|
192
|
+
- 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.
|
|
193
|
+
- 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.
|
|
194
|
+
- 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.
|
|
195
|
+
- 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
196
|
- Switching embedding only takes effect with rebuild=true.
|
|
150
|
-
-
|
|
197
|
+
- **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).
|
|
198
|
+
- `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.
|
|
199
|
+
- zg_status: root + checkReady, for diagnosing a missing/failed/cancelled index or watching progress explicitly.
|
|
200
|
+
- `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.
|
|
201
|
+
- A non-zero exit with an empty report still throws; without `checkReady` a non-zero exit throws as before.
|
|
202
|
+
- 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".
|
|
203
|
+
- **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.
|
|
204
|
+
- `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.
|
|
205
|
+
- `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).
|
|
206
|
+
- 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.
|
|
207
|
+
- 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.
|
|
208
|
+
- 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.
|
|
209
|
+
- `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.
|
|
210
|
+
- 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
211
|
- 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
212
|
|
|
153
213
|
### Settings and search roots
|
|
154
214
|
|
|
155
|
-
- Namespace `zvec-grep`,
|
|
215
|
+
- Namespace `zvec-grep`, fourteen fields with built-in defaults, six of them volatile and on the card.
|
|
156
216
|
- 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
217
|
- enforceSearchFirst=true, grepBudgetPerSearch=3 (1-20), unlockWindowMin=10 (1-240).
|
|
158
|
-
-
|
|
159
|
-
- searchTimeoutMs=300000
|
|
160
|
-
-
|
|
218
|
+
- 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.
|
|
219
|
+
- 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.
|
|
220
|
+
- Remote embedding, three values, all **off by default**: `allowRemoteEmbedding=false`, `remoteEmbeddingEndpoint=""`, `remoteEmbeddingApiKeyFrom=""`.
|
|
221
|
+
- While it is off, an explicit embedding reference must be in the local catalog at **command-assembly time**.
|
|
222
|
+
- 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.
|
|
223
|
+
- 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.
|
|
224
|
+
- 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.
|
|
225
|
+
- `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
226
|
- 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
|
|
227
|
+
- Volatile fields are read via `config.<field>.get()`; the non-volatile deployment values are plain values and skip `.get()`.
|
|
163
228
|
- Root validation: must be an absolute path starting with `/`, lexically normalised (empty and `.` segments folded).
|
|
164
229
|
- Rejects empty strings, non-strings, NUL bytes, relative paths and `..` segments escaping the filesystem root, and `/` itself after normalisation.
|
|
165
230
|
- A missing directory is reported as "root does not exist" instead of a bare spawn ENOENT.
|
|
166
231
|
- The guard and execute share exactly this root predicate, so nothing is refused twice with different wording.
|
|
167
232
|
- 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).
|
|
233
|
+
- 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).
|
|
234
|
+
- 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
235
|
- "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
236
|
- enforceSearchFirst=false disables only the gate; the zg_* backstop (confirm, root rules) is unaffected.
|
|
170
237
|
|
|
@@ -207,12 +274,20 @@ What is not retained, stated plainly: the output ring keeps **UTF-8 bytes** (mea
|
|
|
207
274
|
|
|
208
275
|
- 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
276
|
- 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
|
-
-
|
|
277
|
+
- 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>`).
|
|
278
|
+
- 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.
|
|
279
|
+
- 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.
|
|
280
|
+
- 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.
|
|
281
|
+
- 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.
|
|
282
|
+
- 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.
|
|
283
|
+
- 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.
|
|
284
|
+
- 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`).
|
|
285
|
+
- Hidden files are skipped and ignore files honoured unless noIgnore is set.
|
|
213
286
|
- Nothing is uploaded: the package only assembles zg commands on the local machine and passes output through.
|
|
214
287
|
- The only outbound traffic is the embedding weight download driven by hfEndpoint.
|
|
215
288
|
- 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.
|
|
289
|
+
- 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.
|
|
290
|
+
- `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
291
|
|
|
217
292
|
### FAQ
|
|
218
293
|
|