@reqvire-org/ads 0.3.29 → 0.3.32
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/dist/config.mjs +7 -2
- package/dist/mcp/apps.mjs +3 -1
- package/dist/mcp/build-status.mjs +1 -1
- package/dist/mcp/mutations.mjs +49 -8
- package/dist/mcp/server.mjs +14 -10
- package/dist/preview-files.mjs +19 -12
- package/dist/preview-inputs.mjs +6 -17
- package/dist/preview-resources.mjs +25 -3
- package/dist/project-documents.mjs +4 -0
- package/dist/scenario-trace.mjs +2 -1
- package/dist/showcase/client.bundle.js +23 -23
- package/dist/showcase/index.html +2 -2
- package/dist/showcase/style.css +7 -0
- package/dist/skills/ads-break-ui/references/behaviors.md +2 -0
- package/dist/skills/ads-break-ui/references/layers.md +6 -0
- package/dist/skills/ads-break-ui/references/validation.md +16 -0
- package/dist/skills/ads-designer/references/behaviors.md +2 -0
- package/dist/skills/ads-designer/references/layers.md +6 -0
- package/dist/skills/ads-designer/references/validation.md +16 -0
- package/dist/skills/ads-import/references/behaviors.md +2 -0
- package/dist/skills/ads-import/references/layers.md +6 -0
- package/dist/skills/ads-import/references/validation.md +16 -0
- package/dist/skills/ads-motion/references/behaviors.md +2 -0
- package/dist/skills/ads-motion/references/layers.md +6 -0
- package/dist/skills/ads-motion/references/validation.md +16 -0
- package/dist/skills/ads-port/references/behaviors.md +2 -0
- package/dist/skills/ads-port/references/layers.md +6 -0
- package/dist/skills/ads-port/references/validation.md +16 -0
- package/dist/test-boundaries.mjs +3 -2
- package/dist/units.mjs +8 -2
- package/dist/validation-inputs.mjs +142 -0
- package/dist/validation.mjs +3 -17
- package/docs/ARCHITECTURE.md +26 -5
- package/docs/BEHAVIORS.md +2 -0
- package/docs/CHANGELOG.md +49 -0
- package/docs/GUIDE.md +2 -0
- package/docs/MCP.md +38 -4
- package/package.json +1 -1
package/dist/config.mjs
CHANGED
|
@@ -18,7 +18,7 @@ export const defaultConfig = {
|
|
|
18
18
|
boundaries: { styleWrites: [], componentVariables: [] },
|
|
19
19
|
assets: { publicDirs: ["public/assets"], generatedPaths: ["dist", "dist-showcase", ".vite", ".ds"], generatedFiles: [], iconSource: null },
|
|
20
20
|
oxlint: { plugins: [], rules: {}, overrides: [] },
|
|
21
|
-
validation: { checks: null },
|
|
21
|
+
validation: { checks: null, inputs: [] },
|
|
22
22
|
mcp: { showcaseUrl: null, showcaseTitle: null, apps: [], previewWatch: null, previewManifest: null, mutationChecks: null, mutationCheckTimeoutMs: 60000, behaviorProfiles: {}, capture: {} },
|
|
23
23
|
};
|
|
24
24
|
|
|
@@ -51,6 +51,11 @@ export function loadConfig(directory = process.cwd()) {
|
|
|
51
51
|
}
|
|
52
52
|
const config = { ...defaultConfig, ...user, boundaries: { ...defaultConfig.boundaries, ...user.boundaries }, assets: { ...defaultConfig.assets, ...user.assets }, oxlint: { ...defaultConfig.oxlint, ...user.oxlint }, validation: { ...defaultConfig.validation, ...user.validation }, mcp: { ...defaultConfig.mcp, ...user.mcp } };
|
|
53
53
|
if (config.validation.checks !== null && (!Array.isArray(config.validation.checks) || config.validation.checks.length > 20 || new Set(config.validation.checks).size !== config.validation.checks.length || config.validation.checks.some(name=>typeof name !== "string" || !/^[\w:.-]+$/.test(name)))) throw new Error("validation.checks must be null or up to 20 unique package script names.");
|
|
54
|
+
if (!Array.isArray(config.validation.inputs) || config.validation.inputs.length > 200 || new Set(config.validation.inputs).size !== config.validation.inputs.length) throw new Error("validation.inputs must contain at most 200 unique project-relative files or directories.");
|
|
55
|
+
for (const file of config.validation.inputs) {
|
|
56
|
+
const absolute = projectPath(root,file,"validation.inputs");
|
|
57
|
+
if (absolute === root || path.relative(root,absolute).replaceAll("\\","/") !== file || file.split("/").some(part=>["node_modules",".git",".ds"].includes(part))) throw new Error("validation.inputs must name canonical source paths below the project root, excluding dependency and metadata directories.");
|
|
58
|
+
}
|
|
54
59
|
if (config.schemaVersion !== 1) throw new Error(`Unsupported ADS config version: ${config.schemaVersion}`);
|
|
55
60
|
if (user.framework !== undefined && !supportedFrameworks.includes(user.framework)) throw new Error("framework must be react or preact.");
|
|
56
61
|
if (typeof config.publicAlias !== "string" || !config.publicAlias.trim()) throw new Error("publicAlias must be a non-empty string.");
|
|
@@ -118,7 +123,7 @@ export function loadConfig(directory = process.cwd()) {
|
|
|
118
123
|
|| !["protocol", "playwright"].includes(profile.runner ?? "protocol")
|
|
119
124
|
|| profile.framework !== undefined && profile.framework !== config.framework
|
|
120
125
|
|| profile.mode !== undefined && !["browser", "strict", "unit"].includes(profile.mode)
|
|
121
|
-
|| profile.timeoutMs !== undefined && (!Number.isInteger(profile.timeoutMs) || profile.timeoutMs < 100 || profile.timeoutMs >
|
|
126
|
+
|| profile.timeoutMs !== undefined && (!Number.isInteger(profile.timeoutMs) || profile.timeoutMs < 100 || profile.timeoutMs > 900000)) throw new Error(`Invalid behavior profile ${name}. Use literal executable/args, a protocol or Playwright runner, a matching framework and a timeout from 100 to 900000 ms. Profiles do not install dependencies or receive APIs from an MCP host.`);
|
|
122
127
|
if (profile.mode === "strict" && config.framework !== "react") throw new Error(`Behavior profile ${name}: React StrictMode requires framework react; use the configured framework's lifecycle tests instead.`);
|
|
123
128
|
}
|
|
124
129
|
if (config.mcp.mutationChecks !== null && (!Array.isArray(config.mcp.mutationChecks) || config.mcp.mutationChecks.length > 12 || new Set(config.mcp.mutationChecks).size !== config.mcp.mutationChecks.length || config.mcp.mutationChecks.some(name => typeof name !== "string" || !/^[a-zA-Z0-9][\w:.-]*$/.test(name)))) throw new Error("mcp.mutationChecks must be null or up to 12 unique package script names.");
|
package/dist/mcp/apps.mjs
CHANGED
|
@@ -49,5 +49,7 @@ export function projectApp(options, app, build) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export function appMetadata({ nested = false } = {}) {
|
|
52
|
-
|
|
52
|
+
// Project UI may itself contain an isolated widget. Keep those examples
|
|
53
|
+
// self-contained; external frame origins are still unavailable.
|
|
54
|
+
return { ui: { csp: { connectDomains: ["blob:"], resourceDomains: ["data:", "blob:"], frameDomains: [...(nested ? ["about:"] : []), "data:", "blob:"] } } };
|
|
53
55
|
}
|
|
@@ -158,7 +158,7 @@ export function inspectBuildStatus(root, config, { session, previewSession, proc
|
|
|
158
158
|
}
|
|
159
159
|
if (config.previewManifest && report?.previews.some(entry => entry.state === "ready")) {
|
|
160
160
|
try {
|
|
161
|
-
if (!readPreviewManifest(options, { verify:
|
|
161
|
+
if (!readPreviewManifest(options, { verify: "cached" })) throw new Error("Preview resource manifest is missing.");
|
|
162
162
|
} catch (error) { graphError = `Invalid preview resource graph: ${error.message}`; }
|
|
163
163
|
}
|
|
164
164
|
const previews = config.apps.map((app) => {
|
package/dist/mcp/mutations.mjs
CHANGED
|
@@ -16,8 +16,9 @@ import { checkUnitCandidate, checkUnitFiles, inspectUnits, validateUnitId } from
|
|
|
16
16
|
import { acceptance, failure as evidenceFailure } from "../evidence.mjs";
|
|
17
17
|
import { checkCommand, projectChecks as checks } from "../validation-checks.mjs";
|
|
18
18
|
import { preparePreviewCache } from "../scenarios-compiler.mjs";
|
|
19
|
+
import { validationInputFiles } from "../validation-inputs.mjs";
|
|
19
20
|
|
|
20
|
-
export const mutationLimits = { units: 8, files: 32, patchBytes: 256 * 1024, patchFileBytes: 16 * 1024 * 1024, fileBytes: 16 * 1024 * 1024, readChars: 12000, snapshotFiles:
|
|
21
|
+
export const mutationLimits = { units: 8, files: 32, patchBytes: 256 * 1024, patchFileBytes: 16 * 1024 * 1024, fileBytes: 16 * 1024 * 1024, readChars: 12000, snapshotFiles: 100000, snapshotBytes: 2 * 1024 * 1024 * 1024 };
|
|
21
22
|
const digest = bytes => `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
|
|
22
23
|
const ignored = new Set([".git", ".ds", "node_modules", ".vite", "coverage", ".playwright-cli", "test-results", "output"]);
|
|
23
24
|
const textFile = file => /\.(?:[cm]?[jt]sx?|css|html|jsonc?|md|txt|svg)$/.test(file);
|
|
@@ -79,7 +80,31 @@ function validateContent(change, unit) {
|
|
|
79
80
|
if (unit !== "configuration" && /\b(?:oxlint|eslint)-(?:disable|enable)|\bbiome-ignore|@ts-(?:ignore|nocheck|expect-error)/.test(bytes.toString("utf8"))) throw fail("mutation-policy", "Configure reviewed lint/typecheck exceptions through the configuration unit instead of source suppression directives.", change.path);
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
function
|
|
83
|
+
function candidateInputs(options,extraFiles=[]) {
|
|
84
|
+
try { return validationInputFiles(options,extraFiles,{maxFiles:mutationLimits.snapshotFiles,maxBytes:mutationLimits.snapshotBytes}); }
|
|
85
|
+
catch(error) { if(error.code==="ADS_INPUT_LIMIT")throw fail("mutation-snapshot",error.message);throw error; }
|
|
86
|
+
}
|
|
87
|
+
function copyInputs(options, destination, extraFiles, {baseline=new Map(),changed=new Set(),budget={bytes:0,files:0}}={}) {
|
|
88
|
+
for (const [relative,value] of Object.entries(candidateInputs(options,extraFiles))) {
|
|
89
|
+
if (baseline.has(relative)) continue;
|
|
90
|
+
if (relative==="installed-dependencies" || value===null) { baseline.set(relative,value);continue; }
|
|
91
|
+
const file=path.resolve(options.root,relative),stat=lstatSync(file);
|
|
92
|
+
if (budget.files+1>mutationLimits.snapshotFiles || budget.bytes+stat.size>mutationLimits.snapshotBytes) throw fail("mutation-snapshot","Relevant inputs exceed the bounded validation snapshot limit.");
|
|
93
|
+
const content=readFileSync(file);budget.bytes+=content.length;budget.files++;
|
|
94
|
+
if (budget.bytes>mutationLimits.snapshotBytes) throw fail("mutation-snapshot","Relevant inputs exceed the bounded validation snapshot limit.");
|
|
95
|
+
baseline.set(relative,digest(content));
|
|
96
|
+
if (!changed.has(relative)) {
|
|
97
|
+
const target=path.join(destination,relative);mkdirSync(path.dirname(target),{recursive:true});
|
|
98
|
+
writeFileSync(target,content,{mode:stat.mode});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return baseline;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function snapshot(options) {
|
|
105
|
+
// Scan the entire *candidate* to detect checking commands that rewrite source,
|
|
106
|
+
// including files outside the input graph. Live projects are never copied here.
|
|
107
|
+
candidateInputs(options);
|
|
83
108
|
const entries = [];
|
|
84
109
|
let bytes = 0;
|
|
85
110
|
const generated = options.config.assets.generatedPaths.map(file => path.resolve(options.root, file));
|
|
@@ -89,16 +114,14 @@ function snapshot(options, destination) {
|
|
|
89
114
|
const file = path.join(folder, entry.name);
|
|
90
115
|
const relative = path.relative(options.root, file);
|
|
91
116
|
if (generated.some(base => isInside(base, file))) continue;
|
|
92
|
-
|
|
93
|
-
if (entry.
|
|
94
|
-
if (entry.isDirectory()) { if (target) mkdirSync(target, { recursive: true }); walk(file); }
|
|
117
|
+
if (entry.isSymbolicLink()) continue;
|
|
118
|
+
if (entry.isDirectory()) walk(file);
|
|
95
119
|
else if (entry.isFile()) {
|
|
96
120
|
if (bytes + lstatSync(file).size > mutationLimits.snapshotBytes || entries.length >= mutationLimits.snapshotFiles) throw fail("mutation-snapshot", "Project source exceeds the bounded validation snapshot limit.");
|
|
97
121
|
const content = readFileSync(file);
|
|
98
122
|
bytes += content.length;
|
|
99
123
|
if (bytes > mutationLimits.snapshotBytes || entries.length >= mutationLimits.snapshotFiles) throw fail("mutation-snapshot", "Project source exceeds the bounded validation snapshot limit.");
|
|
100
124
|
entries.push([relative, digest(content)]);
|
|
101
|
-
if (target) writeFileSync(target, content, { mode: lstatSync(file).mode });
|
|
102
125
|
}
|
|
103
126
|
}
|
|
104
127
|
}
|
|
@@ -180,7 +203,9 @@ export function createMutationController(directory, { captures = createCaptureCo
|
|
|
180
203
|
temporary = mkdtempSync(path.join(cache, "mutation-"));
|
|
181
204
|
const candidate = path.join(temporary, "project");
|
|
182
205
|
mkdirSync(candidate);
|
|
183
|
-
const
|
|
206
|
+
const patchPaths=plans.flatMap(plan=>plan.entries.map(entry=>entry.path));
|
|
207
|
+
const copyBudget={bytes:0,files:0};
|
|
208
|
+
const copiedInputs=copyInputs(options,candidate,patchPaths,{budget:copyBudget});
|
|
184
209
|
const dependencies = path.join(root, "node_modules");
|
|
185
210
|
if (!existsSync(dependencies)) throw fail("mutation-check", "Install project dependencies before using guarded mutations.");
|
|
186
211
|
symlinkSync(realpathSync(dependencies), path.join(candidate, "node_modules"), process.platform === "win32" ? "junction" : "dir");
|
|
@@ -235,6 +260,22 @@ export function createMutationController(directory, { captures = createCaptureCo
|
|
|
235
260
|
checkUnitCandidate(loadConfig(candidate),plan.unit,selected,inventory);
|
|
236
261
|
}
|
|
237
262
|
const candidateOptions = loadConfig(candidate);
|
|
263
|
+
// A proposed configuration may add roots or explicit inputs. Preserve
|
|
264
|
+
// already patched files while bringing those additional live inputs in.
|
|
265
|
+
const proposedInputs = Object.keys(validationInputFiles(candidateOptions));
|
|
266
|
+
copyInputs({root,config:candidateOptions.config,dsRoot:path.resolve(root,candidateOptions.config.dsDir),sourceRoot:path.resolve(root,candidateOptions.config.sourceDir)},candidate,[...patchPaths,...proposedInputs],{baseline:copiedInputs,changed:new Set(changes.map(change=>change.path)),budget:copyBudget});
|
|
267
|
+
const inputPaths = [...new Set([...changes.map(change=>change.path),...Object.keys(validationInputFiles(candidateOptions))])];
|
|
268
|
+
const scopedInputs = () => {
|
|
269
|
+
const files = {};
|
|
270
|
+
for (const original of [options,candidateOptions]) {
|
|
271
|
+
const rebased = { root, config: original.config, dsRoot: path.resolve(root,original.config.dsDir), sourceRoot: path.resolve(root,original.config.sourceDir) };
|
|
272
|
+
Object.assign(files,validationInputFiles(rebased,inputPaths));
|
|
273
|
+
}
|
|
274
|
+
return Object.fromEntries(Object.entries(files).sort(([a],[b])=>a.localeCompare(b)));
|
|
275
|
+
};
|
|
276
|
+
const currentInputs = scopedInputs();
|
|
277
|
+
const before = JSON.stringify(Object.fromEntries(Object.keys(currentInputs).map(file=>[file,copiedInputs.get(file)??null])));
|
|
278
|
+
if (JSON.stringify(currentInputs) !== before) throw fail("mutation-conflict","Relevant inputs changed while preparing validation; regenerate the patch.");
|
|
238
279
|
const extraChecks = checks(candidateOptions);
|
|
239
280
|
const expected = snapshot(candidateOptions);
|
|
240
281
|
candidateRevision=digest(Buffer.from(expected));
|
|
@@ -280,7 +321,7 @@ export function createMutationController(directory, { captures = createCaptureCo
|
|
|
280
321
|
if(!dryRun){try{preparedPreview=preparePreviewCache(candidateOptions,loadConfig(root));}catch{/* A missing cache falls back to background compilation. */}}
|
|
281
322
|
if (signal?.aborted) throw fail("mutation-cancelled", "Mutation cancelled before application.",undefined,evidenceFailure("runner","mutation-execution","ADS_CANCELLED"));
|
|
282
323
|
if (snapshot(candidateOptions) !== expected) throw fail("mutation-check", "A validation command changed source files. Use checks without source-writing side effects.");
|
|
283
|
-
if (
|
|
324
|
+
if (JSON.stringify(scopedInputs()) !== before) throw fail("mutation-conflict", "ADS, consuming UI or declared validation inputs changed during validation; no changes were applied. Read current source and retry.");
|
|
284
325
|
for (const change of changes) address(options, change.path);
|
|
285
326
|
if (screenshots) {
|
|
286
327
|
captures.store.commit(screenshots.records);
|
package/dist/mcp/server.mjs
CHANGED
|
@@ -60,7 +60,7 @@ function resourceQuery(uri, allowed) {
|
|
|
60
60
|
return Object.fromEntries([...url.searchParams].map(([key,value])=>[key,["limit","recordIndex","offset","chars"].includes(key)?Number(value):value]));
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollInterval = 1000, previewWatch, showcaseUrl, notifications, inspection, mutations = false } = {}) {
|
|
63
|
+
export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollInterval = 1000, observeChanges = true, previewWatch, showcaseUrl, notifications, inspection, mutations = false } = {}) {
|
|
64
64
|
const root = path.resolve(directory);
|
|
65
65
|
const cache = inspection ?? {};
|
|
66
66
|
const skills = cache.skills ??= createSkillStore(skillDirectory);
|
|
@@ -484,17 +484,21 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
484
484
|
};
|
|
485
485
|
const artifactFingerprint = () => fileFingerprint(allApps(true).map(app => path.resolve(root, previewArtifactPath(previewOptions(), app.file))));
|
|
486
486
|
const assetFingerprint = () => resourceAssets().map(asset => asset.uri).sort().join("\n");
|
|
487
|
-
let previous
|
|
488
|
-
let previousArtifacts = artifactFingerprint();
|
|
489
|
-
let previousAssets = assetFingerprint();
|
|
490
|
-
let previousBuild = JSON.stringify(builds());
|
|
491
|
-
let previousCaptures = captures.store.fingerprint();
|
|
492
|
-
let previousCaptureUris = captures.store.resourceUris();
|
|
487
|
+
let previous, previousArtifacts, previousAssets, previousBuild, previousCaptures, previousCaptureUris;
|
|
493
488
|
const investigationFingerprint=()=>fileFingerprint([path.join(root,".ds/investigations.json")]);
|
|
494
|
-
let previousInvestigations=
|
|
495
|
-
|
|
489
|
+
let previousInvestigations, previousResults, observing=false;
|
|
490
|
+
function initializeObservation() {
|
|
491
|
+
if (observing) return;
|
|
492
|
+
previous=fingerprint();previousArtifacts=artifactFingerprint();previousAssets=assetFingerprint();previousBuild=JSON.stringify(builds());
|
|
493
|
+
previousCaptures=captures.store.fingerprint();previousCaptureUris=captures.store.resourceUris();
|
|
494
|
+
previousInvestigations=investigationFingerprint();previousResults=executionResults.fingerprint();observing=true;
|
|
495
|
+
}
|
|
496
|
+
// Modern HTTP serves a fresh protocol instance per request. Its shared observer
|
|
497
|
+
// already tracks changes; immutable byte reads need no source/build scan.
|
|
498
|
+
if (observeChanges) initializeObservation();
|
|
496
499
|
let deferredDiscovery = false;
|
|
497
500
|
async function refresh(force = false) {
|
|
501
|
+
if (!observing) { initializeObservation();force=true; }
|
|
498
502
|
// Polling covers replaced files and new directories consistently across OSes.
|
|
499
503
|
cache.documents = undefined;
|
|
500
504
|
const next = fingerprint();
|
|
@@ -558,7 +562,7 @@ export async function startAdsMcp(directory = process.cwd(), { stdio = true, sho
|
|
|
558
562
|
let host;
|
|
559
563
|
const showcaseUrl = () => host?.url;
|
|
560
564
|
if (showcase) {
|
|
561
|
-
host = await startShowcaseHost(({ era }) => createAdsMcp(directory, { era, previewWatch, showcaseUrl, inspection, mutations, pollInterval: 0 }).server,
|
|
565
|
+
host = await startShowcaseHost(({ era }) => createAdsMcp(directory, { era, previewWatch, showcaseUrl, inspection, mutations, pollInterval: 0, observeChanges:false }).server,
|
|
562
566
|
{ port, observe: notifications => createAdsMcp(directory, { era: "modern", previewWatch, showcaseUrl, inspection, mutations, notifications }) });
|
|
563
567
|
process.stderr.write(`ADS showcase: ${host.url}\n`);
|
|
564
568
|
}
|
package/dist/preview-files.mjs
CHANGED
|
@@ -1,31 +1,38 @@
|
|
|
1
1
|
import { readdirSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { isInside } from "./config.mjs";
|
|
4
3
|
|
|
5
4
|
const metadata = new Set(["node_modules", ".git", ".ds", ".vite", "coverage"]);
|
|
6
5
|
const generated = new Set(["dist", "build", "target", "out", ".next", ".nuxt", ".svelte-kit", ".turbo"]);
|
|
7
6
|
|
|
8
7
|
/** Shared watch/fingerprint policy. Explicit source roots take priority over default outputs. */
|
|
9
|
-
export function
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const sources = [config.dsDir, config.sourceDir].map(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
export function createPreviewFileFilter({root, config}) {
|
|
9
|
+
const canonical = value => process.platform === "win32" ? value.toLowerCase() : value;
|
|
10
|
+
const relativePath = file => canonical(path.relative(root, path.resolve(root, file)));
|
|
11
|
+
const outputs = config.assets.generatedPaths.map(relativePath);
|
|
12
|
+
const sources = [config.dsDir, config.sourceDir].map(relativePath);
|
|
13
|
+
const within = (parent, file) => parent === ""
|
|
14
|
+
? file !== ".." && !file.startsWith(`..${path.sep}`) && !path.isAbsolute(file)
|
|
15
|
+
: file === parent || file.startsWith(parent + path.sep);
|
|
16
|
+
return file => {
|
|
17
|
+
const relative = path.relative(root, path.resolve(file)), parts = relative.split(path.sep);
|
|
18
|
+
if (parts.some(name => metadata.has(name))) return true;
|
|
19
|
+
const key = canonical(relative);
|
|
20
|
+
if (outputs.some(base => within(base, key))) return true;
|
|
21
|
+
return parts.some(name => generated.has(name)) && !sources.some(source => within(source, key) || within(key, source));
|
|
22
|
+
};
|
|
19
23
|
}
|
|
20
24
|
|
|
25
|
+
export const previewFileIgnored = (options, file) => createPreviewFileFilter(options)(file);
|
|
26
|
+
|
|
21
27
|
/** Allocate individual watches so excluded descendants never consume OS watches. */
|
|
22
28
|
export function previewWatchDirectories(options) {
|
|
23
29
|
const directories = [];
|
|
30
|
+
const ignored = createPreviewFileFilter(options);
|
|
24
31
|
function visit(directory) {
|
|
25
32
|
directories.push(directory);
|
|
26
33
|
for (const entry of readdirSync(directory, {withFileTypes:true})) {
|
|
27
34
|
const child = path.join(directory, entry.name);
|
|
28
|
-
if (entry.isDirectory() && !entry.isSymbolicLink() && !
|
|
35
|
+
if (entry.isDirectory() && !entry.isSymbolicLink() && !ignored(child)) visit(child);
|
|
29
36
|
}
|
|
30
37
|
}
|
|
31
38
|
visit(options.root);
|
package/dist/preview-inputs.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
4
|
-
import { previewFileIgnored } from "./preview-files.mjs";
|
|
5
3
|
import { isScenarioFile } from "./config.mjs";
|
|
6
4
|
import { scenarioGroupFingerprint } from "./scenario-groups.mjs";
|
|
5
|
+
import { validationInputFiles } from "./validation-inputs.mjs";
|
|
7
6
|
|
|
8
7
|
/** Shared source evidence for compilation, watch recovery and status reads. */
|
|
9
8
|
export function previewSourceRevision(options, apps = options.config.mcp.apps ?? []) {
|
|
@@ -11,22 +10,12 @@ export function previewSourceRevision(options, apps = options.config.mcp.apps ??
|
|
|
11
10
|
const rows = [];
|
|
12
11
|
const scenarios = [];
|
|
13
12
|
const outputs = new Set(apps.map(app => path.resolve(root,app.file)));
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (outputs.has(file) || previewFileIgnored(options,file)) continue;
|
|
20
|
-
if (entry.isDirectory()) visit(file);
|
|
21
|
-
else if (entry.isFile() && /\.(?:[cm]?[jt]sx?|css|html|json|md|svg|png|jpe?g|webp|gif|woff2?|ttf|otf|lock|lockb)$/.test(file)) {
|
|
22
|
-
rows.push([path.relative(root,file),digest(file)]);
|
|
23
|
-
if (isScenarioFile(file)) scenarios.push(file);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
13
|
+
for (const [relative,digest] of Object.entries(validationInputFiles(options))) {
|
|
14
|
+
const file=path.resolve(root,relative);
|
|
15
|
+
if (outputs.has(file)) continue;
|
|
16
|
+
rows.push([relative,digest]);
|
|
17
|
+
if (digest && isScenarioFile(file)) scenarios.push(file);
|
|
26
18
|
}
|
|
27
|
-
visit(root);
|
|
28
19
|
rows.push(["scenario-group-structure",scenarioGroupFingerprint(options,scenarios)]);
|
|
29
|
-
const installed = path.join(root,"node_modules/.package-lock.json");
|
|
30
|
-
rows.push(["installed-packages",existsSync(installed) ? digest(installed) : null]);
|
|
31
20
|
return createHash("sha256").update(JSON.stringify(rows.sort((a,b)=>a[0].localeCompare(b[0])))).digest("hex");
|
|
32
21
|
}
|
|
@@ -11,6 +11,10 @@ export const PREVIEW_MANIFEST_URI = "ads://preview/manifest";
|
|
|
11
11
|
export const LIVE_PREVIEW_MANIFEST_URI = "ads://preview/live";
|
|
12
12
|
export const assetUriPattern = /^ads:\/\/assets\/[a-f0-9]{64}\.[a-z0-9]+$/;
|
|
13
13
|
const hash = value => createHash("sha256").update(value).digest("hex");
|
|
14
|
+
// Cache verification metadata only. Resource reads still hash the returned bytes;
|
|
15
|
+
// status polling can reuse a check until the file identity or timestamps change.
|
|
16
|
+
const verifiedAssetFiles = new Map();
|
|
17
|
+
const assetStamp = stat => [stat.dev, stat.ino, stat.mode, stat.size, stat.mtimeNs, stat.ctimeNs].join(":");
|
|
14
18
|
const unknownResource = message => Object.assign(new Error(message), { code: "ADS_PREVIEW_NOT_FOUND" });
|
|
15
19
|
const mime = file => ({ js: "text/javascript", css: "text/css", json: "application/json", svg: "image/svg+xml", woff2: "font/woff2", woff: "font/woff", ttf: "font/ttf", otf: "font/otf", png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", webp: "image/webp", gif: "image/gif", wasm: "application/wasm" })[file.split(".").pop()] ?? "application/octet-stream";
|
|
16
20
|
function atomic(file, bytes) {
|
|
@@ -208,7 +212,9 @@ export function readPreviewManifest(options, { verify = false } = {}) {
|
|
|
208
212
|
const file = previewManifestPath(options);
|
|
209
213
|
if (!existsSync(file)) return null;
|
|
210
214
|
const manifest = readManifestFile(file);
|
|
211
|
-
if (verify) for (const uri of Object.
|
|
215
|
+
if (verify) for (const [uri, record] of Object.entries(manifest.assets)) {
|
|
216
|
+
verifiedAssetBytes(options, uri, record, verify === "cached");
|
|
217
|
+
}
|
|
212
218
|
return manifest;
|
|
213
219
|
}
|
|
214
220
|
|
|
@@ -243,10 +249,26 @@ export function readPreviewAsset(options, uri, manifest = readPreviewManifest(op
|
|
|
243
249
|
}
|
|
244
250
|
}
|
|
245
251
|
if (!record) throw unknownResource("Unknown or expired preview asset resource. Refresh the manifest.");
|
|
252
|
+
const bytes = verifiedAssetBytes(options, uri, record);
|
|
253
|
+
return { uri, mimeType: record.mimeType, ...(/^(?:text\/|application\/json|image\/svg)/.test(record.mimeType) ? { text: bytes.toString() } : { blob: bytes.toString("base64") }) };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function verifiedAssetBytes(options, uri, record, cached = false) {
|
|
246
257
|
const directory = path.join(path.dirname(previewManifestPath(options)), "assets");
|
|
247
258
|
const file = path.join(directory, uri.slice("ads://assets/".length));
|
|
248
|
-
if (!isInside(directory, file) || realpathSync(file) !== file
|
|
259
|
+
if (!isInside(directory, file) || realpathSync(file) !== file) throw new Error("Invalid preview asset file.");
|
|
260
|
+
const stat = statSync(file, { bigint: true });
|
|
261
|
+
if (!stat.isFile() || stat.size > 16n * 1024n * 1024n) throw new Error("Invalid preview asset file.");
|
|
262
|
+
const key = `${file}:${record.digest}:${record.size}`;
|
|
263
|
+
const stamp = assetStamp(stat);
|
|
264
|
+
if (cached && verifiedAssetFiles.get(key) === stamp) return;
|
|
249
265
|
const bytes = readFileSync(file);
|
|
250
266
|
if (bytes.length !== record.size || `sha256:${hash(bytes)}` !== record.digest) throw new Error("Preview resource does not match its successful build. Rebuild before reviewing.");
|
|
251
|
-
|
|
267
|
+
// A write racing the read must not seed a cache entry for different bytes.
|
|
268
|
+
if (assetStamp(statSync(file, { bigint: true })) === stamp) {
|
|
269
|
+
verifiedAssetFiles.delete(key);
|
|
270
|
+
verifiedAssetFiles.set(key, stamp);
|
|
271
|
+
if (verifiedAssetFiles.size > 4096) verifiedAssetFiles.delete(verifiedAssetFiles.keys().next().value);
|
|
272
|
+
}
|
|
273
|
+
return bytes;
|
|
252
274
|
}
|
|
@@ -48,3 +48,7 @@ export function projectDocumentFiles(root) {
|
|
|
48
48
|
export function projectGuideFiles(root) {
|
|
49
49
|
return projectDocumentFiles(root).filter(file => !isProjectNotice(file));
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
export function projectNoticeFiles(root) {
|
|
53
|
+
return projectDocumentFiles(root).filter(isProjectNotice);
|
|
54
|
+
}
|
package/dist/scenario-trace.mjs
CHANGED
|
@@ -191,7 +191,8 @@ export function createScenarioTrace(program, options) {
|
|
|
191
191
|
const context = state();
|
|
192
192
|
const input = property ? get(reference(expression), "className", next(context)) : reference(expression);
|
|
193
193
|
const value = resolve(input, next(context));
|
|
194
|
-
|
|
194
|
+
const absent = value => value.kind === "literal" && value.value === undefined || value.kind === "union" && value.values.every(absent);
|
|
195
|
+
if (property && absent(value)) return { present: false, ok: true, reasons: [] };
|
|
195
196
|
const proof = verify(input, context);
|
|
196
197
|
const ok = proof.ok && proof.branches.some(branch => branch.atoms) && proof.branches.every(branch => !branch.hooks || branch.atoms);
|
|
197
198
|
if (!ok && !reasons.size) reasons.add("Each nonempty return path needs owned Linaria styles; stable hooks alone are not styling evidence.");
|