Start a screen from a template

For AI agents: this page is Markdown at https://squiggle.sh/docs/run/templates.md. Every docs page is listed at https://squiggle.sh/llms.txt, and all of them are one file at https://squiggle.sh/llms-full.txt.

squiggle add screen writes a new screen that already has what the report card checks: a handle on every control, a flow that drives it, its declared controls and a renders budget it meets.

Before you start

  • An app set up with squiggle init. In a React Native app the screens use agentHint from @squiggle.sh/react-native; a React web app gets screens built from plain elements. See In a React web app.
  • Expo Router, or Next.js in a web app, to get a route written for you. Without it you get everything else, and the command tells you which component to mount.

Add a screen

Name the kind, then the route. The route name is lower-case letters, digits and dashes, starting with a letter; leave it out and the screen is named after its kind.

Terminal
squiggle add screen list ordersadd screen list orders · A searchable list of rows, with a count, a selection and an empty state.  ✔ the list template: src/screens/orders.tsx  ✔ its route: src/app/orders.tsx  ✔ its flow: .squiggle/flows/orders.yaml  ✔ its interface: .squiggle/interfaces/orders.json  ✔ its budget: rendersPerTap 60: .squiggle/config.jsonc  squiggle flow orders                      drive it  squiggle card --files src/app/orders.tsx  its report card

Then run its flow, and its card:

Terminal
squiggle flow orders
Terminal
squiggle card --files src/app/orders.tsx

The six kinds

KindWhat you get
listA searchable list of rows, with a count, a selection and an empty state. Rows are drawn by a plain ScrollView; switch to FlatList past about a hundred rows.
formName, email and message fields, checked when you press Send, with an error under each field and a sent state.
authEmail and password sign-in with a busy state and an error. Pass your own check as signIn; the default accepts any well-formed email with a password of eight or more characters.
detailA grid of tiles. Pressing one opens its detail, and the tile’s artwork grows into the detail’s header.
settingsToggles with an On/Off readout, a Delete account button that asks twice, and Done.
onboardingPages with Next, Back and Skip, ending in Get started.

Each screen comes with sample data, so it runs before you connect it to anything. Replace the sample data and the default callbacks with your own.

Try each one below. The phone runs the same file squiggle add screen writes, its flow drives it, and the report card is built from that run.

Template

Starting the demo app…

What it writes

FileWhat it is
src/screens/<name>.tsxThe screen, as one file you own. It imports only react, react-native and @squiggle.sh/react-native. Without a src folder, it goes in screens/.
src/app/<name>.tsxThe route that shows it. Props that leave the screen, such as onDone, call router.back().
.squiggle/flows/<name>.yamlA flow that opens the screen, uses it, asserts what changed on screen, and goes back, so the next run starts the screen fresh.
.squiggle/interfaces/<name>.jsonEvery testID the screen draws when it opens, on its controls and on anything else, such as a text you assert on. The report card checks the running screen against them, so when you add a testID to the screen, add it here too, or the card’s interface row fails.
.squiggle/config.jsoncA budget for the screen: at most 60 renders for any one tap. Your other settings and comments stay as they are.

The route for a settings screen named prefs:

Terminal
import { router } from 'expo-router';import { SettingsScreen } from '../screens/prefs';export default function PrefsRoute() {  return <SettingsScreen onDone={() => router.back()} />;}

In a React web app

In an app that renders with react-dom and has no React Native, squiggle add screen writes the web version of each template: the same controls, text and flow, built from plain elements with a data-testid on each control. It imports only react.

Your appThe page it writes
Next.js, App Routerapp/<name>/page.tsx (in src/ if your app has one), a client page that shows the screen.
Next.js, Pages Routerpages/<name>.tsx.
Vite or another bundlerNone. The command tells you which component to mount at /<name> in your router.

The flow opens the page at /<name>, and ends by opening your home page rather than going back, so the next run starts the screen fresh. Run it with your app’s origin:

Terminal
squiggle flow orders --udid web:http://localhost:3000

In the declared controls, a text field has the role textbox and a search field the role searchbox, as the browser gives them. See React web apps.

Options

FlagWhat it does
--app-dir <dir>The app’s directory, when you run it from somewhere else, such as the root of a monorepo. The flow, the interface and the budget still go in the project’s .squiggle folder.
--dry-runLists every file it would write, and writes none.
--forceOverwrites files that already exist.
--jsonPrints each file with its status: written, planned, exists or todo.

When something is already there

  • A file exists. It is left alone and listed as skipped. Add --force to overwrite it, or pick another name.
  • The screen already has a budget. It is never changed, with or without --force.
  • Your config can’t be edited safely. The command writes everything else and prints the budget line to add yourself.
  • An unknown kind or a name with spaces or capitals stops it with exit code 2. An unknown kind lists the kinds there are; a bad name says what a name may contain.

How the templates are checked

Every template runs in Squiggle’s own CI, inside the demo app the web Studio drives, with its flow and its report card. A change that turns a template’s card red fails that CI run: every control has to be reachable by name, its flow has to pass, and no tap may cost more than 60 renders. The web version of each template runs its flow in the same CI. See The report card for what each row means.