@reqvire-org/ads 0.3.27 → 0.3.29
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/atomic-composition.mjs +2 -1
- package/dist/behaviors.mjs +2 -2
- package/dist/bootstrap-ds/scripts/build-mcp-previews.mjs +6 -7
- package/dist/boundaries.mjs +6 -3
- package/dist/check.mjs +3 -0
- package/dist/cli.mjs +13 -0
- package/dist/config.mjs +5 -3
- package/dist/mcp/build-status.mjs +17 -4
- package/dist/mcp/context.mjs +2 -1
- package/dist/mcp/execution-results.mjs +4 -3
- package/dist/mcp/mutations.mjs +5 -43
- package/dist/mcp/preview-watch.mjs +23 -3
- package/dist/mcp/preview-widget.bundle.js +16 -15
- package/dist/mcp/project-widget.bundle.js +13 -13
- package/dist/mcp/resource-loader.js +50 -13
- package/dist/mcp/server.mjs +81 -39
- package/dist/oxlint.mjs +6 -1
- package/dist/preview-builder.mjs +114 -0
- package/dist/preview-inputs.mjs +8 -1
- package/dist/preview-resources.mjs +11 -4
- package/dist/preview-scope.mjs +6 -0
- package/dist/preview-workers.mjs +184 -0
- package/dist/scenario-groups.mjs +47 -0
- package/dist/scenario-inspector.mjs +34 -0
- package/dist/scenario-trace.mjs +3 -2
- package/dist/scenarios-compiler.mjs +203 -27
- package/dist/scenarios-vite.mjs +13 -5
- package/dist/scenarios.mjs +4 -1
- package/dist/showcase/client.bundle.js +23 -22
- package/dist/showcase/index.html +2 -2
- package/dist/showcase/navigation.js +13 -0
- package/dist/showcase/style.css +3 -1
- package/dist/skills/ads-break-ui/SKILL.md +4 -1
- package/dist/skills/ads-break-ui/references/runtimes.md +48 -0
- package/dist/skills/ads-break-ui/references/scenarios.md +19 -0
- package/dist/skills/ads-break-ui/references/validation.md +53 -0
- package/dist/skills/ads-designer/SKILL.md +4 -1
- package/dist/skills/ads-designer/assets/bootstrap-ds/scripts/build-mcp-previews.mjs +6 -7
- package/dist/skills/ads-designer/references/runtimes.md +48 -0
- package/dist/skills/ads-designer/references/scenarios.md +19 -0
- package/dist/skills/ads-designer/references/validation.md +53 -0
- package/dist/skills/ads-import/SKILL.md +4 -1
- package/dist/skills/ads-import/references/runtimes.md +48 -0
- package/dist/skills/ads-import/references/scenarios.md +19 -0
- package/dist/skills/ads-import/references/validation.md +53 -0
- package/dist/skills/ads-motion/SKILL.md +4 -1
- package/dist/skills/ads-motion/references/runtimes.md +48 -0
- package/dist/skills/ads-motion/references/scenarios.md +19 -0
- package/dist/skills/ads-motion/references/validation.md +53 -0
- package/dist/skills/ads-port/SKILL.md +4 -1
- package/dist/skills/ads-port/references/runtimes.md +48 -0
- package/dist/skills/ads-port/references/scenarios.md +19 -0
- package/dist/skills/ads-port/references/validation.md +53 -0
- package/dist/source-symbols.mjs +11 -0
- package/dist/source-values.mjs +10 -3
- package/dist/test-boundaries.mjs +95 -0
- package/dist/ui-framework.mjs +2 -1
- package/dist/units.mjs +12 -1
- package/dist/validation-checks.mjs +50 -0
- package/dist/validation.mjs +172 -0
- package/dist/verification/browser.mjs +3 -1
- package/dist/verification.mjs +1 -0
- package/docs/ADS.md +12 -2
- package/docs/ARCHITECTURE.md +125 -7
- package/docs/BEHAVIORS.md +7 -0
- package/docs/CHANGELOG.md +54 -0
- package/docs/GUIDE.md +31 -0
- package/docs/MCP.md +127 -16
- package/package.json +1 -1
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
function closure(records, uri) {
|
|
2
|
+
const ordered = [], seen = new Set();
|
|
3
|
+
function visit(id) {
|
|
4
|
+
if (seen.has(id)) return;
|
|
5
|
+
seen.add(id);
|
|
6
|
+
const record=records.get(id);
|
|
7
|
+
if (!record) throw new Error(`Missing preview dependency metadata: ${id}`);
|
|
8
|
+
for (const dependency of [...record.imports,...record.styles,...record.references]) visit(dependency);
|
|
9
|
+
ordered.push(id);
|
|
10
|
+
}
|
|
11
|
+
visit(uri);return ordered;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function changedPreviewScenarios(previous, next) {
|
|
15
|
+
if (!previous || previous.revision===next.revision) return [];
|
|
16
|
+
const signature=(graph,entry)=>{const records=new Map(Object.entries(graph.assets));return JSON.stringify(closure(records,entry.module).map(uri=>[uri,records.get(uri)]));};
|
|
17
|
+
return next.scenarios.filter(entry=>{const before=previous.scenarios.find(item=>item.id===entry.id);return !before || signature(previous,before)!==signature(next,entry);}).map(entry=>entry.id);
|
|
18
|
+
}
|
|
19
|
+
|
|
1
20
|
/** Native ES modules keep framework semantics, cycles, and live bindings intact. */
|
|
2
21
|
export class PreviewResourceLoader {
|
|
3
22
|
constructor(read) {
|
|
@@ -10,6 +29,7 @@ export class PreviewResourceLoader {
|
|
|
10
29
|
this.revisions = new Set();
|
|
11
30
|
this.importing = Promise.resolve();
|
|
12
31
|
this.generation = 0;
|
|
32
|
+
this.prefetchGeneration = 0;
|
|
13
33
|
this.closed = false;
|
|
14
34
|
globalThis.__dsPreviewImport = uri => this.importModule(uri);
|
|
15
35
|
}
|
|
@@ -47,18 +67,25 @@ export class PreviewResourceLoader {
|
|
|
47
67
|
return this.bytes.get(uri);
|
|
48
68
|
}
|
|
49
69
|
closure(uri) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
70
|
+
return closure(this.records,uri);
|
|
71
|
+
}
|
|
72
|
+
async prefetch(manifest, ids) {
|
|
73
|
+
if (this.closed) return;
|
|
74
|
+
this.register(manifest);
|
|
75
|
+
const generation=++this.prefetchGeneration, pending=new Set(), scenarios=[];
|
|
76
|
+
let bytes=0;
|
|
77
|
+
for (const id of ids) {
|
|
78
|
+
const entry=manifest.scenarios.find(entry=>entry.id===id);
|
|
79
|
+
if (!entry) continue;
|
|
80
|
+
const missing=this.closure(entry.module).filter(uri=>!this.bytes.has(uri)&&!pending.has(uri));
|
|
81
|
+
const size=missing.reduce((sum,uri)=>sum+this.records.get(uri).size,0);
|
|
82
|
+
if (bytes+size>16*1024*1024 || pending.size+missing.length>256) continue;
|
|
83
|
+
bytes+=size;scenarios.push(id);for(const uri of missing)pending.add(uri);
|
|
84
|
+
}
|
|
85
|
+
const queue=[...pending];let index=0;
|
|
86
|
+
const next=async()=>{while(!this.closed&&generation===this.prefetchGeneration&&index<queue.length)await this.resource(queue[index++]);};
|
|
87
|
+
await Promise.all(Array.from({length:Math.min(3,queue.length)},next));
|
|
88
|
+
return {scenarios,resources:queue.length};
|
|
62
89
|
}
|
|
63
90
|
async materialize(uri) {
|
|
64
91
|
const ordered = this.closure(uri);
|
|
@@ -115,9 +142,16 @@ export class PreviewResourceLoader {
|
|
|
115
142
|
this.register(manifest);
|
|
116
143
|
const scenario = manifest.scenarios.find(entry => entry.id === id);
|
|
117
144
|
if (!scenario) throw new Error("The selected scenario is no longer registered.");
|
|
145
|
+
const signature = JSON.stringify(this.closure(scenario.module).map(uri => [uri, this.records.get(uri)]));
|
|
146
|
+
// A successful global graph revision may only affect another scenario.
|
|
147
|
+
// Retain this view's form/scroll state, then let the caller rerun its audits.
|
|
148
|
+
if (this.mounted?.id === id && this.mounted.container === container && this.mounted.signature === signature) return true;
|
|
118
149
|
const module = await this.importModule(scenario.module);
|
|
119
150
|
if (generation !== this.generation) return false;
|
|
120
|
-
|
|
151
|
+
const unmount = this.unmount;
|
|
152
|
+
this.unmount = undefined;
|
|
153
|
+
this.mounted = undefined;
|
|
154
|
+
await unmount?.();
|
|
121
155
|
if (generation !== this.generation || this.closed) return false;
|
|
122
156
|
container.replaceChildren();
|
|
123
157
|
const keep = new Set(this.closure(scenario.module));
|
|
@@ -126,13 +160,16 @@ export class PreviewResourceLoader {
|
|
|
126
160
|
if (typeof module.mount !== "function") throw new Error("The compiled scenario has no mount adapter.");
|
|
127
161
|
this.unmount = module.mount(container);
|
|
128
162
|
if (typeof this.unmount !== "function") throw new Error("The scenario mount adapter must return an unmount callback.");
|
|
163
|
+
this.mounted = { id, container, signature };
|
|
129
164
|
return true;
|
|
130
165
|
}
|
|
131
166
|
async dispose() {
|
|
132
167
|
if (this.closed) return;
|
|
133
168
|
this.closed = true;
|
|
134
169
|
++this.generation;
|
|
170
|
+
++this.prefetchGeneration;
|
|
135
171
|
await this.unmount?.();
|
|
172
|
+
this.mounted = undefined;
|
|
136
173
|
for (const style of this.styles.values()) style.remove();
|
|
137
174
|
for (const url of this.urls.values()) URL.revokeObjectURL(url);
|
|
138
175
|
this.styles.clear(); this.styleReady.clear(); this.urls.clear(); this.bytes.clear(); this.records.clear();
|
package/dist/mcp/server.mjs
CHANGED
|
@@ -4,18 +4,20 @@ import { Server, ProtocolError, INVALID_PARAMS, ResourceNotFoundError } from "@m
|
|
|
4
4
|
import { serveStdio, StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { checkProject } from "../check.mjs";
|
|
7
|
+
import { createValidationController } from "../validation.mjs";
|
|
7
8
|
import { loadConfig, sourceFiles } from "../config.mjs";
|
|
8
9
|
import { createVerificationController, BEHAVIOR_URI } from "../verification.mjs";
|
|
9
10
|
import { INVESTIGATIONS_URI, investigationIndex, investigationPage, investigationSections, readInvestigation, readInvestigationResource } from "../investigations.mjs";
|
|
10
11
|
import { failure } from "../evidence.mjs";
|
|
11
12
|
import { inspectTokens } from "../tokens.mjs";
|
|
12
13
|
import { inspectScenarios } from "../scenarios.mjs";
|
|
14
|
+
import { scenarioGroupFingerprint } from "../scenario-groups.mjs";
|
|
13
15
|
import { startShowcaseHost } from "./showcase-host.mjs";
|
|
14
16
|
import { createSkillStore, page, SKILLS_EXTENSION } from "./skills.mjs";
|
|
15
17
|
import { inspectCatalog, projectDocuments, PROJECT_URI, readProjectDocument } from "./catalog.mjs";
|
|
16
18
|
import { APP_MIME, appMetadata, appUri, projectApp, TOKENS_APP_URI, tokensApp, tokenWidgetData, SCENARIO_APP_URI, scenarioApp, previewApp, PREVIEW_APP_URI } from "./apps.mjs";
|
|
17
|
-
import { PREVIEW_MANIFEST_URI, readPreviewManifest, readPreviewAsset } from "../preview-resources.mjs";
|
|
18
|
-
import { previewArtifactPath, withPreviewSession } from "../preview-scope.mjs";
|
|
19
|
+
import { LIVE_PREVIEW_MANIFEST_URI, PREVIEW_MANIFEST_URI, readPreviewManifest, readPreviewAsset } from "../preview-resources.mjs";
|
|
20
|
+
import { livePreviewOptions, previewArtifactPath, withPreviewSession } from "../preview-scope.mjs";
|
|
19
21
|
import { getWorkflowPrompt, promptDefinitions } from "./prompts.mjs";
|
|
20
22
|
import { createReconfigurablePreviewWatch } from "./preview-watch.mjs";
|
|
21
23
|
import { BUILD_URI, buildFailure, inspectBuildStatus, summarizeBuild } from "./build-status.mjs";
|
|
@@ -65,6 +67,7 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
65
67
|
const captures = cache.captures ??= createCaptureController(root);
|
|
66
68
|
const edits = cache.edits ??= createMutationController(root, { captures });
|
|
67
69
|
const verification = cache.verification ??= createVerificationController(root);
|
|
70
|
+
const validation = cache.validation ??= createValidationController(root);
|
|
68
71
|
const executionResults = cache.executionResults ??= createExecutionResults(root);
|
|
69
72
|
const reports = cache.reports ??= createReportStore(root, { context: reportContext, resolveEvidence: reportEvidence });
|
|
70
73
|
let options = loadConfig(root);
|
|
@@ -89,32 +92,34 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
89
92
|
capabilities: { tools: { listChanged: true }, resources: { listChanged: true, subscribe: true }, prompts: {},
|
|
90
93
|
extensions: { "io.modelcontextprotocol/ui": { mimeTypes: [APP_MIME] }, ...(era === "modern" ? { [SKILLS_EXTENSION]: { directoryRead: true } } : {}) } },
|
|
91
94
|
});
|
|
92
|
-
const getRegistry = () => cache.registry ??= inspectScenarios(options);
|
|
95
|
+
const getRegistry = () => { cache.registry ??= inspectScenarios(options); cache.lastRegistry = cache.registry; return cache.registry; };
|
|
96
|
+
const previewRegistry = waitFor => waitFor === "compiled" ? cache.registry ?? cache.lastRegistry ?? getRegistry() : getRegistry();
|
|
93
97
|
function captureInventory() {
|
|
94
98
|
const current = loadConfig(root), registry = inspectScenarios(current);
|
|
95
99
|
return { ...registry, revision: previewSourceRevision(current) };
|
|
96
100
|
}
|
|
97
101
|
function captureIndex() { const inventory = captureInventory(); return captures.store.list(inventory.scenarios, inventory.revision, { prune: !inventory.diagnostics.length }); }
|
|
98
|
-
const scenarioApps = () => getRegistry().scenarios.map(item => ({ id: item.id, title: item.title, kind: item.kind, ...(item.samples ? { samples: item.samples } : {}), file: item.artifact }));
|
|
102
|
+
const scenarioApps = (quick = false) => (quick ? cache.registry ?? cache.lastRegistry ?? getRegistry() : getRegistry()).scenarios.map(item => ({ id: item.id, title: item.title, kind: item.kind, ...(item.samples ? { samples: item.samples } : {}), file: item.artifact }));
|
|
99
103
|
const tokenScenarios = () => getRegistry().scenarios.filter(item => item.kind === "tokens").map(item => ({ id: item.id, title: item.title, count: item.tokens.length }));
|
|
100
|
-
const allApps = () => [...options.config.mcp.apps, ...scenarioApps()];
|
|
104
|
+
const allApps = (quick = false) => [...options.config.mcp.apps, ...scenarioApps(quick)];
|
|
101
105
|
const scenarioWidget = () => options.config.mcp.previewManifest ? PREVIEW_APP_URI : SCENARIO_APP_URI;
|
|
102
106
|
const previewOptions = () => withPreviewSession(options, previewWatch?.resourceSession?.());
|
|
103
107
|
const resourceAssets = () => {
|
|
104
108
|
try { return Object.entries(readPreviewManifest(previewOptions())?.assets ?? {}).map(([uri, record]) => ({ uri, name: `Preview asset ${uri.slice("ads://assets/".length)}`, mimeType: record.mimeType, size: record.size })); }
|
|
105
109
|
catch { return []; } // Discovery and diagnostics remain usable after a failed graph.
|
|
106
110
|
};
|
|
107
|
-
function graphSelection(id) {
|
|
111
|
+
function graphSelection(id, build) {
|
|
108
112
|
if (!options.config.mcp.previewManifest) return {};
|
|
109
|
-
const
|
|
113
|
+
const live = build?.live && !build.current;
|
|
114
|
+
const manifest = readPreviewManifest(live ? livePreviewOptions(previewOptions()) : previewOptions());
|
|
110
115
|
if (!manifest?.scenarios.some(entry => entry.id === id)) throw new Error("The preview resource graph is not ready for this scenario. Rebuild previews.");
|
|
111
|
-
return { manifestUri: PREVIEW_MANIFEST_URI, manifestRevision: manifest.revision };
|
|
116
|
+
return { manifestUri: live ? LIVE_PREVIEW_MANIFEST_URI : PREVIEW_MANIFEST_URI, manifestRevision: manifest.revision };
|
|
112
117
|
}
|
|
113
118
|
const getCatalog = () => cache.catalog ??= inspectCatalog(options, getRegistry().scenarios);
|
|
114
119
|
const getDocuments = () => cache.documents ??= projectDocuments(options);
|
|
115
120
|
const builds = () => {
|
|
116
|
-
previewWatch?.setApps(allApps());
|
|
117
|
-
return previewWatch?.buildStatus() ?? inspectBuildStatus(root, { ...options.config.mcp, apps: allApps() });
|
|
121
|
+
previewWatch?.setApps(allApps(true));
|
|
122
|
+
return previewWatch?.buildStatus() ?? inspectBuildStatus(root, { ...options.config.mcp, apps: allApps(true) });
|
|
118
123
|
};
|
|
119
124
|
const previews = () => options.config.mcp.apps.map((app) => ({ id: app.id, title: app.title, kind: app.kind, tool: `ads_show_${app.id.replaceAll("-", "_")}`, resourceUri: appUri(app.id), available: existsSync(path.resolve(root, app.file)), file: app.file }));
|
|
120
125
|
|
|
@@ -151,6 +156,7 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
151
156
|
return [
|
|
152
157
|
{ uri: GUIDE_URI, name: "Start here: design-system workflow", description: "Read first for UI/ADS tasks, especially when only resource access is exposed. Explains the exact workspace, tool sequence, skill selection, previews, project commands and fallback.", mimeType: "text/markdown" },
|
|
153
158
|
{ uri: "ads://guides/behaviors", name: "Controller and behavioral verification guide", mimeType: "text/markdown" },
|
|
159
|
+
{ uri: "ads://guides/validation", name: "Full and affected validation; test boundaries", mimeType: "text/markdown" },
|
|
154
160
|
{ uri: "ads://guides/runtimes", name: "Node and Bun setup, compiler and verification runtime", mimeType: "text/markdown" },
|
|
155
161
|
{ uri: "ads://guides/evidence", name: "Failure boundaries and compact investigations", mimeType: "text/markdown" },
|
|
156
162
|
{ uri: "ads://guides/atomic-styles", name: "Atomic styles: composition conflicts and custom-property extraction", mimeType: "text/markdown" },
|
|
@@ -176,7 +182,7 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
176
182
|
{ uri: "ads://guides/reporting", name: "Report suspected ADS bugs and feature requests", mimeType: "text/markdown" },
|
|
177
183
|
{ uri: TOKENS_APP_URI, name: "Experimental token widget", mimeType: APP_MIME },
|
|
178
184
|
{ uri: SCENARIO_APP_URI, name: "Experimental scenario widget", mimeType: APP_MIME },
|
|
179
|
-
...(options.config.mcp.previewManifest ? [{ uri: PREVIEW_APP_URI, name: "Shared-resource preview App", mimeType: APP_MIME }, { uri: PREVIEW_MANIFEST_URI, name: "
|
|
185
|
+
...(options.config.mcp.previewManifest ? [{ uri: PREVIEW_APP_URI, name: "Shared-resource preview App", mimeType: APP_MIME }, { uri: PREVIEW_MANIFEST_URI, name: "Verified preview dependency graph", mimeType: "application/json" }, { uri: LIVE_PREVIEW_MANIFEST_URI, name: "Unverified live feedback; background checks pending", mimeType: "application/json" }] : []),
|
|
180
186
|
...(options.config.mcp.previewManifest ? resourceAssets() : []),
|
|
181
187
|
...allApps().map((app) => ({ uri: appUri(app.id), name: app.title, description: app.description, mimeType: APP_MIME })),
|
|
182
188
|
...documents.filter((document) => !promoted.has(document.uri)).map(({ file: _file, ...document }) => document),
|
|
@@ -195,6 +201,7 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
195
201
|
build: summarizeBuild(builds()),
|
|
196
202
|
previews: previews(), skills: skills.skills.map(({ uri, frontmatter }) => ({ uri, name: frontmatter.name, description: frontmatter.description })),
|
|
197
203
|
scenarios: { count: getRegistry().scenarios.length, diagnostics: getRegistry().diagnostics, resourceUri: `${PROJECT_URI}/scenarios`, tool: "ads_show_scenario" },
|
|
204
|
+
validation: { ...validation.status(), tool: "ads_validate", lastResult: executionResults.latest("validation") },
|
|
198
205
|
behaviors: { resourceUri: BEHAVIOR_URI, discoveryTool: "ads_behaviors", verificationTool: "ads_verify", investigationTool: "ads_investigate", investigationResourceUri: INVESTIGATIONS_URI, ...behaviorState, progress: compactProgress(behaviorState.progress), lastResult: executionResults.latest("verification"), resultsTool: "ads_results", resultsResourceUri: RESULTS_URI },
|
|
199
206
|
captures: { resourceUri: CAPTURES_URI, tool: "ads_capture", clearTool: "ads_capture_clear", ...captures.status() },
|
|
200
207
|
reports: { access:"submission-only", storageDirectory:".ds/reports", bugTool:"ads_report_bug", featureTool:"ads_request_feature", guidanceUri:"ads://guides/reporting", delivery:"local-only", retention:"until-explicit-removal" },
|
|
@@ -203,6 +210,7 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
203
210
|
async function read(uri, signal) {
|
|
204
211
|
if (uri === GUIDE_URI) return { contents: [{ uri, mimeType: "text/markdown", text: projectGuide(project(), [...previews(), ...scenarioApps()]) }] };
|
|
205
212
|
if (uri === "ads://guides/behaviors") return { contents: [{ uri, mimeType: "text/markdown", text: readFileSync(new URL("../skills/ads-designer/references/behaviors.md", import.meta.url), "utf8") }] };
|
|
213
|
+
if (uri === "ads://guides/validation") return { contents: [{ uri, mimeType: "text/markdown", text: readFileSync(new URL("../skills/ads-designer/references/validation.md", import.meta.url), "utf8") }] };
|
|
206
214
|
if (uri === "ads://guides/runtimes") return { contents: [{ uri, mimeType: "text/markdown", text: readFileSync(new URL("../skills/ads-designer/references/runtimes.md", import.meta.url), "utf8") }] };
|
|
207
215
|
if (uri === "ads://guides/evidence") return { contents: [{ uri, mimeType: "text/markdown", text: readFileSync(new URL("../skills/ads-designer/references/evidence.md", import.meta.url), "utf8") }] };
|
|
208
216
|
if (uri === "ads://guides/tokens") return { contents: [{ uri, mimeType: "text/markdown", text: readFileSync(new URL("../skills/ads-designer/references/design-data.md", import.meta.url), "utf8") }] };
|
|
@@ -229,6 +237,11 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
229
237
|
value = readPreviewManifest(previewOptions());
|
|
230
238
|
if (!value) throw new Error("Preview resources are not built yet. Invoke ads_show_scenario to start the managed compiler.");
|
|
231
239
|
}
|
|
240
|
+
else if (uri === LIVE_PREVIEW_MANIFEST_URI && options.config.mcp.previewManifest) {
|
|
241
|
+
const report = builds(), live = report.previews.find(entry => entry.live)?.live;
|
|
242
|
+
value = readPreviewManifest(livePreviewOptions(previewOptions()));
|
|
243
|
+
if (!live || value?.revision !== live.revision || value.session !== report.session) throw new Error("No live feedback for the current source. Use the verified preview after checks pass.");
|
|
244
|
+
}
|
|
232
245
|
if (value !== undefined) return { contents: [{ uri, mimeType: "application/json", text: JSON.stringify(value) }] };
|
|
233
246
|
if (uri.startsWith("ads://investigations/") || uri.startsWith("ads://verification-artifacts/")) {
|
|
234
247
|
try { return {contents:[readInvestigationResource(root,uri)]}; }
|
|
@@ -243,7 +256,11 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
243
256
|
if (uri === PREVIEW_APP_URI && options.config.mcp.previewManifest) return { contents: [{ uri, mimeType: APP_MIME, text: previewApp(), _meta: appMetadata() }] };
|
|
244
257
|
if (uri.startsWith("ads://assets/") && options.config.mcp.previewManifest) {
|
|
245
258
|
try { return { contents: [readPreviewAsset(previewOptions(), uri)] }; }
|
|
246
|
-
catch (error) {
|
|
259
|
+
catch (error) {
|
|
260
|
+
if (error.code !== "ADS_PREVIEW_NOT_FOUND") throw error;
|
|
261
|
+
try { return { contents: [readPreviewAsset(livePreviewOptions(previewOptions()), uri)] }; }
|
|
262
|
+
catch (error) { if (error.code === "ADS_PREVIEW_NOT_FOUND") throw new ResourceNotFoundError(uri, error.message); throw error; }
|
|
263
|
+
}
|
|
247
264
|
}
|
|
248
265
|
const app = allApps().find((entry) => appUri(entry.id) === uri);
|
|
249
266
|
if (app) {
|
|
@@ -256,10 +273,14 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
256
273
|
if (document) return { contents: [{ uri, mimeType: document.mimeType, text: readProjectDocument(document) }] };
|
|
257
274
|
throw new ResourceNotFoundError(uri, `Unknown ADS resource: ${uri}`);
|
|
258
275
|
}
|
|
259
|
-
async function previewBuild(app, signal) {
|
|
260
|
-
previewWatch?.setApps(allApps());
|
|
261
|
-
if (previewWatch) return previewWatch.ensure(path.resolve(root, app.file), signal);
|
|
276
|
+
async function previewBuild(app, signal, waitFor = "verified") {
|
|
277
|
+
previewWatch?.setApps(allApps(waitFor === "compiled"));
|
|
278
|
+
if (previewWatch) return previewWatch.ensure(path.resolve(root, app.file), signal, { waitFor });
|
|
262
279
|
const build = builds().previews.find((entry) => entry.id === app.id);
|
|
280
|
+
if (waitFor === "compiled" && options.config.mcp.previewManifest) {
|
|
281
|
+
try { graphSelection(app.id, build); return build; }
|
|
282
|
+
catch { /* No usable graph yet: keep the normal diagnostics/wait path. */ }
|
|
283
|
+
}
|
|
263
284
|
if (build?.state === "error") throw buildFailure(build);
|
|
264
285
|
if (["building", "idle"].includes(build?.state)) throw Object.assign(new Error("Preview build is still pending. Invoke the preview again after rebuilding."), { build: { ...build, resourceUri: BUILD_URI } });
|
|
265
286
|
return build;
|
|
@@ -271,6 +292,7 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
271
292
|
return { ...json(summary), ...(!result.ok ? { isError: true } : {}) };
|
|
272
293
|
}
|
|
273
294
|
async function applyEdits(args,signal,progress) {
|
|
295
|
+
if (validation.status().busy) throw new Error("Wait for the active validation run before editing source.");
|
|
274
296
|
const result = await edits.apply(args,signal,progress);
|
|
275
297
|
if (result.screenshots) await refresh();
|
|
276
298
|
if (result.applied) {
|
|
@@ -278,6 +300,8 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
278
300
|
if (result.changes.some(change => change.path === "ds.config.json") || result.unit === "configuration" || result.units?.includes("configuration")) await previewWatch?.reconfigure?.(loadConfig(root).config.mcp,true);
|
|
279
301
|
await previewWatch?.invalidate?.();
|
|
280
302
|
await refresh(true);
|
|
303
|
+
previewWatch?.setApps(allApps());
|
|
304
|
+
if ((result.units??[result.unit]).some(unit=>unit!=="documentation")) await previewWatch?.warm?.((options.config.mcp.previewManifest?scenarioApps():allApps()).map(app=>path.resolve(root,app.file)));
|
|
281
305
|
} catch (error) {result.warnings=[...(result.warnings ?? []),{rule:"mutation-notification",message:`Changes were applied, but preview refresh failed: ${error.message.slice(0,2000)}. Recheck ads_status and reopen the scenario.`}];}
|
|
282
306
|
}
|
|
283
307
|
return finishExecution("mutation", { ...(args.patches ? {units:args.patches.map(item=>item.unit),transaction:true} : {unit:args.unit}), ...result });
|
|
@@ -294,18 +318,19 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
294
318
|
const units = edits.units();
|
|
295
319
|
return json({ total: matches.length, items: matches.slice(0, limit).map(item => ({ ...item, unit: units.find(unit => unit.files.includes(item.file))?.id ?? null })), resourceUri: `${PROJECT_URI}/catalog` });
|
|
296
320
|
} },
|
|
297
|
-
{ name: "ads_scenarios", description: "Find an independently mountable token, component, pattern or composition preview. IDs derive from source filenames; covers lists rendered public UI, exercises lists behavioral APIs and tokens lists the real token inputs. Use ads_show_scenario with an exact returned id. Showcase and MCP use this same registry.", schema: query.extend({ kind: z.enum(["tokens", "components", "patterns", "composition"]).optional(), offset: z.number().int().min(0).default(0) }), call: ({ query: search = "", limit, kind, offset }) => {
|
|
298
|
-
const matches = getRegistry().scenarios.filter(item => (!kind || item.kind === kind) && `${item.id} ${item.title} ${item.covers.join(" ")} ${(item.exercises ?? []).join(" ")} ${item.tokens.join(" ")}`.toLowerCase().includes(search.toLowerCase()));
|
|
321
|
+
{ name: "ads_scenarios", description: "Find an independently mountable token, component, pattern or composition preview. IDs derive from source filenames. Optional group labels are derived from folder names and searchable; group is discovery output, never scenario metadata. covers lists rendered public UI, exercises lists behavioral APIs and tokens lists the real token inputs. Use ads_show_scenario with an exact returned id. Showcase and MCP use this same registry.", schema: query.extend({ kind: z.enum(["tokens", "components", "patterns", "composition"]).optional(), offset: z.number().int().min(0).default(0) }), call: ({ query: search = "", limit, kind, offset }) => {
|
|
322
|
+
const matches = getRegistry().scenarios.filter(item => (!kind || item.kind === kind) && `${item.id} ${item.title} ${item.group ?? ""} ${item.covers.join(" ")} ${(item.exercises ?? []).join(" ")} ${item.tokens.join(" ")}`.toLowerCase().includes(search.toLowerCase()));
|
|
299
323
|
const units = edits.units();
|
|
300
324
|
return json({ total: matches.length, scenarios: matches.slice(offset, offset + limit).map(item => ({ ...item, unit: units.find(unit => unit.files.includes(item.file))?.id ?? null })), ...(offset + limit < matches.length ? { nextOffset: offset + limit } : {}), diagnostics: getRegistry().diagnostics, resourceUri: `${PROJECT_URI}/scenarios` });
|
|
301
325
|
} },
|
|
302
|
-
{ name: "ads_show_scenario", title: "Scenario preview", description: "Render one real
|
|
303
|
-
const
|
|
326
|
+
{ name: "ads_show_scenario", title: "Scenario preview", description: "Render one real scenario with its fixtures. Discover its exact id first. Default waitFor: verified waits for successful current checks. Interactive browsers may request waitFor: compiled for unverified live feedback or a retained earlier view; inspect build.current and never use pending output as verification evidence. Requires MCP Apps and resource forwarding; fallback links to the same showcase scenario.", schema: z.object({ id: z.string().min(1).max(256), waitFor: z.enum(["verified", "compiled"]).default("verified") }).strict(), _meta: { ui: { resourceUri: scenarioWidget() } }, call: async ({ id, waitFor }, signal) => {
|
|
327
|
+
const registry = previewRegistry(waitFor);
|
|
328
|
+
const entry = registry.scenarios.find(item => item.id === id);
|
|
304
329
|
if (!entry) throw new Error("Unknown scenario id. Read ads_scenarios; IDs must match discovered source entries.");
|
|
305
|
-
if (
|
|
306
|
-
const app = scenarioApps().find(item => item.id === id);
|
|
307
|
-
const build = await previewBuild(app, signal);
|
|
308
|
-
const graph = graphSelection(id);
|
|
330
|
+
if (registry.diagnostics.length) throw new Error("Scenario registry has errors. Read ads://project/scenarios and fix its diagnostics.");
|
|
331
|
+
const app = scenarioApps(waitFor === "compiled").find(item => item.id === id);
|
|
332
|
+
const build = await previewBuild(app, signal, waitFor);
|
|
333
|
+
const graph = graphSelection(id, build);
|
|
309
334
|
if (!options.config.mcp.previewManifest) projectApp(options, app, build);
|
|
310
335
|
return json({ widget: { resourceUri: scenarioWidget() }, scenario: { ...entry, resourceUri: appUri(id) }, ...graph, build, showcaseUrl: scenarioUrl(id) });
|
|
311
336
|
} },
|
|
@@ -329,27 +354,33 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
329
354
|
if (!("text" in content)) return json({ ...manifest, mimeType: content.mimeType, binary: true, note: "Read binary bytes via resources/read; this tool does not embed them." });
|
|
330
355
|
return json({ ...manifest, text: content.text.slice(offset, offset + limit), offset, ...(offset + limit < content.text.length ? { nextOffset: offset + limit } : {}) });
|
|
331
356
|
} },
|
|
332
|
-
{ name: "ads_show_tokens", title: "Token previews", description: "Render
|
|
333
|
-
|
|
357
|
+
{ name: "ads_show_tokens", title: "Token previews", description: "Render a discovered token scenario with project-owned templates and fixtures. Pass its id as category, or omit for the first token scenario. Default waitFor: verified requires current checks. Interactive browsers may use waitFor: compiled for explicitly unverified feedback or a retained view. Older compilers provide a generic definition inspector.", schema: z.object({ category: z.string().max(256).optional(), waitFor: z.enum(["verified", "compiled"]).default("verified") }).strict(), _meta: { ui: { resourceUri: options.config.mcp.previewManifest ? PREVIEW_APP_URI : TOKENS_APP_URI } }, call: async ({ category, waitFor }, signal) => {
|
|
358
|
+
const registry = previewRegistry(waitFor);
|
|
359
|
+
if (!category && options.config.mcp.previewManifest) category = registry.scenarios.find(item => item.kind === "tokens")?.id;
|
|
334
360
|
if (!category && options.config.mcp.previewManifest) throw new Error("No token scenario is registered. Colocate a token scenario and fixture before opening the preview; ads_tokens still inspects definitions.");
|
|
335
361
|
if (category) {
|
|
336
|
-
const entry =
|
|
362
|
+
const entry = registry.scenarios.find(item => item.kind === "tokens" && item.id === category);
|
|
337
363
|
if (!entry) throw new Error("Unknown token scenario. Discover categories with ads_tokens or ads_scenarios(kind: tokens) first.");
|
|
338
|
-
if (
|
|
339
|
-
const app = scenarioApps().find(item => item.id === category);
|
|
340
|
-
const build = await previewBuild(app, signal);
|
|
341
|
-
const graph = graphSelection(category);
|
|
364
|
+
if (registry.diagnostics.length) throw new Error("Scenario registry has errors. Fix its diagnostics before reviewing.");
|
|
365
|
+
const app = scenarioApps(waitFor === "compiled").find(item => item.id === category);
|
|
366
|
+
const build = await previewBuild(app, signal, waitFor);
|
|
367
|
+
const graph = graphSelection(category, build);
|
|
342
368
|
if (!options.config.mcp.previewManifest) projectApp(options, app, build);
|
|
343
369
|
return json({ widget: { resourceUri: options.config.mcp.previewManifest ? PREVIEW_APP_URI : TOKENS_APP_URI }, category, scenario: { ...entry, resourceUri: appUri(category) }, ...graph, build, showcaseUrl: scenarioUrl(category) });
|
|
344
370
|
}
|
|
345
371
|
return json({ widget: { resourceUri: TOKENS_APP_URI }, category: null, tokenCount: inspectTokens(root).tokens.length, dataUri: `${PROJECT_URI}/tokens`, showcaseUrl: getShowcaseUrl() });
|
|
346
372
|
} },
|
|
347
373
|
{ name: "ads_behaviors", description: "Discover behavior owners, then page an exact unit's checks, guarantees, subjects, demonstrations or profiles. Summary listings never embed runner logs. Default 10/max 20 entries and 8 KiB JSON per page; continue with nextCursor and identical filters. Cursors expire when discovery/evidence changes. Read sourceFile with ads_read_file for a complete contract. Metadata and reachable calls do not prove execution; use ads_verify for registered checks.", schema: z.object({ query: z.string().max(200).optional(), unit: z.string().min(1).max(256).optional(), api: z.string().max(200).optional(), section: z.enum(behaviorSections).optional(), ...paged }).strict(), call: args => json(behaviorPage(options,args)) },
|
|
348
|
-
{ name: "ads_results", title: "Read execution outcomes", description: "Read saved ads_verify/ads_apply_patch/ads_apply_transaction outcomes without rerunning anything. Pass the returned resultId; select outcomes, checks, diagnostics, advisories, warnings, changes, captures, acceptance, investigation or selection. Default 10/max 20 rows, at most 8 KiB JSON per page. Follow nextCursor with identical section/status. Rows marked detailTruncated can be read in full using recordIndex and offset/chars (max 2000); follow nextOffset. Only the latest verification and mutation snapshots are retained; replaced IDs fail explicitly. For one outcome's browser evidence use ads_investigate with its exact unit/check/runId.", schema: z.object({ resultId: z.string().uuid(), section: z.enum(resultSections).optional(), status: z.enum(["all","passed","not_passed"]).optional(), ...paged, ...recordRange }).strict(), call: args => json(executionResults.page(args)) },
|
|
374
|
+
{ name: "ads_results", title: "Read execution outcomes", description: "Read saved ads_validate/ads_verify/ads_apply_patch/ads_apply_transaction outcomes without rerunning anything. Pass the returned resultId; select outcomes, checks, diagnostics, advisories, warnings, changes, captures, acceptance, investigation or selection. Default 10/max 20 rows, at most 8 KiB JSON per page. Follow nextCursor with identical section/status. Rows marked detailTruncated can be read in full using recordIndex and offset/chars (max 2000); follow nextOffset. Only the latest validation, verification and mutation snapshots are retained; replaced IDs fail explicitly. For one outcome's browser evidence use ads_investigate with its exact unit/check/runId.", schema: z.object({ resultId: z.string().uuid(), section: z.enum(resultSections).optional(), status: z.enum(["all","passed","not_passed"]).optional(), ...paged, ...recordRange }).strict(), call: args => json(executionResults.page(args)) },
|
|
349
375
|
{ name:"ads_report_bug",title:"Report a suspected ADS defect",description:"Record an unexpected ADS guard, preview, build, transport or runner behavior after targeted investigation. Provide expected/observed behavior, minimal steps and frequency; keep suspectedCause separate. Evidence optionally selects a returned resultId or exact unit/check/runId. ADS snapshots compact evidence, version, configured framework and revisions. A report is an untriaged agent claim, not proof of an ADS cause. Returns a small receipt with the report ID and local file path; submitted reports cannot be read through MCP. Stored locally under .ds/reports/ with deduplication, no automatic expiry and no upload. Read ads://guides/reporting; ordinary valid guard rejections should be fixed in their owner.",schema:bugReportSchema,annotations:{readOnlyHint:false,destructiveHint:false,idempotentHint:false,openWorldHint:false},call:args=>submitReport("bug",args) },
|
|
350
376
|
{ name:"ads_request_feature",title:"Request an ADS capability",description:"Record a legitimate workflow that needs a missing ADS capability. Provide workflow, capability and impact; proposal is optional. Preserve valid design/API rather than weakening guards or inventing workaround props. Optional evidence references an existing execution/check, not pasted files/logs. ADS attaches compact context and returns a receipt with the report ID and local file path. Intake is submission-only; no report-reading tools or resources. Shared local report store: deduplicated, untriaged, no automatic expiry or upload. Read ads://guides/reporting; use ads_report_bug for suspected broken existing behavior.",schema:featureRequestSchema,annotations:{readOnlyHint:false,destructiveHint:false,idempotentHint:false,openWorldHint:false},call:args=>submitReport("feature",args) },
|
|
351
377
|
{ name: "ads_investigate", title: "Inspect check evidence", description: "Read a summary for an exact unit/check, or list latest investigations when no check is selected. Pass the outcome's runId to reject superseded evidence. Summary is at most 4 KiB JSON; details, requests, browserErrors and artifacts are separate paged sections (default 10/max 20 entries, 8 KiB). Read truncated rows with recordIndex/offset/chars and the exact runId. Artifact URIs are read separately. Does not rerun checks or infer root cause. Only the latest bundle per check is retained, including candidate runs.", schema: z.object({unit:z.string().min(1).max(256).optional(),check:z.string().min(1).max(100).optional(),runId:z.string().min(1).max(100).optional(),section:z.enum(investigationSections).optional(),...paged,...recordRange}).strict(), call: args => json(investigationPage(root,args)) },
|
|
378
|
+
{ name: "ads_validate", description: "Run the shared ads validate audit. Default scope all: core architecture and test ownership, registered Oxlint, configured project scripts and all registered behavior checks. scope changed uses affected behavior checks since the last successful full audit; missing/incompatible baselines or broad changes expand to all and report why. Core and opaque project scripts retain their full scope. Use changed during editing, all after test/ownership/config migrations and before releases or explicit complete audits. Reports scope, source revision, skipped stages, progress and a bounded resultId; page diagnostics/checks/outcomes with ads_results. Changed inputs, cancellation and failed/skipped registered cases cannot pass. Read ads://guides/validation. Runs trusted configured commands; installs nothing.", schema: z.object({scope:z.enum(["all","changed"]).default("all")}).strict(), annotations: {readOnlyHint:false,destructiveHint:false,idempotentHint:false,openWorldHint:false}, call: async (args,signal,progress) => {
|
|
379
|
+
if (verification.status().running || edits.status().busy) throw new Error("Wait for the active verification or guarded edit before validating.");
|
|
380
|
+
return finishExecution("validation",await validation.run(args,signal,progress));
|
|
381
|
+
} },
|
|
352
382
|
{ name: "ads_verify", description: "Run one owner's registered development behavior checks using its configured runner/profile. Executes trusted project commands with bounded output, cancellation and process-tree cleanup; installs nothing. Progress and per-check timings are available through ads_status; a profile timeout bounds the whole run. Browser profiles use an isolated managed showcase/MCP App. React StrictMode requires a project development harness, not a production widget. Missing/skipped cases, stale inputs and process exit alone cannot produce passing evidence. Replies contain counts, acceptance, at most three failure summaries and a resultId (4 KiB JSON maximum). Page outcomes with ads_results; inspect one exact unit/check/runId with ads_investigate. Discover exact unit/check IDs with ads_behaviors first.", schema: z.object({ unit: z.string().min(1).max(256), checks: z.array(z.string().min(1).max(100)).min(1).max(100).optional() }).strict(), annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }, call: async (args, signal, progress) => {
|
|
383
|
+
if (validation.status().busy) throw new Error("Wait for the active validation run before verifying separately.");
|
|
353
384
|
const result = await verification.run(args, signal, progress);
|
|
354
385
|
return finishExecution("verification", {unit:args.unit,...result});
|
|
355
386
|
} },
|
|
@@ -447,8 +478,11 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
447
478
|
try { const stat = statSync(file); return `${file}:${stat.mtimeMs}:${stat.size}`; } catch { return `${file}:missing`; }
|
|
448
479
|
}).join("\n");
|
|
449
480
|
}
|
|
450
|
-
const fingerprint = () =>
|
|
451
|
-
|
|
481
|
+
const fingerprint = () => {
|
|
482
|
+
const sources = sourceFiles(options.dsRoot);
|
|
483
|
+
return `${fileFingerprint([...sources, ...getDocuments().map(doc => doc.file), path.join(root, "ds.config.json"), path.join(root, "package.json"), path.join(root, ".ds/behavior-results.json")])}\n${scenarioGroupFingerprint(options, sources)}`;
|
|
484
|
+
};
|
|
485
|
+
const artifactFingerprint = () => fileFingerprint(allApps(true).map(app => path.resolve(root, previewArtifactPath(previewOptions(), app.file))));
|
|
452
486
|
const assetFingerprint = () => resourceAssets().map(asset => asset.uri).sort().join("\n");
|
|
453
487
|
let previous = fingerprint();
|
|
454
488
|
let previousArtifacts = artifactFingerprint();
|
|
@@ -459,6 +493,7 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
459
493
|
const investigationFingerprint=()=>fileFingerprint([path.join(root,".ds/investigations.json")]);
|
|
460
494
|
let previousInvestigations=investigationFingerprint();
|
|
461
495
|
let previousResults=executionResults.fingerprint();
|
|
496
|
+
let deferredDiscovery = false;
|
|
462
497
|
async function refresh(force = false) {
|
|
463
498
|
// Polling covers replaced files and new directories consistently across OSes.
|
|
464
499
|
cache.documents = undefined;
|
|
@@ -473,7 +508,7 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
473
508
|
const capturesChanged = captures.store.fingerprint() !== previousCaptures;
|
|
474
509
|
const investigationsChanged=investigationFingerprint()!==previousInvestigations;
|
|
475
510
|
const resultsChanged=executionResults.fingerprint()!==previousResults;
|
|
476
|
-
if (!filesChanged && !buildChanged && !artifactsChanged && !assetsChanged && !capturesChanged && !investigationsChanged && !resultsChanged) return false;
|
|
511
|
+
if (!filesChanged && !buildChanged && !artifactsChanged && !assetsChanged && !capturesChanged && !investigationsChanged && !resultsChanged && !deferredDiscovery) return false;
|
|
477
512
|
if (filesChanged) {
|
|
478
513
|
const updated = loadConfig(root);
|
|
479
514
|
await previewWatch?.reconfigure?.(updated.config.mcp);
|
|
@@ -485,15 +520,21 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
485
520
|
previous = fingerprint();
|
|
486
521
|
if (appsChanged) { if (notifications) notifications.toolsChanged(); else await server.sendToolListChanged(); }
|
|
487
522
|
}
|
|
488
|
-
|
|
523
|
+
const checking = options.config.mcp.previewManifest && previewWatch?.status().state === "running"
|
|
524
|
+
&& builds().previews.some(entry => ["idle", "building"].includes(entry.state)
|
|
525
|
+
|| entry.diagnostics.some(item => item.code === "ADS_PREVIEW_STALE_SOURCE"));
|
|
526
|
+
deferredDiscovery ||= filesChanged;
|
|
527
|
+
const discoveryChanged = deferredDiscovery && !checking;
|
|
528
|
+
if (discoveryChanged) deferredDiscovery = false;
|
|
529
|
+
if (discoveryChanged || assetsChanged) { if (notifications) notifications.resourcesChanged(); else await server.sendResourceListChanged(); }
|
|
489
530
|
previousArtifacts = artifactFingerprint();
|
|
490
531
|
previousAssets = assetFingerprint();
|
|
491
532
|
previousBuild = JSON.stringify(builds());
|
|
492
|
-
const targets =
|
|
493
|
-
: [BUILD_URI, BEHAVIOR_URI, INVESTIGATIONS_URI, `${PROJECT_URI}/status`, ...(options.config.mcp.previewManifest ? [PREVIEW_MANIFEST_URI] : []), ...(artifactsChanged ? allApps().map(app => appUri(app.id)) : [])].filter((uri) => era === "modern" || subscribed.has(uri));
|
|
533
|
+
const targets = discoveryChanged ? era === "modern" ? resources().map((entry) => entry.uri).filter((uri) => !skills.files.has(uri)) : [...subscribed]
|
|
534
|
+
: [BUILD_URI, BEHAVIOR_URI, INVESTIGATIONS_URI, `${PROJECT_URI}/status`, ...(filesChanged ? [`${PROJECT_URI}/tokens`] : []), ...(options.config.mcp.previewManifest ? [PREVIEW_MANIFEST_URI, LIVE_PREVIEW_MANIFEST_URI] : []), ...(artifactsChanged ? allApps(true).map(app => appUri(app.id)) : [])].filter((uri) => era === "modern" || subscribed.has(uri));
|
|
494
535
|
if(resultsChanged){targets.push(...[RESULTS_URI,...executionResults.index().results.map(entry=>entry.resourceUri),...[...subscribed].filter(uri=>uri.startsWith("ads://results/"))].filter(uri=>era==="modern"||subscribed.has(uri)));previousResults=executionResults.fingerprint();}
|
|
495
536
|
if(investigationsChanged){targets.push(...[INVESTIGATIONS_URI,...investigationIndex(root).entries.map(entry=>entry.resourceUri),...[...subscribed].filter(uri=>uri.startsWith("ads://investigations/"))].filter(uri=>era==="modern"||subscribed.has(uri)));previousInvestigations=investigationFingerprint();}
|
|
496
|
-
if (capturesChanged ||
|
|
537
|
+
if (capturesChanged || discoveryChanged) {
|
|
497
538
|
const current = (captures.store.fingerprint() ? captureIndex().captures : []).flatMap(record => [record.current?.resourceUri, record.candidate?.resourceUri].filter(Boolean));
|
|
498
539
|
targets.push(...[CAPTURES_URI, ...previousCaptureUris, ...current].filter(uri => era === "modern" || subscribed.has(uri)));
|
|
499
540
|
previousCaptureUris = current;
|
|
@@ -506,7 +547,7 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
506
547
|
timer?.unref();
|
|
507
548
|
server.oninitialized = () => previewWatch?.start();
|
|
508
549
|
server.onclose = () => { if (timer) clearInterval(timer); };
|
|
509
|
-
return { server, refresh, async close() { if (timer) clearInterval(timer); if (!inspection) { await verification.close(); await captures.close(); } await server.close(); } };
|
|
550
|
+
return { server, refresh, async close() { if (timer) clearInterval(timer); if (!inspection) { await validation.close(); await verification.close(); await captures.close(); } await server.close(); } };
|
|
510
551
|
}
|
|
511
552
|
|
|
512
553
|
export async function startAdsMcp(directory = process.cwd(), { stdio = true, showcase = true, port = 0, mutations = false } = {}) {
|
|
@@ -531,6 +572,7 @@ export async function startAdsMcp(directory = process.cwd(), { stdio = true, sho
|
|
|
531
572
|
const results = await Promise.allSettled([
|
|
532
573
|
Promise.resolve().then(() => host?.close()),
|
|
533
574
|
previewWatch.stop(),
|
|
575
|
+
Promise.resolve().then(() => inspection.validation?.close()),
|
|
534
576
|
Promise.resolve().then(() => inspection.verification?.close()),
|
|
535
577
|
Promise.resolve().then(() => inspection.captures?.close()),
|
|
536
578
|
Promise.resolve().then(() => handle?.close()),
|
package/dist/oxlint.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import { defaultConfig, importViolation } from "./config.mjs";
|
|
2
|
+
import { defaultConfig, importViolation, isTestFile } from "./config.mjs";
|
|
3
|
+
import { inspectUnits } from "./units.mjs";
|
|
3
4
|
import { appImportViolation, showcaseImportViolation, importResolver } from "./boundaries.mjs";
|
|
4
5
|
|
|
5
6
|
const schema = [{
|
|
@@ -59,6 +60,10 @@ export default {
|
|
|
59
60
|
const resolve = importResolver(settings);
|
|
60
61
|
const filename = path.resolve(context.getFilename());
|
|
61
62
|
const buildFiles = new Set((settings.config.configurationFiles ?? []).map(file => path.resolve(settings.root,file)));
|
|
63
|
+
if (isTestFile(filename)) {
|
|
64
|
+
const inventory = inspectUnits({...settings,sourceRoot:path.resolve(settings.root,settings.config.sourceDir)});
|
|
65
|
+
settings.testOwner = file => inventory.owner(inventory.relative(path.relative(settings.root,file)));
|
|
66
|
+
}
|
|
62
67
|
function inspect(node) {
|
|
63
68
|
if (typeof node.source?.value !== "string") return;
|
|
64
69
|
if (buildFiles.has(filename) && resolve(node.source.value,filename).every(file=>buildFiles.has(file))) return;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { previewSourceRevision } from "./preview-inputs.mjs";
|
|
5
|
+
import { createPreviewResources } from "./preview-resources.mjs";
|
|
6
|
+
import { createPreviewWorkerCache } from "./preview-workers.mjs";
|
|
7
|
+
|
|
8
|
+
/** Project-owned Vite plugins/configuration, with a persistent development graph.
|
|
9
|
+
* Watch output is private scratch data; only the compiler may publish it after
|
|
10
|
+
* the relevant source/generation checks; verified output also requires validation.
|
|
11
|
+
* Existing buildGraph adapters work
|
|
12
|
+
* unchanged; opt in by passing this function as buildGraph. */
|
|
13
|
+
export function createVitePreviewBuilder({ build, configure }) {
|
|
14
|
+
let graph;
|
|
15
|
+
async function close() {
|
|
16
|
+
const previous = graph;
|
|
17
|
+
graph = undefined;
|
|
18
|
+
if (!previous) return;
|
|
19
|
+
previous.closed = true;
|
|
20
|
+
previous.notify();
|
|
21
|
+
try { await previous.watcher?.close(); }
|
|
22
|
+
finally { rmSync(previous.directory, { recursive: true, force: true }); }
|
|
23
|
+
}
|
|
24
|
+
const builder = async (entries, options, track, { watched = false } = {}) => {
|
|
25
|
+
if (!watched) {
|
|
26
|
+
const config = await configure(entries, options);
|
|
27
|
+
const output = await build({ ...config, plugins: [...config.plugins ?? [], track], build: { ...config.build, write: false, watch: null } });
|
|
28
|
+
return createPreviewResources(output, options, entries);
|
|
29
|
+
}
|
|
30
|
+
// Metadata changes do not change virtual module identities. A changed entry
|
|
31
|
+
// list or project configuration does require a fresh configured graph.
|
|
32
|
+
const key = JSON.stringify([options.root, options.config, entries.map(entry => [entry.id, entry.file])]);
|
|
33
|
+
if (graph?.key !== key) {
|
|
34
|
+
await close();
|
|
35
|
+
const directory = path.join(options.root, ".ds/incremental", randomUUID());
|
|
36
|
+
mkdirSync(directory, { recursive: true });
|
|
37
|
+
const trigger = path.join(directory, "trigger");
|
|
38
|
+
writeFileSync(trigger, "0");
|
|
39
|
+
const listeners = new Set();
|
|
40
|
+
const current = { key, directory, closed: false, building: true, serial: 0,
|
|
41
|
+
notify() { for (const resolve of listeners) resolve(); listeners.clear(); },
|
|
42
|
+
wait(reconcile) { return new Promise(resolve => {
|
|
43
|
+
const done = () => { clearTimeout(timer); listeners.delete(done); resolve(); };
|
|
44
|
+
// Watch subscriptions can still be settling after END. Reconcile a
|
|
45
|
+
// missed scratch-file event rather than leave an idle request stuck.
|
|
46
|
+
const timer = reconcile ? setTimeout(done, 100) : undefined;
|
|
47
|
+
listeners.add(done);
|
|
48
|
+
}); },
|
|
49
|
+
};
|
|
50
|
+
graph = current;
|
|
51
|
+
let started;
|
|
52
|
+
let candidate;
|
|
53
|
+
const capture = { name: "ads-incremental-preview", enforce: "post",
|
|
54
|
+
buildStart() { started = previewSourceRevision(options); this.addWatchFile(trigger); },
|
|
55
|
+
writeBundle(_output, bundle) {
|
|
56
|
+
const inputs = [...this.getModuleIds(), ...this.getWatchFiles()].filter(id => !id.startsWith("\0"))
|
|
57
|
+
.map(id => path.isAbsolute(id) ? id : path.resolve(options.root, id));
|
|
58
|
+
candidate = { source: started, output: { output: Object.values(bundle) }, modules: [...new Set(inputs)]
|
|
59
|
+
.filter(file => !file.startsWith(directory + path.sep)) };
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
try {
|
|
63
|
+
const config = await configure(entries, options);
|
|
64
|
+
const output = config.build?.rollupOptions?.output;
|
|
65
|
+
if (Array.isArray(output) || output?.file) throw new Error("Incremental preview builds require one module output without output.file.");
|
|
66
|
+
const workers = createPreviewWorkerCache(options, () => started === previewSourceRevision(options));
|
|
67
|
+
current.watcher = await build({ ...config, plugins: [...config.plugins ?? [], workers, capture],
|
|
68
|
+
build: { ...config.build, minify: false, cssMinify: false, reportCompressedSize: false, write: true, outDir: path.join(directory, "output"), emptyOutDir: true,
|
|
69
|
+
rollupOptions: { ...config.build?.rollupOptions, output: { ...output, dir: path.join(directory, "output") } },
|
|
70
|
+
watch: { ...config.build?.watch, skipWrite: false,
|
|
71
|
+
// Bun's native fs-watch reattachment can miss rapid subsequent
|
|
72
|
+
// edits on Linux. Poll only this compiler's dependency watches.
|
|
73
|
+
chokidar: { ...(process.versions.bun ? { usePolling: true, interval: 100 } : {}), ...config.build?.watch?.chokidar },
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
if (current.closed) {
|
|
78
|
+
await current.watcher.close();
|
|
79
|
+
rmSync(directory, { recursive: true, force: true });
|
|
80
|
+
throw new Error("Preview builder was closed.");
|
|
81
|
+
}
|
|
82
|
+
current.watcher.on("event", event => {
|
|
83
|
+
if (event.code === "START") { current.building = true; current.error = undefined; candidate = undefined; }
|
|
84
|
+
if (event.code === "ERROR") {
|
|
85
|
+
current.error = { source: started, value: event.error }; current.building = false; current.notify();
|
|
86
|
+
}
|
|
87
|
+
if (event.code === "END") {
|
|
88
|
+
if (candidate) current.snapshot = candidate;
|
|
89
|
+
current.building = false; current.notify();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
} catch (error) { await close(); throw error; }
|
|
93
|
+
}
|
|
94
|
+
const current = graph;
|
|
95
|
+
const source = previewSourceRevision(options);
|
|
96
|
+
while (!current.closed) {
|
|
97
|
+
if (!current.building) {
|
|
98
|
+
if (previewSourceRevision(options) !== source) throw new Error("Sources changed during incremental compilation. Waiting for the current build.");
|
|
99
|
+
if (current.error?.source === source) throw current.error.value;
|
|
100
|
+
if (current.snapshot?.source === source) {
|
|
101
|
+
track.generateBundle.call({ getModuleIds: () => current.snapshot.modules });
|
|
102
|
+
return createPreviewResources(current.snapshot.output, options, entries);
|
|
103
|
+
}
|
|
104
|
+
// Metadata/policy/assets outside Rollup's module graph still require a
|
|
105
|
+
// current build. A watched scratch file requests it without touching UI.
|
|
106
|
+
writeFileSync(path.join(current.directory, "trigger"), String(++current.serial));
|
|
107
|
+
}
|
|
108
|
+
await current.wait(!current.building);
|
|
109
|
+
}
|
|
110
|
+
throw new Error("Preview builder was closed.");
|
|
111
|
+
};
|
|
112
|
+
builder.close = close;
|
|
113
|
+
return builder;
|
|
114
|
+
}
|
package/dist/preview-inputs.mjs
CHANGED
|
@@ -2,11 +2,14 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { previewFileIgnored } from "./preview-files.mjs";
|
|
5
|
+
import { isScenarioFile } from "./config.mjs";
|
|
6
|
+
import { scenarioGroupFingerprint } from "./scenario-groups.mjs";
|
|
5
7
|
|
|
6
8
|
/** Shared source evidence for compilation, watch recovery and status reads. */
|
|
7
9
|
export function previewSourceRevision(options, apps = options.config.mcp.apps ?? []) {
|
|
8
10
|
const {root} = options;
|
|
9
11
|
const rows = [];
|
|
12
|
+
const scenarios = [];
|
|
10
13
|
const outputs = new Set(apps.map(app => path.resolve(root,app.file)));
|
|
11
14
|
function digest(file) { return createHash("sha256").update(readFileSync(file)).digest("hex"); }
|
|
12
15
|
function visit(directory) {
|
|
@@ -15,10 +18,14 @@ export function previewSourceRevision(options, apps = options.config.mcp.apps ??
|
|
|
15
18
|
const file = path.join(directory,entry.name);
|
|
16
19
|
if (outputs.has(file) || previewFileIgnored(options,file)) continue;
|
|
17
20
|
if (entry.isDirectory()) visit(file);
|
|
18
|
-
else if (entry.isFile() && /\.(?:[cm]?[jt]sx?|css|html|json|md|svg|png|jpe?g|webp|gif|woff2?|ttf|otf|lock|lockb)$/.test(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
|
+
}
|
|
19
25
|
}
|
|
20
26
|
}
|
|
21
27
|
visit(root);
|
|
28
|
+
rows.push(["scenario-group-structure",scenarioGroupFingerprint(options,scenarios)]);
|
|
22
29
|
const installed = path.join(root,"node_modules/.package-lock.json");
|
|
23
30
|
rows.push(["installed-packages",existsSync(installed) ? digest(installed) : null]);
|
|
24
31
|
return createHash("sha256").update(JSON.stringify(rows.sort((a,b)=>a[0].localeCompare(b[0])))).digest("hex");
|