@longph2102/v-flow 1.5.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.
Files changed (247) hide show
  1. package/AGENTS.md +265 -0
  2. package/CHANGELOG.md +318 -0
  3. package/LICENSE +21 -0
  4. package/README.md +326 -0
  5. package/agents/ba-agent.md +437 -0
  6. package/agents/ba-critic-agent.md +156 -0
  7. package/agents/ba-to-ptyc-agent.md +112 -0
  8. package/agents/bugfix-analyst-agent.md +221 -0
  9. package/agents/constitute-agent.md +155 -0
  10. package/agents/help-agent.md +168 -0
  11. package/agents/implement-agent.md +220 -0
  12. package/agents/import-ba-docs-agent.md +164 -0
  13. package/agents/master-check-agent.md +228 -0
  14. package/agents/metrics-agent.md +180 -0
  15. package/agents/operations-agent.md +123 -0
  16. package/agents/plan-agent.md +218 -0
  17. package/agents/prototype-agent.md +191 -0
  18. package/agents/retrospective-agent.md +196 -0
  19. package/agents/review-agent.md +210 -0
  20. package/agents/sprint-agent.md +191 -0
  21. package/agents/status-agent.md +186 -0
  22. package/agents/sync-agent.md +201 -0
  23. package/agents/test-agent.md +166 -0
  24. package/agents/understand-agent.md +339 -0
  25. package/cli/commands/check.js +96 -0
  26. package/cli/commands/dev-quiz.js +107 -0
  27. package/cli/commands/doctor.js +348 -0
  28. package/cli/commands/feature.js +259 -0
  29. package/cli/commands/hooks.js +163 -0
  30. package/cli/commands/init.js +189 -0
  31. package/cli/commands/log.js +199 -0
  32. package/cli/commands/plugin.js +230 -0
  33. package/cli/commands/score-card.js +203 -0
  34. package/cli/commands/status.js +269 -0
  35. package/cli/commands/sync.js +59 -0
  36. package/cli/commands/upgrade.js +150 -0
  37. package/cli/commands/validate.js +1259 -0
  38. package/cli/commands/watch.js +151 -0
  39. package/cli/index.js +46 -0
  40. package/cli/lib/ac-test-gate.js +89 -0
  41. package/cli/lib/activity-log.js +209 -0
  42. package/cli/lib/cli-error.js +183 -0
  43. package/cli/lib/constitution-lint.js +561 -0
  44. package/cli/lib/dev-quiz-grade.js +127 -0
  45. package/cli/lib/governance.js +78 -0
  46. package/cli/lib/hook-targets.js +167 -0
  47. package/cli/lib/i18n.js +375 -0
  48. package/cli/lib/knowledge-oracle.js +379 -0
  49. package/cli/lib/logger.js +203 -0
  50. package/cli/lib/module-card-lint.js +304 -0
  51. package/cli/lib/module-card-score.js +223 -0
  52. package/cli/lib/plugins.js +481 -0
  53. package/cli/lib/scanner.js +692 -0
  54. package/cli/lib/sync-core.js +232 -0
  55. package/cli/lib/sync-targets.js +84 -0
  56. package/cli/lib/templates.js +268 -0
  57. package/cli/lib/yaml-parser.js +203 -0
  58. package/commands/v.ba-critic.md +101 -0
  59. package/commands/v.ba-to-ptyc.md +71 -0
  60. package/commands/v.bugfix.md +86 -0
  61. package/commands/v.check.md +131 -0
  62. package/commands/v.constitute.md +87 -0
  63. package/commands/v.constitution.md +84 -0
  64. package/commands/v.fork.md +127 -0
  65. package/commands/v.help.md +73 -0
  66. package/commands/v.hotfix.md +200 -0
  67. package/commands/v.implement.md +92 -0
  68. package/commands/v.import-ba-docs.md +222 -0
  69. package/commands/v.metrics.md +74 -0
  70. package/commands/v.operations.md +70 -0
  71. package/commands/v.plan.md +78 -0
  72. package/commands/v.prototype.md +121 -0
  73. package/commands/v.quickfix.md +169 -0
  74. package/commands/v.retrospective.md +80 -0
  75. package/commands/v.review.md +78 -0
  76. package/commands/v.rewind.md +127 -0
  77. package/commands/v.specify.md +118 -0
  78. package/commands/v.sprint.md +75 -0
  79. package/commands/v.status.md +62 -0
  80. package/commands/v.sync.md +81 -0
  81. package/commands/v.test.md +67 -0
  82. package/commands/v.understand.md +112 -0
  83. package/package.json +65 -0
  84. package/skills/_shared/constitution-reader/SKILL.md +109 -0
  85. package/skills/_shared/constitution-reader/config.json +52 -0
  86. package/skills/_shared/constitution-reader/examples/good/b1-phase-output.md +48 -0
  87. package/skills/_shared/constitution-reader/gotchas.md +46 -0
  88. package/skills/_shared/context-reader/SKILL.md +111 -0
  89. package/skills/_shared/context-reader/config.json +54 -0
  90. package/skills/_shared/context-reader/examples/good/legacy-nodejs-output.md +35 -0
  91. package/skills/_shared/context-reader/gotchas.md +49 -0
  92. package/skills/_shared/ears-notation/SKILL.md +63 -0
  93. package/skills/_shared/ears-notation/config.json +55 -0
  94. package/skills/_shared/ears-notation/examples/good/plan-test-interpretation.md +29 -0
  95. package/skills/_shared/ears-notation/gotchas.md +43 -0
  96. package/skills/check/cross-validator/SKILL.md +206 -0
  97. package/skills/check/cross-validator/config.json +33 -0
  98. package/skills/check/cross-validator/examples/good/validation-report-pass-with-concerns.md +105 -0
  99. package/skills/check/cross-validator/gotchas.md +43 -0
  100. package/skills/implement/constitution-enforcer/SKILL.md +134 -0
  101. package/skills/implement/constitution-enforcer/config.json +16 -0
  102. package/skills/implement/constitution-enforcer/examples/bad/vague-report.md +42 -0
  103. package/skills/implement/constitution-enforcer/examples/good/compliance-report.md +57 -0
  104. package/skills/implement/constitution-enforcer/gotchas.md +26 -0
  105. package/skills/implement/constitution-enforcer/scripts/check-constitution.sh +88 -0
  106. package/skills/implement/no-go-zone-guard/SKILL.md +173 -0
  107. package/skills/implement/no-go-zone-guard/config.json +28 -0
  108. package/skills/implement/no-go-zone-guard/examples/good/adapter-workaround.md +46 -0
  109. package/skills/implement/no-go-zone-guard/gotchas.md +27 -0
  110. package/skills/implement/no-go-zone-guard/scripts/check-nogo-zones.sh +148 -0
  111. package/skills/implement/no-go-zone-guard/scripts/nogo-precommit.sh +96 -0
  112. package/skills/implement/tdd-driver/SKILL.md +159 -0
  113. package/skills/implement/tdd-driver/config.json +33 -0
  114. package/skills/implement/tdd-driver/examples/good/tdd-cycle-product-repo.md +81 -0
  115. package/skills/implement/tdd-driver/gotchas.md +34 -0
  116. package/skills/metrics/metrics-collector/SKILL.md +133 -0
  117. package/skills/metrics/metrics-collector/config.json +16 -0
  118. package/skills/metrics/metrics-collector/examples/bad/incomplete-report.md +48 -0
  119. package/skills/metrics/metrics-collector/examples/good/full-metrics-report.md +101 -0
  120. package/skills/metrics/metrics-collector/gotchas.md +26 -0
  121. package/skills/operations/incident-runbook/SKILL.md +167 -0
  122. package/skills/operations/incident-runbook/config.json +21 -0
  123. package/skills/operations/incident-runbook/examples/bad/vague-incident-report.md +48 -0
  124. package/skills/operations/incident-runbook/examples/good/p1-hotfix-response.md +119 -0
  125. package/skills/operations/incident-runbook/gotchas.md +26 -0
  126. package/skills/plan/architecture-designer/SKILL.md +228 -0
  127. package/skills/plan/architecture-designer/config.json +32 -0
  128. package/skills/plan/architecture-designer/examples/bad/vague-plan.md +62 -0
  129. package/skills/plan/architecture-designer/examples/good/expand-contract-migration.md +56 -0
  130. package/skills/plan/architecture-designer/examples/good/plan-structure.md +58 -0
  131. package/skills/plan/architecture-designer/gotchas.md +45 -0
  132. package/skills/plan/task-breakdown/SKILL.md +208 -0
  133. package/skills/plan/task-breakdown/config.json +26 -0
  134. package/skills/plan/task-breakdown/examples/bad/vague-tasks.md +77 -0
  135. package/skills/plan/task-breakdown/examples/good/spike-clarify-tasks.md +66 -0
  136. package/skills/plan/task-breakdown/examples/good/tasks-login-feature.md +111 -0
  137. package/skills/plan/task-breakdown/gotchas.md +39 -0
  138. package/skills/prototype/LOGIC.md +240 -0
  139. package/skills/prototype/SKILL.md +185 -0
  140. package/skills/prototype/UI.md +407 -0
  141. package/skills/prototype/config.json +104 -0
  142. package/skills/prototype/examples/bad/prototype-notes.md +68 -0
  143. package/skills/prototype/examples/good/prototype-notes-ui.md +109 -0
  144. package/skills/prototype/examples/good/prototype-notes.md +67 -0
  145. package/skills/prototype/gotchas.md +128 -0
  146. package/skills/prototype/scripts/check-flow-state.ps1 +112 -0
  147. package/skills/prototype/scripts/check-flow-state.sh +104 -0
  148. package/skills/prototype/scripts/check-prototype-cleanup.ps1 +124 -0
  149. package/skills/prototype/scripts/check-prototype-cleanup.sh +109 -0
  150. package/skills/prototype/scripts/check-prototype-notes.ps1 +107 -0
  151. package/skills/prototype/scripts/check-prototype-notes.sh +102 -0
  152. package/skills/review/adversarial-reviewer/SKILL.md +137 -0
  153. package/skills/review/adversarial-reviewer/config.json +32 -0
  154. package/skills/review/adversarial-reviewer/examples/good/review-report-template.md +56 -0
  155. package/skills/review/adversarial-reviewer/gotchas.md +46 -0
  156. package/skills/review/adversarial-reviewer/scripts/quick-security-scan.sh +52 -0
  157. package/skills/specify/ba-bpmn-doc-gen/SKILL.md +108 -0
  158. package/skills/specify/ba-bpmn-doc-gen/reference/reference-bpmn-generation.md +528 -0
  159. package/skills/specify/ba-bpmn-doc-gen/reference/reference-drawio-flowchart.md +466 -0
  160. package/skills/specify/ba-critic/SKILL.md +172 -0
  161. package/skills/specify/ba-critic/config.json +32 -0
  162. package/skills/specify/ba-critic/examples/good/critic-report-round1.md +51 -0
  163. package/skills/specify/ba-critic/gotchas.md +40 -0
  164. package/skills/specify/ba-critic/scripts/check-spec-quality.sh +72 -0
  165. package/skills/specify/ba-doc-generator/SKILL.md +102 -0
  166. package/skills/specify/ba-doc-generator/references/template-clevel.md +84 -0
  167. package/skills/specify/ba-doc-generator/references/template-compliance.md +83 -0
  168. package/skills/specify/ba-doc-generator/references/template-dev.md +138 -0
  169. package/skills/specify/ba-doc-generator/references/template-partner.md +167 -0
  170. package/skills/specify/ba-doc-generator/references/template-pm.md +92 -0
  171. package/skills/specify/ba-doc-generator/references/template-review.md +114 -0
  172. package/skills/specify/ba-doc-generator/references/template-tester.md +108 -0
  173. package/skills/specify/ba-doc-generator/references/template-user.md +98 -0
  174. package/skills/specify/bugfix-analyst/SKILL.md +296 -0
  175. package/skills/specify/bugfix-analyst/config.json +41 -0
  176. package/skills/specify/bugfix-analyst/examples/bad/common-mistakes.md +71 -0
  177. package/skills/specify/bugfix-analyst/examples/good/email-validation-bugfix.md +53 -0
  178. package/skills/specify/bugfix-analyst/gotchas.md +51 -0
  179. package/skills/specify/ears-writer/SKILL.md +129 -0
  180. package/skills/specify/ears-writer/config.json +20 -0
  181. package/skills/specify/ears-writer/examples/bad/common-mistakes.md +17 -0
  182. package/skills/specify/ears-writer/examples/good/login-requirements.md +41 -0
  183. package/skills/specify/ears-writer/gotchas.md +43 -0
  184. package/skills/specify/ears-writer/scripts/check-ears-compliance.sh +51 -0
  185. package/skills/test/test-case-generator/SKILL.md +161 -0
  186. package/skills/test/test-case-generator/config.json +33 -0
  187. package/skills/test/test-case-generator/examples/good/test-cases-login.md +104 -0
  188. package/skills/test/test-case-generator/gotchas.md +43 -0
  189. package/skills/understand/ba-docs-scanner/SKILL.md +239 -0
  190. package/skills/understand/ba-docs-scanner/config.json +47 -0
  191. package/skills/understand/ba-docs-scanner/examples/good/work-order-br-extract.md +28 -0
  192. package/skills/understand/ba-docs-scanner/gotchas.md +44 -0
  193. package/skills/understand/ba-docs-scanner/merge-rules.md +47 -0
  194. package/skills/understand/codebase-scanner/SKILL.md +260 -0
  195. package/skills/understand/codebase-scanner/config.json +56 -0
  196. package/skills/understand/codebase-scanner/examples/good/menu-module-output.md +44 -0
  197. package/skills/understand/codebase-scanner/gotchas.md +42 -0
  198. package/skills/understand/codebase-scanner/scripts/scan-project-structure.sh +64 -0
  199. package/templates/DESIGN.md +456 -0
  200. package/templates/agent-command-template.yaml +240 -0
  201. package/templates/agent-config-template.md +170 -0
  202. package/templates/agent-definition-template.md +145 -0
  203. package/templates/agent-metrics-template.md +150 -0
  204. package/templates/api-contract-template.md +72 -0
  205. package/templates/bugfix-report-template.md +195 -0
  206. package/templates/bugfix-spec-template.md +134 -0
  207. package/templates/code-review-report-template.md +119 -0
  208. package/templates/constitution-template.md +234 -0
  209. package/templates/context-template.md +94 -0
  210. package/templates/data-model-template.md +95 -0
  211. package/templates/decision-log-template.md +92 -0
  212. package/templates/flow-state-template.yaml +208 -0
  213. package/templates/github/workflows/v-flow-validate.yml +30 -0
  214. package/templates/knowledge/adr-template.md +70 -0
  215. package/templates/knowledge/api-contract-template.md +140 -0
  216. package/templates/knowledge/domain-glossary.md +29 -0
  217. package/templates/knowledge/golden-tests-readme.md +115 -0
  218. package/templates/knowledge/lessons-learned.md +41 -0
  219. package/templates/knowledge/patterns.md +103 -0
  220. package/templates/module-card/SKILL.md +85 -0
  221. package/templates/module-card/api-specs.md +96 -0
  222. package/templates/module-card/business-quiz.md +119 -0
  223. package/templates/module-card/cross-service.md +125 -0
  224. package/templates/module-card/db.md +85 -0
  225. package/templates/module-card/dev-quiz.md +62 -0
  226. package/templates/module-card/permissions.md +83 -0
  227. package/templates/module-card/state-diagram.md +64 -0
  228. package/templates/module-card/tech-context.md +90 -0
  229. package/templates/module-card/ui-flows.md +91 -0
  230. package/templates/module-card/use-cases.md +142 -0
  231. package/templates/module-template.yaml +161 -0
  232. package/templates/operations-report-template.md +108 -0
  233. package/templates/plan-template.md +308 -0
  234. package/templates/prototype-notes-template.md +116 -0
  235. package/templates/ptyc/PTYC.template.docx +0 -0
  236. package/templates/ptyc/ptyc.meta.example.yaml +44 -0
  237. package/templates/retrospective-report-template.md +136 -0
  238. package/templates/security-review-template.md +84 -0
  239. package/templates/session-template.md +167 -0
  240. package/templates/spec-review-log-template.md +75 -0
  241. package/templates/spec-template.md +229 -0
  242. package/templates/sprint-status-template.md +101 -0
  243. package/templates/tasks-template.md +275 -0
  244. package/templates/test-cases-template.md +124 -0
  245. package/templates/ux-checklist-template.md +79 -0
  246. package/templates/validation-report-template.md +125 -0
  247. package/templates/vflow-config-template.yaml +22 -0
@@ -0,0 +1,33 @@
1
+ {
2
+ "setup_questions": [
3
+ {
4
+ "id": "strictness",
5
+ "question": "Mức độ strict của validation?",
6
+ "options": ["strict", "standard", "lenient"],
7
+ "default": "standard",
8
+ "description": "strict = mọi warning → concern. standard = balanced. lenient = chỉ critical gaps → fail."
9
+ },
10
+ {
11
+ "id": "concern_threshold",
12
+ "question": "Max concerns trước khi đổi verdict sang FAIL?",
13
+ "type": "number",
14
+ "default": 5,
15
+ "description": "Nếu > N concerns → FAIL thay vì PASS WITH CONCERNS."
16
+ },
17
+ {
18
+ "id": "require_security_section",
19
+ "question": "Bắt buộc plan có security section?",
20
+ "type": "boolean",
21
+ "default": true
22
+ }
23
+ ],
24
+ "hooks": {
25
+ "pre_check": "Build traceability matrix từ spec + plan + tasks + test-cases",
26
+ "post_check": "Write validation-report.md + update .flow-state.yaml + append _session.md"
27
+ },
28
+ "memory": {
29
+ "file": "check-history.log",
30
+ "format": "[date] | [feature] | [verdict] | [critical] | [major] | [concerns] | [coverage_pct]",
31
+ "purpose": "Track validation quality — dùng cho /v.metrics"
32
+ }
33
+ }
@@ -0,0 +1,105 @@
1
+ # Ví dụ — Validation Report (PASS WITH CONCERNS)
2
+
3
+ > Đây là mẫu output chuẩn cho Master Check Agent.
4
+
5
+ ---
6
+
7
+ # Validation Report — Feature 001: User Login
8
+
9
+ **Ngày:** 2026-04-15
10
+ **Verdict:** ⚠️ PASS WITH CONCERNS
11
+
12
+ ---
13
+
14
+ ## 1. Traceability Matrix
15
+
16
+ | REQ | Task(s) | TC(s) | Status |
17
+ |-----|---------|-------|--------|
18
+ | REQ-E01 | T-001, T-002, T-004, T-005 | TC-E01-01, TC-E01-02 | ✅ Full |
19
+ | REQ-E02 | T-004 | TC-E02-01 | ✅ Full |
20
+ | REQ-U01 | T-001 | TC-U01-01, TC-U01-02 | ✅ Full |
21
+ | REQ-O01 | T-004 | TC-O01-01, TC-O01-02, TC-O01-03 | ✅ Full |
22
+
23
+ **Coverage**: 4/4 REQs (100%) ✅
24
+
25
+ ---
26
+
27
+ ## 2. Consistency Checks
28
+
29
+ | Check | Result | Detail |
30
+ |-------|--------|--------|
31
+ | Architecture vs Constitution | ✅ PASS | Clean Architecture, BLoC pattern — match constitution §3.2 |
32
+ | File paths | ✅ PASS | All paths follow `lib/features/{domain}/` convention |
33
+ | No-Go Zone | ✅ PASS | `token_storage.dart` not in No-Go Zone |
34
+ | Dependency direction | ✅ PASS | presentation → domain → data |
35
+ | Error architecture | ⚠️ CONCERN | Error types defined, but missing retry strategy |
36
+ | Security section | ✅ PASS | Auth flow, token storage documented |
37
+
38
+ ---
39
+
40
+ ## 3. Quality Assessment
41
+
42
+ | Check | Result | Detail |
43
+ |-------|--------|--------|
44
+ | ENTRYPOINT | ✅ | T-001 correctly marked |
45
+ | Circular DEPENDS | ✅ | No circular dependencies |
46
+ | Task granularity | ✅ | All tasks ≤ 3h estimated |
47
+ | TC coverage | ✅ | 100% REQ coverage |
48
+ | TC edge cases | ⚠️ CONCERN | REQ-E02 only has happy-path error, missing empty email TC |
49
+ | TC types | ✅ | Unit + E2E for critical paths |
50
+
51
+ ---
52
+
53
+ ## 4. Concerns
54
+
55
+ ### W-001: Missing retry strategy in error architecture
56
+ - **Type**: Quality
57
+ - **Severity**: Medium
58
+ - **Description**: Plan defines error types but doesn't specify retry behavior for network errors. LoginUseCase should handle transient failures.
59
+ - **Assigned to**: B.1 (Implement Agent — T-004)
60
+ - **Must verify at**: R.1
61
+
62
+ ### W-002: REQ-E02 missing edge case TC for empty email
63
+ - **Type**: Coverage
64
+ - **Severity**: Low
65
+ - **Description**: TC-E02-01 tests wrong password, but no TC for empty email or malformed email format.
66
+ - **Assigned to**: B.1 (Implement Agent — add test in T-005)
67
+ - **Must verify at**: R.1
68
+
69
+ ---
70
+
71
+ ## 5. Issues Found
72
+
73
+ ### Critical
74
+ _(none)_
75
+
76
+ ### Major
77
+ _(none)_
78
+
79
+ ### Minor
80
+ - Rate limit TC-O01-01 doesn't specify timer reset behavior after 15 minutes
81
+
82
+ ---
83
+
84
+ ## 6. Verdict Rationale
85
+
86
+ Traceability 100% (4/4 REQs covered). Constitution alignment verified. No No-Go Zone violations. 2 concerns raised (error retry + edge case TC) — both addressable during B.1 without redesign.
87
+
88
+ **→ PASS WITH CONCERNS**: Implement Agent MAY proceed, MUST address W-001 and W-002.
89
+
90
+ ---
91
+
92
+ ## 7. Routing Decision
93
+
94
+ ```yaml
95
+ verdict: "PASS_WITH_CONCERNS"
96
+ concerns_count: 2
97
+ route_decision: "/v.implement"
98
+ concerns_carry_forward:
99
+ - id: "W-001"
100
+ assigned_phase: "B.1"
101
+ assigned_task: "T-004"
102
+ - id: "W-002"
103
+ assigned_phase: "B.1"
104
+ assigned_task: "T-005"
105
+ ```
@@ -0,0 +1,43 @@
1
+ # Gotchas — Cross Validator
2
+
3
+ > Cập nhật liên tục khi Agent gặp edge case mới.
4
+ > Mỗi lỗi lặp lại 2 lần → BẮT BUỘC thêm vào đây.
5
+
6
+ ---
7
+
8
+ ## Anti-Patterns
9
+
10
+ 1. ❌ **Rubber stamp PASS** — Tất cả trông OK → PASS mà không check kỹ.
11
+ - **Hậu quả**: Gaps leak ra implement → costly rework.
12
+ - **Fix**: PHẢI build traceability matrix. Không có matrix = không có verdict.
13
+
14
+ 2. ❌ **FAIL vì perfectionism** — Fail mọi thứ vì "có thể tốt hơn".
15
+ - **Fix**: FAIL chỉ khi có EVIDENCE cụ thể: missing REQ coverage, constitution violation, No-Go Zone.
16
+
17
+ 3. ❌ **Quên No-Go Zone check** — Validate spec↔plan nhưng không check context.md.
18
+ - **Hậu quả**: Plan includes No-Go Zone modification → Implement Agent blocked.
19
+ - **Fix**: ALWAYS check plan file paths vs context.md No-Go Zones.
20
+
21
+ 4. ❌ **Concerns quá vague** — "W-001: Cần cải thiện quality."
22
+ - **Fix**: Concern PHẢI specific: "W-001: REQ-E02 chỉ có 1 TC (chỉ happy path), thiếu error TC."
23
+
24
+ 5. ❌ **Quên routing decision** — Report không nói FAIL vì gì và route đi đâu.
25
+ - **Fix**: Mỗi FAIL PHẢI có `fail_reason` + `route_decision`. Mỗi CONCERN PHẢI có `assigned_to`.
26
+
27
+ 6. ❌ **Đếm TC nhưng không check content** — "REQ-E01 có 3 TC" nhưng 3 TC test cùng behavior.
28
+ - **Fix**: Check TC CONTENT, không chỉ count. Duplicate TCs = coverage ảo.
29
+
30
+ 7. ❌ **Miss plan↔constitution alignment** — Verify REQ coverage nhưng quên pattern check.
31
+ - **Fix**: Phase 2 Consistency Check PHẢI bao gồm constitution pattern alignment.
32
+
33
+ 8. ❌ **Suy đoán thay vì flag** — Spec mơ hồ → tự interpret rồi PASS.
34
+ - **Fix**: Mơ hồ = flag. Không tự điền thông tin thiếu. Concern hoặc FAIL → BA Agent fix.
35
+
36
+ ---
37
+
38
+ ## Edge Cases
39
+
40
+ - ✅ Spec rất nhỏ (2-3 REQ) → Matrix vẫn bắt buộc. Đơn giản hơn nhưng phải có.
41
+ - ✅ No constitution.md → FLAG [⚠️ No constitution] → PASS WITH CONCERNS mặc định.
42
+ - ✅ No context.md (greenfield) → Skip No-Go Zone check, note trong report.
43
+ - ✅ > 5 concerns → Nâng lên FAIL, quá nhiều concerns = plan chưa ready.
@@ -0,0 +1,134 @@
1
+ ---
2
+ name: constitution-enforcer
3
+ version: "1.0"
4
+ agent: implement
5
+ phase: B.1
6
+ triggers:
7
+ - implement_agent_pre_commit
8
+ - review_agent_check
9
+ dependencies:
10
+ - _shared/constitution-reader
11
+ - _shared/context-reader
12
+ input:
13
+ - constitution.md
14
+ - source code files
15
+ - context.md (for no-go zones)
16
+ output:
17
+ - compliance_report (pass/fail with violations list)
18
+ complexity: medium
19
+ ---
20
+
21
+ # Constitution Enforcer Skill
22
+
23
+ > **Purpose**: Tự động kiểm tra code đang implement có tuân thủ các quy tắc trong `constitution.md` không.
24
+ > **Khi nào dùng**: Trước mỗi commit trong B.1 (Implement) và tại R.1 (Review).
25
+
26
+ ## Quick Reference
27
+
28
+ ```
29
+ Input: constitution.md + source code files + context.md
30
+ Output: Compliance report (PASS / FAIL with violations)
31
+ Agent: Implement Agent, Review Agent
32
+ Phase: B.1 → R.1
33
+ ```
34
+
35
+ ## Enforcement: tool-enforced vs LLM-judged
36
+
37
+ > ⚠️ Đừng tự lừa bằng "đọc bằng mắt". Tách rõ phần **chạy được bằng lệnh** và phần **cần LLM/human suy xét**.
38
+
39
+ | Tầng | Cách enforce | Gồm |
40
+ |------|-------------|-----|
41
+ | **Cơ học (deterministic)** | `bash .v-flow/skills/implement/constitution-enforcer/scripts/check-constitution.sh` + linter dự án | hardcoded secret, lint/format, (mở rộng được: forbidden import) |
42
+ | **Semantic (LLM/human)** | đọc `constitution.md` + đối chiếu code | architecture/layer separation, naming convention nghiệp vụ, API/UI convention |
43
+
44
+ - Implement Agent ở **B.1** chạy script ở Bước 4 (pre-commit). Lint command lấy từ `.v-flow/config.yaml → lint_command` hoặc autodetect.
45
+ - Phần semantic vẫn phải review — script **không** thay thế.
46
+ - Muốn enforce cứng → wire script vào git pre-commit / CI (xem `## Wiring enforcement thật` cuối file).
47
+
48
+ ## What This Skill Does
49
+
50
+ 1. **Parse Constitution Rules** — Đọc `constitution.md`, trích xuất các quy tắc enforceable
51
+ 2. **Classify Rules** — Phân loại thành: Naming, Architecture, Testing, Security, API, UI/UX
52
+ 3. **Scan Code** — Phần cơ học chạy `.v-flow/skills/implement/constitution-enforcer/scripts/check-constitution.sh`; phần semantic LLM đối chiếu
53
+ 4. **Report** — Tạo compliance report với violations và suggestions
54
+
55
+ ## Rule Categories
56
+
57
+ | Category | Examples | Auto-checkable |
58
+ |----------|---------|----------------|
59
+ | **Naming** | Variable naming, file naming conventions | ✅ Yes |
60
+ | **Architecture** | Layer separation, forbidden imports | ✅ Yes |
61
+ | **Testing** | Min coverage, test file naming | ✅ Yes |
62
+ | **Security** | No hardcoded secrets, input validation | ⚠️ Partial |
63
+ | **API** | Response format, error handling | ⚠️ Partial |
64
+ | **UI/UX** | Design system usage | ❌ Manual |
65
+
66
+ ## How to Use
67
+
68
+ ### Step 1: Extract Rules from Constitution
69
+
70
+ ```markdown
71
+ Đọc constitution.md, trích xuất các quy tắc có thể enforce tự động.
72
+ Mỗi rule cần có:
73
+ - Rule ID (ví dụ: CONST-ARCH-001)
74
+ - Category (Naming/Architecture/Testing/Security/API)
75
+ - Description
76
+ - Check method (regex pattern, import check, file structure check)
77
+ - Severity (error/warning)
78
+ ```
79
+
80
+ ### Step 2: Check Code Against Rules
81
+
82
+ ```markdown
83
+ Cho mỗi file trong changeset:
84
+ 1. Check naming conventions (file names, function names, variable names)
85
+ 2. Check import patterns (forbidden dependencies, layer violations)
86
+ 3. Check test existence (nếu constitution yêu cầu)
87
+ 4. Check security patterns (hardcoded values, unsafe operations)
88
+ 5. Check API conventions (response format, error handling)
89
+ ```
90
+
91
+ ### Step 3: Generate Report
92
+
93
+ ```markdown
94
+ ## Constitution Compliance Report
95
+
96
+ ### Summary
97
+ - Rules checked: X
98
+ - Violations: Y (Z errors, W warnings)
99
+ - Compliance score: XX%
100
+
101
+ ### Violations
102
+ | # | Rule | File | Line | Description | Severity |
103
+ |---|------|------|------|-------------|----------|
104
+ | 1 | CONST-ARCH-001 | src/api/handler.js | 15 | Direct DB access from handler (should use repository) | Error |
105
+
106
+ ### Passed Rules
107
+ | Rule | Description |
108
+ |------|-------------|
109
+ | CONST-NAME-001 | File naming follows kebab-case |
110
+ ```
111
+
112
+ ## Integration Points
113
+
114
+ - **Pre-commit**: Implement Agent chạy trước khi commit
115
+ - **Review**: Review Agent include trong adversarial review
116
+ - **CI**: Có thể tích hợp vào CI pipeline
117
+
118
+ ## Gotchas
119
+
120
+ 1. **Không phải mọi rule đều auto-checkable** — UI/UX rules cần manual review
121
+ 2. **False positives** — Regex-based checks có thể bắt nhầm. Agent nên verify context
122
+ 3. **Performance** — Với codebase lớn, chỉ check changed files, không scan toàn bộ
123
+ 4. **Constitution evolves** — Khi constitution update, cần re-run check trên existing code
124
+
125
+ ## Wiring enforcement thật (tùy chọn — khuyến nghị cho production)
126
+
127
+ > Frontmatter `triggers: [pre_commit, review_check]` chỉ là **ý định** — harness/Claude Code KHÔNG tự fire. Có 2 cách để enforce thật (chọn 1):
128
+
129
+ 1. **Agent-invoked (mặc định, không cần setup)**: Implement Agent chạy script trong quy trình B.1 (Bước 4). Deterministic trong 1 lần chạy V-Flow, nhưng phụ thuộc agent thực hiện đúng quy trình.
130
+ 2. **Hard gate (CI / git hook)** — chống bỏ sót triệt để:
131
+ - **git pre-commit**: tạo `.husky/pre-commit` (hoặc `.git/hooks/pre-commit`) gọi `bash .v-flow/skills/implement/constitution-enforcer/scripts/check-constitution.sh` và `.v-flow/skills/implement/no-go-zone-guard/scripts/check-nogo-zones.sh` cho mỗi staged file.
132
+ - **CI**: thêm step chạy 2 script trên PR; fail build nếu exit ≠ 0.
133
+
134
+ > ⚠️ Việc tạo git hook làm thay đổi môi trường dev của cả team — chỉ thêm khi đã thống nhất.
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "constitution-enforcer",
3
+ "version": "1.0",
4
+ "description": "Validates code against constitution.md rules during B.1 and R.1",
5
+ "agent": "implement",
6
+ "phase": ["B.1", "R.1"],
7
+ "triggers": ["pre_commit", "review_check"],
8
+ "dependencies": ["_shared/constitution-reader", "_shared/context-reader"],
9
+ "config": {
10
+ "severity_levels": ["error", "warning", "info"],
11
+ "default_categories": ["naming", "architecture", "testing", "security", "api"],
12
+ "scan_mode": "changed_files",
13
+ "fail_on": "error",
14
+ "report_format": "markdown"
15
+ }
16
+ }
@@ -0,0 +1,42 @@
1
+ # Constitution Enforcer — Bad Example
2
+
3
+ > Ví dụ output THIẾU SÓT — không nên làm theo.
4
+
5
+ ## ❌ Bad Output
6
+
7
+ ```markdown
8
+ ## Constitution Check
9
+
10
+ Everything looks fine. No major issues found.
11
+
12
+ Compliance: OK
13
+ ```
14
+
15
+ ## Vấn đề
16
+
17
+ | # | Lỗi | Giải thích |
18
+ |---|------|-----------|
19
+ | 1 | Không cụ thể | "Everything looks fine" không list rules đã check |
20
+ | 2 | Không có evidence | Không chỉ rõ files đã scan |
21
+ | 3 | False negative | Có thể bỏ sót violations vì không check systematic |
22
+ | 4 | Không có score | Không có metric để track trends |
23
+ | 5 | Không liệt kê passed rules | Không chứng minh thực sự đã check |
24
+
25
+ ## ❌ Bad Output — Quá vague
26
+
27
+ ```markdown
28
+ ## Compliance Report
29
+
30
+ - Checked 3 files
31
+ - Found some naming issues
32
+ - Architecture seems OK
33
+ ```
34
+
35
+ ## Vấn đề
36
+
37
+ | # | Lỗi | Giải thích |
38
+ |---|------|-----------|
39
+ | 1 | "Some naming issues" — mấy? ở đâu? | Phải chỉ file + line + rule |
40
+ | 2 | "Seems OK" — không xác định | Phải PASS hoặc FAIL rõ ràng |
41
+ | 3 | Không có Rule ID | Không thể trace back constitution section |
42
+ | 4 | Không có severity | Không biết Error hay Warning |
@@ -0,0 +1,57 @@
1
+ # Constitution Enforcer — Good Example
2
+
3
+ > Ví dụ output khi Implement Agent chạy constitution-enforcer trước khi commit.
4
+
5
+ ## Input
6
+
7
+ **Constitution.md excerpts:**
8
+ ```markdown
9
+ §1 Architecture: Clean Architecture — domain layer KHÔNG import từ data/presentation
10
+ §2 Code Standards: camelCase cho variables, PascalCase cho classes
11
+ §6 Naming: Files dùng kebab-case, test files dùng *.test.js
12
+ §7 No-Go Zones: lib/legacy-auth/** (không sửa, không import)
13
+ ```
14
+
15
+ **Changed files:**
16
+ - `src/features/user/domain/user.entity.js`
17
+ - `src/features/user/data/user.repository.js`
18
+ - `src/features/user/presentation/user.controller.js`
19
+
20
+ ## Output — Constitution Compliance Report
21
+
22
+ ```markdown
23
+ ## Constitution Compliance Report
24
+
25
+ ### Summary
26
+ - Rules checked: 12
27
+ - Violations: 2 (1 error, 1 warning)
28
+ - Compliance score: 83%
29
+
30
+ ### Violations
31
+
32
+ | # | Rule | File | Line | Description | Severity |
33
+ |---|------|------|------|-------------|----------|
34
+ | 1 | CONST-ARCH-001 | user.entity.js | 3 | `import { db } from '../../data/database'` — Domain layer importing from data layer | Error |
35
+ | 2 | CONST-NAME-002 | user.controller.js | 15 | Variable `user_name` uses snake_case instead of camelCase | Warning |
36
+
37
+ ### Passed Rules
38
+
39
+ | Rule | Description | Files Checked |
40
+ |------|-------------|---------------|
41
+ | CONST-NAME-001 | File naming follows kebab-case | 3/3 ✅ |
42
+ | CONST-NAME-003 | Test files use *.test.js pattern | 1/1 ✅ |
43
+ | CONST-ARCH-002 | No imports from No-Go Zones (lib/legacy-auth) | 3/3 ✅ |
44
+ | CONST-SEC-001 | No hardcoded secrets detected | 3/3 ✅ |
45
+
46
+ ### Recommendations
47
+ 1. **CONST-ARCH-001**: Move database dependency to repository layer, inject via constructor
48
+ 2. **CONST-NAME-002**: Rename `user_name` → `userName`
49
+ ```
50
+
51
+ ## Why This Is Good
52
+
53
+ 1. ✅ Cụ thể — chỉ rõ file, line, và rule bị vi phạm
54
+ 2. ✅ Actionable — mỗi violation có recommendation cụ thể
55
+ 3. ✅ Balanced — liệt kê cả passed rules
56
+ 4. ✅ Severity phân rõ — Error vs Warning giúp prioritize
57
+ 5. ✅ Compliance score — metric đo lường trends
@@ -0,0 +1,26 @@
1
+ # Constitution Enforcer — Gotchas & Common Mistakes
2
+
3
+ ## ⚠️ Gotcha 1: Over-enforcement
4
+
5
+ **Sai**: Cứng nhắc block mọi vi phạm, kể cả những rule mơ hồ.
6
+ **Đúng**: Chỉ block trên `error` severity. `warning` chỉ cảnh báo, để developer quyết định.
7
+
8
+ ## ⚠️ Gotcha 2: Scope Creep
9
+
10
+ **Sai**: Check toàn bộ codebase mỗi lần commit.
11
+ **Đúng**: Chỉ check **changed files** trong commit/PR hiện tại. Full scan chỉ khi `v-flow doctor`.
12
+
13
+ ## ⚠️ Gotcha 3: Static Rules vs Dynamic Context
14
+
15
+ **Sai**: Áp dụng naming convention cho tất cả files, kể cả generated code.
16
+ **Đúng**: Respect No-Go Zones từ `context.md`. Generated code, vendor code, legacy code excluded.
17
+
18
+ ## ⚠️ Gotcha 4: Constitution Updates
19
+
20
+ **Sai**: Khi constitution update, yêu cầu fix ngay toàn bộ codebase.
21
+ **Đúng**: New rules chỉ apply cho new/changed code. Tạo tech-debt ticket cho existing violations.
22
+
23
+ ## ⚠️ Gotcha 5: False Positives trong Security Checks
24
+
25
+ **Sai**: Flag mọi string constant as "potential hardcoded secret".
26
+ **Đúng**: Chỉ flag patterns match secrets (keys, tokens, passwords). Use allowlist cho known safe constants.
@@ -0,0 +1,88 @@
1
+ #!/bin/bash
2
+ # check-constitution.sh — Phần CƠ HỌC (tool-enforced) của Constitution compliance.
3
+ # KHÔNG thay thế LLM review cho rule semantic (architecture/layering/API) — chỉ chạy
4
+ # các check có thể tự động hóa: (1) scan hardcoded secret, (2) chạy linter của dự án.
5
+ #
6
+ # Usage:
7
+ # ./check-constitution.sh [--base <git-ref>] [--lint "<command>"]
8
+ # --base : so changed files với ref này (mặc định: HEAD + staged)
9
+ # --lint : lệnh lint tường minh; nếu bỏ → đọc .v-flow/config.yaml → lint_command,
10
+ # rồi autodetect (npm run lint / flutter analyze / ruff). Không có → skip.
11
+ #
12
+ # Exit: 0 = PASS · 1 = FAIL (secret tìm thấy hoặc lint fail)
13
+
14
+ set -u
15
+ BASE=""
16
+ LINT_CMD=""
17
+ while [ $# -gt 0 ]; do
18
+ case "$1" in
19
+ --base) BASE="$2"; shift 2 ;;
20
+ --lint) LINT_CMD="$2"; shift 2 ;;
21
+ *) echo "Unknown arg: $1"; exit 1 ;;
22
+ esac
23
+ done
24
+
25
+ FAIL=0
26
+
27
+ # ── Danh sách changed files ──────────────────────────────────────────────
28
+ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
29
+ echo "ℹ️ Không phải git repo — bỏ qua phần changed-files; chỉ chạy lint nếu có."
30
+ CHANGED=""
31
+ else
32
+ if [ -n "$BASE" ]; then
33
+ CHANGED=$(git diff --name-only --diff-filter=ACM "$BASE" 2>/dev/null)
34
+ else
35
+ CHANGED=$( (git diff --name-only --diff-filter=ACM HEAD 2>/dev/null; \
36
+ git diff --cached --name-only --diff-filter=ACM 2>/dev/null) | sort -u)
37
+ fi
38
+ fi
39
+
40
+ # ── Check 1: Hardcoded secrets (deterministic) ───────────────────────────
41
+ echo "── Secret scan (changed files) ──"
42
+ SECRET_RE='(AKIA[0-9A-Z]{16})|(-----BEGIN [A-Z ]*PRIVATE KEY-----)|(([Aa][Pp][Ii]_?[Kk][Ee][Yy]|[Ss][Ee][Cc][Rr][Ee][Tt]|[Tt][Oo][Kk][Ee][Nn]|[Pp][Aa][Ss][Ss][Ww][Oo][Rr][Dd])[[:space:]]*[:=][[:space:]]*['"'"'"][^'"'"'"]{8,}['"'"'"])'
43
+ # Allowlist: env-var, ví dụ, placeholder — bỏ qua để giảm false positive
44
+ ALLOW_RE='process\.env|os\.environ|getenv|import\.meta\.env|example|placeholder|changeme|dummy|<your|xxxx|REDACTED|\$\{'
45
+ SECRET_HITS=0
46
+ if [ -n "$CHANGED" ]; then
47
+ while IFS= read -r f; do
48
+ [ -z "$f" ] || [ ! -f "$f" ] && continue
49
+ case "$f" in *.lock|*.png|*.jpg|*.svg|*.min.js) continue ;; esac
50
+ hits=$(grep -EnI "$SECRET_RE" "$f" 2>/dev/null | grep -Ev "$ALLOW_RE")
51
+ if [ -n "$hits" ]; then
52
+ echo "🚫 Hardcoded secret nghi vấn trong $f:"
53
+ echo "$hits" | sed 's/^/ /'
54
+ SECRET_HITS=$((SECRET_HITS+1))
55
+ fi
56
+ done <<EOF
57
+ $CHANGED
58
+ EOF
59
+ fi
60
+ if [ "$SECRET_HITS" -eq 0 ]; then echo "✅ Không thấy hardcoded secret."; else FAIL=1; fi
61
+
62
+ # ── Check 2: Linter của dự án ────────────────────────────────────────────
63
+ echo "── Linter ──"
64
+ if [ -z "$LINT_CMD" ] && [ -f .v-flow/config.yaml ]; then
65
+ LINT_CMD=$(grep -E '^[[:space:]]*lint_command:' .v-flow/config.yaml 2>/dev/null \
66
+ | head -1 | sed -E 's/^[^:]*:[[:space:]]*//; s/^["'"'"']//; s/["'"'"']$//')
67
+ fi
68
+ if [ -z "$LINT_CMD" ]; then
69
+ if [ -f package.json ] && grep -q '"lint"' package.json 2>/dev/null; then LINT_CMD="npm run -s lint"
70
+ elif [ -f pubspec.yaml ]; then LINT_CMD="flutter analyze"
71
+ elif command -v ruff >/dev/null 2>&1 && ls ./*.py >/dev/null 2>&1; then LINT_CMD="ruff check ."
72
+ fi
73
+ fi
74
+ if [ -z "$LINT_CMD" ]; then
75
+ echo "⚠️ Không xác định được lệnh lint — set .v-flow/config.yaml → lint_command hoặc dùng --lint. (skip)"
76
+ else
77
+ echo "▶ $LINT_CMD"
78
+ if eval "$LINT_CMD"; then echo "✅ Lint pass."; else echo "🚫 Lint FAIL."; FAIL=1; fi
79
+ fi
80
+
81
+ echo "────────────────────────────"
82
+ if [ "$FAIL" -eq 0 ]; then
83
+ echo "✅ check-constitution: PASS (phần cơ học). Rule semantic vẫn cần LLM/human review."
84
+ exit 0
85
+ else
86
+ echo "🚫 check-constitution: FAIL — sửa trước khi commit."
87
+ exit 1
88
+ fi