mddd-cli 1.0.10 → 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 +26 -10
- package/bin/cli.spec.md +53 -15
- 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.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
|
|
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.`,
|
|
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
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
|
|
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.
|
|
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]
|
|
@@ -17,8 +17,9 @@ stateDiagram-v2
|
|
|
17
17
|
DetectCommand --> CmdImpl: impl <file>
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
CmdInit -->
|
|
21
|
-
|
|
20
|
+
CmdInit --> MkdirDotAgents: mkdir .agents/
|
|
21
|
+
MkdirDotAgents --> MkdirSkills: mkdir .agents/skills/
|
|
22
|
+
MkdirSkills --> WriteSystemPrompt: write system_prompt.md
|
|
22
23
|
WriteSystemPrompt --> WriteSkills: write 4 SKILL.md files
|
|
23
24
|
WriteSkills --> Done: ✅ Success
|
|
24
25
|
|
|
@@ -39,7 +40,12 @@ stateDiagram-v2
|
|
|
39
40
|
CmdAudit --> ValidateCodeFile: file exists?
|
|
40
41
|
ValidateCodeFile --> NotFoundAudit: no → ❌ Error
|
|
41
42
|
ValidateCodeFile --> PrepareDir: yes → ensure targetDir
|
|
42
|
-
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
|
|
43
49
|
|
|
44
50
|
CmdImpl --> ValidateSpecFile: file exists?
|
|
45
51
|
ValidateSpecFile --> NotFoundImpl: no → ❌ Error
|
|
@@ -63,7 +69,7 @@ stateDiagram-v2
|
|
|
63
69
|
| `md init` | `init` | Create `.agents/` + `system_prompt.md` + 4 skill files | ✅ Created / ✅ Already exists |
|
|
64
70
|
| `md new <path>` | `new` | Create co-located `.spec.md` at path; optional parent linking | ✅ Created / ⚠️ Exists / ❌ Error |
|
|
65
71
|
| `md edit <file> <msg>` | `edit` | Validate file, print instruction to stdout | 📝 Ready / ❌ Not found |
|
|
66
|
-
| `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 |
|
|
67
73
|
| `md impl <file>` | `impl` | Validate spec file exists | 🚀 Ready / ❌ Not found |
|
|
68
74
|
|
|
69
75
|
### 2.2 `init` Command — File Generation
|
|
@@ -74,7 +80,7 @@ stateDiagram-v2
|
|
|
74
80
|
| `./.agents/skills` does not exist | `mkdir .agents/skills` | Continue |
|
|
75
81
|
| Always | Write `system_prompt.md` | Continue |
|
|
76
82
|
| For each skill (`md-new`, `md-edit`, `md-audit`, `md-impl`) | Create folder + `SKILL.md` | Continue → Done |
|
|
77
|
-
| Skill `SKILL.md` already exists |
|
|
83
|
+
| Skill `SKILL.md` already exists | Overwrite silently via `fs.writeFileSync` | Replace |
|
|
78
84
|
|
|
79
85
|
### 2.3 `new` Command — Parent Linking
|
|
80
86
|
|
|
@@ -82,10 +88,20 @@ stateDiagram-v2
|
|
|
82
88
|
| :--- | :--- | :--- |
|
|
83
89
|
| `--parent` provided AND file exists | Append link line to parent | ✅ Linked |
|
|
84
90
|
| `--parent` provided AND file NOT found | `process.exit(1)` with error | ❌ Fatal |
|
|
85
|
-
| `--parent` NOT provided
|
|
86
|
-
| `--macro` flag set | Skip parent linking (unless `-p` explicit) | Macro template generated |
|
|
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
|
|
|
@@ -111,6 +128,8 @@ stateDiagram-v2
|
|
|
111
128
|
| :--- | :--- | :--- | :--- |
|
|
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). |
|
|
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. |
|
|
114
133
|
|
|
115
134
|
### Audit Report: `bin/cli.js` (2026-05-26)
|
|
116
135
|
|
|
@@ -137,10 +156,30 @@ stateDiagram-v2
|
|
|
137
156
|
5. ⚠️ **Template strings** in `new` action: Extract to `templates/` directory for maintainability.
|
|
138
157
|
6. ⚠️ **`process.exit()` scattering**: If this grows into a library, consider centralizing error handling and returning exit codes.
|
|
139
158
|
|
|
140
|
-
|
|
159
|
+
### Audit Report: `bin/cli.js` (2026-05-26) — v1.2.0 Re-audit
|
|
160
|
+
|
|
161
|
+
**Target**: `bin/cli.js` — CLI entry point (v1.0.10)
|
|
162
|
+
|
|
163
|
+
**Discrepancies Found vs Spec v1.1.0**:
|
|
164
|
+
|
|
165
|
+
| Item | Spec Said | Code Does | Verdict |
|
|
166
|
+
| :--- | :--- | :--- | :--- |
|
|
167
|
+
| `init` flow — directory creation | `CreateDotAgents: mkdir .agents/skills/` | Two separate conditional mkdir: `mkdir .agents/` then `mkdir .agents/skills/` | ⚠️ Minor — spec combined into one state; fixed in v1.2.0 diagram |
|
|
168
|
+
| `init` — SKILL.md overwrite | "Delete old, write new" | `fs.writeFileSync` overwrites silently, no deletion | ⚠️ Minor — wording fixed in v1.2.0 matrix |
|
|
169
|
+
| `new` — `CheckExists` guard order | CheckExists branches to Skip or GenerateSpec | Code checks `fs.existsSync(normalizedPath)` for mkdir, then checks `fs.existsSync(finalFile)` separately | ✅ Correct — diagram simplified, no semantic error |
|
|
170
|
+
| `new` — trailing slash normalization | Not mentioned | `normalizedPath` uses `.replace(/[\\/]+$/, '')` | ✅ Enhancement — documented below |
|
|
171
|
+
| `findClosestMacro` — dir exclusion | Not specified | Excludes file named `${path.basename(currentDir)}.spec.md` | ✅ Enhancement — documented in matrix |
|
|
172
|
+
| Version metadata | N/A (spec refers to v1.0.8) | Code declares `v1.0.10` | ✅ Cosmetic — spec now at v1.2.0 |
|
|
173
|
+
|
|
174
|
+
**Newly Documented Behaviors**:
|
|
175
|
+
- **Trailing slash cleanup**: `path.normalize(targetPath).replace(/[\\/]+$/, '')` strips trailing slashes before mkdir.
|
|
176
|
+
- **Self-exclusion in `findClosestMacro`**: The macro search excludes `${path.basename(currentDir)}.spec.md` to avoid matching the directory's own spec file.
|
|
177
|
+
- **Permission-denied break**: On `EACCES`/`EPERM`, the loop breaks and returns `null`. All other `fs.readdirSync` errors are rethrown.
|
|
178
|
+
|
|
179
|
+
**Architecture Diagram (Current State — v1.0.10)**:
|
|
141
180
|
|
|
142
181
|
```mermaid
|
|
143
|
-
%% @spec-version v1.
|
|
182
|
+
%% @spec-version v1.2.0
|
|
144
183
|
graph LR
|
|
145
184
|
subgraph "Entry Point"
|
|
146
185
|
CLI["bin/cli.js"]
|
|
@@ -171,6 +210,7 @@ graph LR
|
|
|
171
210
|
SK3[.agents/skills/md-audit/SKILL.md]
|
|
172
211
|
SK4[.agents/skills/md-impl/SKILL.md]
|
|
173
212
|
SPEC[targetPath/name.spec.md]
|
|
213
|
+
ASPEC[srcDir/codeBasename.spec.md]
|
|
174
214
|
end
|
|
175
215
|
|
|
176
216
|
CLI --> CMD
|
|
@@ -189,13 +229,11 @@ graph LR
|
|
|
189
229
|
|
|
190
230
|
AUDIT --> FS
|
|
191
231
|
AUDIT --> PC
|
|
232
|
+
AUDIT --> ASPEC
|
|
192
233
|
IMPL --> FS
|
|
193
234
|
IMPL --> PC
|
|
194
235
|
EDIT --> FS
|
|
195
236
|
EDIT --> PC
|
|
196
237
|
```
|
|
197
238
|
|
|
198
|
-
**Recommendations for v2.0.0** (future):
|
|
199
|
-
- Replace `process.exit()` with thrown exceptions or a centralized error handler for better testability
|
|
200
|
-
|
|
201
239
|
</details>
|