@exaudeus/workrail 3.27.0 → 3.29.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.
- package/dist/console/assets/{index-FtTaDku8.js → index-BZ6HkxGf.js} +1 -1
- package/dist/console/index.html +1 -1
- package/dist/manifest.json +3 -3
- package/docs/README.md +57 -0
- package/docs/adrs/001-hybrid-storage-backend.md +38 -0
- package/docs/adrs/002-four-layer-context-classification.md +38 -0
- package/docs/adrs/003-checkpoint-trigger-strategy.md +35 -0
- package/docs/adrs/004-opt-in-encryption-strategy.md +36 -0
- package/docs/adrs/005-agent-first-workflow-execution-tokens.md +105 -0
- package/docs/adrs/006-append-only-session-run-event-log.md +76 -0
- package/docs/adrs/007-resume-and-checkpoint-only-sessions.md +51 -0
- package/docs/adrs/008-blocked-nodes-architectural-upgrade.md +178 -0
- package/docs/adrs/009-bridge-mode-single-instance-mcp.md +195 -0
- package/docs/adrs/010-release-pipeline.md +89 -0
- package/docs/architecture/README.md +7 -0
- package/docs/architecture/refactor-audit.md +364 -0
- package/docs/authoring-v2.md +527 -0
- package/docs/authoring.md +873 -0
- package/docs/changelog-recent.md +201 -0
- package/docs/configuration.md +505 -0
- package/docs/ctc-mcp-proposal.md +518 -0
- package/docs/design/README.md +22 -0
- package/docs/design/agent-cascade-protocol.md +96 -0
- package/docs/design/autonomous-console-design-candidates.md +253 -0
- package/docs/design/autonomous-console-design-review.md +111 -0
- package/docs/design/autonomous-platform-mvp-discovery.md +525 -0
- package/docs/design/claude-code-source-deep-dive.md +713 -0
- package/docs/design/console-cyberpunk-ui-discovery.md +504 -0
- package/docs/design/console-execution-trace-candidates-final.md +160 -0
- package/docs/design/console-execution-trace-candidates.md +211 -0
- package/docs/design/console-execution-trace-design-candidates-v2.md +113 -0
- package/docs/design/console-execution-trace-design-review.md +74 -0
- package/docs/design/console-execution-trace-discovery.md +394 -0
- package/docs/design/console-execution-trace-final-review.md +77 -0
- package/docs/design/console-execution-trace-review.md +92 -0
- package/docs/design/console-performance-discovery.md +415 -0
- package/docs/design/console-ui-backlog.md +280 -0
- package/docs/design/daemon-architecture-discovery.md +853 -0
- package/docs/design/daemon-design-candidates.md +318 -0
- package/docs/design/daemon-design-review-findings.md +119 -0
- package/docs/design/daemon-engine-design-candidates.md +210 -0
- package/docs/design/daemon-engine-design-review.md +131 -0
- package/docs/design/daemon-execution-engine-discovery.md +280 -0
- package/docs/design/daemon-gap-analysis.md +554 -0
- package/docs/design/daemon-owns-console-plan.md +168 -0
- package/docs/design/daemon-owns-console-review.md +91 -0
- package/docs/design/daemon-owns-console.md +195 -0
- package/docs/design/data-model-erd.md +11 -0
- package/docs/design/design-candidates-consolidate-dev-staleness.md +98 -0
- package/docs/design/design-candidates-walk-cache-depth-limit.md +80 -0
- package/docs/design/design-review-consolidate-dev-staleness.md +54 -0
- package/docs/design/design-review-walk-cache-depth-limit.md +48 -0
- package/docs/design/implementation-plan-consolidate-dev-staleness.md +142 -0
- package/docs/design/implementation-plan-walk-cache-depth-limit.md +141 -0
- package/docs/design/layer3b-ghost-nodes-design-candidates.md +229 -0
- package/docs/design/layer3b-ghost-nodes-design-review.md +93 -0
- package/docs/design/layer3b-ghost-nodes-implementation-plan.md +219 -0
- package/docs/design/list-workflows-latency-fix-plan.md +128 -0
- package/docs/design/list-workflows-latency-fix-review.md +55 -0
- package/docs/design/list-workflows-latency-fix.md +109 -0
- package/docs/design/native-context-management-api.md +11 -0
- package/docs/design/performance-sweep-2026-04.md +96 -0
- package/docs/design/routines-guide.md +219 -0
- package/docs/design/sequence-diagrams.md +11 -0
- package/docs/design/subagent-design-principles.md +220 -0
- package/docs/design/temporal-patterns-design-candidates.md +312 -0
- package/docs/design/temporal-patterns-design-review-findings.md +163 -0
- package/docs/design/test-isolation-from-config-file.md +335 -0
- package/docs/design/v2-core-design-locks.md +2746 -0
- package/docs/design/v2-lock-registry.json +734 -0
- package/docs/design/workflow-authoring-v2.md +1044 -0
- package/docs/design/workflow-docs-spec.md +218 -0
- package/docs/design/workflow-extension-points.md +687 -0
- package/docs/design/workrail-auto-trigger-system.md +359 -0
- package/docs/design/workrail-config-file-discovery.md +513 -0
- package/docs/docker.md +110 -0
- package/docs/generated/v2-lock-closure-plan.md +26 -0
- package/docs/generated/v2-lock-coverage.json +797 -0
- package/docs/generated/v2-lock-coverage.md +177 -0
- package/docs/ideas/backlog.md +3927 -0
- package/docs/ideas/design-candidates-mcp-resilience.md +208 -0
- package/docs/ideas/design-review-findings-mcp-resilience.md +119 -0
- package/docs/ideas/implementation_plan.md +249 -0
- package/docs/ideas/third-party-workflow-setup-design-thinking.md +1948 -0
- package/docs/implementation/02-architecture.md +316 -0
- package/docs/implementation/04-testing-strategy.md +124 -0
- package/docs/implementation/09-simple-workflow-guide.md +835 -0
- package/docs/implementation/13-advanced-validation-guide.md +874 -0
- package/docs/implementation/README.md +21 -0
- package/docs/integrations/claude-code.md +300 -0
- package/docs/integrations/firebender.md +315 -0
- package/docs/migration/v0.1.0.md +147 -0
- package/docs/naming-conventions.md +45 -0
- package/docs/planning/README.md +104 -0
- package/docs/planning/github-ticketing-playbook.md +195 -0
- package/docs/plans/README.md +24 -0
- package/docs/plans/agent-managed-ticketing-design.md +605 -0
- package/docs/plans/agentic-orchestration-roadmap.md +112 -0
- package/docs/plans/assessment-gates-engine-handoff.md +536 -0
- package/docs/plans/content-coherence-and-references.md +151 -0
- package/docs/plans/library-extraction-plan.md +340 -0
- package/docs/plans/mr-review-workflow-redesign.md +1451 -0
- package/docs/plans/native-context-management-epic.md +11 -0
- package/docs/plans/perf-fixes-design-candidates.md +225 -0
- package/docs/plans/perf-fixes-design-review-findings.md +61 -0
- package/docs/plans/perf-fixes-new-issues-candidates.md +264 -0
- package/docs/plans/perf-fixes-new-issues-review.md +110 -0
- package/docs/plans/prompt-fragments.md +53 -0
- package/docs/plans/ui-ux-workflow-design-candidates.md +120 -0
- package/docs/plans/ui-ux-workflow-discovery.md +100 -0
- package/docs/plans/ui-ux-workflow-review.md +48 -0
- package/docs/plans/v2-followup-enhancements.md +587 -0
- package/docs/plans/workflow-categories-candidates.md +105 -0
- package/docs/plans/workflow-categories-discovery.md +110 -0
- package/docs/plans/workflow-categories-review.md +51 -0
- package/docs/plans/workflow-discovery-model-candidates.md +94 -0
- package/docs/plans/workflow-discovery-model-discovery.md +74 -0
- package/docs/plans/workflow-discovery-model-review.md +48 -0
- package/docs/plans/workflow-source-setup-phase-1.md +245 -0
- package/docs/plans/workflow-source-setup-phase-2.md +361 -0
- package/docs/plans/workflow-staleness-detection-candidates.md +104 -0
- package/docs/plans/workflow-staleness-detection-review.md +58 -0
- package/docs/plans/workflow-staleness-detection.md +80 -0
- package/docs/plans/workflow-v2-design.md +69 -0
- package/docs/plans/workflow-v2-roadmap.md +74 -0
- package/docs/plans/workflow-validation-design.md +98 -0
- package/docs/plans/workflow-validation-roadmap.md +108 -0
- package/docs/plans/workrail-platform-vision.md +420 -0
- package/docs/reference/agent-context-cleaner-snippet.md +94 -0
- package/docs/reference/agent-context-guidance.md +140 -0
- package/docs/reference/context-optimization.md +284 -0
- package/docs/reference/example-workflow-repository-template/.github/workflows/validate.yml +125 -0
- package/docs/reference/example-workflow-repository-template/README.md +268 -0
- package/docs/reference/example-workflow-repository-template/workflows/example-workflow.json +80 -0
- package/docs/reference/external-workflow-repositories.md +916 -0
- package/docs/reference/feature-flags-architecture.md +472 -0
- package/docs/reference/feature-flags.md +349 -0
- package/docs/reference/god-tier-workflow-validation.md +272 -0
- package/docs/reference/loop-optimization.md +209 -0
- package/docs/reference/loop-validation.md +176 -0
- package/docs/reference/loops.md +465 -0
- package/docs/reference/mcp-platform-constraints.md +59 -0
- package/docs/reference/recovery.md +88 -0
- package/docs/reference/releases.md +177 -0
- package/docs/reference/troubleshooting.md +105 -0
- package/docs/reference/workflow-execution-contract.md +998 -0
- package/docs/roadmap/README.md +22 -0
- package/docs/roadmap/legacy-planning-status.md +103 -0
- package/docs/roadmap/now-next-later.md +70 -0
- package/docs/roadmap/open-work-inventory.md +389 -0
- package/docs/tickets/README.md +39 -0
- package/docs/tickets/next-up.md +76 -0
- package/docs/workflow-management.md +317 -0
- package/docs/workflow-templates.md +423 -0
- package/docs/workflow-validation.md +184 -0
- package/docs/workflows.md +254 -0
- package/package.json +3 -1
- package/spec/authoring-spec.json +61 -16
- package/workflows/workflow-for-workflows.json +252 -93
- package/workflows/workflow-for-workflows.v2.json +188 -77
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
# Loop Support in Workrail
|
|
2
|
+
|
|
3
|
+
This guide covers the loop functionality introduced in Workrail v0.1.0, enabling powerful iteration patterns within workflows while maintaining the system's stateless architecture.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
- [Overview](#overview)
|
|
7
|
+
- [Loop Types](#loop-types)
|
|
8
|
+
- [While Loops](#while-loops)
|
|
9
|
+
- [Until Loops](#until-loops)
|
|
10
|
+
- [For Loops](#for-loops)
|
|
11
|
+
- [ForEach Loops](#foreach-loops)
|
|
12
|
+
- [Configuration](#configuration)
|
|
13
|
+
- [Context and State Management](#context-and-state-management)
|
|
14
|
+
- [Best Practices](#best-practices)
|
|
15
|
+
- [Migration Guide](#migration-guide)
|
|
16
|
+
- [Technical Details](#technical-details)
|
|
17
|
+
|
|
18
|
+
## Overview
|
|
19
|
+
|
|
20
|
+
Loops in Workrail allow workflows to iterate over steps, enabling common patterns like:
|
|
21
|
+
- Polling APIs until completion
|
|
22
|
+
- Retrying operations with backoff
|
|
23
|
+
- Processing collections of data
|
|
24
|
+
- Searching across multiple sources
|
|
25
|
+
|
|
26
|
+
### Key Features
|
|
27
|
+
- **Four loop types**: `while`, `until`, `for`, and `forEach`
|
|
28
|
+
- **Safety limits**: Configurable `maxIterations` to prevent infinite loops
|
|
29
|
+
- **Context-based state**: Loop state managed through context (v1: ephemeral, v2: persisted via context_set events)
|
|
30
|
+
- **Flexible body**: Reference existing steps or define inline steps
|
|
31
|
+
- **Custom variables**: Control iteration and item variable names
|
|
32
|
+
|
|
33
|
+
## Loop Types
|
|
34
|
+
|
|
35
|
+
### While Loops
|
|
36
|
+
Continue execution while a condition remains true.
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"id": "poll-status",
|
|
41
|
+
"type": "loop",
|
|
42
|
+
"title": "Poll Until Complete",
|
|
43
|
+
"loop": {
|
|
44
|
+
"type": "while",
|
|
45
|
+
"condition": {
|
|
46
|
+
"and": [
|
|
47
|
+
{ "var": "status", "not_equals": "completed" },
|
|
48
|
+
{ "var": "attempts", "lt": 10 }
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"maxIterations": 10,
|
|
52
|
+
"iterationVar": "currentAttempt"
|
|
53
|
+
},
|
|
54
|
+
"body": "check-status"
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Use cases**:
|
|
59
|
+
- API polling
|
|
60
|
+
- Waiting for conditions
|
|
61
|
+
- Continuous monitoring
|
|
62
|
+
|
|
63
|
+
### Until Loops
|
|
64
|
+
Continue execution until a condition becomes true.
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"id": "search-data",
|
|
69
|
+
"type": "loop",
|
|
70
|
+
"title": "Search Until Found",
|
|
71
|
+
"loop": {
|
|
72
|
+
"type": "until",
|
|
73
|
+
"condition": {
|
|
74
|
+
"or": [
|
|
75
|
+
{ "var": "found", "equals": true },
|
|
76
|
+
{ "var": "sourcesExhausted", "equals": true }
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
"maxIterations": 20
|
|
80
|
+
},
|
|
81
|
+
"body": "search-next-source"
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Use cases**:
|
|
86
|
+
- Searching across sources
|
|
87
|
+
- Waiting for events
|
|
88
|
+
- Progressive discovery
|
|
89
|
+
|
|
90
|
+
### For Loops
|
|
91
|
+
Execute a fixed number of iterations.
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"id": "retry-operation",
|
|
96
|
+
"type": "loop",
|
|
97
|
+
"title": "Retry With Backoff",
|
|
98
|
+
"loop": {
|
|
99
|
+
"type": "for",
|
|
100
|
+
"count": 3,
|
|
101
|
+
"maxIterations": 5,
|
|
102
|
+
"iterationVar": "attemptNumber"
|
|
103
|
+
},
|
|
104
|
+
"body": "attempt-operation"
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Dynamic count using context variable**:
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"loop": {
|
|
112
|
+
"type": "for",
|
|
113
|
+
"count": "maxRetries", // References context variable
|
|
114
|
+
"maxIterations": 10
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Use cases**:
|
|
120
|
+
- Fixed retry attempts
|
|
121
|
+
- Batch operations
|
|
122
|
+
- Timed sequences
|
|
123
|
+
|
|
124
|
+
### ForEach Loops
|
|
125
|
+
Iterate over items in an array.
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"id": "process-items",
|
|
130
|
+
"type": "loop",
|
|
131
|
+
"title": "Process Each Item",
|
|
132
|
+
"loop": {
|
|
133
|
+
"type": "forEach",
|
|
134
|
+
"items": "dataItems",
|
|
135
|
+
"itemVar": "currentItem",
|
|
136
|
+
"indexVar": "itemIndex",
|
|
137
|
+
"maxIterations": 100
|
|
138
|
+
},
|
|
139
|
+
"body": "process-single-item"
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Use cases**:
|
|
144
|
+
- Batch processing
|
|
145
|
+
- Data transformation
|
|
146
|
+
- Collection operations
|
|
147
|
+
|
|
148
|
+
## Configuration
|
|
149
|
+
|
|
150
|
+
### Loop Properties
|
|
151
|
+
|
|
152
|
+
| Property | Type | Required | Description |
|
|
153
|
+
|----------|------|----------|-------------|
|
|
154
|
+
| `type` | string | Yes | One of: `while`, `until`, `for`, `forEach` |
|
|
155
|
+
| `condition` | object | Conditional | Required for `while` and `until` loops |
|
|
156
|
+
| `count` | number/string | Conditional | Required for `for` loops |
|
|
157
|
+
| `items` | string | Conditional | Required for `forEach` loops |
|
|
158
|
+
| `maxIterations` | number | Yes | Safety limit (1-1000) |
|
|
159
|
+
| `iterationVar` | string | No | Custom name for iteration counter |
|
|
160
|
+
| `itemVar` | string | No | Custom name for current item (forEach only) |
|
|
161
|
+
| `indexVar` | string | No | Custom name for current index (forEach only) |
|
|
162
|
+
|
|
163
|
+
### Body Definition
|
|
164
|
+
|
|
165
|
+
The loop body can be defined in two ways:
|
|
166
|
+
|
|
167
|
+
**1. Reference to existing step:**
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"body": "process-step-id"
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**2. Inline step definitions:**
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"body": [
|
|
178
|
+
{
|
|
179
|
+
"id": "step-1",
|
|
180
|
+
"title": "First Step",
|
|
181
|
+
"prompt": "Do something"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"id": "step-2",
|
|
185
|
+
"title": "Second Step",
|
|
186
|
+
"prompt": "Do something else"
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Condition Operators
|
|
193
|
+
|
|
194
|
+
Conditions support the following operators:
|
|
195
|
+
|
|
196
|
+
| Operator | Description | Example |
|
|
197
|
+
|----------|-------------|---------|
|
|
198
|
+
| `equals` | Equal to | `{ "var": "status", "equals": "done" }` |
|
|
199
|
+
| `not_equals` | Not equal to | `{ "var": "status", "not_equals": "error" }` |
|
|
200
|
+
| `gt` | Greater than | `{ "var": "count", "gt": 5 }` |
|
|
201
|
+
| `gte` | Greater than or equal | `{ "var": "count", "gte": 10 }` |
|
|
202
|
+
| `lt` | Less than | `{ "var": "count", "lt": 100 }` |
|
|
203
|
+
| `lte` | Less than or equal | `{ "var": "count", "lte": 50 }` |
|
|
204
|
+
| `and` | Logical AND | `{ "and": [...conditions] }` |
|
|
205
|
+
| `or` | Logical OR | `{ "or": [...conditions] }` |
|
|
206
|
+
| `not` | Logical NOT | `{ "not": condition }` |
|
|
207
|
+
|
|
208
|
+
## Context and State Management
|
|
209
|
+
|
|
210
|
+
### Loop Variables
|
|
211
|
+
|
|
212
|
+
During execution, loops inject special variables into the context:
|
|
213
|
+
|
|
214
|
+
**All loop types:**
|
|
215
|
+
- `{{iterationVar}}`: Current iteration number (1-based)
|
|
216
|
+
- Default: `_iteration`
|
|
217
|
+
|
|
218
|
+
**ForEach loops only:**
|
|
219
|
+
- `{{itemVar}}`: Current item from the array
|
|
220
|
+
- `{{indexVar}}`: Current index (0-based)
|
|
221
|
+
- Defaults: `_item` and `_index`
|
|
222
|
+
|
|
223
|
+
### Example Context Flow
|
|
224
|
+
|
|
225
|
+
```javascript
|
|
226
|
+
// Initial context
|
|
227
|
+
{
|
|
228
|
+
"items": ["apple", "banana", "cherry"],
|
|
229
|
+
"processed": 0
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// During forEach iteration 2
|
|
233
|
+
{
|
|
234
|
+
"items": ["apple", "banana", "cherry"],
|
|
235
|
+
"processed": 1,
|
|
236
|
+
"_item": "banana", // Current item
|
|
237
|
+
"_index": 1, // Current index
|
|
238
|
+
"_iteration": 2 // Iteration count
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Loop State Management
|
|
243
|
+
|
|
244
|
+
The system maintains loop state internally through:
|
|
245
|
+
- `_loopState`: Tracks iteration counts and conditions
|
|
246
|
+
- `_currentLoop`: Identifies the active loop during nested execution
|
|
247
|
+
- `_contextSize`: Monitors context growth for safety
|
|
248
|
+
|
|
249
|
+
These are implementation details and not directly accessible in workflows.
|
|
250
|
+
|
|
251
|
+
## Best Practices
|
|
252
|
+
|
|
253
|
+
### 1. Always Set maxIterations
|
|
254
|
+
```json
|
|
255
|
+
{
|
|
256
|
+
"loop": {
|
|
257
|
+
"type": "while",
|
|
258
|
+
"condition": { "var": "searching", "equals": true },
|
|
259
|
+
"maxIterations": 50 // Prevent infinite loops
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### 2. Update Loop Variables
|
|
265
|
+
Ensure your loop body updates variables used in conditions:
|
|
266
|
+
|
|
267
|
+
```json
|
|
268
|
+
{
|
|
269
|
+
"id": "increment-counter",
|
|
270
|
+
"prompt": "Increment the counter",
|
|
271
|
+
"guidance": ["Set counter = counter + 1"]
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### 3. Use Meaningful Variable Names
|
|
276
|
+
```json
|
|
277
|
+
{
|
|
278
|
+
"loop": {
|
|
279
|
+
"type": "forEach",
|
|
280
|
+
"items": "customers",
|
|
281
|
+
"itemVar": "customer", // Clear naming
|
|
282
|
+
"indexVar": "customerIndex" // Descriptive
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### 4. Consider Performance
|
|
288
|
+
- Keep loop bodies focused
|
|
289
|
+
- Avoid deeply nested loops
|
|
290
|
+
- Monitor context size for large datasets
|
|
291
|
+
- Use appropriate maxIterations values
|
|
292
|
+
|
|
293
|
+
### 5. Handle Edge Cases
|
|
294
|
+
```json
|
|
295
|
+
{
|
|
296
|
+
"runCondition": {
|
|
297
|
+
"and": [
|
|
298
|
+
{ "var": "items", "not_equals": null },
|
|
299
|
+
{ "var": "items.length", "gt": 0 }
|
|
300
|
+
]
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## Migration Guide
|
|
306
|
+
|
|
307
|
+
### From v0.0.1 to v0.1.0
|
|
308
|
+
|
|
309
|
+
Workrail provides an automated migration tool:
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
# Migrate a single workflow
|
|
313
|
+
workrail migrate workflow.json
|
|
314
|
+
|
|
315
|
+
# Dry run to see changes
|
|
316
|
+
workrail migrate workflow.json --dry-run
|
|
317
|
+
|
|
318
|
+
# Create backup
|
|
319
|
+
workrail migrate workflow.json --backup
|
|
320
|
+
|
|
321
|
+
# Specify output file
|
|
322
|
+
workrail migrate workflow.json --output new-workflow.json
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Manual Migration Steps
|
|
326
|
+
|
|
327
|
+
1. **Add version field:**
|
|
328
|
+
```json
|
|
329
|
+
{
|
|
330
|
+
"version": "0.1.0"
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
2. **Convert loop-like patterns:**
|
|
335
|
+
|
|
336
|
+
**Before (v0.0.1):**
|
|
337
|
+
```json
|
|
338
|
+
{
|
|
339
|
+
"id": "step-2",
|
|
340
|
+
"title": "Process Item 2 of 5",
|
|
341
|
+
"prompt": "Process the second item",
|
|
342
|
+
"guidance": ["This is step 2 of 5 in the iteration"]
|
|
343
|
+
}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
**After (v0.1.0):**
|
|
347
|
+
```json
|
|
348
|
+
{
|
|
349
|
+
"id": "process-items",
|
|
350
|
+
"type": "loop",
|
|
351
|
+
"title": "Process All Items",
|
|
352
|
+
"loop": {
|
|
353
|
+
"type": "for",
|
|
354
|
+
"count": 5,
|
|
355
|
+
"maxIterations": 5
|
|
356
|
+
},
|
|
357
|
+
"body": "process-single-item"
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Common Migration Patterns
|
|
362
|
+
|
|
363
|
+
| Pattern | v0.0.1 Approach | v0.1.0 Loop Type |
|
|
364
|
+
|---------|----------------|------------------|
|
|
365
|
+
| Polling | Multiple similar steps | `while` loop |
|
|
366
|
+
| Retry | Duplicate steps with variations | `for` loop |
|
|
367
|
+
| Batch | Hardcoded item processing | `forEach` loop |
|
|
368
|
+
| Search | Sequential check steps | `until` loop |
|
|
369
|
+
|
|
370
|
+
## Technical Details
|
|
371
|
+
|
|
372
|
+
### Performance Considerations
|
|
373
|
+
|
|
374
|
+
- **Context cloning**: Optimized for shallow copies
|
|
375
|
+
- **Iteration overhead**: ~0.1ms per iteration
|
|
376
|
+
- **Memory usage**: Linear with context size
|
|
377
|
+
- **Nested loops**: Supported but use judiciously
|
|
378
|
+
|
|
379
|
+
### Safety Features
|
|
380
|
+
|
|
381
|
+
1. **Iteration limits**: Hard cap at 1000 iterations
|
|
382
|
+
2. **Context size monitoring**: Prevents memory exhaustion
|
|
383
|
+
3. **Timeout protection**: Configurable execution timeouts
|
|
384
|
+
4. **State isolation**: Each iteration has clean context
|
|
385
|
+
|
|
386
|
+
### Error Handling
|
|
387
|
+
|
|
388
|
+
Loops handle errors gracefully:
|
|
389
|
+
- Step failures don't break the loop by default
|
|
390
|
+
- Conditions are re-evaluated after errors
|
|
391
|
+
- Error state can be checked in conditions
|
|
392
|
+
|
|
393
|
+
```json
|
|
394
|
+
{
|
|
395
|
+
"condition": {
|
|
396
|
+
"and": [
|
|
397
|
+
{ "var": "lastError", "equals": null },
|
|
398
|
+
{ "var": "attempts", "lt": 5 }
|
|
399
|
+
]
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Schema Validation
|
|
405
|
+
|
|
406
|
+
Loops are validated against the v0.1.0 schema:
|
|
407
|
+
- Type safety for all properties
|
|
408
|
+
- Condition structure validation
|
|
409
|
+
- Reference integrity for body steps
|
|
410
|
+
- Range checks for numeric values
|
|
411
|
+
|
|
412
|
+
## Examples
|
|
413
|
+
|
|
414
|
+
See the `workflows/examples/loops/` directory for complete examples:
|
|
415
|
+
- `simple-polling.json`: API polling pattern
|
|
416
|
+
- `simple-retry.json`: Retry with backoff
|
|
417
|
+
- `simple-batch.json`: Batch processing
|
|
418
|
+
- `simple-search.json`: Multi-source search
|
|
419
|
+
|
|
420
|
+
## Troubleshooting
|
|
421
|
+
|
|
422
|
+
### Common Issues
|
|
423
|
+
|
|
424
|
+
1. **"Maximum iterations exceeded"**
|
|
425
|
+
- Increase `maxIterations` if legitimate
|
|
426
|
+
- Check loop exit conditions
|
|
427
|
+
- Ensure variables are updated
|
|
428
|
+
|
|
429
|
+
2. **"Invalid condition"**
|
|
430
|
+
- Use correct operator names (`lte` not `less_than_or_equal_to`)
|
|
431
|
+
- Check variable names match context
|
|
432
|
+
- Validate condition structure
|
|
433
|
+
|
|
434
|
+
3. **"Step not found"**
|
|
435
|
+
- Ensure referenced step IDs exist
|
|
436
|
+
- Check for typos in body references
|
|
437
|
+
- Verify step ordering
|
|
438
|
+
|
|
439
|
+
### Debug Tips
|
|
440
|
+
|
|
441
|
+
- Add logging steps to track variables
|
|
442
|
+
- Use small datasets for initial testing
|
|
443
|
+
- Validate workflows before execution
|
|
444
|
+
- Monitor context size with large datasets
|
|
445
|
+
|
|
446
|
+
## Enhanced Loop Validation
|
|
447
|
+
|
|
448
|
+
WorkRail includes enhanced validation features specifically for loops that help catch common issues and promote best practices:
|
|
449
|
+
|
|
450
|
+
- **Conditional Logic Complexity**: Warns about complex ternary operators and suggests using runCondition
|
|
451
|
+
- **Prompt Length Validation**: Checks for excessively long prompts that could cause issues
|
|
452
|
+
- **Template Variable Usage**: Validates that all referenced variables are properly defined
|
|
453
|
+
- **Pattern Detection**: Recognizes common loop patterns and provides guidance
|
|
454
|
+
|
|
455
|
+
For detailed information about loop validation and best practices, see the [Loop Validation Best Practices](./loop-validation-best-practices.md) guide.
|
|
456
|
+
|
|
457
|
+
## Future Enhancements
|
|
458
|
+
|
|
459
|
+
Potential future improvements:
|
|
460
|
+
- Parallel forEach execution
|
|
461
|
+
- Break/continue statements
|
|
462
|
+
- Loop result aggregation
|
|
463
|
+
- Performance profiling tools
|
|
464
|
+
|
|
465
|
+
For the latest updates, see the [changelog](../reference/changelog.md).
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# MCP Platform Constraints (Design Inputs)
|
|
2
|
+
|
|
3
|
+
This document records platform constraints that shape WorkRail's architecture and tool contracts. These are "facts of life" for our environment, not preferences.
|
|
4
|
+
|
|
5
|
+
## Interaction model constraints
|
|
6
|
+
|
|
7
|
+
- **No server push into the chat**
|
|
8
|
+
- The MCP server cannot "push" actions into the conversation.
|
|
9
|
+
- Any action must be initiated by the agent via tool calls.
|
|
10
|
+
|
|
11
|
+
- **No reliable access to chat transcript**
|
|
12
|
+
- WorkRail cannot read or depend on the user's conversation history.
|
|
13
|
+
- Rewinds/editing can delete context without warning; durable memory must live in WorkRail storage.
|
|
14
|
+
|
|
15
|
+
## Tool-call and agent behavior constraints
|
|
16
|
+
|
|
17
|
+
- **Agents are lossy and inconsistent**
|
|
18
|
+
- Agents can omit fields, hallucinate payloads, or call tools out of order.
|
|
19
|
+
- Contracts must be self-correcting: text-first outputs, structured blockers/warnings, and "next input" templates.
|
|
20
|
+
|
|
21
|
+
- **Tool discovery is bounded**
|
|
22
|
+
- Tool schemas/descriptions are learned at MCP initialization (and after restarts).
|
|
23
|
+
- Do not assume dynamic renegotiation mid-session.
|
|
24
|
+
|
|
25
|
+
## Determinism and recovery constraints
|
|
26
|
+
|
|
27
|
+
- **Requests and responses must be self-contained**
|
|
28
|
+
- Tool handlers cannot ask follow-up questions directly; they can only return data.
|
|
29
|
+
- "Blocked" states must include enough structured information to recover on the next call.
|
|
30
|
+
|
|
31
|
+
- **Replays can happen**
|
|
32
|
+
- Even locally, tool calls can be repeated (restart/regenerate/retry).
|
|
33
|
+
- Protocols should be idempotent where possible (e.g., token/ack for workflow advancement).
|
|
34
|
+
|
|
35
|
+
## Environment and storage constraints
|
|
36
|
+
|
|
37
|
+
- **Local-only by default (stdio)**
|
|
38
|
+
- Storage is local filesystem.
|
|
39
|
+
- Sharing requires explicit export/import (no implicit "share links" unless we introduce remote publishing later).
|
|
40
|
+
|
|
41
|
+
- **Integrity over confidentiality**
|
|
42
|
+
- Confidentiality is not a primary requirement in local-only mode.
|
|
43
|
+
- Integrity and fail-fast validation still matter to catch accidental corruption or contract drift.
|
|
44
|
+
|
|
45
|
+
## Payload and capability constraints
|
|
46
|
+
|
|
47
|
+
- **Token/payload budgets matter**
|
|
48
|
+
- Keep inputs/outputs reasonably small.
|
|
49
|
+
- Store large artifacts as session artifacts/references instead of repeating them in every call.
|
|
50
|
+
|
|
51
|
+
- **Capability variability**
|
|
52
|
+
- The agent's surrounding tools differ by IDE/client.
|
|
53
|
+
- WorkRail must degrade gracefully and gate optional features behind capability checks / feature flags.
|
|
54
|
+
|
|
55
|
+
## Multi-entrypoint constraint
|
|
56
|
+
|
|
57
|
+
- **Cross-transport drift risk**
|
|
58
|
+
- MCP/CLI/JSON-RPC must share canonical models and normalization/validation logic.
|
|
59
|
+
- "One protocol, multiple doors" is a requirement to prevent inconsistent behavior.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Recovery Reference
|
|
2
|
+
|
|
3
|
+
> **Data recovery and disaster preparedness**
|
|
4
|
+
|
|
5
|
+
[](https://github.com/EtienneBBeaulac/mcp)
|
|
6
|
+
[](specs/)
|
|
7
|
+
|
|
8
|
+
## Table of Contents
|
|
9
|
+
|
|
10
|
+
1. [Backup Procedures](#backup-procedures)
|
|
11
|
+
2. [Restore Procedures](#restore-procedures)
|
|
12
|
+
3. [Disaster Recovery](#disaster-recovery)
|
|
13
|
+
4. [Testing Recovery](#testing-recovery)
|
|
14
|
+
5. [Best Practices](#best-practices)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Backup Procedures
|
|
19
|
+
|
|
20
|
+
- Schedule regular backups of:
|
|
21
|
+
- Database (Postgres, etc.)
|
|
22
|
+
- Workflow definitions (JSON files)
|
|
23
|
+
- Configuration files
|
|
24
|
+
- Store backups in secure, offsite locations
|
|
25
|
+
- Automate backups using scripts or managed services
|
|
26
|
+
|
|
27
|
+
### Example: Database Backup Script
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
pg_dump $DATABASE_URL > ./backups/db-$(date +%F).sql
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Example: Workflow Backup Script
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
tar czf ./backups/workflows-$(date +%F).tar.gz ./workflows
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Restore Procedures
|
|
42
|
+
|
|
43
|
+
- Verify backup integrity before restoring
|
|
44
|
+
- Restore database using `psql` or cloud provider tools
|
|
45
|
+
- Restore workflow files to the correct directory
|
|
46
|
+
- Restart MCP server after restore
|
|
47
|
+
|
|
48
|
+
### Example: Database Restore
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
psql $DATABASE_URL < ./backups/db-YYYY-MM-DD.sql
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Example: Workflow Restore
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
tar xzf ./backups/workflows-YYYY-MM-DD.tar.gz -C ./workflows
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Disaster Recovery
|
|
63
|
+
|
|
64
|
+
- Maintain a runbook for major incidents
|
|
65
|
+
- Document RTO (Recovery Time Objective) and RPO (Recovery Point Objective)
|
|
66
|
+
- Test failover to standby systems or cloud regions
|
|
67
|
+
- Communicate recovery status to stakeholders
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Testing Recovery
|
|
72
|
+
|
|
73
|
+
- Regularly test backup and restore procedures
|
|
74
|
+
- Simulate disaster scenarios in staging
|
|
75
|
+
- Document lessons learned and update procedures
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Best Practices
|
|
80
|
+
|
|
81
|
+
- Automate and monitor all backup jobs
|
|
82
|
+
- Encrypt backups at rest and in transit
|
|
83
|
+
- Store backups in multiple locations
|
|
84
|
+
- Document all recovery steps and keep this guide up to date
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
**Need help with recovery?** Check the [Troubleshooting Guide](troubleshooting.md) or create an issue on GitHub.
|