@exaudeus/workrail 0.1.4 → 0.1.5
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/application/services/enhanced-loop-validator.d.ts +21 -0
- package/dist/application/services/enhanced-loop-validator.js +137 -0
- package/dist/application/services/validation-engine.d.ts +3 -0
- package/dist/application/services/validation-engine.js +20 -2
- package/dist/cli.js +33 -6
- package/package.json +1 -1
- package/workflows/coding-task-workflow-with-loops.json +59 -10
- package/workflows/systemic-bug-investigation-with-loops.json +61 -15
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LoopStep } from '../../types/workflow-types';
|
|
2
|
+
export interface EnhancedValidationResult {
|
|
3
|
+
warnings: string[];
|
|
4
|
+
suggestions: string[];
|
|
5
|
+
info: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare class EnhancedLoopValidator {
|
|
8
|
+
private readonly PROMPT_WARNING_THRESHOLD;
|
|
9
|
+
private readonly PROMPT_ERROR_THRESHOLD;
|
|
10
|
+
private readonly TEMPLATE_VAR_PATTERN;
|
|
11
|
+
private readonly TERNARY_PATTERN;
|
|
12
|
+
private readonly NESTED_TERNARY_PATTERN;
|
|
13
|
+
validateLoopStep(step: LoopStep): EnhancedValidationResult;
|
|
14
|
+
private getLoopBodySteps;
|
|
15
|
+
private validateConditionalLogic;
|
|
16
|
+
private validatePromptLength;
|
|
17
|
+
private validateTemplateVariables;
|
|
18
|
+
private getKnownLoopVariables;
|
|
19
|
+
private detectLoopPatterns;
|
|
20
|
+
private validateLoopStructure;
|
|
21
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnhancedLoopValidator = void 0;
|
|
4
|
+
class EnhancedLoopValidator {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.PROMPT_WARNING_THRESHOLD = 1500;
|
|
7
|
+
this.PROMPT_ERROR_THRESHOLD = 2000;
|
|
8
|
+
this.TEMPLATE_VAR_PATTERN = /\{\{([^}]+)\}\}/g;
|
|
9
|
+
this.TERNARY_PATTERN = /\{\{[^}]*\?[^}]*:[^}]*\}\}/;
|
|
10
|
+
this.NESTED_TERNARY_PATTERN = /\{\{[^}]*\?[^}]*\?[^}]*:[^}]*:[^}]*\}\}/;
|
|
11
|
+
}
|
|
12
|
+
validateLoopStep(step) {
|
|
13
|
+
const warnings = [];
|
|
14
|
+
const suggestions = [];
|
|
15
|
+
const info = [];
|
|
16
|
+
const stepsToValidate = this.getLoopBodySteps(step);
|
|
17
|
+
for (const bodyStep of stepsToValidate) {
|
|
18
|
+
this.validateConditionalLogic(bodyStep, warnings, suggestions);
|
|
19
|
+
this.validatePromptLength(bodyStep, warnings, suggestions);
|
|
20
|
+
this.validateTemplateVariables(bodyStep, step, warnings, suggestions);
|
|
21
|
+
}
|
|
22
|
+
this.detectLoopPatterns(step, info, suggestions);
|
|
23
|
+
this.validateLoopStructure(step, warnings, suggestions);
|
|
24
|
+
return { warnings, suggestions, info };
|
|
25
|
+
}
|
|
26
|
+
getLoopBodySteps(step) {
|
|
27
|
+
if (Array.isArray(step.body)) {
|
|
28
|
+
return step.body;
|
|
29
|
+
}
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
validateConditionalLogic(step, warnings, suggestions) {
|
|
33
|
+
const fieldsToCheck = ['prompt', 'title', 'agentRole'];
|
|
34
|
+
for (const field of fieldsToCheck) {
|
|
35
|
+
const value = step[field];
|
|
36
|
+
if (!value || typeof value !== 'string')
|
|
37
|
+
continue;
|
|
38
|
+
if (this.NESTED_TERNARY_PATTERN.test(value)) {
|
|
39
|
+
warnings.push(`Step '${step.id}' contains nested ternary operators in ${field}. This can be hard to read and maintain.`);
|
|
40
|
+
suggestions.push(`Consider refactoring nested conditionals into separate steps with runCondition.`);
|
|
41
|
+
}
|
|
42
|
+
else if (this.TERNARY_PATTERN.test(value)) {
|
|
43
|
+
const ternaryCount = (value.match(/\?/g) || []).length;
|
|
44
|
+
if (ternaryCount >= 2) {
|
|
45
|
+
warnings.push(`Step '${step.id}' contains complex conditional logic (${ternaryCount} conditions) in ${field}.`);
|
|
46
|
+
suggestions.push(`For loops with ${ternaryCount} or more conditional paths, consider using separate steps with runCondition instead of inline conditionals.`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
validatePromptLength(step, warnings, suggestions) {
|
|
52
|
+
if (!step.prompt)
|
|
53
|
+
return;
|
|
54
|
+
const promptLength = step.prompt.length;
|
|
55
|
+
if (promptLength > this.PROMPT_ERROR_THRESHOLD) {
|
|
56
|
+
warnings.push(`Step '${step.id}' has a very long prompt (${promptLength} characters). This may cause issues.`);
|
|
57
|
+
suggestions.push(`Consider splitting this into multiple steps or moving content to the guidance section.`);
|
|
58
|
+
}
|
|
59
|
+
else if (promptLength > this.PROMPT_WARNING_THRESHOLD) {
|
|
60
|
+
warnings.push(`Step '${step.id}' has a long prompt (${promptLength} characters).`);
|
|
61
|
+
suggestions.push(`For better maintainability, consider breaking this into smaller, focused steps.`);
|
|
62
|
+
}
|
|
63
|
+
const conditionalMatches = step.prompt.match(/\{\{[^}]*\?[^}]*\}\}/g);
|
|
64
|
+
if (conditionalMatches) {
|
|
65
|
+
let totalConditionalContent = 0;
|
|
66
|
+
for (const match of conditionalMatches) {
|
|
67
|
+
const literals = match.match(/'[^']*'|"[^"]*"/g) || [];
|
|
68
|
+
for (const literal of literals) {
|
|
69
|
+
totalConditionalContent += literal.length - 2;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (totalConditionalContent > this.PROMPT_ERROR_THRESHOLD) {
|
|
73
|
+
warnings.push(`Step '${step.id}' has conditional content totaling ~${totalConditionalContent} characters when expanded.`);
|
|
74
|
+
suggestions.push(`This exceeds safe limits. Use separate steps with runCondition instead of inline conditionals.`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
validateTemplateVariables(step, loopStep, warnings, suggestions) {
|
|
79
|
+
const knownVars = this.getKnownLoopVariables(loopStep);
|
|
80
|
+
const fieldsToCheck = ['prompt', 'title', 'agentRole'];
|
|
81
|
+
for (const field of fieldsToCheck) {
|
|
82
|
+
const value = step[field];
|
|
83
|
+
if (!value || typeof value !== 'string')
|
|
84
|
+
continue;
|
|
85
|
+
const matches = value.matchAll(this.TEMPLATE_VAR_PATTERN);
|
|
86
|
+
for (const match of matches) {
|
|
87
|
+
const expression = match[1].trim();
|
|
88
|
+
const varName = expression.split(/[^a-zA-Z0-9_$]/, 1)[0];
|
|
89
|
+
if (varName && !knownVars.has(varName)) {
|
|
90
|
+
warnings.push(`Step '${step.id}' references potentially undefined variable '${varName}' in ${field}.`);
|
|
91
|
+
suggestions.push(`Ensure '${varName}' is defined in the context or use a known loop variable like: ${Array.from(knownVars).join(', ')}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
getKnownLoopVariables(loopStep) {
|
|
97
|
+
const vars = new Set();
|
|
98
|
+
vars.add(loopStep.loop.iterationVar || 'iteration');
|
|
99
|
+
if (loopStep.loop.type === 'forEach') {
|
|
100
|
+
vars.add(loopStep.loop.itemVar || 'item');
|
|
101
|
+
vars.add(loopStep.loop.indexVar || 'index');
|
|
102
|
+
}
|
|
103
|
+
vars.add('context');
|
|
104
|
+
vars.add('workflowId');
|
|
105
|
+
return vars;
|
|
106
|
+
}
|
|
107
|
+
detectLoopPatterns(step, info, suggestions) {
|
|
108
|
+
const bodySteps = this.getLoopBodySteps(step);
|
|
109
|
+
if (step.loop.type === 'for' && bodySteps.length > 0) {
|
|
110
|
+
const firstStep = bodySteps[0];
|
|
111
|
+
if (firstStep.prompt?.includes('analysis') ||
|
|
112
|
+
firstStep.title?.toLowerCase().includes('analysis') ||
|
|
113
|
+
firstStep.prompt?.includes('Step 1') ||
|
|
114
|
+
firstStep.prompt?.includes('Structure')) {
|
|
115
|
+
info.push('Progressive analysis pattern detected.');
|
|
116
|
+
suggestions.push('Consider using the multi-step pattern with separate steps and runCondition for clearer structure.');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (bodySteps.some(s => s.prompt?.includes('===') && s.prompt?.includes('?'))) {
|
|
120
|
+
info.push('Multi-conditional loop pattern detected.');
|
|
121
|
+
suggestions.push('For loops with multiple conditional paths, the separate steps pattern is more maintainable than inline conditionals.');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
validateLoopStructure(step, warnings, suggestions) {
|
|
125
|
+
if (typeof step.body === 'string' && step.loop.type === 'for' &&
|
|
126
|
+
typeof step.loop.count === 'number' && step.loop.count > 3) {
|
|
127
|
+
suggestions.push(`For loops with ${step.loop.count} iterations, consider if each iteration truly needs different logic. ` +
|
|
128
|
+
`If so, use separate steps with runCondition for better clarity.`);
|
|
129
|
+
}
|
|
130
|
+
if (step.loop.maxIterations > 100) {
|
|
131
|
+
warnings.push(`Loop '${step.id}' has a very high maxIterations limit (${step.loop.maxIterations}). ` +
|
|
132
|
+
`This could cause performance issues.`);
|
|
133
|
+
suggestions.push(`Consider if you really need ${step.loop.maxIterations} iterations, or implement pagination/chunking instead.`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.EnhancedLoopValidator = EnhancedLoopValidator;
|
|
@@ -21,10 +21,13 @@ export interface ValidationResult {
|
|
|
21
21
|
valid: boolean;
|
|
22
22
|
issues: string[];
|
|
23
23
|
suggestions: string[];
|
|
24
|
+
warnings?: string[];
|
|
25
|
+
info?: string[];
|
|
24
26
|
}
|
|
25
27
|
export declare class ValidationEngine {
|
|
26
28
|
private ajv;
|
|
27
29
|
private schemaCache;
|
|
30
|
+
private enhancedLoopValidator;
|
|
28
31
|
constructor();
|
|
29
32
|
private compileSchema;
|
|
30
33
|
private evaluateCriteria;
|
|
@@ -8,10 +8,12 @@ const error_handler_1 = require("../../core/error-handler");
|
|
|
8
8
|
const condition_evaluator_1 = require("../../utils/condition-evaluator");
|
|
9
9
|
const ajv_1 = __importDefault(require("ajv"));
|
|
10
10
|
const workflow_types_1 = require("../../types/workflow-types");
|
|
11
|
+
const enhanced_loop_validator_1 = require("./enhanced-loop-validator");
|
|
11
12
|
class ValidationEngine {
|
|
12
13
|
constructor() {
|
|
13
14
|
this.schemaCache = new Map();
|
|
14
15
|
this.ajv = new ajv_1.default({ allErrors: true });
|
|
16
|
+
this.enhancedLoopValidator = new enhanced_loop_validator_1.EnhancedLoopValidator();
|
|
15
17
|
}
|
|
16
18
|
compileSchema(schema) {
|
|
17
19
|
const schemaKey = JSON.stringify(schema);
|
|
@@ -205,6 +207,7 @@ class ValidationEngine {
|
|
|
205
207
|
throw new error_handler_1.ValidationError('Invalid validationCriteria format.');
|
|
206
208
|
}
|
|
207
209
|
validateLoopStep(step, workflow) {
|
|
210
|
+
const enhancedResult = this.enhancedLoopValidator.validateLoopStep(step);
|
|
208
211
|
const issues = [];
|
|
209
212
|
const suggestions = [];
|
|
210
213
|
const validTypes = ['while', 'until', 'for', 'forEach'];
|
|
@@ -309,15 +312,22 @@ class ValidationEngine {
|
|
|
309
312
|
issues.push(`Invalid index variable name '${step.loop.indexVar}'`);
|
|
310
313
|
suggestions.push('Use a valid JavaScript variable name');
|
|
311
314
|
}
|
|
315
|
+
const allWarnings = [...(enhancedResult.warnings || [])];
|
|
316
|
+
const allSuggestions = [...suggestions, ...(enhancedResult.suggestions || [])];
|
|
317
|
+
const allInfo = [...(enhancedResult.info || [])];
|
|
312
318
|
return {
|
|
313
319
|
valid: issues.length === 0,
|
|
314
320
|
issues,
|
|
315
|
-
suggestions
|
|
321
|
+
suggestions: allSuggestions,
|
|
322
|
+
warnings: allWarnings.length > 0 ? allWarnings : undefined,
|
|
323
|
+
info: allInfo.length > 0 ? allInfo : undefined
|
|
316
324
|
};
|
|
317
325
|
}
|
|
318
326
|
validateWorkflow(workflow) {
|
|
319
327
|
const issues = [];
|
|
320
328
|
const suggestions = [];
|
|
329
|
+
const warnings = [];
|
|
330
|
+
const info = [];
|
|
321
331
|
const stepIds = new Set();
|
|
322
332
|
for (const step of workflow.steps) {
|
|
323
333
|
if (stepIds.has(step.id)) {
|
|
@@ -331,6 +341,12 @@ class ValidationEngine {
|
|
|
331
341
|
const loopResult = this.validateLoopStep(step, workflow);
|
|
332
342
|
issues.push(...loopResult.issues.map(issue => `Step '${step.id}': ${issue}`));
|
|
333
343
|
suggestions.push(...loopResult.suggestions);
|
|
344
|
+
if (loopResult.warnings) {
|
|
345
|
+
warnings.push(...loopResult.warnings.map(warning => `Step '${step.id}': ${warning}`));
|
|
346
|
+
}
|
|
347
|
+
if (loopResult.info) {
|
|
348
|
+
info.push(...loopResult.info.map(i => `Step '${step.id}': ${i}`));
|
|
349
|
+
}
|
|
334
350
|
}
|
|
335
351
|
else {
|
|
336
352
|
if (!step.id) {
|
|
@@ -368,7 +384,9 @@ class ValidationEngine {
|
|
|
368
384
|
return {
|
|
369
385
|
valid: issues.length === 0,
|
|
370
386
|
issues,
|
|
371
|
-
suggestions
|
|
387
|
+
suggestions,
|
|
388
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
389
|
+
info: info.length > 0 ? info : undefined
|
|
372
390
|
};
|
|
373
391
|
}
|
|
374
392
|
isValidVariableName(name) {
|
package/dist/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
11
11
|
const os_1 = __importDefault(require("os"));
|
|
12
12
|
const server_1 = require("./infrastructure/rpc/server");
|
|
13
13
|
const workflow_service_1 = require("./application/services/workflow-service");
|
|
14
|
-
const
|
|
14
|
+
const validation_engine_1 = require("./application/services/validation-engine");
|
|
15
15
|
const multi_directory_workflow_storage_1 = require("./infrastructure/storage/multi-directory-workflow-storage");
|
|
16
16
|
const migrate_workflow_1 = require("./cli/migrate-workflow");
|
|
17
17
|
const program = new commander_1.Command();
|
|
@@ -177,18 +177,45 @@ async function validateWorkflowFile(filePath) {
|
|
|
177
177
|
console.error(chalk_1.default.yellow('\nPlease check the JSON syntax and try again.'));
|
|
178
178
|
process.exit(1);
|
|
179
179
|
}
|
|
180
|
-
const
|
|
181
|
-
|
|
180
|
+
const validationEngine = new validation_engine_1.ValidationEngine();
|
|
181
|
+
const result = validationEngine.validateWorkflow(workflow);
|
|
182
|
+
if (result.valid && !result.warnings?.length && !result.info?.length) {
|
|
182
183
|
console.log(chalk_1.default.green('✅ Workflow is valid:'), filePath);
|
|
183
|
-
|
|
184
|
+
}
|
|
185
|
+
else if (result.valid) {
|
|
186
|
+
console.log(chalk_1.default.green('✅ Workflow is valid with warnings:'), filePath);
|
|
187
|
+
if (result.warnings && result.warnings.length > 0) {
|
|
188
|
+
console.log(chalk_1.default.yellow('\n⚠️ Warnings:'));
|
|
189
|
+
result.warnings.forEach(warning => {
|
|
190
|
+
console.log(chalk_1.default.yellow(' •'), warning);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (result.info && result.info.length > 0) {
|
|
194
|
+
console.log(chalk_1.default.blue('\nℹ️ Information:'));
|
|
195
|
+
result.info.forEach(info => {
|
|
196
|
+
console.log(chalk_1.default.blue(' •'), info);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (result.suggestions && result.suggestions.length > 0) {
|
|
200
|
+
console.log(chalk_1.default.gray('\n💡 Suggestions:'));
|
|
201
|
+
result.suggestions.forEach(suggestion => {
|
|
202
|
+
console.log(chalk_1.default.gray(' •'), suggestion);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
184
205
|
}
|
|
185
206
|
else {
|
|
186
207
|
console.error(chalk_1.default.red('❌ Workflow validation failed:'), filePath);
|
|
187
208
|
console.error(chalk_1.default.yellow('\nValidation errors:'));
|
|
188
|
-
result.
|
|
209
|
+
result.issues.forEach(error => {
|
|
189
210
|
console.error(chalk_1.default.red(' •'), error);
|
|
190
211
|
});
|
|
191
|
-
console.error(chalk_1.default.yellow(`\nFound ${result.
|
|
212
|
+
console.error(chalk_1.default.yellow(`\nFound ${result.issues.length} validation error${result.issues.length === 1 ? '' : 's'}.`));
|
|
213
|
+
if (result.suggestions && result.suggestions.length > 0) {
|
|
214
|
+
console.log(chalk_1.default.gray('\n💡 Suggestions:'));
|
|
215
|
+
result.suggestions.forEach(suggestion => {
|
|
216
|
+
console.log(chalk_1.default.gray(' •'), suggestion);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
192
219
|
process.exit(1);
|
|
193
220
|
}
|
|
194
221
|
}
|
package/package.json
CHANGED
|
@@ -152,23 +152,72 @@
|
|
|
152
152
|
},
|
|
153
153
|
"body": [
|
|
154
154
|
{
|
|
155
|
-
"id": "phase-1-
|
|
156
|
-
"title": "Analysis Step
|
|
157
|
-
"prompt": "
|
|
158
|
-
"agentRole": "You are conducting focused analysis step
|
|
155
|
+
"id": "phase-1-step-structure",
|
|
156
|
+
"title": "Analysis Step 1/4: Structure",
|
|
157
|
+
"prompt": "**STEP 1: STRUCTURAL MAPPING**\\n\\nBuild on phase-0c overview, dive deeper into structure:\\n\\n1. Module organization (packages/services)\\n2. Core components (controllers/services/models)\\n3. Architectural patterns from overview\\n4. File naming conventions\\n5. Code organization\\n\\n**Actions:** useTools() with list_dir, grep_search (class/interface/export), read 2-3 files\\n\\n**Output (400 words):**\\n- Structure summary\\n- User rules alignment\\n- Areas for next steps\\n\\nupdateDecisionLog() with 3-5 key files",
|
|
158
|
+
"agentRole": "You are conducting focused analysis step 1 of 4. Your expertise lies in understanding code structure and organization. Use tools extensively and never make assumptions.",
|
|
159
159
|
"guidance": [
|
|
160
|
-
"This is step
|
|
160
|
+
"This is step 1 of a 4-step analysis process",
|
|
161
|
+
"Each step builds on the previous findings",
|
|
162
|
+
"Use tools liberally - verify everything",
|
|
163
|
+
"Update the Decision Log with key discoveries",
|
|
164
|
+
"Respect word limits to prevent context bloat",
|
|
165
|
+
"Note alignment/conflicts with user rules"
|
|
166
|
+
],
|
|
167
|
+
"runCondition": {"var": "analysisStep", "equals": 1},
|
|
168
|
+
"requireConfirmation": false
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"id": "phase-1-step-modules",
|
|
172
|
+
"title": "Analysis Step 2/4: Modules",
|
|
173
|
+
"prompt": "**STEP 2: TASK-RELEVANT MODULES**\\n\\nFocus on task-specific modules:\\n\\n1. Target areas from mapping\\n2. Core business logic\\n3. Data models (interfaces/types/schemas)\\n4. API contracts\\n5. Pattern implementation\\n\\n**Actions:** useTools() and matchPatterns() with codebase_search, read complete files (with imports), trace flows\\n\\n**Output (400 words):**\\n- Module responsibilities\\n- Patterns to match\\n- Integration points\\n\\nupdateDecisionLog() with core logic files",
|
|
174
|
+
"agentRole": "You are conducting focused analysis step 2 of 4. Your expertise lies in identifying and analyzing task-specific components. Use tools extensively and never make assumptions.",
|
|
175
|
+
"guidance": [
|
|
176
|
+
"This is step 2 of a 4-step analysis process",
|
|
177
|
+
"Each step builds on the previous findings",
|
|
178
|
+
"Use tools liberally - verify everything",
|
|
179
|
+
"Update the Decision Log with key discoveries",
|
|
180
|
+
"Respect word limits to prevent context bloat",
|
|
181
|
+
"Note alignment/conflicts with user rules"
|
|
182
|
+
],
|
|
183
|
+
"runCondition": {"var": "analysisStep", "equals": 2},
|
|
184
|
+
"requireConfirmation": false
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"id": "phase-1-step-dependencies",
|
|
188
|
+
"title": "Analysis Step 3/4: Dependencies",
|
|
189
|
+
"prompt": "**STEP 3: DEPENDENCIES & FLOWS**\\n\\nTrace dependencies and execution:\\n\\n1. Import mapping\\n2. Data flow tracing\\n3. Integration points\\n4. Side effects\\n5. Testing patterns\\n\\n**Actions:** useTools() to follow imports, find test files, trace error handling\\n\\n**Output (400 words):**\\n- Dependency map\\n- Integration challenges\\n- Testing strategies\\n- Risk indicators\\n\\nupdateDecisionLog() with dependencies and test approaches",
|
|
190
|
+
"agentRole": "You are conducting focused analysis step 3 of 4. Your expertise lies in tracing dependencies and system flows. Use tools extensively and never make assumptions.",
|
|
191
|
+
"guidance": [
|
|
192
|
+
"This is step 3 of a 4-step analysis process",
|
|
193
|
+
"Each step builds on the previous findings",
|
|
194
|
+
"Use tools liberally - verify everything",
|
|
195
|
+
"Update the Decision Log with key discoveries",
|
|
196
|
+
"Respect word limits to prevent context bloat",
|
|
197
|
+
"Note alignment/conflicts with user rules"
|
|
198
|
+
],
|
|
199
|
+
"runCondition": {"var": "analysisStep", "equals": 3},
|
|
200
|
+
"requireConfirmation": false
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"id": "phase-1-step-patterns",
|
|
204
|
+
"title": "Analysis Step 4/4: Patterns",
|
|
205
|
+
"prompt": "**STEP 4: PATTERN DISCOVERY**\\n\\nIdentify established patterns relevant to the task type. Analyze if this is a pattern-heavy task (tests, telemetry, logging, APIs, UI components).\\n\\n**Actions:** useTools() extensively - codebase_search for concepts, grep_search for pattern markers, read_file for full examples\\n\\n**Output (400 words):**\\n- Pattern types discovered\\n- Reference implementations (with file paths)\\n- Key conventions to follow\\n- Pattern alignment recommendations\\n\\nupdateDecisionLog() with pattern templates and reference files",
|
|
206
|
+
"agentRole": "You are conducting focused analysis step 4 of 4. Your expertise lies in discovering and documenting established implementation patterns for the specific task type. Use tools extensively and never make assumptions.",
|
|
207
|
+
"guidance": [
|
|
208
|
+
"This is step 4 of a 4-step analysis process",
|
|
161
209
|
"Each step builds on the previous findings",
|
|
162
210
|
"Use tools liberally - verify everything",
|
|
163
211
|
"Update the Decision Log with key discoveries",
|
|
164
212
|
"Respect word limits to prevent context bloat",
|
|
165
213
|
"Note alignment/conflicts with user rules",
|
|
166
|
-
"
|
|
167
|
-
"
|
|
168
|
-
"
|
|
169
|
-
"
|
|
170
|
-
"
|
|
214
|
+
"TASK TYPE ANALYSIS: Determine if this is adding tests (find test utilities, mocking patterns), telemetry/analytics (find tracking implementations, event schemas), logging/monitoring (find log formats, monitoring integrations), API endpoints (find route patterns, validation, error handling), UI components (find component patterns, styling conventions), or other pattern-heavy work",
|
|
215
|
+
"PATTERN SEARCH STRATEGY: Use codebase_search with queries like 'How is [telemetry|testing|logging|API] implemented?'. Use grep_search for pattern markers (e.g., track, analytics, test, describe, log). Find 3-5 reference implementations similar to your task. Look for shared utilities, helpers, or base classes. Check for pattern documentation in README or docs",
|
|
216
|
+
"PATTERN EXTRACTION: Document file structure and naming conventions, common imports and dependencies, implementation approach (functional vs class-based), error handling patterns, configuration patterns, and testing approach for this type of feature",
|
|
217
|
+
"PATTERN VALIDATION: List discovered patterns with file references. Note any conflicting patterns or multiple approaches. Ask user: 'Found these pattern examples: [list files]. Should I follow these patterns, or are there other preferred examples?' Set establishedPatterns context variable",
|
|
218
|
+
"FOCUS ON REUSABILITY: Patterns help avoid reinventing the wheel. Look especially for utility functions, base classes, shared components, or established conventions that should be followed"
|
|
171
219
|
],
|
|
220
|
+
"runCondition": {"var": "analysisStep", "equals": 4},
|
|
172
221
|
"requireConfirmation": false
|
|
173
222
|
}
|
|
174
223
|
],
|
|
@@ -209,21 +209,67 @@
|
|
|
209
209
|
},
|
|
210
210
|
"body": [
|
|
211
211
|
{
|
|
212
|
-
"id": "analysis-
|
|
213
|
-
"title": "Analysis
|
|
214
|
-
"prompt": "
|
|
215
|
-
"agentRole": "You are performing systematic analysis phase
|
|
212
|
+
"id": "analysis-breadth-scan",
|
|
213
|
+
"title": "Analysis 1/4: Breadth Scan",
|
|
214
|
+
"prompt": "**BREADTH SCAN**\n\n1. **Error Mapping**: grep_search errors, trace logs, map stack traces\n2. **Component Discovery**: Find all interacting components using codebase_search\n3. **Data Flow**: Trace data through bug area, transformations, persistence\n4. **Recent Changes**: Git history last 10 commits\n\n**Output**: BreadthAnalysis.md with interaction map",
|
|
215
|
+
"agentRole": "You are performing systematic analysis phase 1 of 4. Your focus is casting a wide net to find all potentially related components.",
|
|
216
216
|
"guidance": [
|
|
217
|
-
"This is analysis phase
|
|
218
|
-
"Phase 1 = Breadth Scan
|
|
219
|
-
"
|
|
220
|
-
"
|
|
217
|
+
"This is analysis phase 1 of 4 total phases",
|
|
218
|
+
"Phase 1 = Breadth Scan - Cast wide net for all related components",
|
|
219
|
+
"Create BreadthAnalysis.md with structured findings",
|
|
220
|
+
"Use findSimilarBugs() to search for historical patterns",
|
|
221
221
|
"Use the function definitions for standardized operations",
|
|
222
|
-
"
|
|
223
|
-
"Update INVESTIGATION_CONTEXT.md after each phase: use updateInvestigationContext('Analysis Findings', phase-specific findings)",
|
|
224
|
-
"In Phase 1 (Breadth Scan): Use findSimilarBugs() to search for historical patterns",
|
|
225
|
-
"After all 4 phases complete, use trackInvestigation('Phase 1 Complete', 'Moving to Hypothesis Development')"
|
|
222
|
+
"Update INVESTIGATION_CONTEXT.md after completion"
|
|
226
223
|
],
|
|
224
|
+
"runCondition": {"var": "analysisPhase", "equals": 1},
|
|
225
|
+
"requireConfirmation": false
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
"id": "analysis-deep-dive",
|
|
229
|
+
"title": "Analysis 2/4: Component Deep Dive",
|
|
230
|
+
"prompt": "**COMPONENT DEEP DIVE**\n\nUse recursiveAnalysis(component, 3) on top 5 suspicious components:\n\n1. **L1 Direct**: Read complete file, state management, error handling\n2. **L2 Dependencies**: Follow imports, contracts, version compatibility\n3. **L3 Integration**: System fit, side effects, concurrency, resources\n\n**Output**: ComponentAnalysis.md with deep insights",
|
|
231
|
+
"agentRole": "You are performing systematic analysis phase 2 of 4. Your focus is deep diving into the most suspicious components to understand their internals.",
|
|
232
|
+
"guidance": [
|
|
233
|
+
"This is analysis phase 2 of 4 total phases",
|
|
234
|
+
"Phase 2 = Deep Dive - Analyze suspicious components 3 levels deep",
|
|
235
|
+
"Build on findings from Phase 1 Breadth Scan",
|
|
236
|
+
"Create ComponentAnalysis.md with structured findings",
|
|
237
|
+
"Use recursiveAnalysis() for systematic exploration",
|
|
238
|
+
"Update INVESTIGATION_CONTEXT.md after completion"
|
|
239
|
+
],
|
|
240
|
+
"runCondition": {"var": "analysisPhase", "equals": 2},
|
|
241
|
+
"requireConfirmation": false
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
"id": "analysis-dependencies",
|
|
245
|
+
"title": "Analysis 3/4: Dependencies & Flow",
|
|
246
|
+
"prompt": "**DEPENDENCY & FLOW ANALYSIS**\n\n1. **Static Graph**: Import tree, circular deps, hidden dependencies\n2. **Runtime Flow**: Execution paths, async flows, state changes\n3. **Data Pipeline**: Track transformations, validation, corruption points\n4. **Integration**: External services, DB, queues, filesystem\n\n**Output**: FlowAnalysis.md with diagrams",
|
|
247
|
+
"agentRole": "You are performing systematic analysis phase 3 of 4. Your focus is tracing how components connect and data flows between them.",
|
|
248
|
+
"guidance": [
|
|
249
|
+
"This is analysis phase 3 of 4 total phases",
|
|
250
|
+
"Phase 3 = Dependencies - Trace connections and data flows",
|
|
251
|
+
"Build on component understanding from Phase 2",
|
|
252
|
+
"Create FlowAnalysis.md with diagrams and flow charts",
|
|
253
|
+
"Focus on runtime behavior and integration points",
|
|
254
|
+
"Update INVESTIGATION_CONTEXT.md after completion"
|
|
255
|
+
],
|
|
256
|
+
"runCondition": {"var": "analysisPhase", "equals": 3},
|
|
257
|
+
"requireConfirmation": false
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
"id": "analysis-test-coverage",
|
|
261
|
+
"title": "Analysis 4/4: Test Coverage",
|
|
262
|
+
"prompt": "**TEST COVERAGE ANALYSIS**\n\nUse analyzeTests(component) for each suspicious component:\n\n1. **Direct Coverage**: Find tests, analyze coverage gaps, quality\n2. **Integration Tests**: Bug area tests, assumptions, flaky tests\n3. **History**: When added/modified, correlation with bug\n4. **Debug Execution**: Run with debug flags, instrument, compare\n\n**Output**: TestAnalysis.md with coverage gaps matrix",
|
|
263
|
+
"agentRole": "You are performing systematic analysis phase 4 of 4. Your focus is leveraging existing tests to understand expected behavior and find coverage gaps.",
|
|
264
|
+
"guidance": [
|
|
265
|
+
"This is analysis phase 4 of 4 total phases",
|
|
266
|
+
"Phase 4 = Tests - Analyze test coverage and quality",
|
|
267
|
+
"Build on all previous analysis phases",
|
|
268
|
+
"Create TestAnalysis.md with coverage gap matrix",
|
|
269
|
+
"Run tests with debug flags for additional insights",
|
|
270
|
+
"After completion, use trackInvestigation('Phase 1 Complete', 'Moving to Hypothesis Development')"
|
|
271
|
+
],
|
|
272
|
+
"runCondition": {"var": "analysisPhase", "equals": 4},
|
|
227
273
|
"requireConfirmation": false
|
|
228
274
|
}
|
|
229
275
|
],
|
|
@@ -415,7 +461,7 @@
|
|
|
415
461
|
"prompt": "**DEBUGGING INSTRUMENTATION for {{currentHypothesis.id}}**\n\n**Hypothesis**: {{currentHypothesis.description}}\n\n**IMPLEMENT SMART LOGGING**:\n\n1. **Standard Format**: Use instrumentCode(location, '{{currentHypothesis.id}}')\n ```\n className.methodName [{{currentHypothesis.id}}] {timestamp}: Specific message\n ```\n\n2. **Deduplication Implementation**:\n ```javascript\n // Add to each instrumentation point\n const debugState = { lastMsg: '', count: 0 };\n function smartLog(msg) {\n if (debugState.lastMsg === msg) {\n debugState.count++;\n if (debugState.count % 10 === 0) {\n console.log(`[{{currentHypothesis.id}}] ${msg} x${debugState.count}`);\n }\n } else {\n if (debugState.count > 1) {\n console.log(`[{{currentHypothesis.id}}] Previous message x${debugState.count}`);\n }\n console.log(`[{{currentHypothesis.id}}] ${msg}`);\n debugState.lastMsg = msg;\n debugState.count = 1;\n }\n }\n ```\n\n3. **Operation Grouping**:\n ```javascript\n console.log(`=== {{currentHypothesis.id}}: Operation ${opName} Start ===`);\n const startTime = Date.now();\n // ... operation code with smartLog() calls ...\n console.log(`=== {{currentHypothesis.id}}: Operation ${opName} End (${Date.now() - startTime}ms) ===`);\n ```\n\n4. **Test Instrumentation**:\n - Add debugging to relevant test files\n - Instrument test setup/teardown\n - Log test assumptions vs actual behavior\n\n5. **High-Frequency Aggregation**:\n - For loops/iterations, log summary every 100 iterations\n - For events, create time-window summaries\n - Track unique values and their counts\n\n**OUTPUT**: Instrumented code ready to produce clean, manageable logs for {{currentHypothesis.id}}",
|
|
416
462
|
"agentRole": "You are instrumenting code specifically to validate hypothesis {{currentHypothesis.id}}. Focus on targeted evidence collection.",
|
|
417
463
|
"guidance": [
|
|
418
|
-
"This is hypothesis {{hypothesisIndex + 1}} of
|
|
464
|
+
"This is hypothesis {{hypothesisIndex + 1}} of 3",
|
|
419
465
|
"Tailor instrumentation to the specific hypothesis",
|
|
420
466
|
"Ensure non-intrusive implementation"
|
|
421
467
|
],
|
|
@@ -436,7 +482,7 @@
|
|
|
436
482
|
{
|
|
437
483
|
"id": "loop-phase-5-synthesis",
|
|
438
484
|
"title": "Phase 5: Evidence Synthesis for {{currentHypothesis.id}}",
|
|
439
|
-
"prompt": "**EVIDENCE SYNTHESIS for {{currentHypothesis.id}}**\n\n**Synthesize findings:**\n1. **Evidence Summary**: What did we learn about {{currentHypothesis.id}}?\n2. **Confidence Update**: Based on evidence, rate confidence this is the root cause (0-10)\n3. **Status Update**: Mark hypothesis as Confirmed/Refuted/Needs-More-Evidence\n\n**If {{currentHypothesis.id}} is confirmed with high confidence (>8.0):**\n- Set `rootCauseFound` = true\n- Set `rootCauseHypothesis` = {{currentHypothesis.id}}\n- Update `currentConfidence` with confidence score\n\n**If all hypotheses validated but confidence <9.0:**\n- Consider additional investigation needs\n- Document what evidence is still missing\n\n**Context Update**:\n- Use updateInvestigationContext('Evidence Log', evidence summary for {{currentHypothesis.id}})\n- Every 3 iterations: Use trackInvestigation('Validation Progress', '{{hypothesisIndex + 1}}/
|
|
485
|
+
"prompt": "**EVIDENCE SYNTHESIS for {{currentHypothesis.id}}**\n\n**Synthesize findings:**\n1. **Evidence Summary**: What did we learn about {{currentHypothesis.id}}?\n2. **Confidence Update**: Based on evidence, rate confidence this is the root cause (0-10)\n3. **Status Update**: Mark hypothesis as Confirmed/Refuted/Needs-More-Evidence\n\n**If {{currentHypothesis.id}} is confirmed with high confidence (>8.0):**\n- Set `rootCauseFound` = true\n- Set `rootCauseHypothesis` = {{currentHypothesis.id}}\n- Update `currentConfidence` with confidence score\n\n**If all hypotheses validated but confidence <9.0:**\n- Consider additional investigation needs\n- Document what evidence is still missing\n\n**Context Update**:\n- Use updateInvestigationContext('Evidence Log', evidence summary for {{currentHypothesis.id}})\n- Every 3 iterations: Use trackInvestigation('Validation Progress', '{{hypothesisIndex + 1}}/3 hypotheses validated')",
|
|
440
486
|
"agentRole": "You are synthesizing evidence to determine if {{currentHypothesis.id}} is the root cause.",
|
|
441
487
|
"guidance": [
|
|
442
488
|
"Update hypothesis status based on evidence",
|
|
@@ -461,7 +507,7 @@
|
|
|
461
507
|
"var": "currentConfidence",
|
|
462
508
|
"lt": 8.0
|
|
463
509
|
},
|
|
464
|
-
"prompt": "**CONTROLLED EXPERIMENTATION** - When observation isn't enough, experiment!\n\n**Current
|
|
510
|
+
"prompt": "**CONTROLLED EXPERIMENTATION** - When observation isn't enough, experiment!\n\n**Current Investigation Status**: Leading hypothesis (Confidence: {{currentConfidence}}/10)\n\n**EXPERIMENT TYPES** (use controlledModification()):\n\n1. **Guard Additions (Non-Breaking)**:\n ```javascript\n // Add defensive check that logs but doesn't change behavior\n if (unexpectedCondition) {\n console.error('[H1_GUARD] Unexpected state detected:', state);\n // Continue normal execution\n }\n ```\n\n2. **Assertion Injections**:\n ```javascript\n // Add assertion that would fail if hypothesis is correct\n console.assert(expectedCondition, '[H1_ASSERT] Hypothesis H1 violated!');\n ```\n\n3. **Minimal Fix Test**:\n ```javascript\n // Apply minimal fix for hypothesis, see if bug disappears\n if (process.env.DEBUG_FIX_H1 === 'true') {\n // Apply hypothesized fix\n return fixedBehavior();\n }\n ```\n\n4. **Controlled Breaking**:\n ```javascript\n // Temporarily break suspected component to verify involvement\n if (process.env.DEBUG_BREAK_H1 === 'true') {\n throw new Error('[H1_BREAK] Intentionally breaking to test hypothesis');\n }\n ```\n\n**PROTOCOL**:\n1. Choose experiment type based on confidence and risk\n2. Implement modification with clear DEBUG markers\n3. Use createInvestigationBranch() if not already on investigation branch\n4. Commit: `git commit -m \"DEBUG: {{experiment_type}} for hypothesis investigation\"`\n5. Run reproduction steps\n6. Use collectEvidence() to gather results\n7. Revert changes: `git revert HEAD`\n8. Document results in ExperimentResults/hypothesis-experiment.md\n\n**SAFETY LIMITS**:\n- Max 3 experiments per hypothesis\n- Each experiment in separate commit\n- Always revert after evidence collection\n- Document everything in INVESTIGATION_CONTEXT.md\n\n**UPDATE**:\n- Hypothesis confidence based on experimental results\n- Use updateInvestigationContext('Experiment Results', experiment details and outcomes)\n- Track failed experiments in 'Dead Ends & Lessons' section",
|
|
465
511
|
"agentRole": "You are a careful experimenter using controlled code modifications to validate hypotheses. Safety and reversibility are paramount.",
|
|
466
512
|
"guidance": [
|
|
467
513
|
"Start with non-breaking experiments (guards, logs)",
|