aios-core 4.0.2 → 4.0.4

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 (145) hide show
  1. package/.aios-core/.session/current-session.json +14 -0
  2. package/.aios-core/core/registry/registry-schema.json +166 -166
  3. package/.aios-core/core/registry/service-registry.json +6585 -6585
  4. package/.aios-core/data/registry-update-log.jsonl +113 -0
  5. package/.aios-core/development/scripts/approval-workflow.js +642 -642
  6. package/.aios-core/development/scripts/backup-manager.js +606 -606
  7. package/.aios-core/development/scripts/branch-manager.js +389 -389
  8. package/.aios-core/development/scripts/code-quality-improver.js +1311 -1311
  9. package/.aios-core/development/scripts/commit-message-generator.js +849 -849
  10. package/.aios-core/development/scripts/conflict-resolver.js +674 -674
  11. package/.aios-core/development/scripts/dependency-analyzer.js +637 -637
  12. package/.aios-core/development/scripts/diff-generator.js +351 -351
  13. package/.aios-core/development/scripts/elicitation-engine.js +384 -384
  14. package/.aios-core/development/scripts/elicitation-session-manager.js +299 -299
  15. package/.aios-core/development/scripts/git-wrapper.js +461 -461
  16. package/.aios-core/development/scripts/manifest-preview.js +244 -244
  17. package/.aios-core/development/scripts/metrics-tracker.js +775 -775
  18. package/.aios-core/development/scripts/modification-validator.js +554 -554
  19. package/.aios-core/development/scripts/pattern-learner.js +1224 -1224
  20. package/.aios-core/development/scripts/performance-analyzer.js +757 -757
  21. package/.aios-core/development/scripts/refactoring-suggester.js +1138 -1138
  22. package/.aios-core/development/scripts/rollback-handler.js +530 -530
  23. package/.aios-core/development/scripts/security-checker.js +358 -358
  24. package/.aios-core/development/scripts/template-engine.js +239 -239
  25. package/.aios-core/development/scripts/template-validator.js +278 -278
  26. package/.aios-core/development/scripts/test-generator.js +843 -843
  27. package/.aios-core/development/scripts/transaction-manager.js +589 -589
  28. package/.aios-core/development/scripts/usage-tracker.js +673 -673
  29. package/.aios-core/development/scripts/validate-filenames.js +226 -226
  30. package/.aios-core/development/scripts/version-tracker.js +526 -526
  31. package/.aios-core/development/scripts/yaml-validator.js +396 -396
  32. package/.aios-core/development/templates/service-template/README.md.hbs +158 -158
  33. package/.aios-core/development/templates/service-template/__tests__/index.test.ts.hbs +237 -237
  34. package/.aios-core/development/templates/service-template/client.ts.hbs +403 -403
  35. package/.aios-core/development/templates/service-template/errors.ts.hbs +182 -182
  36. package/.aios-core/development/templates/service-template/index.ts.hbs +120 -120
  37. package/.aios-core/development/templates/service-template/package.json.hbs +87 -87
  38. package/.aios-core/development/templates/service-template/types.ts.hbs +145 -145
  39. package/.aios-core/development/templates/squad-template/LICENSE +21 -21
  40. package/.aios-core/docs/SHARD-TRANSLATION-GUIDE.md +335 -0
  41. package/.aios-core/docs/component-creation-guide.md +458 -0
  42. package/.aios-core/docs/session-update-pattern.md +307 -0
  43. package/.aios-core/docs/standards/AIOS-FRAMEWORK-MASTER.md +1963 -0
  44. package/.aios-core/docs/standards/AIOS-LIVRO-DE-OURO-V2.1-SUMMARY.md +1190 -0
  45. package/.aios-core/docs/standards/AIOS-LIVRO-DE-OURO-V2.1.md +439 -0
  46. package/.aios-core/docs/standards/AIOS-LIVRO-DE-OURO.md +5398 -0
  47. package/.aios-core/docs/standards/V3-ARCHITECTURAL-DECISIONS.md +523 -0
  48. package/.aios-core/docs/template-syntax.md +267 -0
  49. package/.aios-core/docs/troubleshooting-guide.md +625 -0
  50. package/.aios-core/infrastructure/templates/aios-sync.yaml.template +193 -193
  51. package/.aios-core/infrastructure/templates/coderabbit.yaml.template +279 -279
  52. package/.aios-core/infrastructure/templates/github-workflows/ci.yml.template +169 -169
  53. package/.aios-core/infrastructure/templates/github-workflows/pr-automation.yml.template +330 -330
  54. package/.aios-core/infrastructure/templates/github-workflows/release.yml.template +196 -196
  55. package/.aios-core/infrastructure/templates/gitignore/gitignore-aios-base.tmpl +63 -63
  56. package/.aios-core/infrastructure/templates/gitignore/gitignore-brownfield-merge.tmpl +18 -18
  57. package/.aios-core/infrastructure/templates/gitignore/gitignore-node.tmpl +85 -85
  58. package/.aios-core/infrastructure/templates/gitignore/gitignore-python.tmpl +145 -145
  59. package/.aios-core/infrastructure/tests/utilities-audit-results.json +501 -0
  60. package/.aios-core/install-manifest.yaml +97 -97
  61. package/.aios-core/local-config.yaml.template +68 -68
  62. package/.aios-core/manifests/agents.csv +1 -0
  63. package/.aios-core/manifests/schema/manifest-schema.json +190 -190
  64. package/.aios-core/manifests/tasks.csv +121 -0
  65. package/.aios-core/manifests/workers.csv +204 -0
  66. package/.aios-core/monitor/hooks/lib/__init__.py +1 -1
  67. package/.aios-core/monitor/hooks/lib/enrich.py +58 -58
  68. package/.aios-core/monitor/hooks/lib/send_event.py +47 -47
  69. package/.aios-core/monitor/hooks/notification.py +29 -29
  70. package/.aios-core/monitor/hooks/post_tool_use.py +45 -45
  71. package/.aios-core/monitor/hooks/pre_compact.py +29 -29
  72. package/.aios-core/monitor/hooks/pre_tool_use.py +40 -40
  73. package/.aios-core/monitor/hooks/stop.py +29 -29
  74. package/.aios-core/monitor/hooks/subagent_stop.py +29 -29
  75. package/.aios-core/monitor/hooks/user_prompt_submit.py +38 -38
  76. package/.aios-core/product/templates/adr.hbs +125 -125
  77. package/.aios-core/product/templates/component-react-tmpl.tsx +98 -98
  78. package/.aios-core/product/templates/dbdr.hbs +241 -241
  79. package/.aios-core/product/templates/engine/schemas/adr.schema.json +102 -102
  80. package/.aios-core/product/templates/engine/schemas/dbdr.schema.json +205 -205
  81. package/.aios-core/product/templates/engine/schemas/epic.schema.json +175 -175
  82. package/.aios-core/product/templates/engine/schemas/pmdr.schema.json +175 -175
  83. package/.aios-core/product/templates/engine/schemas/prd-v2.schema.json +300 -300
  84. package/.aios-core/product/templates/engine/schemas/prd.schema.json +152 -152
  85. package/.aios-core/product/templates/engine/schemas/story.schema.json +222 -222
  86. package/.aios-core/product/templates/engine/schemas/task.schema.json +154 -154
  87. package/.aios-core/product/templates/epic.hbs +212 -212
  88. package/.aios-core/product/templates/eslintrc-security.json +32 -32
  89. package/.aios-core/product/templates/github-actions-cd.yml +212 -212
  90. package/.aios-core/product/templates/github-actions-ci.yml +172 -172
  91. package/.aios-core/product/templates/pmdr.hbs +186 -186
  92. package/.aios-core/product/templates/prd-v2.0.hbs +216 -216
  93. package/.aios-core/product/templates/prd.hbs +201 -201
  94. package/.aios-core/product/templates/shock-report-tmpl.html +502 -502
  95. package/.aios-core/product/templates/story.hbs +263 -263
  96. package/.aios-core/product/templates/task.hbs +170 -170
  97. package/.aios-core/product/templates/tmpl-comment-on-examples.sql +158 -158
  98. package/.aios-core/product/templates/tmpl-migration-script.sql +91 -91
  99. package/.aios-core/product/templates/tmpl-rls-granular-policies.sql +104 -104
  100. package/.aios-core/product/templates/tmpl-rls-kiss-policy.sql +10 -10
  101. package/.aios-core/product/templates/tmpl-rls-roles.sql +135 -135
  102. package/.aios-core/product/templates/tmpl-rls-simple.sql +77 -77
  103. package/.aios-core/product/templates/tmpl-rls-tenant.sql +152 -152
  104. package/.aios-core/product/templates/tmpl-rollback-script.sql +77 -77
  105. package/.aios-core/product/templates/tmpl-seed-data.sql +140 -140
  106. package/.aios-core/product/templates/tmpl-smoke-test.sql +16 -16
  107. package/.aios-core/product/templates/tmpl-staging-copy-merge.sql +139 -139
  108. package/.aios-core/product/templates/tmpl-stored-proc.sql +140 -140
  109. package/.aios-core/product/templates/tmpl-trigger.sql +152 -152
  110. package/.aios-core/product/templates/tmpl-view-materialized.sql +133 -133
  111. package/.aios-core/product/templates/tmpl-view.sql +177 -177
  112. package/.aios-core/product/templates/token-exports-css-tmpl.css +240 -240
  113. package/.aios-core/quality/schemas/quality-metrics.schema.json +233 -233
  114. package/.aios-core/scripts/migrate-framework-docs.sh +300 -300
  115. package/.aios-core/scripts/pm.sh +0 -0
  116. package/.claude/hooks/enforce-architecture-first.py +196 -0
  117. package/.claude/hooks/install-hooks.sh +41 -0
  118. package/.claude/hooks/mind-clone-governance.py +192 -0
  119. package/.claude/hooks/pre-commit-mmos-guard.sh +99 -0
  120. package/.claude/hooks/pre-commit-version-check.sh +156 -0
  121. package/.claude/hooks/read-protection.py +151 -0
  122. package/.claude/hooks/slug-validation.py +176 -0
  123. package/.claude/hooks/sql-governance.py +182 -0
  124. package/.claude/hooks/write-path-validation.py +194 -0
  125. package/.claude/rules/agent-authority.md +105 -0
  126. package/.claude/rules/coderabbit-integration.md +93 -0
  127. package/.claude/rules/ids-principles.md +112 -0
  128. package/.claude/rules/story-lifecycle.md +139 -0
  129. package/.claude/rules/workflow-execution.md +150 -0
  130. package/LICENSE +48 -48
  131. package/README.md +30 -7
  132. package/bin/aios-minimal.js +0 -0
  133. package/bin/aios.js +15 -15
  134. package/package.json +2 -4
  135. package/packages/aios-install/bin/aios-install.js +0 -0
  136. package/packages/aios-install/bin/edmcp.js +0 -0
  137. package/packages/aios-pro-cli/bin/aios-pro.js +0 -0
  138. package/scripts/check-markdown-links.py +352 -352
  139. package/scripts/dashboard-parallel-dev.sh +0 -0
  140. package/scripts/dashboard-parallel-phase3.sh +0 -0
  141. package/scripts/dashboard-parallel-phase4.sh +0 -0
  142. package/scripts/glue/README.md +355 -0
  143. package/scripts/glue/compose-agent-prompt.cjs +362 -0
  144. package/scripts/install-monitor-hooks.sh +0 -0
  145. package/.aios-core/lib/build.json +0 -1
@@ -1,385 +1,385 @@
1
- /**
2
- * Interactive Elicitation Engine for AIOS-FULLSTACK
3
- * Handles progressive disclosure and contextual validation for component creation
4
- * @module elicitation-engine
5
- */
6
-
7
- const inquirer = require('inquirer');
8
- const fs = require('fs-extra');
9
- const path = require('path');
10
- const SecurityChecker = require('./security-checker');
11
- const ElicitationSessionManager = require('./elicitation-session-manager');
12
- const chalk = require('chalk');
13
-
14
- class ElicitationEngine {
15
- constructor() {
16
- this.securityChecker = new SecurityChecker();
17
- this.sessionManager = new ElicitationSessionManager();
18
- this.sessionData = {};
19
- this.sessionFile = null;
20
- }
21
-
22
- /**
23
- * Start a new elicitation session
24
- * @param {string} componentType - Type of component being created
25
- * @param {Object} options - Session options
26
- */
27
- async startSession(componentType, options = {}) {
28
- this.sessionData = {
29
- componentType,
30
- startTime: new Date().toISOString(),
31
- answers: {},
32
- currentStep: 0,
33
- options
34
- };
35
-
36
- if (options.saveSession) {
37
- this.sessionFile = path.join(
38
- process.cwd(),
39
- '.aios-sessions',
40
- `${componentType}-${Date.now()}.json`
41
- );
42
- await fs.ensureDir(path.dirname(this.sessionFile));
43
- }
44
- }
45
-
46
- /**
47
- * Run progressive elicitation workflow
48
- * @param {Array} steps - Array of elicitation steps
49
- * @returns {Promise<Object>} Collected answers
50
- */
51
- async runProgressive(steps) {
52
- // If mocked, return mocked answers immediately
53
- if (this.isMocked) {
54
- this.isMocked = false;
55
- return this.mockedAnswers;
56
- }
57
-
58
- console.log(chalk.blue(`\n🚀 Starting ${this.sessionData.componentType} creation wizard...\n`));
59
-
60
- for (let i = 0; i < steps.length; i++) {
61
- const step = steps[i];
62
- this.sessionData.currentStep = i;
63
-
64
- // Show step header
65
- console.log(chalk.yellow(`\n📋 Step ${i + 1}/${steps.length}: ${step.title}`));
66
- if (step.description) {
67
- console.log(chalk.gray(step.description));
68
- }
69
-
70
- // Check if step should be shown based on previous answers
71
- if (step.condition && !this.evaluateCondition(step.condition)) {
72
- continue;
73
- }
74
-
75
- // Run step questions
76
- const stepAnswers = await this.runStep(step);
77
- Object.assign(this.sessionData.answers, stepAnswers);
78
-
79
- // Save session after each step
80
- if (this.sessionFile) {
81
- await this.saveSession();
82
- }
83
-
84
- // Allow early exit if requested
85
- if (stepAnswers._exit) {
86
- console.log(chalk.yellow('\n⚠️ Elicitation cancelled by user'));
87
- return null;
88
- }
89
- }
90
-
91
- return this.sessionData.answers;
92
- }
93
-
94
- /**
95
- * Run a single elicitation step
96
- * @private
97
- */
98
- async runStep(step) {
99
- const questions = step.questions.map(q => this.enhanceQuestion(q, step));
100
-
101
- // Add contextual help if available
102
- if (step.help) {
103
- questions.unshift({
104
- type: 'confirm',
105
- name: '_showHelp',
106
- message: 'Would you like to see help for this step?',
107
- default: false
108
- });
109
- }
110
-
111
- const answers = await inquirer.prompt(questions);
112
-
113
- // Show help if requested
114
- if (answers._showHelp && step.help) {
115
- console.log(chalk.cyan('\n💡 ' + step.help));
116
- delete answers._showHelp;
117
- return this.runStep(step); // Re-run the step
118
- }
119
-
120
- // Validate answers
121
- const validation = await this.validateStepAnswers(answers, step);
122
- if (!validation.valid) {
123
- console.log(chalk.red('\n❌ Validation errors:'));
124
- validation.errors.forEach(err => console.log(chalk.red(` - ${err}`)));
125
- return this.runStep(step); // Re-run the step
126
- }
127
-
128
- return answers;
129
- }
130
-
131
- /**
132
- * Enhance a question with smart defaults and validation
133
- * @private
134
- */
135
- enhanceQuestion(question, step) {
136
- const enhanced = { ...question };
137
-
138
- // Add smart defaults based on previous answers
139
- if (question.smartDefault) {
140
- enhanced.default = this.getSmartDefault(question.smartDefault);
141
- }
142
-
143
- // Add validation with security checks
144
- const originalValidate = enhanced.validate;
145
- enhanced.validate = async (input) => {
146
- // Type validation
147
- if (typeof input !== 'string' && question.type === 'input') {
148
- return 'Invalid input type';
149
- }
150
-
151
- // Security validation using the refactored SecurityChecker
152
- // Note: SecurityChecker.checkCode expects string input for validation
153
- const securityResult = this.securityChecker.checkCode(String(input));
154
- if (!securityResult.valid) {
155
- return `Security check failed: ${securityResult.errors[0]?.message || 'Invalid input'}`;
156
- }
157
-
158
- // Original validation
159
- if (originalValidate) {
160
- const result = await originalValidate(input);
161
- if (result !== true) return result;
162
- }
163
-
164
- // Step-specific validation
165
- if (step.validation && step.validation[question.name]) {
166
- const validator = step.validation[question.name];
167
- const result = await this.runValidator(validator, input);
168
- if (result !== true) return result;
169
- }
170
-
171
- return true;
172
- };
173
-
174
- // Add examples to message if available
175
- if (question.examples && question.examples.length > 0) {
176
- enhanced.message += chalk.gray(` (e.g., ${question.examples.join(', ')})`);
177
- }
178
-
179
- return enhanced;
180
- }
181
-
182
- /**
183
- * Get smart default value based on previous answers
184
- * @private
185
- */
186
- getSmartDefault(smartDefaultConfig) {
187
- const { type, source, transform } = smartDefaultConfig;
188
-
189
- switch (type) {
190
- case 'fromAnswer':
191
- const value = this.sessionData.answers[source];
192
- return transform ? transform(value) : value;
193
-
194
- case 'generated':
195
- return this.generateDefault(smartDefaultConfig);
196
-
197
- case 'conditional':
198
- const condition = this.evaluateCondition(smartDefaultConfig.condition);
199
- return condition ? smartDefaultConfig.ifTrue : smartDefaultConfig.ifFalse;
200
-
201
- default:
202
- return undefined;
203
- }
204
- }
205
-
206
- /**
207
- * Generate a default value
208
- * @private
209
- */
210
- generateDefault(config) {
211
- switch (config.generator) {
212
- case 'kebabCase':
213
- const source = this.sessionData.answers[config.source] || '';
214
- return source.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
215
-
216
- case 'timestamp':
217
- return new Date().toISOString();
218
-
219
- case 'version':
220
- return '1.0.0';
221
-
222
- default:
223
- return '';
224
- }
225
- }
226
-
227
- /**
228
- * Evaluate a condition based on answers
229
- * @private
230
- */
231
- evaluateCondition(condition) {
232
- const { field, operator, value } = condition;
233
- const fieldValue = this.sessionData.answers[field];
234
-
235
- switch (operator) {
236
- case 'equals':
237
- return fieldValue === value;
238
- case 'notEquals':
239
- return fieldValue !== value;
240
- case 'includes':
241
- return Array.isArray(fieldValue) && fieldValue.includes(value);
242
- case 'exists':
243
- return fieldValue !== undefined && fieldValue !== null;
244
- default:
245
- return true;
246
- }
247
- }
248
-
249
- /**
250
- * Validate step answers
251
- * @private
252
- */
253
- async validateStepAnswers(answers, step) {
254
- const errors = [];
255
-
256
- // Check required fields
257
- if (step.required) {
258
- for (const field of step.required) {
259
- if (!answers[field]) {
260
- errors.push(`${field} is required`);
261
- }
262
- }
263
- }
264
-
265
- // Run custom validators
266
- if (step.validators) {
267
- for (const validator of step.validators) {
268
- const result = await this.runValidator(validator, answers);
269
- if (result !== true) {
270
- errors.push(result);
271
- }
272
- }
273
- }
274
-
275
- return {
276
- valid: errors.length === 0,
277
- errors
278
- };
279
- }
280
-
281
- /**
282
- * Run a validator function
283
- * @private
284
- */
285
- async runValidator(validator, value) {
286
- if (typeof validator === 'function') {
287
- return validator(value);
288
- }
289
-
290
- if (typeof validator === 'object') {
291
- switch (validator.type) {
292
- case 'regex':
293
- const regex = new RegExp(validator.pattern);
294
- return regex.test(value) || validator.message;
295
-
296
- case 'length':
297
- if (validator.min && value.length < validator.min) {
298
- return `Must be at least ${validator.min} characters`;
299
- }
300
- if (validator.max && value.length > validator.max) {
301
- return `Must be at most ${validator.max} characters`;
302
- }
303
- return true;
304
-
305
- case 'unique':
306
- const exists = await this.checkExists(validator.path, value);
307
- return !exists || `${value} already exists`;
308
-
309
- default:
310
- return true;
311
- }
312
- }
313
-
314
- return true;
315
- }
316
-
317
- /**
318
- * Check if a component already exists
319
- * @private
320
- */
321
- async checkExists(pathTemplate, name) {
322
- const filePath = pathTemplate.replace('{name}', name);
323
- return fs.pathExists(filePath);
324
- }
325
-
326
- /**
327
- * Save current session to file
328
- * @private
329
- */
330
- async saveSession() {
331
- if (this.sessionFile) {
332
- await fs.writeJson(this.sessionFile, this.sessionData, { spaces: 2 });
333
- }
334
- }
335
-
336
- /**
337
- * Load a saved session
338
- * @param {string} sessionPath - Path to session file
339
- */
340
- async loadSession(sessionPath) {
341
- this.sessionData = await fs.readJson(sessionPath);
342
- this.sessionFile = sessionPath;
343
- return this.sessionData;
344
- }
345
-
346
- /**
347
- * Get session summary
348
- * @returns {Object} Summary of current session
349
- */
350
- getSessionSummary() {
351
- return {
352
- componentType: this.sessionData.componentType,
353
- completedSteps: this.sessionData.currentStep + 1,
354
- answers: Object.keys(this.sessionData.answers).length,
355
- duration: this.sessionData.startTime ?
356
- Date.now() - new Date(this.sessionData.startTime).getTime() : 0
357
- };
358
- }
359
-
360
- /**
361
- * Mock a session with predefined answers for batch creation
362
- * @param {Object} answers - Predefined answers
363
- */
364
- async mockSession(answers) {
365
- this.mockedAnswers = answers;
366
- this.isMocked = true;
367
- }
368
-
369
- /**
370
- * Complete elicitation session
371
- * @param {string} status - Completion status
372
- */
373
- async completeSession(status) {
374
- if (this.currentSession) {
375
- this.currentSession.status = status;
376
- this.currentSession.completedAt = new Date().toISOString();
377
-
378
- if (this.currentSession.saveSession) {
379
- await this.sessionManager.saveSession(this.currentSession);
380
- }
381
- }
382
- }
383
- }
384
-
1
+ /**
2
+ * Interactive Elicitation Engine for AIOS-FULLSTACK
3
+ * Handles progressive disclosure and contextual validation for component creation
4
+ * @module elicitation-engine
5
+ */
6
+
7
+ const inquirer = require('inquirer');
8
+ const fs = require('fs-extra');
9
+ const path = require('path');
10
+ const SecurityChecker = require('./security-checker');
11
+ const ElicitationSessionManager = require('./elicitation-session-manager');
12
+ const chalk = require('chalk');
13
+
14
+ class ElicitationEngine {
15
+ constructor() {
16
+ this.securityChecker = new SecurityChecker();
17
+ this.sessionManager = new ElicitationSessionManager();
18
+ this.sessionData = {};
19
+ this.sessionFile = null;
20
+ }
21
+
22
+ /**
23
+ * Start a new elicitation session
24
+ * @param {string} componentType - Type of component being created
25
+ * @param {Object} options - Session options
26
+ */
27
+ async startSession(componentType, options = {}) {
28
+ this.sessionData = {
29
+ componentType,
30
+ startTime: new Date().toISOString(),
31
+ answers: {},
32
+ currentStep: 0,
33
+ options
34
+ };
35
+
36
+ if (options.saveSession) {
37
+ this.sessionFile = path.join(
38
+ process.cwd(),
39
+ '.aios-sessions',
40
+ `${componentType}-${Date.now()}.json`
41
+ );
42
+ await fs.ensureDir(path.dirname(this.sessionFile));
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Run progressive elicitation workflow
48
+ * @param {Array} steps - Array of elicitation steps
49
+ * @returns {Promise<Object>} Collected answers
50
+ */
51
+ async runProgressive(steps) {
52
+ // If mocked, return mocked answers immediately
53
+ if (this.isMocked) {
54
+ this.isMocked = false;
55
+ return this.mockedAnswers;
56
+ }
57
+
58
+ console.log(chalk.blue(`\n🚀 Starting ${this.sessionData.componentType} creation wizard...\n`));
59
+
60
+ for (let i = 0; i < steps.length; i++) {
61
+ const step = steps[i];
62
+ this.sessionData.currentStep = i;
63
+
64
+ // Show step header
65
+ console.log(chalk.yellow(`\n📋 Step ${i + 1}/${steps.length}: ${step.title}`));
66
+ if (step.description) {
67
+ console.log(chalk.gray(step.description));
68
+ }
69
+
70
+ // Check if step should be shown based on previous answers
71
+ if (step.condition && !this.evaluateCondition(step.condition)) {
72
+ continue;
73
+ }
74
+
75
+ // Run step questions
76
+ const stepAnswers = await this.runStep(step);
77
+ Object.assign(this.sessionData.answers, stepAnswers);
78
+
79
+ // Save session after each step
80
+ if (this.sessionFile) {
81
+ await this.saveSession();
82
+ }
83
+
84
+ // Allow early exit if requested
85
+ if (stepAnswers._exit) {
86
+ console.log(chalk.yellow('\n⚠️ Elicitation cancelled by user'));
87
+ return null;
88
+ }
89
+ }
90
+
91
+ return this.sessionData.answers;
92
+ }
93
+
94
+ /**
95
+ * Run a single elicitation step
96
+ * @private
97
+ */
98
+ async runStep(step) {
99
+ const questions = step.questions.map(q => this.enhanceQuestion(q, step));
100
+
101
+ // Add contextual help if available
102
+ if (step.help) {
103
+ questions.unshift({
104
+ type: 'confirm',
105
+ name: '_showHelp',
106
+ message: 'Would you like to see help for this step?',
107
+ default: false
108
+ });
109
+ }
110
+
111
+ const answers = await inquirer.prompt(questions);
112
+
113
+ // Show help if requested
114
+ if (answers._showHelp && step.help) {
115
+ console.log(chalk.cyan('\n💡 ' + step.help));
116
+ delete answers._showHelp;
117
+ return this.runStep(step); // Re-run the step
118
+ }
119
+
120
+ // Validate answers
121
+ const validation = await this.validateStepAnswers(answers, step);
122
+ if (!validation.valid) {
123
+ console.log(chalk.red('\n❌ Validation errors:'));
124
+ validation.errors.forEach(err => console.log(chalk.red(` - ${err}`)));
125
+ return this.runStep(step); // Re-run the step
126
+ }
127
+
128
+ return answers;
129
+ }
130
+
131
+ /**
132
+ * Enhance a question with smart defaults and validation
133
+ * @private
134
+ */
135
+ enhanceQuestion(question, step) {
136
+ const enhanced = { ...question };
137
+
138
+ // Add smart defaults based on previous answers
139
+ if (question.smartDefault) {
140
+ enhanced.default = this.getSmartDefault(question.smartDefault);
141
+ }
142
+
143
+ // Add validation with security checks
144
+ const originalValidate = enhanced.validate;
145
+ enhanced.validate = async (input) => {
146
+ // Type validation
147
+ if (typeof input !== 'string' && question.type === 'input') {
148
+ return 'Invalid input type';
149
+ }
150
+
151
+ // Security validation using the refactored SecurityChecker
152
+ // Note: SecurityChecker.checkCode expects string input for validation
153
+ const securityResult = this.securityChecker.checkCode(String(input));
154
+ if (!securityResult.valid) {
155
+ return `Security check failed: ${securityResult.errors[0]?.message || 'Invalid input'}`;
156
+ }
157
+
158
+ // Original validation
159
+ if (originalValidate) {
160
+ const result = await originalValidate(input);
161
+ if (result !== true) return result;
162
+ }
163
+
164
+ // Step-specific validation
165
+ if (step.validation && step.validation[question.name]) {
166
+ const validator = step.validation[question.name];
167
+ const result = await this.runValidator(validator, input);
168
+ if (result !== true) return result;
169
+ }
170
+
171
+ return true;
172
+ };
173
+
174
+ // Add examples to message if available
175
+ if (question.examples && question.examples.length > 0) {
176
+ enhanced.message += chalk.gray(` (e.g., ${question.examples.join(', ')})`);
177
+ }
178
+
179
+ return enhanced;
180
+ }
181
+
182
+ /**
183
+ * Get smart default value based on previous answers
184
+ * @private
185
+ */
186
+ getSmartDefault(smartDefaultConfig) {
187
+ const { type, source, transform } = smartDefaultConfig;
188
+
189
+ switch (type) {
190
+ case 'fromAnswer':
191
+ const value = this.sessionData.answers[source];
192
+ return transform ? transform(value) : value;
193
+
194
+ case 'generated':
195
+ return this.generateDefault(smartDefaultConfig);
196
+
197
+ case 'conditional':
198
+ const condition = this.evaluateCondition(smartDefaultConfig.condition);
199
+ return condition ? smartDefaultConfig.ifTrue : smartDefaultConfig.ifFalse;
200
+
201
+ default:
202
+ return undefined;
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Generate a default value
208
+ * @private
209
+ */
210
+ generateDefault(config) {
211
+ switch (config.generator) {
212
+ case 'kebabCase':
213
+ const source = this.sessionData.answers[config.source] || '';
214
+ return source.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
215
+
216
+ case 'timestamp':
217
+ return new Date().toISOString();
218
+
219
+ case 'version':
220
+ return '1.0.0';
221
+
222
+ default:
223
+ return '';
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Evaluate a condition based on answers
229
+ * @private
230
+ */
231
+ evaluateCondition(condition) {
232
+ const { field, operator, value } = condition;
233
+ const fieldValue = this.sessionData.answers[field];
234
+
235
+ switch (operator) {
236
+ case 'equals':
237
+ return fieldValue === value;
238
+ case 'notEquals':
239
+ return fieldValue !== value;
240
+ case 'includes':
241
+ return Array.isArray(fieldValue) && fieldValue.includes(value);
242
+ case 'exists':
243
+ return fieldValue !== undefined && fieldValue !== null;
244
+ default:
245
+ return true;
246
+ }
247
+ }
248
+
249
+ /**
250
+ * Validate step answers
251
+ * @private
252
+ */
253
+ async validateStepAnswers(answers, step) {
254
+ const errors = [];
255
+
256
+ // Check required fields
257
+ if (step.required) {
258
+ for (const field of step.required) {
259
+ if (!answers[field]) {
260
+ errors.push(`${field} is required`);
261
+ }
262
+ }
263
+ }
264
+
265
+ // Run custom validators
266
+ if (step.validators) {
267
+ for (const validator of step.validators) {
268
+ const result = await this.runValidator(validator, answers);
269
+ if (result !== true) {
270
+ errors.push(result);
271
+ }
272
+ }
273
+ }
274
+
275
+ return {
276
+ valid: errors.length === 0,
277
+ errors
278
+ };
279
+ }
280
+
281
+ /**
282
+ * Run a validator function
283
+ * @private
284
+ */
285
+ async runValidator(validator, value) {
286
+ if (typeof validator === 'function') {
287
+ return validator(value);
288
+ }
289
+
290
+ if (typeof validator === 'object') {
291
+ switch (validator.type) {
292
+ case 'regex':
293
+ const regex = new RegExp(validator.pattern);
294
+ return regex.test(value) || validator.message;
295
+
296
+ case 'length':
297
+ if (validator.min && value.length < validator.min) {
298
+ return `Must be at least ${validator.min} characters`;
299
+ }
300
+ if (validator.max && value.length > validator.max) {
301
+ return `Must be at most ${validator.max} characters`;
302
+ }
303
+ return true;
304
+
305
+ case 'unique':
306
+ const exists = await this.checkExists(validator.path, value);
307
+ return !exists || `${value} already exists`;
308
+
309
+ default:
310
+ return true;
311
+ }
312
+ }
313
+
314
+ return true;
315
+ }
316
+
317
+ /**
318
+ * Check if a component already exists
319
+ * @private
320
+ */
321
+ async checkExists(pathTemplate, name) {
322
+ const filePath = pathTemplate.replace('{name}', name);
323
+ return fs.pathExists(filePath);
324
+ }
325
+
326
+ /**
327
+ * Save current session to file
328
+ * @private
329
+ */
330
+ async saveSession() {
331
+ if (this.sessionFile) {
332
+ await fs.writeJson(this.sessionFile, this.sessionData, { spaces: 2 });
333
+ }
334
+ }
335
+
336
+ /**
337
+ * Load a saved session
338
+ * @param {string} sessionPath - Path to session file
339
+ */
340
+ async loadSession(sessionPath) {
341
+ this.sessionData = await fs.readJson(sessionPath);
342
+ this.sessionFile = sessionPath;
343
+ return this.sessionData;
344
+ }
345
+
346
+ /**
347
+ * Get session summary
348
+ * @returns {Object} Summary of current session
349
+ */
350
+ getSessionSummary() {
351
+ return {
352
+ componentType: this.sessionData.componentType,
353
+ completedSteps: this.sessionData.currentStep + 1,
354
+ answers: Object.keys(this.sessionData.answers).length,
355
+ duration: this.sessionData.startTime ?
356
+ Date.now() - new Date(this.sessionData.startTime).getTime() : 0
357
+ };
358
+ }
359
+
360
+ /**
361
+ * Mock a session with predefined answers for batch creation
362
+ * @param {Object} answers - Predefined answers
363
+ */
364
+ async mockSession(answers) {
365
+ this.mockedAnswers = answers;
366
+ this.isMocked = true;
367
+ }
368
+
369
+ /**
370
+ * Complete elicitation session
371
+ * @param {string} status - Completion status
372
+ */
373
+ async completeSession(status) {
374
+ if (this.currentSession) {
375
+ this.currentSession.status = status;
376
+ this.currentSession.completedAt = new Date().toISOString();
377
+
378
+ if (this.currentSession.saveSession) {
379
+ await this.sessionManager.saveSession(this.currentSession);
380
+ }
381
+ }
382
+ }
383
+ }
384
+
385
385
  module.exports = ElicitationEngine;