@crewx/workflow 0.3.8 → 0.3.9
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.
- package/SKILL.md +409 -409
- package/dist/cli.js +34 -34
- package/dist/src/run-manager.d.ts.map +1 -1
- package/dist/src/run-manager.js +65 -3
- package/dist/src/run-manager.js.map +1 -1
- package/dist/src/types.d.ts +10 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/output-format.d.ts +5 -0
- package/dist/src/utils/output-format.d.ts.map +1 -0
- package/dist/src/utils/output-format.js +83 -0
- package/dist/src/utils/output-format.js.map +1 -0
- package/dist/workflow-schema.json +218 -179
- package/package.json +3 -3
- package/workflow-schema.json +218 -179
package/SKILL.md
CHANGED
|
@@ -1,409 +1,409 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: crewx/workflow
|
|
3
|
-
description: Workflow management built-in tool. List, view details (with Mermaid), validate syntax, and manage execution state.
|
|
4
|
-
argument-hint: "<list|show|validate|run> [args]"
|
|
5
|
-
metadata:
|
|
6
|
-
version: 0.3.3
|
|
7
|
-
built-in: true
|
|
8
|
-
entrypoint: cli.ts
|
|
9
|
-
schema: workflow-schema.json
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# CrewX Workflow
|
|
13
|
-
|
|
14
|
-
A built-in tool for managing agent collaboration flows using **semantic workflow YAML**. Define multi-agent processes as directed graphs, visualize them as Mermaid diagrams, validate syntax, and track execution state.
|
|
15
|
-
|
|
16
|
-
## When to Use
|
|
17
|
-
|
|
18
|
-
- "Show available workflows" / "List workflows"
|
|
19
|
-
- "Show me the workflow diagram" / "Visualize the dev process"
|
|
20
|
-
- "Validate my workflow YAML"
|
|
21
|
-
- "Start the code-review workflow" / "Execute the next step"
|
|
22
|
-
- "What's the current state of the running workflow?"
|
|
23
|
-
- When you need to orchestrate multiple agents in a defined sequence
|
|
24
|
-
- When you want to design a reusable collaboration recipe
|
|
25
|
-
|
|
26
|
-
## Quick Start
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
# List all workflows
|
|
30
|
-
crewx workflow list
|
|
31
|
-
|
|
32
|
-
# View workflow details with Mermaid diagram
|
|
33
|
-
crewx workflow show standard-dev-core --mermaid
|
|
34
|
-
|
|
35
|
-
# Validate all workflow files
|
|
36
|
-
crewx workflow validate
|
|
37
|
-
|
|
38
|
-
# Start a workflow execution
|
|
39
|
-
crewx workflow run start standard-dev-core --set goal="implement feature X"
|
|
40
|
-
|
|
41
|
-
# Move to a node
|
|
42
|
-
crewx workflow run node <exec-id> research
|
|
43
|
-
|
|
44
|
-
# Check execution state
|
|
45
|
-
crewx workflow run state <exec-id>
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Commands
|
|
49
|
-
|
|
50
|
-
### `workflow list`
|
|
51
|
-
|
|
52
|
-
Scans `workflows/*.yaml` and outputs all workflow definitions.
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
crewx workflow list # Human-readable table
|
|
56
|
-
crewx workflow list --json # JSON output
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### `workflow show <id|file>`
|
|
60
|
-
|
|
61
|
-
Displays workflow details: metadata, nodes, agents, and optionally a Mermaid diagram.
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
crewx workflow show standard-dev-core
|
|
65
|
-
crewx workflow show standard-dev-core --mermaid # Include Mermaid code
|
|
66
|
-
crewx workflow show standard-dev-core --json # JSON output
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### `workflow validate [file]`
|
|
70
|
-
|
|
71
|
-
Three-phase validation: JSON Schema -> required fields -> reference integrity (node references, agent existence).
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
crewx workflow validate # Validate all files in workflows/
|
|
75
|
-
crewx workflow validate workflows/standard-dev.yaml # Validate a specific file
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### `workflow run start <id|file>`
|
|
79
|
-
|
|
80
|
-
Creates a new execution instance. State is stored as a JSON file in `.crewx/workflow-runs/`.
|
|
81
|
-
|
|
82
|
-
```bash
|
|
83
|
-
crewx workflow run start standard-dev-core
|
|
84
|
-
crewx workflow run start standard-dev-core --set goal="build auth module"
|
|
85
|
-
crewx workflow run start workflows/idea-validation.yaml
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### `workflow run state <exec-id>`
|
|
89
|
-
|
|
90
|
-
Query or modify execution state.
|
|
91
|
-
|
|
92
|
-
```bash
|
|
93
|
-
crewx workflow run state wfr_abc12345 # View state
|
|
94
|
-
crewx workflow run state wfr_abc12345 --set result="completed" # Set a value
|
|
95
|
-
echo "Long text..." | crewx workflow run state wfr_abc12345 --set analysis=- # Pipe via stdin
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### `workflow run node <exec-id> <node-id>`
|
|
99
|
-
|
|
100
|
-
Move to a node: sets `current_node` and appends to `completed_nodes`. For `agent_task` nodes, triggers agent execution via `crewx q/x`.
|
|
101
|
-
|
|
102
|
-
```bash
|
|
103
|
-
crewx workflow run node wfr_abc12345 research
|
|
104
|
-
crewx workflow run node wfr_abc12345 end
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### `workflow run reset <exec-id>`
|
|
108
|
-
|
|
109
|
-
Restores execution state to `initial_state`.
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
crewx workflow run reset wfr_abc12345
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### `workflow run list`
|
|
116
|
-
|
|
117
|
-
Lists all execution instances.
|
|
118
|
-
|
|
119
|
-
```bash
|
|
120
|
-
crewx workflow run list
|
|
121
|
-
crewx workflow run list --json
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
All `run` subcommands support the `--json` flag.
|
|
125
|
-
|
|
126
|
-
## Name Resolution
|
|
127
|
-
|
|
128
|
-
`<id|file>` resolves in this order:
|
|
129
|
-
|
|
130
|
-
1. `.yaml` / `.yml` extension -> treated as direct file path
|
|
131
|
-
2. Workflow ID -> scans all YAML files for matching `workflows:` key
|
|
132
|
-
3. Filename slug -> `workflows/<name>.yaml`
|
|
133
|
-
|
|
134
|
-
## Workflow YAML Structure
|
|
135
|
-
|
|
136
|
-
```yaml
|
|
137
|
-
workflows:
|
|
138
|
-
process-name:
|
|
139
|
-
metadata:
|
|
140
|
-
name: "Process Name"
|
|
141
|
-
description: "What this workflow does"
|
|
142
|
-
version: "1.0"
|
|
143
|
-
timeout: 300 # Global timeout (seconds)
|
|
144
|
-
max_iterations: 50 # Max node transitions
|
|
145
|
-
state: # Initial state variables
|
|
146
|
-
goal: ""
|
|
147
|
-
result: ""
|
|
148
|
-
nodes:
|
|
149
|
-
step_id:
|
|
150
|
-
type: agent_task
|
|
151
|
-
...
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### Top-Level Fields
|
|
155
|
-
|
|
156
|
-
| Field | Type | Required | Description |
|
|
157
|
-
|-------|------|----------|-------------|
|
|
158
|
-
| `metadata` | object | No | `name` (required), `description`, `version` |
|
|
159
|
-
| `timeout` | number | No | Global timeout in seconds |
|
|
160
|
-
| `max_iterations` | number | No | Maximum node transitions |
|
|
161
|
-
| `state` | object | No | Initial state variables (accessible via `{{var}}`) |
|
|
162
|
-
| `nodes` | object | **Yes** | Node definitions (keyed by node ID) |
|
|
163
|
-
|
|
164
|
-
## Node Types
|
|
165
|
-
|
|
166
|
-
### `agent_task` -- Assign task to an agent
|
|
167
|
-
|
|
168
|
-
```yaml
|
|
169
|
-
analyze:
|
|
170
|
-
type: agent_task
|
|
171
|
-
agent: tax_lawyer
|
|
172
|
-
mode: query # query (read-only) | execute (read-write)
|
|
173
|
-
input: |
|
|
174
|
-
Analyze the tax law: {{user_input}}
|
|
175
|
-
output: law_analysis # State key to store the result
|
|
176
|
-
next: calculate
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
### `parallel` -- Fan-out to concurrent branches
|
|
180
|
-
|
|
181
|
-
```yaml
|
|
182
|
-
parallel_review:
|
|
183
|
-
type: parallel
|
|
184
|
-
branches: [cpo_review, persona_survey]
|
|
185
|
-
join: merge_feedback # Node to converge at
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
### `join` -- Fan-in from parallel branches
|
|
189
|
-
|
|
190
|
-
```yaml
|
|
191
|
-
merge_feedback:
|
|
192
|
-
type: join
|
|
193
|
-
on_failure: continue # continue even if a branch failed
|
|
194
|
-
next: check_quality
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
### `branch` -- Conditional routing
|
|
198
|
-
|
|
199
|
-
```yaml
|
|
200
|
-
check_approval:
|
|
201
|
-
type: branch
|
|
202
|
-
condition: "state.cpo_feedback.includes('approved')"
|
|
203
|
-
branches:
|
|
204
|
-
"true": end
|
|
205
|
-
"false": persona_survey
|
|
206
|
-
default: persona_survey
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
### `approval` -- Wait for human decision
|
|
210
|
-
|
|
211
|
-
```yaml
|
|
212
|
-
human_check:
|
|
213
|
-
type: approval
|
|
214
|
-
description: "Would you like to review and approve the result?"
|
|
215
|
-
assignee: "@manager"
|
|
216
|
-
on_approve: publish
|
|
217
|
-
on_reject: revise
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
### `expression` -- Safe state computation
|
|
221
|
-
|
|
222
|
-
Evaluates safe expressions (arithmetic, string, comparison, ternary) and stores results in state. No agent call -- runs instantly.
|
|
223
|
-
|
|
224
|
-
**Allowed:** `+`, `-`, `*`, `/`, `%`, `>`, `<`, `>=`, `<=`, `==`, `!=`, `&&`, `||`, `!`, `? :`, `()`, number/string/boolean literals, state variable references.
|
|
225
|
-
|
|
226
|
-
**Blocked:** `require`, `import`, `process`, `eval`, `Function`, `.` (property access), `[` (bracket access), `__proto__`, `constructor`, `prototype`.
|
|
227
|
-
|
|
228
|
-
```yaml
|
|
229
|
-
# Increment counter
|
|
230
|
-
increment_fix:
|
|
231
|
-
type: expression
|
|
232
|
-
set:
|
|
233
|
-
fix_count: "fix_count + 1"
|
|
234
|
-
next: fix
|
|
235
|
-
|
|
236
|
-
# Multiple keys
|
|
237
|
-
calculate:
|
|
238
|
-
type: expression
|
|
239
|
-
set:
|
|
240
|
-
score: "(pass_count / total_count) * 100"
|
|
241
|
-
remaining: "max_retry - fix_count"
|
|
242
|
-
summary: "wi_id + ' - attempt ' + fix_count"
|
|
243
|
-
next: check_score
|
|
244
|
-
|
|
245
|
-
# Ternary
|
|
246
|
-
decide:
|
|
247
|
-
type: expression
|
|
248
|
-
set:
|
|
249
|
-
action: "fix_count > 3 ? 'escalate' : 'retry'"
|
|
250
|
-
next: route
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
State values are auto-coerced: numeric strings become numbers for arithmetic, results are stored as strings.
|
|
254
|
-
|
|
255
|
-
### `end` -- Termination
|
|
256
|
-
|
|
257
|
-
```yaml
|
|
258
|
-
end:
|
|
259
|
-
type: end
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
## Common Node Options
|
|
263
|
-
|
|
264
|
-
| Field | Type | Description |
|
|
265
|
-
|-------|------|-------------|
|
|
266
|
-
| `timeout` | number | Per-node timeout in seconds |
|
|
267
|
-
| `retry` | object | `{ max, delay: "exponential" \| "fixed" }` |
|
|
268
|
-
| `hooks` | string[] | Hook packages to apply |
|
|
269
|
-
| `on_failure` | string | `fail_fast` \| `continue` \| `ignore` |
|
|
270
|
-
| `on_error` | object | `{ handler?, fallback_node? }` |
|
|
271
|
-
| `comment` | string | Human-readable annotation |
|
|
272
|
-
|
|
273
|
-
## Template Syntax
|
|
274
|
-
|
|
275
|
-
Use `{{variable_name}}` in `input` fields to reference `state` values.
|
|
276
|
-
|
|
277
|
-
```yaml
|
|
278
|
-
state:
|
|
279
|
-
goal: "implement auth"
|
|
280
|
-
nodes:
|
|
281
|
-
plan:
|
|
282
|
-
type: agent_task
|
|
283
|
-
agent: architect
|
|
284
|
-
input: "Create a plan for: {{goal}}"
|
|
285
|
-
output: plan_result
|
|
286
|
-
next: implement
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
## Programmatic API
|
|
290
|
-
|
|
291
|
-
### WorkflowEngine
|
|
292
|
-
|
|
293
|
-
YAML loading, validation, and Mermaid generation. Used by both CLI and server.
|
|
294
|
-
|
|
295
|
-
```typescript
|
|
296
|
-
import { WorkflowEngine } from '@crewx/workflow';
|
|
297
|
-
|
|
298
|
-
const engine = new WorkflowEngine();
|
|
299
|
-
|
|
300
|
-
// Load all workflows from a directory
|
|
301
|
-
const workflows: LoadedWorkflow[] = engine.loadWorkflows('workflows/');
|
|
302
|
-
|
|
303
|
-
// Validate a workflow file (schema -> fields -> references)
|
|
304
|
-
const result = engine.validateFile('workflows/standard-dev.yaml');
|
|
305
|
-
// { success: boolean; results: ValidationResult[]; error?: string }
|
|
306
|
-
|
|
307
|
-
// Generate Mermaid diagram
|
|
308
|
-
const mermaid: string = engine.toMermaid(spec);
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
### RunManager
|
|
312
|
-
|
|
313
|
-
Execution state management. Stores state as JSON files in `.crewx/workflow-runs/`.
|
|
314
|
-
|
|
315
|
-
```typescript
|
|
316
|
-
import { RunManager } from '@crewx/workflow';
|
|
317
|
-
|
|
318
|
-
const manager = new RunManager();
|
|
319
|
-
|
|
320
|
-
// Start execution
|
|
321
|
-
const exec: RunExecution = manager.start('workflows/dev.yaml', 'dev-core', { goal: 'build feature' });
|
|
322
|
-
|
|
323
|
-
// Execute a node (triggers agent call for agent_task nodes)
|
|
324
|
-
const updated: RunExecution = await manager.executeNode(exec.id, 'research');
|
|
325
|
-
|
|
326
|
-
// Move to node without executing
|
|
327
|
-
const moved: RunExecution = manager.moveNode(exec.id, 'implement');
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
### Key Types
|
|
331
|
-
|
|
332
|
-
```typescript
|
|
333
|
-
type NodeType = 'agent_task' | 'parallel' | 'join' | 'branch' | 'approval' | 'expression' | 'end';
|
|
334
|
-
|
|
335
|
-
interface RunExecution {
|
|
336
|
-
id: string; // 'wfr_{nanoid(8)}'
|
|
337
|
-
workflow_id: string;
|
|
338
|
-
workflow_file: string;
|
|
339
|
-
created_at: string; // ISO 8601
|
|
340
|
-
updated_at: string;
|
|
341
|
-
current_node: string;
|
|
342
|
-
completed_nodes: string[];
|
|
343
|
-
state: Record<string, unknown>;
|
|
344
|
-
initial_state: Record<string, unknown>;
|
|
345
|
-
status?: 'running' | 'completed' | 'failed';
|
|
346
|
-
}
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
## Architecture
|
|
350
|
-
|
|
351
|
-
```
|
|
352
|
-
[CLI] crewx workflow list/show/validate
|
|
353
|
-
|
|
|
354
|
-
v
|
|
355
|
-
WorkflowEngine <-- YAML parsing, validation, Mermaid
|
|
356
|
-
|
|
|
357
|
-
v
|
|
358
|
-
workflows/*.yaml (source files)
|
|
359
|
-
|
|
360
|
-
[CLI] crewx workflow run start/node/state
|
|
361
|
-
|
|
|
362
|
-
v
|
|
363
|
-
RunManager <-- execution state management
|
|
364
|
-
|
|
|
365
|
-
+---> .crewx/workflow-runs/wfr_*.json (state files)
|
|
366
|
-
+---> crewx q/x (agent invocation for agent_task nodes)
|
|
367
|
-
|
|
368
|
-
[Server] GET /api/v1/workflows[/:id]
|
|
369
|
-
|
|
|
370
|
-
v
|
|
371
|
-
WorkflowService --> fs (YAML read) + WorkflowEngine.toMermaid()
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
> **Note:** The server only uses `WorkflowEngine.toMermaid()`. YAML listing/parsing is handled by the server's own `WorkflowService`. `RunManager` (execution state) is CLI-only.
|
|
375
|
-
|
|
376
|
-
## Environment Variables
|
|
377
|
-
|
|
378
|
-
| Variable | Description | Default |
|
|
379
|
-
|----------|-------------|---------|
|
|
380
|
-
| `CREWX_WORKSPACE` | Workspace directory (where `workflows/` lives) | `.` |
|
|
381
|
-
| `CREWX_CLI` | CrewX CLI path (for agent execution in `run node`) | `npx crewx` |
|
|
382
|
-
| `CREWX_WORKFLOW_TIMEOUT` | Node execution timeout (ms) | `1800000` (30 min) |
|
|
383
|
-
| `CREWX_CONFIG` | Custom config file path | `crewx.yaml` |
|
|
384
|
-
|
|
385
|
-
## WARNING: Check Agent List Before Designing
|
|
386
|
-
|
|
387
|
-
**Specifying a non-existent agent in a workflow will prevent execution!** Always verify available agents first:
|
|
388
|
-
|
|
389
|
-
```bash
|
|
390
|
-
crewx agent ls
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
## File Layout
|
|
394
|
-
|
|
395
|
-
```
|
|
396
|
-
workflows/ # Workflow YAML sources
|
|
397
|
-
standard-dev.yaml
|
|
398
|
-
idea-validation.yaml
|
|
399
|
-
.crewx/workflow-runs/ # Execution state (auto-created)
|
|
400
|
-
wfr_abc12345.json
|
|
401
|
-
packages/built-in/workflow/ # Package source
|
|
402
|
-
cli.ts # CLI entrypoint
|
|
403
|
-
src/
|
|
404
|
-
types.ts # TypeScript interfaces
|
|
405
|
-
engine.ts # WorkflowEngine
|
|
406
|
-
mermaid.ts # Mermaid diagram renderer
|
|
407
|
-
run-manager.ts # RunManager
|
|
408
|
-
workflow-schema.json # JSON Schema for validation
|
|
409
|
-
```
|
|
1
|
+
---
|
|
2
|
+
name: crewx/workflow
|
|
3
|
+
description: Workflow management built-in tool. List, view details (with Mermaid), validate syntax, and manage execution state.
|
|
4
|
+
argument-hint: "<list|show|validate|run> [args]"
|
|
5
|
+
metadata:
|
|
6
|
+
version: 0.3.3
|
|
7
|
+
built-in: true
|
|
8
|
+
entrypoint: cli.ts
|
|
9
|
+
schema: workflow-schema.json
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# CrewX Workflow
|
|
13
|
+
|
|
14
|
+
A built-in tool for managing agent collaboration flows using **semantic workflow YAML**. Define multi-agent processes as directed graphs, visualize them as Mermaid diagrams, validate syntax, and track execution state.
|
|
15
|
+
|
|
16
|
+
## When to Use
|
|
17
|
+
|
|
18
|
+
- "Show available workflows" / "List workflows"
|
|
19
|
+
- "Show me the workflow diagram" / "Visualize the dev process"
|
|
20
|
+
- "Validate my workflow YAML"
|
|
21
|
+
- "Start the code-review workflow" / "Execute the next step"
|
|
22
|
+
- "What's the current state of the running workflow?"
|
|
23
|
+
- When you need to orchestrate multiple agents in a defined sequence
|
|
24
|
+
- When you want to design a reusable collaboration recipe
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# List all workflows
|
|
30
|
+
crewx workflow list
|
|
31
|
+
|
|
32
|
+
# View workflow details with Mermaid diagram
|
|
33
|
+
crewx workflow show standard-dev-core --mermaid
|
|
34
|
+
|
|
35
|
+
# Validate all workflow files
|
|
36
|
+
crewx workflow validate
|
|
37
|
+
|
|
38
|
+
# Start a workflow execution
|
|
39
|
+
crewx workflow run start standard-dev-core --set goal="implement feature X"
|
|
40
|
+
|
|
41
|
+
# Move to a node
|
|
42
|
+
crewx workflow run node <exec-id> research
|
|
43
|
+
|
|
44
|
+
# Check execution state
|
|
45
|
+
crewx workflow run state <exec-id>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Commands
|
|
49
|
+
|
|
50
|
+
### `workflow list`
|
|
51
|
+
|
|
52
|
+
Scans `workflows/*.yaml` and outputs all workflow definitions.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
crewx workflow list # Human-readable table
|
|
56
|
+
crewx workflow list --json # JSON output
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### `workflow show <id|file>`
|
|
60
|
+
|
|
61
|
+
Displays workflow details: metadata, nodes, agents, and optionally a Mermaid diagram.
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
crewx workflow show standard-dev-core
|
|
65
|
+
crewx workflow show standard-dev-core --mermaid # Include Mermaid code
|
|
66
|
+
crewx workflow show standard-dev-core --json # JSON output
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### `workflow validate [file]`
|
|
70
|
+
|
|
71
|
+
Three-phase validation: JSON Schema -> required fields -> reference integrity (node references, agent existence).
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
crewx workflow validate # Validate all files in workflows/
|
|
75
|
+
crewx workflow validate workflows/standard-dev.yaml # Validate a specific file
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### `workflow run start <id|file>`
|
|
79
|
+
|
|
80
|
+
Creates a new execution instance. State is stored as a JSON file in `.crewx/workflow-runs/`.
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
crewx workflow run start standard-dev-core
|
|
84
|
+
crewx workflow run start standard-dev-core --set goal="build auth module"
|
|
85
|
+
crewx workflow run start workflows/idea-validation.yaml
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### `workflow run state <exec-id>`
|
|
89
|
+
|
|
90
|
+
Query or modify execution state.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
crewx workflow run state wfr_abc12345 # View state
|
|
94
|
+
crewx workflow run state wfr_abc12345 --set result="completed" # Set a value
|
|
95
|
+
echo "Long text..." | crewx workflow run state wfr_abc12345 --set analysis=- # Pipe via stdin
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### `workflow run node <exec-id> <node-id>`
|
|
99
|
+
|
|
100
|
+
Move to a node: sets `current_node` and appends to `completed_nodes`. For `agent_task` nodes, triggers agent execution via `crewx q/x`.
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
crewx workflow run node wfr_abc12345 research
|
|
104
|
+
crewx workflow run node wfr_abc12345 end
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### `workflow run reset <exec-id>`
|
|
108
|
+
|
|
109
|
+
Restores execution state to `initial_state`.
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
crewx workflow run reset wfr_abc12345
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### `workflow run list`
|
|
116
|
+
|
|
117
|
+
Lists all execution instances.
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
crewx workflow run list
|
|
121
|
+
crewx workflow run list --json
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
All `run` subcommands support the `--json` flag.
|
|
125
|
+
|
|
126
|
+
## Name Resolution
|
|
127
|
+
|
|
128
|
+
`<id|file>` resolves in this order:
|
|
129
|
+
|
|
130
|
+
1. `.yaml` / `.yml` extension -> treated as direct file path
|
|
131
|
+
2. Workflow ID -> scans all YAML files for matching `workflows:` key
|
|
132
|
+
3. Filename slug -> `workflows/<name>.yaml`
|
|
133
|
+
|
|
134
|
+
## Workflow YAML Structure
|
|
135
|
+
|
|
136
|
+
```yaml
|
|
137
|
+
workflows:
|
|
138
|
+
process-name:
|
|
139
|
+
metadata:
|
|
140
|
+
name: "Process Name"
|
|
141
|
+
description: "What this workflow does"
|
|
142
|
+
version: "1.0"
|
|
143
|
+
timeout: 300 # Global timeout (seconds)
|
|
144
|
+
max_iterations: 50 # Max node transitions
|
|
145
|
+
state: # Initial state variables
|
|
146
|
+
goal: ""
|
|
147
|
+
result: ""
|
|
148
|
+
nodes:
|
|
149
|
+
step_id:
|
|
150
|
+
type: agent_task
|
|
151
|
+
...
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Top-Level Fields
|
|
155
|
+
|
|
156
|
+
| Field | Type | Required | Description |
|
|
157
|
+
|-------|------|----------|-------------|
|
|
158
|
+
| `metadata` | object | No | `name` (required), `description`, `version` |
|
|
159
|
+
| `timeout` | number | No | Global timeout in seconds |
|
|
160
|
+
| `max_iterations` | number | No | Maximum node transitions |
|
|
161
|
+
| `state` | object | No | Initial state variables (accessible via `{{var}}`) |
|
|
162
|
+
| `nodes` | object | **Yes** | Node definitions (keyed by node ID) |
|
|
163
|
+
|
|
164
|
+
## Node Types
|
|
165
|
+
|
|
166
|
+
### `agent_task` -- Assign task to an agent
|
|
167
|
+
|
|
168
|
+
```yaml
|
|
169
|
+
analyze:
|
|
170
|
+
type: agent_task
|
|
171
|
+
agent: tax_lawyer
|
|
172
|
+
mode: query # query (read-only) | execute (read-write)
|
|
173
|
+
input: |
|
|
174
|
+
Analyze the tax law: {{user_input}}
|
|
175
|
+
output: law_analysis # State key to store the result
|
|
176
|
+
next: calculate
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### `parallel` -- Fan-out to concurrent branches
|
|
180
|
+
|
|
181
|
+
```yaml
|
|
182
|
+
parallel_review:
|
|
183
|
+
type: parallel
|
|
184
|
+
branches: [cpo_review, persona_survey]
|
|
185
|
+
join: merge_feedback # Node to converge at
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### `join` -- Fan-in from parallel branches
|
|
189
|
+
|
|
190
|
+
```yaml
|
|
191
|
+
merge_feedback:
|
|
192
|
+
type: join
|
|
193
|
+
on_failure: continue # continue even if a branch failed
|
|
194
|
+
next: check_quality
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### `branch` -- Conditional routing
|
|
198
|
+
|
|
199
|
+
```yaml
|
|
200
|
+
check_approval:
|
|
201
|
+
type: branch
|
|
202
|
+
condition: "state.cpo_feedback.includes('approved')"
|
|
203
|
+
branches:
|
|
204
|
+
"true": end
|
|
205
|
+
"false": persona_survey
|
|
206
|
+
default: persona_survey
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### `approval` -- Wait for human decision
|
|
210
|
+
|
|
211
|
+
```yaml
|
|
212
|
+
human_check:
|
|
213
|
+
type: approval
|
|
214
|
+
description: "Would you like to review and approve the result?"
|
|
215
|
+
assignee: "@manager"
|
|
216
|
+
on_approve: publish
|
|
217
|
+
on_reject: revise
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### `expression` -- Safe state computation
|
|
221
|
+
|
|
222
|
+
Evaluates safe expressions (arithmetic, string, comparison, ternary) and stores results in state. No agent call -- runs instantly.
|
|
223
|
+
|
|
224
|
+
**Allowed:** `+`, `-`, `*`, `/`, `%`, `>`, `<`, `>=`, `<=`, `==`, `!=`, `&&`, `||`, `!`, `? :`, `()`, number/string/boolean literals, state variable references.
|
|
225
|
+
|
|
226
|
+
**Blocked:** `require`, `import`, `process`, `eval`, `Function`, `.` (property access), `[` (bracket access), `__proto__`, `constructor`, `prototype`.
|
|
227
|
+
|
|
228
|
+
```yaml
|
|
229
|
+
# Increment counter
|
|
230
|
+
increment_fix:
|
|
231
|
+
type: expression
|
|
232
|
+
set:
|
|
233
|
+
fix_count: "fix_count + 1"
|
|
234
|
+
next: fix
|
|
235
|
+
|
|
236
|
+
# Multiple keys
|
|
237
|
+
calculate:
|
|
238
|
+
type: expression
|
|
239
|
+
set:
|
|
240
|
+
score: "(pass_count / total_count) * 100"
|
|
241
|
+
remaining: "max_retry - fix_count"
|
|
242
|
+
summary: "wi_id + ' - attempt ' + fix_count"
|
|
243
|
+
next: check_score
|
|
244
|
+
|
|
245
|
+
# Ternary
|
|
246
|
+
decide:
|
|
247
|
+
type: expression
|
|
248
|
+
set:
|
|
249
|
+
action: "fix_count > 3 ? 'escalate' : 'retry'"
|
|
250
|
+
next: route
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
State values are auto-coerced: numeric strings become numbers for arithmetic, results are stored as strings.
|
|
254
|
+
|
|
255
|
+
### `end` -- Termination
|
|
256
|
+
|
|
257
|
+
```yaml
|
|
258
|
+
end:
|
|
259
|
+
type: end
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Common Node Options
|
|
263
|
+
|
|
264
|
+
| Field | Type | Description |
|
|
265
|
+
|-------|------|-------------|
|
|
266
|
+
| `timeout` | number | Per-node timeout in seconds |
|
|
267
|
+
| `retry` | object | `{ max, delay: "exponential" \| "fixed" }` |
|
|
268
|
+
| `hooks` | string[] | Hook packages to apply |
|
|
269
|
+
| `on_failure` | string | `fail_fast` \| `continue` \| `ignore` |
|
|
270
|
+
| `on_error` | object | `{ handler?, fallback_node? }` |
|
|
271
|
+
| `comment` | string | Human-readable annotation |
|
|
272
|
+
|
|
273
|
+
## Template Syntax
|
|
274
|
+
|
|
275
|
+
Use `{{variable_name}}` in `input` fields to reference `state` values.
|
|
276
|
+
|
|
277
|
+
```yaml
|
|
278
|
+
state:
|
|
279
|
+
goal: "implement auth"
|
|
280
|
+
nodes:
|
|
281
|
+
plan:
|
|
282
|
+
type: agent_task
|
|
283
|
+
agent: architect
|
|
284
|
+
input: "Create a plan for: {{goal}}"
|
|
285
|
+
output: plan_result
|
|
286
|
+
next: implement
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## Programmatic API
|
|
290
|
+
|
|
291
|
+
### WorkflowEngine
|
|
292
|
+
|
|
293
|
+
YAML loading, validation, and Mermaid generation. Used by both CLI and server.
|
|
294
|
+
|
|
295
|
+
```typescript
|
|
296
|
+
import { WorkflowEngine } from '@crewx/workflow';
|
|
297
|
+
|
|
298
|
+
const engine = new WorkflowEngine();
|
|
299
|
+
|
|
300
|
+
// Load all workflows from a directory
|
|
301
|
+
const workflows: LoadedWorkflow[] = engine.loadWorkflows('workflows/');
|
|
302
|
+
|
|
303
|
+
// Validate a workflow file (schema -> fields -> references)
|
|
304
|
+
const result = engine.validateFile('workflows/standard-dev.yaml');
|
|
305
|
+
// { success: boolean; results: ValidationResult[]; error?: string }
|
|
306
|
+
|
|
307
|
+
// Generate Mermaid diagram
|
|
308
|
+
const mermaid: string = engine.toMermaid(spec);
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### RunManager
|
|
312
|
+
|
|
313
|
+
Execution state management. Stores state as JSON files in `.crewx/workflow-runs/`.
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
import { RunManager } from '@crewx/workflow';
|
|
317
|
+
|
|
318
|
+
const manager = new RunManager();
|
|
319
|
+
|
|
320
|
+
// Start execution
|
|
321
|
+
const exec: RunExecution = manager.start('workflows/dev.yaml', 'dev-core', { goal: 'build feature' });
|
|
322
|
+
|
|
323
|
+
// Execute a node (triggers agent call for agent_task nodes)
|
|
324
|
+
const updated: RunExecution = await manager.executeNode(exec.id, 'research');
|
|
325
|
+
|
|
326
|
+
// Move to node without executing
|
|
327
|
+
const moved: RunExecution = manager.moveNode(exec.id, 'implement');
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Key Types
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
type NodeType = 'agent_task' | 'parallel' | 'join' | 'branch' | 'approval' | 'expression' | 'end';
|
|
334
|
+
|
|
335
|
+
interface RunExecution {
|
|
336
|
+
id: string; // 'wfr_{nanoid(8)}'
|
|
337
|
+
workflow_id: string;
|
|
338
|
+
workflow_file: string;
|
|
339
|
+
created_at: string; // ISO 8601
|
|
340
|
+
updated_at: string;
|
|
341
|
+
current_node: string;
|
|
342
|
+
completed_nodes: string[];
|
|
343
|
+
state: Record<string, unknown>;
|
|
344
|
+
initial_state: Record<string, unknown>;
|
|
345
|
+
status?: 'running' | 'completed' | 'failed';
|
|
346
|
+
}
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## Architecture
|
|
350
|
+
|
|
351
|
+
```
|
|
352
|
+
[CLI] crewx workflow list/show/validate
|
|
353
|
+
|
|
|
354
|
+
v
|
|
355
|
+
WorkflowEngine <-- YAML parsing, validation, Mermaid
|
|
356
|
+
|
|
|
357
|
+
v
|
|
358
|
+
workflows/*.yaml (source files)
|
|
359
|
+
|
|
360
|
+
[CLI] crewx workflow run start/node/state
|
|
361
|
+
|
|
|
362
|
+
v
|
|
363
|
+
RunManager <-- execution state management
|
|
364
|
+
|
|
|
365
|
+
+---> .crewx/workflow-runs/wfr_*.json (state files)
|
|
366
|
+
+---> crewx q/x (agent invocation for agent_task nodes)
|
|
367
|
+
|
|
368
|
+
[Server] GET /api/v1/workflows[/:id]
|
|
369
|
+
|
|
|
370
|
+
v
|
|
371
|
+
WorkflowService --> fs (YAML read) + WorkflowEngine.toMermaid()
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
> **Note:** The server only uses `WorkflowEngine.toMermaid()`. YAML listing/parsing is handled by the server's own `WorkflowService`. `RunManager` (execution state) is CLI-only.
|
|
375
|
+
|
|
376
|
+
## Environment Variables
|
|
377
|
+
|
|
378
|
+
| Variable | Description | Default |
|
|
379
|
+
|----------|-------------|---------|
|
|
380
|
+
| `CREWX_WORKSPACE` | Workspace directory (where `workflows/` lives) | `.` |
|
|
381
|
+
| `CREWX_CLI` | CrewX CLI path (for agent execution in `run node`) | `npx crewx` |
|
|
382
|
+
| `CREWX_WORKFLOW_TIMEOUT` | Node execution timeout (ms) | `1800000` (30 min) |
|
|
383
|
+
| `CREWX_CONFIG` | Custom config file path | `crewx.yaml` |
|
|
384
|
+
|
|
385
|
+
## WARNING: Check Agent List Before Designing
|
|
386
|
+
|
|
387
|
+
**Specifying a non-existent agent in a workflow will prevent execution!** Always verify available agents first:
|
|
388
|
+
|
|
389
|
+
```bash
|
|
390
|
+
crewx agent ls
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
## File Layout
|
|
394
|
+
|
|
395
|
+
```
|
|
396
|
+
workflows/ # Workflow YAML sources
|
|
397
|
+
standard-dev.yaml
|
|
398
|
+
idea-validation.yaml
|
|
399
|
+
.crewx/workflow-runs/ # Execution state (auto-created)
|
|
400
|
+
wfr_abc12345.json
|
|
401
|
+
packages/built-in/workflow/ # Package source
|
|
402
|
+
cli.ts # CLI entrypoint
|
|
403
|
+
src/
|
|
404
|
+
types.ts # TypeScript interfaces
|
|
405
|
+
engine.ts # WorkflowEngine
|
|
406
|
+
mermaid.ts # Mermaid diagram renderer
|
|
407
|
+
run-manager.ts # RunManager
|
|
408
|
+
workflow-schema.json # JSON Schema for validation
|
|
409
|
+
```
|