@reqvire-org/ads 0.3.39 → 0.3.41
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/bun-compiler.mjs +1 -1
- package/dist/config.mjs +4 -1
- package/dist/investigations.mjs +27 -8
- package/dist/mcp/build-status.mjs +27 -16
- package/dist/mcp/context.mjs +1 -1
- package/dist/mcp/drafts.mjs +1 -1
- package/dist/mcp/execution-context.mjs +38 -0
- package/dist/mcp/execution-coordinator.mjs +220 -0
- package/dist/mcp/execution-results.mjs +107 -48
- package/dist/mcp/mutations.mjs +2 -0
- package/dist/mcp/preview-widget.bundle.js +2 -2
- package/dist/mcp/resource-loader.js +3 -2
- package/dist/mcp/server.mjs +42 -13
- package/dist/preview-failure.mjs +20 -0
- package/dist/preview-resources.mjs +69 -21
- package/dist/scenarios-compiler.mjs +7 -6
- package/dist/showcase/client.bundle.js +43 -41
- package/dist/showcase/index.html +15 -1
- package/dist/showcase/preview-state.js +2 -1
- package/dist/showcase/style.css +4 -1
- package/dist/skills/ads-break-ui/references/behaviors.md +4 -5
- package/dist/skills/ads-break-ui/references/evidence.md +12 -8
- package/dist/skills/ads-break-ui/references/validation.md +33 -0
- package/dist/skills/ads-designer/references/behaviors.md +4 -5
- package/dist/skills/ads-designer/references/evidence.md +12 -8
- package/dist/skills/ads-designer/references/validation.md +33 -0
- package/dist/skills/ads-import/references/behaviors.md +4 -5
- package/dist/skills/ads-import/references/evidence.md +12 -8
- package/dist/skills/ads-import/references/validation.md +33 -0
- package/dist/skills/ads-motion/references/behaviors.md +4 -5
- package/dist/skills/ads-motion/references/evidence.md +12 -8
- package/dist/skills/ads-motion/references/validation.md +33 -0
- package/dist/skills/ads-port/references/behaviors.md +4 -5
- package/dist/skills/ads-port/references/evidence.md +12 -8
- package/dist/skills/ads-port/references/validation.md +33 -0
- package/dist/validation-checks.mjs +6 -2
- package/dist/validation.mjs +8 -2
- package/dist/verification.mjs +7 -3
- package/docs/ARCHITECTURE.md +21 -3
- package/docs/CHANGELOG.md +40 -28
- package/docs/MCP.md +66 -12
- package/docs/plans/execution-coordination.md +57 -0
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Preserve the boundary that failed across compiler, MCP and Explorer. */
|
|
2
|
+
export function scopedPreviewFailure(value, scope, phase) {
|
|
3
|
+
const error = value instanceof Error ? value : new Error(String(value));
|
|
4
|
+
error.previewFailure ??= { scope, phase };
|
|
5
|
+
return error;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function previewFailureTitle(build) {
|
|
9
|
+
if (build?.failure?.scope !== "project") return "Preview build failed";
|
|
10
|
+
if (build.failure.phase === "validation") return "Project validation failed";
|
|
11
|
+
if (build.failure.phase === "discovery") return "Project scenario discovery failed";
|
|
12
|
+
return "Project preview build failed";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function previewDiagnosticText(diagnostics = []) {
|
|
16
|
+
return diagnostics.map(entry => {
|
|
17
|
+
const location = entry.file ? entry.file + (entry.line ? `:${entry.line}` : "") + (entry.column ? `:${entry.column}` : "") : "";
|
|
18
|
+
return (location ? `${location}: ` : "") + entry.message;
|
|
19
|
+
}).join("\n");
|
|
20
|
+
}
|
|
@@ -48,25 +48,54 @@ export function previewEntriesPlugin(entries, mountEntry) {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
// Hash the dependency graph before inserting resource URLs. Cyclic ES modules
|
|
52
|
+
// share a component fingerprint; hashing rewritten bytes recursively cannot
|
|
53
|
+
// converge for cycles. Unrelated graph branches keep their existing identities.
|
|
54
|
+
function resourceUris(prepared) {
|
|
55
|
+
const nodes = new Map([...prepared].map(([file, item]) => [file, {...item, index: -1, low: -1}]));
|
|
56
|
+
const stack = [];
|
|
57
|
+
let index = 0;
|
|
58
|
+
function visit(node) {
|
|
59
|
+
node.index = node.low = index++;
|
|
60
|
+
stack.push(node); node.stacked = true;
|
|
61
|
+
for (const file of node.dependencies) {
|
|
62
|
+
const child = nodes.get(file);
|
|
63
|
+
if (child.index < 0) { visit(child); node.low = Math.min(node.low, child.low); }
|
|
64
|
+
else if (child.stacked) node.low = Math.min(node.low, child.index);
|
|
65
|
+
}
|
|
66
|
+
if (node.low !== node.index) return;
|
|
67
|
+
const group = {members: []};
|
|
68
|
+
let member;
|
|
69
|
+
do { member = stack.pop(); member.stacked = false; member.group = group; group.members.push(member); } while (member !== node);
|
|
70
|
+
group.members.sort((a, b) => a.file.localeCompare(b.file));
|
|
71
|
+
}
|
|
72
|
+
for (const node of nodes.values()) if (node.index < 0) visit(node);
|
|
73
|
+
function fingerprint(group) {
|
|
74
|
+
return group.fingerprint ??= hash(JSON.stringify(group.members.map(node => [
|
|
75
|
+
node.file, node.digest,
|
|
76
|
+
node.dependencies.map(file => { const child = nodes.get(file); return [file, child.group === group ? null : fingerprint(child.group)]; }),
|
|
77
|
+
])));
|
|
78
|
+
}
|
|
79
|
+
return new Map([...nodes].map(([file, node]) => [file, `ads://assets/${hash("ads-preview-v3\n" + file + "\n" + fingerprint(node.group))}.${file.split(".").pop()}`]));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Convert compiler output to registered MCP resources without evaluating project code. */
|
|
52
83
|
export function createPreviewResources(output, options, entries, {retain, prune = false} = {}) {
|
|
53
84
|
const bundle = (Array.isArray(output) ? output : [output]).flatMap(result => result.output);
|
|
85
|
+
const files = new Map(bundle.map(item => [item.fileName, item]));
|
|
54
86
|
const original = item => Buffer.from(item.type === "chunk" ? item.code : item.source);
|
|
55
|
-
|
|
56
|
-
// content too; an immutable URI must never represent two different outputs.
|
|
57
|
-
// Bump the transform version whenever emitted resource rewriting changes.
|
|
58
|
-
const uris = new Map(bundle.map(item => [item.fileName, `ads://assets/${hash(Buffer.concat([Buffer.from("ads-preview-v2\n" + item.fileName + "\n"), original(item)]))}.${item.fileName.split(".").pop()}`]));
|
|
87
|
+
const prepared = new Map();
|
|
59
88
|
const records = {...retain?.manifest.assets};
|
|
60
89
|
const contents = new Map(retain?.contents);
|
|
61
90
|
function reference(from, value) {
|
|
62
91
|
if (/^(?:[a-z]+:|#|\/\/)/i.test(value)) return null;
|
|
63
92
|
const file = value.startsWith("/") ? value.slice(1) : path.posix.normalize(path.posix.join(path.posix.dirname(from), value));
|
|
64
|
-
return
|
|
93
|
+
return files.has(file) ? file : null;
|
|
65
94
|
}
|
|
66
95
|
for (const item of bundle) {
|
|
67
|
-
const uri = uris.get(item.fileName);
|
|
68
96
|
const references = new Set();
|
|
69
|
-
|
|
97
|
+
const bytes = original(item);
|
|
98
|
+
let render = () => bytes;
|
|
70
99
|
if (item.type === "chunk" || item.fileName.endsWith(".js")) {
|
|
71
100
|
const source = ts.createSourceFile(item.fileName, bytes.toString(), ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
72
101
|
const replacements = [];
|
|
@@ -75,8 +104,8 @@ export function createPreviewResources(output, options, entries, {retain, prune
|
|
|
75
104
|
let bundledWorker = false;
|
|
76
105
|
function workerReference(child) {
|
|
77
106
|
if (ts.isStringLiteralLike(child)) {
|
|
78
|
-
const
|
|
79
|
-
const asset =
|
|
107
|
+
const file = reference(item.fileName, child.text);
|
|
108
|
+
const asset = files.get(file);
|
|
80
109
|
if (asset?.type === "asset" && mime(asset.fileName) === "text/javascript") {
|
|
81
110
|
const worker = ts.createSourceFile(asset.fileName, original(asset).toString(), ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
82
111
|
if (worker.statements.some(statement => ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement) || statement.modifiers?.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword))) throw new Error("Preview workers must be self-contained IIFE output. Use self-contained worker output in the ADS preview compiler.");
|
|
@@ -99,32 +128,51 @@ export function createPreviewResources(output, options, entries, {retain, prune
|
|
|
99
128
|
if (target) {
|
|
100
129
|
references.add(target);
|
|
101
130
|
if (ts.isCallExpression(node.parent) && node.parent.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
102
|
-
replacements.push([node.parent.getStart(source), node.parent.end, `globalThis.__dsPreviewImport(${JSON.stringify(target)})`]);
|
|
103
|
-
} else replacements.push([node.getStart(source), node.end, JSON.stringify(target)]);
|
|
131
|
+
replacements.push([node.parent.getStart(source), node.parent.end, uris => `globalThis.__dsPreviewImport(${JSON.stringify(uris.get(target))})`]);
|
|
132
|
+
} else replacements.push([node.getStart(source), node.end, uris => JSON.stringify(uris.get(target))]);
|
|
104
133
|
}
|
|
105
134
|
}
|
|
106
135
|
ts.forEachChild(node, visit);
|
|
107
136
|
}
|
|
108
137
|
visit(source);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
138
|
+
replacements.sort((a, b) => b[0] - a[0]);
|
|
139
|
+
render = uris => {
|
|
140
|
+
let code = bytes.toString();
|
|
141
|
+
for (const [start, end, replacement] of replacements) code = code.slice(0, start) + (typeof replacement === "function" ? replacement(uris) : replacement) + code.slice(end);
|
|
142
|
+
return Buffer.from(code);
|
|
143
|
+
};
|
|
112
144
|
} else if (item.fileName.endsWith(".css")) {
|
|
113
145
|
const parsed = valueParser(bytes.toString());
|
|
146
|
+
const replacements = [];
|
|
114
147
|
parsed.walk(node => {
|
|
115
148
|
if (node.type !== "function" || node.value !== "url") return;
|
|
116
149
|
const value = valueParser.stringify(node.nodes).replace(/^["']|["']$/g, "");
|
|
117
150
|
const marker=value.indexOf("#"),fragment=marker<0?"":value.slice(marker);
|
|
118
151
|
const target = reference(item.fileName, marker<0?value:value.slice(0,marker));
|
|
119
|
-
if (target) { references.add(target);
|
|
152
|
+
if (target) { references.add(target); replacements.push([node, target, fragment]); }
|
|
120
153
|
});
|
|
121
|
-
|
|
154
|
+
render = uris => {
|
|
155
|
+
for (const [node, target, fragment] of replacements) node.nodes = [{ type: "string", quote: '"', value: uris.get(target)+fragment }];
|
|
156
|
+
return Buffer.from(parsed.toString());
|
|
157
|
+
};
|
|
122
158
|
}
|
|
123
|
-
const imports = item.type === "chunk" ? item.imports.
|
|
124
|
-
const dynamicImports = item.type === "chunk" ? item.dynamicImports.
|
|
159
|
+
const imports = item.type === "chunk" ? item.imports.filter(file => files.has(file)) : [];
|
|
160
|
+
const dynamicImports = item.type === "chunk" ? item.dynamicImports.filter(file => files.has(file)) : [];
|
|
161
|
+
// Only URLs written into bytes affect immutable identity. Associated style
|
|
162
|
+
// metadata can change without changing JS, including already-open lazy
|
|
163
|
+
// modules whose styles refresh while preserving mounted state.
|
|
164
|
+
const dependencies = [...references].sort();
|
|
125
165
|
for (const dependency of [...imports, ...dynamicImports]) references.delete(dependency);
|
|
126
|
-
const styles = item.type === "chunk" ? [...item.viteMetadata?.importedCss ?? []].
|
|
127
|
-
|
|
166
|
+
const styles = item.type === "chunk" ? [...item.viteMetadata?.importedCss ?? []].filter(file => files.has(file)) : [];
|
|
167
|
+
const links = {imports, dynamicImports, styles, references: [...references]};
|
|
168
|
+
prepared.set(item.fileName, {file: item.fileName, digest: hash(bytes), links, dependencies, render});
|
|
169
|
+
}
|
|
170
|
+
// Bump the transform version in resourceUris whenever rewriting changes.
|
|
171
|
+
const uris = resourceUris(prepared);
|
|
172
|
+
for (const item of bundle) {
|
|
173
|
+
const uri = uris.get(item.fileName), preparedItem = prepared.get(item.fileName), bytes = preparedItem.render(uris);
|
|
174
|
+
const links = Object.fromEntries(Object.entries(preparedItem.links).map(([key, files]) => [key, files.map(file => uris.get(file))]));
|
|
175
|
+
records[uri] = { mimeType: mime(item.fileName), size: bytes.length, digest: `sha256:${hash(bytes)}`, kind: item.type === "chunk" ? "module" : "asset", ...links };
|
|
128
176
|
contents.set(uri, bytes);
|
|
129
177
|
}
|
|
130
178
|
const scenarios = entries.map((entry, index) => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { scopedPreviewFailure } from "./preview-failure.mjs";
|
|
1
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
3
|
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
@@ -235,7 +236,7 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
235
236
|
let discovering, unknownRevision;
|
|
236
237
|
let liveCandidate, verifying = false;
|
|
237
238
|
function failure(error) {
|
|
238
|
-
try { reporter.failure(error); } catch (reportError) { console.error(reportError); }
|
|
239
|
+
try { reporter.failure(scopedPreviewFailure(error,"project","discovery")); } catch (reportError) { console.error(reportError); }
|
|
239
240
|
console.error(error);
|
|
240
241
|
if (!watched) process.exitCode = 1;
|
|
241
242
|
}
|
|
@@ -246,7 +247,7 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
246
247
|
return validation ??= Promise.resolve().then(validate).then(() => {
|
|
247
248
|
if (stamp !== cache.inputs()) throw new Error("Sources changed during preview validation. Waiting for the current build.");
|
|
248
249
|
cache.validate(stamp);
|
|
249
|
-
});
|
|
250
|
+
}).catch(error=>{throw scopedPreviewFailure(error,"project","validation");});
|
|
250
251
|
}
|
|
251
252
|
async function checkedBuild(stamp, build) {
|
|
252
253
|
const started = generation;
|
|
@@ -296,7 +297,7 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
296
297
|
reporter.progress("idle");
|
|
297
298
|
} catch (error) {
|
|
298
299
|
if (started !== generation) return;
|
|
299
|
-
reporter.error(entry.id, revision, error);
|
|
300
|
+
reporter.error(entry.id, revision, scopedPreviewFailure(error,"scenario","build"));
|
|
300
301
|
reporter.progress("idle");
|
|
301
302
|
console.error(error);
|
|
302
303
|
if (!watched) process.exitCode = 1;
|
|
@@ -355,7 +356,7 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
355
356
|
return true;
|
|
356
357
|
} catch (error) {
|
|
357
358
|
if (started !== generation) return;
|
|
358
|
-
for (const entry of entries) { pending.delete(entry.id); reporter.error(entry.id, revisions.get(entry.id), error); }
|
|
359
|
+
for (const entry of entries) { pending.delete(entry.id); reporter.error(entry.id, revisions.get(entry.id), scopedPreviewFailure(error,"graph","build")); }
|
|
359
360
|
reporter.progress("idle");
|
|
360
361
|
console.error(error);
|
|
361
362
|
if (!watched) process.exitCode = 1;
|
|
@@ -432,7 +433,7 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
432
433
|
warmProgress();
|
|
433
434
|
reporter.batch(() => {
|
|
434
435
|
reporter.live(undefined);
|
|
435
|
-
for (const entry of candidate.entries) reporter.error(entry.id, candidate.revisions.get(entry.id), error);
|
|
436
|
+
for (const entry of candidate.entries) reporter.error(entry.id, candidate.revisions.get(entry.id), scopedPreviewFailure(error,"graph","build"));
|
|
436
437
|
reporter.progress("idle");
|
|
437
438
|
});
|
|
438
439
|
console.error(error);
|
|
@@ -461,7 +462,7 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
461
462
|
try {
|
|
462
463
|
if (outcomes[2].status === "rejected") throw outcomes[2].reason;
|
|
463
464
|
const registry = outcomes[2].value;
|
|
464
|
-
if (registry.diagnostics.length) throw new Error(registry
|
|
465
|
+
if (registry.diagnostics.length) throw Object.assign(scopedPreviewFailure(new Error("Scenario registry has errors."),"project","discovery"),{diagnostics:registry.diagnostics});
|
|
465
466
|
if (JSON.stringify(registry.scenarios) !== JSON.stringify(candidate.registry)) {
|
|
466
467
|
entries = registry.scenarios;
|
|
467
468
|
writeFileSync(path.join(root, ".ds/scenarios/manifest.json"), JSON.stringify({ schemaVersion: 1, scenarios: entries }, null, 2));
|