intent-format 0.0.0-stage → 1.2.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 (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 +288 -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 +72 -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,409 @@
1
+ // Builds the per-file model: front matter, skeleton, sections, relation lines, sub-documents.
2
+ // Only local (single-file) diagnostics are produced here; cross-card checks live in check.mjs.
3
+ import { readText } from './util.mjs';
4
+ import { modernize } from './rename.mjs';
5
+ import { parseFrontMatter, parseSkeleton, fenceMask, splitSub, contentIdx, bodyState, parseTable } from './parse.mjs';
6
+ import { scanMentions, parseRelSection, parseSubdocSection, parseStepList, finishFlow, parseIaParts } from './relations.mjs';
7
+
8
+ export function buildFile(S, file, rel, opts = {}) {
9
+ const text = modernize(readText(file), S);
10
+ const lines = text.split('\n');
11
+ if (lines.length && lines[lines.length - 1] === '') lines.pop();
12
+ const c = {
13
+ file, rel, lines, text, kind: 'none', diags: [], rels: [], subs: [], mentions: [], placeholders: [],
14
+ vocabUses: [], stories: [], qualRefs: [], stepLists: [], iaNodes: [], groups: [], forgive: [], extLines: new Set(),
15
+ flowVariants: new Set(), reqNums: new Set(), blind: 0, blindBy: {}, mask: null, sk: null,
16
+ why: null, outcomeMark: null, confirmedIdx: [], asks: [],
17
+ };
18
+ c.bs = (kind) => { c.blind++; c.blindBy[kind] = (c.blindBy[kind] || 0) + 1; };
19
+ c.d = (code, idx, msg) => c.diags.push({ code, line: (idx ?? 0) + 1, msg });
20
+ const fm = parseFrontMatter(lines, S.R);
21
+ if (!fm) return c;
22
+ c.fm = fm;
23
+ if (fm.errors.length) { for (const e of fm.errors) c.d('E001', e.idx, e.msg); c.kind = 'broken'; return c; }
24
+ const val = (k) => fm.map.get(k)?.value;
25
+ c.type = val('type');
26
+ c.name = val('name');
27
+ c.status = val('status');
28
+ c.mask = fenceMask(lines, fm.end + 1);
29
+ c.sk = parseSkeleton(lines, fm.end + 1, S.R, c.mask);
30
+ if (!c.type) { c.d('E002', 0, 'type: is missing'); c.kind = 'broken'; return c; }
31
+ if (c.type === 'index' || c.type === 'manifest') {
32
+ c.kind = c.type;
33
+ checkStandard(S, c);
34
+ const t = c.sk.titleIdx >= 0 ? lines[c.sk.titleIdx] : '';
35
+ if (!S.R.plainTitle.test(t) || S.R.title.test(t)) c.d('W010', c.sk.titleIdx >= 0 ? c.sk.titleIdx : fm.end + 1, 'first body line must be "# <name>"');
36
+ return c;
37
+ }
38
+ if (/^x-[a-z0-9-]+$/.test(c.type)) {
39
+ c.kind = 'x';
40
+ const id = val('id');
41
+ if (!id || !S.R.idPattern.test(id) || !S.R.extPrefix.some((r) => r.test(id.slice(0, 2)))) c.d('E003', fm.map.get('id')?.idx ?? 0, `extension card needs an X*/Z* core (got "${id ?? ''}")`);
42
+ else c.id = id;
43
+ return c;
44
+ }
45
+ if (!S.isCardType(c.type)) { c.d('E002', fm.map.get('type').idx, `unknown type "${c.type}"`); c.kind = 'broken'; return c; }
46
+ c.kind = 'card';
47
+ c.def = S.typeDef(c.type);
48
+ const idE = fm.map.get('id');
49
+ const want = S.prefixOfType[c.type];
50
+ if (!idE || idE.kind === 'empty') c.d('E003', 0, 'missing id: (mint one with intent-format new / intent-format mint)');
51
+ else if (!S.R.idPattern.test(idE.value)) c.d('E003', idE.idx, `malformed id "${idE.raw}" (core only: ${want} + 6 digits)`);
52
+ else if (idE.value.slice(0, 2) !== want) c.d('E003', idE.idx, `id prefix ${idE.value.slice(0, 2)} is not ${want} (type ${c.type})`);
53
+ else c.id = idE.value;
54
+ checkFrontMatter(S, c);
55
+ checkTitle(S, c);
56
+ parseSections(S, c, opts.modules || null);
57
+ return c;
58
+ }
59
+
60
+ function checkStandard(S, c) {
61
+ const first = c.fm.entries[0];
62
+ if (!first || first.key !== 'standard') c.d('W001', first ? first.idx : 0, 'standard: must be the first key');
63
+ else if (S.legacyStandards.includes(first.value)) c.d('W001', first.idx, `standard: ${first.value} is a pre-release name — intent-format migrate renames it to ${S.standard}`);
64
+ else if (first.value !== S.standard) c.d('W001', first.idx, `standard: must be ${S.standard}`);
65
+ }
66
+
67
+ function checkFrontMatter(S, c) {
68
+ const R = S.R, type = c.type;
69
+ checkStandard(S, c);
70
+ const order = S.keyOrder(type);
71
+ const xPos = order.indexOf('x-*');
72
+ let maxPos = -1, orderReported = false;
73
+ const seen = new Set();
74
+ for (const e of c.fm.entries) {
75
+ if (seen.has(e.key)) { c.d('W003', e.idx, `duplicate key ${e.key}: (the first one wins)`); continue; }
76
+ seen.add(e.key);
77
+ const isX = /^x-[a-z0-9-]+$/.test(e.key);
78
+ const pos = isX ? xPos : order.indexOf(e.key);
79
+ if (pos < 0) { c.d('W003', e.idx, `key ${e.key}: is not defined for type ${type}`); continue; }
80
+ if (pos < maxPos && !orderReported) { c.d('W002', e.idx, `key order: ${order.filter((k) => k !== 'x-*').join(', ')}, x-*`); orderReported = true; }
81
+ maxPos = Math.max(maxPos, pos);
82
+ if (isX || e.key === 'standard' || e.key === 'type' || e.key === 'id') continue;
83
+ const def = S.keyDef(type, e.key);
84
+ if (!def) continue;
85
+ checkQuoting(S, c, e, def);
86
+ if (e.kind === 'empty') continue;
87
+ if (e.kind === 'blind') { c.bs(e.key === 'status' ? 'status' : 'frontMatter'); continue; }
88
+ if (e.key === 'status') {
89
+ if (!S.statusValues(type).includes(e.value)) c.d('W005', e.idx, `status "${e.value}" is not one of ${S.statusValues(type).join(' · ')} (or —)`);
90
+ continue;
91
+ }
92
+ if (e.kind === 'list' && !def.list) { c.d('W007', e.idx, `${e.key}: takes one value, not a list`); continue; }
93
+ if (e.key === 'state') {
94
+ if (e.kind === 'list' && e.items.length > 1 && (type === 'userflow' || type === 'ia')) c.d('W042', e.idx, `a ${type} carries one state`);
95
+ }
96
+ const values = e.kind === 'list' ? e.items : [e.value];
97
+ const vn = S.vocabName(def.values);
98
+ for (const v of values) {
99
+ if (vn) c.vocabUses.push({ vocab: vn, value: v, idx: e.idx, code: 'W006', what: `${e.key}:` });
100
+ else if (Array.isArray(def.values) && !def.values.includes(v)) c.d('W007', e.idx, `${e.key}: "${v}" is not one of ${def.values.join(' · ')}`);
101
+ if (def.pattern) {
102
+ if (R.rendered.test('#' + v)) { c.d('W020', e.idx, `${e.key}: holds a rendered ID — write the core only`); continue; }
103
+ if (!new RegExp(def.pattern, 'u').test(v)) c.d('W007', e.idx, `${e.key}: "${v}" does not match ${def.pattern}`);
104
+ }
105
+ }
106
+ }
107
+ for (const k of S.requiredKeys(type)) {
108
+ if (['standard', 'type', 'id'].includes(k)) continue;
109
+ const e = c.fm.map.get(k);
110
+ if (!e || e.kind === 'empty') c.d('W004', e ? e.idx : 0, `required key ${k}: is missing (write — when unknown)`);
111
+ }
112
+ if (type === 'shell') {
113
+ const kind = c.fm.map.get('shell-type')?.value, ap = c.fm.map.get('opens-as'), fl = c.fm.map.get('flow');
114
+ const has = (e) => e && e.kind !== 'empty' && e.kind !== 'blind';
115
+ if (has(ap) && kind && kind !== 'overlay') c.d('W047', ap.idx, 'opens-as: belongs on overlay shells (shell-type: overlay)');
116
+ if (has(fl) && kind && kind !== 'stepper') c.d('W047', fl.idx, 'flow: belongs on stepper shells (shell-type: stepper)');
117
+ if (kind === 'overlay' && !has(ap)) c.d('W047', c.fm.map.get('shell-type').idx, 'an overlay shell needs opens-as: (the presentation it frames)');
118
+ if (kind === 'stepper' && !has(fl)) c.d('W047', c.fm.map.get('shell-type').idx, 'a stepper shell needs flow: (the flow it shows)');
119
+ }
120
+ if (type === 'component') {
121
+ const p = c.fm.map.get('provider'), ct = c.fm.map.get('component-type');
122
+ if (p && ct && ct.value !== 'integration') c.d('I018', p.idx, 'provider: belongs on integration components');
123
+ }
124
+ }
125
+
126
+ function checkQuoting(S, c, e, def) {
127
+ const R = S.R;
128
+ const enumKey = Array.isArray(def.values);
129
+ if (e.kind === 'quoted' && e.value === '—') { c.d('W008', e.idx, 'never quote —'); return; }
130
+ if (S.alwaysQuoted.has(e.key)) {
131
+ if (e.kind !== 'quoted' && e.kind !== 'blind' && e.kind !== 'empty') c.d('W008', e.idx, `${e.key}: is always quoted ("…")`);
132
+ return;
133
+ }
134
+ if (e.kind === 'plain' && (R.needsQuotes.test(e.value) || (!enumKey && R.readsAsNonString.test(e.value)))) c.d('W008', e.idx, `${e.key}: value needs double quotes`);
135
+ if (e.kind === 'quoted' && !R.needsQuotes.test(e.value) && !(!enumKey && R.readsAsNonString.test(e.value))) c.d('I013', e.idx, `${e.key}: quotes are not needed`);
136
+ }
137
+
138
+ function checkTitle(S, c) {
139
+ const { sk, lines } = c;
140
+ if (sk.titleIdx < 0) { c.d('W010', c.fm.end + 1, 'first body line must be "# <name> · #<CORE>"'); return; }
141
+ const m = S.R.title.exec(lines[sk.titleIdx]);
142
+ if (!m) { c.d('W010', sk.titleIdx, 'title must be "# <name> · #<CORE>"'); return; }
143
+ if (m.groups.name !== c.name || m.groups.core !== c.id) c.d('I002', sk.titleIdx, 'title out of sync with name: / id: (regen rewrites it)');
144
+ }
145
+
146
+ function parseSections(S, c, modules) {
147
+ const { lines, mask, sk } = c, R = S.R;
148
+ const defs = S.sections(c.type);
149
+ const seen = new Set();
150
+ let maxPos = -1, sawGen = false;
151
+ for (const sec of sk.sections) {
152
+ sec.full = (sec.gear ? S.gear + ' ' : '') + sec.heading;
153
+ sec.ext = /^x-/.test(sec.heading);
154
+ if (seen.has(sec.full)) c.d('W013', sec.idx, `duplicate section ## ${sec.full}`);
155
+ seen.add(sec.full);
156
+ sec.def = defs.find((x) => x.heading === sec.full) || null;
157
+ if (!sec.def) {
158
+ if (sec.gear && !sec.ext) c.d('W014', sec.idx, `## ${sec.full} is not a generated section of ${c.type}`);
159
+ else if (!sec.gear && !sec.ext) c.d('I008', sec.idx, `## ${sec.full} is not a ${c.type} section (kept as is)`);
160
+ } else {
161
+ const pos = defs.indexOf(sec.def);
162
+ if (pos < maxPos) c.d('W012', sec.idx, `## ${sec.full} is out of order (${defs.filter((d) => !d.generated).map((d) => d.heading).join(' · ')}, then ⚙ sections)`);
163
+ maxPos = Math.max(maxPos, pos);
164
+ }
165
+ if (!sec.gear && sawGen && !sec.ext) c.d('W012', sec.idx, `authored section ## ${sec.full} after a generated one`);
166
+ if (sec.gear) sawGen = true;
167
+ }
168
+ for (const def of defs) {
169
+ if (!def.required || def.generated || seen.has(def.heading)) continue;
170
+ if (def.relief && modules && !modules.includes(def.relief)) continue;
171
+ c.d('W011', sk.sections.length ? sk.sections[sk.sections.length - 1].end - 1 : lines.length - 1, `required section ## ${def.heading} is missing (write — when unknown)`);
172
+ }
173
+ // preamble: comment remark (required) or free prose
174
+ const pre = contentIdx(lines, sk.preStart, sk.preEnd, mask);
175
+ if (c.def.preamble) {
176
+ const bs = bodyState(lines, pre, R);
177
+ if (bs === 'empty') c.d('W011', sk.titleIdx >= 0 ? sk.titleIdx : 0, 'the remark (text under the title) is missing');
178
+ if (bs === 'blind' || bs === 'forgive') c.bs('sections');
179
+ if (bs === 'forgive') { c.d('I005', pre[0], `"${lines[pre[0]].trim()}" read as —`); c.forgive.push(pre[0]); }
180
+ }
181
+ parseProse(S, c, pre);
182
+ for (const sec of sk.sections) {
183
+ if (sec.ext) continue;
184
+ const idxs = contentIdx(lines, sec.start, sec.end, mask);
185
+ const bs = bodyState(lines, idxs, R);
186
+ if (sec.gear) {
187
+ if (sec.def && (bs === 'empty' || bs === 'blind' || bs === 'none')) c.d('I009', sec.idx, `## ${sec.full} is empty (regen removes it)`);
188
+ continue;
189
+ }
190
+ const def = sec.def;
191
+ if (!def) { parseProse(S, c, idxs); continue; }
192
+ if (def.content === 'why') { parseWhy(S, c, sec, idxs, def, bs); continue; }
193
+ if (bs === 'forgive') { c.d('I005', idxs[0], `"${lines[idxs[0]].trim()}" read as —`); c.forgive.push(idxs[0]); }
194
+ if (bs === 'empty' && def.required) c.d('W011', sec.idx, `required section ## ${def.heading} is empty (write — or none)`);
195
+ if (bs === 'blind' || bs === 'forgive') {
196
+ const open = def.notCountedWhileOpen && S.openStatuses.includes(c.status);
197
+ if (def.required && !open) c.bs('sections');
198
+ continue;
199
+ }
200
+ if (bs === 'none' || bs === 'empty') continue;
201
+ if (def.content !== 'subdocuments' && def.subsections !== 'flow-variant') {
202
+ for (const s of splitSub(lines, sec.start, sec.end, mask).subs) if (R.subdoc.test(lines[s.idx])) c.d('W023', s.idx, `sub-document heading outside its host section`);
203
+ }
204
+ switch (def.content) {
205
+ case 'relations': parseRelSection(S, c, sec, def); break;
206
+ case 'ordered-relations':
207
+ if (def.subsections === 'flow-variant') parseStepList(S, c, sec, def);
208
+ else parseRelSection(S, c, sec, def);
209
+ break;
210
+ case 'tree': parseIaParts(S, c, sec, def); break;
211
+ case 'subdocuments': parseSubdocSection(S, c, sec, def); break;
212
+ case 'user-stories': parseUseCases(S, c, idxs); break;
213
+ case 'vocabularies': parseVocabularies(S, c, sec, def); break;
214
+ case 'do-donts':
215
+ for (const i of idxs) if (!R.doDont.test(lines[i])) c.d('I024', i, 'Do & Don\'ts lines start with ✅ or 🚫');
216
+ parseProse(S, c, idxs, false);
217
+ break;
218
+ case 'tags':
219
+ if (idxs.length !== 1 || !R.tags.test(lines[idxs[0]])) c.d('I024', idxs[0], 'Tags are one line of comma-separated tags');
220
+ break;
221
+ default: parseProse(S, c, idxs); break;
222
+ }
223
+ }
224
+ if (c.type === 'userflow') finishFlow(S, c);
225
+ scanAsks(S, c);
226
+ for (const g of c.groups) {
227
+ g.forEach((idx, k) => {
228
+ const m = /^\s*(\d+)\./.exec(lines[idx]);
229
+ if (m && +m[1] !== k + 1 && !g.reported) { c.d('I015', idx, 'ordered lines are numbered 1..N (regen renumbers them)'); g.reported = true; }
230
+ });
231
+ }
232
+ cardChecks(S, c);
233
+ }
234
+
235
+ /** ## Why: — (missing, counted as kind why) · none[ — note] · same as #id (resolved in check) · text with an optional confidence mark. */
236
+ function parseWhy(S, c, sec, idxs, def, bs) {
237
+ const { lines } = c, R = S.R;
238
+ const w = { state: 'filled', mark: null, note: null, idx: sec.idx, textIdx: idxs[idxs.length - 1] ?? sec.idx };
239
+ if (bs === 'empty') { if (def.required) c.d('W011', sec.idx, 'required section ## Why is empty (write — or none)'); w.state = 'missing'; c.bs('why'); }
240
+ else if (bs === 'blind' || bs === 'forgive') {
241
+ if (bs === 'forgive') { c.d('I005', idxs[0], `"${lines[idxs[0]].trim()}" read as —`); c.forgive.push(idxs[0]); }
242
+ w.state = 'missing'; c.bs('why');
243
+ } else if (idxs.length === 1 && R.whyNone.test(lines[idxs[0]].trim())) {
244
+ w.state = 'none'; const m = /^none — (.+)$/.exec(lines[idxs[0]].trim()); w.note = m ? m[1] : null;
245
+ } else if (idxs.length === 1 && R.sameAs.test(lines[idxs[0]].trim())) {
246
+ const m = R.sameAs.exec(lines[idxs[0]].trim());
247
+ w.state = 'inherited'; w.sameAs = m.groups.core;
248
+ if (c.fm.map.get('id')?.value === w.sameAs) { c.d('W051', idxs[0], 'same as: a card cannot borrow its own why'); w.state = 'missing'; w.sameAs = null; c.bs('why'); }
249
+ } else {
250
+ parseProse(S, c, idxs, false);
251
+ const last = lines[w.textIdx].trimEnd();
252
+ const m = R.confidenceMark.exec(last);
253
+ if (m) { w.mark = m.groups.mark; if (m.groups.mark === 'confirmed') { c.d('I031', w.textIdx, '[confirmed] is the default — regen removes it'); c.confirmedIdx.push(w.textIdx); } }
254
+ for (const i of idxs) if (i !== w.textIdx && R.confidenceMark.test(lines[i].trimEnd())) c.d('W051', i, 'a confidence mark goes only at the end of the Why text');
255
+ }
256
+ c.why = w;
257
+ }
258
+
259
+ /** [ask: …] markers in authored body lines: questions to the owner, counted in health and listed by intent-format open. */
260
+ function scanAsks(S, c) {
261
+ const { lines, sk, mask } = c;
262
+ const gear = sk.sections.filter((s) => s.gear);
263
+ for (let i = sk.preStart; i < lines.length; i++) {
264
+ if (mask?.[i] || gear.some((s) => i >= s.idx && i < s.end)) continue;
265
+ for (const m of lines[i].matchAll(S.R.askMarker)) c.asks.push({ idx: i, question: m.groups.q.trim(), later: m.groups.date || null });
266
+ }
267
+ }
268
+
269
+ /** Prose: mentions, placeholders, requirement blocks. */
270
+ export function parseProse(S, c, idxs, req = true) {
271
+ const { lines } = c, R = S.R;
272
+ const set = new Set(idxs);
273
+ for (let k = 0; k < idxs.length; k++) {
274
+ const i = idxs[k];
275
+ scanMentions(S, c, i, lines[i]);
276
+ if (!req || !/^\*\*R\d/.test(lines[i])) continue;
277
+ const m = R.reqMarker.exec(lines[i]);
278
+ if (!m) { c.d('W036', i, 'requirement marker must be **R<n> · User story|GWT|EARS|Checklist**'); continue; }
279
+ if (c.reqNums.has(m.groups.n)) c.d('W036', i, `duplicate requirement number R${m.groups.n}`);
280
+ c.reqNums.add(m.groups.n);
281
+ const block = [];
282
+ for (let j = i + 1; set.has(j) && !/^\*\*R\d/.test(lines[j]); j++) block.push(j);
283
+ checkPreset(S, c, i, m.groups.preset, m.groups.rest || null, block, m.groups.n);
284
+ }
285
+ }
286
+
287
+ function checkPreset(S, c, i, preset, rest, block, n = null) {
288
+ const { lines } = c, R = S.R;
289
+ const first = rest ?? (block.length ? lines[block[0]] : '');
290
+ const at = rest ? i : block[0] ?? i;
291
+ if (preset === 'User story') {
292
+ const m = R.userStory.exec(first);
293
+ if (!m) { c.d('W036', at, 'User story: "As a <role>, I want <goal>, so that <benefit>."'); return; }
294
+ for (const s of ['role', 'goal', 'benefit']) if (m.groups[s].trim() === '—') c.bs('requirements');
295
+ if (m.groups.role !== '—') { c.vocabUses.push({ vocab: 'Roles', value: m.groups.role, idx: at, code: 'W006', what: 'role' }); c.stories.push({ role: m.groups.role.trim(), idx: at, n }); }
296
+ } else if (preset === 'EARS') {
297
+ const m = R.ears.exec(first);
298
+ if (!m) { c.d('W036', at, 'EARS block needs "the system shall"'); return; }
299
+ if ((m.groups.condition || '').trim() === '—') c.bs('requirements');
300
+ if (m.groups.response.replace(/\.$/, '').trim() === '—') c.bs('requirements');
301
+ } else if (preset === 'GWT') {
302
+ const ls = (rest ? [rest] : []).concat(block.map((j) => lines[j]));
303
+ let stage = 0;
304
+ for (const l of ls) {
305
+ const m = R.gwt.exec(l);
306
+ if (!m) { c.d('W036', at, `GWT line must start with Given/When/Then/And/But: ${l}`); return; }
307
+ const k = ['Given', 'When', 'Then'].indexOf(m.groups.keyword);
308
+ if (k >= 0) { if (k !== stage) { c.d('W036', at, 'GWT needs Given, When, Then in this order'); return; } stage++; }
309
+ else if (stage === 0) { c.d('W036', at, 'GWT starts with Given'); return; }
310
+ if (m.groups.text.trim() === '—') c.bs('requirements');
311
+ }
312
+ if (stage !== 3) c.d('W036', at, 'GWT needs Given, When and Then');
313
+ } else if (preset === 'Checklist') {
314
+ if (!block.length) { c.d('W036', i, 'Checklist needs at least one "- [ ] item"'); return; }
315
+ for (const j of block) {
316
+ const m = R.checklist.exec(lines[j]);
317
+ if (!m) { c.d('W036', j, 'checklist items are "- [ ] <item>"'); continue; }
318
+ if (m.groups.text.trim() === '—') c.bs('requirements');
319
+ }
320
+ }
321
+ }
322
+
323
+ function parseUseCases(S, c, idxs) {
324
+ const { lines } = c, R = S.R;
325
+ let n = 0;
326
+ for (const i of idxs) {
327
+ const m = R.useCase.exec(lines[i]);
328
+ const us = m && R.userStory.exec(m.groups.story);
329
+ if (!us) { c.d('W037', i, 'main use case: "- As a <Role>, I want <goal>, so that <benefit>."'); continue; }
330
+ n++;
331
+ for (const s of ['role', 'goal', 'benefit']) if (us.groups[s].trim() === '—') c.bs('requirements');
332
+ if (us.groups.role !== '—') { c.vocabUses.push({ vocab: 'Roles', value: us.groups.role, idx: i, code: 'W037', what: 'role' }); c.stories.push({ role: us.groups.role.trim(), idx: i, n: null }); }
333
+ scanMentions(S, c, i, lines[i]);
334
+ }
335
+ if (n && (n < 5 || n > 10)) c.d('I017', idxs[0], `${n} main use cases (5–10 expected)`);
336
+ }
337
+
338
+ function parseVocabularies(S, c, sec, def) {
339
+ const { lines, mask } = c, R = S.R;
340
+ const lists = S.raw.vocabularies.lists;
341
+ const sub = splitSub(lines, sec.start, sec.end, mask);
342
+ for (const i of contentIdx(lines, sub.intro[0], sub.intro[1], mask)) c.d('W035', i, 'vocabulary content belongs under ### <Vocabulary>');
343
+ const vocab = { declared: new Set(), values: {}, stateCodes: new Map(), roleStates: [] };
344
+ for (const name of def.subsections) vocab.values[name] = new Set();
345
+ for (const s of sub.subs) {
346
+ const ld = lists[s.text];
347
+ if (!ld || !def.subsections.includes(s.text)) { c.d('W035', s.idx, `unknown vocabulary ### ${s.text} (${def.subsections.join(' · ')})`); continue; }
348
+ const idxs = contentIdx(lines, s.start, s.end, mask);
349
+ const vals = vocab.values[s.text];
350
+ if (ld.shape === 'table') {
351
+ const t = parseTable(lines, idxs, R);
352
+ for (const b of t.bad) c.d('W035', b, `### ${s.text} is a table: | ${ld.columns.join(' | ')} |`);
353
+ if (t.header && t.header.join('|') !== ld.columns.join('|')) c.d('W035', idxs[0], `### ${s.text} columns must be ${ld.columns.join(' · ')}`);
354
+ const codes = new Set();
355
+ for (const row of t.rows) {
356
+ const v = row.cells[0];
357
+ if (!v) { c.d('W035', row.idx, 'empty vocabulary value'); continue; }
358
+ if (vals.has(v)) c.d('W035', row.idx, `duplicate value "${v}"`);
359
+ vals.add(v);
360
+ if (s.text === 'States') {
361
+ const code = row.cells[1] || '';
362
+ if (v === S.reserved.States) c.d('W035', row.idx, `${v} is implicit — never a row`);
363
+ if (!R.stateCode.test(code) || code === 'SG' || codes.has(code)) c.d('W035', row.idx, `state code "${code}" must be S + letters, unique, not SG`);
364
+ codes.add(code);
365
+ vocab.stateCodes.set(v, code);
366
+ }
367
+ if (s.text === 'Roles' && row.cells[2]) for (const st of row.cells[2].split(',').map((x) => x.trim()).filter(Boolean)) vocab.roleStates.push({ value: st, idx: row.idx });
368
+ }
369
+ } else {
370
+ for (const i of idxs) {
371
+ const m = R.vocabBullet.exec(lines[i]);
372
+ if (!m) { c.d('W035', i, `### ${s.text}: one "- <value>[ — note]" bullet per value`); continue; }
373
+ if (vals.has(m.groups.value)) c.d('W035', i, `duplicate value "${m.groups.value}"`);
374
+ vals.add(m.groups.value);
375
+ }
376
+ }
377
+ if (vals.size) vocab.declared.add(s.text);
378
+ }
379
+ for (const r of vocab.roleStates) c.vocabUses.push({ vocab: 'States', value: r.value, idx: r.idx, code: 'W006', what: 'Roles · States' });
380
+ c.vocab = vocab;
381
+ }
382
+
383
+ function cardChecks(S, c) {
384
+ const { lines } = c;
385
+ const sec = (h) => c.sk.sections.find((s) => s.full === h);
386
+ if (c.type === 'decision') {
387
+ const o = sec('Outcome');
388
+ const oi = o ? contentIdx(lines, o.start, o.end, c.mask) : [];
389
+ const st = o ? bodyState(lines, oi, S.R) : 'empty';
390
+ if (['Decided', 'Superseded'].includes(c.status) && st) c.d('W039', o ? o.idx : 0, `a ${c.status} decision needs its Outcome`);
391
+ if (!st && oi.length) {
392
+ const li = oi[oi.length - 1], m = S.R.confidenceMark.exec(lines[li].trimEnd());
393
+ if (m) { c.outcomeMark = m.groups.mark; if (m.groups.mark === 'confirmed') { c.d('I031', li, '[confirmed] is the default — regen removes it'); c.confirmedIdx.push(li); } }
394
+ }
395
+ const has = (k) => { const e = c.fm.map.get(k); return e && e.kind !== 'empty' && e.kind !== 'blind'; };
396
+ if (c.status === 'Decided' && !has('decided')) c.d('W052', 0, 'a Decided decision records decided: <YYYY-MM-DD> (and by: who)');
397
+ if (c.status === 'Superseded' && !has('superseded-by')) c.d('W052', 0, 'a Superseded decision names superseded-by: <DC core>');
398
+ if (has('decided') && !['Decided', 'Superseded'].includes(c.status)) c.d('W052', c.fm.map.get('decided').idx, `decided: on a ${c.status} decision — set status: Decided or remove it`);
399
+ if (has('superseded-by') && c.status !== 'Superseded') c.d('W052', c.fm.map.get('superseded-by').idx, `superseded-by: on a ${c.status} decision — set status: Superseded or remove it`);
400
+ }
401
+ if (c.type === 'feature' && !c.fm.map.get('parent')) {
402
+ const dr = sec('Description');
403
+ if (dr) for (const i of contentIdx(lines, dr.start, dr.end, c.mask)) {
404
+ const t = lines[i].replace(S.R.boundG, '').replace(S.R.handG, '').replace(/\*\*R\d+ · [^*]+\*\*/g, '')
405
+ .replace(/\b[Vv]\d+(?:\.\d+)*\b/g, '').replace(/\bR\d+\b/g, '');
406
+ if (/\d/.test(t)) { c.d('I021', i, 'numbers in a top-level Feature — consider a rule'); break; }
407
+ }
408
+ }
409
+ }
@@ -0,0 +1,134 @@
1
+ // intent-format next: read a project folder and say the one next step. All state comes from the project's
2
+ // own files (inputs/, proposal/, report.md, the cards), so any agent can pick up a half-built
3
+ // folder. The procedure itself lives in kit/skills/kb-cold-start/SKILL.md; this only points into it.
4
+ import path from 'node:path';
5
+ import { STANDARD_DIR } from './schema.mjs';
6
+ import { exists, readText, listDir } from './util.mjs';
7
+ import { readInventory } from './create.mjs';
8
+ import { checkProject } from './check.mjs';
9
+ import { renderCard } from './templates.mjs';
10
+ import { parseFrontMatter, parseSkeleton } from './parse.mjs';
11
+
12
+ const KIT = path.join(STANDARD_DIR, 'kit', 'skills');
13
+ const SKILL = path.join(KIT, 'kb-cold-start', 'SKILL.md');
14
+ const sheet = (t) => path.join(KIT, 'intent-format', 'types', `${t}.md`);
15
+ const STEPS = ['Set up', 'Kickoff', 'Proposal', 'Owner review', 'Scaffold', 'Fill', 'Check', 'Report'];
16
+ /** Frames and maps before places: a screen is written against the shells that frame it. */
17
+ export const FILL_ORDER = ['project', 'role', 'feature', 'shell', 'ia', 'screen', 'component', 'userflow', 'rule', 'api', 'backend', 'tech', 'edge-case', 'decision', 'comment'];
18
+
19
+ /** A card is pristine when its authored sections still read as its template: scaffolded, not filled. */
20
+ export function isPristine(S, c) {
21
+ const body = (lines, sections) => sections.filter((x) => !x.gear).map((x) => [x.heading, ...lines.slice(x.start, x.end).map((l) => l.trim()).filter(Boolean)].join('\n')).join('\n');
22
+ const secs = c.sk.sections;
23
+ if (!secs.length || !S.typeDef(c.type)) return false;
24
+ const t = renderCard(S, c.type, { id: c.id, name: c.name }).split('\n');
25
+ const fm = parseFrontMatter(t, S.R);
26
+ const tsk = parseSkeleton(t, fm.end + 1, S.R, new Array(t.length).fill(false));
27
+ const mine = body(c.lines, secs), tmpl = body(t, tsk.sections);
28
+ if (mine === tmpl) return true;
29
+ return secs.filter((x) => !x.gear).every((x) => c.lines.slice(x.start, x.end).map((l) => l.trim()).filter(Boolean).every((l) => l === '—'));
30
+ }
31
+
32
+ const inputFiles = (root) => listDir(path.join(root, 'inputs')).filter((e) => e.isFile() && !/^(links|kickoff-answers)\.md$/.test(e.name) && !e.name.startsWith('.')).map((e) => e.name);
33
+ const tableRows = (file) => (exists(file) ? readText(file).split('\n').filter((l) => /^\|\s*D\d+\s*\|/.test(l)).length : 0);
34
+
35
+ /** The next step for the project at root. P may be null (no workspace yet). */
36
+ export function nextStep(S, P, root, wsFolder) {
37
+ const f = (...p) => path.join(root, ...p);
38
+ const step = (n, o) => ({ mode: 'cold start', step: n, of: STEPS.length, title: STEPS[n - 1], read: [], ...o });
39
+ if (!P || !P.workspaces.length) {
40
+ return step(1, { do: [`Create the project: intent-format init ${root} --name "<Product name>" (inputs/ may already hold files; nothing in it is overwritten).`], done: 'V1.0/intent-format.md exists' });
41
+ }
42
+ const ws = (wsFolder && P.workspaces.find((w) => w.folder === wsFolder)) || P.workspaces.find((w) => w.lifecycle === 'in-progress') || P.workspaces[P.workspaces.length - 1];
43
+ const base = { project: ws.name || path.basename(root), workspace: `${ws.folder} (${ws.lifecycle || '—'})` };
44
+ const kickoff = f('inputs', 'kickoff-answers.md');
45
+ const unattended = exists(kickoff) && /^\s*Mode:\s*unattended\b/im.test(readText(kickoff));
46
+ const hasProposal = exists(f('proposal'));
47
+ const r = checkProject(S, P, { ws: ws.folder });
48
+ const errors = r.counts.error, warnings = r.counts.warning;
49
+ const pristine = ws.cards.filter((c) => isPristine(S, c));
50
+ const health = r.health.find((h) => h.workspace === ws.folder);
51
+ const status = { ...base, unattended, cards: ws.cards.length, pristine: pristine.length, errors, warnings, blindSpots: health?.blindSpots ?? 0, openDecisions: health?.openDecisions ?? 0, whyDebt: health?.why?.missing ?? 0, assumed: health?.confidence?.assumed ?? 0, asks: (health?.asks?.open ?? 0) + (health?.asks?.later ?? 0) };
52
+
53
+ // A KB that was built by hand or whose cold start is over: ongoing work.
54
+ // files that still carry a pre-release name of the standard: migrate first, whatever the phase
55
+ const legacy = P.workspaces.flatMap((w) => w.cards).map((c) => c.fm?.entries?.[0]).find((e) => e?.key === 'standard' && S.legacyStandards.includes(e.value));
56
+ if (legacy) {
57
+ return { ...status, mode: 'migrate', step: null, title: 'Migrate first', do: [`files still say ${legacy.value} — the standard is ${S.standard} now: intent-format migrate ${root}`], read: [], done: 'intent-format check shows no W001' };
58
+ }
59
+ // a KB from before role cards: migrate first, whatever the phase
60
+ if (r.diagnostics.some((d) => d.code === 'W050')) {
61
+ return { ...status, mode: 'migrate', step: null, title: 'Migrate first', do: [`project.md still holds a ### Roles table — user types are role cards now: intent-format migrate ${root}`], read: [], done: 'intent-format check shows no W050' };
62
+ }
63
+ const ongoing = exists(f('report.md')) || (!hasProposal && !exists(kickoff) && ws.cards.length > 1);
64
+ if (ongoing) {
65
+ const todo = [];
66
+ if (errors || warnings) todo.push(`Fix ${errors} error(s) and ${warnings} warning(s): intent-format check ${root}`);
67
+ if (pristine.length) todo.push(`${pristine.length} card(s) still empty — e.g. ${pristine.slice(0, 3).map((c) => c.rel).join(', ')}`);
68
+ todo.push('Before writing or changing a screen: intent-format frame <root> <screen> — obey the Places inside it prints.');
69
+ return { ...status, mode: 'ongoing', step: null, title: exists(f('report.md')) ? 'Cold start complete' : 'Established KB', do: todo, read: [path.join(KIT, 'intent-format', 'SKILL.md')], done: 'after every batch of edits: intent-format regen, then intent-format check' };
70
+ }
71
+ if (!exists(kickoff)) {
72
+ return { ...status, ...step(2, {
73
+ do: ['Hand the owner kickoff-questionnaire.md; their answers go to inputs/kickoff-answers.md, keeping the question numbers.',
74
+ 'No owner available: write inputs/kickoff-answers.md yourself, first line "Mode: unattended", every answer "Unknown", then continue.'],
75
+ read: [path.join(KIT, 'kb-cold-start', 'kickoff-questionnaire.md'), `${SKILL} — Phase 1`],
76
+ done: 'inputs/kickoff-answers.md exists' }) };
77
+ }
78
+ const inputs = inputFiles(root);
79
+ if (!exists(f('proposal', 'inventory.md'))) {
80
+ return { ...status, ...step(3, {
81
+ do: [`Read every input (${inputs.length} file(s) in inputs/, plus links.md and the kickoff answers). Set the lifecycle in ${ws.folder}/intent-format.md from kickoff question 7 if it is not in-progress.`,
82
+ 'Write proposal/inventory.md (tables with the columns Type · Name · Parent / home · Evidence · Confidence · Core: one, or one per section), proposal/frames.md (shells and navigation), proposal/decisions.md and proposal/questions.md. No cards yet.'],
83
+ read: [`${SKILL} — Phase 2 and 3`, path.join(KIT, 'intent-format', 'types', '_overview.md'), path.join(KIT, 'kb-cold-start', 'templates.md')],
84
+ done: 'proposal/inventory.md exists' }) };
85
+ }
86
+ if (!exists(f('proposal', 'review.md'))) {
87
+ return { ...status, ...step(4, {
88
+ do: unattended
89
+ ? ['Unattended: write proposal/review.md with the line "Unattended — recommendations applied." and continue.']
90
+ : ['Stop and hand the proposal to the owner: they answer in proposal/review.md (approve, change, or answer each decision). Do not scaffold before.'],
91
+ read: [`${SKILL} — Phase 3`],
92
+ done: 'proposal/review.md exists' }) };
93
+ }
94
+ if (errors) {
95
+ return { ...status, ...step(7, { do: [`Fix ${errors} error(s) first — regen refuses while they stand: intent-format check ${root}`], read: [path.join(KIT, 'intent-format', 'SKILL.md')], done: 'intent-format check shows 0 errors' }) };
96
+ }
97
+ const inv = readInventory(S, f('proposal', 'inventory.md'));
98
+ const open = inv ? inv.rows.filter((x) => !x.core && x.type !== 'project') : [];
99
+ if (!inv || open.length) {
100
+ return { ...status, ...step(5, {
101
+ do: inv ? [`Apply the review to proposal/inventory.md, then: intent-format scaffold ${root} --inventory ${f('proposal', 'inventory.md')} (${open.length} row(s) without a Core).`]
102
+ : ['proposal/inventory.md has no table with Type, Name and Core columns — fix it (templates.md), then run intent-format next.'],
103
+ read: [`${SKILL} — Phase 4`],
104
+ done: 'every inventory row has a Core' }) };
105
+ }
106
+ const byType = new Map();
107
+ for (const c of pristine) { if (!byType.has(c.type)) byType.set(c.type, []); byType.get(c.type).push(c); }
108
+ const type = FILL_ORDER.find((t) => byType.has(t)) || [...byType.keys()][0];
109
+ const decisionsMissing = Math.max(0, tableRows(f('proposal', 'decisions.md')) - ws.cards.filter((c) => c.type === 'decision').length);
110
+ if (type || decisionsMissing) {
111
+ const cards = type ? byType.get(type) : [];
112
+ const todo = type ? [`Fill ${cards.length} ${type} card(s): ${cards.slice(0, 6).map((c) => c.rel).join(', ')}${cards.length > 6 ? ', …' : ''}`] : [];
113
+ if (type === 'screen') todo.push('For each screen first run intent-format frame <root> <core>: write content, outcome and primary action only — the frame owns navigation and controls.');
114
+ if (type === 'shell') todo.push('Shells before screens: Components, the one ordered Navigation list (· in: · state: · platform:), Places inside, Variants that stack. Use proposal/frames.md.');
115
+ if (decisionsMissing && (!type || type === 'decision')) todo.push(`proposal/decisions.md has ${decisionsMissing} more row(s) than there are decision cards — every row becomes a decision card (intent-format new decision "<question>").`);
116
+ todo.push('Then intent-format regen and intent-format next.');
117
+ return { ...status, ...step(6, { do: todo, read: [`${SKILL} — Phase 5`, ...(type ? [sheet(type)] : [sheet('decision')])], done: 'no card is still empty and every decision row has a card' }) };
118
+ }
119
+ if (warnings) {
120
+ return { ...status, ...step(7, { do: [`Fix ${warnings} warning(s): intent-format check ${root}. Infos are optional.`], read: [`${SKILL} — Phase 6`], done: 'intent-format check shows 0 errors and 0 warnings' }) };
121
+ }
122
+ return { ...status, ...step(8, { do: ['Write report.md at the project root (template in templates.md): what was created, health, open decisions, questions for the owner, assumptions.'], read: [`${SKILL} — Phase 7`, path.join(KIT, 'kb-cold-start', 'templates.md')], done: 'report.md exists — the cold start is over' }) };
123
+ }
124
+
125
+ export function renderNext(n, mds) {
126
+ const head = n.step == null ? `${n.title}` : `Cold start · step ${n.step} of ${n.of} · ${n.title}`;
127
+ const out = [`intent-format next · ${n.project ?? 'new project'}${n.workspace ? ' · ' + n.workspace : ''}${n.unattended ? ' · unattended' : ''}`, head];
128
+ n.do.forEach((l, i) => out.push(`${i ? ' ' : ' Do '}${l}`));
129
+ n.read.forEach((l, i) => out.push(`${i ? ' ' : ' Read'} ${l}`));
130
+ out.push(` Done ${n.done}`);
131
+ if (n.cards != null) out.push(` Now ${n.cards} cards · ${n.pristine} still empty · ${n.errors} errors · ${n.warnings} warnings · blind spots ${n.blindSpots} · why debt ${n.whyDebt} · assumed ${n.assumed} · asks ${n.asks} · open decisions ${n.openDecisions}`);
132
+ out.push(` intent-format = ${mds}`);
133
+ return out.join('\n');
134
+ }
@@ -0,0 +1,34 @@
1
+ // intent-format open: the one list of what is still open in a workspace — [ask: …] questions, open decisions, blind spots per card,
2
+ // whys missing, confidence marks to confirm. Computed from the cards; nothing is stored.
3
+ export function openList(S, ws) {
4
+ const blind = [], whyMissing = [], assumed = [], likely = [], decisions = [], asks = [];
5
+ const line = (c, i) => c.lines[i]?.trim() ?? '';
6
+ const again = S.raw.ask?.again ?? 2, today = Date.now();
7
+ const due = (d) => d && (today - Date.parse(d)) / 86400000 >= again;
8
+ for (const c of ws.cards) {
9
+ if (!c.id) continue;
10
+ const kinds = Object.entries(c.blindBy).filter(([k, v]) => v && k !== 'why').map(([k, v]) => `${k} ${v}`);
11
+ if (kinds.length) blind.push({ core: c.id, name: c.name, path: c.rel, kinds });
12
+ if (c.why && (c.whyEffective || c.why.state) === 'missing') whyMissing.push({ core: c.id, name: c.name, path: c.rel });
13
+ if (c.why?.mark === 'assumed') assumed.push({ core: c.id, name: c.name, path: c.rel, where: 'Why', text: line(c, c.why.textIdx) });
14
+ if (c.why?.mark === 'likely') likely.push({ core: c.id, name: c.name, path: c.rel, where: 'Why', text: line(c, c.why.textIdx) });
15
+ if (c.outcomeMark === 'assumed') assumed.push({ core: c.id, name: c.name, path: c.rel, where: 'Outcome' });
16
+ if (c.outcomeMark === 'likely') likely.push({ core: c.id, name: c.name, path: c.rel, where: 'Outcome' });
17
+ for (const a of c.asks || []) asks.push({ core: c.id, name: c.name, path: c.rel, line: a.idx + 1, question: a.question, later: a.later, due: due(a.later) });
18
+ if (c.type === 'decision' && S.openStatuses.includes(c.status)) decisions.push({ core: c.id, name: c.name, path: c.rel, status: c.status });
19
+ }
20
+ asks.sort((a, b) => (b.due ? 1 : 0) - (a.due ? 1 : 0));
21
+ return { workspace: ws.folder, asks, blindSpots: blind, whyMissing, assumed, likely, openDecisions: decisions };
22
+ }
23
+
24
+ export function renderOpen(o) {
25
+ const out = [`intent-format open · ${o.workspace}`];
26
+ const block = (title, items, f) => { out.push('', `${title} (${items.length})`); for (const x of items) out.push(' ' + f(x)); if (!items.length) out.push(' none'); };
27
+ block('Questions to the owner ([ask: …])', o.asks, (x) => `#${x.core} ${x.name} · ${x.question}${x.later ? ` · later ${x.later}${x.due ? ' · due — ask again' : ''}` : ''} · ${x.path}:${x.line}`);
28
+ block('Open decisions', o.openDecisions, (x) => `#${x.core} ${x.name} · ${x.status} · ${x.path}`);
29
+ block('Assumed (a guess — ask the owner)', o.assumed, (x) => `#${x.core} ${x.name} · ${x.where} · ${x.path}`);
30
+ block('Likely (follows from inputs — confirm)', o.likely, (x) => `#${x.core} ${x.name} · ${x.where} · ${x.path}`);
31
+ block('Why missing (why debt)', o.whyMissing, (x) => `#${x.core} ${x.name} · ${x.path}`);
32
+ block('Other blind spots', o.blindSpots, (x) => `#${x.core} ${x.name} · ${x.kinds.join(' · ')} · ${x.path}`);
33
+ return out.join('\n');
34
+ }