@synergenius/flow-weaver 0.3.0 → 0.4.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 (73) hide show
  1. package/README.md +1 -0
  2. package/dist/annotation-generator.js +36 -0
  3. package/dist/api/generate-in-place.js +39 -0
  4. package/dist/api/generate.js +11 -1
  5. package/dist/api/manipulation/nodes.js +22 -0
  6. package/dist/ast/types.d.ts +27 -1
  7. package/dist/built-in-nodes/index.d.ts +1 -0
  8. package/dist/built-in-nodes/index.js +1 -0
  9. package/dist/built-in-nodes/invoke-workflow.js +12 -1
  10. package/dist/built-in-nodes/mock-types.d.ts +2 -0
  11. package/dist/built-in-nodes/wait-for-agent.d.ts +13 -0
  12. package/dist/built-in-nodes/wait-for-agent.js +26 -0
  13. package/dist/chevrotain-parser/fan-parser.d.ts +38 -0
  14. package/dist/chevrotain-parser/fan-parser.js +149 -0
  15. package/dist/chevrotain-parser/grammar-diagrams.d.ts +1 -0
  16. package/dist/chevrotain-parser/grammar-diagrams.js +3 -0
  17. package/dist/chevrotain-parser/index.d.ts +3 -1
  18. package/dist/chevrotain-parser/index.js +3 -1
  19. package/dist/chevrotain-parser/tokens.d.ts +2 -0
  20. package/dist/chevrotain-parser/tokens.js +10 -0
  21. package/dist/cli/commands/diagram.d.ts +2 -1
  22. package/dist/cli/commands/diagram.js +9 -6
  23. package/dist/cli/commands/run.js +59 -1
  24. package/dist/cli/flow-weaver.mjs +1396 -77
  25. package/dist/cli/index.js +23 -36
  26. package/dist/diagram/geometry.js +47 -5
  27. package/dist/diagram/html-viewer.d.ts +12 -0
  28. package/dist/diagram/html-viewer.js +399 -0
  29. package/dist/diagram/index.d.ts +12 -0
  30. package/dist/diagram/index.js +22 -0
  31. package/dist/diagram/types.d.ts +1 -0
  32. package/dist/doc-metadata/extractors/annotations.js +282 -1
  33. package/dist/doc-metadata/types.d.ts +6 -0
  34. package/dist/generator/control-flow.d.ts +13 -0
  35. package/dist/generator/control-flow.js +74 -0
  36. package/dist/generator/inngest.js +23 -0
  37. package/dist/generator/unified.js +122 -2
  38. package/dist/jsdoc-parser.d.ts +24 -0
  39. package/dist/jsdoc-parser.js +41 -1
  40. package/dist/mcp/agent-channel.d.ts +35 -0
  41. package/dist/mcp/agent-channel.js +61 -0
  42. package/dist/mcp/run-registry.d.ts +29 -0
  43. package/dist/mcp/run-registry.js +24 -0
  44. package/dist/mcp/tools-diagram.d.ts +1 -1
  45. package/dist/mcp/tools-diagram.js +15 -7
  46. package/dist/mcp/tools-editor.js +75 -3
  47. package/dist/mcp/workflow-executor.d.ts +28 -0
  48. package/dist/mcp/workflow-executor.js +62 -1
  49. package/dist/parser.d.ts +8 -0
  50. package/dist/parser.js +100 -0
  51. package/dist/runtime/ExecutionContext.d.ts +2 -0
  52. package/dist/runtime/ExecutionContext.js +2 -0
  53. package/dist/runtime/events.d.ts +1 -1
  54. package/dist/sugar-optimizer.js +28 -3
  55. package/dist/validator.d.ts +8 -0
  56. package/dist/validator.js +92 -0
  57. package/docs/reference/advanced-annotations.md +431 -0
  58. package/docs/reference/built-in-nodes.md +225 -0
  59. package/docs/reference/cli-reference.md +882 -0
  60. package/docs/reference/compilation.md +351 -0
  61. package/docs/reference/concepts.md +400 -0
  62. package/docs/reference/debugging.md +255 -0
  63. package/docs/reference/deployment.md +207 -0
  64. package/docs/reference/error-codes.md +686 -0
  65. package/docs/reference/export-interface.md +229 -0
  66. package/docs/reference/iterative-development.md +186 -0
  67. package/docs/reference/jsdoc-grammar.md +471 -0
  68. package/docs/reference/marketplace.md +205 -0
  69. package/docs/reference/node-conversion.md +308 -0
  70. package/docs/reference/patterns.md +161 -0
  71. package/docs/reference/scaffold.md +160 -0
  72. package/docs/reference/tutorial.md +519 -0
  73. package/package.json +1 -1
@@ -0,0 +1,400 @@
1
+ ---
2
+ name: Flow Weaver Concepts
3
+ description: Fundamental concepts of Flow Weaver workflows
4
+ keywords: [annotations, nodes, workflows, ports, scopes, STEP, expression, connect, nodeType]
5
+ ---
6
+
7
+ **Source**: https://github.com/synergenius-fw/flow-weaver
8
+
9
+ # Direct Code Editing
10
+
11
+ **The code IS the workflow. The visual editor is a view.**
12
+
13
+ Flow Weaver workflows are plain TypeScript files with JSDoc annotations. You write functions, annotate them, and the compiler handles everything else. No drag-and-drop required.
14
+
15
+ Here is a complete, minimal workflow written entirely by hand:
16
+
17
+ ```typescript
18
+ /**
19
+ * @flowWeaver nodeType
20
+ * @expression
21
+ * @label Greet
22
+ * @input name - Name to greet
23
+ * @output message - Greeting message
24
+ */
25
+ function greet(name: string): string {
26
+ return `Hello, ${name}!`;
27
+ }
28
+
29
+ /**
30
+ * @flowWeaver nodeType
31
+ * @expression
32
+ * @label Uppercase
33
+ * @input text - Text to transform
34
+ * @output result - Uppercased text
35
+ */
36
+ function uppercase(text: string): string {
37
+ return text.toUpperCase();
38
+ }
39
+
40
+ /**
41
+ * @flowWeaver workflow
42
+ * @param name - Name to greet
43
+ * @returns result - Uppercased greeting
44
+ * @node greeter greet
45
+ * @node transform uppercase
46
+ * @connect Start.name -> greeter.name
47
+ * @connect greeter.message -> transform.text
48
+ * @connect transform.result -> Exit.result
49
+ * @position greeter 180 0
50
+ * @position transform 360 0
51
+ */
52
+ export function greetingWorkflow(
53
+ execute: boolean,
54
+ params: { name: string }
55
+ ): { onSuccess: boolean; onFailure: boolean; result: string } {
56
+ return { onSuccess: true, onFailure: false, result: '' };
57
+ }
58
+ ```
59
+
60
+ That is it. Two expression-mode functions, one workflow annotation, zero boilerplate. The compiler infers STEP connections from the data flow -- no `execute`, `onSuccess`, or `onFailure` wiring needed.
61
+
62
+ ---
63
+
64
+ # Quick Reference
65
+
66
+ ## Topic Navigator
67
+
68
+ | Task | Primary Topic | Supporting |
69
+ | -------------------------------- | ---------------------------- | ------------------- |
70
+ | First time? Build a workflow | `tutorial` | concepts |
71
+ | Build from scratch (experienced) | `iterative-development` | concepts, export-interface |
72
+ | Scaffold from template | `scaffold` | concepts |
73
+ | Add iteration/forEach | `export-interface` | concepts |
74
+ | Convert existing functions | `node-conversion` | concepts |
75
+ | Debug validation errors | `debugging` | error-codes |
76
+ | Look up specific error code | `error-codes` | debugging |
77
+ | Reuse workflow fragments | `patterns` | concepts |
78
+ | Check annotation syntax | `jsdoc-grammar` | concepts |
79
+ | Look up CLI commands/flags | `cli-reference` | — |
80
+ | Pull execution, merge strategies | `advanced-annotations` | jsdoc-grammar |
81
+ | Compile to Inngest | `compilation` | cli-reference |
82
+ | Deploy to cloud | `deployment` | compilation |
83
+ | Use delay/waitForEvent/mocks | `built-in-nodes` | debugging |
84
+ | Publish marketplace packages | `marketplace` | — |
85
+
86
+ Use `flow-weaver docs <topic>` to read any topic.
87
+
88
+ ## File Format
89
+
90
+ Workflows are TypeScript files with JSDoc annotations. Any `.ts`, `.tsx`, `.js`, or `.jsx` file with `@flowWeaver` annotations works.
91
+
92
+ ## CLI Commands
93
+
94
+ ```bash
95
+ flow-weaver validate <file> # Check for errors (--json for machine parsing)
96
+ flow-weaver compile <file> # Generate executable code
97
+ flow-weaver run <file> # Execute a workflow directly. No compile step needed for testing.
98
+ flow-weaver describe <file> # Get workflow structure as JSON
99
+ flow-weaver watch <file> # Watch mode
100
+ flow-weaver dev <file> # Watch + compile + run in one command
101
+ flow-weaver serve [dir] # HTTP server exposing workflows as endpoints
102
+ flow-weaver diagram <file> # Generate SVG diagram
103
+ flow-weaver export <file> # Export as serverless function (lambda/vercel/cloudflare/inngest)
104
+ flow-weaver docs # Browse documentation
105
+ flow-weaver docs <topic> # Read a specific topic
106
+ flow-weaver docs search <q> # Search across all docs
107
+ ```
108
+
109
+ Options: `-w/--workflow-name`, `--json`, `--format text|mermaid`. See `cli-reference` for all commands and flags.
110
+
111
+ ## Core Annotations
112
+
113
+ ### Expression Node Type (Recommended)
114
+
115
+ > **Tip:** Most nodes should use `@expression` mode. Use normal mode only for custom error handling or void returns.
116
+
117
+ ```typescript
118
+ /**
119
+ * @flowWeaver nodeType
120
+ * @expression
121
+ * @label Display Name
122
+ * @input inputA - First input
123
+ * @input inputB - Second input
124
+ * @output outputName - Description
125
+ */
126
+ function nodeName(inputA: TypeA, inputB: TypeB): ReturnType {
127
+ // Pure function logic -- no execute param, no onSuccess/onFailure
128
+ return result;
129
+ }
130
+ ```
131
+
132
+ Expression nodes are pure functions where:
133
+
134
+ - No `execute: boolean` parameter -- the runtime handles execution control
135
+ - No `onSuccess`/`onFailure` in return type -- the runtime auto-sets these
136
+ - Function params map directly to `@input` ports
137
+ - Return value maps to `@output` ports:
138
+ - Primitive/array return -> single output port
139
+ - Object return `{ a, b }` -> one port per property
140
+ - Best for: transformers, math, utilities, data mapping, async fetchers, API calls
141
+
142
+ > **Start with expression mode.** Only switch to normal mode when you need explicit branching (`onSuccess`/`onFailure` routing), custom error-with-data patterns, or void returns with side effects.
143
+
144
+ #### Async Expression Example
145
+
146
+ ```typescript
147
+ /**
148
+ * @flowWeaver nodeType
149
+ * @expression
150
+ * @label Fetch User
151
+ * @input userId - User ID to look up
152
+ * @output user - The fetched user object
153
+ */
154
+ async function fetchUser(userId: string): Promise<User> {
155
+ const res = await fetch(`/api/users/${userId}`);
156
+ return await res.json();
157
+ }
158
+ ```
159
+
160
+ ### Node Type (Normal Mode)
161
+
162
+ Use normal mode when you need explicit `try/catch -> onFailure` error handling or `void` returns.
163
+
164
+ ```typescript
165
+ /**
166
+ * @flowWeaver nodeType
167
+ * @label Display Name
168
+ * @input inputA - First input
169
+ * @input inputB - Second input
170
+ * @output outputName - Description
171
+ */
172
+ function nodeName(
173
+ execute: boolean,
174
+ inputA: TypeA, // Each @input becomes a direct parameter
175
+ inputB: TypeB // NOT wrapped in an object
176
+ ): { onSuccess: boolean; onFailure: boolean; outputName: Type } {
177
+ if (!execute) return { onSuccess: false, onFailure: false, outputName: null };
178
+ return { onSuccess: true, onFailure: false, outputName: result };
179
+ }
180
+ ```
181
+
182
+ ### Workflow Export
183
+
184
+ ```typescript
185
+ /**
186
+ * @flowWeaver workflow
187
+ * @param inputPort - Description
188
+ * @returns outputPort - Description
189
+ * @node instanceId nodeTypeName
190
+ * @connect Start.inputPort -> instanceId.input
191
+ * @connect instanceId.output -> Exit.outputPort
192
+ * @position instanceId 180 0
193
+ */
194
+ export function workflowName(
195
+ execute: boolean,
196
+ params: { inputPort: Type }
197
+ ): { onSuccess: boolean; onFailure: boolean; outputPort: Type } {
198
+ return { onSuccess: true, onFailure: false, outputPort: null };
199
+ }
200
+ ```
201
+
202
+ > STEP connections (`execute`, `onSuccess`, `onFailure`) are auto-wired for expression nodes in linear data flows. Add them explicitly only for branching or normal mode nodes.
203
+
204
+ ### Importing External Functions
205
+
206
+ Use `@fwImport` to turn npm package functions or local module exports into node types without writing wrapper code:
207
+
208
+ ```typescript
209
+ /**
210
+ * @flowWeaver workflow
211
+ * @fwImport npm/lodash/map map from "lodash"
212
+ * @fwImport local/utils/format formatDate from "./utils"
213
+ * @node mapper npm/lodash/map
214
+ * @connect Start.items -> mapper.collection
215
+ */
216
+ ```
217
+
218
+ - First identifier: node type name (convention: `npm/pkg/fn` or `local/path/fn`)
219
+ - Second identifier: exported function name
220
+ - String: package name or relative path
221
+
222
+ Imported functions become expression nodes. Port types are inferred from `.d.ts` files when available.
223
+
224
+ ## Mandatory Signatures
225
+
226
+ ### Node Types (direct parameters)
227
+
228
+ ```typescript
229
+ function myNode(execute: boolean, inputA: Type, inputB: Type): {...}
230
+ ```
231
+
232
+ - First param: `execute: boolean`
233
+ - Remaining params: Each `@input` as a direct parameter
234
+ - Return: `{ onSuccess: boolean, onFailure: boolean, ...outputs }`
235
+
236
+ ### Workflow Exports (params object)
237
+
238
+ ```typescript
239
+ export function myWorkflow(execute: boolean, params: { inputA: Type }): {...}
240
+ ```
241
+
242
+ - First param: `execute: boolean`
243
+ - Second param: `params: {...}` object containing all `@param` inputs
244
+ - Return: `{ onSuccess: boolean, onFailure: boolean, ...outputs }`
245
+
246
+ > **Key difference:** Nodes use direct params, workflows use `params` object.
247
+
248
+ ## Port Types
249
+
250
+ STRING, NUMBER, BOOLEAN, OBJECT, ARRAY, FUNCTION, ANY, STEP
251
+
252
+ Types are inferred from TypeScript signature. STEP is for control flow (execute, onSuccess, onFailure).
253
+
254
+ ## Reserved Nodes
255
+
256
+ - `Start` - Flow entry point (exposes workflow inputs via @param)
257
+ - `Exit` - Flow exit point (receives workflow outputs via @returns)
258
+
259
+ ## Scoped Nodes (Iteration/forEach)
260
+
261
+ For loops/iteration, use **per-port scopes** with explicit `scope:scopeName` suffixes.
262
+
263
+ ### ForEach Node Pattern
264
+
265
+ ```typescript
266
+ /**
267
+ * @flowWeaver nodeType
268
+ * @input items - Array to iterate
269
+ * @output start scope:processItem - Mandatory: triggers child execute
270
+ * @output item scope:processItem - Current item to process
271
+ * @input success scope:processItem - Mandatory: from child onSuccess
272
+ * @input failure scope:processItem - Mandatory: from child onFailure
273
+ * @input processed scope:processItem - Result from child
274
+ * @output results - Collected results
275
+ */
276
+ function forEach(
277
+ execute: boolean,
278
+ items: any[],
279
+ processItem: (start: boolean, item: any) => { success: boolean; failure: boolean; processed: any }
280
+ ) {
281
+ if (!execute) return { onSuccess: false, onFailure: false, results: [] };
282
+ const results = items.map((item) => processItem(true, item).processed);
283
+ return { onSuccess: true, onFailure: false, results };
284
+ }
285
+ ```
286
+
287
+ Key points:
288
+
289
+ - Scope name (`processItem`) must match callback parameter name
290
+ - Callback parameter is auto-generated, receives scoped ports as args
291
+ - Node iterates by calling callback for each item
292
+ - `start`, `success`, `failure` are mandatory scoped STEP ports
293
+
294
+ ### Workflow Usage
295
+
296
+ ```typescript
297
+ /**
298
+ * @flowWeaver workflow
299
+ * @node loop forEach
300
+ * @node proc processor loop.processItem
301
+ * @connect Start.execute -> loop.execute
302
+ * @connect Start.items -> loop.items
303
+ * @connect loop.start:processItem -> proc.execute
304
+ * @connect loop.item:processItem -> proc.item
305
+ * @connect proc.result -> loop.processed:processItem
306
+ * @connect proc.onSuccess -> loop.success:processItem
307
+ * @connect proc.onFailure -> loop.failure:processItem
308
+ * @connect loop.results -> Exit.results
309
+ * @connect loop.onSuccess -> Exit.onSuccess
310
+ * @connect loop.onFailure -> Exit.onFailure
311
+ */
312
+ ```
313
+
314
+ See `flow-weaver docs export-interface` for full scope documentation.
315
+
316
+ ## Node Positioning
317
+
318
+ Syntax: `@position nodeId x y` (values in pixels, 90px grid)
319
+
320
+ Default layout:
321
+
322
+ - Start: -450px (col -5)
323
+ - Exit: 450px (col 5)
324
+
325
+ Spacing: 180px horizontal (standard), 150px vertical for branches
326
+
327
+ ## Workflow Recipes
328
+
329
+ ### Recipe 1: Build a Workflow from Scratch
330
+
331
+ ```
332
+ 1. flow-weaver create workflow sequential my-workflow.ts --preview # preview the template
333
+ 2. Write the file with node types + workflow annotations
334
+ 3. flow-weaver validate my-workflow.ts # check for errors
335
+ 4. Fix any errors, re-validate
336
+ 5. flow-weaver compile my-workflow.ts # generate executable code
337
+ 6. flow-weaver describe my-workflow.ts --format text # verify structure
338
+ ```
339
+
340
+ ### Recipe 2: Add a Node to Existing Workflow
341
+
342
+ ```
343
+ 1. flow-weaver describe my-workflow.ts --format text # understand current structure
344
+ 2. Edit the file: add @flowWeaver nodeType function + @node + @connect annotations
345
+ 3. flow-weaver validate my-workflow.ts # verify
346
+ ```
347
+
348
+ ### Recipe 3: Debug a Broken Workflow
349
+
350
+ ```
351
+ 1. flow-weaver validate my-workflow.ts # get all errors
352
+ 2. flow-weaver describe my-workflow.ts --format text # get full picture
353
+ 3. Fix errors based on error codes (see: flow-weaver docs error-codes)
354
+ ```
355
+
356
+ ### Recipe 4: Add Iteration (ForEach)
357
+
358
+ ```
359
+ 1. Read: flow-weaver docs export-interface # scoped port syntax
360
+ 2. Edit file: add forEach node type with scope ports
361
+ 3. Edit file: add child node with parent scope reference
362
+ 4. Edit file: wire scoped connections (:scopeName suffix)
363
+ 5. flow-weaver validate my-workflow.ts # verify scope wiring
364
+ ```
365
+
366
+ ## Workflow Development Process
367
+
368
+ 1. **Create file** - Write TypeScript file with types and node functions
369
+ 2. **Add annotations** - `@flowWeaver nodeType` and `@flowWeaver workflow`
370
+ 3. **Validate** - `flow-weaver validate <file>`
371
+ 4. **Test** - Start with `flow-weaver run <file>` for quick testing. Compile only for production deployment.
372
+ 5. **Compile** - `flow-weaver compile <file>`
373
+ 6. **Inspect** - `flow-weaver describe <file>` for structure
374
+
375
+ ## Additional Annotations
376
+
377
+ Beyond the core annotations above, Flow Weaver supports advanced features:
378
+
379
+ - **`@autoConnect`** — Auto-wire nodes in declaration order (no `@connect` needed)
380
+ - **`@path`** — Declare multi-step routes with `:ok`/`:fail` branching
381
+ - **`@map`** — Shorthand for forEach iteration patterns
382
+ - **`@pullExecution`** — Lazy evaluation (node only executes when output is consumed)
383
+ - **`@executeWhen`** — Control execution strategy (CONJUNCTION/DISJUNCTION/CUSTOM)
384
+ - **`@strictTypes`** — Promote type warnings to errors
385
+ - **Merge strategies** — `[mergeStrategy:COLLECT]` for fan-in patterns
386
+
387
+ See `advanced-annotations` for full documentation.
388
+
389
+ ## Related Topics
390
+
391
+ - `cli-reference` - Complete CLI command reference
392
+ - `advanced-annotations` - Pull execution, merge strategies, auto-connect, and more
393
+ - `compilation` - Compilation targets (TypeScript, Inngest) and options
394
+ - `deployment` - Export to cloud, serve mode, OpenAPI
395
+ - `built-in-nodes` - delay, waitForEvent, invokeWorkflow, and mock system
396
+ - `marketplace` - Package ecosystem and plugins
397
+ - `export-interface` - Interface ports and scoped iteration
398
+ - `iterative-development` - Step-by-step building
399
+ - `debugging` - Troubleshooting workflows
400
+ - `error-codes` - Error code reference
@@ -0,0 +1,255 @@
1
+ ---
2
+ name: Flow Weaver Debugging
3
+ description: Debugging workflows, validation, diagnostics, and error resolution
4
+ keywords: [debug, troubleshooting, errors, WebSocket, diagnostics, runtime, validation, trace]
5
+ ---
6
+
7
+ # Flow Weaver Debugging Guide
8
+
9
+ For error code lookup, use `flow-weaver docs error-codes`.
10
+
11
+ ---
12
+
13
+ ## Top 5 Errors Quick Fix
14
+
15
+ | Error | Fix |
16
+ | ----------------------- | --------------------------------------------------------------- |
17
+ | UNKNOWN_NODE_TYPE | Check spelling, run `flow-weaver describe <file>` |
18
+ | MISSING_REQUIRED_INPUT | Add `@connect` or make port optional with `@input [name]` |
19
+ | STEP_PORT_TYPE_MISMATCH | STEP ports (execute/onSuccess/onFailure) only connect to STEP |
20
+ | CYCLE_DETECTED | Use scoped forEach instead of graph loops |
21
+ | UNKNOWN_SOURCE_PORT | Check port name spelling, run `flow-weaver describe <file>` |
22
+
23
+ ---
24
+
25
+ ## WebSocket Debug Events
26
+
27
+ Flow Weaver can emit real-time execution events over WebSocket for runtime debugging. This is enabled by compiling without the `--production` flag.
28
+
29
+ ### Enabling Debug Events
30
+
31
+ ```bash
32
+ # Compile the workflow (debug mode is the default)
33
+ flow-weaver compile my-workflow.ts
34
+
35
+ # Run with WebSocket debug target
36
+ FLOW_WEAVER_DEBUG=ws://localhost:9000 node my-workflow.generated.js
37
+ ```
38
+
39
+ Production builds (`flow-weaver compile --production`) strip all debug event code.
40
+
41
+ ### Event Types
42
+
43
+ | Event | Description | Key Fields |
44
+ | ------------------ | ---------------------------- | ----------------------------------------- |
45
+ | STATUS_CHANGED | Node execution status change | `id`, `status` (RUNNING/SUCCEEDED/FAILED) |
46
+ | VARIABLE_SET | Port value set | `identifier.portName`, `value` |
47
+ | LOG_ERROR | Node threw an error | `id`, `error` message |
48
+ | WORKFLOW_COMPLETED | Workflow finished | `status`, `result` |
49
+
50
+ ### WebSocket Message Format
51
+
52
+ Messages are JSON-encoded with envelope: `{ type: "event", sessionId, event: {...} }`.
53
+ On connection: `{ type: "connect", sessionId, workflowExportName, clientInfo }`.
54
+
55
+ When a workflow calls another workflow, inner events have `innerFlowInvocation: true`.
56
+
57
+ ---
58
+
59
+ ## Debugging Decision Tree
60
+
61
+ ```
62
+ START: What is the problem?
63
+ |
64
+ +-- "Compilation fails" (parse or validation errors)
65
+ | |
66
+ | +-- Run: flow-weaver validate <file> --verbose
67
+ | |
68
+ | +-- Are there PARSE errors?
69
+ | | |
70
+ | | +-- YES --> Check annotation syntax:
71
+ | | | - @flowWeaver nodeType / workflow present?
72
+ | | | - @connect format: Source.port -> Target.port ?
73
+ | | | - Function signature: (execute: boolean, ...) => { onSuccess, ... } ?
74
+ | | | - Proper JSDoc comment blocks (/** ... */) not line comments (//)?
75
+ | | |
76
+ | | +-- NO --> Are there VALIDATION errors?
77
+ | | |
78
+ | | +-- YES --> Look up the error code: flow-weaver docs error-codes
79
+ | | | Common quick fixes:
80
+ | | | - UNKNOWN_*: Check spelling, use validator suggestions
81
+ | | | - MISSING_REQUIRED_INPUT: Add connection or default
82
+ | | | - CYCLE_DETECTED: Break the loop, use scoped nodes
83
+ | | | - STEP_PORT_TYPE_MISMATCH: Don't mix control/data flow
84
+ | | |
85
+ | | +-- NO --> Warnings only. Workflow is valid but review warnings.
86
+ | | Common warnings to address:
87
+ | | - UNUSED_NODE: Remove or connect it
88
+ | | - MULTIPLE_EXIT_CONNECTIONS: Use separate exit ports
89
+ | | - TYPE_MISMATCH: Verify data compatibility
90
+ |
91
+ +-- "Runtime error" (workflow compiled but fails when executed)
92
+ | |
93
+ | +-- Enable WebSocket debugging:
94
+ | | FLOW_WEAVER_DEBUG=ws://localhost:9000 node <file>
95
+ | |
96
+ | +-- Is the error "Variable not found: X.Y[Z]"?
97
+ | | |
98
+ | | +-- YES --> A node tried to read a port value that was never set.
99
+ | | Causes: upstream node failed silently, connection goes
100
+ | | through a branch that was not taken, execution order issue.
101
+ | | Check: onSuccess/onFailure path taken by upstream node.
102
+ | |
103
+ | | +-- NO --> Is it a CancellationError?
104
+ | | |
105
+ | | +-- YES --> The AbortSignal was triggered. Check abort logic.
106
+ | | |
107
+ | | +-- NO --> Check the LOG_ERROR events for the failing node.
108
+ | | Read the compiled source file to see the actual code.
109
+ | | Common issues:
110
+ | | - NaN from string-to-number coercion
111
+ | | - undefined property access on OBJECT ports
112
+ | | - JSON.parse failure on string-to-object coercion
113
+ |
114
+ +-- "Wrong output" (workflow runs but returns unexpected values)
115
+ | |
116
+ | +-- Use VARIABLE_SET events to trace data through the graph
117
+ | |
118
+ | +-- Check Exit port connections:
119
+ | | - Is the correct node connected to the Exit port?
120
+ | | - Are there MULTIPLE_EXIT_CONNECTIONS? (only one value used)
121
+ | | - Is the Exit port receiving data from the right branch?
122
+ | |
123
+ | +-- Check branching:
124
+ | | - Which branch was taken (onSuccess vs onFailure)?
125
+ | | - Are conditional nodes evaluating as expected?
126
+ | |
127
+ | +-- Read the compiled source file to verify wiring
128
+ |
129
+ +-- "Node not executing" (node appears to be skipped)
130
+ |
131
+ +-- Is the execute port connected?
132
+ | - Check: Start.onSuccess -> Node.execute or PreviousNode.onSuccess -> Node.execute
133
+ |
134
+ +-- Is the execute signal true?
135
+ | - CONJUNCTION strategy: ALL upstream STEP sources must be true
136
+ | - DISJUNCTION strategy: ANY upstream STEP source must be true
137
+ |
138
+ +-- Is the node on a branch that was not taken?
139
+ | - If upstream node failed, onSuccess=false, onFailure=true
140
+ | - Nodes on the onSuccess branch will receive execute=false
141
+ |
142
+ +-- Is the node in a scope?
143
+ - Scoped nodes only execute when their parent iterates
144
+ - Check the parent node's execution and scope function
145
+ ```
146
+
147
+ ---
148
+
149
+ ## CLI Debugging Commands
150
+
151
+ ### flow-weaver validate -- Validate a Workflow
152
+
153
+ The first command to use when something seems wrong. Returns all errors and warnings with codes, messages, and hints.
154
+
155
+ ```bash
156
+ flow-weaver validate src/workflows/my-workflow.ts
157
+ flow-weaver validate src/workflows/my-workflow.ts --json # machine-readable
158
+ flow-weaver validate src/workflows/my-workflow.ts --verbose # detailed diagnostics
159
+ ```
160
+
161
+ ### flow-weaver describe -- Understand Workflow Structure
162
+
163
+ Provides a full description of the workflow: nodes, connections, ports, types, and execution graph.
164
+
165
+ ```bash
166
+ flow-weaver describe src/workflows/my-workflow.ts # JSON
167
+ flow-weaver describe src/workflows/my-workflow.ts --format text # human-readable
168
+ flow-weaver describe src/workflows/my-workflow.ts --format mermaid # diagram
169
+ flow-weaver describe src/workflows/my-workflow.ts --node fetcher1 # focus on a node
170
+ ```
171
+
172
+ ### Diagnostic Strategy
173
+
174
+ 1. **flow-weaver validate** -- Get all errors and warnings. Fix errors first.
175
+ 2. **flow-weaver describe --format text** -- Full readable summary.
176
+ 3. **flow-weaver describe --node <id>** -- Trace data flow for a specific node.
177
+ 4. **flow-weaver describe --format mermaid** -- Visual graph for inspection.
178
+
179
+ ---
180
+
181
+ ## Common Error Patterns
182
+
183
+ ### Export Returns null/undefined
184
+
185
+ **Cause 1: Exit port not connected.** Add `@connect Processor.result -> Exit.output`.
186
+
187
+ **Cause 2: Multiple connections to same Exit port.** Only one value is used. Use separate Exit ports for each branch.
188
+
189
+ **Cause 3: Upstream node failed.** Check WebSocket events for `FAILED` status.
190
+
191
+ ### "Variable not found" Runtime Error
192
+
193
+ Execution context tried to read a variable never written. Source node didn't execute, failed, or an execution index mismatch. Ensure execution path guarantees source runs before consumer.
194
+
195
+ ### STEP vs Data Port Confusion
196
+
197
+ The three control flow ports (`execute`, `onSuccess`, `onFailure`) are STEP type. They only connect to other STEP ports. All other ports are data ports and only connect to data ports.
198
+
199
+ ```typescript
200
+ // Control flow (STEP to STEP):
201
+ /** @connect NodeA.onSuccess -> NodeB.execute */
202
+ // Data flow (DATA to DATA):
203
+ /** @connect NodeA.result -> NodeB.inputData */
204
+ ```
205
+
206
+ ### Scoped Node Children Not Executing
207
+
208
+ Scoped ports use direction inversion: scoped OUTPUTS = data parent sends to children, scoped INPUTS = data parent receives from children. Ensure child instances have `parent` set to the scoped node.
209
+
210
+ ### Workflow Compiles but Generated Code Has Issues
211
+
212
+ 1. Read the compiled source file to inspect actual code (compilation modifies the file in-place)
213
+ 2. Check connection wiring and variable resolution order
214
+ 3. Re-compile without `--production` to enable tracing
215
+
216
+ ---
217
+
218
+ ## Mock System for Built-in Nodes
219
+
220
+ When testing workflows that use `delay`, `waitForEvent`, or `invokeWorkflow`, use mocks to avoid real side effects:
221
+
222
+ ```bash
223
+ flow-weaver run workflow.ts --mocks '{"fast": true, "events": {"app/approved": {"status": "ok"}}}'
224
+ flow-weaver run workflow.ts --mocks-file mocks.json
225
+ ```
226
+
227
+ Mock config structure:
228
+ - `fast: true` — Skip real sleep in `delay` nodes (1ms instead)
229
+ - `events: { "event-name": data }` — Mock event data for `waitForEvent`
230
+ - `invocations: { "function-id": result }` — Mock results for `invokeWorkflow`
231
+
232
+ See `built-in-nodes` for full documentation on mock configuration and testing patterns.
233
+
234
+ ## Dev Mode
235
+
236
+ Use `flow-weaver dev` to watch, compile, and run in a single command:
237
+
238
+ ```bash
239
+ flow-weaver dev workflow.ts --params '{"data": "test"}'
240
+ ```
241
+
242
+ This recompiles and re-runs automatically on every file save.
243
+
244
+ ---
245
+
246
+ ## Related Topics
247
+
248
+ - `error-codes` — Error code reference with fixes
249
+ - `built-in-nodes` — Mock system for delay, waitForEvent, invokeWorkflow
250
+ - `cli-reference` — All CLI commands and flags
251
+ - `advanced-annotations` — Pull execution, merge strategies, and other advanced features
252
+
253
+ ## Still Stuck?
254
+
255
+ Read the source: https://github.com/synergenius-fw/flow-weaver