@jayyuen66/dsh-zvec-grep 0.1.6 → 0.1.7
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 +36 -0
- package/LICENSE +1 -1
- package/README.md +271 -182
- package/README.zh-CN.md +271 -180
- package/client.js +162 -122
- package/cordis.patch.yml +3 -2
- package/host.js +313 -131
- package/package.json +41 -41
package/client.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// GENERATED by buildClient() in build-client.mjs — edit src/client-entry.ts, then run `node build-client.mjs`.
|
|
2
2
|
window.__ModuleLoader__.load({
|
|
3
|
-
id:
|
|
3
|
+
id: "@jayyuen66/dsh-zvec-grep",
|
|
4
4
|
factory: (require) => {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
'use strict';
|
|
6
|
+
const module = { exports: {} };
|
|
7
|
+
let exports = module.exports;
|
|
7
8
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
9
|
let react = require("react");
|
|
9
|
-
|
|
10
|
+
// lib/embedding-catalog.ts
|
|
10
11
|
/** 默认模型:本地最强(1024 维 / 8192 上下文 / 中英通用),约 640MB 一次性下载。 */
|
|
11
12
|
const DEFAULT_EMBEDDING = "local/qwen3-embedding-0.6b";
|
|
12
13
|
/**
|
|
@@ -81,25 +82,33 @@ const LOCAL_EMBEDDINGS = [
|
|
|
81
82
|
dimension: 768
|
|
82
83
|
}
|
|
83
84
|
];
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return
|
|
85
|
+
// node_modules/@jayyuen66/dsh-plugin-shared/dist/card-diff.js
|
|
86
|
+
function e$1(t, n, r) {
|
|
87
|
+
if (t == null || n == null) return (t ?? null) === (n ?? null);
|
|
88
|
+
if (Object.is(t, n)) return !0;
|
|
89
|
+
if (typeof t != `object` || typeof n != `object`) return !1;
|
|
90
|
+
if (r.get(t) === n) return !0;
|
|
91
|
+
if (r.set(t, n), Array.isArray(t) || Array.isArray(n)) return !Array.isArray(t) || !Array.isArray(n) || t.length !== n.length ? !1 : t.every((t, i) => e$1(t, n[i], r));
|
|
92
|
+
let i = Object.keys(t), a = Object.keys(n);
|
|
93
|
+
return i.length === a.length && i.every((i) => Object.hasOwn(n, i) && e$1(Reflect.get(t, i), Reflect.get(n, i), r));
|
|
90
94
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
function t$1(t, n) {
|
|
96
|
+
let r = [];
|
|
97
|
+
for (let i of Object.keys(t)) e$1(t[i], n[i], /* @__PURE__ */ new WeakMap()) || r.push(i);
|
|
98
|
+
return r;
|
|
99
|
+
}
|
|
100
|
+
// lib/card-draft.ts
|
|
101
|
+
/** 草稿优先取值:touched 有该键(哪怕值是 undefined=待清空)即用草稿。
|
|
102
|
+
* 只判**自有**属性:本函数收任意字段名,`in` 会沿原型链命中 `toString` /
|
|
103
|
+
* `constructor` 这类继承键,把 Object.prototype 的成员当成草稿交出去。 */
|
|
94
104
|
function draftOf(touched, value, field) {
|
|
95
|
-
return field
|
|
105
|
+
return Object.hasOwn(touched, field) ? touched[field] : value[field];
|
|
96
106
|
}
|
|
97
107
|
/** 数值型输入的显示文本:非有限数(含 undefined)回落到默认文案。 */
|
|
98
108
|
function numberText(raw, fallback) {
|
|
99
109
|
return typeof raw === "number" && Number.isFinite(raw) ? String(raw) : fallback;
|
|
100
110
|
}
|
|
101
|
-
|
|
102
|
-
//#region lib/card-logic.ts
|
|
111
|
+
// lib/card-logic.ts
|
|
103
112
|
/**
|
|
104
113
|
* 引导端点交回的守护进程就绪态该显示哪一行。
|
|
105
114
|
*
|
|
@@ -144,28 +153,31 @@ function cardStore(scope) {
|
|
|
144
153
|
}
|
|
145
154
|
};
|
|
146
155
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
156
|
+
/**
|
|
157
|
+
* 三个数值字段的显示值都是「草稿优先 + 默认文案」,且共享同一条清空语义:
|
|
158
|
+
* touched 里显式写了 undefined(用户清空输入)= 待 unset,显示空串;「从没动过、
|
|
159
|
+
* 快照里也没有」不是清空,显示默认文案。判据统一收在这里,与 buildRangeRow /
|
|
160
|
+
* limitDraftOf 的「清空即回『未填』」对齐。
|
|
161
|
+
*/
|
|
162
|
+
function numericFieldDisplay(touched, value, field, fallback) {
|
|
163
|
+
const draft = draftOf(touched, value, field);
|
|
164
|
+
if (draft === void 0) return Object.hasOwn(touched, field) ? "" : fallback;
|
|
165
|
+
return numberText(draft, fallback);
|
|
166
|
+
}
|
|
150
167
|
/** 六个字段的草稿显示值(ZgCard 只渲染这里算出来的东西)。 */
|
|
151
168
|
function draftFields(touched, value) {
|
|
152
169
|
const embedding = draftOf(touched, value, "defaultEmbedding");
|
|
153
170
|
const endpoint = draftOf(touched, value, "hfEndpoint");
|
|
154
171
|
const enforce = draftOf(touched, value, "enforceSearchFirst");
|
|
155
|
-
const limitDraft = draftOf(touched, value, "defaultLimit");
|
|
156
|
-
let limitDisplay = numberText(limitDraft, DEFAULT_LIMIT_TEXT);
|
|
157
|
-
if (limitDraft === void 0) limitDisplay = "defaultLimit" in touched ? "" : DEFAULT_LIMIT_TEXT;
|
|
158
172
|
return {
|
|
159
173
|
embedding: typeof embedding === "string" && embedding.length > 0 ? embedding : DEFAULT_EMBEDDING,
|
|
160
|
-
limitDisplay,
|
|
174
|
+
limitDisplay: numericFieldDisplay(touched, value, "defaultLimit", String(10)),
|
|
161
175
|
hfEndpoint: typeof endpoint === "string" ? endpoint : "",
|
|
162
176
|
enforceSearchFirst: enforce !== false,
|
|
163
|
-
grepBudget:
|
|
164
|
-
unlockWindow:
|
|
177
|
+
grepBudget: numericFieldDisplay(touched, value, "grepBudgetPerSearch", String(3)),
|
|
178
|
+
unlockWindow: numericFieldDisplay(touched, value, "unlockWindowMin", String(10))
|
|
165
179
|
};
|
|
166
180
|
}
|
|
167
|
-
const LIMIT_MIN = 1;
|
|
168
|
-
const LIMIT_MAX = 50;
|
|
169
181
|
function resolveLimitInput(raw, t) {
|
|
170
182
|
const trimmed = raw.trim();
|
|
171
183
|
if (trimmed.length === 0) return { kind: "empty" };
|
|
@@ -173,26 +185,26 @@ function resolveLimitInput(raw, t) {
|
|
|
173
185
|
if (!Number.isSafeInteger(num)) return {
|
|
174
186
|
kind: "invalid",
|
|
175
187
|
hint: t("limitInvalid", {
|
|
176
|
-
min:
|
|
177
|
-
max:
|
|
188
|
+
min: 1,
|
|
189
|
+
max: 50
|
|
178
190
|
})
|
|
179
191
|
};
|
|
180
|
-
if (num <
|
|
192
|
+
if (num < 1) return {
|
|
181
193
|
kind: "clamped",
|
|
182
|
-
value:
|
|
194
|
+
value: 1,
|
|
183
195
|
hint: t("limitClamped", {
|
|
184
|
-
min:
|
|
185
|
-
max:
|
|
186
|
-
value:
|
|
196
|
+
min: 1,
|
|
197
|
+
max: 50,
|
|
198
|
+
value: 1
|
|
187
199
|
})
|
|
188
200
|
};
|
|
189
|
-
if (num >
|
|
201
|
+
if (num > 50) return {
|
|
190
202
|
kind: "clamped",
|
|
191
|
-
value:
|
|
203
|
+
value: 50,
|
|
192
204
|
hint: t("limitClamped", {
|
|
193
|
-
min:
|
|
194
|
-
max:
|
|
195
|
-
value:
|
|
205
|
+
min: 1,
|
|
206
|
+
max: 50,
|
|
207
|
+
value: 50
|
|
196
208
|
})
|
|
197
209
|
};
|
|
198
210
|
return {
|
|
@@ -204,15 +216,18 @@ function limitDraftOf(raw, t) {
|
|
|
204
216
|
const resolution = resolveLimitInput(raw, t);
|
|
205
217
|
if (resolution.kind === "invalid") return {
|
|
206
218
|
draft: void 0,
|
|
207
|
-
error: resolution.hint
|
|
219
|
+
error: resolution.hint,
|
|
220
|
+
hint: null
|
|
208
221
|
};
|
|
209
222
|
if (resolution.kind === "empty") return {
|
|
210
223
|
draft: void 0,
|
|
211
|
-
error: null
|
|
224
|
+
error: null,
|
|
225
|
+
hint: null
|
|
212
226
|
};
|
|
213
227
|
return {
|
|
214
228
|
draft: resolution.value,
|
|
215
|
-
error: null
|
|
229
|
+
error: null,
|
|
230
|
+
hint: resolution.kind === "clamped" ? resolution.hint : null
|
|
216
231
|
};
|
|
217
232
|
}
|
|
218
233
|
/**
|
|
@@ -239,19 +254,18 @@ function parseRebuildPoll(body, t) {
|
|
|
239
254
|
let reason;
|
|
240
255
|
if (status === "killed") reason = t("rebuildKilled");
|
|
241
256
|
else if (status === "failed") reason = t("rebuildFailed");
|
|
242
|
-
else reason = t("rebuildExitCode", { exitCode
|
|
257
|
+
else if (typeof exitCode === "number" && Number.isFinite(exitCode)) reason = t("rebuildExitCode", { exitCode });
|
|
258
|
+
else reason = t("rebuildExitUnknown");
|
|
243
259
|
return {
|
|
244
260
|
phase: "error",
|
|
245
261
|
output: outputText.length > 0 ? `${reason}\n${outputText}` : reason
|
|
246
262
|
};
|
|
247
263
|
}
|
|
248
|
-
|
|
249
|
-
//#region node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
|
|
264
|
+
// node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
|
|
250
265
|
function e(e) {
|
|
251
266
|
return typeof e == `object` && !!e && !Array.isArray(e);
|
|
252
267
|
}
|
|
253
|
-
|
|
254
|
-
//#region src/rebuild-reader.ts
|
|
268
|
+
// src/rebuild-reader.ts
|
|
255
269
|
const REBUILD_NAMESPACE = "zvecGrepRebuild";
|
|
256
270
|
/** 网关给命名空间注册的**服务键**:`remote.<namespace>`。它在 `$mount` 完成之后才存在,
|
|
257
271
|
* 所以只能在挂载后按这个键去读,而不是提前 inject。 */
|
|
@@ -319,59 +333,69 @@ const isRemoteMounter = (value) => e(value) && typeof value["$mount"] === "funct
|
|
|
319
333
|
/** 同上:命名空间服务(挂载之后才有,缺它说明网关没认这枚贡献)。 */
|
|
320
334
|
const isRebuildNamespace = (value) => e(value) && typeof value["roots"] === "function" && typeof value["rebuild"] === "function" && typeof value["status"] === "function";
|
|
321
335
|
/**
|
|
322
|
-
*
|
|
336
|
+
* 线上拒绝(result.ok=false)翻成异常:code 与 message 都来自网关的错误对象。
|
|
337
|
+
* 三个方法同构,收成一个入口——同一份判据,不抄三份。
|
|
338
|
+
*/
|
|
339
|
+
async function unwrapWire(call) {
|
|
340
|
+
const result = await call;
|
|
341
|
+
if (result.ok) return result.value;
|
|
342
|
+
throw new Error(`${result.error.code}: ${result.error.message}`);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* 造出真正的读取器(remote 每次现读 + 挂载只在成功后缓存)。
|
|
323
346
|
* @param ctx - 客户端上下文
|
|
324
|
-
* @param remote - 已核过形状的远程面
|
|
325
347
|
* @returns 读取器
|
|
326
348
|
*/
|
|
327
|
-
function buildRebuildReader(ctx
|
|
349
|
+
function buildRebuildReader(ctx) {
|
|
328
350
|
let mounted;
|
|
329
351
|
const namespaceOf = async () => {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
352
|
+
const mounter = ctx.get?.("remote");
|
|
353
|
+
if (!isRemoteMounter(mounter)) throw new Error("工作区重建读面不可用:宿主网关没有提供 remote 服务");
|
|
354
|
+
try {
|
|
355
|
+
mounted ??= mounter.$mount({
|
|
356
|
+
package: PACKAGE_NAME,
|
|
357
|
+
descriptors: REBUILD_DESCRIPTORS
|
|
358
|
+
});
|
|
359
|
+
await mounted;
|
|
360
|
+
} catch (error) {
|
|
361
|
+
mounted = void 0;
|
|
362
|
+
throw error;
|
|
363
|
+
}
|
|
335
364
|
const namespace = ctx.get?.(REBUILD_SERVICE_KEY, false);
|
|
336
365
|
if (!isRebuildNamespace(namespace)) throw new Error(`${REBUILD_SERVICE_KEY} 未提供:宿主网关没有挂上这枚命名空间`);
|
|
337
366
|
return namespace;
|
|
338
367
|
};
|
|
339
368
|
return {
|
|
340
369
|
async roots() {
|
|
341
|
-
|
|
342
|
-
if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
|
|
343
|
-
return result.value;
|
|
370
|
+
return unwrapWire((await namespaceOf()).roots());
|
|
344
371
|
},
|
|
345
372
|
async rebuild(root) {
|
|
346
|
-
const
|
|
347
|
-
if (
|
|
348
|
-
|
|
349
|
-
return result.value;
|
|
373
|
+
const value = await unwrapWire((await namespaceOf()).rebuild({ root }));
|
|
374
|
+
if (value.ok) return value;
|
|
375
|
+
throw new Error(value.error);
|
|
350
376
|
},
|
|
351
377
|
async status(jobId) {
|
|
352
|
-
const
|
|
353
|
-
if (
|
|
354
|
-
|
|
355
|
-
return { ...result.value };
|
|
378
|
+
const value = await unwrapWire((await namespaceOf()).status({ jobId }));
|
|
379
|
+
if (value.ok) return { ...value };
|
|
380
|
+
throw new Error(value.error);
|
|
356
381
|
}
|
|
357
382
|
};
|
|
358
383
|
}
|
|
359
384
|
/**
|
|
360
|
-
*
|
|
361
|
-
*
|
|
385
|
+
* 造一个「读宿主侧工作区重建」的读取器;**连 ctx.get 面都不在时返回 `undefined`**
|
|
386
|
+
* (卡片照常渲染,点重建时给出错误)。remote 服务是否在场**不在这一步判**:
|
|
387
|
+
* 解析推迟到每次调用(见 buildRebuildReader),apply 期它可能还没注册。
|
|
362
388
|
*
|
|
363
|
-
* `$mount` 是**幂等**的(挂进本 fiber
|
|
364
|
-
*
|
|
389
|
+
* `$mount` 是**幂等**的(挂进本 fiber,随卡片卸载自动撤),成功后缓存那枚 promise:
|
|
390
|
+
* 同一次会话里反复轮询只挂一次;失败则清缓存,下一次调用重新挂。
|
|
365
391
|
*
|
|
366
392
|
* @param ctx - 客户端上下文(只用 `get` 一位)
|
|
367
|
-
* @returns
|
|
393
|
+
* @returns 读取器;ctx 没有 get 面时 `undefined`
|
|
368
394
|
*/
|
|
369
395
|
function createRebuildReader(ctx) {
|
|
370
|
-
|
|
371
|
-
return isRemoteMounter(remote) ? buildRebuildReader(ctx, remote) : void 0;
|
|
396
|
+
return typeof ctx.get === "function" ? buildRebuildReader(ctx) : void 0;
|
|
372
397
|
}
|
|
373
|
-
|
|
374
|
-
//#region src/ui-messages.ts
|
|
398
|
+
// src/ui-messages.ts
|
|
375
399
|
const UI_MESSAGES = {
|
|
376
400
|
zh: {
|
|
377
401
|
cardTitle: "zvec-grep(zg)",
|
|
@@ -386,22 +410,22 @@ const UI_MESSAGES = {
|
|
|
386
410
|
saveRejected: "保存被宿主拒绝(配置校验未通过或写入被跳过),修改未生效",
|
|
387
411
|
embeddingLabel: "默认本地 embedding",
|
|
388
412
|
embeddingHint: "只影响「新建」索引;切换并保存后,已有索引需点下方「重建」重新 embedding",
|
|
389
|
-
limitLabel: "默认每组结果数(
|
|
413
|
+
limitLabel: "默认每组结果数({min}-{max})",
|
|
390
414
|
limitInvalid: "请输入 {min}-{max} 的整数",
|
|
391
415
|
limitClamped: "已钳到 {min}-{max} 范围:{value}",
|
|
392
416
|
endpointLabel: "HuggingFace 镜像地址(可选)",
|
|
393
417
|
endpointHint: "留空走 huggingface.co;国内网络可填 https://modelscope.cn/models 等兼容镜像(仅 llama-cpp 后端生效,如 qwen3)",
|
|
394
418
|
enforceLabel: "强制 search-first(先 zg_search 再 grep/rg)",
|
|
395
419
|
enforceHint: "开启后,已建索引工作区内的 grep/rg 受配额门禁约束:每次成功 zg_search 解锁下方次数的 grep/rg(时效见下),用尽或过期后再次拦截(提高检索覆盖与准确性)",
|
|
396
|
-
budgetLabel: "每次 zg_search 解锁的 grep/rg 次数(
|
|
397
|
-
budgetHint: "配额越小语义检索越频繁、准确性约束越强;清空恢复默认
|
|
420
|
+
budgetLabel: "每次 zg_search 解锁的 grep/rg 次数({min}-{max})",
|
|
421
|
+
budgetHint: "配额越小语义检索越频繁、准确性约束越强;清空恢复默认 {default}",
|
|
398
422
|
budgetInvalid: "解锁次数必须是 {min}-{max} 的整数",
|
|
399
|
-
windowLabel: "解锁时效(分钟,
|
|
400
|
-
windowHint: "超过该时长未再次 zg_search,配额整体过期;清空恢复默认
|
|
423
|
+
windowLabel: "解锁时效(分钟,{min}-{max})",
|
|
424
|
+
windowHint: "超过该时长未再次 zg_search,配额整体过期;清空恢复默认 {default}",
|
|
401
425
|
windowInvalid: "解锁时效必须是 {min}-{max} 的整数",
|
|
402
426
|
rebuildLabel: "工作区重建(切换 embedding 并保存后执行)",
|
|
403
|
-
daemonReadyNote: "
|
|
404
|
-
daemonOfflineNote: "
|
|
427
|
+
daemonReadyNote: "守护进程:就绪(zg server 在跑)。",
|
|
428
|
+
daemonOfflineNote: "守护进程:未就绪。守护进程提供的索引增量刷新、refresh=background 与常驻模型池在缺席时都不可用;需要时在终端执行 `zg server on`。",
|
|
405
429
|
rebuildHint: "以当前默认模型重建:{embedding};等价于 zg index --rebuild。{roots}",
|
|
406
430
|
rootsNoteWith: "候选工作区来自本 daemon 已打开过的会话(服务端白名单)。",
|
|
407
431
|
rootsNoteEmpty: "尚无可选工作区:先在该工作区里开一个会话(任一次工具调用即登记)。",
|
|
@@ -412,6 +436,7 @@ const UI_MESSAGES = {
|
|
|
412
436
|
rebuildKilled: "重建进程被终止",
|
|
413
437
|
rebuildFailed: "重建作业被宿主注册表判定失败(没拿到进程退出码)",
|
|
414
438
|
rebuildExitCode: "重建进程退出码 {exitCode}(zg 未安装/权限不足/沙箱拒绝都会走到这里)",
|
|
439
|
+
rebuildExitUnknown: "重建失败,且没有可读的进程退出码(应答的 status 无法识别)",
|
|
415
440
|
rebuildMissingJobId: "启动重建失败:应答缺 jobId",
|
|
416
441
|
rebuildRootNotAbsolute: "root 必须是绝对路径(以 / 开头)",
|
|
417
442
|
rebuildUnavailable: "宿主没有提供工作区重建读面(未装远程服务)",
|
|
@@ -433,22 +458,22 @@ const UI_MESSAGES = {
|
|
|
433
458
|
saveRejected: "save rejected by host (validation failed or write skipped) — changes not applied",
|
|
434
459
|
embeddingLabel: "Default local embedding",
|
|
435
460
|
embeddingHint: "Affects newly built indexes only; after switching and saving, press Rebuild below to re-embed existing indexes",
|
|
436
|
-
limitLabel: "Default hits per group (
|
|
461
|
+
limitLabel: "Default hits per group ({min}-{max})",
|
|
437
462
|
limitInvalid: "enter an integer between {min} and {max}",
|
|
438
463
|
limitClamped: "clamped into the {min}-{max} range: {value}",
|
|
439
464
|
endpointLabel: "HuggingFace mirror URL (optional)",
|
|
440
465
|
endpointHint: "Leave empty for huggingface.co; on networks that cannot reach HF, fill a compatible mirror such as https://modelscope.cn/models (llama-cpp backends only, e.g. qwen3)",
|
|
441
466
|
enforceLabel: "Enforce search-first (zg_search before grep/rg)",
|
|
442
467
|
enforceHint: "When on, grep/rg inside indexed workspaces is quota-gated: each successful zg_search unlocks the number of grep/rg calls below (valid for the window below), and the gate blocks again once it is spent or expired (better coverage and relevance)",
|
|
443
|
-
budgetLabel: "grep/rg calls unlocked per zg_search (
|
|
444
|
-
budgetHint: "A smaller quota means more semantic searches and a stronger relevance constraint; clear to restore the default
|
|
468
|
+
budgetLabel: "grep/rg calls unlocked per zg_search ({min}-{max})",
|
|
469
|
+
budgetHint: "A smaller quota means more semantic searches and a stronger relevance constraint; clear to restore the default {default}",
|
|
445
470
|
budgetInvalid: "the unlock quota must be an integer between {min} and {max}",
|
|
446
|
-
windowLabel: "Unlock window (minutes,
|
|
447
|
-
windowHint: "Without another zg_search inside this window the whole quota expires; clear to restore the default
|
|
471
|
+
windowLabel: "Unlock window (minutes, {min}-{max})",
|
|
472
|
+
windowHint: "Without another zg_search inside this window the whole quota expires; clear to restore the default {default}",
|
|
448
473
|
windowInvalid: "the unlock window must be an integer between {min} and {max}",
|
|
449
474
|
rebuildLabel: "Workspace rebuild (run after switching embedding and saving)",
|
|
450
|
-
daemonReadyNote: "Daemon: ready
|
|
451
|
-
daemonOfflineNote: "Daemon: not ready —
|
|
475
|
+
daemonReadyNote: "Daemon: ready (zg server is running).",
|
|
476
|
+
daemonOfflineNote: "Daemon: not ready. What the daemon provides — incremental index refresh, refresh=background and the resident embedding model pool — is unavailable while it is absent; run `zg server on` in a terminal when you want it.",
|
|
452
477
|
rebuildHint: "Rebuild with the current default model: {embedding}; same as zg index --rebuild. {roots}",
|
|
453
478
|
rootsNoteWith: "Candidates come from sessions this daemon already opened (server-side whitelist).",
|
|
454
479
|
rootsNoteEmpty: "No workspace to pick yet: open a session in that workspace first (any tool call registers it).",
|
|
@@ -459,6 +484,7 @@ const UI_MESSAGES = {
|
|
|
459
484
|
rebuildKilled: "the rebuild process was terminated",
|
|
460
485
|
rebuildFailed: "the host job registry reported the rebuild as failed (no process exit code)",
|
|
461
486
|
rebuildExitCode: "the rebuild process exited with code {exitCode} (missing zg, insufficient permissions and sandbox denials all land here)",
|
|
487
|
+
rebuildExitUnknown: "the rebuild failed and no process exit code is readable (the response status is unrecognized)",
|
|
462
488
|
rebuildMissingJobId: "failed to start the rebuild: the response has no jobId",
|
|
463
489
|
rebuildRootNotAbsolute: "root must be an absolute path (starting with /)",
|
|
464
490
|
rebuildUnavailable: "the host does not expose the rebuild Remote API",
|
|
@@ -468,8 +494,7 @@ const UI_MESSAGES = {
|
|
|
468
494
|
backendModel2Vec: "model2vec (pure JS worker, lightest)"
|
|
469
495
|
}
|
|
470
496
|
};
|
|
471
|
-
|
|
472
|
-
//#region node_modules/@jayyuen66/dsh-plugin-shared/dist/errors.js
|
|
497
|
+
// node_modules/@jayyuen66/dsh-plugin-shared/dist/errors.js
|
|
473
498
|
function t(e) {
|
|
474
499
|
let t = Object.getOwnPropertyDescriptor(e, `message`);
|
|
475
500
|
return t !== void 0 && `value` in t && typeof t.value == `string` ? t.value : void 0;
|
|
@@ -481,11 +506,11 @@ function n(e, r) {
|
|
|
481
506
|
if (!(e instanceof Error)) {
|
|
482
507
|
if (typeof e == `object` && e) {
|
|
483
508
|
let n = t(e);
|
|
484
|
-
if (n !== void 0) return n;
|
|
509
|
+
if (n !== void 0 && n !== ``) return n;
|
|
485
510
|
}
|
|
486
511
|
return String(e);
|
|
487
512
|
}
|
|
488
|
-
let i = e.message === `` ? e.name : e.message, a = e instanceof AggregateError && e.errors.length > 0 ? ` [${e.errors.map((e) => n(e, r)).join(`; `)}]` : ``, o = e.cause === void 0 || e.cause === null ? `` : n(e.cause, r);
|
|
513
|
+
let i = e.message === `` ? e.name : e.message, a = typeof globalThis.AggregateError == `function` && e instanceof AggregateError && e.errors.length > 0 ? ` [${e.errors.map((e) => n(e, r)).join(`; `)}]` : ``, o = e.cause === void 0 || e.cause === null ? `` : n(e.cause, r);
|
|
489
514
|
return `${i}${a}${o === `` || o === i ? `` : `: ${o}`}`;
|
|
490
515
|
} catch {
|
|
491
516
|
return `<unrenderable value>`;
|
|
@@ -496,8 +521,7 @@ function n(e, r) {
|
|
|
496
521
|
function r(e) {
|
|
497
522
|
return n(e, /* @__PURE__ */ new Set());
|
|
498
523
|
}
|
|
499
|
-
|
|
500
|
-
//#region src/client-entry.ts
|
|
524
|
+
// src/client-entry.ts
|
|
501
525
|
const NS = "zvec-grep";
|
|
502
526
|
/**
|
|
503
527
|
* `plugins.bundle.config` 的 key = **bundle 的 npm 包名**(不是裸条目 id)。
|
|
@@ -518,9 +542,6 @@ const NS = "zvec-grep";
|
|
|
518
542
|
const BUNDLE_PKG = "@jayyuen66/dsh-zvec-grep";
|
|
519
543
|
/** 重建轮询间隔(宿主后台进程,2s 足够跟上 zg 的进度输出)。 */
|
|
520
544
|
const REBUILD_POLL_MS = 2e3;
|
|
521
|
-
/** 解锁配额/时效的合法上限(与 host Config 的 schema 同范围,输入框与提示共用)。 */
|
|
522
|
-
const BUDGET_MAX = 20;
|
|
523
|
-
const WINDOW_MAX = 240;
|
|
524
545
|
const CARD_CSS = [
|
|
525
546
|
".zgc-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}",
|
|
526
547
|
".zgc-card:hover{border-color:var(--dsw-alias-label-dimmed)}",
|
|
@@ -651,7 +672,7 @@ function rangeErrorText(t, key, max) {
|
|
|
651
672
|
});
|
|
652
673
|
}
|
|
653
674
|
/** embedding <select> 的分组候选(逐层构造,避免 createElement 深层嵌套)。 */
|
|
654
|
-
function buildOptionGroups(t, embeddingValue,
|
|
675
|
+
function buildOptionGroups(t, embeddingValue, editable, setField) {
|
|
655
676
|
const groups = [];
|
|
656
677
|
for (const backend of BACKENDS) {
|
|
657
678
|
const options = [];
|
|
@@ -670,7 +691,7 @@ function buildOptionGroups(t, embeddingValue, writable, setField) {
|
|
|
670
691
|
return [(0, react.createElement)("select", {
|
|
671
692
|
className: "zgc-select",
|
|
672
693
|
value: embeddingValue,
|
|
673
|
-
disabled: !
|
|
694
|
+
disabled: !editable,
|
|
674
695
|
onChange: (ev) => {
|
|
675
696
|
setField("defaultEmbedding", ev.target.value);
|
|
676
697
|
}
|
|
@@ -678,26 +699,29 @@ function buildOptionGroups(t, embeddingValue, writable, setField) {
|
|
|
678
699
|
}
|
|
679
700
|
/** embedding 行:本地后端分组的 <select>(候选文本带维度插值)。 */
|
|
680
701
|
function buildEmbeddingRow(deps) {
|
|
681
|
-
const { fields, setField, t
|
|
702
|
+
const { editable, fields, setField, t } = deps;
|
|
682
703
|
const embeddingLabel = (0, react.createElement)("div", { className: "zgc-label" }, t("embeddingLabel"));
|
|
683
704
|
const embeddingHint = (0, react.createElement)("div", { className: "zgc-hint" }, t("embeddingHint"));
|
|
684
|
-
const embeddingSelects = buildOptionGroups(t, fields.embedding,
|
|
705
|
+
const embeddingSelects = buildOptionGroups(t, fields.embedding, editable, setField);
|
|
685
706
|
return (0, react.createElement)("div", { className: "zgc-row" }, embeddingLabel, embeddingHint, embeddingSelects[0]);
|
|
686
707
|
}
|
|
687
708
|
/** defaultLimit 行:数字输入,区间判定在 lib/card-logic.ts 的 limitDraftOf。 */
|
|
688
709
|
function buildLimitRow(deps) {
|
|
689
|
-
const { fields, setField, setSaveError, t
|
|
690
|
-
const limitLabel = (0, react.createElement)("div", { className: "zgc-label" }, t("limitLabel"
|
|
710
|
+
const { editable, fields, setField, setSaveError, t } = deps;
|
|
711
|
+
const limitLabel = (0, react.createElement)("div", { className: "zgc-label" }, t("limitLabel", {
|
|
712
|
+
min: 1,
|
|
713
|
+
max: 50
|
|
714
|
+
}));
|
|
691
715
|
const limitInput = (0, react.createElement)("input", {
|
|
692
716
|
className: "zgc-input",
|
|
693
717
|
type: "number",
|
|
694
718
|
min: 1,
|
|
695
719
|
max: 50,
|
|
696
720
|
value: fields.limitDisplay,
|
|
697
|
-
disabled: !
|
|
721
|
+
disabled: !editable,
|
|
698
722
|
onChange: (ev) => {
|
|
699
723
|
const draft = limitDraftOf(ev.target.value, t);
|
|
700
|
-
setSaveError(draft.error);
|
|
724
|
+
setSaveError(draft.error ?? draft.hint);
|
|
701
725
|
if (draft.error === null) setField("defaultLimit", draft.draft);
|
|
702
726
|
}
|
|
703
727
|
});
|
|
@@ -705,14 +729,14 @@ function buildLimitRow(deps) {
|
|
|
705
729
|
}
|
|
706
730
|
/** hfEndpoint 行:镜像基地址(占位符即 schema 默认的那枚镜像,留空走官方 HF)。 */
|
|
707
731
|
function buildEndpointRow(deps) {
|
|
708
|
-
const { fields, setField, t
|
|
732
|
+
const { editable, fields, setField, t } = deps;
|
|
709
733
|
const endpointLabel = (0, react.createElement)("div", { className: "zgc-label" }, t("endpointLabel"));
|
|
710
734
|
const endpointHint = (0, react.createElement)("div", { className: "zgc-hint" }, t("endpointHint"));
|
|
711
735
|
const endpointInput = (0, react.createElement)("input", {
|
|
712
736
|
className: "zgc-input",
|
|
713
737
|
value: fields.hfEndpoint,
|
|
714
738
|
placeholder: "https://modelscope.cn/models",
|
|
715
|
-
disabled: !
|
|
739
|
+
disabled: !editable,
|
|
716
740
|
onChange: (ev) => {
|
|
717
741
|
setField("hfEndpoint", ev.target.value);
|
|
718
742
|
}
|
|
@@ -721,11 +745,11 @@ function buildEndpointRow(deps) {
|
|
|
721
745
|
}
|
|
722
746
|
/** enforceSearchFirst 行:整行可点的勾选(只读时光标退回 default,与禁用态一致)。 */
|
|
723
747
|
function buildEnforceRow(deps) {
|
|
724
|
-
const { fields, setField, t
|
|
748
|
+
const { editable, fields, setField, t } = deps;
|
|
725
749
|
const enforceCheckbox = (0, react.createElement)("input", {
|
|
726
750
|
type: "checkbox",
|
|
727
751
|
checked: fields.enforceSearchFirst,
|
|
728
|
-
disabled: !
|
|
752
|
+
disabled: !editable,
|
|
729
753
|
onChange: (ev) => {
|
|
730
754
|
setField("enforceSearchFirst", ev.target.checked);
|
|
731
755
|
}
|
|
@@ -735,23 +759,26 @@ function buildEnforceRow(deps) {
|
|
|
735
759
|
display: "flex",
|
|
736
760
|
gap: "8px",
|
|
737
761
|
alignItems: "center",
|
|
738
|
-
cursor:
|
|
762
|
+
cursor: editable ? "pointer" : "default"
|
|
739
763
|
} }, enforceCheckbox, enforceText);
|
|
740
764
|
const enforceHint = (0, react.createElement)("div", { className: "zgc-hint" }, t("enforceHint"));
|
|
741
765
|
return (0, react.createElement)("div", { className: "zgc-row" }, enforceInner, enforceHint);
|
|
742
766
|
}
|
|
743
767
|
/** 配额 / 时效行:区间内落草稿、清空即回「未填」、越界给区间文案并置保存条错误。 */
|
|
744
768
|
function buildRangeRow(deps, spec) {
|
|
745
|
-
const { setField, setSaveError, t
|
|
746
|
-
const label = (0, react.createElement)("div", { className: "zgc-label" }, t(spec.labelKey
|
|
747
|
-
|
|
769
|
+
const { editable, setField, setSaveError, t } = deps;
|
|
770
|
+
const label = (0, react.createElement)("div", { className: "zgc-label" }, t(spec.labelKey, {
|
|
771
|
+
min: 1,
|
|
772
|
+
max: spec.max
|
|
773
|
+
}));
|
|
774
|
+
const hint = (0, react.createElement)("div", { className: "zgc-hint" }, t(spec.hintKey, { default: spec.default }));
|
|
748
775
|
const input = (0, react.createElement)("input", {
|
|
749
776
|
className: "zgc-input",
|
|
750
777
|
type: "number",
|
|
751
778
|
min: 1,
|
|
752
779
|
max: spec.max,
|
|
753
780
|
value: spec.value,
|
|
754
|
-
disabled: !
|
|
781
|
+
disabled: !editable,
|
|
755
782
|
onChange: (ev) => {
|
|
756
783
|
const { value: raw } = ev.target;
|
|
757
784
|
if (raw === "") {
|
|
@@ -837,7 +864,8 @@ function buildCardBody(deps) {
|
|
|
837
864
|
hintKey: "budgetHint",
|
|
838
865
|
field: "grepBudgetPerSearch",
|
|
839
866
|
invalidKey: "budgetInvalid",
|
|
840
|
-
max:
|
|
867
|
+
max: 20,
|
|
868
|
+
default: 3,
|
|
841
869
|
value: fields.grepBudget
|
|
842
870
|
}),
|
|
843
871
|
buildRangeRow(deps, {
|
|
@@ -845,7 +873,8 @@ function buildCardBody(deps) {
|
|
|
845
873
|
hintKey: "windowHint",
|
|
846
874
|
field: "unlockWindowMin",
|
|
847
875
|
invalidKey: "windowInvalid",
|
|
848
|
-
max:
|
|
876
|
+
max: 240,
|
|
877
|
+
default: 10,
|
|
849
878
|
value: fields.unlockWindow
|
|
850
879
|
}),
|
|
851
880
|
(0, react.createElement)(SaveBar, {
|
|
@@ -873,7 +902,7 @@ function pushFieldWrite(ops, key, draft, set) {
|
|
|
873
902
|
else if (key === "grepBudgetPerSearch") ops.push(set("grepBudgetPerSearch", draft));
|
|
874
903
|
else if (key === "unlockWindowMin") ops.push(set("unlockWindowMin", draft));
|
|
875
904
|
}
|
|
876
|
-
/**
|
|
905
|
+
/** 读取器缺席时的可行动文案(只剩 ctx.get 缺席这一档;remote/命名空间的缺席由读取器现抛)。 */
|
|
877
906
|
function requireReader(reader, t) {
|
|
878
907
|
if (reader === void 0) throw new Error(t("rebuildUnavailable"));
|
|
879
908
|
return reader;
|
|
@@ -896,6 +925,9 @@ function useRebuild(t, reader) {
|
|
|
896
925
|
output: ""
|
|
897
926
|
});
|
|
898
927
|
const pollRef = (0, react.useRef)(null);
|
|
928
|
+
const pollingRef = (0, react.useRef)(false);
|
|
929
|
+
const mountedRef = (0, react.useRef)(true);
|
|
930
|
+
const isMounted = () => mountedRef.current;
|
|
899
931
|
function stopPolling() {
|
|
900
932
|
if (pollRef.current !== null) {
|
|
901
933
|
clearInterval(pollRef.current);
|
|
@@ -903,6 +935,7 @@ function useRebuild(t, reader) {
|
|
|
903
935
|
}
|
|
904
936
|
}
|
|
905
937
|
(0, react.useEffect)(() => () => {
|
|
938
|
+
mountedRef.current = false;
|
|
906
939
|
stopPolling();
|
|
907
940
|
}, []);
|
|
908
941
|
/** 拉白名单 + 就绪态。失败**不**改重建面板:面板 idle 时冒一个红字只是噪音,
|
|
@@ -926,19 +959,26 @@ function useRebuild(t, reader) {
|
|
|
926
959
|
})();
|
|
927
960
|
}, [refreshAccess]);
|
|
928
961
|
async function pollStatus(jobId) {
|
|
962
|
+
if (pollingRef.current || !isMounted()) return;
|
|
963
|
+
pollingRef.current = true;
|
|
929
964
|
try {
|
|
930
|
-
const
|
|
965
|
+
const body = await requireReader(reader, t).status(jobId);
|
|
966
|
+
if (!isMounted()) return;
|
|
967
|
+
const poll = parseRebuildPoll(body, t);
|
|
931
968
|
if (poll.phase !== "running") stopPolling();
|
|
932
969
|
setRebuild({
|
|
933
970
|
phase: poll.phase,
|
|
934
971
|
output: poll.output
|
|
935
972
|
});
|
|
936
973
|
} catch (error) {
|
|
974
|
+
if (!isMounted()) return;
|
|
937
975
|
stopPolling();
|
|
938
976
|
setRebuild({
|
|
939
977
|
phase: "error",
|
|
940
978
|
output: r(error)
|
|
941
979
|
});
|
|
980
|
+
} finally {
|
|
981
|
+
pollingRef.current = false;
|
|
942
982
|
}
|
|
943
983
|
}
|
|
944
984
|
/** 发起一次重建;成功后进入轮询。 */
|
|
@@ -993,7 +1033,7 @@ function ZgCard(props) {
|
|
|
993
1033
|
const [saveError, setSaveError] = (0, react.useState)(null);
|
|
994
1034
|
const rebuildView = useRebuild(t, props.rebuildRemote);
|
|
995
1035
|
const fields = draftFields(touched, value);
|
|
996
|
-
const dirty =
|
|
1036
|
+
const dirty = t$1(touched, value).length > 0;
|
|
997
1037
|
const setField = (field, draft) => {
|
|
998
1038
|
setTouched((prev) => ({
|
|
999
1039
|
...prev,
|
|
@@ -1001,7 +1041,7 @@ function ZgCard(props) {
|
|
|
1001
1041
|
}));
|
|
1002
1042
|
};
|
|
1003
1043
|
const save = async () => {
|
|
1004
|
-
const keys =
|
|
1044
|
+
const keys = t$1(touched, value);
|
|
1005
1045
|
if (keys.length === 0) return;
|
|
1006
1046
|
setBusy(true);
|
|
1007
1047
|
setSaveError(null);
|
|
@@ -1035,6 +1075,7 @@ function ZgCard(props) {
|
|
|
1035
1075
|
t,
|
|
1036
1076
|
fields,
|
|
1037
1077
|
writable,
|
|
1078
|
+
editable: writable && !busy,
|
|
1038
1079
|
roots: rebuildView.roots,
|
|
1039
1080
|
serverReady: rebuildView.serverReady,
|
|
1040
1081
|
root: rebuildView.root,
|
|
@@ -1109,7 +1150,6 @@ function apply(ctx) {
|
|
|
1109
1150
|
}, ZgCard);
|
|
1110
1151
|
});
|
|
1111
1152
|
}
|
|
1112
|
-
//#endregion
|
|
1113
1153
|
exports.apply = apply;
|
|
1114
1154
|
exports.cardStore = cardStore;
|
|
1115
1155
|
exports.draftFields = draftFields;
|
package/cordis.patch.yml
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# zvec-grep:工作区语义检索插件(zg)。
|
|
2
2
|
# 3 个工具:zg_search(语义/混合检索,需已建索引)/ zg_index(建/重建/删索引,
|
|
3
|
-
# confirm 强制 true)/ zg_status(索引状态)。后端 zg CLI --mode
|
|
4
|
-
#
|
|
3
|
+
# confirm 强制 true)/ zg_status(索引状态)。后端 zg CLI 缺省 --mode auto
|
|
4
|
+
# (守护进程就绪走 server,缺席落回 direct),经 ctx.shell 调用;root 走
|
|
5
|
+
# workdir/转义位置参数,防注入。
|
|
5
6
|
# systemPrompt 规则段 order 1550 + tools.guard 安全兜底;本地 embedding 设置
|
|
6
7
|
# 卡片(defaultEmbedding 默认 local/qwen3-embedding-0.6b,qwen3 需 node-llama-cpp)。
|
|
7
8
|
# hfEndpoint 默认 https://modelscope.cn/models(国内 HF 不可达,已实测可下载 qwen3)。
|