Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
perf: Improve MCP evaluation reliability and efficiency (#5959)
Oleg Isonen7bc99427740c
diff --git a/packages/cli/evaluations/high-impact/agent-runner.test.ts b/packages/cli/evaluations/high-impact/agent-runner.test.tsindex ac03b6fb2e..710f83336f 100644--- a/packages/cli/evaluations/high-impact/agent-runner.test.ts+++ b/packages/cli/evaluations/high-impact/agent-runner.test.ts@@ -4,6 +4,7 @@ import { join, resolve } from "node:path";import { describe, expect, test } from "vitest";import { authenticatedPageFixture } from "./fixtures";import { designInputFixture } from "./fixtures";+import { fontAssetsFixture } from "./fixtures";import {createMinimalAgentTask,getCliInvocation,@@ -23,15 +24,48 @@ describe("high-impact agent runner", () => {});expect(task).not.toHaveProperty("project");expect(task).toMatchObject({- constraints: [+ constraints: expect.arrayContaining([expect.any(String),- expect.stringContaining("meta.guide"),+ expect.stringContaining("exactly once at the beginning"),expect.any(String),expect.stringContaining("Never use broad project reads"),expect.any(String),expect.stringContaining("meta.next"),- ],+ expect.stringContaining("terminal static audit"),+ expect.stringContaining("Use one verify-page-responsive call"),+ expect.stringContaining("Do not call list-breakpoints"),+ ]),});+ const authConstraints = task.constraints.join("\n");+ expect(authConstraints).toContain("Do not call list-breakpoints");+ expect(authConstraints).toContain("do not call meta.get_more_tools");+ expect(authConstraints).toContain(+ "Create exactly one scoped non-secret fixture variable"+ );+ expect(authConstraints).toContain("Do not call list-variables again");+ expect(authConstraints).toContain("static audit");+ expect(authConstraints).toContain(+ "copy the objective field verbatim into brief"+ );+ expect(authConstraints).toContain("call inspect-auth-context exactly once");+ expect(authConstraints).not.toContain(+ "call get-project-settings, list-pages, list-resources, and list-variables"+ );+ expect(authConstraints).toContain(+ "call create-page exactly once, then create-variable"+ );+ expect(authConstraints).toContain(+ "Call insert-fragment-verified only after all three succeed"+ );+ expect(authConstraints).toContain(+ "Do not call insert-fragment or verify-bindings separately"+ );+ expect(authConstraints).toContain(+ "call verify-page-responsive exactly once"+ );+ expect(authConstraints).toContain(+ "Do not call preview.start, screenshot, screenshot.responsive, or audit separately"+ );expect(createMinimalAgentTask(designInputFixture, {kind: "source",@@ -42,7 +76,40 @@ describe("high-impact agent runner", () => {desktop: { viewport: { width: 1440, height: 900 } },mobile: { viewport: { width: 390, height: 844 } },},+ constraints: expect.arrayContaining([+ expect.stringContaining("exactly three attach-design-token calls"),+ expect.stringContaining("Omit the optional position field"),+ expect.stringContaining("exactly one batched update-styles call"),+ expect.stringContaining("returned mobile breakpoint id"),+ expect.stringContaining("Use this exact fragment verbatim"),+ expect.stringContaining('ws:tag="footer"'),+ expect.stringContaining("Do not call clone-instance"),+ expect.stringContaining("set-text-content"),+ expect.stringContaining("call inspect-design-context exactly once"),+ expect.stringContaining("Do not call list-pages, list-breakpoints"),+ expect.stringContaining("Attach all three tokens in one parallel"),+ expect.stringContaining("Do not call get-page-by-path"),+ expect.stringContaining("call insert-fragment-verified once"),+ expect.stringContaining("pagePath /summer"),+ expect.stringContaining("do not call list-instances"),+ expect.stringContaining("Do not call meta.index"),+ ]),});+ expect(+ createMinimalAgentTask(fontAssetsFixture, {+ kind: "source",+ repositoryRoot: root,+ }).constraints+ ).toEqual(+ expect.arrayContaining([+ expect.stringContaining("Do not call meta.index, meta.get_more_tools"),+ expect.stringContaining("Call meta.guide exactly once"),+ expect.stringContaining("exactly one upload-assets call"),+ expect.stringContaining("parallel tool-call batch"),+ expect.stringContaining("verify-font-assets exactly once"),+ expect.stringContaining("Do not call refresh or get-asset separately"),+ ])+ );});test("retains only a bounded privacy-safe result from a real process", async () => {@@ -72,8 +139,35 @@ describe("high-impact agent runner", () => {provider: "test-provider",model: "test-model",getToolCalls: () => [- { name: "meta.guide", startedAtMs: 100, durationMs: 25 },- { name: "audit", startedAtMs: 500, durationMs: 75 },+ {+ name: "meta.guide",+ startedAtMs: 100,+ durationMs: 25,+ responseBytes: 1_000,+ },+ {+ name: "attach-design-token",+ startedAtMs: 300,+ durationMs: 10,+ responseBytes: 500,+ isError: true,+ errorCode: "INVALID_INPUT",+ },+ {+ name: "audit",+ startedAtMs: 500,+ durationMs: 75,+ responseBytes: 750,+ },+ ],+ getCatalogObservations: () => [+ {+ kind: "tools-list",+ toolCount: 160,+ responseBytes: 100_000,+ inputSchemaBytes: 50_000,+ descriptionBytes: 10_000,+ },],evaluate: async () => ({passed: true,@@ -83,24 +177,41 @@ describe("high-impact agent runner", () => {});expect(result).toMatchObject({schemaVersion: 2,- outcome: "passed",+ outcome: "failed",cli: "packaged",metrics: {durationMs: expect.any(Number),tokens: {input: 1_000,cachedInput: 400,+ uncachedInput: 600,output: 200,total: 1_200,},+ mcpCatalog: {+ responses: 1,+ totalResponseBytes: 100_000,+ latestToolCount: 160,+ latestInputSchemaBytes: 50_000,+ },toolCalls: {- total: 2,- failed: 0,+ total: 3,+ failed: 1,+ failuresByTool: { "attach-design-token": 1 },+ responseBytesByTool: {+ "attach-design-token": {+ count: 1,+ totalBytes: 500,+ p95Bytes: 500,+ maxBytes: 500,+ },+ },+ totalResponseBytes: 2_250,verifications: 1,timeToFirstVerificationMs: 500,},},- callSequence: ["meta.guide", "audit"],+ callSequence: ["meta.guide", "attach-design-token", "audit"],checks: { usageCaptured: "passed" },});const source = await readFile(resultPath, "utf8");@@ -109,6 +220,10 @@ describe("high-impact agent runner", () => {expect(JSON.parse(await readFile(taskPath, "utf8"))).toMatchObject({fixtureId: "authenticated-page-v1",mcp: { args: ["mcp"] },+ constraints: expect.arrayContaining([+ expect.stringContaining("terminal static audit"),+ expect.stringContaining("Use one verify-page-responsive call"),+ ]),});} finally {await rm(directory, { recursive: true, force: true });diff --git a/packages/cli/evaluations/high-impact/agent-runner.ts b/packages/cli/evaluations/high-impact/agent-runner.tsindex db3f568107..929d681c5b 100644--- a/packages/cli/evaluations/high-impact/agent-runner.ts+++ b/packages/cli/evaluations/high-impact/agent-runner.ts@@ -9,8 +9,11 @@ import type {import {addAgentUsage,getAgentUsageEvent,+ getMcpCatalogMetrics,getMcpEvaluationMetrics,type AgentUsage,+ type McpCatalogMetrics,+ type McpCatalogObservation,type McpEvaluationMetrics,} from "./evaluation-metrics";import { runAgentCommand } from "../../scripts/run-agent-command";@@ -33,6 +36,7 @@ export type AgentEvaluationResult = {metrics: {durationMs: number;tokens?: AgentUsage;+ mcpCatalog?: McpCatalogMetrics;toolCalls: McpEvaluationMetrics;};callSequence: string[];@@ -68,11 +72,39 @@ export const createMinimalAgentTask = (mcp: getCliInvocation(target),constraints: ["Use the configured Webstudio project and local CLI.",- "Begin with meta.guide for the objective and follow its workflow.",+ 'Call meta.guide exactly once at the beginning with {"brief":"<objective>"}: copy the objective field verbatim into brief, follow the returned workflow, and do not call meta.guide again.',"Choose focused reads and semantic edits yourself.","Never use broad project reads: snapshot, components.list, or components.coverage-plan.","Do not persist or report credentials or private session data.","Treat mutation meta.next steps as required. Do not report completion until audit and requested visual evidence pass.",+ "Treat the successful final audit and requested visual evidence as terminal; do not mutate, verify, restart preview, or capture more evidence afterward.",+ "Finish all visual polish before evidence capture. Use one verify-page-responsive call for all requested viewports and the terminal static audit. After it begins, do not mutate, rediscover, restart preview, or capture more evidence.",+ ...(fixture.id === "authenticated-page-v1"+ ? [+ "For this fixture, meta.guide already returns the required auth discovery and authoring tool schemas. Do not call list-breakpoints because responsive styling is not required, and do not call meta.get_more_tools or any other tool discovery operation. Create exactly one scoped non-secret fixture variable and keep the required state gallery expression-free. Do not call list-variables again after creating it.",+ "After meta.guide, call inspect-auth-context exactly once. Do not call get-project-settings, list-pages, list-resources, or list-variables separately.",+ "After the context read, call create-page exactly once, then create-variable exactly once, then create-resource exactly once with the returned variable id. Do not parallelize these mutations. Call insert-fragment-verified only after all three succeed, using their returned ids and pagePath /account. Do not call insert-fragment or verify-bindings separately.",+ 'Then call verify-page-responsive exactly once with {"path":"/account","viewports":[{"width":1440,"height":900},{"width":390,"height":844}],"source":"session"}. It captures both required screenshots and runs the terminal static audit. Do not call preview.start, screenshot, screenshot.responsive, or audit separately.',+ ]+ : []),+ ...(fixture.id === "design-input-v1"+ ? [+ "For this fixture, do not call list-instances because the project has no representative existing page pattern. Do not call meta.index, meta.get_more_tools, or any other tool discovery operation because meta.guide and the MCP handshake already provide the required schemas.",+ "After meta.guide, call inspect-design-context exactly once before mutation. Do not call list-pages, list-breakpoints, list-design-tokens, list-assets, or list-variables separately. Do not call get-page-by-path or repeat discovery. Call create-page once, then call insert-fragment-verified once with pagePath /summer before token or style mutations. Do not call insert-fragment or verify-bindings separately.",+ "For this fixture, make exactly three attach-design-token calls: attach only the returned Brand / Coral, Text / Ink, and Type / Heading token ids once each to compatible inserted element instance ids. Attach all three tokens in one parallel tool-call batch. Omit the optional position field and do not attempt any other token attachment.",+ "After the early binding checkpoint, make exactly one batched update-styles call containing all remaining fixed styles. Include at least one declaration on an inserted element using the returned mobile breakpoint id so responsive behavior is persisted before preview.",+ 'Use this exact fragment verbatim in the single insert-fragment-verified call; do not add props, styles, expressions, or alternate components until after it commits: <ws.element ws:tag="header"><ws.element ws:tag="nav"><ws.element ws:tag="a">Northstar</ws.element><ws.element ws:tag="button">Menu</ws.element></ws.element></ws.element><ws.element ws:tag="main"><ws.element ws:tag="section"><ws.element ws:tag="h1">Find your latitude</ws.element><ws.element ws:tag="p">Plan a memorable summer escape.</ws.element><ws.element ws:tag="a">Explore trips</ws.element></ws.element><ws.element ws:tag="section"><ws.element ws:tag="h2">Featured trips</ws.element><ws.element ws:tag="article"><ws.element ws:tag="h3">Coastal escape</ws.element><ws.element ws:tag="p">A restorative journey by the sea.</ws.element></ws.element></ws.element></ws.element><ws.element ws:tag="footer"><ws.element ws:tag="p">Northstar travel</ws.element></ws.element>',+ "The exact fragment already contains all required content. Do not call clone-instance, update-text, set-text-content, or any other content or structure mutation after insertion; only attach the three tokens and apply the one batched style update.",+ 'After the style update, call verify-page-responsive exactly once with {"path":"/summer","viewports":[{"width":1440,"height":900},{"width":390,"height":844}],"source":"session"}. It captures both required screenshots and runs the terminal static audit. Do not call preview.start, screenshot, screenshot.responsive, or audit separately.',+ ]+ : []),+ ...(fixture.id === "font-assets-v1"+ ? [+ "Do not call meta.index, meta.get_more_tools, or any other tool discovery operation because meta.guide and the MCP handshake already provide the required schemas. Upload both supplied fonts together with exactly one upload-assets call; do not use upload-asset.",+ "After upload, update both font assets together in one parallel tool-call batch.",+ "After both updates, call verify-font-assets exactly once with both returned asset ids, then audit. Do not call refresh or get-asset separately.",+ ]+ : []),],};};@@ -91,9 +123,22 @@ const assertBoundedResult = (result: AgentEvaluationResult) => {for (const [key, child] of Object.entries(value)) {const isAggregateUsage =path.length === 1 && path[0] === "metrics" && key === "tokens";+ const isMetricIdentifier =+ path.length === 3 &&+ path[0] === "metrics" &&+ path[1] === "toolCalls" &&+ [+ "failuresByTool",+ "failuresByCode",+ "issuesByCode",+ "issuesByPath",+ "durationsByTool",+ "responseBytesByTool",+ ].includes(path[2]);if (- forbiddenResultKeys.test(key) ||- (forbiddenTokenKey.test(key) && isAggregateUsage === false)+ isMetricIdentifier === false &&+ (forbiddenResultKeys.test(key) ||+ (forbiddenTokenKey.test(key) && isAggregateUsage === false))) {throw new Error(`Agent result contains forbidden field ${key}.`);}@@ -116,6 +161,7 @@ export const runHighImpactAgentEvaluation = async ({provider,model,getToolCalls,+ getCatalogObservations,evaluate,env = process.env,timeoutMs = 10 * 60_000,@@ -129,6 +175,7 @@ export const runHighImpactAgentEvaluation = async ({provider: string;model: string;getToolCalls: () => EvaluationToolCall[];+ getCatalogObservations: () => McpCatalogObservation[];evaluate: () => Promise<HighImpactEvaluationResult>;env?: NodeJS.ProcessEnv;timeoutMs?: number;@@ -160,17 +207,23 @@ export const runHighImpactAgentEvaluation = async ({});const evaluation = await evaluate();const toolCalls = getToolCalls();+ const mcpCatalog = getMcpCatalogMetrics(getCatalogObservations());const checks = {...evaluation.checks,usageCaptured:usage === undefined ? ("failed" as const) : ("passed" as const),};+ const toolCallMetrics = getMcpEvaluationMetrics(toolCalls);const result: AgentEvaluationResult = {schemaVersion: 2,kind: "high-impact-minimal-context-agent-evaluation-result",fixtureId: fixture.id,outcome:- execution.exitCode === 0 && evaluation.passed && usage !== undefined+ execution.exitCode === 0 &&+ evaluation.passed &&+ usage !== undefined &&+ toolCallMetrics.failed === 0 &&+ toolCallMetrics.retries === 0? "passed": "failed",cli: target.kind,@@ -181,7 +234,8 @@ export const runHighImpactAgentEvaluation = async ({metrics: {durationMs: execution.durationMs,...(usage === undefined ? {} : { tokens: usage }),- toolCalls: getMcpEvaluationMetrics(toolCalls),+ ...(mcpCatalog === undefined ? {} : { mcpCatalog }),+ toolCalls: toolCallMetrics,},callSequence: toolCalls.map(({ name }) => name),checks,diff --git a/packages/cli/evaluations/high-impact/evaluation-metrics.test.ts b/packages/cli/evaluations/high-impact/evaluation-metrics.test.tsindex a19d3b14b9..9c3848a848 100644--- a/packages/cli/evaluations/high-impact/evaluation-metrics.test.ts+++ b/packages/cli/evaluations/high-impact/evaluation-metrics.test.ts@@ -2,10 +2,40 @@ import { describe, expect, test } from "vitest";import {addAgentUsage,getAgentUsageEvent,+ getMcpCatalogMetrics,getMcpEvaluationMetrics,} from "./evaluation-metrics";describe("evaluation metrics", () => {+ test("aggregates MCP catalog observations", () => {+ expect(+ getMcpCatalogMetrics([+ {+ kind: "tools-list",+ toolCount: 160,+ responseBytes: 100_000,+ inputSchemaBytes: 50_000,+ descriptionBytes: 10_000,+ },+ {+ kind: "tools-list",+ toolCount: 12,+ responseBytes: 20_000,+ inputSchemaBytes: 8_000,+ descriptionBytes: 2_000,+ },+ ])+ ).toEqual({+ responses: 2,+ totalResponseBytes: 120_000,+ maxResponseBytes: 100_000,+ latestToolCount: 12,+ latestResponseBytes: 20_000,+ latestInputSchemaBytes: 8_000,+ latestDescriptionBytes: 2_000,+ });+ });+test("retains only aggregate usage from Codex completion events", () => {const usage = getAgentUsageEvent({type: "turn.completed",@@ -21,6 +51,7 @@ describe("evaluation metrics", () => {expect(usage).toEqual({input: 1_000,cachedInput: 400,+ uncachedInput: 600,cacheWriteInput: 50,output: 200,reasoningOutput: 75,@@ -33,6 +64,7 @@ describe("evaluation metrics", () => {expect(addAgentUsage(usage, usage)).toEqual({input: 2_000,cachedInput: 800,+ uncachedInput: 1_200,cacheWriteInput: 100,output: 400,reasoningOutput: 150,@@ -44,21 +76,51 @@ describe("evaluation metrics", () => {);});+ test("counts responsive page verification as early evidence", () => {+ expect(+ getMcpEvaluationMetrics([+ {+ name: "verify-page-responsive",+ startedAtMs: 25,+ durationMs: 100,+ responseBytes: 2_000,+ },+ ])+ ).toMatchObject({+ verifications: 1,+ timeToFirstVerificationMs: 25,+ });+ });+test("measures MCP errors, retries, mutations, verification, and latency", () => {expect(getMcpEvaluationMetrics([- { name: "meta.guide", startedAtMs: 10, durationMs: 10 },- { name: "snapshot", startedAtMs: 20, durationMs: 20 },+ {+ name: "meta.guide",+ startedAtMs: 10,+ durationMs: 10,+ responseBytes: 1_000,+ },+ {+ name: "snapshot",+ startedAtMs: 20,+ durationMs: 20,+ responseBytes: 6_000,+ },{name: "create-page",startedAtMs: 50,durationMs: 30,+ responseBytes: 500,isError: true,+ errorCode: "INVALID_INPUT",+ errorIssues: [{ code: "invalid_resource_url", path: "resource.url" }],},{name: "create-page",startedAtMs: 90,durationMs: 40,+ responseBytes: 2_000,committed: true,},{@@ -66,14 +128,63 @@ describe("evaluation metrics", () => {arguments: { dryRun: true },startedAtMs: 110,durationMs: 50,+ responseBytes: 3_000,planned: true,},- { name: "audit", startedAtMs: 170, durationMs: 100 },+ {+ name: "audit",+ startedAtMs: 170,+ durationMs: 100,+ responseBytes: 1_500,+ },])).toEqual({total: 6,succeeded: 5,failed: 1,+ failuresByTool: { "create-page": 1 },+ failuresByCode: { INVALID_INPUT: 1 },+ issuesByCode: { invalid_resource_url: 1 },+ issuesByPath: { "resource.url": 1 },+ durationsByTool: {+ audit: { count: 1, totalMs: 100, p95Ms: 100, maxMs: 100 },+ "create-page": { count: 2, totalMs: 70, p95Ms: 40, maxMs: 40 },+ "meta.guide": { count: 1, totalMs: 10, p95Ms: 10, maxMs: 10 },+ snapshot: { count: 1, totalMs: 20, p95Ms: 20, maxMs: 20 },+ "update-page": { count: 1, totalMs: 50, p95Ms: 50, maxMs: 50 },+ },+ responseBytesByTool: {+ audit: {+ count: 1,+ totalBytes: 1_500,+ p95Bytes: 1_500,+ maxBytes: 1_500,+ },+ "create-page": {+ count: 2,+ totalBytes: 2_500,+ p95Bytes: 2_000,+ maxBytes: 2_000,+ },+ "meta.guide": {+ count: 1,+ totalBytes: 1_000,+ p95Bytes: 1_000,+ maxBytes: 1_000,+ },+ snapshot: {+ count: 1,+ totalBytes: 6_000,+ p95Bytes: 6_000,+ maxBytes: 6_000,+ },+ "update-page": {+ count: 1,+ totalBytes: 3_000,+ p95Bytes: 3_000,+ maxBytes: 3_000,+ },+ },retries: 1,focusedReads: 0,broadReads: 1,@@ -84,6 +195,10 @@ describe("evaluation metrics", () => {totalDurationMs: 250,p50DurationMs: 30,p95DurationMs: 100,+ totalResponseBytes: 14_000,+ p50ResponseBytes: 1_500,+ p95ResponseBytes: 6_000,+ maxResponseBytes: 6_000,timeToFirstMutationMs: 90,timeToFirstVerificationMs: 170,});diff --git a/packages/cli/evaluations/high-impact/evaluation-metrics.ts b/packages/cli/evaluations/high-impact/evaluation-metrics.tsindex 91c682b2f2..d382de92b7 100644--- a/packages/cli/evaluations/high-impact/evaluation-metrics.ts+++ b/packages/cli/evaluations/high-impact/evaluation-metrics.ts@@ -4,6 +4,7 @@ import type { EvaluationToolCall } from "./validate";export type AgentUsage = {input: number;cachedInput: number;+ uncachedInput: number;cacheWriteInput: number;output: number;reasoningOutput: number;@@ -22,9 +23,13 @@ const createAgentUsage = ({cacheWriteInput,output,reasoningOutput,-}: Omit<AgentUsage, "total" | "cachedInputRate">): AgentUsage => ({+}: Omit<+ AgentUsage,+ "total" | "cachedInputRate" | "uncachedInput"+>): AgentUsage => ({input,cachedInput,+ uncachedInput: Math.max(0, input - cachedInput),cacheWriteInput,output,reasoningOutput,@@ -33,6 +38,47 @@ const createAgentUsage = ({input === 0 ? 0 : Math.round((cachedInput / input) * 10_000) / 10_000,});+export type McpCatalogObservation = {+ kind: "tools-list";+ toolCount: number;+ responseBytes: number;+ inputSchemaBytes: number;+ descriptionBytes: number;+};++export type McpCatalogMetrics = {+ responses: number;+ totalResponseBytes: number;+ maxResponseBytes: number;+ latestToolCount: number;+ latestResponseBytes: number;+ latestInputSchemaBytes: number;+ latestDescriptionBytes: number;+};++export const getMcpCatalogMetrics = (+ observations: readonly McpCatalogObservation[]+): McpCatalogMetrics | undefined => {+ const latest = observations.at(-1);+ if (latest === undefined) {+ return;+ }+ return {+ responses: observations.length,+ totalResponseBytes: observations.reduce(+ (total, observation) => total + observation.responseBytes,+ 0+ ),+ maxResponseBytes: Math.max(+ ...observations.map((observation) => observation.responseBytes)+ ),+ latestToolCount: latest.toolCount,+ latestResponseBytes: latest.responseBytes,+ latestInputSchemaBytes: latest.inputSchemaBytes,+ latestDescriptionBytes: latest.descriptionBytes,+ };+};+export const getAgentUsageEvent = (value: unknown): AgentUsage | undefined => {if (isPlainRecord(value) === false ||@@ -84,6 +130,18 @@ export type McpEvaluationMetrics = {total: number;succeeded: number;failed: number;+ failuresByTool: Record<string, number>;+ failuresByCode: Record<string, number>;+ issuesByCode: Record<string, number>;+ issuesByPath: Record<string, number>;+ durationsByTool: Record<+ string,+ { count: number; totalMs: number; p95Ms: number; maxMs: number }+ >;+ responseBytesByTool: Record<+ string,+ { count: number; totalBytes: number; p95Bytes: number; maxBytes: number }+ >;retries: number;focusedReads: number;broadReads: number;@@ -94,6 +152,10 @@ export type McpEvaluationMetrics = {totalDurationMs: number;p50DurationMs: number;p95DurationMs: number;+ totalResponseBytes: number;+ p50ResponseBytes: number;+ p95ResponseBytes: number;+ maxResponseBytes: number;timeToFirstMutationMs?: number;timeToFirstVerificationMs?: number;};@@ -107,8 +169,11 @@ const broadReadNames = new Set([const verificationNames = new Set(["audit","screenshot",+ "screenshot.responsive",+ "verify-page-responsive","screenshot.diff","verify-bindings",+ "insert-fragment-verified",]);export const isFocusedRead = (name: string) =>@@ -125,6 +190,56 @@ const percentile = (values: number[], proportion: number) => {return sorted[index] ?? 0;};+const getDurationsByTool = (calls: readonly EvaluationToolCall[]) => {+ const durations = new Map<string, number[]>();+ for (const call of calls) {+ if (call.durationMs === undefined) {+ continue;+ }+ const values = durations.get(call.name) ?? [];+ values.push(call.durationMs);+ durations.set(call.name, values);+ }+ return Object.fromEntries(+ [...durations.entries()]+ .sort(([left], [right]) => left.localeCompare(right))+ .map(([name, values]) => [+ name,+ {+ count: values.length,+ totalMs: values.reduce((total, value) => total + value, 0),+ p95Ms: percentile(values, 0.95),+ maxMs: Math.max(...values),+ },+ ])+ );+};++const getResponseBytesByTool = (calls: readonly EvaluationToolCall[]) => {+ const responseBytes = new Map<string, number[]>();+ for (const call of calls) {+ if (call.responseBytes === undefined) {+ continue;+ }+ const values = responseBytes.get(call.name) ?? [];+ values.push(call.responseBytes);+ responseBytes.set(call.name, values);+ }+ return Object.fromEntries(+ [...responseBytes.entries()]+ .sort(([left], [right]) => left.localeCompare(right))+ .map(([name, values]) => [+ name,+ {+ count: values.length,+ totalBytes: values.reduce((total, value) => total + value, 0),+ p95Bytes: percentile(values, 0.95),+ maxBytes: Math.max(...values),+ },+ ])+ );+};+const countRetries = (calls: readonly EvaluationToolCall[]) => {const failedNames = new Set<string>();let retries = 0;@@ -141,22 +256,52 @@ const countRetries = (calls: readonly EvaluationToolCall[]) => {return retries;};+const countValues = (values: readonly string[]) =>+ Object.fromEntries(+ [...new Set(values)]+ .sort((left, right) => left.localeCompare(right))+ .map((value) => [+ value,+ values.filter((candidate) => candidate === value).length,+ ])+ );+export const getMcpEvaluationMetrics = (calls: readonly EvaluationToolCall[]): McpEvaluationMetrics => {const durations = calls.flatMap(({ durationMs }) =>durationMs === undefined ? [] : [durationMs]);+ const responseBytes = calls.flatMap(({ responseBytes }) =>+ responseBytes === undefined ? [] : [responseBytes]+ );const firstMutation = calls.find((call) => call.committed === true && call.isError !== true);const firstVerification = calls.find((call) => verificationNames.has(call.name) && call.isError !== true);+ const failedCalls = calls.filter((call) => call.isError === true);return {total: calls.length,succeeded: calls.filter((call) => call.isError !== true).length,- failed: calls.filter((call) => call.isError === true).length,+ failed: failedCalls.length,+ failuresByTool: countValues(failedCalls.map((call) => call.name)),+ failuresByCode: countValues(+ failedCalls.map((call) => call.errorCode ?? "UNKNOWN")+ ),+ issuesByCode: countValues(+ failedCalls.flatMap((call) =>+ (call.errorIssues ?? []).map((issue) => issue.code)+ )+ ),+ issuesByPath: countValues(+ failedCalls.flatMap((call) =>+ (call.errorIssues ?? []).map((issue) => issue.path)+ )+ ),+ durationsByTool: getDurationsByTool(calls),+ responseBytesByTool: getResponseBytesByTool(calls),retries: countRetries(calls),focusedReads: calls.filter((call) => isFocusedRead(call.name)).length,broadReads: calls.filter((call) => isBroadRead(call.name)).length,@@ -173,6 +318,14 @@ export const getMcpEvaluationMetrics = (totalDurationMs: durations.reduce((total, value) => total + value, 0),p50DurationMs: percentile(durations, 0.5),p95DurationMs: percentile(durations, 0.95),+ totalResponseBytes: responseBytes.reduce(+ (total, value) => total + value,+ 0+ ),+ p50ResponseBytes: percentile(responseBytes, 0.5),+ p95ResponseBytes: percentile(responseBytes, 0.95),+ maxResponseBytes:+ responseBytes.length === 0 ? 0 : Math.max(...responseBytes),...(firstMutation?.startedAtMs === undefined? {}: { timeToFirstMutationMs: firstMutation.startedAtMs }),diff --git a/packages/cli/evaluations/high-impact/evaluation-regression.test.ts b/packages/cli/evaluations/high-impact/evaluation-regression.test.tsindex 9a97680faf..cb424b3bbc 100644--- a/packages/cli/evaluations/high-impact/evaluation-regression.test.ts+++ b/packages/cli/evaluations/high-impact/evaluation-regression.test.ts@@ -1,8 +1,10 @@import { describe, expect, test } from "vitest";import type { AgentEvaluationResult } from "./agent-runner";import {+ isAggregateTokenBaselineNonRegressed,compareEvaluationResult,isEvaluationComparisonAccepted,+ shouldUpdateEvaluationBaselines,} from "./evaluation-regression";const createResult = (@@ -22,6 +24,7 @@ const createResult = (tokens: {input: 800,cachedInput: 400,+ uncachedInput: 400,cacheWriteInput: 0,output: 200,reasoningOutput: 50,@@ -32,6 +35,12 @@ const createResult = (total: 10,succeeded: 10,failed: 0,+ failuresByTool: {},+ failuresByCode: {},+ issuesByCode: {},+ issuesByPath: {},+ durationsByTool: {},+ responseBytesByTool: {},retries: 0,focusedReads: 2,broadReads: 0,@@ -42,6 +51,10 @@ const createResult = (totalDurationMs: 500,p50DurationMs: 30,p95DurationMs: 100,+ totalResponseBytes: 10_000,+ p50ResponseBytes: 800,+ p95ResponseBytes: 2_000,+ maxResponseBytes: 3_000,timeToFirstMutationMs: 400,timeToFirstVerificationMs: 800,},@@ -62,7 +75,7 @@ describe("evaluation regression comparison", () => {metrics: {...baseline.metrics,durationMs: 1_100,- tokens: { ...baselineTokens, total: 1_200 },+ tokens: { ...baselineTokens, total: 1_600 },},});const comparison = compareEvaluationResult(current, baseline);@@ -77,16 +90,23 @@ describe("evaluation regression comparison", () => {expect.objectContaining({metric: "metrics.tokens.total",baseline: 1_000,- current: 1_200,+ current: 1_600,}),]));expect(comparison.regressions).toEqual([expect.objectContaining({metric: "metrics.tokens.total",- allowed: 1_150,+ allowed: 1_500,}),]);++ const noisyCurrent = structuredClone(baseline);+ noisyCurrent.metrics.tokens!.total = 1_400;+ expect(compareEvaluationResult(noisyCurrent, baseline)).toMatchObject({+ status: "passed",+ regressions: [],+ });});test("blocks correctness regressions and skips incompatible baselines", () => {@@ -142,6 +162,27 @@ describe("evaluation regression comparison", () => {});});+ test("reports environment-sensitive tool latency without blocking", () => {+ const baseline = createResult();+ const current = structuredClone(baseline);+ current.metrics.toolCalls.totalDurationMs = 20_000;+ current.metrics.toolCalls.p95DurationMs = 10_000;+ const comparison = compareEvaluationResult(current, baseline);+ expect(comparison).toMatchObject({ status: "passed", regressions: [] });+ expect(comparison.deltas).toEqual(+ expect.arrayContaining([+ expect.objectContaining({+ metric: "metrics.toolCalls.totalDurationMs",+ current: 20_000,+ }),+ expect.objectContaining({+ metric: "metrics.toolCalls.p95DurationMs",+ current: 10_000,+ }),+ ])+ );+ });+test("reports stochastic milestone timing without blocking one run", () => {const baseline = createResult();const current = structuredClone(baseline);@@ -164,6 +205,71 @@ describe("evaluation regression comparison", () => {);});+ test("blocks MCP catalog size regressions without gating client refreshes", () => {+ const baseline = createResult();+ baseline.metrics.mcpCatalog = {+ responses: 1,+ totalResponseBytes: 78_000,+ maxResponseBytes: 78_000,+ latestToolCount: 171,+ latestResponseBytes: 78_000,+ latestInputSchemaBytes: 41_000,+ latestDescriptionBytes: 13_000,+ };+ const current = structuredClone(baseline);+ current.metrics.mcpCatalog = {+ ...baseline.metrics.mcpCatalog,+ responses: 2,+ latestResponseBytes: 90_000,+ latestInputSchemaBytes: 48_000,+ };+ const comparison = compareEvaluationResult(current, baseline);+ expect(comparison.regressions).toEqual(+ expect.arrayContaining([+ expect.objectContaining({+ metric: "metrics.mcpCatalog.latestResponseBytes",+ }),+ expect.objectContaining({+ metric: "metrics.mcpCatalog.latestInputSchemaBytes",+ }),+ ])+ );+ expect(comparison.regressions).not.toEqual(+ expect.arrayContaining([+ expect.objectContaining({ metric: "metrics.mcpCatalog.responses" }),+ ])+ );+ expect(comparison.deltas).toEqual(+ expect.arrayContaining([+ expect.objectContaining({ metric: "metrics.mcpCatalog.responses" }),+ ])+ );+ });++ test("blocks aggregate MCP response growth and reports tail changes", () => {+ const baseline = createResult();+ const current = structuredClone(baseline);+ current.metrics.toolCalls.totalResponseBytes = 12_000;+ current.metrics.toolCalls.p95ResponseBytes = 2_400;+ expect(compareEvaluationResult(current, baseline).regressions).toEqual([+ {+ metric: "metrics.toolCalls.totalResponseBytes",+ baseline: 10_000,+ current: 12_000,+ allowed: 11_500,+ },+ ]);+ expect(compareEvaluationResult(current, baseline).deltas).toEqual(+ expect.arrayContaining([+ expect.objectContaining({+ metric: "metrics.toolCalls.p95ResponseBytes",+ baseline: 2_000,+ current: 2_400,+ }),+ ])+ );+ });+test("requires accepted baselines and never accepts metric regressions", () => {const passed = compareEvaluationResult(createResult(), createResult());const missing = compareEvaluationResult(createResult(), undefined);@@ -205,4 +311,84 @@ describe("evaluation regression comparison", () => {})).toBe(false);});++ test("updates baselines only after outcomes and comparisons pass", () => {+ expect(+ shouldUpdateEvaluationBaselines({+ updateBaselines: true,+ evaluationsPassed: true,+ comparisonsPassed: true,+ aggregateTokensPassed: true,+ })+ ).toBe(true);+ expect(+ shouldUpdateEvaluationBaselines({+ updateBaselines: true,+ evaluationsPassed: true,+ comparisonsPassed: false,+ aggregateTokensPassed: true,+ })+ ).toBe(false);+ expect(+ shouldUpdateEvaluationBaselines({+ updateBaselines: true,+ evaluationsPassed: false,+ comparisonsPassed: true,+ aggregateTokensPassed: true,+ })+ ).toBe(false);+ expect(+ shouldUpdateEvaluationBaselines({+ updateBaselines: true,+ evaluationsPassed: true,+ comparisonsPassed: true,+ aggregateTokensPassed: false,+ })+ ).toBe(false);+ });++ test("does not ratchet an existing aggregate token baseline upward", () => {+ const withTokens = (+ fixtureId: AgentEvaluationResult["fixtureId"],+ total: number+ ) => {+ const result = createResult({ fixtureId });+ return {+ ...result,+ metrics: {+ ...result.metrics,+ tokens: { ...result.metrics.tokens!, total },+ },+ };+ };+ const baselines = [+ withTokens("authenticated-page-v1", 1_000),+ withTokens("design-input-v1", 1_000),+ ];++ expect(+ isAggregateTokenBaselineNonRegressed(+ [+ withTokens("authenticated-page-v1", 900),+ withTokens("design-input-v1", 1_000),+ ],+ baselines+ )+ ).toBe(true);+ expect(+ isAggregateTokenBaselineNonRegressed(+ [+ withTokens("authenticated-page-v1", 1_001),+ withTokens("design-input-v1", 1_000),+ ],+ baselines+ )+ ).toBe(false);+ expect(+ isAggregateTokenBaselineNonRegressed(+ [withTokens("authenticated-page-v1", 1_000)],+ []+ )+ ).toBe(true);+ });});diff --git a/packages/cli/evaluations/high-impact/evaluation-regression.ts b/packages/cli/evaluations/high-impact/evaluation-regression.tsindex d44102fdc7..a7a3730b36 100644--- a/packages/cli/evaluations/high-impact/evaluation-regression.ts+++ b/packages/cli/evaluations/high-impact/evaluation-regression.ts@@ -19,11 +19,13 @@ export type EvaluationComparison = {status: "passed" | "regressed" | "missing" | "incompatible";baselineCommandSha256?: string;maxMetricRegressionPercent: number;+ maxTokenRegressionPercent: number;deltas: EvaluationMetricDelta[];regressions: EvaluationRegression[];};export const maxMetricRegressionPercent = 15;+export const maxTokenRegressionPercent = 50;export const isEvaluationComparisonAccepted = ({comparison,@@ -43,20 +45,59 @@ export const isEvaluationComparisonAccepted = ({return updateBaselines || requireBaseline === false;};+export const shouldUpdateEvaluationBaselines = ({+ updateBaselines,+ evaluationsPassed,+ comparisonsPassed,+ aggregateTokensPassed,+}: {+ updateBaselines: boolean;+ evaluationsPassed: boolean;+ comparisonsPassed: boolean;+ aggregateTokensPassed: boolean;+}) =>+ updateBaselines &&+ evaluationsPassed &&+ comparisonsPassed &&+ aggregateTokensPassed;++export const isAggregateTokenBaselineNonRegressed = (+ current: readonly AgentEvaluationResult[],+ baselines: readonly AgentEvaluationResult[]+) => {+ const baselineByFixture = new Map(+ baselines.map((baseline) => [baseline.fixtureId, baseline])+ );+ let currentTotal = 0;+ let baselineTotal = 0;+ let compared = 0;+ for (const result of current) {+ const baseline = baselineByFixture.get(result.fixtureId);+ if (baseline === undefined) {+ continue;+ }+ const currentTokens = result.metrics.tokens?.total;+ const baselineTokens = baseline.metrics.tokens?.total;+ if (currentTokens === undefined || baselineTokens === undefined) {+ return false;+ }+ currentTotal += currentTokens;+ baselineTotal += baselineTokens;+ compared += 1;+ }+ return compared === 0 || currentTotal <= baselineTotal;+};+const gatedMetricPaths = new Set(["metrics.tokens.total",+ "metrics.mcpCatalog.latestResponseBytes",+ "metrics.mcpCatalog.latestInputSchemaBytes","metrics.toolCalls.total","metrics.toolCalls.failed","metrics.toolCalls.retries","metrics.toolCalls.focusedReads","metrics.toolCalls.broadReads",- "metrics.toolCalls.totalDurationMs",- "metrics.toolCalls.p95DurationMs",-]);--const minimumAbsoluteIncrease = new Map([- ["metrics.toolCalls.totalDurationMs", 100],- ["metrics.toolCalls.p95DurationMs", 100],+ "metrics.toolCalls.totalResponseBytes",]);const getNumericMetrics = (@@ -93,6 +134,7 @@ export const compareEvaluationResult = (): EvaluationComparison => {const empty = {maxMetricRegressionPercent,+ maxTokenRegressionPercent,deltas: [],regressions: [],};@@ -128,13 +170,15 @@ export const compareEvaluationResult = (if (gatedMetricPaths.has(metric) === false) {continue;}+ const regressionPercent =+ metric === "metrics.tokens.total"+ ? maxTokenRegressionPercent+ : maxMetricRegressionPercent;const relativeIncrease = Math.floor(- baselineValue * (maxMetricRegressionPercent / 100) ++ baselineValue * (regressionPercent / 100) +Number.EPSILON * Math.max(1, baselineValue));- const allowed =- baselineValue +- Math.max(relativeIncrease, minimumAbsoluteIncrease.get(metric) ?? 0);+ const allowed = baselineValue + relativeIncrease;if (currentValue > allowed) {regressions.push({metric,@@ -168,6 +212,7 @@ export const compareEvaluationResult = (status: regressions.length === 0 ? "passed" : "regressed",baselineCommandSha256: baseline.commandSha256,maxMetricRegressionPercent,+ maxTokenRegressionPercent,deltas,regressions,};diff --git a/packages/cli/evaluations/high-impact/fixtures.ts b/packages/cli/evaluations/high-impact/fixtures.tsindex 4be4847435..d3abad392a 100644--- a/packages/cli/evaluations/high-impact/fixtures.ts+++ b/packages/cli/evaluations/high-impact/fixtures.ts@@ -141,7 +141,7 @@ export const designInputFixture: HighImpactFixture & {} = {id: "design-input-v1",objective:- "Build an editable /summer page from the supplied desktop and mobile design reference. Preserve and reuse the existing design system, implement responsive behavior with the project's breakpoints, then run rendered audit and inspect desktop/mobile screenshots.",+ "Build an editable /summer page from the supplied desktop and mobile design reference. Preserve and reuse the existing design system, implement responsive behavior with the project's breakpoints, inspect desktop/mobile screenshots, then run a static route audit without duplicating the rendered captures.",project: {...emptyProject(),styleSources: [diff --git a/packages/cli/evaluations/high-impact/mcp-trace-proxy.test.ts b/packages/cli/evaluations/high-impact/mcp-trace-proxy.test.tsindex 2e2a9623c2..3f90acdfcd 100644--- a/packages/cli/evaluations/high-impact/mcp-trace-proxy.test.ts+++ b/packages/cli/evaluations/high-impact/mcp-trace-proxy.test.ts@@ -1,5 +1,6 @@import { describe, expect, test } from "vitest";import {+ getMcpCatalogObservation,getMcpMutationToolNames,getMcpToolsListRequestId,getMcpTraceRequest,@@ -7,6 +8,37 @@ import {} from "./mcp-trace-proxy";describe("bounded MCP tracing", () => {+ test("measures the bounded tools catalog payload", () => {+ expect(+ getMcpCatalogObservation({+ id: 1,+ result: {+ tools: [+ {+ name: "list-pages",+ description: "List pages",+ inputSchema: { type: "object", properties: {} },+ },+ {+ name: "create-page",+ description: "Create page",+ inputSchema: {+ type: "object",+ properties: { path: { type: "string" } },+ },+ },+ ],+ },+ })+ ).toEqual({+ kind: "tools-list",+ toolCount: 2,+ responseBytes: 231,+ inputSchemaBytes: 90,+ descriptionBytes: 21,+ });+ });+test("retains only bounded verification fields", () => {expect(getMcpTraceRequest(@@ -35,6 +67,34 @@ describe("bounded MCP tracing", () => {});});+ test("retains responsive verification viewports as bounded evidence", () => {+ expect(+ getMcpTraceRequest({+ id: 9,+ method: "tools/call",+ params: {+ name: "verify-page-responsive",+ arguments: {+ path: "/account",+ viewports: [+ { width: 1440, height: 900 },+ { width: 390, height: 844 },+ ],+ },+ },+ })+ ).toMatchObject({+ call: {+ arguments: {+ viewports: [+ { width: 1440, height: 900 },+ { width: 390, height: 844 },+ ],+ },+ },+ });+ });+test("records confirmation flow without retaining its token", () => {expect(getMcpTraceRequest(@@ -73,33 +133,56 @@ describe("bounded MCP tracing", () => {[2, { name: "verify-bindings", startedAtMs: 200 }],]);- expect(- getMcpTraceResponse(- {- id: 1,- result: {- structuredContent: {- meta: { session: { committed: true } },- },- },+ const committedResponse = {+ id: 1,+ result: {+ structuredContent: {+ meta: { session: { committed: true } },},- pending,- 175- )- ).toEqual({+ },+ };+ expect(getMcpTraceResponse(committedResponse, pending, 175)).toEqual({name: "create-page",startedAtMs: 100,mutation: true,durationMs: 75,+ responseBytes: Buffer.byteLength(JSON.stringify(committedResponse)),committed: true,});- expect(- getMcpTraceResponse({ id: 2, result: { isError: true } }, pending, 260)- ).toEqual({+ const failedResponse = {+ id: 2,+ result: {+ isError: true,+ structuredContent: {+ error: {+ code: "INVALID_INPUT",+ message: "private diagnostic message",+ details: { token: "private-token" },+ issues: [+ {+ code: "invalid_type",+ path: ["resource", "headers", 0, "value"],+ message: "private issue message",+ example: "private example",+ },+ ],+ },+ },+ },+ };+ expect(getMcpTraceResponse(failedResponse, pending, 260)).toEqual({name: "verify-bindings",startedAtMs: 200,durationMs: 60,+ responseBytes: Buffer.byteLength(JSON.stringify(failedResponse)),isError: true,+ errorCode: "INVALID_INPUT",+ errorIssues: [+ {+ code: "invalid_type",+ path: "resource.headers.0.value",+ },+ ],});expect(pending.size).toBe(0);});@@ -117,13 +200,22 @@ describe("bounded MCP tracing", () => {},{name: "create-page",- annotations: { readOnlyHint: false, private: "discard" },+ annotations: {+ destructiveHint: false,+ openWorldHint: false,+ private: "discard",+ },+ },+ {+ name: "delete-external-resource",},],},}));- expect(mutationToolNames).toEqual(new Set(["create-page"]));+ expect(mutationToolNames).toEqual(+ new Set(["create-page", "delete-external-resource"])+ );expect(getMcpTraceRequest({diff --git a/packages/cli/evaluations/high-impact/mcp-trace-proxy.ts b/packages/cli/evaluations/high-impact/mcp-trace-proxy.tsindex c8b062db14..1165f2115a 100644--- a/packages/cli/evaluations/high-impact/mcp-trace-proxy.ts+++ b/packages/cli/evaluations/high-impact/mcp-trace-proxy.ts@@ -1,7 +1,8 @@import { appendFileSync } from "node:fs";import { spawn } from "node:child_process";import { pathToFileURL } from "node:url";-import { isPlainRecord } from "../../src/type-utils";+import { boundedIdentifierPattern, isPlainRecord } from "../../src/type-utils";+import type { McpCatalogObservation } from "./evaluation-metrics";type JsonRpcId = string | number;@@ -9,16 +10,78 @@ export type BoundedMcpCall = {name: string;arguments?: {viewport?: { width: number; height: number };+ viewports?: Array<{ width: number; height: number }>;dryRun?: true;confirmDestructive?: true;hasConfirmationToken?: true;};startedAtMs: number;durationMs?: number;+ responseBytes?: number;mutation?: true;planned?: true;committed?: true;isError?: true;+ errorCode?: string;+ errorIssues?: Array<{ code: string; path: string }>;+};++const getStructuredError = (result: unknown) => {+ const structuredContent =+ isPlainRecord(result) && isPlainRecord(result.structuredContent)+ ? result.structuredContent+ : undefined;+ return structuredContent !== undefined &&+ isPlainRecord(structuredContent.error)+ ? structuredContent.error+ : undefined;+};++const getBoundedErrorCode = (value: unknown, result: unknown) => {+ const error = getStructuredError(result);+ if (+ typeof error?.code === "string" &&+ boundedIdentifierPattern.test(error.code)+ ) {+ return error.code;+ }+ if (isPlainRecord(value) && isPlainRecord(value.error)) {+ const code = value.error.code;+ if (typeof code === "number" && Number.isSafeInteger(code)) {+ return `JSON_RPC_${code}`;+ }+ if (typeof code === "string" && boundedIdentifierPattern.test(code)) {+ return code;+ }+ }+};++const getBoundedErrorIssues = (result: unknown) => {+ const issues = getStructuredError(result)?.issues;+ if (Array.isArray(issues) === false) {+ return;+ }+ const boundedIssues = issues.slice(0, 8).flatMap((issue) => {+ if (+ isPlainRecord(issue) === false ||+ typeof issue.code !== "string" ||+ boundedIdentifierPattern.test(issue.code) === false ||+ Array.isArray(issue.path) === false ||+ issue.path.length > 8+ ) {+ return [];+ }+ const segments = issue.path.map(String);+ if (+ segments.some(+ (segment) => boundedIdentifierPattern.test(segment) === false+ )+ ) {+ return [];+ }+ return [{ code: issue.code, path: segments.join(".") }];+ });+ return boundedIssues.length === 0 ? undefined : boundedIssues;};export const getMcpTraceRequest = (@@ -54,6 +117,25 @@ export const getMcpTraceRequest = () {args.viewport = { width: viewport.width, height: viewport.height };}+ const viewports = params.arguments.viewports;+ if (+ (params.name === "screenshot.responsive" ||+ params.name === "verify-page-responsive") &&+ Array.isArray(viewports) &&+ viewports.length > 0 &&+ viewports.length <= 8 &&+ viewports.every(+ (item) =>+ isPlainRecord(item) &&+ typeof item.width === "number" &&+ typeof item.height === "number"+ )+ ) {+ args.viewports = viewports.map((item) => ({+ width: item.width as number,+ height: item.height as number,+ }));+ }if (params.arguments.dryRun === true) {args.dryRun = true;}@@ -93,6 +175,10 @@ export const getMcpTraceResponse = ((isPlainRecord(result) && result.isError === true)? (true as const): undefined;+ const errorCode =+ isError === true ? getBoundedErrorCode(value, result) : undefined;+ const errorIssues =+ isError === true ? getBoundedErrorIssues(result) : undefined;const structuredContent =isPlainRecord(result) && isPlainRecord(result.structuredContent)? result.structuredContent@@ -118,9 +204,12 @@ export const getMcpTraceResponse = (return {...call,durationMs: Math.max(0, Math.round(completedAtMs - call.startedAtMs)),+ responseBytes: getJsonBytes(value),...(planned === undefined ? {} : { planned }),...(committed === undefined ? {} : { committed }),...(isError === undefined ? {} : { isError }),+ ...(errorCode === undefined ? {} : { errorCode }),+ ...(errorIssues === undefined ? {} : { errorIssues }),};};@@ -145,8 +234,8 @@ export const getMcpMutationToolNames = (value: unknown) => {if (isPlainRecord(tool) &&typeof tool.name === "string" &&- isPlainRecord(tool.annotations) &&- tool.annotations.readOnlyHint === false+ (isPlainRecord(tool.annotations) === false ||+ tool.annotations.readOnlyHint !== true)) {return [tool.name];}@@ -154,6 +243,43 @@ export const getMcpMutationToolNames = (value: unknown) => {});};+const getJsonBytes = (value: unknown) =>+ Buffer.byteLength(JSON.stringify(value), "utf8");++export const getMcpCatalogObservation = (+ value: unknown+): McpCatalogObservation | undefined => {+ if (+ isPlainRecord(value) === false ||+ isPlainRecord(value.result) === false ||+ Array.isArray(value.result.tools) === false+ ) {+ return;+ }+ const tools = value.result.tools;+ return {+ kind: "tools-list",+ toolCount: tools.length,+ responseBytes: getJsonBytes(value.result),+ inputSchemaBytes: tools.reduce(+ (total, tool) =>+ total ++ (isPlainRecord(tool) && tool.inputSchema !== undefined+ ? getJsonBytes(tool.inputSchema)+ : 0),+ 0+ ),+ descriptionBytes: tools.reduce(+ (total, tool) =>+ total ++ (isPlainRecord(tool) && typeof tool.description === "string"+ ? Buffer.byteLength(tool.description, "utf8")+ : 0),+ 0+ ),+ };+};+const observeJsonLines = (stream: NodeJS.ReadableStream,visit: (value: unknown) => void@@ -204,6 +330,10 @@ const run = () => {(typeof value.id === "string" || typeof value.id === "number") &&pendingToolsLists.delete(value.id)) {+ const catalog = getMcpCatalogObservation(value);+ if (catalog !== undefined) {+ appendFileSync(tracePath, `${JSON.stringify(catalog)}\n`, "utf8");+ }for (const name of getMcpMutationToolNames(value) ?? []) {mutationToolNames.add(name);}diff --git a/packages/cli/evaluations/high-impact/results/authenticated-page-v1.json b/packages/cli/evaluations/high-impact/results/authenticated-page-v1.jsonindex b38cc91f1e..9e37932082 100644--- a/packages/cli/evaluations/high-impact/results/authenticated-page-v1.json+++ b/packages/cli/evaluations/high-impact/results/authenticated-page-v1.json@@ -6,100 +6,164 @@"cli": "source","provider": "openai","model": "gpt-5.6-sol",- "commandSha256": "79baa45fea9cee997dfac56c6d33eaf4400efe5e5155db9934c4c82c9df41c83",+ "commandSha256": "f3973839321d489a88526e5e1751d54aa9391af61107e56165cd35520c60a96a","exitCode": 0,"metrics": {- "durationMs": 529970,+ "durationMs": 94027,"tokens": {- "input": 6976750,- "cachedInput": 6771712,+ "input": 319553,+ "cachedInput": 275200,+ "uncachedInput": 44353,"cacheWriteInput": 0,- "output": 17054,- "reasoningOutput": 4582,- "total": 6993804,- "cachedInputRate": 0.9706+ "output": 1843,+ "reasoningOutput": 505,+ "total": 321396,+ "cachedInputRate": 0.8612+ },+ "mcpCatalog": {+ "responses": 1,+ "totalResponseBytes": 51362,+ "maxResponseBytes": 51362,+ "latestToolCount": 176,+ "latestResponseBytes": 51362,+ "latestInputSchemaBytes": 28964,+ "latestDescriptionBytes": 4556},"toolCalls": {- "total": 62,- "succeeded": 51,- "failed": 11,- "retries": 10,- "focusedReads": 8,+ "total": 8,+ "succeeded": 8,+ "failed": 0,+ "failuresByTool": {},+ "failuresByCode": {},+ "issuesByCode": {},+ "issuesByPath": {},+ "durationsByTool": {+ "audit": {+ "count": 1,+ "totalMs": 10,+ "p95Ms": 10,+ "maxMs": 10+ },+ "create-page": {+ "count": 1,+ "totalMs": 29,+ "p95Ms": 29,+ "maxMs": 29+ },+ "create-resource": {+ "count": 1,+ "totalMs": 20,+ "p95Ms": 20,+ "maxMs": 20+ },+ "create-variable": {+ "count": 1,+ "totalMs": 24,+ "p95Ms": 24,+ "maxMs": 24+ },+ "insert-fragment-verified": {+ "count": 1,+ "totalMs": 68,+ "p95Ms": 68,+ "maxMs": 68+ },+ "inspect-auth-context": {+ "count": 1,+ "totalMs": 22,+ "p95Ms": 22,+ "maxMs": 22+ },+ "meta.guide": {+ "count": 1,+ "totalMs": 10,+ "p95Ms": 10,+ "maxMs": 10+ },+ "screenshot.responsive": {+ "count": 1,+ "totalMs": 9439,+ "p95Ms": 9439,+ "maxMs": 9439+ }+ },+ "responseBytesByTool": {+ "audit": {+ "count": 1,+ "totalBytes": 4762,+ "p95Bytes": 4762,+ "maxBytes": 4762+ },+ "create-page": {+ "count": 1,+ "totalBytes": 1342,+ "p95Bytes": 1342,+ "maxBytes": 1342+ },+ "create-resource": {+ "count": 1,+ "totalBytes": 1644,+ "p95Bytes": 1644,+ "maxBytes": 1644+ },+ "create-variable": {+ "count": 1,+ "totalBytes": 1554,+ "p95Bytes": 1554,+ "maxBytes": 1554+ },+ "insert-fragment-verified": {+ "count": 1,+ "totalBytes": 2662,+ "p95Bytes": 2662,+ "maxBytes": 2662+ },+ "inspect-auth-context": {+ "count": 1,+ "totalBytes": 2576,+ "p95Bytes": 2576,+ "maxBytes": 2576+ },+ "meta.guide": {+ "count": 1,+ "totalBytes": 15932,+ "p95Bytes": 15932,+ "maxBytes": 15932+ },+ "screenshot.responsive": {+ "count": 1,+ "totalBytes": 7064,+ "p95Bytes": 7064,+ "maxBytes": 7064+ }+ },+ "retries": 0,+ "focusedReads": 1,"broadReads": 0,- "dryRuns": 12,- "plannedMutations": 7,- "committedMutations": 17,- "verifications": 10,- "totalDurationMs": 165266,- "p50DurationMs": 20,- "p95DurationMs": 27606,- "timeToFirstMutationMs": 69436,- "timeToFirstVerificationMs": 177942+ "dryRuns": 0,+ "plannedMutations": 0,+ "committedMutations": 4,+ "verifications": 3,+ "totalDurationMs": 9622,+ "p50DurationMs": 22,+ "p95DurationMs": 9439,+ "totalResponseBytes": 37536,+ "p50ResponseBytes": 2576,+ "p95ResponseBytes": 15932,+ "maxResponseBytes": 15932,+ "timeToFirstMutationMs": 39076,+ "timeToFirstVerificationMs": 67660}},"callSequence": ["meta.guide",- "meta.index",- "list-pages",- "list-resources",- "list-variables",- "list-instances",- "get-project-settings",- "meta.get_more_tools",- "search-project",- "meta.get_more_tools",- "create-page",+ "inspect-auth-context","create-page",- "create-resource",- "create-resource","create-variable",- "create-variable",- "create-variable",- "insert-fragment",- "insert-fragment",- "verify-bindings",- "list-breakpoints",- "update-styles",- "update-styles",- "preview.start",- "preview.start",- "screenshot",- "wrap-instance",- "wrap-instance",- "wrap-instance",- "wrap-instance",- "wrap-instance",- "wrap-instance",- "wrap-instance",- "wrap-instance",- "list-instances",- "wrap-instance",- "bind-props",- "bind-props",- "verify-bindings",- "screenshot",- "update-resource",- "update-resource",- "preview.start",- "screenshot",- "screenshot",- "update-variable",- "screenshot",- "update-resource",- "update-resource",- "update-resource",- "preview.start",- "preview.stop",- "preview.start",- "screenshot",- "update-variable",- "screenshot",- "update-variable",- "screenshot",- "update-variable",- "verify-bindings",- "audit",- "preview.stop"+ "create-resource",+ "insert-fragment-verified",+ "screenshot.responsive",+ "audit"],"checks": {"guidance": "passed",diff --git a/packages/cli/evaluations/high-impact/results/design-input-v1.json b/packages/cli/evaluations/high-impact/results/design-input-v1.jsonindex d06b378853..cef1e8a342 100644--- a/packages/cli/evaluations/high-impact/results/design-input-v1.json+++ b/packages/cli/evaluations/high-impact/results/design-input-v1.json@@ -6,60 +6,165 @@"cli": "source","provider": "openai","model": "gpt-5.6-sol",- "commandSha256": "b67b2dd38d840a331cf71a72ff8d6417b26cec0d48f1ec48bded91a00d7322e3",+ "commandSha256": "665472955db94c5d88c26b9c858eca2ec7621f04efa461fdb4cff3ae79dc5c5b","exitCode": 0,"metrics": {- "durationMs": 257624,+ "durationMs": 97892,"tokens": {- "input": 1912580,- "cachedInput": 1814272,+ "input": 327593,+ "cachedInput": 273152,+ "uncachedInput": 54441,"cacheWriteInput": 0,- "output": 12382,- "reasoningOutput": 1435,- "total": 1924962,- "cachedInputRate": 0.9486+ "output": 2987,+ "reasoningOutput": 698,+ "total": 330580,+ "cachedInputRate": 0.8338+ },+ "mcpCatalog": {+ "responses": 1,+ "totalResponseBytes": 51362,+ "maxResponseBytes": 51362,+ "latestToolCount": 176,+ "latestResponseBytes": 51362,+ "latestInputSchemaBytes": 28964,+ "latestDescriptionBytes": 4556},"toolCalls": {- "total": 23,- "succeeded": 21,- "failed": 2,- "retries": 2,- "focusedReads": 7,+ "total": 10,+ "succeeded": 10,+ "failed": 0,+ "failuresByTool": {},+ "failuresByCode": {},+ "issuesByCode": {},+ "issuesByPath": {},+ "durationsByTool": {+ "attach-design-token": {+ "count": 3,+ "totalMs": 24,+ "p95Ms": 9,+ "maxMs": 9+ },+ "audit": {+ "count": 1,+ "totalMs": 12,+ "p95Ms": 12,+ "maxMs": 12+ },+ "create-page": {+ "count": 1,+ "totalMs": 91,+ "p95Ms": 91,+ "maxMs": 91+ },+ "insert-fragment-verified": {+ "count": 1,+ "totalMs": 55,+ "p95Ms": 55,+ "maxMs": 55+ },+ "inspect-design-context": {+ "count": 1,+ "totalMs": 30,+ "p95Ms": 30,+ "maxMs": 30+ },+ "meta.guide": {+ "count": 1,+ "totalMs": 11,+ "p95Ms": 11,+ "maxMs": 11+ },+ "screenshot.responsive": {+ "count": 1,+ "totalMs": 10751,+ "p95Ms": 10751,+ "maxMs": 10751+ },+ "update-styles": {+ "count": 1,+ "totalMs": 64,+ "p95Ms": 64,+ "maxMs": 64+ }+ },+ "responseBytesByTool": {+ "attach-design-token": {+ "count": 3,+ "totalBytes": 3900,+ "p95Bytes": 1304,+ "maxBytes": 1304+ },+ "audit": {+ "count": 1,+ "totalBytes": 3711,+ "p95Bytes": 3711,+ "maxBytes": 3711+ },+ "create-page": {+ "count": 1,+ "totalBytes": 1342,+ "p95Bytes": 1342,+ "maxBytes": 1342+ },+ "insert-fragment-verified": {+ "count": 1,+ "totalBytes": 2954,+ "p95Bytes": 2954,+ "maxBytes": 2954+ },+ "inspect-design-context": {+ "count": 1,+ "totalBytes": 3082,+ "p95Bytes": 3082,+ "maxBytes": 3082+ },+ "meta.guide": {+ "count": 1,+ "totalBytes": 15190,+ "p95Bytes": 15190,+ "maxBytes": 15190+ },+ "screenshot.responsive": {+ "count": 1,+ "totalBytes": 7053,+ "p95Bytes": 7053,+ "maxBytes": 7053+ },+ "update-styles": {+ "count": 1,+ "totalBytes": 2804,+ "p95Bytes": 2804,+ "maxBytes": 2804+ }+ },+ "retries": 0,+ "focusedReads": 1,"broadReads": 0,- "dryRuns": 2,- "plannedMutations": 2,- "committedMutations": 5,- "verifications": 4,- "totalDurationMs": 37835,- "p50DurationMs": 27,- "p95DurationMs": 10457,- "timeToFirstMutationMs": 53985,- "timeToFirstVerificationMs": 187306+ "dryRuns": 0,+ "plannedMutations": 0,+ "committedMutations": 6,+ "verifications": 3,+ "totalDurationMs": 11038,+ "p50DurationMs": 12,+ "p95DurationMs": 10751,+ "totalResponseBytes": 40036,+ "p50ResponseBytes": 2804,+ "p95ResponseBytes": 15190,+ "maxResponseBytes": 15190,+ "timeToFirstMutationMs": 30419,+ "timeToFirstVerificationMs": 36551}},"callSequence": ["meta.guide",- "list-breakpoints",- "list-design-tokens",- "list-pages",- "list-assets",- "meta.get_more_tools",- "list-instances",- "list-design-tokens",- "create-page",+ "inspect-design-context","create-page",- "insert-fragment",- "insert-fragment",- "list-instances",+ "insert-fragment-verified","attach-design-token","attach-design-token","attach-design-token",- "verify-bindings",- "preview.start",- "preview.start",- "preview.start",- "screenshot",- "screenshot",+ "update-styles",+ "screenshot.responsive","audit"],"checks": {diff --git a/packages/cli/evaluations/high-impact/results/font-assets-v1.json b/packages/cli/evaluations/high-impact/results/font-assets-v1.jsonindex eafb7eb868..d1fb08fa43 100644--- a/packages/cli/evaluations/high-impact/results/font-assets-v1.json+++ b/packages/cli/evaluations/high-impact/results/font-assets-v1.json@@ -6,35 +6,117 @@"cli": "source","provider": "openai","model": "gpt-5.6-sol",- "commandSha256": "53276281bd1eb5d56e4fe9fe63e44fc5c62ccade4a6f789aafc05367a8f9045d",+ "commandSha256": "5c89af64bb3444ce679f82090c667ece40deb159b6b9ce7cd413e19c466d1ae3","exitCode": 0,"metrics": {- "durationMs": 48517,+ "durationMs": 50677,"tokens": {- "input": 465604,- "cachedInput": 418304,+ "input": 261344,+ "cachedInput": 240640,+ "uncachedInput": 20704,"cacheWriteInput": 0,- "output": 1590,- "reasoningOutput": 324,- "total": 467194,- "cachedInputRate": 0.8984+ "output": 1440,+ "reasoningOutput": 198,+ "total": 262784,+ "cachedInputRate": 0.9208+ },+ "mcpCatalog": {+ "responses": 1,+ "totalResponseBytes": 51362,+ "maxResponseBytes": 51362,+ "latestToolCount": 176,+ "latestResponseBytes": 51362,+ "latestInputSchemaBytes": 28964,+ "latestDescriptionBytes": 4556},"toolCalls": {- "total": 8,- "succeeded": 8,+ "total": 6,+ "succeeded": 6,"failed": 0,+ "failuresByTool": {},+ "failuresByCode": {},+ "issuesByCode": {},+ "issuesByPath": {},+ "durationsByTool": {+ "audit": {+ "count": 1,+ "totalMs": 17,+ "p95Ms": 17,+ "maxMs": 17+ },+ "meta.guide": {+ "count": 1,+ "totalMs": 11,+ "p95Ms": 11,+ "maxMs": 11+ },+ "update-asset": {+ "count": 2,+ "totalMs": 27,+ "p95Ms": 14,+ "maxMs": 14+ },+ "upload-assets": {+ "count": 1,+ "totalMs": 25,+ "p95Ms": 25,+ "maxMs": 25+ },+ "verify-font-assets": {+ "count": 1,+ "totalMs": 8,+ "p95Ms": 8,+ "maxMs": 8+ }+ },+ "responseBytesByTool": {+ "audit": {+ "count": 1,+ "totalBytes": 5300,+ "p95Bytes": 5300,+ "maxBytes": 5300+ },+ "meta.guide": {+ "count": 1,+ "totalBytes": 6566,+ "p95Bytes": 6566,+ "maxBytes": 6566+ },+ "update-asset": {+ "count": 2,+ "totalBytes": 1760,+ "p95Bytes": 880,+ "maxBytes": 880+ },+ "upload-assets": {+ "count": 1,+ "totalBytes": 2196,+ "p95Bytes": 2196,+ "maxBytes": 2196+ },+ "verify-font-assets": {+ "count": 1,+ "totalBytes": 2220,+ "p95Bytes": 2220,+ "maxBytes": 2220+ }+ },"retries": 0,- "focusedReads": 2,+ "focusedReads": 0,"broadReads": 0,"dryRuns": 0,"plannedMutations": 0,"committedMutations": 3,"verifications": 1,- "totalDurationMs": 73,- "p50DurationMs": 10,- "p95DurationMs": 21,- "timeToFirstMutationMs": 27832,- "timeToFirstVerificationMs": 43500+ "totalDurationMs": 88,+ "p50DurationMs": 13,+ "p95DurationMs": 25,+ "totalResponseBytes": 18042,+ "p50ResponseBytes": 2196,+ "p95ResponseBytes": 6566,+ "maxResponseBytes": 6566,+ "timeToFirstMutationMs": 37609,+ "timeToFirstVerificationMs": 47073}},"callSequence": [@@ -42,9 +124,7 @@"upload-assets","update-asset","update-asset",- "refresh",- "get-asset",- "get-asset",+ "verify-font-assets","audit"],"checks": {diff --git a/packages/cli/evaluations/high-impact/run-local-agent.ts b/packages/cli/evaluations/high-impact/run-local-agent.tsindex a00bcb7ecd..eff1ca8f74 100644--- a/packages/cli/evaluations/high-impact/run-local-agent.ts+++ b/packages/cli/evaluations/high-impact/run-local-agent.ts@@ -20,10 +20,13 @@ import {} from "./agent-runner";import { collectHighImpactArtifacts } from "./artifacts";import type { EvaluationToolCall } from "./validate";+import type { McpCatalogObservation } from "./evaluation-metrics";import { writeFontAssetFixtureFiles } from "./font-assets-fixture";import {compareEvaluationResult,+ isAggregateTokenBaselineNonRegressed,isEvaluationComparisonAccepted,+ shouldUpdateEvaluationBaselines,type EvaluationComparison,} from "./evaluation-regression";@@ -38,6 +41,13 @@ type AgentEvaluationReport = AgentEvaluationResult & {comparison: EvaluationComparison;};+type EvaluationTraceEvent = EvaluationToolCall | McpCatalogObservation;++const isCatalogObservation = (+ event: EvaluationTraceEvent+): event is McpCatalogObservation =>+ "kind" in event && event.kind === "tools-list";+const shellQuote = (value: string) => `'${value.replaceAll("'", `'"'"'`)}'`;const selectFixtures = (fixtureId: string | undefined) => {@@ -98,6 +108,7 @@ const runFixture = async ({shellQuote(codex),"exec","--ephemeral",+ "--ignore-user-config","--dangerously-bypass-approvals-and-sandbox","--skip-git-repo-check","--ignore-rules",@@ -112,11 +123,12 @@ const runFixture = async ({),].join(" ");let toolCalls: EvaluationToolCall[] = [];- const readToolCalls = async () =>+ let catalogObservations: McpCatalogObservation[] = [];+ const readTraceEvents = async () =>(await readFile(tracePath, "utf8").catch(() => "")).split("\n").filter(Boolean)- .map((line) => JSON.parse(line) as EvaluationToolCall);+ .map((line) => JSON.parse(line) as EvaluationTraceEvent);return await runHighImpactAgentEvaluation({fixture,target: { kind: "source", repositoryRoot },@@ -128,8 +140,14 @@ const runFixture = async ({model,env,getToolCalls: () => toolCalls,+ getCatalogObservations: () => catalogObservations,evaluate: async () => {- toolCalls = await readToolCalls();+ const traceEvents = await readTraceEvents();+ catalogObservations = traceEvents.filter(isCatalogObservation);+ toolCalls = traceEvents.filter(+ (event): event is EvaluationToolCall =>+ isCatalogObservation(event) === false+ );return evaluateHighImpactOutcome({fixture,project: fixtureApi.getProject(),@@ -204,6 +222,7 @@ const run = async () => {);const results: AgentEvaluationReport[] = [];const rawResults: AgentEvaluationResult[] = [];+ const baselines: AgentEvaluationResult[] = [];for (const fixture of fixtures) {const resultPath = resolve(process.env.WEBSTUDIO_HIGH_IMPACT_RESULT ??@@ -221,6 +240,9 @@ const run = async () => {...result,comparison: compareEvaluationResult(result, baseline),};+ if (baseline !== undefined) {+ baselines.push(baseline);+ }await writeFile(resultPath,`${JSON.stringify(report, undefined, 2)}\n`,@@ -231,7 +253,23 @@ const run = async () => {const evaluationsPassed = rawResults.every((result) => result.outcome === "passed");- if (options.updateBaselines && evaluationsPassed) {+ const comparisonsPassed = results.every(({ comparison }) =>+ isEvaluationComparisonAccepted({+ comparison,+ requireBaseline: options.requireBaseline,+ updateBaselines: options.updateBaselines,+ })+ );+ const baselinesUpdated = shouldUpdateEvaluationBaselines({+ updateBaselines: options.updateBaselines,+ evaluationsPassed,+ comparisonsPassed,+ aggregateTokensPassed: isAggregateTokenBaselineNonRegressed(+ rawResults,+ baselines+ ),+ });+ if (baselinesUpdated) {await mkdir(baselineDirectory, { recursive: true });await Promise.all(rawResults.map((result) =>@@ -243,20 +281,18 @@ const run = async () => {));}- const comparisonsPassed = results.every(({ comparison }) =>- isEvaluationComparisonAccepted({- comparison,- requireBaseline: options.requireBaseline,- updateBaselines: options.updateBaselines,- })- );- const outcome = evaluationsPassed && comparisonsPassed ? "passed" : "failed";+ const outcome =+ evaluationsPassed &&+ comparisonsPassed &&+ (options.updateBaselines === false || baselinesUpdated)+ ? "passed"+ : "failed";process.stdout.write(`${JSON.stringify({outcome,baselines: options.updateBaselines- ? evaluationsPassed+ ? baselinesUpdated? "updated": "not-updated": "compared",diff --git a/packages/cli/evaluations/high-impact/validate.test.ts b/packages/cli/evaluations/high-impact/validate.test.tsindex 24e2576aba..0c3081362a 100644--- a/packages/cli/evaluations/high-impact/validate.test.ts+++ b/packages/cli/evaluations/high-impact/validate.test.ts@@ -169,18 +169,17 @@ describe("font-assets evaluation", () => {values: { meta: fontAssetFixtureMeta },},})),- { name: "refresh" },- ...project.assets.map((asset) => ({- name: "get-asset",- arguments: { assetId: asset.id },- })),+ {+ name: "verify-font-assets",+ arguments: { assetIds: project.assets.map((asset) => asset.id) },+ },],});expect(result).toMatchObject({ passed: true, failures: [] });});- test("rejects a refresh before the final metadata update", () => {+ test("rejects verification before the final metadata update", () => {const project = clone(fontAssetsFixture.project);const result = evaluateHighImpactOutcome({fixture: fontAssetsFixture,@@ -188,7 +187,10 @@ describe("font-assets evaluation", () => {toolCalls: [{ name: "meta.guide" },{ name: "update-asset" },- { name: "refresh" },+ {+ name: "verify-font-assets",+ arguments: { assetIds: ["asset-1", "asset-2"] },+ },{ name: "update-asset" },],});@@ -271,6 +273,28 @@ describe("design-input evaluation", () => {expect(result).toMatchObject({ passed: true, failures: [] });});+ test("accepts one responsive page verification as audit and viewport evidence", () => {+ const result = evaluateHighImpactOutcome({+ fixture: designInputFixture,+ project: addDesignPage(),+ toolCalls: [+ ...designCalls.filter(+ (call) => call.name !== "screenshot" && call.name !== "audit"+ ),+ {+ name: "verify-page-responsive",+ arguments: {+ viewports: [+ { width: 1440, height: 900 },+ { width: 390, height: 844 },+ ],+ },+ },+ ],+ });+ expect(result).toMatchObject({ passed: true, failures: [] });+ });+test("rejects unsupported components", () => {const project = addDesignPage();project.instances.find(@@ -301,6 +325,25 @@ describe("design-input evaluation", () => {expect(result.checks.expressions).toBe("failed");});+ test("accepts a parenthesized object expression", () => {+ const project = addDesignPage();+ project.props.push({+ id: "style-expression",+ instanceId: "summer-heading",+ name: "style",+ type: "expression",+ value: '({ display: state === "ready" ? "block" : "none" })',+ });++ const result = evaluateHighImpactOutcome({+ fixture: designInputFixture,+ project,+ toolCalls: designCalls,+ });++ expect(result.checks.expressions).toBe("passed");+ });+test("rejects broad or unnecessarily verbose reads", () => {const result = evaluateHighImpactOutcome({fixture: designInputFixture,diff --git a/packages/cli/evaluations/high-impact/validate.ts b/packages/cli/evaluations/high-impact/validate.tsindex 29ad1fabed..4de8571721 100644--- a/packages/cli/evaluations/high-impact/validate.ts+++ b/packages/cli/evaluations/high-impact/validate.ts@@ -21,9 +21,12 @@ export type EvaluationToolCall = {arguments?: Record<string, unknown>;startedAtMs?: number;durationMs?: number;+ responseBytes?: number;planned?: true;committed?: true;isError?: boolean;+ errorCode?: string;+ errorIssues?: Array<{ code: string; path: string }>;};export type EvaluationArtifact = {@@ -133,7 +136,10 @@ const getEditablePageState = (project: EvaluationProject) => ({const isValidExpression = (value: string) => {try {- const expression = parseExpressionAt(value, 0, { ecmaVersion: "latest" });+ const expression = parseExpressionAt(value, 0, {+ ecmaVersion: "latest",+ preserveParens: true,+ });return value.slice(expression.end).trim() === "";} catch {return false;@@ -168,6 +174,11 @@ const hasPassedEvidence = (kind: EvaluationArtifact["kind"]) =>hasSuccessfulCall(input.toolCalls, kind) ||+ (kind === "screenshot" &&+ (hasSuccessfulCall(input.toolCalls, "screenshot.responsive") ||+ hasSuccessfulCall(input.toolCalls, "verify-page-responsive"))) ||+ (kind === "audit" &&+ hasSuccessfulCall(input.toolCalls, "verify-page-responsive")) ||(input.artifacts ?? []).some((artifact) => artifact.kind === kind && artifact.passed);@@ -182,6 +193,22 @@ const getScreenshots = (input: HighImpactEvaluationInput) => [| undefined,passed: true,})),+ ...input.toolCalls+ .filter(+ (call) =>+ (call.name === "screenshot.responsive" ||+ call.name === "verify-page-responsive") &&+ call.isError !== true+ )+ .flatMap((call) =>+ Array.isArray(call.arguments?.viewports)+ ? call.arguments.viewports.map((viewport) => ({+ kind: "screenshot" as const,+ viewport: viewport as { width: number; height: number },+ passed: true,+ }))+ : []+ ),...(input.artifacts ?? []).filter((artifact) => artifact.kind === "screenshot" && artifact.passed),@@ -245,7 +272,8 @@ const validateAuth = (checks,failures,"bindingVerification",- hasSuccessfulCall(input.toolCalls, "verify-bindings"),+ hasSuccessfulCall(input.toolCalls, "verify-bindings") ||+ hasSuccessfulCall(input.toolCalls, "insert-fragment-verified"),"The agent did not verify the persisted authentication bindings.");recordCheck(@@ -478,21 +506,20 @@ const validateFontAssets = (? [{ ...call, index }]: []);- const refreshIndex = input.toolCalls.findLastIndex(- (call) => call.name === "refresh" && call.isError !== true- );- const verificationReads = input.toolCalls.filter(- (call, index) =>- call.name === "get-asset" && call.isError !== true && index > refreshIndex+ const verificationCalls = input.toolCalls.flatMap((call, index) =>+ call.name === "verify-font-assets" && call.isError !== true+ ? [{ ...call, index }]+ : []);recordCheck(checks,failures,"metadataWorkflow",updateCalls.length >= expectedNames.size &&- refreshIndex > (updateCalls.at(-1)?.index ?? Number.POSITIVE_INFINITY) &&- verificationReads.length >= expectedNames.size,- "The agent did not update both font assets, refresh, and read both persisted assets afterward."+ verificationCalls.length === 1 &&+ verificationCalls[0]!.index >+ (updateCalls.at(-1)?.index ?? Number.POSITIVE_INFINITY),+ "The agent did not update both font assets and verify both persisted assets in one bounded call afterward.");const fontFaces = getFontFaces(fontAssets, { assetBaseUrl: "/assets/" });recordCheck(diff --git a/packages/cli/src/commands/mcp-preview.test.ts b/packages/cli/src/commands/mcp-preview.test.tsindex 41f352ad55..1cfc3ddb7b 100644--- a/packages/cli/src/commands/mcp-preview.test.ts+++ b/packages/cli/src/commands/mcp-preview.test.ts@@ -1003,6 +1003,63 @@ test("rejects a generated route that rendered Builder chrome", async () => {).rejects.toMatchObject({ code: "SCREENSHOT_NOT_GENERATED_SITE" });});+test("retries a managed generated route while the refreshed preview settles", async () => {+ const createResult = (generatedSiteRootPresent: boolean) => ({+ output: "account.png",+ browser: {+ browser: "chromium" as const,+ path: "/browser",+ source: "path" as const,+ },+ viewport: { width: 1280, height: 720 },+ fullPage: false,+ elapsedMs: 1,+ warnings: [],+ navigation: {+ requestedUrl: "http://127.0.0.1:5173/account",+ finalUrl: "http://127.0.0.1:5173/account",+ redirects: [],+ documentReadyState: "complete",+ generatedSiteRootPresent,+ layoutStable: true,+ },+ });+ const capture = vi+ .fn()+ .mockResolvedValueOnce(createResult(false))+ .mockResolvedValueOnce(createResult(true));+ const sleep = vi.fn(async () => undefined);+ const handlers = createMcpPreviewHandlers({+ preview: {+ status: vi.fn(() => ({+ url: "http://127.0.0.1:5173/",+ running: true,+ mode: "iterative" as const,+ })),+ startAndWait: vi.fn(),+ resolveUrl: vi.fn(() => "http://127.0.0.1:5173/account"),+ },+ isStale: () => false,+ createCaptureSession: vi.fn(() => ({+ capture,+ capturePage: vi.fn(),+ close: vi.fn(),+ })) as never,+ sleep,+ });++ await expect(+ handlers.captureScreenshot({+ path: "/account",+ viewport: { width: 1280, height: 720 },+ })+ ).resolves.toMatchObject({+ navigation: { generatedSiteRootPresent: true },+ });+ expect(capture).toHaveBeenCalledTimes(2);+ expect(sleep).toHaveBeenCalledWith(1000);+});+test("rejects resized generated routes that rendered Builder chrome", async () => {const capturePage = vi.fn(async () => [{diff --git a/packages/cli/src/commands/mcp-preview.ts b/packages/cli/src/commands/mcp-preview.tsindex 08302eae25..02be59bbac 100644--- a/packages/cli/src/commands/mcp-preview.ts+++ b/packages/cli/src/commands/mcp-preview.ts@@ -101,6 +101,8 @@ const isSameCaptureSessionConfig = () => left.browser === right.browser && left.browserPath === right.browserPath;const defaultPreviewSource = "session" satisfies PreviewSource;+const defaultSleep = (durationMs: number) =>+ new Promise<void>((resolve) => setTimeout(resolve, durationMs));const getPreviewSource = (source: PreviewSource | undefined): PreviewSource =>source ?? defaultPreviewSource;@@ -160,6 +162,7 @@ export const createMcpPreviewHandlers = ({prepareSessionDataFile,captureScreenshot = captureScreenshotWithBrowserInstall,createCaptureSession,+ sleep = defaultSleep,}: {preview: McpPreviewController;isStale?: () => boolean;@@ -169,6 +172,7 @@ export const createMcpPreviewHandlers = ({prepareSessionDataFile?: () => Promise<void>;captureScreenshot?: typeof captureScreenshotWithBrowserInstall;createCaptureSession?: typeof createScreenshotCaptureSession;+ sleep?: (durationMs: number) => Promise<void>;}) => {let captureSession:| ReturnType<typeof createScreenshotCaptureSession>@@ -407,9 +411,19 @@ export const createMcpPreviewHandlers = ({isManagedSessionPreviewCapture(input) &&createCaptureSession !== undefined) {- result = await (- await getCaptureSession(input)- ).capture(captureOptions);+ const captureSession = await getCaptureSession(input);+ result = await captureSession.capture(captureOptions);+ for (+ let retry = 0;+ retry < 2 && result.navigation?.generatedSiteRootPresent === false;+ retry += 1+ ) {+ progress?.report(+ "tool screenshot waiting for refreshed generated route"+ );+ await sleep(1000);+ result = await captureSession.capture(captureOptions);+ }} else {result = await captureScreenshot({...captureOptions,diff --git a/packages/cli/src/commands/mcp.test.ts b/packages/cli/src/commands/mcp.test.tsindex 178a2eb424..484c708c5e 100644--- a/packages/cli/src/commands/mcp.test.ts+++ b/packages/cli/src/commands/mcp.test.ts@@ -29,8 +29,98 @@ const {readPersistedMcpCheckpoint,updatePersistedMcpCheckpoint,executeMcpRunCall,+ resolveMcpPreviewInput,+ resolveMcpScreenshotInput,+ startMcpPreview,} = __testing__;+test("allocates an available port only when MCP preview omits one", async () => {+ const getAvailablePort = vi.fn(async () => 53124);++ await expect(+ resolveMcpPreviewInput({ source: "session" }, getAvailablePort)+ ).resolves.toEqual({ source: "session", port: 53124 });+ await expect(+ resolveMcpPreviewInput({ source: "session", port: 0 }, getAvailablePort)+ ).resolves.toEqual({ source: "session", port: 53124 });+ await expect(+ resolveMcpPreviewInput({ source: "session", port: 4173 }, getAvailablePort)+ ).resolves.toEqual({ source: "session", port: 4173 });+ expect(getAvailablePort).toHaveBeenCalledTimes(2);+ expect(getAvailablePort).toHaveBeenNthCalledWith(1, "127.0.0.1");+ expect(getAvailablePort).toHaveBeenNthCalledWith(2, "127.0.0.1");+});++test("allocates and reuses a collision-free port for automatic screenshots", async () => {+ const getAvailablePort = vi.fn(async () => 53124);++ await expect(+ resolveMcpScreenshotInput(+ {+ path: "/account",+ browser: "auto",+ viewport: { width: 390, height: 844 },+ },+ { running: false, url: "http://127.0.0.1:5173/" },+ getAvailablePort+ )+ ).resolves.toMatchObject({ port: 53124 });+ await expect(+ resolveMcpScreenshotInput(+ {+ path: "/account",+ browser: "auto",+ viewport: { width: 1440, height: 900 },+ },+ { running: true, url: "http://127.0.0.1:53125/" },+ getAvailablePort+ )+ ).resolves.toMatchObject({ port: 53125 });+ await expect(+ resolveMcpScreenshotInput(+ {+ path: "/account",+ browser: "auto",+ port: 4173,+ viewport: { width: 1440, height: 900 },+ },+ { running: false, url: "http://127.0.0.1:5173/" },+ getAvailablePort+ )+ ).resolves.toMatchObject({ port: 4173 });+ expect(getAvailablePort).toHaveBeenCalledOnce();+});++test("retries automatic MCP preview ports after a startup race", async () => {+ const getAvailablePort = vi+ .fn()+ .mockResolvedValueOnce(53124)+ .mockResolvedValueOnce(53125);+ const startPreview = vi+ .fn()+ .mockRejectedValueOnce(new Error("Preview server exited before ready"))+ .mockResolvedValueOnce({ url: "http://127.0.0.1:53125/" });+ const sleep = vi.fn(async () => undefined);++ await expect(+ startMcpPreview({+ input: { source: "session" },+ getAvailablePort,+ startPreview,+ sleep,+ })+ ).resolves.toEqual({ url: "http://127.0.0.1:53125/" });+ expect(startPreview).toHaveBeenNthCalledWith(1, {+ source: "session",+ port: 53124,+ });+ expect(startPreview).toHaveBeenNthCalledWith(2, {+ source: "session",+ port: 53125,+ });+ expect(sleep).toHaveBeenCalledWith(500);+});+test("classifies structured MCP tool failures for nonzero CLI exit", () => {expect(isMcpToolCallFailure({diff --git a/packages/cli/src/commands/mcp.ts b/packages/cli/src/commands/mcp.tsindex 220a23b88d..613de0bee9 100644--- a/packages/cli/src/commands/mcp.ts+++ b/packages/cli/src/commands/mcp.ts@@ -7,6 +7,8 @@ import {createMcpStdioTransport,getProjectSessionMcpCheckpoint,isReadOnlyProjectSessionMcpToolCall,+ type ProjectSessionPreviewInput,+ type ProjectSessionScreenshotInput,type ProjectSessionMcpTool,} from "@webstudio-is/project-build/mcp";import type { BuilderNamespace } from "@webstudio-is/project-build/contracts";@@ -825,6 +827,72 @@ const assertSingleOpCallToolSupported = (tool: string) => {}};+const resolveMcpPreviewInput = async (+ input: ProjectSessionPreviewInput,+ getAvailablePort: (host?: string) => Promise<number> = findAvailablePort+) => {+ if (input.port !== undefined && input.port !== 0) {+ return input;+ }+ return {+ ...input,+ port: await getAvailablePort(input.host ?? "127.0.0.1"),+ };+};++const resolveMcpScreenshotInput = async (+ input: ProjectSessionScreenshotInput,+ previewStatus: { running: boolean; url: string },+ getAvailablePort: (host?: string) => Promise<number> = findAvailablePort+) => {+ if (+ input.url !== undefined ||+ input.baseUrl !== undefined ||+ input.source === "local" ||+ (input.port !== undefined && input.port !== 0)+ ) {+ return input;+ }+ const host = input.host ?? "127.0.0.1";+ if (previewStatus.running) {+ const previewUrl = new URL(previewStatus.url);+ if (input.host === undefined || previewUrl.hostname === input.host) {+ const previewPort = Number(previewUrl.port);+ if (Number.isInteger(previewPort) && previewPort > 0) {+ return { ...input, port: previewPort };+ }+ }+ }+ return { ...input, port: await getAvailablePort(host) };+};++const startMcpPreview = async <Result>({+ input,+ startPreview,+ getAvailablePort = findAvailablePort,+ sleep = async (durationMs) =>+ await new Promise<void>((resolve) => setTimeout(resolve, durationMs)),+}: {+ input: ProjectSessionPreviewInput;+ startPreview: (input: ProjectSessionPreviewInput) => Promise<Result>;+ getAvailablePort?: (host?: string) => Promise<number>;+ sleep?: (durationMs: number) => Promise<void>;+}) => {+ const attempts = input.port === undefined || input.port === 0 ? 5 : 1;+ for (let attempt = 0; attempt < attempts; attempt += 1) {+ const resolvedInput = await resolveMcpPreviewInput(input, getAvailablePort);+ try {+ return await startPreview(resolvedInput);+ } catch (error) {+ if (attempt === attempts - 1) {+ throw error;+ }+ await sleep(500);+ }+ }+ throw new Error("MCP preview did not start.");+};+const createCliMcpHost = async ({projectRoot = cwd(),projectId,@@ -999,29 +1067,39 @@ const createCliMcpHost = async ({};},async startPreview(input, progress) {- const resolvedInput =- input.port === 0- ? {- ...input,- port: await findAvailablePort(input.host ?? "127.0.0.1"),- }- : input;- const result = await previewHandlers.startPreview(- resolvedInput,- progress- );- return result;+ return await startMcpPreview({+ input,+ startPreview: async (resolvedInput) =>+ await previewHandlers.startPreview(resolvedInput, progress),+ });},async getPreviewStatus() {return preview.status();},stopPreview: previewHandlers.stopPreview,async captureScreenshot(input) {- const result = await previewHandlers.captureScreenshot(input);+ const resolvedInput = await resolveMcpScreenshotInput(+ input,+ preview.status()+ );+ const result = await previewHandlers.captureScreenshot(resolvedInput);return toProjectSessionScreenshotResult(result);},async capturePageScreenshots(inputs) {- const results = await previewHandlers.capturePageScreenshots(inputs);+ const firstInput = inputs[0];+ if (firstInput === undefined) {+ return [];+ }+ const resolvedFirstInput = await resolveMcpScreenshotInput(+ firstInput,+ preview.status()+ );+ const resolvedInputs = inputs.map((input) => ({+ ...input,+ port: resolvedFirstInput.port,+ }));+ const results =+ await previewHandlers.capturePageScreenshots(resolvedInputs);return results.map(toProjectSessionScreenshotResult);},async diffScreenshots(input) {@@ -1152,6 +1230,9 @@ export const __testing__ = {readPersistedMcpCheckpoint,updatePersistedMcpCheckpoint,executeMcpRunCall,+ resolveMcpPreviewInput,+ resolveMcpScreenshotInput,+ startMcpPreview,};export const mcpSingleOpCall = async (options: McpSingleOpCallOptions) => {diff --git a/packages/project-build/src/mcp.test.ts b/packages/project-build/src/mcp.test.tsindex e1aa53a4eb..805736b2dc 100644--- a/packages/project-build/src/mcp.test.ts+++ b/packages/project-build/src/mcp.test.ts@@ -23,6 +23,7 @@ import {listProjectSessionMcpTools,type PublicMcpOperation,type ProjectSessionMcpGuidance,+ type ProjectSessionScreenshotInput,} from "./mcp";import { getComponentTemplates } from "./runtime/component-templates";import { createEmptyWebstudioFragment } from "./runtime/component-template";@@ -780,6 +781,7 @@ describe("project session mcp adapter", () => {"status","refresh","reset-session",+ "insert-fragment-verified",]);expect(toolNames).toContain("insert-fragment");const assetOperationTools = listProjectSessionMcpTools(@@ -1002,6 +1004,10 @@ describe("project session mcp adapter", () => {]);const fragmentSchema = insertFragmentTool?.inputSchema.properties?.fragment;expect(fragmentSchema).toEqual(expect.objectContaining({ type: "string" }));+ expect(+ tools.find((tool) => tool.name === "insert-fragment-verified")+ ?.inputSchema.required+ ).toEqual(["parentInstanceId", "fragment", "pagePath"]);const jsxDescription =typeof fragmentSchema === "object" &&"description" in fragmentSchema &&@@ -2277,6 +2283,114 @@ describe("project session mcp adapter", () => {expect(call?.input).not.toHaveProperty("source");});+ test("inserts a fragment and verifies persisted bindings in one call", async () => {+ const executeOperation = createExecuteOperation(async ({ command }) =>+ command === "insert-fragment"+ ? createEnvelope({+ operationId: "instances.insertFragment",+ result: { instanceIds: ["section-id"] },+ state: { committed: true, freshness: {} },+ })+ : createEnvelope({+ operationId: "project.verifyBindings",+ result: {+ summary: { bindingsChecked: 2, findings: 0 },+ findings: [],+ },+ })+ );+ const adapter = createProjectSessionMcpCore({+ operations: publicMcpOperations,+ createProjectSession: createSessionFactory(),+ executeOperation,+ });++ expect(adapter.listTools().map(({ name }) => name)).toContain(+ "insert-fragment-verified"+ );+ const result = await adapter.callTool({+ name: "insert-fragment-verified",+ input: {+ parentInstanceId: "root-id",+ pagePath: "/account",+ fragment: '<ws.element ws:tag="section" />',+ },+ });++ expect(executeOperation).toHaveBeenNthCalledWith(+ 1,+ expect.objectContaining({+ command: "insert-fragment",+ dryRun: false,+ })+ );+ expect(executeOperation).toHaveBeenNthCalledWith(2, {+ command: "verify-bindings",+ input: { pagePath: "/account", limit: 200 },+ dryRun: false,+ });+ expect(result.structuredContent).toMatchObject({+ ok: true,+ data: {+ insertion: { instanceIds: ["section-id"] },+ verification: {+ summary: { bindingsChecked: 2, findings: 0 },+ findings: [],+ },+ },+ meta: {+ session: {+ operationId: "workflow.insert-fragment-verified",+ committed: true,+ },+ },+ });++ const failingVerification = createExecuteOperation(async ({ command }) => {+ if (command === "verify-bindings") {+ throw new Error("verification unavailable");+ }+ return createEnvelope({+ operationId: "instances.insertFragment",+ result: { instanceIds: ["committed-section-id"] },+ state: { committed: true, freshness: {} },+ });+ });+ const failureAdapter = createProjectSessionMcpCore({+ operations: publicMcpOperations,+ createProjectSession: createSessionFactory(),+ executeOperation: failingVerification,+ });+ const failedVerificationResult = await failureAdapter.callTool({+ name: "insert-fragment-verified",+ input: {+ parentInstanceId: "root-id",+ pagePath: "/account",+ fragment: '<ws.element ws:tag="section" />',+ },+ });++ expect(failedVerificationResult).toMatchObject({+ isError: true,+ structuredContent: {+ ok: false,+ data: {+ insertion: { instanceIds: ["committed-section-id"] },+ verification: { status: "failed-after-commit" },+ },+ error: { code: "POST_COMMIT_VERIFICATION_FAILED" },+ meta: { session: { committed: true } },+ },+ });+ if (failedVerificationResult.structuredContent.ok !== false) {+ throw new Error("Expected post-commit verification to fail");+ }+ expect(failedVerificationResult.structuredContent.error.message).toContain(+ "Do not retry the insertion"+ );+ expect(failingVerification).toHaveBeenCalledTimes(2);+ });+test("converts semantic Collection item jsx before executing one atomic operation", async () => {const executeOperation = createExecuteOperation(async () =>createEnvelope({@@ -2580,7 +2694,7 @@ describe("project session mcp adapter", () => {name: "create-page",input: {name: "Harbor Ops Design System",- path: "/design-system",+ path: "design-system",title: "Harbor Ops Design System",description:"A realistic component coverage page for the Harbor Ops logistics product design system.",@@ -2660,6 +2774,29 @@ describe("project session mcp adapter", () => {});});+ test("bounds large style mutation results at the MCP boundary", async () => {+ const styleKeys = Array.from(+ { length: 100 },+ (_, index) => `instance:base:property-${index}:`+ );+ const { adapter } = createTestMcpCore({+ operationId: "styles.updateDeclarations",+ result: { styleKeys },+ });++ const result = await adapter.callTool({+ name: "update-styles",+ input: { updates: [] },+ });++ expect(result.structuredContent.data).toEqual({+ styleKeys: styleKeys.slice(0, 20),+ styleKeyCount: 100,+ styleKeysTruncated: true,+ });+ expect(JSON.stringify(result.structuredContent).length).toBeLessThan(1500);+ });+test("parses stringified structured fields using the MCP input schema", async () => {const { adapter, executeOperation } = createTestMcpCore({operationId: "pages.update",@@ -2806,7 +2943,7 @@ describe("project session mcp adapter", () => {});});- test("keeps primitive strings in unconstrained schema fields unchanged", async () => {+ test("normalizes primitive CSS values to typed keyword values", async () => {const updates = [{instanceId: "instance-id",@@ -2826,7 +2963,122 @@ describe("project session mcp adapter", () => {expect(executeOperation).toHaveBeenCalledWith({command: "update-styles",+ input: {+ updates: [+ {+ instanceId: "instance-id",+ property: "font-family",+ value: { type: "keyword", value: "TokenFont" },+ },+ ],+ },+ dryRun: false,+ });+ });++ test("normalizes malformed typed CSS literals to keyword values", async () => {+ const updates = [+ {+ instanceId: "spacing-instance",+ property: "padding",+ value: { type: "unit", value: "48px" },+ },+ {+ instanceId: "gap-instance",+ property: "gap",+ value: { type: "length", value: "2rem" },+ },+ {+ instanceId: "color-instance",+ property: "color",+ value: { type: "color", value: "#fff" },+ },+ {+ instanceId: "structured-color-instance",+ property: "color",+ value: {+ type: "color",+ colorSpace: "srgb",+ components: [1, 1, 1],+ alpha: 1,+ value: "#fff",+ },+ },+ ];+ const { adapter, executeOperation } = createTestMcpCore({+ operationId: "styles.updateDeclarations",+ result: { styleKeys: [] },+ });++ await adapter.callTool({+ name: "update-styles",input: { updates },+ });++ expect(executeOperation).toHaveBeenCalledWith({+ command: "update-styles",+ input: {+ updates: [+ ...updates.slice(0, 3).map((update) => ({+ ...update,+ value: { type: "keyword", value: update.value.value },+ })),+ updates[3],+ ],+ },+ dryRun: false,+ });+ });++ test("flattens grouped style declarations before validation", async () => {+ const { adapter, executeOperation } = createTestMcpCore({+ operationId: "styles.updateDeclarations",+ result: { styleKeys: [] },+ });++ await adapter.callTool({+ name: "update-styles",+ input: {+ updates: [+ {+ instanceId: "hero-instance",+ breakpoint: "mobile-breakpoint",+ styles: {+ display: "grid",+ gap: { type: "unit", value: "24px" },+ },+ },+ {+ instanceId: "title-instance",+ declarations: { color: "#123456" },+ },+ ],+ },+ });++ expect(executeOperation).toHaveBeenCalledWith({+ command: "update-styles",+ input: {+ updates: [+ {+ instanceId: "hero-instance",+ breakpoint: "mobile-breakpoint",+ property: "display",+ value: { type: "keyword", value: "grid" },+ },+ {+ instanceId: "hero-instance",+ breakpoint: "mobile-breakpoint",+ property: "gap",+ value: { type: "keyword", value: "24px" },+ },+ {+ instanceId: "title-instance",+ property: "color",+ value: { type: "keyword", value: "#123456" },+ },+ ],+ },dryRun: false,});});@@ -3489,10 +3741,31 @@ describe("project session mcp adapter", () => {refresh: vi.fn(),reset: vi.fn(),});+ const uploadAssetsOperation = {+ ...publicMcpOperations[0]!,+ command: "upload-assets" as const,+ description: "Upload multiple assets",+ };+ const contextOperations = [+ "list-assets",+ "list-variables",+ "get-asset",+ ].map((command) =>+ publicOperation({+ command,+ id: `test.${command}`,+ description: command,+ })+ );const adapter = createProjectSessionMcpCore({- operations: publicMcpOperations,+ operations: [+ ...publicMcpOperations,+ uploadAssetsOperation,+ ...contextOperations,+ ],createProjectSession: createSessionFactory(session),executeOperation: createExecuteOperation(),+ capturePageScreenshots: vi.fn(async () => []),});const index = await adapter.callTool({ name: "meta.index" });@@ -4118,6 +4391,29 @@ describe("project session mcp adapter", () => {name: "meta.guide",input: { brief: "Add a section that preserves this Craft project" },});+ const authenticatedPageGuideTools = (+ authenticatedPageGuide.structuredContent.data as {+ tools: Array<Record<string, unknown>>;+ }+ ).tools;+ expect(+ authenticatedPageGuideTools.every(+ (tool) => Object.keys(tool).join(",") === "name"+ )+ ).toBe(true);+ const designInputGuideTools = (+ designInputGuide.structuredContent.data as {+ tools: Array<Record<string, unknown>>;+ }+ ).tools;+ expect(+ designInputGuideTools.every((tool) => {+ const keys = Object.keys(tool).join(",");+ return tool.name === "update-styles"+ ? keys === "name,inputSchema"+ : keys === "name";+ })+ ).toBe(true);const getComponentToolNames = (getComponentDetails.structuredContent.data as {tools: { name: string }[];@@ -4141,6 +4437,9 @@ describe("project session mcp adapter", () => {}expect(jsonLdGuide.structuredContent.data).toEqual(expect.objectContaining({+ more: expect.stringContaining(+ "client loads each named tool's exact argument contract"+ ),workflow: expect.arrayContaining([expect.stringContaining("do not use update-page custom metadata"),expect.stringContaining("Insert JsonLd under HeadSlot"),@@ -4179,16 +4478,43 @@ describe("project session mcp adapter", () => {expect.objectContaining({workflow: expect.arrayContaining([expect.stringContaining("existing auth resources"),+ expect.stringContaining("Call inspect-auth-context exactly once"),+ expect.stringContaining(+ "Do not call get-page-by-path to confirm that /account is absent"+ ),+ expect.stringContaining("Do not call meta.index after this guide"),expect.stringContaining("Never place credentials"),expect.stringContaining("signed-out, loading, signed-in"),expect.stringContaining("not an authorization boundary"),- expect.stringContaining("call verify-bindings"),+ expect.stringContaining(+ "Use create-page's returned rootInstanceId directly"+ ),+ expect.stringContaining(+ "Do not repeat list-variables when the fixture variable is not referenced"+ ),+ expect.stringContaining("copy its fixed request URL exactly"),+ expect.stringContaining(+ 'url:"/api/auth/session",headers:[],searchParams:[]'+ ),+ expect.stringContaining(+ "Do not call selector-based structural tools"+ ),+ expect.stringContaining("one expression-free semantic fragment"),+ expect.stringContaining("Use that exact fragment verbatim"),+ expect.stringContaining(+ "Do not bind that server-only resource into local preview rendering"+ ),+ expect.stringContaining("insert-fragment-verified"),+ expect.stringContaining("Call verify-page-responsive once"),+ expect.stringContaining(+ "Do not call preview.start, screenshot, screenshot.responsive, or audit separately"+ ),+ expect.stringContaining("bundled audit is the static evidence"),]),tools: expect.arrayContaining([expect.objectContaining({ name: "list-instances" }),- expect.objectContaining({ name: "insert-fragment" }),- expect.objectContaining({ name: "verify-bindings" }),- expect.objectContaining({ name: "audit" }),+ expect.objectContaining({ name: "insert-fragment-verified" }),+ expect.objectContaining({ name: "verify-page-responsive" }),]),}));@@ -4197,31 +4523,71 @@ describe("project session mcp adapter", () => {workflow: expect.arrayContaining([expect.stringContaining("returned asset ids directly"),expect.stringContaining("without re-uploading"),- expect.stringContaining('"namespaces":["assets"]'),+ expect.stringContaining("verify-font-assets exactly once"),+ expect.stringContaining(+ "do not call refresh or get-asset separately"+ ),]),tools: expect.arrayContaining([- expect.objectContaining({ name: "refresh" }),+ expect.objectContaining({ name: "verify-font-assets" }),]),}));+ expect(fontAssetGuide.structuredContent.data).not.toHaveProperty("brief");+ for (const tool of (+ fontAssetGuide.structuredContent.data as {+ tools: Array<Record<string, unknown>>;+ }+ ).tools) {+ expect(Object.keys(tool)).toEqual(+ tool.name === "upload-assets" ? ["name", "mcpExamples"] : ["name"]+ );+ }expect(designInputGuide.structuredContent.data).toEqual(expect.objectContaining({workflow: expect.arrayContaining([expect.stringContaining("Interpret the supplied design"),expect.stringContaining(- "Before the first mutation, call list-breakpoints and list-design-tokens"+ "Before the first mutation, call inspect-design-context exactly once"),+ expect.stringContaining(+ "instead of calling list-pages, list-breakpoints"+ ),+ expect.stringContaining("Do not call meta.index"),+ expect.stringContaining("Call create-page exactly once"),+ expect.stringContaining(+ "Do not call list-instances after the first mutation"+ ),+ expect.stringContaining("Do not call get-styles"),+ expect.stringContaining("call verify-page-responsive once"),+ expect.stringContaining("Call insert-fragment-verified exactly once"),+ expect.stringContaining('{"pagePath":"/summer"}'),+ expect.stringContaining("exactly the two supplied viewports"),+ expect.stringContaining("bundled audit is the static evidence"),expect.stringContaining("parallel design system"),expect.stringContaining("semantic editable structure"),expect.stringContaining("actual breakpoint ranges"),- expect.stringContaining("Run rendered audit"),+ expect.stringContaining(+ 'Represent literal CSS values as {"type":"keyword","value":"..."}'+ ),+ expect.stringContaining(+ "Do not call preview.start, screenshot, screenshot.responsive, or audit separately"+ ),]),tools: expect.arrayContaining([- expect.objectContaining({ name: "list-breakpoints" }),+ expect.objectContaining({ name: "inspect-design-context" }),expect.objectContaining({ name: "components.search" }),- expect.objectContaining({ name: "insert-fragment" }),+ expect.objectContaining({ name: "insert-fragment-verified" }),expect.objectContaining({ name: "attach-design-token" }),- expect.objectContaining({ name: "update-styles" }),+ expect.objectContaining({ name: "verify-page-responsive" }),+ expect.objectContaining({+ name: "update-styles",+ inputSchema: expect.objectContaining({+ properties: expect.objectContaining({+ updates: expect.objectContaining({ type: "array" }),+ }),+ }),+ }),]),}));@@ -5469,6 +5835,18 @@ describe("project session mcp adapter", () => {elapsedMs: 12,warnings: [],}));+ const capturePageScreenshots = vi.fn(+ async (inputs: readonly ProjectSessionScreenshotInput[]) =>+ inputs.map((input) => ({+ output: `/tmp/${input.viewport.width}.png`,+ browserPath: "/usr/bin/chromium",+ browser: "chromium" as const,+ viewport: input.viewport,+ fullPage: input.fullPage ?? false,+ elapsedMs: 12,+ warnings: [],+ }))+ );const adapterWithoutScreenshot = createProjectSessionMcpCore({operations: publicMcpOperations,createProjectSession: createSessionFactory(session),@@ -5480,6 +5858,12 @@ describe("project session mcp adapter", () => {executeOperation: createExecuteOperation(),captureScreenshot,});+ const adapterWithResponsiveScreenshot = createProjectSessionMcpCore({+ operations: publicMcpOperations,+ createProjectSession: createSessionFactory(session),+ executeOperation: createExecuteOperation(),+ capturePageScreenshots,+ });const adapterWithScreenshotDiff = createProjectSessionMcpCore({operations: publicMcpOperations,createProjectSession: createSessionFactory(session),@@ -5493,6 +5877,9 @@ describe("project session mcp adapter", () => {expect(adapterWithoutScreenshot.listTools().map((tool) => tool.name)).not.toContain("screenshot.diff");+ expect(+ adapterWithoutScreenshot.listTools().map((tool) => tool.name)+ ).not.toContain("screenshot.responsive");expect(adapterWithScreenshot.listTools().map((tool) => tool.name)).toContain("screenshot");@@ -5502,6 +5889,12 @@ describe("project session mcp adapter", () => {expect(adapterWithScreenshotDiff.listTools().map((tool) => tool.name)).toContain("screenshot.diff");+ expect(+ adapterWithResponsiveScreenshot.listTools().map((tool) => tool.name)+ ).toContain("screenshot.responsive");+ expect(+ adapterWithResponsiveScreenshot.listTools().map((tool) => tool.name)+ ).toContain("verify-page-responsive");const result = await adapterWithScreenshot.callTool({name: "screenshot",@@ -5556,6 +5949,63 @@ describe("project session mcp adapter", () => {},meta: {},});++ const responsiveResult = await adapterWithResponsiveScreenshot.callTool({+ name: "screenshot.responsive",+ input: {+ path: "/pricing",+ viewports: [+ { width: 1440, height: 900 },+ { width: 390, height: 844 },+ ],+ fullPage: true,+ source: "session",+ },+ });++ expect(capturePageScreenshots).toHaveBeenCalledWith(+ [+ expect.objectContaining({+ path: "/pricing",+ viewport: { width: 1440, height: 900 },+ fullPage: true,+ source: "session",+ }),+ expect.objectContaining({+ path: "/pricing",+ viewport: { width: 390, height: 844 },+ fullPage: true,+ source: "session",+ }),+ ],+ expect.objectContaining({ report: expect.any(Function) })+ );+ expect(responsiveResult.structuredContent.data).toEqual({+ screenshots: [+ expect.objectContaining({ viewport: { width: 1440, height: 900 } }),+ expect.objectContaining({ viewport: { width: 390, height: 844 } }),+ ],+ });++ const verificationResult = await adapterWithResponsiveScreenshot.callTool({+ name: "verify-page-responsive",+ input: {+ path: "/pricing",+ viewports: [+ { width: 1440, height: 900 },+ { width: 390, height: 844 },+ ],+ source: "session",+ },+ });++ expect(verificationResult.structuredContent.data).toEqual({+ screenshots: [+ expect.objectContaining({ viewport: { width: 1440, height: 900 } }),+ expect.objectContaining({ viewport: { width: 390, height: 844 } }),+ ],+ audit: undefined,+ });});test("omits screenshot diff guidance when diff runner is not injected", async () => {@@ -6037,6 +6487,10 @@ describe("project session mcp adapter", () => {"preview.stop",]));+ expect(+ adapter.listTools().find((tool) => tool.name === "preview.start")+ ?.mcpExamples+ ).toEqual([{ source: "session" }]);const started = await adapter.callTool({name: "preview.start",@@ -6200,6 +6654,173 @@ describe("project session mcp adapter", () => {);});+ test("bundles bounded authentication discovery into one focused call", async () => {+ const commands = [+ "get-project-settings",+ "list-pages",+ "list-resources",+ "list-variables",+ ] as const;+ const operations = [+ ...publicMcpOperations.filter(+ (operation) => commands.includes(operation.command as never) === false+ ),+ ...commands.map((command) =>+ publicOperation({+ command,+ id: `test.${command}`,+ description: command,+ })+ ),+ ];+ const executeOperation = createExecuteOperation(+ async ({ command, input }) =>+ createEnvelope({+ operationId: `test.${command}`,+ result: { command, input },+ })+ );+ const adapter = createProjectSessionMcpCore({+ operations,+ createProjectSession: createSessionFactory(),+ executeOperation,+ });++ expect(adapter.listTools().map(({ name }) => name)).toContain(+ "inspect-auth-context"+ );+ const guide = await adapter.callTool({+ name: "meta.guide",+ input: { brief: "Create an authenticated page" },+ });+ const guideToolNames = (+ guide.structuredContent.data as { tools: Array<{ name: string }> }+ ).tools.map(({ name }) => name);+ expect(guideToolNames).toContain("inspect-auth-context");+ expect(guideToolNames).not.toEqual(expect.arrayContaining([...commands]));++ const result = await adapter.callTool({ name: "inspect-auth-context" });++ expect(result.structuredContent.data).toEqual({+ projectSettings: { command: "get-project-settings", input: {} },+ pages: { command: "list-pages", input: { limit: 50 } },+ resources: { command: "list-resources", input: { limit: 50 } },+ variables: { command: "list-variables", input: { limit: 50 } },+ });+ expect(executeOperation).toHaveBeenCalledTimes(4);+ });++ test("bundles bounded design discovery into one focused call", async () => {+ const commands = [+ "list-pages",+ "list-breakpoints",+ "list-design-tokens",+ "list-assets",+ "list-variables",+ ] as const;+ const operations = [+ ...publicMcpOperations.filter(+ (operation) => commands.includes(operation.command as never) === false+ ),+ ...commands.map((command) =>+ publicOperation({+ command,+ id: `test.${command}`,+ description: command,+ })+ ),+ ];+ const executeOperation = createExecuteOperation(+ async ({ command, input }) =>+ createEnvelope({+ operationId: `test.${command}`,+ result: { command, input },+ })+ );+ const adapter = createProjectSessionMcpCore({+ operations,+ createProjectSession: createSessionFactory(),+ executeOperation,+ });++ expect(adapter.listTools().map(({ name }) => name)).toContain(+ "inspect-design-context"+ );+ const guide = await adapter.callTool({+ name: "meta.guide",+ input: { brief: "Recreate this design as a responsive page" },+ });+ const guideToolNames = (+ guide.structuredContent.data as { tools: Array<{ name: string }> }+ ).tools.map(({ name }) => name);+ expect(guideToolNames).toContain("inspect-design-context");+ expect(guideToolNames).not.toEqual(expect.arrayContaining([...commands]));++ const result = await adapter.callTool({ name: "inspect-design-context" });++ expect(result.structuredContent.data).toEqual({+ pages: { command: "list-pages", input: { limit: 50 } },+ breakpoints: { command: "list-breakpoints", input: {} },+ designTokens: { command: "list-design-tokens", input: { limit: 50 } },+ assets: { command: "list-assets", input: { limit: 50 } },+ variables: { command: "list-variables", input: { limit: 50 } },+ });+ expect(executeOperation).toHaveBeenCalledTimes(5);+ });++ test("refreshes and verifies several font assets in one call", async () => {+ const session = createSession({ refresh: vi.fn() });+ const operations = [+ ...publicMcpOperations,+ publicOperation({+ command: "get-asset",+ id: "assets.get",+ description: "Get asset",+ }),+ ];+ const executeOperation = createExecuteOperation(+ async ({ command, input }) =>+ createEnvelope({+ operationId: `test.${command}`,+ result: { command, input },+ })+ );+ const adapter = createProjectSessionMcpCore({+ operations,+ createProjectSession: createSessionFactory(session),+ executeOperation,+ });++ expect(adapter.listTools().map(({ name }) => name)).toContain(+ "verify-font-assets"+ );+ const guide = await adapter.callTool({+ name: "meta.guide",+ input: { brief: "Upload and manage font assets" },+ });+ const guideToolNames = (+ guide.structuredContent.data as { tools: Array<{ name: string }> }+ ).tools.map(({ name }) => name);+ expect(guideToolNames).toContain("verify-font-assets");+ expect(guideToolNames).not.toEqual(+ expect.arrayContaining(["refresh", "get-asset"])+ );++ const result = await adapter.callTool({+ name: "verify-font-assets",+ input: { assetIds: ["asset-regular", "asset-bold"] },+ });++ expect(session.refresh).toHaveBeenCalledWith(["assets"]);+ expect(result.structuredContent.data).toEqual({+ assets: [+ { command: "get-asset", input: { assetId: "asset-regular" } },+ { command: "get-asset", input: { assetId: "asset-bold" } },+ ],+ });+ expect(executeOperation).toHaveBeenCalledTimes(2);+ });+test("rejects unknown tools before calling the operation executor", async () => {const createProjectSession = createSessionFactory();const executeOperation = createExecuteOperation();@@ -6534,65 +7155,86 @@ describe("project session mcp adapter", () => {name: "webstudio",version: "0.0.0",});- await expect(client.listTools()).resolves.toEqual({+ const listedTools = await client.listTools();+ expect(+ listedTools.tools.find(({ name }) => name === "list-pages")?.annotations+ ).toEqual({ readOnlyHint: true, openWorldHint: false });+ expect(+ listedTools.tools.find(({ name }) => name === "publish")?.annotations+ ).toEqual({ destructiveHint: false });+ expect(+ listedTools.tools.find(({ name }) => name === "list-pages")?.inputSchema+ ).toHaveProperty("additionalProperties", false);+ expect(listedTools).toEqual({tools: expect.arrayContaining([expect.objectContaining({name: "list-pages",- annotations: expect.objectContaining({- readOnlyHint: true,- destructiveHint: false,- }),- _meta: {- webstudio: expect.objectContaining({- operationId: "pages.list",- }),- },+ annotations: { readOnlyHint: true, openWorldHint: false },}),expect.objectContaining({name: "publish",- annotations: expect.objectContaining({- readOnlyHint: false,- destructiveHint: false,- openWorldHint: true,- }),+ annotations: { destructiveHint: false },}),expect.objectContaining({name: "meta.index",- annotations: expect.objectContaining({- readOnlyHint: true,- destructiveHint: false,- }),+ annotations: { readOnlyHint: true, openWorldHint: false },}),expect.objectContaining({name: "components.coverage-status",- annotations: expect.objectContaining({- readOnlyHint: true,- destructiveHint: false,- }),+ annotations: { readOnlyHint: true, openWorldHint: false },}),expect.objectContaining({name: "refresh",- annotations: expect.objectContaining({- readOnlyHint: false,- destructiveHint: false,- }),+ annotations: { destructiveHint: false, openWorldHint: false },}),expect.objectContaining({name: "reset-session",- annotations: expect.objectContaining({- readOnlyHint: false,- destructiveHint: false,- }),+ annotations: { destructiveHint: false, openWorldHint: false },}),expect.objectContaining({name: "delete-instance",- annotations: expect.objectContaining({- readOnlyHint: false,- destructiveHint: true,- }),+ annotations: { openWorldHint: false },}),]),});+ expect(+ listedTools.tools.find(({ name }) => name === "list-pages")+ ).not.toHaveProperty("outputSchema");+ expect(+ listedTools.tools.find(({ name }) => name === "list-pages")+ ).not.toHaveProperty("_meta");+ expect(+ listedTools.tools.find(({ name }) => name === "delete-instance")+ ).not.toHaveProperty("description");+ expect(+ listedTools.tools.find(({ name }) => name === "meta.guide")?.description+ ).toBeTypeOf("string");+ expect(+ listedTools.tools.find(({ name }) => name === "list-pages")?.description+ ).toBeTypeOf("string");+ expect(+ JSON.stringify(+ listedTools.tools.find(({ name }) => name === "list-pages")+ ?.inputSchema+ )+ ).not.toContain('"description"');+ expect(+ getSchemaProperties(+ listedTools.tools.find(({ name }) => name === "list-pages")+ ?.inputSchema+ ).includeFolders+ ).toEqual({});+ expect(+ getSchemaProperties(+ listedTools.tools.find(({ name }) => name === "publish")?.inputSchema+ )+ ).toEqual({});+ const updatePageInputSchema = listedTools.tools.find(+ ({ name }) => name === "update-page"+ )?.inputSchema;+ expect(getSchemaProperties(updatePageInputSchema).values).toEqual({+ type: "object",+ });await expect(client.listResources()).resolves.toEqual({resources: expect.arrayContaining([expect.objectContaining({ uri: "webstudio://project/status" }),@@ -6652,8 +7294,8 @@ describe("project session mcp adapter", () => {confirmationToken: expect.objectContaining({ type: "string" }),}),},- annotations: expect.objectContaining({ destructiveHint: true }),});+ expect(deleteTool?.annotations).toEqual({ openWorldHint: false });expect(tools.tools.find(({ name }) => name === "move-instance")).toMatchObject({@@ -6662,11 +7304,14 @@ describe("project session mcp adapter", () => {dryRun: expect.objectContaining({ type: "boolean" }),}),},- annotations: expect.objectContaining({ destructiveHint: false }),});expect(- tools.tools.find(({ name }) => name === "publish")?.inputSchema- .properties+ tools.tools.find(({ name }) => name === "move-instance")?.annotations+ ).toEqual({ destructiveHint: false, openWorldHint: false });+ expect(+ getSchemaProperties(+ tools.tools.find(({ name }) => name === "publish")?.inputSchema+ )).not.toHaveProperty("dryRun");const planned = await client.callTool({@@ -7042,51 +7687,29 @@ describe("project session mcp adapter", () => {tools: expect.arrayContaining([expect.objectContaining({name: "preview.start",- annotations: expect.objectContaining({- readOnlyHint: false,- destructiveHint: false,- openWorldHint: true,- }),+ annotations: { destructiveHint: false },}),expect.objectContaining({name: "preview.status",- annotations: expect.objectContaining({+ annotations: {readOnlyHint: true,- destructiveHint: false,- openWorldHint: true,- }),+ },}),expect.objectContaining({name: "preview.stop",- annotations: expect.objectContaining({- readOnlyHint: false,- destructiveHint: false,- openWorldHint: true,- }),+ annotations: { destructiveHint: false },}),expect.objectContaining({name: "screenshot",- annotations: expect.objectContaining({- readOnlyHint: false,- destructiveHint: false,- openWorldHint: true,- }),+ annotations: { destructiveHint: false },}),expect.objectContaining({name: "screenshot.diff",- annotations: expect.objectContaining({- readOnlyHint: false,- destructiveHint: false,- openWorldHint: true,- }),+ annotations: { destructiveHint: false },}),expect.objectContaining({name: "vision.install-ocr",- annotations: expect.objectContaining({- readOnlyHint: false,- destructiveHint: false,- openWorldHint: true,- }),+ annotations: { destructiveHint: false },}),]),});diff --git a/packages/project-build/src/mcp.ts b/packages/project-build/src/mcp.tsindex 15045a0e8d..3cd92e2478 100644--- a/packages/project-build/src/mcp.ts+++ b/packages/project-build/src/mcp.ts@@ -577,6 +577,21 @@ const insertFragmentMcpInputSchema = {required: ["parentInstanceId", "fragment"],} as const satisfies ProjectSessionMcpInputSchema;+const insertFragmentVerifiedMcpInputSchema = {+ ...insertFragmentMcpInputSchema,+ description:+ "Insert a Webstudio fragment and immediately verify its persisted bindings in one call.",+ properties: {+ ...insertFragmentMcpInputSchema.properties,+ pagePath: {+ type: "string",+ description:+ "Concrete page path used for post-commit binding verification, for example /account.",+ },+ },+ required: ["parentInstanceId", "fragment", "pagePath"],+} as const satisfies ProjectSessionMcpInputSchema;+const insertCollectionMcpInput = insertCollectionInput.omit({ itemFragment: true }).extend({@@ -1046,19 +1061,40 @@ const normalizeOperationInputAliases = ({command: string;input: unknown;}) => {- if (- command === "create-page" &&- isPlainRecord(input) &&- "description" in input- ) {- const { description, meta, ...rest } = input;- return {- ...rest,- meta: {- ...(isPlainRecord(meta) ? meta : {}),- description,- },- };+ if (command === "create-page" && isPlainRecord(input)) {+ const normalizedInput: Record<string, unknown> =+ "description" in input+ ? (() => {+ const { description, meta, ...rest } = input;+ return {+ ...rest,+ meta: {+ ...(isPlainRecord(meta) ? meta : {}),+ description,+ },+ };+ })()+ : input;+ if (+ typeof normalizedInput.path !== "string" ||+ normalizedInput.path === ""+ ) {+ return normalizedInput;+ }+ try {+ const base = new URL("https://webstudio.invalid/");+ const parsed = new URL(normalizedInput.path, base);+ if (+ parsed.origin === base.origin &&+ parsed.search === "" &&+ parsed.hash === ""+ ) {+ return { ...normalizedInput, path: parsed.pathname };+ }+ } catch {+ return normalizedInput;+ }+ return normalizedInput;}if (command === "insert-component" &&@@ -1072,6 +1108,57 @@ const normalizeOperationInputAliases = ({return input;};+const normalizeOperationInputValues = (command: string, input: unknown) => {+ if (+ command !== "update-styles" ||+ isPlainRecord(input) === false ||+ Array.isArray(input.updates) === false+ ) {+ return input;+ }+ const normalizeStyleValue = (value: unknown) => {+ if (+ isPlainRecord(value) &&+ typeof value.value === "string" &&+ ["unit", "length", "color"].includes(String(value.type)) &&+ (value.type !== "color" || "colorSpace" in value === false)+ ) {+ return { type: "keyword", value: value.value };+ }+ return typeof value === "string" ? { type: "keyword", value } : value;+ };+ return {+ ...input,+ updates: input.updates.flatMap((update) => {+ if (isPlainRecord(update) === false) {+ return [update];+ }+ if (typeof update.property === "string" && "value" in update) {+ return [+ {+ ...update,+ value: normalizeStyleValue(update.value),+ },+ ];+ }+ const grouped = isPlainRecord(update.styles)+ ? update.styles+ : isPlainRecord(update.declarations)+ ? update.declarations+ : undefined;+ if (grouped === undefined) {+ return [update];+ }+ const { styles: _styles, declarations: _declarations, ...rest } = update;+ return Object.entries(grouped).map(([property, value]) => ({+ ...rest,+ property,+ value: normalizeStyleValue(value),+ }));+ }),+ };+};+const getNormalizedOperationInput = (operation: PublicMcpOperation,input: unknown@@ -1091,7 +1178,10 @@ const getNormalizedOperationInput = (command: operation.command,input: wrappedInput,});- const normalizedInput = parseStringifiedJsonInputFields(aliasedInput, schema);+ const normalizedInput = normalizeOperationInputValues(+ operation.command,+ parseStringifiedJsonInputFields(aliasedInput, schema)+ );assertKnownInputFields({command: operation.command,input: normalizedInput,@@ -1222,6 +1312,40 @@ const screenshotInputSchema = {required: ["viewport"],} as const satisfies ProjectSessionMcpInputSchema;+const responsiveScreenshotInputSchema = {+ ...emptyInputSchema,+ description:+ "Capture one generated-site route at multiple viewport sizes in one shared preview/browser session. This starts or refreshes the session preview automatically.",+ properties: {+ path: screenshotInputSchema.properties.path,+ viewports: {+ type: "array",+ minItems: 1,+ maxItems: 8,+ description: "Viewport dimensions to capture in the provided order.",+ items: {+ type: "object",+ properties: {+ width: { type: "number" },+ height: { type: "number" },+ },+ required: ["width", "height"],+ additionalProperties: false,+ },+ },+ fullPage: screenshotInputSchema.properties.fullPage,+ source: screenshotInputSchema.properties.source,+ mode: screenshotInputSchema.properties.mode,+ imageDomains: screenshotInputSchema.properties.imageDomains,+ browser: screenshotInputSchema.properties.browser,+ waitUntil: screenshotInputSchema.properties.waitUntil,+ waitForSelector: screenshotInputSchema.properties.waitForSelector,+ waitForTimeout: screenshotInputSchema.properties.waitForTimeout,+ timeout: screenshotInputSchema.properties.timeout,+ },+ required: ["path", "viewports"],+} as const satisfies ProjectSessionMcpInputSchema;+const statusInputSchema = {...emptyInputSchema,properties: {@@ -1440,7 +1564,8 @@ const previewInputSchema = {},port: {type: "number",- default: 5173,+ description:+ "Optional fixed port. Omit it to allocate an available local port automatically.",},source: {type: "string",@@ -1558,6 +1683,9 @@ const createProjectSessionMcpTool = (export const mcpArgumentExamples: Record<string, readonly unknown[]> = {"meta.guide": [{ brief: "Create a pricing page and style the hero" }],+ "inspect-auth-context": [{}],+ "inspect-design-context": [{}],+ "verify-font-assets": [{ assetIds: ["asset-regular", "asset-bold"] }],"workflow.next": [{ goal: "design-system-page" },{ goal: "design-system-page", phase: "dry-run-section" },@@ -1664,7 +1792,7 @@ export const mcpArgumentExamples: Record<string, readonly unknown[]> = {{ assetId: "asset-id" },{ assetId: "asset-id", folderId: "target-folder-id" },],- "preview.start": [{ host: "127.0.0.1", port: 5173, source: "session" }],+ "preview.start": [{ source: "session" }],"preview.status": [{}],"preview.stop": [{}],status: [{}, { verbose: true }],@@ -1742,6 +1870,14 @@ export const mcpArgumentExamples: Record<string, readonly unknown[]> = {'<ws.element ws:tag="section"><radix.Switch><radix.SwitchThumb /></radix.Switch></ws.element>',},],+ "insert-fragment-verified": [+ {+ parentInstanceId: "parent-id",+ pagePath: "/pricing",+ fragment:+ '<ws.element ws:tag="section"><ws.element ws:tag="h2">Pricing</ws.element></ws.element>',+ },+ ],"update-text": [{instanceId: "instance-id",@@ -2014,6 +2150,26 @@ export const mcpArgumentExamples: Record<string, readonly unknown[]> = {browser: "auto",},],+ "screenshot.responsive": [+ {+ path: "/pricing",+ viewports: [+ { width: 1440, height: 900 },+ { width: 390, height: 844 },+ ],+ source: "session",+ },+ ],+ "verify-page-responsive": [+ {+ path: "/pricing",+ viewports: [+ { width: 1440, height: 900 },+ { width: 390, height: 844 },+ ],+ source: "session",+ },+ ],"screenshot.diff": [{baselinePath: "baseline.png",@@ -2629,6 +2785,138 @@ const sessionTools: readonly ProjectSessionMcpTool[] = [}),];+const authContextOperationCommands = [+ "get-project-settings",+ "list-pages",+ "list-resources",+ "list-variables",+] as const;++const inspectAuthContextTool = createProjectSessionMcpTool({+ name: "inspect-auth-context",+ description:+ "Return one bounded authentication discovery bundle with project settings, pages, resources, and variables. Use once before authentication mutations instead of calling the four underlying reads separately.",+ inputSchema: emptyInputSchema,+ mcpExamples: getMcpExamples("inspect-auth-context"),+ annotations: {+ command: "inspect-auth-context",+ operationId: "workflow.auth-context",+ method: "session",+ permit: "view",+ localCapable: true,+ serverOnly: false,+ readNamespaces: ["projectSettings", "pages", "resources", "dataSources"],+ writeNamespaces: [],+ invalidatesNamespaces: [],+ retryOnConflict: false,+ },+});++const designContextOperationCommands = [+ "list-pages",+ "list-breakpoints",+ "list-design-tokens",+ "list-assets",+ "list-variables",+] as const;++const inspectDesignContextTool = createProjectSessionMcpTool({+ name: "inspect-design-context",+ description:+ "Return one bounded design discovery bundle with pages, breakpoints, design tokens, assets, and variables. Use once before design-driven page mutations instead of calling the five underlying reads separately.",+ inputSchema: emptyInputSchema,+ mcpExamples: getMcpExamples("inspect-design-context"),+ annotations: {+ command: "inspect-design-context",+ operationId: "workflow.design-context",+ method: "session",+ permit: "view",+ localCapable: true,+ serverOnly: false,+ readNamespaces: ["pages", "breakpoints", "styles", "assets", "dataSources"],+ writeNamespaces: [],+ invalidatesNamespaces: [],+ retryOnConflict: false,+ },+});++const verifyFontAssetsInputSchema = {+ ...emptyInputSchema,+ properties: {+ assetIds: {+ type: "array",+ description: "Font asset ids returned by upload-assets.",+ items: { type: "string" },+ minItems: 1,+ maxItems: 50,+ },+ },+ required: ["assetIds"],+} as const satisfies ProjectSessionMcpInputSchema;++const verifyFontAssetsTool = createProjectSessionMcpTool({+ name: "verify-font-assets",+ description:+ "Refresh the asset namespace and return several persisted font assets in one verification call.",+ inputSchema: verifyFontAssetsInputSchema,+ mcpExamples: getMcpExamples("verify-font-assets"),+ annotations: {+ command: "verify-font-assets",+ operationId: "workflow.verify-font-assets",+ method: "session",+ permit: "api",+ localCapable: true,+ serverOnly: false,+ readNamespaces: ["assets"],+ writeNamespaces: [],+ invalidatesNamespaces: [],+ retryOnConflict: false,+ },+});++const insertFragmentVerifiedOperationCommands = [+ "insert-fragment",+ "verify-bindings",+] as const;++const createInsertFragmentVerifiedTool = (+ operations: readonly PublicMcpOperation[]+) => {+ const insertion = operations.find(+ (operation) => operation.command === "insert-fragment"+ );+ const verification = operations.find(+ (operation) => operation.command === "verify-bindings"+ );+ if (insertion === undefined || verification === undefined) {+ throw new Error(+ "insert-fragment-verified requires insert-fragment and verify-bindings operations."+ );+ }+ const mergeNamespaces = (+ key: "readNamespaces" | "writeNamespaces" | "invalidatesNamespaces"+ ) => [...new Set([...insertion[key], ...verification[key]])];+ return createProjectSessionMcpTool({+ name: "insert-fragment-verified",+ description:+ "Insert an authored Webstudio JSX fragment and immediately verify persisted bindings on its page. Prefer this when binding verification is required directly after insertion.",+ inputSchema: insertFragmentVerifiedMcpInputSchema,+ mcpExamples: getMcpExamples("insert-fragment-verified"),+ annotations: {+ command: "insert-fragment-verified",+ operationId: "workflow.insert-fragment-verified",+ method: "mutation",+ permit: insertion.permit,+ localCapable: insertion.localCapable && verification.localCapable,+ serverOnly: insertion.serverOnly || verification.serverOnly,+ readNamespaces: mergeNamespaces("readNamespaces"),+ writeNamespaces: mergeNamespaces("writeNamespaces"),+ invalidatesNamespaces: mergeNamespaces("invalidatesNamespaces"),+ retryOnConflict: insertion.retryOnConflict,+ },+ });+};+const screenshotTool = createProjectSessionMcpTool({name: "screenshot",description:@@ -2649,6 +2937,54 @@ const screenshotTool = createProjectSessionMcpTool({},});+const responsiveScreenshotTool = createProjectSessionMcpTool({+ name: "screenshot.responsive",+ description:+ "Capture one generated route at multiple viewport sizes in one call. Starts or refreshes the session preview automatically and reuses one browser session.",+ inputSchema: responsiveScreenshotInputSchema,+ mcpExamples: getMcpExamples("screenshot.responsive"),+ annotations: {+ command: "screenshot.responsive",+ operationId: "screenshot.responsive",+ method: "session",+ permit: "api",+ localCapable: false,+ serverOnly: true,+ readNamespaces: [],+ writeNamespaces: [],+ invalidatesNamespaces: [],+ retryOnConflict: false,+ },+});++const createResponsivePageVerificationTool = (+ operations: readonly PublicMcpOperation[]+) => {+ const audit = operations.find((operation) => operation.command === "audit");+ if (audit === undefined) {+ throw new Error("verify-page-responsive requires the audit operation.");+ }+ return createProjectSessionMcpTool({+ name: "verify-page-responsive",+ description:+ "Capture one generated route at multiple viewport sizes and immediately run its static audit in one terminal verification call.",+ inputSchema: responsiveScreenshotInputSchema,+ mcpExamples: getMcpExamples("verify-page-responsive"),+ annotations: {+ command: "verify-page-responsive",+ operationId: "workflow.verify-page-responsive",+ method: "session",+ permit: audit.permit,+ localCapable: false,+ serverOnly: true,+ readNamespaces: audit.readNamespaces,+ writeNamespaces: [],+ invalidatesNamespaces: [],+ retryOnConflict: false,+ },+ });+};+const screenshotDiffTool = createProjectSessionMcpTool({name: "screenshot.diff",description:@@ -2856,15 +3192,12 @@ export type ProjectSessionMcpResource = {type SdkTool = {name: string;- description: string;+ description?: string;inputSchema: ProjectSessionMcpInputSchema;- annotations: {- readOnlyHint: boolean;- destructiveHint: boolean;- openWorldHint: boolean;- };- _meta: {- webstudio: ProjectSessionMcpTool["annotations"];+ annotations?: {+ readOnlyHint?: true;+ destructiveHint?: false;+ openWorldHint?: false;};};@@ -2889,6 +3222,7 @@ export const listProjectSessionMcpTools = (includeImport?: boolean;includeDownloadAsset?: boolean;includeScreenshot?: boolean;+ includeResponsiveScreenshot?: boolean;includeScreenshotDiff?: boolean;includeInstallOcr?: boolean;includePreview?: boolean;@@ -2940,10 +3274,33 @@ export const listProjectSessionMcpTools = (...tool,mcpExamples: getMcpExamples(tool.name),})),+ ...(authContextOperationCommands.every((command) =>+ operations.some((operation) => operation.command === command)+ )+ ? [inspectAuthContextTool]+ : []),+ ...(designContextOperationCommands.every((command) =>+ operations.some((operation) => operation.command === command)+ )+ ? [inspectDesignContextTool]+ : []),+ ...(operations.some((operation) => operation.command === "get-asset")+ ? [verifyFontAssetsTool]+ : []),+ ...(insertFragmentVerifiedOperationCommands.every((command) =>+ operations.some((operation) => operation.command === command)+ )+ ? [createInsertFragmentVerifiedTool(operations)]+ : []),...(options.includeRestorePoints ? restorePointTools : []),...(options.includeImport ? [importTool] : []),...(options.includeDownloadAsset ? [downloadAssetTool] : []),...(options.includeScreenshot ? [screenshotTool] : []),+ ...(options.includeResponsiveScreenshot ? [responsiveScreenshotTool] : []),+ ...(options.includeResponsiveScreenshot &&+ operations.some((operation) => operation.command === "audit")+ ? [createResponsivePageVerificationTool(operations)]+ : []),...(options.includeScreenshotDiff ? [screenshotDiffTool] : []),...(options.includeInstallOcr ? [installOcrTool] : []),...(options.includePreview ? previewTools : []),@@ -3000,6 +3357,7 @@ const capabilityAreas = ["preview.status","preview.stop","screenshot",+ "verify-page-responsive","screenshot.diff","vision.install-ocr",],@@ -3012,6 +3370,9 @@ const capabilityAreas = ["meta.guide","meta.get_more_tools","workflow.next",+ "inspect-auth-context",+ "inspect-design-context",+ "verify-font-assets","components.summary","components.coverage-plan","components.coverage-status",@@ -3066,6 +3427,7 @@ const capabilityAreas = ["list-instances","inspect-instance","insert-fragment",+ "insert-fragment-verified","insert-component","move-instance","clone-instance",@@ -5038,28 +5400,28 @@ const metaGoalGuides = [pattern:/authenticated?\s+(?:page|route|screen)|(?:supabase|firebase)\s+auth|sign(?:ed)?[- ]?(?:in|out)|login\s+(?:page|flow)|user\s+session/i,tools: [- "get-project-settings",- "list-resources",- "list-variables",+ "inspect-auth-context","list-instances","create-page","create-resource","create-variable",- "insert-fragment",- "bind-props",- "verify-bindings",+ "insert-fragment-verified","update-page",- "preview.start",- "screenshot",- "audit",+ "verify-page-responsive",],workflow: [- "Inspect the project's existing auth resources, variables, embeds, page settings, and agent instructions before choosing a provider workflow. Reuse that convention; do not add a second auth system implicitly.",+ "Inspect the project's existing auth resources, variables, page settings, and agent instructions before choosing a provider workflow. Call inspect-auth-context exactly once instead of calling get-project-settings, list-pages, list-resources, or list-variables separately; use at most one focused search-project call only when that bundle does not identify the auth convention. Treat its pages section as authoritative for route existence. Do not call get-page-by-path to confirm that /account is absent. Reuse that convention; do not add a second auth system implicitly.",+ "Do not call meta.index after this guide. If an exact mutation schema is still needed, make at most one meta.get_more_tools call listing all immediately required authoring tools rather than rediscovering them one at a time.","Never place credentials, service-role keys, refresh tokens, private session values, or authenticated response bodies in project data, command output, screenshots, agent instructions, or error reports. Ask the user to configure secrets in the provider/server environment.","Model explicit signed-out, loading, signed-in, and failed-auth UI states with ordinary components and bindings. Use page basic auth only when the user asks for Webstudio's fixed login/password gate; it is not Supabase or Firebase authentication.","Use focused resources and variables for public client configuration and session-shaped data. Keep authorization enforcement and privileged provider calls server-side; a hidden Builder element is not an authorization boundary.",- "After creating or changing authentication expressions, call verify-bindings for the account page and resolve every validity, scope, and reference finding before previewing.",- "Preview and verify every auth state with non-secret fixture data, then audit the route. Do not claim the real provider flow works until redirects, session refresh, failure handling, and protected data access are exercised in its configured environment.",+ "When fixture/session data must feed a resource, create the page and scoped fixture variables there. Use create-page's returned rootInstanceId directly instead of listing instances to rediscover it. Call list-variables after creation only when a resource expression actually needs the returned encoded name. Do not repeat list-variables when the fixture variable is not referenced, as in the expression-free state gallery, and do not guess or reference variables before they exist.",+ 'Create resources only after their scope and referenced variables exist. When reusing an existing server-mediated auth convention, copy its fixed request URL exactly into resource.url; resource.url is the HTTP request target, not a provider call or session-state expression. For the discovered /api/auth/session convention, use create-resource with resource:{name:"Account session via server",method:"get",url:"/api/auth/session",headers:[],searchParams:[]}, the new page root as scopeInstanceId, and a descriptive dataSourceName. Use literal wrappers only for fixed header, search-parameter, and body text.',+ "Keep the server-mediated session resource as provider-convention evidence, but use only non-secret scoped fixture variables to drive local auth-state visibility. Do not bind that server-only resource into local preview rendering: its endpoint is intentionally absent locally and can recurse through the generated route.",+ 'Insert signed-out, loading, signed-in, and failed-auth panels together as one expression-free semantic fragment that acts as a state gallery. Keep all four panels visible together for local visual verification; do not add conditional visibility bindings or mutate fixture state solely to capture more screenshots. Use that exact fragment verbatim without adding styles, props, expressions, components, or changing its nesting: <ws.element ws:tag="main"><ws.element ws:tag="section"><ws.element ws:tag="h2">Signed-out</ws.element></ws.element><ws.element ws:tag="section"><ws.element ws:tag="h2">Loading</ws.element></ws.element><ws.element ws:tag="section"><ws.element ws:tag="h2">Signed-in</ws.element></ws.element><ws.element ws:tag="section"><ws.element ws:tag="h2">Failed-auth</ws.element></ws.element></ws.element>.',+ "Do not call selector-based structural tools such as wrap-instance unless a focused list-instances result supplied the complete non-empty selector from the target through its page root. Prefer direct style, prop, or binding corrections when the structure is already sound.",+ 'Insert the complete account fragment with insert-fragment-verified and {"pagePath":"/account"} so persisted bindings are checked in the same call. Resolve every returned validity, scope, and reference finding before previewing. If post-commit verification reports an infrastructure failure, do not repeat the insertion; call verify-bindings separately for /account. Updating only a fixture variable\'s literal state does not require another binding verification.',+ 'Call verify-page-responsive once with path "/account" and the required desktop and mobile viewports; it starts or refreshes the session preview, captures both viewports in one browser session, and immediately runs the static page audit. Do not call preview.start, screenshot, screenshot.responsive, or audit separately. Do not run discovery, inspect-instance, mutate, or repeat binding verification after this terminal verification begins. The screenshots are the rendered evidence and the bundled audit is the static evidence. Do not claim the real provider flow works until redirects, session refresh, failure handling, and protected data access are exercised in its configured environment.',],},{@@ -5071,44 +5433,42 @@ const metaGoalGuides = ["upload-asset","upload-assets","update-asset",- "refresh",- "get-asset",+ "verify-font-assets",+ "audit",],workflow: [+ "The guide and MCP handshake already provide the required tool schemas. Do not call meta.index or meta.get_more_tools for this workflow.","Use upload-asset or upload-assets with the local filename, detected format, and complete family, style, and weight metadata. Use the returned asset ids directly; do not read a project snapshot to rediscover uploaded assets.","Use update-asset to correct font metadata without re-uploading the binary.",- 'After font mutations, call refresh with {"namespaces":["assets"]}, then use get-asset for each changed id to verify the persisted metadata.',+ "After font mutations, call verify-font-assets exactly once with every changed asset id. It refreshes the asset namespace and returns the persisted metadata in one bounded verification call; do not call refresh or get-asset separately.",],},{pattern:/(?:figma|wireframe|screenshot|design\s*(?:guide|input|file)|design\.md|inception).*(?:page|site|build|implement|recreate)|(?:build|implement|recreate).*(?:figma|wireframe|screenshot|design\s*(?:guide|input|file)|design\.md|inception)/i,tools: [- "list-pages",- "list-breakpoints",- "list-variables",- "list-design-tokens",+ "inspect-design-context","list-style-sources","attach-design-token",- "list-assets","components.search","create-page",- "insert-fragment",+ "insert-fragment-verified","update-styles","upload-asset",- "preview.start",- "screenshot",+ "verify-page-responsive","screenshot.diff",- "audit",],workflow: [+ "The guide and MCP handshake already provide the required tool schemas. Do not call meta.index or meta.get_more_tools for this workflow.","Interpret the supplied design before mutating: identify page sections, responsive behavior, reusable patterns, assets, typography, color, spacing, and interaction states. Ask for missing source assets rather than inventing brand-critical content.",- "Before the first mutation, call list-breakpoints and list-design-tokens. Reuse the returned breakpoint ids and attach relevant token ids to the new instances; do not continue with disconnected local copies when matching tokens exist.",- "Inspect the target project's pages, variables, design tokens, style sources, components, and assets. Reuse exact existing values and patterns; do not create a parallel design system from approximate screenshot colors or spacing.",+ "Before the first mutation, call inspect-design-context exactly once instead of calling list-pages, list-breakpoints, list-design-tokens, list-assets, or list-variables separately. Use one list-instances call only when needed to inspect a representative existing page pattern. Do not call get-styles: the bounded design context and optional focused instance result provide the reusable design-system evidence needed here without risking an oversized style dump. Reuse exact existing values, breakpoint ids, and patterns; do not create a parallel design system from approximate screenshot colors or spacing.",+ "Call create-page exactly once and use its returned rootInstanceId as the insertion parent. Insert the complete semantic page in one fragment when practical, and use the insertion result's instanceIds for follow-up token attachments. Do not call list-instances after the first mutation to rediscover ids already returned by mutations.","Attach existing design tokens to the new page's instances when they represent the intended typography, color, or other shared style. Reusing only the token's current raw value creates a disconnected local copy.",- "Create semantic editable structure with insert-fragment and known components. Use assets for real imagery and text/controls for real content; do not flatten the design into one image or absolute-position every element.",- "Implement responsive behavior inside the project's actual breakpoint ranges. Capture one familiar desktop and mobile viewport, plus one representative viewport for any distinct intermediate breakpoint behavior.",- "Run rendered audit and inspect screenshots after each bounded page section. Iterate on hierarchy, overflow, wrapping, image choice, spacing, and states; visual similarity is evidence, not permission to discard accessibility or project conventions.",+ "Create semantic editable structure with insert-fragment-verified using ws.element and literal text first; apply fixed CSS only through ws:style={css`...`}. Do not improvise component names, expression syntax, or object-valued style expressions in the fragment. Use assets for real imagery and text/controls for real content; do not flatten the design into one image or absolute-position every element.",+ "Implement responsive behavior inside the project's actual breakpoint ranges.",+ 'Represent literal CSS values as {"type":"keyword","value":"..."}, including lengths such as "48px" and colors such as "#fff". Do not invent value types such as "length"; use {"type":"unit","value":48,"unit":"px"} only when numeric structure is specifically needed.',+ "Each update-styles updates item is flat: include instanceId, property, value, and optional breakpoint directly on every item. Do not group properties under styles or declarations.",+ 'Call insert-fragment-verified exactly once with {"pagePath":"/summer"} so insertion and persisted binding verification share one bounded call; do not guess a page id or alternate input shape. Treat its verification result as the structural and binding checkpoint before attaching tokens or applying fixed style/page updates. If post-commit verification reports an infrastructure failure, do not repeat the insertion; call verify-bindings separately for /summer. Later fixed-value mutations do not require another binding verification. Finish them before visual verification, then call verify-page-responsive once with path "/summer" and exactly the two supplied viewports, 1440x900 and 390x844. It starts or refreshes preview automatically, captures both viewports, and immediately runs the static page audit. Do not call preview.start, screenshot, screenshot.responsive, or audit separately, and do not add exploratory or intermediate captures. Do not mutate, rediscover, or repeat binding verification after this terminal verification begins. The screenshots are the rendered evidence and the bundled audit is the static evidence. Visual similarity is evidence, not permission to discard accessibility or project conventions.',],},{@@ -5130,6 +5490,36 @@ const metaGoalGuides = [},] as const;+const metaGuideDetailedInputSchemaTools = new Set(["update-styles"]);+const metaGuideExampleTools = new Set(["upload-assets"]);++const serializeMetaGuideTool = (+ tool: ProjectSessionMcpTool,+ includeHandshakeFields: boolean+) =>+ includeHandshakeFields+ ? {+ name: tool.name,+ use: tool.description,+ method: tool.annotations.method,+ permit: tool.annotations.permit,+ inputFields: tool.annotations.inputFields,+ requiredInputFields: tool.annotations.requiredInputFields,+ mcpExamples: tool.mcpExamples ?? [],+ ...(metaGuideDetailedInputSchemaTools.has(tool.name)+ ? { inputSchema: getDetailedProjectSessionMcpInputSchema(tool) }+ : {}),+ }+ : {+ name: tool.name,+ ...(metaGuideExampleTools.has(tool.name)+ ? { mcpExamples: tool.mcpExamples ?? [] }+ : {}),+ ...(metaGuideDetailedInputSchemaTools.has(tool.name)+ ? { inputSchema: getDetailedProjectSessionMcpInputSchema(tool) }+ : {}),+ };+const getMetaGuide = (brief: string,tools: readonly ProjectSessionMcpTool[],@@ -5147,14 +5537,14 @@ const getMetaGuide = ((tool) => tool.name === "screenshot.diff");return {- brief,delegatedAgentRule:"Do not spend the whole phase on discovery. If you are delegated/non-streaming and the parent asks for status within 30 seconds, run exactly one shortcut command such as webstudio meta.index or one explicit webstudio mcp single-op-call command, report its command/result, and wait before the next MCP command.",workflow: [...(goalGuide?.workflow ?? []),"Use the fewest discovery calls needed for the immediate action.","Call permissions or status only when the task depends on capabilities or local session freshness.",- matches.some((tool) => tool.annotations.localCapable)+ matches.some((tool) => tool.annotations.localCapable) &&+ matches.some((tool) => tool.name === "verify-font-assets") === false? "Call refresh if cached namespaces may be stale.": undefined,"Use focused read tools to collect ids and current values.",@@ -5165,16 +5555,13 @@ const getMetaGuide = (? guidance.getVisionWorkflowSummary({ includeDiff: canDiffScreenshots }): undefined,].filter(Boolean),- tools: matches.map((tool) => ({- name: tool.name,- use: tool.description,- method: tool.annotations.method,- permit: tool.annotations.permit,- inputFields: tool.annotations.inputFields,- requiredInputFields: tool.annotations.requiredInputFields,- mcpExamples: tool.mcpExamples ?? [],- })),- more: "Call meta.get_more_tools with the same brief for params, examples, namespaces, and server/local behavior.",+ tools: matches.map((tool) =>+ serializeMetaGuideTool(tool, goalGuide === undefined)+ ),+ more:+ goalGuide === undefined+ ? "The MCP handshake provides top-level argument contracts and required fields, while this guide includes exact examples plus complete schemas for selected complex tools. Call meta.get_more_tools once with all needed tool names only when a nested input shape is not covered here or when you need server/local behavior that the guide does not cover."+ : "The MCP client loads each named tool's exact argument contract before calling it. This guide includes a complete schema only for selected complex inputs. Call meta.get_more_tools once with all needed tool names only when the client does not expose a nested input shape or when you need server/local behavior that the guide does not cover.",};};@@ -5489,22 +5876,124 @@ export const isReadOnlyProjectSessionMcpToolCall = ();};-const toSdkTool = (tool: ProjectSessionMcpTool): SdkTool => ({- name: tool.name,- description: tool.description,- inputSchema: tool.inputSchema,- ...(tool.outputSchema === undefined- ? {}- : { outputSchema: tool.outputSchema }),- annotations: {- readOnlyHint: isReadOnlyProjectSessionMcpTool(tool),- destructiveHint: tool.annotations.requiresConfirm,- openWorldHint: tool.annotations.serverOnly,- },- _meta: {- webstudio: tool.annotations,- },-});+const sdkScalarSchemaKeys = new Set([+ "type",+ "enum",+ "const",+ "format",+ "default",+ "minimum",+ "maximum",+ "exclusiveMinimum",+ "exclusiveMaximum",+ "multipleOf",+ "minLength",+ "maxLength",+ "pattern",+ "minItems",+ "maxItems",+ "uniqueItems",+]);++const sdkDetailedOptionalSchemaProperties = new Set([+ "dryRun",+ "confirmDestructive",+ "confirmationToken",+]);++const getSdkSchemaProperty = (+ value: InputJsonSchemaValue+): InputJsonSchemaValue => {+ if (typeof value === "boolean") {+ return value;+ }+ const result: InputJsonSchema = Object.fromEntries(+ Object.entries(value).filter(([key]) => sdkScalarSchemaKeys.has(key))+ );+ if (value.items !== undefined) {+ result.items = getSdkSchemaProperty(value.items);+ }+ for (const key of ["allOf", "anyOf", "oneOf", "prefixItems"] as const) {+ const branches = value[key];+ if (Array.isArray(branches)) {+ result[key] = branches.map(getSdkSchemaProperty);+ }+ }+ return result;+};++const getSdkInputSchema = (+ schema: ProjectSessionMcpInputSchema,+ includeOptionalProperties: boolean+): ProjectSessionMcpInputSchema => {+ const required = new Set(schema.required ?? []);+ const properties = Object.fromEntries(+ Object.entries(schema.properties ?? {}).flatMap(([name, value]) =>+ required.has(name) ||+ includeOptionalProperties ||+ sdkDetailedOptionalSchemaProperties.has(name)+ ? [+ [+ name,+ required.has(name) ||+ sdkDetailedOptionalSchemaProperties.has(name)+ ? getSdkSchemaProperty(value)+ : {},+ ],+ ]+ : []+ )+ );+ return {+ type: "object",+ additionalProperties:+ schema.additionalProperties === undefined+ ? false+ : getSdkSchemaProperty(schema.additionalProperties),+ ...(Object.keys(properties).length === 0 ? {} : { properties }),+ ...(required.size === 0 ? {} : { required: [...required] }),+ };+};++const sdkDescribedToolNames = new Set([+ "meta.index",+ "meta.guide",+ "meta.get_more_tools",+ "workflow.next",+ ...metaGoalGuides.flatMap(({ tools }) => tools),+]);++const getSdkToolAnnotations = (tool: ProjectSessionMcpTool) => {+ const readOnly = isReadOnlyProjectSessionMcpTool(tool);+ const annotations: NonNullable<SdkTool["annotations"]> = {+ ...(readOnly ? { readOnlyHint: true } : {}),+ ...(readOnly === false && tool.annotations.requiresConfirm === false+ ? { destructiveHint: false }+ : {}),+ ...(tool.annotations.serverOnly ? {} : { openWorldHint: false }),+ };+ return Object.keys(annotations).length === 0 ? undefined : annotations;+};++// Keep output contracts, complete input guidance, and Webstudio operation+// metadata for local validation, generated documentation, and focused+// discovery. The startup instructions and described discovery tools route+// models to meta.guide, which returns descriptions for the relevant operation+// set. Do not resend descriptions for every operation in every MCP handshake.+const toSdkTool = (tool: ProjectSessionMcpTool): SdkTool => {+ const annotations = getSdkToolAnnotations(tool);+ return {+ name: tool.name,+ ...(sdkDescribedToolNames.has(tool.name)+ ? { description: tool.description }+ : {}),+ inputSchema: getSdkInputSchema(+ tool.inputSchema,+ sdkDescribedToolNames.has(tool.name)+ ),+ ...(annotations === undefined ? {} : { annotations }),+ };+};export const listProjectSessionMcpResources =(): ProjectSessionMcpResource[] => [@@ -5585,6 +6074,27 @@ const getDestructivePlanSummary = (};};+const maxMcpStyleKeyResults = 20;++const compactMcpOperationResult = (result: unknown) => {+ if (isPlainRecord(result) === false) {+ return result;+ }+ const styleKeys = result.styleKeys;+ if (+ Array.isArray(styleKeys) === false ||+ styleKeys.length <= maxMcpStyleKeyResults+ ) {+ return result;+ }+ return {+ ...result,+ styleKeys: styleKeys.slice(0, maxMcpStyleKeyResults),+ styleKeyCount: styleKeys.length,+ styleKeysTruncated: true,+ };+};+const toCallResult = (envelope: Parameters<typeof serializeProjectSessionMeta>[0],options: {@@ -5607,12 +6117,12 @@ const toCallResult = (options.error === undefined? {ok: true,- data: envelope.result,+ data: compactMcpOperationResult(envelope.result),meta,}: {ok: false,- data: envelope.result,+ data: compactMcpOperationResult(envelope.result),error: options.error,meta,};@@ -5919,6 +6429,39 @@ const getScreenshotInput = (input: unknown): ProjectSessionScreenshotInput => {};};+const getResponsiveScreenshotInputs = (+ input: unknown+): ProjectSessionScreenshotInput[] => {+ if (isRecord(input) === false) {+ throw new Error("screenshot.responsive input must be an object.");+ }+ if (+ Array.isArray(input.viewports) === false ||+ input.viewports.length === 0 ||+ input.viewports.length > 8+ ) {+ throw new Error(+ "screenshot.responsive input.viewports must contain between 1 and 8 viewport objects."+ );+ }+ return input.viewports.map((viewport, index) => {+ if (+ isRecord(viewport) === false ||+ typeof viewport.width !== "number" ||+ Number.isInteger(viewport.width) === false ||+ viewport.width <= 0 ||+ typeof viewport.height !== "number" ||+ Number.isInteger(viewport.height) === false ||+ viewport.height <= 0+ ) {+ throw new Error(+ `screenshot.responsive input.viewports.${index} must contain positive integer width and height.`+ );+ }+ return getScreenshotInput({ ...input, viewport });+ });+};+const isValidScreenshotDiffVisualExpectation = (value: unknown): value is ScreenshotVisualExpectation => {@@ -6220,6 +6763,7 @@ export const createProjectSessionMcpCore = <Command extends string = string>({includeImport: importProject !== undefined,includeDownloadAsset: downloadAsset !== undefined,includeScreenshot: captureScreenshot !== undefined,+ includeResponsiveScreenshot: capturePageScreenshots !== undefined,includeScreenshotDiff: diffScreenshots !== undefined,includeInstallOcr: installOcr !== undefined,includePreview:@@ -6240,6 +6784,63 @@ export const createProjectSessionMcpCore = <Command extends string = string>({dryRun: false,});};+ const callContextBundle = async ({+ toolName,+ operationId,+ calls,+ getResult,+ }: {+ toolName: string;+ operationId: string;+ calls: readonly {+ command: string;+ input: Record<string, unknown>;+ resultKey?: string;+ }[];+ getResult: (results: ReadonlyMap<string, unknown>) => unknown;+ }) => {+ const envelopes: Array<{+ command: string;+ envelope: ProjectSessionEnvelope;+ }> = [];+ for (const { command, input, resultKey } of calls) {+ if (operationByCommand.has(command as Command) === false) {+ throw new Error(`${toolName} requires the ${command} operation.`);+ }+ envelopes.push({+ command: resultKey ?? command,+ envelope: await executeOperation({+ command: command as Command,+ input,+ dryRun: false,+ }),+ });+ }+ const lastEnvelope = envelopes.at(-1)?.envelope;+ if (lastEnvelope === undefined) {+ throw new Error(`${toolName} produced no results.`);+ }+ const resultByCommand = new Map(+ envelopes.map(({ command, envelope }) => [command, envelope.result])+ );+ const mergeNamespaces = (+ key: keyof ProjectSessionEnvelope["namespaces"]+ ) => [+ ...new Set(envelopes.flatMap(({ envelope }) => envelope.namespaces[key])),+ ];+ return toCallResult({+ ...lastEnvelope,+ operationId,+ result: getResult(resultByCommand),+ namespaces: {+ read: mergeNamespaces("read"),+ write: mergeNamespaces("write"),+ invalidated: mergeNamespaces("invalidated"),+ missing: mergeNamespaces("missing"),+ },+ diagnostics: envelopes.flatMap(({ envelope }) => envelope.diagnostics),+ });+ };return {listTools,listResources: listProjectSessionMcpResources,@@ -6432,6 +7033,82 @@ export const createProjectSessionMcpCore = <Command extends string = string>({getMetaGuide(getBrief(input, "meta.guide"), listTools(), guidance));}+ if (name === "inspect-auth-context") {+ if (isPlainRecord(input) === false || Object.keys(input).length > 0) {+ throw new Error("inspect-auth-context does not accept input.");+ }+ return await callContextBundle({+ toolName: name,+ operationId: "workflow.auth-context",+ calls: [+ { command: "get-project-settings", input: {} },+ { command: "list-pages", input: { limit: 50 } },+ { command: "list-resources", input: { limit: 50 } },+ { command: "list-variables", input: { limit: 50 } },+ ],+ getResult: (resultByCommand) => ({+ projectSettings: resultByCommand.get("get-project-settings"),+ pages: resultByCommand.get("list-pages"),+ resources: resultByCommand.get("list-resources"),+ variables: resultByCommand.get("list-variables"),+ }),+ });+ }+ if (name === "inspect-design-context") {+ if (isPlainRecord(input) === false || Object.keys(input).length > 0) {+ throw new Error("inspect-design-context does not accept input.");+ }+ return await callContextBundle({+ toolName: name,+ operationId: "workflow.design-context",+ calls: [+ { command: "list-pages", input: { limit: 50 } },+ { command: "list-breakpoints", input: {} },+ { command: "list-design-tokens", input: { limit: 50 } },+ { command: "list-assets", input: { limit: 50 } },+ { command: "list-variables", input: { limit: 50 } },+ ],+ getResult: (resultByCommand) => ({+ pages: resultByCommand.get("list-pages"),+ breakpoints: resultByCommand.get("list-breakpoints"),+ designTokens: resultByCommand.get("list-design-tokens"),+ assets: resultByCommand.get("list-assets"),+ variables: resultByCommand.get("list-variables"),+ }),+ });+ }+ if (name === "verify-font-assets") {+ if (+ isPlainRecord(input) === false ||+ Array.isArray(input.assetIds) === false ||+ input.assetIds.length === 0 ||+ input.assetIds.length > 50 ||+ input.assetIds.some(+ (assetId) => typeof assetId !== "string" || assetId.length === 0+ )+ ) {+ throw new Error(+ "verify-font-assets requires assetIds with 1 to 50 non-empty strings."+ );+ }+ const assetIds = [...new Set(input.assetIds as string[])];+ const projectSession = getSession();+ await projectSession.initialize();+ await projectSession.refresh(["assets"]);+ onProjectSessionChange?.();+ return await callContextBundle({+ toolName: name,+ operationId: "workflow.verify-font-assets",+ calls: assetIds.map((assetId) => ({+ command: "get-asset",+ resultKey: assetId,+ input: { assetId },+ })),+ getResult: (resultByAssetId) => ({+ assets: assetIds.map((assetId) => resultByAssetId.get(assetId)),+ }),+ });+ }if (name === "workflow.next") {return toCheckpointedMetaResult(name, getWorkflowNext(input));}@@ -6563,6 +7240,54 @@ export const createProjectSessionMcpCore = <Command extends string = string>({}));}+ if (+ name === "verify-page-responsive" &&+ capturePageScreenshots !== undefined+ ) {+ const auditOperation = operationByCommand.get("audit" as Command);+ if (auditOperation === undefined) {+ throw new Error(+ "verify-page-responsive requires the audit operation."+ );+ }+ const screenshotInputs = getResponsiveScreenshotInputs(input);+ const pagePath = screenshotInputs[0]?.path;+ if (typeof pagePath !== "string" || pagePath.length === 0) {+ throw new Error(+ "verify-page-responsive requires a generated route path."+ );+ }+ const screenshots = await capturePageScreenshots(screenshotInputs, {+ report: (message) => {+ reportToolProgress?.(message);+ },+ });+ const auditEnvelope = await executeOperation({+ command: "audit" as Command,+ input: getNormalizedOperationInput(auditOperation, { pagePath }),+ dryRun: false,+ });+ return toCallResult({+ ...auditEnvelope,+ operationId: "workflow.verify-page-responsive",+ result: { screenshots, audit: auditEnvelope.result },+ });+ }+ if (+ name === "screenshot.responsive" &&+ capturePageScreenshots !== undefined+ ) {+ return toMetaResult({+ screenshots: await capturePageScreenshots(+ getResponsiveScreenshotInputs(input),+ {+ report: (message) => {+ reportToolProgress?.(message);+ },+ }+ ),+ });+ }if (name === "screenshot.diff" && diffScreenshots !== undefined) {return toMetaResult(await diffScreenshots(getScreenshotDiffInput(input))@@ -6587,6 +7312,137 @@ export const createProjectSessionMcpCore = <Command extends string = string>({if (name === "preview.stop" && stopPreview !== undefined) {return toMetaResult(await stopPreview());}+ if (name === "insert-fragment-verified") {+ const insertionOperation = operationByCommand.get(+ "insert-fragment" as Command+ );+ const verificationOperation = operationByCommand.get(+ "verify-bindings" as Command+ );+ if (+ insertionOperation === undefined ||+ verificationOperation === undefined+ ) {+ throw new Error(+ "insert-fragment-verified requires insert-fragment and verify-bindings operations."+ );+ }+ const transportInput = getToolCallInput(input);+ if (+ isPlainRecord(transportInput.input) === false ||+ typeof transportInput.input.pagePath !== "string"+ ) {+ throw new Error(+ "insert-fragment-verified requires a pagePath for persisted binding verification."+ );+ }+ const insertionInput = getNormalizedOperationInput(+ insertionOperation,+ await getInsertFragmentInput(transportInput.input)+ );+ const verificationInput = getNormalizedOperationInput(+ verificationOperation,+ { pagePath: transportInput.input.pagePath, limit: 200 }+ );+ const compositeDryRun = dryRun || transportInput.dryRun;+ const insertionEnvelope = await executeOperation({+ command: "insert-fragment" as Command,+ input: insertionInput,+ dryRun: compositeDryRun,+ });+ if (compositeDryRun) {+ return toCallResult(+ {+ ...insertionEnvelope,+ operationId: "workflow.insert-fragment-verified",+ result: {+ insertion: insertionEnvelope.result,+ verification: {+ status: "skipped",+ reason: "Verification runs only after a committed insertion.",+ },+ },+ },+ {+ next: [+ "Review the planned insertion. Commit it with the same input and dryRun omitted before relying on binding verification.",+ ],+ }+ );+ }+ let verificationEnvelope: ProjectSessionEnvelope;+ try {+ verificationEnvelope = await executeOperation({+ command: "verify-bindings" as Command,+ input: verificationInput,+ dryRun: false,+ });+ } catch {+ return toCallResult(+ {+ ...insertionEnvelope,+ operationId: "workflow.insert-fragment-verified",+ result: {+ insertion: insertionEnvelope.result,+ verification: { status: "failed-after-commit" },+ },+ },+ {+ error: {+ code: "POST_COMMIT_VERIFICATION_FAILED",+ message:+ "The fragment was committed, but binding verification could not run. Do not retry the insertion; call verify-bindings separately for the same pagePath.",+ },+ next: [+ "Do not retry insert-fragment-verified. Call verify-bindings separately for the same pagePath and resolve every finding.",+ ],+ }+ );+ }+ const mergeNamespaces = (+ key: keyof ProjectSessionEnvelope["namespaces"]+ ) => [+ ...new Set([+ ...insertionEnvelope.namespaces[key],+ ...verificationEnvelope.namespaces[key],+ ]),+ ];+ return toCallResult(+ {+ ...verificationEnvelope,+ operationId: "workflow.insert-fragment-verified",+ result: {+ insertion: insertionEnvelope.result,+ verification: verificationEnvelope.result,+ },+ state: {+ ...verificationEnvelope.state,+ committed: insertionEnvelope.state.committed,+ },+ namespaces: {+ read: mergeNamespaces("read"),+ write: mergeNamespaces("write"),+ invalidated: mergeNamespaces("invalidated"),+ missing: mergeNamespaces("missing"),+ },+ diagnostics: [+ ...insertionEnvelope.diagnostics,+ ...verificationEnvelope.diagnostics,+ ],+ },+ {+ next: [+ "Resolve every binding verification finding before previewing.",+ "Before reporting completion, run audit for the changed page or project.",+ ...(startPreview !== undefined && captureScreenshot !== undefined+ ? [+ "For visual changes, start a session preview and capture desktop and mobile screenshots before reporting completion.",+ ]+ : []),+ ],+ }+ );+ }const operation = operationByCommand.get(name as Command);if (operation === undefined) {throw new Error(`Unknown MCP tool "${name}".`);diff --git a/packages/project-build/src/runtime/data.test.tsx b/packages/project-build/src/runtime/data.test.tsxindex 8644af644e..bd8918da29 100644--- a/packages/project-build/src/runtime/data.test.tsx+++ b/packages/project-build/src/runtime/data.test.tsx@@ -2109,6 +2109,18 @@ describe("createResourceValue", () => {});});+ test("accepts root-relative resource urls", () => {+ expect(+ resourceFieldsInput.parse({+ name: "Session",+ method: "get",+ url: "/api/auth/session",+ searchParams: [],+ headers: [],+ })+ ).toMatchObject({ url: '"/api/auth/session"' });+ });+test("creates resource values through the sdk schema", () => {expect(createResourceValue({diff --git a/packages/project-build/src/runtime/data.ts b/packages/project-build/src/runtime/data.tsindex b28a436b6c..6c7ab42064 100644--- a/packages/project-build/src/runtime/data.ts+++ b/packages/project-build/src/runtime/data.ts@@ -32,7 +32,6 @@ import { z } from "zod";import { produceWithPatches } from "immer";import {createJsonStringifyProxy,- isLocalResource,isPlainObject,} from "@webstudio-is/sdk/runtime";import type { CompactBuild } from "../types";@@ -2013,23 +2012,33 @@ const getResourceLiteralUrlValidationIssues = (},];}- if (isLocalResource(value)) {- return [];- }try {new URL(value);+ return [];} catch {- return [- {- code: "invalid_resource_url",- path: ["url"],- message: "URL is invalid",- constraint: "absolute_or_root_relative_url",- example: "https://api.example.com/posts",- },- ];+ try {+ const baseUrl = new URL("https://resource.webstudio.invalid");+ const parsedUrl = new URL(value, baseUrl);+ if (+ value.startsWith("/") &&+ value.startsWith("//") === false &&+ parsedUrl.origin === baseUrl.origin+ ) {+ return [];+ }+ } catch {+ // Report the shared URL validation issue below.+ }}- return [];+ return [+ {+ code: "invalid_resource_url",+ path: ["url"],+ message: "URL is invalid",+ constraint: "absolute_or_root_relative_url",+ example: "https://api.example.com/posts",+ },+ ];};const validateResourceFields = (