mddd-cli 1.0.11 → 1.0.13
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 +27 -10
- package/bin/cli.spec.md +25 -5
- package/package.json +1 -1
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.
|
|
43
|
+
.version('1.0.13');
|
|
44
44
|
|
|
45
45
|
// ==========================================
|
|
46
46
|
// COMMAND: md init
|
|
@@ -110,12 +110,14 @@ 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
|
|
118
|
-
4.
|
|
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.
|
|
120
|
+
- **Audit auto-repair rule:** Whenever the \`/md-audit\` command identifies a \`.dart\` (or equivalent production file) without a co-located \`[name].spec.md\`, the audit **must generate and write the missing spec file** as part of the audit output, before finalizing the report. The auto-generated spec must include at minimum: (a) \`SPEC_VERSION: v1.0.0\`, (b) a \`stateDiagram-v2\` derived from the code logic, and (c) a Decision Matrix when conditional branches exist.`,
|
|
119
121
|
|
|
120
122
|
'md-impl': `[ROLE: SOFTWARE ENGINEER] [STRICT CONTRACT]
|
|
121
123
|
Operational instructions for generating production code and unit tests:
|
|
@@ -241,16 +243,31 @@ program
|
|
|
241
243
|
}
|
|
242
244
|
|
|
243
245
|
const targetDir = path.dirname(codeFilePath);
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
console.log(pc.yellow(`⚡ Requesting AI to validate complexity before generating MDDD specification.`));
|
|
246
|
+
const codeBaseName = path.basename(codeFilePath, path.extname(codeFilePath));
|
|
247
|
+
const specFileName = `${codeBaseName}.spec.md`;
|
|
248
|
+
const specFilePath = path.join(targetDir, specFileName);
|
|
248
249
|
|
|
250
|
+
// Ensures the target directory exists
|
|
249
251
|
if (!fs.existsSync(targetDir)) {
|
|
250
252
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
251
253
|
}
|
|
252
254
|
|
|
253
|
-
|
|
255
|
+
// Creates the .spec.md file if it doesn't exist
|
|
256
|
+
if (!fs.existsSync(specFilePath)) {
|
|
257
|
+
const version = 'v1.0.0';
|
|
258
|
+
const template = `# Audit: ${codeBaseName} | ${version}\n\n` +
|
|
259
|
+
`## 1. Flow Contract (Mermaid)\n\`\`\`mermaid\n%% @spec-version ${version}\ngraph LR\n A([Start]) --> B[Process]\n\`\`\`\n\n` +
|
|
260
|
+
`## 2. Decision Matrix\n| Condition | Action | Next State |\n| :---: | :--- | :---: |\n| | | |\n\n` +
|
|
261
|
+
`## 3. Audit History\n<details>\n<summary>Click to expand</summary>\n\n\n\n</details>\n`;
|
|
262
|
+
fs.writeFileSync(specFilePath, template);
|
|
263
|
+
console.log(pc.green(`✅ Co-located specification file created: ${specFilePath}`));
|
|
264
|
+
} else {
|
|
265
|
+
console.log(pc.blue(`📄 Existing specification found: ${specFilePath}`));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
console.log(pc.cyan(`🔍 Auditing code structure for coupling in: ${path.basename(codeFilePath)}...`));
|
|
269
|
+
console.log(pc.yellow(`⚡ The AI will validate complexity and write the analysis to: ${specFilePath}`));
|
|
270
|
+
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
271
|
});
|
|
255
272
|
|
|
256
273
|
// ==========================================
|
package/bin/cli.spec.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# CLI: mddd-cli | v1.
|
|
1
|
+
# CLI: mddd-cli | v1.3.0
|
|
2
2
|
|
|
3
3
|
## 1. Flow Contract (Mermaid)
|
|
4
4
|
|
|
5
5
|
```mermaid
|
|
6
|
-
%% @spec-version v1.
|
|
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 -->
|
|
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,
|
|
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 `
|
|
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
|