@marktoflow/gui 2.0.0-alpha.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.
Files changed (165) hide show
  1. package/.turbo/turbo-build.log +26 -0
  2. package/.turbo/turbo-test.log +22 -0
  3. package/README.md +179 -0
  4. package/dist/client/assets/index-DwTI8opO.js +608 -0
  5. package/dist/client/assets/index-DwTI8opO.js.map +1 -0
  6. package/dist/client/assets/index-RoEdL6gO.css +1 -0
  7. package/dist/client/index.html +20 -0
  8. package/dist/client/vite.svg +9 -0
  9. package/dist/server/index.d.ts +3 -0
  10. package/dist/server/index.d.ts.map +1 -0
  11. package/dist/server/index.js +56 -0
  12. package/dist/server/index.js.map +1 -0
  13. package/dist/server/routes/ai.js +50 -0
  14. package/dist/server/routes/ai.js.map +1 -0
  15. package/dist/server/routes/execute.js +62 -0
  16. package/dist/server/routes/execute.js.map +1 -0
  17. package/dist/server/routes/workflows.js +99 -0
  18. package/dist/server/routes/workflows.js.map +1 -0
  19. package/dist/server/server/index.js +95 -0
  20. package/dist/server/server/index.js.map +1 -0
  21. package/dist/server/server/routes/ai.js +87 -0
  22. package/dist/server/server/routes/ai.js.map +1 -0
  23. package/dist/server/server/routes/execute.js +63 -0
  24. package/dist/server/server/routes/execute.js.map +1 -0
  25. package/dist/server/server/routes/tools.js +518 -0
  26. package/dist/server/server/routes/tools.js.map +1 -0
  27. package/dist/server/server/routes/workflows.js +99 -0
  28. package/dist/server/server/routes/workflows.js.map +1 -0
  29. package/dist/server/server/services/AIService.js +69 -0
  30. package/dist/server/server/services/AIService.js.map +1 -0
  31. package/dist/server/server/services/FileWatcher.js +60 -0
  32. package/dist/server/server/services/FileWatcher.js.map +1 -0
  33. package/dist/server/server/services/WorkflowService.js +363 -0
  34. package/dist/server/server/services/WorkflowService.js.map +1 -0
  35. package/dist/server/server/services/agents/claude-code-provider.js +250 -0
  36. package/dist/server/server/services/agents/claude-code-provider.js.map +1 -0
  37. package/dist/server/server/services/agents/claude-provider.js +204 -0
  38. package/dist/server/server/services/agents/claude-provider.js.map +1 -0
  39. package/dist/server/server/services/agents/copilot-provider.js +227 -0
  40. package/dist/server/server/services/agents/copilot-provider.js.map +1 -0
  41. package/dist/server/server/services/agents/demo-provider.js +167 -0
  42. package/dist/server/server/services/agents/demo-provider.js.map +1 -0
  43. package/dist/server/server/services/agents/index.js +31 -0
  44. package/dist/server/server/services/agents/index.js.map +1 -0
  45. package/dist/server/server/services/agents/ollama-provider.js +220 -0
  46. package/dist/server/server/services/agents/ollama-provider.js.map +1 -0
  47. package/dist/server/server/services/agents/prompts.js +436 -0
  48. package/dist/server/server/services/agents/prompts.js.map +1 -0
  49. package/dist/server/server/services/agents/registry.js +242 -0
  50. package/dist/server/server/services/agents/registry.js.map +1 -0
  51. package/dist/server/server/services/agents/types.js +6 -0
  52. package/dist/server/server/services/agents/types.js.map +1 -0
  53. package/dist/server/server/websocket/index.js +85 -0
  54. package/dist/server/server/websocket/index.js.map +1 -0
  55. package/dist/server/services/AIService.d.ts +30 -0
  56. package/dist/server/services/AIService.d.ts.map +1 -0
  57. package/dist/server/services/AIService.js +216 -0
  58. package/dist/server/services/AIService.js.map +1 -0
  59. package/dist/server/services/FileWatcher.d.ts +10 -0
  60. package/dist/server/services/FileWatcher.d.ts.map +1 -0
  61. package/dist/server/services/FileWatcher.js +62 -0
  62. package/dist/server/services/FileWatcher.js.map +1 -0
  63. package/dist/server/services/WorkflowService.d.ts +54 -0
  64. package/dist/server/services/WorkflowService.d.ts.map +1 -0
  65. package/dist/server/services/WorkflowService.js +323 -0
  66. package/dist/server/services/WorkflowService.js.map +1 -0
  67. package/dist/server/shared/constants.js +175 -0
  68. package/dist/server/shared/constants.js.map +1 -0
  69. package/dist/server/shared/types.js +3 -0
  70. package/dist/server/shared/types.js.map +1 -0
  71. package/dist/server/websocket/index.d.ts +10 -0
  72. package/dist/server/websocket/index.d.ts.map +1 -0
  73. package/dist/server/websocket/index.js +85 -0
  74. package/dist/server/websocket/index.js.map +1 -0
  75. package/index.html +19 -0
  76. package/package.json +96 -0
  77. package/playwright.config.ts +27 -0
  78. package/postcss.config.js +6 -0
  79. package/public/vite.svg +9 -0
  80. package/src/client/App.tsx +520 -0
  81. package/src/client/components/Canvas/Canvas.tsx +405 -0
  82. package/src/client/components/Canvas/ExecutionOverlay.tsx +847 -0
  83. package/src/client/components/Canvas/NodeContextMenu.tsx +188 -0
  84. package/src/client/components/Canvas/OutputNode.tsx +111 -0
  85. package/src/client/components/Canvas/StepNode.tsx +106 -0
  86. package/src/client/components/Canvas/SubWorkflowNode.tsx +141 -0
  87. package/src/client/components/Canvas/Toolbar.tsx +189 -0
  88. package/src/client/components/Canvas/TriggerNode.tsx +128 -0
  89. package/src/client/components/Editor/InputsEditor.tsx +458 -0
  90. package/src/client/components/Editor/NewStepWizard.tsx +344 -0
  91. package/src/client/components/Editor/StepEditor.tsx +532 -0
  92. package/src/client/components/Editor/YamlEditor.tsx +160 -0
  93. package/src/client/components/Panels/PropertiesPanel.tsx +589 -0
  94. package/src/client/components/Prompt/ChangePreview.tsx +281 -0
  95. package/src/client/components/Prompt/PromptHistoryPanel.tsx +209 -0
  96. package/src/client/components/Prompt/PromptInput.tsx +108 -0
  97. package/src/client/components/Sidebar/Sidebar.tsx +343 -0
  98. package/src/client/components/common/Breadcrumb.tsx +40 -0
  99. package/src/client/components/common/Button.tsx +68 -0
  100. package/src/client/components/common/ContextMenu.tsx +202 -0
  101. package/src/client/components/common/KeyboardShortcuts.tsx +143 -0
  102. package/src/client/components/common/Modal.tsx +93 -0
  103. package/src/client/components/common/Tabs.tsx +57 -0
  104. package/src/client/components/common/ThemeToggle.tsx +63 -0
  105. package/src/client/components/index.ts +32 -0
  106. package/src/client/hooks/index.ts +4 -0
  107. package/src/client/hooks/useAIPrompt.ts +108 -0
  108. package/src/client/hooks/useCanvas.ts +247 -0
  109. package/src/client/hooks/useWebSocket.ts +164 -0
  110. package/src/client/hooks/useWorkflow.ts +138 -0
  111. package/src/client/main.tsx +10 -0
  112. package/src/client/stores/canvasStore.ts +348 -0
  113. package/src/client/stores/editorStore.ts +133 -0
  114. package/src/client/stores/executionStore.ts +440 -0
  115. package/src/client/stores/index.ts +4 -0
  116. package/src/client/stores/layoutStore.ts +103 -0
  117. package/src/client/stores/navigationStore.ts +49 -0
  118. package/src/client/stores/promptStore.ts +113 -0
  119. package/src/client/stores/themeStore.ts +75 -0
  120. package/src/client/stores/workflowStore.ts +177 -0
  121. package/src/client/styles/globals.css +346 -0
  122. package/src/client/utils/cn.ts +9 -0
  123. package/src/client/utils/index.ts +4 -0
  124. package/src/client/utils/serviceIcons.tsx +64 -0
  125. package/src/client/utils/stepValidation.ts +155 -0
  126. package/src/client/utils/workflowToGraph.ts +299 -0
  127. package/src/server/index.ts +114 -0
  128. package/src/server/routes/ai.ts +91 -0
  129. package/src/server/routes/execute.ts +71 -0
  130. package/src/server/routes/tools.ts +564 -0
  131. package/src/server/routes/workflows.ts +106 -0
  132. package/src/server/services/AIService.ts +105 -0
  133. package/src/server/services/FileWatcher.ts +69 -0
  134. package/src/server/services/WorkflowService.ts +441 -0
  135. package/src/server/services/agents/claude-code-provider.ts +320 -0
  136. package/src/server/services/agents/claude-provider.ts +248 -0
  137. package/src/server/services/agents/copilot-provider.ts +311 -0
  138. package/src/server/services/agents/demo-provider.ts +184 -0
  139. package/src/server/services/agents/index.ts +31 -0
  140. package/src/server/services/agents/ollama-provider.ts +267 -0
  141. package/src/server/services/agents/prompts.ts +482 -0
  142. package/src/server/services/agents/registry.ts +289 -0
  143. package/src/server/services/agents/types.ts +146 -0
  144. package/src/server/websocket/index.ts +104 -0
  145. package/src/shared/constants.ts +180 -0
  146. package/src/shared/types.ts +179 -0
  147. package/tailwind.config.ts +73 -0
  148. package/tests/e2e/app.spec.ts +90 -0
  149. package/tests/e2e/canvas.spec.ts +128 -0
  150. package/tests/e2e/workflow.spec.ts +185 -0
  151. package/tests/integration/api.test.ts +250 -0
  152. package/tests/integration/testApp.ts +31 -0
  153. package/tests/setup.ts +37 -0
  154. package/tests/unit/canvasStore.test.ts +502 -0
  155. package/tests/unit/components.test.tsx +151 -0
  156. package/tests/unit/executionStore.test.ts +527 -0
  157. package/tests/unit/layoutStore.test.ts +194 -0
  158. package/tests/unit/navigationStore.test.ts +152 -0
  159. package/tests/unit/stepValidation.test.ts +226 -0
  160. package/tests/unit/themeStore.test.ts +141 -0
  161. package/tests/unit/workflowToGraph.test.ts +289 -0
  162. package/tsconfig.json +29 -0
  163. package/tsconfig.server.json +28 -0
  164. package/vite.config.ts +31 -0
  165. package/vitest.config.ts +26 -0
@@ -0,0 +1,441 @@
1
+ import { readdir, readFile, writeFile, unlink, mkdir } from 'fs/promises';
2
+ import { join, relative, dirname } from 'path';
3
+ import { existsSync } from 'fs';
4
+ import { stringify as yamlStringify } from 'yaml';
5
+ // Import from @marktoflow/core for proper parsing
6
+ import { parseFile as coreParseFile } from '@marktoflow/core';
7
+
8
+ interface WorkflowListItem {
9
+ path: string;
10
+ name: string;
11
+ description?: string;
12
+ version?: string;
13
+ }
14
+
15
+ interface WorkflowMetadata {
16
+ id: string;
17
+ name: string;
18
+ version?: string;
19
+ description?: string;
20
+ author?: string;
21
+ tags?: string[];
22
+ }
23
+
24
+ interface WorkflowStep {
25
+ id: string;
26
+ name?: string;
27
+ action?: string;
28
+ workflow?: string;
29
+ inputs: Record<string, unknown>;
30
+ outputVariable?: string;
31
+ conditions?: string[];
32
+ errorHandling?: {
33
+ action: 'stop' | 'continue' | 'retry';
34
+ maxRetries?: number;
35
+ retryDelay?: number;
36
+ fallbackStep?: string;
37
+ };
38
+ timeout?: number;
39
+ }
40
+
41
+ interface Workflow {
42
+ metadata: WorkflowMetadata;
43
+ steps: WorkflowStep[];
44
+ tools?: Record<string, unknown>;
45
+ inputs?: Record<string, unknown>;
46
+ triggers?: unknown[];
47
+ }
48
+
49
+ export class WorkflowService {
50
+ private workflowDir: string;
51
+
52
+ constructor(workflowDir?: string) {
53
+ this.workflowDir = workflowDir || process.env.WORKFLOW_DIR || process.cwd();
54
+ }
55
+
56
+ async listWorkflows(): Promise<WorkflowListItem[]> {
57
+ const workflows: WorkflowListItem[] = [];
58
+ const baseDir = this.workflowDir;
59
+
60
+ async function scanDirectory(dir: string) {
61
+ try {
62
+ const entries = await readdir(dir, { withFileTypes: true });
63
+
64
+ for (const entry of entries) {
65
+ const fullPath = join(dir, entry.name);
66
+
67
+ // Skip hidden directories and node_modules
68
+ if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'dist') {
69
+ continue;
70
+ }
71
+
72
+ if (entry.isDirectory()) {
73
+ await scanDirectory(fullPath);
74
+ } else if (
75
+ entry.isFile() &&
76
+ (entry.name.endsWith('.md') || entry.name.endsWith('.yaml') || entry.name.endsWith('.yml'))
77
+ ) {
78
+ // Check if it's a workflow file by looking for frontmatter
79
+ try {
80
+ const content = await readFile(fullPath, 'utf-8');
81
+ if (content.includes('workflow:') || content.includes('steps:')) {
82
+ const relativePath = relative(baseDir, fullPath);
83
+ const workflowInfo = extractWorkflowInfo(content, entry.name);
84
+ workflows.push({
85
+ path: relativePath,
86
+ ...workflowInfo,
87
+ });
88
+ }
89
+ } catch {
90
+ // Skip files that can't be read
91
+ }
92
+ }
93
+ }
94
+ } catch {
95
+ // Skip directories we can't read
96
+ }
97
+ }
98
+
99
+ await scanDirectory(this.workflowDir);
100
+ return workflows.sort((a, b) => a.name.localeCompare(b.name));
101
+ }
102
+
103
+ async getWorkflow(workflowPath: string): Promise<Workflow | null> {
104
+ const fullPath = this.resolvePath(workflowPath);
105
+
106
+ if (!existsSync(fullPath)) {
107
+ return null;
108
+ }
109
+
110
+ try {
111
+ // Use core parser for proper workflow parsing
112
+ const result = await coreParseFile(fullPath);
113
+ if (result.warnings && result.warnings.length > 0) {
114
+ console.warn(`Workflow ${workflowPath} has parsing warnings:`, result.warnings);
115
+ }
116
+
117
+ // Convert core Workflow type to GUI Workflow type
118
+ return this.convertCoreWorkflow(result.workflow, workflowPath);
119
+ } catch (error) {
120
+ console.error(`Error parsing workflow ${workflowPath}:`, error);
121
+ // Fallback to local parsing if core parser fails
122
+ try {
123
+ const content = await readFile(fullPath, 'utf-8');
124
+ return this.parseWorkflow(content, workflowPath);
125
+ } catch {
126
+ return null;
127
+ }
128
+ }
129
+ }
130
+
131
+ private convertCoreWorkflow(coreWorkflow: any, path: string): Workflow {
132
+ return {
133
+ metadata: {
134
+ id: coreWorkflow.metadata?.id || path,
135
+ name: coreWorkflow.metadata?.name || path,
136
+ version: coreWorkflow.metadata?.version,
137
+ description: coreWorkflow.metadata?.description,
138
+ author: coreWorkflow.metadata?.author,
139
+ tags: coreWorkflow.metadata?.tags,
140
+ },
141
+ steps: (coreWorkflow.steps || []).map((step: any) => ({
142
+ id: step.id,
143
+ name: step.name,
144
+ action: step.action,
145
+ workflow: step.workflow,
146
+ inputs: step.inputs || {},
147
+ outputVariable: step.outputVariable || step.output_variable,
148
+ conditions: step.conditions,
149
+ errorHandling: step.errorHandling || step.error_handling,
150
+ timeout: step.timeout,
151
+ })),
152
+ tools: coreWorkflow.tools,
153
+ inputs: coreWorkflow.inputs,
154
+ triggers: coreWorkflow.triggers,
155
+ };
156
+ }
157
+
158
+ async createWorkflow(name: string, template?: string): Promise<WorkflowListItem> {
159
+ const filename = name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '') + '.md';
160
+ const workflowPath = join('workflows', filename);
161
+ const fullPath = join(this.workflowDir, workflowPath);
162
+
163
+ // Ensure directory exists
164
+ await mkdir(dirname(fullPath), { recursive: true });
165
+
166
+ const content = template || this.generateWorkflowTemplate(name);
167
+ await writeFile(fullPath, content, 'utf-8');
168
+
169
+ return {
170
+ path: workflowPath,
171
+ name,
172
+ };
173
+ }
174
+
175
+ async updateWorkflow(workflowPath: string, workflow: Workflow): Promise<Workflow> {
176
+ const fullPath = this.resolvePath(workflowPath);
177
+
178
+ // Read original file to preserve markdown content
179
+ let markdownContent = '';
180
+ if (existsSync(fullPath)) {
181
+ const originalContent = await readFile(fullPath, 'utf-8');
182
+ const match = originalContent.match(/^---\n[\s\S]*?\n---\n([\s\S]*)$/);
183
+ if (match) {
184
+ markdownContent = match[1];
185
+ }
186
+ }
187
+
188
+ const content = this.serializeWorkflow(workflow, markdownContent);
189
+ await writeFile(fullPath, content, 'utf-8');
190
+ return workflow;
191
+ }
192
+
193
+ async deleteWorkflow(workflowPath: string): Promise<void> {
194
+ const fullPath = this.resolvePath(workflowPath);
195
+ if (existsSync(fullPath)) {
196
+ await unlink(fullPath);
197
+ }
198
+ }
199
+
200
+ async getExecutionHistory(_workflowPath: string): Promise<unknown[]> {
201
+ // TODO: Query state store for execution history
202
+ // This will integrate with @marktoflow/core StateStore
203
+ return [];
204
+ }
205
+
206
+ private resolvePath(workflowPath: string): string {
207
+ // Handle both absolute and relative paths
208
+ if (workflowPath.startsWith('/')) {
209
+ return workflowPath;
210
+ }
211
+ return join(this.workflowDir, workflowPath);
212
+ }
213
+
214
+ private parseWorkflow(content: string, path: string): Workflow {
215
+ // Extract YAML frontmatter
216
+ const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
217
+
218
+ if (!frontmatterMatch) {
219
+ return {
220
+ metadata: { id: path, name: path },
221
+ steps: [],
222
+ };
223
+ }
224
+
225
+ const yaml = frontmatterMatch[1];
226
+
227
+ // Parse the YAML manually for now (will use @marktoflow/core parser when integrated)
228
+ const workflow: Workflow = {
229
+ metadata: { id: path, name: path },
230
+ steps: [],
231
+ };
232
+
233
+ // Extract workflow metadata
234
+ const workflowSection = yaml.match(/workflow:\s*\n((?: .*\n)*)/);
235
+ if (workflowSection) {
236
+ const idMatch = workflowSection[1].match(/id:\s*(\S+)/);
237
+ const nameMatch = workflowSection[1].match(/name:\s*["']?(.+?)["']?\s*$/m);
238
+ const versionMatch = workflowSection[1].match(/version:\s*["']?(.+?)["']?\s*$/m);
239
+ const descMatch = workflowSection[1].match(/description:\s*["']?(.+?)["']?\s*$/m);
240
+ const authorMatch = workflowSection[1].match(/author:\s*["']?(.+?)["']?\s*$/m);
241
+
242
+ if (idMatch) workflow.metadata.id = idMatch[1].trim();
243
+ if (nameMatch) workflow.metadata.name = nameMatch[1].trim();
244
+ if (versionMatch) workflow.metadata.version = versionMatch[1].trim();
245
+ if (descMatch) workflow.metadata.description = descMatch[1].trim();
246
+ if (authorMatch) workflow.metadata.author = authorMatch[1].trim();
247
+
248
+ // Extract tags
249
+ const tagsMatch = workflowSection[1].match(/tags:\s*\[(.*?)\]/);
250
+ if (tagsMatch) {
251
+ workflow.metadata.tags = tagsMatch[1]
252
+ .split(',')
253
+ .map((t) => t.trim().replace(/["']/g, ''))
254
+ .filter(Boolean);
255
+ }
256
+ }
257
+
258
+ // Extract steps using regex to find step blocks
259
+ const stepsSection = yaml.match(/steps:\s*\n((?: - [\s\S]*?)(?=\n\w|$))/);
260
+ if (stepsSection) {
261
+ const stepBlocks = stepsSection[1].split(/\n - /).filter(Boolean);
262
+
263
+ for (const block of stepBlocks) {
264
+ const stepText = block.startsWith('id:') ? block : block;
265
+ const step = this.parseStep(stepText);
266
+ if (step) {
267
+ workflow.steps.push(step);
268
+ }
269
+ }
270
+ }
271
+
272
+ // Extract tools
273
+ const toolsMatch = yaml.match(/tools:\s*\n((?: .*\n)*)/);
274
+ if (toolsMatch) {
275
+ // Simple extraction - will be enhanced with proper YAML parser
276
+ workflow.tools = {};
277
+ }
278
+
279
+ // Extract inputs
280
+ const inputsMatch = yaml.match(/inputs:\s*\n((?: .*\n)*)/);
281
+ if (inputsMatch) {
282
+ workflow.inputs = {};
283
+ }
284
+
285
+ return workflow;
286
+ }
287
+
288
+ private parseStep(stepText: string): WorkflowStep | null {
289
+ const idMatch = stepText.match(/id:\s*(\S+)/);
290
+ if (!idMatch) return null;
291
+
292
+ const step: WorkflowStep = {
293
+ id: idMatch[1],
294
+ inputs: {},
295
+ };
296
+
297
+ const nameMatch = stepText.match(/name:\s*["']?(.+?)["']?\s*$/m);
298
+ if (nameMatch) step.name = nameMatch[1];
299
+
300
+ const actionMatch = stepText.match(/action:\s*(\S+)/);
301
+ if (actionMatch) step.action = actionMatch[1];
302
+
303
+ const workflowMatch = stepText.match(/workflow:\s*(\S+)/);
304
+ if (workflowMatch) step.workflow = workflowMatch[1];
305
+
306
+ const outputMatch = stepText.match(/output_variable:\s*(\S+)/);
307
+ if (outputMatch) step.outputVariable = outputMatch[1];
308
+
309
+ const timeoutMatch = stepText.match(/timeout:\s*(\d+)/);
310
+ if (timeoutMatch) step.timeout = parseInt(timeoutMatch[1], 10);
311
+
312
+ // Parse inputs (simplified)
313
+ const inputsMatch = stepText.match(/inputs:\s*\n((?: .*\n)*)/);
314
+ if (inputsMatch) {
315
+ const inputLines = inputsMatch[1].split('\n').filter(Boolean);
316
+ for (const line of inputLines) {
317
+ const kvMatch = line.match(/^\s*(\w+):\s*(.+)$/);
318
+ if (kvMatch) {
319
+ let value: unknown = kvMatch[2].trim();
320
+ // Remove quotes if present
321
+ if ((value as string).startsWith("'") && (value as string).endsWith("'")) {
322
+ value = (value as string).slice(1, -1);
323
+ } else if ((value as string).startsWith('"') && (value as string).endsWith('"')) {
324
+ value = (value as string).slice(1, -1);
325
+ }
326
+ step.inputs[kvMatch[1]] = value;
327
+ }
328
+ }
329
+ }
330
+
331
+ return step;
332
+ }
333
+
334
+ private serializeWorkflow(workflow: Workflow, markdownContent: string = ''): string {
335
+ const frontmatter: Record<string, unknown> = {
336
+ workflow: {
337
+ id: workflow.metadata.id,
338
+ name: workflow.metadata.name,
339
+ version: workflow.metadata.version || '1.0.0',
340
+ description: workflow.metadata.description || '',
341
+ author: workflow.metadata.author || '',
342
+ tags: workflow.metadata.tags || [],
343
+ },
344
+ };
345
+
346
+ if (workflow.tools && Object.keys(workflow.tools).length > 0) {
347
+ frontmatter.tools = workflow.tools;
348
+ }
349
+
350
+ if (workflow.inputs && Object.keys(workflow.inputs).length > 0) {
351
+ frontmatter.inputs = workflow.inputs;
352
+ }
353
+
354
+ if (workflow.triggers && workflow.triggers.length > 0) {
355
+ frontmatter.triggers = workflow.triggers;
356
+ }
357
+
358
+ // Serialize steps
359
+ frontmatter.steps = workflow.steps.map((step) => {
360
+ const stepObj: Record<string, unknown> = {
361
+ id: step.id,
362
+ };
363
+
364
+ if (step.name) stepObj.name = step.name;
365
+ if (step.action) stepObj.action = step.action;
366
+ if (step.workflow) stepObj.workflow = step.workflow;
367
+ if (Object.keys(step.inputs).length > 0) stepObj.inputs = step.inputs;
368
+ if (step.outputVariable) stepObj.output_variable = step.outputVariable;
369
+ if (step.conditions && step.conditions.length > 0) stepObj.conditions = step.conditions;
370
+ if (step.errorHandling) stepObj.error_handling = step.errorHandling;
371
+ if (step.timeout) stepObj.timeout = step.timeout;
372
+
373
+ return stepObj;
374
+ });
375
+
376
+ const yaml = yamlStringify(frontmatter, {
377
+ indent: 2,
378
+ lineWidth: 0,
379
+ defaultKeyType: 'PLAIN',
380
+ defaultStringType: 'QUOTE_DOUBLE',
381
+ });
382
+
383
+ // Generate markdown if not provided
384
+ if (!markdownContent.trim()) {
385
+ markdownContent = `\n# ${workflow.metadata.name}\n\n${workflow.metadata.description || ''}\n`;
386
+ }
387
+
388
+ return `---\n${yaml}---${markdownContent}`;
389
+ }
390
+
391
+ private generateWorkflowTemplate(name: string): string {
392
+ const id = name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
393
+
394
+ return `---
395
+ workflow:
396
+ id: ${id}
397
+ name: "${name}"
398
+ version: "1.0.0"
399
+ description: ""
400
+ author: ""
401
+ tags: []
402
+
403
+ inputs: {}
404
+
405
+ steps:
406
+ - id: step-1
407
+ name: "First Step"
408
+ action: http.request
409
+ inputs:
410
+ url: "https://api.example.com"
411
+ method: "GET"
412
+ output_variable: result
413
+ ---
414
+
415
+ # ${name}
416
+
417
+ Describe your workflow here.
418
+
419
+ ## Steps
420
+
421
+ ### Step 1: First Step
422
+
423
+ This step makes an HTTP request to the API.
424
+ `;
425
+ }
426
+ }
427
+
428
+ function extractWorkflowInfo(
429
+ content: string,
430
+ filename: string
431
+ ): { name: string; description?: string; version?: string } {
432
+ const nameMatch = content.match(/name:\s*["']?(.+?)["']?\s*$/m);
433
+ const descMatch = content.match(/description:\s*["']?(.+?)["']?\s*$/m);
434
+ const versionMatch = content.match(/version:\s*["']?(.+?)["']?\s*$/m);
435
+
436
+ return {
437
+ name: nameMatch?.[1]?.trim() || filename.replace(/\.(md|yaml|yml)$/, '').replace(/-/g, ' '),
438
+ description: descMatch?.[1]?.trim(),
439
+ version: versionMatch?.[1]?.trim(),
440
+ };
441
+ }