Introducing a new way to review your PRs.

Read the announcement

frappe / builder

Craft beautiful websites effortlessly with an intuitive visual builder and publish them instantly

View on GitHub

20 documents · Updated Nov 23, 2026

docs / ai-agent-runtime

AI agent runtime

The AI agent runtime turns a user's request into a controlled, saved Builder page change. It connects a selected AI provider to a durable chat session, gives the model site tools, checks proposed changes on the server, and sends accepted work to the editor. It is the server side of AI-assisted building; the editor view is described in AI client experience.

Runtime boundary

The runtime owns state that must survive a page reload or a worker failure. It selects a model, loads the page and chat, runs bounded model rounds, saves accepted work, and emits progress for the open editor.

The browser is a live view of server state. It does not decide whether a block change is valid. This boundary keeps the saved draft, chat record, canvas, and later revert actions aligned.

Provider and model access

Provider and model catalog

AI providers and models are site settings. A provider describes how a service is reached. A model names the service model and its limits. This lets a site use OpenRouter, an OpenAI-compatible gateway, a local service, or a ChatGPT subscription without changing the agent flow.

The model catalog is kept current from the connected provider rather than from a fixed model list. Discovery uses provider listings and model descriptions to keep a small frontier of tool-capable models. An engineer or site owner can also add another model that the provider serves. The catalog tells the runtime whether a model can view images and how much context it can accept.

Discovered models can leave the frontier as newer models arrive. A model added by the user remains under user control. Provider keys serve their own models. The shared Builder key remains a fallback for providers that do not carry a key.

References: builder/…/catalog.py• L16-68 builder/…/discovery.py• L1-22 builder/…/discovery.py• L45-98 builder/…/discovery.py• L137-186 builder/…/models.py• L1-13 builder/…/models.py• L58-110 builder/…/models.py• L147-217 builder/…/api.py• L340-425

Model request boundary

The model adapter gives the agent one common request boundary. It routes a stored model name to the right provider, applies provider limits, supports text and tool calls, and returns a common stream shape.

The adapter also hides provider-specific details such as cache markers, temperature rules, and gateway routes. It retries only failures that may clear on their own. A bad key, missing model, or invalid request becomes a clear user error instead of a repeated paid request. Tool arguments can also be repaired when a model returns common JSON mistakes.

References: builder/…/llm.py• L21-94 builder/…/llm.py• L110-143 builder/…/llm.py• L145-227 builder/…/test_llm.py• L22-139

ChatGPT subscription route

The Codex route lets a site use a ChatGPT sign-in instead of a normal API key. Device-code sign-in is the main path. A browser-link flow is the fallback when device codes are not available. The server completes both exchanges and stores the credential without sending tokens through the browser session.

The route refreshes the saved sign-in when needed and translates the ChatGPT stream into the same text and tool-call form used by other providers. The rest of the agent stays provider-blind. A failed or expired sign-in is reported as a request to sign in again rather than exposing token or transport details.

References: builder/…/codex_login.py• L1-12 builder/…/codex_login.py• L41-104 builder/…/codex.py• L66-85 builder/…/codex.py• L128-181 builder/…/codex.py• L216-349 builder/…/api.py• L530-574

Request entry point

The run endpoint is the entry point for an in-editor turn. It checks page write access, validates and stores an attached image, resolves the selected model, saves the user message, and queues the long-running job. Realtime events connect that job to the open editor without holding the web request open.

The API also supports model setup, session loading, cancellation, conversation rewind, active-build recovery, and approval of sensitive actions. These paths keep user actions separate from changes the model may only propose. A queued job resolves its own provider key, so secrets do not sit in the job payload.

References: builder/…/api.py• L52-141 builder/…/api.py• L144-215 builder/…/api.py• L247-326 builder/…/api.py• L329-337 builder/…/api.py• L444-574 builder/…/test_agent_jobs.py• L20-83

Sessions and memory

Chat sessions

A chat session is the saved conversation for one user and one page. A page can have several sessions, so a user can keep separate lines of work and switch between them. A session can also be linked to pages it changed, which lets the same chat continue when an approved build moves to another page.

Reopening a page returns the most recent session that contains messages. The chat keeps the full transcript for the user. The model receives a bounded history of useful turns. Running, failed, and cancelled turns do not become false evidence in later context. Durable outcomes, such as an approved action, remain in context.

References: builder/…/session.py• L8-18 builder/…/session.py• L26-63 builder/…/session.py• L117-180 builder/…/session.py• L214-272 builder/…/api.py• L579-634

Attachments and replay

An attached image is saved as a private site file so later turns can refer to a stable address. Only a small number of recent images are replayed to a vision model. Permission checks apply before a private image is read or sent onward.

The runtime can also recover an active page-generation stream after an editor reload. The live preview is temporary and expires. The saved draft remains the lasting page state.

References: builder/…/api.py• L28-49 builder/…/api.py• L73-105 builder/…/session.py• L234-300 builder/…/api.py• L699-707 builder/…/artifact.py• L186-203

Site memory

Site memory stores short facts that should survive across chats. These facts can describe the brand, a standing preference, or a correction to the agent's work. The runtime adds them to each agent context so the model can use them without a separate read.

Memory is not a second page store. One-off instructions belong in the current request. Page facts, design values, and component behavior belong in their own site records.

References: builder/…/memory.py• L1-6 builder/…/memory.py• L17-91 builder/…/prompts.py• L44-47 builder/…/loop.py• L758-763

Prompt context

The prompt gives the model shared rules for page structure, styles, bindings, scripts, components, memory, and tool use. A turn then adds the open page, the current page tree, recent chat, saved memory, selected blocks, and any image.

Installed apps can add instructions for the open page through the builder_agent_context hook. The runtime includes each non-empty result in the agent context only when a page is open, so an app can add page-specific rules without changing the shared prompt.

Small pages use their full compact structure. Large pages use an outline with refs and short text previews. The model can ask for full block detail only where it needs it. Skills are short work guides that enter context only when the task needs them. A skill-bound tool cannot author that work until its guide reaches the model. Stable chat history comes before changing page context, which supports prompt caching across rounds and turns.

References: builder/…/prompts.py• L4-42 builder/…/prompts.py• L76-138 builder/…/loop.py• L643-727 builder/…/loop.py• L735-814 builder/…/skills.py• L1-31 builder/…/__init__.py• L1-37 builder/…/test_read_page.py• L193-277

Agent execution

Agent turn loop

An agent turn is a bounded sequence of model rounds. Each round may contain text, tool calls, or both. The runtime first collects a complete streamed round, then applies accepted page operations, runs read or write tools, returns their results to the model, and continues until the model stops or a user-facing card pauses the turn.

The loop streams thinking, narration, tool activity, and page changes as realtime events. It records a compact timeline, token use, retries, failures, and a trace that explains why the turn stopped. A transient stream failure retries the whole unapplied round, so partial output cannot apply the same change twice. Server-side tool writes run behind a savepoint, so a failed handler does not leave a half-applied change.

Each completed round is committed. A later worker failure therefore does not remove earlier saved work. Cancellation keeps work already applied, including a partial generated page when the generation stream produced usable text. A round limit ends an oversized turn with a continuation hint instead of a false completion.

Full-page generation is one step inside this loop rather than the end of the turn. After the generator saves the page, the loop replaces its working tree with the saved result so later tools can add scripts, repair dropped content, inspect the page, and run a visual check. The turn does not close with a final reply while a generated page still needs that review.

The loop can also run a compact edit script. The script names blocks by selector ref and compiles its changes into the same checked operations as individual page tools. This gives a large edit one readable request while keeping the server tree as the only place that accepts changes.

The loop also checks generated pages for focused repair needs such as empty sections, blank text, misplaced positioned blocks, and repeated small labels. A completed reply can include up to three short next-step suggestions. The chat renders these suggestions as buttons while the saved reply keeps them separate from the answer text.

This diagram shows how a request becomes checked and durable page state.

flowchart TD
    A[User request] --> B[Validate and save session message]
    B --> C[Queue agent job]
    C --> D[Load page and acquire locks]
    D --> E[Build prompt context]
    E --> F[Model round]
    F --> G{Tool kind}
    G -->|Read| H[Return site facts]
    G -->|Page change| I[Check working tree and save draft]
    G -->|Artifact| J[Stream, parse, and save page]
    G -->|Question or approval| K[Save card and pause]
    H --> F
    I --> L[Mirror accepted operation]
    J --> L
    L --> F
    F --> M[Save answer and complete event]

References: builder/…/loop.py• L64-113 builder/…/loop.py• L847-1011 builder/…/loop.py• L1177-1338 builder/…/loop.py• L1416-1538 builder/…/loop.py• L1566-1697 builder/…/loop.py• L1783-1819 builder/…/edits.py• L1-155 builder/…/next_steps.py• L1-28

Tool registry

The tool registry is the capability boundary between the model and the site. Each tool declares its name, input shape, side of execution, and optional artifact or terminal behavior. The loop uses that information to handle the tool without adding a special branch for each new capability.

The main tool groups are:

  • Page tools read, select, add, update, move, and remove blocks.
  • Site tools read records, settings, scripts, URLs, and other pages.
  • Data tools connect page repeaters to real records.
  • Artifact tools generate large page results outside normal tool arguments.
  • Terminal tools show a question or approval card and pause the turn.
  • Skill tools provide task guides only when the model needs them.
  • Plugin tools create or inspect editor extensions that can affect every editor user on the site.

The registry marks each tool as a page operation, server action, terminal pause, or streamed artifact. It also controls which skill-bound schemas are visible in a round. This keeps the execution loop stable as new site capabilities are added.

References: builder/…/registry.py• L1-23 builder/…/registry.py• L32-87 builder/…/registry.py• L90-141 builder/…/loop.py• L1177-1315

Data grounding

Data tools let the agent build pages from the site's real data model instead of guessed field names. The agent can list data types, inspect a schema, read permitted records, and write a read-only page data script that fills the page's data values.

Creating a new data type or inserting sample records is a durable site change. Those actions create a pending proposal and require user approval. A page data script only reads data at render time; it cannot save, insert, or delete records.

The same data path can connect a public page form to stored submissions. After approval, the runtime creates a private submission type, a guest-safe web form, and the page wiring that sends form fields to it. This keeps public input behind a field-limited boundary while the owner reads the results in Desk.

References: builder/…/data.py• L27-121 builder/…/data.py• L172-227 builder/…/data.py• L230-269 builder/…/data.py• L291-441 builder/…/forms.py• L1-13 builder/…/forms.py• L85-125 builder/…/pending.py• L162-239

Conversational pauses

The present_ui tool is the pause point for a question, choice, form, plan, or confirmation. It builds a small card from known UI parts. The user's reply returns as the next normal chat message, so the model does not need special command words.

The card is saved before its realtime event is sent. A reload therefore shows the same pending question. Sensitive actions use a separate approval path so model text cannot perform a privileged write by itself.

References: builder/…/conversation.py• L1-13 builder/…/conversation.py• L45-103 builder/…/conversation.py• L190-206 builder/…/api.py• L153-195

Page inspection and references

Selectors and block inspection

Selectors give the model a safe way to find blocks by editor ref, element, text, class, or subtree. A result returns the exact refs needed for a later change. This makes a bulk edit complete and repeatable instead of dependent on a model guessing from a long page outline.

read_block supplies full detail for one block and can attach its image to a vision model. read_page resolves another page by id, route, title, or same-site URL. It returns a read-only design reference, including structure, style values, component contracts, and attached scripts.

References: builder/…/selectors.py• L1-51 builder/…/query.py• L16-31 builder/…/query.py• L34-121 builder/…/query.py• L520-555

Reference design context

A reference page informs a new page's layout and visual language without exposing its blocks as edit targets. The runtime preserves page-level geometry, component versions, scripts, and font availability so a generation brief does not lose the parts that prose describes poorly.

The reference is read-only by design. The open page remains the only page the agent can change live. This supports site consistency without allowing a request for a reference page to become an accidental edit to that page.

References: builder/…/query.py• L124-151 builder/…/query.py• L187-281 builder/…/query.py• L494-517 builder/…/test_read_page.py• L52-141 builder/…/test_read_page.py• L403-465

Reusable components

Reusable components keep shared page areas in one definition. The agent can promote an existing block into a component or edit the shared definition. Embedded pages then receive the shared change while their instance-level content remains distinct.

Component extraction changes the page's editing model, so it is an explicit design choice. The runtime keeps the component instance and its mirrored children usable by the page tree, and it refreshes the open page when a shared edit updates an embedded instance.

References: builder/…/components.py• L1-7 builder/…/components.py• L17-65 builder/…/components.py• L90-125 builder/…/query.py• L203-281

Visual review

preview_page renders the draft at a chosen viewport and color scheme. It measures text contrast in light and dark mode, trims and tiles the result before attaching it to a vision-capable model, and refreshes the page thumbnail. This lets the model review readable sections rather than one unreadable tall image.

The preview is a check, not the source of truth. It can refresh the page thumbnail and can fail without failing the turn. A text-only model skips visual review. The runtime limits page previews and image views so a screenshot loop cannot consume an unbounded turn. Image review accepts only data images, public files, readable private files, or guarded public web images.

Runtime evaluation checks whether an interactive page works in a real browser rather than judging only its screenshot. It records page errors and failed resource loads, then checks the largest canvas for visible output and response to a drag. This helps detect a blank or non-responsive interactive area after the page is built.

References: builder/…/preview.py• L21-35 builder/…/preview.py• L104-160 builder/…/preview.py• L194-248 builder/…/preview.py• L251-338 builder/…/preview.py• L391-468 builder/…/runtime.py• L1-114 builder/…/test_image_view.py• L15-70

Page change application

Model page format

The block codec is the shared language between the model-facing page description and Builder's stored block tree. It keeps the model view compact while preserving the facts needed for styles, attributes, components, scripts, repeaters, and bindings.

Editor refs are distinct from HTML ids. Repeaters and bindings use plain data keys. Icons use a small named form that can expand into the rendered icon block. This common vocabulary lets generation output and targeted edits describe the same page without exposing editor-only noise.

References: builder/…/block_codec.py• L11-47 builder/…/block_codec.py• L49-156 builder/…/block_codec.py• L158-195 builder/…/prompts.py• L10-27

Authoritative working tree

The working tree is the server's current page view for one turn. It starts from the saved draft, applies accepted operations, and saves the result after each round. Only operations accepted by this tree reach the canvas.

The tree checks refs, parents, moves, bindings, repeaters, dynamic text, component props, and script placement. It returns a failure to the model when an operation is invalid, which gives the model a chance to correct the request. The client mirror must follow the same accepted operation shape.

Page scripts that can change state also use verified server handlers. The editor mirrors the accepted result instead of writing a second version in the browser. Component definitions use the same tree rules and reject self-nesting that would create a render cycle.

References: builder/…/tree.py• L19-79 builder/…/tree.py• L91-317 builder/…/tree.py• L333-525 builder/…/tree.py• L527-575 builder/…/loop.py• L1228-1262 builder/…/test_tree_apply.py• L31-255

Page artifact handling

Full-page generation is a large artifact flow rather than a normal tool argument. The conversational model sends a short brief to the generation step. That step streams page markup as plain content, while the runtime sends parsed preview frames to the editor and stores the latest frame for a short reload window. These frames are provisional; the final parsed tree remains authoritative.

Generation carries more than the brief when that context exists. The runtime passes photo-search results by their exact URLs and passes measured geometry from reference pages. Vision-capable models receive the current reference image and marked brief images only after public URLs are checked and site files pass permission and size checks.

After generation, the page writer persists usable output as a draft and the generator returns the canonical operation for the loop to emit. The loop then replaces its working tree with that saved result. It reports lines that did not parse so later edits can restore missing content. A cancelled stream keeps usable partial work rather than discarding everything, while an empty or unusable result is not applied.

References: builder/…/artifact.py• L32-110 builder/…/artifact.py• L115-181 builder/…/artifact.py• L186-231 builder/…/artifact.py• L233-348 builder/…/generate.py• L1-46 builder/…/loop.py• L1310-1321 builder/…/loop.py• L1783-1819

Page writing

The page writer is the boundary between generated page description and Builder page state. It converts the generated structure into blocks, normalizes styles and bindings, removes content that is not a page block, and saves the result as a draft. Repeater data becomes page data that blocks can render through bindings.

Generation is an authoring action, not an automatic publish action. Later page, data, and script changes use the saved draft as their base. The same conversion path supplies the live preview and the final block tree, so the editor does not parse a separate version of generated output.

The loop also checks the contract between generated blocks and existing page scripts. A script selector or style class that has no matching block is reported while the turn can still repair the page.

References: builder/…/page_writer.py• L268-344 builder/…/page_writer.py• L404-426 builder/…/page_writer.py• L473-534 builder/…/artifact.py• L328-348 builder/…/loop.py• L1813-1890

Run and page locks

Locks prevent two AI turns from changing one session or one page at the same time. The session lock protects one conversation. The page lock protects the shared draft, including page-less work that still writes page content.

The locks are atomic and expire after a worker failure. A release token prevents an old worker from releasing a newer lock. A crash therefore leaves a retryable busy state instead of permanently blocking the page.

References: builder/…/locks.py• L1-69 builder/…/session.py• L410-427 builder/…/loop.py• L1047-1063 builder/…/loop.py• L1426-1447

Revert snapshots

The runtime captures the page's pre-turn state before the first page or script mutation. One AI snapshot can restore blocks, page data, and client scripts from a mixed turn. Turns that only read or ask a question do not create a revert snapshot.

Conversation rewind is separate from page revert. Rewind removes the selected chat turn and later messages. The client restores the page from the saved snapshot so the conversation and page return to the same point.

References: builder/…/snapshots.py• L1-65 builder/…/loop.py• L90-105 builder/…/loop.py• L591-599 builder/…/loop.py• L1234-1243 builder/…/api.py• L329-337

Other-page changes

Edits to the working page apply live. An edit to another page is checked against that page immediately, but it is not saved. The runtime collects the checked operations in one confirmation card so the user can review or skip each page before anything lands.

When the user confirms, the runtime replays each checked change against the page as it exists then. Each page has its own permission, lock, snapshot, and result. A page changed in the meantime can fail without rolling back unrelated confirmed pages.

References: builder/…/page_changes.py• L1-9 builder/…/page_changes.py• L92-162 builder/…/page_changes.py• L221-332 builder/…/api.py• L187-215 builder/…/test_page_changes.py• L66-172

New-page proposals

Creating a new page is a two-step flow. The agent first proposes the title, route, and build brief. The user confirms the proposal on a card. The server then creates the empty page and queues a separate off-screen build turn, so the open canvas is not replaced by an unrelated page.

The proposal checks route conflicts and limits the number of pages in one turn. Approved pages are built one at a time. The chat stays attached to the page the user had open while progress events identify the page being built.

References: builder/…/pages.py• L1-38 builder/…/page_changes.py• L164-218 builder/…/page_changes.py• L295-345 builder/…/api.py• L198-244 builder/…/test_page_changes.py• L267-316

Page settings and theme tokens

Page settings and design tokens are page or site design changes that can apply during a turn. Page settings cover metadata and the page route. Design tokens provide shared color and font values that pages can reuse. A route change uses the page save path so route-related lifecycle work and cache refreshes run correctly.

Changes that affect every visitor, such as the home page or global code, stop at a confirmation card. The privileged write runs only after the user approves it. Publishing is also an explicit user action; a build does not publish by itself.

References: builder/…/settings.py• L23-91 builder/…/settings.py• L96-163 builder/…/settings.py• L166-227 builder/…/settings.py• L309-343 builder/…/api.py• L153-195

Confirmation gates

Some actions affect the whole site or create durable structures. The model can prepare a proposal, but the turn stores it as a pending action and waits for the user to apply or skip it.

The confirmation endpoint checks ownership and permission before applying an allowlisted action. It records the outcome in the chat and can resume the interrupted task. Approval is therefore a user action that survives a reload, not a promise inside model text.

References: builder/…/pending.py• L1-85 builder/…/data.py• L233-269 builder/…/page_changes.py• L241-292 builder/…/api.py• L153-215

Editor plugin changes

An editor plugin is a site-wide editor extension rather than a change to one page. The agent can list installed plugins, read the source of a plugin it owns, and save a complete replacement for all editors on the site. It can also load the saved plugin in the current editor and receive a report that says whether it registered usable controls.

Plugin writes require the editor-plugin skill and manager permission. The current editor reports load errors, disabled state, unchanged code, or registered surfaces. Other editors receive the plugin on their next load. The agent can inspect the editor's supported internal modules when it needs to build a plugin against existing controls. This makes plugin creation a checked site change rather than an unverified code message.

References: builder/…/plugins.py• L1-8 builder/…/plugins.py• L37-80 builder/…/plugins.py• L106-139 builder/…/plugins.py• L142-169 builder/…/plugins.py• L172-226 builder/…/plugins.py• L229-303

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep provider and model names aligned across provider records, stored session selections, routing, model setup, discovery, and the model picker. A changed route prefix can make saved sessions point to a model that no longer resolves.
  • Keep the common model stream shape aligned across LiteLLM and the Codex adapter. Tool-call deltas, reasoning text, finish reasons, and usage must remain readable by the loop.
  • Keep the discovery frontier aligned with model requirements. Removing tool or image support from the policy can silently remove models from the picker.
  • Keep queued job arguments free of provider secrets. The worker must resolve the key inside the job.
  • Keep the server working tree and the client operation format aligned. A new block operation must be accepted by the tree before it is emitted to the canvas.
  • Keep ref and HTML-id terms separate. Model context uses editor refs for block tools, while scripts and markup use classes or HTML ids.
  • Keep binding keys and page data keys synchronized. A changed repeater key or an expression in a binding can produce an empty page without a storage error.
  • Keep dynamic text on the binding path. Moustache text in block content or attributes can break the published page.
  • Keep component props on the instance root and component declarations on the shared definition. A child-targeted prop write must still land where the canvas reads it.
  • Keep component client scripts, page scripts, and CSS separate. A script attached to a shared component must not become a one-page copy by accident.
  • Keep client edits ahead of terminal cards in a round. Accepted changes must not be discarded when a confirmation action ends the turn.
  • Keep streamed rounds side-effect free until the full round returns. Otherwise a retry can apply duplicate changes.
  • Keep server tool writes behind their rollback boundary. A handler error must not leave part of a settings, script, or data change committed.
  • Keep a checkpoint after each completed round. Without it, a later worker failure can roll back earlier page, script, and message changes.
  • Keep generation inputs and previews aligned. Photo-search URLs, reference geometry, marked images, cached preview frames, and the final saved tree must describe the same build.
  • Keep generated-page follow-up context aligned with the saved tree. Later script, repair, and preview tools must see the generated refs and blocks. Do not let the turn finish before an unreviewed generated page has had its required check.
  • Keep script selectors and CSS classes aligned with generated block classes. A generated page can save correctly while its behavior remains dead if the class contract is missed.
  • Keep preview cost and image safety bounds intact. A new screenshot or image path must not bypass renderer, size, permission, or per-turn limits.
  • Keep snapshot capture in front of every page or script mutation. A new mutating tool outside the snapshot set can silently remove the user's revert option.
  • Keep terminal action kinds allowlisted in both proposal and application paths. An unknown kind must never reach a privileged write.
  • Keep page data scripts read-only and aligned with the real DocType schema. A script that writes at render time can repeat a durable change on every page view.
  • Keep form connection fields in the same order as the page inputs and keep the submission type private. The browser wiring and the stored schema must agree or submissions can be lost or exposed.
  • Keep reference-page reads read-only and complete enough for generation. A missing component contract, script, font warning, or geometry note can produce a page that looks close but does not work.
  • Keep component extraction and shared-component edits distinct from instance edits. Extraction changes future ownership of the block, while a shared definition update can affect every embedded page.
  • Keep page-change proposals separate from live edits. Checked operations for another page must not save before confirmation, and confirmed replay must handle intervening page changes.
  • Keep route checks in both proposal and application paths. A route can become occupied between the confirmation card and the apply action.
  • Keep page settings and theme-token refetch events after commit. Otherwise the editor can read old settings or variables after a successful server write.
  • Keep plugin publication and editor loading aligned. A saved plugin is not confirmed working until the current editor reports its load and registration result.
  • Keep plugin reads aligned with ownership and source type. A built package must remain read-only, and a plugin update must use the full source under the same name.
  • Keep editor-source inspection within the supported internal module boundary. A missing or renamed module can make a plugin fail even when its own code parses.
  • Keep each skill-bound authoring path gated by the matching skill. A new skill tool must not become usable before its guide reaches the model.
  • Keep builder_agent_context hook output scoped to an open page. Empty hook results must not create prompt content or leak page-specific instructions into page-less chats.
  • Keep next-step tags out of the visible answer and limit their stored button values. A parser change can leak control tags into chat or make a suggested action unavailable after reload.

Important failure modes

TriggerConsequenceGuard
The selected model is unknown or has no usable keyThe turn cannot call a providerResolve the model through the catalog and check a provider or site key before enqueueing
A queued job carries a provider keyA secret can persist in job data or logsResolve the key inside the worker and keep it out of enqueue arguments
Discovery has stale or incomplete provider dataA suitable model is missing from the picker or an old discovered model remains offeredRefresh stale providers in the background and keep user-owned model rows outside automatic retirement
The provider stream fails after partial outputThe user can see duplicate text or the turn can apply an incomplete call setRetry the whole unapplied round and replace partial live text
A ChatGPT credential is missing or expiredThe Codex route cannot start a model roundRefresh the credential and return a sign-in instruction when refresh fails
Two turns target one session or pageDraft changes can conflict or a later turn can use stale stateUse atomic expiring session and page locks
A model sends a bad block ref or parent refThe requested edit does not landReject the operation in the working tree and return a correction result
A bulk edit includes missing refs or invalid bindingsSome blocks change while others do not, or dynamic content stays emptyReturn per-block failure details and require a selector result before a broad update
Moustache text is placed in block content or attributesThe published route can fail during renderReject it and use a plain binding or a page data script
A component prop is written to a child instead of its instance rootThe canvas may show a change that disappears after reloadRoute the value to the owning instance and validate it against the declared schema
A component embeds itself or a nested cycleRendering can recurse foreverReject component cycles before saving the definition
A brief contains an unreachable image URL or a protected site fileThe provider can reject the whole generation request or receive no image contextCheck public URLs and enforce permission, type, size, and count limits before attaching images
A live generation frame is mistaken for the final pageA refresh or later tool can use incomplete blocksKeep the stream buffer temporary and replace it with the parsed saved tree operation
A generation stream ends with invalid or incomplete markupThe page can miss sections or have no usable generated blocksKeep valid parsed output only, report dropped lines, and ask the loop to repair missing content
A generation stream is cancelled after usable outputDiscarding the stream loses work the user already paid to createPersist the usable partial page and end the turn without claiming more work was done
Generated scripts select classes that no block carriesInteractions or styles do not run even though the page savedCheck the class contract and repair the blocks or scripts before closing the build
A preview renderer is unavailable or the model cannot view imagesVisual review cannot happenSave the thumbnail when possible, report the limitation, and continue without claiming a visual check
A preview includes private, internal, oversized, or unreachable image contentProtected content could leave the site or the model receives an incomplete reviewAllow only guarded, user-readable image sources and enforce image limits
A page has unreadable light or dark mode textVisitors can see text that blends into its backgroundUse the measured contrast result to repair the text and background tokens, then preview the changed mode
A page data script writes to a documentEvery page render can repeat an unwanted writeReject save, insert, delete, and permission-bypass calls in data scripts
Form fields do not match the proposed submission schemaPublic submissions can map to the wrong fields or fail to saveKeep field order and names aligned, use the approved web-form boundary, and keep the submission type private
A model proposes a site-wide setting or new data structureA model turn could make a privileged durable change without consentStore a pending action and require the user confirmation endpoint
An approval card contains an unknown action kindA crafted or stale card could reach an unintended writeApply only explicit kinds from the pending-action allowlist
An edit to another page is saved during checkingThe user sees a confirmation card for a change that already happenedRun the check in a rollback scope and save only during confirmed replay
A page changes after an other-page proposal is checkedThe replay can target stale refs or overwrite newer workReapply against the current page under a lock and fail that page without changing it when refs are gone
A new-page route is taken before confirmationThe new page cannot be created at the proposed URLCheck routes at proposal time and again at apply time
A worker dies during a page editThe page can remain locked or lose earlier completed roundsUse expiring token locks and per-round commits
A turn reaches its round limitA large edit can stop before completion while appearing finishedMark the turn incomplete and tell the user to continue
A mutation has no matching snapshotThe user loses a safe one-step revertAdd every page and script mutation to the snapshot set before it applies
A plugin is saved but the editor does not load or register itThe site has a durable extension that may not work for the current userCheck syntax, wait for the editor report, and expose the failure for repair
A plugin is a built package or the requested source module is not availableThe agent cannot safely update the plugin or may author against an unsupported editor APIAllow source reads only for Builder-authored plugins and use the supported editor module list
A plugin is turned off in the site or browserThe saved extension does not run for the userReport the disabled state and enable the plugin before treating it as active
A skill-bound tool runs without its guideThe model can author work without the required site contractKeep the tool unavailable or return a failed result until the skill is read
A page-specific app hook is used without an open pageThe model receives context that has no page scope or the hook is called with invalid stateBuild app context only for page-bound turns and ignore empty hook results
A reply contains malformed or overly long next-step tagsSuggested actions leak into the answer or do not appear as buttonsStrip tags before display and keep only bounded, non-empty suggestions

Key files

FileWhy to read it
builder/…/api.pyShows the request boundary, model setup, session helpers, image storage, cancellation, confirmation, and active-build recovery.
builder/…/loop.pyShows the turn lifecycle, context order, event contract, retries, savepoints, checkpoints, cancellation, generated-page follow-up, and final persistence.
builder/…/page_changes.pyShows how changes to other pages and new-page proposals stay staged until user confirmation, then apply with fresh checks.
builder/…/edits.pyShows how compact multi-block edit scripts become the same checked operations used by normal page edits.
builder/…/next_steps.pyShows how short follow-up suggestions become separate chat actions instead of visible reply text.
builder/…/llm.pyShows provider routing, keys, provider limits, retries, streaming, and tool-call requests.
builder/…/codex.pyShows how a ChatGPT sign-in becomes the common model stream used by the agent.
builder/…/codex_login.pyShows the device-code and browser-link sign-in paths and their server-side token exchange.
builder/…/catalog.pyShows how a provider's available models can be added as user-owned catalog entries.
builder/…/discovery.pyShows how provider listings and model facts become a managed frontier in the model picker.
builder/…/models.pyShows how provider and model records become the available model catalog.
builder/…/session.pyShows how sessions, messages, context history, image replay, notes, and run locks work together.
builder/…/prompts.pyShows the shared rules and context used to guide page generation, editing, bindings, scripts, and component reuse.
builder/…/__init__.pyShows how task guides stay small in the system prompt and enter context on demand.
builder/…/components.mdShows the high-level contract for shared components, props, and component behavior.
builder/…/block_codec.pyShows the compact page vocabulary shared by generation, inspection, and block editing.
builder/…/registry.pyShows the capability model that lets tools join the agent without changing the loop.
builder/…/blocks.pyShows the model-facing boundary for grouped block edits and live page changes.
builder/…/components.pyShows component extraction, shared-definition edits, and page synchronization for embedded components.
builder/…/forms.pyShows the confirmation-gated path from a public page form to private stored submissions.
builder/…/generate.pyShows the full-page generation contract and when generation is different from targeted editing.
builder/…/pages.pyShows the proposal contract for new pages.
builder/…/query.pyShows block selection, block detail, reference-page reads, component contracts, and design context.
builder/…/settings.pyShows immediate page and theme changes, route refetches, publishing, and confirmation-gated site-wide changes.
builder/…/plugins.pyShows plugin publication, plugin source reads, editor-source inspection, and current-editor load reports.
builder/…/images.pyShows image search results and how exact URLs reach the generation step.
builder/…/preview.pyShows draft visual review, contrast checks, image safety checks, tiling, and preview cost limits.
builder/…/runtime.pyShows browser checks for page errors, canvas output, and interactive response.
builder/…/tree.pyShows the server-side page and component change boundary and the checks that keep invalid operations out of the saved tree.
builder/…/artifact.pyShows how large page output, reference geometry, selected images, live previews, and partial streams become authoritative page operations.
builder/…/page_writer.pyShows how generated page descriptions become draft blocks and page data.
builder/…/snapshots.pyShows when AI revert state is captured and what a revert covers.
builder/…/pending.pyShows the proposal and confirmation boundary for sensitive actions.
builder/…/test_agent_jobs.pyShows that queued jobs resolve provider keys in the worker and preserve the chosen effort without carrying secrets.
builder/…/test_page_changes.pyShows staged other-page edits, confirmed replay, route races, isolated failures, and off-screen new-page builds.
builder/…/test_read_page.pyShows the reference-page, component-contract, font, geometry, and page-addressing contracts.
builder/…/test_tree_apply.pyShows the server tree contract for styles, bindings, repeaters, refs, and structural edits.
builder/…/test_get_document.pyShows how site reads stay useful without flooding model context with long fields or page trees.
builder/…/test_image_view.pyShows the safe image-view contract for light and dark image variants and per-turn limits.