Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/selfhost-chrome.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@cloudhal/cli": minor
"@cloudhal/cloudflare": minor
"@cloudhal/mcp-server": minor
"@cloudhal/core-ts": patch
---

`render_page` on self-host through an optional Chrome sidecar (#292).
- **The setting.** `CLOUDHAL_BROWSER_URL` (Chrome's DevTools port) gives the admin Worker a `BROWSER_CDP` binding.
- **The driver.** `@cloudhal/cloudflare`'s new `devtoolsRenderer` drives it with the shared `cdpSession`: one browser context per render, and the shared browser is never closed.
- **What it opens.** `render_page` opens only the page's signed preview link. With `RenderDeps.origin` (`CLOUDHAL_RENDER_ORIGIN`, default `http://cloudhal:8788`) it opens the link at that private origin, so a site without a domain renders too. `@cloudhal/core-ts` gains `previewUrlAt`.
- **The recipes.** The compose file gains a `chrome` profile: no port, and a network shared with Cloudhal only. The Helm chart gains `chrome.*` values: a Deployment, a Service and a NetworkPolicy.
12 changes: 11 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ name: Docker image
# on the next request, a restart, the Node-volume guard, a second instance taking over while the
# first stops), scripts/failover-smoke.ts (three instances, one killed with SIGKILL while a release
# is due, then graceful handoffs under load; #290), scripts/mail-smoke.ts (an invite and a reset
# through Mailpit with STARTTLS and AUTH; #291) and Trivy, which fails the job on a CRITICAL
# through Mailpit with STARTTLS and AUTH; #291), scripts/render-smoke.ts (render_page through
# the Chrome sidecar; #292) and Trivy, which fails the job on a CRITICAL
# vulnerability with a fix;
# - `smoke-arm64` runs the same smoke test on the arm64 image, on GitHub's native arm64 runner;
# - `tag` adds the release tags to the very digest that passed, with `imagetools create`, writes
Expand Down Expand Up @@ -54,6 +55,7 @@ on:
- "scripts/docker-smoke.ts"
- "scripts/failover-smoke.ts"
- "scripts/mail-smoke.ts"
- "scripts/render-smoke.ts"
- "scripts/pack-packages.ts"
- "scripts/selfhost-edge-bundle.ts"
- "packages/cli/src/selfhost/**"
Expand Down Expand Up @@ -114,13 +116,16 @@ jobs:
docker compose -f deploy/docker/compose.yml --env-file "$RUNNER_TEMP/compose.env" config --quiet
docker compose -f deploy/docker/compose.yml --env-file "$RUNNER_TEMP/compose.env" --profile caddy config --quiet
docker compose -f deploy/docker/compose.yml --env-file "$RUNNER_TEMP/compose.env" --profile mail config --quiet
docker compose -f deploy/docker/compose.yml --env-file "$RUNNER_TEMP/compose.env" --profile chrome config --quiet
- name: Lint the Helm chart
run: |
helm lint deploy/helm/cloudhal
helm lint deploy/helm/cloudhal --set replicaCount=3 --set baseUrl=https://studio.example.com --set ingress.enabled=true
helm template t deploy/helm/cloudhal --set httpRoute.enabled=true --set baseUrl=https://studio.example.com --set 'httpRoute.parentRefs[0].name=gw' > /dev/null
helm template t deploy/helm/cloudhal --set mail.smtpUrlSecret.name=smtp --set mail.from=cloudhal@example.com --set mail.caConfigMap.name=ca \
| grep -q 'CLOUDHAL_SMTP_CA_FILE' || { echo "::error::the chart's mail values render no CLOUDHAL_SMTP_CA_FILE"; exit 1; }
helm template t deploy/helm/cloudhal --set chrome.enabled=true \
| grep -q 'value: "http://t-cloudhal-chrome:9222"' || { echo "::error::chrome.enabled renders no CLOUDHAL_BROWSER_URL"; exit 1; }
if helm template t deploy/helm/cloudhal --set mail.smtpUrlSecret.name=smtp > /dev/null 2>&1; then
echo "::error::mail.smtpUrlSecret without mail.from must fail"; exit 1
fi
Expand Down Expand Up @@ -264,6 +269,11 @@ jobs:
- name: Mail smoke test (Mailpit)
timeout-minutes: 10
run: node scripts/mail-smoke.ts --image cloudhal:ci
# render_page (#292): the chrome profile's browser on a network of its own; an agent key calls
# render_page over /mcp and gets a JPEG back. CI only.
- name: render_page smoke test (Chrome sidecar)
timeout-minutes: 10
run: node scripts/render-smoke.ts --image cloudhal:ci
- name: Trivy scan
timeout-minutes: 15
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ node scripts/release-bundle.ts build|verify … # RFC-0046 release bundle: det
- `packages/core-ts` — `SiteGraphStore` (CAS on `rev`, snapshots, diff, publish, rollback). Behavioural suite in `src/testing.ts` runs on sqlite and Miniflare D1. `./local` opens the offline store; `seedStarterSite` seeds a demo. `./surfaces` is RFC-0020's generative UI: the catalog (primitives + block types), eval-free surface checks, bindings, repairs, JSON Patch (`patchPage`), `catalogPrompt`; `./interop` converts A2UI v0.9 and json-render to and from surfaces; `./design` is RFC-0021's DESIGN.md lint and guidance. `./fields` is RFC-0041's typed custom fields (definition and value checks, `resolveFields`, `formatFieldValue`, the agents' JSON Schema, the conversion table); `src/fields-operations/` runs rename/retype/localize/remove. `search.ts` is RFC-0019's FTS5 site search (index written with the publish batch; articles, pages, terms and authors, RFC-0029); `search-provider.ts` is RFC-0029's `SearchProvider` (`fts5`, `memory`, `withFallback`), set with `SiteGraphStoreOptions.search`; `search-ai.ts` is the experimental Cloudflare AI Search provider (`hybridProvider`, `searchProviderFromEnv`, `cloudhal.json` `search`, docs/guides/search.md).
- `packages/schedules` — RFC-0008: time model (only `temporal-polyfill/implementation`, `now` injected, never `Temporal.Now`), RRULE subset, release model (`rl1:`), automation/run state, taint and budgets, `runDue`; `./sql` is `SqlScheduleStore`, `./engine` the Temporal-free part core-ts and the site Worker use. Worker-safe; conformance suites in `src/testing.ts` on sqlite and Miniflare D1.
- `packages/astro-renderer` — `GraphSource` (live/snapshot), `cloudhal()` integration (virtual config + dev route-cache watcher), `.astro` section components (`Surface.astro` for RFC-0020 surfaces; `./surfaces` renders them, `./kit` has the table of contents and reading time; `./fields` and `EntryFields.astro` render typed field values, RFC-0041). `./status-page` is RFC-0043's status pages (`statusPage(state, input) → Response`, served by the Site Worker entry before Astro and by `cloudhal dev` at `/__cloudhal/status/<state>`; the optional `statusPage` theme hook; the catalog in `src/status-strings/` where only `en.ts` is hand-edited and the other languages come from `pnpm i18n:import`). Routes live in starters, not here.
- `packages/cli` — the `cloudhal` CLI (`init`, `dev`, `studio`, `mcp`, `deploy`, `push`, `pull`, `export`, `import`, …; every command is in `src/cli/help.ts`, which `cloudhal --help` prints and the docs site's CLI reference is generated from); TS bin run by Node 24 type stripping. `src/cli.ts` parses flags and dispatches through `COMMANDS`, built from `src/cli/commands-{local,remote,content,ops,site}.ts` (a new command is one handler plus one line in `src/cli/help.ts`). `src/archive/` is RFC-0039's `.cloudhal` container (tar, gzip, manifest, limits), read and written by `src/commands/export.ts` and `import*.ts` (`archive-bundle.ts`, `archive-reassemble.ts`); the starter demo archive `test/fixtures/site-archives/starter-blog.cloudhal` is written by `pnpm demo:archive`, and `pnpm check` fails when it is stale. E2E test spawns the bin (Astro disables dev middleware under `VITEST`). Cloudflare tests run both Workers on workerd via wrangler's `createTestHarness`; test files run serially (shared starter caches). `src/commands/deploy/release/` is RFC-0046 §11b's `deploy --release`: the signed key and yank lists (`trust.ts`, the yank memory in `~/.cloudhal/release-trust.json`), the release lookup and download, the theme check against the CLI's starter (`theme-check.ts`; recheck its build-input list on every Astro or Vite major), the build keys of `src/config-build-keys.ts`, extraction and the `no_bundle` wrangler configs; tests use `@cloudhal/release-verify`'s synthetic bundle (`test/fixtures/release-deploy.ts`), never the network. `src/selfhost/` is RFC-0047's self-host image on workerd (`cloudhal selfhost fetch|check|config|secrets|start`): the settings (`_FILE` secrets), the generated Cap'n Proto config (Durable Object `uniqueKey`s are constants, never change them), the bundle check, the Node-volume guard, the first site and the SMTP sender behind `EMAIL` (`smtp-*.ts`, #291: STARTTLS or TLS only; `smtp-client.ts` has no imports because the config embeds it as a Worker module); `deploy/docker/workerd/` pins workerd (an npm lockfile Dependabot bumps weekly, ADR-0047; never the Miniflare pin), `scripts/docker-smoke.ts` runs it on SeaweedFS.
- `packages/cli` — the `cloudhal` CLI (`init`, `dev`, `studio`, `mcp`, `deploy`, `push`, `pull`, `export`, `import`, …; every command is in `src/cli/help.ts`, which `cloudhal --help` prints and the docs site's CLI reference is generated from); TS bin run by Node 24 type stripping. `src/cli.ts` parses flags and dispatches through `COMMANDS`, built from `src/cli/commands-{local,remote,content,ops,site}.ts` (a new command is one handler plus one line in `src/cli/help.ts`). `src/archive/` is RFC-0039's `.cloudhal` container (tar, gzip, manifest, limits), read and written by `src/commands/export.ts` and `import*.ts` (`archive-bundle.ts`, `archive-reassemble.ts`); the starter demo archive `test/fixtures/site-archives/starter-blog.cloudhal` is written by `pnpm demo:archive`, and `pnpm check` fails when it is stale. E2E test spawns the bin (Astro disables dev middleware under `VITEST`). Cloudflare tests run both Workers on workerd via wrangler's `createTestHarness`; test files run serially (shared starter caches). `src/commands/deploy/release/` is RFC-0046 §11b's `deploy --release`: the signed key and yank lists (`trust.ts`, the yank memory in `~/.cloudhal/release-trust.json`), the release lookup and download, the theme check against the CLI's starter (`theme-check.ts`; recheck its build-input list on every Astro or Vite major), the build keys of `src/config-build-keys.ts`, extraction and the `no_bundle` wrangler configs; tests use `@cloudhal/release-verify`'s synthetic bundle (`test/fixtures/release-deploy.ts`), never the network. `src/selfhost/` is RFC-0047's self-host image on workerd (`cloudhal selfhost fetch|check|config|secrets|start`): the settings (`_FILE` secrets), the generated Cap'n Proto config (Durable Object `uniqueKey`s are constants, never change them), the bundle check, the Node-volume guard, the first site and the SMTP sender behind `EMAIL` (`smtp-*.ts`, #291: STARTTLS or TLS only; `smtp-client.ts` has no imports because the config embeds it as a Worker module); `browser-sidecar.ts` binds the optional Chrome for `render_page` as `BROWSER_CDP` (#292, `@cloudhal/cloudflare`'s `browser-cdp.ts`); `deploy/docker/workerd/` pins workerd (an npm lockfile Dependabot bumps weekly, ADR-0047; never the Miniflare pin), `scripts/docker-smoke.ts` runs it on SeaweedFS.
- `packages/cloudflare` — the admin Worker (`createAdminWorker`); `./playground` is RFC-0036's playground Worker (`createPlaygroundWorker`, the `PlaygroundSite` Durable Object, signed session cookies). Generated entries must import `@cloudhal/cloudflare/workerd-prelude` first (ADR-0012).
- `packages/agent-runtime` / `packages/mcp-server` — policy, skills, audit; MCP tools and transports (ADR-0011). `@cloudhal/mcp-server/render` is RFC-0021's `render_page` core: a small DevTools client, the in-page checks and limits; the CLI drives local Chrome with it (`render-chrome.ts`), the admin Worker Browser Rendering (`browser-render.ts`).
- `starters/blog` — the theme boundary: `src/pages/[...path].astro`, `src/layouts`, `src/theme.ts`.
Expand Down
5 changes: 5 additions & 0 deletions deploy/docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@
#CLOUDHAL_SMTP_URL=smtp://cloudhal:mailpit@mailpit:1025
#CLOUDHAL_SMTP_CA_FILE=/run/cloudhal-mail/cert.pem

# render_page (the agents' screenshot tool): Chrome's DevTools port. The chrome profile runs one
# (`docker compose --profile chrome up -d`); it opens the site at CLOUDHAL_RENDER_ORIGIN.
#CLOUDHAL_BROWSER_URL=http://chrome:9222
#CLOUDHAL_RENDER_ORIGIN=http://cloudhal:8788

# Traces of every Worker invocation to an OTLP/HTTP collector.
#OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318
3 changes: 2 additions & 1 deletion deploy/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The official self-host image, `ghcr.io/cloudhal-dev/cloudhal`, built from each r
- **`compose.yml`, `.env.example`, `Caddyfile`:** Cloudhal with SeaweedFS and a one-shot that creates the bucket.
- With the `caddy` profile, Caddy proxies both hosts with TLS and sets `CF-Connecting-IP`.
- With the `mail` profile, Mailpit catches every message at http://127.0.0.1:8025. It requires STARTTLS, with a certificate the `mail-tls` one-shot makes once.
- With the `chrome` profile, a headless Chrome serves `render_page` (`CLOUDHAL_BROWSER_URL=http://chrome:9222`). It publishes no port and shares a network with Cloudhal only.

Build a release:

Expand All @@ -32,4 +33,4 @@ node scripts/pack-packages.ts deploy/docker/tarballs && pnpm --filter @cloudhal/

`node scripts/docker-smoke.ts --image cloudhal:local` runs what CI runs after every build (`.github/workflows/docker.yml`); `--platform linux/arm64` runs the other architecture where Docker can.

`scripts/failover-smoke.ts` is the cluster failover test (#290): three instances, one killed with SIGKILL while a release is due, then graceful handoffs under load. It runs in CI only and refuses to start anywhere else. So does `scripts/mail-smoke.ts` (#291), which sends an invite and a password reset through Mailpit with STARTTLS and AUTH required.
`scripts/failover-smoke.ts` is the cluster failover test (#290): three instances, one killed with SIGKILL while a release is due, then graceful handoffs under load. It runs in CI only and refuses to start anywhere else. So does `scripts/mail-smoke.ts` (#291), which sends an invite and a password reset through Mailpit with STARTTLS and AUTH required, and `scripts/render-smoke.ts` (#292), which calls `render_page` through the Chrome sidecar.
25 changes: 25 additions & 0 deletions deploy/docker/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# (Studio) and CLOUDHAL_SITE_URL (the site)
# docker compose --profile mail up -d + Mailpit, which catches every mail Cloudhal sends
# (http://127.0.0.1:8025; see the mailpit service)
# docker compose --profile chrome up -d + a headless Chrome for render_page (see the chrome
# service)
# Every instance of an installation needs the same .env; this file runs one instance (the cluster
# of one). More instances: deploy/swarm or deploy/helm.
x-store: &store
Expand Down Expand Up @@ -59,6 +61,11 @@ services:
CLOUDHAL_SMTP_CA_FILE: ${CLOUDHAL_SMTP_CA_FILE:-}
CLOUDHAL_MAIL_FROM: ${CLOUDHAL_MAIL_FROM:-}
CLOUDHAL_MAIL_FROM_NAME: ${CLOUDHAL_MAIL_FROM_NAME:-}
# render_page: Chrome's DevTools port (the chrome profile: http://chrome:9222), off when empty.
# The browser opens the site at CLOUDHAL_RENDER_ORIGIN (default http://cloudhal:8788).
CLOUDHAL_BROWSER_URL: ${CLOUDHAL_BROWSER_URL:-}
CLOUDHAL_RENDER_ORIGIN: ${CLOUDHAL_RENDER_ORIGIN:-}
networks: [default, render]
volumes:
- cloudhal-data:/data
# The mail profile's certificate (empty without the profile).
Expand Down Expand Up @@ -156,6 +163,24 @@ services:
volumes:
- mail-tls:/tls:ro

# The chrome profile: a headless Chrome for render_page (RFC-0047 §6). It publishes no port and
# sits on its own network with Cloudhal only, so it cannot reach the store; Cloudhal opens in it
# only a page's own signed preview link, one browser context per render. Set in .env:
# CLOUDHAL_BROWSER_URL=http://chrome:9222
chrome:
profiles: [chrome]
image: chromedp/headless-shell:159.0.8154.34@sha256:5bb2432d550896f4cb4266c367c48d82e6e2ed61f71ced68687bb175d62ce312
restart: unless-stopped
shm_size: 512m
cap_drop: [ALL]
security_opt: ["no-new-privileges:true"]
networks: [render]

networks:
default:
# Cloudhal and the chrome profile's browser, nothing else.
render:

volumes:
# Each instance's Durable Object files (they replicate through the store) and the v2 marker.
cloudhal-data:
Expand Down
8 changes: 8 additions & 0 deletions deploy/helm/cloudhal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ helm upgrade cloudhal deploy/helm/cloudhal --reuse-values \
- For a relay whose certificate no browser trusts, put its CA in a ConfigMap and set `mail.caConfigMap.name` (key `ca.pem` by default).
- The pods connect to the server themselves. Under an egress NetworkPolicy of your own, allow its port.

## Screenshots for agents

`render_page` needs a browser. `--set chrome.enabled=true` runs a headless Chrome in the release:
- a Deployment and a Service, with no Ingress;
- a NetworkPolicy that admits only the release's instances to its DevTools port.

The instances open in it only a page's signed preview link, at `http://<release>:8788` (`chrome.renderOrigin`). `chrome.url` names a browser of your own instead.

## Upgrades

```bash
Expand Down
95 changes: 95 additions & 0 deletions deploy/helm/cloudhal/templates/chrome.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{{- if .Values.chrome.enabled }}
{{- $fullname := include "cloudhal.fullname" . }}
# A headless Chrome for render_page (RFC-0047 §6, #292). It has no Ingress or route, and only this
# release's instances may reach its DevTools port. They open in it only a page's own signed
# preview link, at http://<release>:<site port>, one browser context per render.
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $fullname }}-chrome
labels:
{{- include "cloudhal.labels" . | nindent 4 }}
app.kubernetes.io/component: chrome
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: chrome
template:
metadata:
labels:
{{- include "cloudhal.labels" . | nindent 8 }}
app.kubernetes.io/component: chrome
spec:
enableServiceLinks: false
automountServiceAccountToken: false
securityContext:
seccompProfile:
type: RuntimeDefault
containers:
- name: chrome
image: "{{ .Values.chrome.image.repository }}:{{ .Values.chrome.image.tag }}"
ports:
- name: devtools
containerPort: 9222
readinessProbe:
tcpSocket: { port: devtools }
periodSeconds: 5
resources:
{{- toYaml .Values.chrome.resources | nindent 12 }}
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: [ALL]
volumeMounts:
- name: shm
mountPath: /dev/shm
volumes:
- name: shm
emptyDir:
medium: Memory
sizeLimit: 512Mi
---
apiVersion: v1
kind: Service
metadata:
name: {{ $fullname }}-chrome
labels:
{{- include "cloudhal.labels" . | nindent 4 }}
app.kubernetes.io/component: chrome
spec:
selector:
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: chrome
ports:
- name: devtools
port: 9222
targetPort: devtools
{{- if .Values.networkPolicy.enabled }}
---
# Whoever reaches the DevTools port drives the browser: only this release's instances may.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ $fullname }}-chrome
labels:
{{- include "cloudhal.labels" . | nindent 4 }}
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: chrome
policyTypes: [Ingress]
ingress:
- from:
- podSelector:
matchLabels:
{{- include "cloudhal.selector" . | nindent 14 }}
ports:
- port: 9222
{{- end }}
{{- end }}
Loading