@dsh-workbench/shared 1.5.4 → 1.5.5-beta.0

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 (125) hide show
  1. package/dist/api/workbench-client.d.ts +7 -0
  2. package/dist/components/card/Activity.d.ts +12 -12
  3. package/dist/components/card/Activity.js +0 -12
  4. package/dist/components/card/ApprovalDetail.d.ts +5 -5
  5. package/dist/components/card/ApprovalDetail.js +0 -5
  6. package/dist/components/card/ApprovalPlan.d.ts +4 -4
  7. package/dist/components/card/ApprovalPlan.js +0 -4
  8. package/dist/components/card/Card.d.ts +7 -6
  9. package/dist/components/card/Card.js +0 -6
  10. package/dist/components/card/CardAnchor.d.ts +2 -2
  11. package/dist/components/card/CardAnchor.js +0 -2
  12. package/dist/components/card/CardBoundary.d.ts +6 -6
  13. package/dist/components/card/CardBoundary.js +0 -6
  14. package/dist/components/card/CardHead.d.ts +11 -6
  15. package/dist/components/card/CardHead.js +0 -6
  16. package/dist/components/card/LongTaskRow.d.ts +20 -16
  17. package/dist/components/card/LongTaskRow.js +0 -16
  18. package/dist/components/card/board-module.d.ts +11 -2
  19. package/dist/components/feedback/EmptyIllustration.d.ts +1 -1
  20. package/dist/components/feedback/EmptyIllustration.js +0 -1
  21. package/dist/components/feedback/Note.d.ts +4 -4
  22. package/dist/components/feedback/Note.js +0 -4
  23. package/dist/components/feedback/ResourceStates.d.ts +22 -18
  24. package/dist/components/feedback/ResourceStates.js +0 -10
  25. package/dist/components/feedback/Spinner.d.ts +2 -2
  26. package/dist/components/feedback/Spinner.js +0 -2
  27. package/dist/components/feedback/StateBlock.d.ts +6 -6
  28. package/dist/components/feedback/StateBlock.js +0 -6
  29. package/dist/components/form/ChoiceGroup.d.ts +19 -10
  30. package/dist/components/form/ChoiceGroup.js +0 -8
  31. package/dist/components/form/ConfirmBar.d.ts +7 -7
  32. package/dist/components/form/ConfirmBar.js +0 -7
  33. package/dist/components/form/Field.d.ts +3 -3
  34. package/dist/components/form/Field.js +0 -3
  35. package/dist/components/form/Form.d.ts +0 -8
  36. package/dist/components/form/Form.js +0 -8
  37. package/dist/components/form/FormActions.d.ts +1 -1
  38. package/dist/components/form/FormActions.js +0 -1
  39. package/dist/components/form/FormRows.d.ts +7 -7
  40. package/dist/components/form/FormRows.js +0 -7
  41. package/dist/components/form/FormTypes.d.ts +8 -0
  42. package/dist/components/form/SaveBar.d.ts +5 -5
  43. package/dist/components/form/SaveBar.js +0 -5
  44. package/dist/components/form/SelectField.d.ts +42 -13
  45. package/dist/components/form/SelectField.js +0 -13
  46. package/dist/components/form/TextField.d.ts +1 -1
  47. package/dist/components/form/TextField.js +0 -1
  48. package/dist/components/layout/Link.d.ts +5 -5
  49. package/dist/components/layout/Link.js +0 -5
  50. package/dist/components/layout/Rows.d.ts +3 -3
  51. package/dist/components/layout/Rows.js +0 -3
  52. package/dist/components/layout/SettingsSection.d.ts +4 -4
  53. package/dist/components/layout/SettingsSection.js +0 -4
  54. package/dist/components/layout/SetupShell.d.ts +40 -5
  55. package/dist/components/layout/SetupShell.js +0 -5
  56. package/dist/components/layout/Stack.d.ts +1 -1
  57. package/dist/components/layout/Stack.js +0 -1
  58. package/dist/components/layout/icons.d.ts +1 -9
  59. package/dist/components/layout/icons.js +0 -9
  60. package/dist/contract/command.d.ts +2 -0
  61. package/dist/contract/data.d.ts +10 -0
  62. package/dist/contract/git.d.ts +4 -0
  63. package/dist/contract/lib.d.ts +2 -0
  64. package/dist/contract/module-context.d.ts +3 -0
  65. package/dist/contract/protocol/platform.d.ts +13 -0
  66. package/dist/host/adapters/toolbox-port.d.ts +0 -6
  67. package/dist/host/ai/port.d.ts +5 -0
  68. package/dist/host/ai/types.d.ts +12 -0
  69. package/dist/host/drafts/draft-store.d.ts +5 -0
  70. package/dist/host/runtime/workspace-store.d.ts +2 -0
  71. package/dist/host/seam/intent.d.ts +9 -0
  72. package/dist/host/seam/unit-seam.d.ts +2 -0
  73. package/dist/host/unit/host-kit.d.ts +8 -0
  74. package/dist/host/unit/long-task.d.ts +16 -0
  75. package/dist/host/unit/unit-face.d.ts +20 -0
  76. package/dist/host/unit/value-handoff.d.ts +3 -0
  77. package/package.json +1 -1
  78. package/src/api/workbench-client.ts +7 -0
  79. package/src/components/card/Activity.tsx +12 -12
  80. package/src/components/card/ApprovalDetail.tsx +5 -5
  81. package/src/components/card/ApprovalPlan.tsx +4 -4
  82. package/src/components/card/Card.tsx +7 -6
  83. package/src/components/card/CardAnchor.tsx +2 -2
  84. package/src/components/card/CardBoundary.tsx +6 -6
  85. package/src/components/card/CardHead.tsx +11 -6
  86. package/src/components/card/LongTaskRow.tsx +20 -16
  87. package/src/components/card/board-module.ts +11 -2
  88. package/src/components/feedback/EmptyIllustration.tsx +1 -1
  89. package/src/components/feedback/Note.tsx +4 -4
  90. package/src/components/feedback/ResourceStates.tsx +24 -16
  91. package/src/components/feedback/Spinner.tsx +2 -2
  92. package/src/components/feedback/StateBlock.tsx +6 -6
  93. package/src/components/form/ChoiceGroup.tsx +19 -9
  94. package/src/components/form/ConfirmBar.tsx +7 -7
  95. package/src/components/form/Field.tsx +3 -3
  96. package/src/components/form/Form.tsx +0 -8
  97. package/src/components/form/FormActions.tsx +1 -1
  98. package/src/components/form/FormRows.tsx +7 -7
  99. package/src/components/form/FormTypes.ts +8 -0
  100. package/src/components/form/SaveBar.tsx +5 -5
  101. package/src/components/form/SelectField.tsx +42 -13
  102. package/src/components/form/TextField.tsx +1 -1
  103. package/src/components/layout/Link.tsx +5 -5
  104. package/src/components/layout/Rows.tsx +3 -3
  105. package/src/components/layout/SettingsSection.tsx +4 -4
  106. package/src/components/layout/SetupShell.tsx +40 -5
  107. package/src/components/layout/Stack.tsx +1 -1
  108. package/src/components/layout/icons.tsx +1 -9
  109. package/src/contract/command.ts +2 -0
  110. package/src/contract/data.ts +10 -0
  111. package/src/contract/git.ts +4 -0
  112. package/src/contract/lib.ts +2 -0
  113. package/src/contract/module-context.ts +3 -0
  114. package/src/contract/protocol/platform.ts +13 -0
  115. package/src/host/adapters/toolbox-port.ts +0 -7
  116. package/src/host/ai/port.ts +5 -0
  117. package/src/host/ai/types.ts +12 -0
  118. package/src/host/drafts/draft-store.ts +5 -0
  119. package/src/host/runtime/workspace-store.ts +2 -0
  120. package/src/host/seam/intent.ts +9 -0
  121. package/src/host/seam/unit-seam.ts +2 -0
  122. package/src/host/unit/host-kit.ts +8 -0
  123. package/src/host/unit/long-task.ts +16 -0
  124. package/src/host/unit/unit-face.ts +20 -0
  125. package/src/host/unit/value-handoff.ts +3 -0
@@ -9,12 +9,19 @@ import styles from './SetupShell.module.css';
9
9
  /**
10
10
  * 初始化的一步:渲染什么、能不能走、走去哪、走之前存什么。
11
11
  */
12
+ /** 初始化的一步。 */
12
13
  export interface SetupStep {
14
+ /** 步骤 id;`initialStep` / `next` 用它。 */
13
15
  readonly id: string;
16
+ /** 步骤标题。 */
14
17
  readonly title: string;
18
+ /** 画这一步。 */
15
19
  readonly render: (ctx: SetupStepContext) => ReactNode;
20
+ /** 能不能走下一步;不给默认 true。 */
16
21
  readonly canLeave?: ((values: Readonly<Record<string, unknown>>) => boolean) | undefined;
22
+ /** 下一步 id;返回 null 表示没有下一步(走完成)。 */
17
23
  readonly next?: ((values: Readonly<Record<string, unknown>>) => string | null) | undefined;
24
+ /** 这一步单独保存;不给则没有这一步的保存钮。 */
18
25
  readonly submit?:
19
26
  | ((values: Readonly<Record<string, unknown>>) => Promise<SetupWriteResult>)
20
27
  | undefined;
@@ -24,9 +31,13 @@ export interface SetupStep {
24
31
  * 每步的渲染上下文:当前值、改值、忙碌与错误。
25
32
  */
26
33
  export interface SetupStepContext {
34
+ /** 当前值。 */
27
35
  readonly values: Readonly<Record<string, unknown>>;
36
+ /** 改值。 */
28
37
  readonly setValues: (next: Record<string, unknown>) => void;
38
+ /** 正在保存。 */
29
39
  readonly busy: boolean;
40
+ /** 上一条错误;没有是 null。 */
30
41
  readonly error: string | null;
31
42
  }
32
43
 
@@ -34,7 +45,9 @@ export interface SetupStepContext {
34
45
  * 一次配置读取的结果:`configured` 为真表示已经不用再初始化,`values` 是已存的值。
35
46
  */
36
47
  export interface SetupSnapshot {
48
+ /** 已经配置好,不用再初始化。 */
37
49
  readonly configured: boolean;
50
+ /** 已存的值。 */
38
51
  readonly values?: Readonly<Record<string, unknown>> | undefined;
39
52
  }
40
53
 
@@ -53,19 +66,33 @@ export type SetupPhase = 'checking' | 'needs-setup' | 'ready' | 'blocked';
53
66
  /**
54
67
  * `useUnitSetup` 交出来的那台机器;`SetupShell` 只认这一个形状。
55
68
  */
69
+ /** `useUnitSetup` 交出来的状态机。 */
56
70
  export interface UnitSetup {
71
+ /** 现在在哪一相。 */
57
72
  readonly phase: SetupPhase;
73
+ /** 全部步骤。 */
58
74
  readonly steps: readonly SetupStep[];
75
+ /** 当前步骤;相位不是 `needs-setup` 时可能没有。 */
59
76
  readonly step: SetupStep | undefined;
77
+ /** 当前值。 */
60
78
  readonly values: Readonly<Record<string, unknown>>;
79
+ /** 改值。 */
61
80
  readonly setValues: (next: Record<string, unknown>) => void;
81
+ /** 正在保存。 */
62
82
  readonly busy: boolean;
83
+ /** 上一条错误;没有是 null。 */
63
84
  readonly error: string | null;
85
+ /** 当前步能不能走。 */
64
86
  readonly canLeave: boolean;
87
+ /** 能不能回上一步。 */
65
88
  readonly canBack: boolean;
89
+ /** 下一步(先运行当前步的 `submit`)。 */
66
90
  readonly next: () => void;
91
+ /** 回上一步。 */
67
92
  readonly back: () => void;
93
+ /** 重读配置。 */
68
94
  readonly retry: () => void;
95
+ /** `edit` 模式一次存全量;没给 `write` 时无效。 */
69
96
  readonly saveAll: () => void;
70
97
  }
71
98
 
@@ -73,13 +100,21 @@ export interface UnitSetup {
73
100
  * `SetupShell` 自己那几句文案;模块按自己的词表给。
74
101
  */
75
102
  export interface SetupShellLabels {
103
+ /** 上一步。 */
76
104
  readonly back: string;
105
+ /** 下一步。 */
77
106
  readonly next: string;
107
+ /** 完成。 */
78
108
  readonly finish: string;
109
+ /** 保存。 */
79
110
  readonly save: string;
111
+ /** 保存中。 */
80
112
  readonly saving: string;
113
+ /** 取消。 */
81
114
  readonly cancel: string;
115
+ /** 正在读。 */
82
116
  readonly reading: string;
117
+ /** 读不到。 */
83
118
  readonly failed: string;
84
119
  }
85
120
 
@@ -87,20 +122,20 @@ export interface SetupShellLabels {
87
122
  * `<SetupShell>` 的 prop:一台 `useUnitSetup` 的机器、文案、以及完成后的主页。
88
123
  */
89
124
  export interface SetupShellProps {
125
+ /** `useUnitSetup` 的返回值;壳不自己取数、不自己写配置。 */
90
126
  readonly setup: UnitSetup;
127
+ /** 八句文案:上一步 / 下一步 / 完成 / 保存 / 保存中 / 取消 / 正在读 / 读不到。 */
91
128
  readonly labels: SetupShellLabels;
129
+ /** `setup`(默认,分步)或 `edit`(同一步骤集合摊成一页,底部 `SaveBar`)。 */
92
130
  readonly mode?: 'setup' | 'edit' | undefined;
131
+ /** 相位到 `ready` 时渲染什么;不给就只留空。 */
93
132
  readonly renderHome?: (() => ReactNode) | undefined;
133
+ /** `edit` 模式点取消做什么;不给钮就什么都不做。 */
94
134
  readonly onCancel?: (() => void) | undefined;
95
135
  }
96
136
 
97
137
  /**
98
138
  * 初始化 / 配置的外壳:分步、上一步 / 下一步 / 完成、阻断与错误,完成之后把主页换进来。
99
- * @param props.setup - `useUnitSetup` 的返回值;壳不自己取数、不自己写配置。
100
- * @param props.labels - 八句文案:上一步 / 下一步 / 完成 / 保存 / 保存中 / 取消 / 正在读 / 读不到。
101
- * @param props.mode - `setup`(默认,分步)或 `edit`(同一步骤集合摊成一页,底部 `SaveBar`)。
102
- * @param props.renderHome - 相位到 `ready` 时渲染什么;不给就只留空。
103
- * @param props.onCancel - `edit` 模式点取消做什么;不给钮就什么都不做。
104
139
  * @returns 一块初始化或配置界面。
105
140
  */
106
141
  export function SetupShell({
@@ -6,12 +6,12 @@ import './Stack.css';
6
6
  * `Stack` 的契约:只带一个竖排内容槽。
7
7
  */
8
8
  export interface StackProps {
9
+ /** 要竖排的内容;不给就渲染一个空容器。 */
9
10
  readonly children?: ReactNode | undefined;
10
11
  }
11
12
 
12
13
  /**
13
14
  * 竖排容器:把相邻内容按统一间距摞起来,懒得自己分组时的默认外包装。
14
- * @param props.children - 要竖排的内容;不给就渲染一个空容器。
15
15
  * @returns 竖排的 div。
16
16
  */
17
17
  export function Stack({ children }: StackProps) {
@@ -4,6 +4,7 @@ import { h, type ReactNode } from '../../lib/react.js';
4
4
  * 自绘图标的契约:只给边长像素。
5
5
  */
6
6
  export interface IconProps {
7
+ /** 边长像素,同时给 `width` 与 `height`。 */
7
8
  size?: number;
8
9
  }
9
10
 
@@ -36,7 +37,6 @@ function Shell({
36
37
 
37
38
  /**
38
39
  * 会话图标:一枚对话气泡,dsh 的图标表里没有,留给我们自己用;默认 16px。
39
- * @param props.size - 边长像素,同时给 `width` 与 `height`。
40
40
  * @returns 一枚 `aria-hidden` 的 svg。
41
41
  */
42
42
  export function IconConversation({ size = 16 }: IconProps) {
@@ -79,7 +79,6 @@ export const BRAND_MARK_COLORS = {
79
79
 
80
80
  /**
81
81
  * 品牌标:一台显示器,屏幕里放着 dsh 官方的鲸鱼标;默认 24px(它是品牌物,别拿它当通用图标)。
82
- * @param props.size - 边长像素,同时给 `width` 与 `height`。
83
82
  * @returns 一枚 `aria-hidden` 的 svg。
84
83
  */
85
84
  export function IconBrandMark({ size = 24 }: IconProps) {
@@ -95,7 +94,6 @@ export function IconBrandMark({ size = 24 }: IconProps) {
95
94
 
96
95
  /**
97
96
  * 品牌标的彩色版:市场里工作台那一行用;颜色写死,不跟主题走。默认 24px。
98
- * @param props.size - 边长像素,同时给 `width` 与 `height`。
99
97
  * @returns 一枚 `aria-hidden` 的 svg。
100
98
  */
101
99
  export function IconBrandMarkColor({ size = 24 }: IconProps) {
@@ -111,7 +109,6 @@ export function IconBrandMarkColor({ size = 24 }: IconProps) {
111
109
 
112
110
  /**
113
111
  * opencli 的标:包类型那一格用它;颜色写死的品牌物,不跟主题走。默认 16px。
114
- * @param props.size - 边长像素,同时给 `width` 与 `height`。
115
112
  * @returns 一枚 `aria-hidden` 的 svg。
116
113
  */
117
114
  export function IconOpencli({ size = 16 }: IconProps) {
@@ -143,7 +140,6 @@ export function IconOpencli({ size = 16 }: IconProps) {
143
140
 
144
141
  /**
145
142
  * npm 的标:包类型那一格用它;保留品牌红,不跟主题走。默认 16px。
146
- * @param props.size - 边长像素,同时给 `width` 与 `height`。
147
143
  * @returns 一枚 `aria-hidden` 的 svg。
148
144
  */
149
145
  export function IconNpm({ size = 16 }: IconProps) {
@@ -159,7 +155,6 @@ export function IconNpm({ size = 16 }: IconProps) {
159
155
 
160
156
  /**
161
157
  * 模块类型标:渐变方块 + 白四宫格,用在"这是个模块"的行首;品牌物,颜色不跟主题走。默认 16px。
162
- * @param props.size - 边长像素,同时给 `width` 与 `height`。
163
158
  * @returns 一枚 `aria-hidden` 的 svg。
164
159
  */
165
160
  export function IconModuleMark({ size = 16 }: IconProps) {
@@ -183,7 +178,6 @@ export function IconModuleMark({ size = 16 }: IconProps) {
183
178
 
184
179
  /**
185
180
  * 面板 / 卡片那类的图标:整屏与柱状那种形状,给"面板"这一档用;默认 16px。
186
- * @param props.size - 边长像素,同时给 `width` 与 `height`。
187
181
  * @returns 一枚 `aria-hidden` 的 svg。
188
182
  */
189
183
  export function IconPanelScreen({ size = 16 }: IconProps) {
@@ -204,7 +198,6 @@ export function IconPanelScreen({ size = 16 }: IconProps) {
204
198
 
205
199
  /**
206
200
  * 命令类型标:一枚终端窗口(第三方图标,配色固定、不跟主题走,出处见 THIRD-PARTY-NOTICES)。默认 16px。
207
- * @param props.size - 边长像素,同时给 `width` 与 `height`。
208
201
  * @returns 一枚 `aria-hidden` 的 svg。
209
202
  */
210
203
  export function IconCommand({ size = 16 }: IconProps) {
@@ -235,7 +228,6 @@ export function IconCommand({ size = 16 }: IconProps) {
235
228
 
236
229
  /**
237
230
  * 环境变量类型标:一个 ENV 字样的方框;颜色用品牌蓝,不跟主题走。默认 16px。
238
- * @param props.size - 边长像素,同时给 `width` 与 `height`。
239
231
  * @returns 一枚 `aria-hidden` 的 svg。
240
232
  */
241
233
  export function IconEnv({ size = 16 }: IconProps) {
@@ -22,7 +22,9 @@ export interface CommandResult {
22
22
  readonly error?: string | undefined;
23
23
  }
24
24
 
25
+ /** 运行一条 argv 命令,不经过 shell。 */
25
26
  export interface CommandReader {
27
+ /** files 先写成临时文件,按 appendFileArgs 追加到 argv,运行完清掉。 */
26
28
  run(request: CommandRequest): Promise<CommandResult>;
27
29
  }
28
30
 
@@ -2,8 +2,11 @@ export interface DataRequestBase {
2
2
  readonly timeoutMs?: number;
3
3
  }
4
4
 
5
+ /** 每次读 / 写调用的通用选项。 */
5
6
  export interface DataCallOptions {
7
+ /** 取消这次调用。 */
6
8
  readonly signal?: AbortSignal | undefined;
9
+ /** 浏览器读时是否打开窗口;不给沿用请求里的 open。 */
7
10
  readonly open?: boolean | undefined;
8
11
  }
9
12
 
@@ -232,20 +235,27 @@ export interface SubmitPlanOptions extends DataCallOptions {
232
235
  readonly onStep?: ((step: PlanStep, index: number, result: PlanStepResult<unknown>) => void) | undefined;
233
236
  }
234
237
 
238
+ /** 站点数据读取:按请求 / 配方 / 计划读,写只走 submit / submitPlan。 */
235
239
  export interface DataReader {
240
+ /** 直接执行一条 DataRequest。 */
236
241
  read<T = unknown>(request: DataRequest, options?: DataCallOptions): Promise<DataResult<T>>;
242
+ /** 按配方读一条;overrides 盖配方里的变量。 */
237
243
  request<T = unknown>(
238
244
  recipe: RequestRecipe,
239
245
  overrides?: CallOverrides,
240
246
  options?: DataCallOptions,
241
247
  ): Promise<DataResult<T>>;
248
+ /** 同一配方多条调用一起读;只读 GET,写仍走 submit。 */
242
249
  requestMany<T = unknown>(
243
250
  recipe: RequestRecipe,
244
251
  calls: RecipeCalls,
245
252
  options?: DataCallOptions,
246
253
  ): Promise<RecipeResults<T>>;
254
+ /** 跑一个只读计划。 */
247
255
  plan(plan: RequestPlan, options?: DataCallOptions): Promise<PlanResults>;
256
+ /** 跑写计划;confirm 返回 false 就停,idempotencyKey 防重复。 */
248
257
  submitPlan(plan: RequestPlan, options: SubmitPlanOptions): Promise<PlanResults>;
258
+ /** 按配方写一条。 */
249
259
  submit<T = unknown>(
250
260
  recipe: RequestRecipe,
251
261
  overrides?: CallOverrides,
@@ -13,8 +13,12 @@ export type HeadRead =
13
13
  | { readonly kind: 'no-head'; readonly detail?: string }
14
14
  | { readonly kind: 'unknown'; readonly reason: string; readonly detail?: string };
15
15
 
16
+ /** 只读 git 信息,不执行任意 git 命令。 */
16
17
  export interface GitReader {
18
+ /** 读 path 的 origin remote;没有回 no-origin,读不了回 unknown。 */
17
19
  origin(path: string): Promise<OriginRead>;
20
+ /** 读当前分支;detached HEAD 回 no-branch。 */
18
21
  branch(path: string): Promise<BranchRead>;
22
+ /** 读当前 commit;没有提交回 no-head。 */
19
23
  head(path: string): Promise<HeadRead>;
20
24
  }
@@ -1,5 +1,7 @@
1
1
  import type { LibNeed } from './needs.js';
2
2
 
3
+ /** 从共用依赖里加载模块。 */
3
4
  export interface LibReader {
5
+ /** 按 need 找已安装版本,加载 entry 指向的模块。 */
4
6
  load<T = unknown>(need: LibNeed, entry: string): Promise<T>;
5
7
  }
@@ -2,8 +2,11 @@
2
2
  * 模块拿得到的上下文:只承诺 `get` / `effect` / `logger`,不把 dsh 的 cordis Context 整棵交出去。
3
3
  */
4
4
  export interface HostContext {
5
+ /** 按名字取注入的服务;名字要写在清单的 host.inject 里,没注入时 undefined。 */
5
6
  get<T = unknown>(name: string): T | undefined;
7
+ /** 登记一个随本单元卸载的副作用;回调返回的函数在卸载时跑,label 只用于日志。 */
6
8
  effect(effect: () => void | (() => void), label?: string): unknown;
9
+ /** 工作台日志口;没有就不记。 */
7
10
  readonly logger?: { info?(message: string): void; warn?(message: string): void } | undefined;
8
11
  }
9
12
 
@@ -26,13 +26,21 @@ export interface ToolchainPlan {
26
26
  readonly pnpm: { readonly neededFor: 'workshop'; readonly expectedMajor: 10 };
27
27
  }
28
28
 
29
+ /** 工作台平台信息:部署形态、系统、运行时、profile、能力、重启提示、工具链。 */
29
30
  export interface HostSurface {
31
+ /** 'web' 是浏览器里跑,'desktop' 是桌面壳。 */
30
32
  readonly deployment: Deployment;
33
+ /** 工作台所在的操作系统;认不出是 'other'。 */
31
34
  readonly hostOs: HostOs;
35
+ /** 工作台运行在 Electron 还是 Node 里。 */
32
36
  readonly runtime: HostRuntime;
37
+ /** 当前 dsh profile;独立实例是它自己的那个。 */
33
38
  readonly profile: ProfileName;
39
+ /** 这份工作台有哪些能力:页面调试 / 站点探索 / 录制 / 浏览器唤醒 / 自更新 / 安全模式 / 文件管理器。 */
34
40
  readonly capabilities: HostCapabilities;
41
+ /** 要重启时给用户看的那句话。 */
35
42
  readonly restartHint: string;
43
+ /** 工具链计划:node 从哪来、npm/pnpm 什么时候需要。 */
36
44
  readonly toolchain: ToolchainPlan;
37
45
  }
38
46
 
@@ -42,9 +50,14 @@ export interface ClientCapabilities {
42
50
  readonly primaryModifier: 'meta' | 'ctrl';
43
51
  }
44
52
 
53
+ /** 浏览器侧平台事实。 */
45
54
  export interface ClientSurface {
55
+ /** 'web' 是浏览器里跑,'desktop' 是桌面壳。 */
46
56
  readonly deployment: Deployment;
57
+ /** 'electron' 桌面壳 / 'browser' 浏览器。 */
47
58
  readonly shell: ClientShell;
59
+ /** 工作台所在的操作系统;认不出是 'other'。 */
48
60
  readonly hostOs: HostOs;
61
+ /** 浏览器侧能力:调试页脚 / 访达 / 主修饰键。 */
49
62
  readonly capabilities: ClientCapabilities;
50
63
  }
@@ -1,12 +1,5 @@
1
- export interface ToolboxCapability {
2
- readonly name: string;
3
- readonly description: string;
4
- readonly content: string;
5
- }
6
-
7
1
  export interface ToolboxPort {
8
2
  packsOf(session: string | null, preset: string | null): ReadonlySet<string>;
9
- capabilityBrief?(workspace: string | null): ToolboxCapability;
10
3
  }
11
4
 
12
5
  export interface McpServerPacks {
@@ -14,11 +14,16 @@ import {
14
14
  /** 这层的版本号:只增。 */
15
15
  export const AI_VERSION = 1;
16
16
 
17
+ /** 模块用的模型入口:ask / askJson / askRich / agent。 */
17
18
  export interface AiPort {
18
19
  readonly version: number;
20
+ /** 只回文本;除 prompt 外全部可选。 */
19
21
  ask(request: AiRequest): Promise<string>;
22
+ /** 保证返回对象:schema 附在提示词后,不合格自动重试一次,仍不合格抛 schema-mismatch。 */
20
23
  askJson<T>(request: AiRequest & { readonly schema: JsonSchema }): Promise<T>;
24
+ /** 同 ask,另回 usage / model / elapsedMs。 */
21
25
  askRich(request: AiRequest): Promise<AiResult>;
26
+ /** 起子 agent(可带工具);比 ask 贵,能用 ask 就不用。 */
22
27
  agent(request: AiRequest & { readonly agent?: AgentOptions }): Promise<string>;
23
28
  supports(capability: AiCapability): boolean;
24
29
  registerAdapter(adapter: AiAdapter): () => void;
@@ -18,18 +18,30 @@ export type ImageLike =
18
18
  export type AttachmentLike = never;
19
19
 
20
20
  /** 一次调用要的东西;除 `prompt` 外都可选,所以加字段永远不算破坏性变更。 */
21
+ /** 一次模型调用:除 prompt 外全部可选。 */
21
22
  export interface AiRequest {
23
+ /** 要模型做什么。 */
22
24
  readonly prompt: string;
25
+ /** 图片:绝对路径 / data URL / Uint8Array;不要自己拼内容块。 */
23
26
  readonly images?: readonly ImageLike[] | undefined;
24
27
  readonly attachments?: readonly AttachmentLike[] | undefined;
28
+ /** 给 askJson 用;会附在提示词后并校验。 */
25
29
  readonly schema?: JsonSchema | undefined;
30
+ /** 取消信号;长任务停止时 abort。 */
26
31
  readonly signal?: AbortSignal | undefined;
32
+ /** 进度回调:结构化输出不合格、准备重试时给一句。 */
27
33
  readonly onStep?: ((text: string) => void) | undefined;
34
+ /** 流式增量回调;只有适配器支持时才有。 */
28
35
  readonly onDelta?: ((chunk: string) => void) | undefined;
36
+ /** 覆盖默认模型:provider / model 都可只给一个。 */
29
37
  readonly model?: { readonly provider?: string; readonly model?: string } | undefined;
38
+ /** 采样温度;不给用模型默认。 */
30
39
  readonly temperature?: number | undefined;
40
+ /** 结构化输出不合格时最多再试几次;默认 1(共两次)。 */
31
41
  readonly retry?: number | undefined;
42
+ /** 本次调用超时;到点中止。 */
32
43
  readonly timeoutMs?: number | undefined;
44
+ /** schema 校验时把不认识的关键字也算问题。 */
33
45
  readonly strict?: boolean | undefined;
34
46
  }
35
47
 
@@ -63,10 +63,15 @@ export interface DraftLookup {
63
63
  readonly session?: string | undefined;
64
64
  }
65
65
 
66
+ /** 会话草稿库:正文落在临时目录,按会话隔离,只认自己发出的 id。 */
66
67
  export interface DraftStore {
68
+ /** 存一份草稿,返回 id / 路径 / 字节数 / sha256;超过上限或不是文本会回 ok:false。 */
67
69
  put(input: DraftPutInput): DraftPutResult;
70
+ /** 按 id 读回正文;带了 session 就还要对得上。 */
68
71
  content(input: DraftLookup): DraftContentResult;
72
+ /** 按 id + session 取写入路径。 */
69
73
  pathOf(input: { readonly id: string; readonly session: string }): DraftPathResult;
74
+ /** 关掉草稿库;之后的 put / content / pathOf 都失效。 */
70
75
  dispose(): void;
71
76
  }
72
77
 
@@ -13,7 +13,9 @@ export interface ModuleStore {
13
13
  list(): string[];
14
14
  }
15
15
 
16
+ /** 按工作区隔离的模块存储。 */
16
17
  export interface WorkspaceStore {
18
+ /** 取单元 + 工作区的存储;workspace 为 null 或空串时是进程内存储(重启就丢)。 */
17
19
  for(unitId: string, workspace: string | null): ModuleStore;
18
20
  machine(unitId: string): ModuleStore;
19
21
  scan(unitId: string): ModuleStore[];
@@ -73,14 +73,23 @@ export class SeamError extends Error {
73
73
 
74
74
  export type UnitWriteScope = 'unit' | 'workspace';
75
75
 
76
+ /** 一次 run 的参数:命令、写到哪、失败怎么办。 */
76
77
  export interface UnitSeamRequest {
78
+ /** 要执行的 shell 命令。 */
77
79
  readonly command: string;
80
+ /** 'unit' 写单元自己的数据根(不用审批);'workspace' 写当前工作区,要声明并带会话。 */
78
81
  readonly scope: UnitWriteScope;
82
+ /** 命令在哪个目录跑;不给用执行缝的默认目录。 */
79
83
  readonly workdir?: string | undefined;
84
+ /** 超时毫秒;不给就不加额外超时。 */
80
85
  readonly timeoutMs?: number | undefined;
86
+ /** 额外环境变量;会盖在工作台注入的 HOME / 缓存之上。 */
81
87
  readonly env?: Readonly<Record<string, string>> | undefined;
88
+ /** 写工作区时必须给:工具里传 exec;路由/动作没有会话,不能请求 workspace。 */
82
89
  readonly session?: unknown;
90
+ /** 取消信号;有人按停时 abort。 */
83
91
  readonly signal?: AbortSignal | undefined;
92
+ /** 'safe' 只给幂等 / 只读命令,失败时可安全重试;默认 'never'。 */
84
93
  readonly retry?: 'safe' | 'never' | undefined;
85
94
  }
86
95
 
@@ -12,7 +12,9 @@ export interface UnitSeamPorts {
12
12
  readonly realHome?: string | undefined;
13
13
  }
14
14
 
15
+ /** 一次受控执行:能写哪里由清单声明,每次调用还要带 scope。 */
15
16
  export interface UnitSeam {
17
+ /** 运行一条命令。scope=workspace 要先在清单声明写入域并带会话;retry 默认 'never'。 */
16
18
  run(request: UnitSeamRequest): Promise<SeamOutcome>;
17
19
  }
18
20
 
@@ -11,13 +11,21 @@ import { sessionIdOf, sessionWorkspace } from './tool-kit.js';
11
11
  * 宿主 kit 的公共部分:flow、工具侧 session 读法、外部供给装法、宿主平台事实、按 unit 绑定的执行缝门面。
12
12
  */
13
13
  export interface HostKit {
14
+ /** 流程入口:createActions / check / run。 */
14
15
  readonly flow: FlowHost;
16
+ /** 从工具执行上下文读会话 id;没有会话时 null。 */
15
17
  readonly sessionIdOf: typeof sessionIdOf;
18
+ /** 从工具执行上下文读当前工作区;没有会话时 null。 */
16
19
  readonly sessionWorkspace: typeof sessionWorkspace;
20
+ /** 拼共用依赖的安装提示;只展示、不执行。 */
17
21
  readonly libInstallCommand: EnvSupplyPort['libInstallCommand'];
22
+ /** 工作台平台信息:deployment / capabilities / toolchain。 */
18
23
  readonly surface: HostSurface;
24
+ /** 按 unit 绑定的受控执行缝;清单没声明 host.writes 时是 undefined。 */
19
25
  readonly seam?: UnitSeam | undefined;
26
+ /** 模块用的模型入口;这份运行时没有模型时是 undefined。 */
20
27
  readonly ai?: AiPort | undefined;
28
+ /** 会话草稿库;没有它就不能把远端文件挂到本地再提交。 */
21
29
  readonly drafts?: DraftStore | undefined;
22
30
  }
23
31
 
@@ -60,7 +60,9 @@ export interface LongTaskChange<S extends LongTaskBase> {
60
60
  readonly by?: string | undefined;
61
61
  }
62
62
 
63
+ /** 长任务怎么跑、怎么投影成面板那一行。 */
63
64
  export interface LongTaskDeps<S extends LongTaskBase> {
65
+ /** 真正执行任务:payload 来自 start,onStep 报步骤,signal 被 abort 时尽快退出。 */
64
66
  readonly run: (options: {
65
67
  readonly payload: unknown;
66
68
  readonly onStep: (step: LongTaskStep) => void;
@@ -69,8 +71,11 @@ export interface LongTaskDeps<S extends LongTaskBase> {
69
71
  readonly step?: ((step: LongTaskStep, current: S) => Partial<S>) | undefined;
70
72
  readonly outcome?: ((result: unknown, current: S) => Partial<S>) | undefined;
71
73
  readonly stopped?: ((current: S) => Partial<S>) | undefined;
74
+ /** 用户点「我处理完了」时调;不给行上就没这颗钮。 */
72
75
  readonly recheck?: ((current: S) => void) | undefined;
76
+ /** 用户交回执时调;不给行上就没表单。 */
73
77
  readonly answer?: ((current: S, values: Readonly<Record<string, string>>) => void) | undefined;
78
+ /** 把快照投影成面板那一行要的字段。 */
74
79
  readonly view: (snapshot: S) => Readonly<Record<string, unknown>>;
75
80
  readonly now?: (() => string) | undefined;
76
81
  readonly nextId?: (() => string) | undefined;
@@ -83,15 +88,24 @@ export interface LongTaskDeps<S extends LongTaskBase> {
83
88
  * loading 点要的(**不分工作区、不分目标**,把现在活着的每一趟交出来),`stop` 只把中断信号转给生产方。
84
89
  */
85
90
  export interface LongTaskRegistry<S extends LongTaskBase> {
91
+ /** 行上有没有「我处理完了」;建注册表时给了 recheck 才 true。 */
86
92
  readonly resumable: boolean;
93
+ /** 行上有没有结构化回执表单;建注册表时给了 answer 才 true。 */
87
94
  readonly answerable: boolean;
95
+ /** 起一趟;同 workspace + target 已有活的就直接返回它,不重复起。 */
88
96
  start(options: LongTaskStart): S;
97
+ /** 按 id 取快照;不在或已清掉回 null。 */
89
98
  snapshot(id: string): S | null;
99
+ /** 找同 workspace + target 的活任务;没有回 null。 */
90
100
  active(workspace: string, target: string): S | null;
101
+ /** 一个工作区里每个 target 最新一趟的投影;活的加最近 recentMs 内的。 */
91
102
  current(workspace: string): readonly Readonly<Record<string, unknown>>[];
103
+ /** 现在活着的每一趟,不分工作区 / 目标;给侧栏状态点用。 */
92
104
  live(): readonly S[];
105
+ /** 请求停止:把中断信号转给生产方;没有这趟或已经结束回 false。 */
93
106
  stop(id: string, by?: string): boolean;
94
107
  recheck(id: string): boolean;
108
+ /** 交回执:只认 intervention.fields 里的 key,必填缺失回 false。 */
95
109
  answer(id: string, values: Readonly<Record<string, string>>): boolean;
96
110
  onChange(listener: (change: LongTaskChange<S>) => void): () => void;
97
111
  rebind?(deps: LongTaskDeps<S>): void;
@@ -485,7 +499,9 @@ export function sharedLongTaskRegistry<S extends LongTaskBase>(
485
499
  return created;
486
500
  }
487
501
 
502
+ /** 一个单元的长任务入口:按 key 建注册表。 */
488
503
  export interface LongTaskHost {
504
+ /** key 是模块内稳定的标识;run / view 必给,recheck / answer 决定行上有没有恢复与回执。 */
489
505
  create<S extends LongTaskBase>(options: { readonly key: string } & LongTaskDeps<S>): LongTaskRegistry<S>;
490
506
  }
491
507
 
@@ -21,25 +21,45 @@ export interface ToolScopeContext {
21
21
  readonly scope?: unknown;
22
22
  }
23
23
 
24
+ /**
25
+ * mount(deps) 拿到的工作台依赖:清单、上下文、数据、执行缝、存储、长任务与供给。
26
+ * 可选成员缺省表示这份运行时不提供该能力。
27
+ */
24
28
  export interface UnitMountDeps extends HostKit {
29
+ /** 当前单元清单。 */
25
30
  readonly manifest: UnitManifest;
31
+ /** 工作台上下文:取服务、登记生命周期。 */
26
32
  readonly ctx: HostContext;
33
+ /** 工作台日志口;没有就不记。 */
27
34
  readonly logger?: { info?(message: string): void; warn?(message: string): void } | undefined;
35
+ /** 读当前安装的其它单元清单。 */
28
36
  readonly manifests: () => readonly UnitManifest[];
37
+ /** 读当前模块拥有的单元 id。 */
29
38
  readonly ownedUnits: () => readonly string[];
39
+ /** 可安装单元 id;没有这个能力时 undefined。 */
30
40
  readonly installable?: (() => readonly string[]) | undefined;
41
+ /** 站点数据读取:request / plan / submitPlan。 */
31
42
  readonly data: DataReader;
43
+ /** 工作台编排出的只读环境变量;不要直接改。 */
32
44
  readonly env?: Readonly<Record<string, string | undefined>> | undefined;
45
+ /** 共用依赖读取;没有时 undefined。 */
33
46
  readonly libs?: LibReader | undefined;
47
+ /** 受控 git 读取;没有时 undefined。 */
34
48
  readonly git?: GitReader | undefined;
49
+ /** argv 命令执行;没有时 undefined。 */
35
50
  readonly commands?: CommandReader | undefined;
51
+ /** 按工作区持久化状态。 */
36
52
  readonly store: WorkspaceStore;
53
+ /** 跨单元值交接;没有时 undefined。 */
37
54
  readonly values?: ValueHandoff | undefined;
55
+ /** 探测单元能力;force 绕过缓存。 */
38
56
  readonly probe?: (
39
57
  unit: string,
40
58
  options?: { readonly force?: boolean; readonly needs?: readonly Need[] },
41
59
  ) => Promise<UnitCapability | undefined>;
60
+ /** 长任务入口;没有时 undefined。 */
42
61
  readonly longTasks?: LongTaskHost | undefined;
62
+ /** 读当前长任务运行表;没有时 undefined。 */
43
63
  readonly longTaskRuns?: (() => ReadonlyMap<string, LongTaskRegistry<LongTaskBase>>) | undefined;
44
64
  }
45
65
 
@@ -11,8 +11,11 @@ export interface HandoffValue {
11
11
  readonly at: number;
12
12
  }
13
13
 
14
+ /** 跨单元交接一个值:按 (fact, key) 放,取一次就没了,过期当没放。 */
14
15
  export interface ValueHandoff {
16
+ /** 放一个值,覆盖同 (fact, key) 的旧值;now 只给测试用。 */
15
17
  hand(entry: HandoffEntry, value: unknown, now?: number): void;
18
+ /** 取走同 (fact, key) 的值;取过就删,过期也返回 undefined。 */
16
19
  take(entry: HandoffEntry, now?: number): HandoffValue | undefined;
17
20
  }
18
21