@dsh-workbench/shared 1.5.5-rc.0 → 1.5.6

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 (93) hide show
  1. package/dist/api/dsh.d.ts +9 -1
  2. package/dist/components/card/ApprovalPlan.css +3 -0
  3. package/dist/components/card/ApprovalPlan.js +7 -2
  4. package/dist/components/card/LongTaskRow.css +32 -0
  5. package/dist/components/card/LongTaskRow.d.ts +8 -2
  6. package/dist/components/card/LongTaskRow.js +26 -5
  7. package/dist/components/card/board-module.d.ts +35 -4
  8. package/dist/components/card/use-text-marquee.d.ts +15 -0
  9. package/dist/components/card/use-text-marquee.js +66 -0
  10. package/dist/components/feedback/ProgressBar.css +56 -0
  11. package/dist/components/feedback/ProgressBar.d.ts +25 -0
  12. package/dist/components/feedback/ProgressBar.js +22 -0
  13. package/dist/config/constants.d.ts +2 -0
  14. package/dist/config/constants.js +2 -0
  15. package/dist/contract/guards.d.ts +1 -0
  16. package/dist/contract/guards.js +3 -0
  17. package/dist/contract/long-task.d.ts +56 -0
  18. package/dist/contract/long-task.js +41 -0
  19. package/dist/contract/protocol/long-tasks.d.ts +8 -2
  20. package/dist/contract/unit.d.ts +1 -0
  21. package/dist/host/diy/diy-preset.d.ts +1 -1
  22. package/dist/host/diy/diy-preset.js +3 -3
  23. package/dist/host/flow/create.d.ts +2 -1
  24. package/dist/host/flow/create.js +6 -0
  25. package/dist/host/flow/dsh-journal.d.ts +3 -0
  26. package/dist/host/flow/dsh-journal.js +55 -0
  27. package/dist/host/flow/journal.d.ts +20 -0
  28. package/dist/host/flow/journal.js +30 -0
  29. package/dist/host/flow/open.js +43 -26
  30. package/dist/host/flow/task.js +12 -1
  31. package/dist/host/flow/types.d.ts +5 -0
  32. package/dist/host/platform/integration/browser-launch.d.ts +1 -0
  33. package/dist/host/platform/integration/browser-launch.js +9 -2
  34. package/dist/host/profile/bundle-manager.js +4 -6
  35. package/dist/host/unit/long-task-host.d.ts +18 -0
  36. package/dist/host/unit/long-task-host.js +44 -0
  37. package/dist/host/unit/long-task-progress.d.ts +3 -0
  38. package/dist/host/unit/long-task-progress.js +32 -0
  39. package/dist/host/unit/long-task.d.ts +14 -38
  40. package/dist/host/unit/long-task.js +95 -94
  41. package/dist/host/unit/unit-face.d.ts +2 -1
  42. package/dist/host/unit/with-intervention-retry.d.ts +20 -0
  43. package/dist/host/unit/with-intervention-retry.js +45 -0
  44. package/dist/host.d.ts +30 -19
  45. package/dist/host.js +30 -19
  46. package/dist/i18n/en.js +33 -7
  47. package/dist/i18n/index.d.ts +33 -7
  48. package/dist/i18n/zh.d.ts +32 -6
  49. package/dist/i18n/zh.js +32 -6
  50. package/dist/index.d.ts +4 -2
  51. package/dist/index.js +4 -2
  52. package/package.json +2 -1
  53. package/src/api/dsh.ts +12 -1
  54. package/src/components/card/ApprovalPlan.css +3 -0
  55. package/src/components/card/ApprovalPlan.tsx +9 -2
  56. package/src/components/card/LongTaskRow.css +32 -0
  57. package/src/components/card/LongTaskRow.tsx +51 -4
  58. package/src/components/card/__tests__/ApprovalPlan.test.tsx +50 -0
  59. package/src/components/card/__tests__/long-task-row.test.ts +64 -2
  60. package/src/components/card/board-module.ts +36 -4
  61. package/src/components/card/use-text-marquee.ts +79 -0
  62. package/src/components/feedback/ProgressBar.css +56 -0
  63. package/src/components/feedback/ProgressBar.tsx +60 -0
  64. package/src/config/constants.ts +3 -0
  65. package/src/contract/__tests__/long-task.test.ts +43 -1
  66. package/src/contract/guards.ts +4 -0
  67. package/src/contract/long-task.ts +75 -0
  68. package/src/contract/protocol/long-tasks.ts +9 -1
  69. package/src/contract/unit.ts +1 -0
  70. package/src/host/diy/__tests__/diy-preset.test.ts +2 -0
  71. package/src/host/diy/diy-preset.ts +3 -2
  72. package/src/host/flow/__tests__/dsh-journal.test.ts +56 -0
  73. package/src/host/flow/__tests__/flow-create.test.ts +41 -1
  74. package/src/host/flow/__tests__/flow-open.test.ts +32 -0
  75. package/src/host/flow/create.ts +8 -5
  76. package/src/host/flow/dsh-journal.ts +74 -0
  77. package/src/host/flow/journal.ts +46 -0
  78. package/src/host/flow/open.ts +41 -26
  79. package/src/host/flow/task.ts +11 -1
  80. package/src/host/flow/types.ts +6 -0
  81. package/src/host/platform/integration/__tests__/browser-launch.test.ts +27 -0
  82. package/src/host/platform/integration/browser-launch.ts +15 -3
  83. package/src/host/profile/bundle-manager.ts +4 -7
  84. package/src/host/unit/__tests__/long-task.test.ts +203 -2
  85. package/src/host/unit/long-task-host.ts +64 -0
  86. package/src/host/unit/long-task-progress.ts +37 -0
  87. package/src/host/unit/long-task.ts +112 -126
  88. package/src/host/unit/unit-face.ts +2 -1
  89. package/src/host/unit/with-intervention-retry.ts +55 -0
  90. package/src/host.ts +31 -20
  91. package/src/i18n/en.ts +33 -7
  92. package/src/i18n/zh.ts +32 -6
  93. package/src/index.ts +4 -2
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ export * from './api/context-ref.js';
3
3
  export * from './api/dsh.js';
4
4
  export * from './api/host-write.js';
5
5
  export * from './api/workbench-client.js';
6
+ export * from './client/platform/surface.js';
6
7
  export * from './components/card/Activity.js';
7
8
  export * from './components/card/ApprovalDetail.js';
8
9
  export * from './components/card/ApprovalPlan.js';
@@ -13,8 +14,10 @@ export * from './components/card/CardHead.js';
13
14
  export * from './components/card/LongTaskRow.js';
14
15
  export * from './components/card/board-module.js';
15
16
  export * from './components/card/card-view-validate.js';
17
+ export * from './components/card/use-text-marquee.js';
16
18
  export * from './components/feedback/EmptyIllustration.js';
17
19
  export * from './components/feedback/Note.js';
20
+ export * from './components/feedback/ProgressBar.js';
18
21
  export * from './components/feedback/ResourceStates.js';
19
22
  export * from './components/feedback/Spinner.js';
20
23
  export * from './components/feedback/StateBlock.js';
@@ -37,7 +40,6 @@ export * from './components/layout/SettingsSection.js';
37
40
  export * from './components/layout/SetupShell.js';
38
41
  export * from './components/layout/Stack.js';
39
42
  export * from './components/layout/icons.js';
40
- export * from './client/platform/surface.js';
41
43
  export * from './config/constants.js';
42
44
  export * from './config/storage.js';
43
45
  export * from './contract/adapters.js';
@@ -56,7 +58,6 @@ export * from './contract/long-task.js';
56
58
  export * from './contract/module-context.js';
57
59
  export * from './contract/needs.js';
58
60
  export * from './contract/plugin-source.js';
59
- export * from './contract/readme.js';
60
61
  export * from './contract/protocol/boot-ok.js';
61
62
  export * from './contract/protocol/bundle-install.js';
62
63
  export * from './contract/protocol/config-sync.js';
@@ -72,6 +73,7 @@ export * from './contract/protocol/release.js';
72
73
  export * from './contract/protocol/sidebar-edition.js';
73
74
  export * from './contract/protocol/unit-manifests.js';
74
75
  export * from './contract/protocol/workbench-settings.js';
76
+ export * from './contract/readme.js';
75
77
  export * from './contract/runner.js';
76
78
  export * from './contract/unit-board.js';
77
79
  export * from './contract/unit-capability.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-workbench/shared",
3
- "version": "1.5.5-rc.0",
3
+ "version": "1.5.6",
4
4
  "description": "工作台与模块共享的纯代码与契约类型:类型、纯逻辑、哑组件、平台解析。宿主侧的东西从 /host 进(不影响浏览器产物)。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -31,6 +31,7 @@
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react": "*",
34
+ "@deepseek-ai/dsh-session": "^0.2.2-rc.2",
34
35
  "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.2"
35
36
  },
36
37
  "devDependencies": {
package/src/api/dsh.ts CHANGED
@@ -25,6 +25,8 @@ import type { AgentPresetRegistry, PresetDefinition } from '@deepseek-ai/dsh-age
25
25
  import type { ProfileContext } from '@deepseek-ai/dsh-app-boot';
26
26
  import type { IndexInjection, WebRoute } from '@deepseek-ai/dsh-host-webserver';
27
27
  import type { dshHomePath } from '@deepseek-ai/dsh-home-paths';
28
+ import type { Session, SessionId, SessionStore } from '@deepseek-ai/dsh-session';
29
+ import type { SessionController } from '@deepseek-ai/dsh-api-session-controller';
28
30
  import type { PluginInstallRequestId, PluginManager } from '@deepseek-ai/dsh-plugin-manager';
29
31
  import type Hmr from '@deepseek-ai/dsh-hmr';
30
32
  import type { ApprovalService } from '@deepseek-ai/dsh-user-approval';
@@ -157,7 +159,16 @@ export type DshSubagentResult = SubagentResult;
157
159
  export type DshContentBlock = ContentBlock;
158
160
 
159
161
  /** 一条会话 id 的 branded 串(子 agent 可以预先指定)。 */
160
- export type DshSessionId = import('@deepseek-ai/dsh-session').SessionId;
162
+ export type DshSessionId = SessionId;
163
+
164
+ /** 一条活着的 dsh 会话:插件记录与 projection 都从它读写。 */
165
+ export type DshSession = Session;
166
+
167
+ /** 宿主侧的会话名册(服务名 `sessions`);这里只用按 id 取会话。 */
168
+ export type DshSessionStore = Pick<SessionStore, 'get'>;
169
+
170
+ /** 宿主侧的会话控制器(服务名 `sessionController`):这里只用建一条会话。 */
171
+ export type DshSessionController = Pick<SessionController, 'create'>;
161
172
 
162
173
  /** 子 agent 结构化输出收的那份对象根 JSON Schema(dsh 的受支持子集)。 */
163
174
  export type DshObjectJsonSchema = import('@deepseek-ai/dsh-tools').ObjectJsonSchema;
@@ -34,6 +34,9 @@
34
34
  color: var(--dsw-alias-label-primary);
35
35
  overflow-wrap: anywhere;
36
36
  }
37
+ .wb-approvalLine {
38
+ display: block;
39
+ }
37
40
  .wb-approvalWarn {
38
41
  color: var(--dsw-alias-label-secondary);
39
42
  }
@@ -24,6 +24,13 @@ export interface ApprovalPlanProps {
24
24
  readonly children?: ReactNode | undefined;
25
25
  }
26
26
 
27
+ function linesOf(value: ReactNode): ReactNode {
28
+ if (!Array.isArray(value)) return value;
29
+ return value.map((line, index) =>
30
+ h('span', { className: 'wb-approvalLine', key: String(index) }, line),
31
+ );
32
+ }
33
+
27
34
  /**
28
35
  * 审批屏那张"这次要做什么"的表:一行一项,上面可给一句附注、下面可给一句警告。
29
36
  * @returns 一个 div。
@@ -36,12 +43,12 @@ export function ApprovalPlan({ rows, hint, warn, children }: ApprovalPlanProps)
36
43
  {rows.map((row, index) => (
37
44
  <div className="wb-approvalRow" key={String(index)}>
38
45
  <dt className="wb-approvalLabel">{row.label}</dt>
39
- <dd className="wb-approvalValue">{row.value}</dd>
46
+ <dd className="wb-approvalValue">{linesOf(row.value)}</dd>
40
47
  </div>
41
48
  ))}
42
49
  </dl>
43
50
  {children}
44
- {warn === undefined ? null : <p className="wb-approvalWarn">{warn}</p>}
51
+ {warn === undefined ? null : <p className="wb-approvalWarn">{linesOf(warn)}</p>}
45
52
  </div>
46
53
  );
47
54
  }
@@ -44,6 +44,20 @@
44
44
  overflow: auto;
45
45
  }
46
46
 
47
+ .wb-longTaskProgress {
48
+ display: flex;
49
+ align-items: center;
50
+ gap: var(--wb-len-8);
51
+ }
52
+
53
+ .wb-longTaskProgressText {
54
+ flex: none;
55
+ font-size: var(--dsw-font-xxxs-11-font-size);
56
+ line-height: var(--wb-line-16);
57
+ color: var(--dsw-alias-label-tertiary);
58
+ font-variant-numeric: tabular-nums;
59
+ }
60
+
47
61
  .wb-longTaskHeadEnd {
48
62
  display: inline-flex;
49
63
  flex: none;
@@ -186,6 +200,19 @@
186
200
  text-overflow: ellipsis;
187
201
  }
188
202
 
203
+ .wb-longTaskDense .wb-longTaskHeadRow {
204
+ height: auto;
205
+ min-height: var(--wb-len-24);
206
+ overflow: visible;
207
+ }
208
+
209
+ .wb-longTaskDense .wb-longTaskHeadline {
210
+ width: auto;
211
+ max-width: 100%;
212
+ white-space: normal;
213
+ overflow-wrap: anywhere;
214
+ }
215
+
189
216
  .wb-longTaskMeta {
190
217
  margin: 0;
191
218
  min-width: 0;
@@ -235,6 +262,11 @@
235
262
  color: var(--dsw-alias-state-error-primary);
236
263
  }
237
264
 
265
+ .wb-longTaskStepRow[data-kind='pending'] .wb-longTaskStepText {
266
+ color: var(--dsw-alias-label-tertiary);
267
+ opacity: 0.7;
268
+ }
269
+
238
270
  .wb-longTaskStepLink {
239
271
  flex: none;
240
272
  font-size: inherit;
@@ -3,13 +3,16 @@ import {
3
3
  LONG_TASK_LINK_MAX,
4
4
  longTaskDot,
5
5
  longTaskIsLive,
6
+ longTaskProgressIsValid,
6
7
  longTaskStopPress,
7
8
  longTaskStopStage,
8
9
  LONG_TASK_STOP_ARM_MS,
9
10
  type LongTaskInterventionField,
11
+ type LongTaskProgress,
10
12
  type LongTaskStatus,
11
13
  type LongTaskStepRow,
12
14
  } from '../../contract/long-task.js';
15
+ import { ProgressBar, type ProgressBarTone } from '../feedback/ProgressBar.js';
13
16
  import { Link } from '../layout/Link.js';
14
17
  import { Fragment, h, useEffect, useState } from '../../lib/react.js';
15
18
  import {
@@ -103,8 +106,14 @@ export interface LongTaskRowProps {
103
106
  readonly dotLabel?: string | undefined;
104
107
  /** 第几次重试那行的文案;只在 `attempt > 1` 时用,不给不画。 */
105
108
  readonly attemptLabel?: ((attempt: number) => string) | undefined;
106
- /** 紧凑档(默认 false)。 */
109
+ /** 紧凑档(默认 false);进度条降到 2px,数字由调用点并进 `meta`。 */
107
110
  readonly dense?: boolean | undefined;
111
+ /** 这一趟走到哪了;不合法或没给就一根条都不画。 */
112
+ readonly progress?: LongTaskProgress | undefined;
113
+ /** 计划里还没开始的步骤(只有给了计划才有);展开时排在已发生的步骤后面。 */
114
+ readonly pending?: readonly string[] | undefined;
115
+ /** 进度条的读屏名;不给就不挂 `aria-label`。 */
116
+ readonly progressLabel?: string | undefined;
108
117
  /** 失败原因;不给不画。 */
109
118
  readonly problem?: string | undefined;
110
119
  /** 行尾的链接,通常指向产物或日志。 */
@@ -355,17 +364,33 @@ export function LongTaskRow(props: LongTaskRowProps) {
355
364
  const problem = props.problem ?? '';
356
365
  const raw = (props.raw ?? '').trim();
357
366
  const steps = props.steps ?? [];
367
+ const pending = (props.pending ?? []).filter((text) => text.trim() !== '');
358
368
  const stop = props.stop;
359
369
  const busy = stop?.busy === true;
360
370
  const stopWhy = stop?.failed ?? '';
361
371
  const stopPending =
362
372
  stopFired && live && !busy && stopWhy === '' ? stop?.pending ?? '' : '';
373
+ const progress =
374
+ props.progress === undefined || !longTaskProgressIsValid(props.progress)
375
+ ? undefined
376
+ : props.progress;
377
+ const progressTone: ProgressBarTone =
378
+ props.status === 'ok'
379
+ ? 'ok'
380
+ : props.status === 'failed'
381
+ ? 'bad'
382
+ : props.status === 'stopped'
383
+ ? 'neutral'
384
+ : props.status === 'needs-human' || props.status === 'needs-login'
385
+ ? 'warn'
386
+ : 'busy';
363
387
 
364
388
  useEffect(() => {
365
389
  if (failed) setStepsOpen(true);
366
390
  }, [failed]);
367
391
 
368
- const expandable = props.stepsTitle !== undefined && (history.length > 0 || steps.length > 0);
392
+ const expandable =
393
+ props.stepsTitle !== undefined && (history.length > 0 || steps.length > 0 || pending.length > 0);
369
394
  const stepShown = step !== '' && !props.headline.includes(step);
370
395
  const dotNode =
371
396
  props.dotLabel === undefined ? (
@@ -379,13 +404,14 @@ export function LongTaskRow(props: LongTaskRowProps) {
379
404
  return (
380
405
  <div className={props.dense === true ? 'wb-longTask wb-longTaskDense' : 'wb-longTask'}>
381
406
  <DisclosureRow
382
- icon={dotNode}
407
+ icon={dotNode}
383
408
  title={props.headline}
384
409
  open={expandable && stepsOpen}
385
410
  expandable={expandable}
386
411
  expandOnRowClick
387
412
  previewChevron
388
413
  titleClassName="wb-longTaskHeadline"
414
+ rowClassName="wb-longTaskHeadRow"
389
415
  onToggle={() => setStepsOpen((value) => !value)}
390
416
  headerAccessory={
391
417
  <span className="wb-longTaskHeadEnd">
@@ -405,7 +431,7 @@ export function LongTaskRow(props: LongTaskRowProps) {
405
431
  }
406
432
  >
407
433
  {stepShown ? <p className="wb-longTaskStep">{step}</p> : null}
408
- {history.length === 0 ? (
434
+ {history.length === 0 && pending.length === 0 ? (
409
435
  <CodeBlock
410
436
  code={steps.join('\n')}
411
437
  className="wb-longTaskDump"
@@ -424,6 +450,12 @@ export function LongTaskRow(props: LongTaskRowProps) {
424
450
  {...(props.attemptLabel === undefined ? {} : { attemptLabel: props.attemptLabel })}
425
451
  />
426
452
  ))}
453
+ {pending.map((text) => (
454
+ <li className="wb-longTaskStepRow" data-kind="pending" key={`pending:${text}`}>
455
+ <StateDot state="idle" size={8} />
456
+ <span className="wb-longTaskStepText">{text}</span>
457
+ </li>
458
+ ))}
427
459
  </ul>
428
460
  )}
429
461
  </DisclosureRow>
@@ -449,6 +481,21 @@ export function LongTaskRow(props: LongTaskRowProps) {
449
481
  />
450
482
  </DumpBlock>
451
483
  )}
484
+ {progress === undefined ? null : (
485
+ <div className="wb-longTaskProgress">
486
+ <ProgressBar
487
+ progress={progress}
488
+ size={props.dense === true ? 2 : 4}
489
+ tone={progressTone}
490
+ {...(props.progressLabel === undefined ? {} : { label: props.progressLabel })}
491
+ />
492
+ {props.dense === true ? null : (
493
+ <span className="wb-longTaskProgressText">
494
+ {`${String(progress.done)}/${String(progress.total)}`}
495
+ </span>
496
+ )}
497
+ </div>
498
+ )}
452
499
  </div>
453
500
  );
454
501
  }
@@ -0,0 +1,50 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+
3
+ vi.mock('../../../lib/react.js', () => ({
4
+ h: (type: unknown, props: unknown, ...children: unknown[]) => ({ type, props, children }),
5
+ }));
6
+
7
+ import { ApprovalPlan, type ApprovalPlanProps } from '../ApprovalPlan.js';
8
+
9
+ interface AnyElement {
10
+ readonly type: unknown;
11
+ readonly props: Record<string, unknown> | null;
12
+ readonly children: unknown[];
13
+ }
14
+
15
+ function flatten(value: unknown): AnyElement[] {
16
+ if (Array.isArray(value)) return value.flatMap(flatten);
17
+ if (typeof value !== 'object' || value === null || !('type' in value)) return [];
18
+ const element = value as AnyElement;
19
+ return [element, ...element.children.flatMap(flatten)];
20
+ }
21
+
22
+ function plan(props: ApprovalPlanProps): AnyElement {
23
+ return ApprovalPlan(props) as unknown as AnyElement;
24
+ }
25
+
26
+ function lineTexts(value: unknown): string[] {
27
+ return flatten(value)
28
+ .filter((element) => element.props?.['className'] === 'wb-approvalLine')
29
+ .map((element) => element.children.filter((child) => typeof child === 'string').join(''));
30
+ }
31
+
32
+ describe('审批表的多行值', () => {
33
+ it('★ 字符串数组每一项一行,warn 也一样', () => {
34
+ const root = plan({
35
+ rows: [
36
+ { label: '修改后', value: ['重新生成 dist', '版本号保持 1.5.0'] },
37
+ { label: '影响范围', value: '只改这三个模块' },
38
+ ],
39
+ warn: ['会短暂空白', '不要同时改'],
40
+ });
41
+
42
+ expect(lineTexts(root)).toEqual(['重新生成 dist', '版本号保持 1.5.0', '会短暂空白', '不要同时改']);
43
+ });
44
+
45
+ it('★ 单字符串照旧一行,不额外包一层', () => {
46
+ const root = plan({ rows: [{ label: '修改后', value: '重新生成 dist' }] });
47
+
48
+ expect(lineTexts(root)).toEqual([]);
49
+ });
50
+ });
@@ -7,6 +7,68 @@ const read = (name: string): string => readFileSync(new URL(name, HERE), 'utf8')
7
7
  const ROW = read('LongTaskRow.tsx');
8
8
  const CSS = read('LongTaskRow.css');
9
9
 
10
+
11
+ describe('长任务进度条:接线(读源码断言)', () => {
12
+ const BAR = read('../feedback/ProgressBar.tsx');
13
+ const BAR_CSS = read('../feedback/ProgressBar.css');
14
+
15
+ it('★★ 条在正文最后一行(raw 之后),只有有进度时才画', () => {
16
+ const last = ROW.lastIndexOf('{progress === undefined ? null : (');
17
+ const rawBlock = ROW.indexOf('props.rawTitle === undefined ? null : (');
18
+
19
+ expect(last).toBeGreaterThan(rawBlock);
20
+ expect(ROW).toContain('<ProgressBar');
21
+ expect(ROW).toContain("size={props.dense === true ? 2 : 4}");
22
+ });
23
+
24
+ it('★★ 紧凑档不留尾随数字(数字由调用点并进 meta);普通档才画 3/7', () => {
25
+ expect(ROW).toContain('{props.dense === true ? null : (');
26
+ expect(ROW).toContain('className="wb-longTaskProgressText"');
27
+ expect(CSS).toContain('.wb-longTaskProgressText {');
28
+ expect(CSS).toContain('font-variant-numeric: tabular-nums');
29
+ });
30
+
31
+ it('★★ 六态取色:完成 / 失败 / 已停止 / 等人 / 在跑各一档', () => {
32
+ expect(ROW).toContain("props.status === 'ok'");
33
+ expect(ROW).toContain("props.status === 'failed'");
34
+ expect(ROW).toContain("props.status === 'stopped'");
35
+ expect(ROW).toContain("props.status === 'needs-human' || props.status === 'needs-login'");
36
+ expect(ROW).toContain("'busy'");
37
+ });
38
+
39
+ it('★★ 无障碍只在有合法进度时挂:progressbar 三个值 + 可读文本', () => {
40
+ expect(BAR).toContain('role="progressbar"');
41
+ expect(BAR).toContain('aria-valuemin={0}');
42
+ expect(BAR).toContain('aria-valuemax={progress.total}');
43
+ expect(BAR).toContain('aria-valuenow={progress.done}');
44
+ expect(BAR).toContain('aria-valuetext');
45
+ expect(BAR).toContain('if (!longTaskProgressIsValid(progress)) return null;');
46
+ });
47
+
48
+ it('★ 条不吃指针、有减少动效的退路', () => {
49
+ expect(BAR_CSS).toContain('pointer-events: none');
50
+ expect(BAR_CSS).toContain('prefers-reduced-motion: reduce');
51
+ expect(BAR_CSS).toContain('corner-shape: round');
52
+ });
53
+ });
54
+
55
+
56
+ it('★★ 紧凑档标题折行(不硬切、不跑马灯);时间仍留在同一行右侧', () => {
57
+ expect(ROW).toContain('rowClassName="wb-longTaskHeadRow"');
58
+ expect(CSS).toMatch(/\.wb-longTaskDense \.wb-longTaskHeadRow\s*\{[^}]*height:\s*auto/);
59
+ expect(CSS).toMatch(/\.wb-longTaskDense \.wb-longTaskHeadline\s*\{[^}]*white-space:\s*normal/);
60
+ expect(ROW).not.toContain('useTextMarquee');
61
+ });
62
+
63
+ it('★★ 计划里还没开始的步骤列在已发生的后面(灰点),光有计划也能展开', () => {
64
+ expect(ROW).toContain('const pending = (props.pending ?? [])');
65
+ expect(ROW).toContain('history.length > 0 || steps.length > 0 || pending.length > 0');
66
+ expect(ROW).toContain('history.length === 0 && pending.length === 0 ? (');
67
+ expect(ROW).toContain('data-kind="pending"');
68
+ expect(ROW).toContain('<StateDot state="idle" size={8} />');
69
+ expect(CSS).toContain(".wb-longTaskStepRow[data-kind='pending'] .wb-longTaskStepText {");
70
+ });
71
+
10
72
  describe('两按停止钮:接线(这仓的组件测试是 node 环境,读源码断言)', () => {
11
73
  it('★★ 不给 stop ⇒ 那颗钮整个不出现(停止钮只有一处入口)', () => {
12
74
  expect(ROW).toContain('const stop = props.stop;');
@@ -265,14 +327,14 @@ describe('行内可读:当前步骤 / 状态 · 耗时 / 结构化步骤 / 停
265
327
  });
266
328
 
267
329
  it('★★ 没有 history 回退旧 CodeBlock:旧模块一个像素不变', () => {
268
- expect(ROW).toContain('history.length === 0 ? (');
330
+ expect(ROW).toContain('history.length === 0 && pending.length === 0 ? (');
269
331
  expect(ROW).toContain('code={steps.join(');
270
332
  });
271
333
 
272
334
  it('★★ 步骤块的展开不再绑死失败:给 stepsTitle 且有内容就画,失败默认开', () => {
273
335
  expect(ROW).toContain("useState(props.status === 'failed')");
274
336
  expect(ROW).toContain('if (failed) setStepsOpen(true);');
275
- expect(ROW).toContain('const expandable = props.stepsTitle !== undefined && (history.length > 0 || steps.length > 0);');
337
+ expect(ROW).toContain('props.stepsTitle !== undefined && (history.length > 0 || steps.length > 0 || pending.length > 0)');
276
338
  expect(ROW).toContain('open={expandable && stepsOpen}');
277
339
  expect(ROW).toContain('expandable={expandable}');
278
340
  });
@@ -348,25 +348,57 @@ export interface ApprovalInput {
348
348
  readonly args: Readonly<Record<string, unknown>>;
349
349
  }
350
350
 
351
+ /**
352
+ * 一条可以分多行的审批值:单字符串是一行,字符串数组由外壳按行排版。
353
+ */
354
+ export type ApprovalLines = string | readonly string[];
355
+
351
356
  /**
352
357
  * 审批详情里的一行附加事实:标签与值都由模块给。
353
358
  */
354
359
  export interface ApprovalPlanExtra {
360
+ /**
361
+ * 附加行的标签。
362
+ */
355
363
  readonly label: string;
356
- readonly value: string;
364
+ /**
365
+ * 附加行的值;字符串数组每项一行,最多 6 行。
366
+ */
367
+ readonly value: ApprovalLines;
357
368
  }
358
369
 
359
370
  /**
360
371
  * 模块审批详情的四行数据:对象、修改后、目标位置、影响范围,外加可选的领域标签、附加行与警告。
361
372
  */
362
373
  export interface ApprovalPlanData {
374
+ /**
375
+ * 修改项:这次改的是哪个对象。
376
+ */
363
377
  readonly object: string;
364
- readonly change: string;
378
+ /**
379
+ * 修改后:改成什么;多条事实用字符串数组,最多 6 行。
380
+ */
381
+ readonly change: ApprovalLines;
382
+ /**
383
+ * 目标位置:这次改在哪里。
384
+ */
365
385
  readonly target: string;
366
- readonly impact: string;
386
+ /**
387
+ * 影响范围:还会波及什么;多条事实用字符串数组,最多 6 行。
388
+ */
389
+ readonly impact: ApprovalLines;
390
+ /**
391
+ * 对象标签,默认「修改项」。
392
+ */
367
393
  readonly objectLabel?: string | undefined;
394
+ /**
395
+ * 附加事实行。
396
+ */
368
397
  readonly extra?: readonly ApprovalPlanExtra[] | undefined;
369
- readonly warn?: string | undefined;
398
+ /**
399
+ * 警告;多条事实用字符串数组,最多 6 行。
400
+ */
401
+ readonly warn?: ApprovalLines | undefined;
370
402
  }
371
403
 
372
404
  /**
@@ -0,0 +1,79 @@
1
+ import { useEffect, useMemo, useRef } from 'react';
2
+
3
+ const MIN_REVEAL_PX = 8;
4
+
5
+ const PX_PER_MS = 0.03;
6
+
7
+ /**
8
+ * 把一段被容器裁掉的文字在指针停留时横向推出来:会话列表的标题、长任务行的标题都用它。
9
+ */
10
+ export interface TextMarquee {
11
+ /** 指针进来:先量溢出,够一截才开始推;减少动效偏好下直接推到末尾。 */
12
+ enter(): void;
13
+ /** 指针离开:立刻回到起点,清掉两个 data 标记。 */
14
+ leave(): void;
15
+ }
16
+
17
+ function placeTitle(title: HTMLElement, left: number, range: number): void {
18
+ title.scrollTo({ left, behavior: 'instant' });
19
+ if (left > 0) title.dataset.scrolled = '';
20
+ else delete title.dataset.scrolled;
21
+ if (left < range) title.dataset.clipped = '';
22
+ else delete title.dataset.clipped;
23
+ }
24
+
25
+ function restTitle(title: HTMLElement): void {
26
+ title.scrollTo({ left: 0, behavior: 'instant' });
27
+ delete title.dataset.scrolled;
28
+ delete title.dataset.clipped;
29
+ }
30
+
31
+ /**
32
+ * 悬停推进的横向跑马灯:按帧累加 scrollLeft,回到起点即复位。
33
+ * @param target 现取滚动容器(元素归调用方所有,可能在子树里)。
34
+ * @returns 一对 enter / leave 指针回调。
35
+ */
36
+ export function useTextMarquee(target: () => HTMLElement | null): TextMarquee {
37
+ const frame = useRef(0);
38
+ const resolve = useRef(target);
39
+ useEffect(() => {
40
+ resolve.current = target;
41
+ });
42
+ useEffect(
43
+ () => () => {
44
+ cancelAnimationFrame(frame.current);
45
+ },
46
+ [],
47
+ );
48
+ return useMemo(
49
+ () => ({
50
+ enter: () => {
51
+ const element = resolve.current();
52
+ if (element === null) return;
53
+ const range = element.scrollWidth - element.clientWidth;
54
+ if (range <= MIN_REVEAL_PX) return;
55
+ if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
56
+ placeTitle(element, range, range);
57
+ return;
58
+ }
59
+ cancelAnimationFrame(frame.current);
60
+ let previous: number | undefined;
61
+ let position = 0;
62
+ const step = (now: number): void => {
63
+ position += previous === undefined ? 0 : (now - previous) * PX_PER_MS;
64
+ previous = now;
65
+ placeTitle(element, Math.min(position, range), range);
66
+ if (position < range) frame.current = requestAnimationFrame(step);
67
+ };
68
+ frame.current = requestAnimationFrame(step);
69
+ },
70
+ leave: () => {
71
+ cancelAnimationFrame(frame.current);
72
+ const element = resolve.current();
73
+ if (element === null) return;
74
+ restTitle(element);
75
+ },
76
+ }),
77
+ [],
78
+ );
79
+ }
@@ -0,0 +1,56 @@
1
+ .wb-progress {
2
+ display: flex;
3
+ flex: 1 1 auto;
4
+ width: 100%;
5
+ min-width: 0;
6
+ overflow: hidden;
7
+ border-radius: var(--wb-radius-pill);
8
+ corner-shape: round;
9
+ background: var(--dsw-alias-bg-skeleton);
10
+ pointer-events: none;
11
+ }
12
+
13
+ .wb-progress-6 {
14
+ height: var(--wb-len-6);
15
+ }
16
+
17
+ .wb-progress-4 {
18
+ height: var(--wb-len-4);
19
+ }
20
+
21
+ .wb-progress-2 {
22
+ height: var(--wb-len-2);
23
+ }
24
+
25
+ .wb-progressFill {
26
+ height: 100%;
27
+ border-radius: var(--wb-radius-pill);
28
+ corner-shape: round;
29
+ transition: width var(--wb-dur-1-5) ease;
30
+ }
31
+
32
+ @media (prefers-reduced-motion: reduce) {
33
+ .wb-progressFill {
34
+ transition: none;
35
+ }
36
+ }
37
+
38
+ .wb-progressFillNeutral {
39
+ background: var(--dsw-alias-label-tertiary);
40
+ }
41
+
42
+ .wb-progressFillOk {
43
+ background: var(--dsw-alias-state-success-primary);
44
+ }
45
+
46
+ .wb-progressFillWarn {
47
+ background: var(--dsw-alias-state-warn-primary);
48
+ }
49
+
50
+ .wb-progressFillBad {
51
+ background: var(--dsw-alias-state-error-primary);
52
+ }
53
+
54
+ .wb-progressFillBusy {
55
+ background: var(--dsw-alias-state-business-primary);
56
+ }