@dsh-workbench/shared 0.3.3 → 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 (193) 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 +19 -1
  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 +15 -1
  26. package/dist/components/ApprovalDetail.js +13 -1
  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 +45 -0
  82. package/dist/config/constants.js +45 -0
  83. package/dist/config/storage.d.ts +4 -0
  84. package/dist/config/storage.js +4 -0
  85. package/dist/host/browser-read.d.ts +1 -0
  86. package/dist/host/browser-read.js +1 -0
  87. package/dist/host/http.d.ts +3 -0
  88. package/dist/host/http.js +10 -1
  89. package/dist/host/tool-approval.d.ts +5 -0
  90. package/dist/host/tool-approval.js +11 -5
  91. package/dist/host/unit-face.d.ts +5 -1
  92. package/dist/host.d.ts +1 -0
  93. package/dist/host.js +1 -0
  94. package/dist/i18n/en.d.ts +1 -0
  95. package/dist/i18n/en.js +22 -8
  96. package/dist/i18n/index.d.ts +25 -9
  97. package/dist/i18n/index.js +1 -0
  98. package/dist/i18n/merge.d.ts +5 -0
  99. package/dist/i18n/merge.js +2 -0
  100. package/dist/i18n/zh.d.ts +23 -8
  101. package/dist/i18n/zh.js +22 -8
  102. package/dist/index.d.ts +7 -2
  103. package/dist/index.js +7 -2
  104. package/dist/lib/blocker-action.d.ts +22 -0
  105. package/dist/lib/blocker-action.js +13 -0
  106. package/dist/lib/board-fact.d.ts +27 -0
  107. package/dist/lib/board-fact.js +18 -0
  108. package/dist/lib/busy.d.ts +10 -0
  109. package/dist/lib/busy.js +7 -0
  110. package/dist/lib/diy-debug.d.ts +42 -2
  111. package/dist/lib/diy-debug.js +19 -1
  112. package/dist/lib/diy-record.d.ts +98 -0
  113. package/dist/lib/diy-record.js +96 -0
  114. package/dist/lib/form-problem.d.ts +10 -0
  115. package/dist/lib/form-problem.js +10 -0
  116. package/dist/lib/panel-state.d.ts +60 -0
  117. package/dist/lib/panel-state.js +30 -0
  118. package/dist/lib/react.d.ts +39 -0
  119. package/dist/lib/react.js +36 -0
  120. package/dist/lib/text.d.ts +22 -0
  121. package/dist/lib/text.js +22 -0
  122. package/dist/lib/ui.d.ts +50 -0
  123. package/dist/lib/ui.js +41 -0
  124. package/package.json +1 -1
  125. package/src/api/blocker-table.ts +13 -0
  126. package/src/api/blocker.ts +6 -0
  127. package/src/api/context-ref.ts +31 -0
  128. package/src/api/dsh-client.ts +99 -0
  129. package/src/api/dsh.ts +56 -1
  130. package/src/api/facts.ts +42 -0
  131. package/src/api/host-write.ts +20 -1
  132. package/src/api/long-task.ts +36 -0
  133. package/src/api/unit-board.ts +25 -0
  134. package/src/api/unit-declaration.ts +36 -0
  135. package/src/api/unit.ts +32 -0
  136. package/src/api/workbench-client.ts +25 -0
  137. package/src/api/workbench-contract.ts +12 -0
  138. package/src/components/Activity.tsx +33 -0
  139. package/src/components/ApprovalDetail.tsx +17 -1
  140. package/src/components/ApprovalPlan.tsx +14 -0
  141. package/src/components/Card.tsx +13 -0
  142. package/src/components/CardAnchor.tsx +14 -0
  143. package/src/components/CardBoundary.tsx +20 -0
  144. package/src/components/CardHead.tsx +13 -0
  145. package/src/components/ChoiceGroup.tsx +24 -0
  146. package/src/components/Field.tsx +10 -0
  147. package/src/components/Form.css +6 -0
  148. package/src/components/Form.test.tsx +475 -0
  149. package/src/components/Form.tsx +78 -0
  150. package/src/components/FormActions.tsx +14 -0
  151. package/src/components/FormNodes.tsx +193 -0
  152. package/src/components/FormRows.tsx +20 -0
  153. package/src/components/FormTypes.ts +65 -0
  154. package/src/components/FormWiring.test.tsx +88 -0
  155. package/src/components/Link.tsx +12 -0
  156. package/src/components/LongTaskRow.tsx +19 -0
  157. package/src/components/Note.tsx +11 -0
  158. package/src/components/ResourceStates.tsx +25 -0
  159. package/src/components/Rows.tsx +17 -0
  160. package/src/components/SaveBar.tsx +12 -0
  161. package/src/components/SelectField.tsx +26 -0
  162. package/src/components/SelectFieldNodes.tsx +24 -0
  163. package/src/components/SettingsSection.tsx +11 -0
  164. package/src/components/Spinner.tsx +9 -0
  165. package/src/components/Stack.tsx +8 -0
  166. package/src/components/StateBlock.tsx +13 -0
  167. package/src/components/TextField.tsx +8 -0
  168. package/src/components/board-module.ts +30 -0
  169. package/src/components/icons.tsx +38 -0
  170. package/src/config/constants.ts +48 -0
  171. package/src/config/storage.ts +4 -0
  172. package/src/host/browser-read.ts +1 -0
  173. package/src/host/http.ts +15 -1
  174. package/src/host/tool-approval.ts +18 -4
  175. package/src/host/unit-face.ts +6 -1
  176. package/src/host.ts +1 -0
  177. package/src/i18n/en.ts +22 -8
  178. package/src/i18n/index.ts +3 -0
  179. package/src/i18n/merge.ts +5 -0
  180. package/src/i18n/zh.ts +23 -8
  181. package/src/index.ts +7 -2
  182. package/src/lib/blocker-action.ts +22 -0
  183. package/src/lib/board-fact.ts +27 -0
  184. package/src/lib/busy.ts +10 -0
  185. package/src/lib/diy-debug.test.ts +2 -1
  186. package/src/lib/diy-debug.ts +44 -3
  187. package/src/lib/diy-record.test.ts +171 -0
  188. package/src/lib/diy-record.ts +185 -0
  189. package/src/lib/form-problem.ts +10 -0
  190. package/src/lib/panel-state.ts +60 -0
  191. package/src/lib/react.ts +39 -0
  192. package/src/lib/text.ts +22 -0
  193. package/src/lib/ui.ts +50 -0
@@ -8,6 +8,11 @@ import type { ApprovalCall, ApprovalFacts, ApprovalPolicy } from '../host/tool-a
8
8
  import type { ValueHandoff } from '../host/value-handoff.js';
9
9
  import type { WorkspaceStore } from '../host/workspace-store.js';
10
10
 
11
+ export interface ToolScopeContext {
12
+ readonly workspace: string | null;
13
+ readonly preset: string | null;
14
+ }
15
+
11
16
  export interface UnitMountDeps {
12
17
  readonly manifest: UnitManifest;
13
18
  readonly ctx: DshHostContext;
@@ -43,7 +48,7 @@ export interface UnitMountResult {
43
48
  registerTools(): Array<() => void>;
44
49
  readonly factsOf?: ((call: UnitCall) => readonly string[] | undefined) | undefined;
45
50
  readonly gate?: {
46
- deniedTools(workspace: string | null): readonly string[];
51
+ deniedTools(context: ToolScopeContext): readonly string[];
47
52
  subscribe(listener: () => void): () => void;
48
53
  };
49
54
  readonly context?: {
package/src/host.ts CHANGED
@@ -9,6 +9,7 @@ export * from './lib/ui.js';
9
9
  export * from './lib/panel-state.js';
10
10
  export * from './lib/board-fact.js';
11
11
  export * from './lib/diy-debug.js';
12
+ export * from './lib/diy-record.js';
12
13
  export * from './api/blocker-table.js';
13
14
  export * from './host/browser-find.js';
14
15
  export * from './host/browser-read.js';
package/src/i18n/en.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { WorkbenchMessages } from './zh.js';
2
2
 
3
+ /** 外壳自带的英文词表:键必须与 `zh` 逐一对应,值不许为空串。 */
3
4
  export const en: Record<keyof WorkbenchMessages, string> = {
4
5
  'brand.name': 'Workbench',
5
6
 
@@ -423,18 +424,31 @@ export const en: Record<keyof WorkbenchMessages, string> = {
423
424
  'configSync.emptyProviders': 'The workbench has no model provider yet — sync the llm- rows from some profile, or configure one under Models.',
424
425
  'configSync.failed': 'The sync did not go through; try again.',
425
426
 
426
- 'debug.status': 'Workbench DIY debugging',
427
- 'debug.status.trouble': 'Workbench DIY debugging needs attention',
428
- 'debug.stalled': 'Workbench DIY debugging paused',
427
+ 'debug.workspace': 'this workspace',
428
+ 'debug.status': 'Debugging “{title}”',
429
+ 'debug.status.trouble': 'Debugging needs your attention ({title})',
430
+ 'debug.stalled': 'Debugging paused ({title})',
429
431
  'debug.act.pause': 'Pause debugging',
430
432
  'debug.act.resume': 'Resume debugging',
431
433
  'debug.act.stop': 'Stop debugging',
432
434
  'debug.act.stop.ask': 'Confirm stop',
433
- 'debug.card.here.title': 'Workbench DIY debugging is on',
435
+ 'debug.card.here.title': 'Debugging “{title}”',
434
436
  'debug.card.here.note': 'Do not switch workspaces or touch the panel',
435
- 'debug.card.away.title': 'Workbench DIY debugging is on',
436
- 'debug.card.away.note': 'Switch to the Workbench DIY workspace',
437
+ 'debug.card.away.note': 'Switch back to “{title}”',
437
438
  'debug.card.paused.note': 'Paused',
438
- 'debug.card.hidden.note': 'Switch to the Workbench panel',
439
- 'debug.back': 'Back to the workshop screen',
439
+ 'debug.card.hidden.note': 'Switch back to the Workbench panel',
440
+ 'record.waiting': 'Recording handoff · your turn',
441
+ 'record.waiting.note': 'Press "Start recording" on that page, then "Stop recording" when done (it will not switch you back)',
442
+ 'record.recording': 'Recording',
443
+ 'record.recording.note': 'Press "Stop recording" when done; if the bar is gone press Halt so the agent grabs it first',
444
+ 'record.finished': 'Recording finished',
445
+ 'record.finished.note': 'This run is done — the agent will grab it and wrap up on its own',
446
+ 'record.act.cancel': 'Cancel',
447
+ 'record.act.halt': 'Halt',
448
+ 'approval.record.site': 'Site',
449
+ 'approval.record.what': 'Records',
450
+ 'approval.record.lands': 'Lands in',
451
+ 'approval.record.noUrl': 'no site given (this call gets refused)',
452
+ 'approval.record.oneAction': 'one action',
453
+ 'approval.record.noSwitch': 'it will not switch you back (the leftbar footer shows the state)',
440
454
  };
package/src/i18n/index.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import { en } from './en.js';
2
2
  import { zh, type WorkbenchMessages } from './zh.js';
3
3
 
4
+ /** 外壳自带的两份词表(`zh` 为基准、`en` 同构):`client.tsx` 拿它当合并各套件词表的底座。 */
4
5
  export const dictionaries = { zh, en };
5
6
 
7
+ /** 中文词表的键类型(从 `zh.ts` 转出):`en` 与模块词表都得覆盖同一批键。 */
6
8
  export type { WorkbenchMessages };
7
9
 
10
+ /** 一份按语言分的词表:`zh` / `en` 必须同键,另可带模块自己那份语言。 */
8
11
  export interface Dictionaries {
9
12
  readonly zh: Readonly<Record<string, string>>;
10
13
  readonly en: Readonly<Record<string, string>>;
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,34 @@ 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
+ 'record.waiting': '取证交接 · 等你出手',
436
+ 'record.waiting.note': '请在那一页按「开始录制」,做完按「结束录制」(录完不替你切回来)',
437
+ 'record.recording': '录制中',
438
+ 'record.recording.note': '做完按「结束录制」;浮条没了按「停」,让 agent 先取再收',
439
+ 'record.finished': '录制完成',
440
+ 'record.finished.note': '这一段录完了 —— agent 会自己来取并收工,不用你点',
441
+ 'record.act.cancel': '取消',
442
+ 'record.act.halt': '停',
443
+ 'approval.record.site': '站点',
444
+ 'approval.record.what': '录制功能',
445
+ 'approval.record.lands': '落点',
446
+ 'approval.record.noUrl': '没给站点地址(这次会被当场拒)',
447
+ 'approval.record.oneAction': '一次操作',
448
+ 'approval.record.noSwitch': '录完不会替你切回来(左栏底部会亮一条状态)',
435
449
  } as const;
436
450
 
451
+ /** 中文词表的键类型:`en` 与模块词表都得覆盖同一批键。 */
437
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,10 +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';
53
+ export * from './lib/diy-record.js';
54
+ export * from './lib/form-problem.js';
50
55
  export * from './lib/panel-state.js';
51
56
  export * from './lib/react.js';
52
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
  }
@@ -0,0 +1,171 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ RECORD_STALE_MS,
4
+ createRecordStore,
5
+ parseRecordIntent,
6
+ recordOwnerText,
7
+ type RecordPact,
8
+ type RecordState,
9
+ } from './diy-record.js';
10
+
11
+ const pact = (sessionId: string, now = 1000, unit = 'demo'): RecordPact => ({
12
+ sessionId,
13
+ workspace: '/w/diy',
14
+ unit,
15
+ name: unit,
16
+ url: 'https://cmdb.example.com/env',
17
+ title: '环境 · CMDB',
18
+ action: '发布',
19
+ expect: { method: 'POST', urlContains: '/api/publish' },
20
+ captureFile: '/w/diy/shots/rec-demo.jsonl',
21
+ now,
22
+ });
23
+
24
+ const held = (move: { ok: true; state: RecordState } | { ok: false; code: string }): RecordState => {
25
+ if (!move.ok) throw new Error(`expected ok, got ${move.code}`);
26
+ return move.state;
27
+ };
28
+
29
+ describe('录制交接:一台机器一次一场,谁开谁收工', () => {
30
+ it('★ begin ⇒ armed,把目标、那一页、那一下、捕获文件都记下', () => {
31
+ const store = createRecordStore();
32
+ const state = held(store.begin(pact('s1', 1000)));
33
+
34
+ expect(state.phase).toBe('armed');
35
+ expect(state.unit).toBe('demo');
36
+ expect(state.url).toBe('https://cmdb.example.com/env');
37
+ expect(state.action).toBe('发布');
38
+ expect(state.expect).toEqual({ method: 'POST', urlContains: '/api/publish' });
39
+ expect(state.captureFile).toBe('/w/diy/shots/rec-demo.jsonl');
40
+ expect(state.startedAt).toBe(1000);
41
+ expect(state.t0).toBeNull();
42
+ expect(state.t1).toBeNull();
43
+ expect(store.live(1000)).toEqual(state);
44
+ });
45
+
46
+ it('★★ 另一场占着就不许再开;同一个会话再来一次 ⇒ already-held', () => {
47
+ const store = createRecordStore();
48
+ store.begin(pact('s1', 1000));
49
+
50
+ expect(store.begin(pact('s2', 1200))).toEqual({ ok: false, code: 'held-by-other' });
51
+ expect(store.begin(pact('s1', 1300))).toEqual({ ok: false, code: 'already-held' });
52
+ expect(store.live(1300)?.sessionId).toBe('s1');
53
+ });
54
+
55
+ it('★ 用户按「开始」⇒ recording,t0 是他按的那一刻(不是 store 收到的那一刻)', () => {
56
+ const store = createRecordStore();
57
+ store.begin(pact('s1', 1000));
58
+
59
+ const state = held(store.started('s1', 2000, 2001));
60
+ expect(state.phase).toBe('recording');
61
+ expect(state.t0).toBe(2000);
62
+ expect(state.at).toBe(2001);
63
+ expect(state.startedAt).toBe(1000);
64
+ });
65
+
66
+ it('★ 用户按「结束」⇒ finished,t1 落下来;再按一次「结束」⇒ not-recording', () => {
67
+ const store = createRecordStore();
68
+ store.begin(pact('s1', 1000));
69
+ store.started('s1', 2000, 2001);
70
+
71
+ const state = held(store.finished('s1', 5000, 5002));
72
+ expect(state.phase).toBe('finished');
73
+ expect(state.t1).toBe(5000);
74
+ expect(store.finished('s1', 6000, 6000)).toEqual({ ok: false, code: 'not-recording' });
75
+ });
76
+
77
+ it('★★ 阶段不对就说清是哪一档:还没开始就结束 / 已经开始又按开始', () => {
78
+ const store = createRecordStore();
79
+ store.begin(pact('s1', 1000));
80
+
81
+ expect(store.finished('s1', 1500, 1500)).toEqual({ ok: false, code: 'not-recording' });
82
+
83
+ store.started('s1', 2000, 2000);
84
+ expect(store.started('s1', 2100, 2100)).toEqual({ ok: false, code: 'already-recording' });
85
+
86
+ store.finished('s1', 3000, 3000);
87
+ expect(store.started('s1', 3100, 3100)).toEqual({ ok: false, code: 'not-armed' });
88
+ });
89
+
90
+ it('★★ 一场就一个周期:finished 之后回不去了(没有「再录一段」,要重录就重新 begin 一场)', () => {
91
+ const store = createRecordStore();
92
+ store.begin(pact('s1', 1000));
93
+ store.started('s1', 2000, 2000);
94
+ store.finished('s1', 3000, 3000);
95
+
96
+ const state = store.live(3000);
97
+ expect(state?.phase).toBe('finished');
98
+ expect(state?.t0).toBe(2000);
99
+ expect(state?.t1).toBe(3000);
100
+ expect(store.started('s1', 3100, 3100)).toEqual({ ok: false, code: 'not-armed' });
101
+ expect(store.finished('s1', 3200, 3200)).toEqual({ ok: false, code: 'not-recording' });
102
+ expect(store.live(3300)?.phase).toBe('finished');
103
+ });
104
+
105
+ it('★ 收工把它清干净(取消那一拍也走它)', () => {
106
+ const store = createRecordStore();
107
+ store.begin(pact('s1', 1000));
108
+
109
+ const stopped = held(store.stop('s1', 1500));
110
+ expect(stopped.unit).toBe('demo');
111
+ expect(store.live(1500)).toBeNull();
112
+ expect(store.stop('s1', 1600)).toEqual({ ok: false, code: 'none' });
113
+ });
114
+
115
+ it('★★ 别人不许动我这一场(not-owner);没开过 ⇒ none', () => {
116
+ const store = createRecordStore();
117
+
118
+ expect(store.started('s1', 1000, 1000)).toEqual({ ok: false, code: 'none' });
119
+ expect(store.finished('s1', 1000, 1000)).toEqual({ ok: false, code: 'none' });
120
+ expect(store.stop('s1', 1000)).toEqual({ ok: false, code: 'none' });
121
+
122
+ store.begin(pact('s1', 1000));
123
+ expect(store.started('s2', 1100, 1100)).toEqual({ ok: false, code: 'not-owner' });
124
+ expect(store.finished('s2', 1100, 1100)).toEqual({ ok: false, code: 'not-owner' });
125
+ expect(store.stop('s2', 1100)).toEqual({ ok: false, code: 'not-owner' });
126
+ expect(store.live(1100)?.sessionId).toBe('s1');
127
+ });
128
+
129
+ it('★ 过期当它不存在(15 分钟没人管就放别人进来)', () => {
130
+ const store = createRecordStore();
131
+ store.begin(pact('s1', 1000));
132
+
133
+ expect(store.live(1000 + RECORD_STALE_MS)).not.toBeNull();
134
+ expect(store.live(1001 + RECORD_STALE_MS)).toBeNull();
135
+ expect(store.begin(pact('s2', 1001 + RECORD_STALE_MS)).ok).toBe(true);
136
+ expect(store.live(1001 + RECORD_STALE_MS)?.sessionId).toBe('s2');
137
+ });
138
+
139
+ it('★ 录制中不被 TTL 拽走:at 每动一次就续上(他正在那一页上操作)', () => {
140
+ const store = createRecordStore();
141
+ store.begin(pact('s1', 1000));
142
+
143
+ const late = 1000 + RECORD_STALE_MS;
144
+ const state = held(store.started('s1', late, late));
145
+ expect(state.phase).toBe('recording');
146
+ expect(state.startedAt).toBe(1000);
147
+ expect(store.live(late + RECORD_STALE_MS)).not.toBeNull();
148
+ expect(store.live(late + RECORD_STALE_MS + 1)).toBeNull();
149
+ });
150
+
151
+ it('★ 占着的那句话里有会话、时间和要录的是什么(另一场要看得懂是谁占的)', () => {
152
+ const store = createRecordStore();
153
+ const state = held(store.begin(pact('s1', 1000)));
154
+ const text = recordOwnerText(state);
155
+
156
+ expect(text).toContain('s1');
157
+ expect(text).toContain('demo');
158
+ expect(text).toContain('发布');
159
+ });
160
+ });
161
+
162
+ describe('用户在左栏按的三个键:意图词表只此一份', () => {
163
+ it('★ 认得出三个,其余一律 null(别把别的字当成指令)', () => {
164
+ expect(parseRecordIntent('peek')).toBe('peek');
165
+ expect(parseRecordIntent('halt')).toBe('halt');
166
+ expect(parseRecordIntent('stop')).toBe('stop');
167
+ for (const bad of ['', 'PEEK', 'Peek', 'cancel', 'kill', 'end', null, undefined, 1, {}, []]) {
168
+ expect(parseRecordIntent(bad)).toBeNull();
169
+ }
170
+ });
171
+ });