mddd-cli 1.0.11 → 1.0.12

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
@@ -40,7 +40,7 @@ function findClosestMacro(currentDir) {
40
40
  program
41
41
  .name('md')
42
42
  .description('Manager for co-located specifications for Mermaid Diagram Driven Development (MDDD)')
43
- .version('1.0.11');
43
+ .version('1.0.12');
44
44
 
45
45
  // ==========================================
46
46
  // COMMAND: md init
@@ -110,12 +110,13 @@ Operational instructions for modifying existing specifications:
110
110
 
111
111
  'md-audit': `[ROLE: SECURITY & QUALITY AUDITOR] [STRICT CONTRACT]
112
112
  Operational instructions for reverse engineering and legacy code analysis:
113
- 1. EXECUTION: Execute the terminal command \`md audit [code_file_path]\`.
113
+ 1. EXECUTION: Execute the terminal command \`md audit [code_file_path]\`. This creates or locates a co-located \`[code_basename].spec.md\` file for audit output.
114
114
  2. COMPLEXITY ANALYSIS: Evaluate the provided code file. Check for coupling, scope leaks, and clarity of business rules.
115
- 3. RETROACTIVE MAPPING:
115
+ 3. RETROACTIVE MAPPING (DOCUMENTATION ONLY):
116
116
  - If the code is clean and modular: Write a Mermaid diagram corresponding to the current state of the code (v1.0.0).
117
- - If the code is chaotic/coupled: Draw the Mermaid diagram of how the flow SHOULD ideally be structured after a refactoring.
118
- 4. HISTORY ISOLATION: Insert your technical analysis report and the generated diagram strictly inside the \`<details><summary>Audit History</summary>\` tag at the end of the corresponding file. Never pollute the main scope with drafts.`,
117
+ - If the code is chaotic/coupled: Draw the Mermaid diagram of how the flow SHOULD ideally be restructured for future implementation. Do NOT modify the audited code file.
118
+ 4. WRITE TO SPEC FILE: Write ALL results — the technical analysis report, the generated diagram (in code fences), and any decision tables — directly into the co-located \`.spec.md\` file found at the path printed by the \`md audit\` command. Insert the analysis strictly inside the \`<details><summary>Audit History</summary>\` tag at the end of that file. Never pollute the main scope with drafts. If the spec file has empty sections, fill them with the retroactive content.
119
+ 5. CODE IMMUTABILITY: You are FORBIDDEN from changing, refactoring, or editing the audited code file. Only the \`md-impl\` command/skill is authorized to modify production code based on a signed spec file. If the audit reveals the code needs refactoring, document the ideal diagram in the spec file and stop.`,
119
120
 
120
121
  'md-impl': `[ROLE: SOFTWARE ENGINEER] [STRICT CONTRACT]
121
122
  Operational instructions for generating production code and unit tests:
@@ -241,16 +242,31 @@ program
241
242
  }
242
243
 
243
244
  const targetDir = path.dirname(codeFilePath);
244
- const fileName = path.basename(codeFilePath);
245
-
246
- console.log(pc.cyan(`🔍 Auditing code structure for coupling in: ${fileName}...`));
247
- console.log(pc.yellow(`⚡ Requesting AI to validate complexity before generating MDDD specification.`));
245
+ const codeBaseName = path.basename(codeFilePath, path.extname(codeFilePath));
246
+ const specFileName = `${codeBaseName}.spec.md`;
247
+ const specFilePath = path.join(targetDir, specFileName);
248
248
 
249
+ // Ensures the target directory exists
249
250
  if (!fs.existsSync(targetDir)) {
250
251
  fs.mkdirSync(targetDir, { recursive: true });
251
252
  }
252
253
 
253
- console.log(pc.green(`\n🚀 Ready! Use the /md-audit shortcut in chat to receive the analysis and structural refactoring diagram.`));
254
+ // Creates the .spec.md file if it doesn't exist
255
+ if (!fs.existsSync(specFilePath)) {
256
+ const version = 'v1.0.0';
257
+ const template = `# Audit: ${codeBaseName} | ${version}\n\n` +
258
+ `## 1. Flow Contract (Mermaid)\n\`\`\`mermaid\n%% @spec-version ${version}\ngraph LR\n A([Start]) --> B[Process]\n\`\`\`\n\n` +
259
+ `## 2. Decision Matrix\n| Condition | Action | Next State |\n| :---: | :--- | :---: |\n| | | |\n\n` +
260
+ `## 3. Audit History\n<details>\n<summary>Click to expand</summary>\n\n\n\n</details>\n`;
261
+ fs.writeFileSync(specFilePath, template);
262
+ console.log(pc.green(`✅ Co-located specification file created: ${specFilePath}`));
263
+ } else {
264
+ console.log(pc.blue(`📄 Existing specification found: ${specFilePath}`));
265
+ }
266
+
267
+ console.log(pc.cyan(`🔍 Auditing code structure for coupling in: ${path.basename(codeFilePath)}...`));
268
+ console.log(pc.yellow(`⚡ The AI will validate complexity and write the analysis to: ${specFilePath}`));
269
+ console.log(pc.green(`\n🚀 Ready! Use the /md-audit shortcut in chat for the AI to write the analysis and structural refactoring diagram into the co-located spec file.`));
254
270
  });
255
271
 
256
272
  // ==========================================
package/bin/cli.spec.md CHANGED
@@ -1,9 +1,9 @@
1
- # CLI: mddd-cli | v1.2.1
1
+ # CLI: mddd-cli | v1.3.0
2
2
 
3
3
  ## 1. Flow Contract (Mermaid)
4
4
 
5
5
  ```mermaid
6
- %% @spec-version v1.2.1
6
+ %% @spec-version v1.3.0
7
7
  stateDiagram-v2
8
8
  [*] --> Idle
9
9
  Idle --> ParseArgs: md <command> [args]
@@ -40,7 +40,12 @@ stateDiagram-v2
40
40
  CmdAudit --> ValidateCodeFile: file exists?
41
41
  ValidateCodeFile --> NotFoundAudit: no → ❌ Error
42
42
  ValidateCodeFile --> PrepareDir: yes → ensure targetDir
43
- PrepareDir --> ReadyAudit: 🚀 Ready
43
+ PrepareDir --> DeriveSpecName: get codeBasename.spec.md
44
+ DeriveSpecName --> CheckSpecExists: spec file exists?
45
+ CheckSpecExists --> CreateSpec: no → write template
46
+ CheckSpecExists --> LogExisting: yes → 📄 Existing found
47
+ CreateSpec --> ReadyAudit: 🚀 Ready
48
+ LogExisting --> ReadyAudit: 🚀 Ready
44
49
 
45
50
  CmdImpl --> ValidateSpecFile: file exists?
46
51
  ValidateSpecFile --> NotFoundImpl: no → ❌ Error
@@ -64,7 +69,7 @@ stateDiagram-v2
64
69
  | `md init` | `init` | Create `.agents/` + `system_prompt.md` + 4 skill files | ✅ Created / ✅ Already exists |
65
70
  | `md new <path>` | `new` | Create co-located `.spec.md` at path; optional parent linking | ✅ Created / ⚠️ Exists / ❌ Error |
66
71
  | `md edit <file> <msg>` | `edit` | Validate file, print instruction to stdout | 📝 Ready / ❌ Not found |
67
- | `md audit <file>` | `audit` | Validate code file, ensure dir exists | 🚀 Ready / ❌ Not found |
72
+ | `md audit <file>` | `audit` | Validate code file, create/co-locate `.spec.md` for audit output | 🚀 Ready / ❌ Not found |
68
73
  | `md impl <file>` | `impl` | Validate spec file exists | 🚀 Ready / ❌ Not found |
69
74
 
70
75
  ### 2.2 `init` Command — File Generation
@@ -85,7 +90,18 @@ stateDiagram-v2
85
90
  | `--parent` provided AND file NOT found | `process.exit(1)` with error | ❌ Fatal |
86
91
  | `--parent` NOT provided | Auto-search via `findClosestMacro()` | ✅ Linked (if found) / No link (if none) |
87
92
 
88
- ### 2.4 `findClosestMacro(currentDir)` — Traversal Logic
93
+ ### 2.4 `audit` Command Spec File Generation
94
+
95
+ | Condition | Action | Next State |
96
+ | :--- | :--- | :--- |
97
+ | Code file does not exist | `process.exit(1)` with error | ❌ Fatal |
98
+ | Code file exists, target dir does not exist | `mkdir -p <targetDir>` | Continue |
99
+ | Code file exists, target dir exists | No action | Continue |
100
+ | Co-located `.spec.md` does NOT exist | Write template with `# Audit: <basename> | v1.0.0` | ⚡ Ready |
101
+ | Co-located `.spec.md` already exists | Log `📄 Existing specification found` | ⚡ Ready |
102
+ | Always after file ready | Print instruction: AI writes analysis into `<details>` in `.spec.md` | 🚀 Ready |
103
+
104
+ ### 2.5 `findClosestMacro(currentDir)` — Traversal Logic
89
105
 
90
106
  | Condition | Action | Return |
91
107
  | :--- | :--- | :--- |
@@ -101,6 +117,7 @@ stateDiagram-v2
101
117
  - **Runtime**: Node.js >= 18 (ESM — `"type": "module"`)
102
118
  - **Pattern**: Each command is a self-contained `.action()` callback. Shared utility (`findClosestMacro`) is a module-level function with clear single responsibility.
103
119
  - **Error handling**: Consistent pattern — validate file existence early, exit with code 1 + red message on failure, green/blue/yellow for success/warnings.
120
+ - **`md audit` spec generation**: The audit command derives the spec file name by stripping the code file extension and appending `.spec.md` (e.g., `user.go` → `user.spec.md`). The generated template includes a Decision Matrix, a placeholder Mermaid diagram, and an Audit History `<details>` section where the AI writes its full analysis.
104
121
 
105
122
  ## 4. Audit History
106
123
 
@@ -112,6 +129,7 @@ stateDiagram-v2
112
129
  | 2026-05-26 | AI (MDDD audit) | v1.0.0 | Initial spec: code is modular, cohesive, clean. Mapped as-is. |
113
130
  | 2026-05-26 | AI (MDDD audit) | v1.1.0 | Deep audit of `bin/cli.js` source code. Code is clean and modular — mapped as-is (architecture diagram below). |
114
131
  | 2026-05-26 | AI (MDDD audit) | v1.2.0 | Re-audit `bin/cli.js` v1.0.10 vs spec v1.1.0. Minor divergences found in `init` flow granularity and `new` guard logic. Spec updated to reflect real code. |
132
+ | 2026-05-26 | AI (MDDD audit) | v1.3.0 | `md audit` now auto-creates/co-locates `[basename].spec.md` for AI audit output. Skill `md-audit` updated to instruct AI to write analysis into that file. |
115
133
 
116
134
  ### Audit Report: `bin/cli.js` (2026-05-26)
117
135
 
@@ -192,6 +210,7 @@ graph LR
192
210
  SK3[.agents/skills/md-audit/SKILL.md]
193
211
  SK4[.agents/skills/md-impl/SKILL.md]
194
212
  SPEC[targetPath/name.spec.md]
213
+ ASPEC[srcDir/codeBasename.spec.md]
195
214
  end
196
215
 
197
216
  CLI --> CMD
@@ -210,6 +229,7 @@ graph LR
210
229
 
211
230
  AUDIT --> FS
212
231
  AUDIT --> PC
232
+ AUDIT --> ASPEC
213
233
  IMPL --> FS
214
234
  IMPL --> PC
215
235
  EDIT --> FS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mddd-cli",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Official CLI for modular, co-located, and versioned Mermaid Diagram Driven Development (MDDD).",
5
5
  "main": "bin/cli.js",
6
6
  "type": "module",