sdtk-spec-kit 0.4.5 → 0.4.7

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.
@@ -1,12 +1,12 @@
1
1
  {
2
- "version": "0.4.4",
3
- "sourceCommit": "unknown",
4
- "fileCount": 97,
2
+ "version": "0.4.7",
3
+ "sourceCommit": "f42cb6f6420371df8305f965b404d173ddb7bb78",
4
+ "fileCount": 98,
5
5
  "files": [
6
- {
7
- "path": "toolkit/AGENTS.md",
8
- "sha256": "336ba97d6702fdf32ffe33f2af3161c118a3b58bf0cee6a5f8859262d4ef12b0",
9
- "size": 14830
6
+ {
7
+ "path": "toolkit/AGENTS.md",
8
+ "sha256": "336ba97d6702fdf32ffe33f2af3161c118a3b58bf0cee6a5f8859262d4ef12b0",
9
+ "size": 14830
10
10
  },
11
11
  {
12
12
  "path": "toolkit/install.ps1",
@@ -18,15 +18,15 @@
18
18
  "sha256": "74c20ab8c3f514c5c6fa8f9e09114e22458e5c2540a83ff1771f9258b6a71a37",
19
19
  "size": 3535
20
20
  },
21
- {
22
- "path": "toolkit/runtimes/claude/CLAUDE_TEMPLATE.md",
23
- "sha256": "6c1aa50cae9752c982c2ad2086d2b8c592a3aaab346323253f8e0b2598b73d03",
24
- "size": 4686
21
+ {
22
+ "path": "toolkit/runtimes/claude/CLAUDE_TEMPLATE.md",
23
+ "sha256": "6c1aa50cae9752c982c2ad2086d2b8c592a3aaab346323253f8e0b2598b73d03",
24
+ "size": 4686
25
25
  },
26
- {
27
- "path": "toolkit/runtimes/codex/CODEX_TEMPLATE.md",
28
- "sha256": "d77de12c4fbce75526614994a5a9ee640581392616811cbf4f430e6094c5b392",
29
- "size": 3477
26
+ {
27
+ "path": "toolkit/runtimes/codex/CODEX_TEMPLATE.md",
28
+ "sha256": "d77de12c4fbce75526614994a5a9ee640581392616811cbf4f430e6094c5b392",
29
+ "size": 3477
30
30
  },
31
31
  {
32
32
  "path": "toolkit/scripts/agents/run-claude-task.ps1",
@@ -55,8 +55,8 @@
55
55
  },
56
56
  {
57
57
  "path": "toolkit/scripts/install-claude-skills.ps1",
58
- "sha256": "1bac6da7f9487c2a112171d9dced50b487e4ed148c5471efc8e3b25bfda68142",
59
- "size": 6253
58
+ "sha256": "ec9bacff547379b04b745371efaab0e4befbed8e38ffc83fcedb763c48bc3f5e",
59
+ "size": 6333
60
60
  },
61
61
  {
62
62
  "path": "toolkit/scripts/install-codex-skills.ps1",
@@ -73,10 +73,10 @@
73
73
  "sha256": "e1fc41f583208c477865d58ed8f548ffe2eba0bb69f06b9318afcf9a88aca971",
74
74
  "size": 4538
75
75
  },
76
- {
77
- "path": "toolkit/SDTK_TOOLKIT.md",
78
- "sha256": "6da7504b1912e05c32110fe5718954c113dd0bbbfa5cb630d18846ae04655bf8",
79
- "size": 9484
76
+ {
77
+ "path": "toolkit/SDTK_TOOLKIT.md",
78
+ "sha256": "6da7504b1912e05c32110fe5718954c113dd0bbbfa5cb630d18846ae04655bf8",
79
+ "size": 9484
80
80
  },
81
81
  {
82
82
  "path": "toolkit/sdtk-spec.config.json",
@@ -88,15 +88,15 @@
88
88
  "sha256": "e6d29627c079dd8929626bceed4bb77eee08963ed6e972ea6afae2f4038c236e",
89
89
  "size": 1545
90
90
  },
91
- {
92
- "path": "toolkit/session/SDTK_ACTIVE_BOOTSTRAP.md",
93
- "sha256": "e757102c21d527ce0f041dd917032363f6759525a772d4a37d1dbf4bee85c10d",
94
- "size": 2582
91
+ {
92
+ "path": "toolkit/session/SDTK_ACTIVE_BOOTSTRAP.md",
93
+ "sha256": "e757102c21d527ce0f041dd917032363f6759525a772d4a37d1dbf4bee85c10d",
94
+ "size": 2582
95
95
  },
96
- {
97
- "path": "toolkit/session/SDTK_AGENT_WORKING_RULES.md",
98
- "sha256": "e7c53dda29fed75233f320e36004dce4a955a0356f34d69c358b58c3100d79fc",
99
- "size": 2186
96
+ {
97
+ "path": "toolkit/session/SDTK_AGENT_WORKING_RULES.md",
98
+ "sha256": "e7c53dda29fed75233f320e36004dce4a955a0356f34d69c358b58c3100d79fc",
99
+ "size": 2186
100
100
  },
101
101
  {
102
102
  "path": "toolkit/skills/sdtk-api-design-spec/scripts/generate_api_design_detail.py",
@@ -183,6 +183,11 @@
183
183
  "sha256": "9e41a944a73c6960c8aa24d8930e64c1ed699ed8b410a587b042186e2d450e6e",
184
184
  "size": 6461
185
185
  },
186
+ {
187
+ "path": "toolkit/skills/sdtk-screen-design-spec/references/commerce-profile-screens.md",
188
+ "sha256": "0702605f4c3a42cd06eb35ef61ca4b64f928c6b89dfb1204bcc978fb3ce033f9",
189
+ "size": 5762
190
+ },
186
191
  {
187
192
  "path": "toolkit/skills/sdtk-screen-design-spec/references/excel-image-export.md",
188
193
  "sha256": "9ef61485c011dd69a6efcd9a5b708bd7acd850dd1c905d3dc162c9b5c19d1e94",
@@ -210,8 +215,8 @@
210
215
  },
211
216
  {
212
217
  "path": "toolkit/skills/sdtk-screen-design-spec/SKILL.md",
213
- "sha256": "77b74f09934ab6b44fb5943b0ce51e027a84d718ec550019f3bd63b26e5c7369",
214
- "size": 7602
218
+ "sha256": "e9a7fc9468a73be6f45b1699bbc4034c8a7fb13101ed1543ab9887a50f203921",
219
+ "size": 8216
215
220
  },
216
221
  {
217
222
  "path": "toolkit/skills/sdtk-test-case-spec/scripts/validate_test_case_spec.py",
@@ -489,4 +494,4 @@
489
494
  "size": 3443
490
495
  }
491
496
  ]
492
- }
497
+ }
@@ -8,7 +8,7 @@ d77de12c4fbce75526614994a5a9ee640581392616811cbf4f430e6094c5b392 toolkit/runtim
8
8
  40d0ffc646d6f4e85034adb9c7cc5090abb31fe59d3c3a27441fb72be55a342d toolkit/scripts/agents/validate-mailbox-formal-artifact.py
9
9
  48bc3d8b1942e1e3499d8933a97e1c8f9bcb201e7c4d801afa3f04159113bdee toolkit/scripts/generate-code-handoff.ps1
10
10
  3f281d25793ada92fe310409c9e87f105be43f16a56f21313aef73cb8505406d toolkit/scripts/init-feature.ps1
11
- 1bac6da7f9487c2a112171d9dced50b487e4ed148c5471efc8e3b25bfda68142 toolkit/scripts/install-claude-skills.ps1
11
+ ec9bacff547379b04b745371efaab0e4befbed8e38ffc83fcedb763c48bc3f5e toolkit/scripts/install-claude-skills.ps1
12
12
  941ffa9933b8ab34819d3cfb8babb45a83d9b2ae76f34c423dc2117251dbd87c toolkit/scripts/install-codex-skills.ps1
13
13
  809ffc1f96528ac1cd453214cd1c2d231ca0753f0d3c19b4a20f11835a64a152 toolkit/scripts/uninstall-claude-skills.ps1
14
14
  e1fc41f583208c477865d58ed8f548ffe2eba0bb69f06b9318afcf9a88aca971 toolkit/scripts/uninstall-codex-skills.ps1
@@ -34,12 +34,13 @@ f7107fdc3b181379fa8ea1d67edc6e5aac8cb575fcae5bd0bca1003daf5bea35 toolkit/skills
34
34
  6a4ee5d6e19025dfd30a1a090468198720345e749378956284d85ac9aa73e40d toolkit/skills/sdtk-orchestrator/SKILL.md
35
35
  90d3c9d8bb2bb3b28e81bc10c6b1799236250dfcb2ebed43eb161c78ff00a084 toolkit/skills/sdtk-pm/SKILL.md
36
36
  9e41a944a73c6960c8aa24d8930e64c1ed699ed8b410a587b042186e2d450e6e toolkit/skills/sdtk-qa/SKILL.md
37
+ 0702605f4c3a42cd06eb35ef61ca4b64f928c6b89dfb1204bcc978fb3ce033f9 toolkit/skills/sdtk-screen-design-spec/references/commerce-profile-screens.md
37
38
  9ef61485c011dd69a6efcd9a5b708bd7acd850dd1c905d3dc162c9b5c19d1e94 toolkit/skills/sdtk-screen-design-spec/references/excel-image-export.md
38
39
  04f5e38d04d6ba69429504cee13ef095ba8234c60a0e2e446bf396d68429f37b toolkit/skills/sdtk-screen-design-spec/references/figma-mcp.md
39
40
  920b203c82ce549e49f1beaa182d26a277883a0bf4e015147265489a246f092c toolkit/skills/sdtk-screen-design-spec/references/numbering-rules.md
40
41
  b54b14cc75c02c3fe9f89547b3f09baf1d7d036ef5f3d9f40487516e22351c45 toolkit/skills/sdtk-screen-design-spec/scripts/renumber_flow_action_spec_global.py
41
42
  8567db6e007df8927edf748fb4175618a8712c4c5b48b9c890c22dddb983b369 toolkit/skills/sdtk-screen-design-spec/scripts/validate_flow_action_spec_numbering.py
42
- 77b74f09934ab6b44fb5943b0ce51e027a84d718ec550019f3bd63b26e5c7369 toolkit/skills/sdtk-screen-design-spec/SKILL.md
43
+ e9a7fc9468a73be6f45b1699bbc4034c8a7fb13101ed1543ab9887a50f203921 toolkit/skills/sdtk-screen-design-spec/SKILL.md
43
44
  b9f512159d7a6dc98e55587d2d8e739ebe15330dfcb54488447ba75bfbb3d0f3 toolkit/skills/sdtk-test-case-spec/scripts/validate_test_case_spec.py
44
45
  00581e372b6a639afbf7d333c0c404d6f1b363ad1089d6ca3805258da4faea58 toolkit/skills/sdtk-test-case-spec/SKILL.md
45
46
  d28e9b020ad7beebc08e17b48134208ea0814e737e1d78104ee65dca6e084b84 toolkit/skills/skills.catalog.yaml
@@ -94,4 +95,4 @@ b67ae168d02764bf189306d58a7971d93a8a9538bcbec0ea8b5ff5ccc891e481 toolkit/templa
94
95
  c05cbd1815650a544dd6b3fe98cfaa900caab2f7ab989eba498120b11e47ae39 toolkit/templates/mailbox/AGENT_TASK_TEMPLATE.md
95
96
  205dafaed01e5841d3c6870a093d08ba4ce58a9bbfc716a506f0951149e2dcf9 toolkit/templates/QUALITY_CHECKLIST.md
96
97
  99d6ef1bccec4162b9c8cd75e20378338f3485d2bbeed996eee9bcddf22dc8a7 toolkit/templates/README.md
97
- b756c866fe7e76d1f4003871d80abe491d0283e0c95205121e6f91fbd8b02471 toolkit/templates/SHARED_PLANNING.md
98
+ b756c866fe7e76d1f4003871d80abe491d0283e0c95205121e6f91fbd8b02471 toolkit/templates/SHARED_PLANNING.md
@@ -56,7 +56,8 @@ function Get-ClaudeManagedReferenceSources {
56
56
  'templates/docs/specs/FLOW_ACTION_SPEC_CREATION_RULES.md',
57
57
  'skills/sdtk-screen-design-spec/references/numbering-rules.md',
58
58
  'skills/sdtk-screen-design-spec/references/figma-mcp.md',
59
- 'skills/sdtk-screen-design-spec/references/excel-image-export.md'
59
+ 'skills/sdtk-screen-design-spec/references/excel-image-export.md',
60
+ 'skills/sdtk-screen-design-spec/references/commerce-profile-screens.md'
60
61
  ) }
61
62
  'test-case-spec' { return @(
62
63
  'templates/docs/qa/TEST_CASE_CREATION_RULES.md'
@@ -166,7 +167,7 @@ foreach ($skillName in @('arch', 'api-doc', 'api-design-spec', 'screen-design-sp
166
167
 
167
168
  # Strict count assertions
168
169
  $expectedSkills = 14
169
- $expectedManagedRefs = 11
170
+ $expectedManagedRefs = 12
170
171
  if ($skillCount -ne $expectedSkills) {
171
172
  throw "Claude install failed. Expected $expectedSkills skills but installed $skillCount."
172
173
  }
@@ -38,7 +38,7 @@ description: Create/update screen flow-action specifications from requirement so
38
38
  - Escalate to `@arch` if API assignment for a screen is architecturally ambiguous.
39
39
 
40
40
  ## Core Process
41
- 1. Read requirement sources and identify in-scope screens, dialogs, and transitions.
41
+ 1. Read requirement sources and identify in-scope screens, dialogs, and transitions. If feature is commerce-domain (feature key matches `cart|checkout|order|account|commerce|ecommerce|ec|shop|store|catalog|b2b-commerce|b2c|retail` OR user explicitly declares commerce intent), consult `references/commerce-profile-screens.md` as a CHECKLIST for canonical sections per screen type. Sections not applicable to the feature may be omitted with a justification note.
42
42
  2. Read and apply rules from `toolkit/templates/docs/specs/FLOW_ACTION_SPEC_CREATION_RULES.md`.
43
43
  3. Determine design source mode per screen:
44
44
  - If Figma URL or screenshot exists: use `source-backed`.
@@ -65,6 +65,7 @@ description: Create/update screen flow-action specifications from requirement so
65
65
  - Every UI-scope screen declares a Design Source Type (`source-backed` or `generated-draft`).
66
66
  - Every generated-draft screen with an embedded wireframe image includes a wireframe-marker mapping table to the global action-table `No`.
67
67
  - Run `validate_flow_action_spec_numbering.py` before finalizing.
68
+ - For commerce-domain features: every declared screen aligns with the canonical sections in `references/commerce-profile-screens.md`; any deliberate omission documented inline (e.g. "address-book omitted — single-address B2B model").
68
69
 
69
70
  ## Order-Critical Hard Gate
70
71
  Do not finalize any screen section before applying `toolkit/templates/docs/specs/FLOW_ACTION_SPEC_CREATION_RULES.md`. The rules define mandatory section structure; skipping them produces incomplete specs that will fail ARCH/DEV review.
@@ -0,0 +1,183 @@
1
+ # Commerce Profile Screen Reference
2
+
3
+ ## Purpose
4
+
5
+ Canonical sections + interactive density guidance for commerce-domain screens. Consult this reference when generating SCREEN_DESIGN_SPEC for commerce features so the SPEC output is structurally rich enough for downstream design and render flows.
6
+
7
+ This reference describes PATTERNS, not VALUES. No brand colors, copy, screen ids, route paths, or project-specific examples appear here.
8
+
9
+ ## Detection rule
10
+
11
+ Consult this reference when:
12
+ - Feature key matches keywords: `cart`, `checkout`, `order`, `account`, `commerce`, `ecommerce`, `ec`, `shop`, `store`, `catalog`, `b2b-commerce`, `b2c`, `retail`.
13
+ - OR user explicitly declares commerce intent in the requirement.
14
+
15
+ Out of commerce domain → reference does NOT apply.
16
+
17
+ ## Canonical screen types
18
+
19
+ ### 1. Home (commerce homepage)
20
+
21
+ Canonical sections:
22
+ - header (site nav, search-bar, cart/account utility)
23
+ - hero (primary value prop)
24
+ - category-grid (4+ entries — drives category nav interactive count)
25
+ - featured-products (4+ product cards)
26
+ - secondary CTA or domain-specific entry (e.g. configurator entry for B2B)
27
+ - footer (links to contact, privacy, terms)
28
+
29
+ Interactive density:
30
+ - header nav (5–8 links)
31
+ - category-grid (4+ anchors)
32
+ - featured-products (4+ anchors)
33
+
34
+ ### 2. Category (catalog listing)
35
+
36
+ Canonical sections:
37
+ - header + breadcrumb
38
+ - filter-sidebar (multi-select, price range, brand)
39
+ - sort-bar
40
+ - product-grid (12+ cards in real layout; SPEC declares 4+ sample cards)
41
+ - pagination
42
+
43
+ Interactive density:
44
+ - filter checkboxes (5+)
45
+ - product cards (4+ anchors)
46
+ - pagination (3+ links)
47
+
48
+ ### 3. Product Detail (PDP)
49
+
50
+ Canonical sections:
51
+ - header + breadcrumb
52
+ - image-gallery (4+ thumbnail anchors + main image)
53
+ - product title + price
54
+ - spec table (technical specs)
55
+ - add-to-cart + quantity selector
56
+ - tab section (description, reviews, shipping, returns)
57
+ - related-products grid (4+ cards)
58
+
59
+ Interactive density:
60
+ - image-gallery (4+ anchors)
61
+ - tab buttons (3–4)
62
+ - related-products (4+ anchors)
63
+ - spec-download or compare anchors (1–2)
64
+
65
+ ### 4. Search (results)
66
+
67
+ Canonical sections:
68
+ - header (with prominent search-bar)
69
+ - filter-panel
70
+ - sort-bar
71
+ - results-grid (dense)
72
+ - no-results state (alternative)
73
+ - pagination
74
+
75
+ Interactive density: matches category screen.
76
+
77
+ ### 5. Cart
78
+
79
+ Canonical sections:
80
+ - header
81
+ - cart-items-table (multiple rows; each row has qty selector + remove anchor)
82
+ - promo / coupon section (input + apply button) — distinguishes commerce cart from a generic list
83
+ - cart-summary (subtotal, tax, total)
84
+ - recommended-products (4+ cards)
85
+ - checkout CTA + continue-shopping link
86
+
87
+ Interactive density:
88
+ - per-row qty + remove (2 actions × N rows)
89
+ - promo input + apply
90
+ - recommended cards (4+ anchors)
91
+
92
+ ### 6. Checkout
93
+
94
+ Canonical sections:
95
+ - header (minimal — focus on checkout flow)
96
+ - progress stepper (3–5 steps)
97
+ - shipping-address form (with postcode lookup + address autocomplete) — dense form
98
+ - billing-address form (with same-as-shipping option)
99
+ - payment-method (multiple options: card, bank transfer, COD for B2B)
100
+ - order-review (items list, totals)
101
+ - place-order CTA
102
+
103
+ Interactive density:
104
+ - form fields (15–25 inputs / selects across address + payment)
105
+ - step navigation links
106
+ - multiple payment radio options
107
+ - item review (3–5 line items)
108
+
109
+ ### 7. Order History
110
+
111
+ Canonical sections:
112
+ - header + sidebar-account-nav
113
+ - filter bar (date range, status)
114
+ - order-list with per-row actions: detail link, reorder link, invoice download, tracking link
115
+ - pagination
116
+
117
+ Interactive density:
118
+ - filter inputs (3–5)
119
+ - order rows × per-row 3–4 actions (12–20 anchors total)
120
+ - pagination links
121
+
122
+ ### 8. Order Detail
123
+
124
+ Canonical sections:
125
+ - header + sidebar-account-nav
126
+ - order-meta-header (order id, date, status)
127
+ - order-items (multiple rows)
128
+ - order-totals
129
+ - shipping-info
130
+ - payment-info
131
+ - actions (reorder, support-contact, invoice-download, return-request)
132
+
133
+ Interactive density:
134
+ - action set (4–5 anchors)
135
+ - item rows with detail links (3+ rows)
136
+
137
+ ### 9. Account Info (profile + address book)
138
+
139
+ Canonical sections:
140
+ - header + sidebar-account-nav
141
+ - profile form (name, email — display + edit)
142
+ - email change form (inline or modal)
143
+ - password change form (inline or modal)
144
+ - address-book section (multi-address list; each address with edit + delete + set-default anchors)
145
+ - preferences (notifications, language)
146
+
147
+ Interactive density:
148
+ - form fields (5–10)
149
+ - address-book entries (3+ addresses × 3 actions each = 9+ anchors)
150
+ - preference toggles
151
+
152
+ ### 10. Mode-B Configurator (B2B industrial-commerce; OPTIONAL — applies only when feature scope includes a configurator)
153
+
154
+ Canonical sections:
155
+ - header
156
+ - wizard steps
157
+ - configuration form (multi-field input)
158
+ - preview panel
159
+ - BOM (bill of materials) table
160
+ - exclude / recalculate actions
161
+ - save / order CTAs
162
+
163
+ Interactive density:
164
+ - form fields (10–20)
165
+ - preview interactions
166
+ - BOM rows with toggles (5+ rows × 2–3 actions)
167
+ - action buttons (3–4)
168
+
169
+ ## Common variants (B2B vs B2C)
170
+
171
+ - B2B carts often include quote-request and order-by-PO-number sections.
172
+ - B2B account pages typically include team-management (additional users) and purchasing-roles.
173
+ - B2C product pages prioritise reviews and social-proof; B2B prioritises spec tables and technical-data.
174
+ - B2B checkout typically supports purchase-order payment; B2C is card-first.
175
+
176
+ These variants are guidance — match feature requirements.
177
+
178
+ ## Boundary
179
+
180
+ - This reference describes PATTERNS, not VALUES.
181
+ - It contains no brand names, brand colors, hex codes, exact copy, screen ids, route paths, product SKUs, or any project-specific examples.
182
+ - It contains no references to any specific reference layout, sample export, or customer artefact.
183
+ - Patterns above are derived from general commerce-domain conventions only.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdtk-spec-kit",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "SDTK-SPEC CLI toolkit for deterministic software documentation workflows via the sdtk-spec command",
5
5
  "bin": {
6
6
  "sdtk-spec": "bin/sdtk.js"
@@ -252,7 +252,7 @@ function cmdHelp() {
252
252
  " sdtk-spec auth --verify",
253
253
  ' sdtk-spec generate --feature-key USER_PROFILE --feature-name "User Profile"',
254
254
  " sdtk-spec generate --feature-key ORDER_MGMT --feature-name \"Order Management\" --validate-only",
255
- " sdtk-spec analyze --source ./requirements.md --feature-key ESTEAM_EC --feature-name \"Esteam E-Commerce\"",
255
+ " sdtk-spec analyze --source ./requirements.md --feature-key ORDER_PORTAL --feature-name \"Order Portal\"",
256
256
  " sdtk-spec init --runtime claude --runtime-scope user",
257
257
  " sdtk-spec runtime install --runtime claude --scope project",
258
258
  " sdtk-spec runtime install --runtime codex --scope user",
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ const PROVENANCE_VIOLATION = "PROVENANCE_VIOLATION";
7
+ const MIN_SOURCE_QUOTE_CODE_POINTS = 30;
8
+
9
+ function stripUtf8Bom(text) {
10
+ return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
11
+ }
12
+
13
+ function normalizeNewlines(text) {
14
+ return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
15
+ }
16
+
17
+ function readSourceText(sourcePath) {
18
+ return normalizeNewlines(stripUtf8Bom(fs.readFileSync(sourcePath, "utf8")));
19
+ }
20
+
21
+ function codePointLength(value) {
22
+ return Array.from(value).length;
23
+ }
24
+
25
+ function normalizedSampleName(value) {
26
+ return String(value || "")
27
+ .replace(/\.[^.\\/]+$/u, "")
28
+ .normalize("NFD")
29
+ .replace(/[\u0300-\u036f]/g, "")
30
+ .toLowerCase()
31
+ .replace(/[^a-z0-9]+/g, "")
32
+ .trim();
33
+ }
34
+
35
+ function extractScreens(handoff) {
36
+ if (!handoff || typeof handoff !== "object") {
37
+ return [];
38
+ }
39
+ if (Array.isArray(handoff.screens)) {
40
+ return handoff.screens;
41
+ }
42
+ if (Array.isArray(handoff.screen_inventory)) {
43
+ return handoff.screen_inventory;
44
+ }
45
+ if (handoff.handoff && Array.isArray(handoff.handoff.screens)) {
46
+ return handoff.handoff.screens;
47
+ }
48
+ if (handoff.design && Array.isArray(handoff.design.screens)) {
49
+ return handoff.design.screens;
50
+ }
51
+ return [];
52
+ }
53
+
54
+ function addViolation(violations, screenRef, field, message) {
55
+ violations.push({
56
+ code: PROVENANCE_VIOLATION,
57
+ screen: screenRef,
58
+ field,
59
+ message,
60
+ });
61
+ }
62
+
63
+ function validateLineRange(sourceLines, quote, lineRange) {
64
+ if (!Array.isArray(lineRange) || lineRange.length !== 2) {
65
+ return "source_line_range must be [start_line, end_line].";
66
+ }
67
+
68
+ const [startLine, endLine] = lineRange;
69
+ if (!Number.isInteger(startLine) || !Number.isInteger(endLine)) {
70
+ return "source_line_range values must be integers.";
71
+ }
72
+ if (startLine < 1 || endLine < 1 || startLine > endLine || endLine > sourceLines.length) {
73
+ return `source_line_range must be within source bounds 1..${sourceLines.length}.`;
74
+ }
75
+
76
+ const selectedText = sourceLines.slice(startLine - 1, endLine).join("\n");
77
+ if (!selectedText.includes(quote)) {
78
+ return "source_quote must appear within the declared source_line_range.";
79
+ }
80
+ return null;
81
+ }
82
+
83
+ function validateDesignHandoffProvenance(options) {
84
+ const handoffPath = options && options.handoffPath;
85
+ const sourcePath = options && options.sourcePath;
86
+ const sampleNames = options && Array.isArray(options.sampleNames) ? options.sampleNames : [];
87
+
88
+ const violations = [];
89
+ if (!handoffPath || !fs.existsSync(handoffPath)) {
90
+ addViolation(violations, "(handoff)", "handoffPath", `Handoff JSON does not exist: ${handoffPath || ""}`);
91
+ return { ok: false, code: PROVENANCE_VIOLATION, violations };
92
+ }
93
+ if (!sourcePath || !fs.existsSync(sourcePath)) {
94
+ addViolation(violations, "(source)", "sourcePath", `Requirement source does not exist: ${sourcePath || ""}`);
95
+ return { ok: false, code: PROVENANCE_VIOLATION, violations };
96
+ }
97
+
98
+ let handoff;
99
+ try {
100
+ handoff = JSON.parse(fs.readFileSync(handoffPath, "utf8"));
101
+ } catch (error) {
102
+ addViolation(violations, "(handoff)", "json", `Handoff JSON is invalid: ${error.message}`);
103
+ return { ok: false, code: PROVENANCE_VIOLATION, violations };
104
+ }
105
+
106
+ const sourceText = readSourceText(sourcePath);
107
+ const sourceLines = sourceText.split("\n");
108
+ const screens = extractScreens(handoff);
109
+ const normalizedSamples = new Set(sampleNames.map(normalizedSampleName).filter(Boolean));
110
+
111
+ if (screens.length === 0) {
112
+ addViolation(violations, "(handoff)", "screens", "Handoff must include at least one screen.");
113
+ }
114
+
115
+ screens.forEach((screen, index) => {
116
+ const screenRef = screen && (screen.id || screen.title) ? screen.id || screen.title : `screens[${index}]`;
117
+ const id = screen && typeof screen.id === "string" ? screen.id.trim() : "";
118
+ const title = screen && typeof screen.title === "string" ? screen.title.trim() : "";
119
+ const quote = screen && typeof screen.source_quote === "string" ? normalizeNewlines(screen.source_quote) : "";
120
+ const lineRange = screen && screen.source_line_range;
121
+
122
+ if (!id) {
123
+ addViolation(violations, screenRef, "id", "Screen id is required.");
124
+ }
125
+ if (!title) {
126
+ addViolation(violations, screenRef, "title", "Screen title is required.");
127
+ }
128
+ if (!quote) {
129
+ addViolation(violations, screenRef, "source_quote", "source_quote is required.");
130
+ } else {
131
+ if (codePointLength(quote) < MIN_SOURCE_QUOTE_CODE_POINTS) {
132
+ addViolation(
133
+ violations,
134
+ screenRef,
135
+ "source_quote",
136
+ `source_quote must be at least ${MIN_SOURCE_QUOTE_CODE_POINTS} Unicode code points.`
137
+ );
138
+ }
139
+ if (!sourceText.includes(quote)) {
140
+ addViolation(violations, screenRef, "source_quote", "source_quote must exist literally in the requirement source.");
141
+ }
142
+ const lineRangeError = validateLineRange(sourceLines, quote, lineRange);
143
+ if (lineRangeError) {
144
+ addViolation(violations, screenRef, "source_line_range", lineRangeError);
145
+ }
146
+ }
147
+
148
+ for (const candidate of [id, title]) {
149
+ const normalized = normalizedSampleName(candidate);
150
+ if (normalized && normalizedSamples.has(normalized)) {
151
+ addViolation(
152
+ violations,
153
+ screenRef,
154
+ "title",
155
+ "Screen id/title matches an explicit sample filename/name supplied for post-generation evaluation."
156
+ );
157
+ }
158
+ }
159
+ });
160
+
161
+ return {
162
+ ok: violations.length === 0,
163
+ code: violations.length === 0 ? "OK" : PROVENANCE_VIOLATION,
164
+ handoffPath: path.resolve(handoffPath),
165
+ sourcePath: path.resolve(sourcePath),
166
+ screenCount: screens.length,
167
+ violations,
168
+ };
169
+ }
170
+
171
+ function assertValidDesignHandoffProvenance(options) {
172
+ const result = validateDesignHandoffProvenance(options);
173
+ if (!result.ok) {
174
+ const details = result.violations.map((item) => `${item.screen} ${item.field}: ${item.message}`).join("; ");
175
+ const error = new Error(`${PROVENANCE_VIOLATION}: ${details}`);
176
+ error.code = PROVENANCE_VIOLATION;
177
+ error.result = result;
178
+ throw error;
179
+ }
180
+ return result;
181
+ }
182
+
183
+ module.exports = {
184
+ PROVENANCE_VIOLATION,
185
+ MIN_SOURCE_QUOTE_CODE_POINTS,
186
+ validateDesignHandoffProvenance,
187
+ assertValidDesignHandoffProvenance,
188
+ normalizedSampleName,
189
+ };
@@ -20,6 +20,15 @@ const FLAG_DEFS = {
20
20
  };
21
21
 
22
22
  const ANALYSIS_STATUS = "SOURCE_INTAKE_READY_FOR_AGENT_ANALYSIS";
23
+ const DESIGN_HANDOFF_ARTIFACTS = [
24
+ "docs/design/SCREEN_INVENTORY_<KEY>.md",
25
+ "docs/design/SCREEN_INVENTORY_<KEY>.json",
26
+ "docs/design/USER_FLOWS_<KEY>.md",
27
+ "docs/design/USER_FLOWS_<KEY>.json",
28
+ "docs/specs/DOMAIN_MODEL_<KEY>.md",
29
+ "docs/specs/DOMAIN_MODEL_<KEY>.json",
30
+ "docs/design/SPEC_TO_DESIGN_HANDOFF_<KEY>.json",
31
+ ];
23
32
 
24
33
  const MOJIBAKE_MARKERS = [
25
34
  "テ",
@@ -155,9 +164,59 @@ function taskHeader(featureKey, featureName, sourceInfo) {
155
164
  `Feature name: ${featureName}`,
156
165
  `Preserved source: ${sourceInfo.preservedCopyRelativePath}`,
157
166
  `Source SHA-256: ${sourceInfo.sha256}`,
167
+ "Inputs allowed: requirements/**. Forbidden: docs/ui/**",
158
168
  ].join("\n");
159
169
  }
160
170
 
171
+ function artifactListForFeature(featureKey) {
172
+ return DESIGN_HANDOFF_ARTIFACTS.map((item) => item.replace("<KEY>", featureKey));
173
+ }
174
+
175
+ function buildInputBoundarySection() {
176
+ return [
177
+ "## Input Boundary",
178
+ "",
179
+ "Inputs allowed: requirements/**. Forbidden: docs/ui/**",
180
+ "",
181
+ "- Allowed before handoff completion: requirement source files, the preserved `.sdtk/spec/requirements/sources/**` copy, and generated SPEC scaffold artifacts under `docs/**`.",
182
+ "- Forbidden before handoff completion: `docs/ui/**`, reference sample HTML/PNG exports, copied sample layouts, and visual benchmark outputs.",
183
+ "- `docs/ui/**` is evaluation-only after SDTK output generation/handoff; it must not be used as a generation input.",
184
+ "- If worker history shows reads under `docs/ui/**` before `SPEC_TO_DESIGN_HANDOFF` is complete, the lane validator must report `PROVENANCE_VIOLATION`.",
185
+ "",
186
+ ];
187
+ }
188
+
189
+ function buildRequiredDesignHandoffSection(featureKey) {
190
+ return [
191
+ "## Required Design Handoff Artifacts",
192
+ "",
193
+ ...artifactListForFeature(featureKey).map((item) => `- \`${item}\``),
194
+ "",
195
+ ];
196
+ }
197
+
198
+ function buildProvenanceContractSection(featureKey) {
199
+ return [
200
+ "## SPEC To DESIGN Provenance Contract",
201
+ "",
202
+ `Every screen in \`docs/design/SPEC_TO_DESIGN_HANDOFF_${featureKey}.json\` must include:`,
203
+ "",
204
+ "- `id`",
205
+ "- `title`",
206
+ "- `source_quote`: at least 30 Unicode code points copied literally from the requirement source",
207
+ "- `source_line_range`: `[start_line, end_line]` using 1-based source line numbers",
208
+ "",
209
+ "Deterministic verifier requirements:",
210
+ "",
211
+ "- `source_quote` must exist literally in the requirement source after UTF-8 BOM stripping and CRLF-to-LF newline normalization.",
212
+ "- `source_line_range` must be inside the source file bounds and must contain the quoted text.",
213
+ "- Screen `id` and `title` must not match an explicit post-generation sample filename/name list supplied to the verifier.",
214
+ "- Missing screens, malformed JSON, missing fields, invalid ranges, or copied sample-derived names must fail as `PROVENANCE_VIOLATION`.",
215
+ "- Runtime must not infer screens, fields, routes, palette, or ecommerce semantics from the raw requirement text.",
216
+ "",
217
+ ];
218
+ }
219
+
161
220
  function buildTaskPacketFiles(featureKey, featureName, sourceInfo) {
162
221
  const header = taskHeader(featureKey, featureName, sourceInfo);
163
222
  return {
@@ -170,6 +229,9 @@ function buildTaskPacketFiles(featureKey, featureName, sourceInfo) {
170
229
  "",
171
230
  "This packet routes source analysis to the SDTK-SPEC agent pipeline. Runtime `analyze` preserved the source and bootstrapped the standard 17-file scaffold; agents now perform the actual PM/BA/ARCH/DEV/QA analysis.",
172
231
  "",
232
+ ...buildInputBoundarySection(),
233
+ ...buildRequiredDesignHandoffSection(featureKey),
234
+ ...buildProvenanceContractSection(featureKey),
173
235
  "## Required Agent Sequence",
174
236
  "",
175
237
  "1. PM/BA: read the preserved source and `docs/discovery/REQUIREMENT_<KEY>.md`.",
@@ -181,6 +243,7 @@ function buildTaskPacketFiles(featureKey, featureName, sourceInfo) {
181
243
  "## Guardrails",
182
244
  "",
183
245
  "- Do not invent screens, fields, APIs, data models, visual constraints, or acceptance criteria without source evidence or user confirmation.",
246
+ "- Do not read `docs/ui/**` or sample layout exports before `SPEC_TO_DESIGN_HANDOFF` is complete.",
184
247
  "- Cite source lines or sections where possible.",
185
248
  "- Mark low-confidence or missing details as open questions.",
186
249
  "",
@@ -190,6 +253,7 @@ function buildTaskPacketFiles(featureKey, featureName, sourceInfo) {
190
253
  "",
191
254
  header,
192
255
  "",
256
+ ...buildInputBoundarySection(),
193
257
  "## PM Tasks",
194
258
  "",
195
259
  "- Read the preserved source and intake requirement artifact.",
@@ -209,6 +273,9 @@ function buildTaskPacketFiles(featureKey, featureName, sourceInfo) {
209
273
  "",
210
274
  header,
211
275
  "",
276
+ ...buildInputBoundarySection(),
277
+ ...buildRequiredDesignHandoffSection(featureKey),
278
+ ...buildProvenanceContractSection(featureKey),
212
279
  "## ARCH Tasks",
213
280
  "",
214
281
  "- Extract screens, user flows, domain entities, data model, APIs, and design constraints from the preserved source and BA artifact.",
@@ -217,6 +284,7 @@ function buildTaskPacketFiles(featureKey, featureName, sourceInfo) {
217
284
  "- Fill `docs/database/DATABASE_SPEC_<KEY>.md`.",
218
285
  "- Fill `docs/api/<Pascal>_API.yaml`, `docs/api/<KEY>_ENDPOINTS.md`, `docs/api/<KEY>_API_DESIGN_DETAIL.md`, and `docs/api/<snake>_api_flow_list.txt` when API scope is source-backed.",
219
286
  "- Fill `docs/design/DESIGN_LAYOUT_<KEY>.md` only with source-backed layout constraints or explicit decisions.",
287
+ "- Fill `docs/design/SPEC_TO_DESIGN_HANDOFF_<KEY>.json` only from explicit source evidence and include `source_quote` plus `source_line_range` for every screen.",
220
288
  "",
221
289
  "## Evidence Rule",
222
290
  "",
@@ -228,6 +296,7 @@ function buildTaskPacketFiles(featureKey, featureName, sourceInfo) {
228
296
  "",
229
297
  header,
230
298
  "",
299
+ ...buildInputBoundarySection(),
231
300
  "## DEV Planning Tasks",
232
301
  "",
233
302
  "- Fill `docs/dev/FEATURE_IMPL_PLAN_<KEY>.md` after PM/BA/ARCH artifacts are reviewed.",
@@ -281,6 +350,13 @@ function buildState(featureKey, featureName, sourceInfo, diagnostics, scaffold,
281
350
  analysisStatus: ANALYSIS_STATUS,
282
351
  artifacts,
283
352
  taskPacket,
353
+ designHandoffContract: {
354
+ requiredArtifacts: artifactListForFeature(featureKey).map((item) => item.replace(/\\/g, "/")),
355
+ requiredScreenFields: ["id", "title", "source_quote", "source_line_range"],
356
+ sourceQuoteMinimumCodePoints: 30,
357
+ forbiddenInputPattern: "docs/ui/**",
358
+ violationCode: "PROVENANCE_VIOLATION",
359
+ },
284
360
  nextRecommendedAction:
285
361
  `Open ${taskPacket.files["README.md"]} and run the PM/BA/ARCH/DEV/QA agent workflow against the preserved source.`,
286
362
  };