kiro-spec-engine 1.45.13 → 1.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +15 -4
  3. package/README.zh.md +15 -3
  4. package/bin/kiro-spec-engine.js +84 -0
  5. package/docs/adoption-guide.md +3 -2
  6. package/docs/command-reference.md +30 -12
  7. package/docs/cross-tool-guide.md +2 -1
  8. package/docs/document-governance.md +2 -1
  9. package/docs/faq.md +14 -13
  10. package/docs/manual-workflows-guide.md +2 -1
  11. package/docs/quick-start-with-ai-tools.md +4 -3
  12. package/docs/quick-start.md +21 -7
  13. package/docs/spec-workflow.md +3 -2
  14. package/docs/tools/claude-guide.md +3 -2
  15. package/docs/tools/cursor-guide.md +3 -2
  16. package/docs/tools/generic-guide.md +3 -2
  17. package/docs/tools/vscode-guide.md +3 -2
  18. package/docs/tools/windsurf-guide.md +3 -2
  19. package/docs/troubleshooting.md +10 -9
  20. package/docs/zh/quick-start.md +30 -14
  21. package/docs/zh/tools/claude-guide.md +2 -1
  22. package/docs/zh/tools/cursor-guide.md +2 -1
  23. package/docs/zh/tools/generic-guide.md +8 -7
  24. package/docs/zh/tools/vscode-guide.md +2 -1
  25. package/docs/zh/tools/windsurf-guide.md +2 -1
  26. package/lib/commands/orchestrate.js +123 -95
  27. package/lib/commands/spec-bootstrap.js +147 -0
  28. package/lib/commands/spec-gate.js +157 -0
  29. package/lib/commands/spec-pipeline.js +205 -0
  30. package/lib/spec/bootstrap/context-collector.js +48 -0
  31. package/lib/spec/bootstrap/draft-generator.js +158 -0
  32. package/lib/spec/bootstrap/questionnaire-engine.js +70 -0
  33. package/lib/spec/bootstrap/trace-emitter.js +59 -0
  34. package/lib/spec/multi-spec-orchestrate.js +93 -0
  35. package/lib/spec/pipeline/constants.js +6 -0
  36. package/lib/spec/pipeline/stage-adapters.js +118 -0
  37. package/lib/spec/pipeline/stage-runner.js +146 -0
  38. package/lib/spec/pipeline/state-store.js +119 -0
  39. package/lib/spec-gate/engine/gate-engine.js +165 -0
  40. package/lib/spec-gate/policy/default-policy.js +22 -0
  41. package/lib/spec-gate/policy/policy-loader.js +103 -0
  42. package/lib/spec-gate/result-emitter.js +81 -0
  43. package/lib/spec-gate/rules/default-rules.js +156 -0
  44. package/lib/spec-gate/rules/rule-registry.js +51 -0
  45. package/package.json +2 -1
@@ -0,0 +1,157 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+ const chalk = require('chalk');
4
+ const { runOrchestration } = require('./orchestrate');
5
+ const {
6
+ parseSpecTargets,
7
+ runMultiSpecViaOrchestrate
8
+ } = require('../spec/multi-spec-orchestrate');
9
+
10
+ const { PolicyLoader } = require('../spec-gate/policy/policy-loader');
11
+ const { RuleRegistry } = require('../spec-gate/rules/rule-registry');
12
+ const { createDefaultRules } = require('../spec-gate/rules/default-rules');
13
+ const { GateEngine } = require('../spec-gate/engine/gate-engine');
14
+ const { ResultEmitter } = require('../spec-gate/result-emitter');
15
+
16
+ async function runSpecGate(options = {}, dependencies = {}) {
17
+ const projectPath = dependencies.projectPath || process.cwd();
18
+ const specTargets = parseSpecTargets(options);
19
+
20
+ if (specTargets.length === 0) {
21
+ throw new Error('Either --spec or --specs is required');
22
+ }
23
+
24
+ if (specTargets.length > 1) {
25
+ const executeOrchestration = dependencies.runOrchestration || runOrchestration;
26
+ return runMultiSpecViaOrchestrate({
27
+ specTargets,
28
+ projectPath,
29
+ commandOptions: options,
30
+ runOrchestration: executeOrchestration,
31
+ commandLabel: 'Multi-spec gate',
32
+ nextActionLabel: 'Multi-spec gate execution defaulted to orchestrate mode.'
33
+ });
34
+ }
35
+
36
+ const specId = specTargets[0];
37
+
38
+ const specPath = path.join(projectPath, '.kiro', 'specs', specId);
39
+ if (!await fs.pathExists(specPath)) {
40
+ throw new Error(`Spec not found: ${specId}`);
41
+ }
42
+
43
+ const policyLoader = dependencies.policyLoader || new PolicyLoader(projectPath);
44
+ const policy = dependencies.policy || await policyLoader.load({
45
+ policy: options.policy,
46
+ strict: options.strict
47
+ });
48
+
49
+ const registry = dependencies.registry || new RuleRegistry(createDefaultRules(projectPath));
50
+ const engine = dependencies.engine || new GateEngine({
51
+ registry,
52
+ policy
53
+ });
54
+
55
+ const result = await engine.evaluate({ specId });
56
+ const emitter = dependencies.emitter || new ResultEmitter(projectPath);
57
+ const emitted = await emitter.emit(result, {
58
+ json: options.json,
59
+ out: options.out,
60
+ silent: options.silent
61
+ });
62
+
63
+ return {
64
+ ...result,
65
+ report_path: emitted.outputPath
66
+ };
67
+ }
68
+
69
+ async function generateSpecGatePolicyTemplate(options = {}, dependencies = {}) {
70
+ const projectPath = dependencies.projectPath || process.cwd();
71
+ const loader = dependencies.policyLoader || new PolicyLoader(projectPath);
72
+ const template = loader.getTemplate();
73
+
74
+ const outputPath = options.out
75
+ ? (path.isAbsolute(options.out) ? options.out : path.join(projectPath, options.out))
76
+ : path.join(projectPath, '.kiro', 'config', 'spec-gate-policy.template.json');
77
+
78
+ await fs.ensureDir(path.dirname(outputPath));
79
+ await fs.writeJson(outputPath, template, { spaces: 2 });
80
+
81
+ if (!options.silent) {
82
+ console.log(chalk.green('✅ Spec gate policy template generated:'));
83
+ console.log(` ${outputPath}`);
84
+ }
85
+
86
+ return {
87
+ success: true,
88
+ outputPath
89
+ };
90
+ }
91
+
92
+ function registerSpecGateCommand(program) {
93
+ const specGate = program
94
+ .command('spec-gate')
95
+ .description('Run standardized Spec gate checks (use: kse spec gate)');
96
+
97
+ specGate
98
+ .command('run')
99
+ .description('Execute gate checks for one or more Specs')
100
+ .option('--spec <name>', 'Single Spec identifier')
101
+ .option('--specs <names>', 'Comma-separated Spec identifiers (multi-spec defaults to orchestrate mode)')
102
+ .option('--policy <path>', 'Policy JSON path')
103
+ .option('--strict', 'Enable strict mode override')
104
+ .option('--json', 'Output machine-readable JSON')
105
+ .option('--out <path>', 'Write JSON result to file')
106
+ .option('--max-parallel <n>', 'Maximum parallel agents when orchestrate mode is used', parseInt)
107
+ .action(async options => {
108
+ try {
109
+ await runSpecGate(options);
110
+ } catch (error) {
111
+ if (options.json) {
112
+ console.log(JSON.stringify({ success: false, error: error.message }, null, 2));
113
+ } else {
114
+ console.error(chalk.red('❌ Spec gate failed:'), error.message);
115
+ }
116
+ process.exit(1);
117
+ }
118
+ });
119
+
120
+ specGate
121
+ .command('policy-template')
122
+ .description('Generate policy template JSON for Spec gate')
123
+ .option('--out <path>', 'Template output path')
124
+ .action(async options => {
125
+ try {
126
+ await generateSpecGatePolicyTemplate(options);
127
+ } catch (error) {
128
+ console.error(chalk.red('❌ Failed to generate policy template:'), error.message);
129
+ process.exit(1);
130
+ }
131
+ });
132
+ }
133
+
134
+ async function _runGateInOrchestrateMode(specTargets, options, dependencies) {
135
+ const projectPath = dependencies.projectPath || process.cwd();
136
+ const executeOrchestration = dependencies.runOrchestration || runOrchestration;
137
+
138
+ return runMultiSpecViaOrchestrate({
139
+ specTargets,
140
+ projectPath,
141
+ commandOptions: options,
142
+ runOrchestration: executeOrchestration,
143
+ commandLabel: 'Multi-spec gate',
144
+ nextActionLabel: 'Multi-spec gate execution defaulted to orchestrate mode.'
145
+ });
146
+ }
147
+
148
+ function _parseSpecTargets(options = {}) {
149
+ return parseSpecTargets(options);
150
+ }
151
+
152
+ module.exports = {
153
+ registerSpecGateCommand,
154
+ runSpecGate,
155
+ generateSpecGatePolicyTemplate,
156
+ _parseSpecTargets
157
+ };
@@ -0,0 +1,205 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+ const chalk = require('chalk');
4
+ const { runOrchestration } = require('./orchestrate');
5
+ const {
6
+ parseSpecTargets,
7
+ runMultiSpecViaOrchestrate
8
+ } = require('../spec/multi-spec-orchestrate');
9
+
10
+ const { PipelineStateStore } = require('../spec/pipeline/state-store');
11
+ const { StageRunner } = require('../spec/pipeline/stage-runner');
12
+ const { createDefaultStageAdapters } = require('../spec/pipeline/stage-adapters');
13
+
14
+ async function runSpecPipeline(options = {}, dependencies = {}) {
15
+ const projectPath = dependencies.projectPath || process.cwd();
16
+ const specTargets = parseSpecTargets(options);
17
+ if (specTargets.length === 0) {
18
+ throw new Error('Either --spec or --specs is required');
19
+ }
20
+
21
+ if (specTargets.length > 1) {
22
+ const executeOrchestration = dependencies.runOrchestration || runOrchestration;
23
+ return runMultiSpecViaOrchestrate({
24
+ specTargets,
25
+ projectPath,
26
+ commandOptions: options,
27
+ runOrchestration: executeOrchestration,
28
+ commandLabel: 'Multi-spec pipeline',
29
+ nextActionLabel: 'Multi-spec execution defaulted to orchestrate mode.'
30
+ });
31
+ }
32
+
33
+ const specId = specTargets[0];
34
+
35
+ const specPath = path.join(projectPath, '.kiro', 'specs', specId);
36
+ if (!await fs.pathExists(specPath)) {
37
+ throw new Error(`Spec not found: ${specId}`);
38
+ }
39
+
40
+ const stateStore = dependencies.stateStore || new PipelineStateStore(projectPath);
41
+ const adapters = dependencies.adapters || createDefaultStageAdapters(projectPath);
42
+ const stageRunner = dependencies.stageRunner || new StageRunner({
43
+ stateStore,
44
+ adapters
45
+ });
46
+
47
+ let state;
48
+ if (options.resume) {
49
+ state = await stateStore.loadLatest(specId);
50
+ }
51
+
52
+ if (!state) {
53
+ state = await stateStore.create(specId, {
54
+ failFast: options.failFast !== false,
55
+ continueOnWarning: !!options.continueOnWarning
56
+ });
57
+ }
58
+
59
+ const runContext = {
60
+ specId,
61
+ runId: state.run_id,
62
+ fromStage: options.fromStage,
63
+ toStage: options.toStage,
64
+ dryRun: !!options.dryRun,
65
+ resume: !!options.resume,
66
+ failFast: options.failFast !== false,
67
+ continueOnWarning: !!options.continueOnWarning,
68
+ strict: !!options.strict,
69
+ gateOut: options.gateOut,
70
+ state
71
+ };
72
+
73
+ const execution = await stageRunner.run(runContext);
74
+ await stateStore.markFinished(state, execution.status);
75
+
76
+ const result = {
77
+ spec_id: specId,
78
+ run_id: state.run_id,
79
+ status: execution.status,
80
+ stage_results: execution.stageResults,
81
+ failure: execution.failure,
82
+ next_actions: buildNextActions(execution),
83
+ state_file: path.relative(projectPath, stateStore.getRunPath(specId, state.run_id))
84
+ };
85
+
86
+ if (options.out) {
87
+ const outPath = path.isAbsolute(options.out)
88
+ ? options.out
89
+ : path.join(projectPath, options.out);
90
+ await fs.ensureDir(path.dirname(outPath));
91
+ await fs.writeJson(outPath, result, { spaces: 2 });
92
+ result.output_file = outPath;
93
+ }
94
+
95
+ if (options.json) {
96
+ console.log(JSON.stringify(result, null, 2));
97
+ } else {
98
+ printResult(result);
99
+ }
100
+
101
+ return result;
102
+ }
103
+
104
+ function registerSpecPipelineCommand(program) {
105
+ const pipeline = program
106
+ .command('spec-pipeline')
107
+ .description('Run Spec workflow pipeline (use: kse spec pipeline run)');
108
+
109
+ pipeline
110
+ .command('run')
111
+ .description('Execute pipeline stages for one or more Specs')
112
+ .option('--spec <name>', 'Single Spec identifier')
113
+ .option('--specs <names>', 'Comma-separated Spec identifiers (multi-spec defaults to orchestrate mode)')
114
+ .option('--from-stage <stage>', 'Start stage (requirements/design/tasks/gate)')
115
+ .option('--to-stage <stage>', 'End stage (requirements/design/tasks/gate)')
116
+ .option('--resume', 'Resume from latest unfinished stage state')
117
+ .option('--dry-run', 'Preview pipeline execution without writing stage outputs')
118
+ .option('--json', 'Output machine-readable JSON')
119
+ .option('--out <path>', 'Write pipeline result JSON to file')
120
+ .option('--max-parallel <n>', 'Maximum parallel agents when orchestrate mode is used', parseInt)
121
+ .option('--continue-on-warning', 'Continue when stage returns warnings')
122
+ .option('--no-fail-fast', 'Do not stop immediately on failed stage')
123
+ .option('--strict', 'Enable strict mode for downstream gate stage')
124
+ .option('--gate-out <path>', 'Output path for nested gate stage report')
125
+ .action(async options => {
126
+ try {
127
+ await runSpecPipeline(options);
128
+ } catch (error) {
129
+ if (options.json) {
130
+ console.log(JSON.stringify({ success: false, error: error.message }, null, 2));
131
+ } else {
132
+ console.error(chalk.red('❌ Spec pipeline failed:'), error.message);
133
+ }
134
+ process.exit(1);
135
+ }
136
+ });
137
+ }
138
+
139
+ function printResult(result) {
140
+ const statusColor = result.status === 'completed' ? chalk.green : chalk.red;
141
+
142
+ console.log(chalk.red('🔥') + ' Spec Workflow Pipeline');
143
+ console.log();
144
+ console.log(`${chalk.gray('Spec:')} ${result.spec_id}`);
145
+ console.log(`${chalk.gray('Run:')} ${result.run_id}`);
146
+ console.log(`${chalk.gray('Status:')} ${statusColor(result.status)}`);
147
+ console.log();
148
+
149
+ console.log(chalk.bold('Stage Results'));
150
+ result.stage_results.forEach(stage => {
151
+ const icon = stage.status === 'completed'
152
+ ? chalk.green('✓')
153
+ : stage.status === 'warning'
154
+ ? chalk.yellow('!')
155
+ : stage.status === 'skipped'
156
+ ? chalk.gray('→')
157
+ : chalk.red('✗');
158
+ console.log(` ${icon} ${stage.name}: ${stage.status}`);
159
+ });
160
+
161
+ if (result.next_actions.length > 0) {
162
+ console.log();
163
+ console.log(chalk.bold('Next Actions'));
164
+ result.next_actions.forEach(action => console.log(` - ${action}`));
165
+ }
166
+ }
167
+
168
+ function buildNextActions(execution) {
169
+ if (execution.status === 'completed') {
170
+ return ['Review pipeline output and continue implementation on completed Spec stages.'];
171
+ }
172
+
173
+ if (execution.failure && execution.failure.stage) {
174
+ return [
175
+ `Resolve failure at stage: ${execution.failure.stage}`,
176
+ 'Use --resume to continue from the last unfinished stage after remediation.'
177
+ ];
178
+ }
179
+
180
+ return ['Inspect stage_results for failure details and re-run pipeline.'];
181
+ }
182
+
183
+ async function _runPipelineInOrchestrateMode(specTargets, options, dependencies) {
184
+ const projectPath = dependencies.projectPath || process.cwd();
185
+ const executeOrchestration = dependencies.runOrchestration || runOrchestration;
186
+
187
+ return runMultiSpecViaOrchestrate({
188
+ specTargets,
189
+ projectPath,
190
+ commandOptions: options,
191
+ runOrchestration: executeOrchestration,
192
+ commandLabel: 'Multi-spec pipeline',
193
+ nextActionLabel: 'Multi-spec execution defaulted to orchestrate mode.'
194
+ });
195
+ }
196
+
197
+ function _parseSpecTargets(options = {}) {
198
+ return parseSpecTargets(options);
199
+ }
200
+
201
+ module.exports = {
202
+ registerSpecPipelineCommand,
203
+ runSpecPipeline,
204
+ _parseSpecTargets
205
+ };
@@ -0,0 +1,48 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+
4
+ class ContextCollector {
5
+ constructor(projectPath = process.cwd()) {
6
+ this.projectPath = projectPath;
7
+ }
8
+
9
+ async collect() {
10
+ const kiroDir = path.join(this.projectPath, '.kiro');
11
+ const specsDir = path.join(kiroDir, 'specs');
12
+ const hasKiro = await fs.pathExists(kiroDir);
13
+ const existingSpecs = await this._listSpecs(specsDir);
14
+
15
+ return {
16
+ projectPath: this.projectPath,
17
+ hasKiro,
18
+ specsDir,
19
+ existingSpecs,
20
+ totalSpecs: existingSpecs.length,
21
+ preferredLanguage: this._detectLanguagePreference()
22
+ };
23
+ }
24
+
25
+ async _listSpecs(specsDir) {
26
+ if (!await fs.pathExists(specsDir)) {
27
+ return [];
28
+ }
29
+
30
+ const entries = await fs.readdir(specsDir, { withFileTypes: true });
31
+ return entries
32
+ .filter(entry => entry.isDirectory())
33
+ .map(entry => entry.name)
34
+ .sort((left, right) => left.localeCompare(right));
35
+ }
36
+
37
+ _detectLanguagePreference() {
38
+ const lang = `${process.env.KSE_LANG || process.env.LANG || ''}`.toLowerCase();
39
+ if (lang.includes('zh')) {
40
+ return 'zh';
41
+ }
42
+
43
+ return 'en';
44
+ }
45
+ }
46
+
47
+ module.exports = { ContextCollector };
48
+
@@ -0,0 +1,158 @@
1
+ class DraftGenerator {
2
+ generate(input = {}) {
3
+ const specName = input.specName;
4
+ const profile = input.profile || 'general';
5
+ const template = input.template || 'default';
6
+ const context = input.context || {};
7
+ const answers = input.answers || {};
8
+
9
+ const requirementIds = ['Requirement 1', 'Requirement 2', 'Requirement 3'];
10
+ const designIds = ['Design 1', 'Design 2', 'Design 3'];
11
+
12
+ const requirements = this._buildRequirements(specName, profile, template, answers);
13
+ const design = this._buildDesign(specName, profile, template, requirementIds, designIds, answers);
14
+ const tasks = this._buildTasks(requirementIds, designIds);
15
+
16
+ return {
17
+ requirements,
18
+ design,
19
+ tasks,
20
+ metadata: {
21
+ profile,
22
+ template,
23
+ projectPath: context.projectPath,
24
+ preferredLanguage: context.preferredLanguage || 'en',
25
+ existingSpecCount: context.totalSpecs || 0,
26
+ mapping: {
27
+ requirements: requirementIds,
28
+ design: designIds,
29
+ taskCount: 6
30
+ }
31
+ }
32
+ };
33
+ }
34
+
35
+ _buildRequirements(specName, profile, template, answers) {
36
+ return `# Requirements Document
37
+
38
+ ## Introduction
39
+
40
+ This Spec bootstrap draft was generated for ${specName} with profile ${profile} and template hint ${template}.
41
+
42
+ ## Context Snapshot
43
+
44
+ - Problem statement: ${answers.problemStatement}
45
+ - Primary flow: ${answers.primaryFlow}
46
+ - Verification plan: ${answers.verificationPlan}
47
+
48
+ ## Requirements
49
+
50
+ ### Requirement 1: Establish command entry
51
+
52
+ **User Story:** As a user, I want one command to initialize a complete Spec draft.
53
+
54
+ #### Acceptance Criteria
55
+
56
+ 1. THE CLI SHALL expose an entry command for bootstrap generation
57
+ 2. THE command SHALL support explicit naming and non-interactive execution
58
+
59
+ ### Requirement 2: Collect minimum context
60
+
61
+ **User Story:** As an implementer, I want the wizard to use project context with a controlled question set.
62
+
63
+ #### Acceptance Criteria
64
+
65
+ 1. THE SYSTEM SHALL collect project metadata and existing Spec inventory
66
+ 2. THE wizard SHALL keep the questionnaire small and default-driven
67
+ 3. WHEN non-interactive mode is enabled THEN generation SHALL rely on arguments and defaults only
68
+
69
+ ### Requirement 3: Generate traceable draft docs
70
+
71
+ **User Story:** As a team member, I want requirements/design/tasks to stay mapped and auditable.
72
+
73
+ #### Acceptance Criteria
74
+
75
+ 1. THE SYSTEM SHALL output requirements.md, design.md, and tasks.md together
76
+ 2. THE output SHALL contain requirement-design-task mapping references
77
+ 3. THE output SHALL capture generation trace information for governance and audit
78
+ `;
79
+ }
80
+
81
+ _buildDesign(specName, profile, template, requirementIds, designIds, answers) {
82
+ return `# Design Document
83
+
84
+ ## Overview
85
+
86
+ This design document defines the bootstrap generation flow for ${specName}.
87
+
88
+ - Profile: ${profile}
89
+ - Template hint: ${template}
90
+
91
+ ## Requirement Mapping
92
+
93
+ | Requirement | Design Component | Notes |
94
+ | --- | --- | --- |
95
+ | ${requirementIds[0]} | ${designIds[0]} | CLI entry and argument handling |
96
+ | ${requirementIds[1]} | ${designIds[1]} | Context collector and questionnaire |
97
+ | ${requirementIds[2]} | ${designIds[2]} | Draft generation and trace output |
98
+
99
+ ## Design Components
100
+
101
+ ### Design 1: Bootstrap command orchestration
102
+
103
+ - Parse name/template/profile/non-interactive/dry-run/json options
104
+ - Handle write mode and dry-run preview mode consistently
105
+
106
+ ### Design 2: Context and prompt pipeline
107
+
108
+ - Collect project metadata and existing Spec list
109
+ - Keep questionnaire minimal with defaults
110
+ - Input guidance: ${answers.primaryFlow}
111
+
112
+ ### Design 3: Draft and trace emitter
113
+
114
+ - Generate linked requirements/design/tasks content
115
+ - Emit trace metadata (template, profile, key parameters)
116
+ - Validation guidance: ${answers.verificationPlan}
117
+ `;
118
+ }
119
+
120
+ _buildTasks(requirementIds, designIds) {
121
+ return `# Implementation Tasks
122
+
123
+ ## Task List
124
+
125
+ - [ ] 1. Implement command entry and option parsing
126
+ - **Requirement**: ${requirementIds[0]}
127
+ - **Design**: ${designIds[0]}
128
+ - **Validation**: Acceptance Criteria 1.1, 1.2
129
+
130
+ - [ ] 2. Implement dry-run and write-mode behavior
131
+ - **Requirement**: ${requirementIds[0]}
132
+ - **Design**: ${designIds[0]}
133
+ - **Validation**: Acceptance Criteria 1.1
134
+
135
+ - [ ] 3. Implement context collector
136
+ - **Requirement**: ${requirementIds[1]}
137
+ - **Design**: ${designIds[1]}
138
+ - **Validation**: Acceptance Criteria 2.1
139
+
140
+ - [ ] 4. Implement minimal questionnaire with defaults
141
+ - **Requirement**: ${requirementIds[1]}
142
+ - **Design**: ${designIds[1]}
143
+ - **Validation**: Acceptance Criteria 2.2, 2.3
144
+
145
+ - [ ] 5. Implement linked document generation
146
+ - **Requirement**: ${requirementIds[2]}
147
+ - **Design**: ${designIds[2]}
148
+ - **Validation**: Acceptance Criteria 3.1, 3.2
149
+
150
+ - [ ] 6. Implement trace output and JSON mode
151
+ - **Requirement**: ${requirementIds[2]}
152
+ - **Design**: ${designIds[2]}
153
+ - **Validation**: Acceptance Criteria 3.3
154
+ `;
155
+ }
156
+ }
157
+
158
+ module.exports = { DraftGenerator };
@@ -0,0 +1,70 @@
1
+ const inquirer = require('inquirer');
2
+
3
+ const DEFAULT_ANSWERS = {
4
+ problemStatement: 'Define the feature scope and the expected business outcome.',
5
+ primaryFlow: 'Capture user flow, data flow, and observable outputs.',
6
+ verificationPlan: 'Define verification checks and acceptance coverage.'
7
+ };
8
+
9
+ class QuestionnaireEngine {
10
+ constructor(options = {}) {
11
+ this.maxQuestions = options.maxQuestions || 3;
12
+ this.prompt = options.prompt || inquirer.prompt;
13
+ }
14
+
15
+ async collect(options = {}) {
16
+ const defaults = this._buildDefaults(options);
17
+
18
+ if (options.nonInteractive) {
19
+ return defaults;
20
+ }
21
+
22
+ const questions = [
23
+ {
24
+ type: 'input',
25
+ name: 'specName',
26
+ message: 'Spec name (for example: 112-00-feature-name):',
27
+ default: defaults.specName,
28
+ validate: input => input && input.trim() ? true : 'Spec name is required'
29
+ },
30
+ {
31
+ type: 'input',
32
+ name: 'problemStatement',
33
+ message: 'What problem should this Spec solve?',
34
+ default: defaults.problemStatement
35
+ },
36
+ {
37
+ type: 'input',
38
+ name: 'primaryFlow',
39
+ message: 'What is the primary implementation flow?',
40
+ default: defaults.primaryFlow
41
+ },
42
+ {
43
+ type: 'input',
44
+ name: 'verificationPlan',
45
+ message: 'How should this Spec be validated?',
46
+ default: defaults.verificationPlan
47
+ }
48
+ ].slice(0, this.maxQuestions + 1);
49
+
50
+ const answers = await this.prompt(questions);
51
+ return {
52
+ ...defaults,
53
+ ...answers,
54
+ questionCount: questions.length
55
+ };
56
+ }
57
+
58
+ _buildDefaults(options = {}) {
59
+ return {
60
+ specName: options.specName || '',
61
+ problemStatement: options.problemStatement || DEFAULT_ANSWERS.problemStatement,
62
+ primaryFlow: options.primaryFlow || DEFAULT_ANSWERS.primaryFlow,
63
+ verificationPlan: options.verificationPlan || DEFAULT_ANSWERS.verificationPlan,
64
+ questionCount: 0
65
+ };
66
+ }
67
+ }
68
+
69
+ module.exports = { QuestionnaireEngine, DEFAULT_ANSWERS };
70
+
@@ -0,0 +1,59 @@
1
+ const chalk = require('chalk');
2
+
3
+ class TraceEmitter {
4
+ emit(result, options = {}) {
5
+ if (options.json) {
6
+ console.log(JSON.stringify(result, null, 2));
7
+ return;
8
+ }
9
+
10
+ console.log(chalk.red('🔥') + ' Spec Bootstrap Wizard');
11
+ console.log();
12
+ console.log(`${chalk.gray('Spec:')} ${result.specName}`);
13
+ console.log(`${chalk.gray('Mode:')} ${result.dryRun ? 'dry-run' : 'write'}`);
14
+ console.log(`${chalk.gray('Template:')} ${result.trace.template}`);
15
+ console.log(`${chalk.gray('Profile:')} ${result.trace.profile}`);
16
+ console.log();
17
+
18
+ if (result.dryRun) {
19
+ console.log(chalk.yellow('⚠ Dry-run mode: no files were written.'));
20
+ console.log();
21
+ this._printPreview(result.preview || {});
22
+ } else {
23
+ console.log(chalk.green('✅ Draft files generated:'));
24
+ Object.values(result.files || {}).forEach(filePath => {
25
+ console.log(` - ${filePath}`);
26
+ });
27
+ }
28
+
29
+ console.log();
30
+ console.log(chalk.blue('📌 Trace Summary'));
31
+ console.log(` - existing specs: ${result.trace.context.totalSpecs}`);
32
+ console.log(` - preferred language: ${result.trace.context.preferredLanguage}`);
33
+ console.log(` - non-interactive: ${result.trace.parameters.nonInteractive}`);
34
+ }
35
+
36
+ _printPreview(preview) {
37
+ const sections = ['requirements', 'design', 'tasks'];
38
+
39
+ sections.forEach(section => {
40
+ const content = preview[section];
41
+ if (!content) {
42
+ return;
43
+ }
44
+
45
+ const lines = content
46
+ .split(/\r?\n/)
47
+ .filter(Boolean)
48
+ .slice(0, 5);
49
+
50
+ console.log(chalk.cyan(`--- ${section}.md preview ---`));
51
+ lines.forEach(line => console.log(` ${line}`));
52
+ console.log(' ...');
53
+ console.log();
54
+ });
55
+ }
56
+ }
57
+
58
+ module.exports = { TraceEmitter };
59
+