@jayyuen66/dsh-zvec-grep 0.1.12 → 0.1.13

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/docs/DETAIL.md CHANGED
@@ -4,24 +4,31 @@ Searches the workspace through a local index instead of raw grep, and can requir
4
4
 
5
5
  ## What the card changes
6
6
 
7
- - **Search model** — `defaultEmbedding` (default `local/qwen3-embedding-0.6b`, about 640 MB) applies to **new** indexes only; an existing index keeps its model until it is rebuilt. `defaultLimit` (1–50, default 10) is how many hits each result group returns.
8
- - **Network and indexing** — `hfEndpoint` defaults to the ModelScope mirror (`https://modelscope.cn/models`); leaving it empty means huggingface.co, which this environment typically cannot reach, so the default should stay. `enforceSearchFirst` (on) gates `grep` / `rg` inside indexed workspaces. `grepBudgetPerSearch` (default 3) is how many plain searches each successful `zg_search` unlocks, and `unlockWindowMin` (default 10) is how many minutes that unlock stays valid. Expiry is checked whenever the budget is read, so an elapsed window stops granting searches without a restart; the per-session table keeps at most 256 sessions and evicts the least recently used one first. When the step's tool admission does not include `zg_search`, the gate stands down rather than forcing a call the step cannot make.
7
+ - **Search model** — `defaultEmbedding` (default `local/qwen3-embedding-0.6b`, about 640 MB) applies to **new** indexes only; an existing index keeps its model until it is rebuilt. The dropdown has a local and a remote group: the remote qwen models (three, new in 0.3.0) additionally require `allowRemoteEmbedding` in the deployment config — remote embedding sends workspace content to an external endpoint, and the first index build needs a one-time user authorization via `zg --auth grant`. `defaultLimit` (1–50, default 10) is how many hits each result group returns.
8
+ - **Network and indexing** — the **search transport** (`transport`, new in 0.3.0) has three settings: auto = searches go through the daemon (MCP) when it is running, CLI otherwise; CLI-only = never touch the daemon; MCP-only = searches always go through the daemon, auto-starting it when absent (opens the `127.0.0.1:7999` loopback port; a failed start is reported explicitly, never silently downgraded). `hfEndpoint` defaults to the ModelScope mirror (`https://modelscope.cn/models`); leaving it empty means huggingface.co, which this environment typically cannot reach, so the default should stay. `enforceSearchFirst` (on) gates `grep` / `rg` inside indexed workspaces. `grepBudgetPerSearch` (default 3) is how many plain searches each successful `zg_search` unlocks, and `unlockWindowMin` (default 10) is how many minutes that unlock stays valid. Expiry is checked whenever the budget is read, so an elapsed window stops granting searches without a restart; the per-session table keeps at most 256 sessions and evicts the least recently used one first. When the step's tool admission does not include `zg_search`, the gate stands down rather than forcing a call the step cannot make.
9
9
 
10
10
  These are read per call and take effect without restarting the host.
11
11
 
12
+ ## Concurrency and platforms
13
+
14
+ - **Within one host**, concurrent cold starts coalesce into one `zg --server on`. **Multiple hosts** sharing the same `ZVEC_GREP_HOME` share one daemon (upstream `instance.lock`; a duplicate start exits 0 with the same PID). The token is claimed atomically with O_EXCL, so later processes read the same value instead of overwriting each other; only the process that created the file stops the daemon it started on unload.
15
+ - One zg MCP session handles one `tools/call` at a time (measured: a second concurrent call on the same session hangs until the caller's deadline), so every concurrent tool call gets its own session and idle sessions are reused. Index-job concurrency (default 2) and same-root writer reuse belong to the upstream scheduler.
16
+ - Searches wait only while a same-root index rebuild holds the write lock, bounded by `rebuildWaitMs`; cold starts do not queue.
17
+ - **Platforms**: POSIX accepts `/…` roots and uses bash single-quote escaping; Windows accepts drive-letter/UNC roots, uses pwsh escaping (embedded `'` becomes `''`), strips executable extensions such as `.exe`/`.cmd` from command names, and lowers the command-size cap to 24,000 bytes for the CreateProcess limit. Real on-disk Windows behavior is exercised by the CI `windows-latest` grid; local runs cover the same predicates with platform-injected win32 fixtures.
18
+
12
19
  ## The Rebuild action is not a setting
13
20
 
14
- The card's Rebuild button runs the equivalent of `zg index --rebuild` for a workspace the daemon has already observed; it is an action, not a stored preference. No approval prompt fires on this path: the pre-execute approval only covers the `zg_*` tools when they name an explicit root, and Remote methods do not go through tool admission. What guards the action is the daemon's list of observed roots (plus its own single-operation lock).
21
+ The card's Rebuild button runs the equivalent of `zg --index --rebuild` for a workspace the daemon has already observed; it is an action, not a stored preference. No approval prompt fires on this path: the pre-execute approval only covers the `zg_*` tools when they name an explicit root, and Remote methods do not go through tool admission. What guards the action is the daemon's list of observed roots (plus its own single-operation lock).
15
22
 
16
23
  ## Restart-only values
17
24
 
18
- Ten deployment values stay off the card: `searchTimeoutMs` (300000), `statusTimeoutMs` (60000), `indexTimeoutMs` (600000), `stdoutMaxBytes` (400000), `rebuildWaitMs` (120000), `clientMode` (`auto` / `direct` / `server`), `allowRemoteEmbedding` (false), `remoteEmbeddingEndpoint`, `remoteEmbeddingApiKeyFrom`, `requireApprovalForExplicitRoot` (false). None of these ten has a card control; the only thing that makes them take effect is the `config:` block of the registration row in the next paragraph, and precedence is row `config:` > the `.default()` in code.
25
+ Eleven deployment values stay off the card: `searchTimeoutMs` (300000), `statusTimeoutMs` (60000), `indexTimeoutMs` (600000), `stdoutMaxBytes` (400000), `rebuildWaitMs` (120000), `clientMode` (`auto` / `direct` / `server`), `daemonUrl` (`http://127.0.0.1:7999/mcp`, the MCP transport's daemon endpoint), `allowRemoteEmbedding` (false), `remoteEmbeddingEndpoint`, `remoteEmbeddingApiKeyFrom`, `requireApprovalForExplicitRoot` (false). None of these eleven has a card control; the only thing that makes them take effect is the `config:` block of the registration row in the next paragraph, and precedence is row `config:` > the `.default()` in code.
19
26
 
20
- Whether workspace content may leave the machine at all is treated as a deployment decision rather than a model-visible choice, which is why the remote-embedding trio appears in neither the card nor the tool parameters; and even when it is enabled, `zg` itself still requires `--allow-remote` or `zg auth grant`. Set all of these in the `config:` block of this plugin's row in your profile's `cordis.yml` (the `cordis.patch.yml` shipped in this package carries that row's `id` / `name` plus a second, **id-less** entry for `@jayyuen66/dsh-plugin-shared` that supplies the card components — deleting it leaves the settings card without its component supplier); they take effect on restart.
27
+ Whether workspace content may leave the machine at all is treated as a deployment decision rather than a model-visible choice, which is why the remote-embedding trio appears in neither the card nor the tool parameters; and even when it is enabled, `zg` itself still requires `--allow-remote` (added automatically by this plugin to remote-reference index commands once the deployment switch is on) or a one-time persistent `zg --auth grant`. Set all of these in the `config:` block of this plugin's row in your profile's `cordis.yml` (the `cordis.patch.yml` shipped in this package carries that row's `id` / `name` plus a second, **id-less** entry for `@jayyuen66/dsh-plugin-shared` that supplies the card components — deleting it leaves the settings card without its component supplier); they take effect on restart.
21
28
 
22
29
  ## What it needs from outside
23
30
 
24
- The external `zg` CLI (`@zvec/zvec-grep`, installed with `npm install -g @zvec/zvec-grep`). The plugin enforces a version floor of **0.2.2** before it builds any command and says so when the installed one is older; a missing CLI is reported as such instead of failing a search. Incremental index refresh, `refresh=background` and the resident model pool need the daemon running (`zg server on`) — when it is offline the card says so. Local embedding backends may require their own native dependency (llama-cpp needs `node-llama-cpp`; model2vec and transformers-js are pure JavaScript). When `allowRemoteEmbedding` is on, the plugin forwards two variables to `zg`: `ZVEC_GREP_ENDPOINT` carries the literal value of `remoteEmbeddingEndpoint` (the deployment endpoint, not a variable name), and `ZVEC_GREP_API_KEY` is the secret looked up from the variable named by `remoteEmbeddingApiKeyFrom`. The key is passed explicitly because the host's subprocess layer strips secret-shaped variables.
31
+ The external `zg` CLI (`@zvec/zvec-grep`, installed with `npm install -g @zvec/zvec-grep`). The plugin enforces a version floor of **0.3.0** (the Rust rewrite's CLI shape; 0.2.x is rejected at the gate) before it builds any command and says so when the installed one is older; a missing CLI is reported as such instead of failing a search. Incremental index refresh, `refresh=background` and the resident model pool need the daemon running (`zg --server on`, or `transport=mcp` lets the plugin start one) — when it is offline the card says so. Local embedding backends may require their own native dependency (llama-cpp needs `node-llama-cpp`; model2vec and transformers-js are pure JavaScript). When `allowRemoteEmbedding` is on, the plugin forwards two variables to `zg`: `ZVEC_GREP_ENDPOINT` carries the literal value of `remoteEmbeddingEndpoint` (the deployment endpoint, not a variable name), and `ZVEC_GREP_API_KEY` is the secret looked up from the variable named by `remoteEmbeddingApiKeyFrom`. The key is passed explicitly because the host's subprocess layer strips secret-shaped variables.
25
32
 
26
33
  ## Further detail
27
34
 
package/docs/DETAIL.zh.md CHANGED
@@ -4,25 +4,32 @@
4
4
 
5
5
  ## 设置卡上改的是什么
6
6
 
7
- - **检索模型** — `defaultEmbedding`(默认 `local/qwen3-embedding-0.6b`,约 640 MB)只作用于**新建**的索引;已有索引沿用它自己的模型,要换得先重建。`defaultLimit`(1–50,默认 10)是每组结果返回多少条命中。
8
- - **网络与索引** — `hfEndpoint` 默认指向 ModelScope 镜像(`https://modelscope.cn/models`);留空就是 huggingface.co,而这个环境通常连不上,所以默认值应当保留。`enforceSearchFirst`(默认开)在已建索引的工作区里拦住 `grep` / `rg`。`grepBudgetPerSearch`(默认 3)是一次**走索引的** `zg_search` 解锁多少次直查(无索引时自动改走穷举词法的检索同样成功,但不发配额),`unlockWindowMin`(默认 10)是这份解锁维持几分钟。配额按「会话 × 索引根」记账(索引根是 root 或最近的含索引祖先,最多上溯 8 层),不是全局一份;「让路」只在宿主提供了步骤准入(`toolSet`)且该视图不含 `zg_search` 时成立——不提供准入信息的宿主仍按原判据拦截。有效期在每次取用配额时现判,窗口一过就不再放行直查、不需要重启;分片表按会话数封顶 256,超出时先淘汰最久未用的那一份。该索引根上有活跃重建时,门禁临时放行且**不消耗配额**:重建持着写锁,这期间语义检索必然失败,门禁不能再把直查一起堵死。本步骤的工具准入不含 `zg_search` 时,门禁让路,不强迫模型去调一个本步骤调不动的工具。
7
+ - **检索模型** — `defaultEmbedding`(默认 `local/qwen3-embedding-0.6b`,约 640 MB)只作用于**新建**的索引;已有索引沿用它自己的模型,要换得先重建。下拉分本地与远程两组:远程 qwen 模型(0.3.0 新增三枚)需在部署配置里打开 `allowRemoteEmbedding` 才可选——远程会把工作区内容送到外部端点,且首次索引要用户执行一次 `zg --auth grant` 授权。`defaultLimit`(1–50,默认 10)是每组结果返回多少条命中。
8
+ - **网络与索引** — 「检索传输方式」(`transport`,0.3.0 起)三档:自动 = 守护进程在跑时检索走 MCP(常驻模型池、队列调度),否则走 CLI;仅 CLI = 永不碰守护进程;仅 MCP = 检索恒走守护进程,缺席时由插件自动拉起(会开 `127.0.0.1:7999` 回环端口;拉起失败明确报错,不静默回退)。`hfEndpoint` 默认指向 ModelScope 镜像(`https://modelscope.cn/models`);留空就是 huggingface.co,而这个环境通常连不上,所以默认值应当保留。`enforceSearchFirst`(默认开)在已建索引的工作区里拦住 `grep` / `rg`。`grepBudgetPerSearch`(默认 3)是一次**走索引的** `zg_search` 解锁多少次直查(无索引时自动改走穷举词法的检索同样成功,但不发配额),`unlockWindowMin`(默认 10)是这份解锁维持几分钟。配额按「会话 × 索引根」记录(索引根是 root 或最近的含索引祖先,最多上溯 8 层),不是全局一份;「让路」只在宿主提供了步骤准入(`toolSet`)且该视图不含 `zg_search` 时成立——不提供准入信息的宿主仍按原判据拦截。有效期在每次取用配额时现判,窗口一过就不再放行直查、不需要重启;分片表按会话数封顶 256,超出时先淘汰最久未用的那一份。该索引根上有活跃重建时,检查临时放行且**不消耗配额**:重建持着写锁,这期间语义检索必然失败,检查不能再把直查一起堵死。本步骤的工具准入不含 `zg_search` 时,检查让路,不强迫模型去调一个本步骤调不动的工具。
9
9
 
10
10
  这些每次调用现读,改完不需要重启宿主。
11
11
 
12
+ ## 并发与平台
13
+
14
+ - **同一宿主**内的并发冷启动合并成一发 `zg --server on`。**多个宿主**共用 `ZVEC_GREP_HOME` 时共享同一个守护进程(上游 `instance.lock`;重复启动退 0 并回同一个 PID)。token 用 O_EXCL 原子认领,后来者读回同一枚,不会互相覆盖;只有创建者会在卸载时停掉自己拉起的 daemon。
15
+ - 同一条 zg MCP 会话一次只处理一个 `tools/call`(实测两发并发时第二条会挂到调用方超时),所以每个并发工具调用各用一条会话,空闲会话复用;不把并发请求塞进同一条会话。索引作业的并发上限(默认 2)与同根写作业复用由上游调度器负责。
16
+ - 检索只在同根索引重建持写锁时等待,上限 `rebuildWaitMs`;冷启动本身不排队。
17
+ - **平台**:POSIX 收 `/…` 根、bash 单引号转义;Windows 收盘符/UNC 根、pwsh 单引号转义(内嵌 `'` 写成 `''`)、命令名剥 `.exe`/`.cmd` 等扩展,并按 CreateProcess 余量把命令规模上限收到 24000 字节。Windows 的真盘行为由 CI 的 `windows-latest` 格验证;本地用平台注入的 win32 夹具覆盖同一套判据。
18
+
12
19
  ## Rebuild 不是设置项
13
20
 
14
- 卡上的 Rebuild 是对守护进程已经观察到的工作区跑一次等价于 `zg index --rebuild` 的动作,不是被存起来的偏好。这条路上不会弹审批:pre-execute 审批只覆盖显式给了 root 的 `zg_*` 工具,Remote 方法不走工具准入;真正管住它的是守护进程那份已观测根白名单(以及它自己的单操作锁)。
21
+ 卡上的 Rebuild 是对守护进程已经观察到的工作区跑一次等价于 `zg --index --rebuild` 的动作,不是被存起来的偏好。这条路上不会弹审批:pre-execute 审批只覆盖显式给了 root 的 `zg_*` 工具,Remote 方法不走工具准入;真正管住它的是守护进程那份已观测根白名单(以及它自己的单操作锁)。
15
22
 
16
23
  ## 要重启的值
17
24
 
18
- 十项部署值刻意不进设置卡:`searchTimeoutMs`(300000)、`statusTimeoutMs`(60000)、`indexTimeoutMs`(600000)、`stdoutMaxBytes`(400000)、`rebuildWaitMs`(120000)、`clientMode`(`auto` / `direct` / `server`)、`allowRemoteEmbedding`(false)、`remoteEmbeddingEndpoint`、`remoteEmbeddingApiKeyFrom`、`requireApprovalForExplicitRoot`(false)。这十项在卡上没有入口,能生效的只有下一段那条注册行 `config:`;优先级是注册行 `config:` > 代码里的 `.default()`。
25
+ 十一项部署值刻意不进设置卡:`searchTimeoutMs`(300000)、`statusTimeoutMs`(60000)、`indexTimeoutMs`(600000)、`stdoutMaxBytes`(400000)、`rebuildWaitMs`(120000)、`clientMode`(`auto` / `direct` / `server`)、`daemonUrl`(`http://127.0.0.1:7999/mcp`,MCP 传输的守护进程端点)、`allowRemoteEmbedding`(false)、`remoteEmbeddingEndpoint`、`remoteEmbeddingApiKeyFrom`、`requireApprovalForExplicitRoot`(false)。这十一项在卡上没有入口,能生效的只有下一段那条注册行 `config:`;优先级是注册行 `config:` > 代码里的 `.default()`。
19
26
 
20
- 「工作区内容能不能离开本机」被当成部署决定,而不是给模型选的开关,所以远程嵌入那三枚既不在卡上也不在工具参数里;即便开了,`zg` 自己仍要求 `--allow-remote` 或 `zg auth grant`。这些值都写在**自己 profile 的 `cordis.yml`** 里本插件注册行的 `config:` 块(随包那份 `cordis.patch.yml` 带本行的 `id` / `name`,另有一条**不写 id** 的 `@jayyuen66/dsh-plugin-shared` 条目供应卡片组件——删掉它设置卡会失去组件供应),改值随重启生效。
27
+ 「工作区内容能不能离开本机」被当成部署决定,而不是给模型选的开关,所以远程嵌入那三枚既不在卡上也不在工具参数里;即便开了,`zg` 自己仍要求 `--allow-remote`(部署开放后本插件在远程引用的索引命令上自动补)或一次 `zg --auth grant` 持久授权。这些值都写在**自己 profile 的 `cordis.yml`** 里本插件注册行的 `config:` 块(随包那份 `cordis.patch.yml` 带本行的 `id` / `name`,另有一条**不写 id** 的 `@jayyuen66/dsh-plugin-shared` 条目供应卡片组件——删掉它设置卡会失去组件供应),改值随重启生效。
21
28
 
22
29
  ## 需要外部提供什么
23
30
 
24
- 外部 `zg` 命令行(`@zvec/zvec-grep`,装法是 `npm install -g @zvec/zvec-grep`)。本插件在拼出任何命令之前先校版本,地板是 **0.2.2**,装的版本低于它会直接说明;命令行不存在时按「未安装」报,而不是伪装成一次查不到。增量索引刷新、`refresh=background` 与常驻模型池都需要守护进程在跑(`zg server on`),离线时卡上会写出来。本地嵌入的后端可能还要各自的依赖(llama-cpp 需要 `node-llama-cpp`;model2vec 与 transformers-js 是纯 JavaScript)。只有 `allowRemoteEmbedding` 开着时,插件才向 `zg` 转发这两个变量:`ZVEC_GREP_ENDPOINT` 放的是 `remoteEmbeddingEndpoint` 的字面值(部署端点,不是变量名),`ZVEC_GREP_API_KEY` 才是按 `remoteEmbeddingApiKeyFrom` 指的变量名去环境里查出来的密钥。密钥要显式转发,因为宿主的子进程层会抹掉形似密钥的变量。
31
+ 外部 `zg` 命令行(`@zvec/zvec-grep`,装法是 `npm install -g @zvec/zvec-grep`)。本插件在拼出任何命令之前先校版本,下限是 **0.3.0**(上游 Rust 重写后的 CLI 形态与 0.2.x 不兼容,0.2.x 会在门槛处被拦下),装的版本低于它会直接说明;命令行不存在时按「未安装」报,而不是伪装成一次查不到。增量索引刷新、`refresh=background` 与常驻模型池都需要守护进程在跑(`zg --server on`),离线时卡上会写出来。本地嵌入的后端可能还要各自的依赖(llama-cpp 需要 `node-llama-cpp`;model2vec 与 transformers-js 是纯 JavaScript)。只有 `allowRemoteEmbedding` 开着时,插件才向 `zg` 转发这两个变量:`ZVEC_GREP_ENDPOINT` 放的是 `remoteEmbeddingEndpoint` 的字面值(部署端点,不是变量名),`ZVEC_GREP_API_KEY` 才是按 `remoteEmbeddingApiKeyFrom` 指的变量名去环境里查出来的密钥。密钥要显式转发,因为宿主的子进程层会抹掉形似密钥的变量。
25
32
 
26
33
  ## 更完整的说明
27
34
 
28
- 参数守卫、`root` 判据与后台作业面都写在随包 README(`README.md` / `README.zh-CN.md`)。README 没有独立的错误码表:`zg` 不在 PATH 上按 `exit 127` 归到「未安装」(见「外部依赖」一节),其余失败按工具回执里的 `reason` 读。
35
+ 参数守卫、`root`判据与后台作业那一节都写在随包 README(`README.md` / `README.zh-CN.md`)。README 没有独立的错误码表:`zg` 不在 PATH 上按 `exit 127` 归到「未安装」(见「外部依赖」一节),其余失败按工具回执里的 `reason` 读。