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,182 @@
|
|
|
1
|
+
// intent-format frame: what surrounds a screen at each of its placements (spec 6.4). Resolves the shell
|
|
2
|
+
// (S-SHELL-4), stacks the matching variants (S-SHELL-5), merges parts, filters navigation
|
|
3
|
+
// (S-SHELL-6) and quotes the contract (S-SHELL-7). A view over the files; nothing is stored.
|
|
4
|
+
|
|
5
|
+
const fmList = (c, key) => {
|
|
6
|
+
const e = c.fm.map.get(key);
|
|
7
|
+
if (!e || e.kind === 'empty' || e.kind === 'blind') return null;
|
|
8
|
+
return e.kind === 'list' ? e.items : [e.value];
|
|
9
|
+
};
|
|
10
|
+
const fmOne = (c, key) => fmList(c, key)?.[0] ?? null;
|
|
11
|
+
const qual = (r, key) => r.quals.find((q) => q.key === key)?.value ?? null;
|
|
12
|
+
const coreOf = (r) => r.atoms.find((a) => a.kind === 'bound' || a.kind === 'hand')?.core ?? null;
|
|
13
|
+
const bare = (v) => (v ? v.replace(/^#/, '') : null);
|
|
14
|
+
|
|
15
|
+
/** `2+` matches depth ≥ 2, `3` exactly 3; a level variant never matches an unknown depth. */
|
|
16
|
+
function levelMatches(spec, depth) {
|
|
17
|
+
if (!spec) return true;
|
|
18
|
+
if (depth == null) return false;
|
|
19
|
+
const m = /^(\d+)(\+?)$/.exec(spec);
|
|
20
|
+
if (!m) return false;
|
|
21
|
+
return m[2] ? depth >= +m[1] : depth === +m[1];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function passportOf(sd) {
|
|
25
|
+
const p = {};
|
|
26
|
+
for (const { key, value } of sd.passport || []) p[key] = value;
|
|
27
|
+
return p;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The default shell: the app shell of the platform and state for a Page, else the overlay of that presentation. */
|
|
31
|
+
function defaultShell(S, ws, pres, platform, state) {
|
|
32
|
+
let best = null;
|
|
33
|
+
for (const c of ws.cards) {
|
|
34
|
+
if (c.type !== 'shell') continue;
|
|
35
|
+
const kind = fmOne(c, 'shell-type');
|
|
36
|
+
if (pres === 'Page' ? kind !== 'app' : kind !== 'overlay' || fmOne(c, 'opens-as') !== pres) continue;
|
|
37
|
+
let score = 0;
|
|
38
|
+
const plats = fmList(c, 'platform');
|
|
39
|
+
if (plats && !plats.includes(S.reserved.Platforms)) { if (!platform || !plats.includes(platform)) continue; score += 2; }
|
|
40
|
+
const states = fmList(c, 'state');
|
|
41
|
+
if (states && !states.includes(S.reserved.States)) { if (!states.includes(state)) continue; score += 1; }
|
|
42
|
+
if (!best || score > best.score) best = { c, score };
|
|
43
|
+
}
|
|
44
|
+
return best?.c ?? null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Resolve one placement: { screen, platform, state, depth, presentation?, own, variantShell, ancestors }. */
|
|
48
|
+
export function resolvePlacement(S, ws, p) {
|
|
49
|
+
const res = (core) => ws.byCore.get(core);
|
|
50
|
+
const pres = p.presentation || 'Page';
|
|
51
|
+
const stepper = p.flow ? ws.cards.find((c) => c.type === 'shell' && fmOne(c, 'shell-type') === 'stepper' && fmOne(c, 'flow') === p.flow.id) : null;
|
|
52
|
+
const ladder = [
|
|
53
|
+
[bare(p.own), 'set on this placement'],
|
|
54
|
+
[bare(p.variantShell), 'from the screen variant'],
|
|
55
|
+
[stepper?.id ?? null, `the stepper of ${p.flow?.name}`],
|
|
56
|
+
[pres === 'Page' ? bare(fmOne(p.screen, 'shell')) : null, 'from the screen card'],
|
|
57
|
+
...(p.ancestors || []).map((a) => [bare(a), 'from the section above']),
|
|
58
|
+
];
|
|
59
|
+
// a shell whose platform: excludes this placement's platform is skipped on every rung
|
|
60
|
+
const fits = (c) => { const pl = fmList(c, 'platform'); return !pl || pl.includes(S.reserved.Platforms) || !p.platform || pl.includes(p.platform); };
|
|
61
|
+
let shell = null, via = 'no shell';
|
|
62
|
+
for (const [v, why] of ladder) {
|
|
63
|
+
if (!v) continue;
|
|
64
|
+
if (v === 'none') { via = `none (${why})`; return { shell: null, via, variants: [], parts: [], navigation: [], contract: [] }; }
|
|
65
|
+
const t = res(v);
|
|
66
|
+
if (t && !t.sub && t.card.type === 'shell' && fits(t.card)) { shell = t.card; via = why; break; }
|
|
67
|
+
}
|
|
68
|
+
if (!shell) { shell = defaultShell(S, ws, pres, p.platform, p.state); if (shell) via = 'by default'; }
|
|
69
|
+
if (!shell) return { shell: null, via, variants: [], parts: [], navigation: [], contract: [] };
|
|
70
|
+
|
|
71
|
+
const variants = shell.subs.filter((sd) => sd.kind === 'shell-variant').filter((sd) => {
|
|
72
|
+
const pp = passportOf(sd);
|
|
73
|
+
if (pp.platform && !pp.platform.split(',').map((x) => x.trim()).includes(p.platform)) return false;
|
|
74
|
+
if (pp.state && pp.state !== S.reserved.States && pp.state !== p.state) return false;
|
|
75
|
+
return levelMatches(pp.level, p.depth);
|
|
76
|
+
});
|
|
77
|
+
const active = new Set([null, ...variants]);
|
|
78
|
+
const parts = [], seen = new Set();
|
|
79
|
+
for (const r of shell.rels) {
|
|
80
|
+
if (r.rel !== 'Part' || !active.has(r.sub)) continue;
|
|
81
|
+
const core = coreOf(r);
|
|
82
|
+
if (!core || seen.has(core)) continue;
|
|
83
|
+
seen.add(core);
|
|
84
|
+
const t = res(core);
|
|
85
|
+
parts.push({ core, name: t?.card?.name ?? core, appearsAs: qual(r, 'opens-as'), from: r.sub ? r.sub.name : null });
|
|
86
|
+
}
|
|
87
|
+
const has = (x) => { const h = /^#?([A-Z]{2}\d{6})$/.exec(x); return parts.find((pt) => (h ? pt.core === h[1] : pt.name.toLowerCase() === x.toLowerCase())); };
|
|
88
|
+
const navigation = [];
|
|
89
|
+
for (const r of shell.rels) {
|
|
90
|
+
if (r.rel !== 'Leads to' || r.sub) continue;
|
|
91
|
+
const plats = qual(r, 'platform')?.split(',').map((x) => x.trim());
|
|
92
|
+
if (plats && !plats.includes(p.platform)) continue;
|
|
93
|
+
const st = qual(r, 'state');
|
|
94
|
+
if (st && st !== S.reserved.States && st !== p.state) continue;
|
|
95
|
+
let where = null;
|
|
96
|
+
if (r.inParts?.length) { where = r.inParts.map(has).find(Boolean); if (!where) continue; }
|
|
97
|
+
const core = coreOf(r);
|
|
98
|
+
const t = core && res(core);
|
|
99
|
+
navigation.push({ core, name: t ? (t.sub ? t.sub.name : t.card.name) : r.atoms[0]?.name ?? '—', label: qual(r, 'label'), kind: qual(r, 'kind') || 'link', in: where?.name ?? null });
|
|
100
|
+
}
|
|
101
|
+
const sec = shell.sk.sections.find((s) => s.heading === 'Places inside');
|
|
102
|
+
const contract = sec ? shell.lines.slice(sec.start, sec.end).map((l) => l.trim()).filter(Boolean) : [];
|
|
103
|
+
return { shell, via, variants, parts, navigation, contract };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Every placement of a screen: map nodes, flow steps, else the screen alone; one row per platform. */
|
|
107
|
+
export function frameOf(S, ws, screen) {
|
|
108
|
+
const res = (core) => ws.byCore.get(core);
|
|
109
|
+
const declared = [...(ws.vocab.values.Platforms || [])];
|
|
110
|
+
const allStates = [...(ws.vocab.values.States || [])];
|
|
111
|
+
const own = fmList(screen, 'state')?.filter((x) => x !== S.reserved.States);
|
|
112
|
+
// a stated map or flow state wins; else the states the screen exists in; else every State
|
|
113
|
+
const statesFor = (st) => (st && st !== S.reserved.States ? [st] : own?.length ? own : allStates.length ? allStates : [S.reserved.States]);
|
|
114
|
+
const rows = [];
|
|
115
|
+
const add = (where, platforms, st, base) => {
|
|
116
|
+
for (const state of statesFor(st)) for (const platform of platforms.length ? platforms : [null]) rows.push({ where, platform, state, ...resolvePlacement(S, ws, { ...base, screen, platform, state }) });
|
|
117
|
+
};
|
|
118
|
+
const pinned = (r) => {
|
|
119
|
+
const v = qual(r, 'variant');
|
|
120
|
+
if (!v) return null;
|
|
121
|
+
return screen.subs.find((sd) => sd.name === v || sd.core === bare(v)) || null;
|
|
122
|
+
};
|
|
123
|
+
const presOf = (r, sd) => qual(r, 'opens-as') || passportOf(sd || {})['opens-as'] || fmOne(screen, 'opens-as') || 'Page';
|
|
124
|
+
for (const m of ws.cards) {
|
|
125
|
+
if (m.type !== 'ia') continue;
|
|
126
|
+
const plats = fmList(m, 'platform')?.filter((x) => x !== S.reserved.Platforms) || declared;
|
|
127
|
+
const state = fmOne(m, 'state');
|
|
128
|
+
for (const n of m.iaNodes) {
|
|
129
|
+
if (!n.rec || coreOf(n.rec) !== screen.id) continue;
|
|
130
|
+
const path = [], ancestors = [];
|
|
131
|
+
for (let a = n.parent; a; a = a.parent) {
|
|
132
|
+
const t = a.rec && res(coreOf(a.rec) || '');
|
|
133
|
+
path.unshift(t ? t.card.name : '?');
|
|
134
|
+
if (a.rec) ancestors.push(qual(a.rec, 'shell'));
|
|
135
|
+
}
|
|
136
|
+
const sd = pinned(n.rec);
|
|
137
|
+
add(`${m.name} › ${[...path, screen.name].join(' › ')}`, plats, state, { depth: n.depth + 1, presentation: presOf(n.rec, sd), own: qual(n.rec, 'shell'), variantShell: passportOf(sd || {}).shell, ancestors });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const f of ws.cards) {
|
|
141
|
+
if (f.type !== 'userflow') continue;
|
|
142
|
+
const state = fmOne(f, 'state');
|
|
143
|
+
const fplats = fmList(f, 'platform')?.filter((x) => x !== S.reserved.Platforms);
|
|
144
|
+
for (const r of f.rels) {
|
|
145
|
+
if (r.rel !== 'Screen' || coreOf(r) !== screen.id) continue;
|
|
146
|
+
const sd = pinned(r);
|
|
147
|
+
add(`${f.name} › ${r.sub ? r.sub.name : 'step'}`, fplats?.length ? fplats : declared, state, { depth: null, presentation: presOf(r, sd), own: qual(r, 'shell'), variantShell: passportOf(sd || {}).shell, flow: f });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!rows.length) add('not placed on a map or flow', declared, null, { depth: null, presentation: fmOne(screen, 'opens-as') || 'Page' });
|
|
151
|
+
return rows;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Group placements that resolve to the same frame; print each frame once, its contract once per shell. */
|
|
155
|
+
export function renderFrame(screen, rows) {
|
|
156
|
+
const out = [`${screen.name} · #${screen.id}`];
|
|
157
|
+
const groups = new Map();
|
|
158
|
+
for (const r of rows) {
|
|
159
|
+
const key = JSON.stringify([r.shell?.id ?? r.via, r.variants.map((v) => v.core), r.parts.map((p) => p.core), r.navigation.map((n) => [n.core, n.label, n.in])]);
|
|
160
|
+
if (!groups.has(key)) groups.set(key, { r, at: new Map() });
|
|
161
|
+
const g = groups.get(key), where = `${r.where} · ${r.state}`;
|
|
162
|
+
if (!g.at.has(where)) g.at.set(where, []);
|
|
163
|
+
if (r.platform) g.at.get(where).push(r.platform);
|
|
164
|
+
}
|
|
165
|
+
const contracts = new Map();
|
|
166
|
+
let n = 0;
|
|
167
|
+
for (const { r, at } of groups.values()) {
|
|
168
|
+
out.push('');
|
|
169
|
+
if (!r.shell) out.push(`${++n}. ${r.via}`);
|
|
170
|
+
else {
|
|
171
|
+
out.push(`${++n}. #${r.shell.id} ${r.shell.name} (${r.shell.fm.map.get('shell-type')?.value}) — ${r.via}${r.variants.length ? ' · + ' + r.variants.map((v) => v.name).join(' + ') : ''}`);
|
|
172
|
+
if (r.contract.length) contracts.set(r.shell.id, r);
|
|
173
|
+
}
|
|
174
|
+
for (const [where, plats] of at) out.push(` at ${where}${plats.length ? ' — ' + plats.join(', ') : ''}`);
|
|
175
|
+
if (!r.shell) continue;
|
|
176
|
+
out.push(` parts ${r.parts.map((p) => p.name + (p.appearsAs ? ` (${p.appearsAs})` : '')).join(' · ') || 'none'}`);
|
|
177
|
+
out.push(` leads ${r.navigation.map((x) => `${x.label || x.name} (${[x.kind, x.in].filter(Boolean).join(', ')})`).join(' · ') || 'none'}`);
|
|
178
|
+
}
|
|
179
|
+
for (const r of contracts.values()) out.push('', `Places inside — #${r.shell.id} ${r.shell.name}:`, ...r.contract.map((l) => ` ${l}`));
|
|
180
|
+
if (!contracts.size && rows.some((r) => r.shell)) out.push('', 'No ## Places inside on these shells — the frame states no rules yet.');
|
|
181
|
+
return out.join('\n');
|
|
182
|
+
}
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
// Pure generation: generated sections, status lines, change fingerprints, rosters, _ids.md, CHANGES.md.
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { relLink, cut, escapeCell, toPosix, sortBy } from './util.mjs';
|
|
4
|
+
import { contentIdx, bodyState } from './parse.mjs';
|
|
5
|
+
import { targetType, targetName, highWater } from './project.mjs';
|
|
6
|
+
|
|
7
|
+
/* ---------------- references ---------------- */
|
|
8
|
+
|
|
9
|
+
export function ref(fromFile, t) {
|
|
10
|
+
const core = t.sub ? t.sub.core : t.card.id;
|
|
11
|
+
const p = relLink(fromFile, t.card.file) + (t.sub ? '#' + t.sub.core.toLowerCase() : '');
|
|
12
|
+
return `[#${core} ${targetName(t)}](${p})`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const homeOf = (c) => {
|
|
16
|
+
const v = c.fm?.map.get('feature')?.value;
|
|
17
|
+
return v && /^FT\d{6}$/.test(v) ? v : null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Resolve a `· variant:` pin (name or core) to a sub-document of the target card. */
|
|
21
|
+
export function pinSub(card, value) {
|
|
22
|
+
if (!value) return null;
|
|
23
|
+
const core = value.replace(/^#/, '');
|
|
24
|
+
return card.subs.find((s) => s.kind !== 'flow-step' && (s.core === core || s.name === value)) || null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* ---------------- one-liner ---------------- */
|
|
28
|
+
|
|
29
|
+
export function oneLiner(S, ws, card) {
|
|
30
|
+
const { lines, sk, mask } = card;
|
|
31
|
+
let start, end;
|
|
32
|
+
if (card.def.preamble) { start = sk.preStart; end = sk.preEnd; }
|
|
33
|
+
else {
|
|
34
|
+
const dr = sk.sections.find((s) => s.full === 'Description')
|
|
35
|
+
|| sk.sections.find((s) => !s.gear && s.def && s.def.content === 'prose');
|
|
36
|
+
if (!dr) return '—';
|
|
37
|
+
start = dr.start; end = dr.end;
|
|
38
|
+
}
|
|
39
|
+
const idxs = contentIdx(lines, start, end, mask);
|
|
40
|
+
const bs = bodyState(lines, idxs, S.R);
|
|
41
|
+
if (bs && bs !== 'none') return '—';
|
|
42
|
+
const para = [];
|
|
43
|
+
for (let i = idxs[0]; i < end && lines[i].trim() !== '' && !mask[i]; i++) para.push(lines[i].trim());
|
|
44
|
+
let text = para.join(' ').replace(/^\*\*R\d+ · [^*]+\*\*\s*/, '');
|
|
45
|
+
text = text.replace(S.R.boundG, (...a) => {
|
|
46
|
+
const g = a[a.length - 1];
|
|
47
|
+
const t = ws.byCore.get(g.core);
|
|
48
|
+
return t ? targetName(t) : (g.name || '#' + g.core);
|
|
49
|
+
});
|
|
50
|
+
text = text.replace(S.R.handG, (...a) => { const t = ws.byCore.get(a[a.length - 1].core); return t ? targetName(t) : a[0]; });
|
|
51
|
+
text = text.replace(S.R.placeholderG, (...a) => a[a.length - 1].name)
|
|
52
|
+
.replace(/\[([^\]]+)\]\([^)]*\)/g, '$1').replace(/\*\*/g, '').replace(/\s+/g, ' ').trim();
|
|
53
|
+
const m = /^(.*?[.?!])(?=\s|$)/u.exec(text);
|
|
54
|
+
if (m) text = m[1];
|
|
55
|
+
return text ? cut(text, 120) : '—';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* ---------------- edges ---------------- */
|
|
59
|
+
|
|
60
|
+
export function collectEdges(S, ws) {
|
|
61
|
+
const edges = [];
|
|
62
|
+
const enabled = (c) => !S.folderOfType[c.type] || ws.modules.includes(S.folderOfType[c.type]);
|
|
63
|
+
const roleByName = new Map();
|
|
64
|
+
for (const c of ws.cards) if (c.type === 'role' && c.id && c.name && !roleByName.has(c.name)) roleByName.set(c.name, { card: c, sub: null });
|
|
65
|
+
for (const c of ws.cards) {
|
|
66
|
+
if (!c.id || !enabled(c)) continue;
|
|
67
|
+
// user stories name a role by its card name → ⚙ Stories on the role
|
|
68
|
+
for (const st of c.stories || []) {
|
|
69
|
+
const t = roleByName.get(st.role);
|
|
70
|
+
if (t && t.card !== c) edges.push({ rel: 'Story', src: c, at: null, t, rec: null, story: st.n ? 'R' + st.n : 'User stories' });
|
|
71
|
+
}
|
|
72
|
+
for (const r of c.rels) {
|
|
73
|
+
const def = S.relations[r.rel];
|
|
74
|
+
if (r.rel === 'Branch') {
|
|
75
|
+
const rq = r.quals.find((q) => q.key === 'rule');
|
|
76
|
+
const h = rq && rq.value && S.R.hand.exec(rq.value);
|
|
77
|
+
const t = h && ws.byCore.get(h.groups.core);
|
|
78
|
+
if (t && !t.sub && t.card.type === 'rule') edges.push({ rel: 'Branch', src: c, at: r.sub?.core || null, t, rec: r });
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (!def.generatedReverse) continue;
|
|
82
|
+
for (const a of r.atoms) {
|
|
83
|
+
if (a.kind !== 'bound' && a.kind !== 'hand') continue;
|
|
84
|
+
const t = ws.byCore.get(a.core);
|
|
85
|
+
if (!t || (def.targetTypes.length && !def.targetTypes.includes(targetType(t)))) continue;
|
|
86
|
+
const pin = !t.sub && r.variant ? pinSub(t.card, r.variant) : null;
|
|
87
|
+
edges.push({ rel: r.rel, src: c, at: r.sub?.core || null, t, pin, rec: r });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const [key, rel, type] of [['feature', 'Home', 'feature'], ['parent', 'Parent', 'feature'], ['flow', 'Realises', 'userflow']]) {
|
|
91
|
+
const v = c.fm.map.get(key)?.value;
|
|
92
|
+
const t = v && ws.byCore.get(v);
|
|
93
|
+
if (t && !t.sub && t.card.type === type && t.card !== c) edges.push({ rel, src: c, at: null, t, rec: null });
|
|
94
|
+
}
|
|
95
|
+
// framing (shell: keys, variant passports, · shell: on IA nodes and step Screen lines) → ⚙ Wraps on the shell
|
|
96
|
+
const shellOf = (v) => {
|
|
97
|
+
const t = v && /^SH\d{6}$/.test(v) && ws.byCore.get(v);
|
|
98
|
+
return t && !t.sub && t.card.type === 'shell' ? t : null;
|
|
99
|
+
};
|
|
100
|
+
if (c.type === 'screen') {
|
|
101
|
+
const t = shellOf(c.fm.map.get('shell')?.value);
|
|
102
|
+
if (t) edges.push({ rel: 'Shell', src: c, at: null, t, rec: null });
|
|
103
|
+
for (const sd of c.subs) {
|
|
104
|
+
const t2 = shellOf(sd.passport?.find((x) => x.key === 'shell')?.value);
|
|
105
|
+
if (t2) edges.push({ rel: 'Shell', src: c, at: sd.core, t: t2, rec: null });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
for (const r of c.rels) {
|
|
109
|
+
if (r.rel !== 'Node' && r.rel !== 'Screen') continue;
|
|
110
|
+
const t = shellOf(r.quals.find((x) => x.key === 'shell')?.value?.replace(/^#/, ''));
|
|
111
|
+
if (!t) continue;
|
|
112
|
+
edges.push({ rel: 'Shell', src: c, at: r.rel === 'Node' ? r.atoms[0]?.core || null : r.sub?.core || null, t, rec: r });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return edges;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* ---------------- generated sections ---------------- */
|
|
119
|
+
|
|
120
|
+
function lineText(card, l) {
|
|
121
|
+
const q = l.quals.map(([k, v]) => ` · ${k}: ${v}`).join('');
|
|
122
|
+
return `- ${ref(card.file, { card: l.card, sub: null })}${q}${l.note ? ' — ' + l.note : ''}`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function finish(S, card, lines) {
|
|
126
|
+
const seen = new Set(), out = [];
|
|
127
|
+
for (const l of lines) {
|
|
128
|
+
const k = l.card.id + '|' + l.quals.map((x) => x.join('=')).join('|') + '|' + (l.note || '');
|
|
129
|
+
if (seen.has(k)) continue;
|
|
130
|
+
seen.add(k);
|
|
131
|
+
out.push(l);
|
|
132
|
+
}
|
|
133
|
+
sortBy(out, (l) => S.typeIndex.get(l.card.type) ?? 99, (l) => l.card.id, (l) => l.quals.map((x) => x[1]).join(' '));
|
|
134
|
+
return out.map((l) => lineText(card, l));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function makeContext(S, ws) {
|
|
138
|
+
const edges = collectEdges(S, ws);
|
|
139
|
+
const partsOf = new Map();
|
|
140
|
+
for (const e of edges) {
|
|
141
|
+
if (e.rel !== 'Part') continue;
|
|
142
|
+
const key = e.src.id + '|' + (e.at || '');
|
|
143
|
+
if (!partsOf.has(key)) partsOf.set(key, { holder: { card: e.src, at: e.at }, parts: [] });
|
|
144
|
+
partsOf.get(key).parts.push({ comp: e.t.card, pin: e.pin });
|
|
145
|
+
}
|
|
146
|
+
return { S, ws, edges, partsOf, oneLiners: new Map() };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function closure(ctx, comp, pin, seen = new Set()) {
|
|
150
|
+
const key = comp.id + '|' + (pin ? pin.core : '');
|
|
151
|
+
if (seen.has(key)) return seen;
|
|
152
|
+
seen.add(key);
|
|
153
|
+
for (const p of ctx.partsOf.get(key)?.parts || []) closure(ctx, p.comp, p.pin, seen);
|
|
154
|
+
return seen;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function usedOn(ctx, card) {
|
|
158
|
+
const out = [];
|
|
159
|
+
for (const { holder, parts } of ctx.partsOf.values()) {
|
|
160
|
+
if (holder.card === card) continue;
|
|
161
|
+
const at = holder.at ? [['at', '#' + holder.at]] : [];
|
|
162
|
+
for (const p of parts) {
|
|
163
|
+
if (p.comp === card) { out.push({ card: holder.card, quals: [...at] }); continue; }
|
|
164
|
+
const reach = closure(ctx, p.comp, p.pin);
|
|
165
|
+
if ([...reach].some((k) => k.startsWith(card.id + '|'))) out.push({ card: holder.card, quals: [...at, ['via', '#' + p.comp.id]] });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function homedFlows(ctx, card) {
|
|
172
|
+
return ctx.edges.filter((e) => e.rel === 'Home' && e.t.card === card && e.src.type === 'userflow').map((e) => e.src);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function alsoLines(ctx, card, rels) {
|
|
176
|
+
const out = [];
|
|
177
|
+
for (const f of homedFlows(ctx, card)) {
|
|
178
|
+
for (const e of ctx.edges) {
|
|
179
|
+
if (e.src !== f || !rels.includes(e.rel) || e.t.sub) continue;
|
|
180
|
+
const h = homeOf(e.t.card);
|
|
181
|
+
if (!h || h === card.id || !ctx.ws.byCore.has(h)) continue;
|
|
182
|
+
out.push({ card: e.t.card, quals: [['home', '#' + h]] });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function reverse(ctx, card, heading) {
|
|
189
|
+
const { S } = ctx;
|
|
190
|
+
const g = S.generated[heading];
|
|
191
|
+
const withAt = /· at:/.test(g.line);
|
|
192
|
+
const bySource = S.relations.Home?.generatedReverse?.bySource || {};
|
|
193
|
+
const out = [];
|
|
194
|
+
for (const e of ctx.edges) {
|
|
195
|
+
if (e.t.card !== card || !g.from.includes(e.rel)) continue;
|
|
196
|
+
if (e.rel === 'Home' && bySource[e.src.type] !== heading) continue;
|
|
197
|
+
const l = { card: e.src, quals: [] };
|
|
198
|
+
const at = e.at || (e.t.sub && e.t.sub.core) || (e.pin && e.pin.core) || null;
|
|
199
|
+
if (withAt && at) l.quals.push(['at', '#' + at]);
|
|
200
|
+
switch (heading) {
|
|
201
|
+
case '⚙ On maps': {
|
|
202
|
+
const pa = e.rec?.node?.parent?.rec?.atoms[0];
|
|
203
|
+
const pt = pa && pa.core && ctx.ws.byCore.get(pa.core);
|
|
204
|
+
if (pt && !pt.sub && pt.card.type === 'screen') l.quals.push(['under', '#' + pt.card.id]);
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
case '⚙ Edge cases': {
|
|
208
|
+
const sv = e.src.fm.map.get('severity')?.value;
|
|
209
|
+
if (sv && sv !== '—') l.quals.push(['severity', sv]);
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
case '⚙ Connected from': {
|
|
213
|
+
const k = e.rec.quals.find((q) => q.key === 'kind');
|
|
214
|
+
if (k && k.value) l.quals.push(['kind', k.value]);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case '⚙ Entered from':
|
|
218
|
+
l.quals.push(['as', e.rel === 'Hand-off' ? 'hand-off' : e.rec.sub && e.rec.sub.shape === 'Connected flow' ? 'subflow' : 'attached']);
|
|
219
|
+
break;
|
|
220
|
+
case '⚙ Decisions':
|
|
221
|
+
l.quals.push(['status', e.src.status || '—']);
|
|
222
|
+
break;
|
|
223
|
+
case '⚙ Stories':
|
|
224
|
+
l.quals.push(['story', e.story]);
|
|
225
|
+
break;
|
|
226
|
+
case '⚙ Reached from': {
|
|
227
|
+
const k = e.rec?.quals.find((q) => q.key === 'kind');
|
|
228
|
+
if (k && k.value) l.quals.push(['kind', k.value]);
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
case '⚙ Sub-features': {
|
|
232
|
+
const ol = oneLiner(S, ctx.ws, e.src);
|
|
233
|
+
if (ol !== '—') l.note = ol;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
default: break;
|
|
237
|
+
}
|
|
238
|
+
out.push(l);
|
|
239
|
+
}
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Generated sections of one card, in registry order, only those with content. */
|
|
244
|
+
export function generatedFor(ctx, card) {
|
|
245
|
+
const { S } = ctx;
|
|
246
|
+
const out = [];
|
|
247
|
+
for (const sec of S.sections(card.type)) {
|
|
248
|
+
if (!sec.generated || !S.generated[sec.heading]) continue;
|
|
249
|
+
let lines;
|
|
250
|
+
if (sec.heading === '⚙ Used in') lines = usedOn(ctx, card);
|
|
251
|
+
else if (sec.heading === '⚙ Also uses') lines = alsoLines(ctx, card, ['Screen']);
|
|
252
|
+
else if (sec.heading === '⚙ Also connects') lines = alsoLines(ctx, card, ['Connected flow', 'Hand-off']);
|
|
253
|
+
else lines = reverse(ctx, card, sec.heading);
|
|
254
|
+
const text = finish(S, card, lines);
|
|
255
|
+
if (text.length) out.push({ heading: sec.heading, lines: text });
|
|
256
|
+
}
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/* ---------------- versions: fingerprints and status lines ---------------- */
|
|
261
|
+
|
|
262
|
+
export function fingerprint(S, card) {
|
|
263
|
+
const R = S.R;
|
|
264
|
+
const norm = (arr) => {
|
|
265
|
+
const out = [];
|
|
266
|
+
for (let l of arr) {
|
|
267
|
+
if (R.anchor.test(l) || R.generatedLine.test(l.trimStart())) continue;
|
|
268
|
+
l = l.replace(R.boundG, (...a) => '#' + a[a.length - 1].core).replace(/^(\s*)\d+\. /, '$1#. ').replace(/\s+$/, '');
|
|
269
|
+
if (R.forgiveness.test(l.trim())) l = '—';
|
|
270
|
+
if (l === '' && (out.length === 0 || out[out.length - 1] === '')) continue;
|
|
271
|
+
out.push(l);
|
|
272
|
+
}
|
|
273
|
+
while (out.length && out[out.length - 1] === '') out.pop();
|
|
274
|
+
return out.join('\n');
|
|
275
|
+
};
|
|
276
|
+
const parts = new Map();
|
|
277
|
+
const pp = card.fm.entries.filter((e) => e.key !== 'standard').map((e) => `${e.key}: ${e.value}`);
|
|
278
|
+
const tm = card.sk.titleIdx >= 0 ? S.R.title.exec(card.lines[card.sk.titleIdx]) : null;
|
|
279
|
+
parts.set('Passport', pp.join('\n') + '\n# ' + (tm ? tm.groups.name : card.name));
|
|
280
|
+
const pre = norm(card.lines.slice(card.sk.preStart, card.sk.preEnd));
|
|
281
|
+
if (pre) parts.set('Preamble', pre);
|
|
282
|
+
for (const sec of card.sk.sections) if (!sec.gear) parts.set(sec.heading, norm(card.lines.slice(sec.start, sec.end)));
|
|
283
|
+
return parts;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function changeOf(S, ws, card) {
|
|
287
|
+
if (!ws.basedOn || !ws.base) return null;
|
|
288
|
+
const b = ws.base.byCore.get(card.id);
|
|
289
|
+
if (!b || b.sub || b.card.kind !== 'card') return { state: 'new' };
|
|
290
|
+
const fa = fingerprint(S, card), fb = fingerprint(S, b.card);
|
|
291
|
+
const parts = [];
|
|
292
|
+
for (const [k, v] of fa) if (fb.get(k) !== v) parts.push(k);
|
|
293
|
+
for (const k of fb.keys()) if (!fa.has(k)) parts.push(k);
|
|
294
|
+
return parts.length ? { state: 'changed', parts } : { state: 'unchanged' };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export function stateCode(S, ws, card) {
|
|
298
|
+
if (!ws.vocab.declared.has('States')) return '';
|
|
299
|
+
const st = card.fm.map.get('state');
|
|
300
|
+
if (!st) return 'SG';
|
|
301
|
+
if (st.kind === 'blind') return '';
|
|
302
|
+
const vals = st.kind === 'list' ? st.items : [st.value];
|
|
303
|
+
if (vals.length !== 1 || vals[0] === S.reserved.States) return 'SG';
|
|
304
|
+
return ws.vocab.stateCodes.get(vals[0]) || '';
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function statusLine(S, ws, card, change) {
|
|
308
|
+
const v = ws.version;
|
|
309
|
+
let s = `> ${S.gear} #${card.id}${stateCode(S, ws, card)}V${v} · V${v} ${ws.lifecycle || 'in-progress'}`;
|
|
310
|
+
if (ws.basedOn) {
|
|
311
|
+
s += ` · based on V${ws.basedOn}`;
|
|
312
|
+
if (change) s += ' · ' + (change.state === 'changed' ? 'changed: ' + change.parts.join(', ') : change.state);
|
|
313
|
+
}
|
|
314
|
+
return s;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/* ---------------- generated files ---------------- */
|
|
318
|
+
|
|
319
|
+
const fmBlock = (S, name) => ['---', `standard: ${S.standard}`, 'type: index', `name: ${name}`, '---'];
|
|
320
|
+
|
|
321
|
+
export function folderTitle(folder) {
|
|
322
|
+
const special = { userflows: 'User flows', ia: 'IA maps', apis: 'APIs' };
|
|
323
|
+
return special[folder] || folder[0].toUpperCase() + folder.slice(1).replace(/-/g, ' ');
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export function renderFolderIndex(S, ws, folder) {
|
|
327
|
+
const type = S.typeOfFolder[folder];
|
|
328
|
+
const dir = path.join(ws.dir, folder);
|
|
329
|
+
const file = path.join(dir, '_index.md');
|
|
330
|
+
const cards = sortBy(ws.cards.filter((c) => c.type === type && c.id && path.dirname(c.file) === dir), (c) => c.id);
|
|
331
|
+
const name = folderTitle(folder);
|
|
332
|
+
const out = [...fmBlock(S, name), `# ${name}`, '', S.typeDef(type).purpose];
|
|
333
|
+
if (cards.length) {
|
|
334
|
+
const keys = S.keyOrder(type);
|
|
335
|
+
const states = ws.vocab.declared.has('States') && keys.includes('state');
|
|
336
|
+
const memb = keys.includes('feature') ? ['Feature', 'feature'] : keys.includes('parent') ? ['Parent', 'parent'] : null;
|
|
337
|
+
const cols = ['ID', 'Name', 'Status', ...(states ? ['State'] : []), ...(memb ? [memb[0]] : []), 'One-liner', 'Blind spots'];
|
|
338
|
+
out.push('', `## ${S.gear} Contents`, `| ${cols.join(' | ')} |`, `|${cols.map(() => '---').join('|')}|`);
|
|
339
|
+
for (const c of cards) {
|
|
340
|
+
const row = [`[#${c.id}](${relLink(file, c.file)})`, escapeCell(c.name || '—'), escapeCell(c.status || '—')];
|
|
341
|
+
if (states) row.push(escapeCell(c.fm.map.get('state')?.value || S.reserved.States));
|
|
342
|
+
if (memb) {
|
|
343
|
+
const v = c.fm.map.get(memb[1])?.value;
|
|
344
|
+
const t = v && ws.byCore.get(v);
|
|
345
|
+
row.push(t ? escapeCell(ref(file, t)) : '—');
|
|
346
|
+
}
|
|
347
|
+
row.push(escapeCell(oneLiner(S, ws, c)), String(c.blind));
|
|
348
|
+
out.push(`| ${row.join(' | ')} |`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return out.join('\n') + '\n';
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export function renderRootIndex(S, P) {
|
|
355
|
+
const newest = P.workspaces[P.workspaces.length - 1];
|
|
356
|
+
const name = (newest && newest.name) || path.basename(P.root);
|
|
357
|
+
const out = [...fmBlock(S, name), `# ${name}`, '', S.raw.indexFile.projectRoster.purpose];
|
|
358
|
+
if (P.workspaces.length) {
|
|
359
|
+
out.push('', `## ${S.gear} Contents`, '| Version | Lifecycle | Based on |', '|---|---|---|');
|
|
360
|
+
for (const ws of P.workspaces) out.push(`| [V${ws.version}](${ws.folder}/intent-format.md) | ${ws.lifecycle || '—'} | ${ws.basedOn ? 'V' + ws.basedOn : '—'} |`);
|
|
361
|
+
}
|
|
362
|
+
return out.join('\n') + '\n';
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export function idsTables(S, P) {
|
|
366
|
+
const rows = new Map();
|
|
367
|
+
for (const ws of P.workspaces) {
|
|
368
|
+
for (const [core, t] of ws.byCore) {
|
|
369
|
+
const r = rows.get(core) || { core, versions: [] };
|
|
370
|
+
r.type = t.sub ? t.sub.kind : t.card.type;
|
|
371
|
+
r.name = targetName(t) || '—';
|
|
372
|
+
r.versions.push(ws.version);
|
|
373
|
+
r.path = toPosix(path.relative(P.root, t.card.file)) + (t.sub ? '#' + t.sub.core.toLowerCase() : '');
|
|
374
|
+
rows.set(core, r);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
const retired = new Map(P.ids.retired.map((r) => [r.core, r]));
|
|
378
|
+
for (const old of P.ids.resolved) {
|
|
379
|
+
if (rows.has(old.core) || retired.has(old.core) || !/^[A-Z]{2}\d{6}$/.test(old.core)) continue;
|
|
380
|
+
retired.set(old.core, { core: old.core, type: old.type, name: old.name, last: old.versions[old.versions.length - 1] || '—', merged: '—' });
|
|
381
|
+
}
|
|
382
|
+
const hw = highWater(P);
|
|
383
|
+
for (const r of retired.values()) {
|
|
384
|
+
const p = r.core.slice(0, 2), n = +r.core.slice(2);
|
|
385
|
+
if (!hw.has(p) || hw.get(p) < n) hw.set(p, n);
|
|
386
|
+
}
|
|
387
|
+
return { rows, retired, hw };
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export function renderIds(S, P, hwOverride = null) {
|
|
391
|
+
const { rows, retired, hw } = idsTables(S, P);
|
|
392
|
+
if (hwOverride) for (const [p, n] of hwOverride) if (!hw.has(p) || hw.get(p) < n) hw.set(p, n);
|
|
393
|
+
const g = S.gear;
|
|
394
|
+
const out = [...fmBlock(S, 'ID register'), '# ID register'];
|
|
395
|
+
const cell = (s) => escapeCell(s ?? '—');
|
|
396
|
+
out.push('', `## ${g} Resolved`, '| Core | Type | Name | Versions | Path |', '|---|---|---|---|---|');
|
|
397
|
+
for (const r of [...rows.values()].sort((a, b) => (a.core < b.core ? -1 : 1))) out.push(`| ${r.core} | ${r.type} | ${cell(r.name)} | ${r.versions.join(', ')} | ${r.path} |`);
|
|
398
|
+
out.push('', `## ${g} Retired`, '| Core | Type | Name | Last version | Merged into |', '|---|---|---|---|---|');
|
|
399
|
+
for (const r of [...retired.values()].sort((a, b) => (a.core < b.core ? -1 : 1))) out.push(`| ${r.core} | ${cell(r.type)} | ${cell(r.name)} | ${cell(r.last)} | ${cell(r.merged)} |`);
|
|
400
|
+
out.push('', `## ${g} High-water marks`, '| Prefix | Highest |', '|---|---|');
|
|
401
|
+
for (const p of [...hw.keys()].sort()) out.push(`| ${p} | ${hw.get(p)} |`);
|
|
402
|
+
return out.join('\n') + '\n';
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export function renderChanges(S, ws, changes) {
|
|
406
|
+
if (!ws.basedOn) return null;
|
|
407
|
+
const file = path.join(ws.dir, 'CHANGES.md');
|
|
408
|
+
const out = ['---', `standard: ${S.standard}`, 'type: index', 'name: Changes', '---', `# Changes · V${ws.version} · based on V${ws.basedOn}`];
|
|
409
|
+
const order = (arr) => sortBy(arr, (c) => S.typeIndex.get(c.type) ?? 99, (c) => c.id);
|
|
410
|
+
const nw = order(ws.cards.filter((c) => c.id && changes.get(c)?.state === 'new'));
|
|
411
|
+
const ch = order(ws.cards.filter((c) => c.id && changes.get(c)?.state === 'changed'));
|
|
412
|
+
const rm = ws.base ? order(ws.base.cards.filter((c) => c.id && !ws.byCore.has(c.id))) : [];
|
|
413
|
+
const g = S.gear;
|
|
414
|
+
if (nw.length) out.push('', `## ${g} New`, ...nw.map((c) => `- ${ref(file, { card: c, sub: null })}`));
|
|
415
|
+
if (ch.length) out.push('', `## ${g} Changed`, ...ch.map((c) => `- ${ref(file, { card: c, sub: null })} · changed: ${changes.get(c).parts.join(', ')}`));
|
|
416
|
+
if (rm.length) out.push('', `## ${g} Removed`, ...rm.map((c) => `- #${c.id} — ${c.name}`));
|
|
417
|
+
return out.join('\n') + '\n';
|
|
418
|
+
}
|