@educa-corp/sdd-framework 0.3.0 → 0.4.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.
Files changed (126) hide show
  1. package/bin/build.js +9 -0
  2. package/bin/index.js +115 -4
  3. package/bin/self-check.js +236 -0
  4. package/bin/trace-schema.json +692 -0
  5. package/commands/debug.md +82 -17
  6. package/commands/define-product.md +82 -17
  7. package/commands/dev-gen-test.md +82 -17
  8. package/commands/dev-run-test.md +84 -18
  9. package/commands/dev-run-test.tmpl +2 -1
  10. package/commands/dev-smoke-test.md +82 -17
  11. package/commands/fix-bug.md +137 -20
  12. package/commands/fix-bug.tmpl +29 -3
  13. package/commands/generate-architecture.md +82 -17
  14. package/commands/generate-bdd.md +187 -44
  15. package/commands/generate-bdd.tmpl +92 -17
  16. package/commands/generate-code.md +115 -20
  17. package/commands/generate-code.tmpl +33 -3
  18. package/commands/generate-design-spec.md +82 -17
  19. package/commands/generate-prd.md +82 -17
  20. package/commands/generate-spec-manifest.md +82 -17
  21. package/commands/generate-tech-docs.md +85 -20
  22. package/commands/generate-tech-docs.tmpl +2 -2
  23. package/commands/learn.md +82 -17
  24. package/commands/map-testids.md +82 -17
  25. package/commands/propose-scenario.md +102 -19
  26. package/commands/propose-scenario.tmpl +20 -2
  27. package/commands/qc-analyze.md +82 -17
  28. package/commands/qc-design-test.md +82 -17
  29. package/commands/qc-plan.md +82 -17
  30. package/commands/qc-report.md +82 -17
  31. package/commands/qc-review.md +82 -17
  32. package/commands/qc-run-test.md +104 -19
  33. package/commands/qc-run-test.tmpl +22 -2
  34. package/commands/refine-prd.md +82 -17
  35. package/commands/report-bug.md +82 -17
  36. package/commands/review-code.md +122 -19
  37. package/commands/review-code.tmpl +40 -2
  38. package/commands/review-context.md +124 -21
  39. package/commands/review-context.tmpl +42 -4
  40. package/commands/review-tech-docs.md +113 -19
  41. package/commands/review-tech-docs.tmpl +31 -2
  42. package/commands/setup-ai-first.md +35 -16
  43. package/commands/setup-ai-first.tmpl +19 -6
  44. package/commands/sync.md +15 -4
  45. package/commands/sync.tmpl +12 -2
  46. package/commands/update-framework.md +40 -2
  47. package/commands/update-framework.tmpl +37 -0
  48. package/commands/validate-traces.md +231 -25
  49. package/commands/validate-traces.tmpl +149 -8
  50. package/core/FRAMEWORK_VERSION +1 -1
  51. package/core/README.md +56 -0
  52. package/core/commands/debug.md +82 -17
  53. package/core/commands/define-product.md +82 -17
  54. package/core/commands/dev-gen-test.md +82 -17
  55. package/core/commands/dev-run-test.md +84 -18
  56. package/core/commands/dev-smoke-test.md +82 -17
  57. package/core/commands/fix-bug.md +137 -20
  58. package/core/commands/generate-architecture.md +82 -17
  59. package/core/commands/generate-bdd.md +187 -44
  60. package/core/commands/generate-code.md +115 -20
  61. package/core/commands/generate-design-spec.md +82 -17
  62. package/core/commands/generate-prd.md +82 -17
  63. package/core/commands/generate-spec-manifest.md +82 -17
  64. package/core/commands/generate-tech-docs.md +85 -20
  65. package/core/commands/learn.md +82 -17
  66. package/core/commands/map-testids.md +82 -17
  67. package/core/commands/propose-scenario.md +102 -19
  68. package/core/commands/qc-analyze.md +82 -17
  69. package/core/commands/qc-design-test.md +82 -17
  70. package/core/commands/qc-plan.md +82 -17
  71. package/core/commands/qc-report.md +82 -17
  72. package/core/commands/qc-review.md +82 -17
  73. package/core/commands/qc-run-test.md +104 -19
  74. package/core/commands/refine-prd.md +82 -17
  75. package/core/commands/report-bug.md +82 -17
  76. package/core/commands/review-code.md +122 -19
  77. package/core/commands/review-context.md +124 -21
  78. package/core/commands/review-tech-docs.md +113 -19
  79. package/core/commands/setup-ai-first.md +35 -16
  80. package/core/commands/sync.md +15 -4
  81. package/core/commands/update-framework.md +40 -2
  82. package/core/commands/validate-traces.md +231 -25
  83. package/core/modules/android-compose/stack-profile.yaml +1 -1
  84. package/core/modules/flutter/stack-profile.yaml +1 -1
  85. package/core/modules/ios-swiftui/stack-profile.yaml +1 -1
  86. package/core/modules/java-spring/stack-profile.yaml +1 -1
  87. package/core/modules/nextjs/stack-profile.yaml +1 -1
  88. package/core/modules/nuxt/stack-profile.yaml +1 -1
  89. package/core/modules/phaser-game/stack-profile.yaml +1 -1
  90. package/core/modules/php-laravel/stack-profile.yaml +1 -1
  91. package/core/modules/qc-playwright/stack-profile.yaml +1 -1
  92. package/core/modules/react/stack-profile.yaml +1 -1
  93. package/core/modules/react-native/stack-profile.yaml +1 -1
  94. package/core/modules/vue/stack-profile.yaml +1 -1
  95. package/core/rules/workflow.md +11 -0
  96. package/core/steps/context-loader.md +66 -7
  97. package/core/steps/gate.md +13 -8
  98. package/core/steps/report-footer.md +3 -2
  99. package/core/templates/README.md +47 -0
  100. package/core/templates/feature.template +13 -10
  101. package/core/templates/project-context.yaml +49 -17
  102. package/core/templates/tech-design.template.md +1 -1
  103. package/docs/02-concepts/traceability.md +29 -6
  104. package/docs/04-reference/trace-schema.md +128 -37
  105. package/modules/android-compose/stack-profile.yaml +1 -1
  106. package/modules/flutter/stack-profile.yaml +1 -1
  107. package/modules/ios-swiftui/stack-profile.yaml +1 -1
  108. package/modules/java-spring/stack-profile.yaml +1 -1
  109. package/modules/nextjs/stack-profile.yaml +1 -1
  110. package/modules/nuxt/stack-profile.yaml +1 -1
  111. package/modules/phaser-game/stack-profile.yaml +1 -1
  112. package/modules/php-laravel/stack-profile.yaml +1 -1
  113. package/modules/qc-playwright/stack-profile.yaml +1 -1
  114. package/modules/react/stack-profile.yaml +1 -1
  115. package/modules/react-native/stack-profile.yaml +1 -1
  116. package/modules/vue/stack-profile.yaml +1 -1
  117. package/package.json +50 -49
  118. package/rules/workflow.md +11 -0
  119. package/scripts/migrate-bdd-platform.js +286 -0
  120. package/steps/context-loader.md +66 -7
  121. package/steps/gate.md +13 -8
  122. package/steps/report-footer.md +3 -2
  123. package/templates/README.md +47 -0
  124. package/templates/feature.template +13 -10
  125. package/templates/project-context.yaml +49 -17
  126. package/templates/tech-design.template.md +1 -1
@@ -0,0 +1,286 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * migrate-bdd-platform — move flat BDD files into the per-platform layout.
4
+ *
5
+ * specs/{domain}/{prd-slug}/bdd/{FILE}.feature
6
+ * → specs/{domain}/{prd-slug}/bdd/{platform}/{FILE}.feature
7
+ *
8
+ * The flat layout was produced by the umbrella-mode branch of /generate-bdd before
9
+ * v0.4.1 (see GAPS.md G3). It breaks five consumers — most importantly `web` and
10
+ * `system` features of the same UC collide on one filename and overwrite each other.
11
+ *
12
+ * The {platform} for each file is resolved in this order:
13
+ * 1. `# @trace.platform:` in the file header (authoritative)
14
+ * 2. `# @trace.module:` mapped through MODULE_PLATFORM (umbrella files carry it)
15
+ * 3. Gherkin step vocabulary ("clicks"→web, "taps"→app, "calls the API"→system)
16
+ * Files that cannot be resolved are LEFT IN PLACE and listed — never moved to a guess.
17
+ *
18
+ * After moving, `@trace.platform` is INSERTED into the header if it was missing
19
+ * (it is mandatory in every mode), and internal path references to the moved files
20
+ * are rewritten across specs/ and .trace/.
21
+ *
22
+ * Also reports (does NOT fix) two conditions that need a human:
23
+ * - OCCUPIED : the target path already holds a file (mixed/partial layout) — moving
24
+ * would overwrite it, so the flat file is left in place instead
25
+ * - LOST SPEC : a UC has N trace books ({UC}-{platform}.tsv) but fewer flat files
26
+ * than N → a previous run likely overwrote a platform's .feature
27
+ *
28
+ * DRY-RUN by default (prints the plan, changes nothing). Pass --apply to execute.
29
+ * Tracked files move with `git mv` to preserve history; the rest with fs.rename.
30
+ *
31
+ * Usage (from the consumer project root):
32
+ * node scripts/migrate-bdd-platform.js # dry-run, prints plan
33
+ * node scripts/migrate-bdd-platform.js --apply # execute
34
+ * node scripts/migrate-bdd-platform.js --specs specs --trace .trace --root .
35
+ */
36
+
37
+ const fs = require('fs');
38
+ const path = require('path');
39
+ const { execSync } = require('child_process');
40
+
41
+ // ── args ──────────────────────────────────────────────────────────────────────
42
+ const argv = process.argv.slice(2);
43
+ const has = f => argv.includes(f);
44
+ const flag = (f, d) => { const i = argv.indexOf(f); return i !== -1 ? argv[i + 1] : d; };
45
+
46
+ const APPLY = has('--apply');
47
+ const ROOT = path.resolve(flag('--root', '.'));
48
+ const SPECS = flag('--specs', 'specs');
49
+ const TRACE = flag('--trace', '.trace');
50
+
51
+ const specsAbs = path.join(ROOT, SPECS);
52
+ const traceAbs = path.join(ROOT, TRACE);
53
+
54
+ const PLATFORMS = ['web', 'app', 'system'];
55
+
56
+ // module → platform (same table as /generate-bdd §Service Detection)
57
+ const MODULE_PLATFORM = {
58
+ react: 'web', nextjs: 'web', vue: 'web', nuxt: 'web', angular: 'web',
59
+ flutter: 'app', 'react-native': 'app', 'ios-swiftui': 'app', 'android-compose': 'app',
60
+ 'java-spring': 'system', golang: 'system', dotnet: 'system', 'php-laravel': 'system',
61
+ 'context-engineering': 'system', 'phaser-game': 'web',
62
+ };
63
+
64
+ // ── git tracked set (for `git mv`) ────────────────────────────────────────────
65
+ let tracked = null;
66
+ try {
67
+ const out = execSync('git ls-files', { cwd: ROOT, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
68
+ tracked = new Set(out.split('\n').filter(Boolean).map(p => p.replace(/\\/g, '/')));
69
+ } catch { tracked = null; }
70
+
71
+ const rel = abs => path.relative(ROOT, abs).replace(/\\/g, '/');
72
+ const isTracked = abs => !!(tracked && tracked.has(rel(abs)));
73
+
74
+ // ── helpers ───────────────────────────────────────────────────────────────────
75
+ function walk(dir) {
76
+ const out = [];
77
+ if (!fs.existsSync(dir)) return out;
78
+ for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
79
+ const p = path.join(dir, e.name);
80
+ if (e.isDirectory()) out.push(...walk(p));
81
+ else out.push(p);
82
+ }
83
+ return out;
84
+ }
85
+ const read = file => { try { return fs.readFileSync(file, 'utf8'); } catch { return ''; } };
86
+
87
+ const rePlatform = /^#\s*@trace\.platform\s*:\s*([A-Za-z-]+)\s*$/m;
88
+ const reModule = /^#\s*@trace\.module\s*:\s*([A-Za-z0-9-]+)\s*$/m;
89
+ const reUcId = /^#\s*@trace\.id\s*:\s*([A-Za-z0-9_-]+)\s*$/m;
90
+
91
+ /** Resolve platform for one flat .feature file. Returns {platform, via} or null. */
92
+ function resolvePlatform(body) {
93
+ const tagged = (body.match(rePlatform) || [])[1];
94
+ if (tagged && PLATFORMS.includes(tagged)) return { platform: tagged, via: '@trace.platform' };
95
+
96
+ const mod = (body.match(reModule) || [])[1];
97
+ if (mod && MODULE_PLATFORM[mod]) return { platform: MODULE_PLATFORM[mod], via: `@trace.module=${mod}` };
98
+
99
+ // last resort: step vocabulary (see the per-platform table in /generate-bdd)
100
+ const steps = body.toLowerCase();
101
+ const web = /\b(clicks|types into|the page shows)\b/.test(steps);
102
+ const app = /\b(taps|the screen shows)\b/.test(steps);
103
+ const sys = /\b(calls the api|submits a request|the system returns|receives response)\b/.test(steps);
104
+ const hits = [web && 'web', app && 'app', sys && 'system'].filter(Boolean);
105
+ if (hits.length === 1) return { platform: hits[0], via: 'step vocabulary' };
106
+
107
+ return null;
108
+ }
109
+
110
+ /** Trace books present for a UC, e.g. {UC}-web.tsv → ['web'] */
111
+ function tracePlatformsFor(ucId) {
112
+ const found = new Set();
113
+ for (const f of walk(traceAbs).filter(f => f.endsWith('.tsv'))) {
114
+ const m = path.basename(f).match(/^(.+)-(web|app|system)\.tsv$/);
115
+ if (m && m[1] === ucId) found.add(m[2]);
116
+ }
117
+ return [...found];
118
+ }
119
+
120
+ // ── plan ──────────────────────────────────────────────────────────────────────
121
+ const moves = []; // { from, to, platform, via, needsTag }
122
+ const unresolved = []; // { file, reason }
123
+ const occupied = []; // { from, to } — target already exists (mixed layout)
124
+ const lostSpecs = []; // { ucId, flat, traceBooks[] }
125
+
126
+ const bddDirs = new Set();
127
+ for (const f of walk(specsAbs).filter(f => f.endsWith('.feature'))) {
128
+ const parts = rel(f).split('/');
129
+ const i = parts.lastIndexOf('bdd');
130
+ if (i === -1) continue;
131
+ // flat == the file sits DIRECTLY under bdd/ (no platform subfolder)
132
+ if (parts.length !== i + 2) continue;
133
+ bddDirs.add(parts.slice(0, i + 1).join('/'));
134
+
135
+ const body = read(f);
136
+ const res = resolvePlatform(body);
137
+ if (!res) {
138
+ unresolved.push({
139
+ file: rel(f),
140
+ reason: 'no @trace.platform, no recognizable @trace.module, and step vocabulary is ambiguous ' +
141
+ '→ add `# @trace.platform: web|app|system` to the header, then re-run',
142
+ });
143
+ continue;
144
+ }
145
+ const dir = path.dirname(f);
146
+ const target = path.join(dir, res.platform, path.basename(f));
147
+
148
+ // Mixed layout: some platforms already migrated, this one left flat. Moving onto an
149
+ // existing file would silently overwrite a real spec — leave it and let a human look.
150
+ if (fs.existsSync(target)) { occupied.push({ from: f, to: target }); continue; }
151
+
152
+ moves.push({
153
+ from: f,
154
+ to: target,
155
+ platform: res.platform,
156
+ via: res.via,
157
+ needsTag: res.via !== '@trace.platform',
158
+ });
159
+ }
160
+
161
+ // lost-spec detection: UC has more trace books than flat files
162
+ const flatByUc = new Map();
163
+ for (const m of moves) {
164
+ const uc = (read(m.from).match(reUcId) || [])[1] || path.basename(m.from).replace(/\.feature$/, '');
165
+ flatByUc.set(uc, [...(flatByUc.get(uc) || []), m]);
166
+ }
167
+ for (const [ucId, list] of flatByUc) {
168
+ const books = tracePlatformsFor(ucId);
169
+ if (books.length > list.length) {
170
+ lostSpecs.push({ ucId, flat: list.map(m => m.platform), traceBooks: books });
171
+ }
172
+ }
173
+
174
+ const refMap = new Map();
175
+ for (const m of moves) refMap.set(rel(m.from), rel(m.to));
176
+
177
+ // ── report ────────────────────────────────────────────────────────────────────
178
+ console.log('');
179
+ console.log('╔════════════════════════════════════════════════╗');
180
+ console.log(`║ migrate-bdd-platform — ${APPLY ? 'APPLY' : 'DRY RUN'}${' '.repeat(APPLY ? 16 : 14)}║`);
181
+ console.log('╚════════════════════════════════════════════════╝');
182
+ console.log(`Root : ${ROOT}`);
183
+ console.log(`Specs : ${SPECS}/ Trace: ${TRACE}/ Git: ${tracked ? 'yes (git mv)' : 'no (fs move)'}`);
184
+ console.log('');
185
+
186
+ if (!moves.length && !unresolved.length && !occupied.length) {
187
+ console.log(`Nothing to migrate — no .feature file sits directly under a bdd/ folder.`);
188
+ console.log(`(Scanned ${bddDirs.size} bdd/ folder(s) under ${SPECS}/.)`);
189
+ process.exit(0);
190
+ }
191
+
192
+ const byPlatform = moves.reduce((a, m) => ((a[m.platform] = (a[m.platform] || 0) + 1), a), {});
193
+ console.log(`Planned moves: ${moves.length} (${Object.entries(byPlatform).map(([k, v]) => `${k}:${v}`).join(' ')})`);
194
+ console.log('');
195
+ for (const m of moves) {
196
+ console.log(` ${rel(m.from)}`);
197
+ console.log(` → ${rel(m.to)} [platform via ${m.via}${m.needsTag ? ' · will INSERT @trace.platform' : ''}]`);
198
+ }
199
+
200
+ if (occupied.length) {
201
+ console.log('');
202
+ console.log(`🔴 OCCUPIED — ${occupied.length} target path already holds a file (mixed/partial layout).`);
203
+ console.log(` NOT moved — that would overwrite a real spec.`);
204
+ for (const o of occupied) console.log(` ${rel(o.from)}\n target exists: ${rel(o.to)}`);
205
+ console.log(` → Diff the two files. Keep the right one, delete the other, then re-run.`);
206
+ }
207
+
208
+ if (lostSpecs.length) {
209
+ console.log('');
210
+ console.log(`🔴 LOST SPEC — a UC has more trace books than flat .feature files.`);
211
+ console.log(` A previous flat-layout run very likely OVERWROTE one platform's .feature.`);
212
+ console.log(` Migration cannot recover it — restore from git history, or re-run /generate-bdd`);
213
+ console.log(` for the missing platform AFTER this migration.`);
214
+ for (const l of lostSpecs) {
215
+ console.log(` ${l.ucId}: flat file(s) resolve to [${l.flat.join(', ')}] but trace books exist for [${l.traceBooks.join(', ')}]`);
216
+ }
217
+ }
218
+
219
+ if (unresolved.length) {
220
+ console.log('');
221
+ console.log(`⚠️ Unresolved (LEFT IN PLACE):`);
222
+ for (const u of unresolved) console.log(` ${u.file}\n ${u.reason}`);
223
+ }
224
+
225
+ console.log('');
226
+ if (!APPLY) {
227
+ console.log('DRY RUN — nothing changed. Re-run with --apply to execute.');
228
+ process.exit(0);
229
+ }
230
+
231
+ // ── apply ─────────────────────────────────────────────────────────────────────
232
+ function mv(from, to) {
233
+ fs.mkdirSync(path.dirname(to), { recursive: true });
234
+ if (isTracked(from)) execSync(`git mv -k "${rel(from)}" "${rel(to)}"`, { cwd: ROOT, stdio: ['ignore', 'ignore', 'pipe'] });
235
+ else fs.renameSync(from, to);
236
+ }
237
+
238
+ /** Insert `# @trace.platform:` right after `# @trace.domain:` (or after @trace.id). */
239
+ function insertPlatformTag(absFile, platform) {
240
+ const txt = read(absFile);
241
+ if (rePlatform.test(txt)) return false;
242
+ const lines = txt.split('\n');
243
+ let at = lines.findIndex(l => /^#\s*@trace\.domain\s*:/.test(l));
244
+ if (at === -1) at = lines.findIndex(l => /^#\s*@trace\.id\s*:/.test(l));
245
+ if (at === -1) return false;
246
+ lines.splice(at + 1, 0, `# @trace.platform: ${platform}`);
247
+ fs.writeFileSync(absFile, lines.join('\n'), 'utf8');
248
+ return true;
249
+ }
250
+
251
+ function rewriteRefs(absFile) {
252
+ if (!/\.(md|feature|tsv|ya?ml|json)$/.test(absFile)) return 0;
253
+ let txt = read(absFile);
254
+ if (!txt) return 0;
255
+ let n = 0, out = txt;
256
+ for (const [oldRef, newRef] of refMap) {
257
+ if (out.includes(oldRef)) { out = out.split(oldRef).join(newRef); n++; }
258
+ }
259
+ if (n) fs.writeFileSync(absFile, out, 'utf8');
260
+ return n;
261
+ }
262
+
263
+ let moved = 0, tagged = 0, skipped = 0;
264
+ for (const m of moves) {
265
+ try {
266
+ mv(m.from, m.to);
267
+ moved++;
268
+ if (m.needsTag && insertPlatformTag(m.to, m.platform)) tagged++;
269
+ } catch (err) {
270
+ console.log(` ❌ ${rel(m.from)} — ${err.message.split('\n')[0]}`);
271
+ skipped++;
272
+ }
273
+ }
274
+
275
+ let rewritten = 0;
276
+ for (const f of [...walk(specsAbs), ...walk(traceAbs)]) rewritten += rewriteRefs(f) ? 1 : 0;
277
+
278
+ console.log(`✅ Moved ${moved} file(s)${skipped ? `, skipped ${skipped}` : ''}.`);
279
+ console.log(`✅ Inserted @trace.platform into ${tagged} header(s).`);
280
+ console.log(`✅ Rewrote path references in ${rewritten} file(s).`);
281
+ console.log('');
282
+ console.log('Next:');
283
+ console.log(' 1. git diff — review the moves + inserted headers');
284
+ console.log(' 2. /validate-traces — reconcile trace books against the new layout');
285
+ console.log(' 3. Commit (spec repo, if specs live in a submodule)');
286
+ console.log('');
@@ -90,23 +90,82 @@ Nếu có section `services`:
90
90
  - Nếu target không mang `@trace.platform` (vd target là PRD `.md`), thử suy từ segment `bdd/{platform}/` trong path target.
91
91
  - Nếu vẫn không xác định được → `active_platform = null`.
92
92
 
93
- **2. Route tới service** — nếu active domain khớp một key trong `services`. Giá trị `services.{domain}` có **hai dạng**; nhận dạng bằng việc có `path` trực tiếp hay không:
93
+ **2. Route tới service** — nếu active domain khớp một key trong `services`.
94
+
95
+ Hình dung việc này như **tra địa chỉ**: đi từ `domain`, có thể qua `platform`, có thể qua `prd_slug`, cho tới khi chỉ còn đúng một submodule.
96
+
97
+ Thứ trỏ tới đích gọi là một **service entry**. Nó chỉ có hai kiểu:
98
+
99
+ | Kiểu | Nhận ra bằng | Nghĩa |
100
+ |---|---|---|
101
+ | **Đã chốt** | có `path` | Xong — đây là submodule cần tìm |
102
+ | **Tra tiếp** | có `by_prd_slug` | Ô này còn nhiều submodule → tra thêm một nấc bằng `prd_slug` (2c) |
103
+
104
+ **Kiểm tra hợp lệ TRƯỚC khi dùng một entry** (làm ngay, đừng đợi tới 2a/2b/2c — sai ở đây mà đi tiếp là route nhầm repo mà không báo gì):
105
+
106
+ | Entry trông thế nào | Xử lý |
107
+ |---|---|
108
+ | có `path`, không có `by_prd_slug` | hợp lệ → dùng |
109
+ | có `by_prd_slug`, không có `path` | hợp lệ → tra tiếp (2c) |
110
+ | **có CẢ HAI** | ❌ lỗi cấu hình → `active_service = unresolved`. **KHÔNG** ưu tiên `path` rồi bỏ qua `by_prd_slug` — như vậy mọi feature sẽ âm thầm route về cùng một repo. Báo đúng key sai để người dùng sửa. |
111
+ | **không có cái nào** (và cũng không phải map platform) | ❌ lỗi cấu hình → `unresolved`, nêu rõ entry thiếu `path`/`by_prd_slug` |
112
+ | `by_prd_slug` chứa entry lại có `by_prd_slug` | ❌ lỗi cấu hình → `unresolved`. Chỉ tra đúng **một** nấc slug, không đệ quy |
113
+
114
+ Còn `services.{domain}` thì có thể là **một service entry** (chốt luôn ở cấp domain), hoặc **một map platform → service entry** (phải qua nấc platform trước). Nhận dạng theo đúng thứ tự này:
115
+
116
+ | Thấy gì trong `services.{domain}` | Đi nhánh |
117
+ |---|---|
118
+ | có `path` | **2a** — chốt luôn |
119
+ | có `by_prd_slug` | **2c** — tra bằng `prd_slug` |
120
+ | không có cả hai (chỉ có các sub-key `system`/`web`/`app`…) | **2b** — tra bằng `platform`, rồi lặp lại đúng bảng này cho entry con |
94
121
 
95
122
  **2a. Dạng phẳng** — `services.{domain}` có **trực tiếp** `path`/`module` (một domain ↔ một service, mọi platform về cùng submodule). Route như cũ:
96
123
  - Lưu `active_service` = `services.{domain}.path`
97
124
  - Lưu `active_service_module` = `services.{domain}.module`
98
125
  - Nếu service có `module` riêng → dùng nó làm `active_module` (override `tech_stack.module`)
99
126
 
100
- **2b. Dạng map-theo-platform** — `services.{domain}` **KHÔNG** có `path` trực tiếp mà chứa các sub-key platform (`system` / `web` / `app`), mỗi cái là `{ path, module }` (một business-domain trải trên nhiều platform/submodule). Route theo `active_platform` (bước 1b):
101
- - Nếu `active_platform` khớp một sub-key → `entry = services.{domain}.{active_platform}`; lưu `active_service = entry.path`, `active_service_module = entry.module` (→ `active_module`, override `tech_stack.module`).
102
- - Nếu `active_platform = null` (chưa xác định platform, vd đang thao tác cấp PRD) → **KHÔNG** chốt một service; đặt `active_service = multi` và lưu `service_candidates = services.{domain}` (toàn map platform→{path,module}). Lệnh cần một service cụ thể (`/generate-code`, `/dev-*`, `/fix-bug`) luôn chạy trên target `.feature` có platform nên sẽ resolve được ở lần chạy đó; lệnh cấp PRD (`/generate-prd`, `/refine-prd`) không cần service cụ thể.
127
+ **2b. Dạng map-theo-platform** — `services.{domain}` **KHÔNG** có `path` trực tiếp mà chứa các sub-key platform (`system` / `web` / `app`), mỗi cái là một **service entry** (một business-domain trải trên nhiều platform/submodule). Route theo `active_platform` (bước 1b):
128
+ - Nếu `active_platform` khớp một sub-key → `entry = services.{domain}.{active_platform}`. Nếu `entry` có `path` → lưu `active_service = entry.path`, `active_service_module = entry.module` (→ `active_module`, override `tech_stack.module`). Nếu `entry` có `by_prd_slug` → **đi tiếp sang 2c** với entry đó.
129
+ - Nếu `active_platform = null` (chưa xác định platform, vd đang thao tác cấp PRD) → **KHÔNG** chốt một service; đặt `active_service = multi`, `service_candidates_kind = platform`, và lưu `service_candidates` = map platform→`{path, module}`. **Làm phẳng luôn ở đây:** platform nào có entry `by_prd_slug` thì giải bằng `prd_slug` hiện tại (target cấp PRD vẫn nằm trong một feature-package nên `prd_slug` đã biết từ bước 1) `service_candidates.{platform}` vẫn là `{path, module}` phẳng. Nếu `prd_slug` không khớp key nào, ghi platform đó là `unresolved` kèm lý do thay vì bỏ im. Nhờ vậy **mọi lệnh downstream chỉ cần biết một kiểu `service_candidates`**. Lệnh cần một service cụ thể (`/generate-code`, `/dev-*`, `/fix-bug`) luôn chạy trên target `.feature` có platform nên sẽ resolve được ở lần chạy đó; lệnh cấp PRD (`/generate-prd`, `/refine-prd`) không cần service cụ thể.
103
130
  - Nếu `active_platform` xác định nhưng không có sub-key tương ứng → `active_service = unresolved` (xem Fallback) với lý do "domain `{domain}` chưa cấu hình platform `{active_platform}`".
104
131
 
105
- *(Cả 2a/2b: override `paths.specs_dir`/`paths.tech_docs_dir` per-service CHỈ khi `setup.spec_source` KHÔNG được đặt. Khi `spec_source` ĐƯỢC đặt, MỌI BDD/tech-doc artifact liên team để bước 4 route sang spec repo; KHÔNG pin per-service đây.)*
132
+ **2c. Dạng map-theo-prd_slug** một service entry chứa `by_prd_slug` thay cho `path`: **một ô của bảng định tuyến ứng với NHIỀU submodule**, mỗi feature-package một submodule. Dùng khi một platform (hoặc cả một domain) bị chia thành nhiều repo theo feature — ví dụ mỗi mini-game webview là một repo riêng.
133
+
134
+ Đến đây `prd_slug` đã được trích ở bước 1 (không cần detect thêm gì). Route:
135
+
136
+ - Nếu `prd_slug` khớp một key dưới `by_prd_slug` → `entry = {…}.by_prd_slug.{prd_slug}`; lưu `active_service = entry.path`, `active_service_module = entry.module` (→ `active_module`, override `tech_stack.module`).
137
+ **"Khớp" ở đây là khớp CHÍNH XÁC toàn chuỗi, phân biệt hoa/thường.** KHÔNG prefix, KHÔNG bỏ hậu tố, KHÔNG so gần đúng: `dap-chuot-v2` **không** khớp key `dap-chuot`; `Ban-Cung` **không** khớp `ban-cung`. Feature mới tách ra từ một feature cũ là một repo khác cho tới khi có người khai nó vào bảng.
138
+ - Nếu `prd_slug = null` (chưa xác định feature-package — chỉ xảy ra khi không có target file, vd `$ARGUMENTS` rỗng) → **KHÔNG** chốt một service; đặt `active_service = multi`, `service_candidates_kind = prd_slug`, và lưu `service_candidates` = toàn map `by_prd_slug` (slug → `{path, module}`).
139
+ ⚠️ Đây là kiểu `service_candidates` **khác** với 2b — lệnh nào duyệt `service_candidates` theo platform (vd `/generate-bdd` sinh `bdd/{platform}/`) phải kiểm `service_candidates_kind = platform` trước; gặp `prd_slug` thì DỪNG và yêu cầu người dùng chỉ rõ target, đừng coi slug là platform.
140
+ - Nếu `prd_slug` xác định nhưng **không** có key tương ứng → `active_service = unresolved` với lý do rõ: "domain `{domain}`{, platform `{active_platform}`} chưa cấu hình prd_slug `{prd_slug}`". **KHÔNG** tự đoán submodule gần đúng theo tên.
141
+
142
+ Vị trí đặt `by_prd_slug` — hợp lệ ở **cả hai cấp**:
143
+ - **Dưới một platform** (lồng trong 2b): `services.{domain}.{platform}.by_prd_slug` — platform đó có nhiều repo, các platform khác vẫn `{path, module}` như thường.
144
+ - **Ngay dưới domain** (thay cho `path` của 2a): `services.{domain}.by_prd_slug` — domain không chia platform nhưng vẫn nhiều repo theo feature.
145
+
146
+ *(`by_prd_slug` lồng trong `by_prd_slug` là vô nghĩa — nếu gặp, coi là lỗi cấu hình: `active_service = unresolved`, nêu rõ để người dùng sửa file. Một entry vừa có `path` vừa có `by_prd_slug` cũng là lỗi cấu hình — báo lỗi, không âm thầm ưu tiên cái nào.)*
147
+
148
+ Ví dụ (một domain trải nhiều platform, riêng `webview` chia theo feature):
149
+ ```yaml
150
+ services:
151
+ learning:
152
+ system: { path: "backend", module: "java-spring" }
153
+ web: { path: "web-app", module: "nextjs" }
154
+ webview:
155
+ by_prd_slug:
156
+ dap-chuot: { path: "games/whac-a-mole", module: "phaser-game" }
157
+ ban-cung: { path: "games/archery", module: "phaser-game" }
158
+ ```
159
+ → target `specs/learning/dap-chuot/bdd/webview/UC1.feature` cho `domain = learning`,
160
+ `active_platform = webview`, `prd_slug = dap-chuot` → `active_service = games/whac-a-mole`.
161
+
162
+ *(Cả 2a/2b/2c: override `paths.specs_dir`/`paths.tech_docs_dir` per-service CHỈ khi `setup.spec_source` KHÔNG được đặt. Khi `spec_source` ĐƯỢC đặt, MỌI BDD/tech-doc là artifact liên team → để bước 4 route sang spec repo; KHÔNG pin per-service ở đây.)*
106
163
 
107
164
  **3. Fallback**:
108
165
  - Không phát hiện được domain, hoặc domain không khớp key nào trong `services` → giữ path mặc định từ Bước 1, đặt `active_service = unresolved`.
109
166
  - Domain khớp một map-theo-platform (2b) nhưng `active_platform` xác định mà thiếu sub-key tương ứng → `active_service = unresolved`, ghi lý do rõ để lệnh DỪNG báo lỗi cấu hình (không tự đoán platform).
167
+ - Entry là map-theo-prd_slug (2c) nhưng `prd_slug` xác định mà thiếu key tương ứng → `active_service = unresolved`, ghi lý do rõ (không tự đoán submodule).
168
+ - Entry sai cấu trúc (vừa có `path` vừa có `by_prd_slug`, hoặc `by_prd_slug` lồng nhau) → `active_service = unresolved`, nêu đúng key sai để người dùng sửa `project-context.yaml`.
110
169
 
111
170
  **4. Tự động override theo spec source** — nếu `setup.spec_source` được đặt VÀ path tương ứng chưa được set tường minh trong `paths:`:
112
171
  - Override `paths.specs_dir` → `{spec_source}/specs` — **luôn khi `spec_source` được đặt.** Mọi spec artifact (PRD, BDD, tech-docs, design-spec) nằm dưới gốc spec thống nhất trong spec repo dùng chung theo bố cục feature-package: `{spec_source}/specs/{domain}/{prd-slug}/`. Mọi umbrella (FE/App/BE) đều đọc từ đây. *(`specs/` theo service chỉ khi không có `spec_source`.)*
@@ -256,7 +315,7 @@ active_module = tech_stack.module (vd: "java-spring", "react", "flutter")
256
315
  | `platform_type` | Modules |
257
316
  |---|---|
258
317
  | `backend` | `java-spring`, `golang`, `dotnet`, `php-laravel`, `context-engineering` |
259
- | `web-frontend` | `react`, `nextjs`, `vue`, `nuxt`, `angular` |
318
+ | `web-frontend` | `react`, `nextjs`, `vue`, `nuxt`, `angular`, `phaser-game` |
260
319
  | `mobile` | `flutter`, `react-native`, `ios-swiftui`, `android-compose` |
261
320
 
262
321
  Nếu `tech_stack.module` rỗng hoặc không nhận diện được → set `platform_type = "unknown"` và gắn cờ ⚠️ trong recap Bước 7.
@@ -303,7 +362,7 @@ Dict : {loaded — N canonical terms, M banned terms | missing}
303
362
  Entities : {loaded — EntityA, EntityB, EntityC | missing}
304
363
  Lessons : {loaded — N guardrails | chưa có}
305
364
  Platform : {active_platform: system | web | app | — nếu chưa xác định}
306
- Service : {active_service} ({active_service_module}) | multi (map-theo-platform, chốt khi target platform) | single-service
365
+ Service : {active_service} ({active_service_module}) [← domain{/platform}{/prd_slug} nếu route qua by_prd_slug] | multi (map-theo-platform hoặc map-theo-prd_slug, chốt khi target đủ platform/prd_slug) | single-service
307
366
  Svc Root : {service_root} — đã nạp conventions + trace_dir từ config service | —
308
367
  Status : {FULL | PARTIAL — thiếu: CLAUDE.md / business-dict / core-entities | MINIMAL}
309
368
  ```
package/steps/gate.md CHANGED
@@ -29,23 +29,23 @@ Hiển thị và chờ phản hồi:
29
29
  ```
30
30
  ⚙️ MODEL CHECK
31
31
  ──────────────────────────────────────────────────────────────────
32
- Recommended : claude-opus-4 (hoặc model Opus mới nhất)
32
+ Recommended : model Opus mới nhất
33
33
  Why needed : Phân tích spec, review kiến trúc, sinh code đòi hỏi
34
- suy luận sâu. Model nhỏ hơn dễ bỏ sót edge case.
34
+ suy luận sâu. Model nhỏ hơn (Haiku/Sonnet) dễ bỏ sót edge case.
35
35
 
36
36
  Cách đổi trong Claude Code:
37
- SettingsModel chọn "claude-opus"
38
- • hoặc: /modelchọn claude-opus
37
+ /modelchọn model Opus
38
+ • hoặc: SettingsModel
39
39
 
40
- Đang chạy claude-opus?
41
- Y — đúng, đang dùng claude-opus → tiếp tục
40
+ Đang chạy một model Opus?
41
+ Y — đúng → tiếp tục
42
42
  S — bỏ qua kiểm tra (tôi chấp nhận rủi ro chất lượng thấp hơn với model hiện tại)
43
43
  ──────────────────────────────────────────────────────────────────
44
44
  ```
45
45
 
46
46
  - "Y" → tiếp tục sang Bước 1.
47
47
  - "S" → tiếp tục sang Bước 1 (người dùng chấp nhận rủi ro, thêm ⚠️ vào report cuối).
48
- - "N" hoặc bất kỳ giá trị nào khác → **DỪNG.** Xuất: "Vui lòng chuyển sang claude-opus rồi chạy lại lệnh này."
48
+ - "N" hoặc bất kỳ giá trị nào khác → **DỪNG.** Xuất: "Vui lòng chuyển sang một model Opus (`/model`) rồi chạy lại lệnh này."
49
49
 
50
50
  ## Bước 1 — Xác định Target File
51
51
 
@@ -54,7 +54,12 @@ Hiển thị và chờ phản hồi:
54
54
  2. Nếu `$ARGUMENTS` là một **UC-ID / ticket ID / tên rút gọn** (không có path) → phân giải thành file bằng cách glob theo bố cục feature-package. `{prd-slug}` lúc này **chưa biết**, nên dùng wildcard `*` cho segment đó, và `**` đệ quy dưới `bdd/` để phủ hết các thư mục con theo platform (`bdd/web/`, `bdd/app/`, `bdd/system/`):
55
55
  - **Lệnh BDD** (target là `.feature`): `{specs_dir}/{domain}/*/bdd/**/{UC-ID}*.feature` — hoặc `{specs_dir}/*/*/bdd/**/{UC-ID}*.feature` nếu domain cũng chưa biết. Nếu lệnh ngụ ý một platform/scope cụ thể (vd: system tech-doc cần BDD `system/`), ưu tiên kết quả trong thư mục con platform đó.
56
56
  - **Lệnh PRD** (target là file PRD `{TICKET-ID}-{prd-slug}.md` — file `.md` duy nhất ở gốc feature folder, cạnh `bdd/`): `{specs_dir}/{domain}/*/{TICKET-ID}*.md` nếu biết TICKET-ID; nếu không, `{specs_dir}/{domain}/*/*.md` (khớp feature folder có id tương ứng), hoặc `{specs_dir}/*/*/*.md` nếu domain cũng chưa biết. *(Glob `*/*.md` ở cấp gốc folder chỉ khớp PRD — tech-docs/design-spec `.md` nằm sâu hơn trong thư mục con.)*
57
- - **Lệnh tech-docs**: `{specs_dir}/{domain}/*/tech-docs/{UC-ID}*-tech-design*.md`.
57
+ - **Lệnh tech-docs** — target là tech-doc **gộp cấp PRD** `{TICKET-ID}-tech-design.md` (MỘT doc phủ nhiều UC; danh sách UC nằm ở `@trace.ucs`). Vì tên file mang `{TICKET-ID}` chứ **không** mang `{UC-ID}`, phải tách trước khi glob:
58
+ - `$ARGUMENTS` là **UC-ID** (`{TICKET-ID}-UC{N}`) → lấy `{TICKET-ID}` = phần **trước** `-UC`, rồi glob `{specs_dir}/{domain}/*/tech-docs/{TICKET-ID}-tech-design.md`.
59
+ - `$ARGUMENTS` là **TICKET-ID** → glob trực tiếp như trên.
60
+ - Chưa biết domain → `{specs_dir}/*/*/tech-docs/{TICKET-ID}-tech-design.md`.
61
+ - Vẫn không khớp → glob rộng `{specs_dir}/*/*/tech-docs/*tech-design*.md` rồi liệt kê để người dùng chọn.
62
+ *(Đừng glob `{UC-ID}*-tech-design*.md` — nó nở thành `FT-001-UC1*-tech-design*.md` và **không bao giờ** khớp `FT-001-tech-design.md`.)*
58
63
  - **Lệnh design-spec**: `{specs_dir}/{domain}/*/design-spec/{TICKET-ID}*.md`.
59
64
 
60
65
  Khi một file khớp: đặt nó làm target **và** ghi lại `domain` + `prd_slug` từ path của nó (theo quy tắc trích xuất trong `context-loader.md` Bước 1 — `prd_slug` = segment đầu tiên sau `{specs_dir}/{domain}/`). Mọi path mà lệnh đọc/ghi về sau (BDD/tech-docs/design-spec/trace cùng cấp) đều dùng **`prd_slug` đã phân giải đó**, nên tất cả artifact nằm chung một feature package. Nếu nhiều file khớp (vd: nhiều platform), chọn theo platform/scope của lệnh hoặc liệt kê ra và hỏi.
@@ -71,6 +71,7 @@ Gợi ý lệnh kế tiếp hợp lý theo phase của workflow:
71
71
  | /qc-run-test | `/qc-report {UC-ID}` rồi `/qc-review {UC-ID}` (review script) |
72
72
  | /qc-review (script) | `/qc-report {UC-ID}` rồi tạo PR nếu APPROVED |
73
73
  | /qc-report | `/validate-traces {UC-ID}` để làm mới Living Docs (qc_status) |
74
+ | /map-testids | `/qc-design-test {UC-ID}` (QC dựng Page Object từ contract §4.5.6 vừa ghi) |
74
75
  | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
75
76
  | /review-tech-docs | `/generate-code {feature-file}` nếu APPROVED; sửa doc nếu NEEDS_FIX |
76
77
  | /generate-code | Lần gen đầu → `/review-code {UC-ID}`; gen lại → `/dev-gen-test {UC-ID}` |
@@ -79,8 +80,8 @@ Gợi ý lệnh kế tiếp hợp lý theo phase của workflow:
79
80
  | /dev-run-test (failing) | `/fix-bug {ticket-id}` hoặc `/debug {error}` |
80
81
  | /review-code | `/dev-smoke-test {UC-ID}` hoặc tạo PR |
81
82
  | /dev-smoke-test | Tạo PR và link tới ticket |
82
- | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/dev-gen-test {UC-ID}`; tất cả OK tạo PR |
83
- | /fix-bug | Tạo PR link tới ticket |
83
+ | /validate-traces | **Cờ 🔴 trước (chặn PR):** SEAM_UNWIRED → nối binding sang class thật, xoá/thay stub · STUB_UNRESOLVED → `/generate-code {owner_uc}` (lấp logic tại chỗ + xoá hàm song song) · ORPHANED/TRACE_ORPHAN → quyết định thủ công (xoá code+test, đưa scenario trở lại `.feature`, hoặc sửa `sc_id` của tag). **Rồi:** DRIFT/UNTRACKED → `/generate-code {UC-ID}` · BDD_DRIFT → `/generate-code {feature-file}` · tech-doc lỗi thời vs BDD → `/generate-tech-docs` → `/review-tech-docs` · PRD drift → `/generate-bdd {prd-file}` · GAP → `/dev-gen-test {UC-ID}`. **Chỉ tạo PR khi mọi cờ 🔴 = 0** |
84
+ | /fix-bug | `/dev-run-test {UC-ID}` (dev_selftest vừa reset về not_run) → tạo PR; nếu fix một `{BUG-ID}` → QC chạy `/qc-run-test {UC-ID}` để verify + đóng bug |
84
85
  | /debug | `/fix-bug {ticket-id}` nếu cần sửa |
85
86
  | /report-bug | Gửi cho dev (`/fix-bug {BUG-ID}`); nếu thiếu coverage → `/propose-scenario {UC-ID}` |
86
87
  | /propose-scenario | Báo PO/Dev review proposal trong `feedback/bdd-proposals/` |
@@ -0,0 +1,47 @@
1
+ # templates/ — build-time skeletons
2
+
3
+ > **Nếu bạn đang mở thư mục này ở `.agent/templates/` trong một project: sửa file ở đây KHÔNG có tác dụng.**
4
+
5
+ ## Vì sao
6
+
7
+ Các skeleton trong thư mục này được `{{include}}` **nướng cứng vào file lệnh lúc `npm run build`**:
8
+
9
+ ```
10
+ templates/feature.template
11
+ ↓ {{include:templates/feature.template}} ← bin/build.js, thay thế văn bản lúc build
12
+ commands/generate-bdd.md
13
+ ↓ copy vào core/ → mirror sang .agent/
14
+ .agent/commands/generate-bdd.md ← LỆNH THẬT SỰ CHẠY (đã chứa sẵn skeleton)
15
+ .agent/templates/feature.template ← bản tham khảo, KHÔNG lệnh nào đọc
16
+ ```
17
+
18
+ Không lệnh nào đọc một path template lúc chạy. `paths.feature_template` / `paths.prd_template` từng tồn tại trong `project-context.yaml` nhưng chưa bao giờ có tác dụng — đã được gỡ bỏ (xem `GAPS.md` G9).
19
+
20
+ **Thêm nữa:** `.agent/` là vùng bị ghi đè. `/update-framework` chạy `npx … --init`, và `--init` copy `core/` → `.agent/` **vô điều kiện** (`bin/index.js` → `copyDirRecursive`, không có existence check, không backup). File duy nhất được giữ lại là `.agent/project-context.yaml`. Nên mọi chỉnh sửa ở `.agent/templates/` sẽ **biến mất im lặng** ở lần nâng cấp kế tiếp.
21
+
22
+ ## Muốn đổi cấu trúc artifact sinh ra thì làm gì
23
+
24
+ Sửa file trong **repo framework** rồi build lại:
25
+
26
+ ```bash
27
+ # trong repo sdd-framework
28
+ vim templates/feature.template # hoặc prd.template.md, tech-design.template.md, …
29
+ npm run build # inline lại vào commands/*.md + core/ + .agent/
30
+ ```
31
+
32
+ Rồi phát hành version mới; project chạy `/update-framework` để nhận.
33
+
34
+ ## File nào ở đây đi vào đâu
35
+
36
+ | Template | Được include vào | Trở thành |
37
+ |---|---|---|
38
+ | `feature.template` | `commands/generate-bdd.tmpl` | mỗi file `.feature` |
39
+ | `prd.template.md` | `commands/generate-prd.tmpl` | mỗi PRD |
40
+ | `tech-design.template.md` | `commands/generate-tech-docs.tmpl` | tech-doc gộp / PRD |
41
+ | `design-spec.template.md` | `commands/generate-design-spec.tmpl` | design-spec / platform |
42
+ | `architecture.template.md` | `commands/generate-architecture.tmpl` | tài liệu kiến trúc |
43
+ | `product-definition.template.md` | `commands/define-product.tmpl` | product definition |
44
+ | `platform-guide.template.md` | (tham khảo) | — |
45
+ | `project-context.yaml` | **không** include — được copy thẳng làm file config khởi tạo | `.agent/project-context.yaml` |
46
+
47
+ > Lưu ý `project-context.yaml` là ngoại lệ duy nhất: nó **được** copy ra làm file thật của project, và **được bảo vệ** khỏi ghi đè khi nâng cấp (chỉ tạo nếu chưa tồn tại).
@@ -1,9 +1,9 @@
1
1
  # ============================================================
2
2
  # @trace.id: {TICKET-ID}-UC{N}
3
3
  # @trace.title: <Feature name>
4
- # @trace.revision: 1 ← field tĩnh; dùng @trace.bdd_version để theo dõi version (tăng bởi /review-context --fix hoặc --resume)
4
+ # @trace.revision: 1 ← field tĩnh; version theo dõi bằng @trace.bdd_version
5
5
  # @trace.domain: <domain>
6
- # @trace.platform: {active_platform — web | app | system | (bỏ trong umbrella mode)}
6
+ # @trace.platform: {active_platform — web | app | system} ← BẮT BUỘC mọi mode; phải khớp segment bdd/{platform}/ của path
7
7
  # @trace.service: {active_service — bỏ trong spec repo mode}
8
8
  # @trace.module: {active_module trong umbrella mode; "unknown" trong spec repo mode}
9
9
  # @trace.status: draft
@@ -11,8 +11,8 @@
11
11
  # @trace.created_at: {YYYY-MM-DD}
12
12
  # @trace.prd: {TICKET-ID}
13
13
  # @trace.prd_version: {đọc từ metadata PRD "| **Version** |"}
14
- # @trace.bdd_version: {1.0 nếu gen mới; tăng 0.1 khi gen lại vd 1.0 1.1}
15
- # @trace.business_rules: {TICKET-ID}-UC{N}-BR1, {TICKET-ID}-UC{N}-BR2
14
+ # @trace.bdd_version: {cấp FILE — 1.0 nếu gen mới; tăng 0.1 khi gen lại. Khác @trace.sc_version (cấp từng SC) bên dưới}
15
+ # @trace.business_rules: {TICKET-ID}-UC{N}-BR{m}, {TICKET-ID}-UC{N}-BR{m+1} ← {m} lấy NGUYÊN từ PRD §3: BR đánh số LIÊN TỤC toàn PRD, KHÔNG reset theo UC
16
16
  # @trace.dataset: {domain}.testdata.yaml
17
17
  # ============================================================
18
18
 
@@ -59,8 +59,8 @@ Feature: <Feature name>
59
59
 
60
60
  # Side-effects: <liệt kê ngắn các Then side-effect cần verify>
61
61
  # @trace.scenario: {TICKET-ID}-UC{N}-SC1
62
- # @trace.sc_version: 1.0
63
- # @trace.business_rules: {TICKET-ID}-UC{N}-BR1
62
+ # @trace.sc_version: 1.0 ← cấp SCENARIO. Sửa thân SC này (tên/step/table/side-effect) thì +0.1, nếu không code cũ mãi hiện OK
63
+ # @trace.business_rules: {TICKET-ID}-UC{N}-BR{m}
64
64
  @happy
65
65
  Scenario: <mô tả business outcome — dùng động từ chính xác: create/receive/assign/block>
66
66
  Given <input state — alias từ dataset>
@@ -71,7 +71,7 @@ Feature: <Feature name>
71
71
  # Side-effects: <...>
72
72
  # @trace.scenario: {TICKET-ID}-UC{N}-SC2
73
73
  # @trace.sc_version: 1.0
74
- # @trace.business_rules: {TICKET-ID}-UC{N}-BR1
74
+ # @trace.business_rules: {TICKET-ID}-UC{N}-BR{m}
75
75
  @happy @alternative
76
76
  Scenario: <cùng theme NHÓM 1 nhưng path khác — vd: giá trị enum khác>
77
77
  Given <state>
@@ -85,7 +85,7 @@ Feature: <Feature name>
85
85
  # Side-effects: <...>
86
86
  # @trace.scenario: {TICKET-ID}-UC{N}-SC3
87
87
  # @trace.sc_version: 1.0
88
- # @trace.business_rules: {TICKET-ID}-UC{N}-BR2
88
+ # @trace.business_rules: {TICKET-ID}-UC{N}-BR{m+2}
89
89
  @edge
90
90
  Scenario: <scenario boundary / error>
91
91
  Given <state>
@@ -97,8 +97,8 @@ Feature: <Feature name>
97
97
  # AC1 (...) → SC1, SC2
98
98
  # AC2 (...) → SC3
99
99
  # BR mapping (mỗi bullet PHẢI có ≥1 SC — C.2):
100
- # {TICKET-ID}-UC{N}-BR1 (...) → SC1, SC2
101
- # {TICKET-ID}-UC{N}-BR2 (...) → SC3
100
+ # {TICKET-ID}-UC{N}-BR{m} (...) → SC1, SC2
101
+ # {TICKET-ID}-UC{N}-BR{m+2} (...) → SC3
102
102
  # Wireframe mapping (mỗi component/action ≥1 SC — C.1):
103
103
  # Screen "<screen name>":
104
104
  # [x] <action 1> → SC1
@@ -111,6 +111,9 @@ Feature: <Feature name>
111
111
 
112
112
  # === PRE-MERGE CHECKLIST ===
113
113
  # - [ ] Mỗi SC có Side-effects + @trace.scenario + @trace.sc_version + @trace.business_rules
114
+ # - [ ] SỬA nội dung một SC (tên / step / data table / side-effect) → đã bump @trace.sc_version của
115
+ # CHÍNH SC đó (+0.1). Quên bump = code sinh từ SC cũ vẫn hiện OK, không ai biết phải regen.
116
+ # (Đổi @trace.business_rules / tag / comment → KHÔNG bump: không đổi hành vi cần implement.)
114
117
  # - [ ] Coverage Matrix: 0 dòng MISSING (C.1)
115
118
  # - [ ] FE/App: mỗi Screen State (≠default) + AC-UI behavioral của design-spec có ≥1 SC (C.1 mở rộng)
116
119
  # - [ ] Mỗi AC/BR map tới ≥1 SC (C.2)