@aestheticfunction/dspack-emit 0.4.1 → 0.6.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 (72) hide show
  1. package/README.md +16 -6
  2. package/dist/cli.js +56 -0
  3. package/dist/index.d.ts +4 -1
  4. package/dist/index.js +3 -1
  5. package/dist/targets/a2ui/diagnostics.d.ts +110 -0
  6. package/dist/targets/a2ui/diagnostics.js +94 -0
  7. package/dist/targets/a2ui/surface.d.ts +28 -9
  8. package/dist/targets/a2ui/surface.js +1004 -222
  9. package/dist/transform/desugar.d.ts +32 -0
  10. package/dist/transform/desugar.js +156 -0
  11. package/dist/transform/emit.js +59 -0
  12. package/dist/transform/index.js +4 -0
  13. package/dist/transform/mapping.d.ts +0 -6
  14. package/dist/transform/mapping.js +66 -2
  15. package/dist/transform/model.d.ts +368 -0
  16. package/dist/transform/model.js +169 -0
  17. package/dist/transform/parse-v2.d.ts +109 -0
  18. package/dist/transform/parse-v2.js +479 -0
  19. package/dist/transform/profile-load.d.ts +7 -6
  20. package/dist/transform/profile-load.js +99 -20
  21. package/dist/transform/profile-schema-v2.d.ts +9 -0
  22. package/dist/transform/profile-schema-v2.js +608 -0
  23. package/dist/transform/profiles.d.ts +31 -1
  24. package/dist/transform/scaffold.d.ts +29 -12
  25. package/dist/transform/scaffold.js +91 -31
  26. package/dist/transform/shadcn-v2-respelling.d.ts +77 -0
  27. package/dist/transform/shadcn-v2-respelling.js +456 -0
  28. package/dist/transform/validate-v2.d.ts +36 -0
  29. package/dist/transform/validate-v2.js +136 -0
  30. package/dist/types.d.ts +23 -0
  31. package/dist/validate/ajv.js +96 -25
  32. package/dist/validate/meta/a2ui-catalog.meta.0_9_1.json +39 -0
  33. package/dist/validate/meta/a2ui-catalog.meta.1_0.json +34 -0
  34. package/package.json +2 -2
  35. package/src/__snapshots__/byte-neutral.test.ts.snap +66 -0
  36. package/src/a0.test.ts +235 -0
  37. package/src/byte-neutral.test.ts +246 -0
  38. package/src/cli.ts +60 -0
  39. package/src/dangling-ref.test.ts +118 -0
  40. package/src/desugar.test.ts +162 -0
  41. package/src/engine-boundary.test.ts +248 -0
  42. package/src/eval-fixture.test.ts +102 -0
  43. package/src/functions.test.ts +182 -0
  44. package/src/index.ts +4 -1
  45. package/src/layered-dissolution.test.ts +139 -0
  46. package/src/profile-load.test.ts +99 -1
  47. package/src/profile-v2.test.ts +369 -0
  48. package/src/review-findings.test.ts +292 -0
  49. package/src/schema-mirrors.test.ts +5 -0
  50. package/src/surface-fidelity.test.ts +213 -0
  51. package/src/t1.test.ts +369 -0
  52. package/src/t2.test.ts +222 -0
  53. package/src/t3.test.ts +304 -0
  54. package/src/t4.test.ts +278 -0
  55. package/src/targets/a2ui/diagnostics.ts +136 -0
  56. package/src/targets/a2ui/surface.ts +1468 -235
  57. package/src/transform/desugar.ts +194 -0
  58. package/src/transform/emit.ts +65 -0
  59. package/src/transform/index.ts +5 -0
  60. package/src/transform/mapping.ts +60 -2
  61. package/src/transform/model.ts +427 -0
  62. package/src/transform/parse-v2.ts +608 -0
  63. package/src/transform/profile-load.ts +104 -22
  64. package/src/transform/profile-schema-v2.ts +608 -0
  65. package/src/transform/profile.v2.schema.json +600 -0
  66. package/src/transform/profiles.ts +32 -1
  67. package/src/transform/scaffold.ts +124 -47
  68. package/src/transform/shadcn-v2-respelling.ts +475 -0
  69. package/src/transform/validate-v2.ts +174 -0
  70. package/src/types.ts +32 -0
  71. package/src/validate/ajv.ts +89 -26
  72. package/src/validate-v2.test.ts +173 -0
@@ -1,17 +1,34 @@
1
1
  /**
2
- * scaffoldProfile: a mechanical 1:1 draft Profile from a dspack contract.
2
+ * scaffoldProfile: a mechanical draft Profile from a dspack contract — in the
3
+ * v2 primitive language, honest about what it cannot decide.
3
4
  *
4
- * Seeded from the json-render CatalogModel (the judgment-free 1:1 IR): every
5
- * top-level contract component becomes a ComponentPlan with verbatim prop
6
- * projections; compound sub-components get subFlatten directives derived from
7
- * their *declared* `acceptsChildren` (text → asText, otherwise transparent).
5
+ * The old scaffold had two measured failures. For props-based contracts it
6
+ * emitted no surface plan at all, so any surface with children hit a hard
7
+ * throw — catalog-valid, surface-unusable, for exactly the idiom the docs
8
+ * call typical. And for compounds it INVENTED the judgment it should have
9
+ * surfaced: every sub auto-classified transparent-or-asText from
10
+ * `acceptsChildren`, which is precisely the guess that is wrong for a
11
+ * repeated item like `radio-group-item` (the measured T2 gap).
8
12
  *
9
- * The scaffold invents no judgment: no valueMaps, no casualties, no lossy
10
- * projections. Everything a human must review is returned as `notes` — the
11
- * scaffold's analog of dspack-export's `awaitingAuthorship`. The result is a
12
- * valid v1 profile document (loadProfile accepts it) whose transform passes
13
- * gates A1/A2 with full coverage; whether each mapping is *right* is the
14
- * author's call.
13
+ * This scaffold derives instead of guessing:
14
+ *
15
+ * - identity and verbatim prop projections, as before — provable 1:1;
16
+ * - a `children` route where the contract OBSERVABLY supports children:
17
+ * the component appears with child nodes in a worked example, or declares
18
+ * sub-components. Provenance lands in the synthNote;
19
+ * - a `text` route where a worked example shows the component carrying text;
20
+ * - sub-components are NOT decided. Each one is an explicit unresolved
21
+ * decision: listed in `notes`, recorded under `x-scaffold.unresolved`, and
22
+ * absent from the surface block — which the v2 contract gate then refuses
23
+ * to transform, per sub, until the author decides (route, collect,
24
+ * transparent, asText, or drop with a reason). A scaffold that transforms
25
+ * before those decisions exist would be inventing them.
26
+ *
27
+ * The result loads (loadProfile accepts it). For a contract with no compound
28
+ * sub-families it transforms immediately; for one with compounds, transform
29
+ * refuses with the exact per-sub checklist. That refusal is the deliverable:
30
+ * the scaffold's job is to make the remaining judgment explicit, not to
31
+ * pretend it has been exercised.
15
32
  */
16
33
  import type { DspackDoc } from "../types.js";
17
34
  export interface ScaffoldOptions {
@@ -32,7 +49,7 @@ export interface ScaffoldNote {
32
49
  note: string;
33
50
  }
34
51
  export interface ScaffoldResult {
35
- /** A v1 profile *document* (includes profileVersion; loadProfile accepts it). */
52
+ /** A v2 profile *document* (includes profileVersion; loadProfile accepts it). */
36
53
  profile: Record<string, unknown>;
37
54
  /** Everything that needs human judgment before the profile is trustworthy. */
38
55
  notes: ScaffoldNote[];
@@ -1,7 +1,6 @@
1
1
  import { buildCatalogModel } from "../targets/json-render/model.js";
2
2
  const DYN_STRING = { $ref: "#/$defs/DynamicString" };
3
3
  const CHILD_LIST = { $ref: "#/$defs/ChildList" };
4
- const COMP_ID = { $ref: "#/$defs/ComponentId" };
5
4
  const TEXT_PLAN = {
6
5
  a2ui: "Text",
7
6
  commons: ["ComponentCommon"],
@@ -48,13 +47,44 @@ function subsOf(doc, id) {
48
47
  }
49
48
  return out;
50
49
  }
50
+ /**
51
+ * What the contract's own worked examples show each component doing. The
52
+ * example corpus is the contract's definition of "expressible", which makes
53
+ * this measurement, not judgment: a component observed with children needs a
54
+ * children story; one observed with text needs a text story.
55
+ */
56
+ function observeExamples(doc) {
57
+ const seen = new Map();
58
+ const examples = doc.examples ?? [];
59
+ const visit = (node, exampleId) => {
60
+ if (!node || typeof node !== "object")
61
+ return;
62
+ const n = node;
63
+ if (typeof n.component === "string") {
64
+ const entry = seen.get(n.component) ?? {};
65
+ const childNodes = [...(n.children ?? []), ...Object.values(n.slots ?? {}).flat()];
66
+ if (childNodes.length > 0 && entry.children === undefined)
67
+ entry.children = exampleId;
68
+ if (typeof n.text === "string" && entry.text === undefined)
69
+ entry.text = exampleId;
70
+ seen.set(n.component, entry);
71
+ for (const child of childNodes)
72
+ visit(child, exampleId);
73
+ }
74
+ };
75
+ for (const ex of examples)
76
+ visit(ex.surface?.root, ex.id ?? "(unnamed example)");
77
+ return seen;
78
+ }
51
79
  export function scaffoldProfile(doc, options) {
52
80
  const notes = [];
53
81
  const model = buildCatalogModel(doc, {});
54
82
  const byId = new Map(model.components.map((c) => [c.dspackId, c]));
55
83
  const topLevelIds = Object.keys(doc.components ?? {});
56
84
  const name = (id) => byId.get(id)?.name ?? id;
85
+ const observed = observeExamples(doc);
57
86
  const usedNames = new Set(topLevelIds.map((id) => name(id)));
87
+ const unresolvedByComponent = {};
58
88
  const components = topLevelIds.map((id) => {
59
89
  const entry = byId.get(id);
60
90
  const contractProps = (doc.components?.[id]?.props ?? {});
@@ -82,43 +112,65 @@ export function scaffoldProfile(doc, options) {
82
112
  .filter(([, p]) => p.required === true)
83
113
  .map(([propName]) => propName)
84
114
  .filter((propName) => propName in propMap);
115
+ const structural = {};
116
+ const routes = [];
117
+ const subs = subsOf(doc, id);
118
+ const seen = observed.get(id) ?? {};
119
+ // Children: only where the contract observably supports them — a worked
120
+ // example shows child nodes, or the component declares sub-components
121
+ // (whose instances arrive as its children in every surface).
122
+ const childrenBecause = seen.children
123
+ ? `observed with child nodes in worked example '${seen.children}'`
124
+ : subs.length > 0
125
+ ? `declares ${subs.length} sub-component(s), which arrive as its children in surfaces`
126
+ : undefined;
127
+ if (childrenBecause) {
128
+ structural.children = {
129
+ schema: CHILD_LIST,
130
+ description: "Child component IDs, in order.",
131
+ synthNote: `Scaffolded: ${childrenBecause}.`,
132
+ };
133
+ required.push("children");
134
+ routes.push({ from: ["children"], to: "slots:children" });
135
+ }
136
+ // Text: only where a worked example shows the component carrying it.
137
+ if (seen.text) {
138
+ structural.text = {
139
+ schema: DYN_STRING,
140
+ description: "The component's text content.",
141
+ synthNote: `Scaffolded: observed carrying text in worked example '${seen.text}'.`,
142
+ };
143
+ routes.push({ from: ["self.text"], to: "prop:text" });
144
+ }
145
+ if (!childrenBecause && !seen.text && Object.keys(propMap).length === 0) {
146
+ notes.push({
147
+ target: id,
148
+ note: "no declarative props, and never observed with children or text in a worked example; the contract likely needs enrichment before this mapping is useful.",
149
+ });
150
+ }
85
151
  const plan = {
86
152
  a2ui: entry.name,
87
153
  dspackId: id,
88
154
  commons: ["ComponentCommon"],
89
- structural: {},
155
+ structural,
90
156
  required,
91
157
  };
92
158
  if (Object.keys(propMap).length > 0)
93
159
  plan.propMap = propMap;
94
- else
95
- notes.push({
96
- target: id,
97
- note: "no declarative props were scaffolded; the contract likely needs prop enrichment before this mapping is useful.",
98
- });
99
- const subs = subsOf(doc, id);
160
+ if (routes.length > 0)
161
+ plan.surface = { routes };
162
+ // Sub-components: explicit unresolved decisions, never guesses. The v2
163
+ // contract gate refuses to transform until each is decided — that refusal,
164
+ // with its per-sub checklist, is the scaffold handing judgment to its
165
+ // owner rather than exercising it.
100
166
  if (subs.length > 0) {
101
- const transparent = subs.filter((s) => s.acceptsChildren !== "text").map((s) => s.id);
102
- const asText = Object.fromEntries(subs.filter((s) => s.acceptsChildren === "text").map((s) => [s.id, "body"]));
103
- plan.structural = {
104
- child: {
105
- schema: COMP_ID,
106
- description: "The ID of the single child component. Wrap multiple elements in a Column and pass its ID.",
107
- synthNote: "Scaffolded: the compound's sub-components flatten (subFlatten) and collapse to a single, possibly Column-wrapped, child slot.",
108
- },
109
- };
110
- plan.required.push("child");
111
- plan.surfacePlan = { childProp: "child", subFlatten: { transparent, asText } };
112
- plan.subCoverage = Object.fromEntries(subs.map((s) => [
113
- s.id,
114
- s.acceptsChildren === "text"
115
- ? "text -> synthesized Text (variant body) [scaffolded from acceptsChildren: text — review]"
116
- : "transparent grouping: children splice inline, in order [scaffolded — review]",
117
- ]));
118
- notes.push({
119
- target: id,
120
- note: `compound scaffolded from declared acceptsChildren (${subs.length} sub-components: ${transparent.length} transparent, ${Object.keys(asText).length} asText); review each subCoverage line and pick text variants.`,
121
- });
167
+ unresolvedByComponent[id] = subs.map((s) => s.id);
168
+ for (const sub of subs) {
169
+ notes.push({
170
+ target: `${id}.${sub.id}`,
171
+ note: "unresolved sub-component: decide route (consume its text/label), collect (repeated items), transparent (dissolve), asText (re-identify), or drop (with a reason). transform() refuses until this is decided.",
172
+ });
173
+ }
122
174
  }
123
175
  return plan;
124
176
  });
@@ -146,10 +198,10 @@ export function scaffoldProfile(doc, options) {
146
198
  });
147
199
  }
148
200
  const profile = {
149
- profileVersion: "1",
201
+ profileVersion: "2",
150
202
  catalogTitle: options.catalogTitle ?? `${doc.name} — A2UI catalog (compiled from dspack)`,
151
203
  catalogDescription: options.catalogDescription ??
152
- `A2UI catalog compiled from the ${doc.name} dspack contract by scaffoldProfile. Mechanical 1:1 draft: review the scaffold notes before trusting any mapping.`,
204
+ `A2UI catalog compiled from the ${doc.name} dspack contract by scaffoldProfile. Mechanical draft in the v2 primitive language: review the scaffold notes, and resolve every listed sub-component decision, before trusting any mapping.`,
153
205
  catalogIdBase: options.catalogIdBase,
154
206
  instructions: options.instructions ?? "For layout, use the Column component to organize other components.",
155
207
  primaryColorToken,
@@ -162,6 +214,14 @@ export function scaffoldProfile(doc, options) {
162
214
  wrapComponent: "Column",
163
215
  wrapChildrenProp: "children",
164
216
  },
217
+ ...(Object.keys(unresolvedByComponent).length > 0
218
+ ? {
219
+ "x-scaffold": {
220
+ unresolved: unresolvedByComponent,
221
+ note: "Every listed sub-component is an authoring decision the scaffold deliberately did not make. transform() refuses until each is resolved in the owning plan's surface block.",
222
+ },
223
+ }
224
+ : {}),
165
225
  };
166
226
  notes.push({
167
227
  target: "casualtyComponents",
@@ -0,0 +1,77 @@
1
+ /**
2
+ * The shadcn plans' v2 re-spelling — the six shipped v1 surface plans written
3
+ * in the primitive language. Byte-proven equivalent: src/profile-v2.test.ts
4
+ * emits every pinned artifact identically through these blocks.
5
+ *
6
+ * Shared by the keystone test and by eval/build-eval-profile.mjs, which
7
+ * transplants them onto a scaffold of the production v3 contract to build the
8
+ * reproducible coverage-evaluation fixture. One source, two consumers — the
9
+ * respelling is committed mapping evidence, not per-file copies.
10
+ */
11
+ import type { SurfaceV2 } from "./parse-v2.js";
12
+ export declare const SHADCN_V2_SURFACES: Record<string, SurfaceV2>;
13
+ /**
14
+ * T1 resolutions for the production v3 contract — the transparent-identity
15
+ * spellings proven by src/t1.test.ts against the named production failure
16
+ * (`card > form > form-field > form-item > form-label + input`). Consumed by
17
+ * the eval fixture builder as committed mapping evidence; the fixture's other
18
+ * unresolved decisions stay deliberately open.
19
+ */
20
+ export declare const SHADCN_V3_T1_SURFACES: Record<string, SurfaceV2>;
21
+ /**
22
+ * T2 resolutions for the production v3 contract — item-mode collection
23
+ * spellings proven by src/t2.test.ts. `radio-group` collects what each item
24
+ * itself carries ({value: self.id}); its htmlFor-joined sibling labels are
25
+ * the measured T3 frontier, dropped with record until declared joins land.
26
+ * `select` is the pure homogeneous shape ({label: self.text}).
27
+ *
28
+ * Each entry carries the full receiving plan (structural options schema) —
29
+ * unlike T1's transparent plans, a collecting plan IS a catalog component.
30
+ */
31
+ export declare const SHADCN_V3_T3_PLANS: Record<string, Record<string, unknown>>;
32
+ export declare const SHADCN_V3_T2_PLANS: Record<string, Record<string, unknown>>;
33
+ /**
34
+ * A0 authoring resolutions (the zero-new-capability milestone): production
35
+ * profile judgment for the families the shipped Identity/Routing/Repetition
36
+ * model already supports, proven by src/a0.test.ts. Six compound plans plus
37
+ * label-slot additions on the five controls that appear as a field's single
38
+ * control (the T1 donation destination). No new primitive anywhere.
39
+ *
40
+ * Grounded in measured usage across the 14 worked examples (contract 3.2.0):
41
+ * alert-title 5/5 + alert-description 5/5 carry the content; avatar-fallback
42
+ * carries text while avatar-image is an EMPTY node (the contract declares no
43
+ * src/alt — the dspack#39 class, recorded on the drop); scroll-area's two
44
+ * subs are scrollbar chrome; the field family follows the corrected
45
+ * declaration (dspack#40) with field as its own donating boundary.
46
+ */
47
+ export declare const SHADCN_V3_A0_PLANS: Record<string, Record<string, unknown>>;
48
+ /**
49
+ * A0 label additions: the five controls that appear as a field's (or
50
+ * form-item's) single control across the worked examples — input already
51
+ * declares `label`; these gain the same structural slot so the T1 donation
52
+ * has a declared destination. Merged onto the scaffolded plans (select's T2
53
+ * plan) by the fixture builder; nothing else on those plans changes.
54
+ */
55
+ export declare const SHADCN_V3_A0_LABEL_ADDITIONS: Record<string, {
56
+ description: string;
57
+ synthNote: string;
58
+ }>;
59
+ /**
60
+ * T4 resolutions: multi-slot compounds, proven by src/t4.test.ts. The new
61
+ * primitive is ONE closed spelling — `sub(x).children -> slot:name` — the
62
+ * region's ordered children emitted as instances, the slot carrying the
63
+ * reference (multi wraps in Column, exactly like T3's joined-children).
64
+ *
65
+ * Measured shapes (contract 3.2.0 worked examples):
66
+ * - dialog/sheet: trigger and close labels are TEXT lifts (the alert-dialog
67
+ * idiom); title/description lift; header dissolves; content minus the
68
+ * claimed regions is the body slot; footer minus close is the footer slot.
69
+ * - popover: same family; its measured body is EMPTY after the header
70
+ * dissolves — the slot stays absent and gate A3 arbitrates. The unused
71
+ * popover-anchor drops pending usage evidence.
72
+ * - dropdown-menu is DATA-shaped, not slot-shaped: its items are a T2
73
+ * item-mode collect and its labels are scalar text routes — resolved with
74
+ * ZERO new primitive. The historic taxonomy called it T4; measurement
75
+ * says otherwise, and the plan follows the measurement.
76
+ */
77
+ export declare const SHADCN_V3_T4_PLANS: Record<string, Record<string, unknown>>;