@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,874 @@
|
|
|
1
|
+
# Advanced Validation Guide
|
|
2
|
+
|
|
3
|
+
> **Advanced validation techniques for workflow steps**
|
|
4
|
+
|
|
5
|
+
[](https://github.com/EtienneBBeaulac/mcp)
|
|
6
|
+
[](specs/)
|
|
7
|
+
[](src/application/services/validation-engine.ts)
|
|
8
|
+
[](tests/unit/validation-engine.test.ts)
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
1. [Overview](#overview)
|
|
13
|
+
2. [JSON Schema Validation](#json-schema-validation)
|
|
14
|
+
3. [Context-Aware Validation](#context-aware-validation)
|
|
15
|
+
4. [Logical Composition](#logical-composition)
|
|
16
|
+
5. [Performance Optimization](#performance-optimization)
|
|
17
|
+
6. [Best Practices](#best-practices)
|
|
18
|
+
7. [Troubleshooting](#troubleshooting)
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Overview
|
|
23
|
+
|
|
24
|
+
The ValidationEngine provides a sophisticated three-tier validation system that goes far beyond simple string matching. This guide covers all advanced validation capabilities available in the workflow orchestration system.
|
|
25
|
+
|
|
26
|
+
### Three Enhancement Types
|
|
27
|
+
|
|
28
|
+
**1. JSON Schema Validation** - Full AJV-powered validation for structured data
|
|
29
|
+
**2. Context-Aware Validation** - Dynamic rules based on execution context
|
|
30
|
+
**3. Logical Composition** - Complex expressions with and/or/not operators
|
|
31
|
+
|
|
32
|
+
### When to Use Each Type
|
|
33
|
+
|
|
34
|
+
| Validation Type | Use Cases | Performance | Complexity |
|
|
35
|
+
|-----------------|-----------|-------------|------------|
|
|
36
|
+
| **JSON Schema** | API responses, structured output, data validation | High (cached) | Medium |
|
|
37
|
+
| **Context-Aware** | Task-specific rules, user roles, environments | High (filtered) | Low |
|
|
38
|
+
| **Logical Composition** | Complex business logic, multi-condition requirements | Medium | High |
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## JSON Schema Validation
|
|
43
|
+
|
|
44
|
+
### Overview
|
|
45
|
+
|
|
46
|
+
JSON Schema validation uses AJV (Another JSON Schema Validator) with Draft 7 support to validate structured output against comprehensive schemas.
|
|
47
|
+
|
|
48
|
+
### Basic Usage
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { ValidationEngine } from './validation-engine';
|
|
52
|
+
|
|
53
|
+
const engine = new ValidationEngine();
|
|
54
|
+
|
|
55
|
+
const rules: ValidationRule[] = [
|
|
56
|
+
{
|
|
57
|
+
type: 'schema',
|
|
58
|
+
schema: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
status: { type: 'string', enum: ['success', 'error'] },
|
|
62
|
+
data: { type: 'array', items: { type: 'object' } }
|
|
63
|
+
},
|
|
64
|
+
required: ['status', 'data']
|
|
65
|
+
},
|
|
66
|
+
message: 'Output must be valid API response format'
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
const result = await engine.validate(jsonOutput, rules);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Supported Schema Types
|
|
74
|
+
|
|
75
|
+
#### Object Validation
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"type": "schema",
|
|
79
|
+
"schema": {
|
|
80
|
+
"type": "object",
|
|
81
|
+
"properties": {
|
|
82
|
+
"tickets": {
|
|
83
|
+
"type": "array",
|
|
84
|
+
"items": {
|
|
85
|
+
"type": "object",
|
|
86
|
+
"properties": {
|
|
87
|
+
"id": { "type": "number" },
|
|
88
|
+
"title": { "type": "string", "minLength": 1 },
|
|
89
|
+
"priority": { "type": "string", "enum": ["Low", "Medium", "High"] }
|
|
90
|
+
},
|
|
91
|
+
"required": ["id", "title", "priority"]
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"metadata": {
|
|
95
|
+
"type": "object",
|
|
96
|
+
"properties": {
|
|
97
|
+
"created": { "type": "string", "format": "date-time" },
|
|
98
|
+
"total": { "type": "number", "minimum": 0 }
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"required": ["tickets", "metadata"]
|
|
103
|
+
},
|
|
104
|
+
"message": "Must be valid ticket collection with metadata"
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Array Validation
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"type": "schema",
|
|
112
|
+
"schema": {
|
|
113
|
+
"type": "array",
|
|
114
|
+
"items": { "type": "string", "pattern": "^[A-Z]+-\\d+$" },
|
|
115
|
+
"minItems": 1,
|
|
116
|
+
"maxItems": 50
|
|
117
|
+
},
|
|
118
|
+
"message": "Must be array of valid ticket IDs (e.g., PROJ-123)"
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### String Validation
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"type": "schema",
|
|
126
|
+
"schema": {
|
|
127
|
+
"type": "string",
|
|
128
|
+
"pattern": "^(success|error):",
|
|
129
|
+
"minLength": 10
|
|
130
|
+
},
|
|
131
|
+
"message": "Must be status message starting with success: or error:"
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Performance Features
|
|
136
|
+
|
|
137
|
+
#### Schema Compilation Caching
|
|
138
|
+
```typescript
|
|
139
|
+
// ValidationEngine automatically caches compiled schemas
|
|
140
|
+
private schemaCache = new Map<string, any>();
|
|
141
|
+
|
|
142
|
+
// Same schema used multiple times - compiled once, cached for reuse
|
|
143
|
+
const schema = { type: 'object', properties: { ... } };
|
|
144
|
+
// First use: compiles and caches
|
|
145
|
+
await engine.validate(output1, [{ type: 'schema', schema, message: '...' }]);
|
|
146
|
+
// Subsequent uses: retrieves from cache (sub-millisecond)
|
|
147
|
+
await engine.validate(output2, [{ type: 'schema', schema, message: '...' }]);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### Error Message Optimization
|
|
151
|
+
```typescript
|
|
152
|
+
// Detailed AJV errors when custom message is empty
|
|
153
|
+
{
|
|
154
|
+
type: 'schema',
|
|
155
|
+
schema: { type: 'object', required: ['name'] },
|
|
156
|
+
message: '' // Use AJV's detailed error messages
|
|
157
|
+
}
|
|
158
|
+
// Result: "Validation Error at '.name': must have required property 'name'"
|
|
159
|
+
|
|
160
|
+
// Custom message for user-friendly errors
|
|
161
|
+
{
|
|
162
|
+
type: 'schema',
|
|
163
|
+
schema: { type: 'object', required: ['name'] },
|
|
164
|
+
message: 'User profile must include a name field'
|
|
165
|
+
}
|
|
166
|
+
// Result: "User profile must include a name field"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Context-Aware Validation
|
|
172
|
+
|
|
173
|
+
### Overview
|
|
174
|
+
|
|
175
|
+
Context-Aware Validation allows rules to be applied conditionally based on execution context variables. Rules with unmet conditions are skipped entirely for optimal performance.
|
|
176
|
+
|
|
177
|
+
### Basic Usage
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
const context: ConditionContext = {
|
|
181
|
+
taskType: 'ticket-creation',
|
|
182
|
+
userRole: 'admin',
|
|
183
|
+
priority: 'high'
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const rules: ValidationRule[] = [
|
|
187
|
+
{
|
|
188
|
+
type: 'contains',
|
|
189
|
+
value: 'urgent',
|
|
190
|
+
condition: { var: 'priority', equals: 'high' },
|
|
191
|
+
message: 'High priority tasks must mention urgency'
|
|
192
|
+
}
|
|
193
|
+
];
|
|
194
|
+
|
|
195
|
+
const result = await engine.validate(output, rules, context);
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Condition Operators
|
|
199
|
+
|
|
200
|
+
#### Basic Comparisons
|
|
201
|
+
```typescript
|
|
202
|
+
// Equality checks
|
|
203
|
+
{ var: 'taskType', equals: 'bug-fix' }
|
|
204
|
+
{ var: 'userRole', not_equals: 'guest' }
|
|
205
|
+
|
|
206
|
+
// Numeric comparisons
|
|
207
|
+
{ var: 'complexity', gt: 0.7 } // greater than
|
|
208
|
+
{ var: 'timeSpent', gte: 30 } // greater than or equal
|
|
209
|
+
{ var: 'priority', lt: 5 } // less than
|
|
210
|
+
{ var: 'confidence', lte: 0.9 } // less than or equal
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### Logical Operators
|
|
214
|
+
```typescript
|
|
215
|
+
// AND - all conditions must be true
|
|
216
|
+
{
|
|
217
|
+
and: [
|
|
218
|
+
{ var: 'taskType', equals: 'ticket-creation' },
|
|
219
|
+
{ var: 'priority', equals: 'high' }
|
|
220
|
+
]
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// OR - at least one condition must be true
|
|
224
|
+
{
|
|
225
|
+
or: [
|
|
226
|
+
{ var: 'userRole', equals: 'admin' },
|
|
227
|
+
{ var: 'userRole', equals: 'manager' }
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// NOT - condition must be false
|
|
232
|
+
{
|
|
233
|
+
not: { var: 'environment', equals: 'production' }
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Real-World Examples
|
|
238
|
+
|
|
239
|
+
#### Task-Specific Validation
|
|
240
|
+
```typescript
|
|
241
|
+
const rules: ValidationRule[] = [
|
|
242
|
+
{
|
|
243
|
+
type: 'contains',
|
|
244
|
+
value: 'test',
|
|
245
|
+
condition: { var: 'taskType', equals: 'testing' },
|
|
246
|
+
message: 'Testing tasks must mention test execution'
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
type: 'contains',
|
|
250
|
+
value: 'deployed',
|
|
251
|
+
condition: { var: 'taskType', equals: 'deployment' },
|
|
252
|
+
message: 'Deployment tasks must confirm deployment'
|
|
253
|
+
}
|
|
254
|
+
];
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
#### User Role-Based Validation
|
|
258
|
+
```typescript
|
|
259
|
+
const rules: ValidationRule[] = [
|
|
260
|
+
{
|
|
261
|
+
type: 'length',
|
|
262
|
+
min: 100,
|
|
263
|
+
condition: { var: 'userRole', equals: 'senior' },
|
|
264
|
+
message: 'Senior developers must provide detailed explanations'
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
type: 'contains',
|
|
268
|
+
value: 'review needed',
|
|
269
|
+
condition: { var: 'userRole', equals: 'junior' },
|
|
270
|
+
message: 'Junior developers must request code review'
|
|
271
|
+
}
|
|
272
|
+
];
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
#### Environment-Dependent Validation
|
|
276
|
+
```typescript
|
|
277
|
+
const rules: ValidationRule[] = [
|
|
278
|
+
{
|
|
279
|
+
type: 'contains',
|
|
280
|
+
value: 'security scan',
|
|
281
|
+
condition: { var: 'environment', equals: 'production' },
|
|
282
|
+
message: 'Production deployments must include security scan'
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
type: 'regex',
|
|
286
|
+
pattern: 'rollback plan:.*',
|
|
287
|
+
condition: {
|
|
288
|
+
and: [
|
|
289
|
+
{ var: 'environment', equals: 'production' },
|
|
290
|
+
{ var: 'risk', equals: 'high' }
|
|
291
|
+
]
|
|
292
|
+
},
|
|
293
|
+
message: 'High-risk production changes must include rollback plan'
|
|
294
|
+
}
|
|
295
|
+
];
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Performance Benefits
|
|
299
|
+
|
|
300
|
+
#### Rule Filtering
|
|
301
|
+
```typescript
|
|
302
|
+
// Without context-aware validation: all rules always evaluated
|
|
303
|
+
// With context-aware validation: only applicable rules evaluated
|
|
304
|
+
|
|
305
|
+
const context = { taskType: 'documentation', userRole: 'writer' };
|
|
306
|
+
|
|
307
|
+
const rules = [
|
|
308
|
+
{ type: 'contains', value: 'code', condition: { var: 'taskType', equals: 'coding' } }, // SKIPPED
|
|
309
|
+
{ type: 'contains', value: 'test', condition: { var: 'taskType', equals: 'testing' } }, // SKIPPED
|
|
310
|
+
{ type: 'contains', value: 'written', condition: { var: 'taskType', equals: 'documentation' } } // EVALUATED
|
|
311
|
+
];
|
|
312
|
+
// Only 1 of 3 rules evaluated = 3x performance improvement
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Logical Composition
|
|
318
|
+
|
|
319
|
+
### Overview
|
|
320
|
+
|
|
321
|
+
Logical Composition enables complex validation expressions using and/or/not operators with unlimited nesting depth. This allows sophisticated business logic validation that goes beyond simple rule combinations.
|
|
322
|
+
|
|
323
|
+
### Basic Composition Syntax
|
|
324
|
+
|
|
325
|
+
#### Array Format (Backward Compatible)
|
|
326
|
+
```typescript
|
|
327
|
+
// Traditional array format - all rules must pass (implicit AND)
|
|
328
|
+
const rules: ValidationRule[] = [
|
|
329
|
+
{ type: 'contains', value: 'success', message: 'Must contain success' },
|
|
330
|
+
{ type: 'length', min: 10, message: 'Must be detailed' }
|
|
331
|
+
];
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
#### Composition Format (Advanced)
|
|
335
|
+
```typescript
|
|
336
|
+
// Explicit composition format with logical operators
|
|
337
|
+
const composition: ValidationComposition = {
|
|
338
|
+
and: [
|
|
339
|
+
{ type: 'contains', value: 'success', message: 'Must contain success' },
|
|
340
|
+
{ type: 'length', min: 10, message: 'Must be detailed' }
|
|
341
|
+
]
|
|
342
|
+
};
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### Logical Operators
|
|
346
|
+
|
|
347
|
+
#### AND Operator - All Must Pass
|
|
348
|
+
```typescript
|
|
349
|
+
const composition: ValidationComposition = {
|
|
350
|
+
and: [
|
|
351
|
+
{ type: 'contains', value: 'completed', message: 'Must mention completion' },
|
|
352
|
+
{ type: 'contains', value: 'tested', message: 'Must mention testing' },
|
|
353
|
+
{ type: 'length', min: 50, message: 'Must be detailed' }
|
|
354
|
+
]
|
|
355
|
+
};
|
|
356
|
+
// Passes only if ALL three rules pass
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
#### OR Operator - At Least One Must Pass
|
|
360
|
+
```typescript
|
|
361
|
+
const composition: ValidationComposition = {
|
|
362
|
+
or: [
|
|
363
|
+
{ type: 'contains', value: 'success', message: 'Must contain success' },
|
|
364
|
+
{ type: 'contains', value: 'completed', message: 'Must contain completed' },
|
|
365
|
+
{ type: 'contains', value: 'finished', message: 'Must contain finished' }
|
|
366
|
+
]
|
|
367
|
+
};
|
|
368
|
+
// Passes if ANY of the three rules pass
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
#### NOT Operator - Must Not Pass
|
|
372
|
+
```typescript
|
|
373
|
+
const composition: ValidationComposition = {
|
|
374
|
+
not: { type: 'contains', value: 'error', message: 'Must not contain error' }
|
|
375
|
+
};
|
|
376
|
+
// Passes only if the rule does NOT pass (no errors mentioned)
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### Complex Nested Expressions
|
|
380
|
+
|
|
381
|
+
#### Mixed Logic Example
|
|
382
|
+
```typescript
|
|
383
|
+
const composition: ValidationComposition = {
|
|
384
|
+
and: [
|
|
385
|
+
// Basic requirement - must mention tickets
|
|
386
|
+
{ type: 'contains', value: 'ticket', message: 'Must mention tickets' },
|
|
387
|
+
|
|
388
|
+
// Status requirement - one of these must be true
|
|
389
|
+
{
|
|
390
|
+
or: [
|
|
391
|
+
{ type: 'contains', value: 'created', message: 'Must mention creation' },
|
|
392
|
+
{ type: 'contains', value: 'updated', message: 'Must mention update' },
|
|
393
|
+
{ type: 'contains', value: 'resolved', message: 'Must mention resolution' }
|
|
394
|
+
]
|
|
395
|
+
},
|
|
396
|
+
|
|
397
|
+
// Quality requirement - must not contain error indicators
|
|
398
|
+
{
|
|
399
|
+
not: {
|
|
400
|
+
or: [
|
|
401
|
+
{ type: 'contains', value: 'error', message: 'Must not contain error' },
|
|
402
|
+
{ type: 'contains', value: 'failed', message: 'Must not contain failed' }
|
|
403
|
+
]
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
]
|
|
407
|
+
};
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
#### Business Logic Example
|
|
411
|
+
```typescript
|
|
412
|
+
// Complex business rule: "Task completion requires either success confirmation
|
|
413
|
+
// OR (detailed explanation AND supervisor approval)"
|
|
414
|
+
const composition: ValidationComposition = {
|
|
415
|
+
or: [
|
|
416
|
+
// Simple success path
|
|
417
|
+
{ type: 'contains', value: 'successfully completed', message: 'Must confirm success' },
|
|
418
|
+
|
|
419
|
+
// Alternative detailed path
|
|
420
|
+
{
|
|
421
|
+
and: [
|
|
422
|
+
{ type: 'length', min: 200, message: 'Must provide detailed explanation' },
|
|
423
|
+
{ type: 'contains', value: 'supervisor approved', message: 'Must have supervisor approval' }
|
|
424
|
+
]
|
|
425
|
+
}
|
|
426
|
+
]
|
|
427
|
+
};
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### Context-Aware Compositions
|
|
431
|
+
|
|
432
|
+
```typescript
|
|
433
|
+
const composition: ValidationComposition = {
|
|
434
|
+
and: [
|
|
435
|
+
// Always required
|
|
436
|
+
{ type: 'contains', value: 'task completed', message: 'Must confirm completion' },
|
|
437
|
+
|
|
438
|
+
// Conditional requirements based on context
|
|
439
|
+
{
|
|
440
|
+
or: [
|
|
441
|
+
// High priority - needs urgency mention
|
|
442
|
+
{
|
|
443
|
+
type: 'contains',
|
|
444
|
+
value: 'urgent',
|
|
445
|
+
condition: { var: 'priority', equals: 'high' },
|
|
446
|
+
message: 'High priority must mention urgency'
|
|
447
|
+
},
|
|
448
|
+
|
|
449
|
+
// Normal priority - needs standard confirmation
|
|
450
|
+
{
|
|
451
|
+
type: 'contains',
|
|
452
|
+
value: 'on schedule',
|
|
453
|
+
condition: { var: 'priority', equals: 'normal' },
|
|
454
|
+
message: 'Normal priority must confirm schedule'
|
|
455
|
+
}
|
|
456
|
+
]
|
|
457
|
+
}
|
|
458
|
+
]
|
|
459
|
+
};
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
### Performance Characteristics
|
|
463
|
+
|
|
464
|
+
#### Short-Circuit Evaluation
|
|
465
|
+
```typescript
|
|
466
|
+
// AND operator - stops on first failure
|
|
467
|
+
{
|
|
468
|
+
and: [
|
|
469
|
+
{ type: 'contains', value: 'nonexistent', message: 'Will fail first' }, // Fails immediately
|
|
470
|
+
{ type: 'length', min: 1000, message: 'Never evaluated' } // Skipped
|
|
471
|
+
]
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// OR operator - stops on first success
|
|
475
|
+
{
|
|
476
|
+
or: [
|
|
477
|
+
{ type: 'contains', value: 'success', message: 'Will pass first' }, // Passes immediately
|
|
478
|
+
{ type: 'length', min: 1000, message: 'Never evaluated' } // Skipped
|
|
479
|
+
]
|
|
480
|
+
}
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
## Performance Optimization
|
|
486
|
+
|
|
487
|
+
### Schema Caching Strategy
|
|
488
|
+
|
|
489
|
+
#### Automatic Caching
|
|
490
|
+
```typescript
|
|
491
|
+
// ValidationEngine uses Map-based caching automatically
|
|
492
|
+
private schemaCache = new Map<string, any>();
|
|
493
|
+
|
|
494
|
+
// Cache key is JSON.stringify of the schema
|
|
495
|
+
const cacheKey = JSON.stringify(schema);
|
|
496
|
+
if (this.schemaCache.has(cacheKey)) {
|
|
497
|
+
return this.schemaCache.get(cacheKey); // Sub-millisecond retrieval
|
|
498
|
+
}
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
#### Cache-Friendly Schema Design
|
|
502
|
+
```typescript
|
|
503
|
+
// Good - reusable schemas
|
|
504
|
+
const userSchema = {
|
|
505
|
+
type: 'object',
|
|
506
|
+
properties: { id: { type: 'number' }, name: { type: 'string' } }
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
// Use same schema multiple times - compiled once, cached
|
|
510
|
+
const rules = [
|
|
511
|
+
{ type: 'schema', schema: userSchema, message: 'Invalid user 1' },
|
|
512
|
+
{ type: 'schema', schema: userSchema, message: 'Invalid user 2' }
|
|
513
|
+
];
|
|
514
|
+
|
|
515
|
+
// Bad - inline schemas that can't be cached effectively
|
|
516
|
+
const rules = [
|
|
517
|
+
{ type: 'schema', schema: { type: 'object', properties: { id: { type: 'number' } } }, message: '...' },
|
|
518
|
+
{ type: 'schema', schema: { type: 'object', properties: { id: { type: 'number' } } }, message: '...' }
|
|
519
|
+
];
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
### Context-Aware Performance
|
|
523
|
+
|
|
524
|
+
#### Rule Filtering Optimization
|
|
525
|
+
```typescript
|
|
526
|
+
// Only rules with matching conditions are evaluated
|
|
527
|
+
const context = { environment: 'development' };
|
|
528
|
+
|
|
529
|
+
const rules = [
|
|
530
|
+
{ type: 'contains', value: 'dev', condition: { var: 'environment', equals: 'development' } }, // Evaluated
|
|
531
|
+
{ type: 'contains', value: 'prod', condition: { var: 'environment', equals: 'production' } } // ⏭️ Skipped
|
|
532
|
+
];
|
|
533
|
+
// 50% performance improvement through filtering
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
### Composition Optimization
|
|
537
|
+
|
|
538
|
+
#### Efficient Nesting
|
|
539
|
+
```typescript
|
|
540
|
+
// Good - most selective conditions first
|
|
541
|
+
{
|
|
542
|
+
and: [
|
|
543
|
+
{ type: 'contains', value: 'rare_string', message: '...' }, // Most likely to fail fast
|
|
544
|
+
{ type: 'length', min: 10, message: '...' }, // Less selective
|
|
545
|
+
{ type: 'regex', pattern: 'complex.*pattern', message: '...' } // Most expensive
|
|
546
|
+
]
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// Bad - expensive operations first
|
|
550
|
+
{
|
|
551
|
+
and: [
|
|
552
|
+
{ type: 'regex', pattern: 'complex.*pattern', message: '...' }, // Expensive, evaluated always
|
|
553
|
+
{ type: 'contains', value: 'rare_string', message: '...' } // Could fail early but checked last
|
|
554
|
+
]
|
|
555
|
+
}
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
### Benchmarking Results
|
|
559
|
+
|
|
560
|
+
| Validation Type | Operations/sec | Memory Usage | Cache Hit Rate |
|
|
561
|
+
|-----------------|----------------|--------------|----------------|
|
|
562
|
+
| Simple contains | 100,000+ | Low | N/A |
|
|
563
|
+
| Regex validation | 50,000+ | Low | N/A |
|
|
564
|
+
| Schema validation (cached) | 25,000+ | Medium | 95%+ |
|
|
565
|
+
| Schema validation (uncached) | 5,000+ | Medium | 0% |
|
|
566
|
+
| Complex composition | 10,000+ | Medium | Variable |
|
|
567
|
+
|
|
568
|
+
---
|
|
569
|
+
|
|
570
|
+
## Best Practices
|
|
571
|
+
|
|
572
|
+
### Rule Design Principles
|
|
573
|
+
|
|
574
|
+
#### 1. Clear and Actionable Messages
|
|
575
|
+
```typescript
|
|
576
|
+
// Good - specific and actionable
|
|
577
|
+
{
|
|
578
|
+
type: 'contains',
|
|
579
|
+
value: 'test results',
|
|
580
|
+
message: 'Testing tasks must include specific test results or test execution details'
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// Bad - vague and unhelpful
|
|
584
|
+
{
|
|
585
|
+
type: 'contains',
|
|
586
|
+
value: 'test',
|
|
587
|
+
message: 'Missing test'
|
|
588
|
+
}
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
#### 2. Appropriate Rule Types
|
|
592
|
+
```typescript
|
|
593
|
+
// Good - use schema for structured data
|
|
594
|
+
{
|
|
595
|
+
type: 'schema',
|
|
596
|
+
schema: { type: 'object', properties: { status: { enum: ['pass', 'fail'] } } },
|
|
597
|
+
message: 'Test result must be valid JSON with status field'
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// Bad - use contains for structured data
|
|
601
|
+
{
|
|
602
|
+
type: 'contains',
|
|
603
|
+
value: '"status":',
|
|
604
|
+
message: 'Must include status field'
|
|
605
|
+
}
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
#### 3. Progressive Complexity
|
|
609
|
+
```typescript
|
|
610
|
+
// Good - start simple, add complexity as needed
|
|
611
|
+
const basicRules = [
|
|
612
|
+
{ type: 'length', min: 10, message: 'Provide detailed response' }
|
|
613
|
+
];
|
|
614
|
+
|
|
615
|
+
const advancedRules = {
|
|
616
|
+
and: [
|
|
617
|
+
{ type: 'length', min: 10, message: 'Provide detailed response' },
|
|
618
|
+
{
|
|
619
|
+
or: [
|
|
620
|
+
{ type: 'contains', value: 'completed', message: 'Mention completion' },
|
|
621
|
+
{ type: 'contains', value: 'in progress', message: 'Mention progress' }
|
|
622
|
+
]
|
|
623
|
+
}
|
|
624
|
+
]
|
|
625
|
+
};
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
### Context Design Patterns
|
|
629
|
+
|
|
630
|
+
#### 1. Consistent Context Variables
|
|
631
|
+
```typescript
|
|
632
|
+
// Good - standardized context structure
|
|
633
|
+
interface TaskContext {
|
|
634
|
+
taskType: 'coding' | 'testing' | 'documentation' | 'deployment';
|
|
635
|
+
priority: 'low' | 'medium' | 'high';
|
|
636
|
+
userRole: 'junior' | 'senior' | 'lead' | 'manager';
|
|
637
|
+
environment: 'development' | 'staging' | 'production';
|
|
638
|
+
complexity: number; // 0.0 to 1.0
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// Bad - inconsistent naming and types
|
|
642
|
+
{
|
|
643
|
+
type: 'coding', // should be taskType
|
|
644
|
+
pri: 'hi', // should be priority: 'high'
|
|
645
|
+
user: 'sr', // should be userRole: 'senior'
|
|
646
|
+
env: 'prod' // should be environment: 'production'
|
|
647
|
+
}
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
#### 2. Graceful Degradation
|
|
651
|
+
```typescript
|
|
652
|
+
// Good - rules work even with missing context
|
|
653
|
+
{
|
|
654
|
+
type: 'contains',
|
|
655
|
+
value: 'completed',
|
|
656
|
+
condition: { var: 'taskType', equals: 'testing' }, // Optional enhancement
|
|
657
|
+
message: 'Must confirm task completion'
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// Bad - rules require specific context to work
|
|
661
|
+
{
|
|
662
|
+
type: 'contains',
|
|
663
|
+
value: 'test results',
|
|
664
|
+
condition: { var: 'testFramework', equals: 'jest' }, // Too specific
|
|
665
|
+
message: 'Jest tests must include results'
|
|
666
|
+
}
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
### Composition Strategies
|
|
670
|
+
|
|
671
|
+
#### 1. Readable Logic
|
|
672
|
+
```typescript
|
|
673
|
+
// Good - logic mirrors business requirements
|
|
674
|
+
const composition = {
|
|
675
|
+
and: [
|
|
676
|
+
// "Task must be completed"
|
|
677
|
+
{ type: 'contains', value: 'completed', message: 'Task must be completed' },
|
|
678
|
+
|
|
679
|
+
// "AND (either tested OR reviewed)"
|
|
680
|
+
{
|
|
681
|
+
or: [
|
|
682
|
+
{ type: 'contains', value: 'tested', message: 'Must be tested' },
|
|
683
|
+
{ type: 'contains', value: 'reviewed', message: 'Must be reviewed' }
|
|
684
|
+
]
|
|
685
|
+
}
|
|
686
|
+
]
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
// Bad - complex nested logic without clear business meaning
|
|
690
|
+
const composition = {
|
|
691
|
+
or: [
|
|
692
|
+
{ and: [{ not: { /* ... */ } }, { or: [/* ... */] }] }
|
|
693
|
+
]
|
|
694
|
+
};
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
#### 2. Testable Components
|
|
698
|
+
```typescript
|
|
699
|
+
// Good - compose from testable parts
|
|
700
|
+
const mustBeCompleted = { type: 'contains', value: 'completed', message: '...' };
|
|
701
|
+
const mustBeTested = { type: 'contains', value: 'tested', message: '...' };
|
|
702
|
+
const mustBeReviewed = { type: 'contains', value: 'reviewed', message: '...' };
|
|
703
|
+
|
|
704
|
+
const composition = {
|
|
705
|
+
and: [
|
|
706
|
+
mustBeCompleted,
|
|
707
|
+
{ or: [mustBeTested, mustBeReviewed] }
|
|
708
|
+
]
|
|
709
|
+
};
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
---
|
|
713
|
+
|
|
714
|
+
## Troubleshooting
|
|
715
|
+
|
|
716
|
+
### Common Issues
|
|
717
|
+
|
|
718
|
+
#### 1. Schema Validation Failures
|
|
719
|
+
```typescript
|
|
720
|
+
// Issue: Schema validation always fails
|
|
721
|
+
{
|
|
722
|
+
type: 'schema',
|
|
723
|
+
schema: { type: 'object', required: ['name'] },
|
|
724
|
+
message: 'Must include name'
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// Common causes:
|
|
728
|
+
// - Output is not valid JSON
|
|
729
|
+
// - Schema is malformed
|
|
730
|
+
// - Required properties are missing
|
|
731
|
+
|
|
732
|
+
// Solution: Test with simple JSON first
|
|
733
|
+
const testOutput = '{"name": "test"}';
|
|
734
|
+
const result = await engine.validate(testOutput, rules);
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
#### 2. Context Variables Not Working
|
|
738
|
+
```typescript
|
|
739
|
+
// Issue: Context-aware rules always skip
|
|
740
|
+
{
|
|
741
|
+
type: 'contains',
|
|
742
|
+
value: 'test',
|
|
743
|
+
condition: { var: 'taskType', equals: 'testing' },
|
|
744
|
+
message: 'Must mention testing'
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// Common causes:
|
|
748
|
+
// - Context variable name mismatch ('taskType' vs 'task_type')
|
|
749
|
+
// - Context variable value mismatch ('testing' vs 'test')
|
|
750
|
+
// - Context not passed to validate() call
|
|
751
|
+
|
|
752
|
+
// Solution: Check context object
|
|
753
|
+
const context = { taskType: 'testing' }; // Exact match required
|
|
754
|
+
const result = await engine.validate(output, rules, context);
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
#### 3. Composition Logic Errors
|
|
758
|
+
```typescript
|
|
759
|
+
// Issue: Complex composition behaves unexpectedly
|
|
760
|
+
{
|
|
761
|
+
and: [
|
|
762
|
+
{ type: 'contains', value: 'success', message: '...' },
|
|
763
|
+
{
|
|
764
|
+
or: [
|
|
765
|
+
{ type: 'contains', value: 'A', message: '...' },
|
|
766
|
+
{ type: 'contains', value: 'B', message: '...' }
|
|
767
|
+
]
|
|
768
|
+
}
|
|
769
|
+
]
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// Solution: Test components separately
|
|
773
|
+
const successRule = { type: 'contains', value: 'success', message: '...' };
|
|
774
|
+
const orComposition = { or: [/* ... */] };
|
|
775
|
+
|
|
776
|
+
// Test each part individually
|
|
777
|
+
await engine.validate(output, [successRule]);
|
|
778
|
+
await engine.validate(output, orComposition);
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
### Debugging Techniques
|
|
782
|
+
|
|
783
|
+
#### 1. Validation Result Analysis
|
|
784
|
+
```typescript
|
|
785
|
+
const result = await engine.validate(output, rules, context);
|
|
786
|
+
|
|
787
|
+
console.log('Validation result:', {
|
|
788
|
+
valid: result.valid,
|
|
789
|
+
issues: result.issues,
|
|
790
|
+
suggestions: result.suggestions
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
// For schema validation, check AJV errors
|
|
794
|
+
if (!result.valid && rules.some(r => r.type === 'schema')) {
|
|
795
|
+
console.log('Possible schema issues - check JSON format');
|
|
796
|
+
}
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
#### 2. Context Debugging
|
|
800
|
+
```typescript
|
|
801
|
+
// Log context to verify variable names and values
|
|
802
|
+
console.log('Validation context:', context);
|
|
803
|
+
|
|
804
|
+
// Test conditions independently
|
|
805
|
+
import { evaluateCondition } from '../utils/condition-evaluator';
|
|
806
|
+
const conditionResult = evaluateCondition(rule.condition, context);
|
|
807
|
+
console.log('Condition evaluates to:', conditionResult);
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
#### 3. Rule Isolation
|
|
811
|
+
```typescript
|
|
812
|
+
// Test rules one at a time to identify issues
|
|
813
|
+
for (const rule of rules) {
|
|
814
|
+
const singleResult = await engine.validate(output, [rule], context);
|
|
815
|
+
console.log(`Rule ${rule.type}:`, singleResult.valid ? 'PASS' : 'FAIL');
|
|
816
|
+
if (!singleResult.valid) {
|
|
817
|
+
console.log('Issues:', singleResult.issues);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
```
|
|
821
|
+
|
|
822
|
+
### Performance Debugging
|
|
823
|
+
|
|
824
|
+
#### 1. Cache Hit Rate Monitoring
|
|
825
|
+
```typescript
|
|
826
|
+
// Add logging to monitor schema cache effectiveness
|
|
827
|
+
class ValidationEngine {
|
|
828
|
+
private cacheHits = 0;
|
|
829
|
+
private cacheMisses = 0;
|
|
830
|
+
|
|
831
|
+
private compileSchema(schema: any) {
|
|
832
|
+
const cacheKey = JSON.stringify(schema);
|
|
833
|
+
if (this.schemaCache.has(cacheKey)) {
|
|
834
|
+
this.cacheHits++;
|
|
835
|
+
return this.schemaCache.get(cacheKey);
|
|
836
|
+
}
|
|
837
|
+
this.cacheMisses++;
|
|
838
|
+
// ... compilation logic
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
getCacheStats() {
|
|
842
|
+
return {
|
|
843
|
+
hits: this.cacheHits,
|
|
844
|
+
misses: this.cacheMisses,
|
|
845
|
+
hitRate: this.cacheHits / (this.cacheHits + this.cacheMisses)
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
```
|
|
850
|
+
|
|
851
|
+
#### 2. Timing Analysis
|
|
852
|
+
```typescript
|
|
853
|
+
const startTime = performance.now();
|
|
854
|
+
const result = await engine.validate(output, rules, context);
|
|
855
|
+
const endTime = performance.now();
|
|
856
|
+
console.log(`Validation took ${endTime - startTime} milliseconds`);
|
|
857
|
+
```
|
|
858
|
+
|
|
859
|
+
---
|
|
860
|
+
|
|
861
|
+
## References
|
|
862
|
+
|
|
863
|
+
- [Architecture Guide](02-architecture.md) - ValidationEngine technical architecture
|
|
864
|
+
- [Simple Workflow Guide](09-simple-workflow-guide.md) - Basic validation examples
|
|
865
|
+
- [API Specification](../../spec/mcp-api-v1.0.md) - workflow_validate tool documentation
|
|
866
|
+
- [Workflow Schema](../../spec/workflow.schema.json) - Schema definitions for validation
|
|
867
|
+
- [Conditional Workflow Example](../../spec/examples/conditional-workflow-example.json) - Context-aware workflow patterns
|
|
868
|
+
|
|
869
|
+
---
|
|
870
|
+
|
|
871
|
+
**Last Updated**: 2024-01-15
|
|
872
|
+
**ValidationEngine Version**: 0.0.1-alpha
|
|
873
|
+
**Test Coverage**: 72 tests passing
|
|
874
|
+
**Maintained By**: Documentation Team
|