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.
- package/.github/ISSUE_TEMPLATE/1-something-wrong.yml +18 -0
- package/.github/ISSUE_TEMPLATE/2-idea.yml +11 -0
- package/.github/ISSUE_TEMPLATE/config.yml +5 -0
- package/AGENTS.md +11 -0
- package/CHANGELOG.md +288 -0
- package/CLAUDE.md +1 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +19 -0
- package/LICENSE +21 -0
- package/README.md +72 -2
- package/SECURITY.md +10 -0
- package/VERSION +1 -0
- package/examples/example-app/AGENTS.md +19 -0
- package/examples/example-app/CLAUDE.md +1 -0
- package/examples/example-app/V1.0/apis/_index.md +14 -0
- package/examples/example-app/V1.0/apis/ap000001-list-items.md +20 -0
- package/examples/example-app/V1.0/apis/ap000002-save-item.md +28 -0
- package/examples/example-app/V1.0/backend/_index.md +15 -0
- package/examples/example-app/V1.0/backend/bn000001-app-server.md +24 -0
- package/examples/example-app/V1.0/backend/bn000002-main-database.md +22 -0
- package/examples/example-app/V1.0/backend/bn000003-file-storage.md +22 -0
- package/examples/example-app/V1.0/comments/_index.md +13 -0
- package/examples/example-app/V1.0/comments/cm000001-empty-list-message.md +15 -0
- package/examples/example-app/V1.0/components/_index.md +16 -0
- package/examples/example-app/V1.0/components/cp000001-button.md +32 -0
- package/examples/example-app/V1.0/components/cp000002-text-field.md +31 -0
- package/examples/example-app/V1.0/components/cp000003-item-row.md +34 -0
- package/examples/example-app/V1.0/components/cp000004-top-bar.md +26 -0
- package/examples/example-app/V1.0/decisions/_index.md +13 -0
- package/examples/example-app/V1.0/decisions/dc000001-where-do-item-images-live.md +26 -0
- package/examples/example-app/V1.0/edge-cases/_index.md +13 -0
- package/examples/example-app/V1.0/edge-cases/ec000001-save-fails.md +24 -0
- package/examples/example-app/V1.0/features/_index.md +17 -0
- package/examples/example-app/V1.0/features/ft000001-items.md +22 -0
- package/examples/example-app/V1.0/features/ft000002-account.md +21 -0
- package/examples/example-app/V1.0/features/ft000003-browse-items.md +26 -0
- package/examples/example-app/V1.0/features/ft000004-edit-an-item.md +33 -0
- package/examples/example-app/V1.0/features/ft000005-change-settings.md +21 -0
- package/examples/example-app/V1.0/ia/_index.md +13 -0
- package/examples/example-app/V1.0/ia/ia000001-main-map.md +23 -0
- package/examples/example-app/V1.0/intent-format.md +12 -0
- package/examples/example-app/V1.0/project.md +51 -0
- package/examples/example-app/V1.0/roles/_index.md +14 -0
- package/examples/example-app/V1.0/roles/ro000001-member.md +22 -0
- package/examples/example-app/V1.0/roles/ro000002-admin.md +19 -0
- package/examples/example-app/V1.0/rules/_index.md +13 -0
- package/examples/example-app/V1.0/rules/rl000001-item-name-is-required.md +20 -0
- package/examples/example-app/V1.0/screens/_index.md +17 -0
- package/examples/example-app/V1.0/screens/sc000001-home.md +18 -0
- package/examples/example-app/V1.0/screens/sc000002-item-list.md +43 -0
- package/examples/example-app/V1.0/screens/sc000003-item-detail.md +24 -0
- package/examples/example-app/V1.0/screens/sc000004-edit-item.md +35 -0
- package/examples/example-app/V1.0/screens/sc000005-settings.md +19 -0
- package/examples/example-app/V1.0/shells/_index.md +8 -0
- package/examples/example-app/V1.0/tech/_index.md +14 -0
- package/examples/example-app/V1.0/tech/tc000001-ui-framework.md +23 -0
- package/examples/example-app/V1.0/tech/tc000002-relational-database.md +25 -0
- package/examples/example-app/V1.0/userflows/_index.md +14 -0
- package/examples/example-app/V1.0/userflows/uf000001-create-an-item.md +66 -0
- package/examples/example-app/V1.0/userflows/uf000002-edit-an-item.md +47 -0
- package/examples/example-app/V1.1/CHANGES.md +12 -0
- package/examples/example-app/V1.1/apis/_index.md +14 -0
- package/examples/example-app/V1.1/apis/ap000001-list-items.md +20 -0
- package/examples/example-app/V1.1/apis/ap000002-save-item.md +28 -0
- package/examples/example-app/V1.1/backend/_index.md +15 -0
- package/examples/example-app/V1.1/backend/bn000001-app-server.md +24 -0
- package/examples/example-app/V1.1/backend/bn000002-main-database.md +22 -0
- package/examples/example-app/V1.1/backend/bn000003-file-storage.md +22 -0
- package/examples/example-app/V1.1/comments/_index.md +14 -0
- package/examples/example-app/V1.1/comments/cm000001-empty-list-message.md +15 -0
- package/examples/example-app/V1.1/comments/cm000002-filter-placement.md +12 -0
- package/examples/example-app/V1.1/components/_index.md +16 -0
- package/examples/example-app/V1.1/components/cp000001-button.md +32 -0
- package/examples/example-app/V1.1/components/cp000002-text-field.md +32 -0
- package/examples/example-app/V1.1/components/cp000003-item-row.md +34 -0
- package/examples/example-app/V1.1/components/cp000004-top-bar.md +26 -0
- package/examples/example-app/V1.1/decisions/_index.md +13 -0
- package/examples/example-app/V1.1/decisions/dc000001-where-do-item-images-live.md +26 -0
- package/examples/example-app/V1.1/edge-cases/_index.md +13 -0
- package/examples/example-app/V1.1/edge-cases/ec000001-save-fails.md +24 -0
- package/examples/example-app/V1.1/features/_index.md +17 -0
- package/examples/example-app/V1.1/features/ft000001-items.md +22 -0
- package/examples/example-app/V1.1/features/ft000002-account.md +21 -0
- package/examples/example-app/V1.1/features/ft000003-browse-items.md +26 -0
- package/examples/example-app/V1.1/features/ft000004-edit-an-item.md +33 -0
- package/examples/example-app/V1.1/features/ft000005-change-settings.md +21 -0
- package/examples/example-app/V1.1/ia/_index.md +13 -0
- package/examples/example-app/V1.1/ia/ia000001-main-map.md +23 -0
- package/examples/example-app/V1.1/intent-format.md +13 -0
- package/examples/example-app/V1.1/project.md +51 -0
- package/examples/example-app/V1.1/roles/_index.md +14 -0
- package/examples/example-app/V1.1/roles/ro000001-member.md +22 -0
- package/examples/example-app/V1.1/roles/ro000002-admin.md +19 -0
- package/examples/example-app/V1.1/rules/_index.md +13 -0
- package/examples/example-app/V1.1/rules/rl000001-item-name-is-required.md +20 -0
- package/examples/example-app/V1.1/screens/_index.md +17 -0
- package/examples/example-app/V1.1/screens/sc000001-home.md +18 -0
- package/examples/example-app/V1.1/screens/sc000002-item-list.md +44 -0
- package/examples/example-app/V1.1/screens/sc000003-item-detail.md +24 -0
- package/examples/example-app/V1.1/screens/sc000004-edit-item.md +35 -0
- package/examples/example-app/V1.1/screens/sc000005-settings.md +19 -0
- package/examples/example-app/V1.1/shells/_index.md +8 -0
- package/examples/example-app/V1.1/tech/_index.md +14 -0
- package/examples/example-app/V1.1/tech/tc000001-ui-framework.md +23 -0
- package/examples/example-app/V1.1/tech/tc000002-relational-database.md +25 -0
- package/examples/example-app/V1.1/userflows/_index.md +14 -0
- package/examples/example-app/V1.1/userflows/uf000001-create-an-item.md +66 -0
- package/examples/example-app/V1.1/userflows/uf000002-edit-an-item.md +47 -0
- package/examples/example-app/_ids.md +78 -0
- package/examples/example-app/_index.md +14 -0
- package/examples/example-app/inputs/brief.md +3 -0
- package/examples/example-app/inputs/links.md +3 -0
- package/kit/cli/README.md +128 -0
- package/kit/cli/intent-format.mjs +342 -0
- package/kit/cli/lib/agents.mjs +39 -0
- package/kit/cli/lib/check.mjs +412 -0
- package/kit/cli/lib/create.mjs +190 -0
- package/kit/cli/lib/frame.mjs +182 -0
- package/kit/cli/lib/generate.mjs +418 -0
- package/kit/cli/lib/kit.mjs +203 -0
- package/kit/cli/lib/migrate.mjs +97 -0
- package/kit/cli/lib/model.mjs +409 -0
- package/kit/cli/lib/next.mjs +134 -0
- package/kit/cli/lib/open.mjs +34 -0
- package/kit/cli/lib/parse.mjs +260 -0
- package/kit/cli/lib/project.mjs +120 -0
- package/kit/cli/lib/regen.mjs +112 -0
- package/kit/cli/lib/relations.mjs +380 -0
- package/kit/cli/lib/rename.mjs +23 -0
- package/kit/cli/lib/schema.mjs +185 -0
- package/kit/cli/lib/templates.mjs +41 -0
- package/kit/cli/lib/util.mjs +165 -0
- package/kit/cli/test/nav.mjs +145 -0
- package/kit/cli/test/roles.mjs +85 -0
- package/kit/cli/test/smoke.mjs +716 -0
- package/kit/skills/intent-format/SKILL.md +91 -0
- package/kit/skills/intent-format/links.md +142 -0
- package/kit/skills/intent-format/types/_overview.md +73 -0
- package/kit/skills/intent-format/types/api.md +111 -0
- package/kit/skills/intent-format/types/backend.md +110 -0
- package/kit/skills/intent-format/types/comment.md +66 -0
- package/kit/skills/intent-format/types/component.md +139 -0
- package/kit/skills/intent-format/types/decision.md +91 -0
- package/kit/skills/intent-format/types/edge-case.md +107 -0
- package/kit/skills/intent-format/types/feature.md +154 -0
- package/kit/skills/intent-format/types/ia.md +106 -0
- package/kit/skills/intent-format/types/project.md +131 -0
- package/kit/skills/intent-format/types/role.md +98 -0
- package/kit/skills/intent-format/types/rule.md +100 -0
- package/kit/skills/intent-format/types/screen.md +153 -0
- package/kit/skills/intent-format/types/shell.md +156 -0
- package/kit/skills/intent-format/types/tech.md +109 -0
- package/kit/skills/intent-format/types/userflow.md +197 -0
- package/kit/skills/kb-cold-start/SKILL.md +124 -0
- package/kit/skills/kb-cold-start/kickoff-questionnaire.md +42 -0
- package/kit/skills/kb-cold-start/templates.md +108 -0
- package/package.json +30 -4
- package/rationale.md +180 -0
- package/schema.json +5895 -0
- package/spec.md +1173 -0
- package/templates/api.md +16 -0
- package/templates/backend.md +15 -0
- package/templates/comment.md +11 -0
- package/templates/component.md +15 -0
- package/templates/decision.md +23 -0
- package/templates/edge-case.md +14 -0
- package/templates/feature.md +14 -0
- package/templates/ia.md +14 -0
- package/templates/project.md +34 -0
- package/templates/role.md +14 -0
- package/templates/rule.md +14 -0
- package/templates/screen.md +14 -0
- package/templates/shell.md +24 -0
- package/templates/tech.md +18 -0
- package/templates/userflow.md +20 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
// Per-card parsing of relation contexts: relation sections, sub-documents (variants, steps),
|
|
2
|
+
// step lists and IA trees. Pushes local diagnostics into card.diags; records relation lines
|
|
3
|
+
// (with atom offsets) into card.rels for resolution, regeneration and generated sections.
|
|
4
|
+
import { splitSub, contentIdx, bodyState, parseRelLine, parsePassport } from './parse.mjs';
|
|
5
|
+
|
|
6
|
+
export function relCx(S, defaultRel, glyphOk = false) {
|
|
7
|
+
return { relations: S.relations, defaultRel, glyphOk };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Scan a text for mentions (bound, hand), placeholders and rendered ids. */
|
|
11
|
+
export function scanMentions(S, c, idx, text, base = 0, placeholderTypes = null) {
|
|
12
|
+
const R = S.R;
|
|
13
|
+
for (const m of text.matchAll(R.boundG)) {
|
|
14
|
+
c.mentions.push({ idx, kind: 'bound', core: m.groups.core, name: m.groups.name ?? null, path: m.groups.path, anchor: m.groups.anchor ?? null, start: base + m.index, end: base + m.index + m[0].length });
|
|
15
|
+
}
|
|
16
|
+
for (const m of text.matchAll(R.handG)) c.mentions.push({ idx, kind: 'hand', core: m.groups.core, start: base + m.index });
|
|
17
|
+
for (const m of text.matchAll(R.placeholderG)) c.placeholders.push({ idx, name: m.groups.name, types: placeholderTypes });
|
|
18
|
+
for (const m of text.matchAll(R.renderedG)) c.d('W020', idx, `rendered ID ${m[0]} used as a reference — write the core only`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Record one parsed line of a relation context.
|
|
23
|
+
* o: { legal:Set, ordered:true|false|null, section, sub, flowVariant, strict, countBlind, tree, defaultRel, group }
|
|
24
|
+
*/
|
|
25
|
+
export function handleRel(S, c, p, idx, o) {
|
|
26
|
+
const line = c.lines[idx];
|
|
27
|
+
switch (p.kind) {
|
|
28
|
+
case 'generated': return null;
|
|
29
|
+
case 'ext': c.extLines.add(idx); return null;
|
|
30
|
+
case 'unknown-word': c.d('W016', idx, `unknown relation word "${p.word}:"`); return null;
|
|
31
|
+
case 'nonlist':
|
|
32
|
+
case 'prose':
|
|
33
|
+
if (o.strict) c.d('W015', idx, `not a relation line: ${line.trim()}`);
|
|
34
|
+
else scanMentions(S, c, idx, line);
|
|
35
|
+
return null;
|
|
36
|
+
default: break;
|
|
37
|
+
}
|
|
38
|
+
const def = S.relations[p.rel];
|
|
39
|
+
if (p.indent > 0 && !o.tree) c.d('W015', idx, 'relation lines never nest (no indentation)');
|
|
40
|
+
if (o.ordered === true && !p.ordered) c.d('W015', idx, 'ordered line expected: "1. <reference>"');
|
|
41
|
+
if (o.ordered === false && p.ordered) c.d('W015', idx, 'bullet line expected: "- <reference>"');
|
|
42
|
+
if (def.generatedOnly) { c.d('W017', idx, `${p.rel} lines are generated (⚙ ${p.rel}); do not write them by hand`); return null; }
|
|
43
|
+
if (def.authoredAs) { c.d('W017', idx, `${p.rel} is a front-matter key, not a relation line`); return null; }
|
|
44
|
+
if (!o.legal.has(p.rel)) { c.d('W017', idx, p.rel === 'Leads to' && c.type === 'shell' ? 'navigation is one list: move this line to ## Navigation and limit it with · state: / · platform:' : `relation ${p.rel} is not allowed here`); return null; }
|
|
45
|
+
if (p.explicit && p.rel === o.defaultRel) c.d('I003', idx, `"${p.rel}:" repeats the section's default relation`);
|
|
46
|
+
if (!p.ok) {
|
|
47
|
+
if (S.R.rendered.test(line)) c.d('W020', idx, 'rendered ID used as a reference — write the core only (#SC000006)');
|
|
48
|
+
else c.d(p.rel === 'Link' ? 'W038' : 'W015', idx, p.why);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const rec = { ...p, idx, section: o.section, sub: o.sub || null, flowVariant: o.flowVariant ?? null };
|
|
52
|
+
c.rels.push(rec);
|
|
53
|
+
if (p.ordered && o.group) o.group.push(idx);
|
|
54
|
+
if (def.textSlot) {
|
|
55
|
+
if (p.text.trim() === '—' && o.countBlind) c.bs('targets');
|
|
56
|
+
else scanMentions(S, c, idx, p.text, p.textStart);
|
|
57
|
+
return rec;
|
|
58
|
+
}
|
|
59
|
+
for (const a of rec.atoms) {
|
|
60
|
+
if (a.kind === 'unknown' && o.countBlind) { c.bs('targets'); rec.countedTarget = true; }
|
|
61
|
+
if (a.kind === 'placeholder') c.placeholders.push({ idx, name: a.name, types: def.targetTypes });
|
|
62
|
+
}
|
|
63
|
+
checkQualifiers(S, c, rec, def);
|
|
64
|
+
return rec;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function checkQualifiers(S, c, rec, def) {
|
|
68
|
+
const R = S.R, idx = rec.idx;
|
|
69
|
+
const qdefs = new Map((def.qualifiers || []).map((q) => [q.key, q]));
|
|
70
|
+
const seen = new Set();
|
|
71
|
+
const link = rec.rel === 'Link';
|
|
72
|
+
for (const q of rec.quals) {
|
|
73
|
+
if (q.bad) { c.d(link ? 'W038' : 'W021', idx, `malformed qualifier "${q.raw.trim()}"`); continue; }
|
|
74
|
+
const qd = qdefs.get(q.key);
|
|
75
|
+
if (!qd) { c.d(link ? 'W038' : 'W021', idx, `unknown qualifier "${q.key}" on ${rec.rel}`); continue; }
|
|
76
|
+
if (seen.has(q.key)) c.d('W021', idx, `duplicate qualifier "${q.key}"`);
|
|
77
|
+
seen.add(q.key);
|
|
78
|
+
if (qd.valueless) { if (q.value != null) c.d('W021', idx, `"${q.key}" takes no value`); continue; }
|
|
79
|
+
if (q.value == null || q.value === '') { c.d('W021', idx, `qualifier "${q.key}" needs a value`); continue; }
|
|
80
|
+
if (/\[#[A-Z]{2}\d{6}[^\]]*\]\(/u.test(q.value)) c.d('W021', idx, `qualifier "${q.key}" holds a bound link — use the bare core`);
|
|
81
|
+
if (!q.quoted && /—|→/.test(q.value)) c.d('W021', idx, `qualifier value with — or → must be quoted`);
|
|
82
|
+
if (Array.isArray(qd.values) && !qd.values.includes(q.value)) {
|
|
83
|
+
c.d(link ? 'W038' : 'W021', idx, `${q.key}: ${q.value} is not one of ${qd.values.join(' · ')}`);
|
|
84
|
+
}
|
|
85
|
+
const vn = S.vocabName(qd.values);
|
|
86
|
+
const items = qd.list ? q.value.split(',').map((x) => x.trim()).filter(Boolean) : [q.value];
|
|
87
|
+
if (vn) for (const v of items) c.vocabUses.push({ vocab: vn, value: v, idx, code: 'W021', what: `${q.key}:` });
|
|
88
|
+
if (q.key === 'in') rec.inParts = items;
|
|
89
|
+
if (q.key === 'state' && rec.rel === 'Leads to') rec.lineState = q.value;
|
|
90
|
+
if (q.key === 'rule') {
|
|
91
|
+
const h = R.hand.exec(q.value), ph = R.placeholder.exec(q.value);
|
|
92
|
+
if (h) c.qualRefs.push({ idx, core: h.groups.core, types: ['rule'], key: 'rule', rec });
|
|
93
|
+
else if (ph) c.placeholders.push({ idx, name: ph.groups.name, types: ['rule'] });
|
|
94
|
+
else c.d('W021', idx, `rule: takes #RL… or [~ Name]`);
|
|
95
|
+
}
|
|
96
|
+
if (q.key === 'shell') {
|
|
97
|
+
const h = R.hand.exec(q.value);
|
|
98
|
+
if (h) c.qualRefs.push({ idx, core: h.groups.core, types: ['shell'], key: 'shell', rec });
|
|
99
|
+
else if (q.value !== 'none') c.d('W021', idx, 'shell: takes #SH… or none');
|
|
100
|
+
}
|
|
101
|
+
if (q.key === 'opens-as' && rec.rel === 'Part' && c.type !== 'shell') c.d('W047', idx, '· opens-as: on a part is for shells only');
|
|
102
|
+
if (q.key === 'variant') rec.variant = q.value;
|
|
103
|
+
}
|
|
104
|
+
if (link && !seen.has('type')) c.d('W038', idx, 'link line needs "· type: Design|Code|Doc|Source|Analytics|Other"');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** A final `- —` / `N. —` item = incomplete list: more items exist but are unknown (blind spot, kind lists). */
|
|
108
|
+
export function markIncomplete(S, c, recs) {
|
|
109
|
+
const last = recs[recs.length - 1];
|
|
110
|
+
if (!last || !S.R.incompleteItem.test(c.lines[last.idx].trim())) return false;
|
|
111
|
+
last.incomplete = true;
|
|
112
|
+
if (last.countedTarget) { c.blind--; c.blindBy.targets--; }
|
|
113
|
+
c.bs('lists');
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** ## sections whose content is relations or ordered-relations (not step lists). */
|
|
118
|
+
export function parseRelSection(S, c, sec, def) {
|
|
119
|
+
const { lines, mask } = c;
|
|
120
|
+
const sub = splitSub(lines, sec.start, sec.end, mask);
|
|
121
|
+
for (const s of sub.subs) c.d(S.R.subdoc.test(lines[s.idx]) ? 'W023' : 'W015', s.idx, `### heading not allowed in ## ${def.heading}`);
|
|
122
|
+
const legal = S.legalIn(c.type, def.heading);
|
|
123
|
+
const group = [];
|
|
124
|
+
const cx = relCx(S, def.defaultRelation);
|
|
125
|
+
const recs = [];
|
|
126
|
+
for (const idx of contentIdx(lines, sub.intro[0], sub.intro[1], mask)) {
|
|
127
|
+
const p = parseRelLine(lines[idx], cx, S.R);
|
|
128
|
+
const rec = handleRel(S, c, p, idx, { legal, ordered: !!def.ordered, section: def.heading, strict: true, countBlind: def.required, defaultRel: def.defaultRelation, group });
|
|
129
|
+
if (rec) recs.push(rec);
|
|
130
|
+
}
|
|
131
|
+
const n = recs.length - (markIncomplete(S, c, recs) ? 1 : 0);
|
|
132
|
+
if (group.length) c.groups.push(group);
|
|
133
|
+
if (def.max && n > def.max) c.d('W022', sec.idx, `## ${def.heading} takes exactly ${def.max} line`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function checkPassport(S, c, pairs, idx, keyDefs, what) {
|
|
137
|
+
let last = -1;
|
|
138
|
+
const seen = new Set();
|
|
139
|
+
for (const { key, value } of pairs) {
|
|
140
|
+
const pos = keyDefs.findIndex((k) => k.key === key);
|
|
141
|
+
if (pos < 0) { c.d('W024', idx, `unknown passport key "${key}" on ${what}`); continue; }
|
|
142
|
+
if (pos < last) c.d('W024', idx, `passport keys out of order (${keyDefs.map((k) => k.key).join(' · ')})`);
|
|
143
|
+
last = Math.max(last, pos);
|
|
144
|
+
if (seen.has(key)) c.d('W024', idx, `duplicate passport key "${key}"`);
|
|
145
|
+
seen.add(key);
|
|
146
|
+
if (value === '—') { c.bs('frontMatter'); continue; }
|
|
147
|
+
const kd = keyDefs[pos];
|
|
148
|
+
const vn = S.vocabName(kd.values);
|
|
149
|
+
const vals = kd.list ? value.split(',').map((x) => x.trim()) : [value];
|
|
150
|
+
if (vn) for (const v of vals) c.vocabUses.push({ vocab: vn, value: v, idx, code: 'W024', what: `${key}:` });
|
|
151
|
+
if (kd.pattern && !new RegExp(kd.pattern, 'u').test(value)) c.d('W024', idx, `${key}: ${value} does not match ${kd.pattern}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** ## Variants and ## Steps. */
|
|
156
|
+
export function parseSubdocSection(S, c, sec, def) {
|
|
157
|
+
const { lines, mask } = c, R = S.R;
|
|
158
|
+
const kind = def.subdocuments;
|
|
159
|
+
const want = S.subdocPrefix[kind];
|
|
160
|
+
const sub = splitSub(lines, sec.start, sec.end, mask);
|
|
161
|
+
const intro = contentIdx(lines, sub.intro[0], sub.intro[1], mask);
|
|
162
|
+
if (intro.length && (sub.subs.length || !bodyState(lines, intro, R))) {
|
|
163
|
+
for (const i of intro) c.d('W015', i, `text before the first ### sub-document in ## ${def.heading}`);
|
|
164
|
+
}
|
|
165
|
+
const names = new Set();
|
|
166
|
+
for (const s of sub.subs) {
|
|
167
|
+
const m = R.subdoc.exec(lines[s.idx]);
|
|
168
|
+
if (!m) { c.d('W023', s.idx, `sub-document heading must be "### ${kind === 'flow-step' ? '<glyph> ' : ''}<Name> · #${want}<6 digits>"`); continue; }
|
|
169
|
+
const core = m.groups.core;
|
|
170
|
+
if (core.slice(0, 2) !== want) { c.d('E003', s.idx, `${core} does not fit ## ${def.heading} (expects ${want}…)`); continue; }
|
|
171
|
+
const sd = { core, kind, name: m.groups.name, glyph: m.groups.glyph || null, idx: s.idx, end: s.end, section: def.heading, anchorIdx: -1, host: c };
|
|
172
|
+
c.subs.push(sd);
|
|
173
|
+
const next = s.idx + 1 < s.end ? lines[s.idx + 1] : null;
|
|
174
|
+
const am = next != null ? R.anchor.exec(next) : null;
|
|
175
|
+
if (am) {
|
|
176
|
+
sd.anchorIdx = s.idx + 1;
|
|
177
|
+
if (am.groups.anchor !== core.toLowerCase()) c.d('W023', s.idx + 1, `anchor id must be ${core.toLowerCase()}`);
|
|
178
|
+
} else c.d('I006', s.idx, `anchor line <a id="${core.toLowerCase()}"></a> missing under the heading`);
|
|
179
|
+
if (kind !== 'flow-step') {
|
|
180
|
+
if (names.has(sd.name)) c.d('W023', s.idx, `variant name "${sd.name}" used twice`);
|
|
181
|
+
names.add(sd.name);
|
|
182
|
+
parseVariantBody(S, c, sd);
|
|
183
|
+
} else parseStepBody(S, c, sd);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function bodyStart(sd) { return sd.anchorIdx >= 0 ? sd.anchorIdx + 1 : sd.idx + 1; }
|
|
188
|
+
|
|
189
|
+
function parseVariantBody(S, c, sd) {
|
|
190
|
+
const { lines, mask } = c, R = S.R;
|
|
191
|
+
let idxs = contentIdx(lines, bodyStart(sd), sd.end, mask);
|
|
192
|
+
if (idxs.length) {
|
|
193
|
+
const pp = parsePassport(lines[idxs[0]], R);
|
|
194
|
+
if (pp) { checkPassport(S, c, pp, idxs[0], S.raw.subdocuments[sd.kind].passport.keys, 'a variant'); sd.passport = pp; sd.passportIdx = idxs[0]; idxs = idxs.slice(1); }
|
|
195
|
+
}
|
|
196
|
+
const legal = new Set(S.legalInSubdoc(sd.kind).keys());
|
|
197
|
+
const prefixless = S.prefixlessIn(sd.kind);
|
|
198
|
+
const cx = relCx(S, prefixless);
|
|
199
|
+
const group = [];
|
|
200
|
+
let states = 0, parts = 0;
|
|
201
|
+
const recs = [];
|
|
202
|
+
for (const idx of idxs) {
|
|
203
|
+
const t = lines[idx].trim();
|
|
204
|
+
if (R.blind.test(t) || R.none.test(t) || R.forgiveness.test(t)) {
|
|
205
|
+
states++;
|
|
206
|
+
if (R.forgiveness.test(t)) { c.d('I005', idx, `"${t}" read as —`); c.forgive.push(idx); }
|
|
207
|
+
if (!R.none.test(t)) c.bs('lists');
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const p = parseRelLine(lines[idx], cx, R);
|
|
211
|
+
const rec = handleRel(S, c, p, idx, { legal, ordered: p.kind === 'rel' && p.rel === prefixless ? true : p.kind === 'rel' ? false : null, section: sd.section, sub: sd, strict: false, countBlind: true, defaultRel: prefixless, group });
|
|
212
|
+
if (rec && rec.rel === prefixless) { parts++; recs.push(rec); }
|
|
213
|
+
}
|
|
214
|
+
markIncomplete(S, c, recs);
|
|
215
|
+
if (states && parts) c.d('W015', sd.idx, "a variant's component list is either lines or — / none, not both");
|
|
216
|
+
if (group.length) c.groups.push(group);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function parseStepBody(S, c, sd) {
|
|
220
|
+
const { lines, mask } = c, R = S.R;
|
|
221
|
+
const shape = sd.glyph ? S.shapeByGlyph[sd.glyph] : null;
|
|
222
|
+
if (!shape) c.d('W025', sd.idx, 'step heading needs its glyph: ○ □ ◇ ◎ ⧉ ⚡');
|
|
223
|
+
sd.shape = shape ? shape.name : null;
|
|
224
|
+
const idxs = contentIdx(lines, bodyStart(sd), sd.end, mask);
|
|
225
|
+
if (idxs.length && parsePassport(lines[idxs[0]], R)) c.d('W024', idxs[0], 'steps carry no passport line (the glyph is the type)');
|
|
226
|
+
const bs = bodyState(lines, idxs, R);
|
|
227
|
+
if (bs === 'forgive') { c.d('I005', idxs[0], `"${lines[idxs[0]].trim()}" read as —`); c.forgive.push(idxs[0]); }
|
|
228
|
+
if (bs === 'blind' || bs === 'forgive') { c.bs('sections'); return; }
|
|
229
|
+
if (bs === 'none' || bs === 'empty') { if (shape) checkShape(c, sd, shape, {}); return; }
|
|
230
|
+
const legalMap = S.legalInSubdoc('flow-step');
|
|
231
|
+
const legal = new Set(legalMap.keys());
|
|
232
|
+
const counts = {};
|
|
233
|
+
const cx = relCx(S, null);
|
|
234
|
+
let primaries = 0;
|
|
235
|
+
for (const idx of idxs) {
|
|
236
|
+
const p = parseRelLine(lines[idx], cx, R);
|
|
237
|
+
if (p.kind === 'rel' && shape && legalMap.has(p.rel)) {
|
|
238
|
+
const e = legalMap.get(p.rel);
|
|
239
|
+
if ((e.shapes && !e.shapes.includes(shape.name)) || !shape.lines[p.rel]) {
|
|
240
|
+
c.d(shape.forbidden.includes(p.rel) ? 'W025' : 'W017', idx, `${p.rel} is not allowed on a ${shape.glyph} ${shape.name} step`);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const rec = handleRel(S, c, p, idx, { legal, ordered: p.kind === 'rel' ? false : null, section: sd.section, sub: sd, strict: false, countBlind: true });
|
|
245
|
+
if (!rec) continue;
|
|
246
|
+
counts[rec.rel] = (counts[rec.rel] || 0) + 1;
|
|
247
|
+
if (rec.rel === 'Branch' && rec.quals.some((q) => q.key === 'primary')) primaries++;
|
|
248
|
+
}
|
|
249
|
+
if (shape) checkShape(c, sd, shape, counts);
|
|
250
|
+
if (shape && shape.name === 'Fork' && primaries !== 1) c.d('I010', sd.idx, `a fork marks exactly one Branch with · primary (found ${primaries})`);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function checkShape(c, sd, shape, counts) {
|
|
254
|
+
for (const [rel, [lo, hi]] of Object.entries(shape.lines)) {
|
|
255
|
+
const n = counts[rel] || 0;
|
|
256
|
+
const own = shape.name === 'Connected flow' && rel === 'Connected flow';
|
|
257
|
+
if (n < lo) c.d(own ? 'W022' : 'W025', sd.idx, `${shape.glyph} ${shape.name} step needs ${lo === hi ? 'exactly' : 'at least'} ${lo} ${rel} line${lo > 1 ? 's' : ''}`);
|
|
258
|
+
if (n > hi) c.d('W022', sd.idx, `${shape.glyph} ${shape.name} step allows at most ${hi} ${rel} line${hi === 1 ? '' : 's'}`);
|
|
259
|
+
}
|
|
260
|
+
if (shape.atLeastOneOf.length && !shape.atLeastOneOf.some((r) => counts[r])) {
|
|
261
|
+
c.d('W025', sd.idx, `${shape.glyph} ${shape.name} step needs ${shape.atLeastOneOf.join(' or ')}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** userflow ## Step list: default list + ### flow variants. */
|
|
266
|
+
export function parseStepList(S, c, sec, def) {
|
|
267
|
+
const { lines, mask } = c, R = S.R;
|
|
268
|
+
const sub = splitSub(lines, sec.start, sec.end, mask);
|
|
269
|
+
const legal = S.legalIn(c.type, def.heading);
|
|
270
|
+
const cx = relCx(S, def.defaultRelation, true);
|
|
271
|
+
const fvKeys = S.raw.subdocuments['flow-variant'].passport.keys;
|
|
272
|
+
const parseList = (name, start, end, headIdx) => {
|
|
273
|
+
let idxs = contentIdx(lines, start, end, mask);
|
|
274
|
+
if (name !== null && idxs.length) {
|
|
275
|
+
const pp = parsePassport(lines[idxs[0]], R);
|
|
276
|
+
if (pp) { checkPassport(S, c, pp, idxs[0], fvKeys, 'a flow variant'); idxs = idxs.slice(1); }
|
|
277
|
+
}
|
|
278
|
+
const list = { name, idx: headIdx, items: [] };
|
|
279
|
+
c.stepLists.push(list);
|
|
280
|
+
const bs = bodyState(lines, idxs, R);
|
|
281
|
+
if (bs === 'blind' || bs === 'forgive') {
|
|
282
|
+
if (bs === 'forgive') { c.d('I005', idxs[0], `"${lines[idxs[0]].trim()}" read as —`); c.forgive.push(idxs[0]); }
|
|
283
|
+
c.bs('lists');
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (bs) return;
|
|
287
|
+
const group = [];
|
|
288
|
+
for (const idx of idxs) {
|
|
289
|
+
const p = parseRelLine(lines[idx], cx, R);
|
|
290
|
+
const rec = handleRel(S, c, p, idx, { legal, ordered: true, section: def.heading, flowVariant: name, strict: true, countBlind: true, defaultRel: def.defaultRelation, group });
|
|
291
|
+
if (rec) list.items.push(rec);
|
|
292
|
+
}
|
|
293
|
+
if (markIncomplete(S, c, list.items)) { list.items.pop(); list.incomplete = true; }
|
|
294
|
+
if (group.length) c.groups.push(group);
|
|
295
|
+
};
|
|
296
|
+
parseList(null, sub.intro[0], sub.intro[1], sec.idx);
|
|
297
|
+
const seen = new Set();
|
|
298
|
+
for (const s of sub.subs) {
|
|
299
|
+
if (R.subdoc.test(lines[s.idx])) { c.d('W023', s.idx, 'step heading outside ## Steps'); continue; }
|
|
300
|
+
if (seen.has(s.text)) c.d('W026', s.idx, `flow variant "${s.text}" repeated`);
|
|
301
|
+
seen.add(s.text);
|
|
302
|
+
c.flowVariants.add(s.text);
|
|
303
|
+
parseList(s.text, s.start, s.end, s.idx);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** Checks that need both ## Step list and ## Steps parsed. */
|
|
308
|
+
export function finishFlow(S, c) {
|
|
309
|
+
const steps = new Map(c.subs.filter((s) => s.kind === 'flow-step').map((s) => [s.core, s]));
|
|
310
|
+
const reached = new Set();
|
|
311
|
+
for (const list of c.stepLists) {
|
|
312
|
+
const items = list.items;
|
|
313
|
+
if (!items.length) continue;
|
|
314
|
+
let starts = 0;
|
|
315
|
+
items.forEach((it, k) => {
|
|
316
|
+
const a = it.atoms[0];
|
|
317
|
+
if (!a || (a.kind !== 'bound' && a.kind !== 'hand')) return;
|
|
318
|
+
const st = steps.get(a.core);
|
|
319
|
+
if (!st) { c.d('W026', it.idx, `#${a.core} is not a step of this flow`); return; }
|
|
320
|
+
reached.add(a.core);
|
|
321
|
+
if (st.shape === 'Start') starts++;
|
|
322
|
+
if (k === 0 && st.shape && st.shape !== 'Start') c.d('W026', it.idx, 'a step list starts with the ○ Start step');
|
|
323
|
+
});
|
|
324
|
+
if (starts > 1) c.d('W026', list.idx, 'a step list has exactly one ○ Start step');
|
|
325
|
+
if (items.length > 15) c.d('I004', list.idx, `${items.length} steps — consider a subflow (⧉ Connected flow)`);
|
|
326
|
+
const la = items[items.length - 1].atoms[0];
|
|
327
|
+
const last = la && steps.get(la.core);
|
|
328
|
+
if (!list.incomplete && last && last.shape && last.shape !== 'Finish' && last.shape !== 'Fork') c.d('I012', list.idx, 'a step list should end on a ◎ Finish or ◇ Fork');
|
|
329
|
+
}
|
|
330
|
+
for (const r of c.rels) {
|
|
331
|
+
if (r.rel !== 'Branch' || !r.atoms[0]) continue;
|
|
332
|
+
const a = r.atoms[0];
|
|
333
|
+
if (a.kind !== 'bound' && a.kind !== 'hand') continue;
|
|
334
|
+
if (!steps.has(a.core)) c.d('W018', r.idx, `Branch target #${a.core} is not a step of this flow`);
|
|
335
|
+
else reached.add(a.core);
|
|
336
|
+
}
|
|
337
|
+
for (const s of steps.values()) if (!reached.has(s.core)) c.d('I011', s.idx, `step #${s.core} is in no step list and no Branch`);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** ia ## Parts: indentation tree + ### Lateral. */
|
|
341
|
+
export function parseIaParts(S, c, sec, def) {
|
|
342
|
+
const { lines, mask } = c, R = S.R;
|
|
343
|
+
const sub = splitSub(lines, sec.start, sec.end, mask);
|
|
344
|
+
const idxs = contentIdx(lines, sub.intro[0], sub.intro[1], mask);
|
|
345
|
+
const bs = bodyState(lines, idxs, R);
|
|
346
|
+
const legal = S.legalIn(c.type, def.heading);
|
|
347
|
+
const cx = relCx(S, def.defaultRelation);
|
|
348
|
+
const stack = [];
|
|
349
|
+
let prev = -1;
|
|
350
|
+
if (!bs) for (const idx of idxs) {
|
|
351
|
+
const line = lines[idx];
|
|
352
|
+
if (/\t/.test(line) || R.iaBadIndent.test(line)) { c.d('W027', idx, 'indent the tree with two spaces per level, no tabs'); continue; }
|
|
353
|
+
const m = R.iaNode.exec(line);
|
|
354
|
+
if (!m) { c.d('W015', idx, `not a tree line "- <screen>": ${line.trim()}`); continue; }
|
|
355
|
+
const depth = m.groups.indent.length / 2;
|
|
356
|
+
if (depth > prev + 1) c.d('W027', idx, 'a line is at most one level deeper than its parent');
|
|
357
|
+
const p = parseRelLine(line, cx, R);
|
|
358
|
+
const rec = handleRel(S, c, p, idx, { legal, ordered: false, section: def.heading, strict: true, countBlind: true, tree: true, defaultRel: def.defaultRelation });
|
|
359
|
+
stack.length = depth;
|
|
360
|
+
const node = { idx, depth, rec, parent: depth > 0 ? stack[depth - 1] || null : null };
|
|
361
|
+
stack[depth] = node;
|
|
362
|
+
prev = depth;
|
|
363
|
+
c.iaNodes.push(node);
|
|
364
|
+
if (rec) rec.node = node;
|
|
365
|
+
}
|
|
366
|
+
markIncomplete(S, c, c.iaNodes.map((n) => n.rec).filter(Boolean));
|
|
367
|
+
const lat = S.legalIn(c.type, def.heading, 'Lateral');
|
|
368
|
+
for (const s of sub.subs) {
|
|
369
|
+
if (s.text !== 'Lateral') { c.d('W015', s.idx, `only ### Lateral may follow the tree in ## ${def.heading}`); continue; }
|
|
370
|
+
for (const idx of contentIdx(lines, s.start, s.end, mask)) {
|
|
371
|
+
const p = parseRelLine(lines[idx], relCx(S, null), R);
|
|
372
|
+
handleRel(S, c, p, idx, { legal: lat, ordered: false, section: def.heading, strict: true, countBlind: true });
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const placed = new Set(c.iaNodes.map((n) => n.rec?.atoms[0]?.core).filter(Boolean));
|
|
376
|
+
for (const r of c.rels) {
|
|
377
|
+
if (r.rel !== 'Edge') continue;
|
|
378
|
+
for (const a of r.atoms) if (a.core && !placed.has(a.core)) c.d('W027', r.idx, `Lateral endpoint #${a.core} is not placed on this map`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Intent Format 1.2 renamed headings, one key, one vocabulary and one qualifier so files read as plain
|
|
2
|
+
// language (schema.json → renames). Old spellings stay readable: every file is modernized as it is
|
|
3
|
+
// read, so parsers, regen and the app see only the new names; regen then writes the new names back,
|
|
4
|
+
// and `intent-format migrate` (standard: + regen) brings a whole KB up to date in one go.
|
|
5
|
+
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
6
|
+
|
|
7
|
+
/** The text of one file with the 1.0 spellings replaced by the 1.1 ones. Pure; idempotent. */
|
|
8
|
+
export function modernize(text, S) {
|
|
9
|
+
const r = S.renames;
|
|
10
|
+
if (!r) return text;
|
|
11
|
+
let t = text;
|
|
12
|
+
for (const [old, now] of Object.entries(r.headings || {})) t = t.replace(new RegExp('^(## )' + esc(old) + '[ \\t]*$', 'gmu'), '$1' + now);
|
|
13
|
+
for (const [old, now] of Object.entries(r.vocabularies || {})) t = t.replace(new RegExp('^(### )' + esc(old) + '[ \\t]*$', 'gmu'), '$1' + now);
|
|
14
|
+
for (const [old, now] of Object.entries(r.keys || {})) {
|
|
15
|
+
t = t.replace(new RegExp('^' + esc(old) + ':', 'gmu'), now + ':'); // front matter and passport lines
|
|
16
|
+
t = t.replace(new RegExp('( · )' + esc(old) + ':', 'gu'), '$1' + now + ':'); // passport pairs and qualifiers
|
|
17
|
+
}
|
|
18
|
+
for (const [old, now] of Object.entries(r.qualifiers || {})) t = t.replace(new RegExp('( · )' + esc(old) + ':', 'gu'), '$1' + now + ':');
|
|
19
|
+
return t;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** True when the text still carries a 1.0 spelling (for W001-style hints). */
|
|
23
|
+
export const isLegacy = (text, S) => modernize(text, S) !== text;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// Loads schema.json (located relative to this file) and derives lookup tables from it.
|
|
2
|
+
// Nothing here restates schema data: every table is computed from the JSON.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
|
|
7
|
+
export const SCHEMA_PATH = fileURLToPath(new URL('../../../schema.json', import.meta.url));
|
|
8
|
+
export const STANDARD_DIR = path.dirname(SCHEMA_PATH);
|
|
9
|
+
|
|
10
|
+
const CARD = 'card';
|
|
11
|
+
|
|
12
|
+
function parseCount(s) {
|
|
13
|
+
const m = /^(\d+)(\.\.(\d+)?)?$/.exec(s);
|
|
14
|
+
if (!m) return [0, Infinity];
|
|
15
|
+
const lo = +m[1];
|
|
16
|
+
if (!m[2]) return [lo, lo];
|
|
17
|
+
return [lo, m[3] === undefined ? Infinity : +m[3]];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function loadSchema(file = SCHEMA_PATH) {
|
|
21
|
+
const s = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
22
|
+
const flags = s.regexFlags || 'u';
|
|
23
|
+
const re = (src, extra = '') => new RegExp(src, flags + extra);
|
|
24
|
+
const g = s.grammar;
|
|
25
|
+
const R = {
|
|
26
|
+
fmLine: re(g.frontMatterLine),
|
|
27
|
+
quoted: re(g.values.quoted),
|
|
28
|
+
list: re(g.values.list),
|
|
29
|
+
needsQuotes: re(g.values.needsQuotes),
|
|
30
|
+
readsAsNonString: re(g.values.readsAsNonString),
|
|
31
|
+
core: re(g.core),
|
|
32
|
+
title: re(g.titleLine),
|
|
33
|
+
plainTitle: re(g.plainTitle),
|
|
34
|
+
statusLine: re(g.statusLine),
|
|
35
|
+
section: re(g.sectionHeading),
|
|
36
|
+
subsection: re(g.subsectionHeading),
|
|
37
|
+
subdoc: re(g.subdocumentHeading),
|
|
38
|
+
anchor: re(g.anchorLine),
|
|
39
|
+
passportLine: re(g.passportLine),
|
|
40
|
+
passportPair: re(g.passportPair),
|
|
41
|
+
listLine: re(g.listLine),
|
|
42
|
+
relationPrefix: re(g.relationPrefix),
|
|
43
|
+
stepGlyph: re(g.stepGlyph),
|
|
44
|
+
generatedLine: re(g.generatedLine),
|
|
45
|
+
qualifier: re(g.qualifier),
|
|
46
|
+
bound: re('^' + g.atoms.bound + '$'),
|
|
47
|
+
boundG: re(g.atoms.bound, 'g'),
|
|
48
|
+
hand: re('^' + g.atoms.hand + '$'),
|
|
49
|
+
handG: re(g.atoms.hand, 'g'),
|
|
50
|
+
placeholder: re('^' + g.atoms.placeholder + '$'),
|
|
51
|
+
placeholderG: re(g.atoms.placeholder, 'g'),
|
|
52
|
+
renderedG: re(g.atoms.renderedIdInReference, 'g'),
|
|
53
|
+
rendered: re(g.atoms.renderedIdInReference),
|
|
54
|
+
link: re(g.link),
|
|
55
|
+
iaNode: re(g.iaNodeLine),
|
|
56
|
+
iaBadIndent: re(g.iaBadIndent),
|
|
57
|
+
ordered: re(g.orderedLine),
|
|
58
|
+
incompleteItem: re(g.incompleteListItem),
|
|
59
|
+
blind: re(g.body.blindSpot),
|
|
60
|
+
none: re(g.body.none),
|
|
61
|
+
forgiveness: re(g.body.forgiveness),
|
|
62
|
+
whyNone: re(g.body.whyNone),
|
|
63
|
+
sameAs: re(g.body.sameAs),
|
|
64
|
+
askMarker: new RegExp(g.askMarker, 'gu'),
|
|
65
|
+
confidenceMark: re(g.confidenceMark),
|
|
66
|
+
reqMarker: re(g.requirementMarker),
|
|
67
|
+
userStory: re(g.userStory),
|
|
68
|
+
useCase: re(g.useCaseLine),
|
|
69
|
+
gwt: re(g.gwtLine),
|
|
70
|
+
ears: re(g.earsLine),
|
|
71
|
+
checklist: re(g.checklistLine),
|
|
72
|
+
tags: re(g.tagsLine),
|
|
73
|
+
doDont: re(g.doDontLine),
|
|
74
|
+
tableRow: re(g.tableRow),
|
|
75
|
+
tableSep: re(g.tableSeparator),
|
|
76
|
+
vocabBullet: re(g.vocabularyBullet),
|
|
77
|
+
filename: re(g.filename),
|
|
78
|
+
workspaceFolder: re(g.workspaceFolder),
|
|
79
|
+
version: re(g.version),
|
|
80
|
+
kbSlug: re(g.kbSlug),
|
|
81
|
+
origin: re(g.origin),
|
|
82
|
+
stateCode: re(g.stateCode),
|
|
83
|
+
idPattern: re(s.idPattern),
|
|
84
|
+
extPrefix: s.reservedPrefixes.filter((p) => !/SS/.test(p.pattern)).map((p) => re(p.pattern)),
|
|
85
|
+
reservedPrefix: s.reservedPrefixes.map((p) => re(p.pattern)),
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const roster = s.typeRoster;
|
|
89
|
+
const typeIndex = new Map(roster.map((t, i) => [t, i]));
|
|
90
|
+
const prefixOfType = {}, typeOfPrefix = {}, kindOfPrefix = {}, subdocPrefix = {};
|
|
91
|
+
for (const [p, d] of Object.entries(s.prefixes)) {
|
|
92
|
+
if (d.kind === CARD) { prefixOfType[d.type] = p; typeOfPrefix[p] = d.type; }
|
|
93
|
+
else { typeOfPrefix[p] = d.subdocument; subdocPrefix[d.subdocument] = p; }
|
|
94
|
+
kindOfPrefix[p] = d.kind;
|
|
95
|
+
}
|
|
96
|
+
const folderOfType = {}, typeOfFolder = {};
|
|
97
|
+
for (const t of roster) {
|
|
98
|
+
const f = s.types[t].folder;
|
|
99
|
+
folderOfType[t] = f;
|
|
100
|
+
if (f) typeOfFolder[f] = t;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Relation legality, from relations.*.authoredIn
|
|
104
|
+
const inSection = new Map(); // "type\0section[\0subsection]" -> Set(rel)
|
|
105
|
+
const inSubdoc = new Map(); // subdoc kind -> Map(rel -> {shapes, prefixless})
|
|
106
|
+
const prefixlessSubdoc = {};
|
|
107
|
+
for (const [name, r] of Object.entries(s.relations)) {
|
|
108
|
+
for (const a of r.authoredIn || []) {
|
|
109
|
+
if (a.subdocument && !a.passportKey) {
|
|
110
|
+
if (!inSubdoc.has(a.subdocument)) inSubdoc.set(a.subdocument, new Map());
|
|
111
|
+
inSubdoc.get(a.subdocument).set(name, { shapes: a.shapes || null, prefixless: !!a.prefixless });
|
|
112
|
+
if (a.prefixless) prefixlessSubdoc[a.subdocument] = name;
|
|
113
|
+
} else if (a.section) {
|
|
114
|
+
const k = [a.type, a.section, a.subsection].filter(Boolean).join('\0');
|
|
115
|
+
if (!inSection.has(k)) inSection.set(k, new Set());
|
|
116
|
+
inSection.get(k).add(name);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Step shapes
|
|
122
|
+
const fsDef = s.subdocuments['flow-step'];
|
|
123
|
+
const shapeByGlyph = {};
|
|
124
|
+
for (const [name, d] of Object.entries(fsDef.shapes)) {
|
|
125
|
+
const lines = {};
|
|
126
|
+
for (const [rel, c] of Object.entries(d.lines)) lines[rel] = parseCount(c);
|
|
127
|
+
for (const [rel, c] of Object.entries(fsDef.commonLines)) {
|
|
128
|
+
if ((d.excludeCommon || []).includes(rel) || lines[rel]) continue;
|
|
129
|
+
lines[rel] = parseCount(c);
|
|
130
|
+
}
|
|
131
|
+
shapeByGlyph[d.glyph] = { name, glyph: d.glyph, lines, atLeastOneOf: d.atLeastOneOf || [], forbidden: d.forbidden || [] };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const keyDefs = {};
|
|
135
|
+
for (const t of roster) {
|
|
136
|
+
const m = new Map();
|
|
137
|
+
for (const k of s.universalKeys) m.set(k.key, k);
|
|
138
|
+
for (const k of s.types[t].extras) m.set(k.key, k);
|
|
139
|
+
m.set(s.originKey.key, s.originKey);
|
|
140
|
+
keyDefs[t] = m;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const diag = new Map(s.diagnostics.map((d) => [d.code, d]));
|
|
144
|
+
|
|
145
|
+
const S = {
|
|
146
|
+
raw: s, R, roster, typeIndex, prefixOfType, typeOfPrefix, kindOfPrefix, subdocPrefix,
|
|
147
|
+
folderOfType, typeOfFolder, shapeByGlyph, diag,
|
|
148
|
+
standard: s.standard,
|
|
149
|
+
legacyStandards: s.legacyStandards || [],
|
|
150
|
+
renames: s.renames || null,
|
|
151
|
+
gear: s.conventions.gear,
|
|
152
|
+
relations: s.relations,
|
|
153
|
+
generated: s.generatedSections,
|
|
154
|
+
modules: s.workspace.moduleFolders,
|
|
155
|
+
lifecycles: s.lifecycles.values,
|
|
156
|
+
isCardType: (t) => typeIndex.has(t),
|
|
157
|
+
typeDef: (t) => s.types[t],
|
|
158
|
+
sections: (t) => s.types[t].sections,
|
|
159
|
+
sectionDef: (t, h) => s.types[t]?.sections.find((x) => x.heading === h) || null,
|
|
160
|
+
legalIn: (type, section, subsection) =>
|
|
161
|
+
inSection.get([type, section, subsection].filter(Boolean).join('\0')) || new Set(),
|
|
162
|
+
legalInSubdoc: (kind) => inSubdoc.get(kind) || new Map(),
|
|
163
|
+
prefixlessIn: (kind) => prefixlessSubdoc[kind] || null,
|
|
164
|
+
statusValues: (t) => s.statusVocabularies[s.types[t].statusVocabulary].values,
|
|
165
|
+
openStatuses: s.statusVocabularies.decision.open,
|
|
166
|
+
keyOrder: (t) => s.types[t].keys.map((k) => k.replace(/\?$/, '')),
|
|
167
|
+
keyDef: (t, k) => keyDefs[t]?.get(k) || null,
|
|
168
|
+
requiredKeys: (t) => s.types[t].keys.filter((k) => !k.endsWith('?')),
|
|
169
|
+
alwaysQuoted: new Set(s.frontMatter.values.alwaysQuoted),
|
|
170
|
+
reserved: s.vocabularies.reservedValues,
|
|
171
|
+
why: s.why || { questions: {}, requiredOn: [] },
|
|
172
|
+
ask: s.ask || null,
|
|
173
|
+
vocabName: (v) => (typeof v === 'string' && v.startsWith('@vocabulary:') ? v.slice(12) : null),
|
|
174
|
+
/** card type, sub-document kind, 'x' for extension prefixes, or null */
|
|
175
|
+
typeOfCore(core) {
|
|
176
|
+
const p = core.slice(0, 2);
|
|
177
|
+
if (typeOfPrefix[p]) return typeOfPrefix[p];
|
|
178
|
+
if (R.extPrefix.some((r) => r.test(p))) return 'x';
|
|
179
|
+
return null;
|
|
180
|
+
},
|
|
181
|
+
isSubdocKind: (k) => !!subdocPrefix[k],
|
|
182
|
+
hostOfKind: (k) => s.subdocuments[k]?.host || null,
|
|
183
|
+
};
|
|
184
|
+
return S;
|
|
185
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Blank cards, generated from schema.json. Used by build-kit (templates/<type>.md), init and new.
|
|
2
|
+
import { fmValue } from './parse.mjs';
|
|
3
|
+
|
|
4
|
+
/** Template core: the type prefix + 000000 (never minted). */
|
|
5
|
+
export const templateCore = (S, type) => S.prefixOfType[type] + '000000';
|
|
6
|
+
|
|
7
|
+
export const templateName = (type) => 'New ' + type.replace(/-/g, ' ');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Render a blank card. values: { id, name, status?, state?, feature?, parent?, ... } — keys are
|
|
11
|
+
* written in schema order; required keys get — (status: the type's templateStatus).
|
|
12
|
+
*/
|
|
13
|
+
export function renderCard(S, type, values = {}) {
|
|
14
|
+
const def = S.typeDef(type);
|
|
15
|
+
const v = { ...values };
|
|
16
|
+
v.id = v.id || templateCore(S, type);
|
|
17
|
+
v.name = v.name || templateName(type);
|
|
18
|
+
const fm = ['---'];
|
|
19
|
+
for (const raw of def.keys) {
|
|
20
|
+
const key = raw.replace(/\?$/, '');
|
|
21
|
+
if (key === 'x-*') continue;
|
|
22
|
+
const optional = raw.endsWith('?');
|
|
23
|
+
let val;
|
|
24
|
+
if (key === 'standard') val = S.standard;
|
|
25
|
+
else if (key === 'type') val = type;
|
|
26
|
+
else if (key === 'status') val = v.status ?? def.templateStatus;
|
|
27
|
+
else if (v[key] !== undefined && v[key] !== null) val = v[key];
|
|
28
|
+
else if (!optional) val = '—';
|
|
29
|
+
else continue;
|
|
30
|
+
const kd = S.keyDef(type, key);
|
|
31
|
+
fm.push(`${key}: ${fmValue(S, key, val, Array.isArray(kd?.values))}`);
|
|
32
|
+
}
|
|
33
|
+
fm.push('---');
|
|
34
|
+
const body = [`# ${v.name} · #${v.id}`];
|
|
35
|
+
if (def.preamble && def.preamble.required) body.push('', '—');
|
|
36
|
+
for (const sec of def.sections) {
|
|
37
|
+
if ((!sec.required && !sec.inTemplate) || sec.generated) continue;
|
|
38
|
+
body.push('', `## ${sec.heading}`, sec.template || '—');
|
|
39
|
+
}
|
|
40
|
+
return [...fm, ...body].join('\n') + '\n';
|
|
41
|
+
}
|