[wrangler] Experiment: redirect agent-driven static Pages deploys to Workers#14312
[wrangler] Experiment: redirect agent-driven static Pages deploys to Workers#14312MattieTK wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 6455144 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
This adds an experimental path that, when Wrangler detects it is being driven by an AI agent, redirects brand-new static pages deploy / pages project create invocations to a Workers static-assets deploy (with fallback to Pages on failure).
Ranked issues:
- (High) The user-specified deploy directory is silently dropped on redirect —
main(["deploy"])ignoresoptions.assetsDirectory, so a user runningwrangler pages deploy ./distgets autoconfig guessing the assets dir instead of using./dist. This can deploy the wrong directory. - (Low)
getDetectedAgentId()re-invokesdetectAgenticEnvironmenta second time (once inisAgenticAgent, once here) per redirect. Minor, but the detection result could be computed once and threaded through.
Noting the PR is explicitly an experiment / do-not-merge, so I've kept this to behavioral correctness rather than polish.
| // Passing no positional path is deliberate — it makes `wrangler deploy` | ||
| // run autoconfig, which detects the static assets directory and | ||
| // configures the project for Workers. | ||
| await main(["deploy"]); |
There was a problem hiding this comment.
The user's requested assets directory is dropped here. For pages deploy <directory>, options.assetsDirectory holds the directory the user explicitly asked to deploy, but main(["deploy"]) is called with no path and no --assets, so autoconfig will re-detect the assets directory and may pick a different one than the user specified. Forward the directory so the redirect deploys what the user asked for:
| await main(["deploy"]); | |
| // Forward the user-specified assets directory (when present) so the | |
| // Workers deploy targets the same files the Pages command would have. | |
| // Without this, autoconfig re-detects the directory and may choose a | |
| // different one than the user requested. | |
| const deployArgs = | |
| options.assetsDirectory !== undefined | |
| ? ["deploy", "--assets", options.assetsDirectory] | |
| : ["deploy"]; | |
| await main(deployArgs); |
|
Review posted successfully to PR #14312. Summary of what I posted:
I acknowledged the PR is an explicit experiment/do-not-merge and kept feedback focused on behavioral correctness. |
|
✅ All changesets look good |
b241ef5 to
6455144
Compare
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
| const redirect = await maybeRedirectPagesToWorkers({ | ||
| command: "create", | ||
| projectPath: process.cwd(), | ||
| }); | ||
| if (redirect.handled) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
🚩 Redirect from pages project create silently discards user-provided project name
When an AI agent runs wrangler pages project create my-app, the handler at packages/wrangler/src/pages/projects.ts:144-150 calls maybeRedirectPagesToWorkers({ command: "create", projectPath: process.cwd() }) — the projectName argument (which is demandOption: true) is not forwarded. The redirect then invokes main(["deploy"]) (redirect-to-workers.ts:78), which runs autoconfig. Autoconfig derives the project name from the directory name, not from the agent's requested name. So wrangler pages project create my-api in a directory named my-project would create a Workers project named my-project, not my-api. This also changes semantics from "create project only" to "create AND deploy". This appears intentional per the changeset description but is worth noting as a potential source of agent confusion.
Was this helpful? React with 👍 or 👎 to provide feedback.
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
Experiment — do not merge.