@fish-under-sea/dsh-approval-guide 1.1.0 → 2.0.1

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/README.en.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @fish-under-sea/dsh-approval-guide
2
2
 
3
- **1.1.0 · Approval Guide**
3
+ **2.0.1 · Approval Guide**
4
+
5
+ Adds Chinese action, risk and rationale notes to approval prompts.
4
6
 
5
7
  [简体中文](README.md)
6
8
 
@@ -8,13 +10,17 @@
8
10
 
9
11
  Adds Chinese action, risk and rationale explanations to approval prompts for files, commands, network access and privilege changes.
10
12
 
13
+ ### Empty-input send
14
+
15
+ When the composer is empty, clicking Send fills in and sends “继续任务,并梳理进度” (continue the task and summarize progress). Non-empty input, the Stop button, attachments, pending uploads and IME composition are untouched; re-entry is guarded and the button wait is bounded to about 816 ms before a single warning.
16
+
11
17
  ## Installation
12
18
 
13
19
  ```sh
14
- dsh plugin --profile <profile> add @fish-under-sea/dsh-approval-guide@1.1.0
20
+ dsh plugin --profile <profile> add @fish-under-sea/dsh-approval-guide@2.0.1
15
21
  ```
16
22
 
17
- Also included in `@fish-under-sea/dsh-fish@1.1.0`. Do not expand duplicate rows through both aggregate and standalone bundles. Restart DSH after installation; use the desktop plugin manager when no CLI is available.
23
+ Also included in `@fish-under-sea/dsh-fish@2.0.1`. Do not expand duplicate rows through both aggregate and standalone bundles. Restart DSH after installation; use the desktop plugin manager when no CLI is available.
18
24
 
19
25
  ## Configuration and Safety
20
26
 
@@ -24,6 +30,6 @@ Node requirement: `>=24.9`. Host compatibility follows this package manifest; th
24
30
 
25
31
  ## Maintenance and Attribution
26
32
 
27
- 1.1.0 is a coordinated release number, not a claim that all latest upstream commits are merged. Historical documentation remains in Git; see [aggregate changelog](https://github.com/Fish-under-sea/dsh-fish/blob/main/CHANGELOG.en.md).
33
+ 2.0.1 is a coordinated release number, not a claim that all latest upstream commits are merged. Historical documentation remains in Git; see [aggregate changelog](https://github.com/Fish-under-sea/dsh-fish/blob/main/CHANGELOG.en.md).
28
34
 
29
35
  Fish-native plugin. License: MIT.
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @fish-under-sea/dsh-approval-guide
2
2
 
3
- **1.1.0 · 审批说明**
3
+ **2.0.1 · 审批说明**
4
+
5
+ 为审批弹窗补充中文动作、风险与依据说明。
4
6
 
5
7
  [English](README.en.md)
6
8
 
@@ -8,13 +10,17 @@
8
10
 
9
11
  为审批弹窗补充中文动作、风险与依据说明;覆盖文件、命令、网络及权限升级等常见请求。
10
12
 
13
+ ### 空输入发送
14
+
15
+ 输入框为空时,点击发送按钮会自动填入并发送「继续任务,并梳理进度」,省去先打字的步骤。非空输入、停止按钮、附件、上传中与输入法组合态都不接管;重复点击有重入保护,按钮未及时可用时最多等待约 816ms 后放弃并只记录一次警告。
16
+
11
17
  ## 安装
12
18
 
13
19
  ```sh
14
- dsh plugin --profile <profile> add @fish-under-sea/dsh-approval-guide@1.1.0
20
+ dsh plugin --profile <profile> add @fish-under-sea/dsh-approval-guide@2.0.1
15
21
  ```
16
22
 
17
- 也可安装聚合包 `@fish-under-sea/dsh-fish@1.1.0`。聚合与独立安装不要重复展开相同插件行;安装完成后重启 DSH。桌面环境无 CLI 时使用插件管理器。
23
+ 也可安装聚合包 `@fish-under-sea/dsh-fish@2.0.1`。聚合与独立安装不要重复展开相同插件行;安装完成后重启 DSH。桌面环境无 CLI 时使用插件管理器。
18
24
 
19
25
  ## 配置与边界
20
26
 
@@ -24,6 +30,6 @@ Node 要求: `>=24.9`. DSH 支持范围以本包声明为准;聚合包不覆
24
30
 
25
31
  ## 维护与来源
26
32
 
27
- 1.1.0 统一发布版本,不表示已合并上游所有最新提交。历史说明保留在 Git 历史中;聚合变更见 [聚合变更记录](https://github.com/Fish-under-sea/dsh-fish/blob/main/CHANGELOG.md).
33
+ 2.0.1 统一发布版本,不表示已合并上游所有最新提交。历史说明保留在 Git 历史中;聚合变更见 [聚合变更记录](https://github.com/Fish-under-sea/dsh-fish/blob/main/CHANGELOG.md).
28
34
 
29
35
  Fish 原生插件。 许可证: MIT.
package/icon.png ADDED
Binary file
package/lib/client.js CHANGED
@@ -238,6 +238,360 @@ window.__ModuleLoader__.load({
238
238
  });
239
239
  }
240
240
  //#endregion
241
+ //#region 空输入发送增强:输入框为空时点发送不再发死键
242
+ /** 输入框为空时点发送按钮要自动填入并发送的固定文案。 */
243
+ const EMPTY_SEND_TEXT = "继续任务,并梳理进度";
244
+ /** 等 React 重渲染把按钮从 disabled 变为可用的有界轮询:24ms × 34 ≈ 816ms。 */
245
+ const SEND_POLL_INTERVAL = 24;
246
+ const SEND_POLL_ATTEMPTS = 34;
247
+ /** 提交后吞掉同一次手势可能补发的原生 click 的窗口(毫秒)。 */
248
+ const CLICK_GUARD_MS = 600;
249
+ const WARN_WRITE = "dsh-approval-guide: 空输入自动发送写入文本失败,已保留原行为。";
250
+ const WARN_TIMEOUT = "dsh-approval-guide: 空输入自动发送等待发送按钮可用超时,本次未发送。";
251
+ /** 附件/上传态的 DOM 线索:显式标记优先,aria-busy 兜住官方缩略图的上传态。 */
252
+ const ATTACHMENT_SELECTOR = "[data-attachment],[data-composer-attachment],[data-uploading],[aria-busy=\"true\"]";
253
+ /** 元素判断不依赖 instanceof:插件与宿主可能分属不同 realm。 */
254
+ function isElement(node) {
255
+ return node !== null && typeof node === "object" && node.nodeType === 1;
256
+ }
257
+ /** 读属性;没有 hasAttribute 的假 DOM 也不抛。 */
258
+ function hasAttr(el, name) {
259
+ if (typeof el?.hasAttribute === "function") return el.hasAttribute(name);
260
+ return el?.getAttribute?.(name) !== null && el?.getAttribute?.(name) !== void 0;
261
+ }
262
+ /** 主按钮:DSH 的发送/停止按钮类名是 CSS Modules 哈希前缀 + `_primary`。 */
263
+ function isPrimaryButton(node) {
264
+ if (!isElement(node) || String(node.tagName ?? "").toUpperCase() !== "BUTTON") return false;
265
+ return String(node.getAttribute?.("class") ?? "").split(/\s+/).some((token) => token.endsWith("_primary"));
266
+ }
267
+ /**
268
+ * 发送按钮:主按钮、不是「正在发送」、也不是停止按钮。
269
+ * 停止按钮的图标是 svg > rect(方块),发送按钮是 svg > path(箭头);
270
+ * 不能只看 `_primary` 类名 —— 停止按钮用的是同一个类。
271
+ */
272
+ function isSendButton(node) {
273
+ if (!isPrimaryButton(node)) return false;
274
+ if (hasAttr(node, "data-sending")) return false;
275
+ if (node.getAttribute?.("aria-busy") === "true") return false;
276
+ const stopGlyph = typeof node.querySelector === "function" && node.querySelector("svg rect") !== null;
277
+ return !stopGlyph;
278
+ }
279
+ /**
280
+ * 从事件目标(或坐标命中)找到发送按钮。
281
+ * 空输入时按钮是 disabled,部分浏览器会把 pointerdown 重定向到父节点,
282
+ * 所以再用 elementFromPoint 按坐标兜底一次。
283
+ */
284
+ function sendButtonOf(event, doc) {
285
+ const target = isElement(event?.target) ? event.target : null;
286
+ const direct = target?.closest?.("button");
287
+ if (isSendButton(direct)) return direct;
288
+ if (typeof doc?.elementFromPoint !== "function") return null;
289
+ const point = doc.elementFromPoint(event?.clientX ?? 0, event?.clientY ?? 0);
290
+ const hit = isElement(point) ? point.closest?.("button") : null;
291
+ return isSendButton(hit) ? hit : null;
292
+ }
293
+ /** 发送按钮所在的编辑器卡片。 */
294
+ function composerCardOf(button) {
295
+ return typeof button?.closest === "function" ? button.closest("[data-composer-card]") : null;
296
+ }
297
+ /** 卡片里的 Lexical 编辑器根;同页可能有多份输入框,所以先按卡片缩小范围。 */
298
+ function editorOf(card, doc) {
299
+ const scope = card ?? doc;
300
+ if (typeof scope?.querySelector !== "function") return null;
301
+ return scope.querySelector('[data-lexical-editor="true"][role="textbox"]') ?? scope.querySelector("[data-composer-input]") ?? null;
302
+ }
303
+ /** 编辑器里的文本。 */
304
+ function editorText(editor) {
305
+ return String(editor?.textContent ?? "");
306
+ }
307
+ /** 编辑器此刻可写、且不处于 slash 命令认领 / 提交中等阶段。 */
308
+ function editorReady(editor) {
309
+ if (editor === null) return false;
310
+ const editable = editor.getAttribute?.("contenteditable");
311
+ if (editable !== null && editable !== void 0 && String(editable).toLowerCase() === "false") return false;
312
+ if (editor.getAttribute?.("aria-disabled") === "true") return false;
313
+ const phase = editor.getAttribute?.("data-phase");
314
+ return phase === null || phase === void 0 || phase === "plain";
315
+ }
316
+ /** 装饰节点 / 已认领的 slash 命令:不接管(发送会把它们丢掉)。 */
317
+ function hasEditorDecoration(editor) {
318
+ if (typeof editor?.querySelector !== "function") return false;
319
+ return editor.querySelector('[data-composer-command],[data-lexical-decorator="true"],[data-composer-chip]') !== null;
320
+ }
321
+ /** 已暂存附件或正在上传:不接管(用户可能想连附件一起发)。 */
322
+ function hasAttachments(card, editor) {
323
+ if (card === null) return false;
324
+ if (typeof card.querySelector === "function" && card.querySelector(ATTACHMENT_SELECTOR) !== null) return true;
325
+ // 附件轨道由 ComposerAttachments 直接渲染成卡片的子元素(编辑器之前),
326
+ // 里面固定有一个 role="group" 列表;overlay 锚点是命令菜单,不算附件。
327
+ const editorHost = typeof editor?.closest === "function" ? editor.closest("[data-input-scroll]") : null;
328
+ for (const child of Array.from(card.children ?? [])) {
329
+ if (editorHost !== null && (child === editorHost || child.contains?.(editorHost) === true)) break;
330
+ if (!isElement(child) || hasAttr(child, "data-composer-overlay")) continue;
331
+ if (child.querySelector?.('[role="group"]') !== null) return true;
332
+ }
333
+ return false;
334
+ }
335
+ /** 加号按钮的 aria-expanded 为 true 时命令菜单开着,让位给宿主。 */
336
+ function commandMenuOpen(card) {
337
+ return typeof card?.querySelector === "function" && card.querySelector('[aria-haspopup="listbox"][aria-expanded="true"]') !== null;
338
+ }
339
+ /** 聚焦输入框:execCommand("insertText") 需要焦点在编辑器里。 */
340
+ function focusEditor(editor) {
341
+ try {
342
+ editor.focus?.({ preventScroll: true });
343
+ } catch {
344
+ try {
345
+ editor.focus?.();
346
+ } catch {
347
+ /* 聚焦失败不影响后面的兜底写入 */
348
+ }
349
+ }
350
+ }
351
+ /**
352
+ * 把文本写进 Lexical 编辑器,三级兜底(每一级都不抛异常):
353
+ * 1) document.execCommand("insertText"):原生编辑命令,Lexical 会收到
354
+ * beforeinput/input,DOM 与内部状态一起更新 —— 首选。
355
+ * 2) 合成 paste 事件(带 text/plain):Lexical 的粘贴处理插入纯文本。
356
+ * 3) 直接写 DOM 再发 input 事件:最后的兜底,至少让用户可以接着手动发送。
357
+ * @returns 编辑器里是否真的出现了文本。
358
+ */
359
+ function writeTextToEditor(editor, text, doc, win) {
360
+ try {
361
+ if (typeof doc?.execCommand === "function" && doc.execCommand("insertText", false, text) === true && editorText(editor).trim() !== "") return true;
362
+ } catch {
363
+ /* 下一级兜底 */
364
+ }
365
+ try {
366
+ let data;
367
+ if (typeof win?.DataTransfer === "function") {
368
+ data = new win.DataTransfer();
369
+ data?.setData?.("text/plain", text);
370
+ }
371
+ let paste;
372
+ try {
373
+ paste = new win.ClipboardEvent("paste", { bubbles: true, cancelable: true, clipboardData: data });
374
+ } catch {
375
+ paste = new win.Event("paste", { bubbles: true, cancelable: true });
376
+ }
377
+ if (data !== void 0 && paste.clipboardData !== data) {
378
+ try {
379
+ Object.defineProperty(paste, "clipboardData", { value: data });
380
+ } catch {
381
+ /* 只读就按纯事件走 */
382
+ }
383
+ }
384
+ editor.dispatchEvent(paste);
385
+ if (editorText(editor).trim() !== "") return true;
386
+ } catch {
387
+ /* 下一级兜底 */
388
+ }
389
+ try {
390
+ editor.textContent = text;
391
+ let input;
392
+ try {
393
+ input = new win.InputEvent("input", { bubbles: true, inputType: "insertText", data: text });
394
+ } catch {
395
+ input = new win.Event("input", { bubbles: true });
396
+ }
397
+ editor.dispatchEvent(input);
398
+ } catch {
399
+ return false;
400
+ }
401
+ return editorText(editor).trim() !== "";
402
+ }
403
+ /**
404
+ * 安装「空输入点发送」增强:命中空输入状态下的发送按钮时,自动填入固定文案并只提交一次。
405
+ *
406
+ * 为什么用 pointerdown 而不是 click:空输入时发送按钮是 disabled,click 根本不会派发;
407
+ * 有些浏览器还会把 pointerdown 重定向到父节点,所以再用 elementFromPoint 按坐标兜底。
408
+ * 一旦接管:preventDefault + stopPropagation,聚焦编辑器、写入文案,再等按钮变可用后
409
+ * 程序化点击一次。全程有重入保护与有界超时,失败只 warn 一次、不重试轰炸。
410
+ *
411
+ * @returns 卸载函数(移除监听、清掉轮询与一次性 click 守卫)。
412
+ */
413
+ function installEmptySend() {
414
+ const doc = typeof document === "undefined" ? void 0 : document;
415
+ const win = typeof window === "undefined" ? void 0 : window;
416
+ if (doc === void 0 || win === void 0 || typeof doc.addEventListener !== "function" || typeof doc.querySelector !== "function" || typeof win.setTimeout !== "function" || typeof win.clearTimeout !== "function") return () => {};
417
+ let disposed = false;
418
+ let inFlight = false;
419
+ let timer = 0;
420
+ /** 手势期间以及提交后短暂窗口内吞掉发送按钮的 click,避免同一次手势提交两次。 */
421
+ let clickGuard = null;
422
+ let guardTimer = 0;
423
+ const warn = (message) => {
424
+ try {
425
+ win.console?.warn?.(message);
426
+ } catch {
427
+ /* 记日志本身不该影响输入框 */
428
+ }
429
+ };
430
+ const swallow = (event) => {
431
+ try {
432
+ event.preventDefault?.();
433
+ } catch {
434
+ /* 忽略 */
435
+ }
436
+ try {
437
+ event.stopPropagation?.();
438
+ } catch {
439
+ /* 忽略 */
440
+ }
441
+ };
442
+ const removeClickGuard = () => {
443
+ if (guardTimer !== 0) {
444
+ try {
445
+ win.clearTimeout(guardTimer);
446
+ } catch {
447
+ /* 忽略 */
448
+ }
449
+ guardTimer = 0;
450
+ }
451
+ if (clickGuard === null) return;
452
+ try {
453
+ doc.removeEventListener("click", clickGuard, true);
454
+ } catch {
455
+ /* 忽略 */
456
+ }
457
+ clickGuard = null;
458
+ };
459
+ /**
460
+ * 挂上 click 守卫:只吞发送按钮上的 click,吞到一次就摘掉。
461
+ * @param graceMs - 大于 0 时到点自动摘掉(提交后的短暂窗口);0 表示交给 release 摘。
462
+ */
463
+ const armClickGuard = (graceMs) => {
464
+ if (clickGuard !== null) return;
465
+ const guard = (clickEvent) => {
466
+ if (sendButtonOf(clickEvent, doc) === null) return;
467
+ swallow(clickEvent);
468
+ removeClickGuard();
469
+ };
470
+ clickGuard = guard;
471
+ try {
472
+ doc.addEventListener("click", guard, true);
473
+ } catch {
474
+ clickGuard = null;
475
+ return;
476
+ }
477
+ if (graceMs > 0) {
478
+ guardTimer = win.setTimeout(() => {
479
+ guardTimer = 0;
480
+ removeClickGuard();
481
+ }, graceMs);
482
+ }
483
+ };
484
+ const release = () => {
485
+ inFlight = false;
486
+ if (timer !== 0) {
487
+ try {
488
+ win.clearTimeout(timer);
489
+ } catch {
490
+ /* 忽略 */
491
+ }
492
+ timer = 0;
493
+ }
494
+ removeClickGuard();
495
+ };
496
+ const submit = (button) => {
497
+ if (disposed || !inFlight) {
498
+ release();
499
+ return;
500
+ }
501
+ // 先摘守卫,否则会把这次程序化点击也吞掉。
502
+ removeClickGuard();
503
+ if (timer !== 0) {
504
+ try {
505
+ win.clearTimeout(timer);
506
+ } catch {
507
+ /* 忽略 */
508
+ }
509
+ timer = 0;
510
+ }
511
+ try {
512
+ button.click();
513
+ } catch {
514
+ warn(WARN_TIMEOUT);
515
+ }
516
+ // 提交后进入短暂冷却:同一手势可能补发一个原生 click(按钮刚变可用),
517
+ // 用户也可能双击;这段时间内既吞 click 也继续吞 pointerdown,
518
+ // 否则「继续任务」会被发两次。冷却结束由 release 统一收尾。
519
+ armClickGuard(CLICK_GUARD_MS);
520
+ timer = win.setTimeout(() => {
521
+ timer = 0;
522
+ release();
523
+ }, CLICK_GUARD_MS);
524
+ };
525
+ const poll = (button, attempt) => {
526
+ if (disposed || !inFlight) return;
527
+ if (button.isConnected === false) {
528
+ warn(WARN_TIMEOUT);
529
+ release();
530
+ return;
531
+ }
532
+ if (button.disabled !== true) {
533
+ submit(button);
534
+ return;
535
+ }
536
+ if (attempt >= SEND_POLL_ATTEMPTS) {
537
+ warn(WARN_TIMEOUT);
538
+ release();
539
+ return;
540
+ }
541
+ timer = win.setTimeout(() => {
542
+ timer = 0;
543
+ poll(button, attempt + 1);
544
+ }, SEND_POLL_INTERVAL);
545
+ };
546
+ const takeOver = (event) => {
547
+ if (disposed) return;
548
+ if (event?.button !== void 0 && event.button !== 0) return;
549
+ const button = sendButtonOf(event, doc);
550
+ if (button === null) return;
551
+ // 重入保护:从接管到提交完成期间,重复 pointerdown 一律吞掉,绝不重复发送。
552
+ if (inFlight) {
553
+ swallow(event);
554
+ return;
555
+ }
556
+ const card = composerCardOf(button);
557
+ const editor = editorOf(card, doc);
558
+ if (editor === null) return;
559
+ if (event?.isComposing === true || hasAttr(editor, "data-composer-composing")) return;
560
+ if (!editorReady(editor) || hasEditorDecoration(editor)) return;
561
+ if (commandMenuOpen(card) || hasAttachments(card, editor)) return;
562
+ if (editorText(editor).trim() !== "") return;
563
+ if (button.disabled !== true) return;
564
+ swallow(event);
565
+ inFlight = true;
566
+ // 吞掉这次手势随后产生的原生 click:文案写入后按钮会被 React 变可用,
567
+ // 用户松手仍可能生成一次 click;不拦就会和程序化点击一起提交两次。
568
+ armClickGuard(0);
569
+ let written = false;
570
+ try {
571
+ focusEditor(editor);
572
+ written = writeTextToEditor(editor, EMPTY_SEND_TEXT, doc, win);
573
+ } catch {
574
+ written = false;
575
+ }
576
+ if (!written) {
577
+ warn(WARN_WRITE);
578
+ release();
579
+ return;
580
+ }
581
+ poll(button, 0);
582
+ };
583
+ doc.addEventListener("pointerdown", takeOver, true);
584
+ return () => {
585
+ disposed = true;
586
+ release();
587
+ try {
588
+ doc.removeEventListener("pointerdown", takeOver, true);
589
+ } catch {
590
+ /* 忽略 */
591
+ }
592
+ };
593
+ }
594
+ //#endregion
241
595
  //#region 插件挂载
242
596
  /** 必需服务:插槽注册表。 */
243
597
  const inject = ["slots"];
@@ -257,6 +611,7 @@ window.__ModuleLoader__.load({
257
611
  name: "conversation.approval.detail",
258
612
  priority: -1
259
613
  }, ApprovalGuide));
614
+ if (typeof ctx.effect === "function") ctx.effect(() => installEmptySend(), "dsh-approval-guide: 空输入自动发送");
260
615
  }
261
616
  //#endregion
262
617
  exports.apply = apply;
@@ -266,7 +621,10 @@ window.__ModuleLoader__.load({
266
621
  explainApproval,
267
622
  parseCallArgs,
268
623
  parseSandboxReason,
269
- findCorrelatedCall
624
+ findCorrelatedCall,
625
+ installEmptySend,
626
+ writeTextToEditor,
627
+ EMPTY_SEND_TEXT
270
628
  };
271
629
  return module.exports;
272
630
  }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Approval Guide",
4
+ "description": "Adds Chinese action, risk and rationale notes to approval prompts."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "审批说明",
4
+ "description": "为审批弹窗补充中文动作、风险与依据说明"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@fish-under-sea/dsh-approval-guide",
3
- "version": "1.1.0",
3
+ "version": "2.0.1",
4
+ "icon": "./icon.png",
4
5
  "description": "在 DSH Web GUI 的审批弹窗里追加中文说明:这次审批会做什么、有什么风险、依据是什么。原英文理由与命令原文保留显示。",
5
6
  "type": "module",
6
7
  "main": "./lib/index.js",
@@ -11,11 +12,15 @@
11
12
  "./client": {
12
13
  "default": "./lib/client.js"
13
14
  },
15
+ "./locale/en.json": "./locale/en.json",
16
+ "./locale/zh.json": "./locale/zh.json",
14
17
  "./package.json": "./package.json"
15
18
  },
16
19
  "files": [
17
20
  "lib",
18
21
  "cordis.patch.yml",
22
+ "icon.png",
23
+ "locale",
19
24
  "README.md",
20
25
  "README.en.md",
21
26
  "LICENSE"