Skip to content

Commit dd03b97

Browse files
committed
feat(code): preview-first scaffolding + cleaner prompt
Reordered the agent's workflow so a live preview comes up as fast as possible: 1. Clarify 2. Scaffold the bare minimum that runs (no features yet) 3. Start the dev server + register the preview NOW 4. Build it out (with the user watching) 5. Wire up PostHog instrumentation The whole thing is one big template-string now instead of an array of joined fragments — easier to read and easier to edit. The intro message also tells the user to expect a preview "as fast as possible", and the build-out step calls out that HMR / re-registration is fine so the agent isn't shy about restarting. Generated-By: PostHog Code Task-Id: 142b4c29-fa5f-4e02-9bc9-de8b22313475
1 parent 76357e8 commit dd03b97

3 files changed

Lines changed: 44 additions & 45 deletions

File tree

apps/code/src/renderer/features/scratchpads/components/ProductCreationDialog.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ describe("ProductCreationDialog", () => {
162162
it("renders the framing banner, name field, prompt input and project radios", () => {
163163
renderDialog();
164164
expect(
165-
screen.getByText(/First I ask, then build, then deploy/),
165+
screen.getByText(/Let's 1\. clarify, 2\. build, 3\. deploy\./),
166166
).toBeInTheDocument();
167167
expect(screen.getByText(/I'll run up to/)).toBeInTheDocument();
168168
expect(screen.getByPlaceholderText("Uber for dogs")).toBeInTheDocument();

apps/code/src/renderer/features/scratchpads/components/ProductCreationDialog.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export function ProductCreationDialog() {
275275
className="shrink-0 text-(--accent-11)"
276276
/>
277277
<Text className="font-medium text-[13px] tracking-tight">
278-
First I ask, then build, then deploy.
278+
Let's 1. clarify, 2. build, 3. deploy.
279279
</Text>
280280
</Flex>
281281
<Text
@@ -297,10 +297,7 @@ export function ProductCreationDialog() {
297297
</SegmentedControl.Item>
298298
))}
299299
</SegmentedControl.Root>{" "}
300-
{rounds === 1 ? "round" : "rounds"} of clarifying questions, then
301-
scaffold a stack with PostHog analytics, replay, and error
302-
tracking wired from the first commit. A live preview opens beside
303-
the chat the moment your dev server is up.
300+
{rounds === 1 ? "round" : "rounds"} of clarifying questions, then build it with a live preview, then help you deploy.
304301
</Text>
305302
</Flex>
306303

apps/code/src/renderer/sagas/scratchpad/scaffolding-prompt.ts

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export interface ScaffoldingPromptInput {
1818
}
1919

2020
/**
21-
* Returns the verbatim scaffolding prompt text. Constraints embedded in the
22-
* prompt are duplicated as agent-facing rules; do not rely on this being
23-
* structured — it is a single text block.
21+
* Returns the verbatim scaffolding prompt text. The agent reads this as
22+
* markdown — keep it human-readable, keep guardrails explicit, and don't
23+
* rely on structured parsing.
2424
*/
2525
export function buildScaffoldingPrompt(input: ScaffoldingPromptInput): string {
2626
const {
@@ -32,40 +32,42 @@ export function buildScaffoldingPrompt(input: ScaffoldingPromptInput): string {
3232
taskId,
3333
} = input;
3434

35-
return [
36-
`You are scaffolding a brand-new app called **${productName}** in \`${scratchpadPath}\`. The user has given you the following idea:`,
37-
"",
38-
"---",
39-
initialIdea,
40-
"---",
41-
"",
42-
"**Before you start anything else**, send a short message to the user (one or two sentences) telling them what to expect: that you'll ask a few clarifying questions, then scaffold the project, install dependencies, and start a dev server — and that **the moment the dev server is up a preview tab will open automatically**. Then proceed with the workflow below.",
43-
"",
44-
"Follow this workflow:",
45-
"",
46-
`1. **Socratic clarification.** Before writing any code, run up to **${rounds}** rounds of Socratic clarification using the \`posthog_code__askClarification\` tool. Each round may include multiple questions; **every question must include a \`prefilledAnswer\`** representing your best guess so the user can accept defaults with one keystroke. Cover at minimum: app type (web/mobile/CLI/etc.), stack choice (your recommendation; the user can override), and any product-specific behaviour you can't safely guess. PostHog instrumentation is implicit — don't ask about it. Skipping clarification entirely is allowed when the request is fully specified, but encouraged for at least one round otherwise.`,
47-
"",
48-
`2. **Scaffold.** Pick a production-grade, simple, mainstream stack appropriate for the product. Run the necessary scaffolding commands inside \`${scratchpadPath}\` (e.g. \`pnpm create vite\`, \`pnpm create next-app\`, \`cargo new\`, etc.). The directory is already a fresh \`git\` repo on \`main\` with no commits — you can use \`git\` normally, but **do NOT run \`git init\`** in subdirectories or scaffolders that try to (pass \`--no-git\`/equivalent flags). Do not add deployment scripts or hosting configuration.`,
49-
"",
50-
" **For any product with a UI, design with intentionality.** Before you write a single line of styling, WebFetch Anthropic's `frontend-design` skill from `https://raw.githubusercontent.com/anthropics/claude-code/main/plugins/frontend-design/skills/frontend-design/SKILL.md` and follow it like a loaded skill — that file IS the skill. If the fetch fails, hold yourself to the same bar inline: pick a distinctive aesthetic direction, distinctive typography (no Inter/Arial/Roboto), dominant color + sharp accents (no cliché purple-on-white gradients), and at least one unforgettable choice.",
51-
"",
52-
[
53-
"3. **PostHog instrumentation.** Run these slash-prompts in order, recovering inside your own loop if any step fails or installs the SDK out of order:",
54-
" - `/instrument-integration`",
55-
" - `/instrument-product-analytics`",
56-
" - `/instrument-error-tracking`",
57-
" - `/instrument-llm-analytics` (only if the product has AI/LLM features)",
58-
projectId === null
59-
? " No PostHog project is linked yet — the user will pick or create one at publish time. Read the API key and host from environment variables (`POSTHOG_API_KEY`, `POSTHOG_HOST`) and add a placeholder `.env.example` documenting them. Do NOT hardcode any project IDs or keys."
60-
: ` Use PostHog project ID \`${projectId}\` for these. Read the API key from environment variables (\`POSTHOG_API_KEY\`, \`POSTHOG_HOST\`) and add a placeholder \`.env.example\`.`,
61-
].join("\n"),
62-
"",
63-
`4. **Preview registration.** Once you have a working dev server, declare it via \`posthog_code__registerPreview({ taskId: "${taskId}", name, command, port, cwd })\`. Always pass \`taskId: "${taskId}"\` — the host uses it to scope the preview to this scratchpad. Call once per process — e.g. one call for frontend, one for backend if both run. Use a \`name\` like \`"frontend"\` or \`"backend"\` for clarity.`,
64-
"",
65-
"**Hard constraints:**",
66-
"- You **must not** write `.posthog.json` directly — the host owns the manifest. If you need to surface preview info, use `posthog_code__registerPreview`.",
67-
"- Do not push to a remote, add a remote, or otherwise publish — Publish is a separate user-driven action.",
68-
"- Choose a mainstream stack. No esoteric or research-grade frameworks unless the user explicitly asked.",
69-
`- All work happens inside \`${scratchpadPath}\`. Do not touch files outside this directory.`,
70-
].join("\n");
35+
const instrumentationProjectNote =
36+
projectId === null
37+
? "No PostHog project is linked yet — the user will pick or create one at publish time. Read the API key and host from environment variables (`POSTHOG_API_KEY`, `POSTHOG_HOST`) and add a placeholder `.env.example` documenting them. Do NOT hardcode any project IDs or keys."
38+
: `Use PostHog project ID \`${projectId}\` for these. Read the API key from environment variables (\`POSTHOG_API_KEY\`, \`POSTHOG_HOST\`) and add a placeholder \`.env.example\`.`;
39+
40+
return `You are scaffolding a brand-new app called **${productName}** in \`${scratchpadPath}\`. The user has given you the following idea:
41+
42+
---
43+
${initialIdea}
44+
---
45+
46+
**Before you start anything else**, send a short message to the user (one or two sentences) telling them what to expect: that you'll ask a few quick clarifying questions, then scaffold a minimal version and **stand up a live preview as fast as possible** so they can see it taking shape — features and styling iterate from there. Then proceed with the workflow below.
47+
48+
Follow this workflow:
49+
50+
1. **Socratic clarification.** Before writing any code, run up to **${rounds}** rounds of Socratic clarification using the \`posthog_code__askClarification\` tool. Each round may include multiple questions; **every question must include a \`prefilledAnswer\`** representing your best guess so the user can accept defaults with one keystroke. Cover at minimum: app type (web/mobile/CLI/etc.), stack choice (your recommendation; the user can override), and any product-specific behaviour you can't safely guess. PostHog instrumentation is implicit — don't ask about it. Skipping clarification entirely is allowed when the request is fully specified, but encouraged for at least one round otherwise.
51+
52+
2. **Scaffold the bare minimum that runs.** Pick a production-grade, simple, mainstream stack appropriate for the product (e.g. \`pnpm create vite\`, \`pnpm create next-app\`, \`cargo new\`, etc.) and get it to a state where \`pnpm dev\` (or equivalent) starts a working dev server — even with placeholder content. Optimize for **speed to first preview**: run the scaffolder, install dependencies, do not yet build out features or polish UI. The directory is already a fresh \`git\` repo on \`main\` with no commits — you can use \`git\` normally, but **do NOT run \`git init\`** in subdirectories or scaffolders that try to (pass \`--no-git\`/equivalent flags). Do not add deployment scripts or hosting configuration.
53+
54+
3. **Start the dev server and register the preview NOW.** As soon as you have anything that boots, kick off the dev server and declare it via \`posthog_code__registerPreview({ taskId: "${taskId}", name, command, port, cwd })\` (always pass \`taskId: "${taskId}"\`; \`name\` should be \`"frontend"\` / \`"backend"\` / etc.). The user sees a live preview tab open the moment the server is up — get them there before you start filling in features. If the product has both a frontend and a backend, register them as you bring each up; you do not have to wait for both.
55+
56+
**For any product with a UI, design with intentionality.** Before you write a single line of styling beyond the scaffolder defaults, WebFetch Anthropic's \`frontend-design\` skill from \`https://raw.githubusercontent.com/anthropics/claude-code/main/plugins/frontend-design/skills/frontend-design/SKILL.md\` and follow it like a loaded skill — that file IS the skill. If the fetch fails, hold yourself to the same bar inline: pick a distinctive aesthetic direction, distinctive typography (no Inter/Arial/Roboto), dominant color + sharp accents (no cliché purple-on-white gradients), and at least one unforgettable choice.
57+
58+
4. **Build it out.** With the preview running and the user watching, iterate on features and UI. Re-saving files is fine — most dev servers HMR. If you have to restart the server, that's also fine; \`registerPreview\` re-registration just updates the URL. Keep the user informed about what you're doing.
59+
60+
5. **PostHog instrumentation.** Once the app is taking shape, wire up PostHog. Run these slash-prompts in order, recovering inside your own loop if any step fails or installs the SDK out of order:
61+
- \`/instrument-integration\`
62+
- \`/instrument-product-analytics\`
63+
- \`/instrument-error-tracking\`
64+
- \`/instrument-llm-analytics\` (only if the product has AI/LLM features)
65+
66+
${instrumentationProjectNote}
67+
68+
**Hard constraints:**
69+
- You **must not** write \`.posthog.json\` directly — the host owns the manifest. If you need to surface preview info, use \`posthog_code__registerPreview\`.
70+
- Do not push to a remote, add a remote, or otherwise publish — Publish is a separate user-driven action.
71+
- Choose a mainstream stack. No esoteric or research-grade frameworks unless the user explicitly asked.
72+
- All work happens inside \`${scratchpadPath}\`. Do not touch files outside this directory.`;
7173
}

0 commit comments

Comments
 (0)