@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
package/dist/i18n/zh.js CHANGED
@@ -239,7 +239,7 @@ export const zh = {
239
239
  'panels.market.failure.askAgentText': '安装这个模块时无法写入:`{command}` 退出码为 {code},受阻于 {path}。请确认是沙箱拦截还是权限问题,并换一个可写入的位置重新安装。',
240
240
  'panels.market.failure.askAgentAuth': '安装这个模块时,私有源 {registry} 拒绝了请求(401/403):`{command}` 退出码为 {code}。\n输出:{reason}\n先确认这台机器有没有这个源的凭据(~/.npmrc 里的 _authToken):登录、补 token 或换一个有权限的账号,再重试。',
241
241
  'panels.market.failure.askAgentUnknown': '安装这个模块失败:`{command}` 退出码为 {code},原因没能自动认出来。\n输出:{reason}\n请按这段输出定位(私有源没登录?网络不通?包名不对?),再重试。',
242
- 'panels.market.failure.askAgentHint': '粘贴到对话里,让 agent 继续处理。',
242
+ 'panels.market.failure.askAgentHint': '粘贴到对话里,agent 会继续诊断。',
243
243
  'panels.market.failure.recheck': '再次检查',
244
244
  'panels.market.failure.showOutput': '查看安装输出',
245
245
  'panels.market.failure.hideOutput': '收起安装输出',
@@ -700,7 +700,7 @@ export const zh = {
700
700
  'panels.boardReadFailed': '面板配置没读出来',
701
701
  'panels.boardReadFailedHint': '这不是「没有模块」:工作台后台读配置失败了,重试一次;还是不行就看日志',
702
702
  'panels.retry': '重试',
703
- 'panels.cardBroken': '这个模块启动失败:{unit}({reason})',
703
+ 'panels.cardBroken': '这个模块启动失败:{unit}',
704
704
  'panels.cardRetry': '重试',
705
705
  'panels.empty': '这个面板还没有模块。',
706
706
  'panels.emptyHint': '也可以直接告诉 agent:「把某个模块加到面板」。',
@@ -722,17 +722,17 @@ export const zh = {
722
722
  'env.bridge.extensionOffline': '扩展没有连接。可以任选一种安装方式:① 点击下面的链接,从 Chrome 应用商店安装;② 加载本地副本:打开 chrome://extensions,在右上角开启「开发者模式」,点击「加载已解压的扩展程序」,选择扩展目录。安装完成后回来点击「重试」。',
723
723
  'env.bridge.extensionLocal': '扩展没有连接。可以任选一种安装方式:① 使用工作台自带的副本:打开 chrome://extensions,在右上角开启「开发者模式」,点击「加载已解压的扩展程序」,选择 {dir};② 点击下面的链接,从 Chrome 应用商店安装。安装完成后回来点击「重试」。',
724
724
  'env.bridge.hold': '浏览器还没有连接。请按下面的步骤修复后点击「重试」,也可以先进入工作台。',
725
- 'env.bridge.unknown': '无法识别问题类型:请展开原文,按其中的步骤处理。',
725
+ 'env.bridge.unknown': '浏览器连接有问题,但工作台没能识别是哪一类。可以展开原文查看,也可以让 agent 诊断。',
726
726
  'env.fix.title': '解决方法',
727
727
  'env.fix.why': '工作台使用自带的后台工具,与你在终端中安装的那份相互独立。这台机器上还没有安装完成。',
728
- 'env.fix.whyPath': '后台工具已经安装,但当前环境仍然找不到它,通常是 PATH 或终端会话的问题。',
728
+ 'env.fix.whyPath': '后台工具已经安装,但当前环境仍然找不到它。',
729
729
  'env.fix.whyShell': '工作台无法访问本机命令行,因此无法获取数据。这一步无法在这里完成,需要管理员处理后台环境。',
730
730
  'env.fix.whyHost': '工作台需要通过命令行运行几项检查并取回结果。本次命令已经发出,但结果没有返回。工具本身通常没有问题,重新安装 Node / npm / pnpm 不会有帮助。',
731
731
  'env.fix.step': '请在终端中运行下面的命令,安装完成后点击「重试」:',
732
732
  'env.fix.stepRetry': '点击「重试」重新安装。如果仍然失败,也可以先进入工作台,安装完成后重启工作台即可使用。',
733
733
  'env.fix.stepPath': '请新开一个终端窗口,或确认 npm 的全局 bin 目录在 PATH 中,然后点击「重试」。',
734
734
  'env.fix.stepShell': '请重启工作台(或 dsh)。如果反复出现,说明工作台仍然无法连接命令行。',
735
- 'env.fix.stepHost': '请完全退出工作台(包括托盘图标),清理系统临时目录中以 dsh- 开头的残留文件,然后重新打开。如果反复出现,请升级 dsh。',
735
+ 'env.fix.stepHost': '请完全退出工作台(包括托盘图标),清理系统临时目录中以 dsh- 开头的残留文件,然后重新打开。',
736
736
  'env.fix.permission': '权限不足。请在命令前加 sudo 后重新运行,或先把 npm 全局目录配置到你的用户目录。',
737
737
  'env.fix.network': '网络不通。请检查网络或代理设置后重试。',
738
738
  'env.fix.details': '详细输出(排障用)',
@@ -746,12 +746,48 @@ export const zh = {
746
746
  'env.bridge.continue': '先进入工作台',
747
747
  'env.diy.ok': '可用',
748
748
  'env.diy.short': '暂时不可用',
749
- 'env.diy.hold': 'DIY 模式暂时不可用。请升级 dsh 后点击「重试」,也可以先进入工作台。',
750
- 'env.diy.why': '这台机器上的 dsh 比工作台验证过的版本旧,因此无法使用 DIY 模式;面板和其他功能不受影响。升级 dsh 后重启再试。',
751
- 'env.diy.rows': '当前版本的 dsh 缺少以下内容:{rows}。',
752
- 'env.diy.noRow': '启动检查没有在 dsh 的模式列表中找到「工作台 DIY 模式」,多半是这次工作台安装没有包含对应的模式补丁。',
753
- 'env.diy.step': '升级 dsh,然后重启一次工作台:',
749
+ 'env.diy.hold': 'DIY 模式暂时不可用。可以重试,也可以让 agent 诊断。',
750
+ 'env.diy.older.why': '这台机器上的 {host} 是 {runtime},工作台验证过的是 {verified}。请升级 {host} 后重启;面板与其他功能不受影响。',
751
+ 'env.diy.older.step': '升级 {host},然后重启工作台:',
752
+ 'env.diy.broken.why': '「工作台 DIY 模式」里这几行没有启动:{rows}。',
753
+ 'env.diy.broken.hint': '原因在 {host} 的启动日志里,可以让 agent 诊断。',
754
+ 'env.diy.presetMissing.why': '启动检查没有在 {host} 的模式列表里找到「工作台 DIY 模式」。',
755
+ 'env.diy.presetMissing.hint': '多半是这次工作台安装不完整。请重新安装一次工作台。',
754
756
  'env.diy.continue': '先进入工作台',
757
+ 'askAgent.title': '需要 agent 诊断',
758
+ 'askAgent.copy': '复制给 agent',
759
+ 'askAgent.copied': '已复制',
760
+ 'askAgent.hint': '粘贴到对话里,agent 会继续诊断。',
761
+ 'askAgent.prompt.head': '工作台遇到一个问题,需要你定位。',
762
+ 'askAgent.prompt.whereOnly': '位置:{screen}',
763
+ 'askAgent.screen.board': '看板',
764
+ 'askAgent.screen.workbench': '工作台界面',
765
+ 'entry.failed': '这里没有加载起来。',
766
+ 'askAgent.screen.settings': '配置同步',
767
+ 'askAgent.prompt.where': '位置:{screen} · {step}',
768
+ 'askAgent.prompt.why': '现象:{detail}',
769
+ 'askAgent.prompt.rows': '没有启动的行:{rows}',
770
+ 'askAgent.prompt.issue': '未能识别的问题:{issue}',
771
+ 'askAgent.prompt.reason': '原因:{reason}',
772
+ 'askAgent.prompt.host': '运行的是 {host} {version},工作台验证过的是 {verified}。',
773
+ 'askAgent.prompt.deployment': '打开方式:{deployment}',
774
+ 'askAgent.deployment.desktop': '桌面版',
775
+ 'askAgent.deployment.web': '网页版',
776
+ 'askAgent.prompt.configDir': '工作台配置目录:{configDir}',
777
+ 'askAgent.prompt.logDir': 'dsh 启动日志目录:{dir}(最新一份)',
778
+ 'askAgent.prompt.tried': '已经试过:重试 {n} 次。',
779
+ 'askAgent.prompt.evidence': '证据文件:{files}',
780
+ 'askAgent.prompt.ask': '先读这些证据,给出确定的原因和下一步;不要猜。',
781
+ 'diag.code.preflightDiyRowBroken': 'DIY 模式的几行没有启动。',
782
+ 'diag.hint.preflightDiyRowBroken': '原因在 dsh 的启动日志里,可以让 agent 诊断。',
783
+ 'diag.code.preflightDiyPresetMissing': '没有找到「工作台 DIY 模式」。',
784
+ 'diag.hint.preflightDiyPresetMissing': '多半是这次工作台安装不完整。请重新安装一次工作台。',
785
+ 'diag.code.preflightBridgeHold': '浏览器连接没有建立。',
786
+ 'diag.hint.preflightBridgeHold': '请按启动检查里的步骤修复后重试。',
787
+ 'diag.code.preflightHostOlder': '工作台运行的版本低于验证过的版本。',
788
+ 'diag.hint.preflightHostOlder': '请升级后重启工作台。',
789
+ 'diag.code.preflightHostNewer': '工作台运行的版本高于验证过的版本。',
790
+ 'diag.hint.preflightHostNewer': '可以继续使用;显示异常时再更新工作台。',
755
791
  'env.step.hostVersion': '检查 {host} 版本',
756
792
  'env.hostVersion.newer': '未验证',
757
793
  'env.hostVersion.older': '版本过低',
package/dist/index.d.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';
package/dist/index.js 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';
@@ -9,6 +9,7 @@ export interface BlockerActionShape {
9
9
  readonly kind: string;
10
10
  readonly label: string;
11
11
  readonly text?: string | undefined;
12
+ readonly prompt?: string | undefined;
12
13
  }
13
14
  /**
14
15
  * 这颗钮此刻的运行态:是否正在重试、哪一支正在跑(按 label 认)、刚复制过哪段文本。
@@ -0,0 +1,10 @@
1
+ export interface CopyFlash {
2
+ copy(text: string, onCopied: (copied: boolean) => void): void;
3
+ dispose(): void;
4
+ }
5
+ /**
6
+ * 「复制一下、按钮亮一会儿再复原」这件小事的计时器:组件只负责把结果写进自己的状态。
7
+ * @param ms - 「已复制」亮多久(毫秒)。
8
+ * @returns `copy` 成功后先给 `true`,到点再给 `false`;`dispose` 清掉未到点的计时器。
9
+ */
10
+ export declare function createCopyFlash(ms: number): CopyFlash;
@@ -0,0 +1,30 @@
1
+ import { writeClipboard } from '@deepseek-ai/dsh-client-ui-primitives';
2
+ /**
3
+ * 「复制一下、按钮亮一会儿再复原」这件小事的计时器:组件只负责把结果写进自己的状态。
4
+ * @param ms - 「已复制」亮多久(毫秒)。
5
+ * @returns `copy` 成功后先给 `true`,到点再给 `false`;`dispose` 清掉未到点的计时器。
6
+ */
7
+ export function createCopyFlash(ms) {
8
+ let timer;
9
+ const clear = () => {
10
+ if (timer === undefined)
11
+ return;
12
+ clearTimeout(timer);
13
+ timer = undefined;
14
+ };
15
+ return {
16
+ copy(text, onCopied) {
17
+ void writeClipboard(text).then((ok) => {
18
+ if (!ok)
19
+ return;
20
+ onCopied(true);
21
+ clear();
22
+ timer = setTimeout(() => {
23
+ timer = undefined;
24
+ onCopied(false);
25
+ }, ms);
26
+ });
27
+ },
28
+ dispose: clear,
29
+ };
30
+ }
@@ -0,0 +1,40 @@
1
+ import type { Translate } from './dsh-client.js';
2
+ export interface PromptHostFacts {
3
+ readonly label: string;
4
+ readonly version: string;
5
+ readonly verified: string;
6
+ }
7
+ export interface PromptProblem {
8
+ readonly why?: string;
9
+ readonly rows?: string;
10
+ readonly issue?: string;
11
+ readonly reason?: string;
12
+ }
13
+ export interface PromptContext {
14
+ readonly deployment?: string;
15
+ readonly configDir?: string;
16
+ readonly logDir?: string;
17
+ readonly evidence?: string;
18
+ readonly tried?: number;
19
+ }
20
+ export interface PromptFacts {
21
+ readonly screen: string;
22
+ readonly step?: string;
23
+ readonly host?: PromptHostFacts;
24
+ readonly problem?: PromptProblem;
25
+ readonly context?: PromptContext;
26
+ }
27
+ /**
28
+ * 取一段多行文本里第一行有内容的,给提示词与卡片当「原文首行」。
29
+ * @param text - 可能为空或全是空行的原文。
30
+ * @returns 第一行非空文本,没有就 `undefined`。
31
+ */
32
+ export declare function firstLineOf(text: string | undefined): string | undefined;
33
+ /**
34
+ * 把「哪里出的问题、看到什么、有什么证据」拼成一段可以直接粘给 agent 的提示词。
35
+ * 空的整行省略;`step` 不给就只写屏幕名。
36
+ * @param facts - 屏幕 / 步骤 / 版本对照 / 现象 / 现场上下文。
37
+ * @param t - 文案函数,键在 askAgent.* 下。
38
+ * @returns 多行提示词,最后一行是「先读证据再下结论」。
39
+ */
40
+ export declare function faultPromptOf(facts: PromptFacts, t: Translate): string;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * 取一段多行文本里第一行有内容的,给提示词与卡片当「原文首行」。
3
+ * @param text - 可能为空或全是空行的原文。
4
+ * @returns 第一行非空文本,没有就 `undefined`。
5
+ */
6
+ export function firstLineOf(text) {
7
+ const line = (text ?? '')
8
+ .split('\n')
9
+ .map((one) => one.trim())
10
+ .find((one) => one !== '');
11
+ return line === undefined ? undefined : line;
12
+ }
13
+ /**
14
+ * 把「哪里出的问题、看到什么、有什么证据」拼成一段可以直接粘给 agent 的提示词。
15
+ * 空的整行省略;`step` 不给就只写屏幕名。
16
+ * @param facts - 屏幕 / 步骤 / 版本对照 / 现象 / 现场上下文。
17
+ * @param t - 文案函数,键在 askAgent.* 下。
18
+ * @returns 多行提示词,最后一行是「先读证据再下结论」。
19
+ */
20
+ export function faultPromptOf(facts, t) {
21
+ const problem = facts.problem ?? {};
22
+ const context = facts.context ?? {};
23
+ const host = facts.host;
24
+ const pick = (key, params) => params === undefined ? [] : [t(key, params)];
25
+ const where = facts.step === undefined || facts.step.trim() === ''
26
+ ? t('askAgent.prompt.whereOnly', { screen: facts.screen })
27
+ : t('askAgent.prompt.where', { screen: facts.screen, step: facts.step });
28
+ const lines = [
29
+ t('askAgent.prompt.head'),
30
+ where,
31
+ ...pick('askAgent.prompt.why', problem.why === undefined ? undefined : { detail: problem.why }),
32
+ ...pick('askAgent.prompt.rows', problem.rows === undefined ? undefined : { rows: problem.rows }),
33
+ ...pick('askAgent.prompt.issue', problem.issue === undefined ? undefined : { issue: problem.issue }),
34
+ ...pick('askAgent.prompt.reason', problem.reason === undefined ? undefined : { reason: problem.reason }),
35
+ ...pick('askAgent.prompt.host', host === undefined ? undefined : { host: host.label, version: host.version, verified: host.verified }),
36
+ ...pick('askAgent.prompt.deployment', context.deployment === undefined ? undefined : { deployment: context.deployment }),
37
+ ...pick('askAgent.prompt.configDir', context.configDir === undefined ? undefined : { configDir: context.configDir }),
38
+ ...pick('askAgent.prompt.logDir', context.logDir === undefined ? undefined : { dir: context.logDir }),
39
+ ...pick('askAgent.prompt.tried', context.tried === undefined || context.tried <= 0 ? undefined : { n: context.tried }),
40
+ ...pick('askAgent.prompt.evidence', context.evidence === undefined ? undefined : { files: context.evidence }),
41
+ t('askAgent.prompt.ask'),
42
+ ];
43
+ return lines.join('\n');
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-workbench/shared",
3
- "version": "1.5.2-rc.1",
3
+ "version": "1.5.2",
4
4
  "description": "工作台与模块共享的纯代码与契约类型:类型、纯逻辑、哑组件、平台解析。宿主侧的东西从 /host 进(不影响浏览器产物)。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -3,6 +3,8 @@ import type { Translate } from '../../lib/dsh-client.js';
3
3
  import type { CapabilityPayload } from '../../contract/workbench-contract.js';
4
4
  import type { NeedState } from '../../contract/unit-capability.js';
5
5
  import { blockerOf, blockerOfCapability, blockerOfDiag, blockerOfError } from '../blocker-table.js';
6
+ import type { ApiError } from '../workbench-client.js';
7
+ import type { ModuleBlocker } from '../../contract/blocker.js';
6
8
 
7
9
  const t: Translate = (key, params) => (params === undefined ? key : `${key}(${JSON.stringify(params)})`);
8
10
 
@@ -111,12 +113,19 @@ describe('blockerOfError', () => {
111
113
  expect(blocker.actions.map((action) => action.kind)).toEqual(['retry']);
112
114
  });
113
115
 
114
- it('未知错误 → 说人话,原文收进详情,并给重试', () => {
116
+ it('未知错误 → 说人话,原文收进详情,并给「复制给 agent」+ 重试', () => {
115
117
  const blocker = blockerOfError({ code: 'weird', message: '怪错误' }, t);
116
118
 
117
119
  expect(blocker.title).toBe('blocker.unknown.title');
118
120
  expect(blocker.detail).toBe('怪错误');
119
- expect(blocker.actions.map((action) => action.kind)).toEqual(['retry']);
121
+ expect(blocker.actions.map((action) => action.kind)).toEqual(['ask-agent', 'retry']);
122
+ const ask = blocker.actions[0];
123
+ expect(ask?.kind).toBe('ask-agent');
124
+ if (ask?.kind !== 'ask-agent') return;
125
+ expect(ask.label).toBe('askAgent.copy');
126
+ expect(ask.prompt).toContain('askAgent.prompt.where');
127
+ expect(ask.prompt).toContain('"issue":"weird"');
128
+ expect(ask.prompt).toContain('"reason":"怪错误"');
120
129
  });
121
130
 
122
131
  it('没有错误对象 → 兜底文案 + 重试(不炸)', () => {
@@ -174,7 +183,9 @@ describe('blockerOfCapability', () => {
174
183
  expect(blocker?.title).toBe('env.unit.failed');
175
184
  expect(blocker?.detail).toBe('模块自己的 bug:kit.components.StateBlock 取不到');
176
185
  expect(blocker?.hint).toBe('env.unit.failedHint');
177
- expect(blocker?.actions.map((action) => action.kind)).toEqual(['retry']);
186
+ expect(blocker?.actions.map((action) => action.kind)).toEqual(['ask-agent', 'retry']);
187
+ const ask = blocker?.actions[0];
188
+ expect(ask?.kind === 'ask-agent' ? ask.prompt : '').toContain('"step":"issues"');
178
189
  });
179
190
 
180
191
  it('★ 未知 kind(模块跑在更新的工作台上)→ 单独一档,叫升级工作台,不猜怎么修', () => {
@@ -414,3 +425,101 @@ describe('blockerOfDiag', () => {
414
425
  expect(blocker.title).toBe('diag.code.unknownCode');
415
426
  });
416
427
  });
428
+
429
+ describe('兜底分支的第三个出口:复制给 agent', () => {
430
+ it('★ 未登记的诊断码 → 「复制给 agent」+ 重试,提示词带码与原文首行', () => {
431
+ const blocker = blockerOfDiag('MY_WEIRD_CODE', t, '原文第一行\n第二行');
432
+ expect(blocker.actions.map((action) => action.kind)).toEqual(['ask-agent', 'retry']);
433
+
434
+ const ask = blocker.actions[0];
435
+ expect(ask?.kind).toBe('ask-agent');
436
+ if (ask?.kind !== 'ask-agent') return;
437
+ expect(ask.label).toBe('askAgent.copy');
438
+ expect(ask.prompt).toContain('"issue":"MY_WEIRD_CODE"');
439
+ expect(ask.prompt).toContain('"reason":"原文第一行"');
440
+ expect(ask.prompt).toContain('"screen":"askAgent.screen.board"');
441
+ });
442
+
443
+ it('已登记的码不加这颗(原因已经说得清)', () => {
444
+ expect(blockerOfDiag('SELF_UPDATE_FAILED', t).actions.map((action) => action.kind)).toEqual(['retry']);
445
+ });
446
+
447
+ it('★ 连错误对象都没有:也要有出口(复制 + 重试)', () => {
448
+ expect(blockerOfError(undefined, t).actions.map((action) => action.kind)).toEqual(['ask-agent', 'retry']);
449
+ });
450
+
451
+ it('调用方能指定屏幕与步骤(配置同步 / 具体模块)', () => {
452
+ const blocker = blockerOfError({ code: 'weird', message: 'x' }, t, {
453
+ ask: { screen: 'askAgent.screen.settings', step: 'my-unit' },
454
+ });
455
+ const ask = blocker.actions[0];
456
+ expect(ask?.kind).toBe('ask-agent');
457
+ if (ask?.kind !== 'ask-agent') return;
458
+ expect(ask.prompt).toContain('"screen":"askAgent.screen.settings"');
459
+ expect(ask.prompt).toContain('"step":"my-unit"');
460
+ });
461
+ });
462
+
463
+ describe('故障面出口矩阵:每个分支都有下一步', () => {
464
+ const ACTION_KINDS = new Set(['open-url', 'copy', 'retry', 'run-fix', 'open-market', 'ask-agent']);
465
+ const ERROR_CODES = [
466
+ 'auth',
467
+ 'auth-required',
468
+ 'permission-denied',
469
+ 'cli-timeout',
470
+ 'cli-exec-failed',
471
+ 'project-unsupported',
472
+ 'weird',
473
+ ] as const;
474
+ const CAPABILITY_STATUSES = ['ok', 'degraded', 'missing', 'outdated', 'unchecked', 'unsupported', 'failed'] as const;
475
+ const NEED_STATUSES = ['ok', 'missing', 'outdated', 'unsatisfied', 'unchecked'] as const;
476
+
477
+ function allBlockers(): ModuleBlocker[] {
478
+ return [
479
+ blockerOfError(undefined, t),
480
+ blockerOfDiag('SELF_UPDATE_FAILED', t),
481
+ blockerOfDiag('NOT_REGISTERED', t),
482
+ ...ERROR_CODES.map((code) => blockerOfError({ code, message: 'x' } as ApiError, t)),
483
+ ...CAPABILITY_STATUSES.map((status) => blockerOfCapability(capability({ status }), t)),
484
+ ...NEED_STATUSES.map((status) =>
485
+ blockerOfCapability(capability({ needs: [needOf({ kind: 'bin', name: 'git', status })] }), t),
486
+ ),
487
+ ].filter((one): one is ModuleBlocker => one !== undefined);
488
+ }
489
+
490
+ it('★ 每个分支至少一颗动作,且动作种类都在协议里(没有一条路是死的)', () => {
491
+ const blockers = allBlockers();
492
+
493
+ expect(blockers.length).toBeGreaterThan(10);
494
+ for (const blocker of blockers) {
495
+ expect(blocker.actions.length, blocker.id).toBeGreaterThan(0);
496
+ for (const action of blocker.actions) {
497
+ expect(ACTION_KINDS.has(action.kind), `${blocker.id}:${action.kind}`).toBe(true);
498
+ }
499
+ }
500
+ });
501
+
502
+ it('★ 认不出原因的分支必须有「复制给 agent」', () => {
503
+ const fallbacks: readonly (ModuleBlocker | undefined)[] = [
504
+ blockerOfError(undefined, t),
505
+ blockerOfError({ code: 'weird', message: 'x' } as ApiError, t),
506
+ blockerOfDiag('NOT_REGISTERED', t),
507
+ blockerOfCapability(capability({ status: 'failed' }), t),
508
+ ];
509
+
510
+ for (const blocker of fallbacks) {
511
+ expect(blocker?.actions.some((action) => action.kind === 'ask-agent'), blocker?.id).toBe(true);
512
+ }
513
+ });
514
+
515
+ it('有确定解释的分支不硬塞「复制给 agent」', () => {
516
+ const known = [
517
+ blockerOfError({ code: 'auth-required', message: '需要登录' } as ApiError, t),
518
+ blockerOfDiag('SELF_UPDATE_FAILED', t),
519
+ ];
520
+
521
+ for (const blocker of known) {
522
+ expect(blocker.actions.some((action) => action.kind === 'ask-agent'), blocker.id).toBe(false);
523
+ }
524
+ });
525
+ });