@reqvire-org/ads 0.4.2 → 0.4.4

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 (78) hide show
  1. package/README.md +11 -2
  2. package/dist/a11y.mjs +71 -65
  3. package/dist/analysis/helpers.mjs +5 -3
  4. package/dist/analysis/inputs.mjs +13 -6
  5. package/dist/analysis/module-resolvers.mjs +46 -0
  6. package/dist/analysis/service.mjs +7 -0
  7. package/dist/analysis/syntax.mjs +20 -5
  8. package/dist/assets.mjs +1 -1
  9. package/dist/boundaries.mjs +6 -4
  10. package/dist/bun-compiler.mjs +6 -5
  11. package/dist/check-service.mjs +8 -5
  12. package/dist/check.mjs +11 -46
  13. package/dist/component-contrast.mjs +126 -8
  14. package/dist/contrast-composition.mjs +80 -0
  15. package/dist/contrast-styles.mjs +88 -0
  16. package/dist/finding-rules.mjs +2 -0
  17. package/dist/font-rules.mjs +20 -15
  18. package/dist/fonts-generated.mjs +21 -14
  19. package/dist/foundation-views.mjs +6 -2
  20. package/dist/image-attributes.mjs +96 -92
  21. package/dist/mcp/build-status.mjs +8 -3
  22. package/dist/mcp/drafts.mjs +12 -5
  23. package/dist/mcp/mutations.mjs +11 -8
  24. package/dist/mcp/preview-widget.bundle.js +45 -45
  25. package/dist/mcp/resource-loader.js +1 -201
  26. package/dist/mcp/server.mjs +19 -5
  27. package/dist/pictogram-model.mjs +59 -0
  28. package/dist/pictograms.mjs +52 -0
  29. package/dist/preview-bun.mjs +76 -60
  30. package/dist/preview-incremental.mjs +358 -0
  31. package/dist/preview-manifest-update.mjs +70 -0
  32. package/dist/preview-resources.mjs +33 -1
  33. package/dist/render-audit/image-shape.mjs +13 -3
  34. package/dist/render-audit/pictograms.mjs +88 -0
  35. package/dist/render-audit/worker.mjs +12 -0
  36. package/dist/render-audit.mjs +11 -1
  37. package/dist/render-composition.mjs +186 -0
  38. package/dist/scenario-registry.mjs +2 -2
  39. package/dist/scenarios-compiler.mjs +1 -1
  40. package/dist/showcase/client.bundle.js +23 -23
  41. package/dist/showcase/draft-navigation.js +5 -5
  42. package/dist/showcase/foundation-view.css +3 -0
  43. package/dist/showcase/foundation-view.mjs +3 -0
  44. package/dist/showcase/pictogram-view.mjs +53 -0
  45. package/dist/showcase/ui/ui.js +2 -0
  46. package/dist/skills/README.md +1 -1
  47. package/dist/skills/ads-designer/SKILL.md +18 -2
  48. package/dist/skills/ads-designer/references/accessibility.md +70 -2
  49. package/dist/skills/ads-designer/references/branding.md +5 -16
  50. package/dist/skills/ads-designer/references/performance.md +3 -2
  51. package/dist/skills/ads-designer/references/pictograms.md +131 -0
  52. package/dist/skills/ads-designer/references/runtimes.md +15 -0
  53. package/dist/skills/ads-import/references/runtimes.md +15 -0
  54. package/dist/skills/ads-migrate/SKILL.md +2 -1
  55. package/dist/skills/ads-migrate/references/0.4.1-to-0.4.2.md +2 -3
  56. package/dist/skills/ads-migrate/references/0.4.3-to-0.4.4.md +80 -0
  57. package/dist/skills/ads-port/SKILL.md +4 -1
  58. package/dist/skills/ads-port/references/runtimes.md +15 -0
  59. package/dist/source-values.mjs +4 -1
  60. package/dist/starters/react/design-system/assets/pictograms/catalog.ads.json +13 -0
  61. package/dist/starters/react/design-system/assets/pictograms/journey.dark.svg +7 -0
  62. package/dist/starters/react/design-system/assets/pictograms/journey.svg +7 -0
  63. package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.exports.ts +1 -0
  64. package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.fixture.ts +1 -0
  65. package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.scenario.tsx +7 -0
  66. package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.tsx +26 -0
  67. package/dist/style-token-rules.mjs +51 -0
  68. package/dist/task-cache.mjs +2 -2
  69. package/dist/units.mjs +4 -4
  70. package/dist/validation-inputs.mjs +7 -3
  71. package/docs/ADS.md +6 -1
  72. package/docs/ARCHITECTURE.md +144 -16
  73. package/docs/CACHING.md +65 -1
  74. package/docs/CHANGELOG.md +86 -50
  75. package/docs/GUIDE.md +52 -7
  76. package/docs/MCP.md +47 -16
  77. package/docs/benchmarks/README.md +1 -1
  78. package/package.json +7 -4
@@ -1,9 +1,9 @@
1
- import { readFileSync } from "node:fs";
2
1
  import path from "node:path";
3
2
  import ts from "./analysis/syntax.mjs";
4
3
  import postcss from "postcss";
5
- import { isDevelopmentFile, isInside, isTestFile, sourceFiles } from "./config.mjs";
4
+ import { isDevelopmentFile, isInside, isTestFile } from "./config.mjs";
6
5
  import { findingSeverity } from "./finding-rules.mjs";
6
+ import { sourceAst, sourceText, memoProgram } from "./analysis/helpers.mjs";
7
7
 
8
8
  /** A raw <img> in component, pattern and composition source reserves its space and chooses how it
9
9
  * loads. It needs width and height, or a size its own style shows (aspect-ratio, or both a width
@@ -83,101 +83,105 @@ function classSize(expression, { variables, classes }) {
83
83
  return found ? true : unknown ? null : false;
84
84
  }
85
85
 
86
- export async function imageAttributeFindings({ root, dsRoot }) {
86
+ export async function imageAttributeFindings({ root, dsRoot }, sources) {
87
87
  const options = { root, dsRoot },
88
88
  findings = [];
89
89
  const inScope = (file) =>
90
90
  (isInside(path.join(dsRoot, "composition"), file) && !isTestFile(file)) ||
91
91
  (["components", "patterns"].some((layer) => isInside(path.join(dsRoot, layer), file)) && !isDevelopmentFile(file, options));
92
- for (const file of sourceFiles(dsRoot).filter((file) => /\.[jt]sx$/.test(file) && inScope(file))) {
93
- const text = readFileSync(file, "utf8");
94
- if (!/<(?:img|Image)\b/.test(text)) continue;
95
- const source = await ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX),
96
- relative = path.relative(root, file).replaceAll("\\", "/");
97
- const styles = fileStyles(source);
98
- const visit = (node) => {
99
- if (ts.isJsxSelfClosingElement(node) || ts.isJsxOpeningElement(node)) {
100
- const tag = node.tagName.getText(source);
101
- if (tag === "img" || tag === "Image") inspectCandidates(node, tag);
102
- if (tag === "img") inspect(node);
103
- }
104
- ts.forEachChild(node, visit);
105
- };
106
- /** Width descriptors say nothing about display size, so sizes must. */
107
- const inspectCandidates = (node, tag) => {
108
- const attributes = node.attributes.properties;
109
- const attribute = (name) => attributes.find((item) => ts.isJsxAttribute(item) && item.name.getText(source) === name);
110
- const candidates = attribute("srcset") ?? attribute("srcSet");
111
- if (!candidates || attribute("sizes")) return;
112
- const { line, character } = source.getLineAndCharacterOfPosition(node.getStart(source));
113
- const add = (rule, message) =>
114
- findings.push({
115
- rule,
116
- severity: findingSeverity(rule),
117
- file: relative,
118
- line: line + 1,
119
- column: character + 1,
120
- guidanceUri: guidance,
121
- message: `${relative}:${line + 1} ${message}`,
122
- });
123
- let value = candidates.initializer;
124
- if (value && ts.isJsxExpression(value)) value = value.expression;
125
- const literal = value && ts.isStringLiteralLike(value) ? value.text : null;
126
- if (attributes.some(ts.isJsxSpreadAttribute) || literal === null)
127
- add(
128
- "img-attributes-unresolved",
129
- `<${tag}> has a srcset ADS cannot read or spread props that may hold sizes. With width descriptors it needs sizes, the width it displays at.`,
130
- );
131
- else if (/\d\s*w\s*(?:,|$)/.test(literal.trim()))
132
- add(
133
- "img-attributes",
134
- `<${tag}> has a srcset with width descriptors and no sizes, so the browser assumes the full viewport width and can pick a larger file than it shows. Add sizes, such as "(min-width: 1024px) 50vw, 100vw".`,
135
- );
136
- };
137
- const inspect = (node) => {
138
- const { line, character } = source.getLineAndCharacterOfPosition(node.getStart(source));
139
- const add = (rule, message) =>
140
- findings.push({
141
- rule,
142
- severity: findingSeverity(rule),
143
- file: relative,
144
- line: line + 1,
145
- column: character + 1,
146
- guidanceUri: guidance,
147
- message: `${relative}:${line + 1} ${message}`,
148
- });
149
- const attributes = node.attributes.properties,
150
- spread = attributes.some(ts.isJsxSpreadAttribute);
151
- const attribute = (name) => attributes.find((item) => ts.isJsxAttribute(item) && item.name.getText(source) === name);
152
- const styleText = attribute("style")?.initializer?.getText(source) ?? "";
153
- const className = attribute("className") ?? attribute("class");
154
- let size = !!(attribute("width") && attribute("height")) || /\baspectRatio\b|aspect-ratio/.test(styleText) || styles.imgRule;
155
- if (!size && className?.initializer) size = classSize(className.initializer, styles);
156
- const loading = !!attribute("loading");
157
- if (spread && (size !== true || !loading)) {
158
- add(
159
- "img-attributes-unresolved",
160
- `spreads props onto <img>, so ADS cannot see its dimensions or loading. Pass width, height and loading explicitly so the page reserves the space and the load order is a choice.`,
161
- );
162
- return;
163
- }
164
- if (size === null)
165
- add(
166
- "img-attributes-unresolved",
167
- `styles <img> with a class ADS cannot read here, so its size is not checked. Set width and height so the page reserves the space.`,
168
- );
169
- if (size === false)
170
- add(
171
- "img-attributes",
172
- `<img> has no width and height or a visible aspect-ratio, so the page shifts when it loads. Set the file's width and height, or a sized aspect-ratio in its style.`,
173
- );
174
- if (!loading)
175
- add(
176
- "img-attributes",
177
- `<img> has no loading attribute. Use loading="lazy" below the fold; the page's main visible image uses loading="eager" with fetchpriority="high", or the project's image component with priority.`,
178
- );
179
- };
180
- visit(source);
92
+ for (const file of sources.filter((file) => /\.[jt]sx$/.test(file) && inScope(file))) {
93
+ if (!/<(?:img|Image)\b/.test(sourceText(file))) continue;
94
+ const source = await sourceAst(file), relative = path.relative(root, file).replaceAll("\\", "/");
95
+ findings.push(...memoProgram(source, `image-attributes:${relative}`, () => sourceFindings(source, relative)));
181
96
  }
182
97
  return findings;
183
98
  }
99
+
100
+ /** Local sizing/loading evidence; imported styles remain explicitly unresolved. */
101
+ function sourceFindings(source, relative) {
102
+ const findings = [], styles = fileStyles(source);
103
+ const visit = (node) => {
104
+ if (ts.isJsxSelfClosingElement(node) || ts.isJsxOpeningElement(node)) {
105
+ const tag = node.tagName.getText(source);
106
+ if (tag === "img" || tag === "Image") inspectCandidates(node, tag);
107
+ if (tag === "img") inspect(node);
108
+ }
109
+ ts.forEachChild(node, visit);
110
+ };
111
+ /** Width descriptors say nothing about display size, so sizes must. */
112
+ const inspectCandidates = (node, tag) => {
113
+ const attributes = node.attributes.properties;
114
+ const attribute = (name) => attributes.find((item) => ts.isJsxAttribute(item) && item.name.getText(source) === name);
115
+ const candidates = attribute("srcset") ?? attribute("srcSet");
116
+ if (!candidates || attribute("sizes")) return;
117
+ const { line, character } = source.getLineAndCharacterOfPosition(node.getStart(source));
118
+ const add = (rule, message) =>
119
+ findings.push({
120
+ rule,
121
+ severity: findingSeverity(rule),
122
+ file: relative,
123
+ line: line + 1,
124
+ column: character + 1,
125
+ guidanceUri: guidance,
126
+ message: `${relative}:${line + 1} ${message}`,
127
+ });
128
+ let value = candidates.initializer;
129
+ if (value && ts.isJsxExpression(value)) value = value.expression;
130
+ const literal = value && ts.isStringLiteralLike(value) ? value.text : null;
131
+ if (attributes.some(ts.isJsxSpreadAttribute) || literal === null)
132
+ add(
133
+ "img-attributes-unresolved",
134
+ `<${tag}> has a srcset ADS cannot read or spread props that may hold sizes. With width descriptors it needs sizes, the width it displays at.`,
135
+ );
136
+ else if (/\d\s*w\s*(?:,|$)/.test(literal.trim()))
137
+ add(
138
+ "img-attributes",
139
+ `<${tag}> has a srcset with width descriptors and no sizes, so the browser assumes the full viewport width and can pick a larger file than it shows. Add sizes, such as "(min-width: 1024px) 50vw, 100vw".`,
140
+ );
141
+ };
142
+ const inspect = (node) => {
143
+ const { line, character } = source.getLineAndCharacterOfPosition(node.getStart(source));
144
+ const add = (rule, message) =>
145
+ findings.push({
146
+ rule,
147
+ severity: findingSeverity(rule),
148
+ file: relative,
149
+ line: line + 1,
150
+ column: character + 1,
151
+ guidanceUri: guidance,
152
+ message: `${relative}:${line + 1} ${message}`,
153
+ });
154
+ const attributes = node.attributes.properties,
155
+ spread = attributes.some(ts.isJsxSpreadAttribute);
156
+ const attribute = (name) => attributes.find((item) => ts.isJsxAttribute(item) && item.name.getText(source) === name);
157
+ const styleText = attribute("style")?.initializer?.getText(source) ?? "";
158
+ const className = attribute("className") ?? attribute("class");
159
+ let size = !!(attribute("width") && attribute("height")) || /\baspectRatio\b|aspect-ratio/.test(styleText) || styles.imgRule;
160
+ if (!size && className?.initializer) size = classSize(className.initializer, styles);
161
+ const loading = !!attribute("loading");
162
+ if (spread && (size !== true || !loading)) {
163
+ add(
164
+ "img-attributes-unresolved",
165
+ `spreads props onto <img>, so ADS cannot see its dimensions or loading. Pass width, height and loading explicitly so the page reserves the space and the load order is a choice.`,
166
+ );
167
+ return;
168
+ }
169
+ if (size === null)
170
+ add(
171
+ "img-attributes-unresolved",
172
+ `styles <img> with a class ADS cannot read here, so its size is not checked. Set width and height so the page reserves the space.`,
173
+ );
174
+ if (size === false)
175
+ add(
176
+ "img-attributes",
177
+ `<img> has no width and height or a visible aspect-ratio, so the page shifts when it loads. Set the file's width and height, or a sized aspect-ratio in its style.`,
178
+ );
179
+ if (!loading)
180
+ add(
181
+ "img-attributes",
182
+ `<img> has no loading attribute. Use loading="lazy" below the fold; the page's main visible image uses loading="eager" with fetchpriority="high", or the project's image component with priority.`,
183
+ );
184
+ };
185
+ visit(source);
186
+ return Object.freeze(findings.map(Object.freeze));
187
+ }
@@ -267,9 +267,12 @@ export async function inspectBuildStatus(root, config, { session, previewSession
267
267
  if (session && report.session !== session) report = undefined;
268
268
  }
269
269
  } catch (error) {
270
- reportError = `Invalid preview build status: ${error.message.slice(0, 500)}`;
270
+ // A watcher restart can remove its report between exists/realpath/read.
271
+ // Absence is pending evidence, just as when existsSync returned false;
272
+ // malformed or unsafe reports still fail closed.
273
+ if (error.code !== "ENOENT") reportError = `Invalid preview build status: ${error.message.slice(0, 500)}`;
271
274
  }
272
- let graphError;
275
+ let graphError, verifiedGraph;
273
276
  let sourceRevision, sourceError;
274
277
  if (report?.live || report?.previews.some((entry) => entry.state === "ready")) {
275
278
  try {
@@ -290,7 +293,8 @@ export async function inspectBuildStatus(root, config, { session, previewSession
290
293
  }
291
294
  if (report?.previews.some((entry) => entry.state === "ready")) {
292
295
  try {
293
- if (!readPreviewManifest(options, { verify: "cached" })) throw new Error("Preview resource manifest is missing.");
296
+ verifiedGraph = readPreviewManifest(options, { verify: "cached" });
297
+ if (!verifiedGraph) throw new Error("Preview resource manifest is missing.");
294
298
  } catch (error) {
295
299
  graphError = `Invalid preview resource graph: ${error.message}`;
296
300
  }
@@ -372,6 +376,7 @@ export async function inspectBuildStatus(root, config, { session, previewSession
372
376
  state,
373
377
  reported: Boolean(report),
374
378
  session: report?.session ?? null,
379
+ ...(verifiedGraph && !graphError && verifiedGraph.session === report?.session ? { manifestRevision: verifiedGraph.revision } : {}),
375
380
  sequence: report?.sequence ?? null,
376
381
  updatedAt: report?.updatedAt ?? null,
377
382
  ...(report?.progress ? { progress: report.progress } : {}),
@@ -525,7 +525,11 @@ export function createDraftController(directory, { edits, startPreview, prewarm
525
525
  return summary(await inspect(id));
526
526
  }
527
527
  async function prepare(id) {
528
- const value = await inspect(id);
528
+ // One operation owns both the inspection revision and the workspace bytes.
529
+ // inspect still performs its targeted live conflict/path checks.
530
+ const captured = new Map();
531
+ const inputs = await validationInputFiles(loadConfig(root), [], { onFile: (file, content) => captured.set(file, content) });
532
+ const value = await inspect(id, [], { inputs, seen: new Set(), memo: new Map() });
529
533
  if (value.dependencyErrors.length) throw new Error(`Draft dependency error: ${value.dependencyErrors[0].message}`);
530
534
  if (value.conflicts.length) throw new Error(`Draft baseline conflict: ${value.conflicts.join(", ")}`);
531
535
  let session = previews.get(id);
@@ -543,9 +547,7 @@ export function createDraftController(directory, { edits, startPreview, prewarm
543
547
  if (session.revision && !existsSync(path.join(session.workspace, ".ds/draft-preview.json"))) session.recovering = true;
544
548
  mkdirSync(session.workspace, { recursive: true });
545
549
  if (realpathSync(session.workspace) !== session.workspace) throw new Error("Draft preview workspace cannot be a symlink.");
546
- const captured = new Map();
547
- const inputs = await validationInputFiles(loadConfig(root), [], { onFile: (file, content) => captured.set(file, content) }),
548
- desired = new Map();
550
+ const desired = new Map();
549
551
  const baseline = new Map([...captured].filter(([file]) => isAnalysisSource(file)).map(([file, content]) => [file, content.toString("utf8")]));
550
552
  let size = 0;
551
553
  for (const [target, digest] of Object.entries(inputs))
@@ -1047,7 +1049,12 @@ export function createDraftController(directory, { edits, startPreview, prewarm
1047
1049
  async function syncPreviews() {
1048
1050
  const order = [...previews.keys()].sort((a, b) => (b === lastShown) - (a === lastShown));
1049
1051
  for (const id of order) {
1050
- const reason = stale(id, previews.get(id));
1052
+ // Earlier resyncs yield; acceptance, drop or shutdown can retire a later
1053
+ // session while this iteration still holds its original ID list.
1054
+ if (closed) break;
1055
+ const session = previews.get(id);
1056
+ if (!session) continue;
1057
+ const reason = stale(id, session);
1051
1058
  if (!reason) continue;
1052
1059
  if (reason === "own" || id === lastShown) {
1053
1060
  backlog.delete(id);
@@ -557,9 +557,12 @@ export function createMutationController(directory, { captures = createCaptureCo
557
557
  }
558
558
  await registerAnalysis();
559
559
  const inputPaths = [...new Set([...changes.map((change) => change.path), ...Object.keys(await validationInputFiles(candidateOptions))])];
560
+ // A source-only edit has the same input scope on both sides. Capture it
561
+ // once per fence; configuration changes still fence both distinct scopes.
562
+ const inputScopes = [...new Map([options, candidateOptions].map(original => [JSON.stringify(original.config), original])).values()];
560
563
  const scopedInputs = async () => {
561
564
  const files = {};
562
- for (const original of [options, candidateOptions]) {
565
+ for (const original of inputScopes) {
563
566
  const rebased = {
564
567
  root,
565
568
  config: original.config,
@@ -581,12 +584,12 @@ export function createMutationController(directory, { captures = createCaptureCo
581
584
  // A reviewed draft's workspace holds exactly this candidate's inputs at a stable path, so
582
585
  // its warm check (and a remembered report from a dry run) applies; otherwise check the copy.
583
586
  // Compared over the project's own inputs plus the changed files.
584
- const compared = [...new Set([...Object.keys(await validationInputFiles(options)), ...changes.map((change) => change.path)])];
585
- const pick = (digests) => JSON.stringify(compared.map((file) => [file, digests[file] ?? null]));
586
- const sameInputs =
587
- checkRoot &&
588
- existsSync(checkRoot) &&
589
- pick(await validationInputFiles(loadConfig(checkRoot), compared)) === pick(await validationInputFiles(candidateOptions, compared));
587
+ let sameInputs = false;
588
+ if (checkRoot && existsSync(checkRoot)) {
589
+ const compared = [...new Set([...Object.keys(await validationInputFiles(options)), ...changes.map((change) => change.path)])];
590
+ const pick = (digests) => JSON.stringify(compared.map((file) => [file, digests[file] ?? null]));
591
+ sameInputs = pick(await validationInputFiles(loadConfig(checkRoot), compared)) === pick(await validationInputFiles(candidateOptions, compared));
592
+ }
590
593
  // Browser checks of a reviewed draft render its workspace through the project's own host and
591
594
  // compiler; only a candidate without one gets a preview host of its own.
592
595
  const reviewRoot = sameInputs ? checkRoot : candidate,
@@ -630,7 +633,7 @@ export function createMutationController(directory, { captures = createCaptureCo
630
633
  const auditSelection =
631
634
  audit && (await analyze(candidate, "audit-selection", [changes.map((change) => change.path), { mode: "owners", owners: units }], signal));
632
635
  // Previews are built only when a browser behavior check renders them.
633
- if ((await analyze(candidate, "needs-browser", [behaviorUnits], signal)) && candidateOptions.config.framework) {
636
+ if (behaviorUnits.length && candidateOptions.config.framework && await analyze(candidate, "needs-browser", [behaviorUnits], signal)) {
634
637
  boundary = evidenceFailure("build", "preview-build", "ADS_PREVIEW_BUILD");
635
638
  progress = { stage: "preview-build", message: "Building all candidate previews" };
636
639
  notifyProgress?.(progress);