@build0.ai/workflow-validator
v1.0.1
Published
Validate workflow.json files for Build0 agents
Downloads
184
Maintainers
Readme
workflow-validator
Validate workflow.json files for Build0 agents without executing them.
Installation
npm install -g workflow-validatorOr use directly with npx:
npx workflow-validator workflow.jsonUsage
CLI
# Validate a workflow file
validate-workflow workflow.json
# Or with npx
npx workflow-validator workflow.jsonExit codes:
0- Workflow is valid1- Workflow is invalid or file not found
Programmatic Usage
import { validateWorkflowFile, WorkflowSchema } from 'workflow-validator';
// Validate a file
const result = validateWorkflowFile('./workflow.json');
if (result.valid) {
console.log('Valid workflow:', result.workflow);
} else {
console.error('Errors:', result.errors);
}
// Or use the Zod schema directly
import { WorkflowSchema } from 'workflow-validator/schemas';
const workflow = WorkflowSchema.parse(jsonData);Validation Rules
Schema Validation (Zod)
- Required top-level fields:
name,version,steps - Steps array must be non-empty
- Each step must have
id,type,name - Step type must be
"command"or"sleep" - Command steps require
commandfield - Sleep steps require positive
durationfield
Semantic Validation
- All step IDs must be unique
onErrorGotomust reference an existing step ID- If
onErrorGotois present,onErrormust be"goto" - Step references in templates (
steps['id'].output) must reference earlier steps - Template braces
{{ }}must be balanced
Optional References
References using optional chaining (steps['id']?.output) are treated as optional and are allowed to:
- Reference steps defined later in the workflow (forward references)
- Reference steps that may not exist
This supports loop patterns where the first iteration uses one step's output and subsequent iterations use another's.
Workflow Structure
{
"name": "My Workflow",
"version": "1.0",
"steps": [
{
"id": "step-1",
"type": "command",
"name": "Run command",
"command": "echo hello",
"env": {
"VAR": "{{ input.value }}"
},
"retries": 2,
"retryDelay": 1000,
"onError": "goto",
"onErrorGoto": "error-handler",
"if": "{{ condition }}"
},
{
"id": "step-2",
"type": "sleep",
"name": "Wait",
"duration": 5000
}
]
}License
MIT
