Repository navigation
Serve product site as live Leaf pages - #380
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
Two of the six route families can't reach their agent, so the change's headline claim doesn't hold on the homepage.
agentRequest in worker/src/index.ts builds http://container${root}/_leaf/agent/${action}, with root empty when route === "/". That produces /_leaf/agent/turn for / and /examples/_leaf/agent/turn for /examples. published_page in worker/server.py resolves neither: / and /examples are exactly the two routes the PRODUCT_ROUTES loop skips, PAGE_RESOURCE has no _leaf alternative, and EXAMPLE_ROUTE's [a-z0-9-]+ slug cannot match _leaf. Both fall through to return None, so _select_page returns false and the container answers _not_found().
Running the two route tables against each other:
/_leaf/agent/turn -> None
/examples/_leaf/agent/turn -> None
/how-it-works/_leaf/agent/turn -> ('how-it-works', '/how-it-works', '/_leaf/agent/turn', 'product')
/examples/design-decision/_leaf/agent/reply -> ('design-decision', '/examples/design-decision', '/_leaf/agent/reply', 'example')
What a reader gets: a comment on / or /examples/ is accepted, acceptedObligation starts the workflow, and askContainer(..., "turn") takes a 404. Because the status is under 500 that is a NonRetryableError, which runAgentWorkflow's catch converts into GENERATION_FAILURE_REPLY; the append generation failure step then 404s the same way and throws out of step.do. The workflow fails, the obligation never settles, and the banner goes on promising that state.publication.agent "replies here" on the very page docs/index.html now invites people to use ("or use the controls on this page").
The two inline suggestions close it. I checked that they leave every other route resolving as before and open no external hole: the Worker still 404s /_leaf/* ahead of routing, and pageRoute("/examples/_leaf/agent/turn") still returns null, so neither path is reachable from outside the container.
Supporting observations:
- Nothing exercises a product-route agent turn end to end.
worker/test/index.test.tsparametrizes the workflow start over/and/examples/design-decision, but the container-side resolution of_leaf/agent/*is only covered for examples, intests/test_website_server.py. A POST to/_leaf/agent/turninsidetest_a_product_route_uses_the_same_real_page_serverwould have caught this. - The product route table and the page-resource allowlist now live in four places with nothing pinning them together:
PRODUCT_ROUTESinscripts/site.py,PRODUCT_ROUTESandPAGE_RESOURCEinworker/server.py,PRODUCT_ROOTSandPAGE_RESOURCEinworker/src/routing.ts, and the inline route array invalidatedAgentParams. The bug above is drift between two of them, and the suite currently notices drift in only one direction. - Each of the five product page directories is a full
copytreeof the prepared page — the diagram (1.6M), diff (1.8M), and default (512K) vendor bundles plus every product image, five times over. The resulting.tmp/sitegoes both into the container image and into the Workers asset upload, but after this changeASSETSonly ever answers/media/*and/sitenote.js:isPrivatePageRequest404s/_leaf/*andpageRoutesends everything else to the container. The asset binding is now carrying roughly 25 MB it can never serve. worker/test/index.test.ts's "serves the product route %s through Leaf" asserts theContent-Security-Policythat its own container mock returned, and with a cookie present the Worker returns that sameResponseuntouched, so the assertion cannot fail. The old test verified thatstaticAssetResponseadded the header. The header itself is still correct —Handlersendsframe_ancestors_policyon HTML — but nothing pins it at the Worker boundary any more.
One conflict, in the banner's status writer. Main's #380 renamed `state.example` to `state.publication` and gave it a `kind`, so a published page says either "This is an example on the Leaf website." or "This website is a Leaf page."; this branch had moved that sentence out of the reading and into `exampleWords`, so the measured status floor could ask the same writer for it. Both, so: the words follow main's two subjects and its `lf-publication-install` class, and they stay a writer of their own, now `publicationWords`, which the floor's enumeration goes on reading. The harness renamed its `website_example` argument to `website_publication` in the same commit, so this branch's floor test follows it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The directories a page answers beneath its root were listed four times: `schema.py`'s served paths, `http.py`'s rooted-reference rebasing, the website adapter's route regex in `worker/server.py`, and the Worker's copy in `worker/src/routing.ts`, which a Python test held to the vendored files by parsing the TypeScript. Both Worker-side lists still routed `guidance/`, which no server has served since #380. - `schema.PAGE_ROUTE_DIRS` names the namespace's directories. The website adapter builds its route regex from it and `VENDORED_FILES`. - `scripts/site.py` writes both into the site manifest as `routes: {dirs, files}`, and the Worker's `pageRoute` and `releaseAssetRoute` route from the manifest, which it already loads and validates, instead of a hand-written regex. - `http.py`'s rooted-reference set is built from the same layer constants. It differs from the route set on purpose, and its comment says how: it leaves out the documents, whose addresses the server writes itself, and takes in the authored `page/` tree, served only beneath a revision. - `schema.REVISION_NAME` and `VERSION_NAME` are the revision and version file-name patterns that `files.py`, `http.py`'s two revision routes and `SERVED_PATH` each spelled out. Behaviour that moved: - `<page>/guidance/...` is no longer routed to a page by the Worker or the adapter; it falls through to static assets, where nothing lives. - The site manifest gains a required `routes` field; the Worker refuses a manifest without one. - `test_the_worker_routes_every_file_a_page_vendors` is deleted: the Worker no longer holds a copy of the list for it to check. `routing.test.ts` now asserts a `guidance/` path is not routed. The worker TypeScript gate (`npm run typecheck` and `npm test` in `worker/`) passes locally; `scripts/verify-site-local.sh` was not run. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
The product site currently publishes Leaf-authored markup as script-free HTML, so the homepage looks like Leaf but lacks its runtime, threads, versions, and state. This change makes the five product routes live Leaf pages without restoring the removed browser-side session emulator.
The site build now produces a complete page directory for each product route. The Worker routes product pages and examples through the canonical Python server in a private per-reader container, while shared social media assets remain static. Website state, session naming, and the Durable Object binding are generalized from examples to publications; a Wrangler migration preserves the existing Durable Object class.
The route tests cover product assets, example assets, private paths, canonical slashes, event delivery, and the
/examples/catalog namespace alongside/examples/<slug>/. Deployment verification checks both a product page and an example after publishing.The server now exercises homepage and catalog agent turns end to end. The generated
.assetsignorelimits the Worker asset manifest to the shared media and site note it can serve; complete page directories remain in the container image. Worker tests also cover CSP preservation when the response receives a new session cookie.Tested with the 907-test Python suite, 19 Worker tests, TypeScript checking, the full pre-commit gate, a 35-page site build, a Wrangler deployment dry-run, and browser interaction checks on desktop and mobile.