feat(vite-plugin): surface Local Explorer API to headless agents- #14688 - #14912
feat(vite-plugin): surface Local Explorer API to headless agents- #14688#14912dario-piotrowicz wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 81d4e62 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This comment was marked as resolved.
This comment was marked as resolved.
@cloudflare/autoconfig
@cloudflare/config
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: |
This comment was marked as low quality.
This comment was marked as low quality.
3f3aadc to
e475dcf
Compare
e475dcf to
81d4e62
Compare
|
✅ All changesets look good |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
| */ | ||
| export function isAgentSession(): boolean { | ||
| try { | ||
| return isAgent({ env: process.env }); |
There was a problem hiding this comment.
🟡 Agent detection runs a slow blocking process scan on every non-interactive server start
Agent detection is invoked (isAgent({ env: process.env }) at packages/vite-plugin-cloudflare/src/detect-agent.ts:18) without disabling the process-tree scan, so every non-interactive dev/preview start performs a slow blocking system call that can stall or time out.
Impact: Starting a Vite dev or preview server in CI or an agent environment can hang or be noticeably slower.
Process ancestry traversal via execSync not disabled
The sibling implementation in Wrangler (packages/wrangler/src/utils/detect-agent.ts:1-47) deliberately passes processAncestry: NO_PROCESS_ANCESTRY (an empty array) to detectAgenticEnvironment, with an explicit comment: "Process tree traversal uses execSync('ps ...') which is slow and can cause timeouts, especially in CI environments. Environment variable detection is sufficient for identifying most agentic environments."
The new wrapper here calls isAgent({ env: process.env }) and omits the processAncestry: [] option, so am-i-vibing falls back to its default process-tree traversal (synchronous execSync('ps ...')). This path is only reached in non-TTY sessions (the guard process.stdin.isTTY || ... || !isAgentSession() in packages/vite-plugin-cloudflare/src/plugins/agent-hint.ts:38-44 short-circuits before isAgentSession() for TTYs), i.e. exactly the CI / agent environments the Wrangler comment warns about.
Align with the Wrangler wrapper by passing an empty processAncestry array.
| return isAgent({ env: process.env }); | |
| // Pass an empty processAncestry to skip process-tree traversal, which | |
| // uses execSync('ps ...') and can be slow / time out in CI. Environment | |
| // variable detection is sufficient for most agentic environments. | |
| return isAgent({ env: process.env, processAncestry: [] }); |
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
@dario-piotrowicz What do you think about this comment? Would it be better to align with the Wrangler implementation?
There was a problem hiding this comment.
ah yeah definitely! 👍
| export function isAgentSession(): boolean { | ||
| try { | ||
| return isAgent({ env: process.env }); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
🔍 isAgentSession relies on am-i-vibing's isAgent returning true only for type 'agent'
The doc comment on isAgentSession claims it returns true only when the environment type is exactly "agent" (not "hybrid"/"interactive"). This depends on am-i-vibing's isAgent() helper being defined as type === "agent". The sibling Wrangler wrapper instead calls detectAgenticEnvironment(...).type === "agent" explicitly (packages/wrangler/src/utils/detect-agent.ts:42). If isAgent() in am-i-vibing were ever to include hybrid (e.g. an alias of isAgentic), this wrapper's contract would silently break, whereas Wrangler's explicit check would not. Worth a quick confirmation against the installed am-i-vibing@0.5.0 API.
Was this helpful? React with 👍 or 👎 to provide feedback.
| const originalBindCLIShortcuts = server.bindCLIShortcuts.bind(server); | ||
| server.bindCLIShortcuts = (options?: vite.BindCLIShortcutsOptions) => { | ||
| originalBindCLIShortcuts(options); | ||
| if (options?.print) { | ||
| printLocalExplorerAgentHint(server, mode); | ||
| } | ||
| }; |
There was a problem hiding this comment.
📝 Info: bindCLIShortcuts patching coexists with shortcutsPlugin only because shortcuts bail in non-TTY
agentHintPlugin patches server.bindCLIShortcuts in configureServer/configurePreviewServer, and so does shortcutsPlugin (packages/vite-plugin-cloudflare/src/plugins/shortcuts.ts:119-161). These do not conflict because maybeAddAgentHint only patches when !process.stdin.isTTY (packages/vite-plugin-cloudflare/src/plugins/agent-hint.ts:38-44), while addShortcuts returns early when !process.stdin.isTTY (shortcuts.ts:44-46). So the two patches are mutually exclusive by TTY state, and the hint relies on cf-vite.ts:192 (and Vite's CLI) calling bindCLIShortcuts({ print: true }) unconditionally. This coupling is subtle: if either the TTY guard in shortcuts or the unconditional bindCLIShortcuts({print:true}) call changes, behavior could break or double-patch.
Was this helpful? React with 👍 or 👎 to provide feedback.
When a Vite dev or preview server with the Cloudflare plugin is started in a headless AI agent environment, the plugin now prints the Local Explorer API URL and useful resource routes to stdout so agents can discover and call them programmatically.
This is the same as #14688 but for the Vite Plugin
A picture of a cute animal (not mandatory, but encouraged)