intent-format 0.0.0-stage → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +287 -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 +71 -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,203 @@
|
|
|
1
|
+
// intent-format build-kit: templates/<type>.md, kit/skills/intent-format/types/<type>.md, kit/skills/intent-format/links.md.
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { STANDARD_DIR } from './schema.mjs';
|
|
4
|
+
import { writeIfChanged, toPosix } from './util.mjs';
|
|
5
|
+
import { renderCard } from './templates.mjs';
|
|
6
|
+
|
|
7
|
+
const GEN_NOTE = '> Generated by `intent-format build-kit` from `schema.json` — do not edit by hand.';
|
|
8
|
+
const code = (s) => '`' + s + '`';
|
|
9
|
+
const cell = (s) => String(s).replace(/\|/g, '\\|').replace(/\n/g, ' ');
|
|
10
|
+
|
|
11
|
+
function valuesText(S, def, type) {
|
|
12
|
+
if (def.values === '@statusVocabulary') return 'status vocabulary below, or `—`';
|
|
13
|
+
if (def.values === '@typeRoster') return code(type);
|
|
14
|
+
const vn = S.vocabName(def.values);
|
|
15
|
+
if (vn) return `a value of ### ${vn} in project.md` + (S.reserved[vn] ? ` (or ${code(S.reserved[vn])})` : '');
|
|
16
|
+
if (Array.isArray(def.values)) return def.values.map(code).join(' · ');
|
|
17
|
+
if (def.value) return code(def.value);
|
|
18
|
+
if (def.pattern) return `pattern ${code(def.pattern)}`;
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function keyRows(S, type) {
|
|
23
|
+
const t = S.typeDef(type);
|
|
24
|
+
const rows = [];
|
|
25
|
+
for (const raw of t.keys) {
|
|
26
|
+
const key = raw.replace(/\?$/, '');
|
|
27
|
+
const req = raw.endsWith('?') ? 'no' : 'yes';
|
|
28
|
+
if (key === 'x-*') { rows.push([code('x-*'), 'no', 'extension keys; kept untouched, always last']); continue; }
|
|
29
|
+
const def = S.keyDef(type, key) || {};
|
|
30
|
+
let text;
|
|
31
|
+
if (key === 'standard') text = code(S.standard) + ' — always the first key';
|
|
32
|
+
else if (key === 'type') text = code(type);
|
|
33
|
+
else if (key === 'status') text = 'status vocabulary below, or `—`';
|
|
34
|
+
else if (key === 'state') text = 'a State of project.md (one value' + (['userflow', 'ia'].includes(type) ? '' : ' or a list') + '); omitted = Shared; only when States are declared';
|
|
35
|
+
else if (key === 'feature') text = 'FT core of this card\'s home Feature or Sub-feature (one)';
|
|
36
|
+
else if (key === 'id') text = `${code(t.prefix + '000000')}-style core (${t.prefix} + 6 digits) — minted by ${code('intent-format new')}, never by hand`;
|
|
37
|
+
else if (key === 'name') text = 'the card name (no `[` `]`); title, references and filename slug derive from it';
|
|
38
|
+
else if (key === 'origin') text = `${code('<kb>/<core>')} — written by import`;
|
|
39
|
+
else {
|
|
40
|
+
text = valuesText(S, def, type);
|
|
41
|
+
const extra = def.description || def.rule || '';
|
|
42
|
+
if (extra) text = text ? `${text} — ${extra}` : extra;
|
|
43
|
+
if (S.alwaysQuoted.has(key)) text += ' (always quoted)';
|
|
44
|
+
}
|
|
45
|
+
rows.push([code(key), req, text]);
|
|
46
|
+
}
|
|
47
|
+
return rows;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function relationRows(S, type) {
|
|
51
|
+
const rows = [];
|
|
52
|
+
const kindLabel = { 'screen-variant': '### variant (#SV)', 'component-variant': '### variant (#CV)', 'shell-variant': '### variant (#HV)', 'flow-step': '### step (#FS)', 'flow-variant': '## Step list › ### flow variant' };
|
|
53
|
+
for (const [name, r] of Object.entries(S.relations)) {
|
|
54
|
+
if (r.generatedOnly) continue;
|
|
55
|
+
const where = [];
|
|
56
|
+
for (const a of r.authoredIn || []) {
|
|
57
|
+
if (a.key && a.type === type) where.push(`front matter ${code(a.key + ':')}`);
|
|
58
|
+
else if (a.passportKey) { if (S.raw.subdocuments[a.subdocument]?.host === type) where.push(`${kindLabel[a.subdocument]} passport ${code(a.passportKey + ':')}`); }
|
|
59
|
+
else if (a.relation) { if ((a.relation === 'Node' && type === 'ia') || (a.relation === 'Screen' && type === 'userflow')) where.push(`${code('· ' + a.qualifier + ':')} on ${a.relation}`); }
|
|
60
|
+
else if (a.section && a.type === type) where.push(`## ${a.section}${a.subsection ? ' › ### ' + a.subsection : ''}${a.prefixless ? ' (no prefix)' : ''}`);
|
|
61
|
+
else if (a.subdocument && (S.hostOfKind(a.subdocument) === type || S.raw.subdocuments[a.subdocument]?.host === type)) {
|
|
62
|
+
where.push(kindLabel[a.subdocument] + (a.shapes ? ` ${a.shapes.join('/')}` : '') + (a.prefixless ? ' (no prefix)' : ''));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!where.length) continue;
|
|
66
|
+
const targets = r.textSlot ? 'text' : r.targetTypes.length ? r.targetTypes.join(', ') : (r.target || '—');
|
|
67
|
+
const quals = (r.qualifiers || []).map((q) => (q.valueless ? q.key : `${q.key}: ${Array.isArray(q.values) ? q.values.join('|') : q.values ? q.values.replace('@vocabulary:', '') : '…'}`)).join(' · ') || '—';
|
|
68
|
+
const gr = r.generatedReverse;
|
|
69
|
+
const rev = gr ? (Array.isArray(gr.section) ? gr.section.join(', ') : gr.section) + ` on ${gr.on.join(', ')}` : '—';
|
|
70
|
+
rows.push([name, cell(where.join('; ')), cell(targets), cell(quals), cell(rev)]);
|
|
71
|
+
}
|
|
72
|
+
return rows;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function table(head, rows) {
|
|
76
|
+
return [`| ${head.join(' | ')} |`, `|${head.map(() => '---').join('|')}|`, ...rows.map((r) => `| ${r.join(' | ')} |`)];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function presetBlock(S, type) {
|
|
80
|
+
const rp = S.raw.requirementPresets;
|
|
81
|
+
const def = rp.defaults[type] || (type === 'userflow' ? rp.defaults['flow-step'] : null);
|
|
82
|
+
const out = ['## Requirement blocks', '', `${rp.where} Marker ${code(rp.marker)}: ${rp.numbering}${def ? ` Default preset here: **${def}** (${rp.defaultsNote.toLowerCase()})` : ''}`, '', '```markdown'];
|
|
83
|
+
let n = 0;
|
|
84
|
+
const blocks = [];
|
|
85
|
+
for (const [name, p] of Object.entries(rp.presets)) {
|
|
86
|
+
const marker = `**R${++n} · ${name}**`;
|
|
87
|
+
const shape = p.shape.split(' / ');
|
|
88
|
+
blocks.push(/^On the marker line/.test(p.placement) ? [`${marker} ${shape.join(' ')}`] : [marker, ...shape]);
|
|
89
|
+
}
|
|
90
|
+
blocks.forEach((b, i) => out.push(...(i ? [''] : []), ...b));
|
|
91
|
+
out.push('```', '', Object.entries(rp.presets).map(([name, p]) => `**${name}**: ${p.rule}`).join(' · ') + ` ${rp.slotUnknown}`, '');
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function overviewSheet(S) {
|
|
96
|
+
const out = ['# Card types — overview', '', GEN_NOTE, '', 'The modelling cheat sheet: pick the type by its purpose, then check what it is not. Details per type: `types/<type>.md`.', ''];
|
|
97
|
+
for (const t of S.roster) {
|
|
98
|
+
const d = S.typeDef(t);
|
|
99
|
+
out.push(`**${t}** · ${d.prefix} · ${d.folder ? code(d.folder + '/') : code(d.file)} — ${d.purpose}`);
|
|
100
|
+
for (const n of d.notToConfuseWith || []) out.push(`- not ${n.type}: ${n.rule}`);
|
|
101
|
+
out.push('');
|
|
102
|
+
}
|
|
103
|
+
const subs = Object.entries(S.raw.subdocuments).filter(([, v]) => v.prefix).map(([k, v]) => `${k} (${v.prefix}, a \`### \` sub-document in ## ${v.section} of a ${v.host})`);
|
|
104
|
+
out.push(`Sub-documents have their own core but no file: ${subs.join(' · ')}.`);
|
|
105
|
+
return out.join('\n') + '\n';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function typeSheet(S, type) {
|
|
109
|
+
const t = S.typeDef(type);
|
|
110
|
+
const out = [`# ${type} · ${t.prefix}${t.folder ? ` · folder ${code(t.folder + '/')}` : ` · ${code(t.file)}`}`, '', GEN_NOTE, '', t.purpose, ''];
|
|
111
|
+
out.push(`**When to use.** ${t.whenToUse}`, '');
|
|
112
|
+
if (t.notToConfuseWith?.length) {
|
|
113
|
+
out.push('**Not to confuse with**');
|
|
114
|
+
for (const n of t.notToConfuseWith) out.push(`- **${n.type}** — ${n.rule}`);
|
|
115
|
+
out.push('');
|
|
116
|
+
}
|
|
117
|
+
if (t.modelling?.length) out.push('**How to model**', ...t.modelling.map((l) => `- ${l}`), '');
|
|
118
|
+
if (t.levels) out.push(`**Levels.** Feature: ${t.levels.feature} Sub-feature: ${t.levels.subfeature}`, '');
|
|
119
|
+
if (t.altitude) out.push(`**Altitude.** ${typeof t.altitude === 'string' ? t.altitude : `Feature: ${t.altitude.feature} Sub-feature: ${t.altitude.subfeature}`}`, '');
|
|
120
|
+
out.push('## Front matter', '', ...table(['Key', 'Required', 'Values'], keyRows(S, type)), '', 'Keys in this order. Unknown = `—` (never quoted); `version`-like values are quoted.', '');
|
|
121
|
+
const sv = S.raw.statusVocabularies[t.statusVocabulary];
|
|
122
|
+
out.push('## Status', '', `${sv.values.map(code).join(' · ')} — ${sv.meaning} Template: ${code(t.templateStatus)}. ${S.raw.statusVocabularies.rule}`, '');
|
|
123
|
+
out.push('## Sections', '');
|
|
124
|
+
const rows = [];
|
|
125
|
+
if (t.preamble) rows.push(['(text under the title)', t.preamble.required ? 'required' : 'optional', cell(t.preamble.guidance)]);
|
|
126
|
+
for (const s of t.sections) {
|
|
127
|
+
const kind = s.generated ? 'generated' : s.required ? (s.relief ? `required (optional without ${s.relief}/)` : 'required') : s.inTemplate ? 'recommended' : 'optional';
|
|
128
|
+
const g = s.generated ? S.generated[s.heading]?.guidance || s.guidance : s.guidance;
|
|
129
|
+
const extra = s.defaultRelation ? ` Default relation: ${s.defaultRelation}${s.ordered ? ' (ordered 1. 2. …)' : ''}.` : '';
|
|
130
|
+
rows.push([`## ${s.heading}`, kind, cell(g + extra)]);
|
|
131
|
+
}
|
|
132
|
+
out.push(...table(['Section', 'Kind', 'Guidance'], rows), '');
|
|
133
|
+
out.push('Body states: \`—\` alone = unknown (counted) · \`none\` alone = verified empty · a final \`- —\` / \`N. —\` list item = more items exist but are unknown. Never edit \`⚙\` sections or the \`> ⚙\` status line — run \`intent-format regen\`.', '');
|
|
134
|
+
if (t.sections.some((s) => s.heading === 'Why')) {
|
|
135
|
+
const q = S.why.questions[type];
|
|
136
|
+
const req = S.why.requiredOn.includes(type);
|
|
137
|
+
out.push(`**Why.** \`## Why\` is ${req ? 'required' : 'optional (absent = nothing to say)'} here. ${q ? `Its question (${q.flavour}): *${q.question}* ` : ''}It holds one of: the answer in one or two sentences, optionally ending \`[likely]\` (follows from inputs) or \`[assumed]\` (a guess; counted as open) — unmarked means confirmed; \`none\` or \`none — <note>\` (no why needed; not counted); \`same as #<id>\` (another card's why covers it; check follows the link); or \`—\` (nobody asked yet; counted as why debt). A Why says what the Description does not; a question for the owner goes in the sentence it concerns as \`[ask: …]\`.`, '');
|
|
138
|
+
}
|
|
139
|
+
if (t.sections.some((s) => s.heading === 'Description')) out.push(...presetBlock(S, type));
|
|
140
|
+
const rel = relationRows(S, type);
|
|
141
|
+
if (rel.length) out.push('## Relations written on this type', '', ...table(['Relation', 'Written in', 'Targets', 'Qualifiers', 'Generated reverse'], rel), '');
|
|
142
|
+
for (const [kind, sd] of Object.entries(S.raw.subdocuments)) {
|
|
143
|
+
if (sd.host !== type) continue;
|
|
144
|
+
out.push(`## Sub-document: ${kind}`, '', `Heading ${code(sd.heading)} in ## ${sd.section}${sd.anchor ? `; anchor ${code(sd.anchor.split(' — ')[0])} on the next line` : ''}.`);
|
|
145
|
+
if (sd.passport?.keys?.length) out.push(`Optional passport line: ${sd.passport.keys.map((k) => code(k.key + ':')).join(' · ')} (${sd.passport.order || 'in this order'}).`);
|
|
146
|
+
if (sd.body) out.push(sd.body);
|
|
147
|
+
if (sd.shapes) {
|
|
148
|
+
out.push('', ...table(['Glyph', 'Step', 'Lines', 'Rule'], Object.entries(sd.shapes).map(([n, d]) => [d.glyph, n, cell(Object.entries(d.lines).map(([r, c]) => `${r} ${c}`).join(' · ')), cell(d.rule)])));
|
|
149
|
+
out.push(`Every step may also carry: ${Object.keys(sd.commonLines).join(' · ')} (except where the step's own line replaces it).`);
|
|
150
|
+
}
|
|
151
|
+
for (const r of sd.rules || []) out.push(`- ${r}`);
|
|
152
|
+
out.push('');
|
|
153
|
+
}
|
|
154
|
+
out.push('## Example', '', '```markdown', t.example.replace(/\n$/, ''), '```');
|
|
155
|
+
if (t.exampleSubfeature) out.push('', 'Sub-feature:', '', '```markdown', t.exampleSubfeature.replace(/\n$/, ''), '```');
|
|
156
|
+
return out.join('\n') + '\n';
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function linksSheet(S) {
|
|
160
|
+
const g = S.raw.grammar;
|
|
161
|
+
const out = ['# Links and relations', '', GEN_NOTE, '', '## Reference atoms', ''];
|
|
162
|
+
out.push(...table(['Atom', 'Shape', 'Meaning'], [
|
|
163
|
+
['bound', code('[#<CORE> <Name>](<relative-path>[#<anchor>])'), 'resolves by core; name and path are courtesy — `intent-format regen` rewrites them'],
|
|
164
|
+
['hand', code('#<CORE>'), 'valid; `intent-format regen` upgrades it to bound on relation lines'],
|
|
165
|
+
['placeholder', code('[~ <Name>]'), 'should exist, does not yet; counted as unresolved'],
|
|
166
|
+
['unknown', code('—'), 'target unknown (blind spot)'],
|
|
167
|
+
]), '', 'Never write rendered IDs (`#SC000006V1.0`) in references or front matter.', '');
|
|
168
|
+
out.push('## Line shapes', '');
|
|
169
|
+
for (const [k, v] of Object.entries(g.shapes)) out.push(`- **${k}**: ${code(v)}`);
|
|
170
|
+
out.push('', '## Rules', '', ...S.raw.relationRules.map((r) => `- ${r}`), '');
|
|
171
|
+
out.push('## Sections with a default relation (write lines without a prefix)', '');
|
|
172
|
+
const rows = [];
|
|
173
|
+
for (const type of S.roster) {
|
|
174
|
+
for (const s of S.sections(type)) if (s.defaultRelation && !s.generated) rows.push([type, `## ${s.heading}`, s.defaultRelation, s.ordered ? 'yes' : 'no']);
|
|
175
|
+
}
|
|
176
|
+
out.push(...table(['Type', 'Section', 'Default relation', 'Ordered'], rows), '');
|
|
177
|
+
out.push('## Relation vocabulary', '');
|
|
178
|
+
const rr = [];
|
|
179
|
+
for (const [name, r] of Object.entries(S.relations)) {
|
|
180
|
+
const where = (r.authoredIn || []).map((a) => (a.key ? `${a.type} ${a.key}:` : a.passportKey ? `${a.subdocument} passport ${a.passportKey}:` : a.relation ? `· ${a.qualifier}: on ${a.relation}` : a.subdocument ? `${a.subdocument}${a.shapes ? ' (' + a.shapes.join('/') + ')' : ''}` : `${a.type} ## ${a.section}${a.subsection ? ' › ' + a.subsection : ''}`));
|
|
181
|
+
const targets = r.textSlot ? 'text' : r.targetTypes.length ? r.targetTypes.join(', ') : (r.target || '—');
|
|
182
|
+
const quals = (r.qualifiers || []).map((q) => (q.valueless ? q.key : q.key + (Array.isArray(q.values) ? ': ' + q.values.join('|') : ''))).join(' · ') || '—';
|
|
183
|
+
const gr = r.generatedReverse;
|
|
184
|
+
const rev = r.generatedOnly ? '(generated line)' : gr ? (Array.isArray(gr.section) ? gr.section.join(', ') : gr.section) : '—';
|
|
185
|
+
rr.push([name, cell(where.join('; ') || '—'), cell(targets), cell(quals), cell(rev)]);
|
|
186
|
+
}
|
|
187
|
+
out.push(...table(['Relation', 'Written in', 'Targets', 'Qualifiers', 'Generated reverse'], rr), '');
|
|
188
|
+
const link = S.relations.Link;
|
|
189
|
+
out.push('## External links', '', `${code(link.shape)} — ${link.note}`, '');
|
|
190
|
+
return out.join('\n') + '\n';
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function buildKit(S) {
|
|
194
|
+
const written = [];
|
|
195
|
+
const put = (rel, text) => { if (writeIfChanged(path.join(STANDARD_DIR, rel), text)) written.push(rel); };
|
|
196
|
+
for (const type of S.roster) {
|
|
197
|
+
put(toPosix(path.join('templates', `${type}.md`)), renderCard(S, type));
|
|
198
|
+
put(toPosix(path.join('kit', 'skills', 'intent-format', 'types', `${type}.md`)), typeSheet(S, type));
|
|
199
|
+
}
|
|
200
|
+
put(toPosix(path.join('kit', 'skills', 'intent-format', 'links.md')), linksSheet(S));
|
|
201
|
+
put(toPosix(path.join('kit', 'skills', 'intent-format', 'types', '_overview.md')), overviewSheet(S));
|
|
202
|
+
return written;
|
|
203
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// intent-format migrate: bring a KB written against an earlier reading of the standard up to date (S-OPS-5).
|
|
2
|
+
// Two steps, both idempotent: pre-release names of the standard (`standard:` first key) become the
|
|
3
|
+
// current one, and the deprecated ### Roles table in project.md becomes role cards — one core per
|
|
4
|
+
// role name across all workspaces, so a role is the same card in every version.
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { parseTable, contentIdx } from './parse.mjs';
|
|
8
|
+
import { renderCard } from './templates.mjs';
|
|
9
|
+
import { mintCores } from './create.mjs';
|
|
10
|
+
import { exists, readText, slugify, toPosix, walkMd } from './util.mjs';
|
|
11
|
+
|
|
12
|
+
/** Rows of the ### Roles table and the line range of the subsection, or null. */
|
|
13
|
+
function rolesTable(S, c) {
|
|
14
|
+
const start = c.lines.findIndex((l, k) => !c.mask[k] && /^### Roles\s*$/.test(l));
|
|
15
|
+
if (start < 0) return null;
|
|
16
|
+
let end = start + 1;
|
|
17
|
+
while (end < c.lines.length && !(!c.mask[end] && /^#{2,3} /.test(c.lines[end]))) end++;
|
|
18
|
+
const t = parseTable(c.lines, contentIdx(c.lines, start + 1, end, c.mask), S.R);
|
|
19
|
+
const rows = t.rows.map((r) => ({ name: (r.cells[0] || '').trim(), description: (r.cells[1] || '').trim(), states: (r.cells[2] || '').split(',').map((x) => x.trim()).filter(Boolean) }));
|
|
20
|
+
return { start, end, rows };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Every file whose `standard:` key holds a pre-release name gets the current one. The name is the
|
|
24
|
+
* format's label, not product content, so released workspaces are renamed too; inputs/ is left alone. */
|
|
25
|
+
function renameStandard(S, P, log) {
|
|
26
|
+
let n = 0;
|
|
27
|
+
for (const f of walkMd(P.root)) {
|
|
28
|
+
if (toPosix(path.relative(P.root, f)).startsWith('inputs/')) continue;
|
|
29
|
+
const t = readText(f);
|
|
30
|
+
const m = /^---\r?\nstandard: (.+?)\s*\r?\n/.exec(t);
|
|
31
|
+
if (!m || !S.legacyStandards.includes(m[1])) continue;
|
|
32
|
+
fs.writeFileSync(f, t.replace(m[0], m[0].replace(m[1], S.standard)));
|
|
33
|
+
n++;
|
|
34
|
+
}
|
|
35
|
+
// the project's AGENTS.md is the project's own text: only the standard's name in it changes
|
|
36
|
+
const agents = path.join(P.root, 'AGENTS.md');
|
|
37
|
+
if (exists(agents)) {
|
|
38
|
+
const t = readText(agents);
|
|
39
|
+
const u = S.legacyStandards.reduce((x, old) => x.split(old.replace('/', ' ')).join(S.standard.replace('/', ' ')), t);
|
|
40
|
+
if (u !== t) { fs.writeFileSync(agents, u); n++; }
|
|
41
|
+
}
|
|
42
|
+
if (n) log(`standard: ${n} file(s) renamed to ${S.standard}`);
|
|
43
|
+
return n;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function migrate(S, P, log) {
|
|
47
|
+
const stats = { renamed: renameStandard(S, P, log), created: 0, reused: 0, kept: 0, workspaces: 0, problems: 0 };
|
|
48
|
+
const coreByName = new Map();
|
|
49
|
+
for (const ws of P.workspaces) for (const c of ws.cards) if (c.type === 'role' && c.id && c.name && !coreByName.has(c.name)) coreByName.set(c.name, c.id);
|
|
50
|
+
for (const ws of P.workspaces) {
|
|
51
|
+
if (S.raw.lifecycles.readOnly.includes(ws.lifecycle)) { log(`${ws.folder}: ${ws.lifecycle} (read-only) — skipped`); continue; }
|
|
52
|
+
const pc = ws.project;
|
|
53
|
+
const table = pc && rolesTable(S, pc);
|
|
54
|
+
if (!table) continue;
|
|
55
|
+
stats.workspaces++;
|
|
56
|
+
const have = new Set(ws.cards.filter((c) => c.type === 'role').map((c) => c.name));
|
|
57
|
+
const dir = path.join(ws.dir, 'roles');
|
|
58
|
+
for (const r of table.rows) {
|
|
59
|
+
if (!r.name || /[[\]]/.test(r.name)) { stats.problems++; log(`${ws.folder}: row "${r.name}" has no usable name — skipped`); continue; }
|
|
60
|
+
if (have.has(r.name)) { stats.kept++; continue; }
|
|
61
|
+
let core = coreByName.get(r.name);
|
|
62
|
+
if (core) stats.reused++;
|
|
63
|
+
else { [core] = mintCores(S, P, 'RO', 1); coreByName.set(r.name, core); stats.created++; }
|
|
64
|
+
const states = r.states.filter((x) => x !== S.reserved.States);
|
|
65
|
+
const unknown = states.filter((x) => !ws.vocab.values.States?.has(x));
|
|
66
|
+
if (unknown.length) { stats.problems++; log(`${ws.folder}: ${r.name} — States ${unknown.join(', ')} are not declared; kept on the card for check to report`); }
|
|
67
|
+
const values = { id: core, name: r.name, ...(states.length === 1 ? { state: states[0] } : states.length > 1 ? { state: states } : {}) };
|
|
68
|
+
let text = renderCard(S, 'role', values);
|
|
69
|
+
if (r.description) text = text.replace('## Description\n—', `## Description\n${r.description}`);
|
|
70
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
71
|
+
const file = path.join(dir, `${core.toLowerCase()}-${slugify(r.name, 'role')}.md`);
|
|
72
|
+
if (!exists(file)) fs.writeFileSync(file, text);
|
|
73
|
+
have.add(r.name);
|
|
74
|
+
log(`${core} ${toPosix(path.relative(P.root, file))}`);
|
|
75
|
+
}
|
|
76
|
+
// drop the table from project.md (blank lines after it too)
|
|
77
|
+
const lines = readText(pc.file).replace(/\n$/, '').split('\n');
|
|
78
|
+
let end = table.end;
|
|
79
|
+
lines.splice(table.start, end - table.start);
|
|
80
|
+
while (lines[table.start] === '' && lines[table.start - 1] === '') lines.splice(table.start, 1);
|
|
81
|
+
fs.writeFileSync(pc.file, lines.join('\n') + '\n');
|
|
82
|
+
// enable the roles module
|
|
83
|
+
const mf = path.join(ws.dir, 'intent-format.md');
|
|
84
|
+
if (exists(mf)) {
|
|
85
|
+
const t = readText(mf);
|
|
86
|
+
const m = /^modules: \[(.*)\]$/m.exec(t);
|
|
87
|
+
if (m) {
|
|
88
|
+
const mods = m[1].split(',').map((x) => x.trim()).filter(Boolean);
|
|
89
|
+
if (!mods.includes('roles')) {
|
|
90
|
+
const next = S.modules.filter((x) => x === 'roles' || mods.includes(x)).concat(mods.filter((x) => !S.modules.includes(x)));
|
|
91
|
+
fs.writeFileSync(mf, t.replace(m[0], `modules: [${next.join(', ')}]`));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return stats;
|
|
97
|
+
}
|