Commit Graph
453 Commits
Author SHA1 Message Date
Oleg Isonen 6c193d8cc7 fix: preserve local assets in exported fixtures 2026-08-01 22:50:58 +01:00
Oleg Isonen b06a5c2ecb fix: load SaaS content documents from asset proxy 2026-08-01 22:23:46 +01:00
Oleg Isonen 92790ecb8c fix: guide compact Markdown blog databases 2026-08-01 12:13:03 +01:00
Oleg Isonen 5be248b2ab fix: defer Markdown body loading 2026-08-01 11:13:07 +01:00
Oleg Isonen 5c6f0a9809 perf: reduce published content database size 2026-08-01 10:15:48 +01:00
Oleg Isonen 590755a4b0 fix: harden document reference runtime 2026-08-01 08:17:09 +01:00
Oleg Isonen cfe6727567 fix: complete document reference workflow 2026-07-31 23:06:40 +01:00
Oleg Isonen bc07ab4696 fix: make document reference workflow retry-free 2026-07-31 17:41:57 +01:00
Oleg Isonen dcbcf1715c fix: normalize document content types 2026-07-31 16:08:07 +01:00
Oleg Isonen 60c8aaed3f test: evaluate document reference discovery 2026-07-31 16:04:22 +01:00
Oleg Isonen cc19dff23b fix: bind published documents to storage identity 2026-07-31 16:00:29 +01:00
Oleg Isonen 428ad2d1e7 test: evaluate document graph author references 2026-07-31 15:20:53 +01:00
Oleg Isonen b62f7417ac feat: discover document graphs from content snapshots 2026-07-31 14:04:54 +01:00
Oleg Isonen 3ccb46cec7 fix: restore Marketplace settings and optimize Assets publishing (#5964)
## Outcome

Restore the Marketplace section for projects without existing
marketplace metadata, make the complete review-submission workflow
available over MCP, clarify shared Assets database diagnostics, and
reduce published database size by materializing fully static Assets
queries.

## Implementation

### Marketplace and MCP

- Initialize the Marketplace form from a safe partial default instead of
rendering nothing when metadata is unconfigured.
- Keep review submission disabled until the complete metadata schema is
valid.
- Allow `get-marketplace-product` to return `null` and
`update-marketplace-product` to create the first marketplace product
through ProjectSession/MCP.
- Add a confirmed `submit-marketplace-product` server operation that
validates configured metadata before setting review status to `PENDING`.
- Document the MCP workflow: upload the thumbnail, update metadata,
publish production, then submit.
- Correct the Marketplace thumbnail upload example to use the current
MCP input field.

### Assets database

- Show query size and merged published-database size separately in
resource diagnostics.
- Clarify that only the merged database counts toward the publish limit.
- Allow the Assets query editor to scroll long query source.
- Materialize fully static metadata-only Assets queries at publish time.
- Store materialized results as compact field columns and rows keyed by
a deterministic normalized-query hash.
- Serve materialized rows through the existing Assets response contract
without candidate documents or a runtime field catalog.
- Keep route- or variable-dependent queries on the existing
document-backed runtime path.
- Exclude overview-only fields from dynamic detail documents so the
merged database does not duplicate them.
- Preserve byte-limit selection, truncation diagnostics, integrity
verification, caching, and backward compatibility with existing
artifacts.

### Release

- Keep the release lockfile stable when preparing the CLI package.
- Regenerate runtime contracts, server-only API metadata, and CLI
documentation where required.

## Todo

- [x] Restore the empty Marketplace settings state
- [x] Prevent empty review submissions
- [x] Support first-time Marketplace metadata creation over MCP
- [x] Add MCP review submission
- [x] Document the end-to-end MCP workflow
- [x] Correct query and merged-database diagnostics
- [x] Make long Assets query source scrollable
- [x] Materialize static overview queries
- [x] Preserve dynamic detail-query behavior
- [x] Add regression coverage with fail/pass proof
- [x] Run relevant package and integration checks

## Verification

- [x] Content engine tests: 158 passed
- [x] Asset uploader tests: 179 passed
- [x] SDK tests: 505 passed
- [x] CLI tests: 921 passed
- [x] CLI prebuild integration tests: 46 passed
- [x] Builder Assets resource and diagnostics tests: 14 passed
- [x] Project runtime and ProjectSession tests: 133 passed
- [x] Builder API router tests: 30 passed
- [x] Protocol operation tests: 18 passed
- [x] Content engine build and declaration generation
- [x] Content engine, asset uploader, SDK, Builder, and CLI typechecks
- [x] Repository lint and formatting checks
- [x] Generated API and documentation checks
- [x] New materialization tests demonstrated failing with the
implementation disabled and passing after restoration

## Notes

- The representative five-post overview fixture shrinks from 2,122 bytes
to 1,197 bytes while returning the same sorted and paginated result.
- Materialization is intentionally limited to static, metadata-only
field queries without runtime asset fields. Unsupported or
data-incompatible queries safely use the existing runtime database.
- The complete `pnpm evaluations` agent suite was not run because
repository policy requires separate explicit approval.
- No database schema or migration changes are required.
2026-07-31 13:16:21 +02:00
Oleg Isonen 3aeb4b3f61 fix: Reuse npm launcher for generated previews (#5962)
## Summary

Generated previews now reuse the npm CLI path supplied by the npx
launcher instead of rediscovering npm or npm.cmd through the MCP
subprocess PATH. The same invocation is used for dependency
installation, production builds, and preview server startup, with the
existing platform command retained as a fallback for direct launches.

## Technical choices

- Invoke npm-cli.js with the current Node executable when npm_execpath
identifies npm as the launcher.
- Parse Windows paths with the platform path implementation.
- Keep npm and npm.cmd fallback behavior when Webstudio was not launched
through npm.
- Inject executable paths in tests so launcher behavior is
deterministic.

## Todo

- [x] Reuse the npx npm launcher during generated dependency
installation.
- [x] Apply the same launcher to generated build and server commands.
- [x] Cover Windows launcher paths and direct-launch fallbacks.
- [x] Run focused tests, typecheck, lint, formatting, and production
build.

## Verification

- pnpm --filter webstudio test -- src/commands/preview.test.ts
src/preview-server.test.ts
- pnpm --filter webstudio typecheck
- pnpm exec oxlint --deny-warnings on the four changed files
- pnpm --filter webstudio build
- git diff --check

All checks passed. The build emitted the existing Radix use-client
bundling warnings. Agent evaluations were not run because they require
separate explicit approval.
2026-07-31 00:56:30 +02:00
Oleg Isonen e210fedc02 fix: support Cursor-compatible MCP tool names (#5961)
## Summary

- configure Cursor connections to request underscore-only MCP tool names
- advertise Cursor-safe names while mapping calls back to canonical
Webstudio operations
- preserve canonical tool names for other MCP clients and shell
workflows

## Verification

- pnpm --filter webstudio test -- src/commands/connect.test.ts
src/commands/mcp.test.ts
- pnpm --filter @webstudio-is/project-build test -- src/mcp.test.ts
- pnpm --filter webstudio typecheck
- pnpm --filter @webstudio-is/project-build typecheck
- pnpm exec oxlint --deny-warnings on changed files
- pnpm exec oxfmt on changed files
- pnpm evaluations not run (requires separate explicit approval)

Closes #5960
2026-07-31 00:37:21 +02:00
Oleg Isonen efbc3098c4 feat: add queryable Assets resources (#5946)
Closes #5919
Ref #5920

## Outcome

Extend the existing Assets system resource with optional queries for
Markdown, JSON, and standard file metadata. Unconfigured Assets
resources retain the existing fetch-all behavior and activate none of
the content-query infrastructure.

Files are the authoring model. A standalone content engine converts an
immutable snapshot of only the files required by configured queries into
one bounded, deterministic runtime database. Builder preview, SSR, and
SSG use the same query semantics without requiring a database service
for a published site.

## Final architecture

```text
Markdown / JSON files
        │
        ▼
ContentSource adapter
(FS or Webstudio Assets)
        │ immutable snapshot
        ▼
ContentCompilationPlan
(union of configured query requirements)
        │
        ▼
ContentCompiler
(parse, normalize, discover fields, enforce budget)
        │
        ▼
ContentArtifact
(bounded, deterministic, immutable JSON)
        │
        ▼
ContentDatabase
(filter, OR groups, sort, paginate, project, read content)
        │
        ├── Builder preview
        ├── SSR runtime
        └── SSG build only
```

The authoring/storage layer owns mutable files. The content engine
consumes immutable snapshots and produces immutable, disposable
artifacts.


Query authoring is a separate OpenAPI-driven path:

```text
Assets REST OpenAPI operation
+ standard request JSON Schema
+ dynamic field paths
        │
        ▼
Generic OpenAPI adapter
        │ resolved schemas, controls, paths, and transport mapping
        ▼
Generic query-builder core and React renderer
        │ arbitrary provider-defined value
        ▼
Assets REST request adapter
        │
        ▼
{ query: value }
```

The selected standard OpenAPI operation is the only source of query UI
semantics. Request parameters and JSON Schema describe the editable
data; the generic renderer derives controls and owns layout.

### Activation and compilation

- The compiler does not index every asset. It combines all reachable
configured Assets-resource queries into one `ContentCompilationPlan`.
- Static constraints such as folder, path, and file type select
candidate files. Dynamic values such as a route-bound slug cannot reduce
the build-time candidate set.
- The plan contains the union of fields used by filtering, sorting,
routing, projection, excerpts, and requested full content.
- Documents shared by multiple resources are stored once in one
deployment-wide runtime database.
- Markdown/frontmatter, JSON properties, excerpts, and full bodies are
prepared only when required.
- No configured content query means no parsing, artifact, or shipped
runtime dependency. Fresh generated apps need no content-runtime
cleanup; incremental generation removes stale integration if a
previously configured query is deleted.

### Runtime database limit

- `CONTENT_DATABASE_MAX_BYTES` limits the complete serialized runtime
database, not source files, images, or unrelated assets.
- The default is `500 * 1024` bytes and is presented as 500 KiB.
- Counted data includes indexed metadata, frontmatter/JSON properties,
excerpts, the field catalog, serialization overhead, and full Markdown
bodies only when requested.
- Prepublish validation builds and serializes the exact database that
will be attached to the immutable build, so it knows the unbounded size,
bounded size, included documents, omitted documents, and affected
resources.
- Overflow never stores partial documents. Candidates are ordered by
`createdAt` descending, canonical path ascending, and stable document ID
ascending. Missing dates follow dated documents. A document that does
not fit is skipped while smaller later documents are still considered.
- Exceeding the limit warns but does not block publishing.
- Builder preview can report exact bounded versus unbounded results when
dynamic expressions have concrete preview values. Prepublish warnings
remain conservative for future route values.

### Snapshot consistency

The source contract guarantees a consistent compilation, while adapters
provide the mechanism:

- Webstudio Assets captures asset metadata and immutable content
references.
- Filesystem sources capture file identity and verify files did not
change before accepting the artifact.
- A changed source retries once, then fails clearly instead of producing
a mixed-revision database.
- This requires no universal snapshot service, source-tree copy, or new
versioned-asset infrastructure.

### Package ownership

- `@webstudio-is/content-engine`: runtime artifact schema, query
execution, field catalog, compact runtime statistics.
- `@webstudio-is/content-engine/compiler`: source snapshots, compilation
plans, Markdown/JSON parsing, deterministic compilation, byte
accounting, and compiler diagnostics. This entry exists to keep
Remark/YAML/future MDX dependencies out of runtime bundles.
- `@webstudio-is/query-builder`: resolves standard OpenAPI operation
schemas into an internal provider-neutral editor model, validation,
mutations, and source serialization. It owns no Assets,
provider-authored UI contract, or fixed REST-query semantics.
- `@webstudio-is/query-builder/react`: container-neutral schema renderer
whose layout is renderer policy. It remains separate from the content
engine.
- SDK: Webstudio Assets/Resource domain models and mapping Webstudio
expressions into generic content requirements.
- Protocol: external Assets REST/OpenAPI transport contracts.
- Asset uploader/repository: asset and folder mutations, generic
metadata, immutable byte references, and storage access. Its hosted
adapter supplies Webstudio Assets snapshots and parsed-metadata cache
persistence to the content engine; parsing, artifact creation, and query
semantics remain engine-owned.
- Builder and generated-app integrations decide when to compile, cache,
embed, load, or discard a database.

### Runtime lifecycle

- Builder caches immutable `ContentDatabase` instances by source
revision plus compilation-plan hash and coalesces concurrent
compilation. Matching operations reuse the same instance; field
discovery uses a dedicated minimal all-properties plan that excludes
excerpts and bodies.
- SSR attaches the validated bounded database to the build and includes
the small runtime only when required.
- SSG uses the database only while generating pages and omits it and the
runtime from final output unless a future runtime-query feature requires
them.
- Local development compiles from the filesystem and uses identical
query semantics.
- Published pages query their local artifact; they do not call Builder
REST endpoints.
- Published artifacts need no external index store, invalidation,
garbage collection, SaaS content proxy, new bucket, or new environment
variable.

## Implemented foundation

These existing parts remain useful and should be moved behind the final
ownership boundaries rather than reimplemented.

- [x] Upgrade the existing Assets system resource in place and preserve
unconfigured fetch-all behavior.
- [x] Implement typed filtering, nested boolean groups, deterministic
sorting, pagination, projections, dynamic values, and content hydration.
- [x] Add Markdown frontmatter, excerpt, JSON-property, and
field-catalog extraction.
- [x] Add reusable query-control implementations and a separately
imported React UI as a foundation for the final OpenAPI-driven contract.
- [x] Add Assets query authoring and dynamic field discovery as existing
behavior to migrate into the Assets OpenAPI operation.
- [x] Add synchronized visual and editable expression authoring.
- [x] Unify Assets REST operations under `/rest/assets/*`.
- [x] Define authenticated collection, item, content, upload, folder,
query, field-catalog, and OpenAPI operations.
- [x] Support Builder cookie authentication and public API token
authentication.
- [x] Add Builder preview, MCP/CLI operations, SSR execution, SSG path
generation, and conditional activation.
- [x] Add revision-keyed parsed metadata persistence for the hosted
Builder.
- [x] Add focused query, API, authorization, Builder, CLI, SSR, SSG,
migration, and fixture coverage.

## Remaining implementation plan

### 1. Establish the content engine

- [x] Rename the generic `@webstudio-is/asset-resource` implementation
to `@webstudio-is/content-engine`.
- [x] Move existing behavior instead of creating a parallel
implementation.
- [x] Keep the primary entry runtime-only and add only the compiler
entry needed for bundle separation.
- [x] Remove the old package after all consumers migrate.
- [x] Ensure the engine has no Builder, SDK, asset-uploader, PostgreSQL,
R2, or deployment-target dependency.

### 2. Define source snapshots and compilation plans

- [x] Introduce `ContentSource.openSnapshot()` and a revision-bearing
`ContentSourceSnapshot`.
- [x] Include canonical path, stable document ID, content type,
immutable content reference, size, and optional `createdAt`.
- [x] Implement Webstudio Assets and filesystem snapshot guarantees
using their adapter-specific mechanisms.
- [x] Introduce `ContentCompilationPlan` for the union of reachable
configured resource requirements.
- [x] Separate statically selectable candidates from dynamic runtime
predicates.
- [x] Add mutation-during-compilation tests for replacement, deletion,
folder movement, and filesystem changes.

### 3. Separate storage from content processing

- [x] Keep upload, replacement, folders, byte storage, revisions, and
generic metadata in the Assets repository/uploader.
- [x] Move parsing, excerpts, field discovery, query execution, and
artifact creation into the content engine.
- [x] Remove content-index coordination from asset mutation business
logic.
- [x] Preserve original source `createdAt` across content replacement
and expose it as optional queryable metadata.
- [x] Keep hosted parsed-document persistence behind the content
compiler's optional cache interface.

### 4. Build deterministic compilation

- [x] Move the existing Markdown, frontmatter, JSON, canonicalization,
hashing, document-building, and tests into the compiler.
- [x] Keep frontmatter behind a dedicated module and continue using the
existing Remark/Micromark pipeline.
- [x] Parse only candidate files and only the tiers required by the
compilation plan.
- [x] Deduplicate documents and fields required by multiple resources.
- [x] Define a versioned, deterministic `ContentArtifact` with integrity
information.
- [x] Keep verbose parse and omission diagnostics outside the runtime
artifact.
- [x] Reject incompatible artifact versions cleanly.

### 5. Enforce the deployment-wide database budget

- [x] Replace the old asset-index limit with
`CONTENT_DATABASE_MAX_BYTES`, defaulting to 500 KiB.
- [x] Have applications read configuration and pass the byte limit into
the compiler.
- [x] Measure the exact serialized database, including selected bodies
and overhead.
- [x] Implement deterministic skip-and-continue packing of complete
documents.
- [x] Return compiler diagnostics with unbounded/bounded bytes,
included/omitted counts, omitted identities, largest contributors, and
affected resources.
- [x] Expose only compact artifact statistics at runtime through
`ContentDatabase.getStats()`.
- [x] Add exact boundary, deterministic ordering, deduplication, and
oversized-document tests.

### 6. Finalize the runtime database

- [x] Define `ContentDatabase` over an immutable artifact.
- [x] Preserve filtering, nested AND/OR groups, sorting, offset/limit,
projection, field references, and content retrieval.
- [x] Expose `getFieldCatalog()` and compact `getStats()`.
- [x] Keep Markdown/YAML/compiler dependencies out of the runtime entry.
- [x] Add execution guards and maximum-size runtime benchmarks.

### 7. Make query authoring OpenAPI-driven

The selected standard OpenAPI operation is the complete query-authoring
contract. The query builder resolves parameters and request-body JSON
Schema, derives its internal editor model, and applies renderer-owned
layout policy. It must not embed or fetch a second capabilities/UI
language through `x-webstudio-query` or another side channel.

- [x] Remove `x-webstudio-query` and all vendor query-definition
metadata from the Assets OpenAPI operation.
- [x] Resolve local OpenAPI references and derive the editable request
value, defaults, validation, labels, choices, arrays, objects, and
unions solely from standard operation parameters and request-body JSON
Schema.
- [x] Represent dynamic Assets field paths with standard JSON Schema
vocabulary in the `queryAssets` request schema.
- [x] Keep the normalized editor representation internal to
query-builder; do not expose another provider-authored capabilities
contract.
- [x] Remove provider-controlled layout metadata such as `group`; make
compact scalar packing and all other layout renderer policy.
- [x] Keep Webstudio expression binding as a consumer/editor concern
layered over schema values, not part of the OpenAPI contract.
- [x] Preserve the existing Assets filter, sort, output selection,
full-content/range selection, limit/offset, editable source, and
configured-field behavior.
- [x] Keep the Assets resource adapter responsible for serializing the
edited query into its request body.
- [x] Remove the obsolete Assets query-capabilities endpoint, URL, and
UI-side capability parsing.
- [x] Add a non-Assets OpenAPI proof with differently named parameters
and no vendor metadata.
- [x] Verify the generic packages contain no Assets imports, fixed
Assets property contract, or provider-authored layout model.
- [x] Update focused core, React, SDK, protocol/OpenAPI, Builder, and
source round-trip tests.

### 8. Manage ContentDatabase lifecycle in Builder

- [x] Cache databases by source revision plus normalized
compilation-plan hash.
- [x] Coalesce concurrent compilation requests.
- [x] Reuse cached database instances across field discovery,
autocomplete, query preview, and response preview when their normalized
compilation plans match.
- [x] Replace it when source revision or query requirements change.
- [x] Preserve the optional revision-keyed hosted parsed-document cache
without making it a source of truth.
- [x] Show exact preview warnings when concrete values reveal missing
bounded results.

### 9. Materialize and verify immutable builds

- [x] Compile and serialize the exact deployment-wide database during
prepublish validation.
- [x] Attach that validated bounded database to the immutable build
without rebuilding it from later asset state.
- [x] Show non-blocking prepublish warnings with database bytes,
omissions, and potentially affected resources.
- [x] Avoid claiming exact future route matches when dynamic values are
unknown.
- [x] Include the database/runtime only when a reachable configured
query requires them.
- [x] Ensure detail resources requesting Markdown content include all
statically eligible bodies needed by dynamic routes.

### 10. Integrate all targets

- [x] SSR: load the build's bounded database and conditionally include
the small runtime.
- [x] SSG: query the same database during generation, then omit
database/runtime output when no runtime query is needed.
- [x] Local/CLI: compile from the filesystem source with the same
semantics.
- [x] Preserve overview pagination, alternative route fields,
draft-as-user-data behavior, and full article rendering.
- [x] Verify ordinary Assets and fresh query-free sites perform no
parser, artifact, content-runtime dependency install, or cleanup work.

### 11. Correct API and package ownership

- [x] Move external Assets REST/OpenAPI contracts to
`@webstudio-is/protocol`.
- [x] Keep Webstudio domain models and Assets system-resource
configuration in the SDK.
- [x] Keep both cookie and token authentication behavior on the unified
Assets REST surface.
- [x] Remove pass-through route wrappers/reexports that add no transport
behavior.
- [x] Keep published runtime queries local to the artifact rather than
routing them through Builder REST.

### 12. Remove superseded deployment infrastructure

- [x] Remove external deployment-index upload, fetch, invalidation,
cleanup, and garbage-collection code.
- [x] Remove the SaaS asset-origin adapter requirement; close
webstudio-is/webstudio-saas#652 as superseded because it has no
independent purpose.
- [x] Remove index-bucket compatibility configuration and avoid adding
Infisical variables.
- [x] Remove obsolete external-index paths, package dependencies,
routes, scripts, and tests.
- [x] Consolidate unreleased intermediate migrations where safe and
retain only schema required by the final hosted cache/API design.

### 13. Verification and release readiness

- [x] Move and preserve existing tests while changing ownership; add new
tests only for changed contracts and behavior.
- [x] Run content-engine compiler/runtime tests, query-builder tests,
SDK/protocol/API tests, Builder tests, CLI tests, and affected
typechecks.
- [x] Run formatting, generated-file idempotence, fixtures, clean
Supabase-compatible migrations, E2E shards, and complete agent
evaluations.
- [x] Verify SSR and SSG conditional inclusion and query-free generated
package manifests.
- [x] Run the five-article MCP blog workflow: authoring, field
discovery, overview, dynamic detail routes, full Markdown rendering,
publishing, and published-site verification.
- [x] Run a maximum-budget database test and a
mutation-during-compilation test.
- [x] Perform a final architecture, security, API compatibility,
migration, bundle, correctness, and DRY review.
- [x] Reconcile every checkbox and replace the verification section with
results from the final architecture before release.

## Future MDX work

MDX is intentionally separate from this release.

- The compiler contract should allow a future build-only MDX parser.
- MDX compilation must not enter the published runtime.
- Embedded JSX must use an explicit compiled representation rather than
runtime source evaluation.
- Webstudio components, tokens, styles, and component allowlists remain
Webstudio integration concerns.
- The future MDX work should reuse `ContentArtifact` and
`ContentDatabase` where practical.

## Superseded design

The following earlier design choices are no longer the target
architecture:

- GROQ or GraphQL as the Assets query language.
- One external or long-lived index object per resource/query.
- A deployment index fetched by the Worker from SaaS/CDN infrastructure.
- Lazy production reads of source Markdown bodies.
- A separate index bucket, asset origin, invalidation service, or
garbage collector.
- A 4 MiB published index limit.
- Rebuilding an old build's database from the current mutable asset set.
- Bundling query infrastructure into projects without a configured
content query.

## Verification baseline

The embedded runtime-database architecture previously passed the checks
below. The OpenAPI-driven query-authoring change additionally passed:

- Query-builder core: 4 files / 19 tests.
- Query-builder React: 1 file / 7 tests.
- SDK Assets source/config: 1 file / 7 tests.
- Protocol Assets OpenAPI: 1 file / 9 tests, including independent
OpenAPI validation.
- Builder Assets OpenAPI description: 1 file / 5 tests.
- Query-builder, React, SDK, protocol, and Builder typechecks.
- Package-boundary validation and formatting of every affected file.

Local verification baseline:

- Content engine: 15 files / 104 tests.
- Asset uploader: 24 files / 175 tests.
- Builder: 204 files / 2,423 tests.
- CLI: 54 files / 866 tests.
- Complete workspace typecheck, formatting, lint, package boundaries,
generated fixtures, and fixture builds.
- The complete migration history applied successfully to a fresh
Supabase-compatible database, including every migration after the
consolidated Assets migration.
- Builder production build and full local E2E suite passed.
- Complete agent evaluations passed: authenticated page (170,859 ms),
design input (207,101 ms), and font assets (67,050 ms).
- Final review additionally verified correct REST edit/view/build
permits, cookie and public-token read paths, immutable snapshot retries,
exact database budgeting, query-free dependency omission, and SSR/SSG
conditional runtime inclusion.

Final staging verification passed against the embedded runtime-database
architecture: MCP uploaded and updated five Markdown articles,
discovered dynamic frontmatter fields, previewed a five-item sorted
overview and one full-body slug query, updated both Assets resources,
found zero binding issues, rendered `/blog` and `/blog/dynamic-routes`
at HTTP 200, published build version 266, and verified both published
routes at HTTP 200 with the expected article metadata and Markdown body.
The workflow also found and fixed offset-form asset timestamps failing
canonical datetime validation and made MCP `preview.start({ port: 0 })`
correctly select an available local port.

## Release constraints

- No new SaaS content service, bucket, or environment variable.
- No published-site database dependency.
- No parser/compiler dependency in query-free sites or runtime-only
bundles.
- The validated content database is immutable build output.
- Publishing warnings do not block deployment.
- The selected standard OpenAPI operation and its request JSON Schema
are the only source of query UI semantics.
2026-07-31 00:17:46 +02:00
Oleg Isonen 7bc9942774 perf: Improve MCP evaluation reliability and efficiency (#5959)
## Summary

- capture bounded MCP failure codes, validation issue paths, per-tool
latency, mutation timing, uncached input, catalog size, and
per-call/per-tool response bytes in every evaluation result
- require every raw fixture outcome to have zero failed calls and zero
retries, even when the workflow later recovers
- update baselines only when all raw outcomes and all regression
comparisons pass
- refuse to replace an accepted aggregate token baseline with a noisier,
higher-token sample
- regression-gate aggregate response bytes alongside tokens, calls,
focused reads, mutations, errors, and retries
- compact repeated SDK schemas while preserving required arguments,
destructive safety controls, and ordinary optional fields for common
goal-guided tools
- omit low-frequency optional argument names until focused discovery,
reducing the initial tool handshake without removing callable tools
- stop echoing the caller's goal from `meta.guide` responses
- make evaluations copy their canonical objective verbatim into
`meta.guide`, preventing vague paraphrases from selecting a generic
workflow
- normalize grouped `styles` and `declarations` maps into canonical flat
`update-styles` operations before validation
- normalize relative `create-page` paths through the platform URL parser
- bundle the four bounded authentication discovery reads into one
`inspect-auth-context` call
- bound large MCP style-key mutation results while preserving a
representative sample and exact total count
- combine fragment insertion with immediate persisted binding
verification to remove a sequential model turn

## Root causes and impact

Recovered MCP failures could previously be reported as successful raw
outcomes, and baseline files could be written before the complete
comparison result was known. Raw outcomes now fail on any MCP error or
retry, and accepted baselines are written only after every fixture and
comparison passes.

Rejected samples exposed two concrete error sources. A vague
authentication objective selected a generic workflow and produced four
validation failures, 20 calls, and 1.07M tokens; evaluations now pass
the canonical objective verbatim. A relative `create-page.path` caused
an `INVALID_INPUT` failure and retry; the adapter now canonicalizes it
before validation.

The deterministic catalog in the accepted baseline measures **50,864
bytes**, down from **53,317 bytes** (−4.60%). Input schemas fell from
**31,190 to 28,737 bytes** (−7.86%). The two composite workflows add two
conditionally exposed tools and 360 catalog bytes (about +0.71%) when
their backing operations are available.

Broad experiments that removed focused descriptions or all goal-specific
examples made guide responses smaller but increased token use or caused
retries. Those variants were rejected. The current implementation
compacts only recognized goal guides, while retaining the detailed
`update-styles` schema and the `upload-assets` batch example proven
necessary by the evaluations.

## Workflow-churn iteration

Authenticated discovery uses one model-visible `inspect-auth-context`
call. Fragment authoring can now use `insert-fragment-verified`, which
commits the insertion and immediately runs persisted binding
verification for up to 200 bindings. This removes the following
sequential verification turn without changing mutation or verification
counts.

Current deterministic workflow shape:

- authenticated workflow calls: **14 → 10** (−28.57%)
- design workflow calls: **17 → 16** (−5.88%)
- aggregate workflow calls: **39 → 34** (−12.82%)
- failures: **0**
- retries: **0**
- authenticated MCP response bytes: **52,524 → 46,900** (−10.71%)
- authenticated guide response: **26,782 → 24,358 bytes** (−9.05%)

One complete run measured authenticated tokens at **348,225** (−11.44%)
and first verification at **38.3s** (−30.14%); design first verification
moved to **28.1s** (−27.27%). The final exact-code run also passed with
**10/16/8** calls and zero failures/retries, measuring authenticated
tokens at **377,802** (−3.92%) and design first verification at
**34.5s** (−10.67%).

The composite preserves post-commit safety: if verification
infrastructure fails after insertion, the result remains
`committed:true`, returns `POST_COMMIT_VERIFICATION_FAILED`, and
explicitly instructs the agent not to repeat the insertion. A guarded
baseline-update run was rejected because stochastic aggregate tokens did
not beat the accepted result, so no result artifacts were rewritten.

## Style response compaction

Large style mutations previously returned every generated style key. In
the design fixture, that single successful response was **19,121 bytes**
and remained in context for all later turns. MCP responses now retain
the first 20 keys plus `styleKeyCount` and `styleKeysTruncated`; the
typed runtime operation remains unchanged.

Focused evaluation results:

- `update-styles` response: **19,121 → 2,815 bytes** (−85.28%)
- design-workflow MCP responses: **70,941 → 54,633 bytes** (−22.99%)
- calls: **17 → 17**
- failures/retries: **0 / 0**
- tokens: **498,764 → 505,136** (+1.28%, treated as noise and not
accepted as a new baseline)

The subsequent complete `pnpm evaluations` run passed all three fixtures
with exact **11/17/8** call sequences and zero failures/retries. The
accepted lower-token baseline remains unchanged.

## Goal-guide context compaction

Recognized goal guides no longer repeat every selected tool's
description and examples. Current Codex clients defer MCP tools and load
each named tool's exact contract before invocation, so the guide keeps
the goal-specific workflow while returning compact tool references.
Free-form guide searches remain fully descriptive.

Two complex inputs remain intentionally hydrated: `update-styles` keeps
its detailed schema, and `upload-assets` keeps one batch example.
Removing the upload example caused five failed attempts in a complete
run; restoring only that example returned the font workflow to its exact
8-call, zero-error path.

Final complete-suite results:

- calls: **10 / 16 / 8** (**34 aggregate**)
- failures/retries: **0 / 0**
- goal-guide payload: **58,082 → 37,718 bytes** (−35.06%)
- authenticated MCP responses: **46,900 → 38,268 bytes** (−18.41%)
- design MCP responses: **51,854 → 44,008 bytes** (−15.13%)
- aggregate MCP responses versus the accepted baseline: **147,335 →
101,922 bytes** (−30.82%)
- aggregate tokens: **1,146,951**, only **+0.33%** above the stricter
accepted 1,143,217-token baseline

The complete suite and every per-fixture comparison passed. The guarded
updater did not replace the accepted artifacts because the aggregate
token sample did not beat the existing baseline.

## Responsive verification batching

The MCP now exposes `screenshot.responsive` when reusable page capture
is available. It accepts one generated route plus 1–8 viewports,
refreshes the session preview once, reuses one browser target, and
returns bounded evidence for every viewport. Auth and design evaluation
workflows use one responsive capture instead of a separate preview start
and two screenshot turns.

Automatic screenshots now allocate an available preview port and reuse
an already-running managed preview port. This prevents an unrelated
service on the historical 5173 default from producing an MCP failure.
Explicit ports, local previews, and external URLs remain unchanged.

The evaluator records the bounded viewport array, counts the batch as
verification and visual evidence, and compares its latency, response
size, calls, errors, retries, and token consumption on every run. The
new regression tests were demonstrated fail-then-pass.

Guarded accepted results:

- aggregate tokens: **1,143,217 → 990,190** (−13.39%)
- aggregate calls: **39 → 30** (−23.08%)
- aggregate MCP response bytes: **147,335 → 98,470** (−33.17%)
- failures/retries: **0 / 0**
- authenticated calls: **14 → 8** (−42.86%)
- design calls: **17 → 14** (−17.65%)

## Design and font workflow batching

Design discovery now uses one conditionally exposed
`inspect-design-context` call to return bounded pages, breakpoints,
design tokens, assets, and variables instead of five model-visible
reads. Font persistence now uses one `verify-font-assets` call to
refresh the asset namespace and return every changed font asset instead
of a refresh plus separate verification reads.

The evaluation tasks and validators require these composite paths. Both
tools retain the underlying operation limits, namespace metadata,
persisted-result checks, and zero-error/retry gates. Review also
confirmed that SDK schemas must keep `additionalProperties:false` and
that non-default MCP safety hints must remain explicit; those protocol
constraints were preserved rather than traded for catalog-token savings.

Guarded accepted improvements versus the previous responsive-batching
baseline:

- aggregate tokens: **990,190 → 914,760** (−7.62%)
- aggregate calls: **30 → 24** (−20.00%)
- aggregate focused reads: **8 → 2** (−75.00%)
- aggregate MCP response bytes: **98,470 → 95,614** (−2.90%)
- design calls: **14 → 10** (−28.57%)
- font calls: **8 → 6** (−25.00%)
- failures/retries: **0 / 0**

The strict SDK catalog is **51,362 bytes** with **28,964 input-schema
bytes**. The two new conditional workflow tools add 355 catalog bytes
(+0.70%) and 130 schema bytes (+0.45%) while removing six model-visible
workflow turns.


## Terminal responsive verification

Auth and design now finish with one conditionally exposed
`verify-page-responsive` call. It captures every requested viewport in
one browser session and immediately runs the static page audit, removing
one sequential model turn per workflow while retaining both kinds of
evaluator evidence. The tool inherits the audit operation's permit and
read namespaces; strict SDK schemas and MCP safety annotations remain
unchanged.

Latest complete comparison against the accepted baseline:

- aggregate tokens: **914,760 → 869,274** (−4.97%)
- aggregate calls: **24 → 22** (−8.33%)
- aggregate MCP response bytes: **95,614 → 95,053** (−0.59%)
- authenticated calls: **8 → 7**
- design calls: **10 → 9**
- font calls: **6 → 6**
- failures/retries: **0 / 0**
- authenticated focused run: **289,078 tokens** (−10.06%) and first
verification **55,552 ms** (−17.90%)
- design focused run: p95 MCP latency **9,642 ms** (−10.32%); token and
first-verification variance increased in that individual sample, so only
the complete comparison is used for the aggregate conclusion

The complete comparison passed all fixture and aggregate regression
gates. Two subsequent guarded `--update-baselines` attempts could not
start any fixture because the external Codex runner had reached its
usage limit; both exited before the first MCP call and wrote no accepted
result files. Therefore the tracked accepted baseline below remains
**914,760 tokens / 24 calls**, while **869,274 tokens / 22 calls** is
the latest successful complete comparison.

Regression coverage was demonstrated fail then pass. After this
iteration, project-build MCP tests passed **105/105**, high-impact
evaluation tests passed **41/41**, and project/CLI typechecks, lint,
package boundaries, generated docs, and diff checks all passed.

## Accepted evaluation baseline

| Fixture | Failed | Retries | Calls | Mutations | Tokens | Uncached
input | Response bytes | First mutation | First verification |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| authenticated-page-v1 | 0 | 0 | 8 | 4 | 321,396 | 44,353 | 37,536 |
39,076 ms | 67,660 ms |
| design-input-v1 | 0 | 0 | 10 | 6 | 330,580 | 54,441 | 40,036 | 30,419
ms | 36,551 ms |
| font-assets-v1 | 0 | 0 | 6 | 3 | 262,784 | 20,704 | 18,042 | 37,609 ms
| 47,073 ms |

Accepted aggregate: **914,760 tokens**, **24 calls**, **2 focused
reads**, and **95,614 MCP response bytes**, with zero failures and zero
retries. Compared with the previous accepted baseline, tokens fell
**7.62%**, calls fell **20.00%**, focused reads fell **75.00%**, and
response bytes fell **2.90%**.

## Verification

- [x] Complete `pnpm evaluations -- --update-baselines`
- [x] Independent complete `pnpm evaluations` after the composite
workflow change
- [x] Worse-token and error-containing samples rejected without
replacing accepted baselines
- [x] Added/changed regression tests demonstrated fail then pass
- [x] Project-build MCP tests: 105 passed
- [x] Complete high-impact evaluation tests: 41 passed
- [x] Project-build and CLI typechecks
- [x] `pnpm lint`
- [x] `pnpm check:package-boundaries`
- [x] `pnpm check:generated-docs`
- [x] `git diff --check`
- [x] Earlier workspace tests, including 2,356 builder tests
- [x] Earlier generated API checks
- [ ] Fixture sync/build: sync could not reach
`main.development.webstudio.is` and timed out; no local test,
evaluation, or code check failed

## Implementation checklist

- [x] Error and retry rate enforced at zero for raw and compared
outcomes
- [x] Relative page paths normalized to prevent a known validation
failure and retry
- [x] Baseline replacement blocked unless every outcome and comparison
passes
- [x] Aggregate token baselines cannot ratchet upward
- [x] Workflow churn bounded and regression-gated
- [x] Authentication discovery collapsed from four model-visible reads
to one
- [x] Fragment insertion and persisted binding verification combined
safely
- [x] Large style-key mutation results bounded at the MCP boundary
- [x] Token consumption captured, compared, and regression-gated
- [x] Response bytes captured per call and tool, summarized, and
aggregate regression-gated
- [x] Per-tool latency, mutation timing, catalog size, and validation
paths captured
- [x] Repeated catalog/schema and focused-guide context reduced
- [x] Canonical goal selection stabilized for evaluations
- [x] Grouped style maps normalized before validation
- [x] Responsive verification batches desktop and mobile evidence in one
call
- [x] Automatic screenshot previews avoid occupied default ports
- [x] Responsive viewport evidence is captured and regression-gated
- [x] Accepted evaluation artifacts preserve the best measured token
baseline
2026-07-30 11:34:02 +02:00
Oleg Isonen e80ca3b54c fix: Improve MCP authoring and screenshot reliability (#5957)
Closes #5954
Closes #5951
Closes #5950
Closes #5953

## Summary

- route external screenshot `url` and `baseUrl` targets through the
self-closing browser path
- keep reusable Chromium sessions limited to Webstudio-managed session
previews
- validate typed style values at the public runtime boundary while
retaining CSS strings for design tokens
- build MCP and shell validation messages from compact structured issues
- advertise typed style objects with a concrete keyword example
- persist `update-asset` metadata patches to the related file record and
verify the saved value
- store multi-sentence page titles and metadata as fixed text without
misclassifying sentence punctuation as member access
- capture privacy-safe aggregate token usage and MCP workflow metrics in
every high-impact evaluation result
- compare each evaluation with a compatible checked-in baseline and fail
on correctness, token, tool-use, error/retry, broad-read, or MCP-latency
regressions

## Root causes

### External screenshot lifecycle

The fast iterative preview change made `session` the default preview
source. External captures were then treated as managed session-preview
captures and opened a reusable Chromium session. One-shot MCP processes
do not call `preview.stop`, so the browser kept the process alive and
could be orphaned when the caller killed the hung CLI.

### Validation errors and schemas

`update-styles` declared `value` as unconstrained input, and
design-token objects were checked only for a string `type`. Invalid
values therefore passed the advertised/input schema and failed later in
the full `StyleValue` parser, exposing the raw Zod union message. Error
serialization already carried flattened issues but did not use them for
`error.message`.

### Asset metadata persistence

`update-asset` correctly produced an `assets/[id]/meta` patch, but asset
persistence compared only Asset-table fields. Metadata lives on the
related File row, so the patch was treated as unchanged and the
successful mutation never wrote the new value.

### Page text expression disambiguation

Page text normalization treated a period followed by whitespace and a
word as JavaScript member access. Normal prose such as `Marques. Toutes
nos marques` was therefore validated as an expression and rejected
instead of being stored as a string literal.

### Evaluation observability

The evaluation result only stored duration and two call counts, so token
cost, failures, retries, mutation flow, verification coverage, and MCP
latency could regress without a durable comparison. Results now use a
bounded schema-v2 aggregate and never persist prompts, transcripts,
stdout/stderr, credentials, arguments, or response payloads.

## Impact

- external screenshots complete without retaining browser processes
- repeated managed-preview screenshots retain browser reuse
- invalid style inputs fail at the public boundary with paths such as
`updates.0.value`
- `error.message` is concise and actionable instead of a repeated raw
union dump
- generated schemas no longer advertise primitive or array values for
`update-styles`
- supported design-token CSS strings remain accepted
- `update-asset` font metadata remains changed after commit, refresh,
and reload
- `create-page` and `update-page` accept ordinary multi-sentence titles
and SEO descriptions while preserving computed expressions
- every high-impact run reports input, cached-input, cache-write,
output, reasoning-output, total-token, and cache-rate aggregates
- MCP results report calls, success/failure, retries, focused/broad
reads, dry runs, planned/committed mutations, verifications,
total/p50/p95 latency, and first-mutation/verification timing
- compatible results are compared with accepted baselines using a 15%
relative regression threshold; correctness failures and zero-baseline
errors, retries, or broad reads remain zero-tolerance
- stochastic wall-clock and milestone timings remain visible as deltas
without making a single noisy run fail

## Todo

- [x] Reproduce external URL browser-session routing
- [x] Use self-closing capture for external screenshots
- [x] Preserve browser reuse for managed session previews
- [x] Reproduce primitive style-value schema acceptance
- [x] Validate typed style values at the public boundary
- [x] Preserve CSS-string design-token inputs
- [x] Format stdio and shell validation messages from structured issues
- [x] Regenerate and verify runtime operation contracts
- [x] Reproduce dropped asset metadata at the persistence boundary
- [x] Persist and verify related File metadata updates
- [x] Reproduce multi-sentence page text failures on create and update
- [x] Distinguish sentence punctuation from computed member access
- [x] Add privacy-safe token and MCP workflow metrics
- [x] Add per-fixture baseline comparisons and regression gates
- [x] Refresh accepted schema-v2 baselines for all fixtures
- [x] Review the complete diff
- [x] Run repository checks and the complete agent evaluation suite

## Verification

- `pnpm checks` — passed, including workspace tests, typechecks, lint,
package-boundary checks, generated API/docs checks, fixture sync, and
fixture builds
- builder tests — 189 files, 2,356 tests passed
- CLI tests — 53 files, 852 tests passed
- project-build tests — 81 files, 2,023 tests passed
- asset-uploader tests — 11 files, 98 tests passed
- targeted evaluation metrics/regression/trace/runner tests — 5 files,
17 tests passed
- all four issue regression tests and the new evaluation harness tests
were demonstrated failing without their implementations and passing with
them
- `pnpm evaluations -- --update-baselines` — 3/3 fixtures passed and
schema-v2 baselines were updated
- a subsequent real `font-assets-v1` result compared successfully after
the regression policy was finalized
2026-07-29 19:33:24 +02:00
Oleg Isonen 5141f61f75 fix: prevent mixed router dependencies in MCP previews (#5948)
## Summary

- generate MCP previews from the standalone React Router template
- prevent Remix and React Router runtimes from being merged into one
dependency graph
- keep the normal Remix build path unchanged

## Root cause

The preview generator combined the complete React Router template with
the Remix defaults template. That installed React Router 7 alongside
Remix-provided React Router DOM 6, causing Vite to fail on incompatible
exports before the iterative preview server became ready.

## User impact

`preview.start({ source: "session", mode: "iterative" })` can now start
successfully, so agents can reuse the preview for fast edit, reload,
screenshot, and vision cycles.

## Verification

- [x] Generated a preview from production-size project data and received
HTTP 200
- [x] Verified the generated package contains React Router and no Remix
router dependencies
- [x] 55 targeted CLI preview, screenshot, and MCP preview tests
- [x] CLI typecheck and formatting
- [x] `pnpm checks`
- [x] `pnpm evaluations` (all three real agent fixtures passed)
2026-07-24 15:18:05 +02:00
Oleg Isonen b2a34f1713 feat: Fast MCP iterative previews (#5947)
## Summary

This PR documents a measured architecture plan for making the MCP
edit-to-screenshot loop fast enough and reliable enough for iterative
site authoring. It intentionally changes no runtime behavior yet.

The current implementation rebuilds a production preview after small
committed mutations. Testing an editable local clone of the production
Webstudio homepage also exposed a correctness gap: a path screenshot
called directly after a mutation can return a stale, byte-identical
image.

## Measured baseline

Repository fixture:

- committed text edit: **24-25 ms**
- post-edit regeneration, production build, and server restart: **7.9
s**
- first screenshot after restart and browser relaunch: **9.1 s**
- combined first post-edit screenshot: **17.1 s**
- unchanged warm screenshot: **1.1 s**

Production homepage, read-only:

- remote refresh: **3.1 s**
- complete production preview preparation/start: **16.0 s**
- cold homepage screenshot: **10.2 s**
- unchanged warm screenshot: **1.36 s**
- predicted post-edit screenshot from measured phases: **approximately
26.2 s**

Editable local production-homepage clone:

- retained **43 routes** and **266 homepage text nodes**
- committed heading mutation: **0.81-0.87 s**
- explicit post-edit preview generation/build/start: **11.6-12.6 s**
- first screenshot after explicit preview start: **9.8-11.8 s**
- complete mutation-to-visible-screenshot cycle: **22.9-25.2 s**
- complete edit, verify, screenshot, restore, and stop run: **52.7 s**

The changed screenshot visibly rendered the test heading, and the
restored screenshot matched the original byte for byte.

## Correctness finding

Calling a path screenshot directly after the committed mutation took
**20.1 s**, but both post-edit captures were byte-identical to the
baseline and rendered the old heading. Explicitly calling
`preview.start({ source: "session" })` made the edit visible.

The reported generated-build version also remained at 1 while the
project session advanced through versions 4 and 5. Current screenshot
output therefore cannot prove that it rendered the mutation it is meant
to verify.

## Proposed direction

- [ ] Introduce explicit iterative and production preview modes under
one controller contract.
- [ ] Keep a Vite development preview and browser alive for MCP
authoring screenshots.
- [ ] Preserve production preview for rendered audits and final
verification.
- [ ] Regenerate from the authoritative project session, wait for Vite
compilation, then normally reload the retained browser page.
- [ ] Make a direct post-mutation path screenshot refresh the latest
committed session without using HMR.
- [ ] Add a project-version freshness handshake so stale screenshots
fail.
- [ ] Serialize and coalesce regeneration after rapid mutations.
- [ ] Return preview mode, rendered project version, and complete phase
timings.
- [ ] Add lifecycle, integration, and local agent evaluation coverage.

## Performance target

Warm edit-to-screenshot latency should be at most **3 seconds p95**
across ten sequential small edits, without invoking `npm run build`,
`npm run start`, or launching another browser.

## Verification

- [x] Measured the source CLI against the authenticated repository
fixture.
- [x] Measured the production homepage without changing production.
- [x] Synchronized the production bundle into a disposable local Builder
project.
- [x] Committed and visually verified a real heading edit through local
MCP.
- [x] Restored the original heading and verified the restored screenshot
byte for byte.
- [x] Reproduced the stale direct-screenshot behavior.
- [x] Formatted the plan with `oxfmt`.
- [x] Verified the documentation diff with `git diff --check`.

The complete architecture, race handling, test matrix, acceptance
criteria, and non-goals are in
`apps/builder/docs/mcp-iterative-preview-plan.md`.
2026-07-24 01:05:10 +02:00
9a087c573a fix: use local URLs for expression assets in exports (#5945)
Fixes #5763

## Description

Assets selected directly in a project already use the generated app's
configured asset base. Assets referenced through `assets.data[...]`,
however, were still emitted with builder-only `/cgi/` URLs, so those
references broke in Docker and other self-hosted exports.

This makes generated asset resources use the same local asset base as
direct asset props while keeping their runtime metadata. The live
builder continues to use its existing `/cgi/` routes.

## Steps for reproduction

1. Upload an audio file and reference `assets.data["<asset-id>"].url`
from the expression editor.
2. Generate a self-hosted project.
3. Inspect `app/__generated__/$resources.assets.ts`.
4. The asset URL is now `/assets/<filename>` instead of the unavailable
`/cgi/asset/<filename>?format=raw` route.

## Testing

- `pnpm --filter webstudio test -- src/prebuild.test.ts -t "uses the
local asset base"`
- `pnpm --filter webstudio exec vite build`
- `pnpm exec oxfmt --check packages/cli/src/prebuild.ts
packages/cli/src/prebuild.test.ts`
- `pnpm exec oxlint --deny-warnings packages/cli/src/prebuild.ts
packages/cli/src/prebuild.test.ts`

## Code Review

@kof, could you please:

- [ ] Review the generated asset URL behavior
- [ ] Review the implementation and regression test
- [ ] Verify an expression-based asset in a self-hosted preview

## Before requesting a review

- [x] Made a self-review
- [x] Added a comment explaining why generated exports override the
runtime URL
- [x] Added a regression test

---------

Co-authored-by: Sviat Barbutsa <9897782+sviat-barbutsa@users.noreply.github.com>
Co-authored-by: Oleg Isonen <oleg008@gmail.com>
2026-07-23 00:11:16 +02:00
Oleg Isonen c3c0e32204 fix: make MCP font assets editable and deterministic (#5944)
Closes #5943
Closes #5942

## User impact

MCP-managed font assets now keep their identity, metadata, and generated
CSS behavior predictable across upload, editing, synchronization, and
rendering.

## Changes

- Preserve explicit font metadata overrides while validating supported
fields and rejecting unsupported metadata instead of silently dropping
it.
- Expose font metadata through `update-asset`, with partial updates
merged into the existing metadata and validated before the mutation is
committed.
- Prefer the typographic family name when reading font files, so
Fontsource and Google font files resolve to the same logical family
where the file provides that information.
- Deduplicate generated font sources by URL and format, choose a
deterministic source when legacy assets collide, and derive the CSS
format hint from the filename when historical metadata is stale.
- Add MCP and CLI examples explaining font metadata upload and
correction.
- Add regression coverage for metadata persistence, invalid overrides,
family-name extraction, duplicate source handling, stale format
metadata, and generated runtime contracts.

## Verification

- `pnpm checks`
- 46 workspace packages tested, including 2,355 Builder tests, 809 CLI
tests, 2,019 project-build tests, and 97 asset-uploader tests.
- All workspace typechecks, Oxlint, package-boundary checks, generated
API/docs checks, and fixture link/sync/build checks passed.
2026-07-22 19:04:53 +02:00
Oleg Isonen 54aa7be145 fix: Make MCP authoring reliable across assets, styles, and embeds (#5932)
Closes #5924
Closes #5925
Closes #5926
Closes #5927
Closes #5928
Closes #5929

## Outcome

Makes MCP and CLI authoring predictable across project-wide CSS
variables, font uploads, retried asset uploads, destructive asset
selection, design-token collisions, and SVG HtmlEmbed edits.

## Delivered

### Project-global CSS variables

- [x] `define-css-variable` writes to `ROOT_INSTANCE_ID` / `:root`
instead of the home-page Body.
- [x] Breakpoint and overwrite behavior is preserved, and compact
results identify the root scope.
- [x] Existing body-local declarations remain untouched.
- [x] Runtime and Builder integration tests cover root selection and
generated project behavior.

### Font metadata and upload overrides

- [x] Static fonts prefer authoritative `OS/2.usWeightClass`.
- [x] Fallback matching normalizes spaces, hyphens, and underscores and
checks specific aliases before shorter ones.
- [x] Explicit format and partial metadata overrides travel through
HTTP, filesystem, and S3 upload paths and are validated after merging
with detected metadata.
- [x] Regression tests cover ExtraBold, Extra-Bold, Semi Bold Italic,
Ultra Light, valid weight classes, invalid weight classes, partial
overrides, and invalid overrides.

### Idempotent asset uploads

- [x] API uploads compute a project-scoped SHA-256 content hash.
- [x] Sequential and concurrent duplicate uploads reuse the existing
asset and return `deduplicated: true`.
- [x] `force: true` bypasses deduplication for intentional duplicates.
- [x] A partial unique index enforces one non-null content hash per
uploader project.
- [x] Stale reservations are cleaned up and active concurrent uploads
are bounded by polling and an actionable retry error.
- [x] HTTP, protocol, uploader, and CLI tests cover hash reuse,
uniqueness races, force propagation, and result markers.

The migration does not backfill historical files. Existing assets begin
participating in deduplication when uploaded through the new path;
matching content keeps the existing asset's metadata rather than
silently rewriting it.

### Consistent asset inputs and permissions output

- [x] `delete-asset` exposes exact `assetIds` and explicit
`assetIdPrefixes`.
- [x] The legacy `assetIdsOrPrefixes` input remains accepted and is
marked deprecated.
- [x] Exact ids no longer accidentally select longer prefixed ids.
- [x] `webstudio permissions` prints a readable role/capability summary
by default while `--json` remains unchanged for machine callers.
- [x] Help and discovery describe JSON output as optional.
- [x] Runtime, CLI, metadata, and generated-contract tests cover
canonical and compatibility behavior.

### Deterministic fragment design tokens

- [x] Fragment insertion reconciles incoming tokens against project
tokens and earlier tokens in the same fragment.
- [x] Equal name/style tokens are reused instead of creating suffixed
twins.
- [x] Same-name/different-style fragments require an explicit `ours`,
`theirs`, or `merge` policy at the public runtime boundary.
- [x] Builder's established internal paste behavior retains its explicit
incoming-value default.
- [x] `create-design-token` accepts documented CSS strings through the
property-aware CSS parser as well as typed style values.
- [x] Tests cover same-fragment reuse/conflicts, persisted tokens,
explicit policies, and CSS string parsing.

### Editable SVG HtmlEmbed content

- [x] HtmlEmbed validation uses parse5 parser errors and source
structure instead of serialization-string equality.
- [x] Valid inline SVG is accepted without silently normalizing authored
markup.
- [x] Fragment insertion now uses the same validator as prop update and
text replacement paths.
- [x] Malformed markup is rejected before mutation.
- [x] Regression tests cover realistic SVG, parser failures, and
no-partial-mutation behavior.

## Verification

- [x] `pnpm checks`: all workspace tests, typechecks, lint, package
boundaries, generated API/docs checks, and fixtures passed on the final
committed tree.
- [x] `pnpm --filter webstudio test:release-smoke`: packaged install,
compact comparison, preview, agent workflow, stdio MCP, and structured
commands passed.
- [x] Prisma schema validation passed with test connection variables.
- [x] Two minimally prompted weak-model subagents independently
exercised the changed CLI/MCP discovery and focused workflows.
- [x] The subagent-found stale `permissions --help` requirement was
fixed, regression-tested, and retested.
- [x] Final diff and worktree are clean.
2026-07-21 14:36:54 +02:00
Oleg Isonen cfba520e6d feat: Open text assets in code editor (#5918)
## What changed

- open every textual asset type from the upload registry in an editable
CodeMirror dialog
- select installed CodeMirror language support by MIME type and use
plain text editing as the fallback
- support `txt`, `csv`, `md`, `js`, `css`, `json`, `html`, `xml`, and
`svg` without adding asset-specific language branches to the shared
editor
- keep the canvas mounted and interactive behind the dialog
- persist edits on blur, `Cmd/Ctrl+S`, or `Cmd/Ctrl+Enter` through the
asset replacement pipeline
- preserve folder and description metadata and repoint supported asset
references
- clean up failed replacement uploads instead of leaving orphan assets

## Impact

Users can open, edit, and persist all text-based upload formats directly
in the builder without replacing or reloading the canvas. New `text/*`
upload types will automatically become editable as plain text; installed
syntax support is selected by MIME type.

## Validation

- `pnpm --filter @webstudio-is/builder test --
app/builder/features/text-file-editor/text-file-utils.test.ts
app/builder/shared/assets/replace-asset.test.ts
app/builder/shared/asset-manager/asset-manager.test.tsx`
- `pnpm --filter @webstudio-is/builder typecheck`
- `pnpm exec oxlint --deny-warnings <changed files>`
- `pnpm exec oxfmt --check <changed files>`
- `git diff --check`
- verified the running dev server applied the changes through Vite HMR

Ref #5824
2026-07-20 13:42:06 +02:00
Oleg Isonen 597642ac2e fix: Accept numeric page status codes (#5915)
## Summary

- accept fixed page status codes as JSON numbers from 200 through 599
- preserve dynamic status expressions and backwards-compatible numeric
strings
- remove a stored status when the Builder input is cleared, while
leaving omitted status values untouched
- advertise the correct number-or-expression contract through runtime
and MCP schemas
- update CLI guidance and examples to use numeric status values

## Testing

- `pnpm --filter @webstudio-is/project-build exec vitest run
src/runtime/pages.test.ts src/contracts/builder-runtime.test.ts
src/mcp.test.ts`
- `pnpm --filter @webstudio-is/project-build typecheck`
- `pnpm --filter webstudio typecheck`
- `pnpm lint`
- `pnpm check:package-boundaries`
- `pnpm check:generated-api`
- `pnpm check:generated-docs`

Closes #5913
2026-07-18 09:29:01 +02:00
Oleg Isonen af29a0cef7 fix: Improve shared Slot selector guidance for MCP agents (#5910)
## What changed

- documents `extract-slot.instanceSelector` as a leaf-to-root occurrence
path
- provides valid examples for sections directly under Body and nested in
a page wrapper
- exposes those examples through `meta.get_more_tools`
- makes invalid parent ordering errors explain how to recover using
`list-instances` IDs and `parentId`
- regenerates the public runtime schema with the selector contract

## Why

Agents could discover `extract-slot` but could not determine the
selector ordering expected by the runtime. Plausible selectors failed
with a generic direct-parent error, and focused MCP discovery returned
no working example.

## User impact

Agents can now reliably convert existing sections into shared Slots
without guessing the Navigator path format. Invalid selectors return
enough context to correct the call instead of repeatedly probing the
project.

## Verification

- project-build slot and MCP tests: 108 passed
- protocol operation docs and operation tests: 17 passed
- CLI MCP tests: 35 passed
- project-build, protocol, and CLI typechecks
- repository lint
- package-boundary check
- generated API and documentation checks
2026-07-18 02:35:10 +02:00
Oleg Isonen 878d6f1de1 feat: Add asset folders to asset manager and improve asset manager UX (#5892)
Closes https://github.com/webstudio-is/webstudio/issues/5877
Closes https://github.com/webstudio-is/webstudio/issues/4775


- Organize assets into nested folders.
- Navigate folders with breadcrumbs and Back controls.
- Select and manage multiple assets and folders at once.
- Drag, copy, cut, paste, duplicate, move, and delete items.
- Use context menus and familiar keyboard shortcuts for common actions.
- Search and sort assets and folders, with folders grouped first.
- Upload files directly into the active folder.
- Manage folder placement from asset and folder settings.
- Automate asset and folder management through MCP.
2026-07-17 23:39:14 +02:00
Oleg Isonen d440e02990 feat: Add safer MCP authoring and draft-page verification (#5905)
- **Restore points for agent work**: Create named restore points before
major edits, review changes with a dry run, and safely revert project
content if needed.

- **Shared Slot authoring**: Agents can turn existing sections into
shared Slots and insert linked copies across pages, including valid
nested Slots.

- **DTCG and Figma token imports**: Import design tokens and CSS
variables through CLI, MCP, or direct paste, with aliases, modes,
composite values, and mappings supported.

- **Consistent token conflict handling**: Every paste workflow now
offers the same preserve, rename, or merge choices instead of silently
overwriting existing design tokens.

- **Draft-page previews**: Agents can generate and inspect previews of
draft pages without publishing them or exposing drafts in production
builds.

- **Safer MCP mutations**: Destructive operations require explicit
confirmation, invalid raw patches and invented record IDs are rejected,
and restore operations commit atomically.

- **More dependable agent contracts**: New tools have complete runtime
schemas, clearer validation errors, and consistent behavior across CLI,
MCP, Builder, and server APIs.
2026-07-17 23:16:39 +02:00
Oleg Isonen 13c0351a03 fix: Move agent connection setup from Builder to the CLI (#5899)
## Summary

- remove the misleading **Connect your agent** section from Builder
Project Settings
- make the CLI the sole owner of MCP client configuration
- verify the linked project endpoint and credential before changing
client configuration
- safely merge Webstudio into existing Claude Code, Cursor, and VS Code
MCP files
- print the explicit global registration command for Codex instead of
editing its global configuration silently
- document the agent-led setup flow and safe handling of editable share
links

## Why

Builder runs in the browser and cannot configure files or global
settings on a user's local machine. The previous Project Settings UI
duplicated client definitions in the protocol package, exposed a setup
command containing the project credential, and could appear successful
without proving that the local agent was connected.

This moves local-client concerns into the CLI, removes the browser-only
setup surface, and makes configuration success depend on a valid,
reachable project link.

## User impact

A user can ask their agent to connect the current folder to Webstudio.
The agent links and synchronizes the project, runs `webstudio connect
<client>`, reloads the client, and verifies the connection by listing
project pages.

Invalid or stale links fail before any client file is changed, with a
credential-safe recovery message.

## Validation

- full CLI suite: 50 files, 786 tests
- full Builder suite: 163 files, 2,148 tests
- protocol suite: 73 tests
- CLI, Builder, and protocol typechecks
- root lint and package-boundary checks
- generated API and documentation checks
- real VS Code MCP handshake against a saved project: 156 tools
discovered
- fresh weak-model subagent test: repeated connection remained
idempotent and `meta.index` returned `ok: true`
2026-07-17 10:54:46 +02:00
Oleg Isonen 98d5c607ee feat: Improve MCP safety, context efficiency, and agent workflows (#5895)
## Summary

This combines the three reported MCP improvements into one release-ready
change:

- Safer mutation planning and confirmation for destructive operations.
- Much smaller MCP handshake and default discovery responses.
- Better agent workflows for checkpoints, multi-project work, and page
duplication.

## Safer destructive operations

- Exposes `dryRun` in MCP schemas for every local-capable mutation.
- Returns planned transactions through `meta.session.transaction`.
- Requires a two-step confirmation flow for destructive semantic
operations.
- Returns a short-lived token bound to the project, build version,
input, and exact generated patch plan.
- Rejects expired tokens, altered inputs, changed versions, and changed
plans.
- Sets `destructiveHint: true` only for operations that actually require
confirmation.
- Explicitly protects destructive operations whose names do not begin
with delete or replace, including replacing all redirects and clearing
all styles from a style source.

## Smaller, focused MCP context

- Defers oversized tool input schemas from the initial MCP handshake.
- Keeps complete focused schemas available through `meta.get_more_tools`
and CLI schema inspection.
- Makes template registry lists compact while preserving complete
payloads through focused get calls.
- Makes component summaries compact by default and supports paginated
component details.
- Replaces placeholder operation descriptions with useful command
descriptions.
- Constrains previously untyped JSON schema fields so clients can
validate inputs earlier.
- Keeps runtime output schemas compatible with strict MCP clients.

## Better agent workflows

- Allows read-only discovery and inspection while a workflow checkpoint
is awaiting acknowledgement.
- Continues blocking mutations until the checkpoint is acknowledged.
- Checks persisted checkpoints before every workflow call rather than
only the first call.
- Adds `--project` support so saved projects can be selected without
relinking the current directory.
- Isolates project sessions and checkpoints by selected project.
- Adds atomic `duplicate-page` substitutions for copied fixed text and
copied variable values.
- Prevents substitutions from modifying source content or global root
state.
- Rejects ambiguous or missing copied variables without leaving a
partial duplicate.

## Realistic agent verification

Minimal-context tests used a weak agent against the local packaged CLI
and stdio MCP:

- Planned a page deletion, stopped for explicit user confirmation,
committed the unchanged plan, and verified the page was absent.
- Tried to reuse a confirmation token with altered input; Webstudio
returned `DESTRUCTIVE_CONFIRMATION_INVALID` and preserved both pages.
- Verified compact handshake schemas and focused retrieval of the
complete oversized schema.
- Verified compact template and component discovery responses.
- Selected a saved project explicitly without relying on the directory
link.
- Verified checkpointed workflows permit reads but block mutations.
- Duplicated a London page into a Paris page with atomic text and
variable substitutions.
- Verified source content remained London, copied content became Paris,
and temporary pages were removed.

## Validation

- Project-build focused suites: 188 tests passed.
- CLI focused suites: 183 tests passed.
- Protocol focused suites: 21 tests passed.
- CLI, project-build, and protocol typechecks passed.
- Repository lint passed with zero warnings.
- Package-boundary validation passed.
- Generated runtime operation contracts were regenerated from source.
- Real local CLI/MCP tests passed against a running Builder server.

Closes #5887
Closes #5888
Closes #5889
2026-07-17 00:39:09 +02:00
Oleg Isonen 12ad74584a feat: Improve MCP authoring, auditing, and verification (#5886)
## Summary

This improves how coding agents discover, author, verify, and audit
Webstudio projects through the CLI and MCP. The work focuses on making
agents more reliable with less context, while keeping edits semantic and
Builder-editable.

## What changes for users

- Agents can verify dynamic bindings after authoring and receive
actionable diagnostics when expressions, resources, scopes, or component
props do not line up.
- Agents can create complete resource-backed runtime UI through a
semantic operation instead of coordinating fragile low-level edits.
- MCP discovery and command output are compact by default, with
pagination and focused verbose detail when an agent needs more context.
- Asset, style, token, font, page, and component inspection provides
stronger usage context so agents can preserve the existing design
system.
- Rendered audits provide better evidence for responsive behavior,
geometry, contrast, generated-build size, and large-project runs.
- Cross-project MCP workflows can run from a manifest with explicit
mutation approval, isolated failures, resumable progress, and persistent
checkpoints.
- Project-specific agent onboarding is clearer and does not add
telemetry.
- Packaged CLI releases gain stronger smoke verification for install,
MCP startup, authoring, preview, screenshots, and audits.

## Reliability and architecture

- Runtime operation output schemas are generated from the runtime
registry and remain client-compatible.
- Project-build exports are consolidated around architectural boundaries
instead of feature-by-feature convenience entry points.
- HTTP, preview, screenshot, and project-session paths are hardened for
longer autonomous workflows.
- Craft compatibility work is read-only and provenance-aware; it does
not silently opt ordinary projects into Craft behavior.
- A minimal-context evaluation harness exercises key workflows with a
weaker model and stores bounded, privacy-safe evidence.

## Validation

- Rebased on the latest `origin/main`.
- `pnpm lint`
- Repository-wide `oxfmt --check`
- CLI typecheck and full test suite: 773 tests passed.
- Project-build typecheck and full test suite: 1,866 tests passed.
- Protocol typecheck and full test suite: 83 tests passed.
- HTTP client tests: 23 passed.
- CSS data tests: 3,620 passed, 1 skipped.
- Focused Builder tests: 67 passed.
- Package-boundary, generated API, and generated documentation checks
passed.
- Minimal-context agent evaluations passed for authenticated
resource-backed UI and design-system-aware responsive authoring.
2026-07-16 17:53:16 +02:00
Oleg Isonen d579607ed8 feat: Add draft pages (#5885)
Closes https://github.com/webstudio-is/webstudio/issues/3036

## Summary

- add an optional page-level draft state with a presentation-only
`[Draft]` prefix in Builder
- add **Mark as draft** and **Stage for publish** actions to the Page
details header menu
- keep drafts editable, previewable, linkable, duplicable, and
path-reserving in Builder
- exclude drafts from generated routes, public page collections, sitemap
output, staging, and production builds
- expose draft state and usage guidance through the runtime API, HTTP
client, CLI docs, and MCP contracts

## Why

Pages need a way to remain unfinished inside Builder without being
included in the next site deployment. Draft is an exclusion flag, not a
separate revision or publishing workflow state.

## Behavior and fixes

- home and `/*` catch-all pages cannot be drafts
- draft pages must be staged before becoming the home page
- restricted features used only on draft pages no longer block
publishing the publishable site
- **Stage for publish** only clears draft state; it does not deploy the
site
- missing or explicit `false` draft state remains backward-compatible
and publishable

## Validation

- 5,179 package tests passed across SDK, migrations, project-build, CLI,
and Builder
- targeted Builder browser E2E passed for draft/stage actions,
persistence, home-page guidance, copy, duplicate, delete, and
generated-app build behavior
- all affected package typechecks passed
- lint and package-boundary checks passed
- generated runtime contracts and CLI docs are reproducible
- `git diff --check` passed
2026-07-16 00:56:54 +02:00
Oleg Isonen dde30ffb54 feat: Improve MCP authoring, compact output, and agent onboarding (#5883)
## Summary

This improves how agents discover, author, inspect, and verify Webstudio
projects while reducing unnecessary MCP context usage.

## What changed

- Adds an **Agents** section to Project Settings with ready-to-run setup
commands and client configuration for Claude Code, Codex, Cursor, and VS
Code.
- Makes large list and schema responses compact and paginated by
default, with **verbose** available when complete records or diagnostics
are needed.
- Applies consistent compact output to assets, instances, styles, design
tokens, CLI schemas, and project-session metadata.
- Returns actionable expression warnings for props, resources, and
Collection bindings, including unknown variables and risky render-time
mutation resources.
- Improves Collection expression guidance so agents can bind array items
with the correct scoped variables.
- Reports rendered audit outcomes explicitly as complete, partial,
confirmation-required, or failed.
- Expands runtime output schemas so MCP clients can validate responses
reliably.
- Strengthens the packaged CLI smoke workflow with a realistic
seven-page stdio MCP scenario.

## Architecture

- Consolidates `project-build` from 65 file-oriented entrypoints to 11
architecture-owned surfaces.
- Separates the core model, contracts, runtime authoring, transfer,
state, project sessions, MCP, visual tooling, persistence codecs, and
authenticated server services.
- Isolates Node-only JSX evaluation from browser-safe transfer utilities
and authenticated server modules.
- Keeps persistence codecs independent from authenticated database
services, preventing unrelated module initialization.
- Defines shared instance-path types once and reuses them across runtime
modules.
- Preserves Immer initialization through explicit package side-effect
metadata.
- Adds package tests that prevent a return to source-file entrypoints or
generic exposure of Node-only surfaces.

## Validation

- Full repository checks, tests, typechecks, generated-file checks, and
fixtures
- All 163 Builder test files and 2,141 tests
- All 71 project-build test files and 1,794 tests
- Lint and package-boundary validation
- Full packed CLI release smoke test, including install, preview, agent
setup, seven-page stdio MCP workflow, rendered audit, and structured
commands
2026-07-15 18:11:28 +02:00
Oleg Isonen 3304819d7e feat: Add complete, client-compatible MCP output schemas (#5882)
## What changed\n\n- Define concrete output schemas for every public
runtime operation.\n- Expose output schemas through generated runtime
contracts and MCP tool discovery.\n- Validate runtime results against
their declared schemas, including mutation result envelopes.\n- Add
output contracts for project-session status, refresh, reset, Collection
insertion, and generated-preview tools.\n- Make every advertised MCP
output schema explicitly object-shaped for strict clients.\n- Keep
generated schema definitions at the correct root so local references
resolve during tool discovery.\n- Report the correct session operation
metadata for refresh and reset.\n- Preserve local workspace package
resolution when the local CLI builds a generated React Router
preview.\n\n## Why\n\nAgents could discover input requirements, but
several tools did not describe their returned data. Strict MCP clients
could also reject the complete tool catalog during reconnect because
output schemas were not consistently object-shaped or contained
unresolved local references.\n\n## User impact\n\n- Agents can plan
calls from complete input and output contracts.\n- MCP clients can fetch
the full Webstudio tool catalog without schema-validation failures.\n-
Agents can reliably parse and validate command results.\n- Local
generated previews continue to work for visual verification.\n\n##
Validation\n\n- Every public runtime operation has an output schema.\n-
Every advertised MCP output schema is object-shaped and has resolvable
local references.\n- A real stdio MCP client connected through the local
CLI and fetched 154 tools, including 119 valid output schemas.\n-
Runtime output contracts validate representative query and mutation
results.\n- A fresh subagent refreshed a real project session, built and
started the generated site, captured the target route with HTTP 200,
checked preview status, and stopped the server.\n- Focused project-build
tests, project-build and CLI typechecks, lint, formatting, and
generated-doc checks passed.\n
2026-07-15 12:13:14 +02:00
Oleg Isonen 2808f06808 feat: Improve MCP validation errors with actionable guidance (#5881)
## What changed

- Return structured validation issues with stable codes, complete field
paths, constraints, and minimal correction examples.
- Preserve validation details through the Builder API, CLI, MCP, local
project sessions, and tRPC errors.
- Explain invalid expressions, JSX fragments, page selectors, component
inputs, asset updates, and project settings in terms an agent can act
on.
- Remove stack frames and credentials from parser details before
exposing them.
- Keep concise human-readable errors while making the complete
structured issues available to agents.

## Why

Agents previously received vague errors without enough information to
repair a request. They could repeat the same invalid call or require
manual intervention.

## User impact

CLI and MCP agents can now identify the exact invalid field, understand
the constraint, see a valid example, and retry with a corrected request.

## Validation

- Focused runtime, MCP, CLI, API, and tRPC validation tests.
- Structured error propagation tests across local and server execution.
- Typechecks and generated contract verification.
2026-07-15 11:33:36 +02:00
Oleg Isonen 03aeb535ef feat: Add semantic Collection authoring to MCP (#5880)
## What changed

- Add an `insert-collection` MCP and CLI operation for creating repeated
UI from array or object data.
- Create the Collection, iterable binding, current-item/current-key
parameters, repeated item structure, and descendant bindings atomically.
- Accept literal JSON data or expressions backed by project variables
and resource results.
- Support `collectionItem` and `collectionItemKey` expressions inside
the repeated Webstudio JSX item.
- Return the created Collection, item root, and parameter IDs for
immediate inspection and follow-up edits.
- Document when agents should use Collection for lists, grids, cards,
rows, options, tabs, and other repeated content.

## Why

Building a data-driven list previously required several low-level
operations and manual handling of Collection's internal parameters. A
missed step could leave a partially configured or incorrectly scoped
Collection.

## User impact

Agents can turn resource or variable data into a correctly bound
repeated layout in one operation, then inspect and refine the result
normally.

## Validation

- Real-world local CLI test created and rendered a three-product
Collection from project data.
- Tests cover literal arrays, objects, resource expressions, item/key
bindings, malformed fragments, ID conflicts, server execution, and
project-session behavior.
- 176 focused tests, project-build typecheck, and generated-doc checks
pass after rebasing onto current `main`.
2026-07-15 11:26:14 +02:00
Oleg Isonen 7b59e70fde fix: Fix MCP mutation persistence and deterministic instance ordering (#5878)
Fixes three MCP issues that could cause misleading mutation results,
unstable instance ordering, and project settings that disappeared after
refresh.

## Changes

- Prevents committed mutations from returning `PROJECT_SESSION_BUSY`.
- Ensures retrying after a reported failure cannot silently create
duplicate instances.
- Reconciles the local project session after a mutation commits
remotely.
- Adds deterministic append behavior with `position: "end"`.
- Preserves the requested order when moving multiple instances.
- Makes project settings updates persist across refreshes.
- Reports no-op project settings updates accurately.
- Updates MCP documentation and generated contracts for the new
behavior.

## Verification

- Reproduced and retested all three user reports with a subagent against
a real local project.
- Verified overlapping duplicate operations commit exactly once.
- Verified ordered moves remain correct after refresh.
- Verified project settings survive refresh.
- Passed all project-build tests: 1,745 tests.
- Passed all CLI tests: 720 tests.
- Passed type checks and lint.
2026-07-15 00:29:38 +02:00
Oleg Isonen d186d24501 feat: Improve MCP project audits, visual verification, and dynamic content authoring (#5874)
This update helps AI agents understand, audit, and visually verify
Webstudio projects more reliably. It also adds clearer guidance for
expressions, Collections, screenshots, and responsive rendered audits.

### Audit complete projects

- Run one `audit` command across accessibility, SEO, security, assets,
styles, and performance.
- Audit the whole project or focus on a specific page, scope, or
severity.
- Receive stable findings with locations, explanations, and recommended
fixes.
- Continue large result sets through pagination without repeating
general guidance.

### Audit the rendered website

- Build and inspect the generated website, rather than relying only on
stored project data.
- Check every static page at representative mobile, tablet, and desktop
widths.
- Use one suitable viewport inside each configured breakpoint range.
- Reuse the same browser and resize pages between captures for
substantially faster audits.
- Process multiple pages concurrently while keeping resource use
bounded.
- Supply concrete examples for dynamic routes such as blog posts.
- Review and confirm unusually large screenshot plans before they run.

### Find visual and performance problems

Rendered audits can detect:

- Horizontal page overflow.
- Broken images.
- Images loaded eagerly below the fold.
- Images that are much larger than their rendered size.
- Render-blocking resources.
- Legacy font formats.
- Pages that fail to load or redirect somewhere unexpected.
- Pages captured before their layout becomes stable.

Detailed screenshots, measurements, failures, and timing evidence are
saved locally for further inspection.

### Capture generated pages directly

- Capture a project route with `webstudio screenshot --path /route`.
- Automatically generate and start a temporary production-style preview.
- Stop the temporary preview after the screenshot is captured.
- Return navigation, responsive layout, and page-size evidence with JSON
output.
- Allow external image domains needed by the generated preview.

### Reuse generated previews

- Cache generated preview builds when the project has not changed.
- Reuse preview dependencies across regenerations.
- Keep preview dependencies isolated from the user’s project
dependencies.
- Surface preview build and startup failures with useful diagnostic
output.
- Include local project assets in generated previews.

### Author Collections correctly

- Explain when Collection is required for arrays and objects.
- Guide agents to bind the complete iterable instead of one item or the
response wrapper.
- Explain how Collection repeats its children for every entry.
- Explain current-item and current-key scope.
- Preserve Webstudio’s generated Collection parameters.
- Guide agents to use stable values for repeated interactive components.

### Write expressions with fewer mistakes

- Add a dedicated `webstudio://project/expressions` reference.
- Document expression scope, supported syntax, and supported methods.
- Explain how resources, variables, Collections, actions, and `system`
values are accessed.
- Distinguish fixed values from runtime expressions.
- Provide valid examples for text, props, resource URLs, headers, query
parameters, and bodies.
- Warn agents that valid syntax does not guarantee that runtime data has
the expected shape.

### Improve agent discovery

- Make Collection and expression workflows discoverable through
`meta.guide`.
- Return Collection-specific instructions through `components.get`.
- Point relevant command schemas to the expression reference.
- Keep detailed guidance available without placing it in every tool
response.

### Improve audit reliability

- Report which rendered captures passed, found issues, failed, or were
skipped.
- Distinguish planning, preview, capture, and cleanup failures.
- Include actionable retry instructions with rendered failures.
- Preserve completed evidence when part of an audit fails.
- Detect stale or conflicting preview servers more clearly.
- Support cancellation and bounded capture timeouts.

### Improve packaged CLI verification

- Add a release-shaped CLI smoke test.
- Install the packed CLI in an isolated temporary project.
- Fail on peer-dependency warning floods.
- Verify preview, screenshots, MCP calls, rendered audits, and generated
assets.
- Confirm that generic React Router previews do not include Docker-only
image dependencies.
- Keep CLI and MCP stdout machine-readable while progress remains on
stderr.

## User Impact

Agents can now audit a real rendered Webstudio site, inspect responsive
behavior, find concrete visual and performance problems, and provide
evidence for their conclusions. They also receive much clearer
instructions when turning API data into repeated content or writing
dynamic expressions.
2026-07-14 13:52:09 +02:00
Oleg Isonen 7d781bdc86 fix: MCP fixes (#5870)
Improves CLI and MCP reliability across project synchronization, asset
editing, imports, audits, and clipboard workflows.

## Changes

- Keeps asset filename and description updates after session refresh.
- Prevents intermittent Immer patch errors during consecutive MCP
mutations.
- Prevents false edit conflicts caused by stale local session state.
- Preserves asset uploads without treating them as redundant metadata
updates.
- Exposes editable asset filenames consistently through MCP.
- Imports project assets correctly when copying projects between
environments.
- Supports refreshing partially available project snapshots.
- Keeps MCP operations working when optional project data is
unavailable.
- Produces clearer compatibility errors when the API and CLI versions
differ.
- Makes rendered audits more resilient when individual screenshots fail.
- Prevents rendered audits from hanging while starting browser captures.
- Handles denied clipboard permissions without uncaught browser errors.
- Improves copy and paste reliability for pages, components, styles, and
animations.

## Verification

- Asset uploader tests and typechecking pass.
- Focused asset workflow E2E passes.
- Complete E2E shard 1 passes.
- Realistic MCP subagent test confirms:
  - Asset filename and description persist after refresh.
  - Consecutive mutations work without manual refresh.
  - No Immer patch error occurs.
  - No false conflict occurs.
  - Original asset values can be restored successfully.
2026-07-13 02:32:27 +02:00
Oleg IsonenandClaude Fable 5 071a4d9a85 feat: MCP update 3 (#5864)
## Summary

This update adds new MCP and CLI capabilities for project auditing,
structured data, project-specific agent instructions, focused project
search, safer bulk editing, image descriptions, font discovery, visual
verification, and external registry inspection.

## New Capabilities

### Audit projects

- Run a single `audit` command across accessibility, SEO, security,
assets, styles, and performance.
- Limit an audit to selected scopes, pages, or severity levels.
- Receive stable findings with locations and suggested fixes.
- Run rendered audits across desktop, mobile, and Builder breakpoint
widths.
- Detect horizontal overflow, broken images, oversized images, eager
below-fold images, render-blocking resources, and legacy font formats.
- Identify unused assets, tokens, CSS variables, local styles, and
breakpoints.
- Identify duplicate token declarations.
- Detect accessibility issues involving names, labels, headings,
landmarks, IDs, keyboard focus, ARIA, iframes, and autoplaying media.
- Detect SEO issues involving titles, descriptions, language, social
images, and structured data.
- Detect unsafe new-tab links and write resources exposed during page
rendering.

### Search an entire project

- Search project text, labels, props, resources, assets, and styles
through `search-project`.
- Find relevant records without downloading and reparsing the full
project snapshot.
- Scope searches to the relevant project-data areas.

### Add validated JSON-LD

- Add structured data with a dedicated JSON-LD component.
- Place JSON-LD inside the page Head Slot.
- Edit JSON in a purpose-built code editor.
- Prevent structurally invalid JSON-LD from being saved.
- Validate Schema.org types, properties, and values.
- Find invalid, missing, unknown, deprecated, or incompatible structured
data through the SEO audit.
- Let agents discover the correct JSON-LD workflow without using page
custom metadata or a generic HTML embed.

### Configure project-specific agent instructions

- Add AI-agent instructions from the new **Agents** section in Project
Settings.
- Synchronize those instructions into a managed root `AGENTS.md`.
- Update or remove the managed file automatically during project sync.
- Protect existing user-owned `AGENTS.md` files from being overwritten.
- Share the instructions with authenticated CLI and MCP agents.
- Keep agent instructions out of publicly readable production bundles.

### Generate and manage image descriptions

- Audit image assets for missing descriptions.
- Let a vision-capable agent inspect each image in its rendered context.
- Save generated descriptions to multiple image assets in one operation.
- Mark images as intentionally decorative.
- Reuse the saved asset description wherever the image is used.
- Re-run the audit to verify that missing-description findings are
resolved.

### Perform bounded bulk replacements

- Replace matching literal text across selected pages with
`replace-text`.
- Replace matching fixed prop text with `replace-prop-text`.
- Replace matching resource names or URLs with `replace-resource-text`.
- Restrict replacements by page, instance, prop, resource, field, match
mode, and maximum change count.
- Leave dynamic expressions unchanged.

### Inspect element ancestry

- Return an element’s direct parent in instance listings.
- Request the complete ancestor chain when inspecting an element.
- Understand tree placement without rebuilding the instance hierarchy
from raw project data.

### Discover available fonts

- List uploaded font families through `list-fonts`.
- Discover available system font stacks.
- Inspect font family, style, weight, format, and associated asset
information before applying typography.

### Inspect external component registries

- Inspect a local or remote shadcn-style registry item.
- Read its description, files, dependencies, targets, and documentation.
- Receive an explicit Webstudio compatibility report.
- Inspect registry metadata without installing or executing external
code.

### Capture generated project routes directly

- Run `webstudio screenshot --path /route` against the configured
project.
- Generate a temporary production-style preview automatically.
- Capture the requested route.
- Stop the temporary preview after capture.
- Avoid manually building and starting a preview for a single
screenshot.

### Assert visual changes

- Add expected text to screenshot comparisons.
- Set maximum pixel mismatch limits.
- Set minimum or maximum changed-region counts.
- Assert whether overall brightness or a color channel moved in the
expected direction.
- Use these assertions as pass/fail evidence for visual changes.

### Require compatible CLI versions

- Send the project-bundle contract version with CLI synchronization
requests.
- Stop incompatible CLI versions before they receive incomplete project
data.
- Tell users exactly how to update the CLI or run the latest version
once.
- Prevent older clients from silently dropping project settings.

## Upgrade Note

This branch introduces a new synchronized project-bundle contract. Older
CLI versions must update before synchronizing against the new API.

```sh
npm install -g webstudio@latest
```

Or run the latest version once:

```sh
npx webstudio@latest <command>
```

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 11:27:58 +02:00
Oleg IsonenandClaude Fable 5 68b7458720 fix: restrict content mode text editing on canvas (#5866)
In content mode user should only edit what's inside a content block.

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 02:18:44 +02:00
Oleg IsonenandClaude Fable 5 de23e2a888 chore: migrate toolchain to oxc (oxfmt, oxlint, rolldown-vite) and typeScript 7 (#5868)
## prettier -> oxfmt (0.58.0)

- .oxfmtrc.json generated with `oxfmt --migrate=prettier`: trailingComma
es5, printWidth 80 (oxfmt defaults to 100), sortPackageJson disabled,
.prettierignore patterns folded in (file deleted).
- ignorePatterns additionally exclude yml/yaml/toml/jsonc and
packages/cli/templates/** so oxfmt covers exactly the file set prettier
used to format (ts,tsx,js,json,css,md) and never touches user-facing
scaffolding artifacts.
- root `format` script, nano-staged pre-commit hook and the CI check
(`pnpm oxfmt --check`, replacing `prettier --cache --check` and its
actions/cache step — oxfmt checks the whole repo in ~0.7s) now run
oxfmt.
- every generator script that ran `prettier --write` on __generated__
output now runs `oxfmt` (css-data, icons, html-data, postgrest, sdk,
sdk-components-*, apps/builder tailwind preflight).
- the four scripts that used prettier's JS `format()` API write raw
source instead and their package.json scripts pipe the generated file
through the oxfmt CLI: project-build generate-docs +
generate-runtime-operation-contracts, cli generate-docs, apps/builder
generate-server-only-api-metadata. oxfmt rejects paths containing "..",
so cross-package generated files are formatted via a subshell cd into
the owning package.
- one-time reformat: oxfmt's canonical output differs from prettier on 8
repo source files (binary-operator continuation indent, import() call
wrapping, sub-pixel spacing of empty for-clauses); oxfmt honors existing
`// prettier-ignore` comments so intentional layouts are kept.
- prettier remains ONLY as a cli devDependency for the
prettier/standalone HTML normalizer inside html-to-jsx.test.ts, and
inside fixtures/ + packages/cli/templates/ (ships to scaffolded user
projects; out of scope here).
- editor config switched from esbenp.prettier-vscode to oxc.oxc-vscode
(devcontainer extension list, .vscode editor.defaultFormatter).

## oxlint 1.56 -> 1.73

- oxlint 1.73 rules-of-hooks special-cases hooks NAMED useEffectEvent:
their results may only be called from effects. Our
app/shared/hook-utils/effect-event.ts is a stable-callback helper
(useEvent pattern), intentionally called from event handlers and passed
as props. The rule is disabled via .oxlintrc.json overrides for the five
files doing this (product code untouched); note those files lose
hook-order linting entirely until the rule becomes configurable.

## TypeScript 5.8.2 -> 7.0.2 (native compiler)

- `tsc` is now the Go-based native binary; all `tsgo` script usages
(workspace packages and fixtures) renamed back to `tsc` and
@typescript/native-preview removed (the package is being phased out).
- fixes for TS7 changed defaults and stricter checks:
- `types` now defaults to [] -> base tsconfig sets "types": ["node"]
(restores the implicit-@types/node behavior of TS5).
- `rootDir` now defaults to ./ -> every tsconfig.dts.json sets
"rootDir": "./src" (TS5011 otherwise).
- import assertions removed -> cli/src/cli.ts uses `with { type: "json"
}` (TS2880).
- stricter isolatedDeclarations inference -> explicit annotations in
css-data bin/property-filter.ts (TS9010) and image image-dev.stories.tsx
(TS9013).
- declaration serialization limit -> project-build builder-runtime.ts
runtimeOperationContracts gets an explicit type (TS7056); the annotation
preserves the narrow RuntimeOperationId union.
- TS7 ships no stable programmatic API:
- react-sdk (component-generator tests drive the compiler API) aliases
its typescript devDependency to @typescript/typescript6@^6.0.2; its bin
is `tsc6`, so the package's typecheck still runs native TS7 tsc from the
workspace root.
- generate-arg-types keeps typescript 5.8.2 for react-docgen-typescript.
- fixtures/ and packages/cli/templates/ keep typescript 5.8.2
(user-facing); fixture scripts still work because plain `tsc` resolves
to their local dependency.

## vite -> rolldown-vite 7.3.1 (oxc bundler)

- global pnpm override `"vite": "npm:rolldown-vite@^7.3.1"`: the builder
app (remix v2 vite plugin works unmodified), every package vite build
and the storybook build now bundle on rolldown/oxc.
- vitest is scoped BACK to vanilla vite via `vitest>vite`,
`vite-node>vite` and `@vitest/mocker>vite` overrides because vitest
3.1's runner does not understand rolldown's SSR transform
(__vite_ssr_exportName__ ReferenceError in every suite).
- those overrides pin vite EXACTLY to 6.3.4: letting ^6.3.4 float to
6.4.3 breaks cli prebuild tests (dynamic import of a generated
app/routes/$.tsx fails to resolve under 6.4.3's loader).

## unrelated cleanup requested during review

- apps/builder commands.ts imports duplicate-tokens-group statically
instead of via dynamic import. The circular dependency the dynamic
import guarded against only exists through the command-panel barrel
(command-panel.tsx > groups/index.ts > commands-group.tsx >
commands.ts); importing the group module directly is cycle-free
(verified with madge), matching the neighboring wrap-group and
convert-group imports.

## verification

- pnpm lint, oxfmt --check: clean.
- pnpm -r typecheck (TS7 native) and pnpm dts: clean.
- pnpm -r test: all suites pass (builder 2093 tests, cli 630, react-sdk
45, project-build 11, ...).
- builder app build, full workspace build, cli build and storybook build
all succeed on rolldown-vite.

## Description

1. What is this PR about (link the issue and add a short description)

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
0000)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 01:03:36 +02:00
Oleg Isonen 6983ecfdb0 fix: Document MCP consumer capabilities & more fixes (#5862) 2026-07-10 16:00:54 +02:00
Oleg Isonen 6e10ae3809 fix: Fix Builder paste transfer data handling and publish sync edge cases (#5861)
- Fix publish sync for empty JSON data variables
- Retry transient asset downloads once with shared sync-client backoff
- Fix Builder paste handling for Webstudio transfer data
- Add transfer/data-envelope terminology and colocated runtime
data-format modules
- Rename page clipboard runtime operation to page transfer semantics
- Report malformed Webstudio/Webflow paste data through paste results
instead of inserting it as text
- Add browser-level E2E coverage for instance, page, folder, template,
generic plugin, malformed data, native input, and content-mode paste
flows

## Details

- Allows empty JSON data variables to sync/publish correctly.
- Adds asset download retry coverage and uses shared backoff logic.
- Introduces runtime `data-formats` modules for data envelopes, instance
transfer data, and page transfer data.
- Removes stale clipboard aliases and `validateTemplateStructure`.
- Keeps clipboard as a Builder UI transport concern while
runtime/protocol use transfer-data terminology.
- Changes paste plugins to return expressive success/error results so
callers can show toast errors and stop fallback insertion.
- Prevents malformed Webstudio transfer payloads from falling through to
text/HTML/markdown insertion.
- Handles malformed Webflow-owned paste data without throwing.
- Adds shared copy-paste fragment insertion helpers to reduce duplicated
breakpoint-warning/fragment-data logic.
2026-07-10 13:51:55 +02:00
Oleg Isonen da13e301c9 chore: Post merge fixes (#5860) 2026-07-10 12:55:20 +02:00
Oleg Isonen d291e4b671 feat: Builder api runtime contracts guardrails for MCP (#5857)
This PR expands Webstudio MCP and CLI into a more complete agent
authoring interface. Agents can discover project capabilities, edit real
Webstudio content, use data/resources, verify visual output, and report
useful issues when workflows fail.

## MCP User Capabilities

- Create, update, duplicate, reorder, and delete pages.
- Create pages from templates and manage reusable page templates.
- Inspect project pages, instances, props, styles, assets, variables,
resources, and metadata.
- Insert Webstudio components and authored JSX fragments into pages.
- Edit text, props, styles, breakpoints, design tokens, and CSS
variables.
- Update page metadata, SEO fields, redirects, marketplace metadata, and
project settings.
- Create and use static data variables.
- Create and use dynamic resources fetched over HTTP.
- Use REST, GraphQL, and built-in system resources in authored pages.
- Bind data variables and resources to visible page content.
- Create resource-backed pages such as sitemap XML, structured SEO data,
and API-driven content sections.
- Preview current project state without requiring a publish step.
- Capture screenshots for visual verification.
- Verify responsive designs across desktop, tablet, and mobile
breakpoints.
- Use screenshot diff and OCR-style checks to inspect rendered output.
- Reset and refresh local MCP project state when needed.
- Discover available CLI/MCP commands from generated manuals.
- Use clearer examples for resources, data variables, JSX authoring,
previewing, and visual checks.
- Read marketplace product metadata without requiring a full project
snapshot.
- Get safer guidance when using low-level patch tools.
- Get a ready-to-copy Discord report template when MCP/CLI behavior is
confusing or broken.
2026-07-10 02:13:22 +02:00
Oleg Isonen bdb3f3dfd3 fix: MCP style mutation validation (#5855) 2026-07-03 19:35:07 +02:00
Oleg Isonen 371a6d6b8a fix: Validate expression-backed API inputs (#5854)
1. fix the issue with expressions requiring string when expression, this
is an issue not only for meta in page settings but for any field that
supports bindings

2. make sure llm knows when to use bindings and when to just set the
string value, test it with a subagent without additional context
2026-07-03 14:50:39 +02:00
Oleg Isonen b1a3eed1f8 feat: guide agents through webstudio cli (#5847) 2026-07-03 01:06:47 +02:00