@xiaoso/dsh-workflow-lite 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/LICENSE +24 -0
  2. package/README.en.md +84 -0
  3. package/README.md +83 -2
  4. package/THIRD_PARTY_NOTICES.md +762 -0
  5. package/assets/icon-full.webp +0 -0
  6. package/assets/icon.webp +0 -0
  7. package/assets/wordmark.png +0 -0
  8. package/cordis.patch.yml +3 -0
  9. package/lib/client.js +127442 -0
  10. package/lib/index.mjs +9613 -0
  11. package/lib/types/client/app/addStep.d.ts +25 -0
  12. package/lib/types/client/app/desktop.d.ts +52 -0
  13. package/lib/types/client/app/host.d.ts +29 -0
  14. package/lib/types/client/app/sessions.d.ts +117 -0
  15. package/lib/types/client/app/theme.d.ts +27 -0
  16. package/lib/types/client/app/usePluginConfig.d.ts +59 -0
  17. package/lib/types/client/app/useRunFile.d.ts +24 -0
  18. package/lib/types/client/app/useRunGraph.d.ts +51 -0
  19. package/lib/types/client/app/useRunHistory.d.ts +21 -0
  20. package/lib/types/client/app/useRuns.d.ts +84 -0
  21. package/lib/types/client/app/useVersions.d.ts +50 -0
  22. package/lib/types/client/app/useWorkflow.d.ts +67 -0
  23. package/lib/types/client/app/viewport.d.ts +14 -0
  24. package/lib/types/client/i18n.d.ts +930 -0
  25. package/lib/types/client/index.d.ts +18 -0
  26. package/lib/types/client/model/connect.d.ts +44 -0
  27. package/lib/types/client/model/editor.d.ts +252 -0
  28. package/lib/types/client/model/fileKind.d.ts +15 -0
  29. package/lib/types/client/model/hostPath.d.ts +15 -0
  30. package/lib/types/client/model/htmlPreview.d.ts +24 -0
  31. package/lib/types/client/model/hubRuns.d.ts +45 -0
  32. package/lib/types/client/model/layout.d.ts +83 -0
  33. package/lib/types/client/model/library.d.ts +109 -0
  34. package/lib/types/client/model/nudge.d.ts +43 -0
  35. package/lib/types/client/model/pathSample.d.ts +26 -0
  36. package/lib/types/client/model/route.d.ts +121 -0
  37. package/lib/types/client/model/runDraft.d.ts +68 -0
  38. package/lib/types/client/model/runGraph.d.ts +15 -0
  39. package/lib/types/client/model/runHistory.d.ts +40 -0
  40. package/lib/types/client/model/themes.d.ts +87 -0
  41. package/lib/types/client/model/time.d.ts +7 -0
  42. package/lib/types/client/rpc.d.ts +42 -0
  43. package/lib/types/client/ui/AppearancePicker.d.ts +23 -0
  44. package/lib/types/client/ui/Canvas.d.ts +76 -0
  45. package/lib/types/client/ui/Confirm.d.ts +42 -0
  46. package/lib/types/client/ui/DocViewer.d.ts +67 -0
  47. package/lib/types/client/ui/Dock.d.ts +13 -0
  48. package/lib/types/client/ui/FileTag.d.ts +9 -0
  49. package/lib/types/client/ui/FileViewer.d.ts +30 -0
  50. package/lib/types/client/ui/FlowStreaks.d.ts +40 -0
  51. package/lib/types/client/ui/Handoff.d.ts +30 -0
  52. package/lib/types/client/ui/HostPicker.d.ts +31 -0
  53. package/lib/types/client/ui/HubDialog.d.ts +38 -0
  54. package/lib/types/client/ui/HubRunRow.d.ts +22 -0
  55. package/lib/types/client/ui/HubRuns.d.ts +19 -0
  56. package/lib/types/client/ui/HubSettings.d.ts +20 -0
  57. package/lib/types/client/ui/HubStorage.d.ts +18 -0
  58. package/lib/types/client/ui/HubWorkflowList.d.ts +21 -0
  59. package/lib/types/client/ui/HubWorkflowRow.d.ts +33 -0
  60. package/lib/types/client/ui/HubWorkflows.d.ts +26 -0
  61. package/lib/types/client/ui/HubWorkspacePicker.d.ts +16 -0
  62. package/lib/types/client/ui/Icon.d.ts +83 -0
  63. package/lib/types/client/ui/InputPanel.d.ts +37 -0
  64. package/lib/types/client/ui/InputsDialog.d.ts +22 -0
  65. package/lib/types/client/ui/Inspector.d.ts +51 -0
  66. package/lib/types/client/ui/Issues.d.ts +15 -0
  67. package/lib/types/client/ui/Launch.d.ts +30 -0
  68. package/lib/types/client/ui/Library.d.ts +23 -0
  69. package/lib/types/client/ui/LinkRow.d.ts +31 -0
  70. package/lib/types/client/ui/Markdown.d.ts +21 -0
  71. package/lib/types/client/ui/NodeHeads.d.ts +47 -0
  72. package/lib/types/client/ui/NoteDrawer.d.ts +21 -0
  73. package/lib/types/client/ui/OpenWith.d.ts +21 -0
  74. package/lib/types/client/ui/Outputs.d.ts +61 -0
  75. package/lib/types/client/ui/PanelHead.d.ts +21 -0
  76. package/lib/types/client/ui/PlanDialog.d.ts +18 -0
  77. package/lib/types/client/ui/PreviewCard.d.ts +38 -0
  78. package/lib/types/client/ui/QuickAdd.d.ts +30 -0
  79. package/lib/types/client/ui/ResourceItemDialog.d.ts +33 -0
  80. package/lib/types/client/ui/ResourceItems.d.ts +30 -0
  81. package/lib/types/client/ui/ResourcePanel.d.ts +26 -0
  82. package/lib/types/client/ui/Resources.d.ts +43 -0
  83. package/lib/types/client/ui/RunDraftBar.d.ts +35 -0
  84. package/lib/types/client/ui/RunEdge.d.ts +29 -0
  85. package/lib/types/client/ui/RunFiles.d.ts +24 -0
  86. package/lib/types/client/ui/RunInput.d.ts +26 -0
  87. package/lib/types/client/ui/RunItemDialog.d.ts +43 -0
  88. package/lib/types/client/ui/RunModeSwitch.d.ts +14 -0
  89. package/lib/types/client/ui/RunNav.d.ts +22 -0
  90. package/lib/types/client/ui/RunNodeState.d.ts +42 -0
  91. package/lib/types/client/ui/RunOverview.d.ts +27 -0
  92. package/lib/types/client/ui/RunPosition.d.ts +24 -0
  93. package/lib/types/client/ui/RunResource.d.ts +40 -0
  94. package/lib/types/client/ui/RunStatusMenu.d.ts +28 -0
  95. package/lib/types/client/ui/RunStep.d.ts +45 -0
  96. package/lib/types/client/ui/RunTopBar.d.ts +42 -0
  97. package/lib/types/client/ui/RunView.d.ts +43 -0
  98. package/lib/types/client/ui/SettingsDialog.d.ts +25 -0
  99. package/lib/types/client/ui/SettingsFields.d.ts +37 -0
  100. package/lib/types/client/ui/SkillPicker.d.ts +25 -0
  101. package/lib/types/client/ui/SkillPreview.d.ts +27 -0
  102. package/lib/types/client/ui/StepMark.d.ts +16 -0
  103. package/lib/types/client/ui/StepPanel.d.ts +26 -0
  104. package/lib/types/client/ui/ThemePicker.d.ts +13 -0
  105. package/lib/types/client/ui/TipLayer.d.ts +17 -0
  106. package/lib/types/client/ui/TopBar.d.ts +32 -0
  107. package/lib/types/client/ui/VersionList.d.ts +19 -0
  108. package/lib/types/client/ui/VersionRow.d.ts +19 -0
  109. package/lib/types/client/ui/VersionsDialog.d.ts +18 -0
  110. package/lib/types/client/ui/WorkflowRow.d.ts +32 -0
  111. package/lib/types/client/ui/WorkflowSwitcher.d.ts +20 -0
  112. package/lib/types/client/ui/WorkflowView.d.ts +27 -0
  113. package/lib/types/client/ui/lines.d.ts +13 -0
  114. package/lib/types/client/ui/primitives.d.ts +119 -0
  115. package/lib/types/client/ui/resourceUi.d.ts +49 -0
  116. package/lib/types/client/ui/stepIcons.d.ts +10 -0
  117. package/lib/types/host/authoringSkill.d.ts +17 -0
  118. package/lib/types/host/config.d.ts +54 -0
  119. package/lib/types/host/hostFs.d.ts +69 -0
  120. package/lib/types/host/plan.d.ts +68 -0
  121. package/lib/types/host/pluginConfig.d.ts +57 -0
  122. package/lib/types/host/rpc.d.ts +45 -0
  123. package/lib/types/host/runs/files.d.ts +37 -0
  124. package/lib/types/host/runs/notice.d.ts +21 -0
  125. package/lib/types/host/runs/service.d.ts +258 -0
  126. package/lib/types/host/runs/skill.d.ts +16 -0
  127. package/lib/types/host/runs/storage.d.ts +16 -0
  128. package/lib/types/host/runs/store.d.ts +56 -0
  129. package/lib/types/host/skillView.d.ts +22 -0
  130. package/lib/types/host/store/atomic.d.ts +34 -0
  131. package/lib/types/host/store/materialize.d.ts +19 -0
  132. package/lib/types/host/store/merge.d.ts +25 -0
  133. package/lib/types/host/store/paths.d.ts +86 -0
  134. package/lib/types/host/store/repository.d.ts +217 -0
  135. package/lib/types/host/store/versions.d.ts +38 -0
  136. package/lib/types/host/tool/tool.d.ts +432 -0
  137. package/lib/types/index.d.ts +35 -0
  138. package/lib/types/shared/appearance.d.ts +49 -0
  139. package/lib/types/shared/compile.d.ts +71 -0
  140. package/lib/types/shared/graph.d.ts +54 -0
  141. package/lib/types/shared/graphDiff.d.ts +29 -0
  142. package/lib/types/shared/inputs.d.ts +46 -0
  143. package/lib/types/shared/limits.d.ts +77 -0
  144. package/lib/types/shared/model.d.ts +122 -0
  145. package/lib/types/shared/naming.d.ts +59 -0
  146. package/lib/types/shared/outputPaths.d.ts +49 -0
  147. package/lib/types/shared/resources.d.ts +98 -0
  148. package/lib/types/shared/runCursor.d.ts +54 -0
  149. package/lib/types/shared/runState.d.ts +221 -0
  150. package/lib/types/shared/runSync.d.ts +24 -0
  151. package/lib/types/shared/types.d.ts +488 -0
  152. package/lib/types/shared/validate.d.ts +54 -0
  153. package/lib/types/shared/wire.d.ts +600 -0
  154. package/locale/en.json +6 -0
  155. package/locale/zh.json +6 -0
  156. package/package.json +144 -4
@@ -0,0 +1,488 @@
1
+ /**
2
+ * dsh-workflow-lite — 文件格式、线格式与校验词汇表。
3
+ *
4
+ * 事实源是 `workflows/<图名>.json`:React Flow 原生三件套 `{ nodes, edges, viewport }`
5
+ * 加我们自己的 `data`。本模块**只放类型与常量,不 import 任何 DSH 包、不含副作用**,
6
+ * 好让 host / client / 单测三边直接共用。
7
+ *
8
+ * @module @xiaoso/dsh-workflow-lite/shared/types
9
+ */
10
+ /** 步骤节点的类型标记。读到未知 `type` 按步骤渲染并报**警告**。 */
11
+ export declare const NODE_TYPE = "wfNode";
12
+ /**
13
+ * 资源节点的类型标记:一组给步骤用的东西(文件、文件夹、网址、Skill、自定义)。
14
+ * 步骤写它(步骤 → 资源,写的是其中的文件与文件夹)、读它(资源 → 步骤)。
15
+ */
16
+ export declare const RESOURCE_TYPE = "wfResource";
17
+ /** 输入节点的类型标记:执行前问用户的一个问题,连到用得着回答的步骤上(输入 → 步骤)。 */
18
+ export declare const INPUT_TYPE = "wfInput";
19
+ /** 一张图 = 一个 JSON 的顶层形状(React Flow 原生三件套 + 可选的工作流设置)。 */
20
+ export interface WorkflowDocument {
21
+ nodes: WorkflowNode[];
22
+ edges: WorkflowEdge[];
23
+ viewport: Viewport;
24
+ /** 整张工作流的设置;全是缺省值时整键不写(老文件不受影响)。 */
25
+ settings?: WorkflowSettings;
26
+ }
27
+ /**
28
+ * 执行方式:
29
+ * - `auto` 不规定,由主 agent 自己决定(缺省);
30
+ * - `serial` 主 agent 本人逐个执行;
31
+ * - `subagent` 主 agent 当 leader,每个节点派一个子代理;
32
+ * - `team` 主 agent 当 Team Lead,节点交给 Agent Team 的队员。
33
+ */
34
+ export declare const EXECUTION_MODES: readonly ["auto", "serial", "subagent", "team"];
35
+ export type ExecutionMode = (typeof EXECUTION_MODES)[number];
36
+ /**
37
+ * 复用执行者:同一个步骤再次执行时(循环的下一轮、重试、中断后继续)交给谁。
38
+ * - `auto` 不规定(缺省);
39
+ * - `reuse` 交回上次做它的那个子代理或队员,接着之前的上下文;
40
+ * - `fresh` 每次都派新的,上下文干净。
41
+ * 串行时没有执行者,这一项不进计划。
42
+ */
43
+ export declare const REUSE_POLICIES: readonly ["auto", "reuse", "fresh"];
44
+ export type ReusePolicy = (typeof REUSE_POLICIES)[number];
45
+ export interface WorkflowSettings {
46
+ /**
47
+ * 产出根目录:相对路径(相对工作区)或绝对路径,存规范化后的写法(`shared/outputPaths.ts`)。
48
+ * 编译时每个产出文件都拼在它下面。缺省 = 工作区根。
49
+ */
50
+ outputRoot?: string;
51
+ /** 执行方式;缺省 = `auto`(`auto` 不写盘)。 */
52
+ mode?: Exclude<ExecutionMode, 'auto'>;
53
+ /** 复用执行者;缺省 = `auto`(`auto` 不写盘)。 */
54
+ reuse?: Exclude<ReusePolicy, 'auto'>;
55
+ /**
56
+ * 设定目标:计划开头让主 agent 先用 `create_goal` 把这次执行设成会话目标,做完标记完成。
57
+ * 缺省 = 开(开时不写盘,只存关掉的 `false`)。
58
+ */
59
+ setGoal?: false;
60
+ /**
61
+ * 记录运行状态:打开后每次编译建一个工作流实例,带一份由主 agent 维护的 YAML 状态文件
62
+ * 缺省 = 关(关时不写盘)。
63
+ */
64
+ runState?: true;
65
+ }
66
+ export interface Viewport {
67
+ x: number;
68
+ y: number;
69
+ zoom: number;
70
+ }
71
+ export interface Point {
72
+ x: number;
73
+ y: number;
74
+ }
75
+ /** 图里的节点:步骤、资源,或输入。 */
76
+ export type WorkflowNode = StepNode | ResourceNode | InputNode;
77
+ export interface StepNode {
78
+ /** 身份,**创建后不可改**;同时是载荷文件名 ⇒ 受文件名约束。图内**大小写不敏感唯一**。 */
79
+ id: string;
80
+ type: typeof NODE_TYPE;
81
+ /** **存盘**。缺失(或 `(0,0)`)→ 布局补位并回写,不算保存级。 */
82
+ position: Point;
83
+ data: NodeData;
84
+ }
85
+ /**
86
+ * 资源节点:一组独立于某一次运行的东西,几个步骤可以先后写它、读它。一个资源里可以放好几项。
87
+ * `id` 与步骤共用一个命名空间(图内大小写不敏感唯一),但不产生载荷文件。
88
+ * 一条线都没连的资源交给整个工作流(每个步骤都能用)。
89
+ */
90
+ export interface ResourceNode {
91
+ id: string;
92
+ type: typeof RESOURCE_TYPE;
93
+ position: Point;
94
+ data: ResourceData;
95
+ }
96
+ /**
97
+ * 资源里一项的种类:
98
+ * - `file` 文件、`folder` 文件夹:`value` 是路径。绝对路径原样用;相对路径在有步骤写这个资源时
99
+ * 放在产出根目录下,只被读时相对工作区(见 `shared/outputPaths.ts` 的 `resolveItemPath`);
100
+ * - `url` 网址;`skill` DSH 能识别的 skill 名;`text` 自定义(一段原样交给执行者的提示词)。
101
+ */
102
+ export declare const RESOURCE_KINDS: readonly ["file", "folder", "url", "skill", "text"];
103
+ export type ResourceKind = (typeof RESOURCE_KINDS)[number];
104
+ /** 步骤能写的种类(其余的只能读)。 */
105
+ export declare const WRITABLE_KINDS: readonly ResourceKind[];
106
+ export interface ResourceItem {
107
+ kind: ResourceKind;
108
+ /** 路径 / 网址 / skill 名 / 自定义的正文。空 = 编译级。 */
109
+ value: string;
110
+ /** 这一项怎么用(写文件时是生成要求)。进计划;`text` 不用它。 */
111
+ note?: string;
112
+ }
113
+ export interface ResourceData {
114
+ /** 名字:卡片标题,也是计划里称呼它的方式。缺省回落成内容摘要。**不得含换行或 `|`**。 */
115
+ label?: string;
116
+ /** 一句话描述(给人看:卡片上显示)。**不进计划**。 */
117
+ description?: string;
118
+ /** 内容,按添加顺序。 */
119
+ items: ResourceItem[];
120
+ }
121
+ /**
122
+ * 输入节点:执行前问用户的一个问题。用户点「执行」时先填好它们,编译时**问题与回答**进计划,
123
+ * 占位与说明只给填写的人看,不进计划。
124
+ * `id` 与步骤、文件共用一个命名空间,但不产生载荷文件。
125
+ */
126
+ export interface InputNode {
127
+ id: string;
128
+ type: typeof INPUT_TYPE;
129
+ position: Point;
130
+ data: InputData;
131
+ }
132
+ /** 输入的交互方式:单行文字 / 多行文字 / 单选 / 多选。 */
133
+ export declare const INPUT_KINDS: readonly ["text", "textarea", "choice", "multi"];
134
+ export type InputKind = (typeof INPUT_KINDS)[number];
135
+ /** 一份回答:文字题与单选是一段文字,多选是选中的那几项(按选项顺序)。 */
136
+ export type InputAnswer = string | string[];
137
+ export interface InputData {
138
+ /** 问题:原样进计划。空 = 编译级。**不得含换行**。 */
139
+ question: string;
140
+ /** 交互方式;缺省 = `text`(`text` 不写盘)。 */
141
+ kind?: Exclude<InputKind, 'text'>;
142
+ /** 选项(单选 / 多选用;其余方式不写)。 */
143
+ options?: string[];
144
+ /** 默认值:文字题是预填的文字,单选是一个选项,多选是若干选项。用户没改就用它。 */
145
+ default?: InputAnswer;
146
+ /** 占位:输入框里的灰字。不进计划。 */
147
+ placeholder?: string;
148
+ /** 说明:填写时显示在问题下面。不进计划。 */
149
+ hint?: string;
150
+ /** 必填:没有回答(也没有默认值)时不能执行。 */
151
+ required?: true;
152
+ }
153
+ export interface NodeData {
154
+ /** 显示名。不要求唯一、不参与寻址与排序;缺省或空串时回落渲染 `id`。**不得含换行或 `|`**。 */
155
+ label?: string;
156
+ /** 一句话说明这一步做什么(给人看:步骤库、卡片)。**不进计划**,也不进载荷。 */
157
+ description?: string;
158
+ /** 卡片上的图标(图标库里的名字,见 `shared/appearance.ts`);缺省按 id 猜。不进计划。 */
159
+ icon?: string;
160
+ /** 卡片的颜色(色板里的名字);缺省按 id 猜。不进计划。 */
161
+ color?: string;
162
+ /** 提示词正文,逐字交给执行者。**缺失或为空串 = 编译级**(允许落盘、阻塞编译)。 */
163
+ prompt?: string;
164
+ /**
165
+ * 产出契约——**只在步骤模板里用**(模板放到画布上时展开成资源节点,每个产出一个文件项);
166
+ * 图里的产出是资源节点。
167
+ * - 字符串 = 一个产出文件;数组 = 一个或多个,每个可带生成规则;`false` = 不产出文件。
168
+ */
169
+ output?: string | false | OutputSpec[];
170
+ }
171
+ /** 一个产出:文件路径(相对工作区根)+ 可选的生成规则。 */
172
+ export interface OutputSpec {
173
+ path: string;
174
+ /** 这份产出该怎么写:格式、必须包含什么、给谁看。 */
175
+ rule?: string;
176
+ }
177
+ export interface WorkflowEdge {
178
+ /** 由工具按构造式生成:`<source>-><target>`,带 `when` 时追加 `#<when>`。 */
179
+ id: string;
180
+ source: string;
181
+ target: string;
182
+ /** 恒为 `null`,但**一律写出**(保持 React Flow 原生形状;不在"缺省整键省略"之列)。 */
183
+ sourceHandle: null;
184
+ targetHandle: null;
185
+ data?: EdgeData;
186
+ }
187
+ export interface EdgeData {
188
+ /** 条件出边的判据;**缺省 = 无条件边**(可以有多条 ⇒ 并行扇出)。空串 = 保存级。 */
189
+ when?: string;
190
+ /** 作者手写的语义短标签,不参与任何判定。 */
191
+ label?: string;
192
+ /**
193
+ * 交接(只用在步骤 → 步骤的线上):上游这一次的执行结果交不交给下游。
194
+ * - 缺省 = 交:把上游回复里的结论与要点交给下游;
195
+ * - 对象 = 交,并附一段交接说明(下游拿到之后怎么用);
196
+ * - `false` = 只管先后,什么都不交。
197
+ * 资源不走这里——资源是独立的节点,谁写谁读看连到它的线。
198
+ */
199
+ handoff?: Handoff | false;
200
+ /**
201
+ * 写入方式(只用在步骤 → 资源的线上):缺省 = 产出(整份写出 / 覆盖);
202
+ * `true` = 在原文件上更新(先读再改,比如修完在问题清单里打钩)。
203
+ */
204
+ update?: true;
205
+ }
206
+ /** 交接说明(空白说明的规范写法是"不写",即缺省)。 */
207
+ export interface Handoff {
208
+ note: string;
209
+ }
210
+ /** 顶层键序(canonical writer 与白名单的唯一口径)。 */
211
+ export declare const DOCUMENT_KEYS: readonly ["nodes", "edges", "viewport", "settings"];
212
+ /** node 的写出键序。 */
213
+ export declare const NODE_KEYS: readonly ["id", "type", "position", "data"];
214
+ /** edge 的写出键序。 */
215
+ export declare const EDGE_KEYS: readonly ["id", "source", "target", "sourceHandle", "targetHandle", "data"];
216
+ /** `templates/nodes/<模板名>.json` —— **一个节点的 `data` 本体**(不带 `id` / `position`)。 */
217
+ export type NodeTemplate = NodeData;
218
+ /** 一次编译的内容寻址标识:图内容哈希前 8 位。同内容 ⇒ 同 planId ⇒ 幂等覆盖。 */
219
+ export type PlanId = string;
220
+ /** 载荷路径形态:`.dispatch/<图名>/<planId>/<节点 id>.md`(派生物,可随时删)。 */
221
+ export interface PayloadPath {
222
+ nodeId: string;
223
+ /** 绝对路径。 */
224
+ path: string;
225
+ }
226
+ /** 编译器(纯函数)的输入。 */
227
+ export interface PlanFacts {
228
+ name: string;
229
+ document: WorkflowDocument;
230
+ /** 本次目标;缺省时 ⑤ 段不写这一行。 */
231
+ goal?: string;
232
+ /** 工作区路径(= ⑤ 段的 cwd);取不到时 ⑤ 渲染「工作区路径:未指定」。 */
233
+ cwd?: string;
234
+ /** 工作流实例 id(预览时是 `{instance}`);不给就不写。 */
235
+ instance?: string;
236
+ /**
237
+ * 用户对输入节点的回答(输入 id → 回答)。**不给 = 预览**:问题照写,回答处写「执行时填写」;
238
+ * 给了(哪怕是空对象)= 真的要执行:没回答的用默认值,必填的还空着就是编译级。
239
+ */
240
+ answers?: Readonly<Record<string, InputAnswer>>;
241
+ /** 路径映射:节点 id → 绝对载荷路径(host 侧算好注入,编译器本身不碰磁盘)。 */
242
+ payloadPaths: ReadonlyMap<string, string>;
243
+ }
244
+ /** 编译器(纯函数)的产物。 */
245
+ export interface PlanResult {
246
+ plan: string;
247
+ problems: ValidationProblem[];
248
+ }
249
+ /**
250
+ * 四级。
251
+ * - `save` 拒绝加载 / 拒绝写入
252
+ * - `compile` 允许落盘、**阻塞编译**
253
+ * - `warning` / `hint` 不阻塞任何操作
254
+ */
255
+ export type ValidationLevel = 'save' | 'compile' | 'warning' | 'hint';
256
+ /** 可判定的机器码;文案由 UI / 工具各自本地化。 */
257
+ export type ValidationCode = 'json_parse_failed' | 'schema_invalid' | 'node_id_missing' | 'node_id_duplicate' | 'node_id_case_collision' | 'edge_field_missing' | 'edge_dangling' | 'edge_id_duplicate' | 'when_invalid' | 'label_invalid' | 'output_invalid' | 'name_invalid' | 'workflow_dir_collision' | 'settings_invalid' | 'handoff_invalid' | 'resource_edge_invalid' | 'resource_invalid' | 'input_invalid' | 'prompt_empty' | 'too_many_nodes' | 'no_nodes' | 'input_question_empty' | 'input_options_empty' | 'input_missing' | 'resource_empty' | 'resource_item_empty' | 'resource_unwritable' | 'loop_without_exit' | 'mixed_conditional_edges' | 'duplicate_edge' | 'shared_output' | 'resource_overwritten' | 'input_default_invalid' | 'unknown_node_type' | 'unknown_fields_dropped' | 'branch_not_exhaustive' | 'freeform_when' | 'multi_back_edges' | 'resource_order' | 'resource_unread' | 'stray_entry' | 'position_filled' | 'legacy_structure' | 'invalid_template';
258
+ export interface ValidationProblem {
259
+ level: ValidationLevel;
260
+ code: ValidationCode;
261
+ message: string;
262
+ /** 归属的节点 id(有归属时)。 */
263
+ node?: string;
264
+ /** 归属的边 id(有归属时)。 */
265
+ edge?: string;
266
+ }
267
+ export declare const TOOL_NAME = "workflow_lite";
268
+ export declare const ACTIONS: readonly ["list", "read", "compile", "create", "write_node", "set_label", "delete_node", "connect", "disconnect", "rename_workflow", "delete_workflow", "save_as_template", "configure", "write_resource", "runs", "resume", "state"];
269
+ export type Action = (typeof ACTIONS)[number];
270
+ /** 失败码只有五个。 */
271
+ export type ErrorCode = 'not_found' | 'invalid_args' | 'blocked' | 'conflict' | 'io_error';
272
+ /** 变更摘要条目。 */
273
+ export interface ChangedEntry {
274
+ kind: 'workflow' | 'node' | 'edge';
275
+ op: 'add' | 'update' | 'delete' | 'rename';
276
+ id: string;
277
+ /** 该条变更的细节(例如被连带删掉的 `edge.id` 清单)。 */
278
+ detail?: Record<string, unknown>;
279
+ }
280
+ /** 非阻塞信息(警告与提示共用一条通道,带 `level` 区分)。 */
281
+ export interface ToolWarning {
282
+ level: 'warning' | 'hint';
283
+ code: ValidationCode;
284
+ message: string;
285
+ nodes?: string[];
286
+ workflows?: string[];
287
+ }
288
+ export interface ToolError {
289
+ error: {
290
+ code: ErrorCode;
291
+ message: string;
292
+ /** 结构化补充:跨文件操作的「已改 N / 未改 M」清单、解析错误的行列与片段等。 */
293
+ detail?: Record<string, unknown>;
294
+ };
295
+ }
296
+ /** 模板条目的状态标记(`list` 用)。 */
297
+ export interface TemplateEntry {
298
+ name: string;
299
+ invalid?: true;
300
+ reason?: string;
301
+ /** 节点模板的一句话描述(有才给)。 */
302
+ description?: string;
303
+ /** 节点模板选的图标与颜色(有才给)。 */
304
+ icon?: string;
305
+ color?: string;
306
+ }
307
+ export interface WorkflowEntry {
308
+ name: string;
309
+ nodeCount: number;
310
+ /** 那份 JSON 的 mtime(选择器"最近修改"的判据)。 */
311
+ updatedAt: number;
312
+ invalid?: true;
313
+ reason?: string;
314
+ /** 存下的版本数(有才给)。 */
315
+ versions?: number;
316
+ }
317
+ /** 工作流的一个版本(`versions/<图名>/<序号>.json`)。 */
318
+ export interface VersionEntry {
319
+ /** 序号:v1、v2……新存的接着现有最大的往上数。 */
320
+ n: number;
321
+ /** 存下的时间(毫秒时间戳)。 */
322
+ createdAt: number;
323
+ /** 说明;没写是空串。 */
324
+ note: string;
325
+ /** 切换到别的版本之前自动存的那份:切到的是哪个版本。 */
326
+ autoBefore?: number;
327
+ nodeCount: number;
328
+ /** 内容和磁盘上现在的工作流一样。 */
329
+ current: boolean;
330
+ /** 文件坏了读不出来(只能删)。 */
331
+ invalid?: true;
332
+ }
333
+ export interface ListResult {
334
+ workflows: WorkflowEntry[];
335
+ templates: {
336
+ nodes: TemplateEntry[];
337
+ };
338
+ warnings: ToolWarning[];
339
+ }
340
+ /** `read` 不给 `node` 时的索引——**绝不含 `prompt`**。 */
341
+ export interface NodeIndexEntry {
342
+ id: string;
343
+ label?: string;
344
+ /** 前置步骤(含回边)的 `id`,按 `id` 码位序。 */
345
+ predecessors: string[];
346
+ /** 它读的资源(资源 id)。 */
347
+ reads?: string[];
348
+ /** 它写的资源(资源 id;`update` = 在原文件上更新)。 */
349
+ writes?: {
350
+ id: string;
351
+ update?: true;
352
+ }[];
353
+ /** 交给它的用户输入(输入节点 id)。 */
354
+ inputs?: string[];
355
+ }
356
+ /** 索引里的一个输入节点(不含占位与说明——那是给填写的人看的)。 */
357
+ export interface InputIndexEntry {
358
+ id: string;
359
+ question: string;
360
+ kind: InputKind;
361
+ options?: string[];
362
+ default?: InputAnswer;
363
+ required?: true;
364
+ /** 回答交给哪些步骤;空 = 交给整个工作流。 */
365
+ readers: string[];
366
+ }
367
+ /** 索引里的一个资源节点(不含描述——那是给人看的)。 */
368
+ export interface ResourceIndexEntry {
369
+ id: string;
370
+ label?: string;
371
+ items: ResourceItem[];
372
+ /** 写它的步骤 id(`update` = 在原文件上更新)。 */
373
+ writers: {
374
+ id: string;
375
+ update?: true;
376
+ }[];
377
+ /** 读它的步骤 id;写读都没有 = 交给整个工作流。 */
378
+ readers: string[];
379
+ }
380
+ export interface ReadIndexResult {
381
+ workflow: string;
382
+ viewport: Viewport;
383
+ /** 工作流设置(有才给)。 */
384
+ settings?: WorkflowSettings;
385
+ nodes: NodeIndexEntry[];
386
+ /** 资源节点(有才给)。 */
387
+ resources?: ResourceIndexEntry[];
388
+ /** 输入节点(有才给),按画布上从上到下的顺序。 */
389
+ inputs?: InputIndexEntry[];
390
+ /** 阻塞编译的问题(有才给)。 */
391
+ problems?: ValidationProblem[];
392
+ warnings: ToolWarning[];
393
+ }
394
+ /** `read` 给了 `node=<id>` 时的单节点详情——这里才有正文。 */
395
+ export interface ReadNodeResult {
396
+ workflow: string;
397
+ node: WorkflowNode;
398
+ /** 该节点的出边(按 `id` 码位序)。 */
399
+ edges: WorkflowEdge[];
400
+ warnings: ToolWarning[];
401
+ }
402
+ export interface WriteResult {
403
+ changed: ChangedEntry[];
404
+ warnings: ToolWarning[];
405
+ }
406
+ export interface CompileResult {
407
+ plan: string;
408
+ /** **只在 `compile` 里出现**,只装编译级问题。 */
409
+ problems: ValidationProblem[];
410
+ warnings: ToolWarning[];
411
+ planId: PlanId;
412
+ }
413
+ /** 工具的成功返回联合。 */
414
+ export type ToolSuccess = {
415
+ action: 'list';
416
+ result: ListResult;
417
+ } | {
418
+ action: 'read';
419
+ result: ReadIndexResult | ReadNodeResult;
420
+ } | {
421
+ action: 'compile';
422
+ result: CompileResult;
423
+ } | {
424
+ action: 'create';
425
+ result: WriteResult;
426
+ } | {
427
+ action: 'write_node';
428
+ result: WriteResult;
429
+ } | {
430
+ action: 'set_label';
431
+ result: WriteResult;
432
+ } | {
433
+ action: 'delete_node';
434
+ result: WriteResult;
435
+ } | {
436
+ action: 'connect';
437
+ result: WriteResult;
438
+ } | {
439
+ action: 'disconnect';
440
+ result: WriteResult;
441
+ } | {
442
+ action: 'rename_workflow';
443
+ result: WriteResult;
444
+ } | {
445
+ action: 'delete_workflow';
446
+ result: WriteResult;
447
+ } | {
448
+ action: 'save_as_template';
449
+ result: WriteResult;
450
+ } | {
451
+ action: 'configure';
452
+ result: WriteResult;
453
+ } | {
454
+ action: 'write_resource';
455
+ result: WriteResult;
456
+ } | {
457
+ action: 'runs';
458
+ result: unknown;
459
+ } | {
460
+ action: 'resume';
461
+ result: unknown;
462
+ };
463
+ /** 出边的四种形态。 */
464
+ export type EdgeShape =
465
+ /** 只有一条出边 */
466
+ 'sequence'
467
+ /** 多条出边,**全都**没有 `when` ⇒ 全部都会走 */
468
+ | 'fanout'
469
+ /** 多条出边,**全都**有 `when` ⇒ 只走成立的那一条 */
470
+ | 'branch'
471
+ /** 混用 ⇒ 有歧义,警告 */
472
+ | 'mixed';
473
+ /** 一个强连通分量=一个循环体。 */
474
+ export interface CycleGroup {
475
+ /** 该 SCC 内的节点 id,按批次序、同批次按 `id` 码位序。 */
476
+ nodes: string[];
477
+ /** 该 SCC 内的回边 id(SCC 内 DFS 指向栈上祖先的边;自环也算)。 */
478
+ backEdges: string[];
479
+ /** 被环外入边指向的入口节点;没有环外入边时按语义挑最像起点的(见 `graph.ts` 的 `loopStart`)。 */
480
+ entry: string;
481
+ /** 环上指向环外的条件边 id ⇒ 有出口;空 ⇒ 循环体没有出口(警告)。 */
482
+ exits: string[];
483
+ }
484
+ /** 执行批次:一批可并行的节点。 */
485
+ export interface ExecutionBatch {
486
+ /** 节点 id,按 `id` 码位序。 */
487
+ nodes: string[];
488
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * dsh-workflow-lite — 四级校验。
3
+ *
4
+ * **本节是校验级别的唯一出处**。四条级别的语义:
5
+ * - **保存级**:结构性破损——拒绝加载 / 拒绝写入。JSON 不合法一律走这里,
6
+ * 新结构没有"坏一个节点"这回事。
7
+ * - **编译级**:语义问题——**允许落盘**(画布标红),但**阻塞编译**。
8
+ * - **警告** / **提示**:不阻塞任何操作,走同一条 `warnings` 通道、带 `level` 区分。
9
+ *
10
+ * 处理性失败(IO 中断、写前哈希冲突、物化失败)**不是校验级别**,不进这里。
11
+ *
12
+ * 纯函数,不碰磁盘、不 import DSH 包。
13
+ * @module @xiaoso/dsh-workflow-lite/shared/validate
14
+ */
15
+ import { type GraphAnalysis } from './graph.ts';
16
+ import type { ResourceData, ResourceItem, ValidationProblem, WorkflowDocument } from './types.ts';
17
+ export interface ValidateOptions {
18
+ /** 图名——校验文件名约束用。 */
19
+ workflowName: string;
20
+ /** 单图节点数上限(`Config.maxNodes`)。 */
21
+ maxNodes: number;
22
+ /** `workflows/` 下存在同名**目录**(md 版遗留)——算撞名占位。 */
23
+ dirCollision?: boolean;
24
+ }
25
+ export interface ValidationReport {
26
+ save: ValidationProblem[];
27
+ compile: ValidationProblem[];
28
+ warning: ValidationProblem[];
29
+ hint: ValidationProblem[];
30
+ /** 保存级为空才能加载。 */
31
+ canLoad: boolean;
32
+ /** 编译级为空才能出计划。 */
33
+ canCompile: boolean;
34
+ }
35
+ /**
36
+ * 校验一张图。
37
+ * @param document - 已规范化的文档。
38
+ * @param options - 图名与上限。
39
+ * @param extra - 读入阶段已报出的问题(未知 `type`/字段、坐标补位、viewport 回落、
40
+ * 旧结构检测…),按级别合进结果,避免上层再分拣一遍。
41
+ */
42
+ export declare function validateDocument(document: WorkflowDocument, options: ValidateOptions, extra?: readonly ValidationProblem[], analysis?: GraphAnalysis): ValidationReport;
43
+ /** 资源里一项的写法与长度(保存级)。属性面板的编辑框也拿它当场提示。 */
44
+ export declare function itemProblem(item: ResourceItem): {
45
+ message: string;
46
+ } | null;
47
+ /** 资源节点的字段规则(保存级):名字、描述、每一项的写法与长度、项数。 */
48
+ export declare function resourceProblem(data: ResourceData): {
49
+ message: string;
50
+ } | null;
51
+ /** 把一份报告摊平成一条通道(`warnings` 用;`problems` 只装编译级,见 8.2)。 */
52
+ export declare function toWarnings(report: ValidationReport): Array<{
53
+ level: 'warning' | 'hint';
54
+ } & ValidationProblem>;