lightspec 0.1.1
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/LICENSE +22 -0
- package/README.md +435 -0
- package/bin/lightspec.js +3 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +361 -0
- package/dist/commands/change.d.ts +35 -0
- package/dist/commands/change.js +277 -0
- package/dist/commands/completion.d.ts +72 -0
- package/dist/commands/completion.js +257 -0
- package/dist/commands/config.d.ts +8 -0
- package/dist/commands/config.js +198 -0
- package/dist/commands/feedback.d.ts +9 -0
- package/dist/commands/feedback.js +183 -0
- package/dist/commands/show.d.ts +14 -0
- package/dist/commands/show.js +132 -0
- package/dist/commands/spec.d.ts +15 -0
- package/dist/commands/spec.js +225 -0
- package/dist/commands/validate.d.ts +24 -0
- package/dist/commands/validate.js +294 -0
- package/dist/core/archive.d.ts +11 -0
- package/dist/core/archive.js +280 -0
- package/dist/core/completions/command-registry.d.ts +7 -0
- package/dist/core/completions/command-registry.js +456 -0
- package/dist/core/completions/completion-provider.d.ts +60 -0
- package/dist/core/completions/completion-provider.js +102 -0
- package/dist/core/completions/factory.d.ts +64 -0
- package/dist/core/completions/factory.js +75 -0
- package/dist/core/completions/generators/bash-generator.d.ts +32 -0
- package/dist/core/completions/generators/bash-generator.js +174 -0
- package/dist/core/completions/generators/fish-generator.d.ts +32 -0
- package/dist/core/completions/generators/fish-generator.js +157 -0
- package/dist/core/completions/generators/powershell-generator.d.ts +33 -0
- package/dist/core/completions/generators/powershell-generator.js +207 -0
- package/dist/core/completions/generators/zsh-generator.d.ts +44 -0
- package/dist/core/completions/generators/zsh-generator.js +250 -0
- package/dist/core/completions/installers/bash-installer.d.ts +87 -0
- package/dist/core/completions/installers/bash-installer.js +318 -0
- package/dist/core/completions/installers/fish-installer.d.ts +43 -0
- package/dist/core/completions/installers/fish-installer.js +143 -0
- package/dist/core/completions/installers/powershell-installer.d.ts +88 -0
- package/dist/core/completions/installers/powershell-installer.js +327 -0
- package/dist/core/completions/installers/zsh-installer.d.ts +125 -0
- package/dist/core/completions/installers/zsh-installer.js +449 -0
- package/dist/core/completions/templates/bash-templates.d.ts +6 -0
- package/dist/core/completions/templates/bash-templates.js +24 -0
- package/dist/core/completions/templates/fish-templates.d.ts +7 -0
- package/dist/core/completions/templates/fish-templates.js +39 -0
- package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
- package/dist/core/completions/templates/powershell-templates.js +25 -0
- package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
- package/dist/core/completions/templates/zsh-templates.js +36 -0
- package/dist/core/completions/types.d.ts +79 -0
- package/dist/core/completions/types.js +2 -0
- package/dist/core/config-prompts.d.ts +9 -0
- package/dist/core/config-prompts.js +34 -0
- package/dist/core/config-schema.d.ts +76 -0
- package/dist/core/config-schema.js +200 -0
- package/dist/core/config.d.ts +16 -0
- package/dist/core/config.js +30 -0
- package/dist/core/configurators/agents.d.ts +8 -0
- package/dist/core/configurators/agents.js +15 -0
- package/dist/core/configurators/base.d.ts +7 -0
- package/dist/core/configurators/base.js +2 -0
- package/dist/core/configurators/claude.d.ts +8 -0
- package/dist/core/configurators/claude.js +15 -0
- package/dist/core/configurators/cline.d.ts +8 -0
- package/dist/core/configurators/cline.js +15 -0
- package/dist/core/configurators/codebuddy.d.ts +8 -0
- package/dist/core/configurators/codebuddy.js +15 -0
- package/dist/core/configurators/costrict.d.ts +8 -0
- package/dist/core/configurators/costrict.js +15 -0
- package/dist/core/configurators/iflow.d.ts +8 -0
- package/dist/core/configurators/iflow.js +15 -0
- package/dist/core/configurators/qoder.d.ts +30 -0
- package/dist/core/configurators/qoder.js +42 -0
- package/dist/core/configurators/qwen.d.ts +24 -0
- package/dist/core/configurators/qwen.js +37 -0
- package/dist/core/configurators/registry.d.ts +9 -0
- package/dist/core/configurators/registry.js +43 -0
- package/dist/core/configurators/slash/amazon-q.d.ts +9 -0
- package/dist/core/configurators/slash/amazon-q.js +46 -0
- package/dist/core/configurators/slash/antigravity.d.ts +9 -0
- package/dist/core/configurators/slash/antigravity.js +23 -0
- package/dist/core/configurators/slash/auggie.d.ts +9 -0
- package/dist/core/configurators/slash/auggie.js +31 -0
- package/dist/core/configurators/slash/base.d.ts +19 -0
- package/dist/core/configurators/slash/base.js +69 -0
- package/dist/core/configurators/slash/claude.d.ts +9 -0
- package/dist/core/configurators/slash/claude.js +37 -0
- package/dist/core/configurators/slash/cline.d.ts +9 -0
- package/dist/core/configurators/slash/cline.js +23 -0
- package/dist/core/configurators/slash/codebuddy.d.ts +9 -0
- package/dist/core/configurators/slash/codebuddy.js +34 -0
- package/dist/core/configurators/slash/codex.d.ts +14 -0
- package/dist/core/configurators/slash/codex.js +109 -0
- package/dist/core/configurators/slash/continue.d.ts +9 -0
- package/dist/core/configurators/slash/continue.js +46 -0
- package/dist/core/configurators/slash/costrict.d.ts +9 -0
- package/dist/core/configurators/slash/costrict.js +31 -0
- package/dist/core/configurators/slash/crush.d.ts +9 -0
- package/dist/core/configurators/slash/crush.js +37 -0
- package/dist/core/configurators/slash/cursor.d.ts +9 -0
- package/dist/core/configurators/slash/cursor.js +37 -0
- package/dist/core/configurators/slash/factory.d.ts +10 -0
- package/dist/core/configurators/slash/factory.js +35 -0
- package/dist/core/configurators/slash/gemini.d.ts +9 -0
- package/dist/core/configurators/slash/gemini.js +22 -0
- package/dist/core/configurators/slash/github-copilot.d.ts +9 -0
- package/dist/core/configurators/slash/github-copilot.js +34 -0
- package/dist/core/configurators/slash/iflow.d.ts +9 -0
- package/dist/core/configurators/slash/iflow.js +37 -0
- package/dist/core/configurators/slash/kilocode.d.ts +9 -0
- package/dist/core/configurators/slash/kilocode.js +17 -0
- package/dist/core/configurators/slash/opencode.d.ts +12 -0
- package/dist/core/configurators/slash/opencode.js +72 -0
- package/dist/core/configurators/slash/qoder.d.ts +35 -0
- package/dist/core/configurators/slash/qoder.js +76 -0
- package/dist/core/configurators/slash/qwen.d.ts +32 -0
- package/dist/core/configurators/slash/qwen.js +49 -0
- package/dist/core/configurators/slash/registry.d.ts +8 -0
- package/dist/core/configurators/slash/registry.js +78 -0
- package/dist/core/configurators/slash/roocode.d.ts +9 -0
- package/dist/core/configurators/slash/roocode.js +23 -0
- package/dist/core/configurators/slash/toml-base.d.ts +10 -0
- package/dist/core/configurators/slash/toml-base.js +53 -0
- package/dist/core/configurators/slash/windsurf.d.ts +9 -0
- package/dist/core/configurators/slash/windsurf.js +23 -0
- package/dist/core/converters/json-converter.d.ts +6 -0
- package/dist/core/converters/json-converter.js +51 -0
- package/dist/core/global-config.d.ts +39 -0
- package/dist/core/global-config.js +115 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +3 -0
- package/dist/core/init.d.ts +52 -0
- package/dist/core/init.js +644 -0
- package/dist/core/list.d.ts +9 -0
- package/dist/core/list.js +171 -0
- package/dist/core/parsers/change-parser.d.ts +13 -0
- package/dist/core/parsers/change-parser.js +193 -0
- package/dist/core/parsers/markdown-parser.d.ts +22 -0
- package/dist/core/parsers/markdown-parser.js +187 -0
- package/dist/core/parsers/requirement-blocks.d.ts +37 -0
- package/dist/core/parsers/requirement-blocks.js +201 -0
- package/dist/core/project-config.d.ts +64 -0
- package/dist/core/project-config.js +223 -0
- package/dist/core/schemas/base.schema.d.ts +13 -0
- package/dist/core/schemas/base.schema.js +13 -0
- package/dist/core/schemas/change.schema.d.ts +73 -0
- package/dist/core/schemas/change.schema.js +31 -0
- package/dist/core/schemas/index.d.ts +4 -0
- package/dist/core/schemas/index.js +4 -0
- package/dist/core/schemas/spec.schema.d.ts +18 -0
- package/dist/core/schemas/spec.schema.js +15 -0
- package/dist/core/specs-apply.d.ts +73 -0
- package/dist/core/specs-apply.js +384 -0
- package/dist/core/styles/palette.d.ts +7 -0
- package/dist/core/styles/palette.js +8 -0
- package/dist/core/templates/agents-root-stub.d.ts +2 -0
- package/dist/core/templates/agents-root-stub.js +17 -0
- package/dist/core/templates/agents-template.d.ts +2 -0
- package/dist/core/templates/agents-template.js +458 -0
- package/dist/core/templates/claude-template.d.ts +2 -0
- package/dist/core/templates/claude-template.js +2 -0
- package/dist/core/templates/cline-template.d.ts +2 -0
- package/dist/core/templates/cline-template.js +2 -0
- package/dist/core/templates/costrict-template.d.ts +2 -0
- package/dist/core/templates/costrict-template.js +2 -0
- package/dist/core/templates/index.d.ts +17 -0
- package/dist/core/templates/index.js +37 -0
- package/dist/core/templates/project-template.d.ts +8 -0
- package/dist/core/templates/project-template.js +32 -0
- package/dist/core/templates/slash-command-templates.d.ts +4 -0
- package/dist/core/templates/slash-command-templates.js +49 -0
- package/dist/core/update.d.ts +4 -0
- package/dist/core/update.js +88 -0
- package/dist/core/validation/constants.d.ts +34 -0
- package/dist/core/validation/constants.js +40 -0
- package/dist/core/validation/types.d.ts +18 -0
- package/dist/core/validation/types.js +2 -0
- package/dist/core/validation/validator.d.ts +33 -0
- package/dist/core/validation/validator.js +409 -0
- package/dist/core/view.d.ts +8 -0
- package/dist/core/view.js +168 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/telemetry/config.d.ts +32 -0
- package/dist/telemetry/config.js +68 -0
- package/dist/telemetry/index.d.ts +31 -0
- package/dist/telemetry/index.js +103 -0
- package/dist/utils/file-system.d.ts +25 -0
- package/dist/utils/file-system.js +218 -0
- package/dist/utils/interactive.d.ts +18 -0
- package/dist/utils/interactive.js +21 -0
- package/dist/utils/item-discovery.d.ts +4 -0
- package/dist/utils/item-discovery.js +72 -0
- package/dist/utils/match.d.ts +3 -0
- package/dist/utils/match.js +22 -0
- package/dist/utils/shell-detection.d.ts +20 -0
- package/dist/utils/shell-detection.js +41 -0
- package/dist/utils/task-progress.d.ts +8 -0
- package/dist/utils/task-progress.js +36 -0
- package/package.json +82 -0
- package/scripts/postinstall.js +147 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { FileSystemUtils } from '../utils/file-system.js';
|
|
3
|
+
import { LIGHTSPEC_DIR_NAME } from './config.js';
|
|
4
|
+
import { ToolRegistry } from './configurators/registry.js';
|
|
5
|
+
import { SlashCommandRegistry } from './configurators/slash/registry.js';
|
|
6
|
+
import { agentsTemplate } from './templates/agents-template.js';
|
|
7
|
+
export class UpdateCommand {
|
|
8
|
+
async execute(projectPath) {
|
|
9
|
+
const resolvedProjectPath = path.resolve(projectPath);
|
|
10
|
+
const lightspecDirName = LIGHTSPEC_DIR_NAME;
|
|
11
|
+
const lightspecPath = path.join(resolvedProjectPath, lightspecDirName);
|
|
12
|
+
// 1. Check lightspec directory exists
|
|
13
|
+
if (!await FileSystemUtils.directoryExists(lightspecPath)) {
|
|
14
|
+
throw new Error(`No LightSpec directory found. Run 'lightspec init' first.`);
|
|
15
|
+
}
|
|
16
|
+
// 2. Update AGENTS.md (full replacement)
|
|
17
|
+
const agentsPath = path.join(lightspecPath, 'AGENTS.md');
|
|
18
|
+
await FileSystemUtils.writeFile(agentsPath, agentsTemplate);
|
|
19
|
+
// 3. Update existing AI tool configuration files only
|
|
20
|
+
const configurators = ToolRegistry.getAll();
|
|
21
|
+
const slashConfigurators = SlashCommandRegistry.getAll();
|
|
22
|
+
const updatedFiles = [];
|
|
23
|
+
const createdFiles = [];
|
|
24
|
+
const failedFiles = [];
|
|
25
|
+
const updatedSlashFiles = [];
|
|
26
|
+
const failedSlashTools = [];
|
|
27
|
+
for (const configurator of configurators) {
|
|
28
|
+
const configFilePath = path.join(resolvedProjectPath, configurator.configFileName);
|
|
29
|
+
const fileExists = await FileSystemUtils.fileExists(configFilePath);
|
|
30
|
+
const shouldConfigure = fileExists || configurator.configFileName === 'AGENTS.md';
|
|
31
|
+
if (!shouldConfigure) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
if (fileExists && !await FileSystemUtils.canWriteFile(configFilePath)) {
|
|
36
|
+
throw new Error(`Insufficient permissions to modify ${configurator.configFileName}`);
|
|
37
|
+
}
|
|
38
|
+
await configurator.configure(resolvedProjectPath, lightspecPath);
|
|
39
|
+
updatedFiles.push(configurator.configFileName);
|
|
40
|
+
if (!fileExists) {
|
|
41
|
+
createdFiles.push(configurator.configFileName);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
failedFiles.push(configurator.configFileName);
|
|
46
|
+
console.error(`Failed to update ${configurator.configFileName}: ${error instanceof Error ? error.message : String(error)}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const slashConfigurator of slashConfigurators) {
|
|
50
|
+
if (!slashConfigurator.isAvailable) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const updated = await slashConfigurator.updateExisting(resolvedProjectPath, lightspecPath);
|
|
55
|
+
updatedSlashFiles.push(...updated);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
failedSlashTools.push(slashConfigurator.toolId);
|
|
59
|
+
console.error(`Failed to update slash commands for ${slashConfigurator.toolId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const summaryParts = [];
|
|
63
|
+
const instructionFiles = ['lightspec/AGENTS.md'];
|
|
64
|
+
if (updatedFiles.includes('AGENTS.md')) {
|
|
65
|
+
instructionFiles.push(createdFiles.includes('AGENTS.md') ? 'AGENTS.md (created)' : 'AGENTS.md');
|
|
66
|
+
}
|
|
67
|
+
summaryParts.push(`Updated LightSpec instructions (${instructionFiles.join(', ')})`);
|
|
68
|
+
const aiToolFiles = updatedFiles.filter((file) => file !== 'AGENTS.md');
|
|
69
|
+
if (aiToolFiles.length > 0) {
|
|
70
|
+
summaryParts.push(`Updated AI tool files: ${aiToolFiles.join(', ')}`);
|
|
71
|
+
}
|
|
72
|
+
if (updatedSlashFiles.length > 0) {
|
|
73
|
+
// Normalize to forward slashes for cross-platform log consistency
|
|
74
|
+
const normalized = updatedSlashFiles.map((p) => FileSystemUtils.toPosixPath(p));
|
|
75
|
+
summaryParts.push(`Updated slash commands: ${normalized.join(', ')}`);
|
|
76
|
+
}
|
|
77
|
+
const failedItems = [
|
|
78
|
+
...failedFiles,
|
|
79
|
+
...failedSlashTools.map((toolId) => `slash command refresh (${toolId})`),
|
|
80
|
+
];
|
|
81
|
+
if (failedItems.length > 0) {
|
|
82
|
+
summaryParts.push(`Failed to update: ${failedItems.join(', ')}`);
|
|
83
|
+
}
|
|
84
|
+
console.log(summaryParts.join(' | '));
|
|
85
|
+
// No additional notes
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=update.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation threshold constants
|
|
3
|
+
*/
|
|
4
|
+
export declare const MIN_WHY_SECTION_LENGTH = 50;
|
|
5
|
+
export declare const MIN_PURPOSE_LENGTH = 50;
|
|
6
|
+
export declare const MAX_WHY_SECTION_LENGTH = 1000;
|
|
7
|
+
export declare const MAX_REQUIREMENT_TEXT_LENGTH = 500;
|
|
8
|
+
export declare const MAX_DELTAS_PER_CHANGE = 10;
|
|
9
|
+
export declare const VALIDATION_MESSAGES: {
|
|
10
|
+
readonly SCENARIO_EMPTY: "Scenario text cannot be empty";
|
|
11
|
+
readonly REQUIREMENT_EMPTY: "Requirement text cannot be empty";
|
|
12
|
+
readonly REQUIREMENT_NO_SHALL: "Requirement must contain SHALL or MUST keyword";
|
|
13
|
+
readonly REQUIREMENT_NO_SCENARIOS: "Requirement must have at least one scenario";
|
|
14
|
+
readonly SPEC_NAME_EMPTY: "Spec name cannot be empty";
|
|
15
|
+
readonly SPEC_PURPOSE_EMPTY: "Purpose section cannot be empty";
|
|
16
|
+
readonly SPEC_NO_REQUIREMENTS: "Spec must have at least one requirement";
|
|
17
|
+
readonly CHANGE_NAME_EMPTY: "Change name cannot be empty";
|
|
18
|
+
readonly CHANGE_WHY_TOO_SHORT: "Why section must be at least 50 characters";
|
|
19
|
+
readonly CHANGE_WHY_TOO_LONG: "Why section should not exceed 1000 characters";
|
|
20
|
+
readonly CHANGE_WHAT_EMPTY: "What Changes section cannot be empty";
|
|
21
|
+
readonly CHANGE_NO_DELTAS: "Change must have at least one delta";
|
|
22
|
+
readonly CHANGE_TOO_MANY_DELTAS: "Consider splitting changes with more than 10 deltas";
|
|
23
|
+
readonly DELTA_SPEC_EMPTY: "Spec name cannot be empty";
|
|
24
|
+
readonly DELTA_DESCRIPTION_EMPTY: "Delta description cannot be empty";
|
|
25
|
+
readonly PURPOSE_TOO_BRIEF: "Purpose section is too brief (less than 50 characters)";
|
|
26
|
+
readonly REQUIREMENT_TOO_LONG: "Requirement text is very long (>500 characters). Consider breaking it down.";
|
|
27
|
+
readonly DELTA_DESCRIPTION_TOO_BRIEF: "Delta description is too brief";
|
|
28
|
+
readonly DELTA_MISSING_REQUIREMENTS: "Delta should include requirements";
|
|
29
|
+
readonly GUIDE_NO_DELTAS: "No deltas found. Ensure your change has a specs/ directory with capability folders (e.g. specs/http-server/spec.md) containing .md files that use delta headers (## ADDED/MODIFIED/REMOVED/RENAMED Requirements) and that each requirement includes at least one \"#### Scenario:\" block. Tip: run \"lightspec change show <change-id> --json --deltas-only\" to inspect parsed deltas.";
|
|
30
|
+
readonly GUIDE_MISSING_SPEC_SECTIONS: "Missing required sections. Expected headers: \"## Purpose\" and \"## Requirements\". Example:\n## Purpose\n[brief purpose]\n\n## Requirements\n### Requirement: Clear requirement statement\nUsers SHALL ...\n\n#### Scenario: Descriptive name\n- **WHEN** ...\n- **THEN** ...";
|
|
31
|
+
readonly GUIDE_MISSING_CHANGE_SECTIONS: "Missing required sections. Expected headers: \"## Why\" and \"## What Changes\". Ensure deltas are documented in specs/ using delta headers.";
|
|
32
|
+
readonly GUIDE_SCENARIO_FORMAT: "Scenarios must use level-4 headers. Convert bullet lists into:\n#### Scenario: Short name\n- **WHEN** ...\n- **THEN** ...\n- **AND** ...";
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation threshold constants
|
|
3
|
+
*/
|
|
4
|
+
// Minimum character lengths
|
|
5
|
+
export const MIN_WHY_SECTION_LENGTH = 50;
|
|
6
|
+
export const MIN_PURPOSE_LENGTH = 50;
|
|
7
|
+
// Maximum character/item limits
|
|
8
|
+
export const MAX_WHY_SECTION_LENGTH = 1000;
|
|
9
|
+
export const MAX_REQUIREMENT_TEXT_LENGTH = 500;
|
|
10
|
+
export const MAX_DELTAS_PER_CHANGE = 10;
|
|
11
|
+
// Validation messages
|
|
12
|
+
export const VALIDATION_MESSAGES = {
|
|
13
|
+
// Required content
|
|
14
|
+
SCENARIO_EMPTY: 'Scenario text cannot be empty',
|
|
15
|
+
REQUIREMENT_EMPTY: 'Requirement text cannot be empty',
|
|
16
|
+
REQUIREMENT_NO_SHALL: 'Requirement must contain SHALL or MUST keyword',
|
|
17
|
+
REQUIREMENT_NO_SCENARIOS: 'Requirement must have at least one scenario',
|
|
18
|
+
SPEC_NAME_EMPTY: 'Spec name cannot be empty',
|
|
19
|
+
SPEC_PURPOSE_EMPTY: 'Purpose section cannot be empty',
|
|
20
|
+
SPEC_NO_REQUIREMENTS: 'Spec must have at least one requirement',
|
|
21
|
+
CHANGE_NAME_EMPTY: 'Change name cannot be empty',
|
|
22
|
+
CHANGE_WHY_TOO_SHORT: `Why section must be at least ${MIN_WHY_SECTION_LENGTH} characters`,
|
|
23
|
+
CHANGE_WHY_TOO_LONG: `Why section should not exceed ${MAX_WHY_SECTION_LENGTH} characters`,
|
|
24
|
+
CHANGE_WHAT_EMPTY: 'What Changes section cannot be empty',
|
|
25
|
+
CHANGE_NO_DELTAS: 'Change must have at least one delta',
|
|
26
|
+
CHANGE_TOO_MANY_DELTAS: `Consider splitting changes with more than ${MAX_DELTAS_PER_CHANGE} deltas`,
|
|
27
|
+
DELTA_SPEC_EMPTY: 'Spec name cannot be empty',
|
|
28
|
+
DELTA_DESCRIPTION_EMPTY: 'Delta description cannot be empty',
|
|
29
|
+
// Warnings
|
|
30
|
+
PURPOSE_TOO_BRIEF: `Purpose section is too brief (less than ${MIN_PURPOSE_LENGTH} characters)`,
|
|
31
|
+
REQUIREMENT_TOO_LONG: `Requirement text is very long (>${MAX_REQUIREMENT_TEXT_LENGTH} characters). Consider breaking it down.`,
|
|
32
|
+
DELTA_DESCRIPTION_TOO_BRIEF: 'Delta description is too brief',
|
|
33
|
+
DELTA_MISSING_REQUIREMENTS: 'Delta should include requirements',
|
|
34
|
+
// Guidance snippets (appended to primary messages for remediation)
|
|
35
|
+
GUIDE_NO_DELTAS: 'No deltas found. Ensure your change has a specs/ directory with capability folders (e.g. specs/http-server/spec.md) containing .md files that use delta headers (## ADDED/MODIFIED/REMOVED/RENAMED Requirements) and that each requirement includes at least one "#### Scenario:" block. Tip: run "lightspec change show <change-id> --json --deltas-only" to inspect parsed deltas.',
|
|
36
|
+
GUIDE_MISSING_SPEC_SECTIONS: 'Missing required sections. Expected headers: "## Purpose" and "## Requirements". Example:\n## Purpose\n[brief purpose]\n\n## Requirements\n### Requirement: Clear requirement statement\nUsers SHALL ...\n\n#### Scenario: Descriptive name\n- **WHEN** ...\n- **THEN** ...',
|
|
37
|
+
GUIDE_MISSING_CHANGE_SECTIONS: 'Missing required sections. Expected headers: "## Why" and "## What Changes". Ensure deltas are documented in specs/ using delta headers.',
|
|
38
|
+
GUIDE_SCENARIO_FORMAT: 'Scenarios must use level-4 headers. Convert bullet lists into:\n#### Scenario: Short name\n- **WHEN** ...\n- **THEN** ...\n- **AND** ...',
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type ValidationLevel = 'ERROR' | 'WARNING' | 'INFO';
|
|
2
|
+
export interface ValidationIssue {
|
|
3
|
+
level: ValidationLevel;
|
|
4
|
+
path: string;
|
|
5
|
+
message: string;
|
|
6
|
+
line?: number;
|
|
7
|
+
column?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ValidationReport {
|
|
10
|
+
valid: boolean;
|
|
11
|
+
issues: ValidationIssue[];
|
|
12
|
+
summary: {
|
|
13
|
+
errors: number;
|
|
14
|
+
warnings: number;
|
|
15
|
+
info: number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ValidationReport } from './types.js';
|
|
2
|
+
export declare class Validator {
|
|
3
|
+
private strictMode;
|
|
4
|
+
constructor(strictMode?: boolean);
|
|
5
|
+
validateSpec(filePath: string): Promise<ValidationReport>;
|
|
6
|
+
/**
|
|
7
|
+
* Validate spec content from a string (used for pre-write validation of rebuilt specs)
|
|
8
|
+
*/
|
|
9
|
+
validateSpecContent(specName: string, content: string): Promise<ValidationReport>;
|
|
10
|
+
validateChange(filePath: string): Promise<ValidationReport>;
|
|
11
|
+
/**
|
|
12
|
+
* Validate delta-formatted spec files under a change directory.
|
|
13
|
+
* Enforces:
|
|
14
|
+
* - At least one delta across all files
|
|
15
|
+
* - ADDED/MODIFIED: each requirement has SHALL/MUST and at least one scenario
|
|
16
|
+
* - REMOVED: names only; no scenario/description required
|
|
17
|
+
* - RENAMED: pairs well-formed
|
|
18
|
+
* - No duplicates within sections; no cross-section conflicts per spec
|
|
19
|
+
*/
|
|
20
|
+
validateChangeDeltaSpecs(changeDir: string): Promise<ValidationReport>;
|
|
21
|
+
private convertZodErrors;
|
|
22
|
+
private applySpecRules;
|
|
23
|
+
private applyChangeRules;
|
|
24
|
+
private enrichTopLevelError;
|
|
25
|
+
private extractNameFromPath;
|
|
26
|
+
private createReport;
|
|
27
|
+
isValid(report: ValidationReport): boolean;
|
|
28
|
+
private extractRequirementText;
|
|
29
|
+
private containsShallOrMust;
|
|
30
|
+
private countScenarios;
|
|
31
|
+
private formatSectionList;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { readFileSync, promises as fs } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { SpecSchema, ChangeSchema } from '../schemas/index.js';
|
|
4
|
+
import { MarkdownParser } from '../parsers/markdown-parser.js';
|
|
5
|
+
import { ChangeParser } from '../parsers/change-parser.js';
|
|
6
|
+
import { MIN_PURPOSE_LENGTH, MAX_REQUIREMENT_TEXT_LENGTH, VALIDATION_MESSAGES } from './constants.js';
|
|
7
|
+
import { parseDeltaSpec, normalizeRequirementName } from '../parsers/requirement-blocks.js';
|
|
8
|
+
import { FileSystemUtils } from '../../utils/file-system.js';
|
|
9
|
+
export class Validator {
|
|
10
|
+
strictMode;
|
|
11
|
+
constructor(strictMode = false) {
|
|
12
|
+
this.strictMode = strictMode;
|
|
13
|
+
}
|
|
14
|
+
async validateSpec(filePath) {
|
|
15
|
+
const issues = [];
|
|
16
|
+
const specName = this.extractNameFromPath(filePath);
|
|
17
|
+
try {
|
|
18
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
19
|
+
const parser = new MarkdownParser(content);
|
|
20
|
+
const spec = parser.parseSpec(specName);
|
|
21
|
+
const result = SpecSchema.safeParse(spec);
|
|
22
|
+
if (!result.success) {
|
|
23
|
+
issues.push(...this.convertZodErrors(result.error));
|
|
24
|
+
}
|
|
25
|
+
issues.push(...this.applySpecRules(spec, content));
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
const baseMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
29
|
+
const enriched = this.enrichTopLevelError(specName, baseMessage);
|
|
30
|
+
issues.push({
|
|
31
|
+
level: 'ERROR',
|
|
32
|
+
path: 'file',
|
|
33
|
+
message: enriched,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return this.createReport(issues);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Validate spec content from a string (used for pre-write validation of rebuilt specs)
|
|
40
|
+
*/
|
|
41
|
+
async validateSpecContent(specName, content) {
|
|
42
|
+
const issues = [];
|
|
43
|
+
try {
|
|
44
|
+
const parser = new MarkdownParser(content);
|
|
45
|
+
const spec = parser.parseSpec(specName);
|
|
46
|
+
const result = SpecSchema.safeParse(spec);
|
|
47
|
+
if (!result.success) {
|
|
48
|
+
issues.push(...this.convertZodErrors(result.error));
|
|
49
|
+
}
|
|
50
|
+
issues.push(...this.applySpecRules(spec, content));
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
const baseMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
54
|
+
const enriched = this.enrichTopLevelError(specName, baseMessage);
|
|
55
|
+
issues.push({ level: 'ERROR', path: 'file', message: enriched });
|
|
56
|
+
}
|
|
57
|
+
return this.createReport(issues);
|
|
58
|
+
}
|
|
59
|
+
async validateChange(filePath) {
|
|
60
|
+
const issues = [];
|
|
61
|
+
const changeName = this.extractNameFromPath(filePath);
|
|
62
|
+
try {
|
|
63
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
64
|
+
const changeDir = path.dirname(filePath);
|
|
65
|
+
const parser = new ChangeParser(content, changeDir);
|
|
66
|
+
const change = await parser.parseChangeWithDeltas(changeName);
|
|
67
|
+
const result = ChangeSchema.safeParse(change);
|
|
68
|
+
if (!result.success) {
|
|
69
|
+
issues.push(...this.convertZodErrors(result.error));
|
|
70
|
+
}
|
|
71
|
+
issues.push(...this.applyChangeRules(change, content));
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
const baseMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
75
|
+
const enriched = this.enrichTopLevelError(changeName, baseMessage);
|
|
76
|
+
issues.push({
|
|
77
|
+
level: 'ERROR',
|
|
78
|
+
path: 'file',
|
|
79
|
+
message: enriched,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return this.createReport(issues);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Validate delta-formatted spec files under a change directory.
|
|
86
|
+
* Enforces:
|
|
87
|
+
* - At least one delta across all files
|
|
88
|
+
* - ADDED/MODIFIED: each requirement has SHALL/MUST and at least one scenario
|
|
89
|
+
* - REMOVED: names only; no scenario/description required
|
|
90
|
+
* - RENAMED: pairs well-formed
|
|
91
|
+
* - No duplicates within sections; no cross-section conflicts per spec
|
|
92
|
+
*/
|
|
93
|
+
async validateChangeDeltaSpecs(changeDir) {
|
|
94
|
+
const issues = [];
|
|
95
|
+
const specsDir = path.join(changeDir, 'specs');
|
|
96
|
+
let totalDeltas = 0;
|
|
97
|
+
const missingHeaderSpecs = [];
|
|
98
|
+
const emptySectionSpecs = [];
|
|
99
|
+
try {
|
|
100
|
+
const entries = await fs.readdir(specsDir, { withFileTypes: true });
|
|
101
|
+
for (const entry of entries) {
|
|
102
|
+
if (!entry.isDirectory())
|
|
103
|
+
continue;
|
|
104
|
+
const specName = entry.name;
|
|
105
|
+
const specFile = path.join(specsDir, specName, 'spec.md');
|
|
106
|
+
let content;
|
|
107
|
+
try {
|
|
108
|
+
content = await fs.readFile(specFile, 'utf-8');
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const plan = parseDeltaSpec(content);
|
|
114
|
+
const entryPath = `${specName}/spec.md`;
|
|
115
|
+
const sectionNames = [];
|
|
116
|
+
if (plan.sectionPresence.added)
|
|
117
|
+
sectionNames.push('## ADDED Requirements');
|
|
118
|
+
if (plan.sectionPresence.modified)
|
|
119
|
+
sectionNames.push('## MODIFIED Requirements');
|
|
120
|
+
if (plan.sectionPresence.removed)
|
|
121
|
+
sectionNames.push('## REMOVED Requirements');
|
|
122
|
+
if (plan.sectionPresence.renamed)
|
|
123
|
+
sectionNames.push('## RENAMED Requirements');
|
|
124
|
+
const hasSections = sectionNames.length > 0;
|
|
125
|
+
const hasEntries = plan.added.length + plan.modified.length + plan.removed.length + plan.renamed.length > 0;
|
|
126
|
+
if (!hasEntries) {
|
|
127
|
+
if (hasSections)
|
|
128
|
+
emptySectionSpecs.push({ path: entryPath, sections: sectionNames });
|
|
129
|
+
else
|
|
130
|
+
missingHeaderSpecs.push(entryPath);
|
|
131
|
+
}
|
|
132
|
+
const addedNames = new Set();
|
|
133
|
+
const modifiedNames = new Set();
|
|
134
|
+
const removedNames = new Set();
|
|
135
|
+
const renamedFrom = new Set();
|
|
136
|
+
const renamedTo = new Set();
|
|
137
|
+
// Validate ADDED
|
|
138
|
+
for (const block of plan.added) {
|
|
139
|
+
const key = normalizeRequirementName(block.name);
|
|
140
|
+
totalDeltas++;
|
|
141
|
+
if (addedNames.has(key)) {
|
|
142
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `Duplicate requirement in ADDED: "${block.name}"` });
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
addedNames.add(key);
|
|
146
|
+
}
|
|
147
|
+
const requirementText = this.extractRequirementText(block.raw);
|
|
148
|
+
if (!requirementText) {
|
|
149
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `ADDED "${block.name}" is missing requirement text` });
|
|
150
|
+
}
|
|
151
|
+
else if (!this.containsShallOrMust(requirementText)) {
|
|
152
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `ADDED "${block.name}" must contain SHALL or MUST` });
|
|
153
|
+
}
|
|
154
|
+
const scenarioCount = this.countScenarios(block.raw);
|
|
155
|
+
if (scenarioCount < 1) {
|
|
156
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `ADDED "${block.name}" must include at least one scenario` });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Validate MODIFIED
|
|
160
|
+
for (const block of plan.modified) {
|
|
161
|
+
const key = normalizeRequirementName(block.name);
|
|
162
|
+
totalDeltas++;
|
|
163
|
+
if (modifiedNames.has(key)) {
|
|
164
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `Duplicate requirement in MODIFIED: "${block.name}"` });
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
modifiedNames.add(key);
|
|
168
|
+
}
|
|
169
|
+
const requirementText = this.extractRequirementText(block.raw);
|
|
170
|
+
if (!requirementText) {
|
|
171
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `MODIFIED "${block.name}" is missing requirement text` });
|
|
172
|
+
}
|
|
173
|
+
else if (!this.containsShallOrMust(requirementText)) {
|
|
174
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `MODIFIED "${block.name}" must contain SHALL or MUST` });
|
|
175
|
+
}
|
|
176
|
+
const scenarioCount = this.countScenarios(block.raw);
|
|
177
|
+
if (scenarioCount < 1) {
|
|
178
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `MODIFIED "${block.name}" must include at least one scenario` });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Validate REMOVED (names only)
|
|
182
|
+
for (const name of plan.removed) {
|
|
183
|
+
const key = normalizeRequirementName(name);
|
|
184
|
+
totalDeltas++;
|
|
185
|
+
if (removedNames.has(key)) {
|
|
186
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `Duplicate requirement in REMOVED: "${name}"` });
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
removedNames.add(key);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// Validate RENAMED pairs
|
|
193
|
+
for (const { from, to } of plan.renamed) {
|
|
194
|
+
const fromKey = normalizeRequirementName(from);
|
|
195
|
+
const toKey = normalizeRequirementName(to);
|
|
196
|
+
totalDeltas++;
|
|
197
|
+
if (renamedFrom.has(fromKey)) {
|
|
198
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `Duplicate FROM in RENAMED: "${from}"` });
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
renamedFrom.add(fromKey);
|
|
202
|
+
}
|
|
203
|
+
if (renamedTo.has(toKey)) {
|
|
204
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `Duplicate TO in RENAMED: "${to}"` });
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
renamedTo.add(toKey);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Cross-section conflicts (within the same spec file)
|
|
211
|
+
for (const n of modifiedNames) {
|
|
212
|
+
if (removedNames.has(n)) {
|
|
213
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `Requirement present in both MODIFIED and REMOVED: "${n}"` });
|
|
214
|
+
}
|
|
215
|
+
if (addedNames.has(n)) {
|
|
216
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `Requirement present in both MODIFIED and ADDED: "${n}"` });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
for (const n of addedNames) {
|
|
220
|
+
if (removedNames.has(n)) {
|
|
221
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `Requirement present in both ADDED and REMOVED: "${n}"` });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for (const { from, to } of plan.renamed) {
|
|
225
|
+
const fromKey = normalizeRequirementName(from);
|
|
226
|
+
const toKey = normalizeRequirementName(to);
|
|
227
|
+
if (modifiedNames.has(fromKey)) {
|
|
228
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `MODIFIED references old name from RENAMED. Use new header for "${to}"` });
|
|
229
|
+
}
|
|
230
|
+
if (addedNames.has(toKey)) {
|
|
231
|
+
issues.push({ level: 'ERROR', path: entryPath, message: `RENAMED TO collides with ADDED for "${to}"` });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
// If no specs dir, treat as no deltas
|
|
238
|
+
}
|
|
239
|
+
for (const { path: specPath, sections } of emptySectionSpecs) {
|
|
240
|
+
issues.push({
|
|
241
|
+
level: 'ERROR',
|
|
242
|
+
path: specPath,
|
|
243
|
+
message: `Delta sections ${this.formatSectionList(sections)} were found, but no requirement entries parsed. Ensure each section includes at least one "### Requirement:" block (REMOVED may use bullet list syntax).`,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
for (const path of missingHeaderSpecs) {
|
|
247
|
+
issues.push({
|
|
248
|
+
level: 'ERROR',
|
|
249
|
+
path,
|
|
250
|
+
message: 'No delta sections found. Add headers such as "## ADDED Requirements" or move non-delta notes outside specs/.',
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
if (totalDeltas === 0) {
|
|
254
|
+
issues.push({ level: 'ERROR', path: 'file', message: this.enrichTopLevelError('change', VALIDATION_MESSAGES.CHANGE_NO_DELTAS) });
|
|
255
|
+
}
|
|
256
|
+
return this.createReport(issues);
|
|
257
|
+
}
|
|
258
|
+
convertZodErrors(error) {
|
|
259
|
+
return error.issues.map(err => {
|
|
260
|
+
let message = err.message;
|
|
261
|
+
if (message === VALIDATION_MESSAGES.CHANGE_NO_DELTAS) {
|
|
262
|
+
message = `${message}. ${VALIDATION_MESSAGES.GUIDE_NO_DELTAS}`;
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
level: 'ERROR',
|
|
266
|
+
path: err.path.join('.'),
|
|
267
|
+
message,
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
applySpecRules(spec, content) {
|
|
272
|
+
const issues = [];
|
|
273
|
+
if (spec.overview.length < MIN_PURPOSE_LENGTH) {
|
|
274
|
+
issues.push({
|
|
275
|
+
level: 'WARNING',
|
|
276
|
+
path: 'overview',
|
|
277
|
+
message: VALIDATION_MESSAGES.PURPOSE_TOO_BRIEF,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
spec.requirements.forEach((req, index) => {
|
|
281
|
+
if (req.text.length > MAX_REQUIREMENT_TEXT_LENGTH) {
|
|
282
|
+
issues.push({
|
|
283
|
+
level: 'INFO',
|
|
284
|
+
path: `requirements[${index}]`,
|
|
285
|
+
message: VALIDATION_MESSAGES.REQUIREMENT_TOO_LONG,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
if (req.scenarios.length === 0) {
|
|
289
|
+
issues.push({
|
|
290
|
+
level: 'WARNING',
|
|
291
|
+
path: `requirements[${index}].scenarios`,
|
|
292
|
+
message: `${VALIDATION_MESSAGES.REQUIREMENT_NO_SCENARIOS}. ${VALIDATION_MESSAGES.GUIDE_SCENARIO_FORMAT}`,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
return issues;
|
|
297
|
+
}
|
|
298
|
+
applyChangeRules(change, content) {
|
|
299
|
+
const issues = [];
|
|
300
|
+
const MIN_DELTA_DESCRIPTION_LENGTH = 10;
|
|
301
|
+
change.deltas.forEach((delta, index) => {
|
|
302
|
+
if (!delta.description || delta.description.length < MIN_DELTA_DESCRIPTION_LENGTH) {
|
|
303
|
+
issues.push({
|
|
304
|
+
level: 'WARNING',
|
|
305
|
+
path: `deltas[${index}].description`,
|
|
306
|
+
message: VALIDATION_MESSAGES.DELTA_DESCRIPTION_TOO_BRIEF,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if ((delta.operation === 'ADDED' || delta.operation === 'MODIFIED') &&
|
|
310
|
+
(!delta.requirements || delta.requirements.length === 0)) {
|
|
311
|
+
issues.push({
|
|
312
|
+
level: 'WARNING',
|
|
313
|
+
path: `deltas[${index}].requirements`,
|
|
314
|
+
message: `${delta.operation} ${VALIDATION_MESSAGES.DELTA_MISSING_REQUIREMENTS}`,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
return issues;
|
|
319
|
+
}
|
|
320
|
+
enrichTopLevelError(itemId, baseMessage) {
|
|
321
|
+
const msg = baseMessage.trim();
|
|
322
|
+
if (msg === VALIDATION_MESSAGES.CHANGE_NO_DELTAS) {
|
|
323
|
+
return `${msg}. ${VALIDATION_MESSAGES.GUIDE_NO_DELTAS}`;
|
|
324
|
+
}
|
|
325
|
+
if (msg.includes('Spec must have a Purpose section') || msg.includes('Spec must have a Requirements section')) {
|
|
326
|
+
return `${msg}. ${VALIDATION_MESSAGES.GUIDE_MISSING_SPEC_SECTIONS}`;
|
|
327
|
+
}
|
|
328
|
+
if (msg.includes('Change must have a Why section') || msg.includes('Change must have a What Changes section')) {
|
|
329
|
+
return `${msg}. ${VALIDATION_MESSAGES.GUIDE_MISSING_CHANGE_SECTIONS}`;
|
|
330
|
+
}
|
|
331
|
+
return msg;
|
|
332
|
+
}
|
|
333
|
+
extractNameFromPath(filePath) {
|
|
334
|
+
const normalizedPath = FileSystemUtils.toPosixPath(filePath);
|
|
335
|
+
const parts = normalizedPath.split('/');
|
|
336
|
+
// Look for the directory name after 'specs' or 'changes'
|
|
337
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
338
|
+
if (parts[i] === 'specs' || parts[i] === 'changes') {
|
|
339
|
+
if (i < parts.length - 1) {
|
|
340
|
+
return parts[i + 1];
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
// Fallback to filename without extension if not in expected structure
|
|
345
|
+
const fileName = parts[parts.length - 1] ?? '';
|
|
346
|
+
const dotIndex = fileName.lastIndexOf('.');
|
|
347
|
+
return dotIndex > 0 ? fileName.slice(0, dotIndex) : fileName;
|
|
348
|
+
}
|
|
349
|
+
createReport(issues) {
|
|
350
|
+
const errors = issues.filter(i => i.level === 'ERROR').length;
|
|
351
|
+
const warnings = issues.filter(i => i.level === 'WARNING').length;
|
|
352
|
+
const info = issues.filter(i => i.level === 'INFO').length;
|
|
353
|
+
const valid = this.strictMode
|
|
354
|
+
? errors === 0 && warnings === 0
|
|
355
|
+
: errors === 0;
|
|
356
|
+
return {
|
|
357
|
+
valid,
|
|
358
|
+
issues,
|
|
359
|
+
summary: {
|
|
360
|
+
errors,
|
|
361
|
+
warnings,
|
|
362
|
+
info,
|
|
363
|
+
},
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
isValid(report) {
|
|
367
|
+
return report.valid;
|
|
368
|
+
}
|
|
369
|
+
extractRequirementText(blockRaw) {
|
|
370
|
+
const lines = blockRaw.split('\n');
|
|
371
|
+
// Skip header line (index 0)
|
|
372
|
+
let i = 1;
|
|
373
|
+
// Find the first substantial text line, skipping metadata and blank lines
|
|
374
|
+
for (; i < lines.length; i++) {
|
|
375
|
+
const line = lines[i];
|
|
376
|
+
// Stop at scenario headers
|
|
377
|
+
if (/^####\s+/.test(line))
|
|
378
|
+
break;
|
|
379
|
+
const trimmed = line.trim();
|
|
380
|
+
// Skip blank lines
|
|
381
|
+
if (trimmed.length === 0)
|
|
382
|
+
continue;
|
|
383
|
+
// Skip metadata lines (lines starting with ** like **ID**, **Priority**, etc.)
|
|
384
|
+
if (/^\*\*[^*]+\*\*:/.test(trimmed))
|
|
385
|
+
continue;
|
|
386
|
+
// Found first non-metadata, non-blank line - this is the requirement text
|
|
387
|
+
return trimmed;
|
|
388
|
+
}
|
|
389
|
+
// No requirement text found
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
containsShallOrMust(text) {
|
|
393
|
+
return /\b(SHALL|MUST)\b/.test(text);
|
|
394
|
+
}
|
|
395
|
+
countScenarios(blockRaw) {
|
|
396
|
+
const matches = blockRaw.match(/^####\s+/gm);
|
|
397
|
+
return matches ? matches.length : 0;
|
|
398
|
+
}
|
|
399
|
+
formatSectionList(sections) {
|
|
400
|
+
if (sections.length === 0)
|
|
401
|
+
return '';
|
|
402
|
+
if (sections.length === 1)
|
|
403
|
+
return sections[0];
|
|
404
|
+
const head = sections.slice(0, -1);
|
|
405
|
+
const last = sections[sections.length - 1];
|
|
406
|
+
return `${head.join(', ')} and ${last}`;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
//# sourceMappingURL=validator.js.map
|