devglide 0.1.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 (252) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +338 -0
  3. package/bin/claude-md-template.js +94 -0
  4. package/bin/devglide.js +387 -0
  5. package/package.json +85 -0
  6. package/pnpm-workspace.yaml +3 -0
  7. package/src/apps/coder/.turbo/turbo-lint.log +5 -0
  8. package/src/apps/coder/package.json +16 -0
  9. package/src/apps/coder/public/favicon.svg +7 -0
  10. package/src/apps/coder/public/page.css +275 -0
  11. package/src/apps/coder/public/page.js +528 -0
  12. package/src/apps/coder/server.js +3 -0
  13. package/src/apps/documentation/public/page.css +597 -0
  14. package/src/apps/documentation/public/page.js +609 -0
  15. package/src/apps/kanban/.turbo/turbo-lint.log +97 -0
  16. package/src/apps/kanban/.turbo/turbo-typecheck.log +5 -0
  17. package/src/apps/kanban/package.json +32 -0
  18. package/src/apps/kanban/public/favicon.svg +7 -0
  19. package/src/apps/kanban/public/page.css +1010 -0
  20. package/src/apps/kanban/public/page.js +1730 -0
  21. package/src/apps/kanban/public/vendor/marked.min.js +6 -0
  22. package/src/apps/kanban/public/vendor/sortable.min.js +2 -0
  23. package/src/apps/kanban/src/db.ts +319 -0
  24. package/src/apps/kanban/src/index.ts +14 -0
  25. package/src/apps/kanban/src/mcp-helpers.test.ts +88 -0
  26. package/src/apps/kanban/src/mcp-helpers.ts +60 -0
  27. package/src/apps/kanban/src/mcp.ts +59 -0
  28. package/src/apps/kanban/src/routes/attachments.ts +161 -0
  29. package/src/apps/kanban/src/routes/features.ts +233 -0
  30. package/src/apps/kanban/src/routes/issues.ts +373 -0
  31. package/src/apps/kanban/src/tools/feature-tools.ts +164 -0
  32. package/src/apps/kanban/src/tools/item-tools.ts +307 -0
  33. package/src/apps/kanban/src/tools/versioned-entry-tools.ts +72 -0
  34. package/src/apps/kanban/tsconfig.check.json +9 -0
  35. package/src/apps/kanban/tsconfig.json +9 -0
  36. package/src/apps/keymap/.turbo/turbo-lint.log +5 -0
  37. package/src/apps/keymap/package.json +16 -0
  38. package/src/apps/keymap/public/page.css +275 -0
  39. package/src/apps/keymap/public/page.js +294 -0
  40. package/src/apps/keymap/server.js +25 -0
  41. package/src/apps/log/.turbo/turbo-build.log +5 -0
  42. package/src/apps/log/.turbo/turbo-lint.log +45 -0
  43. package/src/apps/log/.turbo/turbo-typecheck.log +5 -0
  44. package/src/apps/log/node_modules/.bin/tsc +21 -0
  45. package/src/apps/log/node_modules/.bin/tsserver +21 -0
  46. package/src/apps/log/node_modules/.bin/tsx +21 -0
  47. package/src/apps/log/package.json +36 -0
  48. package/src/apps/log/public/console-sniffer.js +221 -0
  49. package/src/apps/log/public/favicon.svg +7 -0
  50. package/src/apps/log/public/page.css +322 -0
  51. package/src/apps/log/public/page.js +463 -0
  52. package/src/apps/log/src/index.ts +9 -0
  53. package/src/apps/log/src/mcp.ts +122 -0
  54. package/src/apps/log/src/routes/log.ts +333 -0
  55. package/src/apps/log/src/routes/status.ts +25 -0
  56. package/src/apps/log/src/server-sniffer.ts +118 -0
  57. package/src/apps/log/src/services/file-patterns.ts +39 -0
  58. package/src/apps/log/src/services/file-tailer.ts +228 -0
  59. package/src/apps/log/src/services/line-parser.ts +94 -0
  60. package/src/apps/log/src/services/log-writer.ts +39 -0
  61. package/src/apps/log/tsconfig.json +8 -0
  62. package/src/apps/prompts/.turbo/turbo-build.log +5 -0
  63. package/src/apps/prompts/.turbo/turbo-lint.log +24 -0
  64. package/src/apps/prompts/.turbo/turbo-typecheck.log +5 -0
  65. package/src/apps/prompts/mcp.ts +175 -0
  66. package/src/apps/prompts/node_modules/.bin/tsc +21 -0
  67. package/src/apps/prompts/node_modules/.bin/tsserver +21 -0
  68. package/src/apps/prompts/node_modules/.bin/tsx +21 -0
  69. package/src/apps/prompts/package.json +25 -0
  70. package/src/apps/prompts/public/page.css +315 -0
  71. package/src/apps/prompts/public/page.js +541 -0
  72. package/src/apps/prompts/services/prompt-store.ts +212 -0
  73. package/src/apps/prompts/src/index.ts +9 -0
  74. package/src/apps/prompts/tsconfig.json +8 -0
  75. package/src/apps/prompts/types.ts +27 -0
  76. package/src/apps/shell/.turbo/turbo-build.log +5 -0
  77. package/src/apps/shell/.turbo/turbo-lint.log +34 -0
  78. package/src/apps/shell/.turbo/turbo-typecheck.log +5 -0
  79. package/src/apps/shell/package.json +35 -0
  80. package/src/apps/shell/public/favicon.svg +7 -0
  81. package/src/apps/shell/public/page.css +407 -0
  82. package/src/apps/shell/public/page.js +1577 -0
  83. package/src/apps/shell/src/index.ts +150 -0
  84. package/src/apps/shell/src/mcp.ts +398 -0
  85. package/src/apps/shell/src/shell-types.ts +41 -0
  86. package/src/apps/shell/tsconfig.json +8 -0
  87. package/src/apps/test/.turbo/turbo-build.log +5 -0
  88. package/src/apps/test/.turbo/turbo-lint.log +27 -0
  89. package/src/apps/test/.turbo/turbo-typecheck.log +5 -0
  90. package/src/apps/test/node_modules/.bin/tsc +21 -0
  91. package/src/apps/test/node_modules/.bin/tsserver +21 -0
  92. package/src/apps/test/node_modules/.bin/tsx +21 -0
  93. package/src/apps/test/node_modules/.bin/uuid +21 -0
  94. package/src/apps/test/package.json +35 -0
  95. package/src/apps/test/public/favicon.svg +7 -0
  96. package/src/apps/test/public/page.css +499 -0
  97. package/src/apps/test/public/page.js +417 -0
  98. package/src/apps/test/public/scenario-runner.js +450 -0
  99. package/src/apps/test/src/index.ts +9 -0
  100. package/src/apps/test/src/mcp.ts +192 -0
  101. package/src/apps/test/src/routes/trigger.ts +285 -0
  102. package/src/apps/test/src/services/scenario-broadcaster.ts +60 -0
  103. package/src/apps/test/src/services/scenario-manager.ts +361 -0
  104. package/src/apps/test/src/services/scenario-store.ts +145 -0
  105. package/src/apps/test/tsconfig.json +8 -0
  106. package/src/apps/vocabulary/.turbo/turbo-build.log +5 -0
  107. package/src/apps/vocabulary/.turbo/turbo-lint.log +25 -0
  108. package/src/apps/vocabulary/.turbo/turbo-typecheck.log +5 -0
  109. package/src/apps/vocabulary/mcp.ts +173 -0
  110. package/src/apps/vocabulary/node_modules/.bin/tsc +21 -0
  111. package/src/apps/vocabulary/node_modules/.bin/tsserver +21 -0
  112. package/src/apps/vocabulary/node_modules/.bin/tsx +21 -0
  113. package/src/apps/vocabulary/package.json +25 -0
  114. package/src/apps/vocabulary/public/page.css +247 -0
  115. package/src/apps/vocabulary/public/page.js +444 -0
  116. package/src/apps/vocabulary/services/vocabulary-store.ts +179 -0
  117. package/src/apps/vocabulary/src/index.ts +10 -0
  118. package/src/apps/vocabulary/tsconfig.json +8 -0
  119. package/src/apps/vocabulary/types.ts +22 -0
  120. package/src/apps/voice/.turbo/turbo-build.log +5 -0
  121. package/src/apps/voice/.turbo/turbo-lint.log +43 -0
  122. package/src/apps/voice/.turbo/turbo-typecheck.log +5 -0
  123. package/src/apps/voice/node_modules/.bin/openai +21 -0
  124. package/src/apps/voice/node_modules/.bin/tsc +21 -0
  125. package/src/apps/voice/node_modules/.bin/tsserver +21 -0
  126. package/src/apps/voice/node_modules/.bin/tsx +21 -0
  127. package/src/apps/voice/package.json +35 -0
  128. package/src/apps/voice/public/favicon.svg +7 -0
  129. package/src/apps/voice/public/page.css +388 -0
  130. package/src/apps/voice/public/page.js +718 -0
  131. package/src/apps/voice/src/index.ts +10 -0
  132. package/src/apps/voice/src/mcp.ts +70 -0
  133. package/src/apps/voice/src/providers/index.ts +85 -0
  134. package/src/apps/voice/src/providers/openai-compatible.ts +94 -0
  135. package/src/apps/voice/src/providers/types.ts +27 -0
  136. package/src/apps/voice/src/routes/config.ts +118 -0
  137. package/src/apps/voice/src/routes/transcribe.ts +90 -0
  138. package/src/apps/voice/src/services/config-store.ts +129 -0
  139. package/src/apps/voice/src/services/stats.ts +108 -0
  140. package/src/apps/voice/src/transcribe.ts +11 -0
  141. package/src/apps/voice/src/utils/mime.ts +16 -0
  142. package/src/apps/voice/tsconfig.json +8 -0
  143. package/src/apps/workflow/.turbo/turbo-build.log +5 -0
  144. package/src/apps/workflow/.turbo/turbo-lint.log +96 -0
  145. package/src/apps/workflow/.turbo/turbo-typecheck.log +5 -0
  146. package/src/apps/workflow/engine/executors/decision-executor.ts +87 -0
  147. package/src/apps/workflow/engine/executors/file-executor.ts +90 -0
  148. package/src/apps/workflow/engine/executors/git-executor.ts +137 -0
  149. package/src/apps/workflow/engine/executors/http-executor.ts +65 -0
  150. package/src/apps/workflow/engine/executors/index.ts +28 -0
  151. package/src/apps/workflow/engine/executors/kanban-executor.ts +154 -0
  152. package/src/apps/workflow/engine/executors/llm-executor.ts +46 -0
  153. package/src/apps/workflow/engine/executors/log-executor.ts +62 -0
  154. package/src/apps/workflow/engine/executors/loop-executor.ts +14 -0
  155. package/src/apps/workflow/engine/executors/shell-executor.ts +107 -0
  156. package/src/apps/workflow/engine/executors/sub-workflow-executor.ts +61 -0
  157. package/src/apps/workflow/engine/executors/test-executor.ts +73 -0
  158. package/src/apps/workflow/engine/executors/trigger-executor.ts +39 -0
  159. package/src/apps/workflow/engine/expression-evaluator.ts +117 -0
  160. package/src/apps/workflow/engine/graph-runner.ts +438 -0
  161. package/src/apps/workflow/engine/node-executor.ts +104 -0
  162. package/src/apps/workflow/engine/node-registry.ts +15 -0
  163. package/src/apps/workflow/engine/variable-resolver.ts +109 -0
  164. package/src/apps/workflow/mcp.ts +223 -0
  165. package/src/apps/workflow/node_modules/.bin/tsc +21 -0
  166. package/src/apps/workflow/node_modules/.bin/tsserver +21 -0
  167. package/src/apps/workflow/node_modules/.bin/tsx +21 -0
  168. package/src/apps/workflow/package.json +25 -0
  169. package/src/apps/workflow/public/editor/canvas.js +366 -0
  170. package/src/apps/workflow/public/editor/drag-manager.js +326 -0
  171. package/src/apps/workflow/public/editor/edge-renderer.js +235 -0
  172. package/src/apps/workflow/public/editor/history-manager.js +147 -0
  173. package/src/apps/workflow/public/editor/layout-engine.js +159 -0
  174. package/src/apps/workflow/public/editor/node-renderer.js +199 -0
  175. package/src/apps/workflow/public/editor/selection-manager.js +193 -0
  176. package/src/apps/workflow/public/favicon.svg +7 -0
  177. package/src/apps/workflow/public/models/node-types.js +300 -0
  178. package/src/apps/workflow/public/models/workflow-model.js +257 -0
  179. package/src/apps/workflow/public/page.css +406 -0
  180. package/src/apps/workflow/public/page.js +658 -0
  181. package/src/apps/workflow/public/panels/inspector.js +360 -0
  182. package/src/apps/workflow/public/panels/palette.js +106 -0
  183. package/src/apps/workflow/public/panels/run-view.js +275 -0
  184. package/src/apps/workflow/public/panels/toolbar.js +232 -0
  185. package/src/apps/workflow/public/panels/workflow-list.js +237 -0
  186. package/src/apps/workflow/public/state/store.js +47 -0
  187. package/src/apps/workflow/services/custom-node-loader.ts +48 -0
  188. package/src/apps/workflow/services/legacy-converter.ts +72 -0
  189. package/src/apps/workflow/services/run-manager.ts +190 -0
  190. package/src/apps/workflow/services/workflow-store.ts +424 -0
  191. package/src/apps/workflow/services/workflow-validator.test.ts +103 -0
  192. package/src/apps/workflow/services/workflow-validator.ts +98 -0
  193. package/src/apps/workflow/src/index.ts +10 -0
  194. package/src/apps/workflow/templates/ci-pipeline.json +18 -0
  195. package/src/apps/workflow/templates/code-review.json +22 -0
  196. package/src/apps/workflow/templates/kanban-testing.json +24 -0
  197. package/src/apps/workflow/tsconfig.json +8 -0
  198. package/src/apps/workflow/types.ts +268 -0
  199. package/src/packages/auth-middleware.ts +14 -0
  200. package/src/packages/design-tokens/.turbo/turbo-build.log +10 -0
  201. package/src/packages/design-tokens/STYLEGUIDE.md +414 -0
  202. package/src/packages/design-tokens/build.js +413 -0
  203. package/src/packages/design-tokens/demo/index.html +1367 -0
  204. package/src/packages/design-tokens/demo/proposition-a.html +717 -0
  205. package/src/packages/design-tokens/demo/proposition-b.html +1239 -0
  206. package/src/packages/design-tokens/demo/proposition-c.html +1049 -0
  207. package/src/packages/design-tokens/dist/tailwind-preset.js +115 -0
  208. package/src/packages/design-tokens/dist/tokens.css +345 -0
  209. package/src/packages/design-tokens/dist/tokens.d.ts +229 -0
  210. package/src/packages/design-tokens/dist/tokens.js +386 -0
  211. package/src/packages/design-tokens/package.json +25 -0
  212. package/src/packages/design-tokens/tokens.json +228 -0
  213. package/src/packages/devtools-middleware.ts +22 -0
  214. package/src/packages/eslint-config/index.js +63 -0
  215. package/src/packages/eslint-config/node_modules/.bin/eslint +21 -0
  216. package/src/packages/eslint-config/package.json +18 -0
  217. package/src/packages/json-file-store.ts +232 -0
  218. package/src/packages/mcp-utils/.turbo/turbo-build.log +5 -0
  219. package/src/packages/mcp-utils/dist/index.d.ts +33 -0
  220. package/src/packages/mcp-utils/dist/index.d.ts.map +1 -0
  221. package/src/packages/mcp-utils/dist/index.js +126 -0
  222. package/src/packages/mcp-utils/dist/index.js.map +1 -0
  223. package/src/packages/mcp-utils/node_modules/.bin/tsc +21 -0
  224. package/src/packages/mcp-utils/node_modules/.bin/tsserver +21 -0
  225. package/src/packages/mcp-utils/package.json +32 -0
  226. package/src/packages/mcp-utils/src/index.ts +171 -0
  227. package/src/packages/mcp-utils/tsconfig.json +9 -0
  228. package/src/packages/paths.ts +18 -0
  229. package/src/packages/project-context/index.js +55 -0
  230. package/src/packages/project-context/package.json +13 -0
  231. package/src/packages/project-store.ts +127 -0
  232. package/src/packages/server-sniffer.ts +132 -0
  233. package/src/packages/shared-assets/favicon.svg +7 -0
  234. package/src/packages/shared-assets/keymap-registry.js +512 -0
  235. package/src/packages/shared-assets/logo.svg +6 -0
  236. package/src/packages/shared-assets/package.json +11 -0
  237. package/src/packages/shared-assets/ui-utils.js +48 -0
  238. package/src/packages/shared-assets/voice-widget.d.ts +37 -0
  239. package/src/packages/shared-assets/voice-widget.js +695 -0
  240. package/src/packages/shared-types/.turbo/turbo-build.log +5 -0
  241. package/src/packages/shared-types/dist/index.d.ts +39 -0
  242. package/src/packages/shared-types/dist/index.d.ts.map +1 -0
  243. package/src/packages/shared-types/node_modules/.bin/tsc +21 -0
  244. package/src/packages/shared-types/node_modules/.bin/tsserver +21 -0
  245. package/src/packages/shared-types/package.json +25 -0
  246. package/src/packages/shared-types/src/index.ts +41 -0
  247. package/src/packages/shared-types/tsconfig.json +11 -0
  248. package/src/packages/tsconfig/base.json +15 -0
  249. package/src/packages/tsconfig/next.json +14 -0
  250. package/src/packages/tsconfig/node.json +11 -0
  251. package/src/packages/tsconfig/package.json +10 -0
  252. package/turbo.json +25 -0
@@ -0,0 +1,300 @@
1
+ // ── Workflow Editor — Node Type Registry ────────────────────────────────
2
+ // Defines all 12 node types with config fields, icons, colors, and defaults.
3
+ // Config field schemas mirror the TypeScript interfaces in types.ts.
4
+
5
+ export const NODE_CATEGORIES = [
6
+ { id: 'triggers', label: 'Triggers', color: '#f59e0b' },
7
+ { id: 'actions', label: 'Actions', color: '#6366f1' },
8
+ { id: 'control', label: 'Control Flow', color: '#ec4899' },
9
+ { id: 'steps', label: 'Steps', color: '#64748b' },
10
+ ];
11
+
12
+ export const NODE_TYPES = {
13
+ // ── Triggers ────────────────────────────────────────────────────────────
14
+ 'trigger': {
15
+ label: 'Trigger',
16
+ category: 'triggers',
17
+ icon: '\u26A1',
18
+ color: '#f59e0b',
19
+ ports: { in: 0, out: 1 },
20
+ configFields: [
21
+ { key: 'triggerType', label: 'Trigger Type', type: 'select',
22
+ options: ['manual', 'prompt', 'voice', 'webhook', 'schedule', 'git-event', 'log-pattern', 'kanban-move'] },
23
+ { key: 'cron', label: 'Cron Expression', type: 'text',
24
+ showWhen: { triggerType: 'schedule' } },
25
+ { key: 'gitEvent', label: 'Git Event', type: 'select',
26
+ options: ['commit', 'push', 'branch-create', 'tag'],
27
+ showWhen: { triggerType: 'git-event' } },
28
+ { key: 'gitBranch', label: 'Branch Filter', type: 'text',
29
+ showWhen: { triggerType: 'git-event' } },
30
+ { key: 'logPattern', label: 'Log Pattern (regex)', type: 'text',
31
+ showWhen: { triggerType: 'log-pattern' } },
32
+ { key: 'kanbanTargetColumn', label: 'Target Column', type: 'text',
33
+ showWhen: { triggerType: 'kanban-move' } },
34
+ ],
35
+ defaultConfig: { nodeType: 'trigger', triggerType: 'manual' },
36
+ },
37
+
38
+ // ── Actions ─────────────────────────────────────────────────────────────
39
+ 'action:shell': {
40
+ label: 'Shell',
41
+ category: 'actions',
42
+ icon: '\u{1F4BB}',
43
+ color: '#22c55e',
44
+ ports: { in: 1, out: 1 },
45
+ configFields: [
46
+ { key: 'command', label: 'Command', type: 'textarea' },
47
+ { key: 'cwd', label: 'Working Directory', type: 'text' },
48
+ { key: 'captureOutput', label: 'Capture Output', type: 'checkbox' },
49
+ { key: 'outputVariable', label: 'Output Variable', type: 'text' },
50
+ ],
51
+ defaultConfig: { nodeType: 'action:shell', command: '', captureOutput: true },
52
+ },
53
+
54
+ 'action:kanban': {
55
+ label: 'Kanban',
56
+ category: 'actions',
57
+ icon: '\u{1F4CB}',
58
+ color: '#3b82f6',
59
+ ports: { in: 1, out: 1 },
60
+ configFields: [
61
+ { key: 'operation', label: 'Operation', type: 'select',
62
+ options: ['create', 'move', 'update', 'append-work-log', 'append-review', 'list'] },
63
+ { key: 'featureId', label: 'Feature ID', type: 'text' },
64
+ { key: 'itemId', label: 'Item ID', type: 'text' },
65
+ { key: 'columnName', label: 'Column Name', type: 'text',
66
+ showWhen: { operation: 'move' } },
67
+ { key: 'title', label: 'Title', type: 'text',
68
+ showWhen: { operation: 'create' } },
69
+ { key: 'description', label: 'Description', type: 'textarea',
70
+ showWhen: { operation: 'create' } },
71
+ { key: 'content', label: 'Content', type: 'textarea' },
72
+ ],
73
+ defaultConfig: { nodeType: 'action:kanban', operation: 'create' },
74
+ },
75
+
76
+ 'action:git': {
77
+ label: 'Git',
78
+ category: 'actions',
79
+ icon: '\u{1F500}',
80
+ color: '#f97316',
81
+ ports: { in: 1, out: 1 },
82
+ configFields: [
83
+ { key: 'operation', label: 'Operation', type: 'select',
84
+ options: ['status', 'diff', 'commit', 'push', 'branch-create', 'checkout', 'add'] },
85
+ { key: 'message', label: 'Commit Message', type: 'text',
86
+ showWhen: { operation: 'commit' } },
87
+ { key: 'branch', label: 'Branch', type: 'text' },
88
+ { key: 'files', label: 'Files (one per line)', type: 'textarea' },
89
+ ],
90
+ defaultConfig: { nodeType: 'action:git', operation: 'status' },
91
+ },
92
+
93
+ 'action:llm': {
94
+ label: 'LLM',
95
+ category: 'actions',
96
+ icon: '\u{1F9E0}',
97
+ color: '#8b5cf6',
98
+ ports: { in: 1, out: 1 },
99
+ configFields: [
100
+ { key: 'promptSource', label: 'Prompt Source', type: 'select',
101
+ options: ['inline', 'file'] },
102
+ { key: 'prompt', label: 'Prompt', type: 'textarea',
103
+ showWhen: { promptSource: 'inline' } },
104
+ { key: 'promptFile', label: 'Prompt File', type: 'text',
105
+ showWhen: { promptSource: 'file' } },
106
+ { key: 'model', label: 'Model', type: 'text' },
107
+ { key: 'temperature', label: 'Temperature', type: 'number' },
108
+ { key: 'maxTokens', label: 'Max Tokens', type: 'number' },
109
+ ],
110
+ defaultConfig: { nodeType: 'action:llm', promptSource: 'inline', prompt: '' },
111
+ },
112
+
113
+ 'action:test': {
114
+ label: 'Test',
115
+ category: 'actions',
116
+ icon: '\u{1F9EA}',
117
+ color: '#06b6d4',
118
+ ports: { in: 1, out: 1 },
119
+ configFields: [
120
+ { key: 'operation', label: 'Operation', type: 'select',
121
+ options: ['run-scenario', 'run-saved', 'save-scenario', 'list-saved'] },
122
+ { key: 'scenarioId', label: 'Scenario ID', type: 'text' },
123
+ { key: 'target', label: 'Target URL', type: 'text',
124
+ showWhen: { operation: 'run-scenario' } },
125
+ { key: 'linkedItemId', label: 'Linked Item ID', type: 'text' },
126
+ ],
127
+ defaultConfig: { nodeType: 'action:test', operation: 'run-saved' },
128
+ },
129
+
130
+ 'action:log': {
131
+ label: 'Log',
132
+ category: 'actions',
133
+ icon: '\u{1F4DD}',
134
+ color: '#64748b',
135
+ ports: { in: 1, out: 1 },
136
+ configFields: [
137
+ { key: 'operation', label: 'Operation', type: 'select',
138
+ options: ['write', 'read', 'clear'] },
139
+ { key: 'targetPath', label: 'Target Path', type: 'text' },
140
+ { key: 'type', label: 'Log Type', type: 'text',
141
+ showWhen: { operation: 'write' } },
142
+ { key: 'message', label: 'Message', type: 'textarea',
143
+ showWhen: { operation: 'write' } },
144
+ { key: 'lines', label: 'Lines to Read', type: 'number',
145
+ showWhen: { operation: 'read' } },
146
+ ],
147
+ defaultConfig: { nodeType: 'action:log', operation: 'write' },
148
+ },
149
+
150
+ 'action:file': {
151
+ label: 'File',
152
+ category: 'actions',
153
+ icon: '\u{1F4C1}',
154
+ color: '#14b8a6',
155
+ ports: { in: 1, out: 1 },
156
+ configFields: [
157
+ { key: 'operation', label: 'Operation', type: 'select',
158
+ options: ['read', 'write', 'append', 'exists', 'tree'] },
159
+ { key: 'path', label: 'Path', type: 'text' },
160
+ { key: 'content', label: 'Content', type: 'textarea',
161
+ showWhen: { operation: 'write' } },
162
+ ],
163
+ defaultConfig: { nodeType: 'action:file', operation: 'read', path: '' },
164
+ },
165
+
166
+ 'action:http': {
167
+ label: 'HTTP',
168
+ category: 'actions',
169
+ icon: '\u{1F310}',
170
+ color: '#e11d48',
171
+ ports: { in: 1, out: 1 },
172
+ configFields: [
173
+ { key: 'method', label: 'Method', type: 'select',
174
+ options: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'] },
175
+ { key: 'url', label: 'URL', type: 'text' },
176
+ { key: 'headers', label: 'Headers (JSON)', type: 'textarea' },
177
+ { key: 'body', label: 'Body', type: 'textarea' },
178
+ ],
179
+ defaultConfig: { nodeType: 'action:http', method: 'GET', url: '' },
180
+ },
181
+
182
+ // ── Control Flow ────────────────────────────────────────────────────────
183
+ 'decision': {
184
+ label: 'Decision',
185
+ category: 'control',
186
+ icon: '\u{1F500}',
187
+ color: '#ec4899',
188
+ ports: { in: 1, out: 'dynamic' },
189
+ configFields: [
190
+ { key: 'conditionType', label: 'Condition Type', type: 'select',
191
+ options: ['exit-code', 'variable', 'expression'] },
192
+ { key: 'variable', label: 'Variable', type: 'text',
193
+ showWhen: { conditionType: 'variable' } },
194
+ { key: 'expression', label: 'Expression', type: 'text',
195
+ showWhen: { conditionType: 'expression' } },
196
+ ],
197
+ defaultConfig: { nodeType: 'decision', conditionType: 'expression', ports: [] },
198
+ },
199
+
200
+ 'loop': {
201
+ label: 'Loop',
202
+ category: 'control',
203
+ icon: '\u{1F504}',
204
+ color: '#d946ef',
205
+ ports: { in: 1, out: 1 },
206
+ configFields: [
207
+ { key: 'loopType', label: 'Loop Type', type: 'select',
208
+ options: ['count', 'while', 'for-each'] },
209
+ { key: 'count', label: 'Count', type: 'number',
210
+ showWhen: { loopType: 'count' } },
211
+ { key: 'condition', label: 'Condition', type: 'text',
212
+ showWhen: { loopType: 'while' } },
213
+ { key: 'collection', label: 'Collection Variable', type: 'text',
214
+ showWhen: { loopType: 'for-each' } },
215
+ { key: 'itemVariable', label: 'Item Variable', type: 'text',
216
+ showWhen: { loopType: 'for-each' } },
217
+ { key: 'maxIterations', label: 'Max Iterations', type: 'number' },
218
+ ],
219
+ defaultConfig: { nodeType: 'loop', loopType: 'count', count: 1 },
220
+ },
221
+
222
+ 'sub-workflow': {
223
+ label: 'Sub-Workflow',
224
+ category: 'control',
225
+ icon: '\u{1F4E6}',
226
+ color: '#a855f7',
227
+ ports: { in: 1, out: 1 },
228
+ configFields: [
229
+ { key: 'workflowId', label: 'Workflow ID', type: 'text' },
230
+ ],
231
+ defaultConfig: { nodeType: 'sub-workflow', workflowId: '' },
232
+ },
233
+
234
+ // ── Steps (backward compat) ─────────────────────────────────────────────
235
+ 'step': {
236
+ label: 'Step',
237
+ category: 'steps',
238
+ icon: '\u{1F4CB}',
239
+ color: '#64748b',
240
+ ports: { in: 1, out: 1 },
241
+ configFields: [
242
+ { key: 'instructions', label: 'Instructions', type: 'textarea' },
243
+ { key: 'instructionFile', label: 'Instruction File (.md)', type: 'text' },
244
+ ],
245
+ defaultConfig: { nodeType: 'step', instructions: '', instructionFile: '' },
246
+ },
247
+ };
248
+
249
+ /**
250
+ * Get the node type definition for a given type key.
251
+ * @param {string} type
252
+ * @returns {object|null}
253
+ */
254
+ export function getNodeType(type) {
255
+ return NODE_TYPES[type] ?? null;
256
+ }
257
+
258
+ /**
259
+ * Get all node types within a category.
260
+ * @param {string} categoryId
261
+ * @returns {Array<[string, object]>}
262
+ */
263
+ export function getNodesByCategory(categoryId) {
264
+ return Object.entries(NODE_TYPES).filter(([, def]) => def.category === categoryId);
265
+ }
266
+
267
+ /**
268
+ * Resolve the concrete output ports for a node.
269
+ * For static ports (out: N), returns N port descriptors with ids 'out-0', 'out-1', ...
270
+ * For dynamic ports (decision nodes), reads config.ports array.
271
+ * Always returns at least one output port.
272
+ * @param {object} node - { type, config }
273
+ * @returns {Array<{ id: string, label: string }>}
274
+ */
275
+ export function resolveOutputPorts(node) {
276
+ const typeDef = NODE_TYPES[node.type];
277
+ const portsDef = typeDef?.ports?.out ?? 1;
278
+
279
+ if (portsDef === 'dynamic') {
280
+ const configPorts = node.config?.ports;
281
+ if (Array.isArray(configPorts) && configPorts.length > 0) {
282
+ return configPorts.map(p => ({ id: p.id, label: p.label ?? p.id }));
283
+ }
284
+ // Fallback: single default output so the node is still connectable
285
+ return [{ id: 'out-0', label: 'default' }];
286
+ }
287
+
288
+ const count = typeof portsDef === 'number' ? portsDef : 1;
289
+ return Array.from({ length: count }, (_, i) => ({ id: `out-${i}`, label: `out-${i}` }));
290
+ }
291
+
292
+ /**
293
+ * Resolve the number of input ports for a node.
294
+ * @param {object} node - { type }
295
+ * @returns {number}
296
+ */
297
+ export function resolveInputPortCount(node) {
298
+ const typeDef = NODE_TYPES[node.type];
299
+ return typeDef?.ports?.in ?? 1;
300
+ }
@@ -0,0 +1,257 @@
1
+ // ── Workflow Editor — Graph Data Model ──────────────────────────────────
2
+ // Manages the workflow graph: nodes, edges, and structural queries.
3
+
4
+ import { store } from '../state/store.js';
5
+ import { NODE_TYPES } from './node-types.js';
6
+
7
+ function uid() {
8
+ return crypto.randomUUID();
9
+ }
10
+
11
+ function markDirty() {
12
+ store.set('isDirty', true);
13
+ }
14
+
15
+ function emitWorkflow() {
16
+ // Re-set to trigger listeners even though the reference may be the same
17
+ store.set('workflow', store.get('workflow'));
18
+ }
19
+
20
+ export const WorkflowModel = {
21
+ /**
22
+ * Load a workflow object into the store.
23
+ * @param {object} workflow - { id, name, description, nodes, edges, ... }
24
+ */
25
+ load(workflow) {
26
+ const wf = {
27
+ id: workflow.id,
28
+ name: workflow.name ?? 'Untitled Workflow',
29
+ description: workflow.description ?? '',
30
+ nodes: (workflow.nodes ?? []).map(n => ({ ...n })),
31
+ edges: (workflow.edges ?? []).map(e => ({ ...e })),
32
+ enabled: workflow.enabled ?? true,
33
+ global: workflow.global ?? false,
34
+ createdAt: workflow.createdAt ?? new Date().toISOString(),
35
+ updatedAt: workflow.updatedAt ?? new Date().toISOString(),
36
+ };
37
+ store.set('workflow', wf);
38
+ store.set('isDirty', false);
39
+ store.set('selectedNodeIds', new Set());
40
+ store.set('selectedEdgeIds', new Set());
41
+ },
42
+
43
+ /**
44
+ * Return a serializable workflow object from the current store state.
45
+ * @returns {object|null}
46
+ */
47
+ save() {
48
+ const wf = store.get('workflow');
49
+ if (!wf) return null;
50
+ return {
51
+ id: wf.id,
52
+ name: wf.name,
53
+ description: wf.description,
54
+ enabled: wf.enabled,
55
+ global: wf.global,
56
+ nodes: wf.nodes.map(n => ({ ...n, position: { ...n.position }, config: { ...n.config } })),
57
+ edges: wf.edges.map(e => ({ ...e })),
58
+ createdAt: wf.createdAt,
59
+ updatedAt: new Date().toISOString(),
60
+ };
61
+ },
62
+
63
+ /**
64
+ * Add a node to the workflow.
65
+ * @param {string} type - Node type key (e.g. 'action:shell')
66
+ * @param {string} label - Display label
67
+ * @param {{ x: number, y: number }} position
68
+ * @param {object} [config={}] - Node-specific config
69
+ * @returns {object} The created node
70
+ */
71
+ addNode(type, label, position, config = {}) {
72
+ const wf = store.get('workflow');
73
+ if (!wf) return null;
74
+
75
+ const typeDef = NODE_TYPES[type];
76
+ const node = {
77
+ id: uid(),
78
+ type,
79
+ label: label || typeDef?.label || type,
80
+ position: { x: position.x, y: position.y },
81
+ config: { ...(typeDef?.defaultConfig ?? {}), ...config },
82
+ };
83
+ wf.nodes.push(node);
84
+ markDirty();
85
+ emitWorkflow();
86
+ return node;
87
+ },
88
+
89
+ /**
90
+ * Remove a node and all connected edges.
91
+ * @param {string} id
92
+ */
93
+ removeNode(id) {
94
+ const wf = store.get('workflow');
95
+ if (!wf) return;
96
+
97
+ wf.nodes = wf.nodes.filter(n => n.id !== id);
98
+ wf.edges = wf.edges.filter(e => e.source !== id && e.target !== id);
99
+
100
+ // Remove from selection
101
+ const sel = store.get('selectedNodeIds');
102
+ if (sel.has(id)) {
103
+ sel.delete(id);
104
+ store.set('selectedNodeIds', new Set(sel));
105
+ }
106
+
107
+ markDirty();
108
+ emitWorkflow();
109
+ },
110
+
111
+ /**
112
+ * Partial-update a node.
113
+ * @param {string} id
114
+ * @param {object} updates - Merged into the node
115
+ */
116
+ updateNode(id, updates) {
117
+ const wf = store.get('workflow');
118
+ if (!wf) return;
119
+ const node = wf.nodes.find(n => n.id === id);
120
+ if (!node) return;
121
+
122
+ if (updates.config) {
123
+ node.config = { ...node.config, ...updates.config };
124
+ delete updates.config;
125
+ }
126
+ Object.assign(node, updates);
127
+ markDirty();
128
+ emitWorkflow();
129
+ },
130
+
131
+ /**
132
+ * Move a node to a new position.
133
+ * @param {string} id
134
+ * @param {number} x
135
+ * @param {number} y
136
+ */
137
+ moveNode(id, x, y) {
138
+ const wf = store.get('workflow');
139
+ if (!wf) return;
140
+ const node = wf.nodes.find(n => n.id === id);
141
+ if (!node) return;
142
+ node.position = { x, y };
143
+ markDirty();
144
+ emitWorkflow();
145
+ },
146
+
147
+ /**
148
+ * Add an edge between two nodes.
149
+ * @param {string} source - Source node ID
150
+ * @param {string} target - Target node ID
151
+ * @param {string} [sourcePort] - Port identifier (for multi-output nodes)
152
+ * @param {string} [condition] - Edge label / condition text
153
+ * @returns {object} The created edge
154
+ */
155
+ addEdge(source, target, sourcePort, condition) {
156
+ const wf = store.get('workflow');
157
+ if (!wf) return null;
158
+
159
+ // Prevent duplicate edges
160
+ const exists = wf.edges.some(
161
+ e => e.source === source && e.target === target && (e.sourcePort ?? '') === (sourcePort ?? '')
162
+ );
163
+ if (exists) return null;
164
+
165
+ // Prevent self-loops
166
+ if (source === target) return null;
167
+
168
+ const edge = {
169
+ id: uid(),
170
+ source,
171
+ target,
172
+ sourcePort: sourcePort ?? null,
173
+ condition: condition ?? null,
174
+ };
175
+ wf.edges.push(edge);
176
+ markDirty();
177
+ emitWorkflow();
178
+ return edge;
179
+ },
180
+
181
+ /**
182
+ * Remove an edge.
183
+ * @param {string} id
184
+ */
185
+ removeEdge(id) {
186
+ const wf = store.get('workflow');
187
+ if (!wf) return;
188
+ wf.edges = wf.edges.filter(e => e.id !== id);
189
+
190
+ const sel = store.get('selectedEdgeIds');
191
+ if (sel.has(id)) {
192
+ sel.delete(id);
193
+ store.set('selectedEdgeIds', new Set(sel));
194
+ }
195
+
196
+ markDirty();
197
+ emitWorkflow();
198
+ },
199
+
200
+ /**
201
+ * Get a node by ID.
202
+ * @param {string} id
203
+ * @returns {object|null}
204
+ */
205
+ getNode(id) {
206
+ const wf = store.get('workflow');
207
+ return wf?.nodes.find(n => n.id === id) ?? null;
208
+ },
209
+
210
+ /**
211
+ * Get an edge by ID.
212
+ * @param {string} id
213
+ * @returns {object|null}
214
+ */
215
+ getEdge(id) {
216
+ const wf = store.get('workflow');
217
+ return wf?.edges.find(e => e.id === id) ?? null;
218
+ },
219
+
220
+ /**
221
+ * Get all nodes of a given type.
222
+ * @param {string} type
223
+ * @returns {Array<object>}
224
+ */
225
+ getNodesOfType(type) {
226
+ const wf = store.get('workflow');
227
+ return wf?.nodes.filter(n => n.type === type) ?? [];
228
+ },
229
+
230
+ /**
231
+ * Get all edges targeting a given node.
232
+ * @param {string} nodeId
233
+ * @returns {Array<object>}
234
+ */
235
+ getIncomingEdges(nodeId) {
236
+ const wf = store.get('workflow');
237
+ return wf?.edges.filter(e => e.target === nodeId) ?? [];
238
+ },
239
+
240
+ /**
241
+ * Get all edges originating from a given node.
242
+ * @param {string} nodeId
243
+ * @returns {Array<object>}
244
+ */
245
+ getOutgoingEdges(nodeId) {
246
+ const wf = store.get('workflow');
247
+ return wf?.edges.filter(e => e.source === nodeId) ?? [];
248
+ },
249
+
250
+ /**
251
+ * Serialize the workflow as a plain JSON-friendly object.
252
+ * @returns {object|null}
253
+ */
254
+ toJSON() {
255
+ return this.save();
256
+ },
257
+ };