@reqvire-org/ads 0.4.3 → 0.4.5
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/README.md +12 -9
- package/dist/bun-compiler.mjs +6 -5
- package/dist/check.mjs +3 -43
- package/dist/cli.mjs +1 -1
- package/dist/contrast-composition.mjs +6 -60
- package/dist/contrast-styles.mjs +88 -0
- package/dist/mcp/apps.mjs +7 -1
- package/dist/mcp/build-status.mjs +8 -3
- package/dist/mcp/drafts.mjs +13 -1
- package/dist/mcp/preview-http.bundle.js +7 -0
- package/dist/mcp/preview-http.mjs +148 -0
- package/dist/mcp/preview-widget.bundle.js +47 -47
- package/dist/mcp/resource-loader.js +1 -201
- package/dist/mcp/sandbox-host.mjs +6 -1
- package/dist/mcp/server.mjs +35 -4
- package/dist/mcp/showcase-host.mjs +55 -5
- package/dist/mcp/showcase-http.mjs +66 -0
- package/dist/preview-bun.mjs +75 -60
- package/dist/preview-incremental.mjs +358 -0
- package/dist/preview-manifest-update.mjs +70 -0
- package/dist/preview-resources.mjs +33 -1
- package/dist/render-composition.mjs +27 -5
- package/dist/scenarios-compiler.mjs +19 -1
- package/dist/showcase/client.bundle.js +54 -54
- package/dist/showcase/comparison.js +15 -12
- package/dist/showcase/connection.js +10 -0
- package/dist/showcase/http-client.bundle.js +9 -0
- package/dist/showcase/http-connection.js +86 -0
- package/dist/showcase/http-preview.js +81 -0
- package/dist/showcase-http-routes.mjs +31 -0
- package/dist/skills/README.md +3 -3
- package/dist/skills/ads-designer/SKILL.md +5 -1
- package/dist/skills/ads-designer/references/accessibility.md +6 -2
- package/dist/skills/ads-designer/references/captures.md +1 -1
- package/dist/skills/ads-designer/references/runtimes.md +31 -0
- package/dist/skills/ads-designer/references/workflows.md +16 -0
- package/dist/skills/ads-import/references/captures.md +1 -1
- package/dist/skills/ads-import/references/runtimes.md +31 -0
- package/dist/skills/ads-import/references/workflows.md +16 -0
- package/dist/skills/ads-migrate/SKILL.md +3 -1
- package/dist/skills/ads-migrate/references/0.4.1-to-0.4.2.md +2 -3
- package/dist/skills/ads-migrate/references/0.4.3-to-0.4.4.md +89 -0
- package/dist/skills/ads-migrate/references/0.4.4-to-0.4.5.md +72 -0
- package/dist/skills/ads-port/references/captures.md +1 -1
- package/dist/skills/ads-port/references/runtimes.md +31 -0
- package/dist/skills/ads-port/references/workflows.md +16 -0
- package/dist/style-token-rules.mjs +51 -0
- package/dist/verification/browser.mjs +2 -2
- package/docs/ADS.md +9 -7
- package/docs/ARCHITECTURE.md +109 -48
- package/docs/CACHING.md +40 -1
- package/docs/CHANGELOG.md +100 -22
- package/docs/GUIDE.md +37 -10
- package/docs/HTTP-SHOWCASE-POC.md +397 -0
- package/docs/MCP.md +104 -25
- package/docs/benchmarks/README.md +1 -1
- package/docs/benchmarks/http-showcase-optimized.json +1879 -0
- package/docs/benchmarks/http-showcase-profile.json +308 -0
- package/docs/benchmarks/http-showcase.json +3069 -0
- package/package.json +6 -4
|
@@ -6,6 +6,7 @@ import ts from "./analysis/syntax.mjs";
|
|
|
6
6
|
import valueParser from "postcss-value-parser";
|
|
7
7
|
import { isInside } from "./config.mjs";
|
|
8
8
|
import { livePreviewOptions, previewArtifactPath, previewManifestPath } from "./preview-scope.mjs";
|
|
9
|
+
import { previewManifestUpdate } from "./preview-manifest-update.mjs";
|
|
9
10
|
|
|
10
11
|
export const PREVIEW_APP_URI = "ui://ads/preview";
|
|
11
12
|
export const PREVIEW_MANIFEST_URI = "ads://preview/manifest";
|
|
@@ -102,10 +103,15 @@ function resourceUris(prepared) {
|
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
/** Convert compiler output to registered MCP resources without evaluating project code. */
|
|
105
|
-
export async function createPreviewResources(output, options, entries, { retain, prune = false } = {}) {
|
|
106
|
+
export async function createPreviewResources(output, options, entries, { retain, prune = false, refresh, preparedCache } = {}) {
|
|
106
107
|
const bundle = (Array.isArray(output) ? output : [output]).flatMap((result) => result.output);
|
|
107
108
|
const files = new Map(bundle.map((item) => [item.fileName, item]));
|
|
108
109
|
const original = (item) => Buffer.from(item.type === "chunk" ? item.code : item.source);
|
|
110
|
+
// One prepared rewrite per current output file. Membership matters because a
|
|
111
|
+
// formerly external string can become a graph reference. Worker bytes also
|
|
112
|
+
// participate: unchanged callers must recheck a changed worker's module form.
|
|
113
|
+
const membership = preparedCache && hash(JSON.stringify(bundle.map(item => [item.fileName, item.type,
|
|
114
|
+
item.type === "asset" && item.fileName.endsWith(".js") ? hash(original(item)) : null]).sort((a, b) => a[0].localeCompare(b[0]))));
|
|
109
115
|
const prepared = new Map();
|
|
110
116
|
const records = { ...retain?.manifest.assets };
|
|
111
117
|
const contents = new Map(retain?.contents);
|
|
@@ -117,6 +123,9 @@ export async function createPreviewResources(output, options, entries, { retain,
|
|
|
117
123
|
for (const item of bundle) {
|
|
118
124
|
const references = new Set();
|
|
119
125
|
const bytes = original(item);
|
|
126
|
+
const preparationKey = preparedCache && hash(JSON.stringify([membership, hash(bytes), item.imports, item.dynamicImports, [...(item.viteMetadata?.importedCss ?? [])]]));
|
|
127
|
+
const cachedPreparation = preparedCache?.get(item.fileName);
|
|
128
|
+
if (cachedPreparation && cachedPreparation.key === preparationKey) { prepared.set(item.fileName, cachedPreparation.value); continue; }
|
|
120
129
|
let render = () => bytes;
|
|
121
130
|
if (item.type === "chunk" || item.fileName.endsWith(".js")) {
|
|
122
131
|
const source = await ts.createSourceFile(item.fileName, bytes.toString(), ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
@@ -201,7 +210,9 @@ export async function createPreviewResources(output, options, entries, { retain,
|
|
|
201
210
|
const styles = item.type === "chunk" ? [...(item.viteMetadata?.importedCss ?? [])].filter((file) => files.has(file)) : [];
|
|
202
211
|
const links = { imports, dynamicImports, styles, references: [...references] };
|
|
203
212
|
prepared.set(item.fileName, { file: item.fileName, digest: hash(bytes), links, dependencies, render });
|
|
213
|
+
preparedCache?.set(item.fileName, { key: preparationKey, value: prepared.get(item.fileName) });
|
|
204
214
|
}
|
|
215
|
+
if (preparedCache) for (const file of preparedCache.keys()) if (!files.has(file)) preparedCache.delete(file);
|
|
205
216
|
// Bump the transform version in resourceUris whenever rewriting changes.
|
|
206
217
|
const uris = resourceUris(prepared);
|
|
207
218
|
for (const item of bundle) {
|
|
@@ -216,6 +227,7 @@ export async function createPreviewResources(output, options, entries, { retain,
|
|
|
216
227
|
kind: item.type === "chunk" ? "module" : "asset",
|
|
217
228
|
...links,
|
|
218
229
|
...(item.spatial ? { spatial: item.spatial } : {}),
|
|
230
|
+
...(item.hot ? { hot: item.hot } : {}),
|
|
219
231
|
};
|
|
220
232
|
contents.set(uri, bytes);
|
|
221
233
|
}
|
|
@@ -248,6 +260,7 @@ export async function createPreviewResources(output, options, entries, { retain,
|
|
|
248
260
|
const graph = {
|
|
249
261
|
schemaVersion: 1,
|
|
250
262
|
framework: options.config.framework,
|
|
263
|
+
...(refresh ? { refresh } : {}),
|
|
251
264
|
themes: options.config.themes,
|
|
252
265
|
...(options.config.brands?.length ? { brands: options.config.brands } : {}),
|
|
253
266
|
assets: records,
|
|
@@ -394,6 +407,20 @@ export function readPreviewManifest(options, { verify = false } = {}) {
|
|
|
394
407
|
return manifest;
|
|
395
408
|
}
|
|
396
409
|
|
|
410
|
+
/** Use only retained, validated metadata in this project's preview scope. Missing
|
|
411
|
+
* history costs a full response; it never changes current-source authorization. */
|
|
412
|
+
export function readPreviewManifestUpdate(options, current, from) {
|
|
413
|
+
if (!/^[a-f0-9]{64}$/.test(from ?? "")) throw new Error("Preview update from must be a SHA-256 revision.");
|
|
414
|
+
if (from === current.revision) return previewManifestUpdate(current, current);
|
|
415
|
+
for (const file of [path.join(path.dirname(previewManifestPath(options)), "history", `${from}.json`), previewManifestPath(cacheOptions(options, from))]) {
|
|
416
|
+
try {
|
|
417
|
+
const previous = readManifestFile(file);
|
|
418
|
+
if (previous.revision === from) return previewManifestUpdate(current, previous);
|
|
419
|
+
} catch { /* Expired/corrupt history cannot become a delta base. */ }
|
|
420
|
+
}
|
|
421
|
+
return previewManifestUpdate(current);
|
|
422
|
+
}
|
|
423
|
+
|
|
397
424
|
function readManifestFile(file) {
|
|
398
425
|
if (realpathSync(file) !== file || !statSync(file).isFile() || statSync(file).size > 2 * 1024 * 1024) throw new Error("Invalid preview manifest file.");
|
|
399
426
|
return validateManifest(JSON.parse(readFileSync(file, "utf8")));
|
|
@@ -410,6 +437,9 @@ function validateManifest(manifest) {
|
|
|
410
437
|
!Array.isArray(manifest.scenarios)
|
|
411
438
|
)
|
|
412
439
|
throw new Error("Invalid preview resource manifest. Rebuild the project previews.");
|
|
440
|
+
if (manifest.refresh && (manifest.refresh.version !== 1 || typeof manifest.refresh.epoch !== "string" || !manifest.refresh.epoch || manifest.refresh.epoch.length > 100))
|
|
441
|
+
throw new Error("Invalid preview refresh protocol.");
|
|
442
|
+
const hotIds = new Set();
|
|
413
443
|
for (const [uri, record] of Object.entries(manifest.assets)) {
|
|
414
444
|
if (
|
|
415
445
|
!record ||
|
|
@@ -420,11 +450,13 @@ function validateManifest(manifest) {
|
|
|
420
450
|
record.size < 0 ||
|
|
421
451
|
record.size > 16 * 1024 * 1024 ||
|
|
422
452
|
typeof record.mimeType !== "string" ||
|
|
453
|
+
(record.hot && (!manifest.refresh || record.kind !== "module" || typeof record.hot.id !== "string" || !record.hot.id || record.hot.id.length > 4096 || hotIds.has(record.hot.id) || !/^[a-f0-9]{64}$/.test(record.hot.source))) ||
|
|
423
454
|
!["imports", "dynamicImports", "styles", "references"].every(
|
|
424
455
|
(key) => Array.isArray(record[key]) && record[key].every((ref) => Object.hasOwn(manifest.assets, ref)),
|
|
425
456
|
)
|
|
426
457
|
)
|
|
427
458
|
throw new Error("Invalid preview asset dependency graph.");
|
|
459
|
+
if (record.hot) hotIds.add(record.hot.id);
|
|
428
460
|
}
|
|
429
461
|
if (
|
|
430
462
|
manifest.scenarios.some((entry) => !entry || typeof entry.id !== "string" || manifest.assets[entry.module]?.kind !== "module") ||
|
|
@@ -50,13 +50,13 @@ async function build(program, options) {
|
|
|
50
50
|
if (value.values.length > 64) return { templates: [], names: [], reason: "Class composition exceeds 64 alternatives." };
|
|
51
51
|
for (const item of value.values) alternatives.push(await classes(item, values.next(context)));
|
|
52
52
|
const first = alternatives[0];
|
|
53
|
-
if (first && alternatives.every(item => !item.reason && item.templates.length === first.templates.length && item.templates.every((template, i) => template === first.templates[i]) && item.names.join(" ") === first.names.join(" "))) return first;
|
|
54
|
-
return { templates: [], names: [],
|
|
53
|
+
if (first && alternatives.every(item => !item.reason && !item.choices?.length && item.templates.length === first.templates.length && item.templates.every((template, i) => template === first.templates[i]) && item.names.join(" ") === first.names.join(" "))) return first;
|
|
54
|
+
return { templates: [], names: [], choices: [alternatives] };
|
|
55
55
|
}
|
|
56
56
|
if (value.kind === "node") {
|
|
57
57
|
if (ts.isTaggedTemplateExpression(value.node) && await linaria(value.node.tag) === "css") return { templates: [value.node], names: [] };
|
|
58
58
|
if (ts.isCallExpression(value.node) && await isCx(value.node.expression)) {
|
|
59
|
-
const result = { templates: [], names: [] };
|
|
59
|
+
const result = { templates: [], names: [], choices: [] };
|
|
60
60
|
for (const argument of value.node.arguments) {
|
|
61
61
|
const items = ts.isSpreadElement(argument)
|
|
62
62
|
? await values.arrays(reference(argument.expression, value.env, value.via), values.next(context))
|
|
@@ -65,6 +65,7 @@ async function build(program, options) {
|
|
|
65
65
|
for (const item of items) {
|
|
66
66
|
const part = await classes(item, values.next(context));
|
|
67
67
|
result.templates.push(...part.templates); result.names.push(...part.names);
|
|
68
|
+
result.choices.push(...(part.choices ?? []));
|
|
68
69
|
result.reason ??= part.reason;
|
|
69
70
|
}
|
|
70
71
|
}
|
|
@@ -74,6 +75,19 @@ async function build(program, options) {
|
|
|
74
75
|
return { templates: [], names: [], reason: value.reason ?? "A class or later prop spread cannot be resolved." };
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
const textTypes = new Map();
|
|
79
|
+
async function textSlot(input) {
|
|
80
|
+
const node = input?.node;
|
|
81
|
+
if (!node || !ts.isIdentifier(node) && !ts.isPropertyAccessExpression(node) && !ts.isElementAccessExpression(node)) return false;
|
|
82
|
+
if (!textTypes.has(node)) textTypes.set(node, (async () => {
|
|
83
|
+
const type = await checker.getTypeAtLocation(node), parts = type?.isUnion() ? type.types : [type];
|
|
84
|
+
const text = ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike;
|
|
85
|
+
const absent = ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.BooleanLike;
|
|
86
|
+
return parts.some(part => part?.flags & text) && parts.every(part => part?.flags & (text | absent));
|
|
87
|
+
})());
|
|
88
|
+
return textTypes.get(node);
|
|
89
|
+
}
|
|
90
|
+
|
|
77
91
|
async function render(input, parent, context, sites = new Set(), uncertain = false) {
|
|
78
92
|
if (nodes.length >= 20000 || context.depth > 48 || context.budget.steps > 16000) {
|
|
79
93
|
limit(input.node ?? parent?.node, "Render composition reached its depth or work limit.");
|
|
@@ -95,6 +109,9 @@ async function build(program, options) {
|
|
|
95
109
|
return;
|
|
96
110
|
}
|
|
97
111
|
if (value.kind !== "node") {
|
|
112
|
+
// A typed text slot needs readable paint for its supplied text. Arbitrary
|
|
113
|
+
// children, failed resolution and bounded-analysis limits remain unknown.
|
|
114
|
+
if (parent && value.kind === "unknown" && !value.reason && await textSlot(input)) { parent.text = true; return; }
|
|
98
115
|
if (parent) parent.unknownText = value.reason ?? "Dynamic children cannot be established as text.";
|
|
99
116
|
return;
|
|
100
117
|
}
|
|
@@ -156,9 +173,14 @@ async function build(program, options) {
|
|
|
156
173
|
});
|
|
157
174
|
for (const node of sites) await render(reference(node), null, { ...values.state(), maxSteps: 16000 });
|
|
158
175
|
}
|
|
176
|
+
function freezeClasses(classes) {
|
|
177
|
+
Object.freeze(classes.templates); Object.freeze(classes.names);
|
|
178
|
+
for (const choice of classes.choices ?? []) { choice.forEach(freezeClasses); Object.freeze(choice); }
|
|
179
|
+
if (classes.choices) Object.freeze(classes.choices);
|
|
180
|
+
Object.freeze(classes);
|
|
181
|
+
}
|
|
159
182
|
for (const item of nodes) {
|
|
160
|
-
Object.freeze(item.
|
|
161
|
-
Object.freeze(item.classes); Object.freeze(item.children); Object.freeze(item.attributes); Object.freeze(item);
|
|
183
|
+
freezeClasses(item.classes); Object.freeze(item.children); Object.freeze(item.attributes); Object.freeze(item);
|
|
162
184
|
}
|
|
163
185
|
return Object.freeze({ roots: Object.freeze(roots), nodes: Object.freeze(nodes), limits: Object.freeze([...limits.values()]) });
|
|
164
186
|
}
|
|
@@ -476,6 +476,12 @@ export async function runScenarioCompiler(directory, setup) {
|
|
|
476
476
|
const root = path.resolve(directory);
|
|
477
477
|
const { watched = false, validate, buildGraph, compilerFiles = [], context = {} } = typeof setup === "function" ? setup(root) : setup;
|
|
478
478
|
if (typeof buildGraph !== "function") throw new Error("runScenarioCompiler needs buildGraph: previews compile into one shared resource graph.");
|
|
479
|
+
const draftWorkspace = watched && isDraftPreviewWorkspace(root);
|
|
480
|
+
const retired = () => draftWorkspace && !existsSync(root);
|
|
481
|
+
async function retiredStartup() {
|
|
482
|
+
await buildGraph.close?.();
|
|
483
|
+
return { async stop() {} };
|
|
484
|
+
}
|
|
479
485
|
const control = process.env.ADS_MCP_DRAFT_CONTROL,
|
|
480
486
|
hosting = watched && !context.session && control && existsSync(path.dirname(control));
|
|
481
487
|
const scheduler = hosting ? createScheduler() : null;
|
|
@@ -492,6 +498,9 @@ export async function runScenarioCompiler(directory, setup) {
|
|
|
492
498
|
async function registry() {
|
|
493
499
|
options = withPreviewSession(loadConfig(root), buildSession);
|
|
494
500
|
const result = await analyze(root, "registry");
|
|
501
|
+
// Acceptance/drop may retire a draft while asynchronous discovery is running.
|
|
502
|
+
// Never recreate its workspace by publishing a late registry result.
|
|
503
|
+
if (retired()) return [];
|
|
495
504
|
if (result.diagnostics.length)
|
|
496
505
|
throw Object.assign(new Error(result.diagnostics.map((item) => `${item.file}: ${item.message}`).join("\n")), { scenarios: result.scenarios });
|
|
497
506
|
writeRegistryManifest(root, result.scenarios);
|
|
@@ -508,6 +517,7 @@ export async function runScenarioCompiler(directory, setup) {
|
|
|
508
517
|
} finally {
|
|
509
518
|
if (watched) releaseScenarioRegistry(root);
|
|
510
519
|
}
|
|
520
|
+
if (retired()) return retiredStartup();
|
|
511
521
|
const buildApps = () => entries.map((entry) => ({ id: entry.id, file: previewArtifactPath(options, entry.artifact) }));
|
|
512
522
|
const reporter = createBuildReporter(root, {
|
|
513
523
|
apps: buildApps(),
|
|
@@ -553,7 +563,15 @@ export async function runScenarioCompiler(directory, setup) {
|
|
|
553
563
|
let publishedStamp;
|
|
554
564
|
let publishedEntries = new Set();
|
|
555
565
|
let validation;
|
|
556
|
-
let observedSourceRevision
|
|
566
|
+
let observedSourceRevision;
|
|
567
|
+
try {
|
|
568
|
+
observedSourceRevision = await previewSourceRevision(options);
|
|
569
|
+
} catch (error) {
|
|
570
|
+
if (retired()) return retiredStartup();
|
|
571
|
+
await buildGraph.close?.();
|
|
572
|
+
throw error;
|
|
573
|
+
}
|
|
574
|
+
if (retired()) return retiredStartup();
|
|
557
575
|
let invalidation;
|
|
558
576
|
let fullRequest, completedFull;
|
|
559
577
|
// Keep the registry inspector warm while previews are in use: a cold TypeScript program costs ~1.7 s per edit.
|