README.md
# Cloud rehearsal
Rehearse iterate Cloud's sign-up chat against a fake Cloudflare:
```sh
node scripts/cloud-rehearsal/start.ts --mind tthq.app
```
It prints the chat's link, in the mind's Dash, after about half a minute. A start makes no commit.
`node scripts/cloud-rehearsal/stop.ts fake-cf-<time>` ends it. To an agent, "set up a cloud
rehearsal on tthq" is enough: the skill `.agents/skills/cloud-rehearsal` says the rest.
Say how Cloudflare should behave in a sentence, and the fake is set up for it:
```sh
node scripts/cloud-rehearsal/start.ts --mind tthq.app \
--scenario "The payment card is already added, and everything else goes through quickly"
```
## How it works
- **In the mind, the rehearsal app** ([mind-app/](mind-app/), installed as `apps/cloud-rehearsal/`)
is a copy of iterate Cloud's own app. It makes the agent as iterate Cloud makes its own: the
guide arrives as a note, and the agent's scripts reach `itx.cloud` and nothing else of the mind.
Three things differ, and each copy's header lists them:
- Where Cloudflare is. Every call that iterate Cloud sends to api.cloudflare.com goes to the rehearsal's fake, and one extra note tells the agent where the dashboard is, for the links it writes.
- The hand-over, which is ahead of iterate Cloud's own ([The hand-over is real](#the-hand-over-is-real)).
- The agent's config sets `llmRequestPolicy`, so that the person's words cut short the answer the model is writing. Only a mind whose platform has that field reads it (iterate/private, branch `agent-llm-request-policy`); any other mind drops it.
- **A tunnel** (`iterate tunnel`) serves a local port as `fake-cf-<time>.<mind>`. It is public,
because the mind's own Worker calls it, and that call carries no member's sign-in. So every call
must start with the run's secret, a random path segment that start.ts makes and gives the mind:
`https://fake-cf-<time>.<mind>/<secret>/…`. The server answers 404 to anything else, before any
rule or agent sees it. The secret is in the chat's links: share the chat with nobody else.
- **A thin server** ([fake-cloudflare.ts](fake-cloudflare.ts)) answers every call from the run's
folder, `runs.ignoreme/fake-cf-<time>/`:
- `world.json`: the state. A wait is the instant it ends ([rules.ts](rules.ts)).
- `rules.mjs`: this run's rules, tried first. Then [base-rules.ts](base-rules.ts).
- `run.jsonl`: every call, its answer and who gave it.
- **A coding agent is the fake's author** ([ask-agent.ts](ask-agent.ts)), not its server:
- at the start it turns the scenario into `world.json`;
- when a call has no rule, it writes one into `rules.mjs` ([RULES.md](RULES.md)). The same call
is a lookup from then on.
- **A call that is no route of Cloudflare's API** gets Cloudflare's own 404, and the agent is not
asked ([cloudflare-routes.ts](cloudflare-routes.ts), from Cloudflare's public spec).
- **The agent is asked only about** a route of Cloudflare's API, a page under an account
(`/<account id>/…`, as the dashboard's are), or a path that some rule names (`/sandbox`,
`/deploy`). Any other path is a 404, and costs no agent's run.
Save `world.json` or `rules.mjs` by hand to change a running rehearsal: both are read at each call.
## The hand-over is real
Everything of Cloudflare is fake. The hand-over at the end is not.
- `itx.cloud.handOver({ domain, person, said, notes })` writes one sign-up record, and a row that sends that record alone to the mind at `domain`, signed by the mind that runs the rehearsal (the mind meld). It answers `letIn`, the link `https://<domain>/let-in/<the rehearsal's mind>`.
- The mind at `domain` takes the record once its owner signs the rule at that link. `itx.cloud.handedOver({ domain })` says whether it arrived, and has the row try again when it has not.
- That mind's code then gives the record to its onboarding agent, which greets the owner and starts its helpers.
So the domain a person picks in a rehearsal matters. The fake deploys nothing: the hand-over reaches whatever mind already runs at that domain.
- For a hand-over to arrive, that mind must read a sign-up record in the mind form and serve `/let-in/<mind>` (the template of iterate/private, branch `template-meld-handover`), and its `cloud-handover.ts` must name the rehearsal's mind beside iterate.com: the template trusts iterate.com alone.
- At any other domain the record and the row are written, and `handedOver` never answers `arrived`.
- Never a mind that somebody uses: its onboarding agent would get a stranger's record.
- A guide that still calls `handOver({ accountId, name, domain })`, as iterate Cloud's own does today, gets an error that names the new arguments.
iterate Cloud's own `handOver` does not do this yet: it gives the new mind the whole chat and a transcript file. The change is a pull request to iterate/iterate-config from the branch `cloud-meld-handover`. When iterate Cloud's app has it, the rehearsal app is a plain copy again.
## Options
[start.ts](start.ts)'s header says what each is when it is not given.
- `--scenario "…"`: without it, the world is the usual start (`startingWorld` in rules.ts).
- `--guide <file>`: without it, the mind's own draft when it has one
(`apps/cloud-rehearsal/onboarding.md` in its config repo, edited at
`https://docs.<mind>/?doc=apps/cloud-rehearsal/onboarding.md`); else iterate Cloud's own guide
as it is on GitHub now. A file's text
above a first `---` line is the guide; the rest is notes to people. The guide must name the
agent's tools as iterate Cloud's does (`itx.cloud.…`).
- `--person "First Last <email>"`: without it, the person the CLI is signed in to the mind as.
- `--agent claude|codex|"<command>"`: without it, the first of Claude Code and Codex that works.
- `--world <file>` starts from a world as it is.
- `--stale-app` starts although iterate Cloud's app changed since the copy.
## When iterate Cloud's app changes
`mind-app/` is a copy of two files of iterate/iterate-config: `apps/cloud/mind.ts` and
`apps/cloud/backend.ts`. Each copy's header names the commit it was copied at, and what differs
on purpose. A start compares that commit with `main` on GitHub and refuses when either file
changed. Then:
1. Read what changed, in a clone of iterate-config:
`git fetch && git diff <commit>..origin/main -- apps/cloud/mind.ts apps/cloud/backend.ts apps/cloud/onboarding.md`.
The guide is not copied (a start reads the newest), but its diff says what the agent now does.
2. Bring each change into `mind-app/mind.ts.txt` and `mind-app/backend.ts.txt`, except where the
header's "WHAT DIFFERS" already speaks. A new tool on `itx.cloud` gets the same name and
answer here. Where iterate Cloud's reaches Cloudflare or the person's sandbox, the rehearsal's
reaches the fake: no real person's Cloudflare access may come into it. The hand-over is the one
call that reaches a real mind.
3. When the agent now calls Cloudflare, or the fake's `/deploy` or `/sandbox`, in a new way, the
fake must answer as the real thing would: a rule in [base-rules.ts](base-rules.ts), and a test
in [fake-cloudflare.test.ts](fake-cloudflare.test.ts).
4. Write the new commit into both headers.
5. `node scripts/cloud-rehearsal/install.ts --mind tthq.app`: one commit to the mind. A start
refuses while the mind's copy is not this checkout's.
## Removing a rehearsal from a mind
`stop.ts` ends the server and the tunnel on this computer, and nothing in the mind. A rehearsal
that keeps running in the mind calls a fake that is gone and gets errors. To take it away, run a
script in the mind (`iterate itx run --mind <mind> --file <script>`) that does this, for each
rehearsal at `/apps/cloud-rehearsal/minds/<mind_…>`:
- `itx.cd(path).processors.disable("agent")` and `disable("cloud")`: the agent and the app stop.
- `itx.cd(path).schedules.list()`, then `schedules.cancel(key)` for each `cloud/job-ended:…`: the
notes of background commands that have not ended yet.
- For each hand-over, at `<path>/handovers/to-<domain>`: append
`{ type: "events.iterate.com/itx/subscription-configured", payload: { name: "to-<domain>", target: null } }`.
The row stops sending. A record that arrived stays in the mind at that domain.
The rewrite rules of `<path>` and `<path>/scripts` act only inside those contexts, so they can stay.
To take the app itself away, commit to the mind's config repo what `install.ts` added: remove
`apps/cloud-rehearsal/`, the two methods `cloudRehearsalMind` and `cloudRehearsal` and their import in `api.ts`,
and the `/apps/cloud-rehearsal/minds/` line in `agents.ts` (the template's line comes back). The
install's commit message ends with `Via: scripts/cloud-rehearsal/install.ts`. Remove the app only
after every rehearsal is stopped: a rehearsal's rows call `itx.config.cloudRehearsalMind`.
## Not built
- A deploy is a stand-in that takes its time (`POST /deploy`), and so is the sandbox
(`POST /sandbox`). Alchemy's real calls are not played.
- The hand-over commits no `onboarding-transcript.md` to the new mind, as iterate Cloud's does with a git token of the person's: a rehearsal holds no access to a real Cloudflare account.
- Nothing replays a recorded run.
- The person is a person. No agent plays them.
- The chat is the Dash's, not iterate Cloud's own page.
- The tunnel runs on the CLI's stored login. Another `iterate` command at the moment that login
refreshes can end both.
## Not proven
Rehearsals were played by hand to the end on 17 Nov 2026, on tthq.app: the consent, the card page, Workers Paid, R2, both deploys, sandbox commands and a deploy's end. Two of them ended in a real hand-over to benjerate.com.
- `makeAccount` has not been called in a rehearsal.
- No domain has been bought through the fake's registrar API in a rehearsal: each run used a domain that the account already owned, or bought one on the fake's page.
- Claude Code has not been the fake's author on a real run: Codex has.