mddd-cli 4.4.0 → 6.2.0

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.
@@ -0,0 +1,214 @@
1
+ [ROLE: ARCHITECT] [STRICT CONTRACT]
2
+
3
+ ```mermaid
4
+ %% @spec-version v2.2.0
5
+ stateDiagram-v2
6
+ [*] --> LoadMermaidSkill
7
+
8
+ LoadMermaidSkill --> SelfScan: Consume mermaid-diagrams skill to learn diagram types
9
+ SelfScan --> Classify: Walk the project tree and discover .spec.md files
10
+
11
+ state Classify {
12
+ [*] --> DetectMacros: Find .spec.md at project root → MACRO specs (domains)
13
+ DetectMacros --> DetectMicros: Find .spec.md in subfolders → MICRO specs (components)
14
+ DetectMicros --> IdentifyActors: From spec content, identify users and external systems
15
+ }
16
+
17
+ Classify --> ReadSpecs: Read each spec to understand domain, components, and integrations
18
+ ReadSpecs --> PlanDiagram: Plan a multi-level flowchart LR
19
+ PlanDiagram --> ComposeDiagram: Compose flowchart LR with subgraphs, components, actors, edges, classes
20
+
21
+ state ComposeDiagram {
22
+ [*] --> BuildSubgraphs: One subgraph per MACRO domain with its MICRO components inside
23
+ BuildSubgraphs --> AddActors: Add users and external systems OUTSIDE subgraphs
24
+ AddActors --> AddEdges: Connect nodes with labeled arrows (uses, calls, deploys, integrates)
25
+ AddEdges --> AddClasses: Apply classDef for system / user / external / infra distinction
26
+ }
27
+
28
+ ComposeDiagram --> ValidateDiagram: Run `npx md validate <output>.md` until valid
29
+ ValidateDiagram --> WriteArtifact: Save to ARCHITECTURE.md (or similar) at project root
30
+ WriteArtifact --> [*]
31
+ ```
32
+
33
+ ## Purpose
34
+
35
+ The `mddd-context-map` skill teaches the agent to produce a **product architecture diagram** that visualizes the system at **multiple levels**:
36
+
37
+ - **Macro areas (domains)** — each MACRO spec represents a high-level domain.
38
+ - **Micro components / services** — MICRO specs are the building blocks inside each domain.
39
+ - **Data flows** between users, UI, backend, serverless functions, and external infrastructure.
40
+
41
+ The output is a stylized **flowchart LR** that combines domain grouping with internal components and external integrations, emphasizing the user journey, backend orchestration, and the infrastructure layer.
42
+
43
+ > **v2.0.0** rewrites the skill to produce a **multi-level product architecture diagram** (C4-inspired but as `flowchart LR` with classDef styling), instead of the previous C4-only recommendation. The skill now drives a richer, more prescriptive output that mirrors how product teams sketch architecture on a whiteboard.
44
+
45
+ ## Conceptual Model
46
+
47
+ ```
48
+ Users / External Systems MACRO Domain 1 MACRO Domain 2
49
+ (outside subgraphs) (subgraph) (subgraph)
50
+ ┌──────────────┐ ┌──────────────┐
51
+ 👤 User ───uses───▶ │ Component A │ │ Component X │
52
+ │ Component B │ │ Component Y │
53
+ 🌐 External API ──integrates──▶ │ Component C │ │ Component Z │
54
+ └──────────────┘ └──────────────┘
55
+ │ │
56
+ └───calls──────┬─────────────┘
57
+
58
+ Database / Infra
59
+ ```
60
+
61
+ ## Multi-Level Architecture Diagram Spec
62
+
63
+ ### 1. Type and direction
64
+
65
+ - **Type**: `flowchart LR` (left-to-right). Use `graph LR` if `flowchart` is not supported.
66
+ - **Why LR**: the user journey reads left → right, the way most product architecture diagrams are drawn.
67
+
68
+ ### 2. Subgraphs (one per MACRO domain)
69
+
70
+ - For every **MACRO spec** found, create **one `subgraph`** named after the domain.
71
+ - Each subgraph contains the **MICRO components** that belong to that domain, based on explicit domain relationships and spec content rather than file path or folder depth.
72
+ - When a MICRO spec does not explicitly name its domain, infer it from the domain language and the surrounding feature relationship, not from where the file is stored.
73
+ - The subgraph should have a clear, domain-level label (e.g. `subgraph webApp["🌐 Web App"]`).
74
+
75
+ ### 3. Nodes (components, users, external systems)
76
+
77
+ - Inside each subgraph, list the **functional components** as **textual nodes**:
78
+ - `compA["⚙️ Component A<br/>(short role)"]:::systemNode`
79
+ - **Users** and **external systems** are placed **outside** all subgraphs:
80
+ - `user((👤 End User)):::userNode`
81
+ - `external[[🌐 External API]]:::externalNode`
82
+ - Use emojis at the start of node labels to make the diagram scannable.
83
+
84
+ ### 4. Edges (labeled flows)
85
+
86
+ Every meaningful connection is a **labeled arrow**:
87
+
88
+ | Edge type | Label convention | Example |
89
+ | :--- | :--- | :--- |
90
+ | User → UI | `"uses"` | `user -->|"uses"| ui` |
91
+ | UI → Backend | `"calls API"` | `ui -->|"calls API"| api` |
92
+ | Backend → Serverless | `"invokes"` | `api -->|"invokes"| fn` |
93
+ | Service → Database | `"reads/writes"` | `svc -->|"reads/writes"| db` |
94
+ | Service → External API | `"integrates with"` | `svc -->|"integrates with"| ext` |
95
+ | CI/CD → Service | `"deploys"` | `cicd -->|"deploys"| svc` |
96
+ | Service → Queue | `"publishes"` | `svc -->|"publishes"| queue` |
97
+
98
+ Always choose the verb that best matches the *intent* of the connection.
99
+
100
+ ### 5. ClassDef styling (visual hierarchy)
101
+
102
+ Apply at least these `classDef` rules to differentiate the kinds of nodes:
103
+
104
+ ```
105
+ classDef userNode fill:#fef3c7,stroke:#b45309,stroke-width:2px,color:#1f2937;
106
+ classDef systemNode fill:#1e3a8a,stroke:#1e40af,stroke-width:2px,color:#fff;
107
+ classDef externalNode fill:#7c2d12,stroke:#9a3412,stroke-width:2px,color:#fff;
108
+ classDef infraNode fill:#374151,stroke:#4b5563,stroke-width:1px,color:#fff,font-style:italic;
109
+ ```
110
+
111
+ | Class | When to use | Visual feel |
112
+ | :--- | :--- | :--- |
113
+ | `userNode` | People, personas, roles | Warm, friendly (yellow) |
114
+ | `systemNode` | Internal services / components | Strong, professional (blue) |
115
+ | `externalNode` | Third-party APIs, partner systems | Stand-out (red-orange) |
116
+ | `infraNode` | Databases, queues, caches, storage | Subdued, italic (gray) |
117
+
118
+ ### 6. Class assignment
119
+
120
+ After creating the subgraphs and nodes, apply the classes:
121
+
122
+ ```
123
+ class user1,user2 userNode
124
+ class svcA,svcB,svcC systemNode
125
+ class extApi,partnerX externalNode
126
+ class db,queue,cache infraNode
127
+ ```
128
+
129
+ Or attach the class inline with `:::className` on each node.
130
+
131
+ ## Self-Scan Discovery Workflow
132
+
133
+ 1. **Walk the project tree** from the current working directory, recursively finding every `.spec.md`. You MUST use the CLI command `npx md list-specs` to obtain the authoritative list. Prune `node_modules`, `.git`, `.agents`, `build`, `dist`.
134
+ 2. **Classify** each spec by its content and role, not by directory depth or file location:
135
+ - specs that describe broad product domains, business capabilities, or top-level architectural scopes → **MACRO**
136
+ - specs that describe individual components, services, features, or implementation units → **MICRO**
137
+ - use explicit domain labels, architecture language, and the spec's intent to distinguish MACRO from MICRO
138
+ 3. **Read each spec** to understand its purpose, role, and relationships. Do not generate a diagram from filenames or folder structure alone.
139
+ 4. **Identify actors and external systems** by scanning the spec content for keywords:
140
+ - `user`, `customer`, `admin`, `developer`, `operator` → **userNode**
141
+ - `external API`, `third-party`, `partner`, `OAuth`, `Stripe`, `AWS S3` → **externalNode**
142
+ - `database`, `DB`, `PostgreSQL`, `MySQL`, `Redis`, `queue`, `Kafka`, `S3` → **infraNode**
143
+ 5. **Infer edges** by looking for verbs and references between specs (e.g. one MICRO mentions "calls into X" or "publishes to Y").
144
+ 6. **Compose the diagram** following the spec above.
145
+ 7. **Validate** with `npx md validate` and iterate until the diagram is valid.
146
+ 8. **Write the artifact** to `ARCHITECTURE.md` (or `CONTEXT_MAP.md`) at the project root.
147
+
148
+ ## Output Artifact
149
+
150
+ The skill should write the result to `ARCHITECTURE.md` (or `CONTEXT_MAP.md`) at the project root, inside a `mermaid` code fence. The agent must:
151
+
152
+ 1. Use the **`npx md validate <path>`** command to ensure the diagram is syntactically valid.
153
+ 2. Include `click` directives linking each internal node to its spec file (cross-platform navigability).
154
+ 3. Add a short human-readable caption above the diagram summarizing:
155
+ - How many MACROs and MICROs were mapped
156
+ - Which external systems are integrated
157
+ - Which infrastructure layer is used
158
+
159
+ ## Output Template (v2.2.0 — diagram-first, strict)
160
+
161
+ The skill ships a **rigid reference template** that the agent **must** follow section by section. The template is **diagram-first**: every section uses Mermaid diagrams or decision-matrix tables, so the LLM has minimal free-form prose to interpret.
162
+
163
+ - **Template path:** `.agents/templates/ARCHITECTURE.template.md` (copied by `md init`).
164
+ - **Structure (8 sections, in this exact order):**
165
+
166
+ | § | Section | What goes there |
167
+ | :---: | :--- | :--- |
168
+ | 1 | Topology Overview (`flowchart LR`) | One-glance diagram: actors + externals + subgraphs + infra + edges + classDef |
169
+ | 2 | MACRO Decision Matrices | One truth-table per MACRO, factor columns pulled from each `*.spec.md` |
170
+ | 3 | Cross-Domain Data Flow Diagrams | One `sequenceDiagram` per major flow (auth, CRUD, payment, deploy) |
171
+ | 4 | External Integrations (`graph LR`) | Focused diagram of every third-party system |
172
+ | 5 | Infrastructure Topology (`graph TB`) | Stand-alone top-down diagram of infra |
173
+ | 6 | Component Dependency Matrix | Compact truth-table: from / to / label / trigger / source spec |
174
+ | 7 | Click-Through Map | `flowchart LR` with `click` directives for every internal node |
175
+ | 8 | Generation Footer | Counts + validation status |
176
+
177
+ ### Strict substitution rules
178
+
179
+ 1. **Every `{{PLACEHOLDER}}` must be substituted.** If a section has no data, emit a single Mermaid block showing `(empty — no X found)` — do not delete the section.
180
+ 2. **Do not reorder sections.** The order is part of the contract.
181
+ 3. **Do not add free-form prose outside the labeled slots.** Express everything as diagrams or tables.
182
+ 4. **Decision matrices in §2 are truth-tables**, not paragraphs. Reproduce the Primitive Factors columns from each MACRO's `*.spec.md` exactly.
183
+ 5. **Sequence diagrams in §3 are time-ordered**, not topology. One section per main user/system flow.
184
+ 6. **The §6 Component Dependency Matrix is the source of truth for edges** — §1 and §4 and §5 should be consistent with it.
185
+
186
+ ### How to use the template
187
+
188
+ 1. **Read `.agents/templates/ARCHITECTURE.template.md`** to see the 8 sections.
189
+ 2. **Walk the project** and read every `.spec.md` to extract:
190
+ - MACRO domains + their decision matrix factors
191
+ - MICRO components per MACRO
192
+ - External systems (keyword scan: `external`, `third-party`, `OAuth`, `Stripe`, `AWS S3`, `Gemini`, etc.)
193
+ - Infrastructure (keyword scan: `database`, `PostgreSQL`, `MySQL`, `Redis`, `queue`, `Kafka`, `S3`, `Secret Manager`)
194
+ - Main flows (auth, CRUD, payment, deploy) by reading the verbs in each spec
195
+ 3. **Substitute every placeholder** in template order.
196
+ 4. **Validate** with `npx md validate` and iterate until every diagram parses.
197
+ 5. **Write** to `ARCHITECTURE.md` at the project root.
198
+
199
+ ## Hard Rules
200
+
201
+ - **Never** invent edges that are not grounded in the specs.
202
+ - **Always** put users and external systems **outside** the subgraphs (they are not domains of the product).
203
+ - **Always** apply classDef styling to differentiate the four node kinds.
204
+ - **Always** label every edge with a verb that conveys intent (`uses`, `calls`, `invokes`, `reads`, `writes`, `integrates with`, `deploys`, `publishes`).
205
+ - **Always** use `flowchart LR` (left-to-right) so the user journey reads naturally.
206
+ - **Always** preserve `click` directives for internal nodes pointing to their spec files.
207
+ - **Always** validate the resulting Mermaid diagram with `npx md validate` before declaring success.
208
+ - **Always** perform the file discovery yourself with `node:fs` (or any recursive walker) — do not assume the existence of a `md map` CLI command, which has been removed.
209
+ - **Always** use the `md list-specs` command as the authoritative source of all `.spec.md` files in the project before building the architecture map.
210
+
211
+ ## References
212
+
213
+ - `mermaid-diagrams` skill — for the full catalog of Mermaid diagram types and their syntax.
214
+ - `md-audit` skill — for the broader MDDD workflow this skill slots into.
@@ -0,0 +1,152 @@
1
+ <!--
2
+ ⚠️ TEMPLATE FILE — strict structure. The `mddd-context-map` skill must
3
+ populate EVERY section below, leaving no `{{PLACEHOLDER}}` unsubstituted.
4
+ Each section uses Mermaid diagrams and decision matrices instead of
5
+ free-form prose, so the LLM has minimal text to interpret.
6
+ -->
7
+
8
+ # {{PROJECT_NAME}} — Context Map
9
+
10
+ **Stats:** {{MACRO_COUNT}} MACRO · {{MICRO_COUNT}} MICRO · {{EXTERNAL_COUNT}} external · {{INFRA_COUNT}} infra nodes
11
+
12
+ ---
13
+
14
+ ## 1. Topology Overview (flowchart LR)
15
+
16
+ The one-glance picture. Every domain is a subgraph; actors and externals live outside.
17
+
18
+ ```mermaid
19
+ flowchart LR
20
+ %% === ACTORS (outside subgraphs) ===
21
+ {{ACTORS}}
22
+
23
+ %% === EXTERNAL SYSTEMS (outside subgraphs) ===
24
+ {{EXTERNALS}}
25
+
26
+ %% === MACRO DOMAINS ===
27
+ {{MACRO_SUBGRAPHS}}
28
+
29
+ %% === INFRASTRUCTURE LAYER (deduplicated) ===
30
+ {{INFRA_SUBGRAPH}}
31
+
32
+ %% === EDGES ===
33
+ {{EDGES}}
34
+
35
+ %% === CLASSES ===
36
+ classDef userNode fill:#fef3c7,stroke:#b45309,stroke-width:2px,color:#1f2937;
37
+ classDef systemNode fill:#1e3a8a,stroke:#1e40af,stroke-width:2px,color:#fff;
38
+ classDef externalNode fill:#7c2d12,stroke:#9a3412,stroke-width:2px,color:#fff;
39
+ classDef infraNode fill:#374151,stroke:#4b5563,stroke-width:1px,color:#fff,font-style:italic;
40
+ {{CLASS_ASSIGNMENTS}}
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 2. MACRO Decision Matrices
46
+
47
+ For each MACRO domain, emit the **Primitive Factors** that drive its decision matrix (truth-table form, no prose). One table per MACRO. Reproduce the factor columns found in the MACRO's `*.spec.md`.
48
+
49
+ ### 2.1 {{MACRO_1_NAME}}
50
+
51
+ | {{MACRO_1_FACTOR_COLUMNS}} | Proposed Action | Decision | Transition State |
52
+ | :--- | :--- | :---: | :--- |
53
+ | {{MACRO_1_MATRIX_ROWS}} |
54
+
55
+ ### 2.2 {{MACRO_2_NAME}}
56
+
57
+ | {{MACRO_2_FACTOR_COLUMNS}} | Proposed Action | Decision | Transition State |
58
+ | :--- | :--- | :---: | :--- |
59
+ | {{MACRO_2_MATRIX_ROWS}} |
60
+
61
+ *(Add one 2.x section per additional MACRO.)*
62
+
63
+ ---
64
+
65
+ ## 3. Cross-Domain Data Flow Diagrams
66
+
67
+ One **sequence diagram** per main data flow (auth, CRUD, payment, deploy, etc.). No prose.
68
+
69
+ ### 3.1 {{FLOW_1_NAME}} — Sequence
70
+
71
+ ```mermaid
72
+ sequenceDiagram
73
+ {{FLOW_1_PARTICIPANTS}}
74
+ {{FLOW_1_MESSAGES}}
75
+ ```
76
+
77
+ ### 3.2 {{FLOW_2_NAME}} — Sequence
78
+
79
+ ```mermaid
80
+ sequenceDiagram
81
+ {{FLOW_2_PARTICIPANTS}}
82
+ {{FLOW_2_MESSAGES}}
83
+ ```
84
+
85
+ ### 3.3 {{FLOW_3_NAME}} — Sequence
86
+
87
+ ```mermaid
88
+ sequenceDiagram
89
+ {{FLOW_3_PARTICIPANTS}}
90
+ {{FLOW_3_MESSAGES}}
91
+ ```
92
+
93
+ *(Add one 3.x section per major flow.)*
94
+
95
+ ---
96
+
97
+ ## 4. External Integrations (graph LR)
98
+
99
+ A focused diagram of every third-party system and how each one is reached.
100
+
101
+ ```mermaid
102
+ graph LR
103
+ {{INTEGRATION_NODES}}
104
+ {{INTEGRATION_EDGES}}
105
+ classDef externalNode fill:#7c2d12,stroke:#9a3412,stroke-width:2px,color:#fff;
106
+ classDef systemNode fill:#1e3a8a,stroke:#1e40af,stroke-width:2px,color:#fff;
107
+ {{INTEGRATION_CLASS_ASSIGNMENTS}}
108
+ ```
109
+
110
+ ---
111
+
112
+ ## 5. Infrastructure Topology (graph TB)
113
+
114
+ The infrastructure layer as a stand-alone top-down diagram.
115
+
116
+ ```mermaid
117
+ graph TB
118
+ {{INFRA_NODES}}
119
+ {{INFRA_EDGES}}
120
+ classDef infraNode fill:#374151,stroke:#4b5563,stroke-width:1px,color:#fff,font-style:italic;
121
+ classDef systemNode fill:#1e3a8a,stroke:#1e40af,stroke-width:2px,color:#fff;
122
+ {{INFRA_CLASS_ASSIGNMENTS}}
123
+ ```
124
+
125
+ ---
126
+
127
+ ## 6. Component Dependency Matrix
128
+
129
+ Compact truth-table of every inter-component edge found in the project. One row per edge. No free text.
130
+
131
+ | From | To | Edge Label | Trigger | Source Spec |
132
+ | :--- | :--- | :--- | :--- | :--- |
133
+ | {{MATRIX_ROWS}} |
134
+
135
+ ---
136
+
137
+ ## 7. Generation Footer
138
+
139
+ ```
140
+ Generated: {{GENERATION_DATE}}
141
+ MDDD Framework: v1.0.0 — stable
142
+ Methodology: mddd-context-map skill v{{SKILL_VERSION}}
143
+ Project: {{PROJECT_NAME}}
144
+ Total MACRO: {{MACRO_COUNT}} · Total MICRO: {{MICRO_COUNT}} · External: {{EXTERNAL_COUNT}} · Infra: {{INFRA_COUNT}}
145
+ Validation: ✅ npx md validate ARCHITECTURE.md
146
+ ```
147
+
148
+ ---
149
+
150
+ ## Strict Substitution Rules
151
+
152
+ The skill **MUST** populate every section above. If a section does not apply to the project, write a single Mermaid block showing `(empty — no X found)` instead of removing the section. The template is **rigid** — do not reorder sections, do not merge sections, do not add free-form prose outside the labeled slots. Use diagrams and tables to express everything.
package/bin/cli.js CHANGED
@@ -4,12 +4,15 @@ 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 { SpecFinderService } from '../src/services/SpecFinderService.js';
7
8
  import { validateMermaidSyntax } from '../src/commands/validator.js';
8
9
  import * as initCmd from '../src/commands/init.js';
10
+ import * as listSpecsCmd from '../src/commands/listSpecs.js';
9
11
 
10
- // ─── Services ────────────────────────────────────────────────────────────────
12
+ // ─── Services ───────────────────────────────────────────────────────────────
11
13
  const fs = new FileSystemService();
12
14
  const initService = new InitService(fs);
15
+ const specFinderService = new SpecFinderService();
13
16
 
14
17
  // ─── CLI Setup ───────────────────────────────────────────────────────────────
15
18
  const program = new Command();
@@ -17,7 +20,7 @@ const program = new Command();
17
20
  program
18
21
  .name('md')
19
22
  .description('Manager for co-located specifications for Mermaid Diagram Driven Development (MDDD)')
20
- .version('4.4.0');
23
+ .version('6.2.0');
21
24
 
22
25
  // ==========================================
23
26
  // COMMAND: md init
@@ -51,5 +54,18 @@ program
51
54
  process.exit(0);
52
55
  });
53
56
 
54
- // ─── Parse ───────────────────────────────────────────────────────────────────
55
- program.parse(process.argv);
57
+ program
58
+ .command('list-specs')
59
+ .description('List all .spec.md files in the project tree (returns JSON)')
60
+ .action(async () => {
61
+ try {
62
+ await listSpecsCmd.execute(specFinderService);
63
+ process.exit(0);
64
+ } catch (err) {
65
+ console.error(pc.red(`❌ ${err.message}`));
66
+ process.exit(1);
67
+ }
68
+ });
69
+
70
+ // ─── Parse ─────────────────────────────────────────────────────────────────
71
+ program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mddd-cli",
3
- "version": "4.4.0",
3
+ "version": "6.2.0",
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",
@@ -33,6 +33,7 @@ export async function execute(initService) {
33
33
  // 2. Caminhos de origem dentro do pacote da CLI
34
34
  const cliSkillsSourceDir = path.join(cliRootDir, '.agents', 'skills');
35
35
  const cliSpecTemplatePath = path.join(cliRootDir, '.agents', 'templates', 'spec-template.md');
36
+ const cliArchitectureTemplatePath = path.join(cliRootDir, '.agents', 'templates', 'ARCHITECTURE.template.md');
36
37
 
37
38
  await initService.createSystemPrompt(systemPrompt);
38
39
 
@@ -45,6 +46,9 @@ export async function execute(initService) {
45
46
  // 5. Copia o spec template para o projeto
46
47
  await initService.createSpecTemplate(cliSpecTemplatePath, (msg) => console.log(msg));
47
48
 
48
- console.log(pc.green('\n🚀 Universal [system_prompt.md], SKILLS, and spec template generated successfully in the project root!'));
49
+ // 6. Copia o ARCHITECTURE template (usado pela skill mddd-context-map)
50
+ await initService.createArchitectureTemplate(cliArchitectureTemplatePath, (msg) => console.log(msg));
51
+
52
+ console.log(pc.green('\n🚀 Universal [system_prompt.md], SKILLS, spec template, and architecture template generated successfully in the project root!'));
49
53
  console.log(pc.green('Run the "md init" command whenever you update the MDDD-CLI NPM package.'));
50
- }
54
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Executes the `md list-specs` command.
3
+ * @param {{ findSpecs: (rootDir: string) => string[] }} specFinder
4
+ * @returns {Promise<string[]>}
5
+ */
6
+ export async function execute(specFinder) {
7
+ const specs = specFinder.findSpecs(process.cwd());
8
+ console.log(JSON.stringify({ specs }, null, 2));
9
+ return specs;
10
+ }
@@ -95,4 +95,26 @@ export class InitService {
95
95
  await this.#fs.writeFile(targetFile, content);
96
96
  logger(`✅ Spec template copied: ${targetFile}`);
97
97
  }
98
+
99
+ /**
100
+ * Copies the ARCHITECTURE template (used by the `mddd-context-map` skill)
101
+ * to the project's .agents/templates/ directory.
102
+ * @param {string} sourceTemplatePath - Absolute path to the CLI source ARCHITECTURE.template.md
103
+ * @param {(message: string) => void} logger
104
+ * @returns {Promise<void>}
105
+ */
106
+ async createArchitectureTemplate(sourceTemplatePath, logger) {
107
+ const templatesDir = path.join('.agents', 'templates');
108
+ const targetFile = path.join(templatesDir, 'ARCHITECTURE.template.md');
109
+
110
+ if (!fs.existsSync(sourceTemplatePath)) {
111
+ throw new Error(`Source architecture template not found at: ${sourceTemplatePath}`);
112
+ }
113
+
114
+ this.#fs.ensureDir(templatesDir);
115
+
116
+ const content = fs.readFileSync(sourceTemplatePath, 'utf-8');
117
+ await this.#fs.writeFile(targetFile, content);
118
+ logger(`✅ Architecture template copied: ${targetFile}`);
119
+ }
98
120
  }
@@ -0,0 +1,40 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ const IGNORED_DIRECTORIES = new Set(['node_modules', '.git', '.agents', 'build', 'dist']);
5
+ const SPEC_EXTENSION = '.spec.md';
6
+
7
+ export class SpecFinderService {
8
+ /**
9
+ * Recursively scans the project tree for `.spec.md` files.
10
+ * @param {string} [rootDir=process.cwd()]
11
+ * @returns {string[]}
12
+ */
13
+ findSpecs(rootDir = process.cwd()) {
14
+ const specs = [];
15
+
16
+ const walk = (dir) => {
17
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
18
+
19
+ for (const entry of entries) {
20
+ if (entry.isDirectory()) {
21
+ if (IGNORED_DIRECTORIES.has(entry.name)) {
22
+ continue;
23
+ }
24
+
25
+ walk(path.join(dir, entry.name));
26
+ continue;
27
+ }
28
+
29
+ if (entry.isFile() && entry.name.endsWith(SPEC_EXTENSION)) {
30
+ const absolutePath = path.join(dir, entry.name);
31
+ const relativePath = path.relative(rootDir, absolutePath).replace(/\\/g, '/');
32
+ specs.push(relativePath);
33
+ }
34
+ }
35
+ };
36
+
37
+ walk(rootDir);
38
+ return specs.sort();
39
+ }
40
+ }