@jayyuen66/dsh-zvec-grep 0.1.17 → 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 +24 -0
- package/README.md +2 -1
- package/README.zh-CN.md +2 -1
- package/client.js +252 -148
- package/docs/DETAIL.md +1 -1
- package/docs/DETAIL.zh.md +1 -1
- package/host.js +40 -36
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
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). The deviations below are deliberate: version headings carry no release date (publish times are recorded by the registry — `npm view <package> time`), and a release may add sections beyond the standard six, such as `Not changed, deliberately` and `Earlier`.
|
|
4
4
|
|
|
5
|
+
## 0.1.18
|
|
6
|
+
|
|
7
|
+
market 热挂与 bundle 层双路径装载时第二份 `apply` 整份让路(此前第二遍会撞「同名已注册」把 fiber 打成 failed);设置卡接「有字段越界就不许保存」那道门禁;卡片样式改用 shared 的共享 `<style>`;shared 抬到 `^0.2.9`,输入框不再撑出容器、小节内补上纵向间距。工具面与 grep/rg 门禁的行为一字未变。
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **单实例锁**:`apply` 在首道宿主守卫之后用 shared 的 `claimInstance` 抢 `INSTANCE_LOCK_KEY = "@jayyuen66/dsh-zvec-grep/instance"`,抢不到就 `console.warn` 一行「本次装配让路,工具与设置卡由在册的那一份提供」并直接返回。成因是 dshmarket 运行期热装会在 `<profile>/.dsh-market/` 下造一棵它自己的 Include 子树(`mkt-*`,`file://` 直连 `host.js`),与 profile 的 bundle 层解析到同一份模块却各起一个 fiber ⇒ 同一进程里 `apply` 跑两遍,第二遍的三个工具、prompt section 与 Typert Remote 服务注册全部撞名。锁随在册那一份的 fiber 卸载自动释放。
|
|
12
|
+
- **回归测试 `test/instance-lock.test.ts`(6 条)**:空作用域抢到且锁名落进服务表 / 已有一份在册时让路且**不再尝试 provide** / `provide` 抛错时让路、不把异常抛给调用方 / 没有注册口时放行 / `reflect` 在但没有 `provide` 时放行 / 两个不同键互不影响。`test/host.test.ts` 另加一条装配级用例:「第二份装配必须安静让路,绝不能把 fiber 打成 failed」,断言工具数、section 数、Remote 服务三者不变且 `warn` 恰好一次。夹具的 `reflect.provide` 因此从「重复写入覆盖」改成「重复即抛」——真 cordis 的 `Service` 构造就走这里,第二遍若没被锁挡住会当场抛错,而不是静默覆盖。
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- **三处逐字重复收进 shared**:`lib/skill.ts` 的注册正文(取可选 `skills` 服务 → 判形状 → 空正文不注册 → `register`)换成 shared 的 `registerSkill(ctx, spec)`,本文件只剩 `SKILL_NAME` 与把正文收成 spec 的那一层;`lib/messages.ts` 的 `fill()` 换成 shared 的 `fillPlaceholders`;`lib/daemon-client.ts` 的私有 `isRecord` 换成 shared 的 `lib/record`(本包那份少了 `!Array.isArray`,数组会被判成 record —— 这次顺手修掉)。
|
|
17
|
+
- **`fill()` 的缺值语义从「替空串」改成「保留原文」**:漏传或写错占位符时原样留着的 `{xxx}` 一眼可见,比一句悄悄塌成残句的文案好排查。`null` 仍照实渲染成 `"null"`(`exitCode` 这类字段的正常取值)。两条既有断言随之改判。
|
|
18
|
+
- **卡片样式改用 shared 的 `ensureCardUiCss()`**:不再把 `CARD_UI_CSS` 整段拼进本仓的 `<style>`,改为固定 id `dsh-card-ui-css` 的幂等注入 + 引用计数。
|
|
19
|
+
- **运行时依赖 shared 抬到 `^0.2.9`**。
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- **越界数字草稿会被静默丢掉**:`NumberField` 对越界草稿**不调 `onChange`**,于是它根本不进 `touched`。三个数字字段(`defaultLimit` / `grepBudgetPerSearch` / `unlockWindowMin`)现在都接 `onInvalidChange` 上报,卡片据此灰掉保存并在保存条上点名「有字段超出范围,先修正或撤销后再保存。」(`src/ui-messages.ts` 的 `invalidFields`);`resetToken` 在保存/撤销后把框里的非法草稿清回已提交值。
|
|
24
|
+
- **越界时连撤销都点不动**:上一版把「有未保存改动」与「有越界字段」混成保存条的一个 `disabled`。现在 `SaveBar` 分开算:保存被 `blocked` 拦下,撤销保持可点。
|
|
25
|
+
- **「已修改 N 项」把越界字段算重**:一个字段先写进合法草稿(进 `touched`)再改成越界草稿时,草稿差异与越界集各算一次。现在按字段名去重(`InvalidFields.fields`),一格只算一项。
|
|
26
|
+
- **输入控件撑出容器**(shared 侧):`.dsu-form` 整棵子树统一 `border-box`,否则 `.dsu-input` 的 `width:100%` 会连同左右 padding 一起撑出容器 26px。
|
|
27
|
+
- **小节内相邻元素间距为 0**(shared 侧):`.dsu-form .dsu-section>*+*` 给 10px,`.dsu-sectionHint` 4px,`.dsu-field` 之间仍 0。
|
|
28
|
+
|
|
5
29
|
## 0.1.17
|
|
6
30
|
|
|
7
31
|
检索规则从常驻提示词搬进了按需加载的虚拟 skill;工具结果带上可判的错误码与调用态卡片;三个工具各声明自己的墙钟。工具面与 grep/rg 门禁的行为一字未变。
|
package/README.md
CHANGED
|
@@ -108,6 +108,7 @@ If your profile pins `@jayyuen66/dsh-plugin-shared` with a pnpm `overrides` entr
|
|
|
108
108
|
|
|
109
109
|
- `dsh.bundle.patch` points at `cordis.patch.yml`, whose `insert:` block carries a single `- id: zvec-grep` entry with `name: "@jayyuen66/dsh-zvec-grep"` - the **bare package name** is what makes the host scan the client half. The card components are bundled into `client.js` (only `react` / `zod` stay external to the host's module table), so the card does not depend on a second package being loaded. Bundle installation goes through pnpm (>= 12.3.0).
|
|
110
110
|
- A missing injected surface keeps cordis from activating the entry (startup diagnostic: `pending (waiting for service: …)`); a malformed ctx throws `required services … missing` from apply.
|
|
111
|
+
- The two delivery paths - a dshmarket hot-mounted `mkt-*` include and the bundle layer - can resolve to the same module and run `apply` twice in one scope. The second assembly claims a private instance service and stands down with a single `console.warn`; the tools, the prompt section and the `zvecGrepRebuild` namespace stay with the registered copy, and the lock is released when that fiber unloads.
|
|
111
112
|
- The card is registered in the `plugins.bundle.config` slot keyed by the **bundle package name**; the settings namespace and `configForms` reads stay the bare entry id `zvec-grep` (implicit registration by entry id).
|
|
112
113
|
- The rebuild read surface is installed on the apply fiber - no `webServer` dependency, no child fiber. On a TUI host the service still registers; the card simply has nowhere to render.
|
|
113
114
|
- The status poll is the client's own timer (2000 ms), not a server push; every read answers a result object, never a thrown error.
|
|
@@ -162,7 +163,7 @@ Output is plain text; timeouts 5 min (search) / 10 min (index) / 60 s (status);
|
|
|
162
163
|
|
|
163
164
|
## <img src="https://api.iconify.design/lucide/sliders-horizontal.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Settings
|
|
164
165
|
|
|
165
|
-
Namespace `zvec-grep` equals the settings entry id; the schema has 18 fields with built-in defaults, 7 of them volatile and on the card.
|
|
166
|
+
Namespace `zvec-grep` equals the settings entry id; the schema has 18 fields with built-in defaults, 7 of them volatile and on the card. An out-of-range numeric draft never reaches `onChange`, so **Save** is blocked while any numeric field is invalid; **Revert** stays enabled, and the save bar names the reason.
|
|
166
167
|
|
|
167
168
|
| Field | Type | Default | Purpose |
|
|
168
169
|
| --- | --- | --- | --- |
|
package/README.zh-CN.md
CHANGED
|
@@ -108,6 +108,7 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
|
108
108
|
|
|
109
109
|
- `dsh.bundle.patch` 指向 `cordis.patch.yml`,其 `insert:` 块只有一条 `- id: zvec-grep`、`name: "@jayyuen66/dsh-zvec-grep"`——让宿主扫描 client 半的是**不带子路径的包名**。卡片组件直接打进 `client.js`(只有 `react` / `zod` 外置给宿主模块表),卡片不依赖第二份包被装载。bundle 安装走 pnpm(>= 12.3.0)。
|
|
110
110
|
- 缺任一注入宿主服务,cordis 就不激活本条目(启动诊断点名 `pending (waiting for service: …)`);ctx 形状不对时 apply 抛 `required services … missing`。
|
|
111
|
+
- 两条装载路径——dshmarket 热挂的 `mkt-*` 子树与 bundle 层——可能解析到同一份模块而在同一作用域里跑两遍 `apply`。第二份会抢一把私有实例服务锁并安静让路(只 `console.warn` 一行);三个工具、提示词段与 `zvecGrepRebuild` 命名空间仍由在册那一份提供,那一份 fiber 卸载时锁自动释放。
|
|
111
112
|
- 卡片注册在 `plugins.bundle.config` 槽的 **bundle 包名**键下;设置命名空间与 `configForms` 的读仍走裸条目 id `zvec-grep`(按条目 id 隐式注册)。
|
|
112
113
|
- 重建读取接口注册在 apply fiber 上——不声明 `webServer`、没有子 fiber。TUI 宿主上服务照常注册,只是卡片没有地方渲染。
|
|
113
114
|
- 状态轮询是客户端自己的定时器(2000 ms),不是服务端推送;每次读都以结果对象回答,不抛错。
|
|
@@ -162,7 +163,7 @@ dsh plugin --profile web add @jayyuen66/dsh-zvec-grep
|
|
|
162
163
|
|
|
163
164
|
## <img src="https://api.iconify.design/lucide/sliders-horizontal.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> 设置项
|
|
164
165
|
|
|
165
|
-
命名空间 `zvec-grep` 即设置条目 id;schema 共 18 个字段、逐字段带内置默认,其中卡上那 7 枚标 `.volatile()
|
|
166
|
+
命名空间 `zvec-grep` 即设置条目 id;schema 共 18 个字段、逐字段带内置默认,其中卡上那 7 枚标 `.volatile()`。越界数字草稿不会进 `onChange`,所以只要有数字字段越界,**保存**就被禁用(**撤销**保持可点),保存条同时点名原因。
|
|
166
167
|
|
|
167
168
|
| 字段 | 类型 | 默认值 | 作用 |
|
|
168
169
|
| --- | --- | --- | --- |
|
package/client.js
CHANGED
|
@@ -88,10 +88,15 @@ const REMOTE_EMBEDDING_CATALOG = Object.freeze([
|
|
|
88
88
|
dimension: 1024
|
|
89
89
|
}
|
|
90
90
|
].map((entry) => Object.freeze(entry)));
|
|
91
|
-
// node_modules/@jayyuen66/dsh-plugin-shared/dist/card-ui-
|
|
91
|
+
// node_modules/@jayyuen66/dsh-plugin-shared/dist/card-ui-ikodobgI.js
|
|
92
92
|
const c = `
|
|
93
93
|
.dsu-form{display:flex;flex-direction:column}
|
|
94
|
+
.dsu-form,.dsu-form *,.dsu-form *::before,.dsu-form *::after{box-sizing:border-box}
|
|
94
95
|
.dsu-section{margin-top:24px;padding-top:24px;border-top:.5px solid var(--dsw-alias-border-l1)}
|
|
96
|
+
.dsu-form .dsu-section>*+*{margin-top:10px}
|
|
97
|
+
.dsu-form .dsu-section>.dsu-sectionHint{margin-top:4px}
|
|
98
|
+
.dsu-form .dsu-section>*+.dsu-field{margin-top:0}
|
|
99
|
+
.dsu-form .dsu-section>.dsu-savebar{margin-top:24px}
|
|
95
100
|
.dsu-form>.dsu-section:first-child{margin-top:0;padding-top:0;border-top:0}
|
|
96
101
|
.dsu-sectionTitle{margin:0;font-size:15px;font-weight:600;line-height:1.4;color:var(--dsw-alias-label-primary)}
|
|
97
102
|
.dsu-sectionHint{margin:4px 0 0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
@@ -142,8 +147,8 @@ const c = `
|
|
|
142
147
|
.dsu-optionGroup{padding:6px 10px 2px;font-size:11px;font-weight:600;color:var(--dsw-alias-label-tertiary)}
|
|
143
148
|
.dsu-check{opacity:0;flex:none}
|
|
144
149
|
.dsu-option[aria-selected="true"] .dsu-check{opacity:1}
|
|
145
|
-
.dsu-savebar{display:flex;align-items:center;gap:8px;padding:12px 0;margin-top:24px;border-top:.5px solid var(--dsw-alias-border-l2)
|
|
146
|
-
.dsu-savebar[data-dirty="true"]{position:sticky;bottom:0;z-index:2;box-shadow:0 -12px 24px rgb(0 0 0 / 35%)}
|
|
150
|
+
.dsu-savebar{display:flex;align-items:center;gap:8px;padding:12px 0;margin-top:24px;border-top:.5px solid var(--dsw-alias-border-l2)}
|
|
151
|
+
.dsu-savebar[data-dirty="true"]{position:sticky;bottom:0;z-index:2;background:var(--dsw-alias-bg-base);box-shadow:0 -12px 24px rgb(0 0 0 / 35%)}
|
|
147
152
|
.dsu-btn{appearance:none;border:.5px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:1.5;border-radius:var(--dsw-radius-md);padding:5px 14px;cursor:pointer;transition:background-color .12s,border-color .12s,color .12s,filter .12s}
|
|
148
153
|
.dsu-btn:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-border-l3)}
|
|
149
154
|
.dsu-btn:active:not(:disabled){background:var(--dsw-alias-bg-layer-1)}
|
|
@@ -168,61 +173,126 @@ const c = `
|
|
|
168
173
|
.dsu-switch,.dsu-knob,.dsu-chevron,.dsu-btn{transition:none}
|
|
169
174
|
}
|
|
170
175
|
`;
|
|
171
|
-
|
|
176
|
+
const l = `dsh-card-ui-css`;
|
|
177
|
+
const u = Symbol.for(`@jayyuen66/dsh-plugin-shared/card-ui-css/refs`);
|
|
178
|
+
function d() {}
|
|
179
|
+
function f(e) {
|
|
180
|
+
if (typeof e != `object` || !e) return !1;
|
|
181
|
+
let t = Reflect.get(e, `head`);
|
|
182
|
+
return typeof Reflect.get(e, `querySelector`) == `function` && typeof Reflect.get(e, `createElement`) == `function` && typeof t == `object` && !!t && typeof Reflect.get(t, `append`) == `function`;
|
|
183
|
+
}
|
|
184
|
+
function p(e) {
|
|
185
|
+
if (e !== void 0) return f(e) ? e : void 0;
|
|
186
|
+
let t = typeof document > `u` ? void 0 : document;
|
|
187
|
+
return f(t) ? t : void 0;
|
|
188
|
+
}
|
|
189
|
+
function m(e) {
|
|
190
|
+
return typeof Reflect.get(e, `remove`) == `function`;
|
|
191
|
+
}
|
|
192
|
+
function h(e) {
|
|
193
|
+
let t = Reflect.get(e, u);
|
|
194
|
+
return typeof t == `number` && t > 0 ? t : 0;
|
|
195
|
+
}
|
|
196
|
+
function g(e) {
|
|
197
|
+
let t = e.createElement(`style`);
|
|
198
|
+
return t.id = l, t.textContent = c, e.head.append(t), t;
|
|
199
|
+
}
|
|
200
|
+
function _(e) {
|
|
201
|
+
let t = !1;
|
|
202
|
+
return () => {
|
|
203
|
+
if (t) return;
|
|
204
|
+
t = !0;
|
|
205
|
+
let n = h(e);
|
|
206
|
+
n <= 1 ? (Reflect.deleteProperty(e, u), e.remove()) : Reflect.set(e, u, n - 1);
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function v(e) {
|
|
210
|
+
let t = p(e);
|
|
211
|
+
if (t === void 0) return d;
|
|
212
|
+
let n = t.querySelector(`#${l}`);
|
|
213
|
+
if (n != null) {
|
|
214
|
+
if (typeof n != `object` || !m(n)) return d;
|
|
215
|
+
let e = h(n);
|
|
216
|
+
return e === 0 ? d : (Reflect.set(n, u, e + 1), _(n));
|
|
217
|
+
}
|
|
218
|
+
let r = g(t);
|
|
219
|
+
return Reflect.set(r, u, 1), _(r);
|
|
220
|
+
}
|
|
221
|
+
function y(e, t = 30) {
|
|
172
222
|
return e.length <= t ? { hint: e } : { detail: e };
|
|
173
223
|
}
|
|
174
|
-
function
|
|
224
|
+
function b(e, t, n) {
|
|
225
|
+
if (e.has(t) === n) return e;
|
|
226
|
+
let r = new Set(e);
|
|
227
|
+
return n ? r.add(t) : r.delete(t), r;
|
|
228
|
+
}
|
|
229
|
+
function x() {
|
|
230
|
+
let [e, n] = (0, react.useState)(() => /* @__PURE__ */ new Set()), [r, i] = (0, react.useState)(0), a = (0, react.useCallback)((e, t) => {
|
|
231
|
+
n((n) => b(n, e, t));
|
|
232
|
+
}, []), o = (0, react.useCallback)(() => {
|
|
233
|
+
n(/* @__PURE__ */ new Set()), i((e) => e + 1);
|
|
234
|
+
}, []);
|
|
235
|
+
return {
|
|
236
|
+
blocked: e.size > 0,
|
|
237
|
+
fields: e,
|
|
238
|
+
count: e.size,
|
|
239
|
+
resetToken: r,
|
|
240
|
+
reportInvalid: a,
|
|
241
|
+
clear: o
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function S(t) {
|
|
175
245
|
return (0, react.createElement)(`div`, { className: `dsu-form` }, t.children);
|
|
176
246
|
}
|
|
177
|
-
function
|
|
247
|
+
function C(t) {
|
|
178
248
|
return (0, react.createElement)(`section`, { className: `dsu-section` }, (0, react.createElement)(`h2`, { className: `dsu-sectionTitle` }, t.title), t.hint === void 0 ? null : (0, react.createElement)(`p`, { className: `dsu-sectionHint` }, t.hint), t.children);
|
|
179
249
|
}
|
|
180
|
-
function
|
|
250
|
+
function E() {
|
|
181
251
|
return `happyDOM` in globalThis ? !1 : typeof CSS < `u` && typeof CSS.supports == `function` && CSS.supports(`position-area: block-end`);
|
|
182
252
|
}
|
|
183
|
-
function
|
|
253
|
+
function D(e, t) {
|
|
184
254
|
let n = Math.abs(t.left - e.left) <= 2, r = Math.abs(t.right - e.right) <= 2;
|
|
185
255
|
if (!n && !r) return !0;
|
|
186
256
|
let i = t.top >= e.bottom - 2, a = t.bottom <= e.top + 2;
|
|
187
257
|
return !i && !a;
|
|
188
258
|
}
|
|
189
|
-
function
|
|
190
|
-
let c = (0, react.useId)(), l = `--dsu-tip-${c.replaceAll(/[^a-zA-Z0-9]/gu, ``)}`, [u, d] = (0, react.useState)(!1), f = (0, react.useRef)(!1), p = (0, react.useRef)(!1),
|
|
191
|
-
|
|
192
|
-
}, []),
|
|
193
|
-
let e =
|
|
259
|
+
function O(a) {
|
|
260
|
+
let c = (0, react.useId)(), l = `--dsu-tip-${c.replaceAll(/[^a-zA-Z0-9]/gu, ``)}`, [u, d] = (0, react.useState)(!1), f = (0, react.useRef)(!1), p = (0, react.useRef)(!1), m = (0, react.useRef)(!1), h = (0, react.useRef)(null), g = (0, react.useRef)(null), _ = (0, react.useRef)(null), v = (0, react.useRef)(null), y = (0, react.useCallback)(() => {
|
|
261
|
+
v.current !== null && (clearTimeout(v.current), v.current = null);
|
|
262
|
+
}, []), b = (0, react.useCallback)(() => {
|
|
263
|
+
let e = g.current, t = _.current;
|
|
194
264
|
/* v8 ignore next 3 -- place 只在 open 的 layout effect 与挂载期监听器里调用;refs 为空只可能是卸载竞态 */
|
|
195
265
|
if (e === null || t === null) return;
|
|
196
|
-
let n =
|
|
197
|
-
if (n && !
|
|
266
|
+
let n = E() && t.style.positionArea !== `none`, r = e.getBoundingClientRect();
|
|
267
|
+
if (n && !D(r, t.getBoundingClientRect())) return;
|
|
198
268
|
n && (t.style.positionArea = `none`), t.style.marginTop = `0px`;
|
|
199
269
|
let i = t.offsetWidth, a = t.offsetHeight, { left: o } = r, s = r.bottom + 8;
|
|
200
270
|
s + a > window.innerHeight - 8 && (s = r.top - a - 8), o + i > window.innerWidth - 8 && (o = window.innerWidth - i - 8);
|
|
201
271
|
let c = Math.max(8, window.innerWidth - i - 8), l = Math.max(8, window.innerHeight - a - 8);
|
|
202
272
|
t.style.left = `${Math.min(Math.max(8, o), c)}px`, t.style.top = `${Math.min(Math.max(8, s), l)}px`;
|
|
203
|
-
}, []),
|
|
204
|
-
|
|
205
|
-
}, [
|
|
206
|
-
|
|
207
|
-
}, [
|
|
208
|
-
|
|
273
|
+
}, []), x = (0, react.useCallback)(() => {
|
|
274
|
+
y(), m.current = !1, d(!1);
|
|
275
|
+
}, [y]), S = (0, react.useCallback)(() => {
|
|
276
|
+
y(), d(!0);
|
|
277
|
+
}, [y]), C = (0, react.useCallback)(() => {
|
|
278
|
+
y(), f.current || p.current || m.current || (v.current = setTimeout(() => {
|
|
209
279
|
/* v8 ignore next 3 -- 任何重新进入/钉住都会 cancelHide;这次复查只防未来的异步路径 */
|
|
210
|
-
|
|
280
|
+
v.current = null, f.current || p.current || m.current || d(!1);
|
|
211
281
|
}, 120));
|
|
212
|
-
}, [
|
|
213
|
-
|
|
282
|
+
}, [y]), w = (0, react.useCallback)((e) => {
|
|
283
|
+
m.current = e;
|
|
214
284
|
}, []);
|
|
215
285
|
(0, react.useLayoutEffect)(() => {
|
|
216
286
|
if (!u) return () => {};
|
|
217
|
-
|
|
287
|
+
b();
|
|
218
288
|
let e = (e) => {
|
|
219
289
|
let { target: t } = e;
|
|
220
|
-
t instanceof Node &&
|
|
290
|
+
t instanceof Node && _.current?.contains(t) === !0 || (m.current ? b() : x());
|
|
221
291
|
}, t = () => {
|
|
222
|
-
|
|
292
|
+
b();
|
|
223
293
|
}, n = (e) => {
|
|
224
294
|
let t = e.target;
|
|
225
|
-
|
|
295
|
+
h.current?.contains(t) !== !0 && x();
|
|
226
296
|
};
|
|
227
297
|
return document.addEventListener(`pointerdown`, n, !0), window.addEventListener(`scroll`, e, !0), window.addEventListener(`resize`, t), () => {
|
|
228
298
|
document.removeEventListener(`pointerdown`, n, !0), window.removeEventListener(`scroll`, e, !0), window.removeEventListener(`resize`, t);
|
|
@@ -230,19 +300,19 @@ function g(a) {
|
|
|
230
300
|
}, [
|
|
231
301
|
u,
|
|
232
302
|
a.detail,
|
|
233
|
-
|
|
234
|
-
|
|
303
|
+
b,
|
|
304
|
+
x
|
|
235
305
|
]), (0, react.useEffect)(() => {
|
|
236
306
|
if (!u) return () => {};
|
|
237
307
|
let e = (e) => {
|
|
238
|
-
e.key === `Escape` &&
|
|
308
|
+
e.key === `Escape` && x();
|
|
239
309
|
};
|
|
240
310
|
return document.addEventListener(`keydown`, e), () => {
|
|
241
311
|
document.removeEventListener(`keydown`, e);
|
|
242
312
|
};
|
|
243
|
-
}, [u,
|
|
244
|
-
let
|
|
245
|
-
ref:
|
|
313
|
+
}, [u, x]), (0, react.useEffect)(() => y, [y]);
|
|
314
|
+
let T = (0, react.createElement)(`button`, {
|
|
315
|
+
ref: g,
|
|
246
316
|
type: `button`,
|
|
247
317
|
className: `dsu-helpBtn`,
|
|
248
318
|
style: { anchorName: l },
|
|
@@ -250,7 +320,7 @@ function g(a) {
|
|
|
250
320
|
"aria-expanded": u,
|
|
251
321
|
"aria-controls": c,
|
|
252
322
|
onClick: () => {
|
|
253
|
-
|
|
323
|
+
m.current ? x() : (w(!0), S());
|
|
254
324
|
}
|
|
255
325
|
}, (0, react.createElement)(`svg`, {
|
|
256
326
|
width: 12,
|
|
@@ -275,7 +345,7 @@ function g(a) {
|
|
|
275
345
|
r: .8,
|
|
276
346
|
fill: `currentColor`
|
|
277
347
|
}))), O = (0, react.createElement)(`div`, {
|
|
278
|
-
ref:
|
|
348
|
+
ref: _,
|
|
279
349
|
id: c,
|
|
280
350
|
role: `tooltip`,
|
|
281
351
|
className: `dsu-tip`,
|
|
@@ -286,37 +356,37 @@ function g(a) {
|
|
|
286
356
|
hidden: !u
|
|
287
357
|
}, a.detail), k = a.showLabel === !1 ? null : (0, react.createElement)(`span`, { className: `dsu-label${a.compact === !0 ? ` dsu-labelMono` : ``}` }, a.label);
|
|
288
358
|
return (0, react.createElement)(`span`, {
|
|
289
|
-
ref:
|
|
359
|
+
ref: h,
|
|
290
360
|
className: `dsu-help`,
|
|
291
361
|
onMouseEnter: () => {
|
|
292
|
-
f.current = !0,
|
|
362
|
+
f.current = !0, S();
|
|
293
363
|
},
|
|
294
364
|
onMouseLeave: () => {
|
|
295
|
-
f.current = !1,
|
|
365
|
+
f.current = !1, C();
|
|
296
366
|
},
|
|
297
367
|
onFocus: () => {
|
|
298
|
-
p.current = !0,
|
|
368
|
+
p.current = !0, S();
|
|
299
369
|
},
|
|
300
370
|
onBlur: (e) => {
|
|
301
371
|
let t = e.relatedTarget;
|
|
302
|
-
t instanceof Node && e.currentTarget.contains(t) || (p.current = !1,
|
|
372
|
+
t instanceof Node && e.currentTarget.contains(t) || (p.current = !1, C());
|
|
303
373
|
}
|
|
304
|
-
}, k,
|
|
374
|
+
}, k, T, O);
|
|
305
375
|
}
|
|
306
|
-
function
|
|
376
|
+
function k(t) {
|
|
307
377
|
let n = `dsu-label${t.compact === !0 ? ` dsu-labelMono` : ``}`, r = t.controlId === void 0 ? (0, react.createElement)(`span`, { className: n }, t.label) : (0, react.createElement)(`label`, {
|
|
308
378
|
className: n,
|
|
309
379
|
htmlFor: t.controlId
|
|
310
380
|
}, t.label);
|
|
311
|
-
return (0, react.createElement)(`div`, { className: `dsu-labelRow` }, r, t.detail === void 0 ? null : (0, react.createElement)(
|
|
381
|
+
return (0, react.createElement)(`div`, { className: `dsu-labelRow` }, r, t.detail === void 0 ? null : (0, react.createElement)(O, {
|
|
312
382
|
label: t.label,
|
|
313
383
|
detail: t.detail,
|
|
314
384
|
showLabel: !1
|
|
315
385
|
}));
|
|
316
386
|
}
|
|
317
|
-
function
|
|
387
|
+
function A(t) {
|
|
318
388
|
let n = t.controlId === void 0 ? void 0 : `${t.controlId}-hint`;
|
|
319
|
-
return (0, react.createElement)(`div`, { className: `dsu-field${t.wide === !0 ? ` dsu-fieldWide` : ``}` }, (0, react.createElement)(`div`, { className: `dsu-fieldMeta` }, (0, react.createElement)(
|
|
389
|
+
return (0, react.createElement)(`div`, { className: `dsu-field${t.wide === !0 ? ` dsu-fieldWide` : ``}` }, (0, react.createElement)(`div`, { className: `dsu-fieldMeta` }, (0, react.createElement)(k, {
|
|
320
390
|
label: t.label,
|
|
321
391
|
detail: t.detail,
|
|
322
392
|
compact: t.compact,
|
|
@@ -326,9 +396,9 @@ function v(t) {
|
|
|
326
396
|
id: n
|
|
327
397
|
}, t.hint)), (0, react.createElement)(`div`, { className: `dsu-control` }, t.children));
|
|
328
398
|
}
|
|
329
|
-
function
|
|
399
|
+
function j(t) {
|
|
330
400
|
let n = (0, react.useId)(), i = t.hint === void 0 ? void 0 : `${n}-hint`;
|
|
331
|
-
return (0, react.createElement)(
|
|
401
|
+
return (0, react.createElement)(A, {
|
|
332
402
|
...t,
|
|
333
403
|
controlId: n
|
|
334
404
|
}, (0, react.createElement)(`button`, {
|
|
@@ -345,57 +415,67 @@ function y(t) {
|
|
|
345
415
|
}
|
|
346
416
|
}, (0, react.createElement)(`span`, { className: `dsu-knob` })));
|
|
347
417
|
}
|
|
348
|
-
function
|
|
349
|
-
let i = typeof t.value == `number` && Number.isFinite(t.value) ? String(t.value) : ``, [a, c] = (0, react.useState)(i), [l, u] = (0, react.useState)(!1), [d, f] = (0, react.useState)(!1), p = (0, react.useRef)(void 0), m = (0, react.
|
|
418
|
+
function M(t) {
|
|
419
|
+
let i = typeof t.value == `number` && Number.isFinite(t.value) ? String(t.value) : ``, [a, c] = (0, react.useState)(i), [l, u] = (0, react.useState)(!1), [d, f] = (0, react.useState)(!1), p = (0, react.useRef)(void 0), m = (0, react.useRef)(t.resetToken), h = (0, react.useRef)(t.onInvalidChange), g = (0, react.useId)(), _ = (0, react.useId)(), v = t.hint === void 0 ? void 0 : `${g}-hint`, y = l && d, b = [v, y ? _ : void 0].filter((e) => e !== void 0), x = b.length === 0 ? void 0 : b.join(` `);
|
|
350
420
|
(0, react.useEffect)(() => {
|
|
421
|
+
h.current = t.onInvalidChange;
|
|
422
|
+
}, [t.onInvalidChange]), (0, react.useEffect)(() => {
|
|
423
|
+
h.current?.(l);
|
|
424
|
+
}, [l]), (0, react.useEffect)(() => {
|
|
425
|
+
m.current !== t.resetToken && (m.current = t.resetToken, p.current = t.value, c(i), u(!1), f(!1));
|
|
426
|
+
}, [
|
|
427
|
+
t.resetToken,
|
|
428
|
+
t.value,
|
|
429
|
+
i
|
|
430
|
+
]), (0, react.useEffect)(() => {
|
|
351
431
|
t.value !== p.current && (p.current = t.value, c(i), u(!1), f(!1));
|
|
352
432
|
}, [t.value, i]);
|
|
353
|
-
let
|
|
433
|
+
let S = (e) => {
|
|
354
434
|
let n = t.min ?? -1 / 0, r = t.max ?? 1 / 0;
|
|
355
435
|
if (!Number.isFinite(e) || e < n || e > r) return !1;
|
|
356
436
|
let { step: i } = t;
|
|
357
437
|
if (i === void 0 || i <= 0) return !0;
|
|
358
438
|
let a = (e - (t.min ?? 0)) / i;
|
|
359
439
|
return Math.abs(a - Math.round(a)) < 1e-9;
|
|
360
|
-
},
|
|
440
|
+
}, C = (e) => {
|
|
361
441
|
if (f(!1), c(e), e === ``) {
|
|
362
442
|
u(!1), p.current = void 0, t.onChange(void 0);
|
|
363
443
|
return;
|
|
364
444
|
}
|
|
365
445
|
let n = Number(e);
|
|
366
|
-
|
|
367
|
-
}, C = () => {
|
|
368
|
-
a === `` || l || c(String(Number(a)));
|
|
446
|
+
S(n) ? (u(!1), p.current = n, t.onChange(n)) : u(!0);
|
|
369
447
|
}, w = () => {
|
|
370
|
-
|
|
448
|
+
a === `` || l || c(String(Number(a)));
|
|
449
|
+
}, T = () => {
|
|
450
|
+
f(l), w();
|
|
371
451
|
};
|
|
372
|
-
return (0, react.createElement)(
|
|
452
|
+
return (0, react.createElement)(A, {
|
|
373
453
|
...t,
|
|
374
|
-
controlId:
|
|
454
|
+
controlId: g
|
|
375
455
|
}, (0, react.createElement)(`div`, { className: `dsu-numberWrap` }, (0, react.createElement)(`div`, { className: `dsu-number` }, (0, react.createElement)(`input`, {
|
|
376
456
|
className: `dsu-input`,
|
|
377
457
|
type: `number`,
|
|
378
458
|
inputMode: `numeric`,
|
|
379
|
-
id:
|
|
459
|
+
id: g,
|
|
380
460
|
value: a,
|
|
381
461
|
min: t.min,
|
|
382
462
|
max: t.max,
|
|
383
463
|
step: t.step,
|
|
384
464
|
placeholder: t.placeholder,
|
|
385
|
-
"aria-invalid":
|
|
386
|
-
"aria-describedby":
|
|
465
|
+
"aria-invalid": y || void 0,
|
|
466
|
+
"aria-describedby": x,
|
|
387
467
|
"data-field": t.field,
|
|
388
468
|
disabled: t.disabled === !0,
|
|
389
469
|
onChange: (e) => {
|
|
390
|
-
|
|
470
|
+
C(e.target.value);
|
|
391
471
|
},
|
|
392
|
-
onBlur:
|
|
393
|
-
}), t.unit === void 0 ? null : (0, react.createElement)(`span`, { className: `dsu-unit` }, t.unit)),
|
|
472
|
+
onBlur: T
|
|
473
|
+
}), t.unit === void 0 ? null : (0, react.createElement)(`span`, { className: `dsu-unit` }, t.unit)), y ? (0, react.createElement)(`p`, {
|
|
394
474
|
className: `dsu-error`,
|
|
395
|
-
id:
|
|
475
|
+
id: _
|
|
396
476
|
}, t.invalidHint) : null));
|
|
397
477
|
}
|
|
398
|
-
function
|
|
478
|
+
function N(t) {
|
|
399
479
|
let [i, a] = (0, react.useState)(t.value), [o, c] = (0, react.useState)(!1), l = (0, react.useId)(), u = t.hint === void 0 ? void 0 : `${l}-hint`;
|
|
400
480
|
(0, react.useEffect)(() => {
|
|
401
481
|
o || a(t.value);
|
|
@@ -418,23 +498,23 @@ function x(t) {
|
|
|
418
498
|
a(e.target.value), t.onChange(e.target.value);
|
|
419
499
|
}
|
|
420
500
|
};
|
|
421
|
-
return (0, react.createElement)(
|
|
501
|
+
return (0, react.createElement)(A, {
|
|
422
502
|
...t,
|
|
423
503
|
controlId: l
|
|
424
504
|
}, t.multiline === !0 ? (0, react.createElement)(`textarea`, d) : (0, react.createElement)(`input`, d));
|
|
425
505
|
}
|
|
426
|
-
function
|
|
427
|
-
let [l, u] = (0, react.useState)(!1), [d, f] = (0, react.useState)(0), p = (0, react.useRef)(null),
|
|
506
|
+
function F(c) {
|
|
507
|
+
let [l, u] = (0, react.useState)(!1), [d, f] = (0, react.useState)(0), p = (0, react.useRef)(null), m = (0, react.useRef)(null), h = (0, react.useId)(), g = (0, react.useId)(), _ = `--dsu-${g.replaceAll(/[^a-zA-Z0-9]/gu, ``)}`, v = c.hint === void 0 ? void 0 : `${g}-hint`, { disabled: y, value: b, options: x, onChange: S } = c, C = (0, react.useMemo)(() => x.map((e, t) => ({
|
|
428
508
|
option: e,
|
|
429
509
|
index: t
|
|
430
|
-
})).filter((e) => e.option.disabled !== !0), [
|
|
431
|
-
let e = p.current, t =
|
|
510
|
+
})).filter((e) => e.option.disabled !== !0), [x]), w = x.find((e) => e.value === b)?.label ?? b, T = x[d], O = T !== void 0 && T.disabled !== !0, k = (0, react.useCallback)(() => {
|
|
511
|
+
let e = p.current, t = m.current;
|
|
432
512
|
/* v8 ignore next 3 -- place 只在 open 的 layout effect 里调用;refs 为空只可能是卸载竞态 */
|
|
433
513
|
if (e === null || t === null) return;
|
|
434
514
|
let n = e.getBoundingClientRect(), r = Math.min(n.width, window.innerWidth - 16);
|
|
435
515
|
t.style.width = `${r}px`;
|
|
436
|
-
let i =
|
|
437
|
-
if (i && !
|
|
516
|
+
let i = E() && t.style.positionArea !== `none`;
|
|
517
|
+
if (i && !D(n, t.getBoundingClientRect())) return;
|
|
438
518
|
i && (t.style.positionArea = `none`), t.style.marginTop = `0px`;
|
|
439
519
|
let { left: a } = n;
|
|
440
520
|
a + r > window.innerWidth - 8 && (a = window.innerWidth - r - 8);
|
|
@@ -445,43 +525,43 @@ function C(c) {
|
|
|
445
525
|
}, []), j = (0, react.useCallback)(() => {
|
|
446
526
|
u(!1);
|
|
447
527
|
}, []), M = (0, react.useCallback)(() => {
|
|
448
|
-
if (
|
|
449
|
-
let e =
|
|
528
|
+
if (y === !0) return;
|
|
529
|
+
let e = C.find((e) => e.option.value === b) ?? C.at(0);
|
|
450
530
|
e !== void 0 && (f(e.index), u(!0));
|
|
451
531
|
}, [
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
532
|
+
y,
|
|
533
|
+
b,
|
|
534
|
+
C
|
|
455
535
|
]), N = (0, react.useCallback)((e) => {
|
|
456
536
|
/* v8 ignore next 3 -- 浮层只能经由 openMenu 打开;组件禁用时打不开 */
|
|
457
|
-
if (
|
|
458
|
-
let t =
|
|
537
|
+
if (y === !0) return;
|
|
538
|
+
let t = x[e];
|
|
459
539
|
/* v8 ignore next 3 -- disabled 选项在浏览器里不派发 click;越界下标由调用方保证 */
|
|
460
|
-
t !== void 0 && t.disabled !== !0 && (
|
|
540
|
+
t !== void 0 && t.disabled !== !0 && (S(t.value), j(), p.current?.focus());
|
|
461
541
|
}, [
|
|
542
|
+
y,
|
|
543
|
+
x,
|
|
462
544
|
S,
|
|
463
|
-
w,
|
|
464
|
-
T,
|
|
465
545
|
j
|
|
466
546
|
]), P = (0, react.useCallback)((e) => {
|
|
467
|
-
let t =
|
|
547
|
+
let t = C.findIndex((e) => e.index === d);
|
|
468
548
|
/* v8 ignore next 5 -- open 时归一 effect 已保证 enabled 非空且 active 落在可用项上 */
|
|
469
|
-
if (t === -1 ||
|
|
470
|
-
let n = (t + e +
|
|
549
|
+
if (t === -1 || C.length === 0) return;
|
|
550
|
+
let n = (t + e + C.length) % C.length, r = C[n];
|
|
471
551
|
/* v8 ignore next 3 -- next 由取模保证在界内 */
|
|
472
552
|
r !== void 0 && f(r.index);
|
|
473
|
-
}, [d,
|
|
553
|
+
}, [d, C]);
|
|
474
554
|
(0, react.useLayoutEffect)(() => {
|
|
475
555
|
if (!l) return () => {};
|
|
476
|
-
|
|
556
|
+
k();
|
|
477
557
|
let e = (e) => {
|
|
478
558
|
let t = e.target;
|
|
479
|
-
|
|
559
|
+
m.current?.contains(t) !== !0 && p.current?.contains(t) !== !0 && j();
|
|
480
560
|
}, t = (e) => {
|
|
481
561
|
let { target: t } = e;
|
|
482
|
-
t instanceof Node &&
|
|
562
|
+
t instanceof Node && m.current?.contains(t) === !0 || j();
|
|
483
563
|
}, n = () => {
|
|
484
|
-
|
|
564
|
+
k();
|
|
485
565
|
};
|
|
486
566
|
return document.addEventListener(`pointerdown`, e, !0), window.addEventListener(`scroll`, t, !0), window.addEventListener(`resize`, n), () => {
|
|
487
567
|
document.removeEventListener(`pointerdown`, e, !0), window.removeEventListener(`scroll`, t, !0), window.removeEventListener(`resize`, n);
|
|
@@ -489,29 +569,29 @@ function C(c) {
|
|
|
489
569
|
}, [
|
|
490
570
|
l,
|
|
491
571
|
c.options,
|
|
492
|
-
|
|
572
|
+
k,
|
|
493
573
|
j
|
|
494
574
|
]), (0, react.useEffect)(() => {
|
|
495
575
|
if (!l) return;
|
|
496
|
-
if (
|
|
576
|
+
if (y === !0 || C.length === 0) {
|
|
497
577
|
j();
|
|
498
578
|
return;
|
|
499
579
|
}
|
|
500
|
-
if (
|
|
501
|
-
let e =
|
|
580
|
+
if (C.some((e) => e.index === d)) return;
|
|
581
|
+
let e = C.find((e) => e.option.value === b) ?? C.at(0);
|
|
502
582
|
/* v8 ignore next 3 -- enabled 非空在上一分支已保证 */
|
|
503
583
|
e !== void 0 && f(e.index);
|
|
504
584
|
}, [
|
|
505
585
|
l,
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
586
|
+
y,
|
|
587
|
+
b,
|
|
588
|
+
x,
|
|
509
589
|
d,
|
|
510
590
|
j,
|
|
511
|
-
|
|
591
|
+
C
|
|
512
592
|
]), (0, react.useLayoutEffect)(() => {
|
|
513
593
|
if (!l) return;
|
|
514
|
-
let e =
|
|
594
|
+
let e = m.current;
|
|
515
595
|
/* v8 ignore next 2 -- 同上,menu 在 open 的 commit 之后必然已挂上 */
|
|
516
596
|
if (e === null) return;
|
|
517
597
|
let t = e.querySelector(`[data-active="true"]`);
|
|
@@ -520,7 +600,7 @@ function C(c) {
|
|
|
520
600
|
}, [
|
|
521
601
|
l,
|
|
522
602
|
d,
|
|
523
|
-
|
|
603
|
+
x
|
|
524
604
|
]);
|
|
525
605
|
let F = (e) => {
|
|
526
606
|
if (e.key === `ArrowDown` || e.key === `ArrowUp`) {
|
|
@@ -530,8 +610,8 @@ function C(c) {
|
|
|
530
610
|
}
|
|
531
611
|
P(e.key === `ArrowDown` ? 1 : -1);
|
|
532
612
|
} else if (e.key === `Home` || e.key === `End`) {
|
|
533
|
-
if (e.preventDefault(), l || M(),
|
|
534
|
-
let t = e.key === `Home` ?
|
|
613
|
+
if (e.preventDefault(), l || M(), C.length === 0) return;
|
|
614
|
+
let t = e.key === `Home` ? C.at(0) : C.at(-1);
|
|
535
615
|
/* v8 ignore next 3 -- enabled 为空已在上一条返回 */
|
|
536
616
|
if (t === void 0) return;
|
|
537
617
|
f(t.index);
|
|
@@ -543,7 +623,7 @@ function C(c) {
|
|
|
543
623
|
N(d);
|
|
544
624
|
} else (e.key === `Tab` || e.key === `Escape`) && j();
|
|
545
625
|
}, I = [], L;
|
|
546
|
-
for (let [t, n] of
|
|
626
|
+
for (let [t, n] of x.entries()) n.group !== L && (n.group !== void 0 && I.push((0, react.createElement)(`div`, {
|
|
547
627
|
key: `group-${t}-${n.group}`,
|
|
548
628
|
className: `dsu-optionGroup`,
|
|
549
629
|
role: `presentation`
|
|
@@ -551,7 +631,7 @@ function C(c) {
|
|
|
551
631
|
key: `option-${n.value}`,
|
|
552
632
|
type: `button`,
|
|
553
633
|
role: `option`,
|
|
554
|
-
id: `${
|
|
634
|
+
id: `${h}-${t}`,
|
|
555
635
|
className: `dsu-option`,
|
|
556
636
|
tabIndex: -1,
|
|
557
637
|
"aria-selected": n.value === c.value,
|
|
@@ -581,9 +661,9 @@ function C(c) {
|
|
|
581
661
|
strokeLinecap: `round`,
|
|
582
662
|
strokeLinejoin: `round`
|
|
583
663
|
}))));
|
|
584
|
-
return (0, react.createElement)(
|
|
664
|
+
return (0, react.createElement)(A, {
|
|
585
665
|
...c,
|
|
586
|
-
controlId:
|
|
666
|
+
controlId: g
|
|
587
667
|
}, (0, react.createElement)(`div`, {
|
|
588
668
|
className: `dsu-selectWrap`,
|
|
589
669
|
onBlur: (e) => {
|
|
@@ -593,22 +673,22 @@ function C(c) {
|
|
|
593
673
|
}, (0, react.createElement)(`button`, {
|
|
594
674
|
ref: p,
|
|
595
675
|
type: `button`,
|
|
596
|
-
id:
|
|
597
|
-
style: { anchorName:
|
|
676
|
+
id: g,
|
|
677
|
+
style: { anchorName: _ },
|
|
598
678
|
className: `dsu-select dsu-input`,
|
|
599
679
|
role: `combobox`,
|
|
600
680
|
"aria-haspopup": `listbox`,
|
|
601
681
|
"aria-expanded": l,
|
|
602
|
-
"aria-controls": `${
|
|
603
|
-
"aria-activedescendant": l &&
|
|
604
|
-
"aria-describedby":
|
|
682
|
+
"aria-controls": `${h}-list`,
|
|
683
|
+
"aria-activedescendant": l && O ? `${h}-${d}` : void 0,
|
|
684
|
+
"aria-describedby": v,
|
|
605
685
|
"data-field": c.field,
|
|
606
|
-
disabled:
|
|
686
|
+
disabled: y === !0 || x.length === 0,
|
|
607
687
|
onClick: () => {
|
|
608
688
|
l ? j() : M();
|
|
609
689
|
},
|
|
610
690
|
onKeyDown: F
|
|
611
|
-
}, (0, react.createElement)(`span`, { className: `dsu-selectValue` },
|
|
691
|
+
}, (0, react.createElement)(`span`, { className: `dsu-selectValue` }, w), (0, react.createElement)(`svg`, {
|
|
612
692
|
className: `dsu-chevron`,
|
|
613
693
|
width: 14,
|
|
614
694
|
height: 14,
|
|
@@ -622,39 +702,39 @@ function C(c) {
|
|
|
622
702
|
strokeLinecap: `round`,
|
|
623
703
|
strokeLinejoin: `round`
|
|
624
704
|
}))), (0, react.createElement)(`div`, {
|
|
625
|
-
ref:
|
|
626
|
-
id: `${
|
|
705
|
+
ref: m,
|
|
706
|
+
id: `${h}-list`,
|
|
627
707
|
role: `listbox`,
|
|
628
708
|
className: `dsu-menu`,
|
|
629
709
|
style: {
|
|
630
|
-
positionAnchor:
|
|
710
|
+
positionAnchor: _,
|
|
631
711
|
positionTryFallbacks: `flip-block, flip-inline`
|
|
632
712
|
},
|
|
633
713
|
"aria-label": c.label,
|
|
634
714
|
hidden: !l
|
|
635
715
|
}, ...I)));
|
|
636
716
|
}
|
|
637
|
-
function
|
|
638
|
-
let n = !t.writable || t.busy || !t.dirty, r;
|
|
639
|
-
return
|
|
717
|
+
function I(t) {
|
|
718
|
+
let n = t.blocked === !0, r = !t.writable || t.busy, i = r || !t.dirty || n, a = r || !t.dirty && !n, o;
|
|
719
|
+
return o = t.error === null ? t.writable ? t.dirty ? t.dirtyLabel : t.cleanLabel : t.readOnlyLabel : t.error, (0, react.createElement)(`div`, {
|
|
640
720
|
className: `dsu-savebar`,
|
|
641
|
-
"data-dirty": t.dirty
|
|
721
|
+
"data-dirty": t.dirty || n
|
|
642
722
|
}, (0, react.createElement)(`button`, {
|
|
643
723
|
type: `button`,
|
|
644
724
|
className: `dsu-btn dsu-btnPrimary`,
|
|
645
725
|
"data-field": `save`,
|
|
646
|
-
disabled:
|
|
726
|
+
disabled: i,
|
|
647
727
|
onClick: t.onSave
|
|
648
728
|
}, t.busy ? t.savingLabel : t.saveLabel), (0, react.createElement)(`button`, {
|
|
649
729
|
type: `button`,
|
|
650
730
|
className: `dsu-btn`,
|
|
651
731
|
"data-field": `discard`,
|
|
652
|
-
disabled:
|
|
732
|
+
disabled: a,
|
|
653
733
|
onClick: t.onDiscard
|
|
654
734
|
}, t.revertLabel), (0, react.createElement)(`span`, {
|
|
655
735
|
role: `status`,
|
|
656
736
|
className: t.error === null ? `dsu-status` : `dsu-status dsu-statusError`
|
|
657
|
-
},
|
|
737
|
+
}, o));
|
|
658
738
|
}
|
|
659
739
|
// node_modules/@jayyuen66/dsh-plugin-shared/dist/card-diff.js
|
|
660
740
|
function e$1(t, n, r) {
|
|
@@ -1008,6 +1088,7 @@ const UI_MESSAGES = {
|
|
|
1008
1088
|
saving: "保存中…",
|
|
1009
1089
|
revert: "撤销",
|
|
1010
1090
|
saveFailed: "保存失败:{reason}",
|
|
1091
|
+
invalidFields: "有字段超出范围,先修正或撤销后再保存。",
|
|
1011
1092
|
saveRejected: "保存被宿主拒绝(配置校验未通过或写入被跳过),修改未生效",
|
|
1012
1093
|
modelSection: "检索模型",
|
|
1013
1094
|
indexSection: "网络与索引",
|
|
@@ -1067,6 +1148,7 @@ const UI_MESSAGES = {
|
|
|
1067
1148
|
saving: "Saving…",
|
|
1068
1149
|
revert: "Revert",
|
|
1069
1150
|
saveFailed: "save failed: {reason}",
|
|
1151
|
+
invalidFields: "Some fields are out of range; fix them or revert before saving.",
|
|
1070
1152
|
saveRejected: "save rejected by host (validation failed or write skipped) — changes not applied",
|
|
1071
1153
|
modelSection: "Retrieval model",
|
|
1072
1154
|
indexSection: "Network and index",
|
|
@@ -1225,9 +1307,9 @@ function numberDisplay(display, schema) {
|
|
|
1225
1307
|
/** 检索模型小节:embedding 下拉(按本地后端分组)+ 每组结果数。 */
|
|
1226
1308
|
function buildModelSection(deps) {
|
|
1227
1309
|
const { editable, fields, setField, t } = deps;
|
|
1228
|
-
const embedding = (0, react.createElement)(
|
|
1310
|
+
const embedding = (0, react.createElement)(F, {
|
|
1229
1311
|
label: t("embeddingLabel"),
|
|
1230
|
-
...
|
|
1312
|
+
...y(t("embeddingHint")),
|
|
1231
1313
|
field: "defaultEmbedding",
|
|
1232
1314
|
value: fields.embedding,
|
|
1233
1315
|
options: embeddingOptions(t),
|
|
@@ -1236,7 +1318,7 @@ function buildModelSection(deps) {
|
|
|
1236
1318
|
setField("defaultEmbedding", next);
|
|
1237
1319
|
}
|
|
1238
1320
|
});
|
|
1239
|
-
const limit = (0, react.createElement)(
|
|
1321
|
+
const limit = (0, react.createElement)(M, {
|
|
1240
1322
|
label: t("limitLabel"),
|
|
1241
1323
|
hint: t("limitInvalid", {
|
|
1242
1324
|
min: 1,
|
|
@@ -1250,11 +1332,15 @@ function buildModelSection(deps) {
|
|
|
1250
1332
|
unit: t("unitResults"),
|
|
1251
1333
|
invalidHint: t("outOfRange"),
|
|
1252
1334
|
disabled: !editable,
|
|
1335
|
+
resetToken: deps.resetToken,
|
|
1336
|
+
onInvalidChange: (invalid) => {
|
|
1337
|
+
deps.reportInvalid("defaultLimit", invalid);
|
|
1338
|
+
},
|
|
1253
1339
|
onChange: (next) => {
|
|
1254
1340
|
setField("defaultLimit", next);
|
|
1255
1341
|
}
|
|
1256
1342
|
});
|
|
1257
|
-
return (0, react.createElement)(
|
|
1343
|
+
return (0, react.createElement)(C, { title: t("modelSection") }, embedding, limit);
|
|
1258
1344
|
}
|
|
1259
1345
|
/** 重建行:root 输入(白名单候选进 <datalist>)+ 触发按钮(在跑时禁用)。 */
|
|
1260
1346
|
function buildRebuildField(deps) {
|
|
@@ -1280,9 +1366,9 @@ function buildRebuildField(deps) {
|
|
|
1280
1366
|
disabled: rebuild.phase === "running",
|
|
1281
1367
|
onClick: deps.onRebuild
|
|
1282
1368
|
}, rebuild.phase === "running" ? t("rebuildRunning") : t("rebuildButton"));
|
|
1283
|
-
return (0, react.createElement)(
|
|
1369
|
+
return (0, react.createElement)(A, {
|
|
1284
1370
|
label: t("rebuildLabel"),
|
|
1285
|
-
...
|
|
1371
|
+
...y(rebuildHintText(t, fields.embedding, roots.length > 0)),
|
|
1286
1372
|
wide: true
|
|
1287
1373
|
}, rootDatalist, rebuildInput, rebuildButton);
|
|
1288
1374
|
}
|
|
@@ -1313,9 +1399,9 @@ function buildRebuildStatusRow(deps) {
|
|
|
1313
1399
|
/** 网络与索引小节:传输三档、镜像地址、search-first 开关、配额与时效、工作区重建与守护进程状态。 */
|
|
1314
1400
|
function buildIndexSection(deps) {
|
|
1315
1401
|
const { editable, fields, setField, t } = deps;
|
|
1316
|
-
const transport = (0, react.createElement)(
|
|
1402
|
+
const transport = (0, react.createElement)(F, {
|
|
1317
1403
|
label: t("transportLabel"),
|
|
1318
|
-
...
|
|
1404
|
+
...y(t("transportHint")),
|
|
1319
1405
|
field: "transport",
|
|
1320
1406
|
value: fields.transport,
|
|
1321
1407
|
options: transportOptions(t),
|
|
@@ -1324,9 +1410,9 @@ function buildIndexSection(deps) {
|
|
|
1324
1410
|
setField("transport", next);
|
|
1325
1411
|
}
|
|
1326
1412
|
});
|
|
1327
|
-
const endpoint = (0, react.createElement)(
|
|
1413
|
+
const endpoint = (0, react.createElement)(N, {
|
|
1328
1414
|
label: t("endpointLabel"),
|
|
1329
|
-
...
|
|
1415
|
+
...y(t("endpointHint")),
|
|
1330
1416
|
field: "hfEndpoint",
|
|
1331
1417
|
value: fields.hfEndpoint,
|
|
1332
1418
|
placeholder: EMBEDDING_MIRROR_URL,
|
|
@@ -1336,9 +1422,9 @@ function buildIndexSection(deps) {
|
|
|
1336
1422
|
setField("hfEndpoint", next.trim() === "" ? void 0 : next.trim());
|
|
1337
1423
|
}
|
|
1338
1424
|
});
|
|
1339
|
-
const enforce = (0, react.createElement)(
|
|
1425
|
+
const enforce = (0, react.createElement)(j, {
|
|
1340
1426
|
label: t("enforceLabel"),
|
|
1341
|
-
...
|
|
1427
|
+
...y(t("enforceHint")),
|
|
1342
1428
|
field: "enforceSearchFirst",
|
|
1343
1429
|
checked: fields.enforceSearchFirst,
|
|
1344
1430
|
disabled: !editable,
|
|
@@ -1346,9 +1432,9 @@ function buildIndexSection(deps) {
|
|
|
1346
1432
|
setField("enforceSearchFirst", next);
|
|
1347
1433
|
}
|
|
1348
1434
|
});
|
|
1349
|
-
const budget = (0, react.createElement)(
|
|
1435
|
+
const budget = (0, react.createElement)(M, {
|
|
1350
1436
|
label: t("budgetLabel"),
|
|
1351
|
-
...
|
|
1437
|
+
...y(t("budgetHint", { default: 3 })),
|
|
1352
1438
|
field: "grepBudgetPerSearch",
|
|
1353
1439
|
value: numberDisplay(fields.grepBudget, BUDGET_SCHEMA),
|
|
1354
1440
|
min: BUDGET_SCHEMA.minValue ?? 1,
|
|
@@ -1357,13 +1443,17 @@ function buildIndexSection(deps) {
|
|
|
1357
1443
|
unit: t("unitTimes"),
|
|
1358
1444
|
invalidHint: t("outOfRange"),
|
|
1359
1445
|
disabled: !editable,
|
|
1446
|
+
resetToken: deps.resetToken,
|
|
1447
|
+
onInvalidChange: (invalid) => {
|
|
1448
|
+
deps.reportInvalid("grepBudgetPerSearch", invalid);
|
|
1449
|
+
},
|
|
1360
1450
|
onChange: (next) => {
|
|
1361
1451
|
setField("grepBudgetPerSearch", next);
|
|
1362
1452
|
}
|
|
1363
1453
|
});
|
|
1364
|
-
const window = (0, react.createElement)(
|
|
1454
|
+
const window = (0, react.createElement)(M, {
|
|
1365
1455
|
label: t("windowLabel"),
|
|
1366
|
-
...
|
|
1456
|
+
...y(t("windowHint", { default: 10 })),
|
|
1367
1457
|
field: "unlockWindowMin",
|
|
1368
1458
|
value: numberDisplay(fields.unlockWindow, WINDOW_SCHEMA),
|
|
1369
1459
|
min: WINDOW_SCHEMA.minValue ?? 1,
|
|
@@ -1372,20 +1462,25 @@ function buildIndexSection(deps) {
|
|
|
1372
1462
|
unit: t("unitMinutes"),
|
|
1373
1463
|
invalidHint: t("outOfRange"),
|
|
1374
1464
|
disabled: !editable,
|
|
1465
|
+
resetToken: deps.resetToken,
|
|
1466
|
+
onInvalidChange: (invalid) => {
|
|
1467
|
+
deps.reportInvalid("unlockWindowMin", invalid);
|
|
1468
|
+
},
|
|
1375
1469
|
onChange: (next) => {
|
|
1376
1470
|
setField("unlockWindowMin", next);
|
|
1377
1471
|
}
|
|
1378
1472
|
});
|
|
1379
|
-
return (0, react.createElement)(
|
|
1473
|
+
return (0, react.createElement)(C, { title: t("indexSection") }, transport, endpoint, enforce, budget, window, buildDaemonNote(deps), buildRebuildField(deps), buildRebuildStatusRow(deps));
|
|
1380
1474
|
}
|
|
1381
1475
|
/** 卡片主体:检索模型 / 网络与索引两节 + 保存条。 */
|
|
1382
1476
|
function buildCardBody(deps) {
|
|
1383
1477
|
const { t } = deps;
|
|
1384
|
-
const saveBar = (0, react.createElement)(
|
|
1478
|
+
const saveBar = (0, react.createElement)(I, {
|
|
1385
1479
|
dirty: deps.dirty,
|
|
1480
|
+
blocked: deps.blocked,
|
|
1386
1481
|
busy: deps.busy,
|
|
1387
1482
|
writable: deps.writable,
|
|
1388
|
-
error: deps.saveError,
|
|
1483
|
+
error: deps.saveError ?? (deps.blocked ? t("invalidFields") : null),
|
|
1389
1484
|
saveLabel: t("save"),
|
|
1390
1485
|
savingLabel: t("saving"),
|
|
1391
1486
|
revertLabel: t("revert"),
|
|
@@ -1395,7 +1490,7 @@ function buildCardBody(deps) {
|
|
|
1395
1490
|
onSave: deps.onSave,
|
|
1396
1491
|
onDiscard: deps.onDiscard
|
|
1397
1492
|
});
|
|
1398
|
-
return (0, react.createElement)(
|
|
1493
|
+
return (0, react.createElement)(S, null, buildModelSection(deps), buildIndexSection(deps), saveBar);
|
|
1399
1494
|
}
|
|
1400
1495
|
/** 显式字段写入(schema-coverage 门禁按 set('字段名') 字面量识别绑定)。 */
|
|
1401
1496
|
function pushFieldWrite(ops, key, draft, set) {
|
|
@@ -1546,8 +1641,10 @@ function ZgCard(props) {
|
|
|
1546
1641
|
const [saveError, setSaveError] = (0, react.useState)(null);
|
|
1547
1642
|
const rebuildView = useRebuild(t, props.rebuildRemote);
|
|
1548
1643
|
const fields = draftFields(touched, value);
|
|
1549
|
-
const
|
|
1550
|
-
const
|
|
1644
|
+
const invalid = x();
|
|
1645
|
+
const { blocked, fields: invalidFields, resetToken, reportInvalid } = invalid;
|
|
1646
|
+
const dirtyCount = (/* @__PURE__ */ new Set([...t$1(touched, value), ...invalidFields])).size;
|
|
1647
|
+
const dirty = dirtyCount > 0 || blocked;
|
|
1551
1648
|
const setField = (field, draft) => {
|
|
1552
1649
|
setTouched((prev) => ({
|
|
1553
1650
|
...prev,
|
|
@@ -1556,7 +1653,7 @@ function ZgCard(props) {
|
|
|
1556
1653
|
};
|
|
1557
1654
|
const save = async () => {
|
|
1558
1655
|
const keys = t$1(touched, value);
|
|
1559
|
-
if (keys.length === 0) return;
|
|
1656
|
+
if (keys.length === 0 || blocked) return;
|
|
1560
1657
|
setBusy(true);
|
|
1561
1658
|
setSaveError(null);
|
|
1562
1659
|
const ops = [];
|
|
@@ -1580,10 +1677,12 @@ function ZgCard(props) {
|
|
|
1580
1677
|
const next = Object.fromEntries(Object.entries(touched).filter(([entryKey]) => !savedKeys.has(entryKey)));
|
|
1581
1678
|
setBusy(false);
|
|
1582
1679
|
setTouched(next);
|
|
1680
|
+
invalid.clear();
|
|
1583
1681
|
};
|
|
1584
1682
|
const discard = () => {
|
|
1585
1683
|
setTouched({});
|
|
1586
1684
|
setSaveError(null);
|
|
1685
|
+
invalid.clear();
|
|
1587
1686
|
};
|
|
1588
1687
|
return buildCardBody({
|
|
1589
1688
|
t,
|
|
@@ -1595,6 +1694,9 @@ function ZgCard(props) {
|
|
|
1595
1694
|
root: rebuildView.root,
|
|
1596
1695
|
rebuild: rebuildView.state,
|
|
1597
1696
|
dirty,
|
|
1697
|
+
blocked,
|
|
1698
|
+
resetToken,
|
|
1699
|
+
reportInvalid,
|
|
1598
1700
|
dirtyCount,
|
|
1599
1701
|
busy,
|
|
1600
1702
|
saveError,
|
|
@@ -1616,12 +1718,14 @@ const inject = [
|
|
|
1616
1718
|
];
|
|
1617
1719
|
function apply(ctx) {
|
|
1618
1720
|
ctx.effect(() => {
|
|
1721
|
+
const disposeShared = v();
|
|
1619
1722
|
const tag = document.createElement("style");
|
|
1620
1723
|
tag.id = "zvec-grep-card-css";
|
|
1621
|
-
tag.textContent =
|
|
1724
|
+
tag.textContent = CARD_CSS;
|
|
1622
1725
|
document.head.append(tag);
|
|
1623
1726
|
return () => {
|
|
1624
1727
|
tag.remove();
|
|
1728
|
+
disposeShared();
|
|
1625
1729
|
};
|
|
1626
1730
|
}, "zvec-grep-card: styles");
|
|
1627
1731
|
const scope = ctx.configForms.get(NS);
|
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,12 +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";
|
|
10
11
|
import { HarnessError } from "@deepseek-ai/dsh-error";
|
|
12
|
+
import { registerSkill } from "@jayyuen66/dsh-plugin-shared/lib/skill";
|
|
11
13
|
import { LOCALE_SETTINGS_NAMESPACE, messagesFor, resolveLocalePreference } from "@jayyuen66/dsh-plugin-shared/lib/locale";
|
|
12
14
|
import { truncateEnd, truncateStart } from "@jayyuen66/dsh-plugin-shared/lib/text";
|
|
15
|
+
import { claimInstance } from "@jayyuen66/dsh-plugin-shared/lib/instance-lock";
|
|
13
16
|
import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
14
17
|
import { jobOutcomeOf } from "@jayyuen66/dsh-plugin-shared/lib/job-outcome";
|
|
15
18
|
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
@@ -473,17 +476,15 @@ const MESSAGES = {
|
|
|
473
476
|
/**
|
|
474
477
|
* `{name}` 占位符插值(与官方 locale 的 Translate 参数语义同源)。
|
|
475
478
|
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
479
|
+
* 实现已收进 shared 的 `@jayyuen66/dsh-plugin-shared/lib/placeholder`。本包此前缺键即替空串,
|
|
480
|
+
* 现在统一成「缺值保留原文」:写错占位符时原样留着的 `{xxx}` 一眼可见,比一句悄悄塌掉的
|
|
481
|
+
* 文案好排障。`null` 仍照实渲染成 `"null"`(`exitCode` 这类字段的正常取值)。
|
|
478
482
|
* @param template - 字典里的模板。
|
|
479
|
-
* @param params - 占位符名 →
|
|
483
|
+
* @param params - 占位符名 → 值。
|
|
480
484
|
* @returns 填好的文本。
|
|
481
485
|
*/
|
|
482
486
|
function fill(template, params) {
|
|
483
|
-
return template
|
|
484
|
-
const value = Object.hasOwn(params, key) ? params[key] : void 0;
|
|
485
|
-
return value === void 0 ? "" : String(value);
|
|
486
|
-
});
|
|
487
|
+
return fillPlaceholders(template, params);
|
|
487
488
|
}
|
|
488
489
|
// lib/platform.ts
|
|
489
490
|
/** 把 Node 的 platform 收成两档:win32 单独一档,其余都按 POSIX。 */
|
|
@@ -2022,7 +2023,7 @@ function zgToolProblem(name, args, execution, messages, platform) {
|
|
|
2022
2023
|
*/
|
|
2023
2024
|
function zgGuard(execution, messages, platform = "posix") {
|
|
2024
2025
|
const { name } = execution;
|
|
2025
|
-
const args = isRecord
|
|
2026
|
+
const args = isRecord(execution.arguments) ? execution.arguments : {};
|
|
2026
2027
|
let reason;
|
|
2027
2028
|
if (isZgToolName(name)) reason = zgToolProblem(name, args, execution, messages, platform);
|
|
2028
2029
|
return reason;
|
|
@@ -2209,7 +2210,7 @@ function nativeGrepProblem(args, cwd, deps, messages) {
|
|
|
2209
2210
|
*/
|
|
2210
2211
|
function searchFirstGuard(execution, deps, messages) {
|
|
2211
2212
|
const { name } = execution;
|
|
2212
|
-
const args = isRecord
|
|
2213
|
+
const args = isRecord(execution.arguments) ? execution.arguments : {};
|
|
2213
2214
|
const cwd = sessionHeaderCwd$1(execution);
|
|
2214
2215
|
let reason;
|
|
2215
2216
|
if (deps.enabled && cwd !== void 0 && searchAdmitted(execution)) {
|
|
@@ -2519,11 +2520,6 @@ function tooOldZgVersion(stdout) {
|
|
|
2519
2520
|
// lib/skill.ts
|
|
2520
2521
|
/** skill 名:kebab-case,也是模型用 skill 工具加载时的入参。 */
|
|
2521
2522
|
const SKILL_NAME = "zvec-grep";
|
|
2522
|
-
/** 收窄判定:只认「有 register 且是函数」的对象,空对象不能冒充 skill 服务。 */
|
|
2523
|
-
function isSkillsFace(value) {
|
|
2524
|
-
if (typeof value !== "object" || value === null) return false;
|
|
2525
|
-
return typeof Reflect.get(value, "register") === "function";
|
|
2526
|
-
}
|
|
2527
2523
|
/**
|
|
2528
2524
|
* 注册(或重新注册)本包的检索规则 skill。
|
|
2529
2525
|
*
|
|
@@ -2532,17 +2528,14 @@ function isSkillsFace(value) {
|
|
|
2532
2528
|
* @param ctx - 只需 `get`(读可选服务),不要求 skills 进 inject
|
|
2533
2529
|
* @param content - 规则全文(`messages.routingText`)
|
|
2534
2530
|
* @param description - skill 目录里那行说明(模型据此决定要不要加载)
|
|
2535
|
-
* @returns 注册成功与否;未装载 skill
|
|
2531
|
+
* @returns 注册成功与否;未装载 skill 服务或正文为空时为 false(不抛,摘要段照旧生效)
|
|
2536
2532
|
*/
|
|
2537
2533
|
function registerRoutingSkill(ctx, content, description) {
|
|
2538
|
-
|
|
2539
|
-
if (!isSkillsFace(found)) return false;
|
|
2540
|
-
found.register({
|
|
2534
|
+
return registerSkill(ctx, {
|
|
2541
2535
|
name: SKILL_NAME,
|
|
2542
2536
|
description,
|
|
2543
2537
|
content
|
|
2544
2538
|
});
|
|
2545
|
-
return true;
|
|
2546
2539
|
}
|
|
2547
2540
|
// lib/index-preflight.ts
|
|
2548
2541
|
/**
|
|
@@ -3309,7 +3302,7 @@ let ZvecRebuildService = (() => {
|
|
|
3309
3302
|
*/
|
|
3310
3303
|
async rebuild(request) {
|
|
3311
3304
|
const started = this.deps.messages();
|
|
3312
|
-
const accepted = acceptableRoot(isRecord
|
|
3305
|
+
const accepted = acceptableRoot(isRecord(request) ? request.root : void 0, this.deps.ledger, started, this.deps.platform);
|
|
3313
3306
|
if ("error" in accepted) return {
|
|
3314
3307
|
ok: false,
|
|
3315
3308
|
error: accepted.error.value,
|
|
@@ -3372,7 +3365,7 @@ let ZvecRebuildService = (() => {
|
|
|
3372
3365
|
*/
|
|
3373
3366
|
status(request) {
|
|
3374
3367
|
const marks = this.deps.messages();
|
|
3375
|
-
const raw = isRecord
|
|
3368
|
+
const raw = isRecord(request) ? request.jobId : void 0;
|
|
3376
3369
|
const record = typeof raw === "string" && raw.length > 0 ? this.deps.records.get(raw) : void 0;
|
|
3377
3370
|
if (record === void 0) return {
|
|
3378
3371
|
ok: false,
|
|
@@ -3425,7 +3418,7 @@ let ZvecRebuildService = (() => {
|
|
|
3425
3418
|
* @param deps - 重建读取接口的全部依赖(见 ZvecRebuildDeps)
|
|
3426
3419
|
*/
|
|
3427
3420
|
function installRebuildRemote(ctx, deps) {
|
|
3428
|
-
if (!isRecord
|
|
3421
|
+
if (!isRecord(ctx) || !isRecord(ctx.reflect) || typeof ctx.reflect.provide !== "function") return false;
|
|
3429
3422
|
new ZvecRebuildService(ctx, deps);
|
|
3430
3423
|
ctx.effect(() => () => {
|
|
3431
3424
|
releaseRebuildRecords(deps);
|
|
@@ -3568,9 +3561,6 @@ const SESSION_LOST_STATUS = /* @__PURE__ */ new Set([
|
|
|
3568
3561
|
]);
|
|
3569
3562
|
/** 握手与工具调用的 JSON-RPC 常量。 */
|
|
3570
3563
|
const JSONRPC = "2.0";
|
|
3571
|
-
function isRecord(value) {
|
|
3572
|
-
return typeof value === "object" && value !== null;
|
|
3573
|
-
}
|
|
3574
3564
|
/** 从 SSE 正文收集全部 `data:` 行的 JSON 载荷;解析不了的行(心跳/注释)跳过。 */
|
|
3575
3565
|
function ssePayloads(body) {
|
|
3576
3566
|
const payloads = [];
|
|
@@ -3865,11 +3855,18 @@ const MAX_LEDGER_ROOTS = 64;
|
|
|
3865
3855
|
const LEDGER_TTL_MS = 864e5;
|
|
3866
3856
|
/** 成功执行里回显 stderr 的尾部长度(降级提示常就在这一行)。 */
|
|
3867
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";
|
|
3868
3865
|
/** 具名方法在位(typeof 函数)——只看 `typeof x === "object"` 会放过 null、
|
|
3869
3866
|
* 也会放过「是个对象但没注册方法」的错注入。 */
|
|
3870
3867
|
function hasMethod(value, name, keys) {
|
|
3871
3868
|
const member = value[name];
|
|
3872
|
-
return isRecord
|
|
3869
|
+
return isRecord(member) && keys.every((key) => typeof member[key] === "function");
|
|
3873
3870
|
}
|
|
3874
3871
|
/**
|
|
3875
3872
|
* host 是否为本插件所需宿主服务:五个注入都必须是**带相应方法的对象**,
|
|
@@ -3882,7 +3879,7 @@ function hasMethod(value, name, keys) {
|
|
|
3882
3879
|
* 探它们等于断言一条没有测试撑着的能力。
|
|
3883
3880
|
*/
|
|
3884
3881
|
function isZvecGrepHost(value) {
|
|
3885
|
-
if (!isRecord
|
|
3882
|
+
if (!isRecord(value)) return false;
|
|
3886
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";
|
|
3887
3884
|
}
|
|
3888
3885
|
/** 当前会话工作区(root 缺省回退源);非字符串视为缺(读取方式见 lib/routing.ts 的 SessionFace)。 */
|
|
@@ -3900,7 +3897,7 @@ function stringifyJson(value) {
|
|
|
3900
3897
|
return JSON.stringify(value, null, 2);
|
|
3901
3898
|
}
|
|
3902
3899
|
function textBlock(value) {
|
|
3903
|
-
const { text: textValue } = isRecord
|
|
3900
|
+
const { text: textValue } = isRecord(value) ? value : {};
|
|
3904
3901
|
if (typeof textValue === "string") return [{
|
|
3905
3902
|
type: "text",
|
|
3906
3903
|
text: textValue
|
|
@@ -4497,11 +4494,11 @@ function manifestCoversRoot(manifestPath, dir, platform) {
|
|
|
4497
4494
|
} catch {
|
|
4498
4495
|
return false;
|
|
4499
4496
|
}
|
|
4500
|
-
if (!isRecord
|
|
4497
|
+
if (!isRecord(parsed)) return false;
|
|
4501
4498
|
const version = parsed["indexVersion"];
|
|
4502
4499
|
if (typeof version !== "number" || !Number.isSafeInteger(version) || version < MINIMUM_INDEX_VERSION) return false;
|
|
4503
4500
|
const { sourceRoot } = parsed;
|
|
4504
|
-
if (!isRecord
|
|
4501
|
+
if (!isRecord(sourceRoot)) return false;
|
|
4505
4502
|
const recorded = sourceRoot["recordedPath"];
|
|
4506
4503
|
return typeof recorded === "string" && recorded.length > 0 && comparablePath(normalizeRoot(recorded, platform), process.platform) === comparablePath(normalizeRoot(dir, platform), process.platform);
|
|
4507
4504
|
}
|
|
@@ -4620,7 +4617,7 @@ function define(host, spec) {
|
|
|
4620
4617
|
description: spec.description,
|
|
4621
4618
|
parameters,
|
|
4622
4619
|
timeoutMs: spec.timeoutMs,
|
|
4623
|
-
presentCall: (rawArgs) => spec.presentCall(isRecord
|
|
4620
|
+
presentCall: (rawArgs) => spec.presentCall(isRecord(rawArgs) ? rawArgs : {}),
|
|
4624
4621
|
isConcurrencySafe: () => spec.concurrencySafe,
|
|
4625
4622
|
output: {
|
|
4626
4623
|
schema: TEXT_OUTPUT_SCHEMA,
|
|
@@ -4628,7 +4625,7 @@ function define(host, spec) {
|
|
|
4628
4625
|
},
|
|
4629
4626
|
execute: async (rawArgs, exec) => {
|
|
4630
4627
|
const messages = spec.messages();
|
|
4631
|
-
if (!isRecord
|
|
4628
|
+
if (!isRecord(rawArgs)) throw new ZgToolError(ZG_TOOL_ERROR_CODES.badArguments, fill(messages.argsMustBeObject, {
|
|
4632
4629
|
name: spec.name,
|
|
4633
4630
|
received: rawArgs === null ? "null" : typeof rawArgs
|
|
4634
4631
|
}));
|
|
@@ -5095,7 +5092,7 @@ function daemonFailure(text, messages) {
|
|
|
5095
5092
|
}
|
|
5096
5093
|
/** daemon 调用的传输层失败(fetch 层):取消/超时与 CLI lane 同一套归因。 */
|
|
5097
5094
|
function daemonTransportFailure(error, exec, messages, token) {
|
|
5098
|
-
if (!(isRecord
|
|
5095
|
+
if (!(isRecord(error) && error["name"] === "AbortError")) {
|
|
5099
5096
|
const detail = redactToken(errorText(error), token);
|
|
5100
5097
|
return new ZgToolError(ZG_TOOL_ERROR_CODES.daemonUnavailable, fill(messages.mcpCallFailed, { detail }), { cause: error });
|
|
5101
5098
|
}
|
|
@@ -5129,7 +5126,7 @@ async function runSearchViaDaemon(runtime, searchArgs, messages, exec, wait) {
|
|
|
5129
5126
|
signal: exec.signal
|
|
5130
5127
|
}));
|
|
5131
5128
|
} catch (error) {
|
|
5132
|
-
const aborted = isRecord
|
|
5129
|
+
const aborted = isRecord(error) && error["name"] === "AbortError";
|
|
5133
5130
|
if (!aborted) runtime.serverGate.invalidate();
|
|
5134
5131
|
throw new DaemonCallFailureError(daemonTransportFailure(error, exec, messages, runtime.daemon.tokenOf()).message, aborted);
|
|
5135
5132
|
}
|
|
@@ -5530,7 +5527,7 @@ function registerRoutingSection(host, registered) {
|
|
|
5530
5527
|
*/
|
|
5531
5528
|
/** 该不该为这次调用问一句;不该问就交回 undefined(调用方转交 next())。 */
|
|
5532
5529
|
function explicitRootAsk(execution, ledger, messages, platform) {
|
|
5533
|
-
const raw = (isRecord
|
|
5530
|
+
const raw = (isRecord(execution.arguments) ? execution.arguments : void 0)?.["root"];
|
|
5534
5531
|
let question;
|
|
5535
5532
|
if (typeof raw === "string" && raw.trim().length > 0) {
|
|
5536
5533
|
const decision = judgeRoot(raw, sessionHeaderCwd(execution), messages, ledger, platform);
|
|
@@ -5602,6 +5599,13 @@ function apply(ctx, config) {
|
|
|
5602
5599
|
if (!isZvecGrepHost(ctx)) throw new Error("[zvec-grep] required services (settings/shell/tools/systemPrompt/timer/get) missing");
|
|
5603
5600
|
const host = ctx;
|
|
5604
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
|
+
}
|
|
5605
5609
|
configureSettingsPage(host);
|
|
5606
5610
|
const localeMessages = createLocaleMessages(host);
|
|
5607
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": {
|