universal-dev-standards 6.15.0 → 6.16.0-beta.2

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.
Files changed (41) hide show
  1. package/bin/uds.js +2 -0
  2. package/bundled/locales/zh-CN/CHANGELOG.md +34 -4
  3. package/bundled/locales/zh-CN/CLAUDE.md +2 -2
  4. package/bundled/locales/zh-CN/README.md +17 -14
  5. package/bundled/locales/zh-CN/SECURITY.md +1 -0
  6. package/bundled/locales/zh-CN/docs/CHEATSHEET.md +1 -1
  7. package/bundled/locales/zh-CN/docs/CLI-INIT-OPTIONS.md +24 -2
  8. package/bundled/locales/zh-CN/docs/FEATURE-REFERENCE.md +3 -1
  9. package/bundled/locales/zh-TW/CHANGELOG.md +34 -4
  10. package/bundled/locales/zh-TW/CLAUDE.md +2 -2
  11. package/bundled/locales/zh-TW/README.md +17 -14
  12. package/bundled/locales/zh-TW/SECURITY.md +1 -0
  13. package/bundled/locales/zh-TW/docs/CHEATSHEET.md +1 -1
  14. package/bundled/locales/zh-TW/docs/CLI-INIT-OPTIONS.md +24 -2
  15. package/bundled/locales/zh-TW/docs/FEATURE-REFERENCE.md +3 -1
  16. package/package.json +3 -3
  17. package/src/commands/skills.js +9 -0
  18. package/src/commands/update.js +223 -2
  19. package/src/reconciler/desired-state-calculator.js +11 -2
  20. package/src/utils/optional-skills-report.js +86 -0
  21. package/src/utils/optional-skills.js +20 -0
  22. package/src/utils/skill-selection.js +137 -0
  23. package/src/utils/skills-installer.js +11 -4
  24. package/standards-registry.json +7 -7
  25. package/src/core/agent-communication-protocol.js +0 -257
  26. package/src/flow/condition-evaluator.js +0 -86
  27. package/src/flow/flow-bundler.js +0 -80
  28. package/src/flow/flow-commands.js +0 -107
  29. package/src/flow/flow-engine.js +0 -154
  30. package/src/flow/flow-inheritance.js +0 -100
  31. package/src/flow/flow-parser.js +0 -104
  32. package/src/flow/flow-validator.js +0 -37
  33. package/src/flow/gate-checker.js +0 -82
  34. package/src/flow/gate-loader.js +0 -52
  35. package/src/missions/MissionManager.js +0 -533
  36. package/src/utils/e2e-analyzer.js +0 -471
  37. package/src/utils/e2e-detector.js +0 -132
  38. package/src/utils/hook-stats.js +0 -151
  39. package/src/utils/workflow-executor.js +0 -870
  40. package/src/utils/workflows-installer.js +0 -545
  41. package/src/vibe/auto-sweep.js +0 -349
@@ -1,870 +0,0 @@
1
- /**
2
- * Workflow Executor
3
- *
4
- * Core execution engine for UDS workflows.
5
- * Handles step execution, context passing, and progress tracking.
6
- *
7
- * @version 1.0.0
8
- */
9
-
10
- import chalk from 'chalk';
11
- import { select, confirm, input } from '@inquirer/prompts';
12
- import { WorkflowStateManager, StepStatus, WorkflowStatus } from './workflow-state.js';
13
- import {
14
- getWorkflowContent,
15
- parseWorkflow,
16
- validateWorkflow
17
- } from './workflows-installer.js';
18
- import {
19
- getExecutionMode,
20
- adaptAgentForTool,
21
- ExecutionMode
22
- } from './agent-adapter.js';
23
- import { supportsTask, getAgentConfig } from '../config/ai-agent-paths.js';
24
-
25
- /**
26
- * Error recovery action enumeration
27
- */
28
- export const RecoveryAction = {
29
- RETRY: 'retry',
30
- SKIP: 'skip',
31
- PAUSE: 'pause',
32
- ABORT: 'abort'
33
- };
34
-
35
- /**
36
- * WorkflowExecutor
37
- *
38
- * Executes workflow definitions step by step.
39
- */
40
- export class WorkflowExecutor {
41
- /**
42
- * Create a WorkflowExecutor instance
43
- * @param {Object} options - Executor options
44
- * @param {string} options.aiTool - Target AI tool (default: 'claude-code')
45
- * @param {string} options.projectPath - Project root path
46
- * @param {boolean} options.verbose - Enable verbose output
47
- * @param {boolean} options.dryRun - Show steps without executing
48
- * @param {boolean} options.interactive - Enable interactive prompts (default: true)
49
- */
50
- constructor(options = {}) {
51
- this.aiTool = options.aiTool || 'claude-code';
52
- this.projectPath = options.projectPath || process.cwd();
53
- this.verbose = options.verbose || false;
54
- this.dryRun = options.dryRun || false;
55
- this.interactive = options.interactive !== false;
56
- this.stateManager = null;
57
- this.workflow = null;
58
- this.stepOrder = [];
59
- }
60
-
61
- /**
62
- * Execute a workflow by name
63
- * @param {string} workflowName - Name of the workflow to execute
64
- * @param {Object} options - Execution options
65
- * @param {Object} options.initialContext - Initial context values
66
- * @param {boolean} options.restart - Force restart from beginning
67
- * @returns {Object} Execution result
68
- */
69
- async execute(workflowName, options = {}) {
70
- // Load workflow definition
71
- const content = getWorkflowContent(workflowName);
72
- if (!content) {
73
- return {
74
- success: false,
75
- error: `Workflow not found: ${workflowName}`,
76
- workflowName
77
- };
78
- }
79
-
80
- this.workflow = parseWorkflow(content);
81
-
82
- // Validate workflow
83
- const validation = validateWorkflow(this.workflow);
84
- if (!validation.valid) {
85
- return {
86
- success: false,
87
- error: `Invalid workflow: ${validation.errors.join(', ')}`,
88
- workflowName,
89
- validationErrors: validation.errors
90
- };
91
- }
92
-
93
- // Build step order
94
- this.stepOrder = this.workflow.steps.map(step => step.id);
95
-
96
- // Initialize or load state
97
- this.stateManager = new WorkflowStateManager(workflowName, this.projectPath);
98
-
99
- const existingState = this.stateManager.load();
100
-
101
- if (existingState && !options.restart) {
102
- // Check if can resume
103
- if (this.stateManager.canResume()) {
104
- if (this.interactive) {
105
- const action = await select({
106
- message: 'Previous execution found. What would you like to do?',
107
- choices: [
108
- { name: 'Resume from where it stopped', value: 'resume' },
109
- { name: 'Start fresh (discard previous state)', value: 'restart' }
110
- ]
111
- });
112
-
113
- if (action === 'restart') {
114
- this.stateManager.clear();
115
- this.stateManager.initialize(this.workflow);
116
- }
117
- }
118
- } else {
119
- // Previous state exists but completed or failed - ask to restart
120
- this.stateManager.clear();
121
- this.stateManager.initialize(this.workflow);
122
- }
123
- } else {
124
- this.stateManager.initialize(this.workflow);
125
- }
126
-
127
- // Display workflow info
128
- this.displayWorkflowHeader();
129
-
130
- // Check dry-run mode - don't persist state for dry-run
131
- if (this.dryRun) {
132
- return this.displayDryRunPlan();
133
- }
134
-
135
- // Set metadata (only when actually executing)
136
- this.stateManager.setMetadata('aiTool', this.aiTool);
137
-
138
- // Apply initial context if provided
139
- if (options.initialContext) {
140
- for (const [key, value] of Object.entries(options.initialContext)) {
141
- this.stateManager.setContext(key, value);
142
- }
143
- this.stateManager.save();
144
- }
145
-
146
- // Execute steps
147
- return await this.executeSteps();
148
- }
149
-
150
- /**
151
- * Resume a paused workflow
152
- * @param {string} workflowName - Name of the workflow to resume
153
- * @returns {Object} Execution result
154
- */
155
- async resume(workflowName) {
156
- // Load workflow definition
157
- const content = getWorkflowContent(workflowName);
158
- if (!content) {
159
- return {
160
- success: false,
161
- error: `Workflow not found: ${workflowName}`,
162
- workflowName
163
- };
164
- }
165
-
166
- this.workflow = parseWorkflow(content);
167
- this.stepOrder = this.workflow.steps.map(step => step.id);
168
-
169
- // Load existing state
170
- this.stateManager = new WorkflowStateManager(workflowName, this.projectPath);
171
- const existingState = this.stateManager.load();
172
-
173
- if (!existingState) {
174
- return {
175
- success: false,
176
- error: 'No saved state found for this workflow',
177
- workflowName
178
- };
179
- }
180
-
181
- if (!this.stateManager.canResume()) {
182
- return {
183
- success: false,
184
- error: 'Workflow cannot be resumed (already completed or not started)',
185
- workflowName,
186
- status: existingState.status
187
- };
188
- }
189
-
190
- console.log();
191
- console.log(chalk.cyan(`Resuming workflow: ${workflowName}`));
192
-
193
- const summary = this.stateManager.getSummary();
194
- console.log(chalk.gray(`Progress: ${summary.progress.completed}/${summary.progress.total} steps completed`));
195
- console.log();
196
-
197
- return await this.executeSteps();
198
- }
199
-
200
- /**
201
- * Execute remaining steps
202
- * @returns {Object} Execution result
203
- */
204
- async executeSteps() {
205
- this.stateManager.setWorkflowStatus(WorkflowStatus.IN_PROGRESS);
206
-
207
- for (const stepId of this.stepOrder) {
208
- const stepStatus = this.stateManager.getStepStatus(stepId);
209
-
210
- // Skip completed or skipped steps
211
- if (stepStatus === StepStatus.COMPLETED || stepStatus === StepStatus.SKIPPED) {
212
- if (this.verbose) {
213
- console.log(chalk.gray(` Skipping step ${stepId} (${stepStatus})`));
214
- }
215
- continue;
216
- }
217
-
218
- // Find step definition
219
- const step = this.workflow.steps.find(s => s.id === stepId);
220
- if (!step) {
221
- console.log(chalk.red(` Step definition not found: ${stepId}`));
222
- continue;
223
- }
224
-
225
- // Execute the step
226
- const result = await this.executeStep(step);
227
-
228
- if (!result.success) {
229
- // Handle step failure
230
- const action = await this.handleStepFailure(step, result);
231
-
232
- switch (action) {
233
- case RecoveryAction.RETRY: {
234
- // Re-execute the step
235
- const retryResult = await this.executeStep(step);
236
- if (!retryResult.success) {
237
- this.stateManager.setStepStatus(stepId, StepStatus.FAILED, null, retryResult.error);
238
- this.stateManager.setWorkflowStatus(WorkflowStatus.FAILED);
239
- return {
240
- success: false,
241
- error: `Step ${stepId} failed after retry: ${retryResult.error}`,
242
- workflowName: this.workflow.name,
243
- failedStep: stepId
244
- };
245
- }
246
- break;
247
- }
248
-
249
- case RecoveryAction.SKIP:
250
- this.stateManager.setStepStatus(stepId, StepStatus.SKIPPED);
251
- console.log(chalk.yellow(` Skipped step: ${step.name}`));
252
- continue;
253
-
254
- case RecoveryAction.PAUSE:
255
- this.stateManager.setWorkflowStatus(WorkflowStatus.PAUSED);
256
- return {
257
- success: false,
258
- paused: true,
259
- error: `Workflow paused at step: ${stepId}`,
260
- workflowName: this.workflow.name,
261
- pausedAt: stepId
262
- };
263
-
264
- case RecoveryAction.ABORT:
265
- default:
266
- this.stateManager.setStepStatus(stepId, StepStatus.FAILED, null, result.error);
267
- this.stateManager.setWorkflowStatus(WorkflowStatus.FAILED);
268
- return {
269
- success: false,
270
- error: `Workflow aborted at step ${stepId}: ${result.error}`,
271
- workflowName: this.workflow.name,
272
- failedStep: stepId
273
- };
274
- }
275
- }
276
- }
277
-
278
- // All steps completed
279
- this.stateManager.setWorkflowStatus(WorkflowStatus.COMPLETED);
280
-
281
- const summary = this.stateManager.getSummary();
282
- this.displayCompletionSummary(summary);
283
-
284
- // Clear state file on successful completion
285
- this.stateManager.clear();
286
-
287
- return {
288
- success: true,
289
- workflowName: this.workflow.name,
290
- summary
291
- };
292
- }
293
-
294
- /**
295
- * Execute a single step
296
- * @param {Object} step - Step definition
297
- * @returns {Object} Step execution result
298
- */
299
- async executeStep(step) {
300
- const context = this.stateManager.getContext();
301
-
302
- this.displayStepHeader(step);
303
- this.stateManager.setStepStatus(step.id, StepStatus.IN_PROGRESS);
304
-
305
- try {
306
- let result;
307
-
308
- switch (step.type) {
309
- case 'agent':
310
- result = await this.executeAgentStep(step, context);
311
- break;
312
- case 'manual':
313
- result = await this.executeManualStep(step, context);
314
- break;
315
- case 'conditional':
316
- result = await this.executeConditionalStep(step, context);
317
- break;
318
- default:
319
- result = {
320
- success: false,
321
- error: `Unknown step type: ${step.type}`
322
- };
323
- }
324
-
325
- if (result.success) {
326
- this.stateManager.setStepStatus(step.id, StepStatus.COMPLETED, result.outputs);
327
- this.displayStepSuccess(step);
328
- }
329
-
330
- return result;
331
- } catch (error) {
332
- return {
333
- success: false,
334
- error: error.message || String(error)
335
- };
336
- }
337
- }
338
-
339
- /**
340
- * Execute an agent step
341
- * @param {Object} step - Step definition
342
- * @param {Object} context - Current execution context
343
- * @returns {Object} Execution result
344
- */
345
- async executeAgentStep(step, context) {
346
- const executionMode = getExecutionMode(this.aiTool);
347
-
348
- console.log(chalk.gray(` Agent: ${step.agent}`));
349
- console.log(chalk.gray(` Execution mode: ${executionMode}`));
350
-
351
- // Resolve inputs from context
352
- const inputs = this.resolveInputs(step.inputs, context);
353
-
354
- if (this.verbose && Object.keys(inputs).length > 0) {
355
- console.log(chalk.gray(` Inputs: ${Object.keys(inputs).join(', ')}`));
356
- }
357
-
358
- switch (executionMode) {
359
- case ExecutionMode.TASK:
360
- return await this.executeAgentWithTask(step, inputs, context);
361
-
362
- case ExecutionMode.INLINE:
363
- return await this.executeAgentInline(step, inputs, context);
364
-
365
- case ExecutionMode.MANUAL:
366
- default:
367
- return await this.executeAgentManual(step, inputs, context);
368
- }
369
- }
370
-
371
- /**
372
- * Execute agent step using Task tool (Claude Code, OpenCode)
373
- * @param {Object} step - Step definition
374
- * @param {Object} inputs - Resolved inputs
375
- * @param {Object} context - Current context
376
- * @returns {Object} Execution result
377
- */
378
- async executeAgentWithTask(step, _inputs, _context) {
379
- // Build agent configuration for Task tool
380
- const agentConfig = {
381
- name: step.agent,
382
- description: step.description,
383
- role: 'workflow-step'
384
- };
385
-
386
- const adapted = adaptAgentForTool(agentConfig, this.aiTool);
387
-
388
- // For Task mode, we provide instructions for the AI to spawn a subagent
389
- console.log();
390
- console.log(chalk.cyan(' 📋 Agent Task Instructions:'));
391
- console.log(chalk.gray(' ─'.repeat(25)));
392
- console.log();
393
- console.log(chalk.white(` Use the Task tool to spawn a ${step.agent} agent:`));
394
- console.log();
395
- console.log(chalk.yellow(` subagent_type: "${adapted.taskConfig.subagent_type}"`));
396
- console.log(chalk.yellow(` description: "${adapted.taskConfig.description}"`));
397
- console.log();
398
-
399
- if (step.description) {
400
- console.log(chalk.white(' Step description:'));
401
- const descLines = step.description.trim().split('\n');
402
- for (const line of descLines) {
403
- console.log(chalk.gray(` ${line.trim()}`));
404
- }
405
- console.log();
406
- }
407
-
408
- // Show expected outputs
409
- if (step.outputs && step.outputs.length > 0) {
410
- console.log(chalk.white(' Expected outputs:'));
411
- for (const output of step.outputs) {
412
- console.log(chalk.gray(` - ${output}`));
413
- }
414
- console.log();
415
- }
416
-
417
- // Interactive confirmation
418
- if (this.interactive) {
419
- const { completed, outputs } = await this.promptAgentCompletion(step);
420
- return {
421
- success: completed,
422
- outputs: outputs || {},
423
- mode: ExecutionMode.TASK
424
- };
425
- }
426
-
427
- return { success: true, outputs: {}, mode: ExecutionMode.TASK };
428
- }
429
-
430
- /**
431
- * Execute agent step in inline mode (Cursor, etc.)
432
- * @param {Object} step - Step definition
433
- * @param {Object} inputs - Resolved inputs
434
- * @param {Object} context - Current context
435
- * @returns {Object} Execution result
436
- */
437
- async executeAgentInline(step, _inputs, _context) {
438
- const agentConfig = {
439
- name: step.agent,
440
- description: step.description,
441
- role: 'workflow-step'
442
- };
443
-
444
- const adapted = adaptAgentForTool(agentConfig, this.aiTool);
445
-
446
- console.log();
447
- console.log(chalk.cyan(' 📋 Agent Context (copy to AI):'));
448
- console.log(chalk.gray(' ─'.repeat(25)));
449
- console.log();
450
- console.log(adapted.contextPrefix);
451
-
452
- if (step.description) {
453
- console.log(chalk.white(' Task:'));
454
- const descLines = step.description.trim().split('\n');
455
- for (const line of descLines) {
456
- console.log(chalk.gray(` ${line.trim()}`));
457
- }
458
- console.log();
459
- }
460
-
461
- if (this.interactive) {
462
- const { completed, outputs } = await this.promptAgentCompletion(step);
463
- return {
464
- success: completed,
465
- outputs: outputs || {},
466
- mode: ExecutionMode.INLINE
467
- };
468
- }
469
-
470
- return { success: true, outputs: {}, mode: ExecutionMode.INLINE };
471
- }
472
-
473
- /**
474
- * Execute agent step in manual mode
475
- * @param {Object} step - Step definition
476
- * @param {Object} inputs - Resolved inputs
477
- * @param {Object} context - Current context
478
- * @returns {Object} Execution result
479
- */
480
- async executeAgentManual(step, _inputs, _context) {
481
- console.log();
482
- console.log(chalk.cyan(' 📋 Manual Agent Instructions:'));
483
- console.log(chalk.gray(' ─'.repeat(25)));
484
- console.log();
485
-
486
- console.log(chalk.white(` Agent: ${step.agent}`));
487
- console.log();
488
-
489
- if (step.description) {
490
- console.log(chalk.white(' Instructions:'));
491
- const descLines = step.description.trim().split('\n');
492
- for (const line of descLines) {
493
- console.log(chalk.gray(` ${line.trim()}`));
494
- }
495
- console.log();
496
- }
497
-
498
- if (step.checklist && step.checklist.length > 0) {
499
- console.log(chalk.white(' Checklist:'));
500
- for (const item of step.checklist) {
501
- console.log(chalk.gray(` ☐ ${item}`));
502
- }
503
- console.log();
504
- }
505
-
506
- if (this.interactive) {
507
- const { completed, outputs } = await this.promptAgentCompletion(step);
508
- return {
509
- success: completed,
510
- outputs: outputs || {},
511
- mode: ExecutionMode.MANUAL
512
- };
513
- }
514
-
515
- return { success: true, outputs: {}, mode: ExecutionMode.MANUAL };
516
- }
517
-
518
- /**
519
- * Execute a manual step
520
- * @param {Object} step - Step definition
521
- * @param {Object} context - Current execution context
522
- * @returns {Object} Execution result
523
- */
524
- async executeManualStep(step, _context) {
525
- console.log();
526
-
527
- // Show instructions
528
- if (step.instructions) {
529
- console.log(chalk.white(' Instructions:'));
530
- const lines = step.instructions.trim().split('\n');
531
- for (const line of lines) {
532
- console.log(chalk.gray(` ${line.trim()}`));
533
- }
534
- console.log();
535
- }
536
-
537
- // Show checklist
538
- if (step.checklist && step.checklist.length > 0) {
539
- console.log(chalk.white(' Checklist:'));
540
- for (const item of step.checklist) {
541
- console.log(chalk.gray(` ☐ ${item}`));
542
- }
543
- console.log();
544
- }
545
-
546
- // Interactive confirmation
547
- if (this.interactive) {
548
- const stepConfirmed = await confirm({
549
- message: 'Have you completed this step?',
550
- default: true
551
- });
552
-
553
- if (!stepConfirmed) {
554
- const action = await select({
555
- message: 'What would you like to do?',
556
- choices: [
557
- { name: 'Mark as complete anyway', value: 'complete' },
558
- { name: 'Skip this step', value: 'skip' },
559
- { name: 'Pause workflow', value: 'pause' }
560
- ]
561
- });
562
-
563
- if (action === 'skip') {
564
- return { success: true, skipped: true, outputs: {} };
565
- } else if (action === 'pause') {
566
- return { success: false, error: 'User paused workflow' };
567
- }
568
- }
569
- }
570
-
571
- return { success: true, outputs: {} };
572
- }
573
-
574
- /**
575
- * Execute a conditional step
576
- * @param {Object} step - Step definition
577
- * @param {Object} context - Current execution context
578
- * @returns {Object} Execution result
579
- */
580
- async executeConditionalStep(step, context) {
581
- console.log();
582
- console.log(chalk.white(' Evaluating condition...'));
583
-
584
- // Simple condition evaluation based on context
585
- if (step.condition) {
586
- const conditionMet = this.evaluateCondition(step.condition, context);
587
-
588
- if (conditionMet) {
589
- console.log(chalk.green(` Condition met: ${step.condition}`));
590
- if (step.then_branch) {
591
- return { success: true, outputs: { next_branch: 'then' } };
592
- }
593
- } else {
594
- console.log(chalk.yellow(` Condition not met: ${step.condition}`));
595
- if (step.else_branch) {
596
- return { success: true, outputs: { next_branch: 'else' } };
597
- }
598
- }
599
- }
600
-
601
- // If interactive, ask user to choose
602
- if (this.interactive && step.decisions) {
603
- console.log(chalk.white(' Available decisions:'));
604
-
605
- const choices = Object.entries(step.decisions).map(([key, value]) => ({
606
- name: `${key}: ${value.condition || 'No condition'}`,
607
- value: key
608
- }));
609
-
610
- const decision = await select({
611
- message: 'Select decision:',
612
- choices
613
- });
614
-
615
- return { success: true, outputs: { decision } };
616
- }
617
-
618
- return { success: true, outputs: {} };
619
- }
620
-
621
- /**
622
- * Evaluate a condition expression
623
- * @param {string} condition - Condition string
624
- * @param {Object} context - Current context
625
- * @returns {boolean} Condition result
626
- */
627
- evaluateCondition(condition, context) {
628
- // Simple condition evaluation
629
- // Supports: "key exists", "key == value", "key != value"
630
-
631
- if (condition.includes(' exists')) {
632
- const key = condition.replace(' exists', '').trim();
633
- return context[key] !== undefined;
634
- }
635
-
636
- if (condition.includes('==')) {
637
- const [key, value] = condition.split('==').map(s => s.trim());
638
- return String(context[key]) === value;
639
- }
640
-
641
- if (condition.includes('!=')) {
642
- const [key, value] = condition.split('!=').map(s => s.trim());
643
- return String(context[key]) !== value;
644
- }
645
-
646
- // Check if key is truthy
647
- return Boolean(context[condition.trim()]);
648
- }
649
-
650
- /**
651
- * Resolve inputs from context
652
- * @param {Array} inputs - Input definitions
653
- * @param {Object} context - Current context
654
- * @returns {Object} Resolved inputs
655
- */
656
- resolveInputs(inputs, context) {
657
- if (!inputs || !Array.isArray(inputs)) {
658
- return {};
659
- }
660
-
661
- const resolved = {};
662
- for (const input of inputs) {
663
- if (typeof input === 'string') {
664
- resolved[input] = context[input] || null;
665
- } else if (typeof input === 'object' && input.name) {
666
- resolved[input.name] = context[input.name] || input.default || null;
667
- }
668
- }
669
- return resolved;
670
- }
671
-
672
- /**
673
- * Handle step failure with recovery options
674
- * @param {Object} step - Failed step
675
- * @param {Object} result - Failure result
676
- * @returns {string} Recovery action
677
- */
678
- async handleStepFailure(step, result) {
679
- console.log();
680
- console.log(chalk.red(` ✗ Step failed: ${result.error}`));
681
- console.log();
682
-
683
- if (!this.interactive) {
684
- return RecoveryAction.ABORT;
685
- }
686
-
687
- const action = await select({
688
- message: 'How would you like to proceed?',
689
- choices: [
690
- { name: 'Retry this step', value: RecoveryAction.RETRY },
691
- { name: 'Skip and continue', value: RecoveryAction.SKIP },
692
- { name: 'Pause (resume later)', value: RecoveryAction.PAUSE },
693
- { name: 'Abort workflow', value: RecoveryAction.ABORT }
694
- ]
695
- });
696
-
697
- return action;
698
- }
699
-
700
- /**
701
- * Prompt for agent step completion
702
- * @param {Object} step - Step definition
703
- * @returns {Object} Completion info
704
- */
705
- async promptAgentCompletion(step) {
706
- const completed = await confirm({
707
- message: 'Has the agent completed this task?',
708
- default: true
709
- });
710
-
711
- if (!completed) {
712
- return { completed: false, outputs: null };
713
- }
714
-
715
- // Optionally collect outputs
716
- const outputs = {};
717
-
718
- if (step.outputs && step.outputs.length > 0) {
719
- const collectOutputs = await confirm({
720
- message: 'Would you like to record any outputs?',
721
- default: false
722
- });
723
-
724
- if (collectOutputs) {
725
- for (const output of step.outputs) {
726
- const value = await input({
727
- message: `Enter value for "${output}" (or leave empty):`,
728
- default: ''
729
- });
730
-
731
- if (value) {
732
- outputs[output] = value;
733
- }
734
- }
735
- }
736
- }
737
-
738
- return { completed: true, outputs };
739
- }
740
-
741
- /**
742
- * Display workflow header
743
- */
744
- displayWorkflowHeader() {
745
- console.log();
746
- console.log(chalk.bold(`🔄 Executing Workflow: ${this.workflow.name}`));
747
- console.log(chalk.gray('─'.repeat(50)));
748
-
749
- if (this.workflow.description) {
750
- const desc = this.workflow.description.trim().split('\n')[0];
751
- console.log(chalk.gray(desc));
752
- }
753
-
754
- console.log();
755
- console.log(chalk.gray(`AI Tool: ${getAgentConfig(this.aiTool)?.name || this.aiTool}`));
756
- console.log(chalk.gray(`Steps: ${this.workflow.steps?.length || 0}`));
757
- console.log(chalk.gray(`Mode: ${supportsTask(this.aiTool) ? 'Auto-execute' : 'Guided'}`));
758
- console.log();
759
- }
760
-
761
- /**
762
- * Display step header
763
- * @param {Object} step - Step definition
764
- */
765
- displayStepHeader(step) {
766
- const stepIndex = this.stepOrder.indexOf(step.id) + 1;
767
- const total = this.stepOrder.length;
768
- const typeIcon = this.getStepTypeIcon(step.type);
769
-
770
- console.log(chalk.gray('─'.repeat(50)));
771
- console.log();
772
- console.log(chalk.cyan(`${typeIcon} Step ${stepIndex}/${total}: ${step.name}`));
773
-
774
- if (step.phase) {
775
- console.log(chalk.gray(` Phase: ${step.phase}`));
776
- }
777
- }
778
-
779
- /**
780
- * Display step success
781
- * @param {Object} step - Step definition
782
- */
783
- displayStepSuccess(step) {
784
- console.log();
785
- console.log(chalk.green(` ✓ ${step.name} completed`));
786
- console.log();
787
- }
788
-
789
- /**
790
- * Display dry-run plan
791
- * @returns {Object} Dry-run result
792
- */
793
- displayDryRunPlan() {
794
- console.log(chalk.yellow('DRY RUN - No steps will be executed'));
795
- console.log();
796
- console.log(chalk.bold('Execution Plan:'));
797
- console.log();
798
-
799
- for (let i = 0; i < this.workflow.steps.length; i++) {
800
- const step = this.workflow.steps[i];
801
- const icon = this.getStepTypeIcon(step.type);
802
-
803
- console.log(` ${i + 1}. ${icon} ${step.name}`);
804
- console.log(chalk.gray(` Type: ${step.type}`));
805
-
806
- if (step.agent) {
807
- console.log(chalk.gray(` Agent: ${step.agent}`));
808
- }
809
-
810
- if (step.inputs && step.inputs.length > 0) {
811
- console.log(chalk.gray(` Inputs: ${step.inputs.join(', ')}`));
812
- }
813
-
814
- if (step.outputs && step.outputs.length > 0) {
815
- console.log(chalk.gray(` Outputs: ${step.outputs.join(', ')}`));
816
- }
817
-
818
- console.log();
819
- }
820
-
821
- return {
822
- success: true,
823
- dryRun: true,
824
- workflowName: this.workflow.name,
825
- steps: this.workflow.steps.map(s => ({
826
- id: s.id,
827
- name: s.name,
828
- type: s.type
829
- }))
830
- };
831
- }
832
-
833
- /**
834
- * Display completion summary
835
- * @param {Object} summary - Workflow summary
836
- */
837
- displayCompletionSummary(summary) {
838
- console.log(chalk.gray('─'.repeat(50)));
839
- console.log();
840
- console.log(chalk.green.bold('✓ Workflow completed successfully!'));
841
- console.log();
842
- console.log(chalk.gray(` Completed: ${summary.progress.completed}/${summary.progress.total} steps`));
843
-
844
- if (summary.progress.skipped > 0) {
845
- console.log(chalk.gray(` Skipped: ${summary.progress.skipped} steps`));
846
- }
847
-
848
- console.log();
849
- }
850
-
851
- /**
852
- * Get icon for step type
853
- * @param {string} type - Step type
854
- * @returns {string} Icon
855
- */
856
- getStepTypeIcon(type) {
857
- switch (type) {
858
- case 'agent':
859
- return chalk.green('●');
860
- case 'manual':
861
- return chalk.yellow('○');
862
- case 'conditional':
863
- return chalk.blue('◇');
864
- default:
865
- return chalk.gray('○');
866
- }
867
- }
868
- }
869
-
870
- export default WorkflowExecutor;