@jayyuen66/dsh-zvec-grep 0.1.5 → 0.1.6

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 CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
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
4
 
5
+ ## 0.1.6
6
+
7
+ ### Fixed
8
+
9
+ - **`install-probe` 那一格从加进来那天起就不可能绿**:它用 `npm pack` 打的包去 `npm install`,而 `npm pack` 不解析 `catalog:`——tarball 的 `package.json` 里 12 处协议原样留着,安装当场 `EUNSUPPORTEDPROTOCOL Unsupported URL Type "catalog:"`。真实发布走的是 `pnpm publish`(`publish.yml`),所以**用户拿到的包从来不是 npm 打的那个**;这条步骤一直在验一件不存在的东西。现在只留 `pnpm pack`,`npm install` 那一步照旧不带任何 flag(peer 面能不能被默认语义吃下去,仍是它要判的东西),只是改装 pnpm 打的同一个包。本地复跑:pnpm 产物经 `npm install` 退 0,随后 `import` 入口拿到 `apply`/`Config`/`inject` 三件齐备。
10
+ - 重建等待的 `abort` 监听与超时定时器改成 `finally` 里成对撤销。旧写法不成对撤销:一次普通等待就会在 caller 的 signal 上留一个永不触发的监听、在事件循环里留一枚到点才响的定时器,宿主常驻进程里两者都随调用次数累积。
11
+
5
12
  ## 0.1.5-rc
6
13
 
7
14
  把 **Windows 的支持范围说清楚,并让 CI 按这个范围分工**。直接起因是 `b121e91`(0.1.4)推上去之后 `gate (windows-latest, 22)` 交了 184 条失败:唯一成因是 root 判据只认以 `/` 开头的绝对路径,而 win32 上 `os.tmpdir()` 交回盘符形态(`C:\Users\RUNNER~1\AppData\Local\Temp\…`),凡是要在盘上造真实工作区的用例都在 `rootOf` 先被拒、根本走不到被测行为。**这不是 0.1.4 改出来的**(184 条里 173 条的用例在 0.1.3 就存在,两版对 win32 也只保护了「造不出属主不可读文件」那一档),而是这一格的结果第一次被端上来。
package/README.md CHANGED
@@ -20,6 +20,11 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
20
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
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`.
22
22
 
23
+
24
+ ### Shared version floor
25
+
26
+ If your profile pins `@jayyuen66/dsh-plugin-shared` with a pnpm `overrides` entry, that pin must be at least the `@jayyuen66/dsh-plugin-shared` version this package declares. A lower pin installs a copy without the names this package imports at runtime, and the host then reports `N entries did not activate` with `does not provide an export named ...` when it boots -- the package installs fine and never loads, and no per-repo CI run can see it.
27
+
23
28
  ### Enabling it in dsh
24
29
 
25
30
  - 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.
@@ -176,7 +181,7 @@ What is not retained, stated plainly: the output ring keeps **UTF-8 bytes** (mea
176
181
 
177
182
  - 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).
178
183
  - `npm run check` is the single gate to run before publishing: typecheck (both tsconfigs) + `oxlint` + rebuild both bundles + `vitest run --coverage` + `oxfmt --check`.
179
- - 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.
184
+ - Coverage runs under a **100% threshold** (statements/branches/functions/lines) over the surface `vitest.config.ts` opts into (`coverageInclude`: `host.ts` + `lib/**`): anything in that surface that no test pins turns the suite red by design. The client half (`src/**`) sits outside the denominator on purpose - it is exercised through the bundle and `test/ui-messages.test.ts`, not as units.
180
185
  - `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`.
181
186
  - 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.
182
187
 
package/README.zh-CN.md CHANGED
@@ -19,6 +19,11 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
19
19
  - shared 的 `lib/text` 自己值导入 `@deepseek-ai/dsh-output-retention`,所以那枚宿主包也得在提供面上:本包按 `schemastery` 同一口径处理(非 optional `peerDependencies` + `devDependencies` 同枚精确版本,**不进 `dependencies`**)。这条只能靠门禁钉:漏它时本包的类型检查、构建与测试全绿,故障只在装出去之后以 ERR_MODULE_NOT_FOUND 出现。
20
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
21
 
22
+
23
+ ### shared 的版本下限
24
+
25
+ 如果你的 profile 用 pnpm `overrides` 把 `@jayyuen66/dsh-plugin-shared` 钉在某个版本,那个钉住的值必须不低于本包声明的 `@jayyuen66/dsh-plugin-shared` 版本。钉得更低就会装到一份缺少本包运行期所导入的名字的产物,宿主起来时报 `N entries did not activate` 加 `does not provide an export named ...`——包装得上、永远不生效,而各仓单仓 CI 看不见这一类。
26
+
22
27
  ### 在 dsh 里启用
23
28
 
24
29
  - add/remove 按包内 cordis.patch.yml 维护注册行 `- id: zvec-grep`(name 指向本包);该文件由 `package.json` 的 `dsh.bundle.patch` 指向。
@@ -174,7 +179,7 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
174
179
 
175
180
  - 测试分三层。`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 代理,该等式恒假)。
176
181
  - `npm run check` 是发布前的一条门:typecheck(两侧 tsconfig)+ `oxlint` + 重建两个 bundle + `vitest run --coverage` + `oxfmt --check`。
177
- - 覆盖率按**全局 100% 阈值**跑(stmts/branches/funcs/lines):任何一行或分支没被用例钉住,套件当场红——这是本仓的既定质量门,不是巧合。
182
+ - 覆盖率按 **100% 阈值**跑(stmts/branches/funcs/lines),分母是 `vitest.config.ts` 里 `coverageInclude` 选定的那一面(`host.ts` + `lib/**`)——那一面里任何一行或分支没被用例钉住就当场红,这是本仓的既定质量门,不是巧合。客户端半(`src/**`)**刻意在分母外**:它经 bundle 与 `test/ui-messages.test.ts` 覆盖,不按单元测。
178
183
  - `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` 直接拒绝类型剥离。
179
184
  - 行为之外还有一族 manifest 门守着发布面(`test/publish-manifest.test.ts`):每个入口目标都要被 `files` 覆盖、宿主包一律不进 `dependencies`、`dsh-*` 精确钉且与 peer 同版本、随包产物里不许出现本机路径与 store 布局、shared 出货产物值导入的宿主包必须由本包提供。`test/dist-size.test.ts` 给产物体积设预算,`test/readme-parity.test.ts` 钉中英两份的结构对等。
180
185
 
package/host.js CHANGED
@@ -125,7 +125,7 @@ const MESSAGES = {
125
125
  rebuildDescription: "重建已有索引(切换 embedding 时必须为 true)",
126
126
  dropDescription: "删除索引(与其它索引选项互斥)",
127
127
  ignoreFilesDescription: "额外的 ignore 文件路径(如 .gitignore 之外的排除清单),透传 zg --ignore-file",
128
- excludeSecretsDescription: "是否默认排除私钥/密钥库格式(*.pem/*.key/*.p12/*.pfx/*.keystore/id_rsa*),默认 true;仅在明确需要索引此类文件时置 false",
128
+ excludeSecretsDescription: "是否排除私钥/密钥库格式(*.pem/*.key/*.p12/*.pfx/*.keystore/id_rsa*),默认 true。本插件的排除规则排在用户正向 glob 之后,用户规则覆盖不掉它——所以这一位是「要不要索引私钥」的唯一开关:置 false 会把这批文件灌进向量库,此后检索可以把它们回显到上下文。只有用户明确要求索引密钥夹具时才给 false",
129
129
  hiddenDescription: "包含隐藏文件(默认不含,隐藏密钥文件因此已被排除)",
130
130
  noIgnoreDescription: "不读 ignore 文件",
131
131
  maxDepthDescription: "最大目录深度",
@@ -278,7 +278,7 @@ const MESSAGES = {
278
278
  rebuildDescription: "Rebuild the existing index (must be true when switching embedding)",
279
279
  dropDescription: "Delete the index (mutually exclusive with the other index options)",
280
280
  ignoreFilesDescription: "Extra ignore-file paths (exclusion lists beyond .gitignore), passed through as zg --ignore-file",
281
- excludeSecretsDescription: "Whether to exclude private-key/keystore formats by default (*.pem/*.key/*.p12/*.pfx/*.keystore/id_rsa*), default true; set false only when such files genuinely must be indexed",
281
+ excludeSecretsDescription: "Whether to exclude private-key/keystore formats (*.pem/*.key/*.p12/*.pfx/*.keystore/id_rsa*), default true. These exclusion rules are evaluated after user include globs, so no user glob can bring the files back: this flag is the only switch for indexing private keys, and false feeds them into the vector store, from where search can echo them back into context. Set false only when the user explicitly asks to index key fixtures",
282
282
  hiddenDescription: "Include hidden files (excluded by default, which also drops hidden key files)",
283
283
  noIgnoreDescription: "Do not read ignore files",
284
284
  maxDepthDescription: "Maximum directory depth",
@@ -680,12 +680,17 @@ function resolveRoot(value, fallback, messages) {
680
680
  if (typeof fallback === "string" && fallback.trim().length > 0) return assertAbsoluteRoot(fallback.trim(), messages);
681
681
  throw new Error(messages.rootRequiredWithFallback);
682
682
  }
683
- /** limit 钳制:省略(undefined/null)回默认;给了但不是非负整数即抛;越界钳到 [LIMIT_MIN, LIMIT_MAX]。 */
683
+ /**
684
+ * limit 钳制:省略(undefined/null)回默认;给了但不是非负整数即抛;越界钳到 [LIMIT_MIN, LIMIT_MAX]。
685
+ *
686
+ * 类型只认 number:`Number()` 会把 `true` 折成 1、把 `[]` 折成 0——模型给一个类型错的 limit
687
+ * 就会静默只回一条结果,而它会把「只有一处命中」当成这次检索的事实。
688
+ */
684
689
  function clampLimit(value, messages, fallback = 10) {
685
690
  if (value === void 0 || value === null) return fallback;
686
- const num = typeof value === "number" ? value : Number(value);
687
- if (!Number.isSafeInteger(num) || num < 0) throw new Error(messages.limitInvalid);
688
- return Math.min(LIMIT_MAX, Math.max(LIMIT_MIN, num));
691
+ if (typeof value !== "number") throw new TypeError(messages.limitInvalid);
692
+ if (!Number.isSafeInteger(value) || value < 0) throw new Error(messages.limitInvalid);
693
+ return Math.min(LIMIT_MAX, Math.max(LIMIT_MIN, value));
689
694
  }
690
695
  /** 检索类数组(queries/fts/vector)取值:条数与单条长度都放宽到 query 档。 */
691
696
  function queryList(value, name, messages) {
@@ -838,19 +843,18 @@ function buildSearchCommand(args, messages, mode = DEFAULT_CLIENT_MODE, exhausti
838
843
  const root = assertAbsoluteRoot(args.root, messages);
839
844
  return exhaustive ? buildExhaustiveCommand(args, root, messages, mode) : buildIndexedCommand(args, root, messages, mode, backgroundSupport);
840
845
  }
841
- /** 非负/正整数字符串化;非数值类型或非整数报错(`true` 不算 1)。 */
846
+ /** 非负/正整数字符串化;非 number 或非整数报错(`true` 与数字字符串都不算数字)。 */
842
847
  function intFlag(value, name, messages, min) {
843
- if (typeof value !== "number" && typeof value !== "string") throw new TypeError(fill(messages.intWithReceived, {
848
+ if (typeof value !== "number") throw new TypeError(fill(messages.intWithReceived, {
844
849
  name,
845
850
  min,
846
851
  received: typeof value
847
852
  }));
848
- const num = typeof value === "number" ? value : Number(value);
849
- if (!Number.isSafeInteger(num) || num < min) throw new Error(fill(messages.intRequired, {
853
+ if (!Number.isSafeInteger(value) || value < min) throw new Error(fill(messages.intRequired, {
850
854
  name,
851
855
  min
852
856
  }));
853
- return String(num);
857
+ return String(value);
854
858
  }
855
859
  /**
856
860
  * 一次性读完全部布尔旗标:drop=true 的分支不拼 embedding/过滤段,若就地取值,
@@ -1470,27 +1474,6 @@ function searchFirstGuard(execution, deps, messages) {
1470
1474
  }
1471
1475
  return reason;
1472
1476
  }
1473
- /** 等到信号被取消为止。 */
1474
- async function abortOf(signal) {
1475
- const { promise, resolve } = Promise.withResolvers();
1476
- signal.addEventListener("abort", () => {
1477
- resolve(void 0);
1478
- }, { once: true });
1479
- return promise;
1480
- }
1481
- /** 等到信号被取消为止,并归一成等待的一种结局。 */
1482
- async function abortedOutcome(signal) {
1483
- await abortOf(signal);
1484
- return "aborted";
1485
- }
1486
- /** 延时;用不可撤销的定时器换来收尾路径里没有「撤销自己」那种分支。 */
1487
- async function delay(ms) {
1488
- const { promise, resolve } = Promise.withResolvers();
1489
- setTimeout(() => {
1490
- resolve(void 0);
1491
- }, ms);
1492
- return promise;
1493
- }
1494
1477
  /**
1495
1478
  * 容量上限:超过就淘汰若干条目,但**绝不淘汰已经交出作业号的那条**。
1496
1479
  *
@@ -1573,22 +1556,24 @@ function createRebuildRegistry(options = {}) {
1573
1556
  const entry = coveringOf(entries, root, messages);
1574
1557
  if (entry === void 0) return "settled";
1575
1558
  if (signal?.aborted === true) return "aborted";
1576
- const settleOutcome = async () => {
1559
+ const { promise, resolve } = Promise.withResolvers();
1560
+ const timer = setTimeout(() => {
1561
+ resolve("timeout");
1562
+ }, Math.max(0, timeoutMs));
1563
+ const onAbort = () => {
1564
+ resolve("aborted");
1565
+ };
1566
+ signal?.addEventListener("abort", onAbort, { once: true });
1567
+ const settledOutcome = async () => {
1577
1568
  await entry.settled;
1578
1569
  return "settled";
1579
1570
  };
1580
- const expireOutcome = async () => {
1581
- await delay(Math.max(0, timeoutMs));
1582
- return "timeout";
1583
- };
1584
- const settled = settleOutcome();
1585
- const expired = expireOutcome();
1586
- const raced = signal === void 0 ? [settled, expired] : [
1587
- settled,
1588
- expired,
1589
- abortedOutcome(signal)
1590
- ];
1591
- return Promise.race(raced);
1571
+ try {
1572
+ return await Promise.race([settledOutcome(), promise]);
1573
+ } finally {
1574
+ clearTimeout(timer);
1575
+ signal?.removeEventListener("abort", onAbort);
1576
+ }
1592
1577
  },
1593
1578
  keys() {
1594
1579
  return [...entries.keys()];
@@ -3355,9 +3340,12 @@ function searchToolParameters(registered) {
3355
3340
  * 而报错会把模型推向 `zg_index`——那意味着先下载 embedding 权重。对「先看看这个仓库里
3356
3341
  * 有什么」这类问题,逐行字面匹配就是够的,兜底不是妥协。自动改道的代价由 runSearchTool
3357
3342
  * 里的前置声明来偿。
3343
+ *
3344
+ * `value` 只可能是「已过 `boolOf` 的布尔」或「没给」(undefined)——类型错的入参在到达
3345
+ * 这里之前就已经报错,故这里不再有「非布尔也不缺省」这一档。
3358
3346
  */
3359
3347
  function pickExhaustive(value, hasIndex) {
3360
- if (typeof value === "boolean") return value;
3348
+ if (value !== void 0) return value;
3361
3349
  return !hasIndex;
3362
3350
  }
3363
3351
  /**
@@ -3389,7 +3377,7 @@ async function runSearchTool(runtime, args, exec, messages) {
3389
3377
  trackObservedRoot(ledger, exec);
3390
3378
  const resolvedRoot = rootOf(args, exec, messages, ledger);
3391
3379
  const indexRoot = findIndexRoot(resolvedRoot, indexProbe);
3392
- const explicit = args["rg"];
3380
+ const explicit = args["rg"] === void 0 || args["rg"] === null ? void 0 : boolOf(args["rg"], "rg", messages);
3393
3381
  const exhaustive = pickExhaustive(explicit, indexRoot !== void 0);
3394
3382
  const fallback = exhaustive && explicit === void 0 && indexRoot === void 0 ? messages.exhaustiveFallbackNote : void 0;
3395
3383
  const searchArgs = {
@@ -3557,6 +3545,7 @@ async function runIndexTool(runtime, args, exec, messages) {
3557
3545
  };
3558
3546
  const background = boolOf(args["background"], "background", messages);
3559
3547
  const rewriting = boolOf(args["rebuild"], "rebuild", messages) || background;
3548
+ boolOf(args["confirm"], "confirm", messages);
3560
3549
  await runtime.versionGate.ensure(messages);
3561
3550
  if (rewriting && rebuilds.claim(root, "tool") === null) return { text: fill(messages.indexRebuildInFlight, { root }) };
3562
3551
  if (background) return startBackgroundIndex(runtime, root, indexArgs, messages);
@@ -3617,6 +3606,7 @@ async function runStatusTool(runtime, args, exec, messages) {
3617
3606
  maxWaitMs: config.rebuildWaitMs
3618
3607
  },
3619
3608
  ...checkReady ? { resolveFailure: (failure, result) => {
3609
+ if (result.timedOut || result.aborted || result.sandbox?.denied === true) return null;
3620
3610
  const report = result.stdout.text.trim();
3621
3611
  return report.length > 0 ? `${report}\n${fill(messages.statusNotReady, {
3622
3612
  root,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayyuen66/dsh-zvec-grep",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "dsh 工作区语义检索插件(zg):zg_search / zg_index / zg_status + 本地 embedding 设置卡片 + systemPrompt 路由规则 + guard 安全兜底。",
5
5
  "keywords": [
6
6
  "cordis",