@jayyuen66/dsh-zvec-grep 0.1.4 → 0.1.5

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.
Files changed (6) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +26 -20
  3. package/README.zh-CN.md +28 -20
  4. package/client.js +184 -137
  5. package/host.js +1260 -1327
  6. package/package.json +48 -43
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
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.5-rc
6
+
7
+ 把 **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 也只保护了「造不出属主不可读文件」那一档),而是这一格的结果第一次被端上来。
8
+
9
+ ### Changed
10
+
11
+ - **CI 两格分工**:ubuntu 格跑 `pnpm run check`(全部门禁,含四项 100% 覆盖率);其余平台跑新增的 `pnpm run check:platform`——同一套 typecheck / lint / 两个 bundle / 全量用例 / `oxfmt`,只是不判覆盖率。理由写在 `ci.yml` 的注释里:需要盘上真根的用例在 win32 整块跳过之后,`host.ts` 的覆盖率本就到不了 100%,把阈值调低等于把 ubuntu 格的真约束改成装饰。
12
+ - **`test/host.test.ts` 按平台跳过 24 个 suite**(谓词收成一处 `realRootUnavailable = process.platform === "win32"`,各 suite 写 `describe.skipIf(realRootUnavailable)(…)`)。写成字面上的 `describe.skipIf` 而不是包一层别名:oxlint 的 vitest 规则按 `describe` 识别 suite,别名会让整文件被当成一个作用域,实测冒出 221 条 `consistent-test-it` 噪声。**没有**跳过在 win32 上原样通过的那 6 个 suite(信任闸门、白名单有效期、hitSummary、探测缓存、render 全性、隐式注册验收)——跳掉一条本来会绿的用例就是抹掉真实信号。
13
+ - 两份 README 新增「支持面 / Support surface」一节:本包是 POSIX-only,Windows 宿主下三个 zg 工具在 `rootOf` 当场拒并说明原因(fail-fast,不会拿错位路径去拼命令、也不会把错路结果当正常检索交回模型);真要支持 Windows 得动 root 归一、第二套命令形态(pwsh/cmd 的引号与 `bash -c` 不同义)、门禁的 `/` 切词与 `manifest.json` 的 `rootPaths` 比对,属设计变更。
14
+
15
+ ### Fixed
16
+
17
+ - 新增 `test:platform` / `check:platform` 两个脚本,让「不判覆盖率的那套门禁」在 package.json 里单源,CI 只挑命令——避免 workflow 里内联一串命令、日后与本地脚本各走各的。
18
+
5
19
  ## 0.1.4
6
20
 
7
21
  把 **zg 守护进程(server 模式)这一档能力差从「使用限制」变成显式判据**:`--mode auto` 在 daemon 缺席时由上游静默落回 direct(模型逐次冷加载、增量刷新与 `refresh=background` 都不存在),而本包过去既没有一处说明,也没有拦住那个不可能兑现的参数。顺带修掉两处评审确认的缺陷:`requireApprovalForExplicitRoot` 会为**注定被拒**的 root 弹一次换不来放行的确认;两份 README 与 `host.ts` 头注释的配置面数字早已和 schema 脱节(14 vs 16、四个 vs 十枚)。
package/README.md CHANGED
@@ -15,7 +15,7 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
15
15
  ```
16
16
 
17
17
  - The packages are on the public npm registry, so no credentials are needed; the published artifact only carries host.js, client.js and cordis.patch.yml (the files field in package.json).
18
- - Runtime value imports are `@jayyuen66/dsh-plugin-shared` (lib/http, lib/locale, lib/text) and `@deepseek-ai/schemastery` (the host's fork — the only one whose resolve wraps `.volatile()` fields into `Volatile` references).
18
+ - Runtime value imports are `@jayyuen66/dsh-plugin-shared` (`lib/locale`, `lib/text`, `lib/record`, `lib/errors`, `lib/job-outcome`, `lib/card-diff`), `@deepseek-ai/schemastery` (the host's fork — the only one whose resolve wraps `.volatile()` fields into `Volatile` references) and `@deepseek-ai/dsh-typert-protocol` (the Remote base class — `TypertRemoteService` is a **class** to `extends`, so there is no type-only way to take it; it is a required peer plus the same exact pin in devDependencies).
19
19
  - shared's own `lib/text` value-imports `@deepseek-ai/dsh-output-retention`, so that host package has to be supplied too, on the same terms as `schemastery`: a required `peerDependency` plus the same exact pin in `devDependencies`, **never** in `dependencies`. Only a gate can hold this line - with the entry missing, typecheck, build and tests are all green and the failure shows up after installation as ERR_MODULE_NOT_FOUND.
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`.
@@ -24,13 +24,20 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
24
24
 
25
25
  - add/remove maintain the registration line `- id: zvec-grep` (name points at this package) from the in-package cordis.patch.yml, which `dsh.bundle.patch` in `package.json` points at.
26
26
  - Host compatibility is judged on the **peer declarations**, not on `engines.dsh`: before composition the host compares `@deepseek-ai/dsh` and every `@deepseek-ai/dsh-*` range against the current runtime version, prereleases included (the rule is owned by the dsh-app-boot README). A mismatch denies that entry; a bundle without an exemption is skipped whole and listed under `skippedBundles`.
27
- - This package pins every `dsh-*` **exactly** (a requirement of `test/publish-manifest.test.ts`, because "a second copy of the host type surface" is worse than a version conflict), so a host **newer than `0.2.1-alpha.2` also needs approval**. The escape hatch is the one the host prints: `dsh plugin --profile web allow-version @jayyuen66/dsh-zvec-grep@<version> --dsh-version <exact version> --accept-risk`.
28
- - `engines.dsh` is a declaration that nothing reads; keeping it at `>= 0.2.1-alpha.2` only avoids leaving two contradictory numbers behind.
27
+ - This package pins every `dsh-*` **exactly** (a requirement of `test/publish-manifest.test.ts`, because "a second copy of the host type surface" is worse than a version conflict), so a host **newer than `0.2.1-rc.2` also needs approval**. The escape hatch is the one the host prints: `dsh plugin --profile web allow-version @jayyuen66/dsh-zvec-grep@<version> --dsh-version <exact version> --accept-risk`.
28
+ - `engines.dsh` is a declaration that nothing reads; keeping it at `>= 0.2.1-rc.2` only avoids leaving two contradictory numbers behind.
29
29
  - `dsh.client.platform` is web with immediately set, so the card's client half is delivered by the host; bundle installation goes through pnpm (>= 12.3.0).
30
30
  - apply needs the settings/shell/tools/systemPrompt/timer surfaces: all five sit in `inject`, so a missing one keeps cordis from activating the entry (the startup diagnostic prints `pending (waiting for service: …)`).
31
31
  - The guard inside apply is the second layer: a malformed ctx throws `required services … missing`.
32
- - The three `/_dsh/zvec-grep/*` routes hang off an `inject(["webServer"])` child fiber: with no webServer (a TUI host) the child never activates, so those routes simply do not exist while the tools keep working.
33
- - On the real host webServer arrives about a second after this entry, which is why it must be a dependency and not a one-off `ctx.get`.
32
+ - The rebuild read surface is an official Typert Remote namespace installed on the apply fiber (`installRebuildRemote`, `lib/rebuild-remote.ts`), so it needs no `webServer` and no child fiber: on a TUI host with no web layer the service still registers, and the card simply has no place to render.
33
+ - The status poll is the client's own timer (`REBUILD_POLL_MS = 2000` in `src/client-entry.ts`), not a server push, and every read is answered by a result object rather than by a thrown error — see Public interface.
34
+
35
+ ### Support surface
36
+
37
+ - **POSIX hosts (Linux / macOS).** The root predicate accepts only absolute paths starting with `/` (`assertAbsoluteRoot` in `lib/cli.ts`), the command line is POSIX-shaped (`shq()` single-quote escaping plus the whole string handed to `bash -c`), and index probing plus the `rootPaths` comparison inside the manifest split on `/` as well.
38
+ - **Windows hosts are out of scope**, and the failure mode is **fail-fast, not drift**: when the session workspace looks like `C:\Users\…`, all three zg tools refuse right in `rootOf` and say why ("root must be an absolute path starting with /"). The plugin never builds a `zg` command from a mismatched path and never hands a wrong-path result back to the model as if it were a real search. The card's "rebuild workspace" runs into the same root gate.
39
+ - Real Windows support would mean changing the predicate itself rather than translating paths in front of it: root normalization (drive letters and UNC), a second command form (pwsh/cmd quoting is not `bash -c`), the `/`-based grep tokenizer and path-shape rules in the gate, and the `rootPaths` coverage check against `<root>/.zvec-grep/manifest.json`. That is a design change; this package does not do it and does not pretend to.
40
+ - The CI matrix therefore splits in two: **the ubuntu job is the full gate** (including the four 100% coverage thresholds); **other platforms run only the parts that do not need a workspace on disk** — the "same source, two byte shapes" product / line-ending / `path.sep` drift — and **do not judge coverage**, because suites needing a real root skip wholesale on win32 (`realRootUnavailable` in `test/host.test.ts`) and `host.ts` could not reach 100% afterwards. The reasoning is written into `.github/workflows/ci.yml`.
34
41
 
35
42
  ### Tools exposed to the model
36
43
 
@@ -44,7 +51,7 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
44
51
  - 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.
45
52
  - zg_index: confirm is required and must be true (rejected twice, by the required check and by the guard).
46
53
  - `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.
47
- - 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.
54
+ - 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 `status` read — the card sees model-started indexing and vice versa.
48
55
  - 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.
49
56
  - 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.
50
57
  - 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.
@@ -108,22 +115,21 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
108
115
  - This is not a "somewhat faster" distinction. The two sides of `--mode auto` are two capability surfaces: direct builds and closes the engine on every `zg query` and **cold-loads the embedding model each time**, while watcher-driven incremental index refresh, `refresh=background` and a resident model pool **only exist in server mode**. Upstream only probes readiness for `auto`; it never starts a daemon for you.
109
116
  - This package **does not start a long-lived process on the user's behalf**: `zg server on` leaves a detached process and a token file on the machine, which is an action the user should own, not a decision a plugin makes for a deployment. What the package does instead is make the difference **explicit**, rather than leaving it hidden behind usage limits like "the search timeout is 5 minutes" and "recent edits are not findable":
110
117
  - It caches the **exit code** of `zg server status --check-ready` for a 60-second TTL (0 = ready, non-zero = not ready; reading the stdout table would not do — it is formatted for humans and is not part of this package's dependency contract). A failed probe is recorded as "not ready" and never surfaces as an infrastructure error.
111
- - That judgment gates `refresh=background` (see the tools section) and is echoed once at the tail of `zg_status` output and once on the settings card. A request rejected by the trust gate never triggers a probe, and neither does the rebuild-time synthetic projection, whose contract is to start no subprocess at all.
118
+ - That judgment gates `refresh=background` (see the tools section) and is echoed once at the tail of `zg_status` output and once on the settings card. Only `roots()` issues the probe: `rebuild` and `status` never start one, and neither does the rebuild-time synthetic projection, whose contract is to start no subprocess at all.
112
119
  - The card's `serverReady` is only ever `true` / `false`. An older host response simply has no such field, and the card renders **nothing** for that arm instead of claiming "not ready".
113
120
  - To actually get the benefits: run `zg server on` in a terminal (`zg server off` / `zg server status` cover stop and state). This package reads that readiness; it does not own the daemon's lifecycle.
114
121
 
115
122
  ### Public interface
116
123
 
117
- - Every handler opens with `guardTrust(req, res, { servingNonLoopback })` (`shared/lib/trust`); failing any leg yields `403` with `{ ok:false, error: ... }`.
118
- - Order of legs: Host authority -> the `sec-fetch-site` allowlist -> a verbatim `origin` vs Host compare. The two rejection sentences are `"untrusted host authority"` and `"cross-origin request rejected"`.
119
- - `servingNonLoopback` is computed by `isNonLoopbackBindHost(webServer.host)` from the bound address itself - the host only rejects wildcard listeners, while binding a concrete IPv4/IPv6 of a local interface is a legitimate configuration, and a literal comparison would read that surface as loopback. A wrong method yields `405` carrying `Allow` plus `{ ok:false, error:"GET only" | "POST only" }` - no longer an empty reply.
120
- - `GET /_dsh/zvec-grep/rebuild-roots`: returns only this plugin's own data (a CSRF token regenerated on every apply, the observed workspace list, and the daemon readiness the card shows); GET/HEAD allowed, 403 when the gate above rejects it. The readiness probe runs **after** both gates, so a rejected request never starts a subprocess.
121
- - `POST /_dsh/zvec-grep/rebuild?root=...`: gate + header `x-zvec-grep-csrf` + body <= 4096 bytes + root in the whitelist + directory exists; returns `{ ok, jobId }`, otherwise 405/403/400/500.
122
- - `/_dsh/zvec-grep/rebuild-status?jobId=...`: polled behind the gate (the card polls every 2 seconds); returns status/exitCode/root/output (plus sandbox when present); an unknown jobId gets a 404 explaining it left the 10-record settled window.
124
+ - The rebuild surface is one **official Typert Remote namespace**, `zvecGrepRebuild` (`REBUILD_REMOTE_NAMESPACE` in `lib/rebuild-shape.ts`); its three methods are marked programmatically (`markRemote` in `lib/rebuild-remote.ts`) and installed on the apply fiber. There are no `/_dsh/*` routes, no CSRF token and no package-owned body cap any more: authentication, the Host / DNS-rebinding / Origin checks and the request-size limit belong to the host's `/api` gateway, and this package no longer declares a `webServer` dependency at all.
125
+ - `roots()` → `{ roots, serverReady }`: the whitelisted workspaces this daemon actually observed, plus the daemon-readiness line for the card. The `zg server status --check-ready` probe is issued **here and nowhere else**, off the same 60-second TTL cache the tools use. `serverReady` is `undefined` when the probe cannot answer, and the card renders nothing for that arm rather than "not ready".
126
+ - `rebuild({ root })` → `{ ok: true, jobId, reused? }` or `{ ok: false, error, status }`. What is enforced is unchanged from the HTTP version, because those rules guard the action, not the transport: a non-`/`-rooted path is refused (`assertAbsoluteRoot`), a root outside the observed whitelist is refused, a root whose directory disappeared is refused, and with no host `jobs` service **nothing is spawned** (the 503 arm). The per-root claim is taken before the first `await` and is the only mutex, so a second click follows the running rebuild (`reused: true`) or, when nothing can be followed, is refused instead of starting a second `zg` against the same index. The version gate and the ignore-file preflight run before the command is built; a failed start returns its code and releases the claim, so the tree is never left permanently "rebuilding".
127
+ - `status({ jobId })` → `{ status, exitCode, root, output }` (plus `sandbox` when present) or `{ ok: false, error, status: 404 | 503 }`. It resolves only ids present in this package's side table — the last 10 settled records (`REBUILD_HISTORY_MAX`), running records are never displaced — so somebody else's job (the host's `bash-1`, say) cannot be read through it. The three 404 arms are "the window moved on", "the registry row no longer holds it" and "the identity triple (kind / label / startedAt) does not match this record"; the 503 arm is the registry disappearing between starts. The card polls it every 2 seconds (`REBUILD_POLL_MS = 2000`).
128
+ - The `status` inside a refusal is a **retained semantic code, not an HTTP status**: the gateway frames the reply, so a refusal arrives as an ordinary result object, the client renders `error`, and the number exists so the tests can pin which rule fired. None of these three methods throws through the gateway — a rejected Remote call would look to the card like one generic failure, stop the polling and hide a rebuild that is still running.
123
129
  - Also a systemPrompt section `zvec-grep-routing` (order 1550) and the settings namespace `zvec-grep`.
130
+ - The client half (`src/rebuild-reader.ts`) `$mount`s three hand-written descriptors (`kind: "direct"`, `result: { mode: "src-json" }`, strict codecs on the two request bodies), memoised so the mount happens once, then reads the derived key `remote.zvecGrepRebuild`. With no host `remote` service there is no reader at all; with the service present but the namespace unmounted the read throws `… 未提供`, and the card renders the `rebuildUnavailable` line instead of going blank.
124
131
  - How many rebuilds run at once is decided by the **host registry** (measured default: the unowned bucket holds 10); this package no longer carries its own concurrency cap.
125
- When it is full, `POST /rebuild` answers 500 with the official message that names the limit - it no longer kills a rebuild that is already running.
126
- - `rebuild-status` only resolves jobIds present in this package's side table: the last 10 **settled** records are kept (older ones are removed from the registry => 404); running records are never displaced.
132
+ When it is full, `rebuild` returns a refusal carrying the official message that names the limit - it never kills a rebuild that is already running.
127
133
 
128
134
  ### The background job surface (official `ctx.jobs`)
129
135
 
@@ -131,16 +137,16 @@ This package no longer ships a job registry: a "rebuild workspace" run is one **
131
137
 
132
138
  | Aspect | Fact |
133
139
  | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
134
- | The model can see it | The official `job_list` / `job_output` / `job_kill` tools now list the rebuild, with the exit code / signal name carried in the job's `detail` (same shape the host's own bash tool uses - measured in `plugins/docs/harness/f3-equiv/probe-jobs.mjs`). Output rides the official **pull source** (`proc.observed[*].readFrom`), so the ring advances on the registry's own cadence - **even with the settings panel closed** - and the observer never steals bytes from `readOutput()` (the d.ts says so verbatim). The controller is attached only for the instant of `start` and detached right after (see the cross-package rule) |
135
- | Unowned means visible to every session | The registry isolates by owner, and an unowned job can be `list`ed / `read` / `kill`ed by any caller. This is a known, accepted exposure of this wave - the card is a webServer producer outside any session, and owned jobs would need the `dsh-agent` registry (measured unavailable). Rolling this adoption back is the only way to close it. Note `/_dsh/zvec-grep/rebuild-status` still only answers for ids in this package's side table, so somebody else's job (the host's `bash-1`, say) cannot be read through it |
140
+ | The model can see it | The official `job_list` / `job_output` / `job_kill` tools now list the rebuild, with the exit code / signal name carried in the job's `detail` (same shape the host's own bash tool uses). Output rides the official **pull source** (`proc.observed[*].readFrom`), so the ring advances on the registry's own cadence - **even with the settings panel closed** - and the observer never steals bytes from `readOutput()` (the d.ts says so verbatim). The controller is attached only for the instant of `start` and detached right after (see the cross-package rule) |
141
+ | Unowned means visible to every session | The registry isolates by owner, and an unowned job can be `list`ed / `read` / `kill`ed by any caller. This is a known, accepted exposure of this wave - the card reaches the registry through the Remote service, outside any session, and owned jobs would need the `dsh-agent` registry (measured unavailable). Rolling this adoption back is the only way to close it. Note the `status` read still only answers for ids in this package's side table, so somebody else's job (the host's `bash-1`, say) cannot be read through it |
136
142
  | Two more status words | `stopping` (cancellation issued, process not finished settling - the card shows it as still running) and `failed` (the registry's own verdict - it gets its own message instead of rendering as "exit code null") |
137
143
 
138
- What is not retained, stated plainly: the output ring keeps **UTF-8 bytes** (measured host default 262144), while the card's 4000-character tail window and its `shown/total` count **UTF-16 code units** - two unit systems, each doing its own job. `total` therefore counts code units **inside the retention window** (the official byte total lives in `view.output.total`, different unit, never mixed), and for CJK output that window is about **1/3 smaller** than what this package kept before the adoption - the price of using the official ring. The two loss marks say different things: "truncated" = the ring evicted its head (`view.output.earliest > 0`, simply not visible any more), "buffer overflow" = the executor's reader reported lossy or threw outright (bytes really are gone; a spill file may exist). The timeout notice and the sandbox facts are deliberately **not** written into the ring: the ring belongs to the registry's pump, and the registry drops every write after settlement (measured), so the endpoint synthesises both at projection time and they can never be lost by arriving late. **Polling never throws through**: when the `jobs` service is reloaded (or somebody else reclaimed the record) the status endpoint answers **404** rather than letting the official `unknown job` error escape - the host's catch for a throwing handler logs one line and, while no header has gone out yet, writes a bare **400** with no body and no content-type (it only destroys the socket once headers were sent: installed dsh-host-webserver `lib/index.js:246-256`), which would put the card into its terminal `error` phase, stop the polling and hide a rebuild that is still running.
144
+ What is not retained, stated plainly: the output ring keeps **UTF-8 bytes** (measured host default 262144), while the card's 4000-character tail window and its `shown/total` count **UTF-16 code units** - two unit systems, each doing its own job. `total` therefore counts code units **inside the retention window** (the official byte total lives in `view.output.total`, different unit, never mixed), and for CJK output that window is about **1/3 smaller** than what this package kept before the adoption - the price of using the official ring. The two loss marks say different things: "truncated" = the ring evicted its head (`view.output.earliest > 0`, simply not visible any more), "buffer overflow" = the executor's reader reported lossy or threw outright (bytes really are gone; a spill file may exist). The timeout notice and the sandbox facts are deliberately **not** written into the ring: the ring belongs to the registry's pump, and the registry drops every write after settlement (measured), so the `status` read synthesises both at projection time and they can never be lost by arriving late. **Polling never throws through**: when the `jobs` service is reloaded (or somebody else reclaimed the record), `readRebuildOutput` folds the official `unknown job` error into `null` and the read answers a refusal (`status: 404`) rather than letting the exception reach the gateway — a rejected invocation is just one generic failure to the card, which would stop the polling and hide a rebuild that is still running.
139
145
 
140
146
  ### Data and privacy
141
147
 
142
148
  - 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).
143
- - 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`).
149
+ - Two rebuild paths: the model-side `zg_index` (rebuild=true, confirm=true), or the card's "rebuild workspace" button, which calls the `rebuild` method above; deleting is `zg_index` with drop=true (assembled as `zg index <root> --drop --yes`).
144
150
  - 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>`).
145
151
  - 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.
146
152
  - 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.
@@ -160,7 +166,7 @@ What is not retained, stated plainly: the output ring keeps **UTF-8 bytes** (mea
160
166
 
161
167
  - grep/rg refused with "no zg_search has run yet": that is the search-first gate; run zg_search. The same applies once the quota is spent or expired — re-search with a sharper query/fts to refresh it, no need to disable the plugin.
162
168
  - Search times out: the default `--refresh wait` refreshes the existing index synchronously; narrow the range with globs/fileTypes or lower the limit, or fall back to a hand-written literal search. To make the timeout itself smaller, start the daemon (see "Daemon (server mode)") — direct mode cold-loads the embedding model on every call, which is exactly why that budget sits at 5 minutes.
163
- - The rebuild button answers 403 "root is not in the workspace whitelist this daemon observed": that directory never had a session in this daemon; start one there first, or let the model call zg_index with confirm=true.
169
+ - The rebuild button refuses with "root is not in the workspace whitelist this daemon observed": that directory never had a session in this daemon; start one there first, or let the model call zg_index with confirm=true.
164
170
  - The card reports a failed rebuild although zg looks finished: success is "completed with exit 0" — exit 127 (zg not installed) also lands in completed, so read the tail of the output.
165
171
  - A root that was never indexed: zg_search fails loudly instead of silently building the index; building happens only via zg_index on an explicit user request.
166
172
  - Changed the embedding but semantic hits are missing: switching embedding only takes effect after a rebuild with rebuild=true.
package/README.zh-CN.md CHANGED
@@ -15,7 +15,7 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
15
15
  ```
16
16
 
17
17
  - 包在公共 npm 上,安装不需要凭据;发布态产物只有 host.js、client.js、cordis.patch.yml(package.json 的 files)。
18
- - 运行期值 import `@jayyuen66/dsh-plugin-shared`(lib/http、lib/locale、lib/text)与 `@deepseek-ai/schemastery`(宿主 fork:0.1.7 的 `.volatile()` 解析只有它有实现,公共 schemastery 既没这个方法、解析出的也仍是普通值),装不上就是 ERR_MODULE_NOT_FOUND。
18
+ - 运行期值 import `@jayyuen66/dsh-plugin-shared`(`lib/locale`、`lib/text`、`lib/record`、`lib/errors`、`lib/job-outcome`、`lib/card-diff`)、`@deepseek-ai/schemastery`(宿主 fork:0.1.7 的 `.volatile()` 解析只有它有实现,公共 schemastery 既没这个方法、解析出的也仍是普通值)与 `@deepseek-ai/dsh-typert-protocol`(Remote 基类:`TypertRemoteService` 是个**要 `extends` 的类**,没有 type-only 的取法,因此落必需 peer 并在 devDependencies 里同版精确钉),装不上就是 ERR_MODULE_NOT_FOUND。
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
 
@@ -23,11 +23,19 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
23
23
 
24
24
  - add/remove 按包内 cordis.patch.yml 维护注册行 `- id: zvec-grep`(name 指向本包);该文件由 `package.json` 的 `dsh.bundle.patch` 指向。
25
25
  - 宿主兼容性按 **peer 声明**判,不按 `engines.dsh`:装配前逐条比对 `@deepseek-ai/dsh` 与每一枚 `@deepseek-ai/dsh-*` 的区间与当前 runtime 版本,prerelease 也参与匹配(官方口径见 dsh-app-boot README)。不符即该条目被拒;组合包(bundle)没有豁免时整枚跳过并列进 `skippedBundles`。
26
- - 本包把 `dsh-*` 一律**精确钉**(`test/publish-manifest.test.ts` 的要求,理由是「装出第二份宿主类型面」比版本冲突更坏),所以**高于 `0.2.1-alpha.2` 的宿主同样需要授权**,出路是宿主点名的那句:`dsh plugin --profile web allow-version @jayyuen66/dsh-zvec-grep@<版本> --dsh-version <确切版本> --accept-risk`。
27
- - `engines.dsh` 只是声明,无人读;`>= 0.2.1-alpha.2` 与 peer 同值仅为不留下互相矛盾的数。
26
+ - 本包把 `dsh-*` 一律**精确钉**(`test/publish-manifest.test.ts` 的要求,理由是「装出第二份宿主类型面」比版本冲突更坏),所以**高于 `0.2.1-rc.2` 的宿主同样需要授权**,出路是宿主点名的那句:`dsh plugin --profile web allow-version @jayyuen66/dsh-zvec-grep@<版本> --dsh-version <确切版本> --accept-risk`。
27
+ - `engines.dsh` 只是声明,无人读;`>= 0.2.1-rc.2` 与 peer 同值仅为不留下互相矛盾的数。
28
28
  - `dsh.client.platform` 为 web 且 immediately,设置卡的 client 半随宿主下发;bundle 安装走 pnpm(>= 12.3.0)。
29
29
  - apply 需要 settings/shell/tools/systemPrompt/timer 五个服务面:它们都在 `inject` 里,缺任一 cordis 就不激活本条目(宿主启动诊断点名 `pending (waiting for service: …)`);apply 里的守卫再兜一层,ctx 形状不对时抛 `required services … missing`。
30
- - 三条 `/_dsh/zvec-grep/*` 端点挂在 `inject(["webServer"])` 的子 fiber 上:宿主没有 webServer(如 TUI)时子 fiber 不激活,端点不存在而工具照常。真实宿主上 webServer 比本条目晚到位约 1 秒,所以这里必须是依赖、不能只在 apply 里 `ctx.get` 读一次。
30
+ - 设置卡的读面是一枚官方 Typert Remote 命名空间,由 `installRebuildRemote` 注册在 apply fiber 上(`lib/rebuild-remote.ts`),因此不需要 `webServer`、也没有子 fiber:宿主没有 web 层(如 TUI)时服务照旧注册,只是卡片没有地方渲染。
31
+ - 状态轮询是客户端自己的定时器(`src/client-entry.ts` 的 `REBUILD_POLL_MS = 2000`),不是服务端推送;每次读都以结果对象回答,不抛错——见「对外接口」。
32
+
33
+ ### 支持面
34
+
35
+ - **POSIX 宿主(Linux / macOS)**。root 判据只认以 `/` 开头的绝对路径(`lib/cli.ts` 的 `assertAbsoluteRoot`),命令行也是 POSIX 形态(`shq()` 单引号转义 + 整串交给 `bash -c`),索引探测与清单里的 `rootPaths` 比对同样按 `/` 分隔。
36
+ - **Windows 宿主不在支持面内**,而且是 **fail-fast,不是静默走偏**:会话工作区长成 `C:\Users\…` 时,三个 zg 工具都在 `rootOf` 当场拒掉并说清原因(「root 必须是绝对路径(以 / 开头)」),不会拿一个错位的路径去拼 `zg` 命令、也不会把结果当成一次正常检索交回模型;设置卡的「工作区重建」同样过不去 root 那关。
37
+ - 真要在 Windows 上支持,要动的是判据本身而不是加一层路径转换:root 归一(盘符与 UNC)、第二套命令形态(pwsh/cmd 的引号规则与 `bash -c` 不同义)、门禁里那套按 `/` 的 grep 切词与路径形状判据、以及 `<root>/.zvec-grep/manifest.json` 的 `rootPaths` 覆盖判据。这属设计变更,本包没做,也不假装能做。
38
+ - CI 矩阵因此分两手:**ubuntu 格是全部门禁**(含四项 100% 覆盖率);**windows 格只跑不依赖真工作区的部分**与「同一份源码两种字节」的产物 / 换行 / `path.sep` 漂移,**不判覆盖率**——需要盘上真根的用例在 win32 整块跳过(`test/host.test.ts` 的 `realRootUnavailable`),跳过之后 `host.ts` 本就无从到 100%。判据与理由写在 `.github/workflows/ci.yml`。
31
39
 
32
40
  ### 提供给模型的工具
33
41
 
@@ -41,7 +49,7 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
41
49
  - 某组命中数正好等于 `--limit` 时只作**观察陈述**并显式说明「zg 不提供截断信号,此处不作断言」——zg 的输出没有任何截断标记,不能把"可能还有未显示的命中"说成事实。输出被宿主按 stdout 上限截尾时另附「只含保留部分」。
42
50
  - zg_index:confirm 必填且必须为 true(required 校验 + guard 双层拒绝)。
43
51
  - `background=true` 走**模型侧后台索引**:一次调用把「起 zg 进程 + 登记进官方作业注册表 + 挂超时回收」全做完,把可轮询的作业号交回后**立即返回**。建索引可能要下载 embedding 权重、等很久,后台执行免得工具调用一直挂着。
44
- - 不依赖宿主作业工具:宿主作业工具在 web 平面已停用,模型侧那条路根本不可走。插件复用与设置卡**完全相同**的 spawn/登记/占位三步(同一个函数,不是复制品),所以两条入口起的作业在名册、状态投影、轮询端点上完全同形——卡片能看见模型起的索引,反之亦然。
52
+ - 不依赖宿主作业工具:宿主作业工具在 web 平面已停用,模型侧那条路根本不可走。插件复用与设置卡**完全相同**的 spawn/登记/占位三步(同一个函数,不是复制品),所以两条入口起的作业在名册、状态投影、`status` 读面上完全同形——卡片能看见模型起的索引,反之亦然。
45
53
  - 占位与设置卡的重建互斥,且跨入口成立:同根已在跑索引写时,模型侧与卡片侧都只会跟随那一条,不会各起一条 zg 去啃同一份索引。
46
54
  - 官方作业注册表缺席时**根本不起进程**并直接报错:起一条没有环、没有容量、也没人能收的 zg 比不起更糟——它会一直占着同根的写锁,把这棵树的后续索引全堵死。
47
55
  - 落定前该根的语义检索会等它完成再自动重试,期间 grep/rg 不受门禁限制。
@@ -103,23 +111,23 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
103
111
  - 这一档不是「快一点」的区别。`--mode auto` 的两侧是两种能力面:direct 每发 `zg query` 都要新建再关闭一次引擎、**embedding 模型逐次冷加载**;而索引的增量刷新(watcher)、`refresh=background` 与常驻模型池**只在 server 模式下存在**。上游对 `auto` 只做就绪探测、不会替用户拉起 daemon。
104
112
  - 本包**不代为起一个长驻进程**:`zg server on` 会在用户机器上落下 detached 进程与 token 文件,那是该由用户点头的动作,不是插件替部署做的决定。本包做的是把这一档**显式化**,不再让它藏在「检索超时给 5 分钟」和「改动搜不到」这类使用限制背后:
105
113
  - 按 TTL(60 秒)缓存 `zg server status --check-ready` 的**退出码**(就绪 0、未就绪非零;读 stdout 文本不行,那是给人看的状态表、不在本包的依赖契约里)。探测失败一律按未就绪收口,**绝不外抛**基础设施故障。
106
- - 据此收口 `refresh=background`(见工具一节),并在 `zg_status` 的输出尾部与设置卡各回显一行就绪态。被信任闸门拒掉的请求不起探测;重建期那条「合成投影」也不起(它本来的契约就是不启子进程)。
114
+ - 据此收口 `refresh=background`(见工具一节),并在 `zg_status` 的输出尾部与设置卡各回显一行就绪态。探测只由 `roots()` 触发:`rebuild` 与 `status` 不起探测,重建期那条「合成投影」也不起(它本来的契约就是不启子进程)。
107
115
  - 设置卡的 `serverReady` 只可能是 `true` / `false`;旧版 host 的应答里根本没有这一位,卡片对「未知」的那一臂**不显示**,而不是把它说成「未就绪」。
108
116
  - 想把红利拿到手:在持有终端时执行 `zg server on`(起停与状态另有 `zg server off` / `zg server status`)。本包只读它的就绪态,不拥有它的生命周期。
109
117
 
110
118
  ### 对外接口
111
119
 
112
- - 三条路由的 handler 第一句都是 `guardTrust(req, res, { servingNonLoopback })`(`shared/lib/trust`),任一判据不过即 `403` + `{ ok:false, error: ... }`。
113
- - 判据次序:Host 权威 → `sec-fetch-site` 白名单 → `origin` 与 Host 逐字比对;两句错误文本是 `"untrusted host authority"` 与 `"cross-origin request rejected"`。
114
- - `servingNonLoopback` 由 `isNonLoopbackBindHost(webServer.host)` 按**绑定地址本身**算出(宿主只拒通配地址,绑本机网卡的具体 IPv4/IPv6 是合法配置,比字面量会漏判这一面);非本方法的 `405` 带 `Allow` 与 `{ ok:false, error:"GET only" | "POST only" }`,不再是空回显。
115
- - `GET /_dsh/zvec-grep/rebuild-roots`:只回本包自己的数据(每次 apply 重新生成的 CSRF token + 已观测工作区列表 + 卡片要显示的那行守护进程就绪态),允许 GET/HEAD,过不了上面那道闸门即 403。就绪探测排在**两道闸门之后**,被拒的请求不起子进程。
116
- - `POST /_dsh/zvec-grep/rebuild?root=...`:闸门 + 头 `x-zvec-grep-csrf` + body <= 4096 字节 + root 命中白名单 + 目录存在,成功回 `{ ok, jobId }`;否则 405/403/400/500。
117
- - `/_dsh/zvec-grep/rebuild-status?jobId=...`:闸门后轮询(卡片每 2 秒一次),回 status/exitCode/root/output(有沙箱时带 sandbox),未知 jobId 回 404 并说明多半是出了本包那条 10 条落定窗口。
120
+ - 重建面是一枚**官方 Typert Remote 命名空间** `zvecGrepRebuild`(`lib/rebuild-shape.ts` 的 `REBUILD_REMOTE_NAMESPACE`),三个方法用程序化方式打标记(`lib/rebuild-remote.ts` 的 `markRemote`),注册在 apply fiber 上。没有 `/_dsh/*` 路由、没有 CSRF token、本包也不再自带 body 上限:认证与 Host / DNS 重绑定 / Origin 判据、请求体上限都由宿主 `/api` 网关承担,本包连 `webServer` 依赖都不再声明。
121
+ - `roots()` → `{ roots, serverReady }`:本 daemon 真实观测到的白名单工作区,加上卡片那一行守护进程就绪态。`zg server status --check-ready` 探测**只在这里发**,与三条工具共用同一份 60 秒 TTL 缓存。`serverReady` 在探测答不出时是 `undefined`,卡片对这一臂什么都不显示,而不是把「不知道」说成「未就绪」。
122
+ - `rebuild({ root })` → `{ ok: true, jobId, reused? }` 或 `{ ok: false, error, status }。判据与 HTTP 版一模一样,因为它们护的是动作本身、与传输方式无关:非 `/` 开头的路径先拒(`assertAbsoluteRoot`),不在观测白名单里的拒,目录已消失的拒,宿主 `jobs` 服务不在场时**一条都不 spawn**(503 那一臂)。同根占位在第一个 `await` 之前取,是唯一的互斥依据,因此第二次点击跟随在跑的那条(`reused: true`),跟不到也只是被拒,不会在同一份索引上再起一条 `zg`。版本门槛与 ignore 文件预检排在命令构造之前;启动失败会交回自己的码并归还占位,那棵树不会被永久标成「重建中」。
123
+ - `status({ jobId })` → `{ status, exitCode, root, output }`(有沙箱时带 `sandbox`)或 `{ ok: false, error, status: 404 | 503 }`。它只认本包侧表里的 id——保留最近 10 条**已落定**记录(`REBUILD_HISTORY_MAX`,在跑的永不淘汰),所以别人的作业(如宿主的 `bash-1`)经这里读不到。三档 404 分别是「窗口过去了」「注册表那一行不再持有它」「身份三元组(kind / label / startedAt)与这条记录不符」;503 那一档是两次启动之间注册表消失。卡片每 2 秒敲一次(`REBUILD_POLL_MS = 2000`)。
124
+ - 拒绝结果里的 `status` 是**保留下来的语义码,不是 HTTP 状态**:应答由网关成框,所以拒绝就是一个普通结果对象,卡片渲染 `error`,那个数字存在是为了让测试钉住是哪条判据拦的。这三个方法都不许把异常抛穿到网关——一次被拒的 Remote 调用对卡片只是一条笼统的失败,会停掉轮询并让还在跑的重建从此看不见。
118
125
  - 另有 systemPrompt 段 `zvec-grep-routing`(order 1550)与 settings 命名空间 `zvec-grep`。
119
- - 白名单只记本 daemon 真实观测到的会话工作区,容量 64(超出按插入序淘汰)。
126
+ - 客户端那一侧(`src/rebuild-reader.ts`)用 `$mount` 挂三条手写 descriptor(`kind: "direct"`、`result: { mode: "src-json" }`,两个入参各带 strict codec),挂载只发生一次,随后按派生键 `remote.zvecGrepRebuild` 取服务。宿主没有 `remote` 服务时根本不构造读面;服务在、命名空间没挂上时读面抛 `… 未提供`,卡片显示 `rebuildUnavailable` 那一行而不是整片空白。
127
+ - 白名单只记本 daemon 真实观测到的会话工作区,容量 64;**命中会触摸**该条(挪到队尾),淘汰先掉已过期的、再按**最久未触摸**依次淘汰,不是按插入序。
120
128
  - 同时能跑几个重建由**宿主注册表**决定(实测默认未拥有桶 10),本包不再自带并发上限;
121
- 满员时 `POST /rebuild` 直接回 500 并带上官方的点名文案,**不会**再杀掉已经在跑的重建。
122
- - `rebuild-status` 的 `jobId` 只在本包侧表里查得到:本包保留最近 10 条**已结束**的记录
129
+ 满员时 `rebuild` 直接交回拒绝结果并带上官方的点名文案,**不会**再杀掉已经在跑的重建。
130
+ - `status` 的 `jobId` 只在本包侧表里查得到:本包保留最近 10 条**已结束**的记录
123
131
  (超出即从注册表 remove ⇒ 404),进行中的记录永不被动。
124
132
 
125
133
  ### 后台作业面(官方 `ctx.jobs`)
@@ -129,16 +137,16 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
129
137
 
130
138
  | 面 | 事实 |
131
139
  | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
132
- | 模型侧能看见了 | 官方 `job_list` / `job_output` / `job_kill` 现在列得出这次重建,退出码与信号名走作业的 `detail`(口径与宿主的 bash 工具同形,实测 `plugins/docs/harness/f3-equiv/probe-jobs.mjs`)。输出走官方 **pull source**(`proc.observed[*].readFrom`)⇒ 环由注册表按它自己的节拍推进,**设置面板关着也照样前进**;官方那条观察者面与 `readOutput()` 互不偷字节(d.ts 原文 "without stealing bytes from `readOutput`")。controller 只在 `start` 那一瞬挂、摘掉即恢复官方拒绝(见跨包纪律) |
133
- | 未拥有 ⇒ 对全部会话可见 | 官方件按 owner 隔离,未拥有作业任何 caller 都能 `list`/`read`/`kill`。这是本波**已知并接受**的暴露面(卡片是会话外的 webServer 生产者,受有作业则要 `dsh-agent` 注册表,实测不可得)。要收回去只有一条路:回滚这次换装。注意 `/_dsh/zvec-grep/rebuild-status` 仍只认本包侧表里的 id,别人的作业(如宿主的 `bash-1`)经这个端点读不到 |
140
+ | 模型侧能看见了 | 官方 `job_list` / `job_output` / `job_kill` 现在列得出这次重建,退出码与信号名走作业的 `detail`(口径与宿主的 bash 工具同形)。输出走官方 **pull source**(`proc.observed[*].readFrom`)⇒ 环由注册表按它自己的节拍推进,**设置面板关着也照样前进**;官方那条观察者面与 `readOutput()` 互不偷字节(d.ts 原文 "without stealing bytes from `readOutput`")。controller 只在 `start` 那一瞬挂、摘掉即恢复官方拒绝(见跨包纪律) |
141
+ | 未拥有 ⇒ 对全部会话可见 | 官方件按 owner 隔离,未拥有作业任何 caller 都能 `list`/`read`/`kill`。这是本波**已知并接受**的暴露面(卡片经 Remote 读面触达注册表,本身在会话之外,而受有作业则要 `dsh-agent` 注册表,实测不可得)。要收回去只有一条路:回滚这次换装。注意 `status` 读面仍只认本包侧表里的 id,别人的作业(如宿主的 `bash-1`)经它读不到 |
134
142
  | 多了两个状态词 | `stopping`(取消已发出、进程还没收完 ⇒ 卡片按「仍在跑」显示)与 `failed`(注册表侧判定失败 ⇒ 给专门文案,不显示成「退出码 null」) |
135
143
 
136
- 不留存的东西也写清楚:输出环按 **UTF-8 字节**留存(实测宿主默认 262144 字节),卡片的 4000 字符尾窗与 `shown/total` 按 **UTF-16 码元**计——两套单位各管各的。因此 `total` 说的是**留存窗内**的码元数(官方那个字节真值在 `view.output.total`,单位不同不混用),而中文输出下这只窗比换装前(按码元留 256 KiB)**小约 1/3**,这是采用官方件的代价。两条丢失标记各说一件事:`已截断` = 环按留存窗裁掉了头部(`view.output.earliest > 0`,看不见了);`缓冲区溢出` = 执行器的读者报 lossy 或干脆抛了(真少了字节,可能有 spill 文件)。超时说明与沙箱事实**不进环**:环的写权归注册表的泵,而它在落定之后丢弃一切写入(实测),所以这两条由端点在投影时合成,永远不会因为"写晚了"而消失。注册表被重载或记录被别人收走时轮询答 **404**(官方 `get`/`readAt` 对未知 id 抛错,而宿主对 handler 抛出的兜法是记一条日志再写一枚没有 body、没有 content-type 的 **400**,只有头已发时才断掉 socket —— installed dsh-host-webserver `lib/index.js:246-256` ⇒ 卡片会进终止态并停轮询,那条还在跑的重建就再也看不见)。
144
+ 不留存的东西也写清楚:输出环按 **UTF-8 字节**留存(实测宿主默认 262144 字节),卡片的 4000 字符尾窗与 `shown/total` 按 **UTF-16 码元**计——两套单位各管各的。因此 `total` 说的是**留存窗内**的码元数(官方那个字节真值在 `view.output.total`,单位不同不混用),而中文输出下这只窗比换装前(按码元留 256 KiB)**小约 1/3**,这是采用官方件的代价。两条丢失标记各说一件事:`已截断` = 环按留存窗裁掉了头部(`view.output.earliest > 0`,看不见了);`缓冲区溢出` = 执行器的读者报 lossy 或干脆抛了(真少了字节,可能有 spill 文件)。超时说明与沙箱事实**不进环**:环的写权归注册表的泵,而它在落定之后丢弃一切写入(实测),所以这两条由 `status` 读面在投影时合成,永远不会因为"写晚了"而消失。注册表被重载或记录被别人收走时 `status` 交回拒绝结果(`status: 404`),而不是让官方的 `unknown job` 异常抛穿到网关——一次被拒的调用对卡片只是一条笼统失败,会停掉轮询并让还在跑的重建从此看不见。
137
145
 
138
146
  ### 数据与隐私
139
147
 
140
148
  - 索引的唯一落盘形状是被检索 root 下的 `.zvec-grep/` 目录,由 zg 写入(read-only 沙箱下写不了它,会明确报索引可能不完整)。
141
- - 重建有两条路:模型侧 `zg_index`(rebuild=true、confirm=true),或设置卡「工作区重建」走上面的 rebuild 路由;删除是 `zg_index` drop=true(拼成 `zg index <root> --drop --yes`)。
149
+ - 重建有两条路:模型侧 `zg_index`(rebuild=true、confirm=true),或设置卡「工作区重建」走上面的 `rebuild` 方法;删除是 `zg_index` drop=true(拼成 `zg index <root> --drop --yes`)。
142
150
  - 本包自身不写任何文件(唯一的 fs 调用是索引探测:existsSync + 读一次清单),也不向宿主数据目录 `$DSH_HOME`(`<dsh 数据目录>`)落数据。
143
151
  - 索引探测不只判「`.zvec-grep/manifest.json` 在不在」:还要**解析清单**并确认它的 `rootPaths` 真的覆盖这个目录。两种实况会被「只判存在」误判成有索引,而实际检索必然失败——文件在但不是一份清单(半截写入/同名占用),以及清单在但根路径指向别处。此时门禁若还按「已建索引」拦着 grep/rg,就等于把检索与门禁双向堵死。
144
152
  - 认的结构只有 `manifestVersion`(**严格等于 1**)与 `rootPaths`(非空数组、每项带非空 `absolutePath`)两处——版本不等时上游读它会直接抛 `MANIFEST.INVALID`,此时这个目录一次检索都做不了,宽松放行只会把用户卡在「门禁拦着、检索又必失败」的死角里。刻意不校验 embedding / policy 等字段——那些变了索引照样能用,判成「无索引」反而是错的。
@@ -156,7 +164,7 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
156
164
 
157
165
  - grep/rg 被拒且提示「尚未执行过 zg_search」:这是 search-first 门禁,先 zg_search;配额用尽或过期同理,换个更准的 query/fts 重搜即可续上,不必关插件。
158
166
  - 检索超时:默认 `--refresh wait` 会同步刷新既有索引,大工作区请用 globs/fileTypes 缩小范围或调小 limit,也可先手写字面检索;想让超时这件事本身变小,就起守护进程(见「守护进程」一节)——直连模式每次都要冷加载 embedding 模型,那才是超时预算被抬到 5 分钟的原因。
159
- - 重建按钮回 403「root 不在本 daemon 观测到的工作区白名单内」:该目录从未在本 daemon 开过会话;先在该目录起会话,或让模型带 confirm=true 调 zg_index。
167
+ - 重建按钮的拒绝文案是「root 不在本 daemon 观测到的工作区白名单内」:该目录从未在本 daemon 开过会话;先在该目录起会话,或让模型带 confirm=true 调 zg_index。
160
168
  - 卡片显示重建失败而 zg 看着像跑完了:成功判据是 completed 且 exit 0——exit 127(zg 没装)也落在 completed,看输出尾部原因。
161
169
  - 从未建索引的 root:zg_search 明确报错而不是静默建索引;建索引只在用户明确要求时由 zg_index 做。
162
170
  - 换了 embedding 却搜不到语义结果:切换 embedding 必须 rebuild=true 重建后才生效。