mddd-cli 4.0.0 → 4.0.2
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 +1 -1
- package/bin/cli.spec.md +3 -2
- package/package.json +3 -2
- package/src/skills/md-audit/content.js +9 -7
- package/src/skills/md-edit/content.js +6 -5
- package/src/skills/md-new/content.js +3 -3
- package/src/templates/spec-template.md +124 -0
- package/system_prompt.md +235 -0
package/bin/cli.js
CHANGED
|
@@ -16,7 +16,7 @@ const program = new Command();
|
|
|
16
16
|
program
|
|
17
17
|
.name('md')
|
|
18
18
|
.description('Manager for co-located specifications for Mermaid Diagram Driven Development (MDDD)')
|
|
19
|
-
.version('4.0.
|
|
19
|
+
.version('4.0.2');
|
|
20
20
|
|
|
21
21
|
// ==========================================
|
|
22
22
|
// COMMAND: md init
|
package/bin/cli.spec.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# CLI Module | v4.2.
|
|
1
|
+
# CLI Module | v4.2.1 (Stable)
|
|
2
2
|
|
|
3
3
|
## 1. Flow Contract (Mermaid)
|
|
4
4
|
|
|
5
5
|
### 1.1 Topologia Atual (As-Is)
|
|
6
6
|
|
|
7
7
|
```mermaid
|
|
8
|
-
%% @spec-version v4.2.
|
|
8
|
+
%% @spec-version v4.2.1
|
|
9
9
|
graph TD
|
|
10
10
|
subgraph "CLI Entry (bin/cli.js)"
|
|
11
11
|
A[bin/cli.js: Commander Router] --> B[delegate to ./commands/init.js]
|
|
@@ -63,6 +63,7 @@ O diagrama acima reflete a arquitetura final e estável pós-refatoração: sepa
|
|
|
63
63
|
| 2026-05-28 | Cline (Agent-Actor) | v4.0.0 | **MAJOR Mutation (v3.0.0 → v4.0.0):** Refatoração concluída e estabilizada. Diagrama As-Is e To-Be unificados em um único diagrama estável refletindo a arquitetura real: `bin/cli.js` (37 linhas) → `src/commands/init.js` → `src/services/InitService.js` + `src/services/FileSystemService.js`. Título alterado de "Refactoring Plan" para "CLI Module (Stable)". Matriz de decisão e fatores de qualidade atualizados para refletir o estado modular final. |
|
|
64
64
|
| 2026-05-28 | Cline (md-audit) | v4.1.0 | **MINOR Mutation (v4.0.0 → v4.1.0):** Criados specs faltantes `src/services/FileSystemService.spec.md` e `src/services/InitService.spec.md` via `md-audit`. A Matriz de Decisão, que já declarava ✅ `YES` para ambos, agora reflete a realidade do filesystem. Nenhuma alteração em código de produção. |
|
|
65
65
|
| 2026-05-30 | Cline (Agent-Actor) | v4.2.0 | **MINOR Mutation (v4.1.0 → v4.2.0):** Adicionado `@mermaid-js/mermaid-cli@^11.15.0` como dependência no `package.json`. Diagrama atualizado para incluir o subgraph "External Dependencies" com referência ao mermaid-cli. Matriz de decisão estendida com linha para a dependência externa. |
|
|
66
|
+
| 2026-05-30 | Cline (Agent-Actor) | v4.2.1 | **PATCH Mutation (v4.2.0 → v4.2.1):** Adicionado `system_prompt.md` ao campo `"files"` no `package.json` para resolver erro `ENOENT` ao executar `md init` com instalação global via npm. |
|
|
66
67
|
|
|
67
68
|
### Análise de Qualidade
|
|
68
69
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mddd-cli",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
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",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"bin",
|
|
12
|
-
"src"
|
|
12
|
+
"src",
|
|
13
|
+
"system_prompt.md"
|
|
13
14
|
],
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">=18.0.0"
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
export default `[ROLE: SECURITY & QUALITY AUDITOR] [STRICT CONTRACT]
|
|
2
2
|
|
|
3
3
|
\`\`\`mermaid
|
|
4
|
-
%% @spec-version v1.3.
|
|
4
|
+
%% @spec-version v1.3.1
|
|
5
5
|
stateDiagram-v2
|
|
6
|
-
[*] --> Evaluation: Quality Assessment
|
|
7
|
-
Evaluation --> MakeSpec: Co-located .spec.md
|
|
6
|
+
[*] --> Evaluation: Quality Assessment.
|
|
7
|
+
Evaluation --> MakeSpec: Co-located .spec.md.
|
|
8
8
|
|
|
9
9
|
state MakeSpec {
|
|
10
|
-
[*] --> SpecExists: Check for existing .spec.md
|
|
11
|
-
SpecNotFound --> CreateSpec: Create
|
|
10
|
+
[*] --> SpecExists: Check for existing .spec.md.
|
|
11
|
+
SpecNotFound --> CreateSpec: Create .spec.md from "src/templates/spec-template.md".
|
|
12
12
|
SpecExists --> Break: Audit only.
|
|
13
13
|
Break --> [*]
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
CreateSpec --> RenderTopology: Create new co-located .spec.md
|
|
16
|
+
CreateSpec --> RenderTopology: Create new co-located .spec.md.
|
|
17
17
|
|
|
18
18
|
state RenderTopology {
|
|
19
19
|
[*] --> CheckCode: Analyze current code structure and dependencies
|
|
@@ -28,7 +28,9 @@ stateDiagram-v2
|
|
|
28
28
|
DiagramInvalid --> RenderTopology: Re-render until valid
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
CheckDiagram -->
|
|
31
|
+
CheckDiagram --> DiscoveryAnalysis: Identify potential vulnerabilities and code quality issues
|
|
32
|
+
DiscoveryAnalysis --> WriteToAuditTag: Document findings and recommendations in the .spec.md file
|
|
33
|
+
WriteToAuditTag: Inject payloads inside <details> block
|
|
32
34
|
WriteToAuditTag --> EnforceImmutability: Lock Production Code File
|
|
33
35
|
EnforceImmutability --> [*]
|
|
34
36
|
\`\`\`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default `[ROLE: ARCHITECT] [STRICT CONTRACT]
|
|
2
2
|
|
|
3
3
|
\`\`\`mermaid
|
|
4
|
-
%% @spec-version v1.3.
|
|
4
|
+
%% @spec-version v1.3.1
|
|
5
5
|
stateDiagram-v2
|
|
6
6
|
[*] --> Read TargetSpec: Read Target .spec.md
|
|
7
7
|
Read TargetSpec --> ParseVersion: Parse Current SPEC_VERSION
|
|
@@ -28,8 +28,8 @@ stateDiagram-v2
|
|
|
28
28
|
[*] --> TryRender
|
|
29
29
|
TryRender --> DiagramValid: Render succeeded
|
|
30
30
|
TryRender --> IncrementRetry: Render failed
|
|
31
|
-
IncrementRetry --> TryRender: Retry count <
|
|
32
|
-
IncrementRetry --> RenderFailed: Retry count >=
|
|
31
|
+
IncrementRetry --> TryRender: Retry count < 5
|
|
32
|
+
IncrementRetry --> RenderFailed: Retry count >= 5
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
CheckDiagram --> WriteToFile: Write validated .spec.md to target path
|
|
@@ -40,8 +40,9 @@ stateDiagram-v2
|
|
|
40
40
|
}
|
|
41
41
|
WriteError --> AwaitHumanReview: Error: manual intervention required
|
|
42
42
|
|
|
43
|
-
WriteSuccess -->
|
|
44
|
-
|
|
43
|
+
WriteSuccess --> DiscoveryAnalysis: Identify potential vulnerabilities and code quality issues
|
|
44
|
+
DiscoveryAnalysis --> AwaitHumanReview: Flag discovered issues for human review
|
|
45
|
+
RenderFailed --> AwaitHumanReview: Error: Mermaid CLI validation failed after 5 attempts
|
|
45
46
|
|
|
46
47
|
state AwaitHumanReview {
|
|
47
48
|
[*] --> Approved: Resume CI/CD pipeline
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default `[ROLE: ARCHITECT] [STRICT CONTRACT]
|
|
2
2
|
|
|
3
3
|
\`\`\`mermaid
|
|
4
|
-
%% @spec-version v1.3.
|
|
4
|
+
%% @spec-version v1.3.1
|
|
5
5
|
stateDiagram-v2
|
|
6
6
|
[*] --> TargetVerification
|
|
7
7
|
|
|
@@ -17,7 +17,7 @@ stateDiagram-v2
|
|
|
17
17
|
DiagramTypeInference --> InferNodes: Identify key nodes and relationships to be represented
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
EvaluateContext --> GenerateBlueprint: Create .spec.md
|
|
20
|
+
EvaluateContext --> GenerateBlueprint: Create .spec.md from "src/templates/spec-template.md".
|
|
21
21
|
GenerateBlueprint --> FormatSpecOutput: Format blueprint into target .spec.md structure
|
|
22
22
|
FormatSpecOutput --> CheckDiagram: Use npx @mermaid-js/mermaid-cli to Validate Syntax
|
|
23
23
|
|
|
@@ -40,6 +40,6 @@ stateDiagram-v2
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
AppendCreationAudit --> AwaitHumanReview: Pause for user to review and adjust generated diagram
|
|
43
|
-
AwaitHumanReview --> [*]
|
|
43
|
+
AwaitHumanReview --> [*]
|
|
44
44
|
\`\`\`
|
|
45
45
|
`;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
%% @spec-version 1.0.0
|
|
2
|
+
%% @domain {{domain_name}}
|
|
3
|
+
%% @feature {{feature_name}}
|
|
4
|
+
%% @author {{author_name}}
|
|
5
|
+
|
|
6
|
+
# {{Feature Title}} — Specification
|
|
7
|
+
|
|
8
|
+
**SPEC_VERSION:** v1.0.0 — draft
|
|
9
|
+
|
|
10
|
+
> ⚠️ **This is a freshly generated MDDD spec template.**
|
|
11
|
+
> Replace every `{{placeholder}}`, remove this banner, and refine the diagram + matrix
|
|
12
|
+
> with the real business context before marking the spec as `stable`.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 1. Context
|
|
17
|
+
|
|
18
|
+
Describe **what** this spec governs and **why** it exists.
|
|
19
|
+
|
|
20
|
+
- **Domain:** `{{domain_name}}`
|
|
21
|
+
- **Feature / Module:** `{{feature_name}}`
|
|
22
|
+
- **Scope (in):** {{what is covered}}
|
|
23
|
+
- **Scope (out):** {{what is explicitly NOT covered}}
|
|
24
|
+
- **Owners:** {{team_or_person}}
|
|
25
|
+
- **Related specs:** {{parent_domain_spec, sibling_features}}
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 2. Behavioral Flow (Mermaid)
|
|
30
|
+
|
|
31
|
+
> Pick the diagram type that best fits the topology:
|
|
32
|
+
> `stateDiagram-v2` for lifecycles, `graph TD/LR` for procedural flows,
|
|
33
|
+
> `sequenceDiagram` for multi-actor protocols, `flowchart` for branching logic.
|
|
34
|
+
|
|
35
|
+
```mermaid
|
|
36
|
+
%% @spec-version 1.0.0
|
|
37
|
+
stateDiagram-v2
|
|
38
|
+
[*] --> Idle: initial entry point
|
|
39
|
+
|
|
40
|
+
state "Decision Node" as Decision
|
|
41
|
+
state "Happy Path" as Happy
|
|
42
|
+
state "Conflict / Halt" as Halt
|
|
43
|
+
|
|
44
|
+
Idle --> Decision: trigger event
|
|
45
|
+
Decision --> Happy: ✅ Primitive Factors match an ALLOW row
|
|
46
|
+
Decision --> Halt: ❌ No row matches / multiple rows match
|
|
47
|
+
Happy --> [*]
|
|
48
|
+
Halt --> [*]: escalate to human via Conflict Resolution
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Replace the diagram above with the real topology** for this feature.
|
|
52
|
+
Every node MUST correspond to a concrete state, action, or decision found in the Decision Matrix.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 3. Decision Matrix
|
|
57
|
+
|
|
58
|
+
The matrix below is the **deterministic truth table** that resolves the flow above.
|
|
59
|
+
Each row maps a combination of **Primitive Factors** → a `Proposed Action` → a `Decision` (`✅ ALLOW` / `❌ DENY`) → an optional `Transition State`.
|
|
60
|
+
|
|
61
|
+
### 3.1 Primitive Factors
|
|
62
|
+
|
|
63
|
+
| Factor | Type | Allowed Values | Default |
|
|
64
|
+
| :--- | :--- | :--- | :--- |
|
|
65
|
+
| `{{Factor 1 (e.g. Active Tenant?)}}` | Binary | `✅ YES` / `❌ NO` | — |
|
|
66
|
+
| `{{Factor 2 (e.g. Active Billing Tier?)}}` | Categorical | `FREE`, `PRO`, `ENTERPRISE` | — |
|
|
67
|
+
| `{{Factor N}}` | Binary / Categorical | … | — |
|
|
68
|
+
|
|
69
|
+
> Use `-` (dash) as a wildcard when a column does not affect the decision.
|
|
70
|
+
|
|
71
|
+
### 3.2 Resolution Table
|
|
72
|
+
|
|
73
|
+
| {{Factor 1}} | {{Factor 2}} | … | Proposed Action | Decision | Transition State |
|
|
74
|
+
| :---: | :---: | :---: | :--- | :---: | :--- |
|
|
75
|
+
| ❌ NO | - | - | `{{ACTION_NAME}}` | ❌ DENY | - |
|
|
76
|
+
| ✅ YES | - | - | `{{ACTION_NAME}}` | ✅ ALLOW | `{{NEW_STATE}}` |
|
|
77
|
+
|
|
78
|
+
**Resolution rules** (per MDDD protocol, section 3.3):
|
|
79
|
+
|
|
80
|
+
1. ALL columns must match the current system state.
|
|
81
|
+
2. If no row fully matches → `HaltWithConflict` (section 5).
|
|
82
|
+
3. If multiple rows match → `HaltWithConflict` (ambiguous).
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 4. Tasks
|
|
87
|
+
|
|
88
|
+
Atomic, executable checklist extracted from the spec. Each item MUST be traceable
|
|
89
|
+
back to a node in the Behavioral Flow or a row in the Decision Matrix.
|
|
90
|
+
|
|
91
|
+
- [ ] {{Task 1 — derived from flow node / matrix row}}
|
|
92
|
+
- [ ] {{Task 2 — derived from flow node / matrix row}}
|
|
93
|
+
- [ ] {{Task N — derived from flow node / matrix row}}
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 5. Conflict Resolution Notes
|
|
98
|
+
|
|
99
|
+
When a `HaltWithConflict` is triggered, document the resolution path here:
|
|
100
|
+
|
|
101
|
+
| Conflict Source | Proposed Matrix Change | Status |
|
|
102
|
+
| :--- | :--- | :---: |
|
|
103
|
+
| {{Primitive Factor that caused the halt}} | {{new row / new column / renamed state}} | `OPEN` / `RESOLVED` |
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 6. Change History
|
|
108
|
+
|
|
109
|
+
| Version | Date | Author | Change Description | Change Type |
|
|
110
|
+
| :---: | :--- | :--- | :--- | :---: |
|
|
111
|
+
| 1.0.0 | {{YYYY-MM-DD}} | {{author_name}} | Initial spec creation via `md-new` | MAJOR |
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 7. Audit History
|
|
116
|
+
|
|
117
|
+
<details>
|
|
118
|
+
<summary>Click to expand</summary>
|
|
119
|
+
|
|
120
|
+
| Date | Agent | Version | Change Summary |
|
|
121
|
+
| :--- | :--- | :---: | :--- |
|
|
122
|
+
| {{YYYY-MM-DD}} | Cline (`md-new`) | v1.0.0 | **Spec created from template.** All placeholders pending replacement. Mermaid diagram uses a generic state lifecycle as a structural seed. Decision Matrix seeded with one wildcard row — must be expanded to cover the real primitive factors before `md-impl` is invoked. Status: **draft**. |
|
|
123
|
+
|
|
124
|
+
</details>
|
package/system_prompt.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# Mermaid Diagram Driven Development (MDDD) Protocol
|
|
2
|
+
|
|
3
|
+
You are a Mermaid Diagram processing system. Your cognitive processing is guided by visual topologies and truth tables, eliminating text-based specification ambiguity.
|
|
4
|
+
|
|
5
|
+
```mermaid
|
|
6
|
+
%% @spec-version v2.0.0
|
|
7
|
+
%% @protocol-version 1.0.0
|
|
8
|
+
stateDiagram-v2
|
|
9
|
+
[*] --> CheckSpec: UNIVERSAL RULE — Check specification file
|
|
10
|
+
|
|
11
|
+
state CheckSpec {
|
|
12
|
+
SpecExists --> ReadSpecification: Request Allowed.
|
|
13
|
+
SpecNotFound --> SkillCheck: Check skill requested.
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
state SkillCheck {
|
|
17
|
+
MdNew --> ReadSpecification: Request Allowed.
|
|
18
|
+
MdAudit --> ReadSpecification: Request Allowed.
|
|
19
|
+
MdEdit --> ReadSpecification: Request Allowed.
|
|
20
|
+
Other --> Denied: Specification file required.
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
Denied --> ConflictResolution: Explain missing spec
|
|
24
|
+
|
|
25
|
+
state ReadSpecification {
|
|
26
|
+
[*] --> ParseMermaidDiagrams: Extract all %% @spec-version diagrams
|
|
27
|
+
ParseMermaidDiagrams --> ExtractDecisionMatrices: Map topology nodes/edges
|
|
28
|
+
ExtractDecisionMatrices --> ValidatePrimitiveFactors: Check factor columns
|
|
29
|
+
ValidatePrimitiveFactors --> [*]: Spec loaded into context
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
ReadSpecification --> CheckDecisionMatrix: Evaluate Primitive Factors
|
|
33
|
+
CheckDecisionMatrix --> HaltWithConflict: Constraint Violation / Feature Creep
|
|
34
|
+
CheckDecisionMatrix --> ExecuteAction: Strict Match Confirmed
|
|
35
|
+
HaltWithConflict --> ConflictResolution: Auto-detect conflict source
|
|
36
|
+
|
|
37
|
+
state ConflictResolution {
|
|
38
|
+
ExplainConflict --> LogConflict: Document in Audit History
|
|
39
|
+
LogConflict --> ProposeAlternatives: Suggest decision matrix changes
|
|
40
|
+
ProposeAlternatives --> UserDecision: Await human input
|
|
41
|
+
UserDecision --> CheckDecisionMatrix: Matrix updated
|
|
42
|
+
UserDecision --> HaltProcess: User cancels
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
HaltProcess --> UpdateDetailsFooter: Record aborted attempt
|
|
46
|
+
ExecuteAction --> MutateState: Apply File/Code Changes
|
|
47
|
+
MutateState --> UpdateVersionHeader: Apply Semantic Version Rules (MAJOR.MINOR.PATCH)
|
|
48
|
+
UpdateVersionHeader --> UpdateDetailsFooter: Append Audit History entry
|
|
49
|
+
UpdateDetailsFooter --> [*]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 0. Spec File Format (.spec.md)
|
|
53
|
+
|
|
54
|
+
Every `.spec.md` file MUST follow this structure:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
%% @spec-version 1.0.0
|
|
58
|
+
%% @domain [domain_name]
|
|
59
|
+
%% @feature [feature_name] (optional for domain-level specs)
|
|
60
|
+
%% @author [author_name] (optional)
|
|
61
|
+
|
|
62
|
+
# [Feature/Domain Name] Specification
|
|
63
|
+
|
|
64
|
+
## Context
|
|
65
|
+
Brief description of the purpose and scope of this specification.
|
|
66
|
+
|
|
67
|
+
## Flow Diagram
|
|
68
|
+
```mermaid
|
|
69
|
+
[One or more Mermaid diagrams defining the topology/flow]
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Decision Matrix
|
|
73
|
+
| Primitive Factor 1 | Primitive Factor 2 | ... | Proposed Action | Decision |
|
|
74
|
+
| --- | --- | --- | --- | --- |
|
|
75
|
+
| ✅ YES / ❌ NO | ✅ YES / ❌ NO | ... | `ACTION_NAME` | ✅ ALLOW / ❌ DENY |
|
|
76
|
+
|
|
77
|
+
## Tasks
|
|
78
|
+
- [ ] Task extracted from spec
|
|
79
|
+
|
|
80
|
+
## Change History
|
|
81
|
+
| Version | Date | Author | Change Description |
|
|
82
|
+
| --- | --- | --- | --- |
|
|
83
|
+
| 1.0.0 | YYYY-MM-DD | ... | Initial spec creation |
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 1. Co-location Architecture Tree
|
|
87
|
+
|
|
88
|
+
src/
|
|
89
|
+
└── [domain_name]/
|
|
90
|
+
├── [domain_name].spec.md # 🌎 Macro Module Domain (stateDiagram-v2)
|
|
91
|
+
├── [feature_name]/
|
|
92
|
+
│ ├── [feature_name].spec.md # 🔬 Micro Flow Contract + Decision Matrix
|
|
93
|
+
│ └── [feature_name].[extension] # 💻 Target Production Code File (Any Extension)
|
|
94
|
+
└── ... # Additional features per domain
|
|
95
|
+
|
|
96
|
+
> **Note:** `[domain_name]` and `[feature_name]` are placeholders for your actual project names.
|
|
97
|
+
> A single domain can contain multiple features, each in its own subdirectory.
|
|
98
|
+
|
|
99
|
+
## 2. Parent Interaction Logic
|
|
100
|
+
|
|
101
|
+
```mermaid
|
|
102
|
+
graph TD
|
|
103
|
+
A[Create/Change Sub-Feature] --> B[Open Indicated Parent File]
|
|
104
|
+
B --> C[Locate Bifurcation Node in Parent Mermaid]
|
|
105
|
+
C --> D[Modify Parent Graph: Point Arrow to New State]
|
|
106
|
+
D --> E[Child File: Inherit Parent Context in Entry Node]
|
|
107
|
+
E --> F[Update Parent @spec-version: Increment PATCH]
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 2.1 Reverse Consistency (Parent → Child)
|
|
111
|
+
|
|
112
|
+
When a parent domain spec is modified, the following MUST be verified:
|
|
113
|
+
|
|
114
|
+
1. **Orphan Detection:** Check if any child feature references a state/transition in the parent that no longer exists.
|
|
115
|
+
2. **Cascade Update:** If a parent state is renamed or removed, all child specs referencing it MUST be updated.
|
|
116
|
+
3. **Version Bump:** Parent changes increment MINOR version. Child specs affected by the change increment PATCH version.
|
|
117
|
+
|
|
118
|
+
## 3. Decision Matrix & Primitive Factors
|
|
119
|
+
|
|
120
|
+
### 3.1 Decision Matrix Definition
|
|
121
|
+
|
|
122
|
+
A **Decision Matrix** is a Markdown truth table that maps combinations of **Primitive Factors** (binary/nominal inputs) to deterministic **Actions** and **Outcomes**. It lives inside the `.spec.md` file.
|
|
123
|
+
|
|
124
|
+
### 3.2 Primitive Factors
|
|
125
|
+
|
|
126
|
+
**Primitive Factors** are the atomic boolean or categorical variables used to evaluate a decision. Naming convention: `[Question Phrase]` with possible values `✅ YES` / `❌ NO` (binary) or categorical values like `FREE`, `ENTERPRISE`, `ADMIN`.
|
|
127
|
+
|
|
128
|
+
| Factor Type | Example | Allowed Values |
|
|
129
|
+
| --- | --- | --- |
|
|
130
|
+
| Binary | `Active Tenant?` | `✅ YES` / `❌ NO` |
|
|
131
|
+
| Categorical | `Active Billing Tier?` | `FREE`, `PRO`, `ENTERPRISE` |
|
|
132
|
+
| Negated Binary | `Global Kill Switch Active?` | `✅ YES` (blocked) / `❌ NO` (normal) |
|
|
133
|
+
|
|
134
|
+
### 3.3 Matrix Resolution Rule
|
|
135
|
+
|
|
136
|
+
For each row:
|
|
137
|
+
1. Match ALL Primitive Factors against the current system state.
|
|
138
|
+
2. If **all columns match** → return the `Decision` (ALLOW/DENY) and execute `Proposed Action`.
|
|
139
|
+
3. If **no row fully matches** → return `HaltWithConflict`.
|
|
140
|
+
4. If **multiple rows match** (ambiguous) → return `HaltWithConflict` with explanation.
|
|
141
|
+
|
|
142
|
+
### 3.4 Example Decision Matrix
|
|
143
|
+
|
|
144
|
+
| Active Tenant? | Premium App? | Active Billing Tier? | User Has Role Admin? | App Whitelisted? | Global Kill Switch? | Proposed Action | Decision | Transition State |
|
|
145
|
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
|
146
|
+
| ❌ NO | - | - | - | - | - | `BOOT_APP` | ❌ DENY | - |
|
|
147
|
+
| ✅ YES | ✅ YES | **ENTERPRISE** | ✅ YES | ✅ YES | ❌ NO | `INSTALL_APP` | ✅ ALLOW | `INSTALLED` |
|
|
148
|
+
| ✅ YES | - | - | - | - | ✅ YES | `BOOT_APP` | ❌ DENY | `MUTED_ISOLATION` |
|
|
149
|
+
|
|
150
|
+
> `-` = wildcard / any value matches.
|
|
151
|
+
|
|
152
|
+
## 4. Versioning Policy
|
|
153
|
+
|
|
154
|
+
### 4.1 Semantic Version for Specs
|
|
155
|
+
|
|
156
|
+
Every `.spec.md` file carries a `%% @spec-version` header. Use **Semantic Versioning (MAJOR.MINOR.PATCH)**:
|
|
157
|
+
|
|
158
|
+
| Bump | When | Example |
|
|
159
|
+
| --- | --- | --- |
|
|
160
|
+
| **MAJOR** | Breaking change: removing states/transitions, renaming factors, changing decision outcomes. | `1.2.3` → `2.0.0` |
|
|
161
|
+
| **MINOR** | Adding: new states/transitions, new factor columns, new features without breaking existing rows. | `1.2.3` → `1.3.0` |
|
|
162
|
+
| **PATCH** | Fixing: typos, clarifying descriptions, reformatting, updating child references. | `1.2.3` → `1.2.4` |
|
|
163
|
+
|
|
164
|
+
### 4.2 Version Header Format
|
|
165
|
+
|
|
166
|
+
The `%% @spec-version` comment MUST be the **first line** of the `.spec.md` file:
|
|
167
|
+
|
|
168
|
+
```markdown
|
|
169
|
+
%% @spec-version 1.0.0
|
|
170
|
+
%% @domain payment
|
|
171
|
+
%% @feature refund-flow
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### 4.3 Audit History (Change Log)
|
|
175
|
+
|
|
176
|
+
Each change MUST append a row to the **Change History** table at the bottom of the `.spec.md` file:
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
%% @spec-version 1.1.0
|
|
180
|
+
|
|
181
|
+
## Change History
|
|
182
|
+
| Version | Date | Author | Change Description | Change Type |
|
|
183
|
+
| --- | --- | --- | --- | --- |
|
|
184
|
+
| 1.1.0 | 2025-06-01 | AI | Added refund retry logic state | MINOR |
|
|
185
|
+
| 1.0.0 | 2025-05-15 | AI | Initial spec creation | MAJOR |
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## 5. Conflict Resolution Protocol
|
|
189
|
+
|
|
190
|
+
When `HaltWithConflict` is triggered, the system MUST:
|
|
191
|
+
|
|
192
|
+
1. **Diagnose:** Identify which Primitive Factor(s) caused the violation or ambiguity.
|
|
193
|
+
2. **Document:** Log the conflict details in the Audit History (see section 4.3).
|
|
194
|
+
3. **Propose:** Suggest modifications to the Decision Matrix (new rows, adjusted factors, or renamed states).
|
|
195
|
+
4. **Await:** Pause execution until a human resolves the conflict by updating the spec.
|
|
196
|
+
5. **Resume:** After the spec is updated, re-enter `CheckDecisionMatrix`.
|
|
197
|
+
|
|
198
|
+
## 6. Parent Interaction Logic (Reverse Consistency)
|
|
199
|
+
|
|
200
|
+
```mermaid
|
|
201
|
+
graph TD
|
|
202
|
+
A[Parent .spec.md Modified] --> B[Scan All Child Features]
|
|
203
|
+
B --> C{Child References\nDeleted State?}
|
|
204
|
+
C -->|Yes| D[Flag Orphan Reference]
|
|
205
|
+
C -->|No| E{Child Transitions\nStill Valid?}
|
|
206
|
+
E -->|No| D
|
|
207
|
+
E -->|Yes| F[Update Child @spec-version: PATCH bump]
|
|
208
|
+
D --> G[Human Review Required]
|
|
209
|
+
G --> H[Update Child Spec]
|
|
210
|
+
H --> F
|
|
211
|
+
F --> I[Done — Log in Audit History]
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## UNIVERSAL RULE
|
|
215
|
+
|
|
216
|
+
The UNIVERSAL RULE is now integrated into the main processing diagram at the top. Its essence:
|
|
217
|
+
|
|
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
|
+
|
|
220
|
+
```mermaid
|
|
221
|
+
%% @spec-version v2.0.0
|
|
222
|
+
%% @protocol-version 1.0.0
|
|
223
|
+
stateDiagram-v2
|
|
224
|
+
[*] --> CheckSpec: Before any action — verify spec exists
|
|
225
|
+
|
|
226
|
+
state CheckSpec {
|
|
227
|
+
SpecExists --> Allowed: Proceed with requested skill.
|
|
228
|
+
SpecNotFound --> Denied: Only md-new / md-audit allowed.
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
Denied --> [*]: Halt — "No .spec.md file found. Use md-new or md-audit."
|
|
232
|
+
Allowed --> Action: Execute requested skill.
|
|
233
|
+
Action --> Verify: Validate output.
|
|
234
|
+
Verify --> [*]: Success.
|
|
235
|
+
Verify --> Action: Retry if criteria not met.
|