intent-format 0.0.0-stage → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/.github/ISSUE_TEMPLATE/1-something-wrong.yml +18 -0
  2. package/.github/ISSUE_TEMPLATE/2-idea.yml +11 -0
  3. package/.github/ISSUE_TEMPLATE/config.yml +5 -0
  4. package/AGENTS.md +11 -0
  5. package/CHANGELOG.md +287 -0
  6. package/CLAUDE.md +1 -0
  7. package/CODE_OF_CONDUCT.md +128 -0
  8. package/CONTRIBUTING.md +19 -0
  9. package/LICENSE +21 -0
  10. package/README.md +71 -2
  11. package/SECURITY.md +10 -0
  12. package/VERSION +1 -0
  13. package/examples/example-app/AGENTS.md +19 -0
  14. package/examples/example-app/CLAUDE.md +1 -0
  15. package/examples/example-app/V1.0/apis/_index.md +14 -0
  16. package/examples/example-app/V1.0/apis/ap000001-list-items.md +20 -0
  17. package/examples/example-app/V1.0/apis/ap000002-save-item.md +28 -0
  18. package/examples/example-app/V1.0/backend/_index.md +15 -0
  19. package/examples/example-app/V1.0/backend/bn000001-app-server.md +24 -0
  20. package/examples/example-app/V1.0/backend/bn000002-main-database.md +22 -0
  21. package/examples/example-app/V1.0/backend/bn000003-file-storage.md +22 -0
  22. package/examples/example-app/V1.0/comments/_index.md +13 -0
  23. package/examples/example-app/V1.0/comments/cm000001-empty-list-message.md +15 -0
  24. package/examples/example-app/V1.0/components/_index.md +16 -0
  25. package/examples/example-app/V1.0/components/cp000001-button.md +32 -0
  26. package/examples/example-app/V1.0/components/cp000002-text-field.md +31 -0
  27. package/examples/example-app/V1.0/components/cp000003-item-row.md +34 -0
  28. package/examples/example-app/V1.0/components/cp000004-top-bar.md +26 -0
  29. package/examples/example-app/V1.0/decisions/_index.md +13 -0
  30. package/examples/example-app/V1.0/decisions/dc000001-where-do-item-images-live.md +26 -0
  31. package/examples/example-app/V1.0/edge-cases/_index.md +13 -0
  32. package/examples/example-app/V1.0/edge-cases/ec000001-save-fails.md +24 -0
  33. package/examples/example-app/V1.0/features/_index.md +17 -0
  34. package/examples/example-app/V1.0/features/ft000001-items.md +22 -0
  35. package/examples/example-app/V1.0/features/ft000002-account.md +21 -0
  36. package/examples/example-app/V1.0/features/ft000003-browse-items.md +26 -0
  37. package/examples/example-app/V1.0/features/ft000004-edit-an-item.md +33 -0
  38. package/examples/example-app/V1.0/features/ft000005-change-settings.md +21 -0
  39. package/examples/example-app/V1.0/ia/_index.md +13 -0
  40. package/examples/example-app/V1.0/ia/ia000001-main-map.md +23 -0
  41. package/examples/example-app/V1.0/intent-format.md +12 -0
  42. package/examples/example-app/V1.0/project.md +51 -0
  43. package/examples/example-app/V1.0/roles/_index.md +14 -0
  44. package/examples/example-app/V1.0/roles/ro000001-member.md +22 -0
  45. package/examples/example-app/V1.0/roles/ro000002-admin.md +19 -0
  46. package/examples/example-app/V1.0/rules/_index.md +13 -0
  47. package/examples/example-app/V1.0/rules/rl000001-item-name-is-required.md +20 -0
  48. package/examples/example-app/V1.0/screens/_index.md +17 -0
  49. package/examples/example-app/V1.0/screens/sc000001-home.md +18 -0
  50. package/examples/example-app/V1.0/screens/sc000002-item-list.md +43 -0
  51. package/examples/example-app/V1.0/screens/sc000003-item-detail.md +24 -0
  52. package/examples/example-app/V1.0/screens/sc000004-edit-item.md +35 -0
  53. package/examples/example-app/V1.0/screens/sc000005-settings.md +19 -0
  54. package/examples/example-app/V1.0/shells/_index.md +8 -0
  55. package/examples/example-app/V1.0/tech/_index.md +14 -0
  56. package/examples/example-app/V1.0/tech/tc000001-ui-framework.md +23 -0
  57. package/examples/example-app/V1.0/tech/tc000002-relational-database.md +25 -0
  58. package/examples/example-app/V1.0/userflows/_index.md +14 -0
  59. package/examples/example-app/V1.0/userflows/uf000001-create-an-item.md +66 -0
  60. package/examples/example-app/V1.0/userflows/uf000002-edit-an-item.md +47 -0
  61. package/examples/example-app/V1.1/CHANGES.md +12 -0
  62. package/examples/example-app/V1.1/apis/_index.md +14 -0
  63. package/examples/example-app/V1.1/apis/ap000001-list-items.md +20 -0
  64. package/examples/example-app/V1.1/apis/ap000002-save-item.md +28 -0
  65. package/examples/example-app/V1.1/backend/_index.md +15 -0
  66. package/examples/example-app/V1.1/backend/bn000001-app-server.md +24 -0
  67. package/examples/example-app/V1.1/backend/bn000002-main-database.md +22 -0
  68. package/examples/example-app/V1.1/backend/bn000003-file-storage.md +22 -0
  69. package/examples/example-app/V1.1/comments/_index.md +14 -0
  70. package/examples/example-app/V1.1/comments/cm000001-empty-list-message.md +15 -0
  71. package/examples/example-app/V1.1/comments/cm000002-filter-placement.md +12 -0
  72. package/examples/example-app/V1.1/components/_index.md +16 -0
  73. package/examples/example-app/V1.1/components/cp000001-button.md +32 -0
  74. package/examples/example-app/V1.1/components/cp000002-text-field.md +32 -0
  75. package/examples/example-app/V1.1/components/cp000003-item-row.md +34 -0
  76. package/examples/example-app/V1.1/components/cp000004-top-bar.md +26 -0
  77. package/examples/example-app/V1.1/decisions/_index.md +13 -0
  78. package/examples/example-app/V1.1/decisions/dc000001-where-do-item-images-live.md +26 -0
  79. package/examples/example-app/V1.1/edge-cases/_index.md +13 -0
  80. package/examples/example-app/V1.1/edge-cases/ec000001-save-fails.md +24 -0
  81. package/examples/example-app/V1.1/features/_index.md +17 -0
  82. package/examples/example-app/V1.1/features/ft000001-items.md +22 -0
  83. package/examples/example-app/V1.1/features/ft000002-account.md +21 -0
  84. package/examples/example-app/V1.1/features/ft000003-browse-items.md +26 -0
  85. package/examples/example-app/V1.1/features/ft000004-edit-an-item.md +33 -0
  86. package/examples/example-app/V1.1/features/ft000005-change-settings.md +21 -0
  87. package/examples/example-app/V1.1/ia/_index.md +13 -0
  88. package/examples/example-app/V1.1/ia/ia000001-main-map.md +23 -0
  89. package/examples/example-app/V1.1/intent-format.md +13 -0
  90. package/examples/example-app/V1.1/project.md +51 -0
  91. package/examples/example-app/V1.1/roles/_index.md +14 -0
  92. package/examples/example-app/V1.1/roles/ro000001-member.md +22 -0
  93. package/examples/example-app/V1.1/roles/ro000002-admin.md +19 -0
  94. package/examples/example-app/V1.1/rules/_index.md +13 -0
  95. package/examples/example-app/V1.1/rules/rl000001-item-name-is-required.md +20 -0
  96. package/examples/example-app/V1.1/screens/_index.md +17 -0
  97. package/examples/example-app/V1.1/screens/sc000001-home.md +18 -0
  98. package/examples/example-app/V1.1/screens/sc000002-item-list.md +44 -0
  99. package/examples/example-app/V1.1/screens/sc000003-item-detail.md +24 -0
  100. package/examples/example-app/V1.1/screens/sc000004-edit-item.md +35 -0
  101. package/examples/example-app/V1.1/screens/sc000005-settings.md +19 -0
  102. package/examples/example-app/V1.1/shells/_index.md +8 -0
  103. package/examples/example-app/V1.1/tech/_index.md +14 -0
  104. package/examples/example-app/V1.1/tech/tc000001-ui-framework.md +23 -0
  105. package/examples/example-app/V1.1/tech/tc000002-relational-database.md +25 -0
  106. package/examples/example-app/V1.1/userflows/_index.md +14 -0
  107. package/examples/example-app/V1.1/userflows/uf000001-create-an-item.md +66 -0
  108. package/examples/example-app/V1.1/userflows/uf000002-edit-an-item.md +47 -0
  109. package/examples/example-app/_ids.md +78 -0
  110. package/examples/example-app/_index.md +14 -0
  111. package/examples/example-app/inputs/brief.md +3 -0
  112. package/examples/example-app/inputs/links.md +3 -0
  113. package/kit/cli/README.md +128 -0
  114. package/kit/cli/intent-format.mjs +342 -0
  115. package/kit/cli/lib/agents.mjs +39 -0
  116. package/kit/cli/lib/check.mjs +412 -0
  117. package/kit/cli/lib/create.mjs +190 -0
  118. package/kit/cli/lib/frame.mjs +182 -0
  119. package/kit/cli/lib/generate.mjs +418 -0
  120. package/kit/cli/lib/kit.mjs +203 -0
  121. package/kit/cli/lib/migrate.mjs +97 -0
  122. package/kit/cli/lib/model.mjs +409 -0
  123. package/kit/cli/lib/next.mjs +134 -0
  124. package/kit/cli/lib/open.mjs +34 -0
  125. package/kit/cli/lib/parse.mjs +260 -0
  126. package/kit/cli/lib/project.mjs +120 -0
  127. package/kit/cli/lib/regen.mjs +112 -0
  128. package/kit/cli/lib/relations.mjs +380 -0
  129. package/kit/cli/lib/rename.mjs +23 -0
  130. package/kit/cli/lib/schema.mjs +185 -0
  131. package/kit/cli/lib/templates.mjs +41 -0
  132. package/kit/cli/lib/util.mjs +165 -0
  133. package/kit/cli/test/nav.mjs +145 -0
  134. package/kit/cli/test/roles.mjs +85 -0
  135. package/kit/cli/test/smoke.mjs +716 -0
  136. package/kit/skills/intent-format/SKILL.md +91 -0
  137. package/kit/skills/intent-format/links.md +142 -0
  138. package/kit/skills/intent-format/types/_overview.md +73 -0
  139. package/kit/skills/intent-format/types/api.md +111 -0
  140. package/kit/skills/intent-format/types/backend.md +110 -0
  141. package/kit/skills/intent-format/types/comment.md +66 -0
  142. package/kit/skills/intent-format/types/component.md +139 -0
  143. package/kit/skills/intent-format/types/decision.md +91 -0
  144. package/kit/skills/intent-format/types/edge-case.md +107 -0
  145. package/kit/skills/intent-format/types/feature.md +154 -0
  146. package/kit/skills/intent-format/types/ia.md +106 -0
  147. package/kit/skills/intent-format/types/project.md +131 -0
  148. package/kit/skills/intent-format/types/role.md +98 -0
  149. package/kit/skills/intent-format/types/rule.md +100 -0
  150. package/kit/skills/intent-format/types/screen.md +153 -0
  151. package/kit/skills/intent-format/types/shell.md +156 -0
  152. package/kit/skills/intent-format/types/tech.md +109 -0
  153. package/kit/skills/intent-format/types/userflow.md +197 -0
  154. package/kit/skills/kb-cold-start/SKILL.md +124 -0
  155. package/kit/skills/kb-cold-start/kickoff-questionnaire.md +42 -0
  156. package/kit/skills/kb-cold-start/templates.md +108 -0
  157. package/package.json +30 -4
  158. package/rationale.md +180 -0
  159. package/schema.json +5895 -0
  160. package/spec.md +1173 -0
  161. package/templates/api.md +16 -0
  162. package/templates/backend.md +15 -0
  163. package/templates/comment.md +11 -0
  164. package/templates/component.md +15 -0
  165. package/templates/decision.md +23 -0
  166. package/templates/edge-case.md +14 -0
  167. package/templates/feature.md +14 -0
  168. package/templates/ia.md +14 -0
  169. package/templates/project.md +34 -0
  170. package/templates/role.md +14 -0
  171. package/templates/rule.md +14 -0
  172. package/templates/screen.md +14 -0
  173. package/templates/shell.md +24 -0
  174. package/templates/tech.md +18 -0
  175. package/templates/userflow.md +20 -0
@@ -0,0 +1,716 @@
1
+ #!/usr/bin/env node
2
+ // End-to-end smoke test for intent-format. Runs in a temp dir; `--save <dir>` copies the final KB there.
3
+ // node kit/cli/test/smoke.mjs [--save examples/example-app] [--keep]
4
+ import fs from 'node:fs';
5
+ import os from 'node:os';
6
+ import path from 'node:path';
7
+ import crypto from 'node:crypto';
8
+ import { spawnSync } from 'node:child_process';
9
+ import { fileURLToPath } from 'node:url';
10
+
11
+ const here = path.dirname(fileURLToPath(import.meta.url));
12
+ const MDS = path.join(here, '..', 'intent-format.mjs');
13
+ const STD = path.resolve(here, '..', '..', '..');
14
+ const schema = JSON.parse(fs.readFileSync(path.join(STD, 'schema.json'), 'utf8'));
15
+ const args = process.argv.slice(2);
16
+ const saveTo = args.includes('--save') ? path.resolve(args[args.indexOf('--save') + 1]) : null;
17
+ const keep = args.includes('--keep');
18
+
19
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mds-smoke-'));
20
+ const R = path.join(tmp, 'example-app');
21
+ const results = [];
22
+ let failed = 0;
23
+ const ok = (cond, what) => { if (!cond) { failed++; console.error(`FAIL ${what}`); } return !!cond; };
24
+ const step = (name, pass, detail = '') => { results.push(`${pass ? '✓' : '✗'} ${name}${detail ? ' — ' + detail : ''}`); if (!pass) failed++; };
25
+
26
+ function mds(...a) {
27
+ const r = spawnSync(process.execPath, [MDS, ...a], { encoding: 'utf8' });
28
+ return { code: r.status, out: r.stdout, err: r.stderr };
29
+ }
30
+ function hashTree(dir) {
31
+ const h = crypto.createHash('sha256');
32
+ const walk = (d) => {
33
+ for (const e of fs.readdirSync(d, { withFileTypes: true }).sort((a, b) => (a.name < b.name ? -1 : 1))) {
34
+ const p = path.join(d, e.name);
35
+ if (e.isDirectory()) walk(p);
36
+ else { h.update(path.relative(dir, p)); h.update(fs.readFileSync(p)); }
37
+ }
38
+ };
39
+ walk(dir);
40
+ return h.digest('hex');
41
+ }
42
+ const read = (rel) => fs.readFileSync(path.join(R, rel), 'utf8');
43
+ const write = (rel, t) => fs.writeFileSync(path.join(R, rel), t);
44
+ function checkCounts(root, extra = []) {
45
+ const r = mds('check', root, '--json', ...extra);
46
+ const j = JSON.parse(r.out);
47
+ return { ...j.counts, json: j, code: r.code };
48
+ }
49
+ const showProblems = (j) => j.diagnostics.filter((d) => d.severity !== 'info').slice(0, 20).forEach((d) => console.error(` ${d.severity} ${d.code} ${d.path}:${d.line} ${d.message}`));
50
+
51
+ /* ---------- 1. init into an existing root with inputs/ ---------- */
52
+ fs.mkdirSync(path.join(R, 'inputs'), { recursive: true });
53
+ const brief = '# Product brief\n\nExample app: a Member keeps a personal list of items and can create, browse and change them.\n';
54
+ fs.writeFileSync(path.join(R, 'inputs', 'brief.md'), brief);
55
+ const links = '# Links\n\n- [Screen designs](https://example.com/designs) — every screen of Example app\n';
56
+ fs.writeFileSync(path.join(R, 'inputs', 'links.md'), links);
57
+ let r = mds('init', R, '--name', 'Example app', '--kb', 'example-app');
58
+ step('init (existing inputs/ kept)', r.code === 0 && read('inputs/brief.md') === brief && read('inputs/links.md') === links
59
+ && fs.existsSync(path.join(R, '_ids.md')) && fs.existsSync(path.join(R, 'V1.0/project.md')), r.err.trim());
60
+ r = mds('init', R, '--name', 'Example app');
61
+ step('init refuses an existing manifest', r.code === 1);
62
+
63
+ /* ---------- 2. new cards of every type ---------- */
64
+ const C = {}; const F = {};
65
+ function make(key, type, name, ...extra) {
66
+ const res = mds('new', type, name, '--root', R, ...extra);
67
+ const m = /^([A-Z]{2}\d{6}) (\S.*)$/.exec(res.out.trim());
68
+ if (!ok(res.code === 0 && m, `new ${type} "${name}": ${res.err}`)) return;
69
+ C[key] = m[1]; F[key] = m[2];
70
+ }
71
+ make('Member', 'role', 'Member');
72
+ make('Admin', 'role', 'Admin');
73
+ make('Items', 'feature', 'Items');
74
+ make('Account', 'feature', 'Account');
75
+ make('Browse', 'feature', 'Browse items', '--parent', C.Items);
76
+ make('EditF', 'feature', 'Edit an item', '--parent', C.Items);
77
+ make('SettingsF', 'feature', 'Change settings', '--parent', C.Account);
78
+ make('UI', 'tech', 'UI framework');
79
+ make('DB', 'tech', 'Relational database');
80
+ make('Server', 'backend', 'App server');
81
+ make('MainDb', 'backend', 'Main database');
82
+ make('Files', 'backend', 'File storage');
83
+ make('List', 'api', 'List items');
84
+ make('Save', 'api', 'Save item');
85
+ make('Button', 'component', 'Button');
86
+ make('Field', 'component', 'Text field');
87
+ make('Row', 'component', 'Item row', '--feature', C.Browse);
88
+ make('Bar', 'component', 'Top bar');
89
+ make('Home', 'screen', 'Home');
90
+ make('ItemList', 'screen', 'Item list', '--feature', C.Browse);
91
+ make('Detail', 'screen', 'Item detail', '--feature', C.Browse);
92
+ make('EditS', 'screen', 'Edit item', '--feature', C.EditF);
93
+ make('Settings', 'screen', 'Settings', '--feature', C.SettingsF);
94
+ make('Map', 'ia', 'Main map');
95
+ make('Create', 'userflow', 'Create an item', '--feature', C.EditF);
96
+ make('EditFlow', 'userflow', 'Edit an item', '--feature', C.EditF);
97
+ make('NameRule', 'rule', 'Item name is required');
98
+ make('SaveFails', 'edge-case', 'Save fails');
99
+ make('Images', 'decision', 'Where do item images live?');
100
+ make('EmptyMsg', 'comment', 'Empty-list message');
101
+ C.Project = 'PR000001'; F.Project = 'V1.0/project.md';
102
+ const mint = (p, n) => { const x = mds('mint', p, '--root', R, '--count', String(n)); ok(x.code === 0, `mint ${p}`); return x.out.trim().split('\n'); };
103
+ const fs1 = mint('FS', 5), fs2 = mint('FS', 4), [sv1] = mint('SV', 1), [cv1] = mint('CV', 1);
104
+ fs1.forEach((c, i) => { C['S' + (i + 1)] = c; });
105
+ fs2.forEach((c, i) => { C['S' + (i + 6)] = c; });
106
+ C.Picker = sv1; C.Compact = cv1;
107
+ step('new + mint', Object.keys(C).length === 42 && new Set(Object.values(C)).size === 42 && fs1[0] === 'FS000001' && fs2[0] === 'FS000006', `${Object.keys(C).length - 11} cards, 11 sub-document cores`);
108
+
109
+ /* ---------- 3. fill the cards (hand references; regen upgrades them) ---------- */
110
+ const sub = (t) => t.replace(/\{(\w+)\}/g, (m, k) => (C[k] ? '#' + C[k] : m));
111
+ function fill(key, fm, body) {
112
+ const rel = F[key];
113
+ const lines = read(rel).split('\n');
114
+ const end = lines.indexOf('---', 1);
115
+ const type = lines.find((l) => l.startsWith('type: ')).slice(6);
116
+ const order = schema.types[type].keys.map((k) => k.replace(/\?$/, ''));
117
+ const entries = new Map(lines.slice(1, end).map((l) => [l.slice(0, l.indexOf(':')), l.slice(l.indexOf(':') + 2)]));
118
+ for (const [k, v] of Object.entries(fm)) entries.set(k, v);
119
+ const fmOut = order.filter((k) => entries.has(k)).map((k) => `${k}: ${entries.get(k)}`);
120
+ const title = lines[end + 1];
121
+ write(rel, ['---', ...fmOut, '---', title, '', sub(body).trim(), ''].join('\n'));
122
+ }
123
+
124
+ fill('Project', { status: 'In design' }, `
125
+ ## Description
126
+ A small app in which a Member keeps a list of items: create, browse and change them.
127
+
128
+ ## Why
129
+ Members lose track of things kept in notes and chats; one list that is always at hand fixes that.
130
+
131
+ ## User stories
132
+ - As a Member, I want to create an item, so that I can keep track of it.
133
+ - As a Member, I want to browse my items, so that I find one quickly.
134
+ - As a Member, I want to edit an item, so that its details stay current.
135
+ - As a Member, I want to change my settings, so that the app fits how I work.
136
+ - As an Admin, I want to review all items, so that the list stays clean.
137
+
138
+ ## Keep in mind
139
+ **R1 · Checklist**
140
+ - [ ] The Item list opens in under one second with 1000 items.
141
+ - [ ] Every screen works with the keyboard alone.
142
+
143
+ ## Vocabularies
144
+ ### States
145
+ | State | Code | Note |
146
+ |---|---|---|
147
+
148
+ ### Platforms
149
+ - Web
150
+ - Mobile
151
+
152
+ ### Opens-as
153
+ - Side panel — opens beside the current page
154
+
155
+ ### Tech categories
156
+ - Frontend
157
+ - Data & storage
158
+
159
+ ## Built with
160
+ - {UI}
161
+ - {DB}
162
+ - [~ Graph canvas library]
163
+
164
+ ## Links
165
+ - [Product brief](../inputs/brief.md) · type: Source`);
166
+
167
+ fill('Member', { status: 'In design', platform: '[Web, Mobile]' }, `
168
+ ## Description
169
+ Keeps a personal list of items; mostly on the phone, several times a week.
170
+
171
+ ## Why
172
+ The product exists for this user; every story names them.`);
173
+ fill('Admin', { status: 'Idea', platform: 'Web' }, `
174
+ ## Description
175
+ Reviews the items of all Members, on the web.
176
+
177
+ ## Why
178
+ Someone has to keep the shared list clean. [likely]`);
179
+ fill('Items', { status: 'In design', priority: 'High' }, `
180
+ ## Description
181
+ Members need one dependable place for the things they keep track of.
182
+
183
+ In scope: finding, creating and changing items. Out of scope: sharing items with other people.
184
+
185
+ ## Why
186
+ Keeping track of things is the reason the app exists. [confirmed]`);
187
+ fill('Account', { status: 'Idea', priority: 'Medium' }, `
188
+ ## Description
189
+ Members need to adjust the app to how they work.
190
+
191
+ In scope: personal settings. Out of scope: settings shared between Members.
192
+
193
+ ## Why
194
+ Members asked for a dark theme in the first interviews. [assumed]`);
195
+ fill('Browse', { status: 'In design', priority: 'High' }, `
196
+ ## Description
197
+ Lets a Member find an item in their list.
198
+
199
+ **R1 · User story** As a Member, I want to browse my items, so that I find one quickly.
200
+
201
+ ## Why
202
+ same as #${C.Items}`);
203
+ fill('EditF', { status: 'In design', priority: 'High' }, `
204
+ ## Description
205
+ Lets a Member create an item or change its details.
206
+
207
+ **R1 · User story** As a Member, I want to change an item's details, so that my list stays accurate.
208
+
209
+ ## Why
210
+ A list nobody can change goes stale within a week.
211
+
212
+ ## Touchpoints
213
+ - {Field} — name entry`);
214
+ fill('SettingsF', { status: 'Idea' }, `
215
+ ## Description
216
+ Lets a Member change their personal settings.
217
+
218
+ **R1 · User story** As a Member, I want to change my settings, so that the app fits how I work.
219
+
220
+ ## Why
221
+ One app, many working habits.`);
222
+ fill('UI', { status: 'Adopted', category: 'Frontend' }, `
223
+ ## Description
224
+ Renders every screen and component of the app.
225
+
226
+ ## Why
227
+ One component model for the web and mobile screens.
228
+
229
+ ## Alternatives
230
+ none`);
231
+ fill('DB', { status: 'Adopted', category: 'Data & storage', 'tech-version': '"16"', license: 'Open source' }, `
232
+ ## Description
233
+ Keeps items and settings in tables with transactions.
234
+
235
+ ## Why
236
+ Items have a fixed shape and need safe concurrent updates.
237
+
238
+ ## Alternatives
239
+ - [~ Document database]`);
240
+ fill('Server', { status: 'In build', 'backend-type': 'server' }, `
241
+ ## Description
242
+ Serves the item APIs and reads and writes the stored data.
243
+
244
+ ## Connections
245
+ - {MainDb} · kind: stores
246
+ - {Files} · kind: stores
247
+
248
+ ## Built with
249
+ - [~ Server runtime]`);
250
+ fill('MainDb', { status: 'In build', 'backend-type': 'database' }, `
251
+ ## Description
252
+ Stores items and settings.
253
+
254
+ ## Connections
255
+ none
256
+
257
+ ## Built with
258
+ - {DB}`);
259
+ fill('Files', { status: 'Idea', 'backend-type': 'storage' }, `
260
+ ## Description
261
+ Keeps files attached to items.
262
+
263
+ ## Connections
264
+ none`);
265
+ fill('List', { status: 'In build', method: 'GET', endpoint: '/items' }, `
266
+ ## Description
267
+ Returns the items of the signed-in Member, newest first.
268
+
269
+ ## Served by
270
+ - {Server}`);
271
+ fill('Save', { status: 'In build', method: 'PUT', endpoint: '/items/{id}' }, `
272
+ ## Description
273
+ Creates or updates one item and returns the stored version.
274
+
275
+ ## Served by
276
+ - {Server}`);
277
+ fill('Button', { status: 'Live', 'component-type': 'atom' }, `
278
+ ## Description
279
+ Starts one action when chosen.
280
+
281
+ ## Why
282
+ none — layout only
283
+
284
+ ## Components
285
+ none`);
286
+ fill('Field', { status: 'Live', 'component-type': 'atom' }, `
287
+ ## Description
288
+ Lets the user type one line of text.
289
+
290
+ **R1 · GWT**
291
+ Given an empty Text field
292
+ When the user types a name
293
+ Then the name is shown in the field
294
+
295
+ ## Components
296
+ none`);
297
+ fill('Row', { status: 'In design', 'component-type': 'molecule' }, `
298
+ ## Description
299
+ Shows one item's name in a list and opens the item when chosen.
300
+
301
+ ## Why
302
+ same as #${C.Browse}
303
+
304
+ ## Do & Don'ts
305
+ ✅ Show the whole name on one line and cut it at the end.
306
+ 🚫 Don't put more than one button in a row.
307
+
308
+ ## Components
309
+ 1. {Button} — opens the item
310
+
311
+ ## Variants
312
+ ### Compact · {Compact}
313
+
314
+ none`);
315
+ fill('Bar', { status: 'In design', 'component-type': 'organism' }, `
316
+ ## Description
317
+ Shows the title of the current screen and its main action.
318
+
319
+ ## Components
320
+ 1. {Button} — main action
321
+
322
+ ## Built with
323
+ - {UI}`);
324
+ fill('Home', { status: 'In design' }, `
325
+ ## Description
326
+ The starting point of the app.
327
+
328
+ ## Components
329
+ 1. {Bar}`);
330
+ fill('ItemList', { status: 'In design' }, `
331
+ ## Description
332
+ Shows all of a Member's items as rows; choosing a row opens Item detail.
333
+
334
+ **R1 · GWT**
335
+ Given a Member with no items
336
+ When the Item list opens
337
+ Then an empty-list message and a create button are shown
338
+
339
+ ## Components
340
+ 1. {Bar}
341
+ 2. {Row} — one per item
342
+ 3. {Button} — creates an item
343
+
344
+ ## Variants
345
+ ### Picker · {Picker}
346
+ opens-as: Side panel
347
+
348
+ 1. {Row} · variant: Compact
349
+
350
+ ## APIs
351
+ - {List}
352
+
353
+ ## Comments
354
+ - {EmptyMsg}`);
355
+ fill('Detail', { status: 'In design' }, `
356
+ ## Description
357
+ Shows one item with all its details.
358
+
359
+ ## Components
360
+ 1. {Bar}
361
+ 2. {Button} — edits the item`);
362
+ fill('EditS', { status: 'In design', 'opens-as': 'Side panel' }, `
363
+ ## Description
364
+ Lets a Member change an item's name and notes.
365
+
366
+ ## Rules
367
+ - {NameRule}
368
+
369
+ ## Components
370
+ 1. {Bar}
371
+ 2. {Field} — item name
372
+ 3. {Button} — saves the item
373
+
374
+ ## APIs
375
+ - {Save}`);
376
+ fill('Settings', { status: 'Idea' }, `
377
+ ## Description
378
+ Lets a Member change how the app behaves.
379
+
380
+ ## Components
381
+ 1. {Bar}`);
382
+ fill('Map', { status: 'In design', default: 'true' }, `
383
+ ## Description
384
+ How the places of Example app are arranged for every Member.
385
+
386
+ ## Parts
387
+ - {Home}
388
+ - {ItemList} · group: Items
389
+ - {Detail} · group: Items
390
+ - {EditS} · opens-as: Side panel · group: Items
391
+ - {Settings}
392
+
393
+ ### Lateral
394
+ - Edge: {Settings} → {ItemList} · label: Back to items`);
395
+ fill('Create', { status: 'In design' }, `
396
+ ## Description
397
+ A Member adds a new item from the Item list and returns to the list with the item saved.
398
+
399
+ ## Why
400
+ The main use case of Items: without it nothing gets into the list.
401
+
402
+ ## Step list
403
+ 1. {S1}
404
+ 2. {S2}
405
+ 3. {S3}
406
+ 4. {S4}
407
+ 5. {S5}
408
+
409
+ ### Quick add
410
+ platform: Mobile
411
+
412
+ 1. {S1}
413
+ 2. {S2}
414
+ 3. {S4}
415
+ 4. {S5}
416
+
417
+ ## Steps
418
+ ### ○ Start from the list · {S1}
419
+ - Entry: the Member taps Create on the Item list.
420
+ - Screen: {ItemList}
421
+
422
+ ### □ Enter item details · {S2}
423
+ - Screen: {EditS}
424
+ - Component: {Field}
425
+
426
+ The Member types a name and optional notes.
427
+
428
+ ### ◇ Name valid? · {S3}
429
+ - Branch: Yes → {S4} · primary
430
+ - Branch: No → {S2} · rule: {NameRule}
431
+
432
+ ### ⚡ Save the item · {S4}
433
+ - API: {Save}
434
+
435
+ ### ◎ Item created · {S5}
436
+ - Outcome: the new item is saved and shown on the Item list.
437
+ - Screen: {ItemList}`);
438
+ fill('EditFlow', { status: 'In design' }, `
439
+ ## Description
440
+ A Member changes an existing item and returns to its details.
441
+
442
+ ## Why
443
+ Details change; the list must follow.
444
+
445
+ ## Step list
446
+ 1. {S6}
447
+ 2. {S7}
448
+ 3. {S8}
449
+ 4. {S9}
450
+
451
+ ## Steps
452
+ ### ○ Open the item · {S6}
453
+ - Entry: the Member chooses an item on the Item list.
454
+ - Screen: {Detail}
455
+
456
+ ### □ Change the details · {S7}
457
+ - Screen: {EditS}
458
+ - Component: {Field}
459
+
460
+ ### ⚡ Save the changes · {S8}
461
+ - API: {Save}
462
+ - Applies rule: {NameRule}
463
+
464
+ ### ◎ Item updated · {S9}
465
+ - Outcome: the changes are saved and shown on Item detail.
466
+ - Screen: {Detail}`);
467
+ fill('NameRule', { status: 'Approved' }, `
468
+ ## Description
469
+ **R1 · EARS** If the item name is empty, then the system shall refuse to save the item and say why.
470
+
471
+ ## Why
472
+ An item without a name cannot be found again in the list.`);
473
+ fill('SaveFails', { status: 'Idea', severity: 'Medium' }, `
474
+ ## Description
475
+ **R1 · GWT**
476
+ Given a Member editing an item
477
+ When Save item does not answer in time
478
+ Then the edits stay on screen and a retry option is shown
479
+
480
+ ## Rules
481
+ none
482
+
483
+ ## Where
484
+ - {EditS}
485
+ - {S4}
486
+ - {Save}`);
487
+ fill('Images', { status: 'Open' }, `
488
+ ## Question
489
+ Should item images be kept in File storage or inside the Main database?
490
+
491
+ ## Why
492
+ Images are the largest data the app stores; where they live decides backup and cost.
493
+
494
+ ## Options
495
+ 1. File storage — cheap and fast to serve; needs a cleanup job.
496
+ 2. Main database — one backup for everything; larger tables.
497
+
498
+ ## Outcome
499
+ —
500
+
501
+ ## Affects
502
+ - {Files}
503
+ - {Save}`);
504
+ fill('EmptyMsg', { status: 'Open', author: 'Product owner' }, `
505
+ Should the empty Item list also offer to import items? Only if it is cheap.`);
506
+
507
+ /* ---------- 4. regen, check, idempotency ---------- */
508
+ r = mds('regen', R);
509
+ step('regen', r.code === 0, r.out.split('\n')[0]);
510
+ let k = checkCounts(R);
511
+ if (k.error || k.warning) showProblems(k.json);
512
+ step('check after regen', k.error === 0 && k.warning === 0 && k.code === 0, `${k.error} errors · ${k.warning} warnings · ${k.info} infos`);
513
+ const hw = k.json.health[0];
514
+ step('why and confidence counted', hw.why.filled === 13 && hw.why.inherited === 2 && hw.why.none === 1 && hw.why.missing === 0 && hw.confidence.assumed === 1 && hw.confidence.likely === 1
515
+ && hw.blindSpotsByKind.why === 0 && !read(F.Items).includes('[confirmed]') && read(F.Items).includes('reason the app exists.\n'), JSON.stringify({ why: hw.why, confidence: hw.confidence }));
516
+ let h1 = hashTree(R);
517
+ r = mds('regen', R);
518
+ let h2 = hashTree(R);
519
+ step('regen is idempotent', h1 === h2 && /regen: 0 file/.test(r.out), r.out.split('\n')[0]);
520
+
521
+ // spot checks of generated content
522
+ const has = (key, text) => read(F[key]).includes(sub(text));
523
+ ok(has('ItemList', '> ⚙ {ItemList}V1.0 · V1.0 in-progress'), 'status line V1.0');
524
+ ok(has('Create', '1. [{S1} Start from the list](#fs000001)'), 'hand step reference upgraded to bound');
525
+ ok(has('Create', '<a id="fs000003"></a>'), 'anchor inserted');
526
+ ok(has('Row', `- [{ItemList} Item list](../screens/${path.basename(F.ItemList)}) · at: {Picker}`), '⚙ Used in with at:');
527
+ ok(has('Button', `· via: {Bar}`) && has('Button', '## ⚙ Used in'), '⚙ Used in with via:');
528
+ ok(has('NameRule', '## ⚙ Applied in') && has('NameRule', '· at: {S3}') && has('NameRule', '· at: {S8}'), '⚙ Applied in');
529
+ ok(has('Save', '## ⚙ Called from') && has('Save', '· at: {S4}') && has('Save', '## ⚙ Edge cases') && has('Save', '· status: Open'), '⚙ Called from / Edge cases / Decisions');
530
+ ok(has('EditF', '## ⚙ Also uses') && has('EditF', '· home: {Browse}') && has('EditF', '## ⚙ User flows'), '⚙ Also uses / User flows');
531
+ ok(has('Items', '## ⚙ Sub-features') && has('Items', '— Lets a Member find an item in their list.'), '⚙ Sub-features with one-liner');
532
+ ok(has('UI', '## ⚙ Used by') && has('UI', '[#PR000001 Example app](../project.md)'), '⚙ Used by');
533
+ ok(has('EmptyMsg', '## ⚙ Attached to'), '⚙ Attached to');
534
+ ok(has('Home', '## ⚙ On maps') && has('ItemList', '· under: {Home}'), '⚙ On maps');
535
+ ok(has('Server', '## ⚙ Serves') && has('MainDb', '## ⚙ Connected from') && has('MainDb', '· kind: stores'), '⚙ Serves / Connected from');
536
+ ok(has('Field', '## ⚙ Features') && has('Browse', '## ⚙ Screens') && has('Browse', '## ⚙ Components'), '⚙ Features / Screens / Components');
537
+ ok(read('V1.0/screens/_index.md').includes('| Feature | One-liner | Blind spots |'), 'roster columns');
538
+ ok(read('_ids.md').includes(`| ${C.Picker} | screen-variant | Picker | 1.0 |`), '_ids.md lists sub-documents');
539
+ ok(has('Member', '## ⚙ Stories') && has('Member', '[#PR000001 Example app](../project.md) · story: User stories') && has('Member', '{Browse}') && has('Member', '· story: R1'), '⚙ Stories on a role');
540
+ ok(has('Admin', '· story: User stories') && !has('Admin', '{Browse}'), '⚙ Stories only for the role named');
541
+ step('generated sections', failed === 0);
542
+
543
+ /* ---------- 5. release V1.0, branch V1.0 → V1.1, change one card ---------- */
544
+ write('V1.0/intent-format.md', read('V1.0/intent-format.md').replace('lifecycle: in-progress', 'lifecycle: released'));
545
+ r = mds('regen', R);
546
+ ok(read(F.Home).includes('V1.0 released'), 'status line follows the lifecycle');
547
+ r = mds('branch', R, 'V1.0', 'V1.1');
548
+ const v11 = (key) => F[key].replace(/^V1\.0\//, 'V1.1/');
549
+ const man = read('V1.1/intent-format.md');
550
+ step('branch', r.code === 0 && man.includes('version: "1.1"') && man.includes('based-on: "1.0"') && man.includes('lifecycle: in-progress')
551
+ && read(v11('ItemList')).includes('· based on V1.0 · unchanged'), r.err.trim());
552
+ const il = read(v11('ItemList')).replace('3. [#' + C.Button, `4. #${C.Field} — filters the list\n3. [#${C.Button}`);
553
+ write(v11('ItemList'), il);
554
+ r = mds('new', 'comment', 'Filter placement', '--root', R, '--ws', 'V1.1');
555
+ const nm = /^(CM\d{6}) (\S+)$/.exec(r.out.trim());
556
+ ok(nm, 'new in V1.1');
557
+ if (nm) {
558
+ const t = read(nm[2]).replace('author: —', 'author: Designer').replace(/\n—\n$/, '\nShould the filter field sit in the Top bar instead?\n');
559
+ write(nm[2], t);
560
+ }
561
+ r = mds('regen', R);
562
+ const ilText = read(v11('ItemList'));
563
+ const changes = read('V1.1/CHANGES.md');
564
+ step('change detection', r.code === 0 && ilText.includes('> ⚙ #' + C.ItemList + 'V1.1 · V1.1 in-progress · based on V1.0 · changed: Components')
565
+ && /3\. \[#CP000002 Text field\]/.test(ilText) && changes.includes('## ⚙ Changed') && changes.includes(`· changed: Components`)
566
+ && changes.includes('## ⚙ New') && nm && changes.includes(nm[1]) && read(v11('Home')).includes('· unchanged'),
567
+ ilText.split('\n').find((l) => l.startsWith('> ⚙')));
568
+ k = checkCounts(R);
569
+ if (k.error || k.warning) showProblems(k.json);
570
+ h1 = hashTree(R); r = mds('regen', R); h2 = hashTree(R);
571
+ step('check + idempotency after branch', k.error === 0 && k.warning === 0 && h1 === h2, `${k.error} errors · ${k.warning} warnings · ${k.info} infos; second regen: ${r.out.split('\n')[0]}`);
572
+
573
+ /* ---------- 5b. scaffold from an inventory; incomplete-list marker; --lifecycle ---------- */
574
+ const Q = path.join(tmp, 'scaffold-kb');
575
+ mds('init', Q, '--name', 'Scaffold check', '--lifecycle', 'planned');
576
+ const inv = path.join(tmp, 'inventory.md');
577
+ fs.writeFileSync(inv, ['# Inventory — Scaffold check', '',
578
+ '| # | Type | Name | Parent / home | Evidence | Confidence | Notes | Core |',
579
+ '|---|---|---|---|---|---|---|---|',
580
+ '| 1 | project | Scaffold check | | K1 | high | | |',
581
+ '| 2 | screen | Item list | Browse items | inputs/a.html — `<h1>` | high | | |',
582
+ '| 3 | feature | Browse items | Items | K6 | high | | |',
583
+ '| 4 | feature | Items | | K6 | high | | |',
584
+ '| 5 | tech | UI framework | | K16 | high | | |',
585
+ '| 6 | component | Item row | Browse items | inputs/a.html | medium | | |',
586
+ '| 7 | userflow | Create an item | Browse items | K15 | high | | |',
587
+ '| 8 | rule | Item name is required | | doc | high | kept | RL000009 |', ''].join('\n'));
588
+ r = mds('scaffold', Q, '--inventory', inv);
589
+ const invText = fs.readFileSync(inv, 'utf8');
590
+ const coreOf = (name) => (new RegExp(`^\\| \\d+ \\| [a-z-]+ \\| ${name} \\|[^\\n]*\\| ([A-Z]{2}\\d{6}) \\|$`, 'm').exec(invText) || [])[1];
591
+ const qf = (rel) => fs.readFileSync(path.join(Q, rel), 'utf8');
592
+ const scafOk = r.code === 0 && coreOf('Items') === 'FT000001' && coreOf('Browse items') === 'FT000002' && coreOf('Item list') === 'SC000001'
593
+ && coreOf('UI framework') === 'TC000001' && coreOf('Create an item') === 'UF000001' && coreOf('Item name is required') === 'RL000009'
594
+ && qf('V1.0/features/ft000002-browse-items.md').includes('parent: FT000001') && qf('V1.0/screens/sc000001-item-list.md').includes('feature: FT000002')
595
+ && qf('V1.0/components/cp000001-item-row.md').includes('feature: FT000002');
596
+ const r2 = mds('scaffold', Q, '--inventory', inv);
597
+ step('scaffold', scafOk && /scaffold: 6 created/.test(r.out) && /scaffold: 0 created/.test(r2.out) && fs.readFileSync(inv, 'utf8') === invText, r.out.trim().split('\n').pop());
598
+ const scr = path.join(Q, 'V1.0/screens/sc000001-item-list.md');
599
+ fs.writeFileSync(scr, fs.readFileSync(scr, 'utf8').replace(/## Components\n—/, '## Components\n1. #CP000001\n2. —'));
600
+ mds('regen', Q);
601
+ k = checkCounts(Q);
602
+ if (k.error || k.warning) showProblems(k.json);
603
+ step('incomplete-list marker + lifecycle', k.error === 0 && k.warning === 0 && k.json.health[0].blindSpotsByKind.lists === 1 && qf('V1.0/screens/sc000001-item-list.md').includes('V1.0 planned'),
604
+ `blind spots ${k.json.health[0].blindSpots}: ${JSON.stringify(k.json.health[0].blindSpotsByKind)}`);
605
+
606
+ /* ---------- 5c. why values, decision keys, Source links, open ---------- */
607
+ const dec = mds('new', 'decision', 'Keep it simple?', '--root', Q);
608
+ const dm = /^(DC\d{6}) (\S+)$/.exec(dec.out.trim());
609
+ ok(dm, 'new decision in scaffold KB');
610
+ const dpath = path.join(Q, dm[2]);
611
+ const decText = (fm, source) => `---\nstandard: ${schema.standard}\ntype: decision\nid: ${dm[1]}\nname: Keep it simple?\nstatus: Decided\n${fm}---\n# Keep it simple? · #${dm[1]}\n\n## Question\nKeep it simple?\n\n## Why\nIt decides the shape of everything else.\n\n## Options\n1. Yes\n2. No\n\n## Outcome\nYes. [assumed]\n\n## Affects\nnone\n\n## Links\n- [Owner note](${source}) · type: Source\n`;
612
+ fs.writeFileSync(dpath, decText('', '../../notebook/raw/note.md'));
613
+ const tech = path.join(Q, 'V1.0/tech/tc000001-ui-framework.md');
614
+ fs.writeFileSync(tech, fs.readFileSync(tech, 'utf8').replace(/## Why\n—/, '## Why\nsame as #ZZ999999'));
615
+ const comp = path.join(Q, 'V1.0/components/cp000001-item-row.md');
616
+ fs.writeFileSync(comp, fs.readFileSync(comp, 'utf8').replace(/## Description\n—/, '## Description\n—\n\n## Why\nsame as #FT000002'));
617
+ k = checkCounts(Q);
618
+ const codes = (j) => new Set(j.diagnostics.map((d) => d.code));
619
+ let cs = codes(k.json);
620
+ const hq = k.json.health[0];
621
+ step('W052 · W053 · W051 · I030 reported', cs.has('W052') && cs.has('W053') && cs.has('W051') && cs.has('I030') && hq.confidence.assumed === 1 && hq.why.inherited === 0,
622
+ [...cs].filter((c) => /^(W05[123]|I03[01])$/.test(c)).join(' ') + ` · why ${JSON.stringify(hq.why)}`);
623
+ fs.writeFileSync(dpath, decText('decided: 2026-11-10\nby: owner\n', '../../inputs/note.md'));
624
+ fs.writeFileSync(tech, fs.readFileSync(tech, 'utf8').replace(/## Why\nsame as #ZZ999999/, '## Why\nnone'));
625
+ const feat = path.join(Q, 'V1.0/features/ft000002-browse-items.md');
626
+ fs.writeFileSync(feat, fs.readFileSync(feat, 'utf8').replace(/## Why\n—/, '## Why\nFinding things is the point.').replace(/## Description\n—/, '## Description\nA Member finds an item by name [ask: also by tag?]; the list is sorted by date [ask: newest first? · later 2026-11-12].'));
627
+ k = checkCounts(Q);
628
+ cs = codes(k.json);
629
+ const op = mds('open', Q);
630
+ step('decision keys and Source fixed; intent-format open lists the assumed Outcome', !cs.has('W052') && !cs.has('W053') && !cs.has('W051') && !cs.has('I030') && k.json.health[0].why.inherited === 1
631
+ && op.code === 0 && op.out.includes(`#${dm[1]} Keep it simple? · Outcome`) && op.out.includes('Why missing (why debt) (')
632
+ && k.json.health[0].asks.open === 1 && k.json.health[0].asks.later === 1 && op.out.includes('Questions to the owner ([ask: …]) (2)') && op.out.includes('also by tag?') && op.out.includes('later 2026-11-12'),
633
+ op.out.split('\n').slice(0, 5).join(' | ') + ` · asks ${JSON.stringify(k.json.health[0].asks)}`);
634
+
635
+ // a "later" ask older than ask.again days is due: counted, flagged, listed first
636
+ fs.writeFileSync(feat, fs.readFileSync(feat, 'utf8').replace('[ask: newest first? · later 2026-11-12]', '[ask: newest first? · later 2020-01-01]'));
637
+ k = checkCounts(Q);
638
+ const op2 = mds('open', Q);
639
+ step('a later ask past ask.again days is due and listed first', k.json.health[0].asks.due === 1 && k.json.health[0].asks.later === 1 && op2.code === 0
640
+ && op2.out.includes('later 2020-01-01 · due — ask again') && op2.out.indexOf('newest first?') < op2.out.indexOf('also by tag?'),
641
+ `asks ${JSON.stringify(k.json.health[0].asks)}`);
642
+
643
+ /* ---------- 6. templates pass check in a fresh workspace ---------- */
644
+ const T = path.join(tmp, 'templates-kb');
645
+ mds('init', T, '--name', 'Template check');
646
+ const TPL = path.join(STD, 'templates');
647
+ let tplOk = fs.existsSync(TPL);
648
+ for (const type of schema.typeRoster) {
649
+ const f = path.join(TPL, `${type}.md`);
650
+ if (!fs.existsSync(f)) { tplOk = false; continue; }
651
+ const text = fs.readFileSync(f, 'utf8');
652
+ const id = /^id: (\S+)$/m.exec(text)[1], name = /^name: (.+)$/m.exec(text)[1];
653
+ const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
654
+ const dest = type === 'project' ? path.join(T, 'V1.0', 'project.md') : path.join(T, 'V1.0', schema.types[type].folder, `${id.toLowerCase()}-${slug}.md`);
655
+ fs.writeFileSync(dest, text);
656
+ }
657
+ k = checkCounts(T);
658
+ if (k.error || k.warning) showProblems(k.json);
659
+ step('templates pass check', tplOk && k.error === 0 && k.warning === 0, `${k.error} errors · ${k.warning} warnings · ${k.info} infos`);
660
+
661
+ /* ---------- 7. schema examples assembled into a KB ---------- */
662
+ const E = path.join(tmp, 'schema-examples');
663
+ mds('init', E, '--name', 'Example app', '--kb', 'example-app');
664
+ const exFiles = new Map();
665
+ for (const type of schema.typeRoster) {
666
+ const t = schema.types[type];
667
+ for (const ex of [t.example, t.exampleSubfeature].filter(Boolean)) {
668
+ const id = /^id: (\S+)$/m.exec(ex)[1], name = /^name: (.+)$/m.exec(ex)[1];
669
+ const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
670
+ const rel = type === 'project' ? 'V1.0/project.md' : `V1.0/${t.folder}/${id.toLowerCase()}-${slug}.md`;
671
+ exFiles.set(id, rel);
672
+ fs.writeFileSync(path.join(E, rel), ex);
673
+ }
674
+ }
675
+ // stubs for referenced cards that no example defines (authored zones only)
676
+ const stubs = new Map(), known = new Map(), needed = new Set();
677
+ for (const rel of exFiles.values()) {
678
+ const full = fs.readFileSync(path.join(E, rel), 'utf8');
679
+ for (const m of full.matchAll(/\[#([A-Z]{2}\d{6}) ([^\]]+)\]\(([^)#]*)/g)) {
680
+ if (m[3] && !known.has(m[1])) known.set(m[1], { name: m[2], rel: path.posix.join(path.posix.dirname(rel), m[3]) });
681
+ }
682
+ const authored = full.split('\n## ⚙')[0];
683
+ for (const m of authored.matchAll(/\[#([A-Z]{2}\d{6}) /g)) needed.add(m[1]);
684
+ for (const m of authored.matchAll(/^(?:feature|parent): ([A-Z]{2}\d{6})$/gm)) needed.add(m[1]);
685
+ }
686
+ for (const core of needed) {
687
+ if (exFiles.has(core) || !/^(PR|SC|CP|UF|IA|RL|AP|FT|EC|BN|TC|DC|CM)/.test(core) || !known.has(core)) continue;
688
+ stubs.set(core, known.get(core));
689
+ }
690
+ const { renderCard } = await import('../lib/templates.mjs');
691
+ const { loadSchema } = await import('../lib/schema.mjs');
692
+ const S = loadSchema();
693
+ for (const [core, s] of stubs) fs.writeFileSync(path.join(E, s.rel), renderCard(S, S.typeOfCore(core), { id: core, name: s.name }));
694
+ // stories name roles by card name: give every named role a stub card
695
+ const roleNamed = new Set();
696
+ for (const t of Object.values(schema.types)) for (const m of (t.example || '').matchAll(/As an? ([^,]+?), I want/g)) roleNamed.add(m[1]);
697
+ roleNamed.delete(/name: (.+)/.exec(schema.types.role.example)[1]);
698
+ let rn = 900;
699
+ fs.mkdirSync(path.join(E, 'V1.0', 'roles'), { recursive: true });
700
+ for (const name of roleNamed) { const core = 'RO000' + rn++; fs.writeFileSync(path.join(E, 'V1.0', 'roles', `${core.toLowerCase()}-${name.toLowerCase()}.md`), renderCard(S, 'role', { id: core, name })); }
701
+ k = checkCounts(E);
702
+ if (k.error || k.warning) showProblems(k.json);
703
+ step('schema examples pass check', k.error === 0 && k.warning === 0, `${exFiles.size} examples + ${stubs.size} stubs: ${k.error} errors · ${k.warning} warnings · ${k.info} infos`);
704
+
705
+ /* ---------- summary ---------- */
706
+ if (saveTo && failed === 0) {
707
+ fs.rmSync(saveTo, { recursive: true, force: true });
708
+ fs.cpSync(R, saveTo, { recursive: true });
709
+ results.push(`✓ saved the KB to ${path.relative(process.cwd(), saveTo) || saveTo}`);
710
+ }
711
+ console.log('mds smoke test');
712
+ for (const l of results) console.log(' ' + l);
713
+ console.log(failed ? `FAILED (${failed})` : 'PASSED');
714
+ if (!keep) fs.rmSync(tmp, { recursive: true, force: true });
715
+ else console.log(`kept ${tmp}`);
716
+ process.exitCode = failed ? 1 : 0;