@jayyuen66/dsh-zvec-grep 0.1.7 → 0.1.9

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 ADDED
@@ -0,0 +1,28 @@
1
+ # Zvec indexed search
2
+
3
+ Searches the workspace through a local index instead of raw grep, and can require an indexed search before plain `grep` / `rg` are allowed.
4
+
5
+ ## What the card changes
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) how many minutes that unlock stays valid — unlock entries age out on their own TTL and LRU, so they do not wait for a restart. 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
+
10
+ These are read per call and take effect without restarting the host.
11
+
12
+ ## The Rebuild action is not a setting
13
+
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 with an approval prompt, not a stored preference.
15
+
16
+ ## Restart-only values
17
+
18
+ Ten deployment values stay off the card: `searchTimeoutMs` (300000), `statusTimeoutMs` (60000), `indexTimeoutMs` (600000), `stdoutMaxBytes` (400000), `rebuildWaitMs`, `clientMode` (`auto` / `direct` / `server`), `allowRemoteEmbedding` (false), `remoteEmbeddingEndpoint`, `remoteEmbeddingApiKeyFrom`, `requireApprovalForExplicitRoot` (false).
19
+
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 `cordis.patch.yml`; they take effect on restart.
21
+
22
+ ## What it needs from outside
23
+
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). `ZVEC_GREP_ENDPOINT` and `ZVEC_GREP_API_KEY` are read as environment references; the key is forwarded explicitly because the host's subprocess layer strips secret-shaped variables.
25
+
26
+ ## Further detail
27
+
28
+ The error-code table, the argument guards and the background-job surface are in the package README (`README.md` / `README.zh-CN.md`).
@@ -0,0 +1,28 @@
1
+ # Zvec 索引检索
2
+
3
+ 用本地索引检索工作区,而不是裸 grep;也可以要求先走一次索引检索,才允许用普通 `grep` / `rg`。
4
+
5
+ ## 设置卡上改的是什么
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)是这份解锁维持几分钟——解锁条目按自己的 TTL 与 LRU 过期,不等进程重启。本步骤的工具准入不含 `zg_search` 时,门禁让路,不强迫模型去调一个本步骤调不动的工具。
9
+
10
+ 这些每次调用现读,改完不需要重启宿主。
11
+
12
+ ## Rebuild 不是设置项
13
+
14
+ 卡上的 Rebuild 是对守护进程已经观察到的工作区跑一次等价于 `zg index --rebuild` 的动作,带审批提示;它不是被存起来的偏好。
15
+
16
+ ## 要重启的值
17
+
18
+ 十项部署值刻意不进设置卡:`searchTimeoutMs`(300000)、`statusTimeoutMs`(60000)、`indexTimeoutMs`(600000)、`stdoutMaxBytes`(400000)、`rebuildWaitMs`、`clientMode`(`auto` / `direct` / `server`)、`allowRemoteEmbedding`(false)、`remoteEmbeddingEndpoint`、`remoteEmbeddingApiKeyFrom`、`requireApprovalForExplicitRoot`(false)。
19
+
20
+ 「工作区内容能不能离开本机」被当成部署决定,而不是给模型选的开关,所以远程嵌入那三枚既不在卡上也不在工具参数里;即便开了,`zg` 自己仍要求 `--allow-remote` 或 `zg auth grant`。这些值都写在本插件注册行的 `config:` 块,改值随重启生效。
21
+
22
+ ## 需要外部提供什么
23
+
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)。`ZVEC_GREP_ENDPOINT` 与 `ZVEC_GREP_API_KEY` 按环境变量引用读取;密钥要显式转发,因为宿主的子进程层会抹掉形似密钥的变量。
25
+
26
+ ## 更完整的说明
27
+
28
+ 错误码表、参数守卫与后台作业面都写在随包 README(`README.md` / `README.zh-CN.md`)。
package/host.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import Schema from "@deepseek-ai/schemastery";
3
3
  import { accessSync, constants, existsSync, readFileSync, statSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
+ import { scopeOf } from "@deepseek-ai/dsh-scope";
5
6
  import { isRecord } from "@jayyuen66/dsh-plugin-shared/lib/record";
6
7
  import { errorText } from "@jayyuen66/dsh-plugin-shared/lib/errors";
7
8
  import { LOCALE_SETTINGS_NAMESPACE, messagesFor, resolveLocalePreference } from "@jayyuen66/dsh-plugin-shared/lib/locale";
@@ -105,7 +106,7 @@ const MESSAGES = {
105
106
  ftsDescription: "词法查询组(如标识符、报错串)",
106
107
  vectorDescription: "纯语义查询组",
107
108
  fuseDescription: "融合所有组为单一排名",
108
- limitDescription: "每组最大条数 1-50,默认 10",
109
+ limitDescription: "每组最大条数 1-50,默认 10;越出区间直接报错",
109
110
  previewDescription: "每条命中带的源码片段大小:none 只给锚点行、short 给锚点加一段有界上下文、full 给整段源码。默认 short",
110
111
  refreshDescription: "检索前如何刷新索引:wait 等刷新到最新(默认)、off 不刷新、background 交给守护进程后台刷新。background 只在守护进程就绪时可用:没有守护进程时这一档在命令构造前就被拒绝(直连模式下 zg 只会静默关掉刷新并留一行 stderr warning,那等于把「没刷新」说成「后台在刷」),要它请先在终端执行 `zg server on`",
111
112
  globsDescription: "路径 glob(如 src/**),单个字符串或数组",
@@ -161,6 +162,7 @@ const MESSAGES = {
161
162
  abortedFailure: "zg 执行被中止",
162
163
  rebuildWaitTimeout: "等待 {root} 的重建完成超时(约 {seconds} 秒),重建可能仍在进行;请稍后重试。本次不会发放 grep/rg 配额——重建期间索引不可读,先等它结束。",
163
164
  rebuildWaitAborted: "等待 {root} 的重建完成时被中止。",
165
+ lockBusyOtherOperation: "zg 索引锁正被其他操作占用(ownerOperation: {op}),本命令没有等待它结束:这类操作(如索引刷新)可能耗时很久,稍后重试或等它落定后再查",
164
166
  statusRebuilding: "{root} 正在重建中(作业 {jobId})。重建期间索引不可读,检索会自动等待它完成后重试。如需查看实时输出,请在设置卡的工作区重建面板里观察。此刻即使问「索引是否就绪」也是否定的答案——重建落定后再问。",
165
167
  statusNotReady: "[zvec-grep] {root} 的索引**未就绪**(上面是 zg 的完整就绪报告)。这不是执行失败,而是 checkReady=true 要的那个结论:{detail} 若刷新反复失败(报告里出现 `read only mode` 一类写入被拒的措辞),那是该索引自身的状态问题,重建即可恢复:zg_index(root=\"…\", confirm=true, rebuild=true)。",
166
168
  checkReadyDescription: "就绪判定:就绪报告照常给出,另行判定索引是否 ready 并在结论里明说。未就绪不是执行失败,报告仍会返回",
@@ -223,6 +225,7 @@ const MESSAGES = {
223
225
  rootIsFsRoot: "root 不能是文件系统根目录 /",
224
226
  rootRequiredWithFallback: "root 必填,且为工作区绝对路径(可省略:缺省为当前会话工作区)",
225
227
  limitInvalid: "limit 必须是非负整数(省略则用默认值)",
228
+ limitOutOfRange: "limit 超出允许范围 {min}–{max}(省略则用默认值)",
226
229
  mustBeStringArray: "{name} 必须是字符串数组",
227
230
  tooManyItems: "{name} 最多 {maxItems} 项(实际 {actual})",
228
231
  nonStringItem: "{name} 含非字符串项({received})",
@@ -259,7 +262,7 @@ const MESSAGES = {
259
262
  ftsDescription: "Lexical query groups (identifiers, error strings)",
260
263
  vectorDescription: "Purely semantic query groups",
261
264
  fuseDescription: "Fuse all groups into a single ranking",
262
- limitDescription: "Max hits per group, 1-50, default 10",
265
+ limitDescription: "Max hits per group, 1-50, default 10; a value outside that range is refused",
263
266
  previewDescription: "How much source each hit carries: none anchor line only, short anchor plus a bounded context window, full the whole chunk. Default short",
264
267
  refreshDescription: "How the index is refreshed before searching: wait refreshes to the latest (default), off does not refresh, background hands it to the daemon. background needs a ready daemon: without one it is refused before the command is built (in direct mode zg silently turns refreshing off and leaves one stderr warning, which would report \"refreshing in the background\" when nothing refreshes) — run `zg server on` in a terminal to get it",
265
268
  globsDescription: "Path globs (e.g. src/**), a single string or an array",
@@ -315,6 +318,7 @@ const MESSAGES = {
315
318
  abortedFailure: "zg execution was aborted",
316
319
  rebuildWaitTimeout: "timed out after about {seconds}s waiting for the rebuild of {root}; it may still be running. Retry later. No grep/rg quota is granted: the index is unreadable while the rebuild runs.",
317
320
  rebuildWaitAborted: "aborted while waiting for the rebuild of {root} to finish",
321
+ lockBusyOtherOperation: "the zg index lock is held by another operation (ownerOperation: {op}); this command did not wait for it: such operations (e.g. an index refresh) can run very long — retry later, or query again once it settles",
318
322
  statusRebuilding: "{root} is being rebuilt (job {jobId}). The index is unreadable while the rebuild runs; searches wait for it to finish and retry. Watch live output in the settings card rebuild panel. Asking whether the index is ready right now would get a negative answer anyway — ask again once the rebuild settles.",
319
323
  statusNotReady: "[zvec-grep] the index for {root} is **not ready** (the full zg readiness report is above). This is not an execution failure, it is the conclusion checkReady=true asked for: {detail} If refreshes keep failing (wording like `read only mode` means writes are refused), that is the index's own state — rebuild it to recover: zg_index(root=\"…\", confirm=true, rebuild=true).",
320
324
  checkReadyDescription: "Readiness verdict: the readiness report is still returned, and the tool additionally states whether the index is ready. Not-ready is not an execution failure — the report still comes back",
@@ -377,6 +381,7 @@ const MESSAGES = {
377
381
  rootIsFsRoot: "root must not be the filesystem root /",
378
382
  rootRequiredWithFallback: "root is required and must be an absolute workspace path (it may be omitted: defaults to the current session workspace)",
379
383
  limitInvalid: "limit must be a non-negative integer (omit it to use the default)",
384
+ limitOutOfRange: "limit is out of the allowed range {min}–{max} (omit it to use the default)",
380
385
  mustBeStringArray: "{name} must be an array of strings",
381
386
  tooManyItems: "{name} allows at most {maxItems} items (actual {actual})",
382
387
  nonStringItem: "{name} contains a non-string item ({received})",
@@ -684,16 +689,22 @@ function resolveRoot(value, fallback, messages) {
684
689
  throw new Error(messages.rootRequiredWithFallback);
685
690
  }
686
691
  /**
687
- * limit 钳制:省略(undefined/null)回默认;给了但不是非负整数即抛;越界钳到 [LIMIT_MIN, LIMIT_MAX]。
692
+ * limit 取值:省略(undefined/null)回默认;不是非负整数即抛;越界拒绝并点名区间。
688
693
  *
689
694
  * 类型只认 number:`Number()` 会把 `true` 折成 1、把 `[]` 折成 0——模型给一个类型错的 limit
690
- * 就会静默只回一条结果,而它会把「只有一处命中」当成这次检索的事实。
695
+ * 就会静默只回一条结果,而它会把「只有一处命中」当成这次检索的事实。越界同样拒绝而不是
696
+ * 钳制:静默钳过的 limit 让模型以为要回了 999 条、实际只看到 50 条,还把「少」当成了事实;
697
+ * 拒绝并报区间,下一轮它自己改对。
691
698
  */
692
- function clampLimit(value, messages, fallback = 10) {
699
+ function resolveLimit(value, messages, fallback = 10) {
693
700
  if (value === void 0 || value === null) return fallback;
694
701
  if (typeof value !== "number") throw new TypeError(messages.limitInvalid);
695
702
  if (!Number.isSafeInteger(value) || value < 0) throw new Error(messages.limitInvalid);
696
- return Math.min(50, Math.max(1, value));
703
+ if (value < 1 || value > 50) throw new Error(fill(messages.limitOutOfRange, {
704
+ min: 1,
705
+ max: 50
706
+ }));
707
+ return value;
697
708
  }
698
709
  /** 检索类数组(queries/fts/vector)取值:条数与单条长度都放宽到 query 档。 */
699
710
  function queryList(value, name, messages) {
@@ -781,7 +792,7 @@ function buildIndexedCommand(args, root, messages, mode, backgroundSupport) {
781
792
  const refresh = refreshOf(args.refresh, messages);
782
793
  if (refresh === "background" && backgroundSupport === "daemon-down") throw new Error(fill(messages.refreshBackgroundNeedsServer, { root }));
783
794
  if (refresh === "background" && backgroundSupport === "mode-direct") throw new Error(fill(messages.refreshBackgroundPinnedDirect, { root }));
784
- parts.push("--limit", String(clampLimit(args.limit, messages)), "--preview", previewOf(args.preview, messages), "--refresh", refresh);
795
+ parts.push("--limit", String(resolveLimit(args.limit, messages)), "--preview", previewOf(args.preview, messages), "--refresh", refresh);
785
796
  pushSearchGlobs(parts, args, messages);
786
797
  if (boolOf(args.preferSymbol, "preferSymbol", messages)) parts.push("--prefer-symbol");
787
798
  if (boolOf(args.trace, "trace", messages)) parts.push("--trace");
@@ -826,7 +837,7 @@ function buildExhaustiveCommand(args, root, messages, mode) {
826
837
  if (pattern.length === 0) throw new Error(messages.exhaustiveNeedsPattern);
827
838
  if (pattern.startsWith("-")) parts.push("-e", shq(pattern));
828
839
  else parts.push(shq(pattern));
829
- parts.push("--limit", String(clampLimit(args.limit, messages)));
840
+ parts.push("--limit", String(resolveLimit(args.limit, messages)));
830
841
  pushPathFilters(parts, args, messages);
831
842
  pushTimeFilters(parts, args, messages);
832
843
  parts.push(deviceFlag(args.device, messages), modeFlag(mode));
@@ -1039,6 +1050,8 @@ function buildStatusCommand(args, messages, mode = DEFAULT_CLIENT_MODE) {
1039
1050
  return assembled(parts, root, messages);
1040
1051
  }
1041
1052
  // lib/search-predicates.ts
1053
+ /** 根目录末尾斜杠。 */
1054
+ const TRAILING_SLASHES$1 = /\/+$/u;
1042
1055
  const GREP_COMMAND_NAMES = /* @__PURE__ */ new Set([
1043
1056
  "grep",
1044
1057
  "egrep",
@@ -1101,7 +1114,7 @@ const VALUE_TAKING_FLAGS = /* @__PURE__ */ new Set([
1101
1114
  "--user"
1102
1115
  ]);
1103
1116
  /** 命令前的壳层赋值(`VAR=1 grep x` 里的 `VAR=1`):它自己不是命令,其后仍是命令位。 */
1104
- const SHELL_ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/u;
1117
+ const SHELL_ASSIGNMENT = /^[A-Za-z_]\w*=/u;
1105
1118
  /** 包装命令的裸数值参数(`timeout 5 rg` 的 `5`):也不是被执行的命令。 */
1106
1119
  const BARE_NUMBER = /^\d+$/u;
1107
1120
  /** 结束一个 token、但**不**开启新命令位的字符(空白、右括号、重定向)。 */
@@ -1283,7 +1296,7 @@ function isGrepRgCommand(command) {
1283
1296
  * 失败形态是 fail-fast 而不是静默漂移。要真正支持 Windows,得连上面那三处判据一起改。
1284
1297
  */
1285
1298
  function normalizeRoot(root) {
1286
- const trimmed = root.replace(/\/+$/u, "");
1299
+ const trimmed = root.replace(TRAILING_SLASHES$1, "");
1287
1300
  return trimmed.length > 0 ? trimmed : "/";
1288
1301
  }
1289
1302
  /**
@@ -1380,6 +1393,19 @@ const ZG_TOOL_NAMES = /* @__PURE__ */ new Set([
1380
1393
  function isZgToolName(name) {
1381
1394
  return typeof name === "string" && ZG_TOOL_NAMES.has(name);
1382
1395
  }
1396
+ /** search-first 门禁要求先调用的工具名(与注册表里的名字同源)。 */
1397
+ const ZG_SEARCH_NAME = "zg_search";
1398
+ /**
1399
+ * `zg_search` 在本步骤是否可执行。宿主不交步骤准入(rc 线)时按既有的「可执行」处理:
1400
+ * 没有准入信息就不该凭空放行。有准入时按该 Agent 的作用域查视图——受限子代理的
1401
+ * 拒绝与条件工具的未准入都在这里显形,门禁不再强迫模型去调一个本步骤调不动的工具。
1402
+ */
1403
+ function searchAdmitted(execution) {
1404
+ const { toolSet } = execution;
1405
+ if (toolSet === void 0) return true;
1406
+ const scope = execution.agent?.ctx === void 0 ? void 0 : scopeOf(execution.agent.ctx);
1407
+ return toolSet.view(scope).has(ZG_SEARCH_NAME);
1408
+ }
1383
1409
  /** 会话工作区(官方 Agent.session.header.cwd;值按 unknown 读,理由见 SessionFace)。 */
1384
1410
  function sessionHeaderCwd$1(execution) {
1385
1411
  const raw = execution.agent?.session?.header?.cwd;
@@ -1576,7 +1602,7 @@ function searchFirstGuard(execution, deps, messages) {
1576
1602
  const args = isRecord(execution.arguments) ? execution.arguments : {};
1577
1603
  const cwd = sessionHeaderCwd$1(execution);
1578
1604
  let reason;
1579
- if (deps.enabled && cwd !== void 0) {
1605
+ if (deps.enabled && cwd !== void 0 && searchAdmitted(execution)) {
1580
1606
  if (name === "bash" || name === "pwsh") reason = shellSearchProblem(args, cwd, deps, messages);
1581
1607
  else if (name === "grep") reason = nativeGrepProblem(args, cwd, deps, messages);
1582
1608
  }
@@ -1690,6 +1716,8 @@ function createRebuildRegistry(options = {}) {
1690
1716
  }
1691
1717
  /** 索引重建与其它占用者分开:等与不等是两回事。 */
1692
1718
  const REBUILD_OPERATION = "index.rebuild";
1719
+ /** 明细块的表头行(`Details:`)。 */
1720
+ const DETAILS_HEADER = /^\s*Details:\s*$/u;
1693
1721
  /**
1694
1722
  * zg 明细块的键值行。三个细节都来自「明细行是缩进的」这一实测形状:
1695
1723
  * - 缩进**必填**(`\s+`):明细块之后任何含冒号的非空行(第二个错误块的 `Error:` /
@@ -1698,7 +1726,7 @@ const REBUILD_OPERATION = "index.rebuild";
1698
1726
  * 还能被认出来(值是否被消费由查表侧决定),不至于整块收集在此中断;
1699
1727
  * - 值必须以非空白开头:把只含空白的行当成有效值没有意义。
1700
1728
  */
1701
- const DETAIL_LINE = /^(?:\s+)(?<key>[A-Za-z][\w-]*):\s*(?<value>\S.*?)\s*$/u;
1729
+ const DETAIL_LINE = /^\s+(?<key>[A-Za-z][\w-]*):\s*(?<value>\S.*)$/u;
1702
1730
  /** 错误码行的**定位**形状(只认行首,不核内容)。 */
1703
1731
  const CODE_LINE_PREFIX = /^\s*Code:/u;
1704
1732
  /** 错误码行的**取值**形状:`Code:` 之后是单一 token。 */
@@ -1721,12 +1749,12 @@ function zgErrorCode(stderr) {
1721
1749
  function zgErrorDetails(stderr) {
1722
1750
  const details = /* @__PURE__ */ new Map();
1723
1751
  const lines = stderr.split("\n");
1724
- const start = lines.findIndex((line) => /^\s*Details:\s*$/u.test(line));
1752
+ const start = lines.findIndex((line) => DETAILS_HEADER.test(line));
1725
1753
  if (start === -1) return details;
1726
1754
  for (const line of lines.slice(start + 1)) {
1727
1755
  const matched = DETAIL_LINE.exec(line);
1728
1756
  const key = matched?.groups?.["key"];
1729
- const value = matched?.groups?.["value"];
1757
+ const value = matched?.groups?.["value"]?.trimEnd();
1730
1758
  if (key !== void 0 && value !== void 0) {
1731
1759
  if (!details.has(key)) details.set(key, value);
1732
1760
  } else if (line.trim().length > 0) break;
@@ -1918,6 +1946,8 @@ function procSandboxNote(proc, messages) {
1918
1946
  /** 宿主服务键 = 客户端线上命名空间(两侧共用的唯一来源)。 */
1919
1947
  const REBUILD_REMOTE_NAMESPACE = "zvecGrepRebuild";
1920
1948
  // lib/zg-config.ts
1949
+ /** 端点末尾斜杠。 */
1950
+ const TRAILING_SLASHES = /\/+$/u;
1921
1951
  /** http(s) 且带 host 的基地址才算端点:`http://`、`/` 这类值不是可用的镜像基地址。 */
1922
1952
  function isUsableBaseUrl(value) {
1923
1953
  try {
@@ -1937,7 +1967,7 @@ function hfEndpointEnv(config) {
1937
1967
  const endpoint = config.hfEndpoint.get();
1938
1968
  let env;
1939
1969
  if (typeof endpoint === "string") {
1940
- const normalized = endpoint.trim().replace(/\/+$/u, "");
1970
+ const normalized = endpoint.trim().replace(TRAILING_SLASHES, "");
1941
1971
  if (normalized.length > 0 && isUsableBaseUrl(normalized)) env = { HF_ENDPOINT: normalized };
1942
1972
  }
1943
1973
  return env;
@@ -1965,7 +1995,7 @@ function allowRemoteEmbedding(config) {
1965
1995
  * 任意变量(含与 zg 无关的敏感值)转发给子进程;`__proto__` / `constructor` 这类键还会
1966
1996
  * 让 `process.env[name]` 读到对象而不是字符串。不匹配的名字按「没配」处理。
1967
1997
  */
1968
- const ENV_NAME_SHAPE = /^[A-Za-z_][A-Za-z0-9_]*$/u;
1998
+ const ENV_NAME_SHAPE = /^[A-Za-z_]\w*$/u;
1969
1999
  /**
1970
2000
  * zg 子进程的环境变量:HF 镜像 + (仅在部署开放远程 embedding 时的)远程端点与凭据。
1971
2001
  *
@@ -2150,8 +2180,10 @@ function pruneRebuildHistory(jobs, records) {
2150
2180
  * 为什么单独认这一条:它是本包唯一会把宿主英文原话插进中文卡片的错误,又恰恰最该翻成
2151
2181
  * 人话的那一条——用户此时要做的是去 job_list 里收掉不需要的作业,而不是读一句英文。
2152
2182
  */
2183
+ /** 远端容量上限的括号形态。 */
2184
+ const CAPACITY_LIMIT = /\(limit: (?<limit>\d+)\)/u;
2153
2185
  function capacityLimitOf(error) {
2154
- return /\(limit: (?<limit>\d+)\)/u.exec(errorText(error))?.groups?.["limit"];
2186
+ return CAPACITY_LIMIT.exec(errorText(error))?.groups?.["limit"];
2155
2187
  }
2156
2188
  /**
2157
2189
  * 「工作区重建」的四道前置校验:绝对路径 + 归一化、本 daemon 观测过的白名单、
@@ -2597,6 +2629,8 @@ function installRebuildRemote(ctx, deps) {
2597
2629
  return true;
2598
2630
  }
2599
2631
  // host.ts
2632
+ /** 纯数字计数行。 */
2633
+ const DIGITS_ONLY = /^\d+$/u;
2600
2634
  const SEARCH_TIMEOUT_MS = 3e5;
2601
2635
  const STATUS_TIMEOUT_MS = 6e4;
2602
2636
  const INDEX_TIMEOUT_MS = 6e5;
@@ -2926,7 +2960,7 @@ const HITS_LINE_PREFIX = "hits: ";
2926
2960
  const HIT_LINE_PREFIX = /^#\d+(?:\s+\[[^\]]*\])?\s+matchedBy=\S+\s+(?:score=-?\d+(?:\.\d+)?\s+)?(?<location>\S.*)$/u;
2927
2961
  function hitSummary(stdoutText, limit, truncated, messages) {
2928
2962
  const lines = stdoutText.split("\n");
2929
- const perGroup = lines.filter((line) => line.startsWith(HITS_LINE_PREFIX)).map((line) => line.slice(6)).filter((digits) => /^\d+$/u.test(digits)).map((digits) => Math.trunc(Number(digits)));
2963
+ const perGroup = lines.filter((line) => line.startsWith(HITS_LINE_PREFIX)).map((line) => line.slice(6)).filter((digits) => DIGITS_ONLY.test(digits)).map((digits) => Math.trunc(Number(digits)));
2930
2964
  if (perGroup.length === 0) return null;
2931
2965
  const locations = /* @__PURE__ */ new Set();
2932
2966
  for (const line of lines) {
@@ -2971,7 +3005,9 @@ async function runForegroundOnce(host, command, workdir, timeoutMs, opts) {
2971
3005
  const resolved = opts.resolveFailure?.(failure, result) ?? null;
2972
3006
  if (resolved !== null) return resolved;
2973
3007
  const concurrent = classifyConcurrentFailure(result.stderr.text);
2974
- throw concurrent?.kind === "lock-busy" && concurrent.rebuild ? new RebuildLockBusyError(failure) : new Error(failure);
3008
+ if (concurrent?.kind === "lock-busy" && concurrent.rebuild) throw new RebuildLockBusyError(failure);
3009
+ if (concurrent?.kind === "lock-busy") throw new Error(`${fill(opts.messages.lockBusyOtherOperation, { op: concurrent.ownerOperation ?? "unknown" })}\n${failure}`);
3010
+ throw new Error(failure);
2975
3011
  }
2976
3012
  const notes = successNotes(result, opts.messages, opts.stdoutMaxBytes);
2977
3013
  const { text } = result.stdout;
@@ -3030,7 +3066,7 @@ function assertRootExists(root, messages) {
3030
3066
  }
3031
3067
  /**
3032
3068
  * 默认每组结果数:值域 1-50 由 Config schema(隐式命名空间与行 config 共用)保证,
3033
- * 这里只处理「字段缺省」。真正兜住越界的是 cli.clampLimit(命令构造边界)。
3069
+ * 这里只处理「字段缺省」。越界的拒绝在 cli.resolveLimit(命令构造边界),不在此重复。
3034
3070
  */
3035
3071
  function readDefaultLimit(config) {
3036
3072
  return config.defaultLimit.get() ?? 10;
@@ -3576,7 +3612,7 @@ async function runSearchTool(runtime, args, exec, messages) {
3576
3612
  env: zgEnv(config),
3577
3613
  stdoutMaxBytes: config.stdoutMaxBytes,
3578
3614
  messages,
3579
- summaryLimit: clampLimit(searchArgs.limit, messages),
3615
+ summaryLimit: resolveLimit(searchArgs.limit, messages),
3580
3616
  rebuildWait: {
3581
3617
  root: resolvedRoot,
3582
3618
  rebuilds: runtime.rebuilds,
package/locale/en.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Zvec indexed search",
4
+ "description": "Searches the workspace with a local index instead of raw grep, and gates plain grep behind an indexed search.",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Zvec 索引检索",
4
+ "description": "用本地索引检索工作区,替代裸 grep,并可要求先走索引检索再允许直查。",
5
+ "detail": "docs/DETAIL.zh.md"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayyuen66/dsh-zvec-grep",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "dsh 工作区语义检索插件(zg):zg_search / zg_index / zg_status + 本地 embedding 设置卡片 + systemPrompt 路由规则 + guard 安全兜底。",
5
5
  "keywords": [
6
6
  "cordis",
@@ -23,6 +23,9 @@
23
23
  },
24
24
  "files": [
25
25
  "icon.svg",
26
+ "locale/zh.json",
27
+ "locale/en.json",
28
+ "docs",
26
29
  "README.md",
27
30
  "README.zh-CN.md",
28
31
  "CHANGELOG.md",
@@ -37,6 +40,7 @@
37
40
  ".": "./host.js",
38
41
  "./client": "./client.js",
39
42
  "./cordis.patch.yml": "./cordis.patch.yml",
43
+ "./locale/*.json": "./locale/*.json",
40
44
  "./package.json": "./package.json"
41
45
  },
42
46
  "publishConfig": {
@@ -44,48 +48,55 @@
44
48
  "registry": "https://registry.npmjs.org"
45
49
  },
46
50
  "dependencies": {
47
- "@jayyuen66/dsh-plugin-shared": "0.1.9"
51
+ "@jayyuen66/dsh-plugin-shared": "0.2.1",
52
+ "zod": "4.6.7"
48
53
  },
49
54
  "devDependencies": {
50
- "@deepseek-ai/cordis": "4.0.5",
51
- "@deepseek-ai/cordis-plugin-group": "1.0.5",
52
- "@deepseek-ai/cordis-plugin-timer": "1.1.7",
53
- "@deepseek-ai/dsh-api-remotes": "0.2.1-rc.3",
54
- "@deepseek-ai/dsh-bash-local": "0.2.1-rc.3",
55
- "@deepseek-ai/dsh-client-locale": "0.2.1-rc.3",
56
- "@deepseek-ai/dsh-client-store": "0.2.1-rc.3",
57
- "@deepseek-ai/dsh-client-ui-layout": "0.2.1-rc.3",
58
- "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.1-rc.3",
59
- "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.3",
60
- "@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.3",
61
- "@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.3",
62
- "@deepseek-ai/dsh-host-webserver": "0.2.1-rc.3",
63
- "@deepseek-ai/dsh-http-proxy": "0.2.1-rc.3",
64
- "@deepseek-ai/dsh-jobs": "0.2.1-rc.3",
65
- "@deepseek-ai/dsh-jobs-local": "0.2.1-rc.3",
66
- "@deepseek-ai/dsh-llm": "0.2.1-rc.3",
67
- "@deepseek-ai/dsh-output-retention": "0.2.1-rc.3",
68
- "@deepseek-ai/dsh-package-manifest": "0.2.1-rc.3",
69
- "@deepseek-ai/dsh-ptc-runtime": "0.2.1-rc.3",
70
- "@deepseek-ai/dsh-sandbox": "0.2.1-rc.3",
71
- "@deepseek-ai/dsh-scope": "0.2.1-rc.3",
72
- "@deepseek-ai/dsh-session": "0.2.1-rc.3",
73
- "@deepseek-ai/dsh-settings": "0.2.1-rc.3",
74
- "@deepseek-ai/dsh-shell": "0.2.1-rc.3",
75
- "@deepseek-ai/dsh-subprocess": "0.2.1-rc.3",
76
- "@deepseek-ai/dsh-subprocess-local": "0.2.1-rc.3",
77
- "@deepseek-ai/dsh-system-prompt": "0.2.1-rc.3",
78
- "@deepseek-ai/dsh-timeout": "0.2.1-rc.3",
79
- "@deepseek-ai/dsh-tools": "0.2.1-rc.3",
80
- "@deepseek-ai/dsh-typert-protocol": "0.2.1-rc.3",
81
- "@deepseek-ai/dsh-user-approval": "0.2.1-rc.3",
82
- "@deepseek-ai/schemastery": "3.18.5",
83
- "@types/node": "26.6.5",
55
+ "@deepseek-ai/cordis": "4.0.6-alpha.1",
56
+ "@deepseek-ai/cordis-plugin-group": "1.0.6-alpha.1",
57
+ "@deepseek-ai/cordis-plugin-timer": "1.1.8-alpha.1",
58
+ "@deepseek-ai/dsh-agent": "0.2.2-alpha.2",
59
+ "@deepseek-ai/dsh-api-remotes": "0.2.2-alpha.2",
60
+ "@deepseek-ai/dsh-bash-local": "0.2.2-alpha.2",
61
+ "@deepseek-ai/dsh-client-locale": "0.2.2-alpha.2",
62
+ "@deepseek-ai/dsh-client-store": "0.2.2-alpha.2",
63
+ "@deepseek-ai/dsh-client-ui-layout": "0.2.2-alpha.2",
64
+ "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.2-alpha.2",
65
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.2-alpha.2",
66
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.2-alpha.2",
67
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.2-alpha.2",
68
+ "@deepseek-ai/dsh-host-webserver": "0.2.2-alpha.2",
69
+ "@deepseek-ai/dsh-http-proxy": "0.2.2-alpha.2",
70
+ "@deepseek-ai/dsh-jobs": "0.2.2-alpha.2",
71
+ "@deepseek-ai/dsh-jobs-local": "0.2.2-alpha.2",
72
+ "@deepseek-ai/dsh-llm": "0.2.2-alpha.2",
73
+ "@deepseek-ai/dsh-output-retention": "0.2.2-alpha.2",
74
+ "@deepseek-ai/dsh-package-manifest": "0.2.2-alpha.2",
75
+ "@deepseek-ai/dsh-ptc-runtime": "0.2.2-alpha.2",
76
+ "@deepseek-ai/dsh-sandbox": "0.2.2-alpha.2",
77
+ "@deepseek-ai/dsh-scope": "0.2.2-alpha.2",
78
+ "@deepseek-ai/dsh-session": "0.2.2-alpha.2",
79
+ "@deepseek-ai/dsh-session-projection": "0.2.2-alpha.2",
80
+ "@deepseek-ai/dsh-settings": "0.2.2-alpha.2",
81
+ "@deepseek-ai/dsh-shell": "0.2.2-alpha.2",
82
+ "@deepseek-ai/dsh-subprocess": "0.2.2-alpha.2",
83
+ "@deepseek-ai/dsh-subprocess-local": "0.2.2-alpha.2",
84
+ "@deepseek-ai/dsh-system-prompt": "0.2.2-alpha.2",
85
+ "@deepseek-ai/dsh-timeout": "0.2.2-alpha.2",
86
+ "@deepseek-ai/dsh-tool-executor-native": "0.2.2-alpha.2",
87
+ "@deepseek-ai/dsh-tools": "0.2.2-alpha.2",
88
+ "@deepseek-ai/dsh-typert-protocol": "0.2.2-alpha.2",
89
+ "@deepseek-ai/dsh-user-approval": "0.2.2-alpha.2",
90
+ "@deepseek-ai/schemastery": "3.18.6-alpha.1",
91
+ "@e18e/eslint-plugin": "0.8.1",
92
+ "@types/node": "26.6.6",
84
93
  "@types/react": "19.3.0",
85
94
  "@vitest/coverage-v8": "5.0.5",
95
+ "eslint-plugin-regexp": "3.3.2",
86
96
  "eslint-plugin-sonarjs": "4.2.2",
87
- "oxfmt": "0.74.0",
88
- "oxlint": "1.89.0",
97
+ "eslint-plugin-zod": "5.2.2",
98
+ "oxfmt": "0.75.0",
99
+ "oxlint": "1.90.0",
89
100
  "oxlint-tsgolint": "7.0.2005",
90
101
  "react": "^19.3.0",
91
102
  "rolldown": "1.2.15",
@@ -95,9 +106,10 @@
95
106
  },
96
107
  "peerDependencies": {
97
108
  "@deepseek-ai/dsh": "^0.2.1-rc.3",
98
- "@deepseek-ai/dsh-output-retention": "0.2.1-rc.3",
99
- "@deepseek-ai/dsh-typert-protocol": "0.2.1-rc.3",
100
- "@deepseek-ai/schemastery": "3.18.5"
109
+ "@deepseek-ai/dsh-output-retention": "^0.2.1-rc.3",
110
+ "@deepseek-ai/dsh-scope": "^0.2.1-rc.3",
111
+ "@deepseek-ai/dsh-typert-protocol": "^0.2.1-rc.3",
112
+ "@deepseek-ai/schemastery": "3.18.6-alpha.1"
101
113
  },
102
114
  "peerDependenciesMeta": {
103
115
  "@deepseek-ai/dsh": {