clack-kit 0.0.1-beta.1

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.
@@ -0,0 +1,2976 @@
1
+ import * as _$_clack_prompts0 from "@clack/prompts";
2
+ import { AutocompleteMultiSelectOptions, AutocompleteOptions, BoxAlignment, BoxOptions, CommonOptions, ConfirmOptions, GroupMultiSelectOptions, LimitOptionsParams, LogMessageOptions, MultiSelectOptions, NoteOptions, PasswordOptions, PathOptions, ProgressOptions, ProgressResult, SelectKeyOptions, SelectOptions, SpinnerOptions, SpinnerResult, Task, TaskLogOptions, TextOptions, autocomplete, autocompleteMultiselect, box, cancel, confirm, group, groupMultiselect, intro, isCI, isCancel, isTTY, limitOptions, log, multiselect, note, outro, password, path, progress, select, selectKey, spinner, stream, symbol, symbolBar, taskLog, tasks, text, unicode, unicodeOr } from "@clack/prompts";
3
+ import * as _$node_stream0 from "node:stream";
4
+
5
+ //#region node_modules/picocolors/types.d.ts
6
+ type Formatter = (input: string | number | null | undefined) => string;
7
+ interface Colors {
8
+ isColorSupported: boolean;
9
+ reset: Formatter;
10
+ bold: Formatter;
11
+ dim: Formatter;
12
+ italic: Formatter;
13
+ underline: Formatter;
14
+ inverse: Formatter;
15
+ hidden: Formatter;
16
+ strikethrough: Formatter;
17
+ black: Formatter;
18
+ red: Formatter;
19
+ green: Formatter;
20
+ yellow: Formatter;
21
+ blue: Formatter;
22
+ magenta: Formatter;
23
+ cyan: Formatter;
24
+ white: Formatter;
25
+ gray: Formatter;
26
+ bgBlack: Formatter;
27
+ bgRed: Formatter;
28
+ bgGreen: Formatter;
29
+ bgYellow: Formatter;
30
+ bgBlue: Formatter;
31
+ bgMagenta: Formatter;
32
+ bgCyan: Formatter;
33
+ bgWhite: Formatter;
34
+ blackBright: Formatter;
35
+ redBright: Formatter;
36
+ greenBright: Formatter;
37
+ yellowBright: Formatter;
38
+ blueBright: Formatter;
39
+ magentaBright: Formatter;
40
+ cyanBright: Formatter;
41
+ whiteBright: Formatter;
42
+ bgBlackBright: Formatter;
43
+ bgRedBright: Formatter;
44
+ bgGreenBright: Formatter;
45
+ bgYellowBright: Formatter;
46
+ bgBlueBright: Formatter;
47
+ bgMagentaBright: Formatter;
48
+ bgCyanBright: Formatter;
49
+ bgWhiteBright: Formatter;
50
+ }
51
+ //#endregion
52
+ //#region node_modules/picocolors/picocolors.d.ts
53
+ declare const picocolors: Colors & {
54
+ createColors: (enabled?: boolean) => Colors;
55
+ };
56
+ //#endregion
57
+ //#region node_modules/@clack/core/dist/index.d.mts
58
+ /**
59
+ * The state of the prompt
60
+ */
61
+ type ClackState = 'initial' | 'active' | 'cancel' | 'submit' | 'error';
62
+ /**
63
+ * Typed event emitter for clack
64
+ */
65
+ //#endregion
66
+ //#region src/runtime/clack.d.ts
67
+ /** 默认的 Clack runtime,供渲染器复用 */
68
+ declare const defaultPromptRuntime: {
69
+ autocomplete: <Value>(opts: _$_clack_prompts0.AutocompleteOptions<Value>) => Promise<Value | symbol>;
70
+ autocompleteMultiselect: <Value>(opts: _$_clack_prompts0.AutocompleteMultiSelectOptions<Value>) => Promise<Value[] | symbol>;
71
+ box: (message?: string, title?: string, opts?: _$_clack_prompts0.BoxOptions) => void;
72
+ cancel: (message?: string, opts?: _$_clack_prompts0.CommonOptions) => void;
73
+ confirm: (opts: _$_clack_prompts0.ConfirmOptions) => Promise<boolean | symbol>;
74
+ group: <T>(prompts: _$_clack_prompts0.PromptGroup<T>, opts?: _$_clack_prompts0.PromptGroupOptions<T>) => Promise<{ [P in keyof _$_clack_prompts0.PromptGroupAwaitedReturn<T>]: _$_clack_prompts0.PromptGroupAwaitedReturn<T>[P] }>;
75
+ groupMultiselect: <Value>(opts: _$_clack_prompts0.GroupMultiSelectOptions<Value>) => Promise<Value[] | symbol>;
76
+ intro: (title?: string, opts?: _$_clack_prompts0.CommonOptions) => void;
77
+ isCancel: typeof isCancel;
78
+ isCI: () => boolean;
79
+ isTTY: (output: _$node_stream0.Writable) => boolean;
80
+ limitOptions: <TOption>({
81
+ cursor,
82
+ options,
83
+ style,
84
+ output,
85
+ maxItems,
86
+ columnPadding,
87
+ rowPadding
88
+ }: _$_clack_prompts0.LimitOptionsParams<TOption>) => string[];
89
+ log: {
90
+ message: (message?: string | string[], {
91
+ symbol,
92
+ secondarySymbol,
93
+ output,
94
+ spacing,
95
+ withGuide
96
+ }?: _$_clack_prompts0.LogMessageOptions) => void;
97
+ info: (message: string, opts?: _$_clack_prompts0.LogMessageOptions) => void;
98
+ success: (message: string, opts?: _$_clack_prompts0.LogMessageOptions) => void;
99
+ step: (message: string, opts?: _$_clack_prompts0.LogMessageOptions) => void;
100
+ warn: (message: string, opts?: _$_clack_prompts0.LogMessageOptions) => void;
101
+ warning: (message: string, opts?: _$_clack_prompts0.LogMessageOptions) => void;
102
+ error: (message: string, opts?: _$_clack_prompts0.LogMessageOptions) => void;
103
+ };
104
+ multiselect: <Value>(opts: _$_clack_prompts0.MultiSelectOptions<Value>) => Promise<Value[] | symbol>;
105
+ note: (message?: string, title?: string, opts?: _$_clack_prompts0.NoteOptions) => void;
106
+ outro: (message?: string, opts?: _$_clack_prompts0.CommonOptions) => void;
107
+ password: (opts: _$_clack_prompts0.PasswordOptions) => Promise<string | symbol>;
108
+ path: (opts: _$_clack_prompts0.PathOptions) => Promise<string | symbol>;
109
+ progress: typeof progress;
110
+ select: <Value>(opts: _$_clack_prompts0.SelectOptions<Value>) => Promise<Value | symbol>;
111
+ selectKey: <Value extends string>(opts: _$_clack_prompts0.SelectKeyOptions<Value>) => Promise<Value | symbol>;
112
+ spinner: ({
113
+ indicator,
114
+ onCancel,
115
+ output,
116
+ cancelMessage,
117
+ errorMessage,
118
+ frames,
119
+ delay,
120
+ signal,
121
+ ...opts
122
+ }?: _$_clack_prompts0.SpinnerOptions) => _$_clack_prompts0.SpinnerResult;
123
+ stream: {
124
+ message: (iterable: Iterable<string> | AsyncIterable<string>, {
125
+ symbol
126
+ }?: _$_clack_prompts0.LogMessageOptions) => Promise<void>;
127
+ info: (iterable: Iterable<string> | AsyncIterable<string>) => Promise<void>;
128
+ success: (iterable: Iterable<string> | AsyncIterable<string>) => Promise<void>;
129
+ step: (iterable: Iterable<string> | AsyncIterable<string>) => Promise<void>;
130
+ warn: (iterable: Iterable<string> | AsyncIterable<string>) => Promise<void>;
131
+ warning: (iterable: Iterable<string> | AsyncIterable<string>) => Promise<void>;
132
+ error: (iterable: Iterable<string> | AsyncIterable<string>) => Promise<void>;
133
+ };
134
+ symbol: (state: ClackState) => string;
135
+ symbolBar: (state: ClackState) => string;
136
+ taskLog: (opts: _$_clack_prompts0.TaskLogOptions) => {
137
+ message(msg: string, mopts?: _$_clack_prompts0.TaskLogMessageOptions): void;
138
+ group(name: string): {
139
+ message(msg: string, mopts?: _$_clack_prompts0.TaskLogMessageOptions): void;
140
+ error(message: string): void;
141
+ success(message: string): void;
142
+ };
143
+ error(message: string, opts?: _$_clack_prompts0.TaskLogCompletionOptions): void;
144
+ success(message: string, opts?: _$_clack_prompts0.TaskLogCompletionOptions): void;
145
+ };
146
+ tasks: (tasks: _$_clack_prompts0.Task[], opts?: _$_clack_prompts0.CommonOptions) => Promise<void>;
147
+ text: (opts: _$_clack_prompts0.TextOptions) => Promise<string | symbol>;
148
+ unicode: boolean;
149
+ unicodeOr: (c: string, fallback: string) => string;
150
+ };
151
+ /** Clack runtime 的形状定义 */
152
+ type PromptRuntime = typeof defaultPromptRuntime;
153
+ //#endregion
154
+ //#region src/shared/types.d.ts
155
+ type MaybePromise<TValue> = Promise<TValue> | TValue;
156
+ type WorkflowColors = Omit<typeof picocolors, 'createColors'>;
157
+ /** 支持的内置语言标识 */
158
+ type WorkflowLocale = 'en-US' | 'zh-CN' | (string & {});
159
+ /** 时区标识,通常使用 IANA Time Zone 名称 */
160
+ type WorkflowTimeZone = string;
161
+ /** 统一的日志级别 */
162
+ type WorkflowLogLevel = 'error' | 'info' | 'message' | 'step' | 'success' | 'warn' | 'warning';
163
+ /** 工作流运行的最终状态 */
164
+ type WorkflowRunStatus = 'cancelled' | 'completed' | 'failed' | 'running';
165
+ /** 历史复用策略 */
166
+ type WorkflowHistoryReuseMode = 'ask' | 'history' | 'latest' | 'off';
167
+ /** Checkpoint 恢复策略 */
168
+ type WorkflowCheckpointResumeMode = 'always' | 'ask' | 'never';
169
+ /** Checkpoint 保留时的中断原因 */
170
+ type WorkflowCheckpointReason = 'cancelled' | 'failed';
171
+ /** 结构化消息模板的插值参数 */
172
+ type WorkflowMessageValues = Record<string, boolean | null | number | string | undefined>;
173
+ /** 单个 locale 的嵌套资源结构 */
174
+ interface WorkflowLocaleResource {
175
+ [key: string]: string | WorkflowLocaleResource;
176
+ }
177
+ /** 国际化 locale 资源目录 */
178
+ type WorkflowLocaleCatalog = Record<string, WorkflowLocaleResource>;
179
+ /** 选择类步骤的选项结构 */
180
+ interface WorkflowSelectOption<TValue> {
181
+ /** 是否禁用当前选项 */
182
+ disabled?: boolean;
183
+ /** 展示在终端中的补充说明 */
184
+ hint?: string;
185
+ /** 选项标签 */
186
+ label: string;
187
+ /** 选项值 */
188
+ value: TValue;
189
+ }
190
+ /** 工作流运行时暴露给回调和 resolver 的上下文 */
191
+ interface WorkflowRuntimeContext<TValues extends Record<string, unknown> = Record<string, unknown>, TResults extends Record<string, unknown> = Record<string, unknown>> {
192
+ /** 输出结构化 box */
193
+ box: (message?: string, title?: string, options?: WorkflowRendererBoxOptions) => void;
194
+ /** picocolors 颜色工具,可直接拿来拼装彩色输出 */
195
+ colors: WorkflowColors;
196
+ /** 当前运行语言 */
197
+ locale: WorkflowLocale;
198
+ /** 输出一条带级别的消息 */
199
+ log: (level: WorkflowLogLevel, message: string | string[], options?: WorkflowRendererLogOptions) => void;
200
+ /** 输出结构化说明块 */
201
+ note: (message?: string, title?: string, options?: WorkflowRendererNoteOptions) => void;
202
+ /** 当前运行 ID */
203
+ runId: string;
204
+ /** 读取本次运行中可用的辅助函数 */
205
+ tools: WorkflowContextTools;
206
+ /** 翻译消息 */
207
+ t: (key: string, params?: WorkflowMessageValues) => string;
208
+ /** 当前运行时区 */
209
+ timeZone: WorkflowTimeZone;
210
+ /** 当前步骤执行结果;读取命令步骤返回值时优先使用这里 */
211
+ results: Partial<TResults>;
212
+ /** 当前已解析的 values */
213
+ values: Partial<TValues>;
214
+ /** 当前工作流 ID */
215
+ workflowId: string;
216
+ }
217
+ /** 工作流上下文中可直接复用的辅助函数 */
218
+ interface WorkflowContextTools {
219
+ /** 允许插件向 tools 挂载额外能力 */
220
+ [key: string]: unknown;
221
+ /** 暴露原始 @clack/prompts runtime,便于直接复用内置组件 */
222
+ clack: PromptRuntime;
223
+ /** 当前项目根目录 */
224
+ projectRoot: string;
225
+ /** 读取文本文件 */
226
+ readFile: (filePath: string) => Promise<string>;
227
+ /** 读取 JSON 文件 */
228
+ readJson: <TValue = unknown>(filePath: string) => Promise<TValue>;
229
+ /** 执行简单 glob 查询 */
230
+ globFiles: (pattern: string, options?: WorkflowGlobOptions) => Promise<string[]>;
231
+ /** 合并并写回 JSON 文件 */
232
+ patchJson: <TValue extends Record<string, unknown>>(filePath: string, updater: (current: TValue) => MaybePromise<TValue>) => Promise<TValue>;
233
+ /** 休眠指定毫秒数 */
234
+ sleep: (milliseconds: number) => Promise<void>;
235
+ /** 写入文本文件 */
236
+ writeFile: (filePath: string, content: string) => Promise<void>;
237
+ /** 写入 JSON 文件 */
238
+ writeJson: (filePath: string, value: unknown) => Promise<void>;
239
+ }
240
+ /** 允许用常量或 resolver 提供动态值 */
241
+ type WorkflowValueResolver<TValue, TValues extends Record<string, unknown> = Record<string, unknown>, TResults extends Record<string, unknown> = Record<string, unknown>> = TValue | ((context: WorkflowRuntimeContext<TValues, TResults>) => MaybePromise<TValue>);
242
+ /** 步骤是否执行的判定函数 */
243
+ type WorkflowPredicate<TValues extends Record<string, unknown> = Record<string, unknown>, TResults extends Record<string, unknown> = Record<string, unknown>> = (context: WorkflowRuntimeContext<TValues, TResults>) => MaybePromise<boolean>;
244
+ /** 步骤值校验函数 */
245
+ type WorkflowValidator<TValue, TValues extends Record<string, unknown> = Record<string, unknown>, TResults extends Record<string, unknown> = Record<string, unknown>> = (value: TValue, context: WorkflowRuntimeContext<TValues, TResults>) => MaybePromise<Error | string | undefined>;
246
+ /** 所有可执行步骤共有的基础配置 */
247
+ interface WorkflowBaseStep<TId extends string, TValue, TKind extends string> {
248
+ /** 步骤在 values 中对应的 key */
249
+ id: TId;
250
+ /** 为交互输入提供默认值;不同于运行参数里的 `initialValues` */
251
+ defaultValue?: WorkflowValueResolver<TValue | undefined>;
252
+ /** 步骤类型 */
253
+ kind: TKind;
254
+ /** 控制步骤是否执行 */
255
+ when?: WorkflowPredicate<Record<string, unknown>>;
256
+ }
257
+ /** 文本输入步骤 */
258
+ interface WorkflowTextStep<TId extends string> extends WorkflowBaseStep<TId, string, 'text'> {
259
+ /** 提示文案 */
260
+ message: WorkflowValueResolver<TextOptions['message']>;
261
+ /** 占位提示 */
262
+ placeholder?: WorkflowValueResolver<TextOptions['placeholder']>;
263
+ /** 是否必填;当为 `true` 时默认文案为 `<Key> is required` */
264
+ required?: boolean | string;
265
+ /** 是否显示 Clack guide */
266
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
267
+ /** 自定义校验函数 */
268
+ validate?: WorkflowValidator<string>;
269
+ }
270
+ /** 单选步骤 */
271
+ interface WorkflowSelectStep<TId extends string, TValue> extends WorkflowBaseStep<TId, TValue, 'select'> {
272
+ /** 提示文案 */
273
+ message: WorkflowValueResolver<SelectOptions<TValue>['message']>;
274
+ /** 最多显示多少项 */
275
+ maxItems?: WorkflowValueResolver<SelectOptions<TValue>['maxItems']>;
276
+ /** 可选项列表 */
277
+ options: WorkflowValueResolver<readonly TValue[]> | WorkflowValueResolver<readonly WorkflowSelectOption<TValue>[]>;
278
+ /** 是否显示 Clack guide */
279
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
280
+ /** 自定义校验函数 */
281
+ validate?: WorkflowValidator<TValue>;
282
+ }
283
+ /** 自动补全步骤,表现为带筛选能力的单选 */
284
+ interface WorkflowAutocompleteStep<TId extends string, TValue> extends WorkflowBaseStep<TId, TValue, 'autocomplete'> {
285
+ /** 自定义筛选函数 */
286
+ filter?: (search: string, option: WorkflowSelectOption<TValue>) => boolean;
287
+ /** 首次打开时的搜索词 */
288
+ initialUserInput?: WorkflowValueResolver<AutocompleteOptions<TValue>['initialUserInput']>;
289
+ /** 提示文案 */
290
+ message: WorkflowValueResolver<AutocompleteOptions<TValue>['message']>;
291
+ /** 最多显示多少项 */
292
+ maxItems?: WorkflowValueResolver<AutocompleteOptions<TValue>['maxItems']>;
293
+ /** 可搜索选项列表 */
294
+ options: WorkflowValueResolver<readonly TValue[]> | WorkflowValueResolver<readonly WorkflowSelectOption<TValue>[]>;
295
+ /** 搜索输入占位提示 */
296
+ placeholder?: WorkflowValueResolver<AutocompleteOptions<TValue>['placeholder']>;
297
+ /** 是否显示 Clack guide */
298
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
299
+ /** 自定义校验函数 */
300
+ validate?: WorkflowValidator<TValue>;
301
+ }
302
+ /** 多选步骤 */
303
+ interface WorkflowMultiSelectStep<TId extends string, TValue> extends WorkflowBaseStep<TId, TValue[], 'multiselect'> {
304
+ /** 初始光标所在的选项值 */
305
+ cursorAt?: WorkflowValueResolver<MultiSelectOptions<TValue>['cursorAt']>;
306
+ /** 提示文案 */
307
+ message: WorkflowValueResolver<MultiSelectOptions<TValue>['message']>;
308
+ /** 最多显示多少项 */
309
+ maxItems?: WorkflowValueResolver<MultiSelectOptions<TValue>['maxItems']>;
310
+ /** 可选项列表 */
311
+ options: WorkflowValueResolver<readonly TValue[]> | WorkflowValueResolver<readonly WorkflowSelectOption<TValue>[]>;
312
+ /** 是否至少要选中一项;为 `true` 时默认文案为 `<Key> is required` */
313
+ required?: boolean | string;
314
+ /** 是否显示 Clack guide */
315
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
316
+ /** 自定义校验函数 */
317
+ validate?: WorkflowValidator<TValue[]>;
318
+ }
319
+ /** 自动补全多选步骤 */
320
+ interface WorkflowAutocompleteMultiSelectStep<TId extends string, TValue> extends WorkflowBaseStep<TId, TValue[], 'autocomplete-multiselect'> {
321
+ /** 自定义筛选函数 */
322
+ filter?: (search: string, option: WorkflowSelectOption<TValue>) => boolean;
323
+ /** 提示文案 */
324
+ message: WorkflowValueResolver<AutocompleteMultiSelectOptions<TValue>['message']>;
325
+ /** 最多显示多少项 */
326
+ maxItems?: WorkflowValueResolver<AutocompleteMultiSelectOptions<TValue>['maxItems']>;
327
+ /** 可搜索选项列表 */
328
+ options: WorkflowValueResolver<readonly TValue[]> | WorkflowValueResolver<readonly WorkflowSelectOption<TValue>[]>;
329
+ /** 搜索输入占位提示 */
330
+ placeholder?: WorkflowValueResolver<AutocompleteMultiSelectOptions<TValue>['placeholder']>;
331
+ /** 是否至少要选中一项;为 `true` 时默认文案为 `<Key> is required` */
332
+ required?: boolean | string;
333
+ /** 是否显示 Clack guide */
334
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
335
+ /** 自定义校验函数 */
336
+ validate?: WorkflowValidator<TValue[]>;
337
+ }
338
+ /** 分组多选步骤 */
339
+ interface WorkflowGroupMultiSelectStep<TId extends string, TValue> extends WorkflowBaseStep<TId, TValue[], 'group-multiselect'> {
340
+ /** 初始光标所在的选项值 */
341
+ cursorAt?: WorkflowValueResolver<GroupMultiSelectOptions<TValue>['cursorAt']>;
342
+ /** 分组间距 */
343
+ groupSpacing?: WorkflowValueResolver<GroupMultiSelectOptions<TValue>['groupSpacing']>;
344
+ /** 提示文案 */
345
+ message: WorkflowValueResolver<GroupMultiSelectOptions<TValue>['message']>;
346
+ /** 分组选项列表 */
347
+ options: WorkflowValueResolver<Record<string, readonly TValue[] | readonly WorkflowSelectOption<TValue>[]>>;
348
+ /** 是否至少要选中一项;为 `true` 时默认文案为 `<Key> is required` */
349
+ required?: boolean | string;
350
+ /** 是否允许直接选中整组 */
351
+ selectableGroups?: WorkflowValueResolver<GroupMultiSelectOptions<TValue>['selectableGroups']>;
352
+ /** 是否显示 Clack guide */
353
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
354
+ /** 自定义校验函数 */
355
+ validate?: WorkflowValidator<TValue[]>;
356
+ }
357
+ /** 密码输入步骤 */
358
+ interface WorkflowPasswordStep<TId extends string> extends WorkflowBaseStep<TId, string, 'password'> {
359
+ /** 校验失败时是否清空输入 */
360
+ clearOnError?: WorkflowValueResolver<PasswordOptions['clearOnError']>;
361
+ /** 掩码字符 */
362
+ mask?: WorkflowValueResolver<PasswordOptions['mask']>;
363
+ /** 提示文案 */
364
+ message: WorkflowValueResolver<PasswordOptions['message']>;
365
+ /** 是否必填;当为 `true` 时默认文案为 `<Key> is required` */
366
+ required?: boolean | string;
367
+ /** 是否显示 Clack guide */
368
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
369
+ /** 自定义校验函数 */
370
+ validate?: WorkflowValidator<string>;
371
+ }
372
+ /** 文件路径输入步骤 */
373
+ interface WorkflowPathStep<TId extends string> extends WorkflowBaseStep<TId, string, 'path'> {
374
+ /** 是否要求选择目录 */
375
+ directory?: WorkflowValueResolver<PathOptions['directory']>;
376
+ /** 提示文案 */
377
+ message: WorkflowValueResolver<PathOptions['message']>;
378
+ /** 是否必填;当为 `true` 时默认文案为 `<Key> is required` */
379
+ required?: boolean | string;
380
+ /** 根目录 */
381
+ root?: WorkflowValueResolver<PathOptions['root']>;
382
+ /** 是否显示 Clack guide */
383
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
384
+ /** 自定义校验函数 */
385
+ validate?: WorkflowValidator<string>;
386
+ }
387
+ /** 带快捷键的单选步骤 */
388
+ interface WorkflowSelectKeyStep<TId extends string, TValue extends string> extends WorkflowBaseStep<TId, TValue, 'select-key'> {
389
+ /** 是否区分大小写 */
390
+ caseSensitive?: WorkflowValueResolver<SelectKeyOptions<TValue>['caseSensitive']>;
391
+ /** 提示文案 */
392
+ message: WorkflowValueResolver<SelectKeyOptions<TValue>['message']>;
393
+ /** 可选项列表 */
394
+ options: WorkflowValueResolver<readonly TValue[]> | WorkflowValueResolver<readonly WorkflowSelectOption<TValue>[]>;
395
+ /** 是否显示 Clack guide */
396
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
397
+ /** 自定义校验函数 */
398
+ validate?: WorkflowValidator<TValue>;
399
+ }
400
+ /** 布尔确认步骤 */
401
+ interface WorkflowConfirmStep<TId extends string> extends WorkflowBaseStep<TId, boolean, 'confirm'> {
402
+ /** “确认”文案 */
403
+ active?: WorkflowValueResolver<ConfirmOptions['active']>;
404
+ /** “取消”文案 */
405
+ inactive?: WorkflowValueResolver<ConfirmOptions['inactive']>;
406
+ /** 提示文案 */
407
+ message: WorkflowValueResolver<ConfirmOptions['message']>;
408
+ /** 是否垂直排列选项 */
409
+ vertical?: WorkflowValueResolver<ConfirmOptions['vertical']>;
410
+ /** 是否显示 Clack guide */
411
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
412
+ /** 自定义校验函数 */
413
+ validate?: WorkflowValidator<boolean>;
414
+ }
415
+ /** 结构化说明步骤 */
416
+ interface WorkflowNoteStep<TId extends string> extends WorkflowBaseStep<TId, undefined, 'note'> {
417
+ /** 每一行的格式化函数 */
418
+ format?: NoteOptions['format'];
419
+ /** 提示内容 */
420
+ message?: WorkflowValueResolver<string | undefined>;
421
+ /** 标题 */
422
+ title?: WorkflowValueResolver<string | undefined>;
423
+ /** 是否显示 Clack guide */
424
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
425
+ }
426
+ /** 带边框的说明步骤 */
427
+ interface WorkflowBoxStep<TId extends string> extends WorkflowBaseStep<TId, undefined, 'box'> {
428
+ /** 内容对齐方式 */
429
+ contentAlign?: WorkflowValueResolver<BoxOptions['contentAlign']>;
430
+ /** 内容内边距 */
431
+ contentPadding?: WorkflowValueResolver<BoxOptions['contentPadding']>;
432
+ /** 自定义边框格式化 */
433
+ formatBorder?: BoxOptions['formatBorder'];
434
+ /** 提示内容 */
435
+ message?: WorkflowValueResolver<string | undefined>;
436
+ /** 是否使用圆角 */
437
+ rounded?: WorkflowValueResolver<BoxOptions['rounded']>;
438
+ /** 标题对齐方式 */
439
+ titleAlign?: WorkflowValueResolver<BoxOptions['titleAlign']>;
440
+ /** 标题内边距 */
441
+ titlePadding?: WorkflowValueResolver<BoxOptions['titlePadding']>;
442
+ /** 标题 */
443
+ title?: WorkflowValueResolver<string | undefined>;
444
+ /** 是否显示 Clack guide */
445
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
446
+ /** 宽度 */
447
+ width?: WorkflowValueResolver<BoxOptions['width']>;
448
+ }
449
+ /** 语义化日志步骤 */
450
+ interface WorkflowLogStep<TId extends string> extends WorkflowBaseStep<TId, undefined, 'log'> {
451
+ /** 日志级别 */
452
+ level?: WorkflowValueResolver<WorkflowLogLevel | undefined>;
453
+ /** 日志内容 */
454
+ message?: WorkflowValueResolver<string | string[] | undefined>;
455
+ /** 次级符号 */
456
+ secondarySymbol?: WorkflowValueResolver<LogMessageOptions['secondarySymbol']>;
457
+ /** 行间距 */
458
+ spacing?: WorkflowValueResolver<LogMessageOptions['spacing']>;
459
+ /** 主符号 */
460
+ symbol?: WorkflowValueResolver<LogMessageOptions['symbol']>;
461
+ /** 是否显示 Clack guide */
462
+ withGuide?: WorkflowValueResolver<CommonOptions['withGuide']>;
463
+ }
464
+ /** 命令步骤最终结果类型;具体结构由步骤作者决定 */
465
+ type WorkflowCommandResult<TValue = unknown> = TValue;
466
+ /** 外部命令执行器返回的标准执行记录 */
467
+ interface WorkflowCommandExecutionResult {
468
+ /** 退出码 */
469
+ code: number;
470
+ /** 合并后的 stdout + stderr 文本 */
471
+ combined: string;
472
+ /** stderr 文本 */
473
+ stderr: string;
474
+ /** stdout 文本 */
475
+ stdout: string;
476
+ }
477
+ /** 命令步骤失败后的重试配置 */
478
+ interface WorkflowCommandRetryOptions {
479
+ /** 退避策略 */
480
+ backoff?: 'exponential' | 'fixed' | 'linear';
481
+ /** 每次重试前的基础等待毫秒数 */
482
+ delayMs?: number;
483
+ /** 最大尝试次数,包含首次执行 */
484
+ maxAttempts?: number;
485
+ }
486
+ /** shell 模式下执行脚本时用到的解释器配置 */
487
+ interface WorkflowCommandShellOptions {
488
+ /** shell 可执行文件;未提供时按当前平台选择默认值 */
489
+ command?: WorkflowValueResolver<string | undefined>;
490
+ /** 传给 shell 的前置参数;运行时会自动把脚本文本追加到最后 */
491
+ args?: WorkflowValueResolver<string[] | undefined>;
492
+ }
493
+ /** 在 command 步骤内部直接执行命令时可传的选项 */
494
+ interface WorkflowCommandExecOptions {
495
+ /** 工作目录;相对路径会基于项目根目录解析 */
496
+ cwd?: string;
497
+ /** 额外环境变量 */
498
+ env?: NodeJS.ProcessEnv;
499
+ /** shell 解释器配置;未提供时自动检测或回退到平台默认值 */
500
+ shell?: WorkflowCommandShellOptions;
501
+ /** stdin 处理策略 */
502
+ stdin?: 'ignore' | 'inherit';
503
+ }
504
+ /** task-log 展示器的配置 */
505
+ interface WorkflowCommandTaskLogOptions {
506
+ /** 保留的日志行数上限 */
507
+ limit?: number;
508
+ /** 任务结束后是否保留日志内容 */
509
+ retainLog?: boolean;
510
+ }
511
+ /** 命令步骤中可用的输出工具 */
512
+ interface WorkflowCommandTaskIO {
513
+ /** 输出结构化 box */
514
+ box: (message?: string, title?: string, options?: WorkflowRendererBoxOptions) => void;
515
+ /** 暴露原始 @clack/prompts runtime,便于直接使用 taskLog、spinner 等能力 */
516
+ clack: PromptRuntime;
517
+ /** picocolors 颜色工具,可直接给 stdout / stderr / note 上色 */
518
+ colors: WorkflowColors;
519
+ /** 直接执行一条完整命令字符串;命令会通过 shell 运行,并同步当前步骤的退出码 */
520
+ exec: (command: string, options?: WorkflowCommandExecOptions) => Promise<WorkflowCommandExecutionResult>;
521
+ /** 直接执行一个脚本文件;路径相对项目根目录解析 */
522
+ execScriptFile: (scriptFile: string, options?: WorkflowCommandExecOptions) => Promise<WorkflowCommandExecutionResult>;
523
+ /** 输出一条带级别的消息 */
524
+ log: (level: WorkflowLogLevel, message: string | string[], options?: WorkflowRendererLogOptions) => void;
525
+ /** 输出结构化说明块 */
526
+ note: (message?: string, title?: string, options?: WorkflowRendererNoteOptions) => void;
527
+ /** 当前项目根目录 */
528
+ projectRoot: string;
529
+ /** 显式设置当前命令步骤的退出码 */
530
+ setExitCode: (code: number) => void;
531
+ /** 休眠指定毫秒数 */
532
+ sleep: (milliseconds: number) => Promise<void>;
533
+ /** 当前命令步骤的 task-log 配置 */
534
+ taskLog?: WorkflowCommandTaskLogOptions;
535
+ /** 写入 stderr */
536
+ stderr: (chunk: string) => void;
537
+ /** 写入 stdout */
538
+ stdout: (chunk: string) => void;
539
+ }
540
+ /** 异步命令处理函数 */
541
+ type WorkflowCommandHandler<TValues extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = (context: WorkflowRuntimeContext<TValues>, io: WorkflowCommandTaskIO) => MaybePromise<TResult | undefined> | Promise<void>;
542
+ /** 将命令执行记录映射成步骤最终结果 */
543
+ type WorkflowCommandResultResolver<TResult = unknown, TValues extends Record<string, unknown> = Record<string, unknown>, TResults extends Record<string, unknown> = Record<string, unknown>> = (execution: WorkflowCommandExecutionResult, context: WorkflowRuntimeContext<TValues, TResults>) => MaybePromise<TResult>;
544
+ /** 外部命令步骤 */
545
+ interface WorkflowExternalCommandStep<TId extends string, TResult = unknown> extends WorkflowBaseStep<TId, WorkflowCommandResult<TResult>, 'command'> {
546
+ /** 非零退出码是否允许继续工作流 */
547
+ allowFailure?: boolean;
548
+ /** 要执行的完整命令字符串;支持直接传字符串,也支持用函数动态返回 */
549
+ command: WorkflowValueResolver<string>;
550
+ /** 命令执行目录 */
551
+ cwd?: WorkflowValueResolver<string | undefined>;
552
+ /** 命令环境变量 */
553
+ env?: WorkflowValueResolver<NodeJS.ProcessEnv | undefined>;
554
+ /**
555
+ * 输出渲染方式
556
+ *
557
+ * @default 'task-log'
558
+ */
559
+ renderer?: 'inherit' | 'quiet' | 'task-log';
560
+ /** shell 解释器配置;未提供时按平台默认值执行 `command` */
561
+ shell?: WorkflowCommandShellOptions;
562
+ /** 当前命令步骤的 task-log 配置;会覆盖 renderer 上的全局默认值 */
563
+ taskLog?: WorkflowCommandTaskLogOptions;
564
+ /** 命令失败后的重试策略 */
565
+ retry?: boolean | WorkflowCommandRetryOptions;
566
+ /** 并行分组;同层连续且 group 相同的 command 步骤会并行执行 */
567
+ parallel?: string;
568
+ /** 将执行记录映射成最终写入 results 的值 */
569
+ result?: WorkflowCommandResultResolver<TResult>;
570
+ /** stdin 处理策略 */
571
+ stdin?: 'ignore' | 'inherit';
572
+ /** 展示标题 */
573
+ title?: WorkflowValueResolver<string | undefined>;
574
+ }
575
+ /** 脚本文件步骤 */
576
+ interface WorkflowScriptFileCommandStep<TId extends string, TResult = unknown> extends WorkflowBaseStep<TId, WorkflowCommandResult<TResult>, 'command'> {
577
+ /** 非零退出码是否允许继续工作流 */
578
+ allowFailure?: boolean;
579
+ /** 命令执行目录 */
580
+ cwd?: WorkflowValueResolver<string | undefined>;
581
+ /** 命令环境变量 */
582
+ env?: WorkflowValueResolver<NodeJS.ProcessEnv | undefined>;
583
+ /**
584
+ * 输出渲染方式
585
+ *
586
+ * @default 'task-log'
587
+ */
588
+ renderer?: 'inherit' | 'quiet' | 'task-log';
589
+ /** shell 解释器配置;未提供时优先根据 shebang / 扩展名自动检测 */
590
+ shell?: WorkflowCommandShellOptions;
591
+ /** 要执行的脚本文件路径;支持直接传字符串,也支持用函数动态返回 */
592
+ scriptFile: WorkflowValueResolver<string>;
593
+ /** 当前命令步骤的 task-log 配置;会覆盖 renderer 上的全局默认值 */
594
+ taskLog?: WorkflowCommandTaskLogOptions;
595
+ /** 命令失败后的重试策略 */
596
+ retry?: boolean | WorkflowCommandRetryOptions;
597
+ /** 并行分组;同层连续且 group 相同的 command 步骤会并行执行 */
598
+ parallel?: string;
599
+ /** 将执行记录映射成最终写入 results 的值 */
600
+ result?: WorkflowCommandResultResolver<TResult>;
601
+ /** stdin 处理策略 */
602
+ stdin?: 'ignore' | 'inherit';
603
+ /** 展示标题 */
604
+ title?: WorkflowValueResolver<string | undefined>;
605
+ }
606
+ /** 内联异步任务步骤 */
607
+ interface WorkflowInlineCommandStep<TId extends string, TResult = unknown> extends WorkflowBaseStep<TId, WorkflowCommandResult<TResult>, 'command'> {
608
+ /** 非零退出码是否允许继续工作流 */
609
+ allowFailure?: boolean;
610
+ /**
611
+ * 输出渲染方式
612
+ *
613
+ * @default 'task-log'
614
+ */
615
+ renderer?: 'inherit' | 'quiet' | 'task-log';
616
+ /** 当前命令步骤的 task-log 配置;会覆盖 renderer 上的全局默认值 */
617
+ taskLog?: WorkflowCommandTaskLogOptions;
618
+ /** 命令失败后的重试策略 */
619
+ retry?: boolean | WorkflowCommandRetryOptions;
620
+ /** 并行分组;同层连续且 group 相同的 command 步骤会并行执行 */
621
+ parallel?: string;
622
+ /** 内联异步任务 */
623
+ run: WorkflowCommandHandler<Record<string, unknown>, TResult>;
624
+ /** 展示标题 */
625
+ title?: WorkflowValueResolver<string | undefined>;
626
+ }
627
+ /** 命令步骤 */
628
+ type WorkflowCommandStep<TId extends string, TResult = unknown> = WorkflowExternalCommandStep<TId, TResult> | WorkflowScriptFileCommandStep<TId, TResult> | WorkflowInlineCommandStep<TId, TResult>;
629
+ /** 当前版本支持的会写入 values 的内置步骤 */
630
+ type WorkflowBuiltinValueStep = WorkflowAutocompleteMultiSelectStep<string, any> | WorkflowConfirmStep<string> | WorkflowGroupMultiSelectStep<string, any> | WorkflowMultiSelectStep<string, any> | WorkflowPasswordStep<string> | WorkflowPathStep<string> | WorkflowAutocompleteStep<string, any> | WorkflowSelectKeyStep<string, string> | WorkflowSelectStep<string, any> | WorkflowTextStep<string>;
631
+ /** 当前版本支持的展示类步骤 */
632
+ type WorkflowBuiltinDisplayStep = WorkflowBoxStep<string> | WorkflowLogStep<string> | WorkflowNoteStep<string>;
633
+ /** 当前版本支持的会写入 results 的内置步骤 */
634
+ type WorkflowBuiltinResultStep = WorkflowBuiltinValueStep | WorkflowCommandStep<string, unknown>;
635
+ /** 当前版本支持的可执行步骤 */
636
+ type WorkflowBuiltinExecutableStep = WorkflowBuiltinResultStep | WorkflowBuiltinDisplayStep;
637
+ /** 插件注册的自定义步骤 */
638
+ interface WorkflowPluginStep<TId extends string = string, TValue = unknown, TKind extends string = string> extends WorkflowBaseStep<TId, TValue, TKind> {
639
+ /** 允许插件步骤挂载任意自定义字段 */
640
+ [key: string]: unknown;
641
+ }
642
+ /** 当前版本支持的可执行步骤 */
643
+ type WorkflowExecutableStep = WorkflowBuiltinExecutableStep | WorkflowPluginStep;
644
+ /** 当前版本支持的步骤联合类型 */
645
+ type WorkflowStepDefinition = WorkflowExecutableStep;
646
+ /** 从步骤定义中提取指定步骤集合对应的对象形状 */
647
+ type StepRecordFor<TStep, TAllowed> = TStep extends TAllowed ? TStep extends WorkflowBaseStep<infer TId, infer TValue, string> ? { [TKey in TId]: TValue } : never : never;
648
+ /** 从步骤定义中提取结果对象形状 */
649
+ type StepValueRecord<TStep extends WorkflowStepDefinition> = StepRecordFor<TStep, WorkflowBuiltinValueStep | WorkflowPluginStep>;
650
+ /** 从步骤定义中提取 results 对象形状 */
651
+ type StepResultRecord<TStep extends WorkflowStepDefinition> = StepRecordFor<TStep, WorkflowBuiltinResultStep | WorkflowPluginStep>;
652
+ /** 将联合类型转换成交叉类型,便于组装步骤结果 */
653
+ type UnionToIntersection<TValue> = (TValue extends unknown ? (value: TValue) => void : never) extends ((value: infer TResult) => void) ? TResult : never;
654
+ /** 让交叉类型以对象字面量形式显示 */
655
+ type Simplify<TValue> = { [TKey in keyof TValue]: TValue[TKey] } & {};
656
+ /** 从步骤列表推导最终的 values 类型 */
657
+ type WorkflowValuesFromSteps<TSteps extends readonly WorkflowStepDefinition[]> = Simplify<UnionToIntersection<StepValueRecord<TSteps[number]>>>;
658
+ /** 从步骤列表推导最终的 results 类型 */
659
+ type WorkflowResultsFromSteps<TSteps extends readonly WorkflowStepDefinition[]> = Simplify<UnionToIntersection<StepResultRecord<TSteps[number]>>>;
660
+ /** 工作流级 ASCII banner 定义 */
661
+ type WorkflowAsciiArtDefinition<TValues extends Record<string, unknown> = Record<string, unknown>> = WorkflowValueResolver<boolean | string | undefined, TValues>;
662
+ /** 工作流快照的定义 */
663
+ interface WorkflowSnapshotOptions<TValues extends Record<string, unknown> = Record<string, unknown>> {
664
+ /** 是否启用完整工作流快照保存 */
665
+ enabled?: boolean;
666
+ /** 自定义快照标签 */
667
+ label?: (context: WorkflowRuntimeContext<TValues, Record<string, unknown>>) => MaybePromise<string>;
668
+ }
669
+ /** 默认 summary 的格式预设 */
670
+ type WorkflowSummaryPreset = 'json' | 'key-value';
671
+ /** 工作流完成后自动输出 summary 的配置 */
672
+ interface WorkflowSummaryOptions<TValues extends Record<string, unknown> = Record<string, unknown>> {
673
+ /**
674
+ * 是否启用默认 summary
675
+ *
676
+ * @default true
677
+ */
678
+ enabled?: boolean;
679
+ /** summary 格式预设 */
680
+ preset?: WorkflowValueResolver<WorkflowSummaryPreset | undefined, TValues>;
681
+ /** summary 标题 */
682
+ title?: WorkflowValueResolver<string | undefined, TValues>;
683
+ }
684
+ /** 工作流级日志策略 */
685
+ interface WorkflowLogOptions {
686
+ /** 工作流成功完成后的日志处理方式 */
687
+ completion?: false | WorkflowLogCompletionOptions;
688
+ /**
689
+ * 工作流失败时是否自动保存日志
690
+ *
691
+ * @default true
692
+ */
693
+ saveOnFailure?: boolean;
694
+ }
695
+ /** `intro` 支持的 authoring 形态 */
696
+ type WorkflowIntroDefinition<TValues extends Record<string, unknown> = Record<string, unknown>> = false | string | ((context: WorkflowRuntimeContext<TValues>) => MaybePromise<string | undefined>);
697
+ /** 工作流定义 */
698
+ interface WorkflowDefinition<TSteps extends readonly WorkflowStepDefinition[] = readonly WorkflowStepDefinition[]> {
699
+ /**
700
+ * ASCII 文字内容;传字符串时直接打印,传 `true` 时会基于标题自动生成
701
+ *
702
+ * @default true
703
+ */
704
+ asciiArt?: WorkflowAsciiArtDefinition<WorkflowValuesFromSteps<TSteps>>;
705
+ /** 工作流唯一 ID,同时也是历史和日志的命名空间 */
706
+ id: string;
707
+ /** 开场信息;可传字符串、函数或 `false` */
708
+ intro?: WorkflowIntroDefinition<WorkflowValuesFromSteps<TSteps>>;
709
+ /** 工作流完成后的自定义回调;未提供时会默认打印 `key=value` 摘要 */
710
+ onComplete?: (context: WorkflowRuntimeContext<WorkflowValuesFromSteps<TSteps>, WorkflowResultsFromSteps<TSteps>>) => MaybePromise<void>;
711
+ /** 工作流开始前执行的回调 */
712
+ onStart?: (context: WorkflowRuntimeContext<WorkflowValuesFromSteps<TSteps>, WorkflowResultsFromSteps<TSteps>>) => MaybePromise<void>;
713
+ /** 工作流级日志策略 */
714
+ log?: WorkflowLogOptions;
715
+ /** 结束语;既可以直接传字符串,也可以按运行时上下文动态生成 */
716
+ outro?: WorkflowValueResolver<string | undefined, WorkflowValuesFromSteps<TSteps>>;
717
+ /** 工作流级历史快照配置 */
718
+ snapshot?: WorkflowSnapshotOptions<WorkflowValuesFromSteps<TSteps>>;
719
+ /**
720
+ * 默认 summary 输出配置
721
+ *
722
+ * @default true
723
+ */
724
+ summary?: false | WorkflowSummaryOptions<WorkflowValuesFromSteps<TSteps>>;
725
+ /** 工作流步骤列表;支持分支嵌套 */
726
+ steps: TSteps;
727
+ /** `intro` 的简写标题;当未提供 `intro` 时会自动回退到这里 */
728
+ title?: WorkflowValueResolver<string | undefined, WorkflowValuesFromSteps<TSteps>>;
729
+ }
730
+ /** 工作流模板定义 */
731
+ interface WorkflowTemplate<TInput = void, TSteps extends readonly WorkflowStepDefinition[] = readonly WorkflowStepDefinition[]> {
732
+ /** 模板创建函数 */
733
+ create: (input: TInput) => MaybePromise<WorkflowDefinition<TSteps> | WorkflowDefinition<readonly WorkflowStepDefinition[]>>;
734
+ /** 模板说明 */
735
+ description?: string;
736
+ /** 模板唯一 ID */
737
+ id: string;
738
+ /** 模板展示名称 */
739
+ title?: string;
740
+ }
741
+ /** 工作流模板目录接口 */
742
+ interface WorkflowTemplateCatalog<TTemplates extends readonly WorkflowTemplate[] = readonly WorkflowTemplate[]> {
743
+ /** 根据 ID 判断模板是否存在 */
744
+ has: (id: TTemplates[number]['id']) => boolean;
745
+ /** 根据 ID 读取模板定义 */
746
+ get: (id: TTemplates[number]['id']) => TTemplates[number] | null;
747
+ /** 生成目录中的全部模板 */
748
+ list: () => TTemplates;
749
+ }
750
+ /** 插件步骤执行器入参 */
751
+ interface WorkflowPluginStepExecutionOptions<TStep extends WorkflowPluginStep = WorkflowPluginStep, TValues extends Record<string, unknown> = Record<string, unknown>> {
752
+ /** 当前运行上下文 */
753
+ context: WorkflowRuntimeContext<TValues>;
754
+ /** 事件记录器 */
755
+ record: (event: Omit<WorkflowRunEvent, 'runId' | 'timestamp' | 'workflowId'>) => void;
756
+ /** 当前插件步骤定义 */
757
+ step: TStep;
758
+ /** 可变 values 容器 */
759
+ values: Partial<TValues>;
760
+ }
761
+ /** 插件步骤处理函数 */
762
+ type WorkflowPluginStepHandler<TStep extends WorkflowPluginStep = WorkflowPluginStep, TValues extends Record<string, unknown> = Record<string, unknown>> = (options: WorkflowPluginStepExecutionOptions<TStep, TValues>) => MaybePromise<unknown>;
763
+ /** 暴露给插件的注册接口 */
764
+ interface WorkflowPluginAPI {
765
+ /** 注册某个自定义步骤 kind 的执行器 */
766
+ registerStepHandler: (kind: string, handler: WorkflowPluginStepHandler) => void;
767
+ }
768
+ /** 工作流插件定义 */
769
+ interface WorkflowPlugin {
770
+ /** 向 context.tools 挂载额外工具 */
771
+ extendContextTools?: (tools: WorkflowContextTools) => Record<string, unknown> | undefined;
772
+ /** 插件名称 */
773
+ name: string;
774
+ /** 注册自定义步骤处理器 */
775
+ setup?: (api: WorkflowPluginAPI) => void;
776
+ /** 包裹命令执行器 */
777
+ wrapExecutor?: (executor: WorkflowCommandExecutor) => WorkflowCommandExecutor;
778
+ /** 包裹渲染器 */
779
+ wrapRenderer?: (renderer: WorkflowRenderer) => WorkflowRenderer;
780
+ }
781
+ /** 单条工作流快照记录 */
782
+ interface WorkflowSnapshotEntry<TValues extends Record<string, unknown> = Record<string, unknown>> {
783
+ /** 快照标签 */
784
+ label: string;
785
+ /** 记录语言 */
786
+ locale: WorkflowLocale;
787
+ /** 记录时区 */
788
+ timeZone: WorkflowTimeZone;
789
+ /** 保存时间 */
790
+ timestamp: string;
791
+ /** 整个工作流输入值 */
792
+ values: Partial<TValues>;
793
+ /** 工作流 ID */
794
+ workflowId: string;
795
+ }
796
+ /** 工作流快照查询条件 */
797
+ interface WorkflowSnapshotQuery {
798
+ /** 返回条数上限 */
799
+ limit?: number;
800
+ /** 工作流 ID */
801
+ workflowId: string;
802
+ }
803
+ /** 历史存储接口 */
804
+ interface WorkflowHistoryStore {
805
+ /** 查询工作流快照 */
806
+ listSnapshots: <TValues extends Record<string, unknown>>(query: WorkflowSnapshotQuery) => Promise<WorkflowSnapshotEntry<TValues>[]>;
807
+ /** 保存工作流快照 */
808
+ saveSnapshot: <TValues extends Record<string, unknown>>(entry: WorkflowSnapshotEntry<TValues>, options?: {
809
+ maxSnapshotsPerWorkflow?: number;
810
+ }) => Promise<void>;
811
+ }
812
+ /** 单次 workflow 的 checkpoint 记录 */
813
+ interface WorkflowCheckpointEntry<TValues extends Record<string, unknown> = Record<string, unknown>> {
814
+ /** 已完成的步骤 ID */
815
+ completedStepIds: string[];
816
+ /** 记录语言 */
817
+ locale: WorkflowLocale;
818
+ /** 记录时区 */
819
+ timeZone: WorkflowTimeZone;
820
+ /** 当前运行结果 */
821
+ results: Partial<Record<string, unknown>>;
822
+ /** 最近一次中断原因 */
823
+ reason?: WorkflowCheckpointReason;
824
+ /** 运行 ID */
825
+ runId: string;
826
+ /** 更新时间 */
827
+ timestamp: string;
828
+ /** 当前工作流值 */
829
+ values: Partial<TValues>;
830
+ /** 工作流 ID */
831
+ workflowId: string;
832
+ }
833
+ /** checkpoint 存储接口 */
834
+ interface WorkflowCheckpointStore {
835
+ /** 清理某个 workflow 的 checkpoint;传入 runId 时仅清理指定运行 */
836
+ clear: (workflowId: string, runId?: string) => Promise<void>;
837
+ /** 读取最近一次 checkpoint */
838
+ getLatest: <TValues extends Record<string, unknown>>(workflowId: string) => Promise<WorkflowCheckpointEntry<TValues> | null>;
839
+ /** 保存 checkpoint */
840
+ save: <TValues extends Record<string, unknown>>(entry: WorkflowCheckpointEntry<TValues>) => Promise<void>;
841
+ }
842
+ /** 单次运行中的事件记录 */
843
+ interface WorkflowRunEvent {
844
+ /** 结构化附加数据 */
845
+ data?: Record<string, unknown>;
846
+ /** 事件级别 */
847
+ level?: WorkflowLogLevel;
848
+ /** 事件消息 */
849
+ message?: string;
850
+ /** 运行 ID */
851
+ runId: string;
852
+ /** 关联步骤 ID */
853
+ stepId?: string;
854
+ /** 发生时间 */
855
+ timestamp: string;
856
+ /** 事件类型 */
857
+ type: 'box' | 'command-output' | 'checkpoint-cleared' | 'checkpoint-loaded' | 'checkpoint-skipped' | 'checkpoint-saved' | 'message' | 'note' | 'snapshot-loaded' | 'snapshot-saved' | 'step-completed' | 'step-retried' | 'step-skipped' | 'step-started' | 'workflow-cancelled' | 'workflow-completed' | 'workflow-failed' | 'workflow-started';
858
+ /** 工作流 ID */
859
+ workflowId: string;
860
+ }
861
+ /** 日志快照格式 */
862
+ type WorkflowLogFormat = 'ecs-ndjson' | 'pretty';
863
+ /** 单个步骤的运行分析信息 */
864
+ interface WorkflowStepAnalysis {
865
+ /** 实际尝试次数,包含首次执行 */
866
+ attempts: number;
867
+ /** 步骤耗时,单位毫秒 */
868
+ durationMs: number;
869
+ /** 步骤最终状态 */
870
+ status: 'completed' | 'skipped';
871
+ }
872
+ /** 一次 workflow 运行的分析摘要 */
873
+ interface WorkflowRunAnalysis {
874
+ /** 各步骤的分析信息 */
875
+ steps: Record<string, WorkflowStepAnalysis>;
876
+ /** 总耗时,单位毫秒 */
877
+ totalDurationMs: number;
878
+ }
879
+ /** 保存到日志存储的运行快照 */
880
+ interface WorkflowRunSnapshot<TValues extends Record<string, unknown> = Record<string, unknown>> {
881
+ /** 运行分析摘要 */
882
+ analysis: WorkflowRunAnalysis;
883
+ /** 结束时间 */
884
+ endedAt?: string;
885
+ /** 事件列表 */
886
+ events: WorkflowRunEvent[];
887
+ /** 运行语言 */
888
+ locale: WorkflowLocale;
889
+ /** 自定义元数据 */
890
+ meta?: Record<string, unknown>;
891
+ /** 运行 ID */
892
+ runId: string;
893
+ /** 开始时间 */
894
+ startedAt: string;
895
+ /** 运行状态 */
896
+ status: WorkflowRunStatus;
897
+ /** 运行时区 */
898
+ timeZone: WorkflowTimeZone;
899
+ /** 最终 results */
900
+ results: Partial<Record<string, unknown>>;
901
+ /** 最终 values */
902
+ values: Partial<TValues>;
903
+ /** 工作流 ID */
904
+ workflowId: string;
905
+ }
906
+ /** 日志存储接口 */
907
+ interface WorkflowLogStore {
908
+ /** 保存运行快照 */
909
+ save: <TValues extends Record<string, unknown>>(snapshot: WorkflowRunSnapshot<TValues>, options?: {
910
+ path?: string;
911
+ }) => Promise<string>;
912
+ }
913
+ /** 工作流完成后的日志处理策略 */
914
+ interface WorkflowLogCompletionOptions {
915
+ /** 处理完成后的回调;`confirm` 模式下会带上用户选择结果 */
916
+ afterComplete?: (context: WorkflowConfirmSaveLogContext<Record<string, unknown>>) => MaybePromise<void>;
917
+ /**
918
+ * `confirm` 模式下的默认选择
919
+ *
920
+ * @default false
921
+ */
922
+ initialValue?: boolean;
923
+ /** `confirm` 模式下的提示文案 */
924
+ message?: string;
925
+ /**
926
+ * 完成后采用的处理模式
927
+ *
928
+ * @default 'confirm'
929
+ */
930
+ mode?: 'confirm' | 'save';
931
+ /** 自定义保存路径 */
932
+ path?: string;
933
+ }
934
+ /** note 渲染参数 */
935
+ interface WorkflowRendererNoteOptions {
936
+ /** 每一行的格式化函数 */
937
+ format?: NoteOptions['format'];
938
+ /** 是否显示 Clack guide */
939
+ withGuide?: CommonOptions['withGuide'];
940
+ }
941
+ /** box 渲染参数 */
942
+ interface WorkflowRendererBoxOptions {
943
+ /** 内容对齐方式 */
944
+ contentAlign?: BoxOptions['contentAlign'];
945
+ /** 内容内边距 */
946
+ contentPadding?: BoxOptions['contentPadding'];
947
+ /** 自定义边框格式化 */
948
+ formatBorder?: BoxOptions['formatBorder'];
949
+ /** 是否使用圆角 */
950
+ rounded?: BoxOptions['rounded'];
951
+ /** 标题对齐方式 */
952
+ titleAlign?: BoxOptions['titleAlign'];
953
+ /** 标题内边距 */
954
+ titlePadding?: BoxOptions['titlePadding'];
955
+ /** 是否显示 Clack guide */
956
+ withGuide?: CommonOptions['withGuide'];
957
+ /** 宽度 */
958
+ width?: BoxOptions['width'];
959
+ }
960
+ /** log 渲染参数 */
961
+ interface WorkflowRendererLogOptions {
962
+ /** 次级符号 */
963
+ secondarySymbol?: LogMessageOptions['secondarySymbol'];
964
+ /** 行间距 */
965
+ spacing?: LogMessageOptions['spacing'];
966
+ /** 主符号 */
967
+ symbol?: LogMessageOptions['symbol'];
968
+ /** 是否显示 Clack guide */
969
+ withGuide?: CommonOptions['withGuide'];
970
+ }
971
+ /** 文本输入渲染参数 */
972
+ interface WorkflowRendererTextOptions {
973
+ /** 初始值 */
974
+ initialValue?: string;
975
+ /** 提示文案 */
976
+ message: string;
977
+ /** 占位提示 */
978
+ placeholder?: string;
979
+ /** 是否显示 Clack guide */
980
+ withGuide?: CommonOptions['withGuide'];
981
+ }
982
+ /** 密码输入渲染参数 */
983
+ interface WorkflowRendererPasswordOptions {
984
+ /** 校验失败时是否清空输入 */
985
+ clearOnError?: boolean;
986
+ /** 提示文案 */
987
+ message: string;
988
+ /** 掩码字符 */
989
+ mask?: string;
990
+ /** 是否显示 Clack guide */
991
+ withGuide?: CommonOptions['withGuide'];
992
+ }
993
+ /** 路径输入渲染参数 */
994
+ interface WorkflowRendererPathOptions {
995
+ /** 是否要求选择目录 */
996
+ directory?: boolean;
997
+ /** 初始值 */
998
+ initialValue?: string;
999
+ /** 提示文案 */
1000
+ message: string;
1001
+ /** 根目录 */
1002
+ root?: string;
1003
+ /** 是否显示 Clack guide */
1004
+ withGuide?: CommonOptions['withGuide'];
1005
+ }
1006
+ /** 确认输入渲染参数 */
1007
+ interface WorkflowRendererConfirmOptions {
1008
+ /** “确认”文案 */
1009
+ active?: string;
1010
+ /** “取消”文案 */
1011
+ inactive?: string;
1012
+ /** 初始值 */
1013
+ initialValue?: boolean;
1014
+ /** 提示文案 */
1015
+ message: string;
1016
+ /** 是否垂直排列选项 */
1017
+ vertical?: boolean;
1018
+ /** 是否显示 Clack guide */
1019
+ withGuide?: CommonOptions['withGuide'];
1020
+ }
1021
+ /** 单选输入渲染参数 */
1022
+ interface WorkflowRendererSelectOptions<TValue> {
1023
+ /** 初始值 */
1024
+ initialValue?: TValue;
1025
+ /** 最多显示多少项 */
1026
+ maxItems?: number;
1027
+ /** 提示文案 */
1028
+ message: string;
1029
+ /** 选项列表 */
1030
+ options: WorkflowSelectOption<TValue>[];
1031
+ /** 是否显示 Clack guide */
1032
+ withGuide?: CommonOptions['withGuide'];
1033
+ }
1034
+ /** 自动补全输入渲染参数 */
1035
+ interface WorkflowRendererAutocompleteOptions<TValue> {
1036
+ /** 自定义筛选函数 */
1037
+ filter?: (search: string, option: WorkflowSelectOption<TValue>) => boolean;
1038
+ /** 初始值 */
1039
+ initialValue?: TValue;
1040
+ /** 首次打开时的搜索词 */
1041
+ initialUserInput?: string;
1042
+ /** 最多显示多少项 */
1043
+ maxItems?: number;
1044
+ /** 提示文案 */
1045
+ message: string;
1046
+ /** 选项列表 */
1047
+ options: WorkflowSelectOption<TValue>[];
1048
+ /** 搜索输入占位提示 */
1049
+ placeholder?: string;
1050
+ /** 是否显示 Clack guide */
1051
+ withGuide?: CommonOptions['withGuide'];
1052
+ }
1053
+ /** 自动补全多选渲染参数 */
1054
+ interface WorkflowRendererAutocompleteMultiSelectOptions<TValue> {
1055
+ /** 自定义筛选函数 */
1056
+ filter?: (search: string, option: WorkflowSelectOption<TValue>) => boolean;
1057
+ /** 初始值 */
1058
+ initialValues?: TValue[];
1059
+ /** 最多显示多少项 */
1060
+ maxItems?: number;
1061
+ /** 提示文案 */
1062
+ message: string;
1063
+ /** 选项列表 */
1064
+ options: WorkflowSelectOption<TValue>[];
1065
+ /** 搜索输入占位提示 */
1066
+ placeholder?: string;
1067
+ /** 是否至少选择一项 */
1068
+ required?: boolean;
1069
+ /** 是否显示 Clack guide */
1070
+ withGuide?: CommonOptions['withGuide'];
1071
+ }
1072
+ /** 多选输入渲染参数 */
1073
+ interface WorkflowRendererMultiSelectOptions<TValue> {
1074
+ /** 初始光标所在的选项值 */
1075
+ cursorAt?: TValue;
1076
+ /** 初始值 */
1077
+ initialValues?: TValue[];
1078
+ /** 最多显示多少项 */
1079
+ maxItems?: number;
1080
+ /** 提示文案 */
1081
+ message: string;
1082
+ /** 选项列表 */
1083
+ options: WorkflowSelectOption<TValue>[];
1084
+ /** 是否至少选择一项 */
1085
+ required?: boolean;
1086
+ /** 是否显示 Clack guide */
1087
+ withGuide?: CommonOptions['withGuide'];
1088
+ }
1089
+ /** 分组多选渲染参数 */
1090
+ interface WorkflowRendererGroupMultiSelectOptions<TValue> {
1091
+ /** 初始光标所在的选项值 */
1092
+ cursorAt?: TValue;
1093
+ /** 分组间距 */
1094
+ groupSpacing?: number;
1095
+ /** 初始值 */
1096
+ initialValues?: TValue[];
1097
+ /** 提示文案 */
1098
+ message: string;
1099
+ /** 分组选项列表 */
1100
+ options: Record<string, WorkflowSelectOption<TValue>[]>;
1101
+ /** 是否至少选择一项 */
1102
+ required?: boolean;
1103
+ /** 是否允许直接选中整组 */
1104
+ selectableGroups?: boolean;
1105
+ /** 是否显示 Clack guide */
1106
+ withGuide?: CommonOptions['withGuide'];
1107
+ }
1108
+ /** 带快捷键的单选渲染参数 */
1109
+ interface WorkflowRendererSelectKeyOptions<TValue extends string> {
1110
+ /** 是否区分大小写 */
1111
+ caseSensitive?: boolean;
1112
+ /** 初始值 */
1113
+ initialValue?: TValue;
1114
+ /** 提示文案 */
1115
+ message: string;
1116
+ /** 选项列表 */
1117
+ options: WorkflowSelectOption<TValue>[];
1118
+ /** 是否显示 Clack guide */
1119
+ withGuide?: CommonOptions['withGuide'];
1120
+ }
1121
+ /** 命令展示器接口 */
1122
+ interface WorkflowCommandPresenter {
1123
+ /** 结束展示 */
1124
+ finish: (code: number) => void;
1125
+ /** 写入 stderr */
1126
+ stderr: (chunk: string) => void;
1127
+ /** 写入 stdout */
1128
+ stdout: (chunk: string) => void;
1129
+ }
1130
+ /** 命令展示器创建参数 */
1131
+ interface WorkflowCommandPresenterOptions {
1132
+ /** 命令参数;仅外部命令步骤会提供 */
1133
+ args?: string[];
1134
+ /** 要执行的命令;仅外部命令步骤会提供 */
1135
+ command?: string;
1136
+ /** 用户声明的完整命令字符串;仅 command 字符串模式会提供 */
1137
+ commandLine?: string;
1138
+ /** 命令工作目录;仅外部命令步骤会提供 */
1139
+ cwd?: string;
1140
+ /** 脚本文件路径;仅脚本文件模式会提供 */
1141
+ scriptFile?: string;
1142
+ /** 当前命令步骤的 task-log 配置 */
1143
+ taskLog?: WorkflowCommandTaskLogOptions;
1144
+ /** 输出呈现模式:`streaming` 代表实时展示,`buffered` 代表先缓存后统一回放 */
1145
+ outputMode: 'buffered' | 'streaming';
1146
+ /** 当前命令步骤使用的渲染器类型 */
1147
+ renderer: 'inherit' | 'quiet' | 'task-log';
1148
+ /** 当前运行 ID */
1149
+ runId: string;
1150
+ /** 当前命令步骤 ID */
1151
+ stepId: string;
1152
+ /** 当前命令步骤来源:`inline` 表示 `run()`,`shell` 表示命令字符串 / 脚本文件 */
1153
+ source: 'inline' | 'shell';
1154
+ /** 展示标题 */
1155
+ title: string;
1156
+ /** 当前工作流 ID */
1157
+ workflowId: string;
1158
+ }
1159
+ /** 终端渲染器接口 */
1160
+ interface WorkflowRenderer {
1161
+ /** 渲染自动补全多选输入 */
1162
+ autocompleteMultiselect?: <TValue>(options: WorkflowRendererAutocompleteMultiSelectOptions<TValue>) => Promise<TValue[] | symbol>;
1163
+ /** 渲染结构化 box */
1164
+ box?: (message?: string, title?: string, options?: WorkflowRendererBoxOptions) => void;
1165
+ /** 在工作流最开始输出 ASCII Banner */
1166
+ banner?: (message: string) => void;
1167
+ /** 渲染取消提示 */
1168
+ cancel?: (message: string) => void;
1169
+ /** 渲染确认输入 */
1170
+ confirm: (options: WorkflowRendererConfirmOptions) => Promise<boolean | symbol>;
1171
+ /** 创建命令输出展示器 */
1172
+ createCommandPresenter?: (options: WorkflowCommandPresenterOptions) => WorkflowCommandPresenter | null;
1173
+ /** 渲染开场信息 */
1174
+ intro?: (message?: string) => void;
1175
+ /** 判断值是否是取消符号 */
1176
+ isCancel?: (value: unknown) => boolean;
1177
+ /** 当前环境是否支持交互 */
1178
+ isInteractive: () => boolean;
1179
+ /** 输出消息 */
1180
+ log: (level: WorkflowLogLevel, message: string | string[], options?: WorkflowRendererLogOptions) => void;
1181
+ /** 渲染分组多选输入 */
1182
+ groupMultiselect?: <TValue>(options: WorkflowRendererGroupMultiSelectOptions<TValue>) => Promise<TValue[] | symbol>;
1183
+ /** 渲染多选输入 */
1184
+ multiselect: <TValue>(options: WorkflowRendererMultiSelectOptions<TValue>) => Promise<TValue[] | symbol>;
1185
+ /** 渲染说明块 */
1186
+ note: (message?: string, title?: string, options?: WorkflowRendererNoteOptions) => void;
1187
+ /** 渲染结束语 */
1188
+ outro?: (message?: string) => void;
1189
+ /** 渲染密码输入 */
1190
+ password?: (options: WorkflowRendererPasswordOptions) => Promise<string | symbol>;
1191
+ /** 渲染路径输入 */
1192
+ path?: (options: WorkflowRendererPathOptions) => Promise<string | symbol>;
1193
+ /** 渲染自动补全输入 */
1194
+ autocomplete: <TValue>(options: WorkflowRendererAutocompleteOptions<TValue>) => Promise<TValue | symbol>;
1195
+ /** 渲染带快捷键的单选输入 */
1196
+ selectKey?: <TValue extends string>(options: WorkflowRendererSelectKeyOptions<TValue>) => Promise<TValue | symbol>;
1197
+ /** 渲染单选输入 */
1198
+ select: <TValue>(options: WorkflowRendererSelectOptions<TValue>) => Promise<TValue | symbol>;
1199
+ /** 渲染文本输入 */
1200
+ text: (options: WorkflowRendererTextOptions) => Promise<string | symbol>;
1201
+ }
1202
+ /** 命令执行参数 */
1203
+ interface WorkflowCommandExecutionOptions {
1204
+ /** 命令参数 */
1205
+ args?: string[];
1206
+ /** 要执行的命令 */
1207
+ command: string;
1208
+ /** 执行目录 */
1209
+ cwd?: string;
1210
+ /** 环境变量 */
1211
+ env?: NodeJS.ProcessEnv;
1212
+ /** stderr 输出回调 */
1213
+ onStderr?: (chunk: string) => void;
1214
+ /** stdout 输出回调 */
1215
+ onStdout?: (chunk: string) => void;
1216
+ /** 输出渲染方式 */
1217
+ renderer?: 'inherit' | 'quiet' | 'task-log';
1218
+ /** stdin 策略 */
1219
+ stdin?: 'ignore' | 'inherit';
1220
+ /** 展示标题 */
1221
+ title?: string;
1222
+ }
1223
+ /** 内置命令执行器类型 */
1224
+ type WorkflowCommandExecutorType = 'node' | 'tinyexec';
1225
+ /** 命令执行器接口 */
1226
+ interface WorkflowCommandExecutor {
1227
+ /** 执行命令 */
1228
+ execute: (options: WorkflowCommandExecutionOptions) => Promise<WorkflowCommandExecutionResult>;
1229
+ }
1230
+ /** 直接执行命令时的参数 */
1231
+ interface WorkflowRunCommandOptions extends WorkflowCommandExecutionOptions {
1232
+ /** 内置命令执行器类型 */
1233
+ executorType?: WorkflowCommandExecutorType;
1234
+ }
1235
+ /** 历史存储的全局配置 */
1236
+ interface WorkflowKitHistoryOptions {
1237
+ /**
1238
+ * 是否启用历史存储
1239
+ *
1240
+ * @default true
1241
+ */
1242
+ enabled?: boolean;
1243
+ /**
1244
+ * 历史文件路径
1245
+ *
1246
+ * @default '.clack-kit/history.json'
1247
+ */
1248
+ filePath?: string;
1249
+ /**
1250
+ * workflow 快照最大条数
1251
+ *
1252
+ * @default 20
1253
+ */
1254
+ maxSnapshotsPerWorkflow?: number;
1255
+ /** 自定义历史存储实现 */
1256
+ store?: WorkflowHistoryStore;
1257
+ }
1258
+ /** 日志存储的全局配置 */
1259
+ interface WorkflowKitLogOptions {
1260
+ /**
1261
+ * 日志目录
1262
+ *
1263
+ * @default '.clack-kit/logs'
1264
+ */
1265
+ directory?: string;
1266
+ /**
1267
+ * 是否启用日志
1268
+ *
1269
+ * @default true
1270
+ */
1271
+ enabled?: boolean;
1272
+ /**
1273
+ * 日志格式
1274
+ *
1275
+ * @default 'pretty'
1276
+ */
1277
+ format?: WorkflowLogFormat;
1278
+ /** 自定义日志存储实现 */
1279
+ store?: WorkflowLogStore;
1280
+ }
1281
+ /** Checkpoint 存储的全局配置 */
1282
+ interface WorkflowKitCheckpointOptions {
1283
+ /**
1284
+ * 是否启用 checkpoint
1285
+ *
1286
+ * @default true
1287
+ */
1288
+ enabled?: boolean;
1289
+ /**
1290
+ * checkpoint 文件路径
1291
+ *
1292
+ * @default '.clack-kit/checkpoints.json'
1293
+ */
1294
+ filePath?: string;
1295
+ /** 自定义 checkpoint 存储实现 */
1296
+ store?: WorkflowCheckpointStore;
1297
+ }
1298
+ /** 默认 Clack renderer 的配置 */
1299
+ interface WorkflowClackRendererOptions {
1300
+ /** 覆盖交互环境判定逻辑 */
1301
+ interactive?: () => boolean;
1302
+ /** 覆盖底层 @clack/prompts runtime */
1303
+ prompts?: Partial<PromptRuntime>;
1304
+ /** task-log 的全局默认配置 */
1305
+ taskLogOptions?: WorkflowCommandTaskLogOptions;
1306
+ }
1307
+ /** 国际化接口 */
1308
+ interface WorkflowI18n {
1309
+ /** 回退语言 */
1310
+ fallbackLocale: WorkflowLocale;
1311
+ /** 当前语言 */
1312
+ locale: WorkflowLocale;
1313
+ /** 完整 locale 资源目录 */
1314
+ locales: WorkflowLocaleCatalog;
1315
+ /** 用当前语言翻译消息 */
1316
+ t: (key: string, params?: WorkflowMessageValues) => string;
1317
+ /** 用指定语言翻译消息 */
1318
+ translate: (locale: WorkflowLocale, key: string, params?: WorkflowMessageValues) => string;
1319
+ }
1320
+ /** 创建 kit 的配置 */
1321
+ interface CreateWorkflowKitOptions {
1322
+ /**
1323
+ * 是否启用 intro 中的 ASCII 文字
1324
+ *
1325
+ * @default true
1326
+ */
1327
+ asciiArt?: boolean;
1328
+ /**
1329
+ * checkpoint 配置;`true` 表示使用默认路径启用
1330
+ *
1331
+ * @default false
1332
+ */
1333
+ checkpoints?: boolean | WorkflowKitCheckpointOptions;
1334
+ /** 自定义命令执行器 */
1335
+ executor?: WorkflowCommandExecutor;
1336
+ /**
1337
+ * 内置命令执行器类型;仅在未显式传入 `executor` 时生效
1338
+ *
1339
+ * @default 'node'
1340
+ */
1341
+ executorType?: WorkflowCommandExecutorType;
1342
+ /**
1343
+ * 历史配置;`true` 表示使用默认路径启用
1344
+ *
1345
+ * @default false
1346
+ */
1347
+ history?: boolean | WorkflowKitHistoryOptions;
1348
+ /**
1349
+ * 默认语言;不传时会尽量根据系统环境变量自动推断
1350
+ *
1351
+ * @default 自动解析
1352
+ */
1353
+ locale?: WorkflowLocale;
1354
+ /**
1355
+ * 日志配置;`true` 表示使用默认路径启用
1356
+ *
1357
+ * @default false
1358
+ */
1359
+ logs?: boolean | WorkflowKitLogOptions;
1360
+ /** 自定义 locale 资源目录 */
1361
+ locales?: WorkflowLocaleCatalog;
1362
+ /** 运行时插件 */
1363
+ plugins?: readonly WorkflowPlugin[];
1364
+ /**
1365
+ * 项目根目录;command 的相对路径会基于它解析
1366
+ *
1367
+ * @default process.cwd()
1368
+ */
1369
+ projectRoot?: string;
1370
+ /** 默认 Clack renderer 的配置;只在未显式传入 `renderer` 时生效 */
1371
+ rendererOptions?: WorkflowClackRendererOptions;
1372
+ /** 自定义渲染器 */
1373
+ renderer?: WorkflowRenderer;
1374
+ /** 动态解析语言 */
1375
+ resolveLocale?: () => WorkflowLocale;
1376
+ /** 动态解析时区 */
1377
+ resolveTimeZone?: () => WorkflowTimeZone;
1378
+ /**
1379
+ * 用户取消时是否显示取消提示
1380
+ *
1381
+ * @default true
1382
+ */
1383
+ showCancelMessage?: boolean;
1384
+ /** 固定时区 */
1385
+ timeZone?: WorkflowTimeZone;
1386
+ }
1387
+ /** 单次运行的历史选项 */
1388
+ interface WorkflowRunHistoryOptions {
1389
+ /**
1390
+ * 启动时如何处理工作流级历史快照
1391
+ *
1392
+ * @default 'ask'
1393
+ */
1394
+ reuse?: WorkflowHistoryReuseMode;
1395
+ /**
1396
+ * 本次运行完成后是否保存 workflow 快照
1397
+ *
1398
+ * @default true
1399
+ */
1400
+ saveSnapshot?: boolean;
1401
+ }
1402
+ /** 单次运行的 checkpoint 选项 */
1403
+ interface WorkflowRunCheckpointOptions {
1404
+ /**
1405
+ * 本次运行是否保存 checkpoint
1406
+ *
1407
+ * @default true
1408
+ */
1409
+ save?: boolean;
1410
+ /**
1411
+ * 启动时是否恢复未完成的 checkpoint
1412
+ *
1413
+ * @default 交互环境下为 'ask',否则为 'never'
1414
+ */
1415
+ resume?: WorkflowCheckpointResumeMode;
1416
+ }
1417
+ /** 单次运行的日志选项 */
1418
+ interface WorkflowRunLogOptions<_TValues extends Record<string, unknown> = Record<string, unknown>> {
1419
+ /**
1420
+ * 是否启用本次运行的日志保存能力
1421
+ *
1422
+ * @default true
1423
+ */
1424
+ enabled?: boolean;
1425
+ }
1426
+ /** 单次运行的配置 */
1427
+ interface WorkflowRunOptions<TValues extends Record<string, unknown> = Record<string, unknown>> {
1428
+ /** 本次运行的 checkpoint 行为 */
1429
+ checkpoint?: false | WorkflowRunCheckpointOptions;
1430
+ /** 本次运行的历史行为 */
1431
+ history?: false | WorkflowRunHistoryOptions;
1432
+ /** 用来跳过交互的预填值 */
1433
+ initialValues?: Partial<TValues>;
1434
+ /** 本次运行语言 */
1435
+ locale?: WorkflowLocale;
1436
+ /** 本次运行的日志行为 */
1437
+ logs?: false | WorkflowRunLogOptions<TValues>;
1438
+ /** 需要进入日志快照的元数据 */
1439
+ meta?: Record<string, unknown>;
1440
+ /** 本次运行时区 */
1441
+ timeZone?: WorkflowTimeZone;
1442
+ }
1443
+ /** 保存日志确认完成后的上下文 */
1444
+ interface WorkflowConfirmSaveLogContext<TValues extends Record<string, unknown> = Record<string, unknown>> {
1445
+ /** 用户是否确认保存 */
1446
+ confirmed: boolean;
1447
+ /** 最终保存路径;未保存时为 null */
1448
+ path: string | null;
1449
+ /** 当前运行的 results */
1450
+ results: Record<string, unknown>;
1451
+ /** 当前运行的 values */
1452
+ values: TValues;
1453
+ /** 工作流 ID */
1454
+ workflowId: string;
1455
+ }
1456
+ /** 手动确认保存日志时可传入的配置 */
1457
+ interface WorkflowConfirmSaveLogOptions<TValues extends Record<string, unknown> = Record<string, unknown>> {
1458
+ /** 用户完成确认后的回调 */
1459
+ afterConfirm?: (context: WorkflowConfirmSaveLogContext<TValues>) => MaybePromise<void>;
1460
+ /** confirm 组件的初始值 */
1461
+ initialValue?: boolean;
1462
+ /** confirm 组件展示的消息 */
1463
+ message?: string;
1464
+ /** 指定保存路径 */
1465
+ path?: string;
1466
+ }
1467
+ /** 单次运行的结果 */
1468
+ interface WorkflowRunResult<TValues extends Record<string, unknown> = Record<string, unknown>> {
1469
+ /** 询问是否保存日志,并允许在结束后执行钩子;禁用日志时返回 null */
1470
+ confirmSaveLog: (options?: WorkflowConfirmSaveLogOptions<TValues>) => Promise<string | null>;
1471
+ /** 与 confirmSaveLog 相同,但用户取消时不会抛错,直接返回 null */
1472
+ confirmSaveLogSafely: (options?: WorkflowConfirmSaveLogOptions<TValues>) => Promise<string | null>;
1473
+ /** 运行事件列表 */
1474
+ events: WorkflowRunEvent[];
1475
+ /** 运行语言 */
1476
+ locale: WorkflowLocale;
1477
+ /** 运行 ID */
1478
+ runId: string;
1479
+ /** 最近一次成功保存的日志路径;未保存时为 `null` */
1480
+ savedLogPath: string | null;
1481
+ /** 直接保存日志;当本次运行禁用日志时返回空字符串 */
1482
+ saveLog: (options?: {
1483
+ path?: string;
1484
+ }) => Promise<string>;
1485
+ /** 获取当前运行快照 */
1486
+ snapshot: () => WorkflowRunSnapshot<TValues>;
1487
+ /** 运行状态 */
1488
+ status: 'completed';
1489
+ /** 最终 results;读取命令步骤或中间步骤产物时优先使用这里 */
1490
+ results: Record<string, unknown>;
1491
+ /** 最终 values */
1492
+ values: TValues;
1493
+ /** 工作流 ID */
1494
+ workflowId: string;
1495
+ }
1496
+ /** 对外暴露的 kit 接口 */
1497
+ interface WorkflowKit {
1498
+ /** checkpoint 存储实例 */
1499
+ checkpointStore: WorkflowCheckpointStore | null;
1500
+ /** 命令执行器 */
1501
+ executor: WorkflowCommandExecutor;
1502
+ /** 历史存储实例 */
1503
+ historyStore: WorkflowHistoryStore | null;
1504
+ /** 日志存储实例 */
1505
+ logStore: WorkflowLogStore | null;
1506
+ /** 渲染器实例 */
1507
+ renderer: WorkflowRenderer;
1508
+ /** 运行一个工作流 */
1509
+ run: (workflow: WorkflowDefinition<readonly WorkflowStepDefinition[]>, options?: WorkflowRunOptions<Record<string, unknown>>) => Promise<WorkflowRunResult<Record<string, unknown>>>;
1510
+ /** 运行一个工作流;当用户取消时返回 null,而不是抛出 PromptCancelledError */
1511
+ runSafely: (workflow: WorkflowDefinition<readonly WorkflowStepDefinition[]>, options?: WorkflowRunOptions<Record<string, unknown>>) => Promise<WorkflowRunResult<Record<string, unknown>> | null>;
1512
+ /** 使用默认语言翻译消息 */
1513
+ t: (key: string, params?: WorkflowMessageValues) => string;
1514
+ }
1515
+ /** glob 辅助函数的配置 */
1516
+ interface WorkflowGlobOptions {
1517
+ /** 是否返回绝对路径 */
1518
+ absolute?: boolean;
1519
+ /** 搜索根目录 */
1520
+ cwd?: string;
1521
+ }
1522
+ //#endregion
1523
+ //#region src/authoring/cli.d.ts
1524
+ /** 只要求实现 `option()` 的最小 CLI 接口 */
1525
+ interface WorkflowCliOptionRegistrar {
1526
+ /** 注册一条 CLI option */
1527
+ option: (definition: string, description: string, config?: WorkflowCliOptionConfig) => WorkflowCliOptionRegistrar;
1528
+ }
1529
+ /** 常见 CLI `option()` 第三个参数的最小兼容类型 */
1530
+ interface WorkflowCliOptionConfig {
1531
+ /** 与常见 CLI 库一致的默认值配置 */
1532
+ default?: unknown;
1533
+ /** 与常见 CLI 库一致的类型转换配置 */
1534
+ type?: unknown[];
1535
+ /** 透传给具体 CLI 实现的其他字段 */
1536
+ [key: string]: unknown;
1537
+ }
1538
+ /** 单个字段的 CLI 桥接配置 */
1539
+ interface WorkflowCliFieldOptions<TValue = unknown> {
1540
+ /** 覆盖自动生成的说明文案 */
1541
+ description?: string;
1542
+ /** 自定义完整 option 定义,例如 `--plain-progress [plainProgress]` */
1543
+ option?: string;
1544
+ /** 透传给 `cli.option()` 的第三个参数 */
1545
+ optionConfig?: WorkflowCliOptionConfig;
1546
+ /** 当 option 名与 step id 不一致时,指定解析后的 options key */
1547
+ optionKey?: string;
1548
+ /** 自定义值解析函数 */
1549
+ parse?: (value: unknown) => TValue | undefined;
1550
+ }
1551
+ /** workflow / steps 接入 CLI 时的桥接配置 */
1552
+ interface WorkflowCliBridgeOptions {
1553
+ /** 按 step id 定义单字段覆盖规则 */
1554
+ fields?: Record<string, WorkflowCliFieldOptions>;
1555
+ }
1556
+ /** workflow / steps 映射到 CLI 后的结果 */
1557
+ interface WorkflowCliBridge {
1558
+ /** 把步骤映射成 CLI options */
1559
+ apply: <TRegistrar extends WorkflowCliOptionRegistrar>(cli: TRegistrar) => TRegistrar;
1560
+ /** 从解析后的 CLI options 提取 workflow initialValues */
1561
+ getInitialValues: (options: Record<string, unknown>) => Partial<Record<string, unknown>>;
1562
+ }
1563
+ /** 解析 CLI 里的布尔值 */
1564
+ declare function parseWorkflowCliBoolean(value: unknown): boolean | undefined;
1565
+ /** 解析 CLI 列表值,默认按逗号分隔 */
1566
+ declare function parseWorkflowCliList(value: unknown): string[] | undefined;
1567
+ type WorkflowCliBridgeSource = readonly WorkflowStepDefinition[] | {
1568
+ steps: readonly WorkflowStepDefinition[];
1569
+ };
1570
+ /** 创建 workflow / steps 到 CLI 的 bridge */
1571
+ declare function createWorkflowCliBridge(source: WorkflowCliBridgeSource, options?: WorkflowCliBridgeOptions): WorkflowCliBridge;
1572
+ //#endregion
1573
+ //#region src/authoring/templates.d.ts
1574
+ /** 显式声明一个工作流模板,便于复用和类型推导 */
1575
+ declare function defineWorkflowTemplate<const TTemplate extends WorkflowTemplate>(template: TTemplate): TTemplate;
1576
+ /** 创建一个按模板 ID 检索的目录 */
1577
+ declare function createWorkflowTemplateCatalog<const TTemplates extends readonly WorkflowTemplate[]>(templates: TTemplates): WorkflowTemplateCatalog<TTemplates>;
1578
+ //#endregion
1579
+ //#region src/authoring/workflow-types.d.ts
1580
+ /** 供 authoring DSL 复用的基础步骤字段 */
1581
+ interface WorkflowStepConfigBase<TKey extends string, TValue> {
1582
+ /** 步骤在 values 中对应的 key */
1583
+ id: TKey;
1584
+ /** 为交互输入提供默认值;不同于运行参数里的 `initialValues` */
1585
+ defaultValue?: WorkflowValueResolver<TValue | undefined>;
1586
+ /** 控制步骤是否执行 */
1587
+ when?: WorkflowPredicate<Record<string, unknown>>;
1588
+ }
1589
+ /** 选择类步骤在 authoring 层共享的选项结构 */
1590
+ type WorkflowChoiceOptions<TValue> = WorkflowValueResolver<readonly TValue[]> | WorkflowValueResolver<readonly WorkflowSelectOption<TValue>[]>;
1591
+ /** 分组多选在 authoring 层共享的分组选项结构 */
1592
+ type WorkflowGroupedChoiceOptions<TValue> = WorkflowValueResolver<Record<string, readonly TValue[] | readonly WorkflowSelectOption<TValue>[]>>;
1593
+ /** `defineSteps()` 支持的文本步骤 DSL */
1594
+ interface WorkflowTextStepConfig<TKey extends string> extends WorkflowStepConfigBase<TKey, string> {
1595
+ /** 提示文案 */
1596
+ message: WorkflowValueResolver<string>;
1597
+ /** 占位提示 */
1598
+ placeholder?: WorkflowValueResolver<string | undefined>;
1599
+ /** 是否必填;当为 `true` 时默认文案为 `<Key> is required` */
1600
+ required?: boolean | string;
1601
+ /** 声明式步骤类型 */
1602
+ type: 'text';
1603
+ /** 自定义校验函数 */
1604
+ validate?: WorkflowValidator<string>;
1605
+ }
1606
+ /** `defineSteps()` 支持的单选步骤 DSL */
1607
+ interface WorkflowSelectStepConfig<TKey extends string, TValue> extends WorkflowStepConfigBase<TKey, TValue> {
1608
+ /** 提示文案 */
1609
+ message: WorkflowValueResolver<string>;
1610
+ /** 可选项列表 */
1611
+ options: WorkflowChoiceOptions<TValue>;
1612
+ /** 声明式步骤类型 */
1613
+ type: 'select';
1614
+ /** 自定义校验函数 */
1615
+ validate?: WorkflowValidator<TValue>;
1616
+ }
1617
+ /** `defineSteps()` 支持的自动补全步骤 DSL */
1618
+ interface WorkflowAutocompleteStepConfig<TKey extends string, TValue> extends WorkflowStepConfigBase<TKey, TValue> {
1619
+ /** 自定义筛选函数 */
1620
+ filter?: (search: string, option: WorkflowSelectOption<TValue>) => boolean;
1621
+ /** 首次打开时的搜索词 */
1622
+ initialUserInput?: WorkflowValueResolver<string | undefined>;
1623
+ /** 提示文案 */
1624
+ message: WorkflowValueResolver<string>;
1625
+ /** 最多显示多少项 */
1626
+ maxItems?: WorkflowValueResolver<number | undefined>;
1627
+ /** 可搜索选项列表 */
1628
+ options: WorkflowChoiceOptions<TValue>;
1629
+ /** 搜索输入占位提示 */
1630
+ placeholder?: WorkflowValueResolver<string | undefined>;
1631
+ /** 声明式步骤类型 */
1632
+ type: 'autocomplete';
1633
+ /** 自定义校验函数 */
1634
+ validate?: WorkflowValidator<TValue>;
1635
+ /** 是否显示 Clack guide */
1636
+ withGuide?: WorkflowValueResolver<boolean | undefined>;
1637
+ }
1638
+ /** `defineSteps()` 支持的多选步骤 DSL */
1639
+ interface WorkflowMultiSelectStepConfig<TKey extends string, TValue> extends WorkflowStepConfigBase<TKey, TValue[]> {
1640
+ /** 初始光标所在的选项值 */
1641
+ cursorAt?: WorkflowValueResolver<TValue | undefined>;
1642
+ /** 最多显示多少项 */
1643
+ maxItems?: WorkflowValueResolver<number | undefined>;
1644
+ /** 提示文案 */
1645
+ message: WorkflowValueResolver<string>;
1646
+ /** 可选项列表 */
1647
+ options: WorkflowChoiceOptions<TValue>;
1648
+ /** 是否至少要选中一项;为 `true` 时默认文案为 `<Key> is required` */
1649
+ required?: boolean | string;
1650
+ /** 声明式步骤类型 */
1651
+ type: 'multiselect';
1652
+ /** 自定义校验函数 */
1653
+ validate?: WorkflowValidator<TValue[]>;
1654
+ /** 是否显示 Clack guide */
1655
+ withGuide?: WorkflowValueResolver<boolean | undefined>;
1656
+ }
1657
+ /** `defineSteps()` 支持的自动补全多选步骤 DSL */
1658
+ interface WorkflowAutocompleteMultiSelectStepConfig<TKey extends string, TValue> extends WorkflowStepConfigBase<TKey, TValue[]> {
1659
+ /** 自定义筛选函数 */
1660
+ filter?: (search: string, option: WorkflowSelectOption<TValue>) => boolean;
1661
+ /** 最多显示多少项 */
1662
+ maxItems?: WorkflowValueResolver<number | undefined>;
1663
+ /** 提示文案 */
1664
+ message: WorkflowValueResolver<string>;
1665
+ /** 可搜索选项列表 */
1666
+ options: WorkflowChoiceOptions<TValue>;
1667
+ /** 搜索输入占位提示 */
1668
+ placeholder?: WorkflowValueResolver<string | undefined>;
1669
+ /** 是否至少要选中一项;为 `true` 时默认文案为 `<Key> is required` */
1670
+ required?: boolean | string;
1671
+ /** 声明式步骤类型 */
1672
+ type: 'autocompleteMultiselect';
1673
+ /** 自定义校验函数 */
1674
+ validate?: WorkflowValidator<TValue[]>;
1675
+ /** 是否显示 Clack guide */
1676
+ withGuide?: WorkflowValueResolver<boolean | undefined>;
1677
+ }
1678
+ /** `defineSteps()` 支持的分组多选步骤 DSL */
1679
+ interface WorkflowGroupMultiSelectStepConfig<TKey extends string, TValue> extends WorkflowStepConfigBase<TKey, TValue[]> {
1680
+ /** 初始光标所在的选项值 */
1681
+ cursorAt?: WorkflowValueResolver<TValue | undefined>;
1682
+ /** 分组间距 */
1683
+ groupSpacing?: WorkflowValueResolver<number | undefined>;
1684
+ /** 提示文案 */
1685
+ message: WorkflowValueResolver<string>;
1686
+ /** 分组选项列表 */
1687
+ options: WorkflowGroupedChoiceOptions<TValue>;
1688
+ /** 是否至少要选中一项;为 `true` 时默认文案为 `<Key> is required` */
1689
+ required?: boolean | string;
1690
+ /** 是否允许直接选中整组 */
1691
+ selectableGroups?: WorkflowValueResolver<boolean | undefined>;
1692
+ /** 声明式步骤类型 */
1693
+ type: 'groupMultiselect';
1694
+ /** 自定义校验函数 */
1695
+ validate?: WorkflowValidator<TValue[]>;
1696
+ /** 是否显示 Clack guide */
1697
+ withGuide?: WorkflowValueResolver<boolean | undefined>;
1698
+ }
1699
+ /** `defineSteps()` 支持的确认步骤 DSL */
1700
+ interface WorkflowConfirmStepConfig<TKey extends string> extends WorkflowStepConfigBase<TKey, boolean> {
1701
+ /** “确认”文案 */
1702
+ active?: WorkflowValueResolver<string | undefined>;
1703
+ /** “取消”文案 */
1704
+ inactive?: WorkflowValueResolver<string | undefined>;
1705
+ /** 提示文案 */
1706
+ message: WorkflowValueResolver<string>;
1707
+ /** 声明式步骤类型 */
1708
+ type: 'confirm';
1709
+ /** 自定义校验函数 */
1710
+ validate?: WorkflowValidator<boolean>;
1711
+ /** 是否垂直排列选项 */
1712
+ vertical?: WorkflowValueResolver<boolean | undefined>;
1713
+ /** 是否显示 Clack guide */
1714
+ withGuide?: WorkflowValueResolver<boolean | undefined>;
1715
+ }
1716
+ /** `defineSteps()` 支持的密码步骤 DSL */
1717
+ interface WorkflowPasswordStepConfig<TKey extends string> extends WorkflowStepConfigBase<TKey, string> {
1718
+ /** 校验失败时是否清空输入 */
1719
+ clearOnError?: WorkflowValueResolver<boolean | undefined>;
1720
+ /** 掩码字符 */
1721
+ mask?: WorkflowValueResolver<string | undefined>;
1722
+ /** 提示文案 */
1723
+ message: WorkflowValueResolver<string>;
1724
+ /** 是否必填;当为 `true` 时默认文案为 `<Key> is required` */
1725
+ required?: boolean | string;
1726
+ /** 声明式步骤类型 */
1727
+ type: 'password';
1728
+ /** 自定义校验函数 */
1729
+ validate?: WorkflowValidator<string>;
1730
+ /** 是否显示 Clack guide */
1731
+ withGuide?: WorkflowValueResolver<boolean | undefined>;
1732
+ }
1733
+ /** `defineSteps()` 支持的路径步骤 DSL */
1734
+ interface WorkflowPathStepConfig<TKey extends string> extends WorkflowStepConfigBase<TKey, string> {
1735
+ /** 是否要求选择目录 */
1736
+ directory?: WorkflowValueResolver<boolean | undefined>;
1737
+ /** 提示文案 */
1738
+ message: WorkflowValueResolver<string>;
1739
+ /** 是否必填;当为 `true` 时默认文案为 `<Key> is required` */
1740
+ required?: boolean | string;
1741
+ /** 根目录 */
1742
+ root?: WorkflowValueResolver<string | undefined>;
1743
+ /** 声明式步骤类型 */
1744
+ type: 'path';
1745
+ /** 自定义校验函数 */
1746
+ validate?: WorkflowValidator<string>;
1747
+ /** 是否显示 Clack guide */
1748
+ withGuide?: WorkflowValueResolver<boolean | undefined>;
1749
+ }
1750
+ /** `defineSteps()` 支持的快捷键单选步骤 DSL */
1751
+ interface WorkflowSelectKeyStepConfig<TKey extends string, TValue extends string> extends WorkflowStepConfigBase<TKey, TValue> {
1752
+ /** 是否区分大小写 */
1753
+ caseSensitive?: WorkflowValueResolver<boolean | undefined>;
1754
+ /** 提示文案 */
1755
+ message: WorkflowValueResolver<string>;
1756
+ /** 可选项列表 */
1757
+ options: WorkflowChoiceOptions<TValue>;
1758
+ /** 声明式步骤类型 */
1759
+ type: 'selectKey';
1760
+ /** 自定义校验函数 */
1761
+ validate?: WorkflowValidator<TValue>;
1762
+ /** 是否显示 Clack guide */
1763
+ withGuide?: WorkflowValueResolver<boolean | undefined>;
1764
+ }
1765
+ /** `defineSteps()` 支持的外部命令步骤 DSL */
1766
+ interface WorkflowExternalCommandStepConfig<TKey extends string, TResult = unknown> extends WorkflowStepConfigBase<TKey, WorkflowCommandResult<TResult>> {
1767
+ /** 非零退出码是否允许继续工作流 */
1768
+ allowFailure?: boolean;
1769
+ /** 要执行的完整命令字符串;支持直接传字符串,也支持用函数动态返回 */
1770
+ command: WorkflowValueResolver<string>;
1771
+ /** 命令执行目录 */
1772
+ cwd?: WorkflowValueResolver<string | undefined>;
1773
+ /** 命令环境变量 */
1774
+ env?: WorkflowValueResolver<NodeJS.ProcessEnv | undefined>;
1775
+ /** 并行分组;同层连续且 group 相同的 command 步骤会并行执行 */
1776
+ parallel?: string;
1777
+ /** 将执行记录映射成最终写入 results 的值 */
1778
+ result?: WorkflowCommandResultResolver<TResult>;
1779
+ /** 输出渲染方式 */
1780
+ renderer?: 'inherit' | 'quiet' | 'task-log';
1781
+ /** shell 解释器配置;未提供时按平台默认值执行 `command` */
1782
+ shell?: {
1783
+ args?: WorkflowValueResolver<string[] | undefined>;
1784
+ command?: WorkflowValueResolver<string | undefined>;
1785
+ };
1786
+ /** 当前命令步骤的 task-log 配置 */
1787
+ taskLog?: {
1788
+ limit?: number;
1789
+ retainLog?: boolean;
1790
+ };
1791
+ /** 命令失败后的重试策略 */
1792
+ retry?: boolean | WorkflowCommandRetryOptions;
1793
+ /** stdin 处理策略 */
1794
+ stdin?: 'ignore' | 'inherit';
1795
+ /** 展示标题 */
1796
+ title?: WorkflowValueResolver<string | undefined>;
1797
+ /** 声明式步骤类型 */
1798
+ type: 'command';
1799
+ }
1800
+ /** `defineSteps()` 支持的 note 步骤 DSL */
1801
+ interface WorkflowNoteStepConfig<TKey extends string> extends WorkflowStepConfigBase<TKey, undefined> {
1802
+ /** 每一行的格式化函数 */
1803
+ format?: (line: string) => string;
1804
+ /** 提示内容 */
1805
+ message?: WorkflowValueResolver<string | undefined>;
1806
+ /** 标题 */
1807
+ title?: WorkflowValueResolver<string | undefined>;
1808
+ /** 声明式步骤类型 */
1809
+ type: 'note';
1810
+ /** 是否显示 Clack guide */
1811
+ withGuide?: WorkflowValueResolver<boolean | undefined>;
1812
+ }
1813
+ /** `defineSteps()` 支持的 box 步骤 DSL */
1814
+ interface WorkflowBoxStepConfig<TKey extends string> extends WorkflowStepConfigBase<TKey, undefined> {
1815
+ /** 内容对齐方式 */
1816
+ contentAlign?: WorkflowValueResolver<'left' | 'center' | 'right' | undefined>;
1817
+ /** 内容内边距 */
1818
+ contentPadding?: WorkflowValueResolver<number | undefined>;
1819
+ /** 自定义边框格式化 */
1820
+ formatBorder?: (text: string) => string;
1821
+ /** 提示内容 */
1822
+ message?: WorkflowValueResolver<string | undefined>;
1823
+ /** 是否使用圆角 */
1824
+ rounded?: WorkflowValueResolver<boolean | undefined>;
1825
+ /** 标题对齐方式 */
1826
+ titleAlign?: WorkflowValueResolver<'left' | 'center' | 'right' | undefined>;
1827
+ /** 标题内边距 */
1828
+ titlePadding?: WorkflowValueResolver<number | undefined>;
1829
+ /** 标题 */
1830
+ title?: WorkflowValueResolver<string | undefined>;
1831
+ /** 声明式步骤类型 */
1832
+ type: 'box';
1833
+ /** 是否显示 Clack guide */
1834
+ withGuide?: WorkflowValueResolver<boolean | undefined>;
1835
+ /** 宽度 */
1836
+ width?: WorkflowValueResolver<number | 'auto' | undefined>;
1837
+ }
1838
+ /** `defineSteps()` 支持的 log 步骤 DSL */
1839
+ interface WorkflowLogStepConfig<TKey extends string> extends WorkflowStepConfigBase<TKey, undefined> {
1840
+ /** 日志级别 */
1841
+ level?: WorkflowValueResolver<WorkflowLogLevel | undefined>;
1842
+ /** 提示内容 */
1843
+ message?: WorkflowValueResolver<string | string[] | undefined>;
1844
+ /** 次级符号 */
1845
+ secondarySymbol?: WorkflowValueResolver<string | undefined>;
1846
+ /** 行间距 */
1847
+ spacing?: WorkflowValueResolver<number | undefined>;
1848
+ /** 主符号 */
1849
+ symbol?: WorkflowValueResolver<string | undefined>;
1850
+ /** 声明式步骤类型 */
1851
+ type: 'log';
1852
+ /** 是否显示 Clack guide */
1853
+ withGuide?: WorkflowValueResolver<boolean | undefined>;
1854
+ }
1855
+ /** `defineSteps()` 支持的内联命令步骤 DSL */
1856
+ interface WorkflowInlineCommandStepConfig<TKey extends string, TResult = unknown> extends WorkflowStepConfigBase<TKey, WorkflowCommandResult<TResult>> {
1857
+ /** 非零退出码是否允许继续工作流 */
1858
+ allowFailure?: boolean;
1859
+ /** 并行分组;同层连续且 group 相同的 command 步骤会并行执行 */
1860
+ parallel?: string;
1861
+ /** 输出渲染方式 */
1862
+ renderer?: 'inherit' | 'quiet' | 'task-log';
1863
+ /** 当前命令步骤的 task-log 配置 */
1864
+ taskLog?: {
1865
+ limit?: number;
1866
+ retainLog?: boolean;
1867
+ };
1868
+ /** 命令失败后的重试策略 */
1869
+ retry?: boolean | WorkflowCommandRetryOptions;
1870
+ /** 内联异步任务 */
1871
+ run: WorkflowCommandHandler<Record<string, unknown>, TResult>;
1872
+ /** 展示标题 */
1873
+ title?: WorkflowValueResolver<string | undefined>;
1874
+ /** 声明式步骤类型 */
1875
+ type: 'command';
1876
+ }
1877
+ /** `defineSteps()` 支持的脚本文件步骤 DSL */
1878
+ interface WorkflowScriptFileCommandStepConfig<TKey extends string, TResult = unknown> extends WorkflowStepConfigBase<TKey, WorkflowCommandResult<TResult>> {
1879
+ /** 非零退出码是否允许继续工作流 */
1880
+ allowFailure?: boolean;
1881
+ /** 命令执行目录 */
1882
+ cwd?: WorkflowValueResolver<string | undefined>;
1883
+ /** 命令环境变量 */
1884
+ env?: WorkflowValueResolver<NodeJS.ProcessEnv | undefined>;
1885
+ /** 并行分组;同层连续且 group 相同的 command 步骤会并行执行 */
1886
+ parallel?: string;
1887
+ /** 将执行记录映射成最终写入 results 的值 */
1888
+ result?: WorkflowCommandResultResolver<TResult>;
1889
+ /** 输出渲染方式 */
1890
+ renderer?: 'inherit' | 'quiet' | 'task-log';
1891
+ /** shell 解释器配置;未提供时优先根据 shebang / 扩展名自动检测 */
1892
+ shell?: {
1893
+ args?: WorkflowValueResolver<string[] | undefined>;
1894
+ command?: WorkflowValueResolver<string | undefined>;
1895
+ };
1896
+ /** 要执行的脚本文件路径;支持直接传字符串,也支持用函数动态返回 */
1897
+ scriptFile: WorkflowValueResolver<string>;
1898
+ /** 当前命令步骤的 task-log 配置 */
1899
+ taskLog?: {
1900
+ limit?: number;
1901
+ retainLog?: boolean;
1902
+ };
1903
+ /** 命令失败后的重试策略 */
1904
+ retry?: boolean | WorkflowCommandRetryOptions;
1905
+ /** stdin 处理策略 */
1906
+ stdin?: 'ignore' | 'inherit';
1907
+ /** 展示标题 */
1908
+ title?: WorkflowValueResolver<string | undefined>;
1909
+ /** 声明式步骤类型 */
1910
+ type: 'command';
1911
+ }
1912
+ /** `defineSteps()` 支持的命令步骤 DSL */
1913
+ type WorkflowCommandStepConfig<TKey extends string, TResult = unknown> = WorkflowExternalCommandStepConfig<TKey, TResult> | WorkflowScriptFileCommandStepConfig<TKey, TResult> | WorkflowInlineCommandStepConfig<TKey, TResult>;
1914
+ /** typed helper 入参会由方法名隐式确定 `type`,因此无需重复书写 */
1915
+ type WorkflowStepConfigInput<TStep> = TStep extends {
1916
+ type: string;
1917
+ } ? Omit<TStep, 'type'> : TStep;
1918
+ /** `defineSteps()` 支持的步骤类型字符串 */
1919
+ type WorkflowStepType = 'autocompleteMultiselect' | 'autocomplete' | 'box' | 'command' | 'confirm' | 'groupMultiselect' | 'log' | 'multiselect' | 'note' | 'password' | 'path' | 'select' | 'selectKey' | 'text';
1920
+ /** 按 `type` 精确提取某一类声明式步骤配置 */
1921
+ type WorkflowStepConfigByType<TType extends WorkflowStepType> = TType extends 'text' ? WorkflowTextStepConfig<string> : TType extends 'select' ? WorkflowSelectStepConfig<string, any> : TType extends 'autocomplete' ? WorkflowAutocompleteStepConfig<string, any> : TType extends 'multiselect' ? WorkflowMultiSelectStepConfig<string, any> : TType extends 'autocompleteMultiselect' ? WorkflowAutocompleteMultiSelectStepConfig<string, any> : TType extends 'groupMultiselect' ? WorkflowGroupMultiSelectStepConfig<string, any> : TType extends 'confirm' ? WorkflowConfirmStepConfig<string> : TType extends 'note' ? WorkflowNoteStepConfig<string> : TType extends 'box' ? WorkflowBoxStepConfig<string> : TType extends 'log' ? WorkflowLogStepConfig<string> : TType extends 'password' ? WorkflowPasswordStepConfig<string> : TType extends 'path' ? WorkflowPathStepConfig<string> : TType extends 'selectKey' ? WorkflowSelectKeyStepConfig<string, string> : TType extends 'command' ? WorkflowCommandStepConfig<string, unknown> : never;
1922
+ /** `defineSteps()` 支持的声明式步骤联合类型 */
1923
+ type WorkflowStepConfigDefinition = WorkflowStepConfigByType<WorkflowStepType>;
1924
+ /** `defineSteps()` 同时接受标准化步骤和声明式 DSL */
1925
+ type WorkflowStepAuthoringDefinition = WorkflowStepConfigDefinition | WorkflowStepDefinition;
1926
+ /** `defineWorkflow()` 使用的轻量 authoring 结构 */
1927
+ interface WorkflowAuthoringDefinition<TSteps extends readonly WorkflowStepDefinition[] = readonly WorkflowStepDefinition[]> {
1928
+ /** ASCII 文字内容 */
1929
+ asciiArt?: WorkflowAsciiArtDefinition<Record<string, unknown>>;
1930
+ /** 工作流唯一 ID */
1931
+ id: string;
1932
+ /** 开场信息 */
1933
+ intro?: WorkflowIntroDefinition<Record<string, unknown>>;
1934
+ /** 工作流完成回调 */
1935
+ onComplete?: (context: WorkflowRuntimeContext<Record<string, unknown>, Record<string, unknown>>) => MaybePromise<void>;
1936
+ /** 工作流开始回调 */
1937
+ onStart?: (context: WorkflowRuntimeContext<Record<string, unknown>, Record<string, unknown>>) => MaybePromise<void>;
1938
+ /** 工作流级日志策略 */
1939
+ log?: WorkflowLogOptions;
1940
+ /** 结束语 */
1941
+ outro?: WorkflowValueResolver<string | undefined, Record<string, unknown>>;
1942
+ /** 历史快照配置 */
1943
+ snapshot?: WorkflowSnapshotOptions<Record<string, unknown>>;
1944
+ /** 默认 summary 输出配置 */
1945
+ summary?: false | WorkflowSummaryOptions<Record<string, unknown>>;
1946
+ /** 工作流步骤列表 */
1947
+ steps: TSteps;
1948
+ /** `intro` 的简写标题 */
1949
+ title?: WorkflowValueResolver<string | undefined, Record<string, unknown>>;
1950
+ }
1951
+ //#endregion
1952
+ //#region src/authoring/step-builders.d.ts
1953
+ /** 创建文本输入步骤 */
1954
+ declare function createTextStep<TKey extends string>(key: TKey, step: Omit<WorkflowTextStep<TKey>, 'id' | 'kind'>): WorkflowTextStep<TKey>;
1955
+ /** 创建单选步骤 */
1956
+ declare function createSelectStep<TKey extends string, TValue>(key: TKey, step: Omit<WorkflowSelectStep<TKey, TValue>, 'id' | 'kind'>): WorkflowSelectStep<TKey, TValue>;
1957
+ /** 创建自动补全步骤 */
1958
+ declare function createAutocompleteStep<TKey extends string, TValue>(key: TKey, step: Omit<WorkflowAutocompleteStep<TKey, TValue>, 'id' | 'kind'>): WorkflowAutocompleteStep<TKey, TValue>;
1959
+ /** 创建多选步骤 */
1960
+ declare function createMultiSelectStep<TKey extends string, TValue>(key: TKey, step: Omit<WorkflowMultiSelectStep<TKey, TValue>, 'id' | 'kind'>): WorkflowMultiSelectStep<TKey, TValue>;
1961
+ /** 创建自动补全多选步骤 */
1962
+ declare function createAutocompleteMultiSelectStep<TKey extends string, TValue>(key: TKey, step: Omit<WorkflowAutocompleteMultiSelectStep<TKey, TValue>, 'id' | 'kind'>): WorkflowAutocompleteMultiSelectStep<TKey, TValue>;
1963
+ /** 创建分组多选步骤 */
1964
+ declare function createGroupMultiSelectStep<TKey extends string, TValue>(key: TKey, step: Omit<WorkflowGroupMultiSelectStep<TKey, TValue>, 'id' | 'kind'>): WorkflowGroupMultiSelectStep<TKey, TValue>;
1965
+ /** 创建确认步骤 */
1966
+ declare function createConfirmStep<TKey extends string>(key: TKey, step: Omit<WorkflowConfirmStep<TKey>, 'id' | 'kind'>): WorkflowConfirmStep<TKey>;
1967
+ /** 创建 note 步骤 */
1968
+ declare function createNoteStep<TKey extends string>(key: TKey, step: Omit<WorkflowNoteStep<TKey>, 'id' | 'kind'>): WorkflowNoteStep<TKey>;
1969
+ /** 创建 box 步骤 */
1970
+ declare function createBoxStep<TKey extends string>(key: TKey, step: Omit<WorkflowBoxStep<TKey>, 'id' | 'kind'>): WorkflowBoxStep<TKey>;
1971
+ /** 创建 log 步骤 */
1972
+ declare function createLogStep<TKey extends string>(key: TKey, step: Omit<WorkflowLogStep<TKey>, 'id' | 'kind'>): WorkflowLogStep<TKey>;
1973
+ /** 创建密码输入步骤 */
1974
+ declare function createPasswordStep<TKey extends string>(key: TKey, step: Omit<WorkflowPasswordStep<TKey>, 'id' | 'kind'>): WorkflowPasswordStep<TKey>;
1975
+ /** 创建路径输入步骤 */
1976
+ declare function createPathStep<TKey extends string>(key: TKey, step: Omit<WorkflowPathStep<TKey>, 'id' | 'kind'>): WorkflowPathStep<TKey>;
1977
+ /** 创建带快捷键的单选步骤 */
1978
+ declare function createSelectKeyStep<TKey extends string, TValue extends string>(key: TKey, step: Omit<WorkflowSelectKeyStep<TKey, TValue>, 'id' | 'kind'>): WorkflowSelectKeyStep<TKey, TValue>;
1979
+ /** 创建命令步骤 */
1980
+ declare function createCommandStep<TKey extends string, TResult = unknown>(key: TKey, step: Omit<WorkflowExternalCommandStep<TKey, TResult>, 'id' | 'kind'> | Omit<WorkflowScriptFileCommandStep<TKey, TResult>, 'id' | 'kind'> | Omit<WorkflowInlineCommandStep<TKey, TResult>, 'id' | 'kind'>): WorkflowCommandStep<TKey, TResult>;
1981
+ /** `defineStep` 的可调用接口,同时暴露按类型分发的方法 */
1982
+ interface DefineStep {
1983
+ /** 显式定义单个 DSL 步骤 */
1984
+ <const TStep extends WorkflowStepConfigDefinition>(step: TStep): WorkflowStepDefinition;
1985
+ /** 透传已经标准化过的步骤 */
1986
+ <const TStep extends WorkflowStepDefinition>(step: TStep): WorkflowStepDefinition;
1987
+ /** 定义自动补全步骤 */
1988
+ autocomplete: <TKey extends string, TValue>(step: WorkflowStepConfigInput<WorkflowAutocompleteStepConfig<TKey, TValue>>) => WorkflowAutocompleteStep<TKey, TValue>;
1989
+ /** 定义自动补全多选步骤 */
1990
+ autocompleteMultiselect: <TKey extends string, TValue>(step: WorkflowStepConfigInput<WorkflowAutocompleteMultiSelectStepConfig<TKey, TValue>>) => WorkflowAutocompleteMultiSelectStep<TKey, TValue>;
1991
+ /** 定义 box 步骤 */
1992
+ box: <TKey extends string>(step: WorkflowStepConfigInput<WorkflowBoxStepConfig<TKey>>) => WorkflowBoxStep<TKey>;
1993
+ /** 定义命令步骤 */
1994
+ command: <TKey extends string, TResult = unknown>(step: WorkflowStepConfigInput<WorkflowCommandStepConfig<TKey, TResult>>) => WorkflowCommandStep<TKey, TResult>;
1995
+ /** 定义确认步骤 */
1996
+ confirm: <TKey extends string>(step: WorkflowStepConfigInput<WorkflowConfirmStepConfig<TKey>>) => WorkflowConfirmStep<TKey>;
1997
+ /** 定义分组多选步骤 */
1998
+ groupMultiselect: <TKey extends string, TValue>(step: WorkflowStepConfigInput<WorkflowGroupMultiSelectStepConfig<TKey, TValue>>) => WorkflowGroupMultiSelectStep<TKey, TValue>;
1999
+ /** 定义 log 步骤 */
2000
+ log: <TKey extends string>(step: WorkflowStepConfigInput<WorkflowLogStepConfig<TKey>>) => WorkflowLogStep<TKey>;
2001
+ /** 定义多选步骤 */
2002
+ multiselect: <TKey extends string, TValue>(step: WorkflowStepConfigInput<WorkflowMultiSelectStepConfig<TKey, TValue>>) => WorkflowMultiSelectStep<TKey, TValue>;
2003
+ /** 定义 note 步骤 */
2004
+ note: <TKey extends string>(step: WorkflowStepConfigInput<WorkflowNoteStepConfig<TKey>>) => WorkflowNoteStep<TKey>;
2005
+ /** 定义密码步骤 */
2006
+ password: <TKey extends string>(step: WorkflowStepConfigInput<WorkflowPasswordStepConfig<TKey>>) => WorkflowPasswordStep<TKey>;
2007
+ /** 定义路径步骤 */
2008
+ path: <TKey extends string>(step: WorkflowStepConfigInput<WorkflowPathStepConfig<TKey>>) => WorkflowPathStep<TKey>;
2009
+ /** 定义快捷键单选步骤 */
2010
+ selectKey: <TKey extends string, TValue extends string>(step: WorkflowStepConfigInput<WorkflowSelectKeyStepConfig<TKey, TValue>>) => WorkflowSelectKeyStep<TKey, TValue>;
2011
+ /** 定义单选步骤 */
2012
+ select: <TKey extends string, TValue>(step: WorkflowStepConfigInput<WorkflowSelectStepConfig<TKey, TValue>>) => WorkflowSelectStep<TKey, TValue>;
2013
+ /** 定义文本步骤 */
2014
+ text: <TKey extends string>(step: WorkflowStepConfigInput<WorkflowTextStepConfig<TKey>>) => WorkflowTextStep<TKey>;
2015
+ }
2016
+ /** 显式定义单个步骤;当编辑器对数组字面量提示不稳定时可用它拿到精确类型 */
2017
+ declare const defineStep: DefineStep;
2018
+ /** 显式定义纯 DSL 步骤数组,优先保留编辑器字段提示 */
2019
+ declare function defineSteps<const TSteps extends readonly WorkflowStepConfigDefinition[]>(steps: TSteps): readonly WorkflowStepDefinition[];
2020
+ /** 显式定义纯标准化步骤数组 */
2021
+ declare function defineSteps<const TSteps extends readonly WorkflowStepDefinition[]>(steps: TSteps): readonly WorkflowStepDefinition[];
2022
+ /** 显式定义混合步骤数组;同时接受标准化步骤和声明式 DSL */
2023
+ declare function defineSteps<const TSteps extends readonly WorkflowStepAuthoringDefinition[]>(steps: TSteps): readonly WorkflowStepDefinition[];
2024
+ //#endregion
2025
+ //#region src/authoring/workflow.d.ts
2026
+ /** 定义一个工作流,并保留步骤元数据给后续类型推导使用 */
2027
+ declare function defineWorkflow(workflow: WorkflowAuthoringDefinition): WorkflowDefinition<readonly WorkflowStepDefinition[]>;
2028
+ //#endregion
2029
+ //#region src/runtime/command.d.ts
2030
+ /** 创建默认的 Node 子进程命令执行器 */
2031
+ declare function createNodeCommandExecutor(): WorkflowCommandExecutor;
2032
+ /** 创建基于 tinyexec 的命令执行器 */
2033
+ declare function createTinyexecCommandExecutor(): WorkflowCommandExecutor;
2034
+ /** 直接执行一条外部命令,适合作为底层工具函数单独使用 */
2035
+ declare function runCommand(options: WorkflowRunCommandOptions): Promise<WorkflowCommandExecutionResult>;
2036
+ /** 根据类型选择内置命令执行器 */
2037
+ declare function createCommandExecutor(executorType?: WorkflowCommandExecutorType): WorkflowCommandExecutor;
2038
+ //#endregion
2039
+ //#region src/runtime/kit.d.ts
2040
+ /** 创建一个以 workflow 为中心的 clack-kit 实例 */
2041
+ declare function createWorkflowKit(options?: CreateWorkflowKitOptions): WorkflowKit;
2042
+ /** 不显式创建 kit,直接运行 workflow */
2043
+ declare function runWorkflow(workflow: WorkflowDefinition<readonly WorkflowStepDefinition[]>, options?: WorkflowRunOptions<Record<string, unknown>>): Promise<WorkflowRunResult<Record<string, unknown>>>;
2044
+ /** 不显式创建 kit,安全运行 workflow;用户取消时返回 null */
2045
+ declare function runWorkflowSafely(workflow: WorkflowDefinition<readonly WorkflowStepDefinition[]>, options?: WorkflowRunOptions<Record<string, unknown>>): Promise<WorkflowRunResult<Record<string, unknown>> | null>;
2046
+ //#endregion
2047
+ //#region src/runtime/renderer.d.ts
2048
+ /** Clack 渲染器的创建选项 */
2049
+ interface CreateClackRendererOptions extends WorkflowClackRendererOptions {}
2050
+ /** 创建默认的 Clack 渲染器适配器 */
2051
+ declare function createClackRenderer(options?: CreateClackRendererOptions): WorkflowRenderer;
2052
+ //#endregion
2053
+ //#region src/shared/errors.d.ts
2054
+ /** 用户主动取消交互时抛出的错误 */
2055
+ declare class PromptCancelledError extends Error {
2056
+ readonly key?: string;
2057
+ readonly scope?: string;
2058
+ constructor(message?: string, options?: {
2059
+ key?: string;
2060
+ scope?: string;
2061
+ });
2062
+ }
2063
+ /** 标识工作流执行过程中出现的业务级失败 */
2064
+ declare class WorkflowExecutionError extends Error {
2065
+ readonly stepId: string;
2066
+ readonly workflowId: string;
2067
+ constructor(message: string, options: {
2068
+ cause?: unknown;
2069
+ stepId: string;
2070
+ workflowId: string;
2071
+ });
2072
+ }
2073
+ /** 判断未知错误是否来自用户取消 */
2074
+ declare function isPromptCancelledError(error: unknown): error is PromptCancelledError;
2075
+ /** 判断未知错误是否是工作流执行错误 */
2076
+ declare function isWorkflowExecutionError(error: unknown): error is WorkflowExecutionError;
2077
+ //#endregion
2078
+ //#region src/shared/files.d.ts
2079
+ /** 读取文本文件 */
2080
+ declare function readTextFile(filePath: string): Promise<string>;
2081
+ /** 写入文本文件,并自动创建父目录 */
2082
+ declare function writeTextFile(filePath: string, content: string): Promise<void>;
2083
+ /** 读取 JSON 文件并解析成对象 */
2084
+ declare function readJson<TValue = unknown>(filePath: string): Promise<TValue>;
2085
+ /** 写入 JSON 文件,并使用稳定缩进与换行 */
2086
+ declare function writeJson(filePath: string, value: unknown): Promise<void>;
2087
+ /** 读取、更新并回写 JSON 文件 */
2088
+ declare function patchJson<TValue extends Record<string, unknown>>(filePath: string, updater: (current: TValue) => Promise<TValue> | TValue): Promise<TValue>;
2089
+ /** 基于 `fast-glob` 提供高性能 glob helper */
2090
+ declare function globFiles(pattern: string, options?: WorkflowGlobOptions): Promise<string[]>;
2091
+ //#endregion
2092
+ //#region src/shared/helpers.d.ts
2093
+ type PromptValidator<TValue> = (value: TValue | undefined) => Error | string | undefined;
2094
+ /** 按顺序运行多个校验函数,命中第一个错误后立即返回 */
2095
+ declare function composeValidators<TValue>(...validators: Array<PromptValidator<TValue> | undefined>): PromptValidator<TValue>;
2096
+ /** 生成一个“非空字符串”校验器 */
2097
+ declare function createRequiredTextValidator(message?: string): PromptValidator<string>;
2098
+ /** 把工作流里的任意值转成便于展示和记录的文本 */
2099
+ declare function formatPromptValue(value: unknown): string;
2100
+ /** 把 `project-name` 这类 key 转成人看得懂的标题 */
2101
+ declare function formatFieldLabel(key: string): string;
2102
+ /** 把任意字符串整理成更适合文件系统的文件名 */
2103
+ declare function sanitizeFileName(value: string): string;
2104
+ /** 休眠指定毫秒数 */
2105
+ declare function sleep(milliseconds: number): Promise<void>;
2106
+ /** 用 figlet 生成 ASCII Art;多行输入会直接视为现成内容返回 */
2107
+ declare function renderAsciiArt(value: string): string;
2108
+ /** 把原始值列表映射成选择组件能直接用的 options */
2109
+ declare function toOptions<TValue>(values: readonly TValue[], mapper?: (value: TValue, index: number) => {
2110
+ disabled?: boolean;
2111
+ hint?: string;
2112
+ label?: string;
2113
+ value?: TValue;
2114
+ }): Array<{
2115
+ disabled?: boolean;
2116
+ hint?: string;
2117
+ label?: string;
2118
+ value: TValue;
2119
+ }>;
2120
+ //#endregion
2121
+ //#region node_modules/i18next/typescript/helpers.d.ts
2122
+ // Types
2123
+ type $Dictionary<T = unknown> = {
2124
+ [key: string]: T;
2125
+ };
2126
+ type $MergeBy<T, K> = Omit<T, keyof K> & K;
2127
+ type $PreservedValue<Value, Fallback> = [Value] extends [never] ? Fallback : Value;
2128
+ //#endregion
2129
+ //#region node_modules/i18next/typescript/options.d.ts
2130
+ /**
2131
+ * This interface can be augmented by users to add types to `i18next` default TypeOptions.
2132
+ *
2133
+ * Usage:
2134
+ * ```ts
2135
+ * // i18next.d.ts
2136
+ * import 'i18next';
2137
+ * declare module 'i18next' {
2138
+ * interface CustomTypeOptions {
2139
+ * defaultNS: 'custom';
2140
+ * returnNull: false;
2141
+ * returnObjects: false;
2142
+ * nsSeparator: ':';
2143
+ * keySeparator: '.';
2144
+ * compatibilityJSON: 'v4';
2145
+ * allowObjectInHTMLChildren: false;
2146
+ * resources: {
2147
+ * custom: {
2148
+ * foo: 'foo';
2149
+ * };
2150
+ * };
2151
+ * }
2152
+ * }
2153
+ * ```
2154
+ */
2155
+ interface CustomTypeOptions {}
2156
+ /**
2157
+ * This interface can be augmented by users to add types to `i18next` default PluginOptions.
2158
+ */
2159
+ interface CustomPluginOptions {}
2160
+ type TypeOptions = $MergeBy<{
2161
+ /** @see {InitOptions.returnNull} */returnNull: false; /** @see {InitOptions.returnEmptyString} */
2162
+ returnEmptyString: true; /** @see {InitOptions.returnObjects} */
2163
+ returnObjects: false; /** @see {InitOptions.keySeparator} */
2164
+ keySeparator: '.'; /** @see {InitOptions.nsSeparator} */
2165
+ nsSeparator: ':'; /** @see {InitOptions.pluralSeparator} */
2166
+ pluralSeparator: '_'; /** @see {InitOptions.contextSeparator} */
2167
+ contextSeparator: '_'; /** @see {InitOptions.defaultNS} */
2168
+ defaultNS: 'translation'; /** @see {InitOptions.fallbackNS} */
2169
+ fallbackNS: false; /** @see {InitOptions.compatibilityJSON} */
2170
+ compatibilityJSON: 'v4'; /** @see {InitOptions.resources} */
2171
+ resources: object;
2172
+ /**
2173
+ * Flag that allows HTML elements to receive objects. This is only useful for React applications
2174
+ * where you pass objects to HTML elements so they can be replaced to their respective interpolation
2175
+ * values (mostly with Trans component)
2176
+ */
2177
+ allowObjectInHTMLChildren: false;
2178
+ /**
2179
+ * Flag that enables strict key checking even if a `defaultValue` has been provided.
2180
+ * This ensures all calls of `t` function don't accidentally use implicitly missing keys.
2181
+ */
2182
+ strictKeyChecks: false;
2183
+ /**
2184
+ * Prefix for interpolation
2185
+ */
2186
+ interpolationPrefix: '{{';
2187
+ /**
2188
+ * Suffix for interpolation
2189
+ */
2190
+ interpolationSuffix: '}}'; /** @see {InterpolationOptions.unescapePrefix} */
2191
+ unescapePrefix: '-'; /** @see {InterpolationOptions.unescapeSuffix} */
2192
+ unescapeSuffix: '';
2193
+ /**
2194
+ * Use a proxy-based selector to select a translation.
2195
+ *
2196
+ * Enables features like go-to definition, and better DX/faster autocompletion
2197
+ * for TypeScript developers.
2198
+ *
2199
+ * If you're working with an especially large set of translations and aren't
2200
+ * using context, you set `enableSelector` to `"optimize"` and i18next won't do
2201
+ * any type-level processing of your translations at all.
2202
+ *
2203
+ * With `enableSelector` set to `"optimize"`, i18next is capable of supporting
2204
+ * arbitrarily large/deep translation sets without causing any IDE slowdown
2205
+ * whatsoever.
2206
+ *
2207
+ * @default false
2208
+ */
2209
+ enableSelector: false;
2210
+ /**
2211
+ * Maps interpolation format specifiers to their expected value types.
2212
+ *
2213
+ * By default, i18next infers types from built-in formatter names:
2214
+ * - `number`, `currency` → `number`
2215
+ * - `datetime` → `Date`
2216
+ * - `relativetime` → `number`
2217
+ * - `list` → `readonly string[]`
2218
+ * - No format specifier → `string`
2219
+ *
2220
+ * Use this option to add mappings for custom formatters or to override
2221
+ * the built-in defaults.
2222
+ *
2223
+ * @default {} (empty — built-in defaults apply)
2224
+ *
2225
+ * @example
2226
+ * ```ts
2227
+ * interface CustomTypeOptions {
2228
+ * interpolationFormatTypeMap: {
2229
+ * // custom formatter
2230
+ * uppercase: string;
2231
+ * // override built-in
2232
+ * currency: string;
2233
+ * };
2234
+ * }
2235
+ * ```
2236
+ */
2237
+ interpolationFormatTypeMap: {};
2238
+ }, CustomTypeOptions>;
2239
+ type PluginOptions<T> = $MergeBy<{
2240
+ /**
2241
+ * Options for language detection - check documentation of plugin
2242
+ * @default undefined
2243
+ */
2244
+ detection?: object;
2245
+ /**
2246
+ * Options for backend - check documentation of plugin
2247
+ * @default undefined
2248
+ */
2249
+ backend?: T;
2250
+ /**
2251
+ * Options for cache layer - check documentation of plugin
2252
+ * @default undefined
2253
+ */
2254
+ cache?: object;
2255
+ /**
2256
+ * Options for i18n message format - check documentation of plugin
2257
+ * @default undefined
2258
+ */
2259
+ i18nFormat?: object;
2260
+ }, CustomPluginOptions>;
2261
+ interface InterpolationOptions {
2262
+ /**
2263
+ * Used to separate format from interpolation value
2264
+ * @default ','
2265
+ */
2266
+ formatSeparator?: string;
2267
+ /**
2268
+ * Escape function
2269
+ * @default str => str
2270
+ */
2271
+ escape?(str: string): string;
2272
+ /**
2273
+ * Always format interpolated values.
2274
+ * @default false
2275
+ */
2276
+ alwaysFormat?: boolean;
2277
+ /**
2278
+ * Escape passed in values to avoid xss injection
2279
+ * @default true
2280
+ */
2281
+ escapeValue?: boolean;
2282
+ /**
2283
+ * If true, then value passed into escape function is not casted to string, use with custom escape function that does its own type check
2284
+ * @default false
2285
+ */
2286
+ useRawValueToEscape?: boolean;
2287
+ /**
2288
+ * Prefix for interpolation
2289
+ * @default '{{'
2290
+ */
2291
+ prefix?: string;
2292
+ /**
2293
+ * Suffix for interpolation
2294
+ * @default '}}'
2295
+ */
2296
+ suffix?: string;
2297
+ /**
2298
+ * Escaped prefix for interpolation (regexSafe)
2299
+ * @default undefined
2300
+ */
2301
+ prefixEscaped?: string;
2302
+ /**
2303
+ * Escaped suffix for interpolation (regexSafe)
2304
+ * @default undefined
2305
+ */
2306
+ suffixEscaped?: string;
2307
+ /**
2308
+ * Suffix to unescaped mode
2309
+ * @default undefined
2310
+ */
2311
+ unescapeSuffix?: string;
2312
+ /**
2313
+ * Prefix to unescaped mode
2314
+ * @default '-'
2315
+ */
2316
+ unescapePrefix?: string;
2317
+ /**
2318
+ * Prefix for nesting
2319
+ * @default '$t('
2320
+ */
2321
+ nestingPrefix?: string;
2322
+ /**
2323
+ * Suffix for nesting
2324
+ * @default ')'
2325
+ */
2326
+ nestingSuffix?: string;
2327
+ /**
2328
+ * Escaped prefix for nesting (regexSafe)
2329
+ * @default undefined
2330
+ */
2331
+ nestingPrefixEscaped?: string;
2332
+ /**
2333
+ * Escaped suffix for nesting (regexSafe)
2334
+ * @default undefined
2335
+ */
2336
+ nestingSuffixEscaped?: string;
2337
+ /**
2338
+ * Separates options from key
2339
+ * @default ','
2340
+ */
2341
+ nestingOptionsSeparator?: string;
2342
+ /**
2343
+ * Global variables to use in interpolation replacements
2344
+ * @default undefined
2345
+ */
2346
+ defaultVariables?: {
2347
+ [index: string]: any;
2348
+ };
2349
+ /**
2350
+ * After how many interpolation runs to break out before throwing a stack overflow
2351
+ * @default 1000
2352
+ */
2353
+ maxReplaces?: number;
2354
+ /**
2355
+ * If true, it will skip to interpolate the variables
2356
+ * @default true
2357
+ */
2358
+ skipOnVariables?: boolean;
2359
+ }
2360
+ interface FallbackLngObjList {
2361
+ [language: string]: readonly string[];
2362
+ }
2363
+ type FallbackLng = string | readonly string[] | FallbackLngObjList | ((code: string) => string | readonly string[] | FallbackLngObjList);
2364
+ interface ReactOptions {
2365
+ /**
2366
+ * Set it to fallback to let passed namespaces to translated hoc act as fallbacks
2367
+ * @default 'default'
2368
+ */
2369
+ nsMode?: 'default' | 'fallback';
2370
+ /**
2371
+ * Set it to the default parent element created by the Trans component.
2372
+ * @default 'div'
2373
+ */
2374
+ defaultTransParent?: string;
2375
+ /**
2376
+ * Set which events trigger a re-render, can be set to false or string of events
2377
+ * @default 'languageChanged'
2378
+ */
2379
+ bindI18n?: string | false;
2380
+ /**
2381
+ * Set which events on store trigger a re-render, can be set to false or string of events
2382
+ * @default ''
2383
+ */
2384
+ bindI18nStore?: string | false;
2385
+ /**
2386
+ * Set fallback value for Trans components without children
2387
+ * @default undefined
2388
+ */
2389
+ transEmptyNodeValue?: string;
2390
+ /**
2391
+ * Set it to false if you do not want to use Suspense
2392
+ * @default true
2393
+ */
2394
+ useSuspense?: boolean;
2395
+ /**
2396
+ * Function to generate an i18nKey from the defaultValue (or Trans children)
2397
+ * when no key is provided.
2398
+ * By default, the defaultValue (Trans text) itself is used as the key.
2399
+ * If you want to require keys for all translations, supply a function
2400
+ * that always throws an error.
2401
+ * @default undefined
2402
+ */
2403
+ hashTransKey?(defaultValue: TOptionsBase['defaultValue']): TOptionsBase['defaultValue'];
2404
+ /**
2405
+ * Convert eg. <br/> found in translations to a react component of type br
2406
+ * @default true
2407
+ */
2408
+ transSupportBasicHtmlNodes?: boolean;
2409
+ /**
2410
+ * Which nodes not to convert in defaultValue generation in the Trans component.
2411
+ * @default ['br', 'strong', 'i', 'p']
2412
+ */
2413
+ transKeepBasicHtmlNodesFor?: readonly string[];
2414
+ /**
2415
+ * Wrap text nodes in a user-specified element.
2416
+ * @default ''
2417
+ */
2418
+ transWrapTextNodes?: string;
2419
+ /**
2420
+ * Default props to apply to all Trans components.
2421
+ * Component-level props will override these defaults.
2422
+ */
2423
+ transDefaultProps?: {
2424
+ tOptions?: TOptions;
2425
+ values?: object;
2426
+ shouldUnescape?: boolean;
2427
+ components?: readonly unknown[] | {
2428
+ readonly [tagName: string]: unknown;
2429
+ }; // Use `unknown` (or `any`) to be permissive without importing React.
2430
+ };
2431
+ /**
2432
+ * Optional keyPrefix that will be automatically applied to returned t function in useTranslation for example.
2433
+ * Accepts a string or a selector function (e.g. `$ => $.deeply.nested`).
2434
+ * @default undefined
2435
+ */
2436
+ keyPrefix?: string | (($: any) => any);
2437
+ /**
2438
+ * Unescape function
2439
+ * by default it unescapes some basic html entities
2440
+ */
2441
+ unescape?(str: string): string;
2442
+ }
2443
+ type ResourceKey = string | {
2444
+ [key: string]: any;
2445
+ };
2446
+ interface ResourceLanguage {
2447
+ [namespace: string]: ResourceKey;
2448
+ }
2449
+ interface Resource {
2450
+ [language: string]: ResourceLanguage;
2451
+ }
2452
+ interface InitOptions<T = object> extends PluginOptions<T> {
2453
+ /**
2454
+ * Logs info level to console output. Helps finding issues with loading not working.
2455
+ * @default false
2456
+ */
2457
+ debug?: boolean;
2458
+ /**
2459
+ * Resources to initialize with (if not using loading or not appending using addResourceBundle)
2460
+ * @default undefined
2461
+ */
2462
+ resources?: Resource;
2463
+ /**
2464
+ * Allow initializing with bundled resources while using a backend to load non bundled ones.
2465
+ * @default false
2466
+ */
2467
+ partialBundledLanguages?: boolean;
2468
+ /**
2469
+ * Language to use (overrides language detection)
2470
+ * @default undefined
2471
+ */
2472
+ lng?: string;
2473
+ /**
2474
+ * Language to use if translations in user language are not available.
2475
+ * @default 'dev'
2476
+ */
2477
+ fallbackLng?: false | FallbackLng;
2478
+ /**
2479
+ * Array of allowed languages
2480
+ * @default false
2481
+ */
2482
+ supportedLngs?: false | readonly string[];
2483
+ /**
2484
+ * If true will pass eg. en-US if finding en in supportedLngs
2485
+ * @default false
2486
+ */
2487
+ nonExplicitSupportedLngs?: boolean;
2488
+ /**
2489
+ * Language codes to lookup, given set language is 'en-US':
2490
+ * 'all' --> ['en-US', 'en', 'dev'],
2491
+ * 'currentOnly' --> 'en-US',
2492
+ * 'languageOnly' --> 'en'
2493
+ * @default 'all'
2494
+ */
2495
+ load?: 'all' | 'currentOnly' | 'languageOnly';
2496
+ /**
2497
+ * Array of languages to preload. Important on server-side to assert translations are loaded before rendering views.
2498
+ * @default false
2499
+ */
2500
+ preload?: false | readonly string[];
2501
+ /**
2502
+ * Language will be lowercased eg. en-US --> en-us
2503
+ * @default false
2504
+ */
2505
+ lowerCaseLng?: boolean;
2506
+ /**
2507
+ * Language will be lowercased EN --> en while leaving full locales like en-US
2508
+ * @default false
2509
+ */
2510
+ cleanCode?: boolean;
2511
+ /**
2512
+ * String or array of namespaces to load
2513
+ * @default 'translation'
2514
+ */
2515
+ ns?: string | readonly string[];
2516
+ /**
2517
+ * Default namespace used if not passed to translation function
2518
+ * @default 'translation'
2519
+ */
2520
+ defaultNS?: string | false | readonly string[];
2521
+ /**
2522
+ * String or array of namespaces to lookup key if not found in given namespace.
2523
+ * @default false
2524
+ */
2525
+ fallbackNS?: false | string | readonly string[];
2526
+ /**
2527
+ * Calls save missing key function on backend if key not found.
2528
+ * @default false
2529
+ */
2530
+ saveMissing?: boolean;
2531
+ /**
2532
+ * Calls save missing key function on backend if key not found also for plural forms.
2533
+ * @default false
2534
+ */
2535
+ saveMissingPlurals?: boolean;
2536
+ /**
2537
+ * Experimental: enable to update default values using the saveMissing
2538
+ * (Works only if defaultValue different from translated value.
2539
+ * Only useful on initial development or when keeping code as source of truth not changing values outside of code.
2540
+ * Only supported if backend supports it already)
2541
+ * @default false
2542
+ */
2543
+ updateMissing?: boolean;
2544
+ /**
2545
+ * @default 'fallback'
2546
+ */
2547
+ saveMissingTo?: 'current' | 'all' | 'fallback';
2548
+ /**
2549
+ * Used to not fallback to the key as default value, when using saveMissing functionality.
2550
+ * i.e. when using with i18next-http-backend this will result in having a key with an empty string value.
2551
+ * @default false
2552
+ */
2553
+ missingKeyNoValueFallbackToKey?: boolean;
2554
+ /**
2555
+ * Used for custom missing key handling (needs saveMissing set to true!)
2556
+ * @default false
2557
+ */
2558
+ missingKeyHandler?: false | ((lngs: readonly string[], ns: string, key: string, fallbackValue: string, updateMissing: boolean, options: any) => void);
2559
+ /**
2560
+ * Receives a key that was not found in `t()` and returns a value, that will be returned by `t()`
2561
+ * @default noop
2562
+ */
2563
+ parseMissingKeyHandler?(key: string, defaultValue?: string, options?: any): any;
2564
+ /**
2565
+ * Appends namespace to missing key
2566
+ * @default false
2567
+ */
2568
+ appendNamespaceToMissingKey?: boolean;
2569
+ /**
2570
+ * Gets called in case a interpolation value is undefined. This method will not be called if the value is empty string or null
2571
+ * @default noop
2572
+ */
2573
+ missingInterpolationHandler?: (text: string, value: any, options: InitOptions) => any;
2574
+ /**
2575
+ * String or array of postProcessors to apply per default
2576
+ * @default false
2577
+ */
2578
+ postProcess?: false | string | readonly string[];
2579
+ /**
2580
+ * passthrough the resolved object including 'usedNS', 'usedLang' etc into options object of postprocessors as 'i18nResolved' property
2581
+ * @default false
2582
+ */
2583
+ postProcessPassResolved?: boolean;
2584
+ /**
2585
+ * Allows null values as valid translation
2586
+ * @default false
2587
+ */
2588
+ returnNull?: boolean;
2589
+ /**
2590
+ * Allows empty string as valid translation
2591
+ * @default true
2592
+ */
2593
+ returnEmptyString?: boolean;
2594
+ /**
2595
+ * Allows objects as valid translation result
2596
+ * @default false
2597
+ */
2598
+ returnObjects?: boolean;
2599
+ /**
2600
+ * Returns an object that includes information about the used language, namespace, key and value
2601
+ * @default false
2602
+ */
2603
+ returnDetails?: boolean;
2604
+ /**
2605
+ * Gets called if object was passed in as key but returnObjects was set to false
2606
+ * @default noop
2607
+ */
2608
+ returnedObjectHandler?(key: string, value: string, options: any): void;
2609
+ /**
2610
+ * Char, eg. '\n' that arrays will be joined by
2611
+ * @default false
2612
+ */
2613
+ joinArrays?: false | string;
2614
+ /**
2615
+ * Sets defaultValue
2616
+ * @default args => ({ defaultValue: args[1] })
2617
+ */
2618
+ overloadTranslationOptionHandler?(args: string[]): TOptions;
2619
+ /**
2620
+ * @see https://www.i18next.com/translation-function/interpolation
2621
+ */
2622
+ interpolation?: InterpolationOptions;
2623
+ /**
2624
+ * Options for react - check documentation of plugin
2625
+ * @default undefined
2626
+ */
2627
+ react?: ReactOptions;
2628
+ /**
2629
+ * Triggers resource loading in init function inside a setTimeout (default async behaviour).
2630
+ * Set it to false if your backend loads resources sync - that way calling i18next.t after
2631
+ * init is possible without relaying on the init callback.
2632
+ * @default true
2633
+ */
2634
+ initAsync?: boolean;
2635
+ /**
2636
+ * Char to separate keys
2637
+ * @default '.'
2638
+ */
2639
+ keySeparator?: false | string;
2640
+ /**
2641
+ * Char to split namespace from key
2642
+ * @default ':'
2643
+ */
2644
+ nsSeparator?: false | string;
2645
+ /**
2646
+ * Char to split plural from key
2647
+ * @default '_'
2648
+ */
2649
+ pluralSeparator?: string;
2650
+ /**
2651
+ * Char to split context from key
2652
+ * @default '_'
2653
+ */
2654
+ contextSeparator?: string;
2655
+ /**
2656
+ * Prefixes the namespace to the returned key when using `cimode`
2657
+ * @default false
2658
+ */
2659
+ appendNamespaceToCIMode?: boolean;
2660
+ /**
2661
+ * Compatibility JSON version
2662
+ * @warning only `v4` is available and supported by typescript
2663
+ * @default 'v4'
2664
+ */
2665
+ compatibilityJSON?: 'v4';
2666
+ /**
2667
+ * Options for https://github.com/locize/locize-lastused
2668
+ * @default undefined
2669
+ */
2670
+ locizeLastUsed?: {
2671
+ /**
2672
+ * The id of your locize project
2673
+ */
2674
+ projectId: string;
2675
+ /**
2676
+ * An api key if you want to send missing keys
2677
+ */
2678
+ apiKey?: string;
2679
+ /**
2680
+ * The reference language of your project
2681
+ * @default 'en'
2682
+ */
2683
+ referenceLng?: string;
2684
+ /**
2685
+ * Version
2686
+ * @default 'latest'
2687
+ */
2688
+ version?: string;
2689
+ /**
2690
+ * Debounce interval to send data in milliseconds
2691
+ * @default 90000
2692
+ */
2693
+ debounceSubmit?: number;
2694
+ /**
2695
+ * Hostnames that are allowed to send last used data.
2696
+ * Please keep those to your local system, staging, test servers (not production)
2697
+ * @default ['localhost']
2698
+ */
2699
+ allowedHosts?: readonly string[];
2700
+ };
2701
+ /**
2702
+ * Automatically lookup for a flat key if a nested key is not found an vice-versa
2703
+ * @default true
2704
+ */
2705
+ ignoreJSONStructure?: boolean;
2706
+ /**
2707
+ * Limit parallelism of calls to backend
2708
+ * This is needed to prevent trying to open thousands of
2709
+ * sockets or file descriptors, which can cause failures
2710
+ * and actually make the entire process take longer.
2711
+ * @default 10
2712
+ */
2713
+ maxParallelReads?: number;
2714
+ /**
2715
+ * The maximum number of retries to perform.
2716
+ * Note that retries are only performed when a request has no response
2717
+ * and throws an error.
2718
+ * The default value is used if value is set below 0.
2719
+ * @default 5
2720
+ */
2721
+ maxRetries?: number;
2722
+ /**
2723
+ * Set how long to wait, in milliseconds, between retries of failed requests.
2724
+ * This number is compounded by a factor of 2 for subsequent retry.
2725
+ * The default value is used if value is set below 1ms.
2726
+ * @default 350
2727
+ */
2728
+ retryTimeout?: number;
2729
+ /**
2730
+ * Initializes the internal formatter for the in-built formats as cached version.
2731
+ * Can be set to false for this type of issues: https://github.com/i18next/i18next/issues/2227
2732
+ * @default true
2733
+ */
2734
+ cacheInBuiltFormats?: boolean;
2735
+ }
2736
+ interface TOptionsBase {
2737
+ /**
2738
+ * Default value to return if a translation was not found
2739
+ */
2740
+ defaultValue?: unknown;
2741
+ /**
2742
+ * Count value used for plurals
2743
+ */
2744
+ count?: number;
2745
+ /**
2746
+ * Ordinal flag for ordinal plurals
2747
+ */
2748
+ ordinal?: boolean;
2749
+ /**
2750
+ * Used for contexts (eg. male\female)
2751
+ */
2752
+ context?: unknown;
2753
+ /**
2754
+ * Object with vars for interpolation - or put them directly in options
2755
+ */
2756
+ replace?: any;
2757
+ /**
2758
+ * Override language to use
2759
+ */
2760
+ lng?: string;
2761
+ /**
2762
+ * Override languages to use
2763
+ */
2764
+ lngs?: readonly string[];
2765
+ /**
2766
+ * Override language to lookup key if not found see fallbacks for details
2767
+ */
2768
+ fallbackLng?: false | FallbackLng;
2769
+ /**
2770
+ * Override namespaces (string or array)
2771
+ */
2772
+ ns?: Namespace;
2773
+ /**
2774
+ * Override char to separate keys
2775
+ */
2776
+ keySeparator?: false | string;
2777
+ /**
2778
+ * Override char to split namespace from key
2779
+ */
2780
+ nsSeparator?: false | string;
2781
+ /**
2782
+ * Accessing an object not a translation string (can be set globally too)
2783
+ */
2784
+ returnObjects?: boolean;
2785
+ /**
2786
+ * Returns an object that includes information about the used language, namespace, key and value
2787
+ */
2788
+ returnDetails?: boolean;
2789
+ /**
2790
+ * Char, eg. '\n' that arrays will be joined by (can be set globally too)
2791
+ */
2792
+ joinArrays?: string;
2793
+ /**
2794
+ * String or array of postProcessors to apply see interval plurals as a sample
2795
+ */
2796
+ postProcess?: string | readonly string[];
2797
+ /**
2798
+ * Override interpolation options
2799
+ */
2800
+ interpolation?: InterpolationOptions;
2801
+ /**
2802
+ * Optional keyPrefix that will be applied to the key before resolving.
2803
+ * Accepts a string or a selector function (e.g. `$ => $.deeply.nested`).
2804
+ * Only supported on the TFunction returned by getFixedT().
2805
+ */
2806
+ keyPrefix?: string | (($: any) => any);
2807
+ }
2808
+ type TOptions<TInterpolationMap extends object = $Dictionary> = TOptionsBase & TInterpolationMap;
2809
+ type FlatNamespace = $PreservedValue<keyof TypeOptions['resources'], string>;
2810
+ type Namespace<T = FlatNamespace> = T | readonly T[];
2811
+ //#endregion
2812
+ //#region src/shared/i18n.d.ts
2813
+ /** 根据环境变量推断默认语言 */
2814
+ declare function detectLocaleFromEnv(): WorkflowLocale;
2815
+ /** 创建一个国际化实例,供 kit 和运行时共享使用 */
2816
+ declare function createWorkflowI18n(options?: {
2817
+ fallbackLocale?: WorkflowLocale;
2818
+ locale?: WorkflowLocale;
2819
+ locales?: WorkflowLocaleCatalog;
2820
+ resolveLocale?: () => WorkflowLocale;
2821
+ }): WorkflowI18n;
2822
+ /** 方便调用方显式构建 locale 资源目录 */
2823
+ declare function createI18nLocales<TCatalog extends WorkflowLocaleCatalog>(catalog: TCatalog): TCatalog;
2824
+ /** 导出内置 locale 资源目录,便于增量覆盖 */
2825
+ declare const builtinWorkflowLocales: {
2826
+ 'en-US': {
2827
+ log: {
2828
+ confirmSave: string;
2829
+ saveFailed: string;
2830
+ saved: string;
2831
+ savedOnFailure: string;
2832
+ };
2833
+ prompt: {
2834
+ cancelled: string;
2835
+ };
2836
+ workflow: {
2837
+ checkpoint: {
2838
+ applied: string;
2839
+ appliedCancelled: string;
2840
+ appliedFailed: string;
2841
+ message: string;
2842
+ restoredSteps: string;
2843
+ skippedInitialValues: string;
2844
+ };
2845
+ parallel: {
2846
+ completedNoOutput: string;
2847
+ started: string;
2848
+ };
2849
+ reuse: {
2850
+ applied: string;
2851
+ choose: string;
2852
+ chooseHint: string;
2853
+ empty: string;
2854
+ latest: string;
2855
+ latestHint: string;
2856
+ message: string;
2857
+ new: string;
2858
+ newHint: string;
2859
+ };
2860
+ savedAt: string;
2861
+ step: {
2862
+ duplicateSkipped: string;
2863
+ invalidChoice: string;
2864
+ overwritten: string;
2865
+ };
2866
+ };
2867
+ };
2868
+ 'zh-CN': {
2869
+ log: {
2870
+ confirmSave: string;
2871
+ saveFailed: string;
2872
+ saved: string;
2873
+ savedOnFailure: string;
2874
+ };
2875
+ prompt: {
2876
+ cancelled: string;
2877
+ };
2878
+ workflow: {
2879
+ checkpoint: {
2880
+ applied: string;
2881
+ appliedCancelled: string;
2882
+ appliedFailed: string;
2883
+ message: string;
2884
+ restoredSteps: string;
2885
+ skippedInitialValues: string;
2886
+ };
2887
+ parallel: {
2888
+ completedNoOutput: string;
2889
+ started: string;
2890
+ };
2891
+ reuse: {
2892
+ applied: string;
2893
+ choose: string;
2894
+ chooseHint: string;
2895
+ empty: string;
2896
+ latest: string;
2897
+ latestHint: string;
2898
+ message: string;
2899
+ new: string;
2900
+ newHint: string;
2901
+ };
2902
+ savedAt: string;
2903
+ step: {
2904
+ duplicateSkipped: string;
2905
+ invalidChoice: string;
2906
+ overwritten: string;
2907
+ };
2908
+ };
2909
+ };
2910
+ };
2911
+ /** 导出 i18next 基础配置,供工具链和外部集成复用 */
2912
+ declare const workflowI18nextOptions: InitOptions<object>;
2913
+ //#endregion
2914
+ //#region src/shared/timezone.d.ts
2915
+ /** 根据环境变量或运行时信息推断默认时区 */
2916
+ declare function detectTimeZone(): WorkflowTimeZone;
2917
+ //#endregion
2918
+ //#region src/storage/checkpoint.d.ts
2919
+ interface FileCheckpointStoreOptions {
2920
+ filePath: string;
2921
+ }
2922
+ /** 创建一个基于本地 JSON 文件的 checkpoint 存储 */
2923
+ declare function createFileCheckpointStore(options: FileCheckpointStoreOptions): WorkflowCheckpointStore;
2924
+ /** 创建一个仅保存在内存中的 checkpoint 存储 */
2925
+ declare function createMemoryCheckpointStore(): WorkflowCheckpointStore & {
2926
+ checkpoints: WorkflowCheckpointEntry[];
2927
+ };
2928
+ //#endregion
2929
+ //#region src/storage/history.d.ts
2930
+ interface FileHistoryStoreOptions {
2931
+ filePath: string;
2932
+ maxSnapshotsPerWorkflow?: number;
2933
+ }
2934
+ /** 创建一个基于本地 JSON 文件的历史存储 */
2935
+ declare function createFileHistoryStore(options: FileHistoryStoreOptions): WorkflowHistoryStore;
2936
+ /** 创建一个仅保存在内存中的历史存储,适合测试和短生命周期脚本 */
2937
+ declare function createMemoryHistoryStore(): WorkflowHistoryStore;
2938
+ //#endregion
2939
+ //#region src/storage/log.d.ts
2940
+ interface FileLogStoreOptions {
2941
+ directory: string;
2942
+ fileName?: (snapshot: WorkflowRunSnapshot) => string;
2943
+ format?: WorkflowLogFormat;
2944
+ }
2945
+ interface WorkflowLogSession<TValues extends Record<string, unknown>> {
2946
+ complete: (status: WorkflowRunStatus, values: Partial<TValues>, results: Partial<Record<string, unknown>>) => void;
2947
+ record: (event: Omit<WorkflowRunEvent, 'runId' | 'timestamp' | 'workflowId'>) => void;
2948
+ save: (options?: {
2949
+ path?: string;
2950
+ }) => Promise<string>;
2951
+ snapshot: () => WorkflowRunSnapshot<TValues>;
2952
+ }
2953
+ /** 计算单次运行的分析摘要 */
2954
+ declare function analyzeWorkflowRun(snapshot: WorkflowRunSnapshot): WorkflowRunAnalysis;
2955
+ /** 将运行快照渲染成指定日志格式 */
2956
+ declare function renderWorkflowLog(snapshot: WorkflowRunSnapshot, format?: WorkflowLogFormat): string;
2957
+ /** 创建一个写入本地文件的日志存储 */
2958
+ declare function createFileLogStore(options: FileLogStoreOptions): WorkflowLogStore;
2959
+ /** 创建一个空实现的日志存储 */
2960
+ declare function createNoopLogStore(): WorkflowLogStore;
2961
+ /** 创建一个仅保存在内存中的日志存储 */
2962
+ declare function createMemoryLogStore(): WorkflowLogStore & {
2963
+ snapshots: WorkflowRunSnapshot[];
2964
+ };
2965
+ /** 创建一次运行对应的日志会话对象 */
2966
+ declare function createWorkflowLogSession<TValues extends Record<string, unknown>>(options: {
2967
+ locale: string;
2968
+ meta?: Record<string, unknown>;
2969
+ runId: string;
2970
+ store: WorkflowLogStore;
2971
+ timeZone: string;
2972
+ workflowId: string;
2973
+ }): WorkflowLogSession<TValues>;
2974
+ //#endregion
2975
+ export { type AutocompleteMultiSelectOptions, type AutocompleteOptions, type BoxAlignment, type BoxOptions, type CommonOptions, type ConfirmOptions, CreateClackRendererOptions, CreateWorkflowKitOptions, DefineStep, type GroupMultiSelectOptions, type LimitOptionsParams, type LogMessageOptions, MaybePromise, type MultiSelectOptions, type NoteOptions, type PasswordOptions, type PathOptions, type ProgressOptions, type ProgressResult, PromptCancelledError, PromptRuntime, PromptValidator, type SelectKeyOptions, type SelectOptions, Simplify, type SpinnerOptions, type SpinnerResult, StepResultRecord, StepValueRecord, type Task, type TaskLogOptions, type TextOptions, UnionToIntersection, WorkflowAsciiArtDefinition, WorkflowAuthoringDefinition, WorkflowAutocompleteMultiSelectStep, WorkflowAutocompleteMultiSelectStepConfig, WorkflowAutocompleteStep, WorkflowAutocompleteStepConfig, WorkflowBaseStep, WorkflowBoxStep, WorkflowBoxStepConfig, WorkflowBuiltinDisplayStep, WorkflowBuiltinExecutableStep, WorkflowBuiltinResultStep, WorkflowBuiltinValueStep, WorkflowCheckpointEntry, WorkflowCheckpointReason, WorkflowCheckpointResumeMode, WorkflowCheckpointStore, WorkflowChoiceOptions, WorkflowClackRendererOptions, WorkflowCliBridge, WorkflowCliBridgeOptions, WorkflowCliFieldOptions, WorkflowCliOptionConfig, WorkflowCliOptionRegistrar, WorkflowColors, WorkflowCommandExecOptions, WorkflowCommandExecutionOptions, type WorkflowCommandExecutionResult, WorkflowCommandExecutor, WorkflowCommandExecutorType, WorkflowCommandHandler, WorkflowCommandPresenter, WorkflowCommandPresenterOptions, type WorkflowCommandResult, WorkflowCommandResultResolver, WorkflowCommandRetryOptions, WorkflowCommandShellOptions, WorkflowCommandStep, WorkflowCommandStepConfig, WorkflowCommandTaskIO, WorkflowCommandTaskLogOptions, WorkflowConfirmSaveLogContext, WorkflowConfirmSaveLogOptions, WorkflowConfirmStep, WorkflowConfirmStepConfig, WorkflowContextTools, WorkflowDefinition, WorkflowExecutableStep, WorkflowExecutionError, WorkflowExternalCommandStep, WorkflowExternalCommandStepConfig, WorkflowGlobOptions, WorkflowGroupMultiSelectStep, WorkflowGroupMultiSelectStepConfig, WorkflowGroupedChoiceOptions, WorkflowHistoryReuseMode, WorkflowHistoryStore, WorkflowI18n, WorkflowInlineCommandStep, WorkflowInlineCommandStepConfig, WorkflowIntroDefinition, WorkflowKit, WorkflowKitCheckpointOptions, WorkflowKitHistoryOptions, WorkflowKitLogOptions, WorkflowLocale, WorkflowLocaleCatalog, WorkflowLocaleResource, WorkflowLogCompletionOptions, WorkflowLogFormat, WorkflowLogLevel, WorkflowLogOptions, WorkflowLogStep, WorkflowLogStepConfig, WorkflowLogStore, WorkflowMessageValues, WorkflowMultiSelectStep, WorkflowMultiSelectStepConfig, WorkflowNoteStep, WorkflowNoteStepConfig, WorkflowPasswordStep, WorkflowPasswordStepConfig, WorkflowPathStep, WorkflowPathStepConfig, WorkflowPlugin, WorkflowPluginAPI, WorkflowPluginStep, WorkflowPluginStepExecutionOptions, WorkflowPluginStepHandler, WorkflowPredicate, WorkflowRenderer, WorkflowRendererAutocompleteMultiSelectOptions, WorkflowRendererAutocompleteOptions, WorkflowRendererBoxOptions, WorkflowRendererConfirmOptions, WorkflowRendererGroupMultiSelectOptions, WorkflowRendererLogOptions, WorkflowRendererMultiSelectOptions, WorkflowRendererNoteOptions, WorkflowRendererPasswordOptions, WorkflowRendererPathOptions, WorkflowRendererSelectKeyOptions, WorkflowRendererSelectOptions, WorkflowRendererTextOptions, WorkflowResultsFromSteps, WorkflowRunAnalysis, WorkflowRunCheckpointOptions, WorkflowRunCommandOptions, WorkflowRunEvent, WorkflowRunHistoryOptions, WorkflowRunLogOptions, WorkflowRunOptions, WorkflowRunResult, WorkflowRunSnapshot, WorkflowRunStatus, WorkflowRuntimeContext, WorkflowScriptFileCommandStep, WorkflowScriptFileCommandStepConfig, WorkflowSelectKeyStep, WorkflowSelectKeyStepConfig, WorkflowSelectOption, WorkflowSelectStep, WorkflowSelectStepConfig, WorkflowSnapshotEntry, WorkflowSnapshotOptions, WorkflowSnapshotQuery, WorkflowStepAnalysis, WorkflowStepAuthoringDefinition, WorkflowStepConfigBase, WorkflowStepConfigByType, WorkflowStepConfigDefinition, WorkflowStepConfigInput, WorkflowStepDefinition, WorkflowStepType, WorkflowSummaryOptions, WorkflowSummaryPreset, WorkflowTemplate, WorkflowTemplateCatalog, WorkflowTextStep, WorkflowTextStepConfig, WorkflowTimeZone, WorkflowValidator, WorkflowValueResolver, WorkflowValuesFromSteps, analyzeWorkflowRun, autocomplete, autocompleteMultiselect, box, builtinWorkflowLocales, cancel, composeValidators, confirm, createAutocompleteMultiSelectStep, createAutocompleteStep, createBoxStep, createClackRenderer, createCommandExecutor, createCommandStep, createConfirmStep, createFileCheckpointStore, createFileHistoryStore, createFileLogStore, createGroupMultiSelectStep, createI18nLocales, createLogStep, createMemoryCheckpointStore, createMemoryHistoryStore, createMemoryLogStore, createMultiSelectStep, createNodeCommandExecutor, createNoopLogStore, createNoteStep, createPasswordStep, createPathStep, createRequiredTextValidator, createSelectKeyStep, createSelectStep, createTextStep, createTinyexecCommandExecutor, createWorkflowCliBridge, createWorkflowI18n, createWorkflowKit, createWorkflowLogSession, createWorkflowTemplateCatalog, defaultPromptRuntime, defineStep, defineSteps, defineWorkflow, defineWorkflowTemplate, detectLocaleFromEnv, detectTimeZone, formatFieldLabel, formatPromptValue, globFiles, group, groupMultiselect, intro, isCI, isCancel, isPromptCancelledError, isTTY, isWorkflowExecutionError, limitOptions, log, multiselect, note, outro, parseWorkflowCliBoolean, parseWorkflowCliList, password, patchJson, path, progress, readJson, readTextFile, renderAsciiArt, renderWorkflowLog, runCommand, runWorkflow, runWorkflowSafely, sanitizeFileName, select, selectKey, sleep, spinner, stream, symbol, symbolBar, taskLog, tasks, text, toOptions, unicode, unicodeOr, workflowI18nextOptions, writeJson, writeTextFile };
2976
+ //# sourceMappingURL=index.d.mts.map