@dsh-workbench/shared 0.3.4 → 0.3.5

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 (180) hide show
  1. package/dist/api/blocker-table.d.ts +13 -0
  2. package/dist/api/blocker-table.js +13 -0
  3. package/dist/api/blocker.d.ts +6 -0
  4. package/dist/api/context-ref.d.ts +31 -0
  5. package/dist/api/context-ref.js +28 -0
  6. package/dist/api/dsh-client.d.ts +99 -0
  7. package/dist/api/dsh.d.ts +55 -3
  8. package/dist/api/facts.d.ts +42 -0
  9. package/dist/api/facts.js +33 -0
  10. package/dist/api/host-write.d.ts +18 -0
  11. package/dist/api/host-write.js +12 -0
  12. package/dist/api/long-task.d.ts +36 -0
  13. package/dist/api/long-task.js +27 -0
  14. package/dist/api/unit-board.d.ts +25 -0
  15. package/dist/api/unit-board.js +16 -0
  16. package/dist/api/unit-declaration.d.ts +36 -0
  17. package/dist/api/unit-declaration.js +24 -0
  18. package/dist/api/unit.d.ts +32 -0
  19. package/dist/api/unit.js +5 -0
  20. package/dist/api/workbench-client.d.ts +25 -0
  21. package/dist/api/workbench-client.js +13 -0
  22. package/dist/api/workbench-contract.d.ts +12 -0
  23. package/dist/components/Activity.d.ts +33 -0
  24. package/dist/components/Activity.js +24 -0
  25. package/dist/components/ApprovalDetail.d.ts +12 -0
  26. package/dist/components/ApprovalDetail.js +9 -0
  27. package/dist/components/ApprovalPlan.d.ts +14 -0
  28. package/dist/components/ApprovalPlan.js +8 -0
  29. package/dist/components/Card.d.ts +13 -0
  30. package/dist/components/Card.js +10 -0
  31. package/dist/components/CardAnchor.d.ts +14 -0
  32. package/dist/components/CardAnchor.js +11 -0
  33. package/dist/components/CardBoundary.d.ts +20 -0
  34. package/dist/components/CardBoundary.js +14 -0
  35. package/dist/components/CardHead.d.ts +13 -0
  36. package/dist/components/CardHead.js +10 -0
  37. package/dist/components/ChoiceGroup.d.ts +24 -0
  38. package/dist/components/ChoiceGroup.js +12 -0
  39. package/dist/components/Field.d.ts +10 -0
  40. package/dist/components/Field.js +7 -0
  41. package/dist/components/Form.css +6 -0
  42. package/dist/components/Form.d.ts +20 -0
  43. package/dist/components/Form.js +58 -0
  44. package/dist/components/FormActions.d.ts +14 -0
  45. package/dist/components/FormActions.js +5 -0
  46. package/dist/components/FormNodes.d.ts +103 -0
  47. package/dist/components/FormNodes.js +153 -0
  48. package/dist/components/FormRows.d.ts +20 -0
  49. package/dist/components/FormRows.js +14 -0
  50. package/dist/components/FormTypes.d.ts +59 -0
  51. package/dist/components/FormTypes.js +1 -0
  52. package/dist/components/Link.d.ts +12 -0
  53. package/dist/components/Link.js +9 -0
  54. package/dist/components/LongTaskRow.d.ts +19 -0
  55. package/dist/components/LongTaskRow.js +13 -0
  56. package/dist/components/Note.d.ts +11 -0
  57. package/dist/components/Note.js +8 -0
  58. package/dist/components/ResourceStates.d.ts +25 -0
  59. package/dist/components/ResourceStates.js +22 -0
  60. package/dist/components/Rows.d.ts +17 -0
  61. package/dist/components/Rows.js +11 -0
  62. package/dist/components/SaveBar.d.ts +12 -0
  63. package/dist/components/SaveBar.js +9 -0
  64. package/dist/components/SelectField.d.ts +26 -0
  65. package/dist/components/SelectField.js +22 -0
  66. package/dist/components/SelectFieldNodes.d.ts +24 -0
  67. package/dist/components/SelectFieldNodes.js +24 -0
  68. package/dist/components/SettingsSection.d.ts +11 -0
  69. package/dist/components/SettingsSection.js +8 -0
  70. package/dist/components/Spinner.d.ts +9 -0
  71. package/dist/components/Spinner.js +6 -0
  72. package/dist/components/Stack.d.ts +8 -0
  73. package/dist/components/Stack.js +5 -0
  74. package/dist/components/StateBlock.d.ts +13 -0
  75. package/dist/components/StateBlock.js +10 -0
  76. package/dist/components/TextField.d.ts +8 -0
  77. package/dist/components/TextField.js +5 -0
  78. package/dist/components/board-module.d.ts +30 -0
  79. package/dist/components/icons.d.ts +38 -0
  80. package/dist/components/icons.js +35 -0
  81. package/dist/config/constants.d.ts +42 -0
  82. package/dist/config/constants.js +42 -0
  83. package/dist/config/storage.d.ts +4 -0
  84. package/dist/config/storage.js +4 -0
  85. package/dist/host/unit-face.d.ts +5 -1
  86. package/dist/i18n/en.d.ts +1 -0
  87. package/dist/i18n/en.js +8 -8
  88. package/dist/i18n/index.d.ts +11 -9
  89. package/dist/i18n/index.js +1 -0
  90. package/dist/i18n/merge.d.ts +5 -0
  91. package/dist/i18n/merge.js +2 -0
  92. package/dist/i18n/zh.d.ts +9 -8
  93. package/dist/i18n/zh.js +8 -8
  94. package/dist/index.d.ts +6 -2
  95. package/dist/index.js +6 -2
  96. package/dist/lib/blocker-action.d.ts +22 -0
  97. package/dist/lib/blocker-action.js +13 -0
  98. package/dist/lib/board-fact.d.ts +27 -0
  99. package/dist/lib/board-fact.js +18 -0
  100. package/dist/lib/busy.d.ts +10 -0
  101. package/dist/lib/busy.js +7 -0
  102. package/dist/lib/diy-debug.d.ts +42 -2
  103. package/dist/lib/diy-debug.js +19 -1
  104. package/dist/lib/diy-record.d.ts +41 -0
  105. package/dist/lib/diy-record.js +17 -0
  106. package/dist/lib/form-problem.d.ts +10 -0
  107. package/dist/lib/form-problem.js +10 -0
  108. package/dist/lib/panel-state.d.ts +60 -0
  109. package/dist/lib/panel-state.js +30 -0
  110. package/dist/lib/react.d.ts +39 -0
  111. package/dist/lib/react.js +36 -0
  112. package/dist/lib/text.d.ts +22 -0
  113. package/dist/lib/text.js +22 -0
  114. package/dist/lib/ui.d.ts +50 -0
  115. package/dist/lib/ui.js +41 -0
  116. package/package.json +1 -1
  117. package/src/api/blocker-table.ts +13 -0
  118. package/src/api/blocker.ts +6 -0
  119. package/src/api/context-ref.ts +31 -0
  120. package/src/api/dsh-client.ts +99 -0
  121. package/src/api/dsh.ts +56 -1
  122. package/src/api/facts.ts +42 -0
  123. package/src/api/host-write.ts +18 -0
  124. package/src/api/long-task.ts +36 -0
  125. package/src/api/unit-board.ts +25 -0
  126. package/src/api/unit-declaration.ts +36 -0
  127. package/src/api/unit.ts +32 -0
  128. package/src/api/workbench-client.ts +25 -0
  129. package/src/api/workbench-contract.ts +12 -0
  130. package/src/components/Activity.tsx +33 -0
  131. package/src/components/ApprovalDetail.tsx +12 -0
  132. package/src/components/ApprovalPlan.tsx +14 -0
  133. package/src/components/Card.tsx +13 -0
  134. package/src/components/CardAnchor.tsx +14 -0
  135. package/src/components/CardBoundary.tsx +20 -0
  136. package/src/components/CardHead.tsx +13 -0
  137. package/src/components/ChoiceGroup.tsx +24 -0
  138. package/src/components/Field.tsx +10 -0
  139. package/src/components/Form.css +6 -0
  140. package/src/components/Form.test.tsx +475 -0
  141. package/src/components/Form.tsx +78 -0
  142. package/src/components/FormActions.tsx +14 -0
  143. package/src/components/FormNodes.tsx +193 -0
  144. package/src/components/FormRows.tsx +20 -0
  145. package/src/components/FormTypes.ts +65 -0
  146. package/src/components/FormWiring.test.tsx +88 -0
  147. package/src/components/Link.tsx +12 -0
  148. package/src/components/LongTaskRow.tsx +19 -0
  149. package/src/components/Note.tsx +11 -0
  150. package/src/components/ResourceStates.tsx +25 -0
  151. package/src/components/Rows.tsx +17 -0
  152. package/src/components/SaveBar.tsx +12 -0
  153. package/src/components/SelectField.tsx +26 -0
  154. package/src/components/SelectFieldNodes.tsx +24 -0
  155. package/src/components/SettingsSection.tsx +11 -0
  156. package/src/components/Spinner.tsx +9 -0
  157. package/src/components/Stack.tsx +8 -0
  158. package/src/components/StateBlock.tsx +13 -0
  159. package/src/components/TextField.tsx +8 -0
  160. package/src/components/board-module.ts +30 -0
  161. package/src/components/icons.tsx +38 -0
  162. package/src/config/constants.ts +43 -0
  163. package/src/config/storage.ts +4 -0
  164. package/src/host/unit-face.ts +6 -1
  165. package/src/i18n/en.ts +8 -8
  166. package/src/i18n/index.ts +3 -0
  167. package/src/i18n/merge.ts +5 -0
  168. package/src/i18n/zh.ts +9 -8
  169. package/src/index.ts +6 -2
  170. package/src/lib/blocker-action.ts +22 -0
  171. package/src/lib/board-fact.ts +27 -0
  172. package/src/lib/busy.ts +10 -0
  173. package/src/lib/diy-debug.test.ts +2 -1
  174. package/src/lib/diy-debug.ts +44 -3
  175. package/src/lib/diy-record.ts +41 -0
  176. package/src/lib/form-problem.ts +10 -0
  177. package/src/lib/panel-state.ts +60 -0
  178. package/src/lib/react.ts +39 -0
  179. package/src/lib/text.ts +22 -0
  180. package/src/lib/ui.ts +50 -0
package/src/i18n/merge.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Dictionaries } from './index.js';
2
2
 
3
+ /** 一个套件交上来的词表:`unit` 是套件 id(也是键前缀),`messages` 缺省表示这次不参与合并。 */
3
4
  export interface MessagesContribution {
4
5
  readonly unit: string;
5
6
  readonly messages?: Dictionaries | undefined;
@@ -23,6 +24,7 @@ function assertSelfConsistent(unit: string, messages: Dictionaries): void {
23
24
  }
24
25
  }
25
26
 
27
+ /** 把各套件的词表合到外壳底座上:键必须以 `<unit>.` 开头、不许撞已有键,违规当场抛错。 */
26
28
  export function mergeMessages(
27
29
  base: Dictionaries,
28
30
  contributions: readonly MessagesContribution[],
@@ -53,11 +55,13 @@ export function mergeMessages(
53
55
  return { zh, en };
54
56
  }
55
57
 
58
+ /** 一条没合进去的贡献:哪个套件 + 为什么被拒(人话原因)。 */
56
59
  export interface MessagesProblem {
57
60
  readonly unit: string;
58
61
  readonly reason: string;
59
62
  }
60
63
 
64
+ /** 合并结果:合出来的词表 + 被跳过的贡献;`problems` 为空即全部合上了。 */
61
65
  export interface MessagesMerge {
62
66
  readonly dictionaries: Dictionaries;
63
67
  readonly problems: readonly MessagesProblem[];
@@ -68,6 +72,7 @@ function reasonOf(error: unknown): string {
68
72
  return typeof error === 'string' ? error : String(error);
69
73
  }
70
74
 
75
+ /** 逐份试合、坏的跳过:一份贡献不合规只记进 `problems`,不影响其余套件与已有词表。 */
71
76
  export function mergeMessagesSkipping(
72
77
  base: Dictionaries,
73
78
  contributions: readonly MessagesContribution[],
package/src/i18n/zh.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /** 外壳自带的中文词表(命名空间 `workbench`):`en` 与它逐键对齐,模块那份在它之上合并。 */
1
2
  export const zh = {
2
3
  'brand.name': '工作台',
3
4
 
@@ -418,20 +419,19 @@ export const zh = {
418
419
  'configSync.emptyProviders': '工作台还没有任何模型供应商 —— 去「配置同步」从某个 profile 把 llm- 那几行搬过来,或自己去「模型」里配。',
419
420
  'configSync.failed': '同步没成功,再试一次。',
420
421
 
421
- 'debug.status': '工作台 DIY 开发调试中',
422
- 'debug.status.trouble': '工作台 DIY 开发调试异常',
423
- 'debug.stalled': '工作台 DIY 调试暂停',
422
+ 'debug.workspace': '这个工作区',
423
+ 'debug.status': '「{title}」调试中',
424
+ 'debug.status.trouble': '调试要你看一眼({title})',
425
+ 'debug.stalled': '调试已暂停({title})',
424
426
  'debug.act.pause': '暂停调试',
425
427
  'debug.act.resume': '继续调试',
426
428
  'debug.act.stop': '结束调试',
427
429
  'debug.act.stop.ask': '确认结束',
428
- 'debug.card.here.title': '当前工作台 DIY 开发调试中',
430
+ 'debug.card.here.title': '正在调试「{title}」',
429
431
  'debug.card.here.note': '请勿切换工作区和操作面板',
430
- 'debug.card.away.title': '工作台 DIY 开发调试中',
431
- 'debug.card.away.note': '请切换到工作台 DIY 工作区',
432
+ 'debug.card.away.note': '请切回「{title}」那一屏',
432
433
  'debug.card.paused.note': '已暂停',
433
- 'debug.card.hidden.note': '请切换到工作台面板',
434
- 'debug.back': '回到工坊那一屏',
434
+ 'debug.card.hidden.note': '请切回工作台面板',
435
435
  'record.waiting': '取证交接 · 等你出手',
436
436
  'record.waiting.note': '请在那一页按「开始录制」,做完按「结束录制」(录完不替你切回来)',
437
437
  'record.recording': '录制中',
@@ -448,4 +448,5 @@ export const zh = {
448
448
  'approval.record.noSwitch': '录完不会替你切回来(左栏底部会亮一条状态)',
449
449
  } as const;
450
450
 
451
+ /** 中文词表的键类型:`en` 与模块词表都得覆盖同一批键。 */
451
452
  export type WorkbenchMessages = typeof zh;
package/src/index.ts CHANGED
@@ -20,8 +20,11 @@ export * from './components/CardBoundary.js';
20
20
  export * from './components/CardHead.js';
21
21
  export * from './components/ChoiceGroup.js';
22
22
  export * from './components/Field.js';
23
+ export * from './components/Form.js';
23
24
  export * from './components/FormActions.js';
25
+ export * from './components/FormNodes.js';
24
26
  export * from './components/FormRows.js';
27
+ export * from './components/FormTypes.js';
25
28
  export * from './components/Link.js';
26
29
  export * from './components/LongTaskRow.js';
27
30
  export * from './components/Note.js';
@@ -29,6 +32,7 @@ export * from './components/ResourceStates.js';
29
32
  export * from './components/Rows.js';
30
33
  export * from './components/SaveBar.js';
31
34
  export * from './components/SelectField.js';
35
+ export * from './components/SelectFieldNodes.js';
32
36
  export * from './components/SettingsSection.js';
33
37
  export * from './components/Spinner.js';
34
38
  export * from './components/Stack.js';
@@ -43,11 +47,11 @@ export * from './i18n/index.js';
43
47
  export * from './i18n/merge.js';
44
48
  export * from './i18n/zh.js';
45
49
  export * from './lib/blocker-action.js';
46
- export * from './lib/busy.js';
47
- export * from './lib/form-problem.js';
48
50
  export * from './lib/board-fact.js';
51
+ export * from './lib/busy.js';
49
52
  export * from './lib/diy-debug.js';
50
53
  export * from './lib/diy-record.js';
54
+ export * from './lib/form-problem.js';
51
55
  export * from './lib/panel-state.js';
52
56
  export * from './lib/react.js';
53
57
  export * from './lib/text.js';
@@ -1,21 +1,43 @@
1
+ /**
2
+ * 阻断态取词:i18n 的 `(key) => 文案` 那一半;那几颗钮的「重试中…」等临时说法都从它来。
3
+ */
1
4
  export type BlockerLabelTranslate = (key: string) => string;
2
5
 
6
+ /**
7
+ * 阻断态上一颗钮的形状:`kind` 定行为(`retry` / `copy` 等),`label` 是它平时的文案。
8
+ */
3
9
  export interface BlockerActionShape {
4
10
  readonly kind: string;
5
11
  readonly label: string;
6
12
  readonly text?: string | undefined;
7
13
  }
8
14
 
15
+ /**
16
+ * 这颗钮此刻的运行态:是否正在重试、哪一支正在跑(按 label 认)、刚复制过哪段文本。
17
+ */
9
18
  export interface BlockerLabelState {
10
19
  readonly retrying: boolean;
11
20
  readonly running: string | null;
12
21
  readonly copied: string | null;
13
22
  }
14
23
 
24
+ /**
25
+ * 这颗钮此刻该不该按成等待态:这一轮忙还没收,或有一支正在跑。
26
+ * @param busy - 这一轮忙是不是还在。
27
+ * @param running - 正在跑的那一支的 label;没有就给 `null`。
28
+ * @returns 该等待给 `true`,否则 `false`。
29
+ */
15
30
  export function blockerPending(busy: boolean, running: string | null): boolean {
16
31
  return busy || running !== null;
17
32
  }
18
33
 
34
+ /**
35
+ * 这颗钮此刻该显示什么字:正在重试说「重试中…」,正在跑的那一支说「修复中…」,刚复制过的说「已复制」,其余原样。
36
+ * @param action - 这颗钮的形状(行为 + 平时文案)。
37
+ * @param state - 此刻的运行态。
38
+ * @param t - i18n 取词函数。
39
+ * @returns 要显示的文案;三种临时态都不成立时就是 `action.label`。
40
+ */
19
41
  export function blockerActionLabel(
20
42
  action: BlockerActionShape,
21
43
  state: BlockerLabelState,
@@ -1,9 +1,15 @@
1
+ /**
2
+ * 椅面(右栏那块画板)此刻归属哪一类:`workshop` 本工坊、`other` 别家、`hidden` 没画出来、`unknown` 探不到。
3
+ */
1
4
  export type BoardFactState =
2
5
  | 'workshop'
3
6
  | 'other'
4
7
  | 'hidden'
5
8
  | 'unknown';
6
9
 
10
+ /**
11
+ * 左栏底部「调试」那条状态要说的档位:`ok` 在板上、`off-workspace` 切去了别的项目、`panel-closed` 面板没开、`other-board` 画的是别家的板、`unknown` 探不到。
12
+ */
7
13
  export type BoardSituation =
8
14
  | 'ok'
9
15
  | 'off-workspace'
@@ -11,6 +17,9 @@ export type BoardSituation =
11
17
  | 'other-board'
12
18
  | 'unknown';
13
19
 
20
+ /**
21
+ * 一次页面探针的读数:外壳在不在、探的是哪个工作区、右栏开没开、板上挂的路径、椅面画出来没有。
22
+ */
14
23
  export interface BoardProbe {
15
24
  readonly workbench: boolean;
16
25
  readonly where: string;
@@ -20,12 +29,24 @@ export interface BoardProbe {
20
29
  readonly drawn: boolean;
21
30
  }
22
31
 
32
+ /**
33
+ * 判一个路径落不落在这个工作区里(按路径前缀比,不是字符串包含)。
34
+ * @param root - 工作区根路径。
35
+ * @param target - 要判的路径。
36
+ * @returns 同一个路径或在其下给 `true`;`root` 末尾带不带斜杠都认(`/a` 不匹配 `/ab`)。
37
+ */
23
38
  export function insideWorkshop(root: string, target: string): boolean {
24
39
  if (target === root) return true;
25
40
  const base = root.endsWith('/') ? root : `${root}/`;
26
41
  return target.startsWith(base);
27
42
  }
28
43
 
44
+ /**
45
+ * 把一次探针读数归成椅面归属。
46
+ * @param probe - 探针读数。
47
+ * @param workshop - 当前工作区根路径;`null` 表示还不知道当前是哪个工作区。
48
+ * @returns 外壳不在、或板路径与工作区缺一 → `unknown`;右栏没开或没画出来 → `hidden`;板在本工作区 → `workshop`,否则 `other`。
49
+ */
29
50
  export function boardFactOf(probe: BoardProbe, workshop: string | null): BoardFactState {
30
51
  if (!probe.workbench) return 'unknown';
31
52
  if (!probe.bar || !probe.open || !probe.drawn) return 'hidden';
@@ -33,6 +54,12 @@ export function boardFactOf(probe: BoardProbe, workshop: string | null): BoardFa
33
54
  return insideWorkshop(workshop, probe.board) ? 'workshop' : 'other';
34
55
  }
35
56
 
57
+ /**
58
+ * 把探针读数归成左栏那句人话的档位。
59
+ * @param probe - 探针读数。
60
+ * @param workshop - 当前工作区根路径;`null` 一律 `unknown`。
61
+ * @returns 椅面画着 → 本板 `ok` / 别板 `other-board`;没画着 → 页面已走 `off-workspace`,否则 `panel-closed`。
62
+ */
36
63
  export function boardSituation(probe: BoardProbe, workshop: string | null): BoardSituation {
37
64
  if (!probe.workbench || workshop === null) return 'unknown';
38
65
  const drawn = probe.bar && probe.open && probe.drawn;
package/src/lib/busy.ts CHANGED
@@ -1,8 +1,18 @@
1
+ /**
2
+ * 忙态按下限收尾的判据结果:还该不该显示(`visible`),以及还要按住多少毫秒(`releaseInMs`,0 = 立刻可收)。
3
+ */
1
4
  export interface BusyHold {
2
5
  readonly visible: boolean;
3
6
  readonly releaseInMs: number;
4
7
  }
5
8
 
9
+ /**
10
+ * 按「至少显示 floorMs」算这一轮忙此刻该不该收:没到下限就继续显示,并给出剩余时长供调用方起定时器。
11
+ * @param since - 这一轮忙开始的时间戳;`null`(没开过这一轮)一律不显示。
12
+ * @param now - 当前时间戳。
13
+ * @param floorMs - 至少显示的时长(毫秒)。
14
+ * @returns 还该不该显示 + 剩余毫秒;到点或已过下限给不显示,时钟倒退按「刚开头」算(剩余 = 下限,不给负数)。
15
+ */
6
16
  export function holdBusy(since: number | null, now: number, floorMs: number): BusyHold {
7
17
  if (since === null) return { visible: false, releaseInMs: 0 };
8
18
  const elapsed = Math.max(0, now - since);
@@ -3,7 +3,8 @@ import { DEBUG_STALE_MS, createDebugStore, parseDebugIntent, type DebugPact } fr
3
3
 
4
4
  const pact = (sessionId: string, now = 1000, unit = 'demo'): DebugPact => ({
5
5
  sessionId,
6
- workspace: '/w/diy',
6
+ workspacePath: '/w/diy',
7
+ title: '演示工作区',
7
8
  board: '/w/diy',
8
9
  unit,
9
10
  name: unit,
@@ -1,17 +1,35 @@
1
+ /**
2
+ * 调试约定的两个相位:`debugging` 正占着用户的屏,`paused` 已暂停但仍持着约定。
3
+ */
1
4
  export type DebugPhase = 'debugging' | 'paused';
2
5
 
6
+ /**
7
+ * 调试约定收得下的三个人话动作:暂停 / 继续 / 结束。
8
+ */
3
9
  export type DebugIntent = 'pause' | 'resume' | 'stop';
4
10
 
11
+ /**
12
+ * 把工具入参收成人话动作。
13
+ * @param value - 任意入参值。
14
+ * @returns `'pause'` / `'resume'` / `'stop'` 原样;别的值(含 `undefined`、多余空白、大小写不同)给 `null`,由调用方拒。
15
+ */
5
16
  export function parseDebugIntent(value: unknown): DebugIntent | null {
6
17
  return value === 'pause' || value === 'resume' || value === 'stop' ? value : null;
7
18
  }
8
19
 
20
+ /**
21
+ * 调试约定的有效期(4 小时,毫秒):超过它没动静的约定算过期、当场让人。
22
+ */
9
23
  export const DEBUG_STALE_MS = 4 * 60 * 60 * 1000;
10
24
 
25
+ /**
26
+ * 一份活着的调试约定:相位 + 谁的会话 + 哪个工作区 / 板 / 单元 + 起于何时(`at` 是最后一次动作)。
27
+ */
11
28
  export interface DebugState {
12
29
  readonly phase: DebugPhase;
13
30
  readonly sessionId: string;
14
- readonly workspace: string;
31
+ readonly workspacePath: string;
32
+ readonly title: string;
15
33
  readonly board: string;
16
34
  readonly unit: string;
17
35
  readonly name: string;
@@ -19,15 +37,22 @@ export interface DebugState {
19
37
  readonly at: number;
20
38
  }
21
39
 
40
+ /**
41
+ * 建立约定要交的那几件:会话、工作区、板、单元、名字,以及此刻的时间戳。
42
+ */
22
43
  export interface DebugPact {
23
44
  readonly sessionId: string;
24
- readonly workspace: string;
45
+ readonly workspacePath: string;
46
+ readonly title: string;
25
47
  readonly board: string;
26
48
  readonly unit: string;
27
49
  readonly name: string;
28
50
  readonly now: number;
29
51
  }
30
52
 
53
+ /**
54
+ * 约定被拒的原因码:自己已持有 / 别人持着 / 不是持有者 / 没有约定 / 已暂停 / 已在调试。
55
+ */
31
56
  export type DebugRefusal =
32
57
  | 'already-held'
33
58
  | 'held-by-other'
@@ -36,10 +61,16 @@ export type DebugRefusal =
36
61
  | 'already-paused'
37
62
  | 'already-debugging';
38
63
 
64
+ /**
65
+ * 一次约定动作的结果:成功带新状态,失败带拒绝码。
66
+ */
39
67
  export type DebugMove =
40
68
  | { readonly ok: true; readonly state: DebugState }
41
69
  | { readonly ok: false; readonly code: DebugRefusal };
42
70
 
71
+ /**
72
+ * 调试约定的存取口(外壳持有一份):`live` 取当前有效的约定,`begin` / `pause` / `resume` / `stop` 推相位。
73
+ */
43
74
  export interface DebugStore {
44
75
  live(now: number): DebugState | null;
45
76
  begin(pact: DebugPact): DebugMove;
@@ -60,6 +91,10 @@ function ownerOf(state: DebugState | null, sessionId: string, now: number): Debu
60
91
  return held.sessionId === sessionId ? held : 'not-owner';
61
92
  }
62
93
 
94
+ /**
95
+ * 造一份新的调试约定存储(进程内存,同一时刻只可能有一份有效约定)。
96
+ * @returns 存取口;动作成不成都在返回的 `DebugMove` 里,不抛异常。
97
+ */
63
98
  export function createDebugStore(): DebugStore {
64
99
  let held: DebugState | null = null;
65
100
 
@@ -76,7 +111,8 @@ export function createDebugStore(): DebugStore {
76
111
  const state: DebugState = {
77
112
  phase: 'debugging',
78
113
  sessionId: pact.sessionId,
79
- workspace: pact.workspace,
114
+ workspacePath: pact.workspacePath,
115
+ title: pact.title,
80
116
  board: pact.board,
81
117
  unit: pact.unit,
82
118
  name: pact.name,
@@ -114,6 +150,11 @@ export function createDebugStore(): DebugStore {
114
150
  };
115
151
  }
116
152
 
153
+ /**
154
+ * 「谁还占着」的一句话,用于别人来抢时说清现况。
155
+ * @param state - 当前有效的那份约定。
156
+ * @returns 形如「会话 x(自 HH:mm:ssZ 起在调试 y)」的中文串。
157
+ */
117
158
  export function debugOwnerText(state: DebugState): string {
118
159
  return `会话 ${state.sessionId}(自 ${new Date(state.startedAt).toISOString().slice(11, 19)}Z 起在调试 ${state.unit})`;
119
160
  }
@@ -1,12 +1,24 @@
1
+ /**
2
+ * 录制交接的三个相位:`armed` 等用户在外站页面上动手,`recording` 正在录,`finished` 录完待取。
3
+ */
1
4
  export type RecordPhase = 'armed' | 'recording' | 'finished';
2
5
 
6
+ /**
7
+ * 录制约定的有效期(15 分钟,毫秒):超过它没动静的约定算过期、当场让人。
8
+ */
3
9
  export const RECORD_STALE_MS = 15 * 60 * 1000;
4
10
 
11
+ /**
12
+ * 这次录制要找的那一次写:HTTP 方法 + URL 里必须含的一段(不填就是只认方法)。
13
+ */
5
14
  export interface RecordExpect {
6
15
  readonly method: string;
7
16
  readonly urlContains: string;
8
17
  }
9
18
 
19
+ /**
20
+ * 一份活着的录制约定:相位 + 谁的会话 + 哪个工作区 / 单元 + 页面 URL 与标题 + 要找的那一次写 + 落盘文件 + 三个时间戳。
21
+ */
10
22
  export interface RecordState {
11
23
  readonly phase: RecordPhase;
12
24
  readonly sessionId: string;
@@ -24,6 +36,9 @@ export interface RecordState {
24
36
  readonly at: number;
25
37
  }
26
38
 
39
+ /**
40
+ * 开一次录制要交的那几件:会话、工作区、单元、名字、页面 URL 与标题、动作名、期望、落盘文件,以及此刻时间。
41
+ */
27
42
  export interface RecordPact {
28
43
  readonly sessionId: string;
29
44
  readonly workspace: string;
@@ -37,6 +52,9 @@ export interface RecordPact {
37
52
  readonly now: number;
38
53
  }
39
54
 
55
+ /**
56
+ * 录制被拒的原因码:自己已持有 / 别人持着 / 不是持有者 / 没有约定 / 已在录 / 还没 arm / 不在录 / 还没录完。
57
+ */
40
58
  export type RecordRefusal =
41
59
  | 'already-held'
42
60
  | 'held-by-other'
@@ -47,16 +65,30 @@ export type RecordRefusal =
47
65
  | 'not-recording'
48
66
  | 'not-finished';
49
67
 
68
+ /**
69
+ * 一次录制动作的结果:成功带新状态,失败带拒绝码。
70
+ */
50
71
  export type RecordMove =
51
72
  | { readonly ok: true; readonly state: RecordState }
52
73
  | { readonly ok: false; readonly code: RecordRefusal };
53
74
 
75
+ /**
76
+ * 录制约定收得下的三个人话动作:看看进度 / 停手 / 结束并取回。
77
+ */
54
78
  export type RecordIntent = 'peek' | 'halt' | 'stop';
55
79
 
80
+ /**
81
+ * 把工具入参收成人话动作。
82
+ * @param raw - 任意入参值。
83
+ * @returns `'peek'` / `'halt'` / `'stop'` 原样;别的值(含 `undefined`、多余空白)给 `null`,由调用方拒。
84
+ */
56
85
  export function parseRecordIntent(raw: unknown): RecordIntent | null {
57
86
  return raw === 'peek' || raw === 'halt' || raw === 'stop' ? raw : null;
58
87
  }
59
88
 
89
+ /**
90
+ * 录制约定的存取口(外壳持有一份):相位随 `begin → started → finished` 推进,`release` 是收尾时放掉浏览器那一跳。
91
+ */
60
92
  export interface RecordStore {
61
93
  readonly release?: ((state: RecordState) => Promise<{ readonly tab: boolean; readonly capture: boolean }>) | undefined;
62
94
  live(now: number): RecordState | null;
@@ -77,6 +109,10 @@ function ownerOf(state: RecordState | null, sessionId: string, now: number): Rec
77
109
  return held.sessionId === sessionId ? held : 'not-owner';
78
110
  }
79
111
 
112
+ /**
113
+ * 造一份新的录制约定存储(进程内存,同一时刻只可能有一份有效约定)。
114
+ * @returns 存取口;动作成不成都在返回的 `RecordMove` 里,不抛异常。
115
+ */
80
116
  export function createRecordStore(): RecordStore {
81
117
  let held: RecordState | null = null;
82
118
 
@@ -138,6 +174,11 @@ export function createRecordStore(): RecordStore {
138
174
  };
139
175
  }
140
176
 
177
+ /**
178
+ * 「谁还占着、在录哪个动作」的一句话,用于别人来抢时说清现况。
179
+ * @param state - 当前有效的那份约定。
180
+ * @returns 形如「会话 x(自 HH:mm:ssZ 起在录 y 的「动作」)」的中文串。
181
+ */
141
182
  export function recordOwnerText(state: RecordState): string {
142
183
  const at = new Date(state.startedAt).toISOString().slice(11, 19);
143
184
  return `会话 ${state.sessionId}(自 ${at}Z 起在录 ${state.unit} 的「${state.action}」)`;
@@ -9,10 +9,20 @@ const FOCUSABLE_SELECTOR = [
9
9
  '[tabindex]:not([tabindex="-1"])',
10
10
  ].join(', ');
11
11
 
12
+ /**
13
+ * 找 `root` 里第一个带 `[data-wb-problem]` 标记的元素 —— 表单校验失败时,调用方拿它定位「哪一格错了」。
14
+ * @param root - 要搜的范围(表单容器,或 document)。
15
+ * @returns 第一个出问题的元素;一个标记都没有就给 `null`。
16
+ */
12
17
  export function firstProblemOf(root: ParentNode): Element | null {
13
18
  return root.querySelector(PROBLEM_SELECTOR);
14
19
  }
15
20
 
21
+ /**
22
+ * 把第一个出问题的元素滚进视野、并把焦点交给它里面第一个可聚焦控件(输入框 / 按钮 / 链接等)。
23
+ * @param root - 要搜的范围。
24
+ * @returns 找到并滚过给 `true`;没有问题给 `false`(不滚、不抢焦点);元素不可滚或没有可聚焦控件也不报错,只是少做一步。
25
+ */
16
26
  export function revealFirstProblem(root: ParentNode): boolean {
17
27
  const problem = firstProblemOf(root);
18
28
  if (problem === null) return false;
@@ -1,10 +1,19 @@
1
+ /**
2
+ * 一张面板卡片取数走到哪一步:`idle` 还没取、`loading` 取着、`ready` 拿到了、`error` 失败了。
3
+ */
1
4
  export type PanelCardPhase = 'idle' | 'loading' | 'ready' | 'error';
2
5
 
6
+ /**
7
+ * 一次取数失败:机器码 + 给人看的一句话。
8
+ */
3
9
  export interface PanelCardError {
4
10
  readonly code: string;
5
11
  readonly message: string;
6
12
  }
7
13
 
14
+ /**
15
+ * 一张卡片最近一次取数的读数:哪个单元、哪条路由、什么相位、什么时候、失败原因。
16
+ */
8
17
  export interface PanelCardRead {
9
18
  readonly unit: string;
10
19
  readonly route: string;
@@ -13,6 +22,9 @@ export interface PanelCardRead {
13
22
  readonly error?: PanelCardError;
14
23
  }
15
24
 
25
+ /**
26
+ * 一张卡片崩了的读数:单元、原因、时间,以及同一原因连着崩了几次(窗口见 `PANEL_STATE_CRASH_WINDOW_MS`)。
27
+ */
16
28
  export interface PanelCardCrash {
17
29
  readonly unit: string;
18
30
  readonly reason: string;
@@ -20,6 +32,9 @@ export interface PanelCardCrash {
20
32
  readonly count: number;
21
33
  }
22
34
 
35
+ /**
36
+ * 一个单元此刻的读数:它的卡片、最近一次读成的时间(`okAt`,没成过给 `null`),以及崩了的那一条。
37
+ */
23
38
  export interface PanelUnitReport {
24
39
  readonly unit: string;
25
40
  readonly at: number;
@@ -28,17 +43,26 @@ export interface PanelUnitReport {
28
43
  readonly crash?: PanelCardCrash;
29
44
  }
30
45
 
46
+ /**
47
+ * 一个工作区此刻的全量读数(面板按工作区存):所有单元的读数 + 整块最近动过的时间。
48
+ */
31
49
  export interface PanelWorkspaceReport {
32
50
  readonly workspace: string | null;
33
51
  readonly at: number;
34
52
  readonly units: readonly PanelUnitReport[];
35
53
  }
36
54
 
55
+ /**
56
+ * 客户端往上报的一批卡片读数(`POST` 请求体的形状)。
57
+ */
37
58
  export interface PanelCardsReport {
38
59
  readonly workspace: string;
39
60
  readonly cards: readonly PanelCardRead[];
40
61
  }
41
62
 
63
+ /**
64
+ * 客户端往上报的一次卡片崩溃(`POST` 请求体的形状)。
65
+ */
42
66
  export interface PanelCrashReport {
43
67
  readonly workspace: string;
44
68
  readonly unit: string;
@@ -46,16 +70,34 @@ export interface PanelCrashReport {
46
70
  readonly at: number;
47
71
  }
48
72
 
73
+ /**
74
+ * 面板运行态的留存口(宿主持有一份):收卡片读数与崩溃,按工作区取快照。
75
+ */
49
76
  export interface PanelStateStore {
50
77
  cards(report: PanelCardsReport): void;
51
78
  crash(report: PanelCrashReport): void;
52
79
  snapshot(workspace: string | null): PanelWorkspaceReport;
53
80
  }
54
81
 
82
+ /**
83
+ * 留存的工作区上限(LRU,满 64 个丢最旧的)。
84
+ */
55
85
  export const PANEL_STATE_MAX_UNITS = 64;
86
+ /**
87
+ * 每个单元留存的卡片上限(按路由 LRU,满 12 张丢最旧的)。
88
+ */
56
89
  export const PANEL_STATE_MAX_CARDS = 12;
90
+ /**
91
+ * 一次上报最多读入的卡片条数(32 条之后的丢掉)。
92
+ */
57
93
  export const PANEL_STATE_MAX_REPORTS = 32;
94
+ /**
95
+ * 同一原因的连续崩溃算进同一次计数的窗口(10 分钟,毫秒)。
96
+ */
58
97
  export const PANEL_STATE_CRASH_WINDOW_MS = 600000;
98
+ /**
99
+ * 上报文本字段的截断长度(2000 字符;workspace / reason / message 共用)。
100
+ */
59
101
  export const PANEL_STATE_MAX_TEXT = 2000;
60
102
 
61
103
  const PHASES: readonly PanelCardPhase[] = ['idle', 'loading', 'ready', 'error'];
@@ -71,6 +113,9 @@ interface WorkspaceEntry {
71
113
  units: Map<string, UnitEntry>;
72
114
  }
73
115
 
116
+ /**
117
+ * 上报解析的结果:`ok: true` 带收好的值,`ok: false` 带一句中文原因(直接回给上报方)。
118
+ */
74
119
  export type PanelParse<T> =
75
120
  | { readonly ok: true; readonly value: T }
76
121
  | { readonly ok: false; readonly message: string };
@@ -100,6 +145,12 @@ function errorOf(raw: unknown): PanelCardError | undefined {
100
145
  return { code: code === '' ? 'unknown' : code, message };
101
146
  }
102
147
 
148
+ /**
149
+ * 收一批卡片读数上报。
150
+ * @param payload - `POST` 的请求体。
151
+ * @returns 至少收到一条能认的卡片才 `ok: true`;请求体不是对象、`workspace` 为空、`cards` 不是数组,
152
+ * 或一条都认不出(`unit` / `route` / `phase` / `at` 缺一)时 `ok: false` + 中文原因;认不出的单条静默跳过。
153
+ */
103
154
  export function parseCardsReport(payload: unknown): PanelParse<PanelCardsReport> {
104
155
  const record = asRecord(payload);
105
156
  if (record === undefined) return { ok: false, message: '请求体要是一个对象' };
@@ -123,6 +174,11 @@ export function parseCardsReport(payload: unknown): PanelParse<PanelCardsReport>
123
174
  return { ok: true, value: { workspace, cards } };
124
175
  }
125
176
 
177
+ /**
178
+ * 收一次卡片崩溃上报。
179
+ * @param payload - `POST` 的请求体。
180
+ * @returns `workspace` / `unit` / `reason` 都不能空,缺一给 `ok: false` + 中文原因;`at` 缺省或不合法时取当前时间。
181
+ */
126
182
  export function parseCrashReport(payload: unknown): PanelParse<PanelCrashReport> {
127
183
  const record = asRecord(payload);
128
184
  if (record === undefined) return { ok: false, message: '请求体要是一个对象' };
@@ -135,6 +191,10 @@ export function parseCrashReport(payload: unknown): PanelParse<PanelCrashReport>
135
191
  return { ok: true, value: { workspace, unit, reason, at: atOf(record['at']) ?? Date.now() } };
136
192
  }
137
193
 
194
+ /**
195
+ * 造一份面板运行态的留存(进程内存、按工作区分桶,带上面那几条上限的 LRU)。
196
+ * @returns 留存口:`cards` / `crash` 收上报,`snapshot(workspace)` 取全量;没存过的工作区(含 `null`)给一份空的。
197
+ */
138
198
  export function createPanelStateStore(): PanelStateStore {
139
199
  const workspaces = new Map<string, WorkspaceEntry>();
140
200