@exaudeus/workrail 3.28.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-C146q2kN.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 +3 -3
- package/workflows/workflow-for-workflows.v2.json +3 -3
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Context Cleaner for Agents
|
|
2
|
+
|
|
3
|
+
## Quick Copy-Paste Function
|
|
4
|
+
|
|
5
|
+
Add this to your agent implementation to automatically clean context before sending to `workflow_next`:
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
function cleanContextForWorkflowNext(
|
|
9
|
+
fullContext: any,
|
|
10
|
+
modifiedFields: string[] = []
|
|
11
|
+
): any {
|
|
12
|
+
// Start with only essential fields
|
|
13
|
+
const cleanContext: any = {};
|
|
14
|
+
|
|
15
|
+
// Always include current loop variables if present
|
|
16
|
+
if (fullContext.currentStep) {
|
|
17
|
+
cleanContext.currentStep = fullContext.currentStep;
|
|
18
|
+
}
|
|
19
|
+
if (typeof fullContext.stepIndex === 'number') {
|
|
20
|
+
cleanContext.stepIndex = fullContext.stepIndex;
|
|
21
|
+
}
|
|
22
|
+
if (typeof fullContext.stepIteration === 'number') {
|
|
23
|
+
cleanContext.stepIteration = fullContext.stepIteration;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Add any fields the agent explicitly modified
|
|
27
|
+
modifiedFields.forEach(field => {
|
|
28
|
+
if (field in fullContext) {
|
|
29
|
+
cleanContext[field] = fullContext[field];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// NEVER include these
|
|
34
|
+
const blocklist = [
|
|
35
|
+
'implementationSteps',
|
|
36
|
+
'_loopState',
|
|
37
|
+
'_currentLoop',
|
|
38
|
+
'_contextSize',
|
|
39
|
+
'_warnings',
|
|
40
|
+
'userRules',
|
|
41
|
+
'taskDescription'
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
// Remove any blocklisted fields that snuck in
|
|
45
|
+
blocklist.forEach(field => {
|
|
46
|
+
delete cleanContext[field];
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return cleanContext;
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Usage Example
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
// During your workflow execution:
|
|
57
|
+
const response = await workflow_next({
|
|
58
|
+
workflowId: "coding-task-workflow-agentic",
|
|
59
|
+
completedSteps: ["phase-6-prep"],
|
|
60
|
+
context: cleanContextForWorkflowNext(fullContext, [
|
|
61
|
+
'featureBranch', // I created this
|
|
62
|
+
'verificationResult', // I added this
|
|
63
|
+
'filesCreated' // I added this
|
|
64
|
+
])
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Even Simpler: Manual Approach
|
|
69
|
+
|
|
70
|
+
If you're manually calling workflow_next, just remember:
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"workflowId": "...",
|
|
75
|
+
"completedSteps": [...],
|
|
76
|
+
"context": {
|
|
77
|
+
// Only 3-5 fields max!
|
|
78
|
+
"currentStep": {...},
|
|
79
|
+
"stepIndex": 1,
|
|
80
|
+
"stepIteration": 2,
|
|
81
|
+
"yourNewData": "..."
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Validation Check
|
|
87
|
+
|
|
88
|
+
Before sending, ask yourself:
|
|
89
|
+
- Is my context < 5KB?
|
|
90
|
+
- Did I remove all arrays I didn't modify?
|
|
91
|
+
- Did I remove all `_` fields?
|
|
92
|
+
- Am I only sending what I changed?
|
|
93
|
+
|
|
94
|
+
If yes to all, you're doing it right!
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Agent Context Optimization Guide
|
|
2
|
+
|
|
3
|
+
## The Problem
|
|
4
|
+
|
|
5
|
+
Agents currently send back the ENTIRE context (15-20KB) on every `workflow_next` call, even though they only need to send what changed.
|
|
6
|
+
|
|
7
|
+
## The Solution: Send Only What Changed
|
|
8
|
+
|
|
9
|
+
### DON'T DO THIS (Current Behavior)
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"workflowId": "coding-task-workflow-agentic",
|
|
14
|
+
"completedSteps": ["phase-6-prep"],
|
|
15
|
+
"context": {
|
|
16
|
+
// All 17KB of data including:
|
|
17
|
+
"taskDescription": "...",
|
|
18
|
+
"userRules": "...",
|
|
19
|
+
"implementationSteps": [/* all 14 items */],
|
|
20
|
+
"_loopState": {/* entire state */},
|
|
21
|
+
"_currentLoop": {/* full definition */},
|
|
22
|
+
// ... everything else unchanged
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### DO THIS INSTEAD (Optimized)
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"workflowId": "coding-task-workflow-agentic",
|
|
32
|
+
"completedSteps": ["phase-6-prep"],
|
|
33
|
+
"context": {
|
|
34
|
+
// Only what you need or changed:
|
|
35
|
+
"currentStep": {
|
|
36
|
+
"title": "Core Contracts...",
|
|
37
|
+
"description": "...",
|
|
38
|
+
"outputs": "..."
|
|
39
|
+
},
|
|
40
|
+
"stepIndex": 1,
|
|
41
|
+
"stepIteration": 2,
|
|
42
|
+
"featureBranch": "feat/new-feature", // NEW data you created
|
|
43
|
+
// That's it! 3KB instead of 17KB
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Rules for Context Management
|
|
49
|
+
|
|
50
|
+
### 1. Never Echo Arrays
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
// BAD: Sending back unchanged array
|
|
54
|
+
"implementationSteps": [/* all 14 items */]
|
|
55
|
+
|
|
56
|
+
// GOOD: Only send current item
|
|
57
|
+
"currentStep": { /* just this one */ }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 2. Skip Internal Fields
|
|
61
|
+
|
|
62
|
+
Never send these back:
|
|
63
|
+
- `_loopState`
|
|
64
|
+
- `_currentLoop`
|
|
65
|
+
- `_contextSize`
|
|
66
|
+
- `_warnings`
|
|
67
|
+
|
|
68
|
+
### 3. Only Send What You Modified
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
// If you created a new variable:
|
|
72
|
+
"verificationResult": true
|
|
73
|
+
|
|
74
|
+
// If you modified existing data:
|
|
75
|
+
"confidenceScore": 10 // was 9
|
|
76
|
+
|
|
77
|
+
// DON'T send unchanged data:
|
|
78
|
+
// "taskDescription": "..." // unchanged, don't send
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Specific Examples
|
|
82
|
+
|
|
83
|
+
### For Loop Steps
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"workflowId": "coding-task-workflow-agentic",
|
|
88
|
+
"completedSteps": ["phase-6-prep", "phase-6-implement"],
|
|
89
|
+
"context": {
|
|
90
|
+
"currentStep": { /* current */ },
|
|
91
|
+
"stepIndex": 2,
|
|
92
|
+
"stepIteration": 3,
|
|
93
|
+
"filesCreated": ["new-file.ts"], // NEW data
|
|
94
|
+
"testsPassed": true // NEW data
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### For Clarification Steps
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"workflowId": "coding-task-workflow-agentic",
|
|
104
|
+
"completedSteps": ["phase-2-informed-clarification"],
|
|
105
|
+
"context": {
|
|
106
|
+
"clarifiedRequirements": "Updated requirements...", // MODIFIED
|
|
107
|
+
"confidenceScore": 8 // MODIFIED
|
|
108
|
+
// Don't send taskDescription, userRules, etc.
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Why This Matters
|
|
114
|
+
|
|
115
|
+
- **80-90% smaller requests** (3KB vs 17KB)
|
|
116
|
+
- **Faster processing**
|
|
117
|
+
- **Lower costs**
|
|
118
|
+
- **Better performance**
|
|
119
|
+
|
|
120
|
+
## Implementation Checklist
|
|
121
|
+
|
|
122
|
+
When calling `workflow_next`:
|
|
123
|
+
|
|
124
|
+
1. [ ] Remove all arrays you didn't modify
|
|
125
|
+
2. [ ] Remove all `_` prefixed fields
|
|
126
|
+
3. [ ] Only include fields you created or changed
|
|
127
|
+
4. [ ] For loops: only send current item, not all items
|
|
128
|
+
5. [ ] Check: Is my context < 5KB? (Good!)
|
|
129
|
+
|
|
130
|
+
## Testing Your Implementation
|
|
131
|
+
|
|
132
|
+
Before:
|
|
133
|
+
```
|
|
134
|
+
Context size: 17,104 bytes
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
After following this guide:
|
|
138
|
+
```
|
|
139
|
+
Context size: 2,048 bytes (88% reduction!)
|
|
140
|
+
```
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# Context Optimization Guide for Workflows
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The MCP server now includes automatic context optimization instructions that help AI agents reduce the size of context sent with each `workflow_next` call. This guide explains how workflows can
|
|
6
|
+
use this feature effectively.
|
|
7
|
+
|
|
8
|
+
## Understanding the Stateless Nature
|
|
9
|
+
|
|
10
|
+
The MCP server is **completely stateless**. This means:
|
|
11
|
+
- It doesn't remember previous requests
|
|
12
|
+
- Every `workflow_next` call must include ALL necessary data
|
|
13
|
+
- Missing required variables will cause failures
|
|
14
|
+
|
|
15
|
+
## What Gets Optimized
|
|
16
|
+
|
|
17
|
+
### Before Optimization
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"workflowId": "coding-task-workflow-agentic",
|
|
21
|
+
"completedSteps": ["phase-1", "phase-2"],
|
|
22
|
+
"context": {
|
|
23
|
+
// 17KB of accumulated state including:
|
|
24
|
+
"taskDescription": "...", // 2KB
|
|
25
|
+
"implementationSteps": [...], // 10KB array
|
|
26
|
+
"_loopState": {...}, // 3KB
|
|
27
|
+
"analysisResults": {...}, // 1KB
|
|
28
|
+
"userRules": [...], // 500B
|
|
29
|
+
"existingCode": "...", // 500B
|
|
30
|
+
// ... and much more
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### After Optimization
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"workflowId": "coding-task-workflow-agentic",
|
|
39
|
+
"completedSteps": ["phase-1", "phase-2", "phase-3"],
|
|
40
|
+
"context": {
|
|
41
|
+
// Only what's needed for the next step:
|
|
42
|
+
"taskComplexity": "Medium", // Used in conditions
|
|
43
|
+
"currentStepNumber": 3, // Used in templates
|
|
44
|
+
"stepCompleted": true, // New variable
|
|
45
|
+
"testResults": "passed" // Modified variable
|
|
46
|
+
// Total: <2KB
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Critical Rules for Context Preservation
|
|
52
|
+
|
|
53
|
+
### 1. Variables in Conditions
|
|
54
|
+
|
|
55
|
+
If a step has a `runCondition`, ALL referenced variables MUST be included:
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"id": "conditional-step",
|
|
60
|
+
"runCondition": {
|
|
61
|
+
"and": [
|
|
62
|
+
{"var": "taskComplexity", "equals": "Large"},
|
|
63
|
+
{"var": "needsReview", "equals": true}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Required context:**
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"taskComplexity": "Large",
|
|
73
|
+
"needsReview": true
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 2. Template Variables
|
|
78
|
+
|
|
79
|
+
Any `{{variable}}` in prompts, titles, or guidance MUST be included:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"id": "loop-step",
|
|
84
|
+
"title": "Step {{currentStepNumber}} of {{totalSteps}}",
|
|
85
|
+
"prompt": "Implement item {{currentItem.name}}"
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Required context:**
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"currentStepNumber": 3,
|
|
93
|
+
"totalSteps": 10,
|
|
94
|
+
"currentItem": {"name": "User authentication"}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 3. Loop Variables
|
|
99
|
+
|
|
100
|
+
When inside a loop, specific variables are injected and must be preserved:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
// For forEach loops:
|
|
105
|
+
"currentItem": {...}, // Current item being processed
|
|
106
|
+
"currentIndex": 2, // Index in the array
|
|
107
|
+
"currentIteration": 3, // 1-based iteration count
|
|
108
|
+
|
|
109
|
+
// Only the active loop state:
|
|
110
|
+
"_loopState": {
|
|
111
|
+
"active-loop-id": {
|
|
112
|
+
"iteration": 2,
|
|
113
|
+
"index": 2
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Best Practices for Workflow Design
|
|
120
|
+
|
|
121
|
+
### 1. Avoid Large Array Storage
|
|
122
|
+
|
|
123
|
+
**Bad: Storing large arrays**
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"id": "prepare-implementation",
|
|
127
|
+
"prompt": "Extract all implementation steps into an array"
|
|
128
|
+
// Results in: implementationSteps: [30 items] = 15KB
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Good: Store count and read on-demand**
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"id": "count-steps",
|
|
136
|
+
"prompt": "Count the implementation steps in the plan"
|
|
137
|
+
// Results in: totalSteps: 30 = 4 bytes
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 2. Use Explicit Variable Names
|
|
142
|
+
|
|
143
|
+
Make it clear which variables are important:
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"id": "validation-step",
|
|
148
|
+
"prompt": "Validate the code. Set 'validationPassed' to true/false",
|
|
149
|
+
"guidance": ["Variable 'validationPassed' will be used in next step's condition"]
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### 3. Document Variable Dependencies
|
|
154
|
+
|
|
155
|
+
Add guidance about what needs to be preserved:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"id": "analysis-step",
|
|
160
|
+
"guidance": [
|
|
161
|
+
"Extract key findings into 'analysisResults'",
|
|
162
|
+
"This variable is needed until phase-5"
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Workflow-Specific Optimizations
|
|
168
|
+
|
|
169
|
+
### 1. Coding Task Workflow
|
|
170
|
+
|
|
171
|
+
The coding task workflow now includes explicit optimization instructions:
|
|
172
|
+
|
|
173
|
+
```json
|
|
174
|
+
{
|
|
175
|
+
"id": "phase-6-prep",
|
|
176
|
+
"prompt": "...\n\n**CRITICAL CONTEXT OPTIMIZATION:**\nWhen calling workflow_next after this step, send ONLY:\n- currentStepNumber and totalImplementationSteps\n- Any NEW variables you created (like featureBranch)\n- DO NOT send: arrays, plans, _loopState, _currentLoop, unchanged data"
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 2. Custom Workflows
|
|
181
|
+
|
|
182
|
+
You can add similar instructions to your workflows:
|
|
183
|
+
|
|
184
|
+
```json
|
|
185
|
+
{
|
|
186
|
+
"id": "data-processing",
|
|
187
|
+
"prompt": "Process the data...",
|
|
188
|
+
"guidance": [
|
|
189
|
+
"After processing, only send 'processingStatus' and 'errorCount'",
|
|
190
|
+
"The large 'rawData' array is no longer needed"
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Debugging Context Issues
|
|
196
|
+
|
|
197
|
+
### Common Problems
|
|
198
|
+
|
|
199
|
+
1. **Missing Condition Variable**
|
|
200
|
+
- Error: `Cannot read property 'X' of undefined`
|
|
201
|
+
- Fix: Ensure variable X is included in context
|
|
202
|
+
|
|
203
|
+
2. **Missing Template Variable**
|
|
204
|
+
- Symptom: `{{variable}}` appears literally in output
|
|
205
|
+
- Fix: Include the variable in context
|
|
206
|
+
|
|
207
|
+
3. **Loop State Lost**
|
|
208
|
+
- Symptom: Loop restarts or skips
|
|
209
|
+
- Fix: Preserve `_loopState[activeLoopId]`
|
|
210
|
+
|
|
211
|
+
4. **Loop Count Variable Missing**
|
|
212
|
+
- Symptom: Loop exits immediately, jumps to next major phase
|
|
213
|
+
- Error: "Invalid count value for 'for' loop: variableName"
|
|
214
|
+
- Fix: Ensure count variable (e.g., `totalImplementationSteps`) is preserved
|
|
215
|
+
- Common cause: Workflow step instructions override general template variable rules
|
|
216
|
+
|
|
217
|
+
### Validation Checklist
|
|
218
|
+
|
|
219
|
+
Before each `workflow_next` call, agents should verify:
|
|
220
|
+
|
|
221
|
+
- [ ] `workflowId` is included
|
|
222
|
+
- [ ] `completedSteps` array is complete
|
|
223
|
+
- [ ] All condition variables are present
|
|
224
|
+
- [ ] All template variables are included
|
|
225
|
+
- [ ] Loop count variables are preserved (e.g., `totalImplementationSteps`)
|
|
226
|
+
- [ ] New/modified variables are added
|
|
227
|
+
- [ ] Active loop state is preserved
|
|
228
|
+
- [ ] Context size is reasonable (<10KB)
|
|
229
|
+
|
|
230
|
+
## Size Targets
|
|
231
|
+
|
|
232
|
+
| Scenario | Target Size | Maximum |
|
|
233
|
+
|----------|------------|---------|
|
|
234
|
+
| Simple step | <1KB | 2KB |
|
|
235
|
+
| With conditions | <2KB | 5KB |
|
|
236
|
+
| Loop iteration | <3KB | 5KB |
|
|
237
|
+
| Complex state | <5KB | 10KB |
|
|
238
|
+
| Maximum allowed | - | 256KB |
|
|
239
|
+
|
|
240
|
+
## Example: Complete Optimization Flow
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
// Step 1: Agent receives response with optimization instructions
|
|
244
|
+
const response = await workflow_next({
|
|
245
|
+
workflowId: "my-workflow",
|
|
246
|
+
completedSteps: ["step-1"],
|
|
247
|
+
context: fullContext // 15KB
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// Step 2: Agent reads optimization requirements
|
|
251
|
+
// Sees: "ALWAYS INCLUDE condition variables..."
|
|
252
|
+
|
|
253
|
+
// Step 3: Agent analyzes next step requirements
|
|
254
|
+
// Next step has: runCondition using 'status'
|
|
255
|
+
// Next step has: "Review {{itemCount}} items"
|
|
256
|
+
|
|
257
|
+
// Step 4: Agent sends optimized context
|
|
258
|
+
const nextCall = await workflow_next({
|
|
259
|
+
workflowId: "my-workflow",
|
|
260
|
+
completedSteps: ["step-1", "step-2"],
|
|
261
|
+
context: {
|
|
262
|
+
// Required for condition:
|
|
263
|
+
status: "ready",
|
|
264
|
+
// Required for template:
|
|
265
|
+
itemCount: 5,
|
|
266
|
+
// New variable from this step:
|
|
267
|
+
reviewStarted: true
|
|
268
|
+
// Total: <1KB (vs 15KB)
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Migration Guide
|
|
274
|
+
|
|
275
|
+
For existing agents:
|
|
276
|
+
1. Start logging context sizes
|
|
277
|
+
2. Identify which variables are actually used
|
|
278
|
+
3. Implement context filtering based on the requirements
|
|
279
|
+
4. Test with reduced context
|
|
280
|
+
5. Monitor for any missing variable errors
|
|
281
|
+
|
|
282
|
+
## Summary
|
|
283
|
+
|
|
284
|
+
The context optimization feature helps reduce token usage by 70-90% while maintaining full functionality. The key is understanding what the stateless server actually needs and sending only that data. When in doubt, err on the side of including data rather than breaking functionality.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
name: Validate Workflows
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main, master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main, master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
validate:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout repository
|
|
15
|
+
uses: actions/checkout@v3
|
|
16
|
+
|
|
17
|
+
- name: Setup Node.js
|
|
18
|
+
uses: actions/setup-node@v3
|
|
19
|
+
with:
|
|
20
|
+
node-version: '18'
|
|
21
|
+
|
|
22
|
+
- name: Install WorkRail
|
|
23
|
+
run: npm install -g workrail || echo "WorkRail not yet published, skipping validation"
|
|
24
|
+
|
|
25
|
+
- name: Count workflows
|
|
26
|
+
id: count
|
|
27
|
+
run: |
|
|
28
|
+
count=$(ls -1 workflows/*.json 2>/dev/null | wc -l || echo 0)
|
|
29
|
+
echo "count=$count" >> $GITHUB_OUTPUT
|
|
30
|
+
echo "Found $count workflow(s)"
|
|
31
|
+
|
|
32
|
+
- name: Validate workflow files
|
|
33
|
+
if: steps.count.outputs.count > 0
|
|
34
|
+
run: |
|
|
35
|
+
errors=0
|
|
36
|
+
for file in workflows/*.json; do
|
|
37
|
+
echo "Validating $file..."
|
|
38
|
+
|
|
39
|
+
# Check if file exists and is readable
|
|
40
|
+
if [ ! -r "$file" ]; then
|
|
41
|
+
echo "❌ Cannot read file: $file"
|
|
42
|
+
errors=$((errors + 1))
|
|
43
|
+
continue
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
# Validate JSON syntax
|
|
47
|
+
if ! jq empty "$file" 2>/dev/null; then
|
|
48
|
+
echo "❌ Invalid JSON in $file"
|
|
49
|
+
errors=$((errors + 1))
|
|
50
|
+
continue
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
# Check required fields
|
|
54
|
+
if ! jq -e '.id' "$file" >/dev/null; then
|
|
55
|
+
echo "❌ Missing 'id' field in $file"
|
|
56
|
+
errors=$((errors + 1))
|
|
57
|
+
fi
|
|
58
|
+
|
|
59
|
+
if ! jq -e '.name' "$file" >/dev/null; then
|
|
60
|
+
echo "❌ Missing 'name' field in $file"
|
|
61
|
+
errors=$((errors + 1))
|
|
62
|
+
fi
|
|
63
|
+
|
|
64
|
+
if ! jq -e '.description' "$file" >/dev/null; then
|
|
65
|
+
echo "❌ Missing 'description' field in $file"
|
|
66
|
+
errors=$((errors + 1))
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
if ! jq -e '.version' "$file" >/dev/null; then
|
|
70
|
+
echo "❌ Missing 'version' field in $file"
|
|
71
|
+
errors=$((errors + 1))
|
|
72
|
+
fi
|
|
73
|
+
|
|
74
|
+
if ! jq -e '.steps' "$file" >/dev/null; then
|
|
75
|
+
echo "❌ Missing 'steps' field in $file"
|
|
76
|
+
errors=$((errors + 1))
|
|
77
|
+
fi
|
|
78
|
+
|
|
79
|
+
# Check filename matches workflow ID
|
|
80
|
+
workflow_id=$(jq -r '.id' "$file")
|
|
81
|
+
expected_filename="workflows/${workflow_id}.json"
|
|
82
|
+
if [ "$file" != "$expected_filename" ]; then
|
|
83
|
+
echo "⚠️ Warning: Workflow ID '$workflow_id' doesn't match filename '$file'"
|
|
84
|
+
echo " Expected: $expected_filename"
|
|
85
|
+
fi
|
|
86
|
+
|
|
87
|
+
echo "✅ $file is valid"
|
|
88
|
+
done
|
|
89
|
+
|
|
90
|
+
if [ $errors -gt 0 ]; then
|
|
91
|
+
echo "❌ Found $errors error(s)"
|
|
92
|
+
exit 1
|
|
93
|
+
fi
|
|
94
|
+
|
|
95
|
+
echo "✅ All workflows are valid"
|
|
96
|
+
|
|
97
|
+
- name: Check for duplicate IDs
|
|
98
|
+
if: steps.count.outputs.count > 0
|
|
99
|
+
run: |
|
|
100
|
+
ids=$(jq -r '.id' workflows/*.json | sort)
|
|
101
|
+
duplicate_ids=$(echo "$ids" | uniq -d)
|
|
102
|
+
|
|
103
|
+
if [ -n "$duplicate_ids" ]; then
|
|
104
|
+
echo "❌ Found duplicate workflow IDs:"
|
|
105
|
+
echo "$duplicate_ids"
|
|
106
|
+
exit 1
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
echo "✅ No duplicate workflow IDs found"
|
|
110
|
+
|
|
111
|
+
- name: Generate workflow summary
|
|
112
|
+
if: steps.count.outputs.count > 0
|
|
113
|
+
run: |
|
|
114
|
+
echo "## Workflow Summary" >> $GITHUB_STEP_SUMMARY
|
|
115
|
+
echo "" >> $GITHUB_STEP_SUMMARY
|
|
116
|
+
echo "| ID | Name | Version |" >> $GITHUB_STEP_SUMMARY
|
|
117
|
+
echo "|---|---|---|" >> $GITHUB_STEP_SUMMARY
|
|
118
|
+
|
|
119
|
+
for file in workflows/*.json; do
|
|
120
|
+
id=$(jq -r '.id' "$file")
|
|
121
|
+
name=$(jq -r '.name' "$file")
|
|
122
|
+
version=$(jq -r '.version' "$file")
|
|
123
|
+
echo "| $id | $name | $version |" >> $GITHUB_STEP_SUMMARY
|
|
124
|
+
done
|
|
125
|
+
|