mddd-cli 6.2.2 → 7.1.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.
- package/.agents/skills/md-audit/SKILL.md +36 -34
- package/.agents/skills/md-edit/SKILL.md +38 -50
- package/.agents/skills/md-impl/SKILL.md +58 -48
- package/.agents/skills/md-new/SKILL.md +29 -40
- package/.agents/templates/spec-template.md +22 -40
- package/AGENTS.md +192 -0
- package/bin/cli.js +15 -1
- package/package.json +2 -2
- package/readme.md +105 -19
- package/src/commands/init.js +3 -3
- package/src/commands/status.js +534 -0
- package/src/commands/status.spec.md +131 -0
- package/src/services/FileSystemService.spec.md +3 -1
- package/src/services/InitService.js +1 -1
- package/src/services/InitService.spec.md +7 -5
- package/system_prompt.md +0 -171
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
[ROLE: SECURITY & QUALITY AUDITOR] [STRICT CONTRACT]
|
|
2
|
-
|
|
3
1
|
```mermaid
|
|
4
|
-
%% @spec-version v1.3.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
2
|
+
%% @spec-version v1.3.3
|
|
3
|
+
graph TD
|
|
4
|
+
Start((Start)) --> Evaluation{Quality Assessment}
|
|
5
|
+
|
|
6
|
+
Evaluation -->|Co-located .spec.md| MakeSpec
|
|
7
|
+
|
|
8
|
+
subgraph MakeSpec[Check Existing Spec]
|
|
9
|
+
direction TB
|
|
10
|
+
M1{Spec exists?}
|
|
11
|
+
M1 -->|No| M2[Create .spec.md from .agents/templates/spec-template.md]
|
|
12
|
+
M1 -->|Yes| M3[Audit only]
|
|
13
|
+
M3 --> Break([Break])
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
M2 --> RenderTopology
|
|
17
|
+
|
|
18
|
+
subgraph RenderTopology[Analyze Code]
|
|
19
|
+
direction TB
|
|
20
|
+
R1[Analyze code structure and dependencies]
|
|
21
|
+
R1 --> R2{Chaotic or Coese?}
|
|
22
|
+
R2 -->|Coese| R3[Map exact architecture — stable]
|
|
23
|
+
R2 -->|Chaotic| R4[Draw current + ideal refactored graph — draft]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
RenderTopology --> CheckDiagram
|
|
27
|
+
|
|
28
|
+
subgraph CheckDiagram[Validate Syntax]
|
|
29
|
+
direction TB
|
|
30
|
+
C1{Diagram valid?}
|
|
31
|
+
C1 -->|Yes| C2[Proceed]
|
|
32
|
+
C1 -->|No| RenderTopology
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
CheckDiagram --> D[Identify vulnerabilities and code quality issues]
|
|
36
|
+
D --> W[Document findings in .spec.md <details> block]
|
|
37
|
+
W --> End((End))
|
|
36
38
|
```
|
|
37
39
|
|
|
38
40
|
```mermaid
|
|
@@ -1,56 +1,44 @@
|
|
|
1
1
|
[ROLE: ARCHITECT] [STRICT CONTRACT]
|
|
2
2
|
|
|
3
3
|
```mermaid
|
|
4
|
-
%% @spec-version v1.3.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Read
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
[
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
[
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
46
|
-
|
|
47
|
-
state AwaitHumanReview {
|
|
48
|
-
[*] --> Approved: Resume CI/CD pipeline
|
|
49
|
-
[*] --> ChangesRequested: Loop back to ApplyAdjustments
|
|
50
|
-
[*] --> Aborted: Terminate session
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
AwaitHumanReview --> [*]: Pause Code & Test Generation
|
|
4
|
+
%% @spec-version v1.3.2
|
|
5
|
+
graph TD
|
|
6
|
+
Start((Start)) --> Read[Read target .spec.md]
|
|
7
|
+
Read --> Parse[Parse SPEC_VERSION]
|
|
8
|
+
Parse --> Apply[Apply requested diagram/matrix adjustments]
|
|
9
|
+
Apply --> Scope{Evaluate mutation scope}
|
|
10
|
+
|
|
11
|
+
Scope -->|Typo / label fix| PatchBump[Increment PATCH]
|
|
12
|
+
Scope -->|New node / flow / factor| MinorBump[Increment MINOR]
|
|
13
|
+
Scope -->|Breaking restructure| MajorBump[Increment MAJOR]
|
|
14
|
+
|
|
15
|
+
PatchBump --> Validate
|
|
16
|
+
MinorBump --> Validate
|
|
17
|
+
MajorBump --> Validate
|
|
18
|
+
|
|
19
|
+
subgraph Validate[Validate & Write]
|
|
20
|
+
direction TB
|
|
21
|
+
V1[Try render with npx md validate] --> V2{Render result?}
|
|
22
|
+
V2 -->|Success| V3[Write to target path]
|
|
23
|
+
V2 -->|Failed, retries < 5| V1
|
|
24
|
+
V2 -->|Failed, retries >= 5| V4[[RENDER_FAILED]]
|
|
25
|
+
V3 --> V5{Write result?}
|
|
26
|
+
V5 -->|Success| V6[Proceed]
|
|
27
|
+
V5 -->|Error| V7[[WRITE_ERROR]]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
V6 --> Audit[Identify vulnerabilities and issues]
|
|
31
|
+
Audit --> Review
|
|
32
|
+
V4 --> Review
|
|
33
|
+
V7 --> Review
|
|
34
|
+
|
|
35
|
+
subgraph Review[Await Human Review]
|
|
36
|
+
direction TB
|
|
37
|
+
R1{Await decision}
|
|
38
|
+
R1 -->|Approved| R2([End])
|
|
39
|
+
R1 -->|Changes requested| Apply
|
|
40
|
+
R1 -->|Aborted| R3([End])
|
|
41
|
+
end
|
|
54
42
|
```
|
|
55
43
|
|
|
56
44
|
```mermaid
|
|
@@ -1,54 +1,64 @@
|
|
|
1
1
|
[ROLE: SOFTWARE ENGINEER] [STRICT CONTRACT]
|
|
2
2
|
|
|
3
3
|
```mermaid
|
|
4
|
-
%% @spec-version v1.3.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
4
|
+
%% @spec-version v1.3.2
|
|
5
|
+
graph TD
|
|
6
|
+
Start((Start)) --> Ingest[Ingest signed .spec.md]
|
|
7
|
+
Ingest --> Parse[Parse matrix rows & version header]
|
|
8
|
+
Parse --> Verify{Verify request against decision matrix}
|
|
9
|
+
|
|
10
|
+
Verify -->|100% match| CheckTarget{Check target state}
|
|
11
|
+
Verify -->|Skip / extraneous scope| Defense[[PROMPT INJECTION DEFENSE]]
|
|
12
|
+
Defense --> Refuse[Refuse — demand spec refinement via md-edit]
|
|
13
|
+
Refuse --> End((End))
|
|
14
|
+
|
|
15
|
+
CheckTarget -->|New file| GenCode[Generate code from scratch]
|
|
16
|
+
CheckTarget -->|Existing file| Overwrite[Idempotent overwrite]
|
|
17
|
+
|
|
18
|
+
Overwrite --> DataLossCheck{Data loss risk?}
|
|
19
|
+
|
|
20
|
+
subgraph DataLossCheck[Evaluate Data Loss Risk]
|
|
21
|
+
direction TB
|
|
22
|
+
D1[File exists + will be overwritten?]
|
|
23
|
+
D2[Changes outside spec scope?]
|
|
24
|
+
D3[Uncommitted changes?]
|
|
25
|
+
D1 --> D4{Any risk factor true?}
|
|
26
|
+
D2 --> D4
|
|
27
|
+
D3 --> D4
|
|
28
|
+
D4 -->|Yes| Alert[[ALERT — pause generation]]
|
|
29
|
+
D4 -->|No| Proceed
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
GenCode --> Proceed
|
|
33
|
+
Proceed --> GenTests[Generate truth-table unit tests]
|
|
34
|
+
GenTests --> Run{All tests pass?}
|
|
35
|
+
Run -->|Yes| Promote[Promote .spec.md: draft → stable]
|
|
36
|
+
Run -->|No| Fix[Fix code/tests & retry]
|
|
37
|
+
Fix --> Proceed
|
|
38
|
+
|
|
39
|
+
Promote --> Update[Update SPEC_VERSION to stable]
|
|
40
|
+
Update --> History[Append audit history]
|
|
41
|
+
History --> Persist[Persist .spec.md to disk]
|
|
42
|
+
Persist --> Review
|
|
43
|
+
|
|
44
|
+
subgraph Review[Await Human Approval]
|
|
45
|
+
direction TB
|
|
46
|
+
R1{Await decision}
|
|
47
|
+
R1 -->|Lock approved| Lock
|
|
48
|
+
R1 -->|Changes requested| GenCode
|
|
49
|
+
R1 -->|Aborted| End
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
subgraph Lock[Lock Code Immutability]
|
|
53
|
+
direction TB
|
|
54
|
+
L1[Install pre-commit hook]
|
|
55
|
+
L2[Set SPEC_IMMUTABLE: true]
|
|
56
|
+
L3[chmod 444 on production files]
|
|
57
|
+
L4[Verify git diff = clean]
|
|
58
|
+
L1 --> L2 --> L3 --> L4 --> L5([Lock confirmed])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
Lock --> End((End))
|
|
52
62
|
```
|
|
53
63
|
|
|
54
64
|
```mermaid
|
|
@@ -1,44 +1,33 @@
|
|
|
1
1
|
[ROLE: ARCHITECT] [STRICT CONTRACT]
|
|
2
2
|
|
|
3
3
|
```mermaid
|
|
4
|
-
%% @spec-version v1.3.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
CheckDiagram -->
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
[*] --> SetDraftVersion: Set SPEC_VERSION to v1.0.0-draft
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
InitializeVersion --> AppendCreationAudit: Record creation metadata
|
|
37
|
-
|
|
38
|
-
state AppendCreationAudit {
|
|
39
|
-
[*] --> LogCreation: Append audit entry: "Created via md-new" with timestamp
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
AppendCreationAudit --> AwaitHumanReview: Pause for user to review and adjust generated diagram
|
|
43
|
-
AwaitHumanReview --> [*]
|
|
4
|
+
%% @spec-version v1.3.2
|
|
5
|
+
graph TD
|
|
6
|
+
Start((Start)) --> CheckTarget{Target .spec.md exists?}
|
|
7
|
+
|
|
8
|
+
CheckTarget -->|Yes| Break([Break — existing specs are immutable. Use md-edit])
|
|
9
|
+
CheckTarget -->|No| Evaluate
|
|
10
|
+
|
|
11
|
+
subgraph Evaluate[Evaluate Context]
|
|
12
|
+
direction TB
|
|
13
|
+
E1[Analyze target context and goal]
|
|
14
|
+
E1 --> E2[Infer diagram type and template]
|
|
15
|
+
E2 --> E3[Identify key nodes and relationships]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
Evaluate --> Blueprint[Create .spec.md from .agents/templates/spec-template.md]
|
|
19
|
+
Blueprint --> Format[Format into target .spec.md structure]
|
|
20
|
+
Format --> CheckDiagram
|
|
21
|
+
|
|
22
|
+
subgraph CheckDiagram[Validate Syntax]
|
|
23
|
+
direction TB
|
|
24
|
+
C1{Diagram valid?}
|
|
25
|
+
C1 -->|Yes| C2[Proceed]
|
|
26
|
+
C1 -->|No| Blueprint
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
CheckDiagram --> Write[Write validated .spec.md to path]
|
|
30
|
+
Write --> Init[Set SPEC_VERSION to v1.0.0-draft]
|
|
31
|
+
Init --> Audit[Append audit entry: 'Created via md-new' with timestamp]
|
|
32
|
+
Audit --> Review([Pause for user review])
|
|
44
33
|
```
|
|
@@ -3,20 +3,11 @@
|
|
|
3
3
|
# {{Feature Title}} — Specification
|
|
4
4
|
|
|
5
5
|
> ⚠️ **This is a freshly generated MDDD spec template.**
|
|
6
|
-
> Replace every `{{placeholder}}`, remove this banner, and refine the diagram + matrix
|
|
7
|
-
> with the real business context before marking the spec as `stable`.
|
|
6
|
+
> Replace every `{{placeholder}}`, remove this banner, and refine the diagram + matrix with the real business context. Only mark the spec as `stable` if it's coese and reflecting the real code.
|
|
8
7
|
|
|
9
8
|
---
|
|
10
9
|
|
|
11
|
-
## 1.
|
|
12
|
-
|
|
13
|
-
Describe **what** this spec governs and **why** it exists.
|
|
14
|
-
|
|
15
|
-
- **Related specs:** {{parent_domain_spec, sibling_features}}
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## 2. Behavioral Flow (Mermaid)
|
|
10
|
+
## 1. Behavioral Flow (Mermaid)
|
|
20
11
|
|
|
21
12
|
> Pick the diagram type that best fits the topology using mermaid-diagrams skill.
|
|
22
13
|
|
|
@@ -40,44 +31,35 @@ Every node MUST correspond to a concrete state, action, or decision found in the
|
|
|
40
31
|
|
|
41
32
|
---
|
|
42
33
|
|
|
43
|
-
##
|
|
34
|
+
## 2. Decision Matrix
|
|
44
35
|
|
|
45
36
|
The matrix below is the **deterministic truth table** that resolves the flow above.
|
|
46
|
-
Each row maps a combination of **Primitive Factors** → a `
|
|
37
|
+
Each row maps a combination of **Primitive Factors** → a `Action` → `States/Validations(✅|❌)` → `Result`.
|
|
47
38
|
|
|
48
|
-
|
|
39
|
+
**Resolution rules** (per MDDD protocol):
|
|
49
40
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
| `{{Factor 2 (e.g. Active Billing Tier?)}}` | Categorical | `FREE`, `PRO`, `ENTERPRISE` | — |
|
|
54
|
-
| `{{Factor N}}` | Binary / Categorical | … | — |
|
|
41
|
+
1. ALL columns must match a system state.
|
|
42
|
+
2. If no row fully matches → `HaltWithConflict`.
|
|
43
|
+
3. If multiple rows match → `HaltWithConflict`.
|
|
55
44
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
### 3.2 Resolution Table
|
|
45
|
+
---
|
|
59
46
|
|
|
60
|
-
|
|
61
|
-
| :---: | :---: | :---: | :--- | :---: | :--- |
|
|
62
|
-
| ❌ NO | - | - | `{{ACTION_NAME}}` | ❌ DENY | - |
|
|
63
|
-
| ✅ YES | - | - | `{{ACTION_NAME}}` | ✅ ALLOW | `{{NEW_STATE}}` |
|
|
47
|
+
## 3. Tasks
|
|
64
48
|
|
|
65
|
-
|
|
49
|
+
Atomic, executable checklist. Each item MUST be traceable
|
|
50
|
+
back to a node in the Behavioral Flow or a row in the Decision Matrix.
|
|
66
51
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
3. If multiple rows match → `HaltWithConflict` (ambiguous).
|
|
52
|
+
- [ ] {{Task X — derived from flow node / matrix row}}
|
|
53
|
+
- [ ] {{Task X+1 — derived from flow node / matrix row}}
|
|
70
54
|
|
|
71
55
|
---
|
|
72
56
|
|
|
73
|
-
## 4
|
|
57
|
+
## 4 Test plan
|
|
74
58
|
|
|
75
|
-
Atomic, executable checklist
|
|
76
|
-
back to a node in the Behavioral Flow or a row in the Decision Matrix.
|
|
59
|
+
Atomic, executable test checklist to be implemented covering edge-cases.
|
|
77
60
|
|
|
78
|
-
- [ ] {{
|
|
79
|
-
- [ ] {{
|
|
80
|
-
- [ ] {{Task N — derived from flow node / matrix row}}
|
|
61
|
+
- [ ] {{Test X — Use case/Scenario covered}}
|
|
62
|
+
- [ ] {{Test X+1 — Use case/Scenario covered}}
|
|
81
63
|
|
|
82
64
|
---
|
|
83
65
|
|
|
@@ -89,15 +71,15 @@ When a `HaltWithConflict` is triggered, document the resolution path here:
|
|
|
89
71
|
| :--- | :--- | :---: |
|
|
90
72
|
| {{Primitive Factor that caused the halt}} | {{new row / new column / renamed state}} | `OPEN` / `RESOLVED` |
|
|
91
73
|
|
|
92
|
-
|
|
74
|
+
___
|
|
93
75
|
|
|
94
76
|
## 6. Audit History
|
|
95
77
|
|
|
96
78
|
<details>
|
|
97
79
|
<summary>Click to expand</summary>
|
|
98
80
|
|
|
99
|
-
| Date |
|
|
100
|
-
| :--- |
|
|
101
|
-
| {{YYYY-MM-DD}} |
|
|
81
|
+
| Date | Version | Change Short Tech-Summary |
|
|
82
|
+
| :--- | :---: | :--- |
|
|
83
|
+
| {{YYYY-MM-DD}} | v1.0.0 | Short tech explain of what changed. Status: `draft\|stable`. |
|
|
102
84
|
|
|
103
85
|
</details>
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
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. Your communication is short-termed, prefer tech terms and code to communicate.
|
|
4
|
+
|
|
5
|
+
Consume the `@/.agents/skills/mermaid-diagrams` skill to learn how to produce it.
|
|
6
|
+
|
|
7
|
+
Use the spec template: `@/.agents/templates/spec-template.md`.
|
|
8
|
+
|
|
9
|
+
use the Chaotic/Coese evaluation: `@./agents/skills/md-audit/SKILL.md`
|
|
10
|
+
|
|
11
|
+
Mark every .spec as Coese or Chaotic based on auditory.
|
|
12
|
+
|
|
13
|
+
```mermaid
|
|
14
|
+
graph TD
|
|
15
|
+
Start((Start)) --> CheckSpec{Spec exists?}
|
|
16
|
+
|
|
17
|
+
CheckSpec -->|Yes| ExistingSpec
|
|
18
|
+
CheckSpec -->|No| SkillCheck{Check requested skill}
|
|
19
|
+
|
|
20
|
+
SkillCheck -->|md-new| NewSpec[New Specification]
|
|
21
|
+
SkillCheck -->|md-audit| AuditCode[Audit Legacy Code]
|
|
22
|
+
SkillCheck -->|other skill| DENIED[[DENIED]]
|
|
23
|
+
SkillCheck -->|unknown| DENIED
|
|
24
|
+
|
|
25
|
+
subgraph NewSpec[New Specification]
|
|
26
|
+
direction TB
|
|
27
|
+
NS1[Fill spec-template] --> NS2[Read user request]
|
|
28
|
+
NS2 --> NS3[Write specification]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
subgraph AuditCode[Audit Legacy Code]
|
|
32
|
+
direction TB
|
|
33
|
+
A1[Consume md-audit SKILL.md] --> A2[Read legacy code file]
|
|
34
|
+
A2 --> A3[Load related files]
|
|
35
|
+
A3 --> A4[Deep code analysis]
|
|
36
|
+
A4 --> A5{Chaotic or Coese?}
|
|
37
|
+
A5 -->|Coese — high quality| A6[Write spec from template]
|
|
38
|
+
A5 -->|Chaotic — low quality| A7[Draft proposal spec]
|
|
39
|
+
A6 --> A8[Enter SpecMod]
|
|
40
|
+
A7 --> A8
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
subgraph SpecMod[Spec Modification]
|
|
44
|
+
direction TB
|
|
45
|
+
S1[Plan the edit] --> S2[Apply changes to spec]
|
|
46
|
+
S2 --> S3[Extract all mermaid diagrams]
|
|
47
|
+
S3 --> S4[Map topology → decision matrix]
|
|
48
|
+
S4 --> S5[Validate primitive factors]
|
|
49
|
+
S5 --> S6[Code review]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
subgraph ExistingSpec[Existing Spec Flow]
|
|
53
|
+
direction TB
|
|
54
|
+
E1[Read skill content] --> E2{Which skill?}
|
|
55
|
+
E2 -->|md-impl| MdImpl
|
|
56
|
+
E2 -->|md-edit| MdEdit
|
|
57
|
+
|
|
58
|
+
subgraph MdImpl[Implementation]
|
|
59
|
+
direction TB
|
|
60
|
+
I1[Read spec status] --> I2{Draft or Stable?}
|
|
61
|
+
I2 -->|Draft| I3[Implement code]
|
|
62
|
+
I3 --> I4[Implement tests]
|
|
63
|
+
I4 --> I5[Run tests]
|
|
64
|
+
I5 --> I6[Code review]
|
|
65
|
+
I2 -->|Stable| ConflictTrigger{Halt — spec is stable}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
subgraph MdEdit[Edit Spec]
|
|
69
|
+
direction TB
|
|
70
|
+
Ed1[Read spec content] --> Ed2[Read user request]
|
|
71
|
+
Ed2 --> Ed3[Enter SpecMod]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
MdImpl --> ValidateChanges[Validate changes]
|
|
75
|
+
MdEdit --> ValidateChanges
|
|
76
|
+
ValidateChanges --> UpdateSpec[Update spec status draft/stable]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
NewSpec --> SpecMod
|
|
80
|
+
AuditCode --> SpecMod
|
|
81
|
+
ExistingSpec -.-> SpecMod
|
|
82
|
+
ConflictTrigger --> ConflictRes
|
|
83
|
+
|
|
84
|
+
subgraph ConflictRes[Conflict Resolution]
|
|
85
|
+
direction TB
|
|
86
|
+
C1[Explain conflict to user] --> C2[Propose alternatives]
|
|
87
|
+
C2 --> C3{Await human decision}
|
|
88
|
+
C3 -->|Accept proposal| C4[Update decision matrix]
|
|
89
|
+
C3 -->|Cancel| Cancelled([Cancelled])
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
NS3 --> Conclude
|
|
93
|
+
A8 --> Conclude
|
|
94
|
+
UpdateSpec --> Conclude
|
|
95
|
+
C4 --> Conclude
|
|
96
|
+
|
|
97
|
+
subgraph Conclude[Finalize]
|
|
98
|
+
direction TB
|
|
99
|
+
Co1[Validate with npx md validate] --> Co2[Check parent/child consistency]
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
Conclude --> End([End])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## 2. Reverse Consistency
|
|
106
|
+
|
|
107
|
+
### 2.1. **Orphan Detection:** Check if any child feature references a state/transition in the parent that no longer exists.
|
|
108
|
+
### 2.2. **Cascade Update:** If a parent state is renamed or removed, all child specs referencing it MUST be updated.
|
|
109
|
+
### 2.3. **Version Bump:** Parent changes increment MINOR version. Child specs affected by the change increment PATCH version.
|
|
110
|
+
|
|
111
|
+
## 3. Decision Matrix & Primitive Factors
|
|
112
|
+
|
|
113
|
+
### 3.1 Decision Matrix Definition
|
|
114
|
+
|
|
115
|
+
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.
|
|
116
|
+
|
|
117
|
+
### 3.2 Primitive Factors
|
|
118
|
+
|
|
119
|
+
**Primitive Factors** are the atomic boolean or categorical variables used to evaluate a decision. Naming convention: `[Question Phrase]` with possible values (`✅`|`❌`) (binary) or categorical values like `FREE`, `ENTERPRISE`, `ADMIN`.
|
|
120
|
+
|
|
121
|
+
| Factor Type | Example | Allowed Values |
|
|
122
|
+
| --- | --- | --- |
|
|
123
|
+
| Binary | `Active Tenant?` | `✅`, `❌` |
|
|
124
|
+
| Categorical | `Active Billing Tier?` | `FREE`, `PRO`, `ENTERPRISE` |
|
|
125
|
+
| Negated Binary | `Global Kill Switch Active?` | `✅`, `❌` |
|
|
126
|
+
|
|
127
|
+
### 3.3 Matrix Resolution Rule
|
|
128
|
+
|
|
129
|
+
For each row:
|
|
130
|
+
1. Match ALL Primitive Factors against the current system state.
|
|
131
|
+
2. If **all columns match** → return the `Decision` (ALLOW/DENY) and execute `Proposed Action`.
|
|
132
|
+
3. If **no row fully matches** → return `HaltWithConflict`.
|
|
133
|
+
4. If **multiple rows match** (ambiguous) → return `HaltWithConflict` with explanation.
|
|
134
|
+
|
|
135
|
+
### 3.4 Example Decision Matrix
|
|
136
|
+
|
|
137
|
+
| Active Tenant? | Premium App? | Active Billing Tier? | User Has Role Admin? | App Whitelisted? | Global Kill Switch? | Proposed Action | Decision | Transition State |
|
|
138
|
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
|
139
|
+
| ❌ | - | - | - | - | - | `BOOT_APP` | ❌ | - |
|
|
140
|
+
| ✅ | ✅ | **ENTERPRISE** | ✅ | ✅ | ❌ | `INSTALL_APP` | ✅ | `INSTALLED` |
|
|
141
|
+
| ✅ | - | - | - | - | ✅ | `BOOT_APP` | ❌ | `MUTED_ISOLATION` |
|
|
142
|
+
|
|
143
|
+
> `-` = wildcard / any value matches.
|
|
144
|
+
|
|
145
|
+
## 4. Versioning Policy
|
|
146
|
+
|
|
147
|
+
### 4.1 Semantic Version for Specs
|
|
148
|
+
|
|
149
|
+
Every `.spec.md` file carries a `%% @spec-version` header. Use **Semantic Versioning (MAJOR.MINOR.PATCH)**:
|
|
150
|
+
|
|
151
|
+
| Bump | When | Example |
|
|
152
|
+
| --- | --- | --- |
|
|
153
|
+
| **MAJOR** | Breaking change: removing states/transitions, renaming factors, changing decision outcomes. | `1.2.3` → `2.0.0` |
|
|
154
|
+
| **MINOR** | Adding: new states/transitions, new factor columns, new features without breaking existing rows. | `1.2.3` → `1.3.0` |
|
|
155
|
+
| **PATCH** | Fixing: typos, clarifying descriptions, reformatting, updating child references. | `1.2.3` → `1.2.4` |
|
|
156
|
+
|
|
157
|
+
### 4.2 Audit History (Change Log)
|
|
158
|
+
|
|
159
|
+
Each change MUST append a row to the **Change History** table at the bottom of the `.spec.md` file:
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
## Change History
|
|
163
|
+
| Version | Date | Change Description |
|
|
164
|
+
| --- | --- | --- |
|
|
165
|
+
| 1.1.0 | 2025-06-01 | Added refund retry logic state
|
|
166
|
+
| 1.0.0 | 2025-05-15 | Initial spec creation
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## 5. Conflict Resolution Protocol
|
|
170
|
+
|
|
171
|
+
When `HaltWithConflict` is triggered, the system MUST:
|
|
172
|
+
|
|
173
|
+
1. **Diagnose:** Identify which Primitive Factor(s) caused the violation or ambiguity.
|
|
174
|
+
2. **Document:** Log the conflict details in the Audit History (see section 4.3).
|
|
175
|
+
3. **Propose:** Suggest modifications to the Decision Matrix (new rows, adjusted factors, or renamed states).
|
|
176
|
+
4. **Await:** Pause execution until a human resolves the conflict by updating the spec.
|
|
177
|
+
5. **Resume:** After the spec is updated, re-enter `CheckDecisionMatrix`.
|
|
178
|
+
|
|
179
|
+
## 6. Parent Interaction Logic (Reverse Consistency)
|
|
180
|
+
|
|
181
|
+
```mermaid
|
|
182
|
+
graph TD
|
|
183
|
+
A[Parent .spec.md Modified] --> B[Scan All Child Features]
|
|
184
|
+
B --> C{Child References\nDeleted State?}
|
|
185
|
+
C -->|Yes| D[Flag Orphan Reference]
|
|
186
|
+
C -->|No| E{Child Transitions\nStill Valid?}
|
|
187
|
+
E -->|No| D
|
|
188
|
+
E -->|Yes| F[Update Child @spec-version: PATCH bump]
|
|
189
|
+
D --> G[Human Review Required]
|
|
190
|
+
G --> H[Update Child Spec]
|
|
191
|
+
H --> F
|
|
192
|
+
F --> I[Done — Log in Audit History]
|