1import { useEffect, useState } from "react";
2
3const CANONICAL_ORIGIN = "https://alchemy.run";
4
5/**
6 * Build the copy-for-agent prompt. The doc links must be absolute — the
7 * prompt is pasted into a coding agent outside the browser — so instead of
8 * relative paths, the origin is a parameter: preview deployments pass their
9 * own origin and produce prompts that point back at themselves.
10 */
11export const agentPrompt = (
12 origin: string = CANONICAL_ORIGIN,
13) => `Help me build an Alchemy app on Cloudflare. Start by reading ${origin}/getting-started and follow it exactly: scaffold a fresh project, install the dependencies, create the \`alchemy.run.ts\` Stack with a single Cloudflare R2 Bucket (no Worker yet), and run \`alchemy deploy\` so I sign in to Cloudflare and provision the Bucket. Confirm the Bucket is live before moving on.
14
15Then STOP and ASK ME what I want to build. From there, consult only the docs you need for what I asked for — don't march me through every tutorial. A Worker only gets added later if what I want to build needs one (the tutorial covers that in part-2).
16
17Tutorial — foundations, work through whichever parts I haven't touched:
18 ${origin}/cloudflare/tutorial/part-1 First Stack (state store + first resource)
19 ${origin}/cloudflare/tutorial/part-2 Add a Worker
20 ${origin}/cloudflare/tutorial/part-3 Testing
21 ${origin}/cloudflare/tutorial/part-4 Local Dev (\`alchemy dev\`)
22 ${origin}/cloudflare/tutorial/part-5 CI/CD (per-PR previews from GitHub Actions)
23
24For everything else (Cloudflare deep-dives, guides, concepts), fetch ${origin}/llms.txt — it's the index of the guide and concept docs. Use it to look up the specific page you need instead of guessing URLs. The per-resource API reference is indexed separately in ${origin}/llms-full.txt — it's large, so only fetch it when you need a specific resource's reference page.
25
26Important:
27- Confirm with me before each deploy. Don't batch.
28- Do NOT instruct me to export CLOUDFLARE_ACCOUNT_ID or CLOUDFLARE_API_TOKEN. Alchemy stores credentials in profiles — \`alchemy profile edit\` (or the first \`alchemy deploy\`) prompts interactively for OAuth or an API token and saves it to ~/.alchemy/profiles.json.
29- Use pnpm: \`pnpm add\` to install packages and \`pnpm alchemy deploy\` to deploy.
30- If I'm migrating from Alchemy v1 (async/await), find the v1 migration guide via llms.txt and read it first.`;
31
32/**
33 * The agent prompt for the current deployment. SSR and first paint render
34 * the canonical-origin prompt; after hydration it swaps to the page's own
35 * origin (a no-op string-wise on prod, the preview URL on PR previews).
36 */
37export const useAgentPrompt = () => {
38 const [prompt, setPrompt] = useState(agentPrompt());
39 useEffect(() => setPrompt(agentPrompt(window.location.origin)), []);
40 return prompt;
41};