@dsh-workbench/shared 1.5.2-rc.1 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/api/blocker-table.d.ts +11 -3
  2. package/dist/api/blocker-table.js +88 -49
  3. package/dist/components/card/CardBoundary.d.ts +17 -4
  4. package/dist/components/card/CardBoundary.js +55 -12
  5. package/dist/components/card/CardBoundary.module.css +10 -0
  6. package/dist/contract/blocker.d.ts +4 -0
  7. package/dist/contract/blocker.js +25 -12
  8. package/dist/host/adapters/port-types.d.ts +2 -0
  9. package/dist/host/supply/preflight.d.ts +16 -1
  10. package/dist/i18n/en.js +46 -10
  11. package/dist/i18n/index.d.ts +47 -11
  12. package/dist/i18n/zh.d.ts +46 -10
  13. package/dist/i18n/zh.js +46 -10
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +2 -0
  16. package/dist/lib/blocker-action.d.ts +1 -0
  17. package/dist/lib/copy-flash.d.ts +10 -0
  18. package/dist/lib/copy-flash.js +30 -0
  19. package/dist/lib/fault-prompt.d.ts +40 -0
  20. package/dist/lib/fault-prompt.js +44 -0
  21. package/package.json +1 -1
  22. package/src/api/__tests__/blocker-table.test.ts +112 -3
  23. package/src/api/blocker-table.ts +109 -54
  24. package/src/components/card/CardBoundary.module.css +10 -0
  25. package/src/components/card/CardBoundary.tsx +83 -12
  26. package/src/components/card/__tests__/card-boundary.test.tsx +137 -0
  27. package/src/contract/blocker.ts +31 -12
  28. package/src/host/adapters/port-types.ts +2 -0
  29. package/src/host/runtime/__tests__/dsh-compat.test.ts +1 -1
  30. package/src/host/supply/preflight.ts +18 -2
  31. package/src/i18n/en.ts +46 -10
  32. package/src/i18n/zh.ts +46 -10
  33. package/src/index.ts +2 -0
  34. package/src/lib/__tests__/copy-flash.test.ts +72 -0
  35. package/src/lib/blocker-action.ts +1 -0
  36. package/src/lib/copy-flash.ts +34 -0
  37. package/src/lib/fault-prompt.ts +90 -0
@@ -15,15 +15,28 @@ export interface PreflightStep {
15
15
  }
16
16
 
17
17
  export interface PreflightDiyGap {
18
+ readonly kind: 'older-dsh' | 'broken-row' | 'preset-missing';
18
19
  readonly rows: readonly string[];
19
20
  readonly detail: string;
20
- readonly command: string;
21
+ readonly command?: string;
22
+ }
23
+
24
+ export interface PreflightPaths {
25
+ readonly workbenchRoot: string;
26
+ readonly dshHome: string;
27
+ }
28
+
29
+ export interface PreflightHostFacts {
30
+ readonly version?: string;
31
+ readonly from?: string;
32
+ readonly profileDir?: string;
33
+ readonly verified?: string;
21
34
  }
22
35
 
23
36
  export type PreflightHostTier = 'newer' | 'older';
24
37
 
25
38
  export type PreflightHostStanding =
26
- | { readonly tier: 'ok'; readonly log?: readonly string[] }
39
+ | { readonly tier: 'ok'; readonly log?: readonly string[]; readonly facts?: PreflightHostFacts }
27
40
  | PreflightHostGap;
28
41
 
29
42
  export interface PreflightHostGap {
@@ -32,6 +45,7 @@ export interface PreflightHostGap {
32
45
  readonly verified: string;
33
46
  readonly command?: string;
34
47
  readonly log?: readonly string[];
48
+ readonly facts?: PreflightHostFacts;
35
49
  }
36
50
 
37
51
  export interface PreflightSnapshot {
@@ -43,6 +57,8 @@ export interface PreflightSnapshot {
43
57
  readonly guidance?: PreflightGuidance;
44
58
  readonly bridgeIssues?: readonly PreflightBridgeIssue[];
45
59
  readonly hostGap?: PreflightHostGap;
60
+ readonly hostFacts?: PreflightHostFacts;
61
+ readonly paths?: PreflightPaths;
46
62
  readonly diyGap?: PreflightDiyGap;
47
63
  readonly canWakeBrowser?: boolean;
48
64
  readonly extensionDir?: string;
package/src/i18n/en.ts CHANGED
@@ -247,7 +247,7 @@ export const en: Record<keyof WorkbenchMessages, string> = {
247
247
  'panels.market.failure.askAgentText': 'Installing this module could not write: `{command}` returned exit code {code} at {path}. Check whether the sandbox or file permissions blocked it, then install again at a writable location.',
248
248
  'panels.market.failure.askAgentAuth': 'Installing this module failed: the private source {registry} rejected the request (401/403): `{command}` returned exit code {code}.\nOutput: {reason}\nFirst check whether this machine has credentials for that source (`_authToken` in ~/.npmrc). Log in, add the token, or switch to an account with access, then retry.',
249
249
  'panels.market.failure.askAgentUnknown': 'Installing this module failed: `{command}` returned exit code {code}, and the cause could not be identified automatically.\nOutput: {reason}\nUse that output to pin down the cause (private source not logged in? network down? wrong package name?), then retry.',
250
- 'panels.market.failure.askAgentHint': 'Paste it into the chat so the agent can continue.',
250
+ 'panels.market.failure.askAgentHint': 'Paste it into the chat; the agent will continue the diagnosis.',
251
251
  'panels.market.failure.recheck': 'Check again',
252
252
  'panels.market.failure.showOutput': 'Show install output',
253
253
  'panels.market.failure.hideOutput': 'Hide install output',
@@ -717,7 +717,7 @@ export const en: Record<keyof WorkbenchMessages, string> = {
717
717
  'panels.boardReadFailed': 'Could not read the panel setup',
718
718
  'panels.boardReadFailedHint': 'This is not "no modules": the host failed to read the setup. Try again; if it keeps failing, check the log',
719
719
  'panels.retry': 'Retry',
720
- 'panels.cardBroken': 'This module failed to start: {unit} ({reason})',
720
+ 'panels.cardBroken': 'This module failed to start: {unit}',
721
721
  'panels.cardRetry': 'Retry',
722
722
  'panels.empty': 'This panel has no modules yet.',
723
723
  'panels.emptyHint': 'You can also tell the agent directly: “add a module to the panel”.',
@@ -739,17 +739,17 @@ export const en: Record<keyof WorkbenchMessages, string> = {
739
739
  'env.bridge.extensionOffline': 'The extension is not connected. Choose either install method: (1) click the link below to install it from the Chrome Web Store; (2) load a local copy: open chrome://extensions, turn on Developer mode in the top right, click Load unpacked, and choose the extension folder. When done, come back and click Retry.',
740
740
  'env.bridge.extensionLocal': 'The extension is not connected. Choose either install method: (1) use the copy shipped with the workbench: open chrome://extensions, turn on Developer mode in the top right, click Load unpacked, and choose {dir}; (2) click the link below to install it from the Chrome Web Store. When done, come back and click Retry.',
741
741
  'env.bridge.hold': 'The browser is not connected yet. Fix it with the steps below and click Retry, or enter the workbench first.',
742
- 'env.bridge.unknown': 'Could not tell what went wrong. Expand the raw output and follow the steps in it.',
742
+ 'env.bridge.unknown': 'The browser connection reported a problem this workbench cannot classify. You can expand the original output, or let the agent diagnose.',
743
743
  'env.fix.title': 'How to fix this',
744
744
  'env.fix.why': 'The workbench uses its own bundled background tool, separate from the one installed in your terminal. It is not installed yet on this machine.',
745
- 'env.fix.whyPath': 'The background tool is installed, but this environment still cannot find it; usually a PATH or terminal-session issue.',
745
+ 'env.fix.whyPath': 'The background tool is installed, but this environment still cannot find it.',
746
746
  'env.fix.whyShell': 'The workbench cannot reach this machine’s command line, so it cannot fetch data. This step cannot be completed here; an administrator needs to fix the background environment.',
747
747
  'env.fix.whyHost': 'The workbench runs a few checks on the command line and collects the results. The command was sent this time, but no result came back. The tools themselves are usually fine; reinstalling Node / npm / pnpm will not help.',
748
748
  'env.fix.step': 'Run the command below in a terminal, then click Retry after installation:',
749
749
  'env.fix.stepRetry': 'Click Retry to install again. If it still fails, you can enter the workbench first; once installed, restart the workbench to use it.',
750
750
  'env.fix.stepPath': 'Open a new terminal window, or make sure npm’s global bin directory is on PATH, then click Retry.',
751
751
  'env.fix.stepShell': 'Restart the workbench (or dsh). If it keeps happening, the workbench still cannot reach the command line.',
752
- 'env.fix.stepHost': 'Quit the workbench completely (including the tray icon), clear the dsh-* leftovers in the system temp directory, then open it again. If it keeps happening, update dsh.',
752
+ 'env.fix.stepHost': 'Quit the workbench completely (including the tray icon), clear the dsh-* leftovers in the system temp directory, then open it again.',
753
753
  'env.fix.permission': 'Permission denied. Rerun the command with sudo, or point npm’s global directory at your user directory first.',
754
754
  'env.fix.network': 'The network is unreachable. Check your network or proxy settings and try again.',
755
755
  'env.fix.details': 'Details (for troubleshooting)',
@@ -763,13 +763,49 @@ export const en: Record<keyof WorkbenchMessages, string> = {
763
763
  'env.bridge.continue': 'Enter the workbench anyway',
764
764
  'env.diy.ok': 'Available',
765
765
  'env.diy.short': 'Unavailable for now',
766
- 'env.diy.hold': 'DIY mode is unavailable for now. Upgrade dsh and click Retry, or enter the workbench first.',
767
- 'env.diy.why': 'The dsh on this machine is older than the version this workbench was verified against, so DIY mode is unavailable. Panels and other features are unaffected. Upgrade dsh and restart, then try again.',
768
- 'env.diy.rows': 'This dsh version is missing the following: {rows}.',
769
- 'env.diy.noRow': 'The startup check did not find “Workbench DIY mode” in dsh’s mode list. This workbench install most likely does not include the matching mode patch.',
770
- 'env.diy.step': 'Upgrade dsh, then restart the workbench:',
766
+ 'env.diy.hold': 'DIY mode is unavailable. You can retry, or let the agent diagnose.',
767
+ 'env.diy.older.why': 'This machine runs {host} {runtime}; this workbench was verified on {verified}. Upgrade {host} and restart; panels and other features are unaffected.',
768
+ 'env.diy.older.step': 'Upgrade {host}, then restart the workbench:',
769
+ 'env.diy.broken.why': 'These rows of Workbench DIY mode did not start: {rows}.',
770
+ 'env.diy.broken.hint': 'The cause is in the {host} startup log. You can let the agent diagnose.',
771
+ 'env.diy.presetMissing.why': 'The startup check did not find Workbench DIY mode in the {host} mode list.',
772
+ 'env.diy.presetMissing.hint': 'This workbench install is most likely incomplete. Reinstall the workbench.',
771
773
  'env.diy.continue': 'Enter the workbench anyway',
772
774
 
775
+ 'askAgent.title': 'Agent diagnosis needed',
776
+ 'askAgent.copy': 'Copy for the agent',
777
+ 'askAgent.copied': 'Copied',
778
+ 'askAgent.hint': 'Paste it into the chat; the agent will continue the diagnosis.',
779
+ 'askAgent.prompt.head': 'The workbench ran into a problem that needs your diagnosis.',
780
+ 'askAgent.prompt.whereOnly': 'Where: {screen}',
781
+ 'askAgent.screen.board': 'Board',
782
+ 'askAgent.screen.workbench': 'Workbench UI',
783
+ 'entry.failed': 'This part failed to load.',
784
+ 'askAgent.screen.settings': 'Config sync',
785
+ 'askAgent.prompt.where': 'Where: {screen} / {step}',
786
+ 'askAgent.prompt.why': 'Symptom: {detail}',
787
+ 'askAgent.prompt.rows': 'Rows that did not start: {rows}',
788
+ 'askAgent.prompt.issue': 'Unrecognized problem: {issue}',
789
+ 'askAgent.prompt.reason': 'Reason: {reason}',
790
+ 'askAgent.prompt.host': 'Running {host} {version}; this workbench was verified on {verified}.',
791
+ 'askAgent.prompt.deployment': 'Opened as: {deployment}',
792
+ 'askAgent.deployment.desktop': 'desktop app',
793
+ 'askAgent.deployment.web': 'web',
794
+ 'askAgent.prompt.configDir': 'Workbench config directory: {configDir}',
795
+ 'askAgent.prompt.logDir': 'dsh startup log directory: {dir} (latest file)',
796
+ 'askAgent.prompt.tried': 'Already tried: retried {n} times.',
797
+ 'askAgent.prompt.evidence': 'Evidence: {files}',
798
+ 'askAgent.prompt.ask': 'Read the evidence first, then state a confirmed cause and next step; do not guess.',
799
+ 'diag.code.preflightDiyRowBroken': 'Some rows of DIY mode did not start.',
800
+ 'diag.hint.preflightDiyRowBroken': 'The cause is in the dsh startup log. You can let the agent diagnose.',
801
+ 'diag.code.preflightDiyPresetMissing': 'Workbench DIY mode was not found.',
802
+ 'diag.hint.preflightDiyPresetMissing': 'This workbench install is most likely incomplete. Reinstall the workbench.',
803
+ 'diag.code.preflightBridgeHold': 'The browser connection was not established.',
804
+ 'diag.hint.preflightBridgeHold': 'Follow the steps in the startup check, then retry.',
805
+ 'diag.code.preflightHostOlder': 'The running version is older than the verified version.',
806
+ 'diag.hint.preflightHostOlder': 'Upgrade, then restart the workbench.',
807
+ 'diag.code.preflightHostNewer': 'The running version is newer than the verified version.',
808
+ 'diag.hint.preflightHostNewer': 'Keep working; update the workbench if something displays incorrectly.',
773
809
  'env.step.hostVersion': 'Check {host} version',
774
810
  'env.hostVersion.newer': 'Unverified',
775
811
  'env.hostVersion.older': 'Too old',
package/src/i18n/zh.ts CHANGED
@@ -243,7 +243,7 @@ export const zh = {
243
243
  'panels.market.failure.askAgentText': '安装这个模块时无法写入:`{command}` 退出码为 {code},受阻于 {path}。请确认是沙箱拦截还是权限问题,并换一个可写入的位置重新安装。',
244
244
  'panels.market.failure.askAgentAuth': '安装这个模块时,私有源 {registry} 拒绝了请求(401/403):`{command}` 退出码为 {code}。\n输出:{reason}\n先确认这台机器有没有这个源的凭据(~/.npmrc 里的 _authToken):登录、补 token 或换一个有权限的账号,再重试。',
245
245
  'panels.market.failure.askAgentUnknown': '安装这个模块失败:`{command}` 退出码为 {code},原因没能自动认出来。\n输出:{reason}\n请按这段输出定位(私有源没登录?网络不通?包名不对?),再重试。',
246
- 'panels.market.failure.askAgentHint': '粘贴到对话里,让 agent 继续处理。',
246
+ 'panels.market.failure.askAgentHint': '粘贴到对话里,agent 会继续诊断。',
247
247
  'panels.market.failure.recheck': '再次检查',
248
248
  'panels.market.failure.showOutput': '查看安装输出',
249
249
  'panels.market.failure.hideOutput': '收起安装输出',
@@ -712,7 +712,7 @@ export const zh = {
712
712
  'panels.boardReadFailed': '面板配置没读出来',
713
713
  'panels.boardReadFailedHint': '这不是「没有模块」:工作台后台读配置失败了,重试一次;还是不行就看日志',
714
714
  'panels.retry': '重试',
715
- 'panels.cardBroken': '这个模块启动失败:{unit}({reason})',
715
+ 'panels.cardBroken': '这个模块启动失败:{unit}',
716
716
  'panels.cardRetry': '重试',
717
717
  'panels.empty': '这个面板还没有模块。',
718
718
  'panels.emptyHint': '也可以直接告诉 agent:「把某个模块加到面板」。',
@@ -734,17 +734,17 @@ export const zh = {
734
734
  'env.bridge.extensionOffline': '扩展没有连接。可以任选一种安装方式:① 点击下面的链接,从 Chrome 应用商店安装;② 加载本地副本:打开 chrome://extensions,在右上角开启「开发者模式」,点击「加载已解压的扩展程序」,选择扩展目录。安装完成后回来点击「重试」。',
735
735
  'env.bridge.extensionLocal': '扩展没有连接。可以任选一种安装方式:① 使用工作台自带的副本:打开 chrome://extensions,在右上角开启「开发者模式」,点击「加载已解压的扩展程序」,选择 {dir};② 点击下面的链接,从 Chrome 应用商店安装。安装完成后回来点击「重试」。',
736
736
  'env.bridge.hold': '浏览器还没有连接。请按下面的步骤修复后点击「重试」,也可以先进入工作台。',
737
- 'env.bridge.unknown': '无法识别问题类型:请展开原文,按其中的步骤处理。',
737
+ 'env.bridge.unknown': '浏览器连接有问题,但工作台没能识别是哪一类。可以展开原文查看,也可以让 agent 诊断。',
738
738
  'env.fix.title': '解决方法',
739
739
  'env.fix.why': '工作台使用自带的后台工具,与你在终端中安装的那份相互独立。这台机器上还没有安装完成。',
740
- 'env.fix.whyPath': '后台工具已经安装,但当前环境仍然找不到它,通常是 PATH 或终端会话的问题。',
740
+ 'env.fix.whyPath': '后台工具已经安装,但当前环境仍然找不到它。',
741
741
  'env.fix.whyShell': '工作台无法访问本机命令行,因此无法获取数据。这一步无法在这里完成,需要管理员处理后台环境。',
742
742
  'env.fix.whyHost': '工作台需要通过命令行运行几项检查并取回结果。本次命令已经发出,但结果没有返回。工具本身通常没有问题,重新安装 Node / npm / pnpm 不会有帮助。',
743
743
  'env.fix.step': '请在终端中运行下面的命令,安装完成后点击「重试」:',
744
744
  'env.fix.stepRetry': '点击「重试」重新安装。如果仍然失败,也可以先进入工作台,安装完成后重启工作台即可使用。',
745
745
  'env.fix.stepPath': '请新开一个终端窗口,或确认 npm 的全局 bin 目录在 PATH 中,然后点击「重试」。',
746
746
  'env.fix.stepShell': '请重启工作台(或 dsh)。如果反复出现,说明工作台仍然无法连接命令行。',
747
- 'env.fix.stepHost': '请完全退出工作台(包括托盘图标),清理系统临时目录中以 dsh- 开头的残留文件,然后重新打开。如果反复出现,请升级 dsh。',
747
+ 'env.fix.stepHost': '请完全退出工作台(包括托盘图标),清理系统临时目录中以 dsh- 开头的残留文件,然后重新打开。',
748
748
  'env.fix.permission': '权限不足。请在命令前加 sudo 后重新运行,或先把 npm 全局目录配置到你的用户目录。',
749
749
  'env.fix.network': '网络不通。请检查网络或代理设置后重试。',
750
750
  'env.fix.details': '详细输出(排障用)',
@@ -758,13 +758,49 @@ export const zh = {
758
758
  'env.bridge.continue': '先进入工作台',
759
759
  'env.diy.ok': '可用',
760
760
  'env.diy.short': '暂时不可用',
761
- 'env.diy.hold': 'DIY 模式暂时不可用。请升级 dsh 后点击「重试」,也可以先进入工作台。',
762
- 'env.diy.why': '这台机器上的 dsh 比工作台验证过的版本旧,因此无法使用 DIY 模式;面板和其他功能不受影响。升级 dsh 后重启再试。',
763
- 'env.diy.rows': '当前版本的 dsh 缺少以下内容:{rows}。',
764
- 'env.diy.noRow': '启动检查没有在 dsh 的模式列表中找到「工作台 DIY 模式」,多半是这次工作台安装没有包含对应的模式补丁。',
765
- 'env.diy.step': '升级 dsh,然后重启一次工作台:',
761
+ 'env.diy.hold': 'DIY 模式暂时不可用。可以重试,也可以让 agent 诊断。',
762
+ 'env.diy.older.why': '这台机器上的 {host} 是 {runtime},工作台验证过的是 {verified}。请升级 {host} 后重启;面板与其他功能不受影响。',
763
+ 'env.diy.older.step': '升级 {host},然后重启工作台:',
764
+ 'env.diy.broken.why': '「工作台 DIY 模式」里这几行没有启动:{rows}。',
765
+ 'env.diy.broken.hint': '原因在 {host} 的启动日志里,可以让 agent 诊断。',
766
+ 'env.diy.presetMissing.why': '启动检查没有在 {host} 的模式列表里找到「工作台 DIY 模式」。',
767
+ 'env.diy.presetMissing.hint': '多半是这次工作台安装不完整。请重新安装一次工作台。',
766
768
  'env.diy.continue': '先进入工作台',
767
769
 
770
+ 'askAgent.title': '需要 agent 诊断',
771
+ 'askAgent.copy': '复制给 agent',
772
+ 'askAgent.copied': '已复制',
773
+ 'askAgent.hint': '粘贴到对话里,agent 会继续诊断。',
774
+ 'askAgent.prompt.head': '工作台遇到一个问题,需要你定位。',
775
+ 'askAgent.prompt.whereOnly': '位置:{screen}',
776
+ 'askAgent.screen.board': '看板',
777
+ 'askAgent.screen.workbench': '工作台界面',
778
+ 'entry.failed': '这里没有加载起来。',
779
+ 'askAgent.screen.settings': '配置同步',
780
+ 'askAgent.prompt.where': '位置:{screen} · {step}',
781
+ 'askAgent.prompt.why': '现象:{detail}',
782
+ 'askAgent.prompt.rows': '没有启动的行:{rows}',
783
+ 'askAgent.prompt.issue': '未能识别的问题:{issue}',
784
+ 'askAgent.prompt.reason': '原因:{reason}',
785
+ 'askAgent.prompt.host': '运行的是 {host} {version},工作台验证过的是 {verified}。',
786
+ 'askAgent.prompt.deployment': '打开方式:{deployment}',
787
+ 'askAgent.deployment.desktop': '桌面版',
788
+ 'askAgent.deployment.web': '网页版',
789
+ 'askAgent.prompt.configDir': '工作台配置目录:{configDir}',
790
+ 'askAgent.prompt.logDir': 'dsh 启动日志目录:{dir}(最新一份)',
791
+ 'askAgent.prompt.tried': '已经试过:重试 {n} 次。',
792
+ 'askAgent.prompt.evidence': '证据文件:{files}',
793
+ 'askAgent.prompt.ask': '先读这些证据,给出确定的原因和下一步;不要猜。',
794
+ 'diag.code.preflightDiyRowBroken': 'DIY 模式的几行没有启动。',
795
+ 'diag.hint.preflightDiyRowBroken': '原因在 dsh 的启动日志里,可以让 agent 诊断。',
796
+ 'diag.code.preflightDiyPresetMissing': '没有找到「工作台 DIY 模式」。',
797
+ 'diag.hint.preflightDiyPresetMissing': '多半是这次工作台安装不完整。请重新安装一次工作台。',
798
+ 'diag.code.preflightBridgeHold': '浏览器连接没有建立。',
799
+ 'diag.hint.preflightBridgeHold': '请按启动检查里的步骤修复后重试。',
800
+ 'diag.code.preflightHostOlder': '工作台运行的版本低于验证过的版本。',
801
+ 'diag.hint.preflightHostOlder': '请升级后重启工作台。',
802
+ 'diag.code.preflightHostNewer': '工作台运行的版本高于验证过的版本。',
803
+ 'diag.hint.preflightHostNewer': '可以继续使用;显示异常时再更新工作台。',
768
804
  'env.step.hostVersion': '检查 {host} 版本',
769
805
  'env.hostVersion.newer': '未验证',
770
806
  'env.hostVersion.older': '版本过低',
package/src/index.ts CHANGED
@@ -91,7 +91,9 @@ export * from './lib/board-fact.js';
91
91
  export * from './lib/bundle-requirements.js';
92
92
  export * from './lib/busy.js';
93
93
  export * from './lib/concurrency.js';
94
+ export * from './lib/copy-flash.js';
94
95
  export * from './lib/dsh-client.js';
96
+ export * from './lib/fault-prompt.js';
95
97
  export * from './lib/form-problem.js';
96
98
  export * from './lib/git-address.js';
97
99
  export * from './lib/market-index.js';
@@ -0,0 +1,72 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
4
+ writeClipboard: vi.fn(async () => true),
5
+ }));
6
+
7
+ import { writeClipboard } from '@deepseek-ai/dsh-client-ui-primitives';
8
+ import { createCopyFlash } from '../copy-flash.js';
9
+
10
+ afterEach(() => {
11
+ vi.useRealTimers();
12
+ });
13
+
14
+ describe('复制一下亮一会儿再复原', () => {
15
+ it('★ 成功:先亮,到点复原', async () => {
16
+ vi.useFakeTimers();
17
+ const seen: boolean[] = [];
18
+ const flash = createCopyFlash(1500);
19
+
20
+ flash.copy('提示词', (copied) => seen.push(copied));
21
+ await Promise.resolve();
22
+ await Promise.resolve();
23
+ expect(seen).toEqual([true]);
24
+
25
+ vi.advanceTimersByTime(1500);
26
+ expect(seen).toEqual([true, false]);
27
+ flash.dispose();
28
+ });
29
+
30
+ it('★ 复制没成功:按钮不动(不假装复制了)', async () => {
31
+ vi.mocked(writeClipboard).mockResolvedValueOnce(false);
32
+ const seen: boolean[] = [];
33
+ const flash = createCopyFlash(1500);
34
+
35
+ flash.copy('提示词', (copied) => seen.push(copied));
36
+ await Promise.resolve();
37
+ await Promise.resolve();
38
+ expect(seen).toEqual([]);
39
+ flash.dispose();
40
+ });
41
+
42
+ it('★ 连续点两次:只有一条计时器,旧的不再回调', async () => {
43
+ vi.useFakeTimers();
44
+ const seen: boolean[] = [];
45
+ const flash = createCopyFlash(1500);
46
+
47
+ flash.copy('第一次', (copied) => seen.push(copied));
48
+ await Promise.resolve();
49
+ await Promise.resolve();
50
+ flash.copy('第二次', (copied) => seen.push(copied));
51
+ await Promise.resolve();
52
+ await Promise.resolve();
53
+ vi.advanceTimersByTime(1500);
54
+
55
+ expect(seen).toEqual([true, true, false]);
56
+ flash.dispose();
57
+ });
58
+
59
+ it('★ dispose 之后到点不再回调(组件已卸载)', async () => {
60
+ vi.useFakeTimers();
61
+ const seen: boolean[] = [];
62
+ const flash = createCopyFlash(1500);
63
+
64
+ flash.copy('提示词', (copied) => seen.push(copied));
65
+ await Promise.resolve();
66
+ await Promise.resolve();
67
+ flash.dispose();
68
+ vi.advanceTimersByTime(1500);
69
+
70
+ expect(seen).toEqual([true]);
71
+ });
72
+ });
@@ -10,6 +10,7 @@ export interface BlockerActionShape {
10
10
  readonly kind: string;
11
11
  readonly label: string;
12
12
  readonly text?: string | undefined;
13
+ readonly prompt?: string | undefined;
13
14
  }
14
15
 
15
16
  /**
@@ -0,0 +1,34 @@
1
+ import { writeClipboard } from '@deepseek-ai/dsh-client-ui-primitives';
2
+
3
+ export interface CopyFlash {
4
+ copy(text: string, onCopied: (copied: boolean) => void): void;
5
+ dispose(): void;
6
+ }
7
+
8
+ /**
9
+ * 「复制一下、按钮亮一会儿再复原」这件小事的计时器:组件只负责把结果写进自己的状态。
10
+ * @param ms - 「已复制」亮多久(毫秒)。
11
+ * @returns `copy` 成功后先给 `true`,到点再给 `false`;`dispose` 清掉未到点的计时器。
12
+ */
13
+ export function createCopyFlash(ms: number): CopyFlash {
14
+ let timer: ReturnType<typeof setTimeout> | undefined;
15
+ const clear = (): void => {
16
+ if (timer === undefined) return;
17
+ clearTimeout(timer);
18
+ timer = undefined;
19
+ };
20
+ return {
21
+ copy(text, onCopied) {
22
+ void writeClipboard(text).then((ok) => {
23
+ if (!ok) return;
24
+ onCopied(true);
25
+ clear();
26
+ timer = setTimeout(() => {
27
+ timer = undefined;
28
+ onCopied(false);
29
+ }, ms);
30
+ });
31
+ },
32
+ dispose: clear,
33
+ };
34
+ }
@@ -0,0 +1,90 @@
1
+ import type { Translate } from './dsh-client.js';
2
+
3
+ export interface PromptHostFacts {
4
+ readonly label: string;
5
+ readonly version: string;
6
+ readonly verified: string;
7
+ }
8
+
9
+ export interface PromptProblem {
10
+ readonly why?: string;
11
+ readonly rows?: string;
12
+ readonly issue?: string;
13
+ readonly reason?: string;
14
+ }
15
+
16
+ export interface PromptContext {
17
+ readonly deployment?: string;
18
+ readonly configDir?: string;
19
+ readonly logDir?: string;
20
+ readonly evidence?: string;
21
+ readonly tried?: number;
22
+ }
23
+
24
+ export interface PromptFacts {
25
+ readonly screen: string;
26
+ readonly step?: string;
27
+ readonly host?: PromptHostFacts;
28
+ readonly problem?: PromptProblem;
29
+ readonly context?: PromptContext;
30
+ }
31
+
32
+ /**
33
+ * 取一段多行文本里第一行有内容的,给提示词与卡片当「原文首行」。
34
+ * @param text - 可能为空或全是空行的原文。
35
+ * @returns 第一行非空文本,没有就 `undefined`。
36
+ */
37
+ export function firstLineOf(text: string | undefined): string | undefined {
38
+ const line = (text ?? '')
39
+ .split('\n')
40
+ .map((one) => one.trim())
41
+ .find((one) => one !== '');
42
+ return line === undefined ? undefined : line;
43
+ }
44
+
45
+ /**
46
+ * 把「哪里出的问题、看到什么、有什么证据」拼成一段可以直接粘给 agent 的提示词。
47
+ * 空的整行省略;`step` 不给就只写屏幕名。
48
+ * @param facts - 屏幕 / 步骤 / 版本对照 / 现象 / 现场上下文。
49
+ * @param t - 文案函数,键在 askAgent.* 下。
50
+ * @returns 多行提示词,最后一行是「先读证据再下结论」。
51
+ */
52
+ export function faultPromptOf(facts: PromptFacts, t: Translate): string {
53
+ const problem = facts.problem ?? {};
54
+ const context = facts.context ?? {};
55
+ const host = facts.host;
56
+ const pick = (key: string, params: Record<string, string | number> | undefined): string[] =>
57
+ params === undefined ? [] : [t(key, params)];
58
+ const where =
59
+ facts.step === undefined || facts.step.trim() === ''
60
+ ? t('askAgent.prompt.whereOnly', { screen: facts.screen })
61
+ : t('askAgent.prompt.where', { screen: facts.screen, step: facts.step });
62
+ const lines = [
63
+ t('askAgent.prompt.head'),
64
+ where,
65
+ ...pick('askAgent.prompt.why', problem.why === undefined ? undefined : { detail: problem.why }),
66
+ ...pick('askAgent.prompt.rows', problem.rows === undefined ? undefined : { rows: problem.rows }),
67
+ ...pick('askAgent.prompt.issue', problem.issue === undefined ? undefined : { issue: problem.issue }),
68
+ ...pick('askAgent.prompt.reason', problem.reason === undefined ? undefined : { reason: problem.reason }),
69
+ ...pick(
70
+ 'askAgent.prompt.host',
71
+ host === undefined ? undefined : { host: host.label, version: host.version, verified: host.verified },
72
+ ),
73
+ ...pick(
74
+ 'askAgent.prompt.deployment',
75
+ context.deployment === undefined ? undefined : { deployment: context.deployment },
76
+ ),
77
+ ...pick(
78
+ 'askAgent.prompt.configDir',
79
+ context.configDir === undefined ? undefined : { configDir: context.configDir },
80
+ ),
81
+ ...pick('askAgent.prompt.logDir', context.logDir === undefined ? undefined : { dir: context.logDir }),
82
+ ...pick(
83
+ 'askAgent.prompt.tried',
84
+ context.tried === undefined || context.tried <= 0 ? undefined : { n: context.tried },
85
+ ),
86
+ ...pick('askAgent.prompt.evidence', context.evidence === undefined ? undefined : { files: context.evidence }),
87
+ t('askAgent.prompt.ask'),
88
+ ];
89
+ return lines.join('\n');
90
+ }