@jayyuen66/dsh-zvec-grep 0.1.16 → 0.1.18
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 +50 -0
- package/README.md +5 -4
- package/README.zh-CN.md +5 -4
- package/client.js +252 -148
- package/docs/DETAIL.md +1 -1
- package/docs/DETAIL.zh.md +1 -1
- package/host.js +233 -46
- package/package.json +9 -7
package/docs/DETAIL.md
CHANGED
|
@@ -24,7 +24,7 @@ The card's Rebuild button runs the equivalent of `zg --index --rebuild` for a wo
|
|
|
24
24
|
|
|
25
25
|
Eleven deployment values stay off the card: `searchTimeoutMs` (300000), `statusTimeoutMs` (60000), `indexTimeoutMs` (600000), `stdoutMaxBytes` (400000), `rebuildWaitMs` (120000), `clientMode` (`auto` / `direct` / `server`), `daemonUrl` (`http://127.0.0.1:7999/mcp`, the MCP transport's daemon endpoint), `allowRemoteEmbedding` (false), `remoteEmbeddingEndpoint`, `remoteEmbeddingApiKeyFrom`, `requireApprovalForExplicitRoot` (false). None of these eleven has a card control; the only thing that makes them take effect is the `config:` block of the registration row in the next paragraph, and precedence is row `config:` > the `.default()` in code.
|
|
26
26
|
|
|
27
|
-
Whether workspace content may leave the machine at all is treated as a deployment decision rather than a model-visible choice, which is why the remote-embedding trio appears in neither the card nor the tool parameters; and even when it is enabled, `zg` itself still requires `--allow-remote` (added automatically by this plugin to remote-reference index commands once the deployment switch is on) or a one-time persistent `zg --auth grant`. Set all of these in the `config:` block of this plugin's row in your profile's `cordis.yml` (the `cordis.patch.yml` shipped in this package carries that row's `id` / `name
|
|
27
|
+
Whether workspace content may leave the machine at all is treated as a deployment decision rather than a model-visible choice, which is why the remote-embedding trio appears in neither the card nor the tool parameters; and even when it is enabled, `zg` itself still requires `--allow-remote` (added automatically by this plugin to remote-reference index commands once the deployment switch is on) or a one-time persistent `zg --auth grant`. Set all of these in the `config:` block of this plugin's row in your profile's `cordis.yml` (the `cordis.patch.yml` shipped in this package carries that row's `id` / `name`; the card components are bundled into `client.js`, so no second package entry is needed); they take effect on restart.
|
|
28
28
|
|
|
29
29
|
## What it needs from outside
|
|
30
30
|
|
package/docs/DETAIL.zh.md
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
十一项部署值刻意不进设置卡:`searchTimeoutMs`(300000)、`statusTimeoutMs`(60000)、`indexTimeoutMs`(600000)、`stdoutMaxBytes`(400000)、`rebuildWaitMs`(120000)、`clientMode`(`auto` / `direct` / `server`)、`daemonUrl`(`http://127.0.0.1:7999/mcp`,MCP 传输的守护进程端点)、`allowRemoteEmbedding`(false)、`remoteEmbeddingEndpoint`、`remoteEmbeddingApiKeyFrom`、`requireApprovalForExplicitRoot`(false)。这十一项在卡上没有入口,能生效的只有下一段那条注册行 `config:`;优先级是注册行 `config:` > 代码里的 `.default()`。
|
|
26
26
|
|
|
27
|
-
「工作区内容能不能离开本机」被当成部署决定,而不是给模型选的开关,所以远程嵌入那三枚既不在卡上也不在工具参数里;即便开了,`zg` 自己仍要求 `--allow-remote`(部署开放后本插件在远程引用的索引命令上自动补)或一次 `zg --auth grant` 持久授权。这些值都写在**自己 profile 的 `cordis.yml`** 里本插件注册行的 `config:` 块(随包那份 `cordis.patch.yml` 带本行的 `id` / `name
|
|
27
|
+
「工作区内容能不能离开本机」被当成部署决定,而不是给模型选的开关,所以远程嵌入那三枚既不在卡上也不在工具参数里;即便开了,`zg` 自己仍要求 `--allow-remote`(部署开放后本插件在远程引用的索引命令上自动补)或一次 `zg --auth grant` 持久授权。这些值都写在**自己 profile 的 `cordis.yml`** 里本插件注册行的 `config:` 块(随包那份 `cordis.patch.yml` 带本行的 `id` / `name`;卡片组件已打进 `client.js`,不需要第二条包条目),改值随重启生效。
|
|
28
28
|
|
|
29
29
|
## 需要外部提供什么
|
|
30
30
|
|
package/host.js
CHANGED
|
@@ -4,11 +4,15 @@ import { randomBytes } from "node:crypto";
|
|
|
4
4
|
import { accessSync, constants, existsSync, readFileSync, statSync } from "node:fs";
|
|
5
5
|
import { homedir, tmpdir } from "node:os";
|
|
6
6
|
import nodePath from "node:path";
|
|
7
|
+
import { fillPlaceholders } from "@jayyuen66/dsh-plugin-shared/lib/placeholder";
|
|
7
8
|
import { scopeOf } from "@deepseek-ai/dsh-scope";
|
|
8
|
-
import { isRecord
|
|
9
|
+
import { isRecord } from "@jayyuen66/dsh-plugin-shared/lib/record";
|
|
9
10
|
import { errorText } from "@jayyuen66/dsh-plugin-shared/lib/errors";
|
|
11
|
+
import { HarnessError } from "@deepseek-ai/dsh-error";
|
|
12
|
+
import { registerSkill } from "@jayyuen66/dsh-plugin-shared/lib/skill";
|
|
10
13
|
import { LOCALE_SETTINGS_NAMESPACE, messagesFor, resolveLocalePreference } from "@jayyuen66/dsh-plugin-shared/lib/locale";
|
|
11
14
|
import { truncateEnd, truncateStart } from "@jayyuen66/dsh-plugin-shared/lib/text";
|
|
15
|
+
import { claimInstance } from "@jayyuen66/dsh-plugin-shared/lib/instance-lock";
|
|
12
16
|
import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
13
17
|
import { jobOutcomeOf } from "@jayyuen66/dsh-plugin-shared/lib/job-outcome";
|
|
14
18
|
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
@@ -171,6 +175,19 @@ const MESSAGES = {
|
|
|
171
175
|
"5. 新建索引用用户选定的 embedding,未选定时不得臆测;切换 embedding 需 rebuild 才生效。",
|
|
172
176
|
"6. zg_* 的 root 可省略:缺省为当前会话工作区(绝对路径)。显式传入时必须落在本会话可操作范围内——会话工作区本身、它的上级或下级目录,或本会话已登记过的工作区;其余绝对路径会被拒绝。"
|
|
173
177
|
].join("\n"),
|
|
178
|
+
routingSummary: [
|
|
179
|
+
"# zvec-grep(zg)工作区检索规则",
|
|
180
|
+
"",
|
|
181
|
+
"- 工作区**已建 zg 索引**(存在 .zvec-grep/manifest.json)时:所有检索必须先调用 zg_search;grep/rg 只作为它之后的精确字面/正则补充。门禁会拦下未经 zg_search 的 grep/rg(bash 里的命令与原生 grep 工具都算),被拦时按拒绝理由办:换一个更准确的 query/fts 重新 zg_search。",
|
|
182
|
+
"- 语义/关系/跨文件/多跳证据(架构、调用链、依赖、生命周期、数据流或控制流、设计意图、对比、跨文件综合)→ 必须先调用 zg_search。",
|
|
183
|
+
"- **无索引工作区**:zg_search 自动改走穷举词法检索,精确查找用它就够,不必先 zg_index(那要先下载 embedding 权重)。穷举检索不发放 grep/rg 配额。",
|
|
184
|
+
"- zg_index 仅在用户明确要求建/重建/删索引时调用,且 confirm 必须为 true;绝不静默建索引。",
|
|
185
|
+
"- zg_status 只在诊断索引缺失/失败/取消或显式监控进度时调用,普通搜索前不要调。",
|
|
186
|
+
"- zg_* 的 root 可省略:缺省为当前会话工作区(绝对路径)。显式传入时必须落在本会话可操作范围内——工作区本身、它的上级或下级目录,或本会话已登记过的工作区;其余绝对路径被拒绝。",
|
|
187
|
+
"",
|
|
188
|
+
"配额算法、重建流程、embedding 选择、检索结果的证据判读等完整规则见 skill `zvec-grep`(用 skill 工具按名加载)。"
|
|
189
|
+
].join("\n"),
|
|
190
|
+
skillDescription: "zvec-grep 工作区检索的完整规则:索引/免索引两条路由、grep/rg 门禁与配额算法、重建与 embedding 选择、检索结果的证据判读。开始在本工作区做检索前先加载它,尤其当你准备用 grep/rg/glob 或语义检索、或要建/重建索引时。",
|
|
174
191
|
argsMustBeObject: "zg {name}: 参数必须是一个 JSON 对象(收到 {received})",
|
|
175
192
|
missingRequiredArgs: "zg {name}: 缺少必填参数 {fields}(缺失即拒绝,不产生副作用)",
|
|
176
193
|
sandboxFacts: "(沙箱 mode={mode}{enforcement})",
|
|
@@ -337,6 +354,19 @@ const MESSAGES = {
|
|
|
337
354
|
"5. Use the embedding the user picked for a new index; never guess when none was chosen. Switching embedding requires rebuild to take effect.",
|
|
338
355
|
"6. root may be omitted for zg_* tools: it defaults to the current session workspace (absolute path). When passed explicitly it must stay inside this session's operable scope — the workspace itself, its parents or children, or a workspace this session already registered; any other absolute path is rejected."
|
|
339
356
|
].join("\n"),
|
|
357
|
+
routingSummary: [
|
|
358
|
+
"# zvec-grep (zg) workspace search rules",
|
|
359
|
+
"",
|
|
360
|
+
"- When the workspace **has a zg index** (a .zvec-grep/manifest.json exists): every search must call zg_search first; grep/rg only as the exact literal/regex follow-up. The gate refuses grep/rg that did not follow a zg_search (both the bash command and the native grep tool); when it refuses, take the way out it names: re-run zg_search with a more precise query/fts.",
|
|
361
|
+
"- Semantic / relational / cross-file / multi-hop evidence (architecture, call chains, dependencies, lifecycles, data or control flow, design intent, comparisons, cross-file synthesis) → always call zg_search first.",
|
|
362
|
+
"- Workspaces **without an index**: zg_search falls back to exhaustive lexical search, which is enough for exact lookups — no need to zg_index first (that would download embedding weights). Exhaustive search grants no grep/rg quota.",
|
|
363
|
+
"- Call zg_index only when the user explicitly asks to build/rebuild/drop the index, and confirm must be true; never index silently.",
|
|
364
|
+
"- Call zg_status only to diagnose a missing/failed/cancelled index or to watch progress explicitly; not before a normal search.",
|
|
365
|
+
"- root may be omitted for zg_* tools: it defaults to the current session workspace (absolute path). When passed explicitly it must stay inside this session's operable scope — the workspace itself, its parents or children, or a workspace this session already registered; any other absolute path is rejected.",
|
|
366
|
+
"",
|
|
367
|
+
"The full rules (quota arithmetic, rebuild flow, embedding choice, how to read result evidence) live in the skill `zvec-grep`: load it by name with the skill tool."
|
|
368
|
+
].join("\n"),
|
|
369
|
+
skillDescription: "The full zvec-grep workspace search rules: both routes (indexed and index-free), the grep/rg gate and its quota arithmetic, rebuild and embedding choice, and how to read result evidence. Load it before searching in this workspace, especially before reaching for grep/rg/glob or semantic search, or before building/rebuilding an index.",
|
|
340
370
|
argsMustBeObject: "zg {name}: arguments must be a JSON object (received {received})",
|
|
341
371
|
missingRequiredArgs: "zg {name}: missing required arguments {fields} (refused outright, no side effects)",
|
|
342
372
|
sandboxFacts: " (sandbox mode={mode}{enforcement})",
|
|
@@ -446,17 +476,15 @@ const MESSAGES = {
|
|
|
446
476
|
/**
|
|
447
477
|
* `{name}` 占位符插值(与官方 locale 的 Translate 参数语义同源)。
|
|
448
478
|
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
479
|
+
* 实现已收进 shared 的 `@jayyuen66/dsh-plugin-shared/lib/placeholder`。本包此前缺键即替空串,
|
|
480
|
+
* 现在统一成「缺值保留原文」:写错占位符时原样留着的 `{xxx}` 一眼可见,比一句悄悄塌掉的
|
|
481
|
+
* 文案好排障。`null` 仍照实渲染成 `"null"`(`exitCode` 这类字段的正常取值)。
|
|
451
482
|
* @param template - 字典里的模板。
|
|
452
|
-
* @param params - 占位符名 →
|
|
483
|
+
* @param params - 占位符名 → 值。
|
|
453
484
|
* @returns 填好的文本。
|
|
454
485
|
*/
|
|
455
486
|
function fill(template, params) {
|
|
456
|
-
return template
|
|
457
|
-
const value = Object.hasOwn(params, key) ? params[key] : void 0;
|
|
458
|
-
return value === void 0 ? "" : String(value);
|
|
459
|
-
});
|
|
487
|
+
return fillPlaceholders(template, params);
|
|
460
488
|
}
|
|
461
489
|
// lib/platform.ts
|
|
462
490
|
/** 把 Node 的 platform 收成两档:win32 单独一档,其余都按 POSIX。 */
|
|
@@ -1995,7 +2023,7 @@ function zgToolProblem(name, args, execution, messages, platform) {
|
|
|
1995
2023
|
*/
|
|
1996
2024
|
function zgGuard(execution, messages, platform = "posix") {
|
|
1997
2025
|
const { name } = execution;
|
|
1998
|
-
const args = isRecord
|
|
2026
|
+
const args = isRecord(execution.arguments) ? execution.arguments : {};
|
|
1999
2027
|
let reason;
|
|
2000
2028
|
if (isZgToolName(name)) reason = zgToolProblem(name, args, execution, messages, platform);
|
|
2001
2029
|
return reason;
|
|
@@ -2182,7 +2210,7 @@ function nativeGrepProblem(args, cwd, deps, messages) {
|
|
|
2182
2210
|
*/
|
|
2183
2211
|
function searchFirstGuard(execution, deps, messages) {
|
|
2184
2212
|
const { name } = execution;
|
|
2185
|
-
const args = isRecord
|
|
2213
|
+
const args = isRecord(execution.arguments) ? execution.arguments : {};
|
|
2186
2214
|
const cwd = sessionHeaderCwd$1(execution);
|
|
2187
2215
|
let reason;
|
|
2188
2216
|
if (deps.enabled && cwd !== void 0 && searchAdmitted(execution)) {
|
|
@@ -2381,6 +2409,52 @@ function classifyConcurrentFailure(stderr) {
|
|
|
2381
2409
|
if (code === "ZG.ENGINE.PERMISSION_DENIED") return { kind: "permission-denied" };
|
|
2382
2410
|
return null;
|
|
2383
2411
|
}
|
|
2412
|
+
// lib/zg-tool-error.ts
|
|
2413
|
+
/**
|
|
2414
|
+
* 本包工具失败的错误码。
|
|
2415
|
+
*
|
|
2416
|
+
* 为什么要码而不只是人话:宿主 `packages/core/tools/src/pipeline.ts` 的 `errorInfo()` 用
|
|
2417
|
+
* `error instanceof HarnessError` 判断要不要把 `{ name, code }` 写进工具失败的
|
|
2418
|
+
* `ToolFailure.info`。判不中时 `info` **整块消失且没有任何提示** —— 模型只看到一句
|
|
2419
|
+
* `Error: …`,无法据此区分「等一会重试」与「换条路」。码是给模型与下游消费方判读的,
|
|
2420
|
+
* 人话仍然是 `message`,两者不互相替代。
|
|
2421
|
+
*
|
|
2422
|
+
* 码值一经发布即持久化契约(宿主 error-codes 的注释原话:`The values are persisted
|
|
2423
|
+
* contract`):会话日志里存的是这些串,改名等于让旧日志读不懂。要加码就新增,不要复用。
|
|
2424
|
+
*/
|
|
2425
|
+
const ZG_TOOL_ERROR_CODES = {
|
|
2426
|
+
/** 装着的 zg 低于本包下限;出路是升级 zg(不是重试)。 */
|
|
2427
|
+
versionTooOld: "ZG_VERSION_TOO_OLD",
|
|
2428
|
+
/** 本插件正在重建该根:等它落定后重试一次即可,属于可重试。 */
|
|
2429
|
+
rebuildLockBusy: "ZG_REBUILD_LOCK_BUSY",
|
|
2430
|
+
/** 别的进程/操作占着锁:不归本插件管,重试也等不到。 */
|
|
2431
|
+
lockBusy: "ZG_LOCK_BUSY",
|
|
2432
|
+
/** 远程 embedding 授权被拒:出路在部署侧(开关或 grant)。 */
|
|
2433
|
+
permissionDenied: "ZG_PERMISSION_DENIED",
|
|
2434
|
+
/** 守护进程拉不起来或调用失败:模型该退回不起服务的那条路。 */
|
|
2435
|
+
daemonUnavailable: "ZG_DAEMON_UNAVAILABLE",
|
|
2436
|
+
/** 调用方给的根不存在或不被允许。 */
|
|
2437
|
+
rootRejected: "ZG_ROOT_REJECTED",
|
|
2438
|
+
/** 参数形态不合契约(非对象、必填缺失)。模型的输入错误,改参数即可。 */
|
|
2439
|
+
badArguments: "ZG_BAD_ARGUMENTS",
|
|
2440
|
+
/** zg 跑了但失败了,且不属于以上任何一类。 */
|
|
2441
|
+
commandFailed: "ZG_COMMAND_FAILED"
|
|
2442
|
+
};
|
|
2443
|
+
/**
|
|
2444
|
+
* 本包工具失败的统一错误类。
|
|
2445
|
+
*
|
|
2446
|
+
* 继承宿主的 `HarnessError` 是**整件事的关键**:那个类必须来自宿主那一份模块实例
|
|
2447
|
+
* (`@deepseek-ai/dsh-error` 声明在 peerDependencies,构建期按包名外部化),
|
|
2448
|
+
* `instanceof` 才成立。若把它挪进 devDependencies,rolldown 会把整包内联进 host.js,
|
|
2449
|
+
* 于是本包继承的是产物里另一个类,宿主的判据恒为 false —— 码静默消失,
|
|
2450
|
+
* 而源码、单测、类型检查一路绿。`test/publish-manifest.test.ts` 有一条正相断言盯着这一位。
|
|
2451
|
+
*/
|
|
2452
|
+
var ZgToolError = class extends HarnessError {
|
|
2453
|
+
constructor(code, message, options) {
|
|
2454
|
+
super(message, code, options);
|
|
2455
|
+
this.name = "ZgToolError";
|
|
2456
|
+
}
|
|
2457
|
+
};
|
|
2384
2458
|
// lib/zg-version.ts
|
|
2385
2459
|
/**
|
|
2386
2460
|
* 版本下限本体:比较用的对象是唯一事实来源,回显用的字符串由它派生——两处在编译期
|
|
@@ -2443,6 +2517,26 @@ function tooOldZgVersion(stdout) {
|
|
|
2443
2517
|
const parsed = parseZgVersion(stdout);
|
|
2444
2518
|
return parsed === void 0 || versionAtLeast(parsed, MINIMUM) ? void 0 : parsed;
|
|
2445
2519
|
}
|
|
2520
|
+
// lib/skill.ts
|
|
2521
|
+
/** skill 名:kebab-case,也是模型用 skill 工具加载时的入参。 */
|
|
2522
|
+
const SKILL_NAME = "zvec-grep";
|
|
2523
|
+
/**
|
|
2524
|
+
* 注册(或重新注册)本包的检索规则 skill。
|
|
2525
|
+
*
|
|
2526
|
+
* 文案随调用点传入而不是在这里取:语言由 apply 时的官方 locale 偏好决定,与工具描述、
|
|
2527
|
+
* 参数说明同源——三处各取一次就会出现「工具描述是中文、skill 正文是英文」那种错位。
|
|
2528
|
+
* @param ctx - 只需 `get`(读可选服务),不要求 skills 进 inject
|
|
2529
|
+
* @param content - 规则全文(`messages.routingText`)
|
|
2530
|
+
* @param description - skill 目录里那行说明(模型据此决定要不要加载)
|
|
2531
|
+
* @returns 注册成功与否;未装载 skill 服务或正文为空时为 false(不抛,摘要段照旧生效)
|
|
2532
|
+
*/
|
|
2533
|
+
function registerRoutingSkill(ctx, content, description) {
|
|
2534
|
+
return registerSkill(ctx, {
|
|
2535
|
+
name: SKILL_NAME,
|
|
2536
|
+
description,
|
|
2537
|
+
content
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
2446
2540
|
// lib/index-preflight.ts
|
|
2447
2541
|
/**
|
|
2448
2542
|
* 预检判「文件不合适」时接受的家庭错误码:其余(fd 耗尽、符号链接成环、IO 错误等环境故障)
|
|
@@ -3208,7 +3302,7 @@ let ZvecRebuildService = (() => {
|
|
|
3208
3302
|
*/
|
|
3209
3303
|
async rebuild(request) {
|
|
3210
3304
|
const started = this.deps.messages();
|
|
3211
|
-
const accepted = acceptableRoot(isRecord
|
|
3305
|
+
const accepted = acceptableRoot(isRecord(request) ? request.root : void 0, this.deps.ledger, started, this.deps.platform);
|
|
3212
3306
|
if ("error" in accepted) return {
|
|
3213
3307
|
ok: false,
|
|
3214
3308
|
error: accepted.error.value,
|
|
@@ -3271,7 +3365,7 @@ let ZvecRebuildService = (() => {
|
|
|
3271
3365
|
*/
|
|
3272
3366
|
status(request) {
|
|
3273
3367
|
const marks = this.deps.messages();
|
|
3274
|
-
const raw = isRecord
|
|
3368
|
+
const raw = isRecord(request) ? request.jobId : void 0;
|
|
3275
3369
|
const record = typeof raw === "string" && raw.length > 0 ? this.deps.records.get(raw) : void 0;
|
|
3276
3370
|
if (record === void 0) return {
|
|
3277
3371
|
ok: false,
|
|
@@ -3324,7 +3418,7 @@ let ZvecRebuildService = (() => {
|
|
|
3324
3418
|
* @param deps - 重建读取接口的全部依赖(见 ZvecRebuildDeps)
|
|
3325
3419
|
*/
|
|
3326
3420
|
function installRebuildRemote(ctx, deps) {
|
|
3327
|
-
if (!isRecord
|
|
3421
|
+
if (!isRecord(ctx) || !isRecord(ctx.reflect) || typeof ctx.reflect.provide !== "function") return false;
|
|
3328
3422
|
new ZvecRebuildService(ctx, deps);
|
|
3329
3423
|
ctx.effect(() => () => {
|
|
3330
3424
|
releaseRebuildRecords(deps);
|
|
@@ -3467,9 +3561,6 @@ const SESSION_LOST_STATUS = /* @__PURE__ */ new Set([
|
|
|
3467
3561
|
]);
|
|
3468
3562
|
/** 握手与工具调用的 JSON-RPC 常量。 */
|
|
3469
3563
|
const JSONRPC = "2.0";
|
|
3470
|
-
function isRecord(value) {
|
|
3471
|
-
return typeof value === "object" && value !== null;
|
|
3472
|
-
}
|
|
3473
3564
|
/** 从 SSE 正文收集全部 `data:` 行的 JSON 载荷;解析不了的行(心跳/注释)跳过。 */
|
|
3474
3565
|
function ssePayloads(body) {
|
|
3475
3566
|
const payloads = [];
|
|
@@ -3764,11 +3855,18 @@ const MAX_LEDGER_ROOTS = 64;
|
|
|
3764
3855
|
const LEDGER_TTL_MS = 864e5;
|
|
3765
3856
|
/** 成功执行里回显 stderr 的尾部长度(降级提示常就在这一行)。 */
|
|
3766
3857
|
const STDERR_NOTE_CHARS = 400;
|
|
3858
|
+
/**
|
|
3859
|
+
* 单实例锁的服务名。dshmarket 热挂子树与 bundle 层会各跑一次 `apply`,第二遍的注册面会撞
|
|
3860
|
+
* 「同名已注册」而把 fiber 打成 failed;抢这把锁能把第二遍安静地挡在注册面之外。
|
|
3861
|
+
* 取包名形态而**不带随机后缀**:名字必须每一份实例都算出同一个串才可能互斥,随机后缀等于
|
|
3862
|
+
* 谁都能抢到。判据与边界见 shared 的 `lib/instance-lock` 头注释。
|
|
3863
|
+
*/
|
|
3864
|
+
const INSTANCE_LOCK_KEY = "@jayyuen66/dsh-zvec-grep/instance";
|
|
3767
3865
|
/** 具名方法在位(typeof 函数)——只看 `typeof x === "object"` 会放过 null、
|
|
3768
3866
|
* 也会放过「是个对象但没注册方法」的错注入。 */
|
|
3769
3867
|
function hasMethod(value, name, keys) {
|
|
3770
3868
|
const member = value[name];
|
|
3771
|
-
return isRecord
|
|
3869
|
+
return isRecord(member) && keys.every((key) => typeof member[key] === "function");
|
|
3772
3870
|
}
|
|
3773
3871
|
/**
|
|
3774
3872
|
* host 是否为本插件所需宿主服务:五个注入都必须是**带相应方法的对象**,
|
|
@@ -3781,7 +3879,7 @@ function hasMethod(value, name, keys) {
|
|
|
3781
3879
|
* 探它们等于断言一条没有测试撑着的能力。
|
|
3782
3880
|
*/
|
|
3783
3881
|
function isZvecGrepHost(value) {
|
|
3784
|
-
if (!isRecord
|
|
3882
|
+
if (!isRecord(value)) return false;
|
|
3785
3883
|
return hasMethod(value, "settings", ["describe"]) && hasMethod(value, "shell", ["resolve", "execute"]) && hasMethod(value, "tools", ["register", "guard"]) && hasMethod(value, "systemPrompt", ["section"]) && hasMethod(value, "timer", ["timeout"]) && typeof value["get"] === "function";
|
|
3786
3884
|
}
|
|
3787
3885
|
/** 当前会话工作区(root 缺省回退源);非字符串视为缺(读取方式见 lib/routing.ts 的 SessionFace)。 */
|
|
@@ -3799,7 +3897,7 @@ function stringifyJson(value) {
|
|
|
3799
3897
|
return JSON.stringify(value, null, 2);
|
|
3800
3898
|
}
|
|
3801
3899
|
function textBlock(value) {
|
|
3802
|
-
const { text: textValue } = isRecord
|
|
3900
|
+
const { text: textValue } = isRecord(value) ? value : {};
|
|
3803
3901
|
if (typeof textValue === "string") return [{
|
|
3804
3902
|
type: "text",
|
|
3805
3903
|
text: textValue
|
|
@@ -3963,7 +4061,7 @@ const ZG_VERSION_TTL_MS = 6e5;
|
|
|
3963
4061
|
const ZG_VERSION_PROBE_TIMEOUT_MS = 1e4;
|
|
3964
4062
|
/** 版本过低的文案:回显实际版本与下限值,并给出唯一的出路(升级 zvec-grep)。 */
|
|
3965
4063
|
function tooOldZgError(actual, messages) {
|
|
3966
|
-
return new
|
|
4064
|
+
return new ZgToolError(ZG_TOOL_ERROR_CODES.versionTooOld, fill(messages.zgVersionTooOld, {
|
|
3967
4065
|
actual: formatZgVersion(actual),
|
|
3968
4066
|
minimum: MINIMUM_ZG_VERSION
|
|
3969
4067
|
}));
|
|
@@ -4137,7 +4235,7 @@ function createDaemonHandle(options) {
|
|
|
4137
4235
|
}
|
|
4138
4236
|
setToken(void 0);
|
|
4139
4237
|
ownsTokenFile = false;
|
|
4140
|
-
throw new
|
|
4238
|
+
throw new ZgToolError(ZG_TOOL_ERROR_CODES.daemonUnavailable, fill(messages.daemonStartFailed, { detail: failure ?? "zg --server on exited 0 but the readiness probe still fails (another daemon may be using a different token)" }));
|
|
4141
4239
|
};
|
|
4142
4240
|
return {
|
|
4143
4241
|
tokenOf,
|
|
@@ -4224,9 +4322,9 @@ function hitSummary(stdoutText, limit, truncated, messages) {
|
|
|
4224
4322
|
* 只有占锁方自报重建才带这个类型——把「别的进程占锁」也当成可等的重建,
|
|
4225
4323
|
* 会在一把永远不会由本插件放开的锁上无界挂起。
|
|
4226
4324
|
*/
|
|
4227
|
-
var RebuildLockBusyError = class extends
|
|
4325
|
+
var RebuildLockBusyError = class extends ZgToolError {
|
|
4228
4326
|
constructor(message) {
|
|
4229
|
-
super(message);
|
|
4327
|
+
super(ZG_TOOL_ERROR_CODES.rebuildLockBusy, message);
|
|
4230
4328
|
this.name = "RebuildLockBusyError";
|
|
4231
4329
|
}
|
|
4232
4330
|
};
|
|
@@ -4248,9 +4346,9 @@ async function runForegroundOnce(host, command, workdir, timeoutMs, opts) {
|
|
|
4248
4346
|
if (resolved !== null) return resolved;
|
|
4249
4347
|
const concurrent = classifyConcurrentFailure(result.stderr.text);
|
|
4250
4348
|
if (concurrent?.kind === "lock-busy" && concurrent.rebuild) throw new RebuildLockBusyError(failure);
|
|
4251
|
-
if (concurrent?.kind === "lock-busy") throw new
|
|
4252
|
-
if (concurrent?.kind === "permission-denied") throw new
|
|
4253
|
-
throw new
|
|
4349
|
+
if (concurrent?.kind === "lock-busy") throw new ZgToolError(ZG_TOOL_ERROR_CODES.lockBusy, `${fill(opts.messages.lockBusyOtherOperation, { op: concurrent.ownerOperation ?? "unknown" })}\n${failure}`);
|
|
4350
|
+
if (concurrent?.kind === "permission-denied") throw new ZgToolError(ZG_TOOL_ERROR_CODES.permissionDenied, `${failure}\n${opts.messages.remoteAuthDenied}`);
|
|
4351
|
+
throw new ZgToolError(ZG_TOOL_ERROR_CODES.commandFailed, failure);
|
|
4254
4352
|
}
|
|
4255
4353
|
const notes = successNotes(result, opts.messages, opts.stdoutMaxBytes).map((note) => redactToken(note, secret));
|
|
4256
4354
|
const text = redactToken(result.stdout.text, secret);
|
|
@@ -4282,7 +4380,7 @@ async function attemptWithRebuildWait(wait, messages, signal, attempt) {
|
|
|
4282
4380
|
if (!(error instanceof RebuildLockBusyError) || entry === void 0) throw error;
|
|
4283
4381
|
const outcome = await wait.rebuilds.wait(wait.root, messages, wait.maxWaitMs, signal);
|
|
4284
4382
|
if (outcome === "settled") return attempt();
|
|
4285
|
-
throw new
|
|
4383
|
+
throw new ZgToolError(ZG_TOOL_ERROR_CODES.lockBusy, outcome === "aborted" ? messagesAbortedWaiting(entry.root, messages) : messagesWaitExpired(entry.root, wait.maxWaitMs, messages), { cause: error });
|
|
4286
4384
|
}
|
|
4287
4385
|
}
|
|
4288
4386
|
/**
|
|
@@ -4312,7 +4410,7 @@ async function runForeground(host, command, workdir, timeoutMs, opts) {
|
|
|
4312
4410
|
* 模型据此给出的建议会把用户带偏。提前一次 existsSync 换明确归因。
|
|
4313
4411
|
*/
|
|
4314
4412
|
function assertRootExists(root, messages) {
|
|
4315
|
-
if (!existsSync(root)) throw new
|
|
4413
|
+
if (!existsSync(root)) throw new ZgToolError(ZG_TOOL_ERROR_CODES.rootRejected, fill(messages.rootMissing, { root }));
|
|
4316
4414
|
return root;
|
|
4317
4415
|
}
|
|
4318
4416
|
/**
|
|
@@ -4396,11 +4494,11 @@ function manifestCoversRoot(manifestPath, dir, platform) {
|
|
|
4396
4494
|
} catch {
|
|
4397
4495
|
return false;
|
|
4398
4496
|
}
|
|
4399
|
-
if (!isRecord
|
|
4497
|
+
if (!isRecord(parsed)) return false;
|
|
4400
4498
|
const version = parsed["indexVersion"];
|
|
4401
4499
|
if (typeof version !== "number" || !Number.isSafeInteger(version) || version < MINIMUM_INDEX_VERSION) return false;
|
|
4402
4500
|
const { sourceRoot } = parsed;
|
|
4403
|
-
if (!isRecord
|
|
4501
|
+
if (!isRecord(sourceRoot)) return false;
|
|
4404
4502
|
const recorded = sourceRoot["recordedPath"];
|
|
4405
4503
|
return typeof recorded === "string" && recorded.length > 0 && comparablePath(normalizeRoot(recorded, platform), process.platform) === comparablePath(normalizeRoot(dir, platform), process.platform);
|
|
4406
4504
|
}
|
|
@@ -4452,10 +4550,65 @@ function judgeRoot(rawRoot, cwd, messages, ledger, platform) {
|
|
|
4452
4550
|
/** 工具入参的 root:过 root 判据,放行后登记进白名单(一处三工具共用)。 */
|
|
4453
4551
|
function rootOf(args, exec, messages, ledger, platform) {
|
|
4454
4552
|
const decision = judgeRoot(args["root"], sessionHeaderCwd(exec), messages, ledger, platform);
|
|
4455
|
-
if (!decision.allowed) throw new
|
|
4553
|
+
if (!decision.allowed) throw new ZgToolError(ZG_TOOL_ERROR_CODES.rootRejected, decision.reason);
|
|
4456
4554
|
ledger.add(decision.root);
|
|
4457
4555
|
return decision.root;
|
|
4458
4556
|
}
|
|
4557
|
+
/**
|
|
4558
|
+
* 工具级预算在内部最坏路径之外多给的一分钟。
|
|
4559
|
+
*
|
|
4560
|
+
* 必须是**严格大于**而不是等于:`zg_index` 的内部超时(10 分钟)恰好等于宿主
|
|
4561
|
+
* `bash-local` 的 `maxTimeoutMs` 默认值,`ctx.shell.resolve` 会按
|
|
4562
|
+
* `min(请求, 上限)` 收敛,于是内层实际生效的截止与工具级这一枚同刻到期。
|
|
4563
|
+
* 两者同时触发时谁的结果落地是不确定的——宿主那一路会把结果换成
|
|
4564
|
+
* `tool call timed out after Nms`,本包自己那句「zg 执行超时,请缩小范围」
|
|
4565
|
+
* 就没机会说话。留一分钟,让内层永远先到期、先归因。
|
|
4566
|
+
*/
|
|
4567
|
+
const TOOL_TIMEOUT_MARGIN_MS = 6e4;
|
|
4568
|
+
/**
|
|
4569
|
+
* 工具级墙钟预算:**最坏路径**而不是单次执行。
|
|
4570
|
+
*
|
|
4571
|
+
* 带 `rebuildWait` 的工具(检索与状态)在撞上同根重建时会等它落定后**重跑一次**,
|
|
4572
|
+
* 所以最坏是两趟执行加上那段等待;`zg_index` 自己就是那条重建,不等待也不重试,
|
|
4573
|
+
* 一趟就够。少算这一趟的话,宿主会在一趟本来还能成功的重试途中把调用掐掉,
|
|
4574
|
+
* 而模型看到的是一句「tool call timed out」——它无法知道是内部哪一段慢。
|
|
4575
|
+
* @param driven 该工具单趟执行的内部超时(部署值,非 volatile)
|
|
4576
|
+
* @param waitsRebuild 该工具是否会在锁忙时等重建并重试一次
|
|
4577
|
+
* @param rebuildWaitMs 等待重建落定的上限
|
|
4578
|
+
* @returns 交给 `ToolDefinition.timeoutMs` 的毫秒数
|
|
4579
|
+
*/
|
|
4580
|
+
function budgetOf(driven, waitsRebuild, rebuildWaitMs) {
|
|
4581
|
+
return (waitsRebuild ? driven * 2 + rebuildWaitMs : driven) + TOOL_TIMEOUT_MARGIN_MS;
|
|
4582
|
+
}
|
|
4583
|
+
/**
|
|
4584
|
+
* 以 root 为标题的调用态:模型给了 root 就用它,否则回落工具名。
|
|
4585
|
+
*
|
|
4586
|
+
* root 可以省略(缺省=当前会话工作区),而调用态发生在解析之前——这里不猜工作区,
|
|
4587
|
+
* 猜错会让卡片写着一个模型没指定的目录。
|
|
4588
|
+
* @param args - 模型交进来的原始参数
|
|
4589
|
+
* @param toolName - 参数里没有 root 时的回落标题
|
|
4590
|
+
* @returns 卡片标题(永不为空串)
|
|
4591
|
+
*/
|
|
4592
|
+
function rootTitleOf(args, toolName) {
|
|
4593
|
+
const { root } = args;
|
|
4594
|
+
return typeof root === "string" && root.length > 0 ? root : toolName;
|
|
4595
|
+
}
|
|
4596
|
+
/**
|
|
4597
|
+
* 检索类调用态的标题:优先用模型给的检索词,没有就给一句动作说明。
|
|
4598
|
+
*
|
|
4599
|
+
* 只读参数、不看结果:调用态卡片在 `execute` 之前就要画出来,那时还没有命中。
|
|
4600
|
+
* 参数是未经校验的原样 unknown,所以每一格都要先判类型再取——直接把
|
|
4601
|
+
* `args["query"]` 当字符串交给 UI,遇到数组或对象时卡片上会出现 `[object Object]`。
|
|
4602
|
+
* @param args - 模型交进来的原始参数(已由调用点收窄成对象)
|
|
4603
|
+
* @returns 卡片标题(永不为空串)
|
|
4604
|
+
*/
|
|
4605
|
+
function queryTitleOf(args) {
|
|
4606
|
+
const { query, queries, fts, root } = args;
|
|
4607
|
+
if (typeof query === "string" && query.length > 0) return query;
|
|
4608
|
+
if (Array.isArray(queries) && typeof queries[0] === "string" && queries[0].length > 0) return queries[0];
|
|
4609
|
+
if (Array.isArray(fts) && typeof fts[0] === "string" && fts[0].length > 0) return fts[0];
|
|
4610
|
+
return typeof root === "string" && root.length > 0 ? root : "zg_search";
|
|
4611
|
+
}
|
|
4459
4612
|
function define(host, spec) {
|
|
4460
4613
|
const { parameters } = spec;
|
|
4461
4614
|
const required = Array.isArray(parameters["required"]) ? parameters["required"].filter((item) => typeof item === "string") : [];
|
|
@@ -4463,18 +4616,21 @@ function define(host, spec) {
|
|
|
4463
4616
|
name: spec.name,
|
|
4464
4617
|
description: spec.description,
|
|
4465
4618
|
parameters,
|
|
4619
|
+
timeoutMs: spec.timeoutMs,
|
|
4620
|
+
presentCall: (rawArgs) => spec.presentCall(isRecord(rawArgs) ? rawArgs : {}),
|
|
4621
|
+
isConcurrencySafe: () => spec.concurrencySafe,
|
|
4466
4622
|
output: {
|
|
4467
4623
|
schema: TEXT_OUTPUT_SCHEMA,
|
|
4468
4624
|
render: (_args, value) => textBlock(value)
|
|
4469
4625
|
},
|
|
4470
4626
|
execute: async (rawArgs, exec) => {
|
|
4471
4627
|
const messages = spec.messages();
|
|
4472
|
-
if (!isRecord
|
|
4628
|
+
if (!isRecord(rawArgs)) throw new ZgToolError(ZG_TOOL_ERROR_CODES.badArguments, fill(messages.argsMustBeObject, {
|
|
4473
4629
|
name: spec.name,
|
|
4474
4630
|
received: rawArgs === null ? "null" : typeof rawArgs
|
|
4475
4631
|
}));
|
|
4476
4632
|
const missing = required.filter((fieldName) => rawArgs[fieldName] === void 0);
|
|
4477
|
-
if (missing.length > 0) throw new
|
|
4633
|
+
if (missing.length > 0) throw new ZgToolError(ZG_TOOL_ERROR_CODES.badArguments, fill(messages.missingRequiredArgs, {
|
|
4478
4634
|
name: spec.name,
|
|
4479
4635
|
fields: missing.join(", ")
|
|
4480
4636
|
}));
|
|
@@ -4930,17 +5086,17 @@ function daemonFailure(text, messages) {
|
|
|
4930
5086
|
});
|
|
4931
5087
|
const concurrent = classifyConcurrentFailure(text);
|
|
4932
5088
|
if (concurrent?.kind === "lock-busy" && concurrent.rebuild) return new RebuildLockBusyError(failure);
|
|
4933
|
-
if (concurrent?.kind === "lock-busy") return
|
|
4934
|
-
if (concurrent?.kind === "permission-denied") return
|
|
4935
|
-
return new
|
|
5089
|
+
if (concurrent?.kind === "lock-busy") return new ZgToolError(ZG_TOOL_ERROR_CODES.lockBusy, `${fill(messages.lockBusyOtherOperation, { op: concurrent.ownerOperation ?? "unknown" })}\n${failure}`);
|
|
5090
|
+
if (concurrent?.kind === "permission-denied") return new ZgToolError(ZG_TOOL_ERROR_CODES.permissionDenied, `${failure}\n${messages.remoteAuthDenied}`);
|
|
5091
|
+
return new ZgToolError(ZG_TOOL_ERROR_CODES.commandFailed, failure);
|
|
4936
5092
|
}
|
|
4937
5093
|
/** daemon 调用的传输层失败(fetch 层):取消/超时与 CLI lane 同一套归因。 */
|
|
4938
5094
|
function daemonTransportFailure(error, exec, messages, token) {
|
|
4939
|
-
if (!(isRecord
|
|
5095
|
+
if (!(isRecord(error) && error["name"] === "AbortError")) {
|
|
4940
5096
|
const detail = redactToken(errorText(error), token);
|
|
4941
|
-
return new
|
|
5097
|
+
return new ZgToolError(ZG_TOOL_ERROR_CODES.daemonUnavailable, fill(messages.mcpCallFailed, { detail }), { cause: error });
|
|
4942
5098
|
}
|
|
4943
|
-
return new
|
|
5099
|
+
return new ZgToolError(ZG_TOOL_ERROR_CODES.daemonUnavailable, exec.signal.aborted ? messages.abortedFailure : messages.timeoutFailure);
|
|
4944
5100
|
}
|
|
4945
5101
|
/** daemon 成功应答的后处理:截尾(保尾部)与命中摘要,与 CLI lane 同一套路。 */
|
|
4946
5102
|
function daemonSuccessText(text, stdoutMaxBytes, summaryLimit, messages) {
|
|
@@ -4970,7 +5126,7 @@ async function runSearchViaDaemon(runtime, searchArgs, messages, exec, wait) {
|
|
|
4970
5126
|
signal: exec.signal
|
|
4971
5127
|
}));
|
|
4972
5128
|
} catch (error) {
|
|
4973
|
-
const aborted = isRecord
|
|
5129
|
+
const aborted = isRecord(error) && error["name"] === "AbortError";
|
|
4974
5130
|
if (!aborted) runtime.serverGate.invalidate();
|
|
4975
5131
|
throw new DaemonCallFailureError(daemonTransportFailure(error, exec, messages, runtime.daemon.tokenOf()).message, aborted);
|
|
4976
5132
|
}
|
|
@@ -5070,6 +5226,13 @@ function registerSearchTool(runtime, registered) {
|
|
|
5070
5226
|
description: registered.searchToolDescription,
|
|
5071
5227
|
messages: runtime.messages,
|
|
5072
5228
|
parameters: searchToolParameters(registered),
|
|
5229
|
+
concurrencySafe: true,
|
|
5230
|
+
timeoutMs: budgetOf(runtime.config.searchTimeoutMs, true, runtime.config.rebuildWaitMs),
|
|
5231
|
+
presentCall: (args) => ({
|
|
5232
|
+
card: "generic",
|
|
5233
|
+
title: queryTitleOf(args),
|
|
5234
|
+
kind: "search"
|
|
5235
|
+
}),
|
|
5073
5236
|
run: (args, exec, messages) => runSearchTool(runtime, args, exec, messages)
|
|
5074
5237
|
});
|
|
5075
5238
|
}
|
|
@@ -5185,17 +5348,17 @@ async function startBackgroundIndex(runtime, root, indexArgs, messages, claimed)
|
|
|
5185
5348
|
};
|
|
5186
5349
|
if (runtime.jobsOf() === void 0) {
|
|
5187
5350
|
runtime.rebuilds.release(root, claimed);
|
|
5188
|
-
throw new
|
|
5351
|
+
throw new ZgToolError(ZG_TOOL_ERROR_CODES.daemonUnavailable, messages.endpointJobsUnavailable);
|
|
5189
5352
|
}
|
|
5190
5353
|
const spawned = await spawnIndexWrite(routes, messages, indexArgs, readDefaultEmbedding(runtime.config));
|
|
5191
5354
|
if ("error" in spawned) {
|
|
5192
5355
|
runtime.rebuilds.release(root, claimed);
|
|
5193
|
-
throw new
|
|
5356
|
+
throw new ZgToolError(ZG_TOOL_ERROR_CODES.commandFailed, spawned.error);
|
|
5194
5357
|
}
|
|
5195
5358
|
const attached = attachIndexWrite(routes, root, messages, spawned, claimed);
|
|
5196
5359
|
if ("error" in attached) {
|
|
5197
5360
|
runtime.rebuilds.release(root, claimed);
|
|
5198
|
-
throw new
|
|
5361
|
+
throw new ZgToolError(ZG_TOOL_ERROR_CODES.commandFailed, attached.error);
|
|
5199
5362
|
}
|
|
5200
5363
|
runtime.rebuilds.attach(root, attached.jobId, claimed);
|
|
5201
5364
|
return { text: fill(messages.indexBackgroundStarted, {
|
|
@@ -5246,6 +5409,13 @@ function registerIndexTool(runtime, registered) {
|
|
|
5246
5409
|
description: registered.indexToolDescription,
|
|
5247
5410
|
messages: runtime.messages,
|
|
5248
5411
|
parameters: indexToolParameters(registered),
|
|
5412
|
+
concurrencySafe: false,
|
|
5413
|
+
timeoutMs: budgetOf(runtime.config.indexTimeoutMs, false, runtime.config.rebuildWaitMs),
|
|
5414
|
+
presentCall: (args) => ({
|
|
5415
|
+
card: "generic",
|
|
5416
|
+
title: rootTitleOf(args, "zg_index"),
|
|
5417
|
+
kind: "other"
|
|
5418
|
+
}),
|
|
5249
5419
|
run: (args, exec, messages) => runIndexTool(runtime, args, exec, messages)
|
|
5250
5420
|
});
|
|
5251
5421
|
}
|
|
@@ -5317,6 +5487,13 @@ function registerStatusTool(runtime, registered) {
|
|
|
5317
5487
|
}
|
|
5318
5488
|
}
|
|
5319
5489
|
},
|
|
5490
|
+
concurrencySafe: true,
|
|
5491
|
+
timeoutMs: budgetOf(runtime.config.statusTimeoutMs, true, runtime.config.rebuildWaitMs),
|
|
5492
|
+
presentCall: (args) => ({
|
|
5493
|
+
card: "generic",
|
|
5494
|
+
title: rootTitleOf(args, "zg_status"),
|
|
5495
|
+
kind: "read"
|
|
5496
|
+
}),
|
|
5320
5497
|
run: (args, exec, messages) => runStatusTool(runtime, args, exec, messages)
|
|
5321
5498
|
});
|
|
5322
5499
|
}
|
|
@@ -5326,13 +5503,16 @@ function registerZvecTools(runtime, registered) {
|
|
|
5326
5503
|
registerIndexTool(runtime, registered);
|
|
5327
5504
|
registerStatusTool(runtime, registered);
|
|
5328
5505
|
}
|
|
5329
|
-
/** 硬规则段(systemPrompt
|
|
5506
|
+
/** 硬规则段(systemPrompt)+ 规则全文的虚拟 skill。
|
|
5507
|
+
* 常驻的只有摘要(逐条对应「不照做会被门禁拒绝」);全文注册成 skill `zvec-grep`,
|
|
5508
|
+
* 模型按需用 skill 工具加载。拆开的理由与两边各放什么见 lib/skill.ts 的头注释。 */
|
|
5330
5509
|
function registerRoutingSection(host, registered) {
|
|
5331
5510
|
host.systemPrompt.section({
|
|
5332
5511
|
name: ROUTING_NAME,
|
|
5333
5512
|
order: ROUTING_ORDER,
|
|
5334
|
-
text: registered.
|
|
5513
|
+
text: registered.routingSummary
|
|
5335
5514
|
});
|
|
5515
|
+
registerRoutingSkill(host, registered.routingText, registered.skillDescription);
|
|
5336
5516
|
}
|
|
5337
5517
|
/**
|
|
5338
5518
|
* 安全后备 guard(只拦 zg_*)+ search-first 门禁(拦 bash/pwsh 里的 grep/rg
|
|
@@ -5347,7 +5527,7 @@ function registerRoutingSection(host, registered) {
|
|
|
5347
5527
|
*/
|
|
5348
5528
|
/** 该不该为这次调用问一句;不该问就交回 undefined(调用方转交 next())。 */
|
|
5349
5529
|
function explicitRootAsk(execution, ledger, messages, platform) {
|
|
5350
|
-
const raw = (isRecord
|
|
5530
|
+
const raw = (isRecord(execution.arguments) ? execution.arguments : void 0)?.["root"];
|
|
5351
5531
|
let question;
|
|
5352
5532
|
if (typeof raw === "string" && raw.trim().length > 0) {
|
|
5353
5533
|
const decision = judgeRoot(raw, sessionHeaderCwd(execution), messages, ledger, platform);
|
|
@@ -5419,6 +5599,13 @@ function apply(ctx, config) {
|
|
|
5419
5599
|
if (!isZvecGrepHost(ctx)) throw new Error("[zvec-grep] required services (settings/shell/tools/systemPrompt/timer/get) missing");
|
|
5420
5600
|
const host = ctx;
|
|
5421
5601
|
const platform = runtimePlatform();
|
|
5602
|
+
if (!claimInstance({
|
|
5603
|
+
get: host.get,
|
|
5604
|
+
reflect: host.reflect
|
|
5605
|
+
}, INSTANCE_LOCK_KEY)) {
|
|
5606
|
+
console.warn("[zvec-grep] 检测到本插件已在同一作用域内装载:本次装配让路,工具与设置卡由在册的那一份提供。");
|
|
5607
|
+
return;
|
|
5608
|
+
}
|
|
5422
5609
|
configureSettingsPage(host);
|
|
5423
5610
|
const localeMessages = createLocaleMessages(host);
|
|
5424
5611
|
const ledger = createRootLedger(localeMessages(), MAX_LEDGER_ROOTS, Date.now, LEDGER_TTL_MS, platform);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayyuen66/dsh-zvec-grep",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "dsh 工作区语义检索插件(zg):zg_search / zg_index / zg_status + 本地 embedding 设置卡片 + systemPrompt 路由规则 + guard 安全兜底。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cordis",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"registry": "https://registry.npmjs.org"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@jayyuen66/dsh-plugin-shared": "^0.2.
|
|
54
|
+
"@jayyuen66/dsh-plugin-shared": "^0.2.9",
|
|
55
55
|
"zod": "4.6.7"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
"@deepseek-ai/dsh-session-projection": "0.2.2-rc.2",
|
|
83
83
|
"@deepseek-ai/dsh-settings": "0.2.2-rc.2",
|
|
84
84
|
"@deepseek-ai/dsh-shell": "0.2.2-rc.2",
|
|
85
|
+
"@deepseek-ai/dsh-skill": "0.2.2-rc.2",
|
|
85
86
|
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.2",
|
|
86
87
|
"@deepseek-ai/dsh-subprocess-local": "0.2.2-rc.2",
|
|
87
88
|
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.2",
|
|
@@ -109,10 +110,11 @@
|
|
|
109
110
|
"vitest": "5.1.0"
|
|
110
111
|
},
|
|
111
112
|
"peerDependencies": {
|
|
112
|
-
"@deepseek-ai/dsh": "^0.2.2-rc.
|
|
113
|
-
"@deepseek-ai/dsh-
|
|
114
|
-
"@deepseek-ai/dsh-
|
|
115
|
-
"@deepseek-ai/dsh-
|
|
113
|
+
"@deepseek-ai/dsh": "^0.2.2-rc.2",
|
|
114
|
+
"@deepseek-ai/dsh-error": "^0.2.2-rc.2",
|
|
115
|
+
"@deepseek-ai/dsh-output-retention": "^0.2.2-rc.2",
|
|
116
|
+
"@deepseek-ai/dsh-scope": "^0.2.2-rc.2",
|
|
117
|
+
"@deepseek-ai/dsh-typert-protocol": "^0.2.2-rc.2",
|
|
116
118
|
"@deepseek-ai/schemastery": "^3.19.0"
|
|
117
119
|
},
|
|
118
120
|
"peerDependenciesMeta": {
|
|
@@ -122,7 +124,7 @@
|
|
|
122
124
|
},
|
|
123
125
|
"icon": "icon.svg",
|
|
124
126
|
"engines": {
|
|
125
|
-
"dsh": "^0.2.2-rc.
|
|
127
|
+
"dsh": "^0.2.2-rc.2",
|
|
126
128
|
"node": ">=24.9.0"
|
|
127
129
|
},
|
|
128
130
|
"dsh": {
|