mddd-cli 4.0.4 → 4.0.6

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/bin/cli.js CHANGED
@@ -4,6 +4,7 @@ import { Command } from 'commander';
4
4
  import pc from 'picocolors';
5
5
  import { FileSystemService } from '../src/services/FileSystemService.js';
6
6
  import { InitService } from '../src/services/InitService.js';
7
+ import { validateMermaidSyntax } from '../src/commands/validator.js';
7
8
  import * as initCmd from '../src/commands/init.js';
8
9
 
9
10
  // ─── Services ────────────────────────────────────────────────────────────────
@@ -16,7 +17,7 @@ const program = new Command();
16
17
  program
17
18
  .name('md')
18
19
  .description('Manager for co-located specifications for Mermaid Diagram Driven Development (MDDD)')
19
- .version('4.0.4');
20
+ .version('4.0.6');
20
21
 
21
22
  // ==========================================
22
23
  // COMMAND: md init
@@ -33,5 +34,22 @@ program
33
34
  }
34
35
  });
35
36
 
37
+ program
38
+ .command('validate <target>')
39
+ .description('Validate Mermaid diagrams in .md files (returns JSON)')
40
+ .action(async (target) => {
41
+ // Executa a lógica de validação na memória
42
+ const result = await validateMermaidSyntax(target);
43
+
44
+ // Cospe APENAS o JSON no stdout para a IA ler de forma limpa
45
+ console.log(JSON.stringify(result));
46
+
47
+ // Controla o encerramento do processo com o exit code correto
48
+ if (!result.valid) {
49
+ process.exit(1);
50
+ }
51
+ process.exit(0);
52
+ });
53
+
36
54
  // ─── Parse ───────────────────────────────────────────────────────────────────
37
55
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mddd-cli",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
4
4
  "description": "Official CLI for modular, co-located, and versioned Mermaid Diagram Driven Development (MDDD).",
5
5
  "type": "module",
6
6
  "exports": "./bin/cli.js",
@@ -39,8 +39,8 @@
39
39
  },
40
40
  "homepage": "https://github.com/JulioCRFilho/mermaid-diagram-driven-development#readme",
41
41
  "dependencies": {
42
- "@mermaid-js/mermaid-cli": "^11.15.0",
42
+ "@mermaid-js/parser": "^1.1.1",
43
43
  "commander": "^12.0.0",
44
44
  "picocolors": "^1.0.0"
45
45
  }
46
- }
46
+ }
@@ -0,0 +1,57 @@
1
+ import { parse } from '@mermaid-js/parser';
2
+ import fs from 'node:fs';
3
+
4
+ /**
5
+ * Filtra o texto para extrair apenas o que está dentro dos blocos ```mermaid
6
+ */
7
+ function extractMermaidBlocks(text) {
8
+ const regex = /```mermaid\s*([\s\S]*?)\s*```/g;
9
+ const blocks = [];
10
+ let match;
11
+
12
+ while ((match = regex.exec(text)) !== null) {
13
+ if (match[1].trim()) {
14
+ blocks.push(match[1].trim());
15
+ }
16
+ }
17
+
18
+ return blocks;
19
+ }
20
+
21
+ /**
22
+ * Valida o conteúdo recebido (pode ser o caminho de um arquivo ou a string direta)
23
+ */
24
+ export async function validateMermaidSyntax(input) {
25
+ let content = input;
26
+
27
+ // Se o input for um caminho de arquivo válido no disco, lê o conteúdo dele
28
+ if (fs.existsSync(input)) {
29
+ content = fs.readFileSync(input, 'utf-8');
30
+ }
31
+
32
+ // Se houver blocos de Markdown indicando Mermaid, isola os diagramas
33
+ let diagramsToValidate = [content];
34
+ if (content.includes('```mermaid')) {
35
+ diagramsToValidate = extractMermaidBlocks(content);
36
+
37
+ if (diagramsToValidate.length === 0) {
38
+ return {
39
+ valid: false,
40
+ error: "Nenhum bloco de código '```mermaid' estruturado foi encontrado."
41
+ };
42
+ }
43
+ }
44
+
45
+ // Valida cada bloco na memória usando o parser oficial
46
+ try {
47
+ for (const diagramCode of diagramsToValidate) {
48
+ await parse(diagramCode);
49
+ }
50
+ return { valid: true };
51
+ } catch (error) {
52
+ return {
53
+ valid: false,
54
+ error: error.message || 'Erro de sintaxe desconhecido no Mermaid.'
55
+ };
56
+ }
57
+ }
@@ -21,7 +21,7 @@ stateDiagram-v2
21
21
  CheckCode --> EvaluatedCodeIsChaotic: Draw BOTH current chaotic logic AND ideal target refactored graph (v1.0.0 - draft)
22
22
  }
23
23
 
24
- RenderTopology --> CheckDiagram: Use mmdc -i <path/to/diagram.md> --checkSyntax to validate diagram syntax
24
+ RenderTopology --> CheckDiagram: Use "npx md validate <path/to/spec.md>" to validate diagram syntax
25
25
 
26
26
  state CheckDiagram {
27
27
  [*] --> DiagramValid: Proceed to next step
@@ -22,7 +22,7 @@ stateDiagram-v2
22
22
  [*] --> IncrementMajor: Increment Major: Bump X in X.Y.Z
23
23
  }
24
24
 
25
- IncrementVersion --> CheckDiagram: Use mmdc -i <path/to/diagram.md> --checkSyntax to validate diagram syntax
25
+ IncrementVersion --> CheckDiagram: Use "npx md validate <path/to/spec.md>" to validate diagram syntax
26
26
 
27
27
  state CheckDiagram {
28
28
  [*] --> TryRender
@@ -19,7 +19,7 @@ stateDiagram-v2
19
19
 
20
20
  EvaluateContext --> GenerateBlueprint: Create .spec.md from "src/templates/spec-template.md".
21
21
  GenerateBlueprint --> FormatSpecOutput: Format blueprint into target .spec.md structure
22
- FormatSpecOutput --> CheckDiagram: Use mmdc -i <path/to/diagram.md> --checkSyntax to validate diagram syntax
22
+ FormatSpecOutput --> CheckDiagram: Use "npx md validate <path/to/spec.md>" to validate diagram syntax
23
23
 
24
24
  state CheckDiagram {
25
25
  [*] --> DiagramValid: Proceed to next step
package/system_prompt.md CHANGED
@@ -217,7 +217,7 @@ The UNIVERSAL RULE is now integrated into the main processing diagram at the top
217
217
 
218
218
  **Before ANY action, the system MUST verify that a `.spec.md` file exists for the target domain/feature.** If no spec exists, only `md-new` and `md-audit` skills are allowed to proceed (to create or propose a spec). All other skills (`md-impl`, `md-edit`, etc.) are DENIED without an existing specification.
219
219
 
220
- Diagrams: Always use npx @mermaid-js/mermaid-cli to Validate Diagrams Syntax (Mandatory)
220
+ Diagrams: Always use mmdc -i <path/to/diagram.md> --checkSyntax to validate diagram syntax (Mandatory)
221
221
 
222
222
  ```mermaid
223
223
  %% @spec-version v2.0.0