@leo-studio/leo-markup 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +18 -2
  3. package/dist/agent-support.d.ts +10 -0
  4. package/dist/agent-support.d.ts.map +1 -0
  5. package/dist/agent-support.js +27 -0
  6. package/dist/agent-support.js.map +1 -0
  7. package/dist/ast-json.d.ts +104 -0
  8. package/dist/ast-json.d.ts.map +1 -0
  9. package/dist/ast-json.js +203 -0
  10. package/dist/ast-json.js.map +1 -0
  11. package/dist/authoring-lints.d.ts +79 -0
  12. package/dist/authoring-lints.d.ts.map +1 -0
  13. package/dist/authoring-lints.js +145 -0
  14. package/dist/authoring-lints.js.map +1 -0
  15. package/dist/block-inline.d.ts +74 -0
  16. package/dist/block-inline.d.ts.map +1 -0
  17. package/dist/block-inline.js +171 -0
  18. package/dist/block-inline.js.map +1 -0
  19. package/dist/fence.d.ts +14 -0
  20. package/dist/fence.d.ts.map +1 -0
  21. package/dist/fence.js +55 -0
  22. package/dist/fence.js.map +1 -0
  23. package/dist/index.d.ts +20 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +20 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/parity.d.ts +44 -0
  28. package/dist/parity.d.ts.map +1 -0
  29. package/dist/parity.js +80 -0
  30. package/dist/parity.js.map +1 -0
  31. package/dist/product-spec.d.ts +164 -0
  32. package/dist/product-spec.d.ts.map +1 -0
  33. package/dist/product-spec.js +240 -0
  34. package/dist/product-spec.js.map +1 -0
  35. package/dist/registry.d.ts +53 -0
  36. package/dist/registry.d.ts.map +1 -0
  37. package/dist/registry.js +483 -0
  38. package/dist/registry.js.map +1 -0
  39. package/dist/scanner.d.ts +40 -0
  40. package/dist/scanner.d.ts.map +1 -0
  41. package/dist/scanner.js +291 -0
  42. package/dist/scanner.js.map +1 -0
  43. package/dist/schema/leo-markup-ast.schema.json +217 -0
  44. package/dist/schema/vocabulary.json +382 -0
  45. package/dist/tree-text.d.ts +16 -0
  46. package/dist/tree-text.d.ts.map +1 -0
  47. package/dist/tree-text.js +320 -0
  48. package/dist/tree-text.js.map +1 -0
  49. package/dist/types.d.ts +211 -0
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/types.js +34 -0
  52. package/dist/types.js.map +1 -0
  53. package/dist/vocabulary.d.ts +293 -0
  54. package/dist/vocabulary.d.ts.map +1 -0
  55. package/dist/vocabulary.js +226 -0
  56. package/dist/vocabulary.js.map +1 -0
  57. package/package.json +43 -3
package/dist/parity.js ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The parity harness.
3
+ *
4
+ * The anti-drift spine: a shared component cannot ship half-rendered. This
5
+ * module checks a registry against the parity contract and returns the
6
+ * violations; a build/test wraps it to FAIL when any exist.
7
+ *
8
+ * Contract:
9
+ * - `targets: 'both'` → MUST register an ansi emitter AND a web emitter.
10
+ * - `targets: 'web-only'` → MUST register a web emitter AND declare a degrade.
11
+ * - `targets: 'terminal-only'` → MUST register an ansi emitter AND declare a degrade.
12
+ *
13
+ * The harness takes the registry as a PARAMETER (no hidden import of the real
14
+ * one) so it can be exercised against synthetic registries — including the
15
+ * RED-CHECK: a deliberately emitter-less `both` entry must produce a violation,
16
+ * proving the coverage check is not vacuous.
17
+ *
18
+ * Until both emitters are attached — the web emitters by leo-doc-web and the
19
+ * terminal emitters by leo-pty-renderer — the real registry's `both` entries
20
+ * have no emitters yet, so `checkParity(leoRegistry)` is EXPECTED to report
21
+ * violations. Once they are wired, the verify step re-runs it against the wired
22
+ * registry, where it must be clean. (This module never imports the real registry
23
+ * — it only defines the check.)
24
+ */
25
+ import { requiresAnsi, requiresWeb } from './types.js';
26
+ /**
27
+ * Check one entry against the contract. Returns the violations it introduces (an
28
+ * entry can violate more than one rule).
29
+ */
30
+ function checkEntry(component) {
31
+ const violations = [];
32
+ const { name, targets } = component;
33
+ if (requiresAnsi(component) && component.ansi === undefined) {
34
+ violations.push({
35
+ name,
36
+ kind: 'missing-ansi',
37
+ message: `"${name}" targets ${targets} but has no ansi emitter registered`,
38
+ });
39
+ }
40
+ if (requiresWeb(component) && component.web === undefined) {
41
+ violations.push({
42
+ name,
43
+ kind: 'missing-web',
44
+ message: `"${name}" targets ${targets} but has no web emitter registered`,
45
+ });
46
+ }
47
+ // web-only / terminal-only must declare how they degrade on the off-surface
48
+ // (no silent disappearance).
49
+ if ((targets === 'web-only' || targets === 'terminal-only') &&
50
+ component.degrade === undefined) {
51
+ violations.push({
52
+ name,
53
+ kind: 'missing-degrade',
54
+ message: `"${name}" targets ${targets} but declares no degrade strategy for the off-surface`,
55
+ });
56
+ }
57
+ return violations;
58
+ }
59
+ /** Check a whole registry; returns every violation (stable order by key). */
60
+ export function checkParity(registry) {
61
+ const violations = [];
62
+ for (const name of Object.keys(registry).sort()) {
63
+ const component = registry[name];
64
+ violations.push(...checkEntry(component));
65
+ }
66
+ return { ok: violations.length === 0, violations };
67
+ }
68
+ /**
69
+ * Assert parity over a registry: throws with a readable message listing every
70
+ * violation when the contract is not met. This is the form a build/test step
71
+ * calls to FAIL on a missing emitter.
72
+ */
73
+ export function assertParity(registry) {
74
+ const report = checkParity(registry);
75
+ if (!report.ok) {
76
+ const lines = report.violations.map((v) => ` - ${v.message}`).join('\n');
77
+ throw new Error(`leo-doc-core parity check failed:\n${lines}`);
78
+ }
79
+ }
80
+ //# sourceMappingURL=parity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parity.js","sourceRoot":"","sources":["../src/parity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAcvD;;;GAGG;AACH,SAAS,UAAU,CAAC,SAAuB;IACvC,MAAM,UAAU,GAAsB,EAAE,CAAC;IACzC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,SAAS,C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;AACH,MAAM,UAAU,YAAY,CAAC,QAAqB;IAC9C,MAAM,MAAM,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1E,MAAM,IAAI,KAAK,CAAC,sCAAsC,KAAK,EAAE,CAAC,CAAC;IACnE,CAAC;AACL,CAAC","sourcesContent":["/**\n * The parity harness.\n *\n * The anti-drift spine: a shared component cannot ship half-rendered. This\n * module checks a registry against the parity contract and returns the\n * violations; a build/test wraps it to FAIL when any exist.\n *\n * Contract:\n * - `targets: 'both'` → MUST register an ansi emitter AND a web emitter.\n * - `targets: 'web-only'` → MUST register a web emitter AND declare a degrade.\n * - `targets: 'terminal-only'` → MUST register an ansi emitter AND declare a degrade.\n *\n * The harness takes the registry as a PARAMETER (no hidden import of the real\n * one) so it can be exercised against synthetic registries — including the\n * RED-CHECK: a deliberately emitter-less `both` entry must produce a violation,\n * proving the coverage check is not vacuous.\n *\n * Until both emitters are attached — the web emitters by leo-doc-web and the\n * terminal emitters by leo-pty-renderer — the real registry's `both` entries\n * have no emitters yet, so `checkParity(leoRegistry)` is EXPECTED to report\n * violations. Once they are wired, the verify step re-runs it against the wired\n * registry, where it must be clean. (This module never imports the real registry\n * — it only defines the check.)\n */\n\nimport type { LeoComponent, LeoRegistry } from './types.js';\nimport { requiresAnsi, requiresWeb } from './types.js';\n\nexport interface ParityViolation {\n /** The offending entry's registry key. */\n readonly name: string;\n readonly kind: 'missing-ansi' | 'missing-web' | 'missing-degrade';\n readonly message: string;\n}\n\nexport interface ParityReport {\n readonly ok: boolean;\n readonly violations: readonly ParityViolation[];\n}\n\n/**\n * Check one entry against the contract. Returns the violations it introduces (an\n * entry can violate more than one rule).\n */\nfunction checkEntry(component: LeoComponent): ParityViolation[] {\n const violations: ParityViolation[] = [];\n const { name, targets } = component;\n\n if (requiresAnsi(component) && component.ansi === undefined) {\n violations.push({\n name,\n kind: 'missing-ansi',\n message: `\"${name}\" targets ${targets} but has no ansi emitter registered`,\n });\n }\n if (requiresWeb(component) && component.web === undefined) {\n violations.push({\n name,\n kind: 'missing-web',\n message: `\"${name}\" targets ${targets} but has no web emitter registered`,\n });\n }\n // web-only / terminal-only must declare how they degrade on the off-surface\n // (no silent disappearance).\n if (\n (targets === 'web-only' || targets === 'terminal-only') &&\n component.degrade === undefined\n ) {\n violations.push({\n name,\n kind: 'missing-degrade',\n message: `\"${name}\" targets ${targets} but declares no degrade strategy for the off-surface`,\n });\n }\n\n return violations;\n}\n\n/** Check a whole registry; returns every violation (stable order by key). */\nexport function checkParity(registry: LeoRegistry): ParityReport {\n const violations: ParityViolation[] = [];\n for (const name of Object.keys(registry).sort()) {\n const component = registry[name];\n violations.push(...checkEntry(component));\n }\n return { ok: violations.length === 0, violations };\n}\n\n/**\n * Assert parity over a registry: throws with a readable message listing every\n * violation when the contract is not met. This is the form a build/test step\n * calls to FAIL on a missing emitter.\n */\nexport function assertParity(registry: LeoRegistry): void {\n const report = checkParity(registry);\n if (!report.ok) {\n const lines = report.violations.map((v) => ` - ${v.message}`).join('\\n');\n throw new Error(`leo-doc-core parity check failed:\\n${lines}`);\n }\n}\n"]}
@@ -0,0 +1,164 @@
1
+ import type { IslandSpan, LeoRegistry } from './types.js';
2
+ /** The authored product-spec profile; display step/tree contracts remain independent. */
3
+ export declare const productSpecSchemas: {
4
+ readonly documents: {};
5
+ readonly document: {
6
+ readonly path: {
7
+ readonly kind: 'string';
8
+ readonly required: true;
9
+ };
10
+ readonly title: {
11
+ readonly kind: 'string';
12
+ readonly required: true;
13
+ };
14
+ readonly role: {
15
+ readonly kind: 'enum';
16
+ readonly required: true;
17
+ readonly values: readonly ["index", "decisions", "detail", "glossary", "audit"];
18
+ };
19
+ };
20
+ readonly journey: {
21
+ readonly id: {
22
+ readonly kind: 'string';
23
+ readonly required: true;
24
+ };
25
+ readonly title: {
26
+ readonly kind: 'string';
27
+ readonly required: true;
28
+ };
29
+ };
30
+ readonly step: {
31
+ readonly id: {
32
+ readonly kind: 'string';
33
+ readonly required: true;
34
+ };
35
+ };
36
+ readonly transition: {
37
+ readonly to: {
38
+ readonly kind: 'string';
39
+ readonly required: true;
40
+ };
41
+ readonly when: {
42
+ readonly kind: 'string';
43
+ readonly required: true;
44
+ };
45
+ };
46
+ readonly tree: {
47
+ readonly id: {
48
+ readonly kind: 'string';
49
+ readonly required: true;
50
+ };
51
+ readonly title: {
52
+ readonly kind: 'string';
53
+ };
54
+ };
55
+ readonly node: {
56
+ readonly label: {
57
+ readonly kind: 'string';
58
+ readonly required: true;
59
+ };
60
+ readonly id: {
61
+ readonly kind: 'string';
62
+ };
63
+ };
64
+ readonly scope: {
65
+ readonly increment: {
66
+ readonly kind: 'string';
67
+ };
68
+ readonly deferred: {
69
+ readonly kind: 'boolean';
70
+ };
71
+ readonly unassigned: {
72
+ readonly kind: 'boolean';
73
+ };
74
+ };
75
+ readonly ref: {
76
+ readonly relation: {
77
+ readonly kind: 'string';
78
+ readonly required: true;
79
+ };
80
+ readonly target: {
81
+ readonly kind: 'string';
82
+ readonly required: true;
83
+ };
84
+ };
85
+ readonly decisions: {};
86
+ readonly decision: {
87
+ readonly id: {
88
+ readonly kind: 'string';
89
+ readonly required: true;
90
+ };
91
+ readonly title: {
92
+ readonly kind: 'string';
93
+ readonly required: true;
94
+ };
95
+ readonly status: {
96
+ readonly kind: 'enum';
97
+ readonly required: true;
98
+ readonly values: readonly ["accepted", "superseded"];
99
+ };
100
+ readonly architectural: {
101
+ readonly kind: 'boolean';
102
+ };
103
+ };
104
+ readonly statement: {};
105
+ readonly rationale: {};
106
+ };
107
+ export type ProductSpecName = keyof typeof productSpecSchemas;
108
+ export type DeliveryScope = {
109
+ readonly kind: 'increment';
110
+ readonly increment: string;
111
+ } | {
112
+ readonly kind: 'deferred' | 'unassigned';
113
+ };
114
+ /** Explicit capability profile: web consumers retain source until they implement these nodes. */
115
+ export declare const productSpecRegistry: LeoRegistry;
116
+ interface SourceNode {
117
+ readonly start: number;
118
+ readonly end: number;
119
+ readonly source: string;
120
+ readonly scope?: DeliveryScope;
121
+ }
122
+ export interface ProductSpecComponent extends SourceNode {
123
+ readonly kind: 'component';
124
+ readonly name: ProductSpecName;
125
+ readonly props: Readonly<Record<string, string | boolean>>;
126
+ readonly bodyStart: number;
127
+ readonly body: string;
128
+ readonly children: readonly ProductSpecNode[];
129
+ }
130
+ export type ProductSpecText = SourceNode & ({
131
+ readonly kind: 'prose';
132
+ } | {
133
+ readonly kind: 'fallback';
134
+ });
135
+ export interface ProductSpecDisplay extends SourceNode {
136
+ readonly kind: 'display';
137
+ readonly island: IslandSpan;
138
+ }
139
+ export type ProductSpecNode = ProductSpecComponent | ProductSpecText | ProductSpecDisplay;
140
+ export interface ProductSpecDiagnostic {
141
+ readonly code: 'invalid-component' | 'unknown-component' | 'malformed-component' | 'unsupported-version';
142
+ readonly message: string;
143
+ readonly start: number;
144
+ readonly end: number;
145
+ }
146
+ export interface ProductSpecParseResult {
147
+ readonly nodes: readonly ProductSpecNode[];
148
+ readonly diagnostics: readonly ProductSpecDiagnostic[];
149
+ }
150
+ /** The product-spec children each component accepts; a missing entry accepts any. */
151
+ export declare const productSpecChildren: Partial<Record<ProductSpecName, readonly ProductSpecName[]>>;
152
+ /** Parse semantic components once, preserving source for every unsupported interpretation. */
153
+ export declare function parseProductSpec(source: string, options?: {
154
+ readonly schemaVersion?: unknown;
155
+ readonly offset?: number;
156
+ }): ProductSpecParseResult;
157
+ /** Feed already interpreted nodes into the shared Markdown composition mechanism. */
158
+ export declare function composeProductSpecNodes(nodes: readonly ProductSpecNode[]): {
159
+ spans: readonly import("./block-inline.js").ComposedSpan[];
160
+ diagnostics: readonly import("./block-inline.js").IslandDiagnostic[];
161
+ byOffset: Map<number, ProductSpecNode>;
162
+ };
163
+ export {};
164
+ //# sourceMappingURL=product-spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-spec.d.ts","sourceRoot":"","sources":["../src/product-spec.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAW,UAAU,EAAgB,WAAW,EAAc,MAAM,YAAY,CAAC;AAK7F,yFAAyF;AACzF,eAAO,MAAM,kBAAkB;;;iBAGvB,IAAI;2BAPmB,QAAQ;;;iBAQ/B,KAAK;;;;iBACL,IAAI;qBACA,IAAI,EAAE,MAAM;qBACZ,QAAQ;qBACR,MAAM;;;;iBAGH,EAAE;;;;iBAAkB,KAAK;;;;;;iBAC5B,EAAE;;;;;;iBACI,EAAE;;;;iBAAkB,IAAI;;;;;;iBAC9B,EAAE;;;;iBAAkB,KAAK;2BAjBN,QAAQ;;;;iBAkB3B,KAAK;;;;iBAAkB,EAAE;;;;;iBAE7B,SAAS;;;iBACT,QAAQ;qBAAI,IAAI,EAAE,SAAS;;iBAC3B,UAAU;qBAAI,IAAI,EAAE,SAAS;;;;iBAE1B,QAAQ;;;;iBAAkB,MAAM;;;;;;;iBAGnC,EAAE;;;;iBACF,KAAK;;;;iBACL,MAAM;qBAAI,IAAI,EAAE,MAAM;qBAAE,QAAQ;qBAAQ,MAAM;;iBAC9C,aAAa;qBAAI,IAAI,EAAE,SAAS;;;;;CAIO,CAAC;AAEhD,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,kBAAkB,CAAC;AAC9D,MAAM,MAAM,aAAa,GACnB;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,YAAY,CAAA;CAAE,CAAC;AAEnD,iGAAiG;AACjG,eAAO,MAAM,mBAAmB,EAAE,WAiBhC,CAAC;AAEH,UAAU,UAAU;IAChB,QAAQ,CAAC,K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eAAe,EAAE,CAAC;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAC1D;AAED,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,EAAE,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,SAAS,eAAe,EAAE,CAAC,CAU5F,CAAC;AA+CF,8FAA8F;AAC9F,wBAAgB,gBAAgB,CAC5B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAC7E,sBAAsB,CA4HxB;AAED,qFAAqF;AACrF,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE;;;;EA8BxE"}
@@ -0,0 +1,240 @@
1
+ import { composeMarkdownIslands } from './block-inline.js';
2
+ import { coerceProps, leoRegistry } from './registry.js';
3
+ import { scan } from './scanner.js';
4
+ const requiredString = { kind: 'string', required: true };
5
+ const optionalString = { kind: 'string' };
6
+ /** The authored product-spec profile; display step/tree contracts remain independent. */
7
+ export const productSpecSchemas = {
8
+ documents: {},
9
+ document: {
10
+ path: requiredString,
11
+ title: requiredString,
12
+ role: {
13
+ kind: 'enum',
14
+ required: true,
15
+ values: ['index', 'decisions', 'detail', 'glossary', 'audit'],
16
+ },
17
+ },
18
+ journey: { id: requiredString, title: requiredString },
19
+ step: { id: requiredString },
20
+ transition: { to: requiredString, when: requiredString },
21
+ tree: { id: requiredString, title: optionalString },
22
+ node: { label: requiredString, id: optionalString },
23
+ scope: {
24
+ increment: optionalString,
25
+ deferred: { kind: 'boolean' },
26
+ unassigned: { kind: 'boolean' },
27
+ },
28
+ ref: { relation: requiredString, target: requiredString },
29
+ decisions: {},
30
+ decision: {
31
+ id: requiredString,
32
+ title: requiredString,
33
+ status: { kind: 'enum', required: true, values: ['accepted', 'superseded'] },
34
+ architectural: { kind: 'boolean' },
35
+ },
36
+ statement: {},
37
+ rationale: {},
38
+ };
39
+ /** Explicit capability profile: web consumers retain source until they implement these nodes. */
40
+ export const productSpecRegistry = Object.freeze({
41
+ ...leoRegistry,
42
+ ...Object.fromEntries(Object.entries(productSpecSchemas).map(([name, props]) => [
43
+ name,
44
+ {
45
+ name,
46
+ flow: name === 'ref' ? 'inline' : 'block',
47
+ props,
48
+ targets: 'terminal-only',
49
+ degrade: {
50
+ kind: 'note',
51
+ text: 'Product-spec component: inspect source on this surface',
52
+ },
53
+ },
54
+ ])),
55
+ });
56
+ /** The product-spec children each component accepts; a missing entry accepts any. */
57
+ export const productSpecChildren = {
58
+ documents: ['document'],
59
+ journey: ['step', 'scope'],
60
+ tree: ['node', 'scope'],
61
+ node: ['node', 'scope', 'ref'],
62
+ step: ['transition', 'ref', 'scope'],
63
+ decisions: ['decision'],
64
+ decision: ['statement', 'rationale', 'ref'],
65
+ ref: [],
66
+ transition: [],
67
+ };
68
+ function sameScope(a, b) {
69
+ return (a.kind === b.kind &&
70
+ (a.kind !== 'increment' || (b.kind === 'increment' && a.increment === b.increment)));
71
+ }
72
+ function readScope(props) {
73
+ if (typeof props.increment === 'string' && /^I[1-9][0-9]*$/.test(props.increment)) {
74
+ return { kind: 'increment', increment: props.increment };
75
+ }
76
+ if (props.deferred === true) {
77
+ return { kind: 'deferred' };
78
+ }
79
+ if (props.unassigned === true) {
80
+ return { kind: 'unassigned' };
81
+ }
82
+ return undefined;
83
+ }
84
+ /** Identify the established display forms before selecting the spec profile. */
85
+ function isDisplayForm(span, parent) {
86
+ if (span.name === 'step') {
87
+ return !parent && !Object.hasOwn(span.attrs, 'id');
88
+ }
89
+ if (span.name === 'node') {
90
+ return !parent && Object.hasOwn(span.attrs, 'name') && !Object.hasOwn(span.attrs, 'label');
91
+ }
92
+ if (span.name !== 'tree' || Object.hasOwn(span.attrs, 'id')) {
93
+ return false;
94
+ }
95
+ const children = scan(span.body).filter((child) => child.kind === 'island');
96
+ return (children.length > 0 &&
97
+ children.every((child) => child.name === 'folder' ||
98
+ child.name === 'file' ||
99
+ (child.name === 'node' &&
100
+ Object.hasOwn(child.attrs, 'name') &&
101
+ !Object.hasOwn(child.attrs, 'label'))));
102
+ }
103
+ /** Parse semantic components once, preserving source for every unsupported interpretation. */
104
+ export function parseProductSpec(source, options = {}) {
105
+ const diagnostics = [];
106
+ const offset = options.offset ?? 0;
107
+ if (options.schemaVersion !== undefined && options.schemaVersion !== 1) {
108
+ const node = {
109
+ kind: 'fallback',
110
+ source,
111
+ start: offset,
112
+ end: offset + source.length,
113
+ };
114
+ return {
115
+ nodes: [node],
116
+ diagnostics: [
117
+ {
118
+ code: 'unsupported-version',
119
+ message: `Unsupported product-spec schema version: ${String(options.schemaVersion)}`,
120
+ start: node.start,
121
+ end: node.end,
122
+ },
123
+ ],
124
+ };
125
+ }
126
+ const parse = (text, base, parent, scope) => scan(text).map((span) => {
127
+ const raw = text.slice(span.start, span.end);
128
+ const common = {
129
+ source: raw,
130
+ start: base + span.start,
131
+ end: base + span.end,
132
+ ...(scope ? { scope } : {}),
133
+ };
134
+ const fallback = (code, message) => {
135
+ diagnostics.push({ code, message, start: common.start, end: common.end });
136
+ return { ...common, kind: 'fallback' };
137
+ };
138
+ if (span.kind === 'prose') {
139
+ return { ...common, kind: 'prose' };
140
+ }
141
+ if (span.kind === 'malformed') {
142
+ return fallback('malformed-component', span.reason);
143
+ }
144
+ const name = span.name;
145
+ const isSpec = Object.hasOwn(productSpecSchemas, name) && !isDisplayForm(span, parent);
146
+ if (!isSpec) {
147
+ if (Object.hasOwn(leoRegistry, name)) {
148
+ return { ...common, kind: 'display', island: span };
149
+ }
150
+ return fallback('unknown-component', `Unknown component <leo.${name}>`);
151
+ }
152
+ // Only references participate in ordinary inline prose in the spec profile.
153
+ const prefix = text.slice(text.lastIndexOf('\n', span.start - 1) + 1, span.start);
154
+ const followsComponent = /<\/leo\.[a-z]+>\s*$/.test(prefix) || /\/>\s*$/.test(prefix);
155
+ if (!parent && name !== 'ref' && prefix.trim() && !followsComponent) {
156
+ return { ...common, kind: 'prose' };
157
+ }
158
+ const specName = name;
159
+ if (parent &&
160
+ productSpecChildren[parent] &&
161
+ !productSpecChildren[parent]?.includes(specName)) {
162
+ return fallback('invalid-component', `<leo.${name}> is not valid inside <leo.${parent}>`);
163
+ }
164
+ const coerced = coerceProps(productSpecSchemas[specName], span.attrs);
165
+ const errors = [...coerced.errors];
166
+ for (const [key, value] of Object.entries(span.attrs)) {
167
+ if (Object.hasOwn(productSpecSchemas[specName], key) &&
168
+ value.trim() === '' &&
169
+ productSpecSchemas[specName][key]?.required) {
170
+ errors.push(`Empty required attribute ${key}`);
171
+ }
172
+ }
173
+ const props = coerced.props;
174
+ let effectiveScope = scope;
175
+ if (specName === 'scope') {
176
+ const next = readScope(props);
177
+ if (!next || Object.keys(span.attrs).length !== 1) {
178
+ errors.push('Scope requires exactly one valid disposition');
179
+ }
180
+ else if (scope && scope.kind !== 'unassigned' && !sameScope(scope, next)) {
181
+ errors.push('Conflicting nested delivery scope');
182
+ }
183
+ else {
184
+ effectiveScope = next;
185
+ }
186
+ }
187
+ if (specName === 'transition' && span.body.trim()) {
188
+ errors.push('Transition cannot contain a body');
189
+ }
190
+ if (errors.length) {
191
+ return fallback('invalid-component', `<leo.${name}>: ${errors.join('; ')}`);
192
+ }
193
+ const bodyStart = base + (span.bodyStart ?? span.end - `</leo.${name}>`.length - span.body.length);
194
+ const children = parse(span.body, bodyStart, specName === 'scope' ? parent : specName, effectiveScope);
195
+ return {
196
+ ...common,
197
+ kind: 'component',
198
+ name: specName,
199
+ props,
200
+ body: span.body,
201
+ bodyStart,
202
+ children,
203
+ ...(effectiveScope ? { scope: effectiveScope } : {}),
204
+ };
205
+ });
206
+ return { nodes: parse(source, offset), diagnostics };
207
+ }
208
+ /** Feed already interpreted nodes into the shared Markdown composition mechanism. */
209
+ export function composeProductSpecNodes(nodes) {
210
+ const source = nodes.map((node) => node.source).join('');
211
+ const byOffset = new Map();
212
+ let offset = 0;
213
+ const spans = nodes.map((node) => {
214
+ const start = offset;
215
+ const end = start + node.source.length;
216
+ offset = end;
217
+ byOffset.set(start, node);
218
+ if (node.kind === 'component') {
219
+ return {
220
+ kind: 'island',
221
+ name: node.name,
222
+ attrs: {},
223
+ body: node.body,
224
+ bodyStart: start + node.bodyStart - node.start,
225
+ selfClosing: node.body === '',
226
+ start,
227
+ end,
228
+ };
229
+ }
230
+ if (node.kind === 'display') {
231
+ return { ...node.island, start, end };
232
+ }
233
+ if (node.kind === 'fallback') {
234
+ return { kind: 'malformed', reason: 'unclosed-body', text: node.source, start, end };
235
+ }
236
+ return { kind: 'prose', text: node.source, start, end };
237
+ });
238
+ return { ...composeMarkdownIslands(source, productSpecRegistry, spans), byOffset };
239
+ }
240
+ //# sourceMappingURL=product-spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-spec.js","sourceRoot":"","sources":["../src/product-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC,MAAM,cAAc,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAW,CAAC;AACnE,MAAM,cAAc,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAW,CAAC;AAEnD,yFAAyF;AACzF,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAC9B,SAAS,EAAE,EAAE;IACb,QAAQ,EAAE;QACN,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,cAAc;QACrB,IAAI,EAAE;YACF,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC;SAChE;KACJ;IACD,OAAO,EAAE,EAAE,EAAE,EAAE,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I,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;QAC1C,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC3B,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;QACzF,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IAC5D,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,sBAAsB,CAAC,MAAM,EAAE,mBAAmB,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;AACvF,CAAC","sourcesContent":["import { composeMarkdownIslands } from './block-inline.js';\nimport { coerceProps, leoRegistry } from './registry.js';\nimport { scan } from './scanner.js';\nimport type { DocSpan, IslandSpan, LeoComponent, LeoRegistry, PropSchema } from './types.js';\n\nconst requiredString = { kind: 'string', required: true } as const;\nconst optionalString = { kind: 'string' } as const;\n\n/** The authored product-spec profile; display step/tree contracts remain independent. */\nexport const productSpecSchemas = {\n documents: {},\n document: {\n path: requiredString,\n title: requiredString,\n role: {\n kind: 'enum',\n required: true,\n values: ['index', 'decisions', 'detail', 'glossary', 'audit'],\n },\n },\n journey: { id: requiredString, title: requiredString },\n step: { id: requiredString },\n transition: { to: requiredString, when: requiredString },\n tree: { id: requiredString, title: optionalString },\n node: { label: requiredString, id: optionalString },\n scope: {\n increment: optionalString,\n deferred: { kind: 'boolean' },\n unassigned: { kind: 'boolean' },\n },\n ref: { relation: requiredString, target: requiredString },\n decisions: {},\n decision: {\n id: requiredString,\n title: requiredString,\n status: { kind: 'enum', required: true, values: ['accepted', 'superseded'] },\n architectural: { kind: 'boolean' },\n },\n statement: {},\n rationale: {},\n} as const satisfies Record<string, PropSchema>;\n\nexport type ProductSpecName = keyof typeof productSpecSchemas;\nexport type DeliveryScope =\n | { readonly kind: 'increment'; readonly increment: string }\n | { readonly kind: 'deferred' | 'unassigned' };\n\n/** Explicit capability profile: web consumers retain source until they implement these nodes. */\nexport const productSpecRegistry: LeoRegistry = Object.freeze({\n ...leoRegistry,\n ...Object.fromEntries(\n Object.entries(productSpecSchemas).map(([name, props]) => [\n name,\n {\n name,\n flow: name === 'ref' ? 'inline' : 'block',\n props,\n targets: 'terminal-only',\n degrade: {\n kind: 'note',\n text: 'Product-spec component: inspect source on this surface',\n },\n } satisfies LeoComponent,\n ])\n ),\n});\n\ninterface SourceNode {\n readonly start: number;\n readonly end: number;\n readonly source: string;\n readonly scope?: DeliveryScope;\n}\n\nexport interface ProductSpecComponent extends SourceNode {\n readonly kind: 'component';\n readonly name: ProductSpecName;\n readonly props: Readonly<Record<string, string | boolean>>;\n readonly bodyStart: number;\n readonly body: string;\n readonly children: readonly ProductSpecNode[];\n}\n\nexport type ProductSpecText = SourceNode &\n ({ readonly kind: 'prose' } | { readonly kind: 'fallback' });\n\nexport interface ProductSpecDisplay extends SourceNode {\n readonly kind: 'display';\n readonly island: IslandSpan;\n}\n\nexport type ProductSpecNode = ProductSpecComponent | ProductSpecText | ProductSpecDisplay;\nexport interface ProductSpecDiagnostic {\n readonly code:\n | 'invalid-component'\n | 'unknown-component'\n | 'malformed-component'\n | 'unsupported-version';\n readonly message: string;\n readonly start: number;\n readonly end: number;\n}\nexport interface ProductSpecParseResult {\n readonly nodes: readonly ProductSpecNode[];\n readonly diagnostics: readonly ProductSpecDiagnostic[];\n}\n\n/** The product-spec children each component accepts; a missing entry accepts any. */\nexport const productSpecChildren: Partial<Record<ProductSpecName, readonly ProductSpecName[]>> = {\n documents: ['document'],\n journey: ['step', 'scope'],\n tree: ['node', 'scope'],\n node: ['node', 'scope', 'ref'],\n step: ['transition', 'ref', 'scope'],\n decisions: ['decision'],\n decision: ['statement', 'rationale', 'ref'],\n ref: [],\n transition: [],\n};\n\nfunction sameScope(a: DeliveryScope, b: DeliveryScope): boolean {\n return (\n a.kind === b.kind &&\n (a.kind !== 'increment' || (b.kind === 'increment' && a.increment === b.increment))\n );\n}\n\nfunction readScope(props: Readonly<Record<string, string | boolean>>): DeliveryScope | undefined {\n if (typeof props.increment === 'string' && /^I[1-9][0-9]*$/.test(props.increment)) {\n return { kind: 'increment', increment: props.increment };\n }\n if (props.deferred === true) {\n return { kind: 'deferred' };\n }\n if (props.unassigned === true) {\n return { kind: 'unassigned' };\n }\n return undefined;\n}\n\n/** Identify the established display forms before selecting the spec profile. */\nfunction isDisplayForm(span: IslandSpan, parent?: ProductSpecName): boolean {\n if (span.name === 'step') {\n return !parent && !Object.hasOwn(span.attrs, 'id');\n }\n if (span.name === 'node') {\n return !parent && Object.hasOwn(span.attrs, 'name') && !Object.hasOwn(span.attrs, 'label');\n }\n if (span.name !== 'tree' || Object.hasOwn(span.attrs, 'id')) {\n return false;\n }\n const children = scan(span.body).filter((child) => child.kind === 'island');\n return (\n children.length > 0 &&\n children.every(\n (child) =>\n child.name === 'folder' ||\n child.name === 'file' ||\n (child.name === 'node' &&\n Object.hasOwn(child.attrs, 'name') &&\n !Object.hasOwn(child.attrs, 'label'))\n )\n );\n}\n\n/** Parse semantic components once, preserving source for every unsupported interpretation. */\nexport function parseProductSpec(\n source: string,\n options: { readonly schemaVersion?: unknown; readonly offset?: number } = {}\n): ProductSpecParseResult {\n const diagnostics: ProductSpecDiagnostic[] = [];\n const offset = options.offset ?? 0;\n if (options.schemaVersion !== undefined && options.schemaVersion !== 1) {\n const node = {\n kind: 'fallback',\n source,\n start: offset,\n end: offset + source.length,\n } as const;\n return {\n nodes: [node],\n diagnostics: [\n {\n code: 'unsupported-version',\n message: `Unsupported product-spec schema version: ${String(options.schemaVersion)}`,\n start: node.start,\n end: node.end,\n },\n ],\n };\n }\n\n const parse = (\n text: string,\n base: number,\n parent?: ProductSpecName,\n scope?: DeliveryScope\n ): ProductSpecNode[] =>\n scan(text).map((span): ProductSpecNode => {\n const raw = text.slice(span.start, span.end);\n const common = {\n source: raw,\n start: base + span.start,\n end: base + span.end,\n ...(scope ? { scope } : {}),\n };\n const fallback = (\n code: ProductSpecDiagnostic['code'],\n message: string\n ): ProductSpecText => {\n diagnostics.push({ code, message, start: common.start, end: common.end });\n return { ...common, kind: 'fallback' };\n };\n if (span.kind === 'prose') {\n return { ...common, kind: 'prose' };\n }\n if (span.kind === 'malformed') {\n return fallback('malformed-component', span.reason);\n }\n const name = span.name;\n const isSpec = Object.hasOwn(productSpecSchemas, name) && !isDisplayForm(span, parent);\n if (!isSpec) {\n if (Object.hasOwn(leoRegistry, name)) {\n return { ...common, kind: 'display', island: span };\n }\n return fallback('unknown-component', `Unknown component <leo.${name}>`);\n }\n // Only references participate in ordinary inline prose in the spec profile.\n const prefix = text.slice(text.lastIndexOf('\\n', span.start - 1) + 1, span.start);\n const followsComponent = /<\\/leo\\.[a-z]+>\\s*$/.test(prefix) || /\\/>\\s*$/.test(prefix);\n if (!parent && name !== 'ref' && prefix.trim() && !followsComponent) {\n return { ...common, kind: 'prose' };\n }\n const specName = name as ProductSpecName;\n if (\n parent &&\n productSpecChildren[parent] &&\n !productSpecChildren[parent]?.includes(specName)\n ) {\n return fallback(\n 'invalid-component',\n `<leo.${name}> is not valid inside <leo.${parent}>`\n );\n }\n const coerced = coerceProps(productSpecSchemas[specName], span.attrs);\n const errors = [...coerced.errors];\n for (const [key, value] of Object.entries(span.attrs)) {\n if (\n Object.hasOwn(productSpecSchemas[specName], key) &&\n value.trim() === '' &&\n (productSpecSchemas[specName] as PropSchema)[key]?.required\n ) {\n errors.push(`Empty required attribute ${key}`);\n }\n }\n const props = coerced.props as Record<string, string | boolean>;\n let effectiveScope = scope;\n if (specName === 'scope') {\n const next = readScope(props);\n if (!next || Object.keys(span.attrs).length !== 1) {\n errors.push('Scope requires exactly one valid disposition');\n } else if (scope && scope.kind !== 'unassigned' && !sameScope(scope, next)) {\n errors.push('Conflicting nested delivery scope');\n } else {\n effectiveScope = next;\n }\n }\n if (specName === 'transition' && span.body.trim()) {\n errors.push('Transition cannot contain a body');\n }\n if (errors.length) {\n return fallback('invalid-component', `<leo.${name}>: ${errors.join('; ')}`);\n }\n const bodyStart =\n base + (span.bodyStart ?? span.end - `</leo.${name}>`.length - span.body.length);\n const children = parse(\n span.body,\n bodyStart,\n specName === 'scope' ? parent : specName,\n effectiveScope\n );\n return {\n ...common,\n kind: 'component',\n name: specName,\n props,\n body: span.body,\n bodyStart,\n children,\n ...(effectiveScope ? { scope: effectiveScope } : {}),\n };\n });\n return { nodes: parse(source, offset), diagnostics };\n}\n\n/** Feed already interpreted nodes into the shared Markdown composition mechanism. */\nexport function composeProductSpecNodes(nodes: readonly ProductSpecNode[]) {\n const source = nodes.map((node) => node.source).join('');\n const byOffset = new Map<number, ProductSpecNode>();\n let offset = 0;\n const spans: DocSpan[] = nodes.map((node): DocSpan => {\n const start = offset;\n const end = start + node.source.length;\n offset = end;\n byOffset.set(start, node);\n if (node.kind === 'component') {\n return {\n kind: 'island',\n name: node.name,\n attrs: {},\n body: node.body,\n bodyStart: start + node.bodyStart - node.start,\n selfClosing: node.body === '',\n start,\n end,\n };\n }\n if (node.kind === 'display') {\n return { ...node.island, start, end };\n }\n if (node.kind === 'fallback') {\n return { kind: 'malformed', reason: 'unclosed-body', text: node.source, start, end };\n }\n return { kind: 'prose', text: node.source, start, end };\n });\n return { ...composeMarkdownIslands(source, productSpecRegistry, spans), byOffset };\n}\n"]}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The `leo` registry — the allow-list.
3
+ *
4
+ * A single object keyed by the LOWERCASE authored name (`leo.callout` resolves
5
+ * `registry['callout']`). Each entry declares its `targets`, its canonical
6
+ * `PropSchema` (the one contract both the ANSI and web emitters adapt to), its
7
+ * Markdown flow placement,
8
+ * and a `degrade` strategy for any surface it does not target.
9
+ *
10
+ * EMITTERS ARE NOT WIRED HERE. This module declares the vocabulary, targets,
11
+ * placement, and prop schemas; the concrete `ansi` emitters are attached by
12
+ * leo-pty-renderer and the `web` emitters by leo-doc-web.
13
+ * The parity harness (src/parity.ts) checks the contract against whatever
14
+ * registry it is given; the FULLY-WIRED registry only satisfies the `both`
15
+ * entries once those emitters are attached.
16
+ *
17
+ * Prop-schema conflicts: where leo's ANSI attrs and Glottodoc's web props
18
+ * disagree, leo's ANSI attrs WIN (the smaller, stable subset). Each such
19
+ * choice is recorded inline as a `note` on the prop so the canonical decision is
20
+ * auditable.
21
+ */
22
+ import type { LeoComponent, LeoRegistry, PropSchema } from './types.js';
23
+ /**
24
+ * The canonical leo registry. Frozen so callers cannot mutate the allow-list at
25
+ * runtime. The port-backs (progress, card, metric, icon) are now `both`
26
+ * (their second-surface emitters have landed).
27
+ */
28
+ export declare const leoRegistry: LeoRegistry;
29
+ /**
30
+ * Resolve a lowercase authored name (`callout`) to its registry entry, against
31
+ * the provided registry root (the renderer always provides one — a missing root
32
+ * is a programmer error). Returns `undefined` for an unknown name; the
33
+ * caller treats unknown `<leo.X>` as an authoring error (a lint surfaces it —
34
+ * never silently rendered).
35
+ */
36
+ export declare function resolve(name: string, registry?: LeoRegistry): LeoComponent | undefined;
37
+ /** True iff `name` is in the allow-list. */
38
+ export declare function isKnown(name: string, registry?: LeoRegistry): boolean;
39
+ export interface CoerceResult {
40
+ /** Coerced props (defaults applied, types converted). */
41
+ readonly props: Record<string, unknown>;
42
+ /** Validation errors (unknown enum value, missing required, bad JSON). */
43
+ readonly errors: readonly string[];
44
+ }
45
+ /**
46
+ * Coerce/validate raw (string) scanned attrs against a component's PropSchema.
47
+ * Attributes arrive as strings; per-prop the schema converts to the
48
+ * declared kind, applies defaults, and validates enums / required / JSON. An
49
+ * unknown attr (not in the schema) is dropped with a recorded error — the schema
50
+ * is the contract.
51
+ */
52
+ export declare function coerceProps(schema: PropSchema, attrs: Readonly<Record<string, string>>): CoerceResult;
53
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAOH,OAAO,KAAK,EAAc,YAAY,EAAE,WAAW,EAAY,UAAU,EAAE,MAAM,YAAY,CAAC;AA6Y9F;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,WAOxB,CAAC;AAIH;;;;;;GAMG;AACH,wBAAgB,OAAO,CACnB,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,WAAyB,GACpC,YAAY,GAAG,SAAS,CAI1B;AAED,4CAA4C;AAC5C,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,WAAyB,GAAG,OAAO,CAElF;AAID,MAAM,WAAW,YAAY;IACzB,yDAAyD;IACzD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACvB,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACxC,YAAY,CA2Bd"}