@anselmdk/feature-spec-md 0.1.1 → 0.2.1-rc.1

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 (50) hide show
  1. package/README.md +159 -49
  2. package/SPEC_FORMAT.md +200 -38
  3. package/dist/cli.js +198 -28
  4. package/dist/cli.js.map +1 -1
  5. package/dist/featureSpecs.d.ts +34 -0
  6. package/dist/featureSpecs.d.ts.map +1 -0
  7. package/dist/featureSpecs.js +240 -0
  8. package/dist/featureSpecs.js.map +1 -0
  9. package/dist/filePatterns.d.ts.map +1 -1
  10. package/dist/filePatterns.js +4 -0
  11. package/dist/filePatterns.js.map +1 -1
  12. package/dist/githubActionReport.d.ts +3 -0
  13. package/dist/githubActionReport.d.ts.map +1 -0
  14. package/dist/githubActionReport.js +247 -0
  15. package/dist/githubActionReport.js.map +1 -0
  16. package/dist/html.d.ts +3 -0
  17. package/dist/html.d.ts.map +1 -1
  18. package/dist/html.js +3 -0
  19. package/dist/html.js.map +1 -1
  20. package/dist/index.d.ts +3 -34
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +7 -338
  23. package/dist/index.js.map +1 -1
  24. package/dist/playwright.d.ts.map +1 -1
  25. package/dist/playwright.js +13 -21
  26. package/dist/playwright.js.map +1 -1
  27. package/dist/reportTemplate.d.ts +4 -1
  28. package/dist/reportTemplate.d.ts.map +1 -1
  29. package/dist/reportTemplate.js +251 -21
  30. package/dist/reportTemplate.js.map +1 -1
  31. package/dist/screenshots.d.ts.map +1 -1
  32. package/dist/screenshots.js +4 -0
  33. package/dist/screenshots.js.map +1 -1
  34. package/dist/specDocuments.d.ts +86 -0
  35. package/dist/specDocuments.d.ts.map +1 -0
  36. package/dist/specDocuments.js +351 -0
  37. package/dist/specDocuments.js.map +1 -0
  38. package/dist/specMarkdown.d.ts +26 -0
  39. package/dist/specMarkdown.d.ts.map +1 -0
  40. package/dist/specMarkdown.js +126 -0
  41. package/dist/specMarkdown.js.map +1 -0
  42. package/dist/testImplementationReport.d.ts +53 -0
  43. package/dist/testImplementationReport.d.ts.map +1 -0
  44. package/dist/testImplementationReport.js +160 -0
  45. package/dist/testImplementationReport.js.map +1 -0
  46. package/dist/types.d.ts +76 -11
  47. package/dist/types.d.ts.map +1 -1
  48. package/docs/releasing.md +108 -0
  49. package/docs/spec-driven-flow.md +175 -0
  50. package/package.json +13 -3
package/README.md CHANGED
@@ -1,67 +1,189 @@
1
1
  # feature-spec-md
2
2
 
3
- Markdown feature specs with stable rule and scenario IDs, validation, coverage checks, and generated reports.
3
+ Markdown specs for AI-assisted, testable spec driven development.
4
4
 
5
- The goal is simple:
5
+ The concept is deliberately small:
6
6
 
7
7
  ```txt
8
- human-readable feature spec
9
- exact executable tests
10
- generated coverage report
8
+ model + features + stack + design
9
+ -> AI-written executable tests that reference stable spec IDs
10
+ -> validation, coverage, screenshots, and reports
11
11
  ```
12
12
 
13
- The handwritten spec stays clean. It contains purpose, rules, and scenarios. Test mapping is derived from stable IDs instead of being written manually in the spec.
13
+ The specs are meant to be written with an AI before implementation. The tests are meant to be written with an AI from those specs. `feature-spec-md` checks that the Markdown stays structured and that executable tests still cover the model items, rules, and scenarios the specs define.
14
14
 
15
- ## Format
15
+ ## What You Write
16
16
 
17
- Feature specs are ordinary Markdown files named `*.feature.md`.
17
+ Use four ordinary Markdown document types:
18
18
 
19
- They use:
19
+ ```txt
20
+ *.model.md shared domain vocabulary
21
+ *.feature.md user-facing behavior, rules, and scenarios
22
+ *.stack.md technical platform choices
23
+ *.design.md product, UI, and interaction direction
24
+ ```
25
+
26
+ Each document has frontmatter, a short `## Purpose`, and stable IDs. Tests reference those IDs in titles, tags, annotations, comments, or metadata.
27
+
28
+ ```md
29
+ ### ACCOUNT-ACCESS-S001: Registered person signs in
30
+
31
+ Given a registered person is on the sign-in page
32
+ When they request and open a valid sign-in link
33
+ Then they are signed in
34
+ ```
35
+
36
+ ```ts
37
+ test("ACCOUNT-ACCESS-S001 registered person signs in", async ({ page }) => {
38
+ // Covers ACCOUNT-ACCESS-R001 and ACCOUNT-M001.
39
+ });
40
+ ```
41
+
42
+ See [SPEC_FORMAT.md](SPEC_FORMAT.md) for the exact document format.
43
+
44
+ ## Install
45
+
46
+ ```bash
47
+ npm install -D @anselmdk/feature-spec-md
48
+ ```
49
+
50
+ Create starter specs:
51
+
52
+ ```bash
53
+ npx feature-spec-md init --kind model --dir specs
54
+ npx feature-spec-md init --kind feature --dir specs
55
+ npx feature-spec-md init --kind stack --dir specs
56
+ npx feature-spec-md init --kind design --dir specs
57
+ ```
20
58
 
21
- - frontmatter for metadata
22
- - `## Purpose` for intent
23
- - `## Rules` for general business rules
24
- - `## Scenarios` for Given / When / Then examples
59
+ ## Workflow
25
60
 
26
- See `SPEC_FORMAT.md` and `examples/account-access.feature.md`.
61
+ 1. Ask an AI to draft or update `*.model.md`, `*.feature.md`, `*.stack.md`, and `*.design.md` files.
62
+ 2. Run `npx feature-spec-md check` until the spec set is valid.
63
+ 3. Ask an AI to write executable tests from the specs, preserving the relevant `-M001`, `-R001`, and `-S001` IDs in the test source.
64
+ 4. Run `npx feature-spec-md coverage` to see which scenarios, rules, and model items have tests.
65
+ 5. Run `npx feature-spec-md report` to generate an HTML implementation report for review or CI artifacts.
66
+
67
+ The longer flow, including AI prompts and CI setup, is in [docs/spec-driven-flow.md](docs/spec-driven-flow.md).
27
68
 
28
69
  ## CLI
29
70
 
30
71
  ```bash
31
- npm install
32
- npm run dev -- check --specs "examples/**/*.feature.md" --tests "tests/**/*.test.ts" --require-scenario-coverage=false
33
- npm run dev -- report --specs "examples/**/*.feature.md" --tests "tests/**/*.test.ts"
34
- npm run dev -- report --specs "examples/**/*.feature.md" --tests "tests/**/*.test.ts" --screenshots "test-results/spec-report/screenshots-*.json"
72
+ npx feature-spec-md check
73
+ npx feature-spec-md coverage --fail-on-missing
74
+ npx feature-spec-md report --out test-results/feature-spec-report/index.html
75
+ ```
76
+
77
+ By default the CLI scans:
78
+
79
+ ```txt
80
+ specs/**/*.model.md
81
+ specs/**/*.feature.md
82
+ specs/**/*.stack.md
83
+ specs/**/*.design.md
84
+ tests/**/*.spec.ts
85
+ ```
86
+
87
+ Use explicit patterns when your project uses different paths:
88
+
89
+ ```bash
90
+ npx feature-spec-md check \
91
+ --specs "product/**/*.model.md,product/**/*.feature.md,product/**/*.stack.md,product/**/*.design.md" \
92
+ --tests "e2e/**/*.spec.ts"
35
93
  ```
36
94
 
37
- Playwright screenshot evidence can be shown in the report by passing one or
38
- more screenshot manifest JSON files. Each screenshot should point at the spec
39
- file and line it proves:
95
+ The `check` command validates spec structure, references between documents, and test coverage. Scenario coverage is required by default when tests are scanned. Use `--require-scenario-coverage=false` while drafting. Use `--require-rule-coverage` and `--require-model-coverage` when rules and model items must also fail validation if they have no test references.
96
+
97
+ The `coverage` command prints a terminal implementation report. Use `--fail-on-missing` when missing model item, rule, or scenario coverage should fail CI.
98
+
99
+ The `report` command writes an HTML report. It can include screenshot evidence from Playwright or another test runner by passing one or more screenshot manifest files:
40
100
 
41
- ```json
42
- {
43
- "screenshots": [
44
- {
45
- "specPath": "specs/account-access.feature.md",
46
- "line": 24,
47
- "path": "screenshots/account-s001-line-24.png",
48
- "title": "ACCOUNT-S001:24 Given a registered person is on the sign-in page"
49
- }
50
- ]
51
- }
101
+ ```bash
102
+ npx feature-spec-md report \
103
+ --screenshots "test-results/spec-report/screenshots-*.json"
104
+ ```
105
+
106
+ ## GitHub Actions report publishing
107
+
108
+ `feature-spec-md github-report` writes the GitHub Actions job summary and can either prepare outputs for a GitHub artifact upload or publish the generated report to FTP.
109
+
110
+ ```bash
111
+ npx feature-spec-md github-report \
112
+ --report-dir test-results/spec-report \
113
+ --publish ftp
52
114
  ```
53
115
 
116
+ For FTP publishing, configure repository secrets in GitHub under **Settings → Secrets and variables → Actions → Repository secrets**. For this repository, the direct settings URL is:
117
+
118
+ ```txt
119
+ https://github.com/anselmdk/feature-spec-md/settings/secrets/actions
120
+ ```
121
+
122
+ GitHub's documentation for repository secrets is here:
123
+
124
+ ```txt
125
+ https://docs.github.com/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository
126
+ ```
127
+
128
+ Required secrets or environment variables:
129
+
130
+ ```txt
131
+ FEATURE_SPEC_FTP_HOST=ftp.example.com
132
+ FEATURE_SPEC_FTP_USER=feature-spec-md
133
+ FEATURE_SPEC_FTP_PASSWORD=<your FTP password>
134
+ FEATURE_SPEC_REPORT_BASE_URL=http://feature-spec-md.anselm.dk/
135
+ ```
136
+
137
+ Optional values:
138
+
139
+ ```txt
140
+ FEATURE_SPEC_FTP_REMOTE_DIR=/public_html/feature-spec-md
141
+ FEATURE_SPEC_FTP_PORT=21
142
+ FEATURE_SPEC_FTP_SECURE=false
143
+ ```
144
+
145
+ Example GitHub Actions step:
146
+
147
+ ```yaml
148
+ - name: Publish feature spec report
149
+ if: always() && hashFiles('test-results/spec-report/index.html') != ''
150
+ run: npx feature-spec-md github-report --publish ftp --report-dir test-results/spec-report
151
+ env:
152
+ FEATURE_SPEC_FTP_HOST: ${{ secrets.FEATURE_SPEC_FTP_HOST }}
153
+ FEATURE_SPEC_FTP_USER: ${{ secrets.FEATURE_SPEC_FTP_USER }}
154
+ FEATURE_SPEC_FTP_PASSWORD: ${{ secrets.FEATURE_SPEC_FTP_PASSWORD }}
155
+ FEATURE_SPEC_REPORT_BASE_URL: ${{ secrets.FEATURE_SPEC_REPORT_BASE_URL }}
156
+ ```
157
+
158
+ With `FEATURE_SPEC_REPORT_BASE_URL=http://feature-spec-md.anselm.dk/` and GitHub Actions build number `42`, the report is uploaded to a build-numbered directory and linked as:
159
+
160
+ ```txt
161
+ http://feature-spec-md.anselm.dk/42/
162
+ ```
163
+
164
+ The build index is created or updated at:
165
+
166
+ ```txt
167
+ http://feature-spec-md.anselm.dk/
168
+ ```
169
+
170
+ FTP reports are uploaded into a build-numbered directory using `GITHUB_RUN_NUMBER`, and an `index.html` file is created or updated at the public base URL so all uploaded builds can be browsed. When FTP publishing is used, the command emits `upload-github-artifact=false` and links the GitHub Actions job summary directly to the hosted report URL.
171
+
54
172
  ## Library API
55
173
 
174
+ Most integrations can use the top-level document API:
175
+
56
176
  ```ts
57
177
  import {
58
- checkFeatureSpecs,
59
- parseFeatureSpec,
178
+ checkSpecDocuments,
179
+ parseSpecDocument,
60
180
  renderHtmlReport,
61
- validateFeatureSpec,
62
- } from "feature-spec-md";
181
+ validateSpecDocument,
182
+ } from "@anselmdk/feature-spec-md";
63
183
  ```
64
184
 
185
+ Feature-only helpers such as `parseFeatureSpec` and `checkFeatureSpecs` remain available for compatibility.
186
+
65
187
  ## Development
66
188
 
67
189
  ```bash
@@ -73,16 +195,4 @@ npm run build
73
195
 
74
196
  ## Releases
75
197
 
76
- Stable releases are published to npm by the `Publish to npm` GitHub Actions workflow when a `v*` tag is pushed, or when the workflow is run manually.
77
-
78
- Release candidates are published manually from GitHub Actions:
79
-
80
- 1. Open the `Publish RC to npm` workflow.
81
- 2. Run the workflow from `main`.
82
- 3. The workflow verifies the package, creates a prerelease version using the current package version and GitHub run number, and publishes it with the npm `rc` dist-tag.
83
-
84
- Install the latest release candidate with:
85
-
86
- ```bash
87
- npm install @anselmdk/feature-spec-md@rc
88
- ```
198
+ Release candidates and stable releases are documented in [docs/releasing.md](docs/releasing.md).
package/SPEC_FORMAT.md CHANGED
@@ -1,21 +1,32 @@
1
- # Feature Spec Markdown format
1
+ # Feature Spec Markdown Format
2
2
 
3
- Feature Spec Markdown is a lightweight convention for readable, testable feature specifications.
3
+ Feature Spec Markdown is a lightweight format for testable specs.
4
4
 
5
- It intentionally uses ordinary Markdown and stable IDs instead of a dedicated executable specification language.
5
+ It uses ordinary Markdown plus stable IDs so an AI can write clear product specs, another AI pass can write executable tests from those specs, and tooling can verify that the tests still cover the documented behavior.
6
6
 
7
- ## File name
7
+ ## Document Set
8
8
 
9
- Use:
9
+ A spec set can contain four document types:
10
10
 
11
11
  ```txt
12
+ *.model.md
12
13
  *.feature.md
14
+ *.stack.md
15
+ *.design.md
13
16
  ```
14
17
 
15
- Example:
18
+ - `*.model.md` defines shared domain vocabulary and global domain rules.
19
+ - `*.feature.md` defines user-facing behavior with rules and scenarios.
20
+ - `*.stack.md` defines technical platform choices and their rationale.
21
+ - `*.design.md` defines product, UI, layout, visual, and interaction direction.
22
+
23
+ The short version:
16
24
 
17
25
  ```txt
18
- account-access.feature.md
26
+ model tells tests what things mean
27
+ features tell tests what behavior must work
28
+ stack tells implementation what tools and constraints to use
29
+ design tells implementation what experience to create
19
30
  ```
20
31
 
21
32
  ## Frontmatter
@@ -24,9 +35,10 @@ Every file starts with YAML-like frontmatter:
24
35
 
25
36
  ```md
26
37
  ---
27
- id: ACCOUNT
28
- title: Account access
38
+ id: KANBAN-CARD-AUTHORING
39
+ title: Card authoring
29
40
  status: draft
41
+ model: KANBAN
30
42
  ---
31
43
  ```
32
44
 
@@ -39,48 +51,81 @@ Optional fields:
39
51
 
40
52
  - `status`: `draft`, `active`, or `deprecated`
41
53
  - `owner`
54
+ - `model`: a single referenced model id, for feature and design files
55
+ - `models`: comma-separated referenced model ids, for feature and design files
56
+
57
+ IDs use uppercase words separated by hyphens. IDs are the contract between specs, tests, reports, and implementation work.
58
+
59
+ ## Purpose
60
+
61
+ Every model, feature, stack, and design file MUST include a short `## Purpose` section.
62
+
63
+ Purpose explains the document boundary and intent. It SHOULD be one or two short paragraphs and SHOULD NOT contain rules, scenarios, implementation details, or roadmap notes.
42
64
 
43
- ## Required sections
65
+ ## Model Files
66
+
67
+ Model files use the `.model.md` suffix.
68
+
69
+ Required sections:
44
70
 
45
71
  ```md
46
- # Account access
72
+ # Kanban model
47
73
 
48
74
  ## Purpose
49
75
 
50
- ## Rules
51
-
52
- ## Scenarios
76
+ ## Model
53
77
  ```
54
78
 
79
+ Optional sections:
80
+
81
+ ```md
55
82
  ## Rules
83
+ ```
84
+
85
+ Model items use stable `-M001` IDs:
86
+
87
+ ```md
88
+ ### KANBAN-M001: Card
89
+
90
+ A card represents one work item on the board.
91
+ ```
56
92
 
57
- Rules are durable business truths. They use stable IDs and requirement keywords.
93
+ Model rules use stable `-R001` IDs and describe global invariants for the domain vocabulary:
58
94
 
59
95
  ```md
60
- - ACCOUNT-R001: A person MUST prove control of a registered email address before accessing an account.
61
- - ACCOUNT-R002: The system MUST NOT reveal whether an unknown email address belongs to an account.
62
- - ACCOUNT-R003: A signed-in person SHOULD be returned to the page they originally requested.
96
+ - KANBAN-R001: A card MUST have one current workflow state.
63
97
  ```
64
98
 
65
- Use these keywords:
99
+ ## Feature Files
100
+
101
+ Feature files use the `.feature.md` suffix.
102
+
103
+ Required sections:
104
+
105
+ ```md
106
+ # Card authoring
107
+
108
+ ## Purpose
66
109
 
67
- - `MUST`
68
- - `MUST NOT`
69
- - `SHOULD`
70
- - `SHOULD NOT`
71
- - `MAY`
72
- - `OPTIONAL`
110
+ ## Rules
73
111
 
74
112
  ## Scenarios
113
+ ```
75
114
 
76
- Scenarios are concrete examples. They use stable IDs and Given / When / Then steps.
115
+ Rules use stable `-R001` IDs:
77
116
 
78
117
  ```md
79
- ### ACCOUNT-S001: Registered person signs in
118
+ - KANBAN-CARD-AUTHORING-R001: A new card MUST start in the To do column.
119
+ ```
120
+
121
+ Scenarios use stable `-S001` IDs and Given / When / Then steps:
80
122
 
81
- Given a registered person is on the sign-in page
82
- When they request and open a valid sign-in link
83
- Then they are signed in
123
+ ```md
124
+ ### KANBAN-CARD-AUTHORING-S001: User creates a card
125
+
126
+ Given the user is on the board
127
+ When they create a card with the title "Write release notes"
128
+ Then the card "Write release notes" is visible in the To do column
84
129
  ```
85
130
 
86
131
  Allowed step keywords:
@@ -91,20 +136,137 @@ Allowed step keywords:
91
136
  - `And`
92
137
  - `But`
93
138
 
94
- ## Test coverage convention
139
+ Rules state durable product truths. Scenarios show concrete examples that executable tests can implement.
140
+
141
+ ## Stack Files
142
+
143
+ Stack files use the `.stack.md` suffix.
144
+
145
+ A stack file defines technical platform choices and the reasoning behind them.
146
+
147
+ Required sections:
148
+
149
+ ```md
150
+ # Kanban tech stack
151
+
152
+ ## Purpose
153
+
154
+ ## Stack
155
+ ```
95
156
 
96
- The spec file does not contain test mappings.
157
+ Optional sections:
97
158
 
98
- Tests reference rule and scenario IDs in test titles, tags, annotations, comments, or metadata.
159
+ ```md
160
+ ## Context
161
+
162
+ ## Rationale
163
+
164
+ ## Consequences
165
+ ```
99
166
 
100
- Generated tooling can then answer:
167
+ Example:
168
+
169
+ ```md
170
+ ---
171
+ id: KANBAN-STACK
172
+ title: Kanban tech stack
173
+ status: draft
174
+ ---
101
175
 
176
+ # Kanban tech stack
177
+
178
+ ## Purpose
179
+
180
+ Define the initial technical stack for implementing the Kanban board.
181
+
182
+ ## Stack
183
+
184
+ | Area | Choice |
185
+ | -------- | ---------- |
186
+ | Frontend | React |
187
+ | Language | TypeScript |
188
+ | Testing | Playwright |
189
+ ```
190
+
191
+ ## Design Files
192
+
193
+ Design files use the `.design.md` suffix.
194
+
195
+ A design file defines product, UI, layout, visual, and interaction direction.
196
+
197
+ Required sections:
198
+
199
+ ```md
200
+ # Kanban board design
201
+
202
+ ## Purpose
203
+
204
+ ## Design
205
+ ```
206
+
207
+ Optional sections:
208
+
209
+ ```md
210
+ ## Principles
211
+
212
+ ## Layout
213
+
214
+ ## Interaction
215
+
216
+ ## Visual style
217
+ ```
218
+
219
+ Example:
220
+
221
+ ```md
222
+ ---
223
+ id: KANBAN-DESIGN
224
+ title: Kanban board design
225
+ status: draft
226
+ model: KANBAN
227
+ ---
228
+
229
+ # Kanban board design
230
+
231
+ ## Purpose
232
+
233
+ Define the visual and interaction design direction for the Kanban board.
234
+
235
+ ## Design
236
+
237
+ The board should feel lightweight, immediate, and calm.
238
+ ```
239
+
240
+ ## Splitting Guidance
241
+
242
+ Split model files by coherent domain vocabulary, ownership, or lifecycle.
243
+
244
+ Split feature files by user capability.
245
+
246
+ Use stack files for broad technical choices such as framework, language, testing, persistence, deployment, and runtime constraints.
247
+
248
+ Use design files for product/UI direction such as layout, interaction, visual style, and design principles.
249
+
250
+ Keep each document small enough for an AI to read, revise, and use as test-writing context without extra explanation.
251
+
252
+ ## Test Coverage Convention
253
+
254
+ Spec files do not contain test mappings.
255
+
256
+ Tests reference model item, rule, and scenario IDs in test titles, tags, annotations, comments, or metadata.
257
+
258
+ Generated tooling can answer:
259
+
260
+ - Which model items are referenced?
102
261
  - Which scenarios have tests?
103
262
  - Which rules have executable coverage?
104
263
  - Which tests reference deleted or unknown spec IDs?
105
264
  - Which visible flows have screenshots, traces, or other evidence?
106
265
 
107
- For Playwright tests, capture one screenshot for each scenario step line in the
108
- spec. Report manifests associate each screenshot with the exact spec file and
109
- line number, so the HTML report can display the evidence beside the
110
- Given / When / Then / And line it proves.
266
+ Example:
267
+
268
+ ```ts
269
+ test("KANBAN-CARD-AUTHORING-S001 user creates a card", async ({ page }) => {
270
+ // Covers KANBAN-M001 and KANBAN-CARD-AUTHORING-R001.
271
+ });
272
+ ```