@mistflow-ai/mcp 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +103 -99
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as Et,d as Nt,e as Le}from"./chunk-UNFTM4B3.js";import{b as ys,c as co,d as po,e as bs}from"./chunk-2X3ZTRP7.js";import{A as ao,C as Qo,D as Je,E as lo,F as Xo,G as Zo,H as es,I as ts,J as os,K as ss,L as rs,M as ns,N as is,O as yt,P as as,Q as ls,R as cs,S as ds,T as Dt,U as ps,V as us,W as ms,X as hs,Y as gs,_ as fs,b as Uo,c as Fo,d as gt,e as Bo,f as io,g as _t,h as be,i as Re,j as Ye,k as ft,l as qo,m as Se,n as zo,o as Ho,s as Go,t as Wo,u as Vo,w as Yo,x as Oe,y as Jo,z as Ko}from"./chunk-OIW7LXTF.js";import{Server as ec}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as tc}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as oc,ListToolsRequestSchema as sc}from"@modelcontextprotocol/sdk/types.js";import{zodToJsonSchema as rc}from"zod-to-json-schema";function d(s,o=!1){let t=s;try{let e=Fo();e&&(t=s+e)}catch{}return{content:[{type:"text",text:t}],isError:o}}function Ee(s){return d(`This is not a Mistflow project (no mistflow.json found at ${s}).
|
|
2
2
|
|
|
3
3
|
Mistflow creates new projects from scratch \u2014 it doesn't work inside existing codebases.
|
|
4
4
|
|
|
@@ -7,14 +7,14 @@ To get started:
|
|
|
7
7
|
2. Run mist_build (action: 'init') to create a new project in a subdirectory
|
|
8
8
|
3. Run mist_build (action: 'implement') to build each step
|
|
9
9
|
|
|
10
|
-
If you want to deploy an existing project, use your framework's deploy tools directly.`,!0)}async function Ue(s,o){try{let{getPage:
|
|
10
|
+
If you want to deploy an existing project, use your framework's deploy tools directly.`,!0)}async function Ue(s,o){try{let{getPage:t,takeScreenshot:e}=await import("./browser-manager-QW3OYPFB.js"),n=await t();await n.goto(s,{waitUntil:"domcontentloaded",timeout:15e3}),await n.waitForLoadState("networkidle").catch(()=>{});let a=await e(n,!1);return{content:[{type:"text",text:o},{type:"image",data:a.toString("base64"),mimeType:"image/png"}]}}catch{return d(o)}}import{z as uo}from"zod";import{platform as bn}from"os";import{execFile as ws}from"child_process";var wn=uo.object({apiKey:uo.string().optional().describe("API key (mist_...) for headless auth. Skips the device code flow entirely. Generate one at app.mistflow.ai/mcp-keys."),deviceCode:uo.string().optional().describe("Resume polling for a pending device code. Returned by a previous mist_setup call with status 'pending'. Call mist_setup again with this value after ~15 seconds to check if the user approved.")});function vn(s){return"error"in s}function kn(s){return new Promise(o=>setTimeout(o,s))}function xn(s){return new Promise(o=>{let t=bn();t==="win32"?ws("cmd.exe",["/c","start","",s],e=>{e&&console.error("Could not open browser:",e.message),o(!e)}):ws(t==="darwin"?"open":"xdg-open",[s],n=>{n&&console.error("Could not open browser:",n.message),o(!n)}),setTimeout(()=>o(!1),5e3)})}var Sn={fetch:globalThis.fetch,openBrowser:xn};async function vs(s,o,t,e){let n=t;for(let a=0;a<o;a++){await kn(n);let r;try{let l=await e.fetch(`${Ye()}/auth/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:s})});if(!l.ok)continue;r=await l.json()}catch{continue}if(vn(r))switch(r.error){case"authorization_pending":continue;case"slow_down":n+=5e3;continue;case"expired_token":return d("The sign-in link expired. Run mist_setup again to get a new code.",!0);case"access_denied":return d("Sign-in was cancelled. Run mist_setup again to try again.",!0);case"already_exchanged":return d("This sign-in link was already used. Run mist_setup again to get a new code.",!0)}let i=r.email||r.org_name||r.org_slug;return io({apiKey:r.api_key,apiKeyId:r.api_key_id,apiKeyName:r.api_key_name,orgId:r.org_id,orgSlug:r.org_slug,email:r.email}),d(`Connected to Mistflow as ${i}. You are ready to build and deploy.`)}return null}async function Tn(s,o=Sn){let t=s;if(t?.apiKey)try{let r=await o.fetch(`${Ye()}/api/org`,{headers:{Authorization:`ApiKey ${t.apiKey}`}});if(!r.ok)return d("Invalid API key. Check the key and try again.",!0);let i=await r.json();return io({apiKey:t.apiKey,orgId:i.id,orgSlug:i.slug}),d(`Connected to Mistflow as ${i.slug} via API key. You are ready to build and deploy.`)}catch{return d("Cannot reach Mistflow servers. Check your internet connection.",!0)}if(t?.deviceCode){let r=await vs(t.deviceCode,6,5e3,o);return r||d(JSON.stringify({status:"pending",deviceCode:t.deviceCode,instruction:"The user hasn't approved yet. Wait ~15 seconds and call mist_setup again with the same deviceCode."}))}let e;try{let r=await o.fetch(`${Ye()}/auth/device`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!r.ok)return d("Cannot reach Mistflow servers. Check your internet connection.",!0);e=await r.json()}catch{return d("Cannot reach Mistflow servers. Check your internet connection.",!0)}let n=`${e.verification_uri}?code=${e.user_code}`;console.error(`
|
|
11
11
|
Sign in at: ${n}
|
|
12
|
-
Your code: ${
|
|
13
|
-
`);try{await o.openBrowser(n)}catch{}let a=await vs(
|
|
12
|
+
Your code: ${e.user_code}
|
|
13
|
+
`);try{await o.openBrowser(n)}catch{}let a=await vs(e.device_code,6,5e3,o);return a||d(JSON.stringify({status:"pending",deviceCode:e.device_code,signInUrl:n,userCode:e.user_code,instruction:"The user hasn't approved yet. Wait ~15 seconds, then call mist_setup again with deviceCode='"+e.device_code+"' to check if they approved."}))}var ks={name:"mist_setup",description:"Connect the user's Mistflow account. Call this ONLY when: (a) the user has literally never signed in, or (b) a previous tool call returned error code 'auth_missing' or 'auth_revoked'. DO NOT call this tool in response to 500 errors, 404 errors, network errors, or any generic failure \u2014 those are backend issues, not auth issues. Running mist_setup when not needed wastes the user's time and creates login fatigue. Once signed in, the MCP persists a long-lived API key and never asks again. Two-phase device code flow: (1) Call without deviceCode \u2014 opens browser, returns status 'pending' with deviceCode and userCode. Tell the user the verification code and that they need to approve in the browser. (2) Call again with deviceCode after ~15 seconds \u2014 polls for approval. Also accepts an apiKey for headless auth (skips device code entirely).",inputSchema:wn,handler:s=>Tn(s)};import{z as O}from"zod";import{existsSync as bt,mkdirSync as $t,readFileSync as Ds,readdirSync as jn,statSync as Ln,unlinkSync as On,writeFileSync as jt}from"fs";import{dirname as Un,isAbsolute as Fn,join as ve}from"path";import{homedir as Fe}from"os";import{createHash as Bn,createHmac as Ms,randomBytes as qn,randomUUID as _s,timingSafeEqual as zn}from"crypto";function Ke(s,o,t,e=3e3){if(o===void 0)return{stop:()=>{}};let n=0,a=!1,i=setInterval(()=>{a||(n++,s.notification({method:"notifications/progress",params:{progressToken:o,progress:n,message:t()}}).catch(()=>{}))},e);return{stop:()=>{a||(a=!0,clearInterval(i))}}}var mo={},tt=[];function ot(s){let o=tt.find(e=>e.id===s);if(o)return o;let t=s.toLowerCase().replace(/[^a-z0-9]/g,"");return tt.find(e=>{let n=e.title.toLowerCase().replace(/[^a-z0-9]/g,"");return n===t||n.includes(t)||t.includes(n)})}function xs(s){return mo[s]}function ho(s){return s?tt.filter(o=>o.category.toLowerCase()===s.toLowerCase()):tt}function Ss(s){let o=s??tt;if(o.length===0)return"Landing page presets have been replaced by the tone-based system. The landing page tone is now auto-selected based on your app's description during planning.";let t={};for(let n of o){t[n.category]||(t[n.category]=[]);let a=mo[n.id],r=a?` \u2014 ${a.description}`:"";t[n.category].push(`${n.id} \u2014 "${n.title}"${r}`)}let e=[];for(let[n,a]of Object.entries(t))e.push(`**${n}**:
|
|
14
14
|
${a.map(r=>` \u2022 ${r}`).join(`
|
|
15
|
-
`)}`);return
|
|
15
|
+
`)}`);return e.join(`
|
|
16
16
|
|
|
17
|
-
`)}function Pn(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function Ts(s){return(s?ho(s):tt).map(
|
|
17
|
+
`)}function Pn(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function Ts(s){return(s?ho(s):tt).map(t=>{let e=mo[t.id];return{id:t.id,slug:Pn(t.title),title:t.title,category:t.category,description:e?.description??"",tags:e?.tags??[],theme:e?.theme??"dark",colors:e?.colors??[],style:e?.style??""}})}function Ps(s,o){return[]}var go={"resend-email":{description:"Transactional email with React Email templates and webhook handling.",tags:["email","transactional","welcome","notification","invite","alert"],envVars:[{key:"RESEND_API_KEY",description:"Resend API key for sending emails",setupUrl:"https://resend.com/api-keys"}],docsUrl:"https://resend.com/docs/send-with-nextjs",packages:["resend","@react-email/components"],difficulty:"easy"},"r2-storage":{description:"File uploads with drag-and-drop UI, stored in Mistflow Cloud.",tags:["storage","upload","file","image","media","attachment","avatar"],envVars:[],docsUrl:"https://developers.cloudflare.com/r2/",packages:[],difficulty:"easy"},"openai-ai":{description:"AI-powered features with OpenAI SDK, streaming chat, and content generation.",tags:["ai","openai","chatbot","gpt","llm","assistant","generation"],envVars:[{key:"OPENAI_API_KEY",description:"OpenAI API key for AI features",setupUrl:"https://platform.openai.com/api-keys"}],docsUrl:"https://platform.openai.com/docs/guides/text-generation",packages:["openai","ai"],difficulty:"medium"},"anthropic-ai":{description:"AI features with the Anthropic SDK, streaming Claude chat, and content generation.",tags:["ai","anthropic","claude","llm","assistant","generation"],envVars:[{key:"ANTHROPIC_API_KEY",description:"Anthropic API key for Claude",setupUrl:"https://console.anthropic.com/settings/keys"}],docsUrl:"https://docs.anthropic.com/en/docs/initial-setup",packages:["@anthropic-ai/sdk","ai"],difficulty:"medium"},"openrouter-ai":{description:"AI model router with access to 200+ models (GPT, Claude, Llama, Mistral, etc.) through one API.",tags:["ai","openrouter","llm","multi-model","claude","gpt","llama","mistral"],envVars:[{key:"OPENROUTER_API_KEY",description:"OpenRouter API key",setupUrl:"https://openrouter.ai/keys"}],docsUrl:"https://openrouter.ai/docs/quickstart",packages:["@openrouter/sdk"],difficulty:"easy"},"stripe-payments":{description:"Payment processing with Stripe Checkout, webhooks, and billing portal.",tags:["payments","stripe","billing","subscription","checkout","invoice"],envVars:[{key:"STRIPE_SECRET_KEY",description:"Stripe secret key",setupUrl:"https://dashboard.stripe.com/apikeys"},{key:"STRIPE_PUBLISHABLE_KEY",description:"Stripe publishable key (client-side)",setupUrl:"https://dashboard.stripe.com/apikeys"},{key:"STRIPE_WEBHOOK_SECRET",description:"Stripe webhook signing secret",setupUrl:"https://dashboard.stripe.com/webhooks"}],docsUrl:"https://docs.stripe.com/checkout/quickstart",packages:["stripe","@stripe/stripe-js"],difficulty:"advanced"},"elevenlabs-voice":{description:"Text-to-speech and voice generation with ElevenLabs API.",tags:["voice","tts","speech","audio","elevenlabs","narration","podcast"],envVars:[{key:"ELEVENLABS_API_KEY",description:"ElevenLabs API key for voice generation",setupUrl:"https://elevenlabs.io/app/settings/api-keys"}],docsUrl:"https://elevenlabs.io/docs/api-reference/text-to-speech",packages:["elevenlabs"],difficulty:"medium"},"google-maps":{description:"Google Maps embed, Places autocomplete, and geolocation features.",tags:["maps","location","google","places","geocoding","directions","nearby"],envVars:[{key:"NEXT_PUBLIC_GOOGLE_MAPS_API_KEY",description:"Google Maps API key (client-side)",setupUrl:"https://console.cloud.google.com/apis/credentials"}],docsUrl:"https://developers.google.com/maps/documentation/javascript",packages:["@googlemaps/js-api-loader"],difficulty:"medium"},"twilio-sms":{description:"SMS notifications, OTP verification, and phone number validation.",tags:["sms","twilio","otp","phone","verification","text-message"],envVars:[{key:"TWILIO_ACCOUNT_SID",description:"Twilio account SID",setupUrl:"https://console.twilio.com/"},{key:"TWILIO_AUTH_TOKEN",description:"Twilio auth token",setupUrl:"https://console.twilio.com/"},{key:"TWILIO_PHONE_NUMBER",description:"Twilio phone number for sending SMS",setupUrl:"https://console.twilio.com/us1/develop/phone-numbers/manage/incoming"}],docsUrl:"https://www.twilio.com/docs/messaging/quickstart/node",packages:["twilio"],difficulty:"medium"},"posthog-analytics":{description:"Product analytics with event tracking, feature flags, and session replay.",tags:["analytics","posthog","tracking","funnel","event","feature-flag"],envVars:[{key:"NEXT_PUBLIC_POSTHOG_KEY",description:"PostHog project API key",setupUrl:"https://app.posthog.com/project/settings"},{key:"NEXT_PUBLIC_POSTHOG_HOST",description:"PostHog instance URL (default: https://us.i.posthog.com)",setupUrl:"https://app.posthog.com/project/settings"}],docsUrl:"https://posthog.com/docs/libraries/next-js",packages:["posthog-js","posthog-node"],difficulty:"easy"},"firecrawl-scraping":{description:"Web scraping and crawling with markdown output, structured extraction, and async crawls.",tags:["scraping","crawl","firecrawl","web","extract","rag","markdown"],envVars:[{key:"FIRECRAWL_API_KEY",description:"Firecrawl API key",setupUrl:"https://firecrawl.dev"}],docsUrl:"https://docs.firecrawl.dev/sdks/node",packages:["@mendable/firecrawl-js"],difficulty:"easy"},"replicate-media":{description:"Image and video generation with 200+ AI models (Flux, Wan Video, Runway, SDXL, etc.) through one API.",tags:["image","video","replicate","flux","sdxl","generation","media","avatar","thumbnail"],envVars:[{key:"REPLICATE_API_TOKEN",description:"Replicate API token",setupUrl:"https://replicate.com/account/api-tokens"}],docsUrl:"https://replicate.com/docs/get-started/nodejs",packages:["replicate"],difficulty:"medium"}},st=[{id:"resend-email",name:"Resend Email",category:"communication",prompt:`## Resend Email Integration
|
|
18
18
|
|
|
19
19
|
### File Structure
|
|
20
20
|
\`\`\`
|
|
@@ -1434,12 +1434,12 @@ export function ImageGenerator() {
|
|
|
1434
1434
|
5. **Replicate charges per prediction.** Flux Schnell is ~$0.003/image. Flux Pro is ~$0.05/image. Video models are $0.05-$0.50/generation. Show generation cost to users.
|
|
1435
1435
|
6. **Cache generated images.** Store output URLs in your database. Replicate URLs expire after a few hours. Download and re-host on R2 for permanent storage.
|
|
1436
1436
|
7. **Network I/O does NOT count as CPU time on Workers.** Image generation wait time is all network I/O.
|
|
1437
|
-
8. **Never ask the user to paste REPLICATE_API_TOKEN in chat.** Direct them to set it in the Mistflow dashboard (Project Settings > Environment Variables).`}];function
|
|
1437
|
+
8. **Never ask the user to paste REPLICATE_API_TOKEN in chat.** Direct them to set it in the Mistflow dashboard (Project Settings > Environment Variables).`}];function Cn(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function rt(s){let o=st.find(e=>e.id===s);if(o)return o;let t=s.toLowerCase().replace(/[^a-z0-9]/g,"");return st.find(e=>{let n=e.name.toLowerCase().replace(/[^a-z0-9]/g,"");return n===t||n.includes(t)||t.includes(n)})}function nt(s){return go[s]}function fo(s){return s?st.filter(o=>o.category.toLowerCase()===s.toLowerCase()):st}function Cs(s){let o=s??st,t={};for(let n of o){t[n.category]||(t[n.category]=[]);let a=go[n.id],r=a?` \u2014 ${a.description}`:"",i=a?.packages.length?` (${a.packages.join(", ")})`:"";t[n.category].push(`${n.id} \u2014 "${n.name}"${r}${i}`)}let e=[];for(let[n,a]of Object.entries(t))e.push(`**${n}**:
|
|
1438
1438
|
${a.map(r=>` - ${r}`).join(`
|
|
1439
|
-
`)}`);return
|
|
1439
|
+
`)}`);return e.join(`
|
|
1440
1440
|
|
|
1441
|
-
`)}function
|
|
1442
|
-
`)}function In(s){let o=s.match(/\b(?:called|named)\s+["']?([A-Za-z][A-Za-z0-9 ]{1,30})["']?/i);if(o)return yo(o[1]);let
|
|
1441
|
+
`)}function As(s){return(s?fo(s):st).map(t=>{let e=go[t.id];return{id:t.id,slug:Cn(t.name),name:t.name,category:t.category,description:e?.description??"",tags:e?.tags??[],envVars:e?.envVars??[],docsUrl:e?.docsUrl??"",packages:e?.packages??[],difficulty:e?.difficulty??"medium"}})}var An=[{name:"Dashboard",description:"Overview with key stats and today's activity",condition:s=>s.surfaceType==="internal-tool"||s.surfaceType==="customer-app",keywords:/\b(dashboard|overview|home.?page|stats)\b/i},{name:"Landing Page",description:"Public page explaining what this does",condition:s=>s.publicLanding===!0,keywords:/\b(landing|marketing|hero|homepage)\b/i},{name:"Scheduling / Booking",description:"Calendar, time slots, reservations",condition:s=>s.scheduling===!0,keywords:/\b(schedul|book|reserv|appointment|calendar|slot)\b/i},{name:"Payments / Billing",description:"Charge users, invoices, subscriptions (experimental \u2014 Stripe integration is early-stage)",condition:()=>!1,keywords:/\b(payment|billing|invoice|subscription|checkout|stripe)\b/i},{name:"Admin Panel",description:"Manage users, roles, and content",condition:s=>s.multiRole===!0||s.primaryActor==="both",keywords:/\b(admin|panel|manage.?user|moderat)\b/i},{name:"User Profiles",description:"Account pages, settings, preferences",condition:s=>s.primaryActor==="customers"||s.primaryActor==="both",keywords:/\b(profile|account|settings|preferences)\b/i},{name:"Search / Browse",description:"Find and filter content or listings",condition:s=>s.surfaceType==="marketplace",keywords:/\b(search|browse|filter|discover|explore)\b/i},{name:"Email Notifications",description:"Welcome emails, alerts, reminders",condition:s=>s.integrations?.includes("email")===!0,keywords:/\b(notification|alert|reminder|email.?notif|sms|welcome.?email)\b/i},{name:"Analytics / Reports",description:"Usage stats, trends, data exports",condition:()=>!1,keywords:/\b(analytics|report|chart|trend|insight|metric)\b/i},{name:"File Uploads",description:"Images, documents, attachments",condition:s=>s.integrations?.includes("file-uploads")===!0,keywords:/\b(upload|image|photo|attachment|document|gallery|file)\b/i},{name:"AI Features",description:"Chatbot, content generation, AI assistant",condition:s=>s.integrations?.includes("ai")===!0,keywords:/\b(ai|chatbot|gpt|llm|generat|assistant)\b/i},{name:"Maps / Location",description:"Google Maps, location search, geolocation",condition:s=>s.integrations?.includes("maps")===!0,keywords:/\b(map|location|address|geo|places)\b/i},{name:"Voice / TTS",description:"Text-to-speech, voice notes, audio generation",condition:()=>!1,keywords:/\b(voice|tts|text.?to.?speech|audio|speak|narrat|podcast|elevenlabs)\b/i},{name:"SMS / Text Messages",description:"Send SMS notifications, OTP verification",condition:s=>s.integrations?.includes("sms")===!0,keywords:/\b(sms|text.?message|twilio|otp|verification.?code|phone.?verif)\b/i},{name:"Web Scraping",description:"Scrape URLs, crawl websites, extract structured data",condition:()=>!1,keywords:/\b(scrape|crawl|web.?scrap|extract.?from.?url|read.?url|ingest.?web|firecrawl)\b/i},{name:"Chat / Messaging",description:"Real-time messaging between users",condition:()=>!1,keywords:/\b(chat|messag|inbox|conversation|dm)\b/i},{name:"Events / Tournaments",description:"Create and manage events, registrations",condition:()=>!1,keywords:/\b(event|tournament|competition|league|registration)\b/i},{name:"High Scores",description:"Track and display top scores with a leaderboard",condition:s=>s.surfaceType==="game",keywords:/\b(high.?score|leaderboard|top.?score|ranking|scoreboard)\b/i},{name:"Save Progress",description:"Save and resume game state between sessions",condition:s=>s.surfaceType==="game",keywords:/\b(save|progress|resume|checkpoint|continue)\b/i},{name:"Guest Play",description:"Play immediately without signing up, optionally link account later",condition:s=>s.surfaceType==="game",keywords:/\b(guest|anonymous|no.?login|play.?now|instant.?play)\b/i},{name:"Levels / Stages",description:"Progressive difficulty with unlockable stages",condition:()=>!1,keywords:/\b(level|stage|unlock|difficult|progress|world)\b/i},{name:"Achievements",description:"Badges, trophies, and milestones for player accomplishments",condition:()=>!1,keywords:/\b(achieve|badge|trophy|milestone|reward|unlock)\b/i},{name:"Daily Challenge",description:"New puzzle or challenge every day to keep players coming back",condition:()=>!1,keywords:/\b(daily|challenge|streak|word.?of.?the.?day|puzzle.?of)\b/i}];function Is(s,o,t){let e=t?.suggestedName||In(s),n=o.primaryActor==="both"?"Staff + Customers":o.primaryActor==="staff"?"Staff / Admin":o.primaryActor==="customers"?"End Users":"Users",a=o.audienceType??(o.surfaceType==="internal-tool"?"internal":(o.primaryActor==="customers"||o.primaryActor==="both","b2c")),r=o.surfaceType==="internal-tool"?"Internal tool":o.surfaceType==="marketplace"?"Marketplace":o.surfaceType==="content-site"?"Content site":o.surfaceType==="game"?"Game":"App",i;if(t?.suggestedFeatures&&t.suggestedFeatures.length>0)i=t.suggestedFeatures.map(l=>({name:l.name,description:l.description,checked:l.recommended,source:l.recommended?"explicit":"suggested"}));else{let l=`${s} ${o.primaryAction||""}`;i=[];for(let c of An){let u=c.keywords.test(l),m=c.condition(o);(u||m)&&i.push({name:c.name,description:c.description,checked:u,source:u?"explicit":"suggested"})}}return{name:e,audience:n,audienceType:a,surfaceType:r,primaryAction:o.primaryAction||"manage items",features:i,publicLanding:o.publicLanding??!0,authModel:o.authModel??"email",dbProvider:o.dbProvider??"neon",integrations:o.integrations??[],language:t?.language||"English"}}function Rs(s){let o=s.features.filter(i=>i.checked),t=s.features.filter(i=>!i.checked),e={email:"Email sign-up",none:"No login (public)",social:"Social login","invite-only":"Invite-only"},n={neon:"Postgres",turso:"SQLite (legacy)"},a={b2c:"Your customers use this app (business-to-customer)",b2b:"Other businesses sign up for this (SaaS platform)",internal:"Internal team tool (staff only)"},r=[`**${s.name}** \u2014 ${s.surfaceType} for ${s.audience}`,`Audience: ${a[s.audienceType]??s.audienceType}`,`Primary action: ${s.primaryAction}`,`Access: ${e[s.authModel]??s.authModel} | Database: ${n[s.dbProvider]??s.dbProvider}${s.publicLanding?" | Landing page: Yes":""}${s.language&&s.language!=="English"?` | Language: ${s.language}`:""}`,""];if(o.length>0){r.push("**Included:**");for(let i of o)r.push(` \u2713 ${i.name} \u2014 ${i.description}`)}if(s.integrations.length>0&&(r.push(""),r.push(`**Integrations:** ${s.integrations.join(", ")}`)),t.length>0){r.push(""),r.push("**Available to add:**");for(let i of t)r.push(` \u25CB ${i.name} \u2014 ${i.description}`)}return r.join(`
|
|
1442
|
+
`)}function In(s){let o=s.match(/\b(?:called|named)\s+["']?([A-Za-z][A-Za-z0-9 ]{1,30})["']?/i);if(o)return yo(o[1]);let t=new Set(["build","create","make","a","an","the","for","me","my","app","application","website","web","tool","system","platform","using","with","and","that","this","want","need","please","can","you","i","mist","mistflow"]),n=s.toLowerCase().replace(/[^a-z0-9\s]/g,"").split(/\s+/).filter(a=>a.length>2&&!t.has(a)).slice(0,3);return n.length===0?"my-app":n.join("-")}function yo(s){return s.toLowerCase().replace(/[^a-z0-9\s]/g,"").trim().replace(/\s+/g,"-")}var Rn=["typographic","split-panel","terminal","full-bleed-photo","magazine-hero"],En=["sharp","soft","pill","organic"],Nn=["flat","paper-grain","film-grain","scanlines","gradient-mesh","noise","glassmorphic"];function bo(s,o,t){return o.includes(s)?s:t}function we(s){return String(s??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function it(s,o){return typeof s!="string"?o:/^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/.test(s.trim())?s.trim():o}function _n(s){let o=new Set;for(let e of s)e.fonts?.display&&o.add(e.fonts.display),e.fonts?.body&&o.add(e.fonts.body);return o.size===0?"":`https://fonts.googleapis.com/css2?${[...o].map(e=>`family=${e.trim().replace(/\s+/g,"+").replace(/[^A-Za-z0-9+]/g,"")}:wght@400;700`).join("&")}&display=swap`}function Es(s){let o=(s||"").trim(),t=o.toLowerCase(),e=/mono|courier|code/.test(t)?"ui-monospace, monospace":/serif|garamond|bodoni|fraunces|playfair|lora|sentient|migra|sectra|cormorant|abril|crimson/.test(t)?"Georgia, serif":"system-ui, sans-serif";return o?`"${o.replace(/"/g,"")}", ${e}`:e}function Dn(s){switch(s){case"sharp":return{card:"0px",button:"0px",chip:"0px"};case"pill":return{card:"20px",button:"999px",chip:"999px"};case"organic":return{card:"4px 24px 4px 24px",button:"24px 4px 24px 4px",chip:"12px 2px 12px 2px"};default:return{card:"10px",button:"8px",chip:"6px"}}}function Mn(){let s=`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.3 0 0 0 0 0.3 0 0 0 0 0.3 0 0 0 0.55 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>")`;return`
|
|
1443
1443
|
.card-hero { position: relative; overflow: hidden; isolation: isolate; }
|
|
1444
1444
|
.card-hero::before {
|
|
1445
1445
|
content: "";
|
|
@@ -1497,7 +1497,7 @@ ${a.map(r=>` - ${r}`).join(`
|
|
|
1497
1497
|
backdrop-filter: blur(14px);
|
|
1498
1498
|
mix-blend-mode: normal;
|
|
1499
1499
|
}
|
|
1500
|
-
`}function $n(s,o,e
|
|
1500
|
+
`}function $n(s,o,t,e){let n=it(s.colors?.bg??"","#0f0f0f"),a=it(s.colors?.fg??"","#f5f5f5"),r=it(s.colors?.accent??"","#7c9cff"),i=we(s.name),l=we(s.hero_headline||s.name),c=we(s.body_sample||s.summary||""),u=we(s.cta_text||"Continue"),m=`<div class="hero-eyebrow" style="font-family:${t}">${i.toUpperCase()}</div>`,p=`<h2 class="hero-headline" style="font-family:${o}">${l}</h2>`,g=`<p class="hero-body" style="font-family:${t}">${c}</p>`,b=`<button class="hero-cta" style="background:${r};color:${n};font-family:${t};border-radius:${e.button}">${u}</button>`,f=bo(s.hero_treatment,Rn,"typographic");if(f==="terminal"){let h=`"${(s.fonts?.display??"JetBrains Mono").replace(/"/g,"")}", ui-monospace, monospace`;return`
|
|
1501
1501
|
${m}
|
|
1502
1502
|
<div class="hero-terminal-lines" style="font-family:${h};color:${a}">
|
|
1503
1503
|
<div>$ status --all</div>
|
|
@@ -1511,7 +1511,7 @@ ${a.map(r=>` - ${r}`).join(`
|
|
|
1511
1511
|
`}return f==="split-panel"?`
|
|
1512
1512
|
<div class="hero-split">
|
|
1513
1513
|
<div class="hero-split-left" style="background:${r};color:${n};font-family:${o}">
|
|
1514
|
-
<div class="hero-split-mark" style="font-family:${
|
|
1514
|
+
<div class="hero-split-mark" style="font-family:${t};color:${n}">${i[0]??"\xB7"}</div>
|
|
1515
1515
|
</div>
|
|
1516
1516
|
<div class="hero-split-right">
|
|
1517
1517
|
${m}
|
|
@@ -1522,7 +1522,7 @@ ${a.map(r=>` - ${r}`).join(`
|
|
|
1522
1522
|
</div>
|
|
1523
1523
|
`:f==="full-bleed-photo"?`
|
|
1524
1524
|
<div class="hero-photo" style="background: linear-gradient(160deg, ${r}30 0%, ${a}08 35%, ${n} 100%), ${n}">
|
|
1525
|
-
<span class="hero-photo-label" style="font-family:${
|
|
1525
|
+
<span class="hero-photo-label" style="font-family:${t};color:${a}">photo slot</span>
|
|
1526
1526
|
</div>
|
|
1527
1527
|
${m}
|
|
1528
1528
|
${p}
|
|
@@ -1532,15 +1532,15 @@ ${a.map(r=>` - ${r}`).join(`
|
|
|
1532
1532
|
${m}
|
|
1533
1533
|
<h2 class="hero-headline hero-headline-mag" style="font-family:${o}">${l}</h2>
|
|
1534
1534
|
<div class="hero-rule" style="background:${a}"></div>
|
|
1535
|
-
<p class="hero-body hero-body-mag" style="font-family:${
|
|
1536
|
-
<div class="hero-byline" style="font-family:${
|
|
1535
|
+
<p class="hero-body hero-body-mag" style="font-family:${t}">${c}</p>
|
|
1536
|
+
<div class="hero-byline" style="font-family:${t};color:${a}">\u2014 Volume 01 \xB7 Issue 01</div>
|
|
1537
1537
|
<div class="hero-cta-row">${b}</div>
|
|
1538
1538
|
`:`
|
|
1539
1539
|
${m}
|
|
1540
1540
|
${p}
|
|
1541
1541
|
${g}
|
|
1542
1542
|
<div class="hero-cta-row">${b}</div>
|
|
1543
|
-
`}function
|
|
1543
|
+
`}function Ns(s,o){let t=_n(o),e=o.map(n=>{let a=it(n.colors?.bg??"","#0f0f0f"),r=it(n.colors?.fg??"","#f5f5f5"),i=it(n.colors?.accent??"","#7c9cff"),l=Es(n.fonts?.display??""),c=Es(n.fonts?.body??""),u=bo(n.shape_lang,En,"soft"),m=bo(n.texture,Nn,"flat"),p=Dn(u),g=$n(n,l,c,p),b=we(n.name),f=we(n.id),h=we(n.fonts?.display??""),w=we(n.fonts?.body??""),P=we(n.summary||""),I=we(n.decoration_hint||""),x=(E,L)=>`<div class="card-meta-row"><span class="card-meta-label">${E}</span><span class="card-meta-value">${L}</span></div>`;return` <article class="card" data-direction-id="${f}" style="border-radius:${p.card}">
|
|
1544
1544
|
<div class="card-hero texture-${m}" style="background:${a};color:${r}">${g}
|
|
1545
1545
|
</div>
|
|
1546
1546
|
<div class="card-meta" style="border-top-color:${r}14">
|
|
@@ -1568,7 +1568,7 @@ ${a.map(r=>` - ${r}`).join(`
|
|
|
1568
1568
|
<title>Design directions \u2014 ${we(s)}</title>
|
|
1569
1569
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
1570
1570
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
1571
|
-
${
|
|
1571
|
+
${t?`<link rel="stylesheet" href="${t}" />`:""}
|
|
1572
1572
|
<style>
|
|
1573
1573
|
:root {
|
|
1574
1574
|
--chrome-bg: #f4f3ef;
|
|
@@ -1866,7 +1866,7 @@ ${a.map(r=>` - ${r}`).join(`
|
|
|
1866
1866
|
</header>
|
|
1867
1867
|
|
|
1868
1868
|
<div class="grid">
|
|
1869
|
-
${
|
|
1869
|
+
${e}
|
|
1870
1870
|
</div>
|
|
1871
1871
|
|
|
1872
1872
|
<footer class="page-footer">
|
|
@@ -1881,22 +1881,22 @@ ${t}
|
|
|
1881
1881
|
</div>
|
|
1882
1882
|
</body>
|
|
1883
1883
|
</html>
|
|
1884
|
-
`}var Mt="__mistflow_url_choice__",Hn=600*1e3;function $s(){let s=ve(Fe(),".mistflow","confirm-secret");if(bt(s))try{return Buffer.from(Ds(s,"utf-8").trim(),"hex")}catch{}let o=qn(32);return $t(ve(Fe(),".mistflow"),{recursive:!0}),jt(s,o.toString("hex"),{mode:384}),o}function js(s){return Bn("sha256").update(s.trim().toLowerCase()).digest("hex").slice(0,16)}function Gn(s,o){let
|
|
1885
|
-
`)}),!0);if(v==="foreign"&&!b){if(!(f?Wn(f,t
|
|
1886
|
-
`)}))}
|
|
1884
|
+
`}var Mt="__mistflow_url_choice__",Hn=600*1e3;function $s(){let s=ve(Fe(),".mistflow","confirm-secret");if(bt(s))try{return Buffer.from(Ds(s,"utf-8").trim(),"hex")}catch{}let o=qn(32);return $t(ve(Fe(),".mistflow"),{recursive:!0}),jt(s,o.toString("hex"),{mode:384}),o}function js(s){return Bn("sha256").update(s.trim().toLowerCase()).digest("hex").slice(0,16)}function Gn(s,o){let t={cwd:s,d:js(o),exp:Date.now()+Hn},e=Buffer.from(JSON.stringify(t)).toString("base64url"),n=Ms("sha256",$s()).update(e).digest("base64url");return`${e}.${n}`}function Wn(s,o,t){let e=s.split(".");if(e.length!==2)return!1;let[n,a]=e,r=Ms("sha256",$s()).update(n).digest("base64url"),i=Buffer.from(a),l=Buffer.from(r);if(i.length!==l.length||!zn(i,l))return!1;try{let c=JSON.parse(Buffer.from(n,"base64url").toString("utf-8"));return!(typeof c.exp!="number"||Date.now()>c.exp||c.cwd!==o||c.d!==js(t))}catch{return!1}}function Vn(s){let o=s,t=Fe(),e=!1;for(let n=0;n<64;n++){if(bt(ve(o,"mistflow.json")))return"mistflow";if(!e&&bt(ve(o,"package.json"))&&(e=!0),o===t)break;let a=Un(o);if(a===o)break;o=a}return e?"foreign":"none"}function Yn(s){let o=Fe(),t=s.replace(/\/+$/,"");if(t===o||t==="/"||t===""||t==="/tmp"||t==="/private/tmp")return!0;let e=["Desktop","Documents","Downloads"];for(let n of e)if(t===ve(o,n))return!0;return!1}var Jn=O.object({description:O.string().min(1,"App description or modification request"),projectPath:O.string().min(1).describe("REQUIRED. Absolute path to the user's current working directory \u2014 where the Mistflow app will be scaffolded. Pass the directory the user is actually working in (e.g. /Users/alice/projects). Do NOT pass '/', '~', $HOME, Desktop, Documents, Downloads, or /tmp \u2014 the tool will refuse to scaffold at those locations. If you are unsure of the user's working directory, ask them before calling this tool."),conversationId:O.string().optional().describe("Returned by a previous mist_plan call with status 'clarify'. Pass it back to continue the conversation."),answers:O.record(O.string()).optional().describe("User's answers to the clarifying questions from the previous round. Keys are the questions, values are the answers."),existingPlan:O.record(O.unknown()).optional().describe("If provided, modifies this existing plan instead of creating a new one. Pass the current plan object from mistflow.json."),existingPlanId:O.string().optional().describe("Alternative to existingPlan \u2014 pass the planId from a previous mist_plan call to modify that plan."),templateToken:O.string().optional().describe("Fork from a shared template. Pass the share token (from a mistflow.ai/t/... URL) to clone that project's plan into your workspace."),remixDescription:O.string().optional().describe("Optional remix request when forking a template. Describes how you want the template to be different. E.g. 'Make it for tracking books instead of habits, add a search feature.' Only used with templateToken."),autonomous:O.boolean().optional().describe("Skip clarifying questions and generate the plan immediately"),landingDesign:O.string().optional().describe("ID of a curated landing page design for the hero section. When set, the design's detailed blueprint (colors, fonts, layout, animations) is injected during the landing page implementation step. Use mist_project with action='landing-designs' to browse available landing designs."),appStyle:O.string().optional().describe("ID of a full-app style (e.g. 'stripe', 'linear', 'vercel', 'notion'). When set, the style's color palette, typography, component specs, shadows, and layout rules are injected during ALL implementation steps for consistent brand-quality design across every page. Use mist_project with action='app-styles' to browse available app styles."),language:O.string().optional().describe("UI language for the app. All user-facing text, labels, buttons, and content will be generated in this language. Use the language name in English (e.g. 'Spanish', 'French', 'Arabic', 'Japanese'). Defaults to English if not specified."),brandMentioned:O.boolean().optional().describe("Set to true ONLY when the user's original request explicitly invoked Mistflow by name (e.g. 'build me a CRM using mist', 'make a todo app with mistflow'). Skips the existing-project confirmation gate because the user clearly wants Mistflow. Do NOT set this for generic 'build me X' requests. Do NOT infer this \u2014 only set it when the user literally typed 'mist' or 'mistflow'."),confirmToken:O.string().optional().describe("The token returned in a previous mist_plan response with status 'confirm_new_project'. Only pass this AFTER asking the user via AskUserQuestion and they chose to scaffold a new Mistflow app in an existing-project directory. The token is bound to the projectPath and description \u2014 you must pass the SAME description AND projectPath on the retry."),urlChoice:O.string().optional().describe("The user's answer to the 'Your app URL' question from a previous mist_plan response. Pass JUST the subdomain (e.g. 'nutrition-tracker'), not the full URL or the option label. If the user kept the default suggestion, pass the suggested subdomain verbatim. If they typed a custom URL like 'myapp.mistflow.app', pass just 'myapp'. Pass this as a top-level parameter \u2014 do NOT nest it inside answers. The answers-dict magic key is deprecated and unreliable."),designConversationId:O.string().optional().describe("Returned by a previous mist_plan call with status 'design_clarify'. Pass it back on the follow-up call together with designDirection to finalize the plan's DESIGN.md."),designDirection:O.object({id:O.string().optional(),name:O.string().optional(),summary:O.string().optional(),heroHeadline:O.string().optional(),ctaText:O.string().optional(),bodySample:O.string().optional(),fontsHint:O.string().optional(),fonts:O.object({display:O.string(),body:O.string()}).partial().optional(),colorMood:O.string().optional(),colors:O.object({bg:O.string(),fg:O.string(),accent:O.string()}).partial().optional(),heroTreatment:O.string().optional(),shapeLang:O.string().optional(),texture:O.string().optional(),decorationHint:O.string().optional(),custom:O.string().optional()}).passthrough().optional().describe("The creative direction the user picked from a previous 'design_clarify' response. Pass the FULL direction object the user chose (all fields from the 'directions' array). If the user wrote their own description instead of picking one, pass { custom: '<their description>' } and omit the other fields.")});function Kn(s){let o=[[/payment/i,"Payments"],[/database/i,"Database"],[/auth|sign.?up|login|access/i,"Access"],[/landing.?page/i,"Landing page"],[/who.*using|user|role/i,"Users"],[/design|theme|style/i,"Design"],[/deploy/i,"Deploy"],[/domain/i,"Domain"],[/notification/i,"Notify"],[/email/i,"Email"],[/mobile|responsive/i,"Mobile"],[/integrat/i,"Integration"],[/field|info|propert|detail|contain/i,"Item shape"],[/view|layout|board|grid|list|timeline/i,"View"],[/scope|how many|one.*or.*many|multi/i,"Scope"],[/share|read.?only|viewer|stakeholder/i,"Sharing"],[/workflow|status|state|move|stage|pipeline/i,"Workflow"],[/avoid|bloat|simple|complex|minimal/i,"Constraints"],[/time.*period|quarter|month|sprint/i,"Time periods"],[/swimlane|column|group|categor/i,"Structure"]];for(let[e,n]of o)if(e.test(s))return n;return s.replace(/[?.,!]/g,"").split(/\s+/).filter(e=>!["what","how","do","does","is","are","the","a","an","would","should","you","your","for","this","that","to","of","or","and","want","like","prefer"].includes(e.toLowerCase())).slice(0,2).join(" ").slice(0,12)||"Option"}function Qn(s){let o=ve(Fe(),".mistflow","plans",`${s}.json`);if(!bt(o))return null;try{return JSON.parse(Ds(o,"utf-8")).plan??null}catch{return null}}async function Xn(s){for(let e=0;e<60;e++){try{let n=await Jo(s.design_conversation_id);if(n.status==="ready")return{status:"design_clarify",design_conversation_id:s.design_conversation_id,directions:n.directions,plan:n.plan,methodology:n.methodology};if(n.status==="failed")return{status:"ready",plan:n.plan,methodology:n.methodology}}catch(n){let a=n instanceof Error?n.message:String(n);if(a.toLowerCase().includes("not found"))return{status:"ready",plan:s.plan,methodology:s.methodology};console.error(`[plan] directions poll attempt ${e+1} failed: ${a}`)}await new Promise(n=>setTimeout(n,2e3))}return console.error("[plan] directions poll exhausted, falling back to ready"),{status:"ready",plan:s.plan,methodology:s.methodology}}async function Zn(s,o){let{description:t,projectPath:e,conversationId:n,answers:a,existingPlan:r,existingPlanId:i,templateToken:l,remixDescription:c,autonomous:u,language:m,landingDesign:p,appStyle:g,brandMentioned:b,confirmToken:f,urlChoice:h,designConversationId:w,designDirection:P}=s,I=r;if(!I&&i&&(I=Qn(i)??void 0,!I))return d("Your previous plan is no longer available. Please describe your app again to generate a new plan.",!0);let x=n;if(!be())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let E;if(!x&&!I&&!l){if(!Fn(e))return d(`projectPath must be an absolute path \u2014 received '${e}'. Pass the full absolute path to the user's project directory (e.g. /Users/alice/projects/my-app).`,!0);let v=Vn(e);if(v!=="mistflow"&&Yn(e))return d(JSON.stringify({status:"unsafe_cwd",projectPath:e,instruction:[`The projectPath you passed (${e}) is a system-level directory (home root, Desktop, Documents, Downloads, or /tmp).`,"Scaffolding here would drop node_modules and a git repo directly at that location, which is messy and hard to clean up.","MANDATORY: Before calling mist_plan again:"," 1. Pick a subfolder name based on the app description (e.g. 'nutrition-tracker', 'habit-app').",` 2. Create the subfolder at ${e}/<subfolder-name>.`," 3. Call mist_plan again with the SAME description and projectPath set to the new subfolder.","Do NOT ask the user where to put the project \u2014 just pick a sensible subfolder name from their description."].join(`
|
|
1885
|
+
`)}),!0);if(v==="foreign"&&!b){if(!(f?Wn(f,e,t):!1)){let $=Gn(e,t);return d(JSON.stringify({status:"confirm_new_project",projectPath:e,description:t,confirmToken:$,askUserQuestion:{question:"You're inside an existing project directory. Do you want to scaffold a new Mistflow app here, or edit the existing codebase directly?",header:"Scope",options:[{label:"Scaffold a new Mistflow app in a subdirectory",description:"Creates a fresh project in this folder without touching the existing code."},{label:"Edit this existing codebase directly",description:"Cancel Mistflow. Handle the request by editing the current project's files."}],multiSelect:!1},instruction:["The user is inside an existing project (package.json found up the directory tree, no mistflow.json) and did NOT explicitly invoke Mistflow by name.","MANDATORY: Use the AskUserQuestion tool with the provided askUserQuestion to confirm their intent before calling mist_plan again.","If they pick 'Scaffold a new Mistflow app in a subdirectory', call mist_plan again with the SAME description and confirmToken set to the token returned above.","If they pick 'Edit this existing codebase directly', DO NOT call mist_plan again. Fulfill their request by editing files directly in the current project.",f?"The previous confirmToken was invalid, expired, or did not match the current directory/description. Use the fresh token above.":""].filter(Boolean).join(`
|
|
1886
|
+
`)}))}E="Note: You're inside an existing project. Mistflow will create the new app in a subdirectory. It won't modify this codebase."}else v==="foreign"&&b&&(E="Note: You're inside an existing project. Mistflow will create the new app in a subdirectory. It won't modify this codebase.")}if(l)try{if(!(await ms(l)).plan)return d("This template has no plan to fork. Try a different template.",!0);let T=await hs(l),$=T.plan,j="";if(c&&T.has_source)try{let ye=await ao(T.plan,c),Q=ye.plan??ye,Rt=ye.diff,ae=Q?.steps??[],no=new Set([...(Rt?.added??[]).map(Ie=>Ie.number),...(Rt?.modified??[]).map(Ie=>Ie.number)]),je=ae.map(Ie=>{let yn=Ie.number;return no.has(yn)?{...Ie,status:"pending"}:{...Ie,status:"completed",source:"forked"}});Q.steps=je,$=Q;let Ve=je.filter(Ie=>Ie.status==="pending").length;j=` Remixed: ${je.filter(Ie=>Ie.status==="completed").length} steps unchanged, ${Ve} steps need re-implementation.`}catch(ye){console.error("[plan] Remix failed, using original plan:",ye),j=" (Remix failed \u2014 using original plan. You can modify it later.)"}let de=_s(),ie=ve(Fe(),".mistflow","plans");$t(ie,{recursive:!0}),jt(ve(ie,`${de}.json`),JSON.stringify({plan:$,projectId:T.id,sourceDeploymentId:T.source_deployment_id,forkToken:T.fork_token,requiredEnvVars:T.required_env_vars,dbProvider:T.db_provider}));let he=$?.name??"forked-app",fe=T.has_source,ht=fe?"Source code will be restored during init. Run init promptly \u2014 the download token expires in 1 hour.":"",We=T.deploy_url?` Instant deploy started \u2014 your app will be live at ${T.deploy_url} in under a minute.`:"";return d(JSON.stringify({planId:de,forkedFrom:T.forked_from,projectId:T.id,hasSource:fe,deployUrl:T.deploy_url,message:`Forked "${T.forked_from}" into your workspace.${j}${We} ${ht} NEXT: Call mist_build with action='init', name='${he}', and planId='${de}' to create the project now.`}))}catch(v){let T=v instanceof Error?v.message:"Failed to fork template";return d(T,!0)}if(I){let v;try{v=await ao(I,t)}catch(ie){let he=ie instanceof Error?ie.message:"Failed to modify plan";return d(he,!0)}let T=v.plan,$=v.diff,j=[];if($?.added?.length){let ie=$.added.map(he=>he.title);j.push(`Added ${ie.length} step(s): ${ie.join(", ")}`)}if($?.removed?.length){let ie=$.removed.map(he=>he.title);j.push(`Removed ${ie.length} step(s): ${ie.join(", ")}`)}if($?.modified?.length){let ie=$.modified.map(he=>he.title);j.push(`Modified ${ie.length} step(s): ${ie.join(", ")}`)}let de=j.length>0?j.join(". "):"No changes detected.";return d(JSON.stringify({plan:T,diff:$,message:`Plan modified. ${de}. Update mistflow.json with the new plan, then continue with mist_build (action: 'implement').`}))}let L=h?.trim()||void 0,C=a;if(!L&&a&&Mt in a&&(L=a[Mt]),a&&Mt in a){let{[Mt]:v,...T}=a;C=Object.keys(T).length>0?T:void 0}if(L&&(L=L.replace(/^Keep\s+/i,"").replace(/\s*\(Recommended\)\s*$/i,"").replace(/\.mistflow\.app.*$/i,"").trim()||void 0),L){let v=L.toLowerCase().replace(/\s+/g,"-");/^[a-z0-9][a-z0-9-]{1,30}[a-z0-9]$/.test(v)?L=v:(console.error(`[mist_plan] Discarding urlChoice '${L}' \u2014 does not look like a subdomain. Backend will auto-generate.`),L=void 0)}let q;if(P){q={...P};let v={fontsHint:"fonts_hint",colorMood:"color_mood",heroHeadline:"hero_headline",ctaText:"cta_text",bodySample:"body_sample",heroTreatment:"hero_treatment",shapeLang:"shape_lang",decorationHint:"decoration_hint"};for(let[T,$]of Object.entries(v))P[T]!==void 0&&q[$]===void 0&&(q[$]=P[T])}let W=a?"Generating plan with your answers (LLM call)":w?"Finalizing design direction":"Thinking through discovery questions",H=o?Ke(o.server,o.progressToken,()=>W):{stop:()=>{}};o&&(o.cleanup=()=>H.stop());let z;try{z=await Ko(t,{conversationId:x,answers:C,autonomous:u,language:m,designConversationId:w,designDirection:q})}catch(v){H.stop();let T=v instanceof Error?v.message:"Failed to generate plan";return d(T,!0)}if(z.status==="design_clarify_pending"&&(W="Generating creative design directions",z=await Xn(z)),H.stop(),z.status==="clarify"){let v=z.reflection||"",T=z.suggestedName||"",$=z.suggestedFeatures??[],j=z.questions??[],de=j.some(ae=>Array.isArray(ae.options)&&typeof ae.options[0]=="object"&&ae.options[0]?.label),ie={primaryActor:"Users",primaryAction:"Core action",surfaceType:"App type",audienceType:"Audience",multiRole:"Roles",publicLanding:"Landing page",realMoney:"Payments",scheduling:"Scheduling",authModel:"Access",dbProvider:"Database",integrations:"Integration",entityShape:"Item shape",coreView:"View",scope:"Scope",sharing:"Sharing",workflow:"Workflow",constraints:"Constraints",domain:"Product"},he=j.map(ae=>{let no=ae.decisionKey&&ie[ae.decisionKey]||Kn(ae.question),je;return de&&Array.isArray(ae.options)?je=ae.options.map(Ve=>({label:Ve.label,description:Ve.description??""})):Array.isArray(ae.options)?je=ae.options.map((Ve,Oo)=>({label:Oo===0?`${Ve} (Recommended)`:String(Ve),description:ae.why??""})):je=[{label:"Yes (Recommended)",description:ae.why??""},{label:"No",description:""}],{question:ae.question,header:no,options:je,multiSelect:!1}}),ht=z.decisions?.audienceType??null,We=$.length>0?Is(t,{primaryActor:null,primaryAction:null,surfaceType:null,audienceType:ht,multiRole:null,publicLanding:null,realMoney:null,scheduling:null,authModel:null,dbProvider:null,integrations:null},{suggestedName:T,suggestedFeatures:$,language:m}):null,ye=We?Rs(We):"",Q=yo(T||"my-app").slice(0,32);try{let ae=await Wo(Q);!ae.available&&ae.suggestion&&(Q=ae.suggestion)}catch{}ye&&(ye+=`
|
|
1887
1887
|
|
|
1888
|
-
**Your app URL:** https://${Q}.mistflow.app`);let Rt={question:`Your app will be at ${Q}.mistflow.app \u2014 want to customize the URL?`,header:"URL",options:[{label:`Keep ${Q}.mistflow.app (Recommended)`,description:"This URL is available"},{label:"Choose a different URL",description:"Type your preferred subdomain"}],multiSelect:!1};return he.push(Rt),d(JSON.stringify({status:"clarify",conversation_id:z.conversation_id,questions:j,questionCount:j.length,suggestedFeatures:$,suggestedName:T,suggestedSubdomain:Q,reflection:v,briefText:ye,askUserQuestions:he,planTimingHint:"After the user answers all questions, generating the actual plan takes about 60-90 seconds (backend LLM). Narrate this explicitly before the next mist_plan call.",instruction:[...
|
|
1888
|
+
**Your app URL:** https://${Q}.mistflow.app`);let Rt={question:`Your app will be at ${Q}.mistflow.app \u2014 want to customize the URL?`,header:"URL",options:[{label:`Keep ${Q}.mistflow.app (Recommended)`,description:"This URL is available"},{label:"Choose a different URL",description:"Type your preferred subdomain"}],multiSelect:!1};return he.push(Rt),d(JSON.stringify({status:"clarify",conversation_id:z.conversation_id,questions:j,questionCount:j.length,suggestedFeatures:$,suggestedName:T,suggestedSubdomain:Q,reflection:v,briefText:ye,askUserQuestions:he,planTimingHint:"After the user answers all questions, generating the actual plan takes about 60-90 seconds (backend LLM). Narrate this explicitly before the next mist_plan call.",instruction:[...E?[E,""]:[],v?`${v}
|
|
1889
1889
|
`:"",ye?`Here's what I'd build:
|
|
1890
1890
|
|
|
1891
1891
|
${ye}
|
|
1892
1892
|
`:"",`I have ${j.length} quick question${j.length===1?"":"s"} to pin down the details.`,"","MANDATORY: Use the AskUserQuestion tool to present these questions. Do NOT present them as text.","","IF you have access to the AskUserQuestion tool (Claude Code):"," Use it to present questions with selectable options. Pass the 'askUserQuestions' array directly.","","OTHERWISE (Cursor, Codex, or other hosts):"," Present each question conversationally with the options listed.","","BEFORE calling mist_plan for the final plan generation, tell the user:"," 'Generating your plan now. This usually takes about 60\u201390 seconds \u2014 I'm designing the data model, laying out pages, and writing build steps.'","This primes the user for the silent wait. Do NOT call mist_plan without saying this first.","","Once you have all answers, call mist_plan again with:",` conversationId: "${z.conversation_id}"`,' answers: { "<question text>": "<user answer>", ... }'," description: (same description as before)",' urlChoice: "<the URL subdomain the user picked>" \u2190 pass as a top-level param, NOT inside answers',"","NOTE: You may receive another 'clarify' response with follow-up questions if the user's answers","revealed new ambiguity. This is normal \u2014 relay those questions too. Keep going until you get 'ready'.","","IMPORTANT: For the URL question, pass the answer as the top-level 'urlChoice' parameter (not inside answers).",`If the user keeps the default, set urlChoice: "${Q}".`,'If they type a custom URL, set urlChoice to just the subdomain part (e.g. "myapp" for "myapp.mistflow.app"). Do not include ".mistflow.app" or any "Keep X" label text \u2014 the tool strips those but passing just the subdomain is cleanest.'].join(`
|
|
1893
|
-
`)}))}if(z.status==="design_clarify"){let v=z.directions??[],T=z.plan.name??"your app",$;try{let fe=v.map(Q=>({id:Q.id,name:Q.name,summary:Q.summary,hero_headline:Q.hero_headline,cta_text:Q.cta_text,body_sample:Q.body_sample,fonts:Q.fonts,colors:Q.colors,hero_treatment:Q.hero_treatment,shape_lang:Q.shape_lang,texture:Q.texture,decoration_hint:Q.decoration_hint})),ht=
|
|
1894
|
-
`)}))}let _=z.plan,ee=_.name??"Untitled App",Y=z.methodology,B=_.steps;if(!Array.isArray(B)||B.length===0)return d("Plan generation incomplete \u2014 the plan is missing implementation steps. Please call mist_plan again with the same description to retry.",!0);let E=_.publicPages;if(!E||Array.isArray(E)&&E.length===0){let v=_.pages,T=B.some(j=>typeof j.name=="string"&&j.name.toLowerCase().includes("landing")||typeof j.title=="string"&&j.title.toLowerCase().includes("landing")),$=Array.isArray(v)&&v.some(j=>j.path==="/"||j.route==="/");T||$?E=["/","/pricing"]:E=["/"]}let le=_.primaryAction;if(!le){let v=_.features;if(Array.isArray(v)&&v.length>0){let $=v.find(de=>typeof de.priority=="string"&&de.priority.toLowerCase()==="must-have")??v[0];le={entity:$.name??$.title??"item",action:"create",fromPage:"/dashboard"}}}let ce=_.nonNegotiables;(!ce||Array.isArray(ce)&&ce.length===0)&&(ce=["Landing page renders correctly at / with content (not a redirect)","Core user action works end-to-end (create entity, see it in list)"]);let me=_s(),re=ve(Fe(),".mistflow","plans");$t(re,{recursive:!0});try{let T=Date.now();for(let $ of[re,ve(Fe(),".mistflow","mockup-state")])if(bt($))for(let j of jn($))try{let de=ve($,j),ie=Ln(de).mtimeMs;T-ie>6048e5&&On(de)}catch{}}catch{}let k;if(p){let v=ot(p);v?k=v.id:console.error(`Landing design '${p}' not found \u2014 ignoring. Use mist_project action='landing-designs' to browse available landing designs.`)}let M=g||void 0,U=!!k,y=B.some(v=>{let T=`${v.name??v.title} ${v.description??""}`.toLowerCase();return T.includes("landing")||T.includes("hero")||T.includes("marketing")||T.includes("homepage")}),R=!U&&y?Ps(e,{maxResults:2}):[];R.length>0&&(k=R[0].id,console.error(`Auto-assigned landing layout preset (default): ${R[0].title} (${k})`));let te={name:_.name,summary:_.summary,dataModel:_.dataModel,pages:_.pages,features:_.features,steps:B.map(v=>({...v,name:v.name??v.title})),design:_.design,landingDesign:k,appStyle:M,dbProvider:_.dbProvider??"neon",authModel:_.authModel,audienceType:_.audienceType??"b2c",roles:_.roles,defaultRole:_.defaultRole,publicPages:E,navStyle:_.navStyle,multiTenant:_.multiTenant,primaryAction:le,nonNegotiables:ce,requestedSubdomain:L,...m&&m.toLowerCase()!=="english"?{language:m}:{}};jt(ve(re,`${me}.json`),JSON.stringify({plan:te,methodology:Y}));let Pe=B.map(v=>`${v.number}. ${v.name??v.title}`),ge="",S=[],D;!U&&R.length>0&&(S=R.map(T=>({id:T.id,slug:T.slug,title:T.title,description:T.description,url:`${ft()}/designs?tab=landing-designs`})),D={question:"What landing page style fits this app?",header:"Landing Design",options:[...R.map((T,$)=>({label:$===0?`${T.title} (Recommended)`:T.title,description:T.description})),{label:"Design from scratch (Creative)",description:"No template \u2014 the AI designs a bespoke hero from your app's concept using 3D, scroll-driven animation, or particle effects. Higher creative ceiling, takes ~10 min longer, occasionally needs a second pass."},{label:"Browse all landing designs",description:`Not sure? See all landing designs at ${ft()}/designs?tab=landing-designs and pass the ID back.`}],multiSelect:!1},ge=` REQUIRED: ask the user which landing design they want using the AskUserQuestion tool with the 'landingDesignQuestion' object before calling mist_build init. Do NOT assume the recommended option \u2014 the user may want a different style than we inferred. Recommended: ${R.map(T=>T.title).join(" or ")}. If they pick "Design from scratch", pass landingDesign='freeform' to mist_build init. If they pick a specific preset title, look up its ID via mist_project action='landing-designs' and pass that. If they pick the recommended option, pass landingDesign='${R[0].id}' explicitly.`);let G="",J=[],oe=void 0,C=(_.audienceType??"b2c")==="b2c",K={question:"Include a lifestyle photo in your landing page hero? Photos add warmth and human context; pure CSS stays cleaner.",header:"Hero",options:[{label:C?"Yes, add a photo (Recommended)":"Yes, add a photo",description:"Lifestyle photography background with your product preview overlaid \u2014 feels warm and human (like HabitFlow, Airbnb)."},{label:C?"No, CSS only":"No, CSS only (Recommended)",description:"Animated gradients + glassmorphism, no photo \u2014 cleaner and more technical (like Stripe, Linear, Vercel)."}],multiSelect:!1},ne=" Also ask the user about the 'heroPhotoQuestion' provided. Once they pick, pass heroPhoto=true (photo) or heroPhoto=false (CSS only) to the mist_build init call.",X="",Ce=[];for(let v of B){let T=v.name??v.title,$=v.integrationId;if($){let j=rt($);if(j){let de=nt(j.id);Ce.push({step:T,presetId:j.id,presetName:j.name,envVars:de?.envVars??[]})}}}if(Ce.length>0){let v=Ce.flatMap(j=>j.envVars),T=[...new Set(v.map(j=>j.key))];X=` This plan uses integrations (${Ce.map(j=>j.presetName).join(", ")}). Detailed blueprints will be auto-injected during each integration step.${T.length>0?` The user will need these API keys: ${T.join(", ")}.`:""}`}return d(JSON.stringify({planId:me,name:_.name,summary:_.summary,stepCount:B.length,steps:Pe,design:_.design,...k?{landingDesign:k}:{},...M?{appStyle:M}:{},...J.length>0?{recommendedAppStyles:J}:{},...oe?{appStyleQuestion:oe}:{},...S.length>0?{recommendedLandingDesigns:S}:{},...D?{landingDesignQuestion:D}:{},heroPhotoQuestion:K,...Ce.length>0?{integrations:Ce.map(v=>({step:v.step,preset:v.presetId,name:v.presetName,envVars:v.envVars}))}:{},message:`Plan generated for "${ee}" (${B.length} steps).${k?` Landing layout "${k}" set as default.`:""}${M?` App style "${M}" will be applied across all pages.`:""}${X}${G}${ge}${ne}`,timingContext:`Planning took ~90 seconds. Building will take roughly ${Math.max(15,B.length*3)}\u2013${B.length*5} minutes total across ${B.length} steps (varies by complexity). Mention this to the user before starting the build so they know what to expect.`,mockupPrompt:`Before building, ask the user: "Would you like to preview a mockup of your app before we start building? You can iterate on the design, or skip straight to building." If the user wants a mockup, call mist_build with action='mockup' and planId='${me}'. If the user says skip or "just build it", call mist_build with action='init', name='${ee}', and planId='${me}' immediately.`,...N?{warning:N}:{}}))}var Ls={name:"mist_plan",description:["ENTRY POINT for creating a NEW web app, website, internal tool, dashboard, landing page, marketplace, content site, or browser game. Mistflow scaffolds a complete Next.js project. It does NOT edit existing codebases.","","WHEN TO CALL THIS \u2014 route here automatically on natural 'build me X' intent. The user does NOT need to say 'mist' or 'mistflow'. Examples that MUST route here:","\u2022 'build me a habit tracker'","\u2022 'make a site for my bakery'","\u2022 'I want an app where users log workouts'","\u2022 'create a dashboard that shows sales'","\u2022 'build a Wordle clone'","\u2022 'build me a CRM using mist' / 'make a todo app with mistflow' (explicit brand invocation)","","PASSING THE DESCRIPTION: Pass the user's words EXACTLY. Do NOT expand, elaborate, add features, rewrite, or strip anything (including 'using mist' / 'with mistflow'). 'build me a habit tracker using mist' becomes description: 'build me a habit tracker using mist'. The description is preserved verbatim.","","BRAND MENTIONED FLAG: If the user's original request literally contained the word 'mist' or 'mistflow' as an explicit invocation (e.g. 'build me a CRM using mist', 'use mistflow to make a todo app'), set brandMentioned: true. If the user did NOT mention the brand by name, omit brandMentioned (do not set it). Only set brandMentioned when the user literally typed the brand name \u2014 never infer it. Do NOT set brandMentioned for the common English noun 'mist' used in other contexts (e.g. 'app about morning mist').","","SAFETY GATE \u2014 the handler walks up the directory tree to detect if you're inside an existing non-Mistflow codebase (package.json found anywhere up the tree, no mistflow.json). When that happens AND brandMentioned is not set, the handler returns status 'confirm_new_project' with a signed confirmToken and an askUserQuestion. On that response:","\u2022 MANDATORY: use the AskUserQuestion tool with the provided askUserQuestion to ask the user.","\u2022 If the user picks 'Scaffold a new Mistflow app in a subdirectory', call mist_plan again with the SAME description and confirmToken set to the token from the response.","\u2022 If the user picks 'Edit this existing codebase directly', DO NOT call mist_plan again. Fulfill their request by editing files directly.","\u2022 The confirmToken is bound to the projectPath and description. If either changes, you'll get a fresh token and must ask again.","\u2022 You do not need to pre-check the directory yourself. The handler handles detection.","","FOLLOW-UP FLOW (after the plan is being generated):","\u2022 status 'clarify' \u2192 use AskUserQuestion with the provided askUserQuestions, then call mist_plan again with conversationId + answers + the same description.","\u2022 You may receive MULTIPLE 'clarify' rounds \u2014 if the user's answers reveal new ambiguity, the planner will ask follow-up questions. Keep relaying questions until you get status 'ready'. This is normal and produces better plans.","\u2022 status 'ready' \u2192 IMMEDIATELY call mist_build (action: 'init') with the returned planId. Do not ask permission.","\u2022 NEVER skip the clarifying questions. The discovery process ensures the right thing gets built.","","EXISTING MISTFLOW PROJECTS (mistflow.json present anywhere up the tree): call this for changes that need a new data model, third-party integration, or multi-step structural change (pass existingPlan or existingPlanId). For simpler features (new pages, UI additions), do NOT call mist_plan, but DO ask the user product questions before building (what fields, what layout, what constraints). Get the spec right, build once. For cosmetic changes and bug fixes, skip questions and edit directly. Use mist_project action='get' for context.","","OTHER MODES: Pass templateToken to fork from a mistflow.ai/t/... shared template. Pass appStyle (53 full-app design systems like 'stripe', 'linear') to apply a design system. Browse via mist_project action='app-styles'. Landing layout presets are auto-assigned based on app description."].join(`
|
|
1895
|
-
`),inputSchema:Jn,handler:Zn};import{z as pe}from"zod";import{existsSync as Gt,readFileSync as ya}from"fs";import{join as Wt,resolve as ba}from"path";import{homedir as wa}from"os";import{execFileSync as Io}from"child_process";import{z as Lt}from"zod";import{existsSync as
|
|
1893
|
+
`)}))}if(z.status==="design_clarify"){let v=z.directions??[],T=z.plan.name??"your app",$;try{let fe=v.map(Q=>({id:Q.id,name:Q.name,summary:Q.summary,hero_headline:Q.hero_headline,cta_text:Q.cta_text,body_sample:Q.body_sample,fonts:Q.fonts,colors:Q.colors,hero_treatment:Q.hero_treatment,shape_lang:Q.shape_lang,texture:Q.texture,decoration_hint:Q.decoration_hint})),ht=Ns(T,fe),We=ve(e,".mistflow");$t(We,{recursive:!0});let ye=ve(We,"design-directions.html");jt(ye,ht,"utf-8"),$=ye}catch(fe){console.error(`[mist_plan] design-directions preview render failed: ${fe instanceof Error?fe.message:String(fe)}`)}let j=v.map(fe=>({label:fe.name,description:`${fe.summary} \u2014 ${fe.fonts?.display??""} + ${fe.fonts?.body??""}`}));j.push({label:"Describe your own direction",description:"Skip the proposed options and give me a short description of how the app should feel."});let de={question:`${T} is planned. Now pick the creative direction \u2014 this shapes fonts, colors, and overall feel.`,header:"Design",options:j,multiSelect:!1},ie=$?`A visual preview of all ${v.length} directions has been written to ${$}. Open it in the browser \u2014 each card is rendered in its direction's own fonts + palette so the user can see what they're picking.`:"No visual preview rendered (see server logs). The AskUserQuestion options below carry fonts + mood so the user can still pick.",he=$?`open "${$}"`:"";return d(JSON.stringify({status:"design_clarify",designConversationId:z.design_conversation_id,directions:v,previewPath:$,askUserQuestion:de,instruction:[`The plan for "${T}" is ready. I've proposed ${v.length} creative directions \u2014 each commits to a specific aesthetic (fonts, colors, voice).`,"",ie,he?`Run this command for the user: ${he}`:"","","MANDATORY: After opening the preview, use the AskUserQuestion tool to present the directionQuestion above. Do NOT present it as text.","","Once the user picks a direction, call mist_plan again with:"," description: (same description as before)",` designConversationId: "${z.design_conversation_id}"`," designDirection: <the full direction object from the 'directions' array that the user picked>","","IF the user picks 'Describe your own direction':"," Ask them a short open question ('How should the app feel? Any fonts or colors in mind?')."," Then call mist_plan with designDirection: { custom: '<their description>' } and the same designConversationId.","","The next mist_plan call takes ~10-20s \u2014 that's the LLM generating the final DESIGN.md with the picked direction. Tell the user 'Locking in the direction now \u2014 this takes about 15 seconds.' before calling."].filter(Boolean).join(`
|
|
1894
|
+
`)}))}let _=z.plan,ee=_.name??"Untitled App",Y=z.methodology,B=_.steps;if(!Array.isArray(B)||B.length===0)return d("Plan generation incomplete \u2014 the plan is missing implementation steps. Please call mist_plan again with the same description to retry.",!0);let N=_.publicPages;if(!N||Array.isArray(N)&&N.length===0){let v=_.pages,T=B.some(j=>typeof j.name=="string"&&j.name.toLowerCase().includes("landing")||typeof j.title=="string"&&j.title.toLowerCase().includes("landing")),$=Array.isArray(v)&&v.some(j=>j.path==="/"||j.route==="/");T||$?N=["/","/pricing"]:N=["/"]}let le=_.primaryAction;if(!le){let v=_.features;if(Array.isArray(v)&&v.length>0){let $=v.find(de=>typeof de.priority=="string"&&de.priority.toLowerCase()==="must-have")??v[0];le={entity:$.name??$.title??"item",action:"create",fromPage:"/dashboard"}}}let ce=_.nonNegotiables;(!ce||Array.isArray(ce)&&ce.length===0)&&(ce=["Landing page renders correctly at / with content (not a redirect)","Core user action works end-to-end (create entity, see it in list)"]);let me=_s(),re=ve(Fe(),".mistflow","plans");$t(re,{recursive:!0});try{let T=Date.now();for(let $ of[re,ve(Fe(),".mistflow","mockup-state")])if(bt($))for(let j of jn($))try{let de=ve($,j),ie=Ln(de).mtimeMs;T-ie>6048e5&&On(de)}catch{}}catch{}let k;if(p){let v=ot(p);v?k=v.id:console.error(`Landing design '${p}' not found \u2014 ignoring. Use mist_project action='landing-designs' to browse available landing designs.`)}let M=g||void 0,U=!!k,y=B.some(v=>{let T=`${v.name??v.title} ${v.description??""}`.toLowerCase();return T.includes("landing")||T.includes("hero")||T.includes("marketing")||T.includes("homepage")}),R=!U&&y?Ps(t,{maxResults:2}):[];R.length>0&&(k=R[0].id,console.error(`Auto-assigned landing layout preset (default): ${R[0].title} (${k})`));let te={name:_.name,summary:_.summary,dataModel:_.dataModel,pages:_.pages,features:_.features,steps:B.map(v=>({...v,name:v.name??v.title})),design:_.design,landingDesign:k,appStyle:M,dbProvider:_.dbProvider??"neon",authModel:_.authModel,audienceType:_.audienceType??"b2c",roles:_.roles,defaultRole:_.defaultRole,publicPages:N,navStyle:_.navStyle,multiTenant:_.multiTenant,primaryAction:le,nonNegotiables:ce,requestedSubdomain:L,...m&&m.toLowerCase()!=="english"?{language:m}:{}};jt(ve(re,`${me}.json`),JSON.stringify({plan:te,methodology:Y}));let Pe=B.map(v=>`${v.number}. ${v.name??v.title}`),ge="",S=[],D;!U&&R.length>0&&(S=R.map(T=>({id:T.id,slug:T.slug,title:T.title,description:T.description,url:`${ft()}/designs?tab=landing-designs`})),D={question:"What landing page style fits this app?",header:"Landing Design",options:[...R.map((T,$)=>({label:$===0?`${T.title} (Recommended)`:T.title,description:T.description})),{label:"Design from scratch (Creative)",description:"No template \u2014 the AI designs a bespoke hero from your app's concept using 3D, scroll-driven animation, or particle effects. Higher creative ceiling, takes ~10 min longer, occasionally needs a second pass."},{label:"Browse all landing designs",description:`Not sure? See all landing designs at ${ft()}/designs?tab=landing-designs and pass the ID back.`}],multiSelect:!1},ge=` REQUIRED: ask the user which landing design they want using the AskUserQuestion tool with the 'landingDesignQuestion' object before calling mist_build init. Do NOT assume the recommended option \u2014 the user may want a different style than we inferred. Recommended: ${R.map(T=>T.title).join(" or ")}. If they pick "Design from scratch", pass landingDesign='freeform' to mist_build init. If they pick a specific preset title, look up its ID via mist_project action='landing-designs' and pass that. If they pick the recommended option, pass landingDesign='${R[0].id}' explicitly.`);let G="",J=[],oe=void 0,A=(_.audienceType??"b2c")==="b2c",K={question:"Include a lifestyle photo in your landing page hero? Photos add warmth and human context; pure CSS stays cleaner.",header:"Hero",options:[{label:A?"Yes, add a photo (Recommended)":"Yes, add a photo",description:"Lifestyle photography background with your product preview overlaid \u2014 feels warm and human (like HabitFlow, Airbnb)."},{label:A?"No, CSS only":"No, CSS only (Recommended)",description:"Animated gradients + glassmorphism, no photo \u2014 cleaner and more technical (like Stripe, Linear, Vercel)."}],multiSelect:!1},ne=" Also ask the user about the 'heroPhotoQuestion' provided. Once they pick, pass heroPhoto=true (photo) or heroPhoto=false (CSS only) to the mist_build init call.",X="",Ae=[];for(let v of B){let T=v.name??v.title,$=v.integrationId;if($){let j=rt($);if(j){let de=nt(j.id);Ae.push({step:T,presetId:j.id,presetName:j.name,envVars:de?.envVars??[]})}}}if(Ae.length>0){let v=Ae.flatMap(j=>j.envVars),T=[...new Set(v.map(j=>j.key))];X=` This plan uses integrations (${Ae.map(j=>j.presetName).join(", ")}). Detailed blueprints will be auto-injected during each integration step.${T.length>0?` The user will need these API keys: ${T.join(", ")}.`:""}`}return d(JSON.stringify({planId:me,name:_.name,summary:_.summary,stepCount:B.length,steps:Pe,design:_.design,...k?{landingDesign:k}:{},...M?{appStyle:M}:{},...J.length>0?{recommendedAppStyles:J}:{},...oe?{appStyleQuestion:oe}:{},...S.length>0?{recommendedLandingDesigns:S}:{},...D?{landingDesignQuestion:D}:{},heroPhotoQuestion:K,...Ae.length>0?{integrations:Ae.map(v=>({step:v.step,preset:v.presetId,name:v.presetName,envVars:v.envVars}))}:{},message:`Plan generated for "${ee}" (${B.length} steps).${k?` Landing layout "${k}" set as default.`:""}${M?` App style "${M}" will be applied across all pages.`:""}${X}${G}${ge}${ne}`,timingContext:`Planning took ~90 seconds. Building will take roughly ${Math.max(15,B.length*3)}\u2013${B.length*5} minutes total across ${B.length} steps (varies by complexity). Mention this to the user before starting the build so they know what to expect.`,mockupPrompt:`Before building, ask the user: "Would you like to preview a mockup of your app before we start building? You can iterate on the design, or skip straight to building." If the user wants a mockup, call mist_build with action='mockup' and planId='${me}'. If the user says skip or "just build it", call mist_build with action='init', name='${ee}', and planId='${me}' immediately.`,...E?{warning:E}:{}}))}var Ls={name:"mist_plan",description:["ENTRY POINT for creating a NEW web app, website, internal tool, dashboard, landing page, marketplace, content site, or browser game. Mistflow scaffolds a complete Next.js project. It does NOT edit existing codebases.","","WHEN TO CALL THIS \u2014 route here automatically on natural 'build me X' intent. The user does NOT need to say 'mist' or 'mistflow'. Examples that MUST route here:","\u2022 'build me a habit tracker'","\u2022 'make a site for my bakery'","\u2022 'I want an app where users log workouts'","\u2022 'create a dashboard that shows sales'","\u2022 'build a Wordle clone'","\u2022 'build me a CRM using mist' / 'make a todo app with mistflow' (explicit brand invocation)","","PASSING THE DESCRIPTION: Pass the user's words EXACTLY. Do NOT expand, elaborate, add features, rewrite, or strip anything (including 'using mist' / 'with mistflow'). 'build me a habit tracker using mist' becomes description: 'build me a habit tracker using mist'. The description is preserved verbatim.","","BRAND MENTIONED FLAG: If the user's original request literally contained the word 'mist' or 'mistflow' as an explicit invocation (e.g. 'build me a CRM using mist', 'use mistflow to make a todo app'), set brandMentioned: true. If the user did NOT mention the brand by name, omit brandMentioned (do not set it). Only set brandMentioned when the user literally typed the brand name \u2014 never infer it. Do NOT set brandMentioned for the common English noun 'mist' used in other contexts (e.g. 'app about morning mist').","","SAFETY GATE \u2014 the handler walks up the directory tree to detect if you're inside an existing non-Mistflow codebase (package.json found anywhere up the tree, no mistflow.json). When that happens AND brandMentioned is not set, the handler returns status 'confirm_new_project' with a signed confirmToken and an askUserQuestion. On that response:","\u2022 MANDATORY: use the AskUserQuestion tool with the provided askUserQuestion to ask the user.","\u2022 If the user picks 'Scaffold a new Mistflow app in a subdirectory', call mist_plan again with the SAME description and confirmToken set to the token from the response.","\u2022 If the user picks 'Edit this existing codebase directly', DO NOT call mist_plan again. Fulfill their request by editing files directly.","\u2022 The confirmToken is bound to the projectPath and description. If either changes, you'll get a fresh token and must ask again.","\u2022 You do not need to pre-check the directory yourself. The handler handles detection.","","FOLLOW-UP FLOW (after the plan is being generated):","\u2022 status 'clarify' \u2192 use AskUserQuestion with the provided askUserQuestions, then call mist_plan again with conversationId + answers + the same description.","\u2022 You may receive MULTIPLE 'clarify' rounds \u2014 if the user's answers reveal new ambiguity, the planner will ask follow-up questions. Keep relaying questions until you get status 'ready'. This is normal and produces better plans.","\u2022 status 'ready' \u2192 IMMEDIATELY call mist_build (action: 'init') with the returned planId. Do not ask permission.","\u2022 NEVER skip the clarifying questions. The discovery process ensures the right thing gets built.","","EXISTING MISTFLOW PROJECTS (mistflow.json present anywhere up the tree): call this for changes that need a new data model, third-party integration, or multi-step structural change (pass existingPlan or existingPlanId). For simpler features (new pages, UI additions), do NOT call mist_plan, but DO ask the user product questions before building (what fields, what layout, what constraints). Get the spec right, build once. For cosmetic changes and bug fixes, skip questions and edit directly. Use mist_project action='get' for context.","","OTHER MODES: Pass templateToken to fork from a mistflow.ai/t/... shared template. Pass appStyle (53 full-app design systems like 'stripe', 'linear') to apply a design system. Browse via mist_project action='app-styles'. Landing layout presets are auto-assigned based on app description."].join(`
|
|
1895
|
+
`),inputSchema:Jn,handler:Zn};import{z as pe}from"zod";import{existsSync as Gt,readFileSync as ya}from"fs";import{join as Wt,resolve as ba}from"path";import{homedir as wa}from"os";import{execFileSync as Io}from"child_process";import{z as Lt}from"zod";import{existsSync as Ne,mkdirSync as Ut,writeFileSync as Be,readFileSync as Ft,readdirSync as ei,copyFileSync as ti}from"fs";import{join as Z,resolve as Bt,dirname as wt,isAbsolute as vo}from"path";import{spawn as oi}from"child_process";import{randomBytes as si}from"crypto";import{simpleGit as Fs}from"simple-git";function ri(s){let o=wt(Bt(s)),t=10,e=0;for(;e<t&&o!==wt(o);){if(Ne(Z(o,"pnpm-workspace.yaml"))||Ne(Z(o,"lerna.json")))return o;let n=Z(o,"package.json");if(Ne(n))try{if(JSON.parse(Ft(n,"utf-8")).workspaces)return o}catch{}o=wt(o),e++}return null}function vt(s,o,t,e,n,a){return new Promise(r=>{let i=oi(s,o,{cwd:t,stdio:["pipe","pipe","pipe"],timeout:e,env:a?{...process.env,...a}:process.env}),l="",c="";i.stdout?.on("data",u=>{let m=u.toString();if(c+=m,n)for(let p of m.split(`
|
|
1896
1896
|
`).filter(Boolean))n(p)}),i.stderr?.on("data",u=>{let m=u.toString();if(l+=m,n)for(let p of m.split(`
|
|
1897
1897
|
`).filter(Boolean))n(p)}),i.on("close",u=>{if(u===0)r({success:!0});else{let m=l.split(`
|
|
1898
|
-
`).find(p=>p.startsWith("npm error"))??l.slice(0,300);r({success:!1,error:m})}}),i.on("error",u=>{r({success:!1,error:u.message})})})}var zc=Lt.object({name:Lt.string().min(1),plan:Lt.any(),path:Lt.string().optional()});function F(s,o,
|
|
1899
|
-
`),a=null,r=null,i=l=>l.replace(/^["']|["']$/g,"").trim();for(let l of n){let c=l.replace(/\r$/,"");if(!c.trim()||c.trim().startsWith("#"))continue;if(c.startsWith("theme:")){let p=i(c.slice(6).trim());(p==="dark"||p==="light")&&(
|
|
1898
|
+
`).find(p=>p.startsWith("npm error"))??l.slice(0,300);r({success:!1,error:m})}}),i.on("error",u=>{r({success:!1,error:u.message})})})}var zc=Lt.object({name:Lt.string().min(1),plan:Lt.any(),path:Lt.string().optional()});function F(s,o,t){let e=Z(s,o);Ut(wt(e),{recursive:!0}),Be(e,t)}var ni={sharp:"0.125rem",subtle:"0.375rem",rounded:"0.75rem",pill:"9999px"},ii=[["--color-background","#ffffff"],["--color-foreground","#0a0a0a"],["--color-card","#ffffff"],["--color-card-foreground","#0a0a0a"],["--color-popover","#ffffff"],["--color-popover-foreground","#0a0a0a"],["--color-muted","#f5f5f5"],["--color-muted-foreground","#525252"],["--color-border","#e5e5e5"],["--color-input","#e5e5e5"],["--color-primary","#0a0a0a"],["--color-primary-foreground","#ffffff"],["--color-ring","#0a0a0a"],["--color-secondary","#f5f5f5"],["--color-secondary-foreground","#0a0a0a"],["--color-accent","#f5f5f5"],["--color-accent-foreground","#0a0a0a"],["--color-destructive","#b91c1c"],["--color-destructive-foreground","#ffffff"],["--color-success","#15803d"],["--color-success-foreground","#ffffff"],["--color-warning","#a16207"],["--color-warning-foreground","#ffffff"],["--color-info","#0369a1"],["--color-info-foreground","#ffffff"]];function ai(s){let o=s.match(/^---\n([\s\S]*?)\n---/);if(!o)return null;let t=o[1],e={theme:"light",colors:{},typography:{},rounded:{},spacing:{}},n=t.split(`
|
|
1899
|
+
`),a=null,r=null,i=l=>l.replace(/^["']|["']$/g,"").trim();for(let l of n){let c=l.replace(/\r$/,"");if(!c.trim()||c.trim().startsWith("#"))continue;if(c.startsWith("theme:")){let p=i(c.slice(6).trim());(p==="dark"||p==="light")&&(e.theme=p);continue}let u=c.match(/^(colors|typography|rounded|spacing):\s*$/);if(u){a=u[1],r=null;continue}if(a==="typography"){let p=c.match(/^ {2}([a-zA-Z0-9_-]+):\s*$/);if(p){r=p[1].replace(/-/g,"_"),e.typography[r]={};continue}let g=c.match(/^ {4}([a-zA-Z0-9_-]+):\s*(.+)$/);if(g&&r){e.typography[r][g[1]]=i(g[2]);continue}}let m=c.match(/^ {2}([a-zA-Z0-9_-]+):\s*(.+)$/);if(m&&a){let p=m[1].replace(/-/g,"_"),g=i(m[2]);a==="colors"?e.colors[p]=g:a==="rounded"?e.rounded[p]=g:a==="spacing"&&(e.spacing[p]=g)}}return e}function li(s,o){let t=s.colors,n=[["--color-background",t.background],["--color-foreground",t.on_background??t.on_surface],["--color-card",t.surface??t.background],["--color-card-foreground",t.on_surface??t.on_background],["--color-popover",t.surface??t.background],["--color-popover-foreground",t.on_surface??t.on_background],["--color-muted",t.surface_variant??t.outline_variant??t.outline],["--color-muted-foreground",t.on_surface_variant??t.outline],["--color-border",t.outline_variant??t.outline],["--color-input",t.outline_variant??t.outline],["--color-primary",t.primary],["--color-primary-foreground",t.on_primary],["--color-ring",t.primary],["--color-secondary",t.secondary],["--color-secondary-foreground",t.on_secondary],["--color-accent",t.secondary],["--color-accent-foreground",t.on_secondary],["--color-destructive",t.error],["--color-destructive-foreground",t.on_error],["--color-success",t.success],["--color-success-foreground",t.on_success],["--color-warning",t.warning],["--color-warning-foreground",t.on_warning],["--color-info",t.info??t.primary],["--color-info-foreground",t.on_info??t.on_primary]].filter(i=>typeof i[1]=="string").map(([i,l])=>` ${i}: ${l};`).join(`
|
|
1900
1900
|
`),a=[` --radius-sm: ${s.rounded.sm??"0.25rem"};`,` --radius-md: ${s.rounded.md??o};`,` --radius-lg: ${s.rounded.lg??"0.5rem"};`,` --radius-xl: ${s.rounded.xl??"0.75rem"};`].join(`
|
|
1901
1901
|
`);return`@import "tailwindcss";
|
|
1902
1902
|
@import "tw-animate-css";
|
|
@@ -1953,7 +1953,7 @@ ${a}
|
|
|
1953
1953
|
|
|
1954
1954
|
button, [role="button"] { transition: transform 100ms var(--ease-quart-out); }
|
|
1955
1955
|
button:active:not(:disabled), [role="button"]:active:not(:disabled) { transform: scale(0.97); }
|
|
1956
|
-
`}function ci(s,o,
|
|
1956
|
+
`}function ci(s,o,t){let e=s?.borderRadius??"subtle",n=ni[e]??"0.375rem";if(t){let r=ai(t);if(r)return li(r,n)}return`@import "tailwindcss";
|
|
1957
1957
|
@import "tw-animate-css";
|
|
1958
1958
|
|
|
1959
1959
|
@theme {
|
|
@@ -2007,14 +2007,14 @@ ${[...ii.map(([r,i])=>` ${r}: ${i};`)," --radius-sm: 0.25rem;",` --radius-md:
|
|
|
2007
2007
|
|
|
2008
2008
|
button, [role="button"] { transition: transform 100ms var(--ease-quart-out); }
|
|
2009
2009
|
button:active:not(:disabled), [role="button"]:active:not(:disabled) { transform: scale(0.97); }
|
|
2010
|
-
`}var Os={"Fredoka One":"Fredoka","Source Sans Pro":"Source_Sans_3","Source Serif Pro":"Source_Serif_4","Open Sans Condensed":"Open_Sans","Baloo 2":"Baloo_2","DM Serif Display":"DM_Serif_Display","DM Serif Text":"DM_Serif_Text","IBM Plex Mono":"IBM_Plex_Mono","IBM Plex Sans":"IBM_Plex_Sans","IBM Plex Serif":"IBM_Plex_Serif","Fira Code":"Fira_Code","Fira Sans":"Fira_Sans","Noto Sans JP":"Noto_Sans_JP","PT Sans":"PT_Sans","PT Serif":"PT_Serif","Work Sans":"Work_Sans","Space Mono":"Space_Mono","Space Grotesk":"Space_Grotesk","Plus Jakarta Sans":"Plus_Jakarta_Sans"};function Us(s){let o=s.replace(/[^A-Za-z0-9_ -]/g,"");return Os[o]?Os[o]:o.replace(/\s+/g,"_")}function di(s){return s?{english:"en",spanish:"es",french:"fr",german:"de",italian:"it",portuguese:"pt",dutch:"nl",russian:"ru",japanese:"ja",chinese:"zh",korean:"ko",arabic:"ar",hebrew:"he",hindi:"hi",turkish:"tr",polish:"pl",swedish:"sv",norwegian:"no",danish:"da",finnish:"fi",thai:"th",vietnamese:"vi",indonesian:"id",malay:"ms",farsi:"fa",persian:"fa",czech:"cs",greek:"el",romanian:"ro",hungarian:"hu",ukrainian:"uk",bengali:"bn",tamil:"ta",telugu:"te",urdu:"ur"}[s.toLowerCase()]??"en":"en"}var pi=new Set(["ar","he","fa","ur"]);function ui(s,o,
|
|
2010
|
+
`}var Os={"Fredoka One":"Fredoka","Source Sans Pro":"Source_Sans_3","Source Serif Pro":"Source_Serif_4","Open Sans Condensed":"Open_Sans","Baloo 2":"Baloo_2","DM Serif Display":"DM_Serif_Display","DM Serif Text":"DM_Serif_Text","IBM Plex Mono":"IBM_Plex_Mono","IBM Plex Sans":"IBM_Plex_Sans","IBM Plex Serif":"IBM_Plex_Serif","Fira Code":"Fira_Code","Fira Sans":"Fira_Sans","Noto Sans JP":"Noto_Sans_JP","PT Sans":"PT_Sans","PT Serif":"PT_Serif","Work Sans":"Work_Sans","Space Mono":"Space_Mono","Space Grotesk":"Space_Grotesk","Plus Jakarta Sans":"Plus_Jakarta_Sans"};function Us(s){let o=s.replace(/[^A-Za-z0-9_ -]/g,"");return Os[o]?Os[o]:o.replace(/\s+/g,"_")}function di(s){return s?{english:"en",spanish:"es",french:"fr",german:"de",italian:"it",portuguese:"pt",dutch:"nl",russian:"ru",japanese:"ja",chinese:"zh",korean:"ko",arabic:"ar",hebrew:"he",hindi:"hi",turkish:"tr",polish:"pl",swedish:"sv",norwegian:"no",danish:"da",finnish:"fi",thai:"th",vietnamese:"vi",indonesian:"id",malay:"ms",farsi:"fa",persian:"fa",czech:"cs",greek:"el",romanian:"ro",hungarian:"hu",ukrainian:"uk",bengali:"bn",tamil:"ta",telugu:"te",urdu:"ur"}[s.toLowerCase()]??"en":"en"}var pi=new Set(["ar","he","fa","ur"]);function ui(s,o,t){let e=s.replace(/[\\"`$]/g,""),n=di(t),r=pi.has(n)?`lang="${n}" dir="rtl"`:`lang="${n}"`,i=o?.fonts?.heading,l=o?.fonts?.body;if(!i&&!l)return`import type { Metadata } from "next";
|
|
2011
2011
|
import { DM_Sans } from "next/font/google";
|
|
2012
2012
|
import { Toaster } from "sonner";
|
|
2013
2013
|
import "./globals.css";
|
|
2014
2014
|
|
|
2015
2015
|
const body = DM_Sans({ subsets: ["latin"], variable: "--font-body" });
|
|
2016
2016
|
|
|
2017
|
-
export const metadata: Metadata = { title: "${
|
|
2017
|
+
export const metadata: Metadata = { title: "${e}", description: "Built with Mistflow" };
|
|
2018
2018
|
|
|
2019
2019
|
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
2020
2020
|
return (
|
|
@@ -2030,7 +2030,7 @@ import "./globals.css";
|
|
|
2030
2030
|
|
|
2031
2031
|
const font = ${c}({ subsets: ["latin"], variable: "--font-body" });
|
|
2032
2032
|
|
|
2033
|
-
export const metadata: Metadata = { title: "${
|
|
2033
|
+
export const metadata: Metadata = { title: "${e}", description: "Built with Mistflow" };
|
|
2034
2034
|
|
|
2035
2035
|
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
2036
2036
|
return (
|
|
@@ -2047,7 +2047,7 @@ import "./globals.css";
|
|
|
2047
2047
|
const heading = ${c}({ subsets: ["latin"], variable: "--font-heading" });
|
|
2048
2048
|
const body = ${u}({ subsets: ["latin"], variable: "--font-body" });
|
|
2049
2049
|
|
|
2050
|
-
export const metadata: Metadata = { title: "${
|
|
2050
|
+
export const metadata: Metadata = { title: "${e}", description: "Built with Mistflow" };
|
|
2051
2051
|
|
|
2052
2052
|
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
2053
2053
|
return (
|
|
@@ -2056,38 +2056,38 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
2056
2056
|
</html>
|
|
2057
2057
|
);
|
|
2058
2058
|
}
|
|
2059
|
-
`}function Ot(s,...o){let
|
|
2060
|
-
`)}function gi(s){if(s.navStyle==="none")return null;let o=["/api","/login","/register","/sign-in","/sign-up","/admin","/pricing","/about","/contact","/terms","/privacy","/onboarding","/join","/forgot-password","/reset-password"],
|
|
2061
|
-
`)}}let i=[];i.push('"use client";'),i.push(""),i.push('import { useState } from "react";'),i.push('import Link from "next/link";'),i.push('import { usePathname } from "next/navigation";'),n||i.push('import { authClient } from "@/lib/auth-client";'),i.push('import { Button } from "@/components/ui/button";'),i.push('import { Sheet, SheetContent, SheetTrigger, SheetTitle } from "@/components/ui/sheet";'),i.push('import { cn } from "@/lib/utils";'),i.push("import { Menu, "+a.join(", ")+' } from "lucide-react";'),i.push(""),i.push("interface SidebarProps {"),i.push(" user: { name: string | null; email: string; role?: string | undefined };"),i.push("}"),i.push(""),i.push("const NAV_ITEMS = [");for(let l of
|
|
2062
|
-
`)}}function fi(s){if(!s.roles||s.roles.length===0)return null;let o=s.roles,
|
|
2059
|
+
`}function Ot(s,...o){let t=JSON.stringify(s).toLowerCase();return o.some(e=>t.includes(e.toLowerCase()))}var mi={dashboard:"Home",home:"Home",overview:"Home",patient:"Users",member:"Users",user:"Users",people:"Users",team:"Users",client:"Users",contact:"Users",customer:"Users",appointment:"Calendar",schedule:"Calendar",booking:"Calendar",event:"Calendar",billing:"CreditCard",invoice:"CreditCard",payment:"CreditCard",pricing:"CreditCard",treatment:"ClipboardList",plan:"ClipboardList",task:"CheckSquare",exercise:"Dumbbell",workout:"Dumbbell",report:"BarChart3",analytics:"BarChart3",stats:"BarChart3",setting:"Settings",config:"Settings",profile:"User",account:"User",message:"MessageSquare",chat:"MessageSquare",inbox:"MessageSquare",product:"Package",item:"Package",catalog:"Package",order:"ShoppingCart",cart:"ShoppingCart",file:"FileText",document:"FileText",upload:"Upload",notification:"Bell",alert:"Bell",project:"FolderKanban",board:"FolderKanban",post:"PenSquare",blog:"PenSquare",article:"PenSquare",course:"GraduationCap",lesson:"GraduationCap",class:"GraduationCap",habit:"Target",goal:"Target",streak:"Flame",progress:"TrendingUp",feature:"Sparkles",subscription:"CreditCard",price:"CreditCard",recipe:"ChefHat",food:"UtensilsCrossed",meal:"UtensilsCrossed",pet:"PawPrint",animal:"PawPrint",music:"Music",playlist:"ListMusic",song:"Music",photo:"Image",image:"Image",gallery:"Images",video:"Video",movie:"Film",map:"MapPin",location:"MapPin",place:"MapPin",search:"Search",explore:"Compass",inventory:"Boxes",stock:"Boxes",warehouse:"Warehouse",review:"Star",rating:"Star",feedback:"Star",log:"ScrollText",history:"Clock",activity:"Activity"};function wo(s){let o=s.toLowerCase().replace(/[^a-z]/g,"");for(let[t,e]of Object.entries(mi))if(o.includes(t))return e;return"Circle"}function kt(s){return s.split("-").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ")}function hi(s){if(s.authModel==="none")return null;let o=["/login","/register","/forgot-password","/reset-password","/api/auth","/api/health","/api/webhooks","/api/admin/seed"];if(s.publicPages&&Array.isArray(s.publicPages))for(let a of s.publicPages){if(typeof a!="string"||a.length<1)continue;let r=a.replace(/[\u201C\u201D\u201E\u201F\u2018\u2019\u2033\u2036]/g,"").trim();if(!r)continue;let i=r.startsWith("/")?r:"/"+r;o.includes(i)||o.push(i)}let t=o.filter(a=>a==="/"),e=o.filter(a=>a!=="/"),n=[];n.push('import { NextRequest, NextResponse } from "next/server";'),n.push(""),n.push("const PUBLIC_PREFIXES = [");for(let a of e)n.push(' "'+a+'",');return n.push("];"),n.push(""),t.length>0&&(n.push('const PUBLIC_EXACT = ["'+t.join('", "')+'"];'),n.push("")),n.push("export function middleware(req: NextRequest) {"),n.push(" const { pathname, search } = req.nextUrl;"),n.push(""),t.length>0&&n.push(" if (PUBLIC_EXACT.includes(pathname)) return NextResponse.next();"),n.push(" if (PUBLIC_PREFIXES.some((p) => pathname.startsWith(p))) return NextResponse.next();"),n.push(""),n.push(' const token = req.cookies.get("better-auth.session_token")?.value || req.cookies.get("__Secure-better-auth.session_token")?.value;'),n.push(" if (!token) {"),n.push(' const loginUrl = new URL("/login", req.url);'),n.push(" const params = new URLSearchParams(search);"),n.push(' for (const key of ["verified", "error"]) {'),n.push(" const v = params.get(key);"),n.push(" if (v) loginUrl.searchParams.set(key, v);"),n.push(" }"),n.push(" return NextResponse.redirect(loginUrl);"),n.push(" }"),n.push(""),n.push(" return NextResponse.next();"),n.push("}"),n.push(""),n.push("export const config = {"),n.push(' matcher: ["/((?!_next|static|favicon\\\\.ico).*)"],'),n.push("};"),n.push(""),n.join(`
|
|
2060
|
+
`)}function gi(s){if(s.navStyle==="none")return null;let o=["/api","/login","/register","/sign-in","/sign-up","/admin","/pricing","/about","/contact","/terms","/privacy","/onboarding","/join","/forgot-password","/reset-password"],e=(s.pages??[]).filter(l=>{let c=l.path??l.route??"";return c==="/"||c===""||c.includes("[")||c.replace(/^\//,"").split("/").length>1?!1:!o.some(m=>c.startsWith(m))}).map(l=>{let c=l.path??l.route??"",u=c.startsWith("/")?c:"/"+c,m=l.name??kt(c.replace(/^\//,"")),p=wo(m);return{label:m,href:u,icon:p}});e.some(l=>l.href==="/dashboard")||e.unshift({label:"Dashboard",href:"/dashboard",icon:"Home"});let n=s.authModel==="none",a=[...new Set(e.map(l=>l.icon))];n||a.push("LogOut");let r=kt(s.name);if(s.navStyle==="topbar"){let l=[];l.push('"use client";'),l.push(""),l.push('import Link from "next/link";'),l.push('import { usePathname } from "next/navigation";'),n||l.push('import { authClient } from "@/lib/auth-client";'),l.push('import { Button } from "@/components/ui/button";'),l.push('import { cn } from "@/lib/utils";'),l.push("import { "+a.join(", ")+' } from "lucide-react";'),l.push(""),l.push("interface TopNavProps {"),l.push(" user: { name: string | null; email: string; role?: string | undefined };"),l.push("}"),l.push(""),l.push("const NAV_ITEMS = [");for(let c of e)l.push(' { label: "'+c.label+'", href: "'+c.href+'", icon: '+c.icon+" },");return l.push("];"),l.push(""),l.push("export default function TopNav({ user }: TopNavProps) {"),l.push(" const pathname = usePathname();"),l.push(""),l.push(" return ("),l.push(' <nav className="border-b bg-card">'),l.push(' <div className="mx-auto flex h-14 max-w-7xl items-center justify-between px-4">'),l.push(' <div className="flex items-center gap-6">'),l.push(' <span className="text-lg font-semibold">'+r+"</span>"),l.push(' <div className="flex items-center gap-1">'),l.push(" {NAV_ITEMS.map((item) => ("),l.push(" <Link"),l.push(" key={item.href}"),l.push(" href={item.href}"),l.push(' aria-current={pathname === item.href ? "page" : undefined}'),l.push(" className={cn("),l.push(' "flex items-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium transition-colors",'),l.push(' pathname === item.href ? "bg-primary/10 text-primary" : "text-muted-foreground hover:text-foreground"'),l.push(" )}"),l.push(" >"),l.push(' <item.icon className="h-4 w-4" />'),l.push(" {item.label}"),l.push(" </Link>"),l.push(" ))}"),l.push(" </div>"),l.push(" </div>"),n?l.push(' <span className="text-sm text-muted-foreground">{user.name}</span>'):(l.push(' <div className="flex items-center gap-2">'),l.push(' <span className="text-sm text-muted-foreground">{user.email}</span>'),l.push(" <Button"),l.push(' variant="ghost"'),l.push(' size="sm"'),l.push(' onClick={() => authClient.signOut({ fetchOptions: { onSuccess: () => { window.location.href = "/login"; } } })}'),l.push(" >"),l.push(' <LogOut className="h-4 w-4" />'),l.push(" </Button>"),l.push(" </div>")),l.push(" </div>"),l.push(" </nav>"),l.push(" );"),l.push("}"),l.push(""),{path:"components/topnav.tsx",content:l.join(`
|
|
2061
|
+
`)}}let i=[];i.push('"use client";'),i.push(""),i.push('import { useState } from "react";'),i.push('import Link from "next/link";'),i.push('import { usePathname } from "next/navigation";'),n||i.push('import { authClient } from "@/lib/auth-client";'),i.push('import { Button } from "@/components/ui/button";'),i.push('import { Sheet, SheetContent, SheetTrigger, SheetTitle } from "@/components/ui/sheet";'),i.push('import { cn } from "@/lib/utils";'),i.push("import { Menu, "+a.join(", ")+' } from "lucide-react";'),i.push(""),i.push("interface SidebarProps {"),i.push(" user: { name: string | null; email: string; role?: string | undefined };"),i.push("}"),i.push(""),i.push("const NAV_ITEMS = [");for(let l of e)i.push(' { label: "'+l.label+'", href: "'+l.href+'", icon: '+l.icon+" },");return i.push("];"),i.push(""),i.push('function NavContent({ pathname, user, onNavigate }: { pathname: string; user: SidebarProps["user"]; onNavigate?: () => void }) {'),i.push(" return ("),i.push(" <>"),i.push(' <div className="flex h-14 items-center border-b px-4">'),i.push(' <span className="text-lg font-semibold">'+r+"</span>"),i.push(" </div>"),i.push(' <nav className="flex-1 space-y-1 p-2">'),i.push(" {NAV_ITEMS.map((item) => ("),i.push(" <Link"),i.push(" key={item.href}"),i.push(" href={item.href}"),i.push(" onClick={onNavigate}"),i.push(' aria-current={pathname === item.href ? "page" : undefined}'),i.push(" className={cn("),i.push(' "flex items-center gap-3 rounded-md px-3 py-2.5 text-sm font-medium transition-colors",'),i.push(' pathname === item.href ? "bg-primary/10 text-primary" : "text-muted-foreground hover:bg-muted hover:text-foreground"'),i.push(" )}"),i.push(" >"),i.push(' <item.icon className="h-4 w-4" />'),i.push(" {item.label}"),i.push(" </Link>"),i.push(" ))}"),i.push(" </nav>"),i.push(' <div className="border-t p-4">'),i.push(' <div className="flex items-center gap-3">'),i.push(' <div className="flex-1 truncate">'),i.push(' <p className="truncate text-sm font-medium">{user.name ?? "User"}</p>'),i.push(' <p className="truncate text-xs text-muted-foreground">{user.email}</p>'),i.push(" </div>"),n||(i.push(" <Button"),i.push(' variant="ghost"'),i.push(' size="icon"'),i.push(' onClick={() => authClient.signOut({ fetchOptions: { onSuccess: () => { window.location.href = "/login"; } } })}'),i.push(" >"),i.push(' <LogOut className="h-4 w-4" />'),i.push(" </Button>")),i.push(" </div>"),i.push(" </div>"),i.push(" </>"),i.push(" );"),i.push("}"),i.push(""),i.push("export default function Sidebar({ user }: SidebarProps) {"),i.push(" const pathname = usePathname();"),i.push(" const [open, setOpen] = useState(false);"),i.push(""),i.push(" return ("),i.push(" <>"),i.push(' <aside className="hidden md:flex h-screen w-64 flex-col border-r bg-card">'),i.push(" <NavContent pathname={pathname} user={user} />"),i.push(" </aside>"),i.push(' <div className="sticky top-0 z-[var(--z-sticky)] flex h-14 items-center gap-3 border-b bg-card px-4 md:hidden">'),i.push(" <Sheet open={open} onOpenChange={setOpen}>"),i.push(" <SheetTrigger asChild>"),i.push(' <Button variant="ghost" size="icon" className="-ml-2">'),i.push(' <Menu className="h-5 w-5" />'),i.push(" </Button>"),i.push(" </SheetTrigger>"),i.push(' <SheetContent side="left" className="w-64 p-0">'),i.push(' <SheetTitle className="sr-only">Navigation</SheetTitle>'),i.push(' <div className="flex h-full flex-col">'),i.push(" <NavContent pathname={pathname} user={user} onNavigate={() => setOpen(false)} />"),i.push(" </div>"),i.push(" </SheetContent>"),i.push(" </Sheet>"),i.push(' <span className="text-lg font-semibold">'+r+"</span>"),i.push(" </div>"),i.push(" </>"),i.push(" );"),i.push("}"),i.push(""),{path:"components/sidebar.tsx",content:i.join(`
|
|
2062
|
+
`)}}function fi(s){if(!s.roles||s.roles.length===0)return null;let o=s.roles,t=s.defaultRole??o[0],e=[];e.push("export type Role = "+o.map(n=>'"'+n+'"').join(" | ")+";"),e.push(""),e.push("export const ROLES = ["+o.map(n=>'"'+n+'"').join(", ")+"] as const;"),e.push(""),e.push('export const DEFAULT_ROLE: Role = "'+t+'";'),e.push(""),e.push("export const ROLE_LABELS: Record<Role, string> = {");for(let n of o){let a=n.charAt(0).toUpperCase()+n.slice(1);e.push(' "'+n+'": "'+a+'",')}return e.push("};"),e.push(""),e.push("export function getUserRole(user: Record<string, unknown>): Role {"),e.push(" const role = (user.role as string) ?? DEFAULT_ROLE;"),e.push(" if (ROLES.includes(role as Role)) return role as Role;"),e.push(" return DEFAULT_ROLE;"),e.push("}"),e.push(""),e.push("export function hasRole(userRole: string | undefined, required: Role | Role[]): boolean {"),e.push(" if (!userRole) return false;"),e.push(" const allowed = Array.isArray(required) ? required : [required];"),e.push(" return allowed.includes(userRole as Role);"),e.push("}"),e.push(""),e.join(`
|
|
2063
2063
|
`)}function yi(s){let o=kt(s.name);if(s.authModel==="none"){let a=[];return a.push("export default function HomePage() {"),a.push(" return ("),a.push(' <main className="flex min-h-screen flex-col items-center justify-center p-8">'),a.push(' <h1 className="text-4xl font-bold">'+o+"</h1>"),s.summary&&a.push(' <p className="mt-4 text-lg text-muted-foreground">'+s.summary+"</p>"),a.push(" </main>"),a.push(" );"),a.push("}"),a.push(""),a.join(`
|
|
2064
|
-
`)}let
|
|
2065
|
-
`)}if(
|
|
2064
|
+
`)}let t=s.publicPages?.includes("/"),e=s.design?.landingTone;if(t&&e){let a=[];return a.push('import Link from "next/link";'),a.push(""),a.push("export default function HomePage() {"),a.push(" return ("),a.push(' <main className="flex min-h-screen flex-col">'),a.push(' <section className="flex flex-1 flex-col items-center justify-center gap-6 px-4 py-24 text-center">'),a.push(' <h1 className="text-5xl font-bold tracking-tight">'+o+"</h1>"),s.summary&&a.push(' <p className="max-w-2xl text-xl text-muted-foreground">'+s.summary+"</p>"),a.push(' <div className="flex gap-4">'),a.push(' <Link href="/register" className="inline-flex h-11 items-center rounded-md bg-primary px-8 text-sm font-medium text-primary-foreground hover:bg-primary/90">'),a.push(" Get Started"),a.push(" </Link>"),a.push(' <Link href="/login" className="inline-flex h-11 items-center rounded-md border px-8 text-sm font-medium hover:bg-muted">'),a.push(" Sign In"),a.push(" </Link>"),a.push(" </div>"),a.push(" </section>"),a.push(" </main>"),a.push(" );"),a.push("}"),a.push(""),a.join(`
|
|
2065
|
+
`)}if(t){let a=[];return a.push('import Link from "next/link";'),a.push(""),a.push("export default function HomePage() {"),a.push(" return ("),a.push(' <main className="flex min-h-screen flex-col items-center justify-center gap-6 p-8 text-center">'),a.push(' <h1 className="text-4xl font-bold">'+o+"</h1>"),s.summary&&a.push(' <p className="text-lg text-muted-foreground">'+s.summary+"</p>"),a.push(' <Link href="/login" className="inline-flex h-10 items-center rounded-md bg-primary px-6 text-sm font-medium text-primary-foreground hover:bg-primary/90">'),a.push(" Sign In"),a.push(" </Link>"),a.push(" </main>"),a.push(" );"),a.push("}"),a.push(""),a.join(`
|
|
2066
2066
|
`)}let n=[];return n.push('import { headers } from "next/headers";'),n.push('import { redirect } from "next/navigation";'),n.push('import { auth } from "@/lib/auth";'),n.push(""),n.push("export default async function HomePage() {"),n.push(" const session = await auth.api.getSession({ headers: await headers() });"),n.push(' if (session) redirect("/dashboard");'),n.push(' redirect("/login");'),n.push("}"),n.push(""),n.join(`
|
|
2067
|
-
`)}function bi(s,o){let
|
|
2068
|
-
`)}function wi(s){let o=kt(s.name),
|
|
2069
|
-
`)}function vi(s,o=!1){if(!s.multiTenant)return null;let
|
|
2067
|
+
`)}function bi(s,o){let t=s.authModel==="none",e=[];t||(e.push('import { Suspense } from "react";'),e.push('import { headers } from "next/headers";'),e.push('import { redirect } from "next/navigation";'),e.push('import { auth } from "@/lib/auth";'),e.push('import { VerifiedBanner } from "@/components/auth/verified-banner";')),s.navStyle==="topbar"?e.push('import TopNav from "@/components/topnav";'):s.navStyle!=="none"&&e.push('import Sidebar from "@/components/sidebar";'),!t&&s.roles&&s.roles.length>0&&e.push('import { getUserRole } from "@/lib/roles";'),e.push(""),e.push("export default async function DashboardLayout({ children }: { children: React.ReactNode }) {"),t?e.push(' const user = { name: "Guest", email: "" };'):(e.push(" const session = await auth.api.getSession({ headers: await headers() });"),e.push(' if (!session) redirect("/login");'),e.push(""),s.roles&&s.roles.length>0?(e.push(" const role = getUserRole(session.user as Record<string, unknown>);"),e.push(" const user = { name: session.user.name, email: session.user.email, role };")):(e.push(" const user = {"),e.push(" name: session.user.name,"),e.push(" email: session.user.email,"),e.push(" role: (session.user as Record<string, unknown>).role as string | undefined,"),e.push(" };"))),e.push("");let n=t?"":"<Suspense fallback={null}><VerifiedBanner /></Suspense>";return s.navStyle==="topbar"?(e.push(" return ("),e.push(' <div className="min-h-screen">'),e.push(" <TopNav user={user} />"),e.push(' <main className="mx-auto max-w-7xl p-6">'+n+"{children}</main>"),e.push(" </div>"),e.push(" );")):s.navStyle==="none"?(e.push(" return ("),e.push(' <div className="min-h-screen">'),e.push(' <main className="mx-auto max-w-5xl p-6">'+n+"{children}</main>"),e.push(" </div>"),e.push(" );")):(e.push(" return ("),e.push(' <div className="flex flex-col md:flex-row min-h-screen">'),e.push(" <Sidebar user={user} />"),e.push(' <main className="flex-1 overflow-x-hidden p-4 md:p-6">'+n+"{children}</main>"),e.push(" </div>"),e.push(" );")),e.push("}"),e.push(""),e.join(`
|
|
2068
|
+
`)}function wi(s){let o=kt(s.name),t=s.dataModel??[],e=[];if(t.length>0){let n=t.map(r=>wo(r.entity??r.name??"item")),a=[...new Set(n)];e.push('import { Card, CardContent } from "@/components/ui/card";'),e.push("import { "+a.join(", ")+' } from "lucide-react";'),e.push("")}if(e.push("export default function DashboardPage() {"),e.push(" return ("),e.push(' <div className="space-y-6">'),e.push(" <div>"),e.push(' <h1 className="text-3xl font-bold">'+o+"</h1>"),s.summary&&e.push(' <p className="mt-1 text-muted-foreground">'+s.summary+"</p>"),e.push(" </div>"),t.length>0){e.push(' <div className="rounded-lg border p-8 text-center">'),e.push(' <h2 className="text-lg font-semibold">Get started</h2>'),e.push(` <p className="mt-1 text-sm text-muted-foreground">Here's what you can do</p>`),e.push(' <div className="mt-6 grid gap-3 sm:grid-cols-2 text-left">');for(let n of t){let a=n.entity??n.name??"Item",r=wo(a),i=kt(a.replace(/_/g,"-"));e.push(' <div className="flex items-center gap-3 rounded-md border p-3">'),e.push(" <"+r+' className="h-5 w-5 text-muted-foreground" />'),e.push(' <span className="text-sm font-medium">Add your first '+i+"</span>"),e.push(" </div>")}e.push(" </div>"),e.push(" </div>")}return e.push(" </div>"),e.push(" );"),e.push("}"),e.push(""),e.join(`
|
|
2069
|
+
`)}function vi(s,o=!1){if(!s.multiTenant)return null;let t=[];return o?(t.push('import { pgTable, text, timestamp, index } from "drizzle-orm/pg-core";'),t.push('import { user } from "./auth";'),t.push(""),t.push('export const organization = pgTable("organization", {'),t.push(' id: text("id").primaryKey(),'),t.push(' name: text("name").notNull(),'),t.push(' slug: text("slug").unique().notNull(),'),t.push(' createdAt: timestamp("created_at").defaultNow().notNull(),'),t.push(' updatedAt: timestamp("updated_at").defaultNow().notNull(),'),t.push("});"),t.push(""),t.push("export const orgMember = pgTable(")):(t.push('import { sqliteTable, text, index } from "drizzle-orm/sqlite-core";'),t.push('import { sql } from "drizzle-orm";'),t.push('import { user } from "./auth";'),t.push(""),t.push('export const organization = sqliteTable("organization", {'),t.push(' id: text("id").primaryKey(),'),t.push(' name: text("name").notNull(),'),t.push(' slug: text("slug").unique().notNull(),'),t.push(' createdAt: text("created_at").default(sql`CURRENT_TIMESTAMP`).notNull(),'),t.push(' updatedAt: text("updated_at").default(sql`CURRENT_TIMESTAMP`).notNull(),'),t.push("});"),t.push(""),t.push("export const orgMember = sqliteTable(")),t.push(' "org_member",'),t.push(" {"),t.push(' id: text("id").primaryKey(),'),t.push(' orgId: text("org_id").notNull().references(() => organization.id),'),t.push(' userId: text("user_id").notNull().references(() => user.id),'),t.push(' role: text("role").notNull(),'),o?t.push(' joinedAt: timestamp("joined_at").defaultNow().notNull(),'):t.push(' joinedAt: text("joined_at").default(sql`CURRENT_TIMESTAMP`).notNull(),'),t.push(" },"),t.push(" (table) => ({"),t.push(' orgIdx: index("org_member_org_idx").on(table.orgId),'),t.push(' userIdx: index("org_member_user_idx").on(table.userId),'),t.push(" }),"),t.push(");"),t.push(""),t.join(`
|
|
2070
2070
|
`)}function ki(s){if(!s.multiTenant)return null;let o=[];return o.push('import { db } from "./db";'),o.push('import { organization, orgMember } from "@/db/schema/organization";'),o.push('import { eq } from "drizzle-orm";'),o.push(""),o.push("export async function getCurrentOrg(userId: string) {"),o.push(" const membership = await db"),o.push(" .select()"),o.push(" .from(orgMember)"),o.push(" .where(eq(orgMember.userId, userId))"),o.push(" .limit(1);"),o.push(" if (membership.length === 0) return null;"),o.push(" const org = await db"),o.push(" .select()"),o.push(" .from(organization)"),o.push(" .where(eq(organization.id, membership[0].orgId))"),o.push(" .limit(1);"),o.push(" return org[0] ?? null;"),o.push("}"),o.push(""),o.push("export async function getOrgMembers(orgId: string) {"),o.push(" return db"),o.push(" .select()"),o.push(" .from(orgMember)"),o.push(" .where(eq(orgMember.orgId, orgId));"),o.push("}"),o.push(""),o.push("export async function inviteToOrg(orgId: string, email: string, role: string) {"),o.push(" const id = crypto.randomUUID();"),o.push(" await db.insert(orgMember).values({"),o.push(" id,"),o.push(" orgId,"),o.push(" userId: email,"),o.push(" role,"),o.push(" });"),o.push(" return { id, orgId, email, role };"),o.push("}"),o.push(""),o.join(`
|
|
2071
2071
|
`)}function xi(s){if(!s.multiTenant)return null;let o=[];return o.push('"use client";'),o.push(""),o.push("import {"),o.push(" DropdownMenu,"),o.push(" DropdownMenuContent,"),o.push(" DropdownMenuItem,"),o.push(" DropdownMenuTrigger,"),o.push('} from "@/components/ui/dropdown-menu";'),o.push('import { Button } from "@/components/ui/button";'),o.push('import { ChevronsUpDown } from "lucide-react";'),o.push(""),o.push("interface OrgSwitcherProps {"),o.push(" orgs: Array<{ id: string; name: string }>;"),o.push(" currentOrgId: string;"),o.push("}"),o.push(""),o.push("export default function OrgSwitcher({ orgs, currentOrgId }: OrgSwitcherProps) {"),o.push(" const currentOrg = orgs.find((o) => o.id === currentOrgId);"),o.push(""),o.push(" return ("),o.push(" <DropdownMenu>"),o.push(" <DropdownMenuTrigger asChild>"),o.push(' <Button variant="outline" className="w-full justify-between">'),o.push(' <span className="truncate">{currentOrg?.name ?? "Select org"}</span>'),o.push(' <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />'),o.push(" </Button>"),o.push(" </DropdownMenuTrigger>"),o.push(' <DropdownMenuContent className="w-56">'),o.push(" {orgs.map((org) => ("),o.push(" <DropdownMenuItem key={org.id}>"),o.push(" {org.name}"),o.push(" </DropdownMenuItem>"),o.push(" ))}"),o.push(" </DropdownMenuContent>"),o.push(" </DropdownMenu>"),o.push(" );"),o.push("}"),o.push(""),o.join(`
|
|
2072
|
-
`)}function Si(s,o,
|
|
2073
|
-
`)}async function Bs(s,o){let{name:
|
|
2072
|
+
`)}function Si(s,o,t){let e=[],n=s.split("-").map(l=>l.charAt(0).toUpperCase()+l.slice(1)).join(" ");e.push(`# ${n}`),e.push(""),o?.summary&&(e.push(o.summary),e.push(""));let a=o?.features??[];if(a.length>0){e.push("## Features"),e.push("");for(let l of a){let c=l.description?` \u2014 ${l.description}`:"";e.push(`- **${l.name}**${c}`)}e.push("")}e.push("## Tech Stack"),e.push(""),e.push("| Layer | Technology |"),e.push("|-------|------------|"),e.push("| Framework | Next.js 15 (App Router) |"),e.push("| Database | Mistflow Cloud (Postgres) + Drizzle ORM |"),e.push("| Auth | Better Auth (email/password, social login) |"),e.push("| Styling | Tailwind CSS + shadcn/ui |"),e.push("| Deployment | Mistflow Cloud |"),t.hasStripe&&e.push("| Payments | Stripe |"),t.hasResend&&e.push("| Email | Resend + React Email |"),t.hasStorage&&e.push("| File Storage | Mistflow Cloud (managed blob storage) |"),t.hasAdmin&&e.push("| Admin | Better Auth admin plugin |"),t.hasAI&&e.push("| AI | Vercel AI SDK + OpenAI |"),e.push("");let r=o?.pages??[];if(r.length>0){e.push("## Pages"),e.push(""),e.push("| Route | Description |"),e.push("|-------|-------------|");for(let l of r){let c=l.path??l.route??l.name??"",u=l.description??"";e.push(`| \`${c.startsWith("/")?c:"/"+c}\` | ${u} |`)}e.push("")}let i=o?.dataModel??[];if(i.length>0){e.push("## Data Model"),e.push("");for(let l of i){let c=l.entity??l.name??"Unknown";if(e.push(`### ${c}`),e.push(""),l.fields.length>0){if(typeof l.fields[0]=="string")e.push(`Fields: ${l.fields.join(", ")}`);else{e.push("| Field | Type |"),e.push("|-------|------|");for(let u of l.fields)e.push(`| ${u.name} | ${u.type} |`)}e.push("")}}}return e.push("## Getting Started"),e.push(""),e.push("### Prerequisites"),e.push(""),e.push("- Node.js 20+"),e.push("- npm"),e.push(""),e.push("### Install"),e.push(""),e.push("Use the Mistflow CLI (recommended \u2014 streams output live and has no 60s tool-call timeout):"),e.push(""),e.push("```bash"),e.push("npx -y @mistflow-ai/cli install"),e.push("```"),e.push(""),e.push("Or plain npm if you prefer:"),e.push(""),e.push("```bash"),e.push("npm install"),e.push("```"),e.push(""),e.push("### Set up environment"),e.push(""),e.push("Copy `.env.example` to `.env.local` and fill in the values:"),e.push(""),e.push("```bash"),e.push("cp .env.example .env.local"),e.push("```"),e.push(""),e.push("| Variable | Description | Required |"),e.push("|----------|-------------|----------|"),t.isNeon?e.push("| `DATABASE_URL` | Postgres connection URL | Yes |"):(e.push("| `TURSO_URL` | Database connection URL | Yes |"),e.push("| `TURSO_AUTH_TOKEN` | Database auth token | Yes |")),e.push("| `AUTH_SECRET` | Auth encryption secret (auto-generated) | Yes |"),t.hasStripe&&(e.push("| `STRIPE_SECRET_KEY` | Stripe secret key | Yes |"),e.push("| `STRIPE_WEBHOOK_SECRET` | Stripe webhook signing secret | Yes |"),e.push("| `NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY` | Stripe publishable key | Yes |")),t.hasResend&&(e.push("| `RESEND_API_KEY` | Resend API key | Yes |"),e.push("| `EMAIL_FROM` | Sender email address | Yes (production) |")),t.hasStorage&&(e.push("| `MISTFLOW_API_KEY` | Mistflow API key for file storage | Yes |"),e.push("| `MISTFLOW_PROJECT_ID` | Mistflow project ID | Yes |")),t.hasAI&&e.push("| `OPENAI_API_KEY` | OpenAI API key | Yes |"),e.push(""),e.push("### Local database"),e.push(""),t.isNeon?(e.push("For local development, start a local Postgres server:"),e.push(""),e.push("```bash"),e.push("# Using Docker:"),e.push("docker run -d --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:17"),e.push("# Or install via Homebrew: brew install postgresql@17 && brew services start postgresql@17"),e.push("```")):(e.push("For local development, start a local Turso server:"),e.push(""),e.push("```bash"),e.push("npx turso dev"),e.push("```")),e.push(""),e.push("Then set up the database:"),e.push(""),e.push("```bash"),e.push("npm run db:push"),e.push("```"),e.push(""),e.push("### Run"),e.push(""),e.push("```bash"),e.push("npm run dev"),e.push("```"),e.push(""),e.push("Open [http://localhost:3000](http://localhost:3000)."),e.push(""),e.push("## Project Structure"),e.push(""),e.push("```"),e.push("app/"),e.push(" (auth)/ Login and registration pages"),e.push(" (dashboard)/ Authenticated app pages"),t.hasAdmin&&e.push(" (admin)/ Admin panel pages"),e.push(" api/ API routes (auth, health, webhooks)"),e.push(" layout.tsx Root layout with fonts and providers"),e.push(" globals.css Design tokens and Tailwind config"),e.push("components/ Reusable UI components"),e.push("db/"),e.push(" schema/ Database table definitions"),e.push(" index.ts Schema exports"),e.push("lib/"),e.push(" auth.ts Better Auth server config"),e.push(" auth-client.ts Better Auth client config"),e.push(` db.ts ${t.isNeon?"Postgres":"SQLite"} database connection`),t.hasStripe&&e.push(" stripe.ts Stripe client"),t.hasResend&&(e.push(" resend.ts Resend client"),e.push(" email.ts Email send helpers")),t.hasStorage&&e.push(" storage.ts File upload/download helpers"),t.hasAI&&e.push(" ai.ts AI client (Vercel AI SDK + OpenAI)"),t.hasResend&&e.push("emails/ React Email templates"),e.push("```"),e.push(""),e.push("## Deploy"),e.push(""),e.push("Deploy to production with Mistflow:"),e.push(""),e.push("```"),e.push("# In your AI editor (Claude Code, Cursor, etc.):"),e.push("mist_deploy action='deploy'"),e.push("```"),e.push(""),e.push("Your app will be live at `https://<app-name>.mistflow.app`."),e.push(""),o?.design&&(e.push("## Design"),e.push(""),o.design.tone&&e.push(`- **Tone**: ${o.design.tone}`),o.design.fonts&&(e.push(`- **Heading font**: ${o.design.fonts.heading}`),e.push(`- **Body font**: ${o.design.fonts.body}`)),o.design.accentColor&&e.push(`- **Accent color**: ${o.design.accentColor}`),o.design.borderRadius&&e.push(`- **Border radius**: ${o.design.borderRadius}`),e.push("")),e.push("---"),e.push(""),e.push("Built with [Mistflow](https://mistflow.ai)"),e.push(""),e.join(`
|
|
2073
|
+
`)}async function Bs(s,o){let{name:t,plan:e,path:n,planId:a}=s;if(!n)return d("mist_build init requires an explicit 'path' \u2014 the absolute directory where the project should be scaffolded. Pass the user's project directory (e.g. /Users/alice/projects/my-app). Do not rely on a default.",!0);if(!vo(n))return d(`mist_build init 'path' must be an absolute path \u2014 received '${n}'. Pass the full absolute path to the target directory.`,!0);let r=Bt(n),i=e?.design,l=e?.appStyle,c=e?Ot(e,"stripe","payment","billing","subscription","checkout","pricing"):!1,u=!0,m=e?Ot(e,"upload","file storage","image upload","profile picture","attachment","gallery","media","blob"):!1,p=e?Ot(e,"admin panel","admin dashboard","admin management"):!1,g=e?Ot(e,"ai integration","openai","llm","ai chat","chatbot","gpt"):!1,b=e,f=!0;if(Ne(r))return d(`A project already exists at this location (${r}). Choose a different name, or delete the existing folder first.`,!0);Ut(r,{recursive:!0});try{let S=Z(wt(r),".mistflow","mockups");if(Ne(S)){let D=ei(S).filter(G=>G.endsWith(".html"));if(D.length>0){let G=Z(r,".mistflow","mockups");Ut(G,{recursive:!0});for(let J of D)ti(Z(S,J),Z(G,J));console.error(`Copied ${D.length} mockup file(s) into project`)}}}catch(S){console.error("Could not copy mockup files:",S instanceof Error?S.message:S)}let h=null;try{h=await Dt("nextjs")}catch(S){console.error("Could not fetch scaffold from API, using minimal scaffold:",S instanceof Error?S.message:S)}if(h){let S=t.toLowerCase().replace(/[^a-z0-9-]/g,"-");for(let A of h.files){if(A.path==="package.json"||A.path==="middleware.ts"||A.path==="components/sidebar.tsx"||A.path==="components/topnav.tsx"||A.path==="app/(dashboard)/layout.tsx"||A.path==="app/(dashboard)/page.tsx"||A.path==="app/(dashboard)/dashboard/page.tsx"||!c&&(A.path.includes("stripe")||A.path.includes("webhook/stripe"))||!u&&(A.path.includes("resend")||A.path.includes("emails/"))||!p&&(A.path.includes("(admin)")||A.path.includes("admin-sidebar"))||f&&(A.path==="lib/db.ts"||A.path==="lib/auth.ts"||A.path==="drizzle.config.ts"||A.path==="db/schema/auth.ts"))continue;let K=A.content.replace(/\{\{APP_NAME\}\}/g,t).replace(/\{\{WORKER_NAME\}\}/g,S);if(f&&A.path==="next.config.ts"&&(K=K.replace(/serverExternalPackages:\s*\[[^\]]*\],?/g,'serverExternalPackages: ["@electric-sql/pglite"],')),A.path==="next.config.ts"){let ne=ri(r);ne&&(console.error(`[init] Project is inside monorepo at ${ne} \u2014 adding outputFileTracingRoot`),K.includes("outputFileTracingRoot")||(K=K.replace('import type { NextConfig } from "next";',`import type { NextConfig } from "next";
|
|
2074
2074
|
import { dirname } from "path";
|
|
2075
2075
|
import { fileURLToPath } from "url";
|
|
2076
2076
|
|
|
2077
2077
|
const __dirname = dirname(fileURLToPath(import.meta.url));`),K=K.replace("images: {",`outputFileTracingRoot: __dirname,
|
|
2078
|
-
images: {`)))}!p&&
|
|
2078
|
+
images: {`)))}!p&&A.path.includes("sidebar")&&(K=K.replace(/\{user\.role === "admin"[\s\S]*?<\/Link>\s*\)\}/m,""),K=K.replace(/, Shield/g,"")),F(r,A.path,K)}let D={...h.dependencies},G={...h.devDependencies};if(f&&(delete D["@libsql/client"],D["@neondatabase/serverless"]="^0.10.0",G["@electric-sql/pglite"]="^0.2.0"),c&&(D.stripe="^17.0.0"),u&&(D.resend="^4.0.0",D["@react-email/components"]="^0.0.31"),g&&(D.ai="^4.0.0",D["@ai-sdk/openai"]="^1.0.0",D.openai="^4.0.0"),F(r,"package.json",JSON.stringify({name:t,version:"0.1.0",private:!0,scripts:{dev:"next dev",build:"next build",start:"next start",lint:"next lint","db:push":"drizzle-kit push","db:studio":"drizzle-kit studio"},dependencies:D,devDependencies:G,optionalDependencies:{"@noble/ciphers":"^1.3.0"},overrides:{react:"19.1.0","react-dom":"19.1.0",punycode:"^2.3.1"}},null,2)),h.methodology){let A=h.methodology;f&&(A=A.replace(/sqliteTable/g,"pgTable").replace(/drizzle-orm\/sqlite-core/g,"drizzle-orm/pg-core").replace(/Use `text` for dates \(SQLite stores dates as text\)/g,"Use `timestamp` for dates and `boolean` for booleans (native Postgres types)").replace(/text\("created_at"\)\.notNull\(\)\.default\(sql`\(CURRENT_TIMESTAMP\)`\)/g,'timestamp("created_at").notNull().defaultNow()').replace(/text\("updated_at"\)\.notNull\(\)\.default\(sql`\(CURRENT_TIMESTAMP\)`\)/g,'timestamp("updated_at").notNull().defaultNow()').replace(/import { sqliteTable, text, integer } from "drizzle-orm\/sqlite-core";\nimport { sql } from "drizzle-orm";/g,'import { pgTable, text, timestamp, boolean } from "drizzle-orm/pg-core";').replace(/`drizzle-kit push` for SQLite\/Turso/g,"`drizzle-kit push` for Postgres")),F(r,"AGENTS.md",A),F(r,"CLAUDE.md",A)}let xe=e?.designMd;xe&&F(r,"DESIGN.md",xe),f&&(F(r,"lib/db.ts",['import { neon } from "@neondatabase/serverless";','import { drizzle as drizzleNeon } from "drizzle-orm/neon-http";',"","// eslint-disable-next-line @typescript-eslint/no-explicit-any","let _db: any = null;","","function getDb() {"," if (!_db) {",' if (process.env.DATABASE_URL && process.env.DATABASE_URL !== "pglite") {'," // Production / remote Postgres"," const sql = neon(process.env.DATABASE_URL);"," _db = drizzleNeon(sql);"," } else {"," // Local dev \u2014 PGlite (zero-install embedded Postgres). Lives in"," // lib/db-local.ts and is loaded through a runtime-only require"," // whose path is built from a variable, so esbuild's static"," // analysis can't follow it. Keeps pglite + its 30MB WASM out of"," // the Worker bundle.",' const localPath: string = "./" + "db-local";'," // eslint-disable-next-line @typescript-eslint/no-require-imports"," const { createLocalDb } = require(localPath);"," _db = createLocalDb();"," }"," }"," return _db;","}","","// Lazy proxy \u2014 DB isn't initialized at import/build time","// eslint-disable-next-line @typescript-eslint/no-explicit-any","export const db: any = new Proxy({} as any, {"," get(_target, prop, receiver) {"," const realDb = getDb();"," const value = Reflect.get(realDb, prop, receiver);",' if (typeof value === "function") {'," return value.bind(realDb);"," }"," return value;"," },","});",""].join(`
|
|
2079
2079
|
`)),F(r,"lib/db-local.ts",["// Local-dev-only DB factory. Isolated from lib/db.ts so the production","// Cloudflare Worker bundle never loads drizzle-orm/pglite or its","// transitive 30MB WASM binary. Loaded via runtime-only require() from","// db.ts, where the path is built from a variable to defeat static analysis.","",'const pglitePkg: string = ["@electric-sql", "pglite"].join("/");',"// eslint-disable-next-line @typescript-eslint/no-require-imports","const { PGlite } = require(pglitePkg);","",'const drizzlePath: string = "drizzle-orm/" + "pglite";',"// eslint-disable-next-line @typescript-eslint/no-require-imports","const { drizzle } = require(drizzlePath);","","// eslint-disable-next-line @typescript-eslint/no-explicit-any","export function createLocalDb(): any {",' const client = new PGlite("./local.pg");'," return drizzle(client);","}",""].join(`
|
|
2080
2080
|
`)),F(r,"drizzle.config.ts",['import { defineConfig } from "drizzle-kit";',"","// PGlite for local dev (no Postgres install needed), Mistflow Cloud for production",'const isPglite = !process.env.DATABASE_URL || process.env.DATABASE_URL === "pglite";',"","export default defineConfig({",' schema: "./db/schema",',' out: "./db/migrations",',' dialect: "postgresql",',' ...(isPglite ? { driver: "pglite", dbCredentials: { url: "./local.pg" } } : { dbCredentials: { url: process.env.DATABASE_URL! } }),',"});",""].join(`
|
|
2081
2081
|
`)),F(r,"db/schema/auth.ts",['import { pgTable, text, boolean, timestamp } from "drizzle-orm/pg-core";',"",'export const user = pgTable("user", {',' id: text("id").primaryKey(),',' name: text("name").notNull(),',' email: text("email").notNull().unique(),',' emailVerified: boolean("email_verified").notNull().default(false),',' image: text("image"),',' role: text("role").default("user"),',' banned: boolean("banned").default(false),',' banReason: text("ban_reason"),',' banExpires: timestamp("ban_expires"),',' createdAt: timestamp("created_at").notNull(),',' updatedAt: timestamp("updated_at").notNull(),',"});","",'export const session = pgTable("session", {',' id: text("id").primaryKey(),',' expiresAt: timestamp("expires_at").notNull(),',' token: text("token").notNull().unique(),',' createdAt: timestamp("created_at").notNull(),',' updatedAt: timestamp("updated_at").notNull(),',' ipAddress: text("ip_address"),',' userAgent: text("user_agent"),',' userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),',' impersonatedBy: text("impersonated_by"),',"});","",'export const account = pgTable("account", {',' id: text("id").primaryKey(),',' accountId: text("account_id").notNull(),',' providerId: text("provider_id").notNull(),',' userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),',' accessToken: text("access_token"),',' refreshToken: text("refresh_token"),',' idToken: text("id_token"),',' accessTokenExpiresAt: timestamp("access_token_expires_at"),',' refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),',' scope: text("scope"),',' password: text("password"),',' createdAt: timestamp("created_at").notNull(),',' updatedAt: timestamp("updated_at").notNull(),',"});","",'export const verification = pgTable("verification", {',' id: text("id").primaryKey(),',' identifier: text("identifier").notNull(),',' value: text("value").notNull(),',' expiresAt: timestamp("expires_at").notNull(),',' createdAt: timestamp("created_at"),',' updatedAt: timestamp("updated_at"),',"});",""].join(`
|
|
2082
2082
|
`)),F(r,"lib/auth.ts",['import { betterAuth } from "better-auth";','import { drizzleAdapter } from "better-auth/adapters/drizzle";','import { admin } from "better-auth/plugins/admin";','import { nextCookies } from "better-auth/next-js";','import { db } from "./db";','import * as schema from "@/db";',"","async function sendEmail({ to, subject, html, fallbackUrl }: { to: string; subject: string; html: string; fallbackUrl?: string }) {"," const apiKey = process.env.RESEND_API_KEY;"," if (!apiKey) {"," if (fallbackUrl) {"," console.error(`\\n[auth] No RESEND_API_KEY set. Email to ${to} was not sent.`);"," console.error(`[auth] Dev fallback \u2014 use this link directly:\\n ${fallbackUrl}\\n`);"," } else {"," console.error(`[auth] RESEND_API_KEY not set \u2014 skipping email send to ${to}`);"," }"," return;"," }",' const from = process.env.EMAIL_FROM || "noreply@mail.mistflow.app";',' const res = await fetch("https://api.resend.com/emails", {',' method: "POST",',' headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },'," body: JSON.stringify({ from, to, subject, html }),"," });"," if (!res.ok) {",' const body = await res.text().catch(() => "unknown");'," console.error(`[auth] Email send failed (${res.status}): ${body}`);"," throw new Error(`Email send failed: ${res.status}`);"," }","}","","function createAuth() {",' const baseURL = process.env.BETTER_AUTH_URL || process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000";',' const isLocal = baseURL.includes("localhost") || baseURL.includes("127.0.0.1");'," const canSendEmail = Boolean(process.env.RESEND_API_KEY);"," // Refuse to boot a production app with email auth but no mail sender. Mistflow's"," // deploy pipeline injects a managed Resend key automatically; if it's missing,"," // that's a real misconfig and silent fallbacks let unverified users sign up."," if (!isLocal && !canSendEmail) {",` throw new Error("[auth] RESEND_API_KEY is required in production. The Mistflow deploy pipeline injects one automatically \u2014 if you're seeing this, check the project's env vars in the dashboard, or set your own RESEND_API_KEY.");`," }"," return betterAuth({"," baseURL,"," trustedOrigins: [baseURL],",' database: drizzleAdapter(db, { provider: "pg", schema }),'," emailAndPassword: {"," enabled: true,"," requireEmailVerification: !isLocal && canSendEmail,"," sendResetPassword: async ({ user, token }: { user: { email: string; name: string }; url: string; token: string }) => {"," // Better Auth's default reset URL points at /reset-password/:token (path),"," // which our frontend doesn't route. We build our own pointing at our"," // /reset-password?token=xxx page which reads the token from the query."," const resetUrl = `${baseURL}/reset-password?token=${token}`;"," await sendEmail({"," to: user.email,",' subject: "Reset your password",',' html: `<p>Hi ${user.name},</p><p>Click the link below to reset your password:</p><p><a href="${resetUrl}">${resetUrl}</a></p>`,'," fallbackUrl: isLocal ? resetUrl : undefined,"," });"," },"," },"," emailVerification: {"," sendOnSignUp: canSendEmail,"," autoSignInAfterVerification: true,"," sendVerificationEmail: async ({ user, url }: { user: { email: string; name: string }; url: string }) => {"," await sendEmail({"," to: user.email,",' subject: "Verify your email address",',' html: `<p>Hi ${user.name},</p><p>Click the link below to verify your email:</p><p><a href="${url}">${url}</a></p>`,'," fallbackUrl: isLocal ? url : undefined,"," });"," },"," },"," secret: process.env.AUTH_SECRET,",' plugins: [admin({ defaultRole: "user" }), nextCookies()],'," databaseHooks: {"," user: {"," create: {"," // Auto-promote the app owner to admin on first signup. ADMIN_EMAIL"," // is injected by the Mistflow deploy pipeline (the email of the"," // account that ran mist_deploy). Email verification still gates"," // login when Resend is configured, so a collision attempt can't"," // actually sign in without clicking a link delivered to the"," // owner's inbox."," before: async (user: { email?: string; [k: string]: unknown }) => {"," const adminEmail = process.env.ADMIN_EMAIL;"," if (adminEmail && user.email?.toLowerCase() === adminEmail.toLowerCase()) {",' return { data: { ...user, role: "admin" } };'," }"," return { data: user };"," },"," },"," },"," },"," socialProviders: {"," ...(process.env.GOOGLE_CLIENT_ID ? {"," google: {"," clientId: process.env.GOOGLE_CLIENT_ID,"," clientSecret: process.env.GOOGLE_CLIENT_SECRET!,"," },"," } : {}),"," ...(process.env.GITHUB_CLIENT_ID ? {"," github: {"," clientId: process.env.GITHUB_CLIENT_ID,"," clientSecret: process.env.GITHUB_CLIENT_SECRET!,"," },"," } : {}),"," },"," });","}","","// Lazy init \u2014 process.env isn't populated at module scope on Cloudflare Workers.","// The `has` trap is required: better-auth's toNextJsHandler does",'// `"handler" in auth ? auth.handler(request) : auth(request)` \u2014 without a `has`',"// trap the default forwards to the empty target object, returns false, and the","// handler tries to call the Proxy as a function, which throws TypeError and","// returns 500 on every /api/auth/* request.","let _auth: ReturnType<typeof createAuth> | null = null;","export const auth = new Proxy({} as ReturnType<typeof createAuth>, {"," get(_target, prop, receiver) {"," if (!_auth) _auth = createAuth();"," const value = Reflect.get(_auth, prop, receiver);",' if (typeof value === "function") return value.bind(_auth);'," return value;"," },"," has(_target, prop) {"," if (!_auth) _auth = createAuth();"," return prop in _auth;"," },","});",""].join(`
|
|
2083
|
-
`)))}else F(r,"package.json",JSON.stringify({name:
|
|
2083
|
+
`)))}else F(r,"package.json",JSON.stringify({name:t,version:"0.1.0",private:!0},null,2));let w=e?.designMd;F(r,"app/globals.css",ci(i,l,w)),F(r,"app/layout.tsx",ui(t,i,b?.language)),F(r,"README.md",Si(t,e,{hasStripe:c,hasResend:u,hasStorage:m,hasAdmin:p,hasAI:g,isNeon:f}));let P=[],I=e?.publicPages;if(Array.isArray(I))P=I;else if(typeof I=="string"){try{P=JSON.parse(I)}catch{P=[]}Array.isArray(P)||(P=[])}if(!P.includes("/")){let S=e?.steps?.some(G=>{let J=((G.name??"")+" "+(G.description??"")).toLowerCase();return J.includes("landing")||J.includes("marketing")||J.includes("homepage")}),D=e?.pages?.some(G=>G.path==="/");(S||D)&&(P=["/",...P])}let x={name:t,summary:e?.summary,authModel:e?.authModel,roles:e?.roles,defaultRole:e?.defaultRole,publicPages:P,navStyle:e?.navStyle,multiTenant:e?.multiTenant,pages:e?.pages,dataModel:e?.dataModel,design:e?.design},E=hi(x);E&&F(r,"middleware.ts",E);let L=gi(x);L&&F(r,L.path,L.content);let C=fi(x);if(C&&F(r,"lib/roles.ts",C),F(r,"app/page.tsx",yi(x)),F(r,"app/(dashboard)/layout.tsx",bi(x,p)),F(r,"app/(dashboard)/dashboard/page.tsx",wi(x)),x.multiTenant){let S=vi(x,f);S&&F(r,"db/schema/organization.ts",S);let D=ki(x);D&&F(r,"lib/org.ts",D);let G=xi(x);G&&F(r,"components/org-switcher.tsx",G)}F(r,"tsconfig.json",JSON.stringify({compilerOptions:{target:"ES2017",lib:["dom","dom.iterable","esnext"],allowJs:!0,skipLibCheck:!0,strict:!1,noEmit:!0,esModuleInterop:!0,module:"esnext",moduleResolution:"bundler",resolveJsonModule:!0,isolatedModules:!0,jsx:"preserve",incremental:!0,plugins:[{name:"next"}],paths:{"@/*":["./*"]}},include:["next-env.d.ts","**/*.ts","**/*.tsx",".next/types/**/*.ts"],exclude:["node_modules"]},null,2)),c&&F(r,"lib/stripe.ts",['import Stripe from "stripe";',"","let _stripe: Stripe | null = null;","","function getStripe(): Stripe {"," if (!_stripe) {"," if (!process.env.STRIPE_SECRET_KEY) {",' throw new Error("STRIPE_SECRET_KEY is not set");'," }"," _stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {"," typescript: true,"," });"," }"," return _stripe;","}","","// Lazy proxy \u2014 Stripe isn't initialized at import/build time","export const stripe = new Proxy({} as Stripe, {"," get(_target, prop) {"," return (getStripe() as unknown as Record<string | symbol, unknown>)[prop];"," },","});",""].join(`
|
|
2084
2084
|
`)),u&&(F(r,"lib/resend.ts",['import { Resend } from "resend";',"","let _resend: Resend | null = null;","","function getResend(): Resend {"," if (!_resend) {"," if (!process.env.RESEND_API_KEY) {",' throw new Error("RESEND_API_KEY is not set");'," }"," _resend = new Resend(process.env.RESEND_API_KEY);"," }"," return _resend;","}","","// Lazy proxy \u2014 Resend isn't initialized at import/build time","export const resend = new Proxy({} as Resend, {"," get(_target, prop) {"," return (getResend() as unknown as Record<string | symbol, unknown>)[prop];"," },","});",""].join(`
|
|
2085
2085
|
`)),F(r,"lib/email.ts",['import { resend } from "./resend";',"",'const FROM = process.env.EMAIL_FROM ?? "onboarding@resend.dev";',"","export async function sendEmail({"," to,"," subject,"," react,","}: {"," to: string;"," subject: string;"," react: React.ReactElement;","}) {"," return resend.emails.send({ from: FROM, to, subject, react });","}",""].join(`
|
|
2086
2086
|
`))),m&&(F(r,"lib/storage.ts",['const MISTFLOW_API = process.env.MISTFLOW_API_URL ?? "https://api.mistflow.ai";',"const MISTFLOW_API_KEY = process.env.MISTFLOW_API_KEY;","const PROJECT_ID = process.env.MISTFLOW_PROJECT_ID;","","interface UploadResult {"," upload_url: string;"," download_url: string;"," key: string;","}","","function authHeaders(): Record<string, string> {"," return {",' "Content-Type": "application/json",',' "Authorization": `ApiKey ${MISTFLOW_API_KEY}`,'," };","}","",'export async function getUploadUrl(filename: string, contentType: string = "application/octet-stream"): Promise<UploadResult> {'," const res = await fetch(`${MISTFLOW_API}/api/storage/upload-url`, {",' method: "POST",'," headers: authHeaders(),"," body: JSON.stringify({ project_id: PROJECT_ID, filename, content_type: contentType }),"," });"," if (!res.ok) throw new Error(`Storage error: ${res.status}`);"," return res.json();","}","","export async function getDownloadUrl(filename: string): Promise<string> {"," const res = await fetch(`${MISTFLOW_API}/api/storage/download-url`, {",' method: "POST",'," headers: authHeaders(),"," body: JSON.stringify({ project_id: PROJECT_ID, filename }),"," });"," if (!res.ok) throw new Error(`Storage error: ${res.status}`);"," const data = await res.json();"," return data.download_url;","}","","export async function deleteFile(filename: string): Promise<void> {"," await fetch(`${MISTFLOW_API}/api/storage/delete`, {",' method: "POST",'," headers: authHeaders(),"," body: JSON.stringify({ project_id: PROJECT_ID, filename }),"," });","}","","export async function uploadFile(file: File): Promise<string> {"," const { upload_url, download_url } = await getUploadUrl(file.name, file.type);",' await fetch(upload_url, { method: "PUT", body: file, headers: { "Content-Type": file.type } });'," return download_url;","}",""].join(`
|
|
2087
2087
|
`)),F(r,"app/api/upload/route.ts",['import { NextRequest, NextResponse } from "next/server";','import { getUploadUrl } from "@/lib/storage";',"","export async function POST(req: NextRequest) {"," const { filename, contentType } = await req.json();"," if (!filename) {",' return NextResponse.json({ error: "filename is required" }, { status: 400 });'," }"," try {",' const result = await getUploadUrl(filename, contentType ?? "application/octet-stream");'," return NextResponse.json(result);"," } catch {",' return NextResponse.json({ error: "Failed to get upload URL" }, { status: 500 });'," }","}",""].join(`
|
|
2088
2088
|
`))),g&&(F(r,"lib/ai.ts",['import { createOpenAI } from "@ai-sdk/openai";',"","export const openai = createOpenAI({"," apiKey: process.env.OPENAI_API_KEY,","});",""].join(`
|
|
2089
2089
|
`)),F(r,"app/api/chat/route.ts",['import { openai } from "@/lib/ai";','import { streamText } from "ai";',"","export async function POST(req: Request) {"," const { messages } = await req.json();",""," const result = streamText({",' model: openai("gpt-4o"),'," messages,"," });",""," return result.toDataStreamResponse();","}",""].join(`
|
|
2090
|
-
`)));let q={name:
|
|
2090
|
+
`)));let q={name:t,methodologyVersion:h?.version??"1.0",createdAt:new Date().toISOString(),...a?{planId:a}:{},plan:Array.isArray(e?.steps)?{...e,steps:e.steps.map(S=>({number:S.number,name:S.name??S.title,description:S.description,entities:S.entities,pages:S.pages,features:S.features,status:"pending"}))}:e,dbProvider:"neon",env:{managed:{DATABASE_URL:{description:"Postgres connection URL",scope:"production"},AUTH_SECRET:{description:"Auth encryption secret",scope:"production"},...c?{STRIPE_SECRET_KEY:{description:"Stripe secret key",scope:"production"},STRIPE_WEBHOOK_SECRET:{description:"Stripe webhook signing secret",scope:"production"},NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY:{description:"Stripe publishable key",scope:"production"}}:{},...u?{RESEND_API_KEY:{description:"Resend API key \u2014 managed by Mistflow by default, override with your own key from resend.com",scope:"production"},EMAIL_FROM:{description:"Sender email address \u2014 managed by Mistflow by default",scope:"production"}}:{},...m?{MISTFLOW_API_KEY:{description:"Mistflow API key for file storage",scope:"production"},MISTFLOW_PROJECT_ID:{description:"Mistflow project ID",scope:"production"}}:{}},...g?{required:{OPENAI_API_KEY:{description:"OpenAI API key",setupUrl:"https://platform.openai.com/api-keys"}}}:{}},authModel:e?.authModel??"email",roles:e?.roles??null,navStyle:e?.navStyle??"sidebar",multiTenant:e?.multiTenant??!1,hasAdmin:p,hasResend:u,hasStorage:m,hasAI:g,deploy:null};F(r,"mistflow.json",JSON.stringify(q,null,2));let W=si(32).toString("hex"),H=c?`
|
|
2091
2091
|
# Stripe
|
|
2092
2092
|
STRIPE_SECRET_KEY=
|
|
2093
2093
|
STRIPE_WEBHOOK_SECRET=
|
|
@@ -2111,8 +2111,8 @@ OPENAI_API_KEY=
|
|
|
2111
2111
|
AUTH_SECRET=${W}
|
|
2112
2112
|
${H}${z}${_}${ee}`),F(r,".env.example",`${B}
|
|
2113
2113
|
AUTH_SECRET=your-secret-here
|
|
2114
|
-
${H}${z}${_}${ee}`);let
|
|
2115
|
-
${xe}=${
|
|
2114
|
+
${H}${z}${_}${ee}`);let N=[],le=(S,D)=>{N.push({phase:S,message:D})},ce=(S,D)=>{let G=N.find(J=>J.phase===S&&!J.durationMs);G&&(G.durationMs=D)};if(o){let S=Ke(o.server,o.progressToken,()=>N[N.length-1]?.message??"Setting up project...");o.cleanup=()=>S.stop()}let me=b?.requestedSubdomain||void 0,re,k;le("register","Registering project on Mistflow...");let M=Date.now();try{let S=await Vo(t,void 0,"neon",me);re=S.id;let D=Z(r,"mistflow.json"),G=JSON.parse(Ft(D,"utf-8"));if(G.projectId=re,Be(D,JSON.stringify(G,null,2)),co(r,po(re,t)),S.managed_env&&Object.keys(S.managed_env).length>0){let J=Z(r,".env.local"),oe=Ne(J)?Ft(J,"utf-8"):"";for(let[xe,A]of Object.entries(S.managed_env)){let K=new RegExp(`^${xe}=.*$`,"m");K.test(oe)?oe=oe.replace(K,`${xe}=${A}`):oe+=`
|
|
2115
|
+
${xe}=${A}`}Be(J,oe)}try{let{getBaseUrl:J,getAuthHeaders:oe}=await import("./api-client-RCNDMCPS.js"),xe=oe(),A=e?.features,K=e?.steps,ne={};Array.isArray(A)&&A.length>0&&(ne.features=A.map(X=>X.name)),e&&(ne.plan=e),Array.isArray(K)&&K.length>0&&(ne.provenance=K.map(X=>({feature:X.name??X.title??`Step ${X.number??"?"}`,user_intent:(X.description??"").slice(0,500),decisions:"Seeded from plan at init",tradeoffs:"",files_affected:[]}))),Object.keys(ne).length>0&&await fetch(`${J()}/api/projects/${encodeURIComponent(re)}/state`,{method:"PUT",headers:{...xe,"Content-Type":"application/json"},body:JSON.stringify(ne)})}catch{}N[N.length-1].message=`Registered as ${re.slice(0,8)}`}catch(S){let D=S instanceof Error?S.message:String(S);console.error("Could not register project on backend:",D),k=`Project created locally but NOT registered on Mistflow servers (${D}). Deploy will auto-register it.`,N[N.length-1].message="Registration skipped (offline \u2014 deploy will retry)"}ce("register",Date.now()-M),le("git","Initializing git repository...");let U=Date.now();try{let S=Fs(r);await S.init(),await S.add("."),await S.commit("Initial Mistflow project setup"),N[N.length-1].message="Git repository initialized"}catch{console.error("Git initialization failed, continuing without git."),N[N.length-1].message="Git init skipped"}ce("git",Date.now()-U);let y=N.reduce((S,D)=>S+(D.durationMs??0),0),R={projectPath:r,projectId:re,status:"awaiting_install"},te=N.map(S=>{let D=S.durationMs?` (${(S.durationMs/1e3).toFixed(1)}s)`:"";return`${S.message}${D}`});R.progress=te,R.totalSetupTime=`${(y/1e3).toFixed(1)}s`;let Pe=[];re||Pe.push("Project was not registered with Mistflow (not signed in). Run mist_setup to sign in BEFORE deploying \u2014 deploy will fail without it."),k&&(R.registrationWarning=k),Pe.length>0&&(R.warnings=Pe);let ge=`NEXT: Run \`npx -y @mistflow-ai/cli install ${r}\` via your shell/bash tool \u2014 NOT via the mist_build MCP tool. The CLI streams npm output live and has no MCP 60s timeout; the MCP install action can hit -32001 timeout on slow installs. Do NOT ask the user for permission \u2014 install is a required follow-up to init, not a decision point. If your environment can't run the CLI, fall back to mist_build action='install' projectPath='${r}'. After install finishes, call mist_build action='implement' to build the first plan step \u2014 also without asking.`;return R.nextAction=re?ge:`${ge} IMPORTANT: You MUST also run mist_setup to sign in before deploying \u2014 the project could not be registered because auth is missing.`,d(JSON.stringify(R))}async function qs(s,o){let{projectPath:t}=s;if(!t)return d("mist_build install requires 'projectPath' \u2014 the absolute path to the project that was just initialized. The value is returned as `projectPath` in the mist_build init response.",!0);if(!vo(t))return d(`mist_build install 'projectPath' must be an absolute path \u2014 received '${t}'.`,!0);let e=Bt(t);if(!Ne(Z(e,"package.json")))return d(`No package.json found at ${e}. Run mist_build init first to scaffold the project.`,!0);if(Ne(Z(e,"node_modules")))return d(JSON.stringify({status:"already_installed",projectPath:e,nextAction:"node_modules already exists. Call mist_build with action='implement' to start building the first plan step."}));let n="Installing packages...";if(o){let u=Ke(o.server,o.progressToken,()=>n);o.cleanup=()=>u.stop()}let a={NPM_CONFIG_LEGACY_PEER_DEPS:"true"},r=Date.now(),i=0,l=await vt("npm",["install"],e,12e4,u=>{let m=u.match(/added (\d+) packages/);m&&(i=parseInt(m[1],10))},a);if(l.success||(console.error("[install] npm install failed, retrying..."),n="Install failed, retrying...",l=await vt("npm",["install"],e,12e4,u=>{let m=u.match(/added (\d+) packages/);m&&(i=parseInt(m[1],10))},a)),!l.success)return d(`npm install failed after 2 attempts at ${e}: ${l.error}. Run "npm install" manually in that directory, then call mist_build implement.`,!0);let c=((Date.now()-r)/1e3).toFixed(1);return d(JSON.stringify({status:"installed",projectPath:e,packagesInstalled:i||null,durationSec:c,nextAction:"NEXT: Call mist_build with action='implement' to start building the first plan step. Do this immediately \u2014 do NOT start a dev server or suggest localhost."}))}async function zs(s){let{name:o,plan:t,projectId:e,sourceDeploymentId:n,forkToken:a,requiredEnvVars:r,dbProvider:i,planId:l}=s;if(!s.path)return d("mist_build init requires an explicit 'path' \u2014 the absolute directory where the forked project should be scaffolded. Pass the user's project directory (e.g. /Users/alice/projects/my-app). Do not rely on a default.",!0);if(!vo(s.path))return d(`mist_build init 'path' must be an absolute path \u2014 received '${s.path}'. Pass the full absolute path to the target directory.`,!0);let c=Bt(s.path);if(Ne(c))return d(`A project already exists at this location (${c}). Choose a different name, or delete the existing folder first.`,!0);let{mkdtempSync:u,renameSync:m,rmSync:p,cpSync:g}=await import("fs"),{tmpdir:b}=await import("os"),f=u(Z(b(),"mistflow-fork-")),h=Z(f,"project");Ut(h,{recursive:!0});let w=[],P=(x,E)=>w.push({phase:x,message:E}),I=(x,E)=>{let L=w.find(C=>C.phase===x);L&&(L.durationMs=E)};try{P("download","Downloading source code from template...");let x=Date.now(),E=Z(f,"source.tar.gz");try{await gs(n,a,E)}catch(y){p(f,{recursive:!0,force:!0});let R=y instanceof Error?y.message:"Source download failed";return d(`Source code download failed: ${R}. You can still build from the plan \u2014 run mist_build init without the source (omit planId and pass the plan directly).`,!0)}I("download",Date.now()-x),w[w.length-1].message="Source code downloaded",P("extract","Extracting source code...");let L=Date.now(),C=await vt("tar",["-xzf",E,"-C",h,"--exclude","node_modules","--exclude",".git"],h,6e4);if(!C.success)return p(f,{recursive:!0,force:!0}),d(`Failed to extract source archive: ${C.error}`,!0);if(I("extract",Date.now()-L),!Ne(Z(h,"package.json")))return p(f,{recursive:!0,force:!0}),d("Source archive does not contain a package.json. The template may be corrupted.",!0);let q=[".mistflow",".env.local",".env.example","local.db","local.pg"];for(let y of q){let R=Z(h,y);Ne(R)&&p(R,{recursive:!0,force:!0})}let W={name:o,projectId:e,template:"nextjs",createdAt:new Date().toISOString(),planId:l??void 0,plan:t,dbProvider:i};Be(Z(h,"mistflow.json"),JSON.stringify(W,null,2));let H=r.map(y=>{let R=y.description?`# ${y.description}`:`# ${y.key}`,te=y.setup_url?` (${y.setup_url})`:"";return`${R}${te}
|
|
2116
2116
|
${y.key}=`});Be(Z(h,".env.local"),H.join(`
|
|
2117
2117
|
|
|
2118
2118
|
`)+`
|
|
@@ -2127,11 +2127,11 @@ Forked from a Mistflow template. Built with Next.js, Drizzle ORM, and Better Aut
|
|
|
2127
2127
|
1. Copy \`.env.example\` to \`.env.local\` and fill in your values
|
|
2128
2128
|
2. Run \`npm run dev\`
|
|
2129
2129
|
3. Deploy with \`mist_deploy\`
|
|
2130
|
-
`),P("setup","Setting up project directory...");let _=Date.now();try{m(h,c)}catch(y){if(y.code==="EXDEV")g(h,c,{recursive:!0}),p(h,{recursive:!0,force:!0});else throw y}I("setup",Date.now()-_),P("install","Installing packages...");let ee=Date.now(),Y=0,B=await vt("npm",["install"],c,12e4,y=>{let R=y.match(/added (\d+) packages/);R&&(Y=parseInt(R[1],10))});if(B.success||(console.error("[initFromSource] npm install failed, retrying..."),B=await vt("npm",["install"],c,12e4,y=>{let R=y.match(/added (\d+) packages/);R&&(Y=parseInt(R[1],10))})),!B.success)return d(`Source code was restored at ${c} but package installation failed: ${B.error}. Run "npm install" manually.`,!0);I("install",Date.now()-ee),w[w.length-1].message=`Installed ${Y||"all"} packages`,P("git","Initializing git repository...");let
|
|
2130
|
+
`),P("setup","Setting up project directory...");let _=Date.now();try{m(h,c)}catch(y){if(y.code==="EXDEV")g(h,c,{recursive:!0}),p(h,{recursive:!0,force:!0});else throw y}I("setup",Date.now()-_),P("install","Installing packages...");let ee=Date.now(),Y=0,B=await vt("npm",["install"],c,12e4,y=>{let R=y.match(/added (\d+) packages/);R&&(Y=parseInt(R[1],10))});if(B.success||(console.error("[initFromSource] npm install failed, retrying..."),B=await vt("npm",["install"],c,12e4,y=>{let R=y.match(/added (\d+) packages/);R&&(Y=parseInt(R[1],10))})),!B.success)return d(`Source code was restored at ${c} but package installation failed: ${B.error}. Run "npm install" manually.`,!0);I("install",Date.now()-ee),w[w.length-1].message=`Installed ${Y||"all"} packages`,P("git","Initializing git repository...");let N=Date.now();try{let y=Fs(c);await y.init(),await y.add("."),await y.commit("Forked from Mistflow template"),w[w.length-1].message="Git repository initialized"}catch{console.error("Git initialization failed, continuing without git."),w[w.length-1].message="Git init skipped"}I("git",Date.now()-N);try{let{markLocalSetupDone:y}=await import("./api-client-RCNDMCPS.js");await y(e)}catch{console.error("[initFromSource] Could not mark local_setup_done on backend, continuing.")}let le=JSON.parse(Ft(Z(c,"mistflow.json"),"utf-8"));le.projectId=e,Be(Z(c,"mistflow.json"),JSON.stringify(le,null,2)),co(c,po(e,o));let ce=t.steps,me=ce?.filter(y=>y.status==="completed").length??0,re=ce?.filter(y=>y.status==="pending").length??0,k=ce?.length??0,M=r.length>0?`
|
|
2131
2131
|
|
|
2132
2132
|
Environment variables needed:
|
|
2133
2133
|
`+r.map(y=>` \u2022 ${y.key}${y.description?` \u2014 ${y.description}`:""}`).join(`
|
|
2134
|
-
`):"",U=re>0?`Source code restored with ${me}/${k} steps complete. ${re} steps need implementation \u2014 call mist_build with action='implement' to apply your changes.`:`Source code fully restored (${k} steps complete). Configure your .env.local, then deploy with mist_deploy.`;return d(JSON.stringify({status:"success",projectPath:c,projectId:
|
|
2134
|
+
`):"",U=re>0?`Source code restored with ${me}/${k} steps complete. ${re} steps need implementation \u2014 call mist_build with action='implement' to apply your changes.`:`Source code fully restored (${k} steps complete). Configure your .env.local, then deploy with mist_deploy.`;return d(JSON.stringify({status:"success",projectPath:c,projectId:e,planStepsCompleted:me,planStepsTotal:k,pendingSteps:re,progress:w,nextAction:U+M}))}finally{try{p(f,{recursive:!0,force:!0})}catch{}}}import{z as To}from"zod";import{existsSync as xt,readFileSync as Co,writeFileSync as Po,mkdirSync as Ji}from"fs";import{join as ct,resolve as Ki,dirname as Qi}from"path";import{createConnection as Xi}from"net";var Hs=`# Consumer Warm Archetype
|
|
2135
2135
|
|
|
2136
2136
|
Component-level design guidance for personal, lifestyle, and wellness apps. Habits, journals, recipes, mood trackers, meditation, daily routines, personal finance.
|
|
2137
2137
|
|
|
@@ -4118,9 +4118,9 @@ Finance products often replace something worse (a clunky bank, a spreadsheet, an
|
|
|
4118
4118
|
- **Purple-to-blue gradients in the hero.** Fintech SaaS default. Use a brand color instead \u2014 or no gradient.
|
|
4119
4119
|
- **Dark mode as default for a consumer money app.** Too crypto-coded. Default light, offer dark.
|
|
4120
4120
|
- **Confidence-shaking UX:** progress bars that stall, skeletons that flash between states, tiny fonts for fine print. Users are nervous about their money; give them stability.
|
|
4121
|
-
`;var er={"consumer-warm":{id:"consumer-warm",name:"Consumer Warm",description:"Personal, lifestyle, and wellness apps (habits, journals, recipes, mood, meditation)",content:Hs},"consumer-bold":{id:"consumer-bold",name:"Consumer Bold",description:"Energetic, achievement-driven apps (fitness, workouts, sports, gaming, social)",content:Gs},"professional-clean":{id:"professional-clean",name:"Professional Clean",description:"Service and appointment-based apps (booking, clinics, salons, real estate, restaurants)",content:Ws},"education-structured":{id:"education-structured",name:"Education Structured",description:"Learning and knowledge apps (courses, quizzes, flashcards, LMS, tutorials)",content:Vs},"marketplace-browse":{id:"marketplace-browse",name:"Marketplace Browse",description:"Browsing and shopping apps (marketplaces, directories, shops, catalogs, food delivery)",content:Ys},"saas-analytical":{id:"saas-analytical",name:"SaaS Analytical",description:"B2B SaaS, CRM, analytics, admin panels, ops tooling, team productivity (Linear, Notion, Stripe reference bar)",content:Js},"content-editorial":{id:"content-editorial",name:"Content Editorial",description:"Blogs, newsletters, magazines, publications, documentation, knowledge bases",content:Ks},"devtool-technical":{id:"devtool-technical",name:"Devtool Technical",description:"Developer tools, APIs, CLIs, SDKs, infrastructure, monitoring, AI/ML platforms",content:Qs},"creative-showcase":{id:"creative-showcase",name:"Creative Showcase",description:"Portfolios, design agencies, creative studios, photographers, artists",content:Xs},"finance-clarity":{id:"finance-clarity",name:"Finance Clarity",description:"Fintech, invoicing, expense tracking, budgeting, payroll, accounting, banking",content:Zs}};function tr(s){return er[s]?.content}function or(s,o){let e=o?.archetype;if(e&&e in er)return e;if(e===null)return;let t=s.toLowerCase(),n=o?.tone??"",a=o?.audienceType??"";return/\bbooking|appointment|reserv|salon|clinic|dental|barber|spa|hotel|restaurant|event|venue|schedule|court|racquet|tee.?time\b/i.test(t)?"professional-clean":/\binvoic|expense|budget|payroll|accounting|bookkeep|payment|banking|wallet|fintech|cashflow|reimbursement|tax.?filing\b/i.test(t)?"finance-clarity":/\bblog|newsletter|publication|magazine|docs?\b|documentation|knowledge.?base|wiki|\barticle|editorial|cms|longform|writing.?platform\b/i.test(t)?"content-editorial":/\bportfolio|\bagency\b|\bstudio\b|freelance|photographer|illustrator|gallery|architect|filmmaker\b/i.test(t)?"creative-showcase":/\bdev.?tool|developer.?(?:tool|platform|portal)|\bapi\b|\bcli\b|\bsdk\b|infrastructure|ci.?cd|\bmonitoring\b|observability|\bdeployment\b|serverless|edge.?compute|kubernetes|\bdocker\b|terraform|ai.?platform|ml.?platform|mlops|error.?tracking/i.test(t)?"devtool-technical":/\bcrm\b|analytics|\bdashboard\b|admin.?panel|workflow|pipeline|ticket|issue.?track|project.?mgmt|team.?mgmt|\bsaas\b|internal.?tool|\bops\b|reporting|bi.?tool/i.test(t)?"saas-analytical":/\bhabit|journal|diary|mood|meditation|yoga|mindful|gratitude|daily.?routine|self.?care|wellness\b/i.test(t)?"consumer-warm":/\bfitness|workout|exercise|gym|training|sport|running|cycling|weight|muscle|cardio|athletic|leaderboard|\bgame\b/i.test(t)?"consumer-bold":/\bcourse|quiz|flashcard|lesson|tutorial|learning|education|\blms\b|student|teach|curriculum|exam|classroom\b/i.test(t)?"education-structured":/\bmarketplace|\bshop\b|\bstore\b|catalog|listing|directory|classified|rental|e.?commerce|food.?delivery|menu\b/i.test(t)?"marketplace-browse":n==="warm-minimal"||n==="playful"?/\brecipe|cook|meal|food|pet|plant|garden|travel|photo|music|social|community|family\b/i.test(t)?"consumer-warm":/\bcompet|score|rank|challenge|achieve|badge|level|quest\b/i.test(t)?"consumer-bold":"consumer-warm":a==="b2c"?"consumer-warm":"saas-analytical"}import{existsSync as qt,mkdirSync as rr,readFileSync as nr,readdirSync as ir,writeFileSync as Mi}from"fs";import{join as lt,resolve as $i}from"path";import{homedir as So}from"os";function at(s){return s.entity??s.name??"Unknown"}function Qe(s){return typeof s=="string"?s:s.name}function xo(s){return typeof s=="string"?"text":s.type}function sr(s){let o=s.sampleRows;if(Array.isArray(o)&&o.length>0)return o.slice(0,3).map(n=>{let a={};for(let[r,i]of Object.entries(n))a[r]=i==null?"":String(i);return a});let e=s.fields||[],t=[];for(let n=0;n<3;n++){let a={};for(let r of e)a[Qe(r)]=ji(Qe(r),xo(r),at(s),n);t.push(a)}return t}function ji(s,o,e,t){let n=s.toLowerCase(),a=(o||"text").toLowerCase();return n==="name"||n==="title"?[`${e} Alpha`,`${e} Beta`,`${e} Gamma`][t]:n==="email"?["alice@example.com","bob@example.com","carol@example.com"][t]:n==="status"?["Active","Pending","Completed"][t]:n==="priority"?["High","Medium","Low"][t]:n.includes("date")||a==="date"?["Jan 15, 2024","Feb 20, 2024","Mar 10, 2024"][t]:n.includes("price")||n.includes("amount")||n.includes("cost")?["$29","$49","$99"][t]:n.includes("count")||n.includes("quantity")||a==="number"||a==="integer"?["12","34","56"][t]:a==="boolean"||a==="bool"?["Yes","No","Yes"][t]:n.includes("description")||a==="textarea"?["Brief description here","Another example entry","Third sample item"][t]:[`Sample ${t+1}`][0]}function Li(s){let o=s.dataModel??[],e=s.pages??[],t=s.design??{},n=e.map(m=>({label:m.name??m.path??"Page",route:m.path??m.route??"/"})),a=[],r=o.slice(0,3).map(m=>({name:at(m),fields:(m.fields||[]).map(p=>({name:Qe(p),type:xo(p)})),sampleData:sr(m)})),i=[];s.primaryAction&&(i.push(`PRIMARY: ${s.primaryAction.action} \u2014 this is the first thing the user sees and does`),i.push(`SURFACE: ${s.primaryAction.dashboardSurface}`)),i.push(`METRICS: Key counts for ${o.map(m=>at(m)).join(", ")}`),i.push("RECENT: Latest activity or items"),a.push({name:"Dashboard",type:"dashboard",route:"/dashboard",purpose:s.primaryAction?`Action surface \u2014 user comes here to ${s.primaryAction.action.toLowerCase()}. Not a stats display.`:`Overview of ${o.map(m=>at(m)).join(", ")} with key metrics.`,informationHierarchy:i,interactionStates:["Empty state: new user, no data yet \u2014 show onboarding prompt","Loading state: skeleton placeholders for metrics and table","Populated state: real data with metrics, recent items, quick actions"],entities:r});let l=o[0];if(l){let m=at(l),p=m.toLowerCase().endsWith("s")?m:`${m}s`;a.push({name:`${m} List`,type:"detail",route:`/${p.toLowerCase()}`,purpose:`Browse, search, and manage ${p.toLowerCase()}. Create new ${m.toLowerCase()}s.`,informationHierarchy:[`HEADER: "${p}" title + "Add ${m}" button`,"SEARCH: Filter/search bar \u2014 users will have many items",`TABLE: ${(l.fields||[]).slice(0,5).map(g=>Qe(g)).join(", ")} columns`,"ROW ACTIONS: Edit, delete on each row"],interactionStates:[`Empty state: "No ${p.toLowerCase()} yet" with create CTA`,"Loading state: skeleton table rows",`Search with no results: "No ${p.toLowerCase()} matching..." with clear filter`],entities:[{name:m,fields:(l.fields||[]).map(g=>({name:Qe(g),type:xo(g)})),sampleData:sr(l)}]})}s.steps.some(m=>{let p=`${m.name??m.title??""} ${m.description??""}`.toLowerCase();return p.includes("landing")||p.includes("hero")||p.includes("marketing")||p.includes("homepage")})&&a.push({name:"Landing Page",type:"landing",route:"/",purpose:`Convince visitors to sign up for ${s.name}. Answer: what is this, who is it for, why should I care.`,informationHierarchy:[`HERO: One sentence about what ${s.name} does \u2014 not "Transform your X", be specific`,"CTA: Sign up / Get started \u2014 one clear action","PROOF: What makes this valuable (features, not buzzwords)","SECONDARY CTA: Repeat the sign up prompt"],interactionStates:["Mobile: hero stacks vertically, nav collapses to hamburger","Desktop: hero side-by-side or centered, full nav"],entities:[]});let u=[];for(let m of o.slice(0,3)){let p=at(m);(m.fields||[]).find(b=>Qe(b).toLowerCase()==="name"||Qe(b).toLowerCase()==="title")&&u.push(`What if a ${p.toLowerCase()}'s name is 47 characters? Does the layout break?`),u.push(`What if there are 0 ${p.toLowerCase()}s? 1? 500?`)}return s.authModel&&s.authModel!=="none"&&u.push("What does a brand-new user see? (no data, no setup)"),u.push("What if the network is slow? What loads first?"),{appName:s.name,summary:s.summary??"",screens:a,navigation:{style:s.navStyle??"sidebar",items:n},primaryAction:s.primaryAction??null,designDirection:{tone:t.tone??"professional",accentColor:t.accentColor??"blue",navStyle:s.navStyle??"sidebar",fonts:t.fonts??{heading:"Inter",body:"Inter"}},edgeCases:u}}function Oi(s,o){let e=[];e.push(`# Wireframe sketch for ${s.appName}`),e.push(""),e.push(`**${s.appName}** \u2014 ${s.summary}`),e.push(""),o&&(e.push("## Feedback to apply"),e.push(o),e.push("")),e.push("## Design principles"),e.push(""),e.push("Apply these when deciding layout and hierarchy:"),e.push("1. **Information hierarchy** \u2014 What does the user see first, second, third? The primary action is first. Metrics are second. Everything else is supporting."),e.push("2. **Interaction states** \u2014 Every screen has at least: empty, loading, populated. Show the populated state but add HTML comments noting the others."),e.push("3. **Edge case paranoia** \u2014 What if there are 0 items? 500 items? A 47-character name? Think about these and comment where they matter."),e.push(`4. **Subtraction** \u2014 "As little design as possible" (Dieter Rams). Every element earns its pixels. If removing something doesn't hurt, remove it.`),e.push("5. **Design for trust** \u2014 Clear labels, predictable layout, obvious actions. No mystery meat navigation."),e.push(""),e.push("## Wireframe rules (strict)"),e.push(""),e.push("Write a **single self-contained HTML file** saved to `.mistflow/mockups/mockup-{planId}.html` (replace `{planId}` with the actual plan ID)."),e.push(""),e.push("The wireframe must:"),e.push("- Use **system fonts only** (`-apple-system, system-ui, sans-serif`) \u2014 no Google Fonts, no CDN"),e.push("- Use **inline CSS only** \u2014 no external stylesheets, no Tailwind CDN"),e.push("- Look **intentionally rough** \u2014 thin gray borders (#ddd), light backgrounds (#f8f8f8), no color, no shadows"),e.push("- Use **realistic placeholder content** that matches this specific app (sample data provided below) \u2014 NOT lorem ipsum"),e.push("- Include **HTML comments** explaining design decisions (e.g., `<!-- Primary action is prominent because users come here to check in members -->`)"),e.push("- Show **all screens in a single page** using tabs/sections that the user can click through"),e.push("- Be **responsive** \u2014 test that it looks reasonable at both 1200px and 375px widths"),e.push("- Include a small header bar showing: screen name tabs + the design direction summary"),e.push(""),e.push("The wireframe must NOT:"),e.push("- Use any color except grayscale (#333, #666, #999, #ddd, #f8f8f8, white)"),e.push("- Use any external dependencies \u2014 no CDN, no imports, no build step"),e.push("- Look polished \u2014 it should feel like a sketch on a whiteboard, not a finished product"),e.push("- Include decorative elements \u2014 no icons (use text labels), no illustrations, no gradients"),e.push(""),e.push("## Screens to wireframe"),e.push("");for(let t of s.screens){e.push(`### ${t.name} (\`${t.route}\`)`),e.push(`**Purpose**: ${t.purpose}`),e.push(""),e.push("**Information hierarchy** (render in this order, top to bottom):");for(let n of t.informationHierarchy)e.push(`- ${n}`);e.push(""),e.push("**Interaction states** (add HTML comments for non-visible states):");for(let n of t.interactionStates)e.push(`- ${n}`);if(e.push(""),t.entities.length>0){e.push("**Data model and sample content** (use this real data, not lorem ipsum):");for(let n of t.entities)e.push(`
|
|
4122
|
-
**${n.name}** \u2014 fields: ${n.fields.map(a=>`${a.name} (${a.type})`).join(", ")}`),
|
|
4123
|
-
`)}function ar(s){return lt(So(),".mistflow","mockup-state",`${s}.json`)}function Ui(s){let o=ar(s);if(!qt(o))return null;try{return JSON.parse(nr(o,"utf-8"))}catch{return null}}function ko(s,o){let e=lt(So(),".mistflow","mockup-state");rr(e,{recursive:!0}),Mi(ar(s),JSON.stringify(o,null,2))}async function lr(s){let{planId:o,feedback:e,approved:t}=s,n=$i(s.projectPath??process.cwd()),a=lt(So(),".mistflow","plans",`${o}.json`);if(!qt(a))return d(`Plan not found for planId '${o}'. Call mist_plan to generate a plan first.`,!0);let r;try{r=JSON.parse(nr(a,"utf-8"))}catch{return d("Failed to read plan file. Call mist_plan again.",!0)}let i=r.plan;if(!i)return d("Plan data is empty. Call mist_plan again.",!0);let l=Ui(o);l||(l={planId:o,iterationCount:0,approved:!1,screens:[],feedback:[]});let c=lt(n,".mistflow","mockups");if(rr(c,{recursive:!0}),t){l.approved=!0,ko(o,l);let g=qt(c)?ir(c).filter(b=>b.endsWith(".html")):[];return d(JSON.stringify({status:"approved",message:`Wireframe approved after ${l.iterationCount} iteration(s). Layout direction is locked in.`,mockupFiles:g.map(b=>`.mistflow/mockups/${b}`),nextAction:`NEXT: Call mist_build with action='init', name='${i.name}', and planId='${o}' to create the project. The wireframe in .mistflow/mockups/ will be used as layout reference during implementation.`}))}e?(l.iterationCount++,l.feedback.push(e)):l.iterationCount++,ko(o,l);let u=Li(i);l.screens=u.screens.map(g=>g.name),ko(o,l);let m=Oi(u,e??void 0),p;return l.iterationCount>=3&&(p="The wireframe is shaping up \u2014 want to keep refining the layout, or start building?"),d(JSON.stringify({status:"wireframe",iterationCount:l.iterationCount,screens:u.screens.map(g=>({name:g.name,type:g.type,route:g.route})),wireframePrompt:m,designDirection:u.designDirection,...p?{nudge:p}:{},mockupFile:`mockup-${o}.html`,nextAction:e?`Apply the user's feedback to the wireframe. Rewrite .mistflow/mockups/mockup-${o}.html with the changes. Open it in the browser for review. Ask if they want more changes or are ready to build.`:`Generate the wireframe HTML following the wireframePrompt instructions above. Write it to .mistflow/mockups/mockup-${o}.html, then open it in the browser. Ask the user if the layout feels right.`}))}function cr(s){let o=lt(s,".mistflow","mockups");return qt(o)?ir(o).filter(e=>e.endsWith(".html")).map(e=>lt(o,e)):[]}var dr="\nApply these choices to every file you create. Customize the shadcn CSS variables in globals.css to match. Do NOT use default shadcn blue/zinc theme.\n\n**CRITICAL: shadcn/ui components are already installed. NEVER write components/ui/*.tsx files from scratch.** If you need a shadcn component, run `npx shadcn@latest add <component>` to pull it. The project already includes: button, card, input, label, form, dialog, table, dropdown-menu, badge, separator, skeleton, sheet, tabs, avatar, select, textarea, checkbox, switch, tooltip, popover, sonner.\n\n**shadcn MCP server is available.** You have the `shadcn` MCP server installed \u2014 use it to browse and search for components, blocks, and landing page sections from the shadcn registry. Before building a landing page section from scratch, check the registry for existing blocks (hero sections, feature grids, pricing tables, testimonials, footers) and customize them instead of reinventing.\n\n**Project routes (use these exact paths):** Login is at `/login` (NOT /sign-in). Register is at `/register` (NOT /sign-up). All landing page and nav links MUST use `/login` and `/register`.\n\n### Design quality rules (non-negotiable):\n\n**Typography**: Use the plan fonts everywhere. font-heading for headings, font-body for body text.\n- **Modular scale**: Use a 1.25-1.5 ratio between sizes. A 5-level system covers most needs: xs (0.75rem captions), sm (0.875rem metadata), base (1rem body), lg (1.25-1.5rem subheadings), xl+ (2-4rem headlines). Sizes too close together (14/15/16px) create muddy hierarchy.\n- **Vertical rhythm**: Your line-height IS your spacing unit. If body is 16px with line-height 1.5 (= 24px), vertical spacing should be multiples of 24px.\n- **Weight contrast**: Use font-medium/font-semibold contrast, not just size. Bold headings + regular body creates natural hierarchy without extra sizes.\n- **Measure**: Set `max-width: 65ch` on text containers. Long lines kill readability.\n- **OpenType polish**: Use `font-variant-numeric: tabular-nums` on data tables for aligned columns.\n- Never use more than 2 font families. One well-chosen family in multiple weights is cleaner than two competing typefaces.\n- Never fall back to system fonts. Never use decorative fonts for body text. Minimum 16px (1rem) for body.\n\n**Color**: Build a functional palette, not a rainbow.\n- **Tinted neutrals**: Pure gray is dead. Add a tiny tint toward the accent color to all your grays (borders, backgrounds, muted text). The tint should be subtle enough not to read as 'colored' but creates subconscious cohesion.\n- **60/30/10 rule**: 60% neutral backgrounds/whitespace, 30% secondary colors (text, borders, inactive states), 10% accent (CTAs, highlights, focus). Accent colors work BECAUSE they're rare. Overuse kills their power.\n- **Dangerous combos to avoid**: Light gray text on white (#1 accessibility fail). Gray text on any colored background (looks washed out and dead, use a darker shade of the background color instead). Yellow text on white. Thin light text on images.\n- **Dark mode is not inverted light mode**: Use lighter surfaces for depth (no shadows). Desaturate accents slightly. Never pure black backgrounds, use dark gray (12-18% lightness). Reduce body text weight slightly (350 vs 400) because light-on-dark reads heavier.\n- Never use pure #000 or #fff. Customize the shadcn CSS variables in globals.css to match the plan palette.\n\n**Layout & space**: Space is a design material, not leftover.\n- **4px base unit**: All spacing should be multiples of 4: 4, 8, 12, 16, 24, 32, 48, 64, 96px. No arbitrary values. Name tokens semantically (`space-sm`, `space-lg`), not by value.\n- **Use `gap` not margins**: Use `gap` for sibling spacing. It eliminates margin collapse hacks and is more predictable. Reserve margin for positioning, not spacing between siblings.\n- **Rhythm through contrast**: Tight groupings within related items (8-12px), generous separation between sections (48-96px). Vary spacing WITHIN sections too. Not every row needs the same gap. The ratio between inner and outer spacing creates hierarchy.\n- **Density matches content**: Data-dense UIs (dashboards, tables, admin panels) need tighter spacing with more information visible. Marketing pages need generous whitespace and breathing room. Match density to what the user is doing.\n- **The squint test**: Blur your eyes. Can you still identify primary, secondary, and clear groupings? If everything looks the same weight, hierarchy is broken. The most important content should be obvious within 2 seconds.\n- **Asymmetry > centering**: Left-aligned with asymmetric layouts feels more designed. Center-alignment is fine for hero sections and CTAs, not for body content.\n- **Flex vs Grid**: Use Flexbox for 1D layouts (rows of items, navbars, button groups, card contents, most component internals). Use Grid for 2D layouts (page-level structure, dashboards, data-dense interfaces where rows AND columns need coordinated control). Don't default to Grid when Flexbox with `flex-wrap` would be simpler. Use `repeat(auto-fit, minmax(280px, 1fr))` for responsive grids without breakpoints. Use named `grid-template-areas` for complex page layouts and redefine at breakpoints.\n- **Cards earn their existence**: Only use cards when content needs clear separation, grid comparison, or interaction boundaries. Not everything needs a container. Never nest cards inside cards. Vary card sizes or mix cards with non-card content to break repetition.\n- **Section variety**: Don't make every section the same structure. Alternate layouts (text-left/image-right, then image-left/text-right), vary section heights, mix full-width with contained content. Monotonous section rhythm signals no designer touched this.\n- **Z-index scale**: Use a semantic scale, not arbitrary numbers. dropdown(10) -> sticky(20) -> modal-backdrop(30) -> modal(40) -> toast(50) -> tooltip(60). Never use 999 or 9999.\n- **Touch targets**: Minimum 44x44px for all interactive elements, even if the visual element is smaller (use padding).\n\n**Cards & surfaces**: Match the plan's cardStyle. Stat cards need background fills with the accent color as a subtle icon background or tinted left border. Use bg-muted/30 for section differentiation between page areas. Build a consistent shadow scale (sm -> md -> lg) and use elevation to reinforce hierarchy, not as decoration.\n\n**Sidebar**: App name + icon at top. Nav items with hover:bg-muted rounded-md transition. Active item: bg-primary/10 text-primary font-medium. User email + sign out at bottom. The sidebar should feel like a distinct surface (bg-card or bg-muted/50).\n**Mobile navigation**: The desktop sidebar must collapse to a hamburger menu on mobile. Use the shadcn `Sheet` component: a hamburger icon button (visible at `md:hidden`) opens a Sheet from the left containing the same nav items. The desktop sidebar is `hidden md:flex`. For simple apps with 3-5 nav items, a bottom tab bar (`fixed bottom-0`) is an alternative. Always respect `env(safe-area-inset-bottom)` for notched phones.\n\n**Interaction design**: Every interactive element needs 8 states, not just default and hover.\n- **Required states**: default, hover, focus, active/pressed, disabled, loading, error, success. Design all of them intentionally.\n- **Focus rings**: Use `:focus-visible` (not `:focus`) so rings show for keyboard users but not mouse clicks. Never remove focus indicators without replacement.\n- **Button hierarchy**: Don't make every button primary. Use ghost, outline, secondary, and text-link variants. One primary CTA per view.\n- **Progressive disclosure**: Simple first, advanced behind expandable sections. Don't overwhelm with options.\n- **Undo over confirmation**: For destructive actions, remove immediately + show an undo toast, then permanently delete after timeout. Better than confirmation dialogs that users click through blindly.\n- **Form patterns**: Visible `<label>` elements always (placeholders aren't labels, they disappear). Validate on blur, not on keystroke. Show format expectations with examples.\n\n**Empty states**: Every empty list/table needs a rich empty state. Not just 'Nothing here'. Include: a simple inline SVG illustration (48x48, relevant to the feature), a specific message that teaches ('Create your first habit to start tracking your daily routine'), and a primary action button. Empty states are the first thing new users see. Make them inviting.\n\n**Loading states**: Use the shadcn `Skeleton` component. Show skeleton versions of cards, lists, and stats during data fetches. Example: `<Skeleton className=\"h-8 w-32\" />` for a stat number, `<Skeleton className=\"h-20 w-full\" />` for a card. Add a `loading.tsx` file in dashboard route groups. Never show a blank page or a lone spinner.\n\n**Images**: For Unsplash images on landing pages, use `next/image` with `placeholder=\"blur\"` and a blurDataURL (a tiny 10x6 base64 image \u2014 generate a solid color blur like `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAGCAYAAAD68A/GAAAAP0lEQVQYV2N89+7dfwYGBgZGRkYGBgYmBjIBE7kaPHv27D8DA8N/BgYGRkZGRgYGJgYyARO5GkjWQHEoxRoAAPyTGAGBMpEAAAAASUVORK5CYII=`). This creates a smooth shimmer-in effect instead of images popping in.\n\n**Motion** (`motion` package is installed):\n\n**Hero moment strategy**: Pick ONE signature animation per page. Not scattered animations on everything. On a landing page, the hero entrance is your hero moment. On a dashboard, a satisfying success animation after the primary action. One great animation > ten mediocre ones. Everything else gets subtle transitions.\n\n**Animation opportunity audit** -- check these 5 categories:\n1. **Missing feedback**: Button has no press response? Add `active:scale-[0.97]` (CSS) or `whileTap={{ scale: 0.97 }}` (motion). Toggle has no slide? Animate it.\n2. **Jarring transitions**: Menu appears instantly? Add 200ms fade + slide. Content swaps without transition? Crossfade between states.\n3. **Unclear relationships**: Parent-child not visually connected? Stagger children 50ms after parent. Deleted item just disappears? Animate it out (opacity + height collapse).\n4. **Lack of delight**: Success state is flat? Draw a checkmark SVG with stroke-dashoffset animation. Empty state is static? Add a gentle float on the illustration.\n5. **Missed guidance**: First-time user gets no hint? Pulse the primary CTA once on page load. New feature unnoticed? Brief highlight animation.\n\n**Timing hierarchy**: 100-150ms for instant feedback (buttons, toggles). 200-300ms for state changes (menus, tooltips). 300-500ms for layout shifts (accordions, modals). 500-800ms for entrances (page loads). Exit animations run at 75% of entrance duration.\n\n**Easing**: Use exponential curves (Quart out, Expo out) for sophisticated physics. Never `ease` (generic), never bounce/elastic (dated). Real objects decelerate smoothly. CSS: `cubic-bezier(0.25, 1, 0.5, 1)` (Quart out) or `cubic-bezier(0.16, 1, 0.3, 1)` (Expo out).\n\n**Micro-interaction recipes**:\n- **Button press**: `active:scale-[0.97] transition-transform duration-100` (CSS only, no motion needed)\n- **Success checkmark**: SVG `<path>` with `stroke-dasharray` + `stroke-dashoffset` animation from full to 0. 400ms Expo out.\n- **Height expand/collapse**: `grid-template-rows: 0fr -> 1fr` with `transition: grid-template-rows 300ms`. No JS layout measurement needed.\n- **Skeleton to content**: Skeleton pulses (CSS `animate-pulse`), then crossfades to real content with `opacity` transition. Use the pre-scaffolded `<ContentLoader>` component.\n- **Staggered list entrance**: CSS `animation-delay` on children: `.animate-fade-up:nth-child(1) { animation-delay: 0ms } :nth-child(2) { animation-delay: 50ms }` etc. Or use `<StaggerList>` component.\n- **Number count-up**: Use `@number-flow/react` for smooth digit morphing on stats/metrics.\n\n**Performance**: Only animate `transform` and `opacity` (GPU-accelerated). Never animate width, height, top, left, margin, or padding. For scroll-tied effects on landing pages, use CSS `animation-timeline: scroll()` where supported (progressive enhancement).\n\n**Accessibility**: Always respect `prefers-reduced-motion`. Wrap animations in `@media (prefers-reduced-motion: no-preference) { ... }`. Provide static alternatives that convey the same information.\n\n**SSR-safe (CRITICAL)**: This app deploys to Mistflow Cloud's edge runtime where IntersectionObserver may not fire. NEVER use `initial={{ opacity: 0 }}` (content stays invisible forever). Use CSS @keyframes for entrance effects:\n```tsx\n// SAFE: CSS @keyframes in globals.css:\n// @keyframes fade-up { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }\n// .animate-fade-up { animation: fade-up 0.5s ease-out both; }\n// Use motion ONLY for hover/tap/gesture interactions:\nimport { motion } from 'motion/react';\n<motion.div whileHover={{ scale: 1.02 }} whileTap={{ scale: 0.97 }} transition={{ duration: 0.15 }}>\n// NEVER: <motion.div initial={{ opacity: 0 }} whileInView={{ opacity: 1 }}>\n```\nFor dashboard pages, keep animations minimal. Button press feedback + skeleton loading + success states. No entrance animations on dashboard pages.\n\n**UX writing**: Every word earns its place.\n- **Buttons**: Use outcome-focused verb + object ('Save changes', 'Create account'), never generic ('Submit', 'OK', 'Click here').\n- **Destructive actions**: State exact consequences ('Delete 5 items permanently', not 'Delete selected'). Distinguish 'Delete' (permanent) from 'Remove' (recoverable).\n- **Error messages**: Answer three questions: what happened, why, and how to fix it. 'Email address is not valid. Include an @ symbol.' not 'Invalid input'. Never blame the user.\n- **Empty states**: Explain what will appear here, why it matters, and give a clear next action.\n- **Loading/progress**: Set time expectations. 'Deploying your app (usually takes 30 seconds)' not just a spinner.\n- **Consistency**: Pick one term and stick with it. 'Delete' everywhere, not Delete/Remove/Trash interchangeably.\n- **Link text**: Make it standalone for accessibility. 'View pricing plans' not 'Click here'.\n\n**Responsive design**: Mobile-first, then enhance.\n- **Mobile-first CSS**: Write base styles for mobile, then use `min-width` media queries to enhance for larger screens. Never start with desktop and try to cram it into mobile.\n- **Input method matters more than screen size**: Use `@media (pointer: fine)` for mouse/trackpad (smaller targets OK, hover effects work), `@media (pointer: coarse)` for touch (44px targets required, no hover-dependent UI). Use `@media (hover: none)` to detect devices that can't hover. Never require hover to reveal functionality.\n- **Safe areas**: Add `<meta name='viewport' content='width=device-width, initial-scale=1, viewport-fit=cover'>` and use `env(safe-area-inset-bottom)` for bottom navigation on notched phones. Fixed bottom bars must respect safe areas.\n- **Self-adjusting grids**: Use `grid-template-columns: repeat(auto-fit, minmax(280px, 1fr))` for card grids. Columns reflow naturally without breakpoint management.\n- **Container queries over media queries**: For reusable components, use `container-type: inline-size` on the parent and `@container (min-width: 400px)` on children. Components adapt to their container, not the viewport.\n- **No horizontal scroll**: Nothing should overflow the viewport width. Test at 320px width (smallest common phone). Use `overflow-x: hidden` on the body as a safety net but fix the root cause.\n- **Touch-friendly spacing**: On mobile, increase padding on list items and nav links. Thumb zone for primary actions is bottom-center of the screen.\n- **Responsive images**: Use `next/image` with `sizes` prop for responsive sizing. For art direction changes, use `<picture>` with `<source media='...'>`. Always set `width` and `height` to prevent layout shift.\n\n**Cognitive load**: Simpler apps feel better, even with the same features.\n- **Max 4 items per group**: Humans hold 4 items in working memory. Navigation menus: max 5 top-level items. Forms: max 4 fields per section. Dashboards: max 4 metrics visible without scrolling. Pricing: max 3 tiers.\n- **Single focus per view**: Every page has ONE primary task. If there are two equal CTAs, neither is primary. One primary action, everything else is secondary or tertiary.\n- **Sequential decisions**: Don't present all options at once. Multi-step forms beat one long form. Each step should have one decision.\n- **Progressive disclosure**: Show the essential first, reveal complexity on demand. Use expandable sections, tabs, or drill-down navigation. The default view should cover 80% of use cases.\n- **Visual grouping**: Related items must be visually grouped (proximity + shared background or border). Unrelated items must have clear separation. The Gestalt principle of proximity is the easiest way to reduce cognitive load.\n- **Reduce choice anxiety**: For important decisions, provide a recommended/default option. Highlight it visually. 'Most popular' badges on pricing plans reduce decision time.\n- **Keep context visible**: In multi-step flows, show a progress indicator and allow going back. Never make users remember what they entered on a previous screen.\n\n**Production hardening**: Designs that only work with perfect data aren't production-ready.\n- **Text overflow**: Use `text-overflow: ellipsis` + `overflow: hidden` for single-line text in constrained spaces. Use `-webkit-line-clamp` for multi-line. Add `min-width: 0` on flex items to prevent overflow.\n- **Extreme inputs**: Test with 100+ character names, emoji in text fields, and empty strings. The layout should not break.\n- **Error resilience**: Every API call needs error UI. Network failures, 404s, 500s all need clear messages with recovery options. Never show raw stack traces.\n\n**Landing page component patterns** (use these for professional, non-generic landing pages):\nBuild these components inline (shadcn + motion + Tailwind is enough):\n- **Animated number counters**: Use `@number-flow/react` (installed) for stat sections. `<NumberFlow value={count} />` with smooth digit transitions.\n- **Marquee / logo ticker**: CSS-only infinite scroll (`@keyframes marquee { from { transform: translateX(0) } to { transform: translateX(-50%) } }`) with duplicated content. Pause on hover.\n- **Bento grid**: CSS grid with varied `col-span` and `row-span`. Each cell gets a unique visual. Never make all cells the same size.\n- **Animated beam / connection lines**: SVG paths with `motion` stroke-dashoffset animation for 'how it works' sections.\n- **Shimmer borders**: `background: conic-gradient(...)` wrapper with animation for hero CTAs.\n- **Comparison tables**: Sticky-header table with check/x icons and row highlighting on the recommended plan.\n- **Testimonial carousel**: CSS scroll-snap for horizontal cards with avatar, quote, name, role. Auto-scroll paused on hover.\n- **Gradient mesh backgrounds**: Multiple layered `radial-gradient` backgrounds for hero sections.\nPick 3-5 per landing page based on the app's content. The goal: every landing page should look like it was designed by a human, not generated by AI.\n\n**Landing page navbar (non-negotiable):** Fully transparent (no background, no border, no backdrop-blur) and NOT sticky/fixed. It sits inside the hero section and scrolls naturally. White text on dark hero backgrounds. Primary CTA button in the nav uses the accent color (solid fill, rounded-md). Do NOT use `sticky`, `fixed`, `top-0`, or `backdrop-blur` on landing page navbars. Dashboard sidebar/nav IS fixed (different pattern).\n\n**Design for THIS app, not any app** (the #1 way to avoid generic AI output):\n- Every layout decision should be informed by what THIS app does. A gym check-in app needs a prominent search bar. A habit tracker needs a daily view. A CRM needs a pipeline. Don't default to the same dashboard-with-stats layout for everything.\n- Write copy that is SPECIFIC to the app's domain. Not 'Manage your data efficiently' but 'Check in members in under 3 seconds'. Every headline, empty state, and CTA should reference what the user actually does in this app.\n- Choose visual emphasis based on the primary action. If the user comes to log a workout, the workout form should be the biggest thing on the dashboard.\n- Use domain-appropriate metaphors. A fitness app uses progress rings. A project tracker uses kanban columns. A recipe app uses cards with photos. Don't use the same card grid for everything.\n\n**NEVER do these (AI slop anti-patterns)**:\nThe following are telltale signs of AI-generated design. Avoid all of them.\n*Visual patterns*:\n- Cyan-on-dark, purple-to-blue gradients, neon accents on dark backgrounds (the AI color palette)\n- Gradient text on headings or metrics (decorative noise, not meaningful)\n- Glassmorphism / blur effects used decoratively (only use blur for overlays/modals that need it)\n- Rounded rectangles with thick colored border on one side (lazy accent, never looks intentional)\n- Dark mode with glowing colored box-shadows on accent elements\n- Small rounded-square icon tiles stacked above headings (the icon-tile pattern)\n- Pure black (#000) backgrounds in dark mode (use tinted dark gray instead)\n- 3-column icon + title + paragraph feature grid (use asymmetric layouts, bento grids, or varied card sizes)\n- Nested cards inside cards (visual noise, flatten the hierarchy)\n- Everything center-aligned (use left-alignment for body content, reserve center for heroes/CTAs)\n- Monotonous spacing (same gap everywhere signals no designer touched this)\n*Copy patterns*:\n- Hero text like 'Transform your X' / 'One Day at a Time' / 'Join thousands' / 'Unlock the power of' (write SPECIFIC copy)\n- Generic feature descriptions ('Powerful analytics', 'Seamless integration', 'Lightning fast')\n- The hero metric template (big number, small label, supporting stats, gradient accent)\n- Repeating information users can already see. Every word must earn its place.\n*Functional patterns*:\n- Bounce/elastic easing on animations (feels dated, real objects decelerate smoothly, use Quart/Expo out)\n- Modals for things that could be inline (modals are a last resort, not a default)\n- Nav links to pages that don't exist. EVERY link in the sidebar/topnav MUST have a corresponding page.\n- FAKE FORMS. NEVER use `setTimeout` or `await new Promise` to simulate API calls. Every form MUST have a real server action (actions.ts with 'use server') that writes to the database. If a form doesn't persist data, the feature is BROKEN.\n\n**Favicon**: A default SVG favicon exists at app/icon.svg. On the landing page step, update it to match the app. Keep it simple (a single icon/letter on a rounded square, using the accent color).\n";var pr=`# Landing Page Rules
|
|
4121
|
+
`;var er={"consumer-warm":{id:"consumer-warm",name:"Consumer Warm",description:"Personal, lifestyle, and wellness apps (habits, journals, recipes, mood, meditation)",content:Hs},"consumer-bold":{id:"consumer-bold",name:"Consumer Bold",description:"Energetic, achievement-driven apps (fitness, workouts, sports, gaming, social)",content:Gs},"professional-clean":{id:"professional-clean",name:"Professional Clean",description:"Service and appointment-based apps (booking, clinics, salons, real estate, restaurants)",content:Ws},"education-structured":{id:"education-structured",name:"Education Structured",description:"Learning and knowledge apps (courses, quizzes, flashcards, LMS, tutorials)",content:Vs},"marketplace-browse":{id:"marketplace-browse",name:"Marketplace Browse",description:"Browsing and shopping apps (marketplaces, directories, shops, catalogs, food delivery)",content:Ys},"saas-analytical":{id:"saas-analytical",name:"SaaS Analytical",description:"B2B SaaS, CRM, analytics, admin panels, ops tooling, team productivity (Linear, Notion, Stripe reference bar)",content:Js},"content-editorial":{id:"content-editorial",name:"Content Editorial",description:"Blogs, newsletters, magazines, publications, documentation, knowledge bases",content:Ks},"devtool-technical":{id:"devtool-technical",name:"Devtool Technical",description:"Developer tools, APIs, CLIs, SDKs, infrastructure, monitoring, AI/ML platforms",content:Qs},"creative-showcase":{id:"creative-showcase",name:"Creative Showcase",description:"Portfolios, design agencies, creative studios, photographers, artists",content:Xs},"finance-clarity":{id:"finance-clarity",name:"Finance Clarity",description:"Fintech, invoicing, expense tracking, budgeting, payroll, accounting, banking",content:Zs}};function tr(s){return er[s]?.content}function or(s,o){let t=o?.archetype;if(t&&t in er)return t;if(t===null)return;let e=s.toLowerCase(),n=o?.tone??"",a=o?.audienceType??"";return/\bbooking|appointment|reserv|salon|clinic|dental|barber|spa|hotel|restaurant|event|venue|schedule|court|racquet|tee.?time\b/i.test(e)?"professional-clean":/\binvoic|expense|budget|payroll|accounting|bookkeep|payment|banking|wallet|fintech|cashflow|reimbursement|tax.?filing\b/i.test(e)?"finance-clarity":/\bblog|newsletter|publication|magazine|docs?\b|documentation|knowledge.?base|wiki|\barticle|editorial|cms|longform|writing.?platform\b/i.test(e)?"content-editorial":/\bportfolio|\bagency\b|\bstudio\b|freelance|photographer|illustrator|gallery|architect|filmmaker\b/i.test(e)?"creative-showcase":/\bdev.?tool|developer.?(?:tool|platform|portal)|\bapi\b|\bcli\b|\bsdk\b|infrastructure|ci.?cd|\bmonitoring\b|observability|\bdeployment\b|serverless|edge.?compute|kubernetes|\bdocker\b|terraform|ai.?platform|ml.?platform|mlops|error.?tracking/i.test(e)?"devtool-technical":/\bcrm\b|analytics|\bdashboard\b|admin.?panel|workflow|pipeline|ticket|issue.?track|project.?mgmt|team.?mgmt|\bsaas\b|internal.?tool|\bops\b|reporting|bi.?tool/i.test(e)?"saas-analytical":/\bhabit|journal|diary|mood|meditation|yoga|mindful|gratitude|daily.?routine|self.?care|wellness\b/i.test(e)?"consumer-warm":/\bfitness|workout|exercise|gym|training|sport|running|cycling|weight|muscle|cardio|athletic|leaderboard|\bgame\b/i.test(e)?"consumer-bold":/\bcourse|quiz|flashcard|lesson|tutorial|learning|education|\blms\b|student|teach|curriculum|exam|classroom\b/i.test(e)?"education-structured":/\bmarketplace|\bshop\b|\bstore\b|catalog|listing|directory|classified|rental|e.?commerce|food.?delivery|menu\b/i.test(e)?"marketplace-browse":n==="warm-minimal"||n==="playful"?/\brecipe|cook|meal|food|pet|plant|garden|travel|photo|music|social|community|family\b/i.test(e)?"consumer-warm":/\bcompet|score|rank|challenge|achieve|badge|level|quest\b/i.test(e)?"consumer-bold":"consumer-warm":a==="b2c"?"consumer-warm":"saas-analytical"}import{existsSync as qt,mkdirSync as rr,readFileSync as nr,readdirSync as ir,writeFileSync as Mi}from"fs";import{join as lt,resolve as $i}from"path";import{homedir as So}from"os";function at(s){return s.entity??s.name??"Unknown"}function Qe(s){return typeof s=="string"?s:s.name}function xo(s){return typeof s=="string"?"text":s.type}function sr(s){let o=s.sampleRows;if(Array.isArray(o)&&o.length>0)return o.slice(0,3).map(n=>{let a={};for(let[r,i]of Object.entries(n))a[r]=i==null?"":String(i);return a});let t=s.fields||[],e=[];for(let n=0;n<3;n++){let a={};for(let r of t)a[Qe(r)]=ji(Qe(r),xo(r),at(s),n);e.push(a)}return e}function ji(s,o,t,e){let n=s.toLowerCase(),a=(o||"text").toLowerCase();return n==="name"||n==="title"?[`${t} Alpha`,`${t} Beta`,`${t} Gamma`][e]:n==="email"?["alice@example.com","bob@example.com","carol@example.com"][e]:n==="status"?["Active","Pending","Completed"][e]:n==="priority"?["High","Medium","Low"][e]:n.includes("date")||a==="date"?["Jan 15, 2024","Feb 20, 2024","Mar 10, 2024"][e]:n.includes("price")||n.includes("amount")||n.includes("cost")?["$29","$49","$99"][e]:n.includes("count")||n.includes("quantity")||a==="number"||a==="integer"?["12","34","56"][e]:a==="boolean"||a==="bool"?["Yes","No","Yes"][e]:n.includes("description")||a==="textarea"?["Brief description here","Another example entry","Third sample item"][e]:[`Sample ${e+1}`][0]}function Li(s){let o=s.dataModel??[],t=s.pages??[],e=s.design??{},n=t.map(m=>({label:m.name??m.path??"Page",route:m.path??m.route??"/"})),a=[],r=o.slice(0,3).map(m=>({name:at(m),fields:(m.fields||[]).map(p=>({name:Qe(p),type:xo(p)})),sampleData:sr(m)})),i=[];s.primaryAction&&(i.push(`PRIMARY: ${s.primaryAction.action} \u2014 this is the first thing the user sees and does`),i.push(`SURFACE: ${s.primaryAction.dashboardSurface}`)),i.push(`METRICS: Key counts for ${o.map(m=>at(m)).join(", ")}`),i.push("RECENT: Latest activity or items"),a.push({name:"Dashboard",type:"dashboard",route:"/dashboard",purpose:s.primaryAction?`Action surface \u2014 user comes here to ${s.primaryAction.action.toLowerCase()}. Not a stats display.`:`Overview of ${o.map(m=>at(m)).join(", ")} with key metrics.`,informationHierarchy:i,interactionStates:["Empty state: new user, no data yet \u2014 show onboarding prompt","Loading state: skeleton placeholders for metrics and table","Populated state: real data with metrics, recent items, quick actions"],entities:r});let l=o[0];if(l){let m=at(l),p=m.toLowerCase().endsWith("s")?m:`${m}s`;a.push({name:`${m} List`,type:"detail",route:`/${p.toLowerCase()}`,purpose:`Browse, search, and manage ${p.toLowerCase()}. Create new ${m.toLowerCase()}s.`,informationHierarchy:[`HEADER: "${p}" title + "Add ${m}" button`,"SEARCH: Filter/search bar \u2014 users will have many items",`TABLE: ${(l.fields||[]).slice(0,5).map(g=>Qe(g)).join(", ")} columns`,"ROW ACTIONS: Edit, delete on each row"],interactionStates:[`Empty state: "No ${p.toLowerCase()} yet" with create CTA`,"Loading state: skeleton table rows",`Search with no results: "No ${p.toLowerCase()} matching..." with clear filter`],entities:[{name:m,fields:(l.fields||[]).map(g=>({name:Qe(g),type:xo(g)})),sampleData:sr(l)}]})}s.steps.some(m=>{let p=`${m.name??m.title??""} ${m.description??""}`.toLowerCase();return p.includes("landing")||p.includes("hero")||p.includes("marketing")||p.includes("homepage")})&&a.push({name:"Landing Page",type:"landing",route:"/",purpose:`Convince visitors to sign up for ${s.name}. Answer: what is this, who is it for, why should I care.`,informationHierarchy:[`HERO: One sentence about what ${s.name} does \u2014 not "Transform your X", be specific`,"CTA: Sign up / Get started \u2014 one clear action","PROOF: What makes this valuable (features, not buzzwords)","SECONDARY CTA: Repeat the sign up prompt"],interactionStates:["Mobile: hero stacks vertically, nav collapses to hamburger","Desktop: hero side-by-side or centered, full nav"],entities:[]});let u=[];for(let m of o.slice(0,3)){let p=at(m);(m.fields||[]).find(b=>Qe(b).toLowerCase()==="name"||Qe(b).toLowerCase()==="title")&&u.push(`What if a ${p.toLowerCase()}'s name is 47 characters? Does the layout break?`),u.push(`What if there are 0 ${p.toLowerCase()}s? 1? 500?`)}return s.authModel&&s.authModel!=="none"&&u.push("What does a brand-new user see? (no data, no setup)"),u.push("What if the network is slow? What loads first?"),{appName:s.name,summary:s.summary??"",screens:a,navigation:{style:s.navStyle??"sidebar",items:n},primaryAction:s.primaryAction??null,designDirection:{tone:e.tone??"professional",accentColor:e.accentColor??"blue",navStyle:s.navStyle??"sidebar",fonts:e.fonts??{heading:"Inter",body:"Inter"}},edgeCases:u}}function Oi(s,o){let t=[];t.push(`# Wireframe sketch for ${s.appName}`),t.push(""),t.push(`**${s.appName}** \u2014 ${s.summary}`),t.push(""),o&&(t.push("## Feedback to apply"),t.push(o),t.push("")),t.push("## Design principles"),t.push(""),t.push("Apply these when deciding layout and hierarchy:"),t.push("1. **Information hierarchy** \u2014 What does the user see first, second, third? The primary action is first. Metrics are second. Everything else is supporting."),t.push("2. **Interaction states** \u2014 Every screen has at least: empty, loading, populated. Show the populated state but add HTML comments noting the others."),t.push("3. **Edge case paranoia** \u2014 What if there are 0 items? 500 items? A 47-character name? Think about these and comment where they matter."),t.push(`4. **Subtraction** \u2014 "As little design as possible" (Dieter Rams). Every element earns its pixels. If removing something doesn't hurt, remove it.`),t.push("5. **Design for trust** \u2014 Clear labels, predictable layout, obvious actions. No mystery meat navigation."),t.push(""),t.push("## Wireframe rules (strict)"),t.push(""),t.push("Write a **single self-contained HTML file** saved to `.mistflow/mockups/mockup-{planId}.html` (replace `{planId}` with the actual plan ID)."),t.push(""),t.push("The wireframe must:"),t.push("- Use **system fonts only** (`-apple-system, system-ui, sans-serif`) \u2014 no Google Fonts, no CDN"),t.push("- Use **inline CSS only** \u2014 no external stylesheets, no Tailwind CDN"),t.push("- Look **intentionally rough** \u2014 thin gray borders (#ddd), light backgrounds (#f8f8f8), no color, no shadows"),t.push("- Use **realistic placeholder content** that matches this specific app (sample data provided below) \u2014 NOT lorem ipsum"),t.push("- Include **HTML comments** explaining design decisions (e.g., `<!-- Primary action is prominent because users come here to check in members -->`)"),t.push("- Show **all screens in a single page** using tabs/sections that the user can click through"),t.push("- Be **responsive** \u2014 test that it looks reasonable at both 1200px and 375px widths"),t.push("- Include a small header bar showing: screen name tabs + the design direction summary"),t.push(""),t.push("The wireframe must NOT:"),t.push("- Use any color except grayscale (#333, #666, #999, #ddd, #f8f8f8, white)"),t.push("- Use any external dependencies \u2014 no CDN, no imports, no build step"),t.push("- Look polished \u2014 it should feel like a sketch on a whiteboard, not a finished product"),t.push("- Include decorative elements \u2014 no icons (use text labels), no illustrations, no gradients"),t.push(""),t.push("## Screens to wireframe"),t.push("");for(let e of s.screens){t.push(`### ${e.name} (\`${e.route}\`)`),t.push(`**Purpose**: ${e.purpose}`),t.push(""),t.push("**Information hierarchy** (render in this order, top to bottom):");for(let n of e.informationHierarchy)t.push(`- ${n}`);t.push(""),t.push("**Interaction states** (add HTML comments for non-visible states):");for(let n of e.interactionStates)t.push(`- ${n}`);if(t.push(""),e.entities.length>0){t.push("**Data model and sample content** (use this real data, not lorem ipsum):");for(let n of e.entities)t.push(`
|
|
4122
|
+
**${n.name}** \u2014 fields: ${n.fields.map(a=>`${a.name} (${a.type})`).join(", ")}`),t.push("```json"),t.push(JSON.stringify(n.sampleData,null,2)),t.push("```");t.push("")}}t.push("## Navigation"),t.push(`**Style**: ${s.navigation.style} (use this layout)`),t.push("**Items**:");for(let e of s.navigation.items)t.push(`- ${e.label} \u2192 \`${e.route}\``);if(t.push(""),s.primaryAction&&(t.push("## Primary action (this drives the layout)"),t.push(`- **Action**: ${s.primaryAction.action}`),t.push(`- **Flow**: ${s.primaryAction.flow}`),t.push(`- **Dashboard must show**: ${s.primaryAction.dashboardSurface}`),t.push(""),t.push("The dashboard is an ACTION surface. The primary action should be the most prominent thing on the page \u2014 above the metrics, above the recent items. Users came here to DO something, not to look at numbers."),t.push("")),s.edgeCases.length>0){t.push("## Edge cases to consider"),t.push("Add HTML comments in the wireframe where these matter:");for(let e of s.edgeCases)t.push(`- ${e}`);t.push("")}return t.push("## Design direction (DO NOT apply to wireframe \u2014 this is for reference only)"),t.push(`The final app will use: ${s.designDirection.tone} tone, ${s.designDirection.accentColor} accent, ${s.designDirection.navStyle} nav, ${s.designDirection.fonts.heading} / ${s.designDirection.fonts.body} fonts.`),t.push("The wireframe is grayscale and rough. These tokens will be applied during the actual build."),t.push(""),t.push("## After writing the wireframe"),t.push(""),t.push("1. Write the file to `.mistflow/mockups/mockup-{planId}.html` (replace `{planId}` with the actual plan ID)"),t.push("2. Open it: `open .mistflow/mockups/mockup-{planId}.html`"),t.push(`3. Tell the user: "Here's a rough wireframe of your app. This shows the layout and information hierarchy \u2014 not the final visual design (colors, fonts, polish come during the build). Does the layout feel right? Want to move things around, or shall we start building?"`),t.join(`
|
|
4123
|
+
`)}function ar(s){return lt(So(),".mistflow","mockup-state",`${s}.json`)}function Ui(s){let o=ar(s);if(!qt(o))return null;try{return JSON.parse(nr(o,"utf-8"))}catch{return null}}function ko(s,o){let t=lt(So(),".mistflow","mockup-state");rr(t,{recursive:!0}),Mi(ar(s),JSON.stringify(o,null,2))}async function lr(s){let{planId:o,feedback:t,approved:e}=s,n=$i(s.projectPath??process.cwd()),a=lt(So(),".mistflow","plans",`${o}.json`);if(!qt(a))return d(`Plan not found for planId '${o}'. Call mist_plan to generate a plan first.`,!0);let r;try{r=JSON.parse(nr(a,"utf-8"))}catch{return d("Failed to read plan file. Call mist_plan again.",!0)}let i=r.plan;if(!i)return d("Plan data is empty. Call mist_plan again.",!0);let l=Ui(o);l||(l={planId:o,iterationCount:0,approved:!1,screens:[],feedback:[]});let c=lt(n,".mistflow","mockups");if(rr(c,{recursive:!0}),e){l.approved=!0,ko(o,l);let g=qt(c)?ir(c).filter(b=>b.endsWith(".html")):[];return d(JSON.stringify({status:"approved",message:`Wireframe approved after ${l.iterationCount} iteration(s). Layout direction is locked in.`,mockupFiles:g.map(b=>`.mistflow/mockups/${b}`),nextAction:`NEXT: Call mist_build with action='init', name='${i.name}', and planId='${o}' to create the project. The wireframe in .mistflow/mockups/ will be used as layout reference during implementation.`}))}t?(l.iterationCount++,l.feedback.push(t)):l.iterationCount++,ko(o,l);let u=Li(i);l.screens=u.screens.map(g=>g.name),ko(o,l);let m=Oi(u,t??void 0),p;return l.iterationCount>=3&&(p="The wireframe is shaping up \u2014 want to keep refining the layout, or start building?"),d(JSON.stringify({status:"wireframe",iterationCount:l.iterationCount,screens:u.screens.map(g=>({name:g.name,type:g.type,route:g.route})),wireframePrompt:m,designDirection:u.designDirection,...p?{nudge:p}:{},mockupFile:`mockup-${o}.html`,nextAction:t?`Apply the user's feedback to the wireframe. Rewrite .mistflow/mockups/mockup-${o}.html with the changes. Open it in the browser for review. Ask if they want more changes or are ready to build.`:`Generate the wireframe HTML following the wireframePrompt instructions above. Write it to .mistflow/mockups/mockup-${o}.html, then open it in the browser. Ask the user if the layout feels right.`}))}function cr(s){let o=lt(s,".mistflow","mockups");return qt(o)?ir(o).filter(t=>t.endsWith(".html")).map(t=>lt(o,t)):[]}var dr="\nApply these choices to every file you create. Customize the shadcn CSS variables in globals.css to match. Do NOT use default shadcn blue/zinc theme.\n\n**CRITICAL: shadcn/ui components are already installed. NEVER write components/ui/*.tsx files from scratch.** If you need a shadcn component, run `npx shadcn@latest add <component>` to pull it. The project already includes: button, card, input, label, form, dialog, table, dropdown-menu, badge, separator, skeleton, sheet, tabs, avatar, select, textarea, checkbox, switch, tooltip, popover, sonner.\n\n**shadcn MCP server is available.** You have the `shadcn` MCP server installed \u2014 use it to browse and search for components, blocks, and landing page sections from the shadcn registry. Before building a landing page section from scratch, check the registry for existing blocks (hero sections, feature grids, pricing tables, testimonials, footers) and customize them instead of reinventing.\n\n**Project routes (use these exact paths):** Login is at `/login` (NOT /sign-in). Register is at `/register` (NOT /sign-up). All landing page and nav links MUST use `/login` and `/register`.\n\n### Design quality rules (non-negotiable):\n\n**Typography**: Use the plan fonts everywhere. font-heading for headings, font-body for body text.\n- **Modular scale**: Use a 1.25-1.5 ratio between sizes. A 5-level system covers most needs: xs (0.75rem captions), sm (0.875rem metadata), base (1rem body), lg (1.25-1.5rem subheadings), xl+ (2-4rem headlines). Sizes too close together (14/15/16px) create muddy hierarchy.\n- **Vertical rhythm**: Your line-height IS your spacing unit. If body is 16px with line-height 1.5 (= 24px), vertical spacing should be multiples of 24px.\n- **Weight contrast**: Use font-medium/font-semibold contrast, not just size. Bold headings + regular body creates natural hierarchy without extra sizes.\n- **Measure**: Set `max-width: 65ch` on text containers. Long lines kill readability.\n- **OpenType polish**: Use `font-variant-numeric: tabular-nums` on data tables for aligned columns.\n- Never use more than 2 font families. One well-chosen family in multiple weights is cleaner than two competing typefaces.\n- Never fall back to system fonts. Never use decorative fonts for body text. Minimum 16px (1rem) for body.\n\n**Color**: Build a functional palette, not a rainbow.\n- **Tinted neutrals**: Pure gray is dead. Add a tiny tint toward the accent color to all your grays (borders, backgrounds, muted text). The tint should be subtle enough not to read as 'colored' but creates subconscious cohesion.\n- **60/30/10 rule**: 60% neutral backgrounds/whitespace, 30% secondary colors (text, borders, inactive states), 10% accent (CTAs, highlights, focus). Accent colors work BECAUSE they're rare. Overuse kills their power.\n- **Dangerous combos to avoid**: Light gray text on white (#1 accessibility fail). Gray text on any colored background (looks washed out and dead, use a darker shade of the background color instead). Yellow text on white. Thin light text on images.\n- **Dark mode is not inverted light mode**: Use lighter surfaces for depth (no shadows). Desaturate accents slightly. Never pure black backgrounds, use dark gray (12-18% lightness). Reduce body text weight slightly (350 vs 400) because light-on-dark reads heavier.\n- Never use pure #000 or #fff. Customize the shadcn CSS variables in globals.css to match the plan palette.\n\n**Layout & space**: Space is a design material, not leftover.\n- **4px base unit**: All spacing should be multiples of 4: 4, 8, 12, 16, 24, 32, 48, 64, 96px. No arbitrary values. Name tokens semantically (`space-sm`, `space-lg`), not by value.\n- **Use `gap` not margins**: Use `gap` for sibling spacing. It eliminates margin collapse hacks and is more predictable. Reserve margin for positioning, not spacing between siblings.\n- **Rhythm through contrast**: Tight groupings within related items (8-12px), generous separation between sections (48-96px). Vary spacing WITHIN sections too. Not every row needs the same gap. The ratio between inner and outer spacing creates hierarchy.\n- **Density matches content**: Data-dense UIs (dashboards, tables, admin panels) need tighter spacing with more information visible. Marketing pages need generous whitespace and breathing room. Match density to what the user is doing.\n- **The squint test**: Blur your eyes. Can you still identify primary, secondary, and clear groupings? If everything looks the same weight, hierarchy is broken. The most important content should be obvious within 2 seconds.\n- **Asymmetry > centering**: Left-aligned with asymmetric layouts feels more designed. Center-alignment is fine for hero sections and CTAs, not for body content.\n- **Flex vs Grid**: Use Flexbox for 1D layouts (rows of items, navbars, button groups, card contents, most component internals). Use Grid for 2D layouts (page-level structure, dashboards, data-dense interfaces where rows AND columns need coordinated control). Don't default to Grid when Flexbox with `flex-wrap` would be simpler. Use `repeat(auto-fit, minmax(280px, 1fr))` for responsive grids without breakpoints. Use named `grid-template-areas` for complex page layouts and redefine at breakpoints.\n- **Cards earn their existence**: Only use cards when content needs clear separation, grid comparison, or interaction boundaries. Not everything needs a container. Never nest cards inside cards. Vary card sizes or mix cards with non-card content to break repetition.\n- **Section variety**: Don't make every section the same structure. Alternate layouts (text-left/image-right, then image-left/text-right), vary section heights, mix full-width with contained content. Monotonous section rhythm signals no designer touched this.\n- **Z-index scale**: Use a semantic scale, not arbitrary numbers. dropdown(10) -> sticky(20) -> modal-backdrop(30) -> modal(40) -> toast(50) -> tooltip(60). Never use 999 or 9999.\n- **Touch targets**: Minimum 44x44px for all interactive elements, even if the visual element is smaller (use padding).\n\n**Cards & surfaces**: Match the plan's cardStyle. Stat cards need background fills with the accent color as a subtle icon background or tinted left border. Use bg-muted/30 for section differentiation between page areas. Build a consistent shadow scale (sm -> md -> lg) and use elevation to reinforce hierarchy, not as decoration.\n\n**Sidebar**: App name + icon at top. Nav items with hover:bg-muted rounded-md transition. Active item: bg-primary/10 text-primary font-medium. User email + sign out at bottom. The sidebar should feel like a distinct surface (bg-card or bg-muted/50).\n**Mobile navigation**: The desktop sidebar must collapse to a hamburger menu on mobile. Use the shadcn `Sheet` component: a hamburger icon button (visible at `md:hidden`) opens a Sheet from the left containing the same nav items. The desktop sidebar is `hidden md:flex`. For simple apps with 3-5 nav items, a bottom tab bar (`fixed bottom-0`) is an alternative. Always respect `env(safe-area-inset-bottom)` for notched phones.\n\n**Interaction design**: Every interactive element needs 8 states, not just default and hover.\n- **Required states**: default, hover, focus, active/pressed, disabled, loading, error, success. Design all of them intentionally.\n- **Focus rings**: Use `:focus-visible` (not `:focus`) so rings show for keyboard users but not mouse clicks. Never remove focus indicators without replacement.\n- **Button hierarchy**: Don't make every button primary. Use ghost, outline, secondary, and text-link variants. One primary CTA per view.\n- **Progressive disclosure**: Simple first, advanced behind expandable sections. Don't overwhelm with options.\n- **Undo over confirmation**: For destructive actions, remove immediately + show an undo toast, then permanently delete after timeout. Better than confirmation dialogs that users click through blindly.\n- **Form patterns**: Visible `<label>` elements always (placeholders aren't labels, they disappear). Validate on blur, not on keystroke. Show format expectations with examples.\n\n**Empty states**: Every empty list/table needs a rich empty state. Not just 'Nothing here'. Include: a simple inline SVG illustration (48x48, relevant to the feature), a specific message that teaches ('Create your first habit to start tracking your daily routine'), and a primary action button. Empty states are the first thing new users see. Make them inviting.\n\n**Loading states**: Use the shadcn `Skeleton` component. Show skeleton versions of cards, lists, and stats during data fetches. Example: `<Skeleton className=\"h-8 w-32\" />` for a stat number, `<Skeleton className=\"h-20 w-full\" />` for a card. Add a `loading.tsx` file in dashboard route groups. Never show a blank page or a lone spinner.\n\n**Images**: For Unsplash images on landing pages, use `next/image` with `placeholder=\"blur\"` and a blurDataURL (a tiny 10x6 base64 image \u2014 generate a solid color blur like `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAGCAYAAAD68A/GAAAAP0lEQVQYV2N89+7dfwYGBgZGRkYGBgYmBjIBE7kaPHv27D8DA8N/BgYGRkZGRgYGJgYyARO5GkjWQHEoxRoAAPyTGAGBMpEAAAAASUVORK5CYII=`). This creates a smooth shimmer-in effect instead of images popping in.\n\n**Motion** (`motion` package is installed):\n\n**Hero moment strategy**: Pick ONE signature animation per page. Not scattered animations on everything. On a landing page, the hero entrance is your hero moment. On a dashboard, a satisfying success animation after the primary action. One great animation > ten mediocre ones. Everything else gets subtle transitions.\n\n**Animation opportunity audit** -- check these 5 categories:\n1. **Missing feedback**: Button has no press response? Add `active:scale-[0.97]` (CSS) or `whileTap={{ scale: 0.97 }}` (motion). Toggle has no slide? Animate it.\n2. **Jarring transitions**: Menu appears instantly? Add 200ms fade + slide. Content swaps without transition? Crossfade between states.\n3. **Unclear relationships**: Parent-child not visually connected? Stagger children 50ms after parent. Deleted item just disappears? Animate it out (opacity + height collapse).\n4. **Lack of delight**: Success state is flat? Draw a checkmark SVG with stroke-dashoffset animation. Empty state is static? Add a gentle float on the illustration.\n5. **Missed guidance**: First-time user gets no hint? Pulse the primary CTA once on page load. New feature unnoticed? Brief highlight animation.\n\n**Timing hierarchy**: 100-150ms for instant feedback (buttons, toggles). 200-300ms for state changes (menus, tooltips). 300-500ms for layout shifts (accordions, modals). 500-800ms for entrances (page loads). Exit animations run at 75% of entrance duration.\n\n**Easing**: Use exponential curves (Quart out, Expo out) for sophisticated physics. Never `ease` (generic), never bounce/elastic (dated). Real objects decelerate smoothly. CSS: `cubic-bezier(0.25, 1, 0.5, 1)` (Quart out) or `cubic-bezier(0.16, 1, 0.3, 1)` (Expo out).\n\n**Micro-interaction recipes**:\n- **Button press**: `active:scale-[0.97] transition-transform duration-100` (CSS only, no motion needed)\n- **Success checkmark**: SVG `<path>` with `stroke-dasharray` + `stroke-dashoffset` animation from full to 0. 400ms Expo out.\n- **Height expand/collapse**: `grid-template-rows: 0fr -> 1fr` with `transition: grid-template-rows 300ms`. No JS layout measurement needed.\n- **Skeleton to content**: Skeleton pulses (CSS `animate-pulse`), then crossfades to real content with `opacity` transition. Use the pre-scaffolded `<ContentLoader>` component.\n- **Staggered list entrance**: CSS `animation-delay` on children: `.animate-fade-up:nth-child(1) { animation-delay: 0ms } :nth-child(2) { animation-delay: 50ms }` etc. Or use `<StaggerList>` component.\n- **Number count-up**: Use `@number-flow/react` for smooth digit morphing on stats/metrics.\n\n**Performance**: Only animate `transform` and `opacity` (GPU-accelerated). Never animate width, height, top, left, margin, or padding. For scroll-tied effects on landing pages, use CSS `animation-timeline: scroll()` where supported (progressive enhancement).\n\n**Accessibility**: Always respect `prefers-reduced-motion`. Wrap animations in `@media (prefers-reduced-motion: no-preference) { ... }`. Provide static alternatives that convey the same information.\n\n**SSR-safe (CRITICAL)**: This app deploys to Mistflow Cloud's edge runtime where IntersectionObserver may not fire. NEVER use `initial={{ opacity: 0 }}` (content stays invisible forever). Use CSS @keyframes for entrance effects:\n```tsx\n// SAFE: CSS @keyframes in globals.css:\n// @keyframes fade-up { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }\n// .animate-fade-up { animation: fade-up 0.5s ease-out both; }\n// Use motion ONLY for hover/tap/gesture interactions:\nimport { motion } from 'motion/react';\n<motion.div whileHover={{ scale: 1.02 }} whileTap={{ scale: 0.97 }} transition={{ duration: 0.15 }}>\n// NEVER: <motion.div initial={{ opacity: 0 }} whileInView={{ opacity: 1 }}>\n```\nFor dashboard pages, keep animations minimal. Button press feedback + skeleton loading + success states. No entrance animations on dashboard pages.\n\n**UX writing**: Every word earns its place.\n- **Buttons**: Use outcome-focused verb + object ('Save changes', 'Create account'), never generic ('Submit', 'OK', 'Click here').\n- **Destructive actions**: State exact consequences ('Delete 5 items permanently', not 'Delete selected'). Distinguish 'Delete' (permanent) from 'Remove' (recoverable).\n- **Error messages**: Answer three questions: what happened, why, and how to fix it. 'Email address is not valid. Include an @ symbol.' not 'Invalid input'. Never blame the user.\n- **Empty states**: Explain what will appear here, why it matters, and give a clear next action.\n- **Loading/progress**: Set time expectations. 'Deploying your app (usually takes 30 seconds)' not just a spinner.\n- **Consistency**: Pick one term and stick with it. 'Delete' everywhere, not Delete/Remove/Trash interchangeably.\n- **Link text**: Make it standalone for accessibility. 'View pricing plans' not 'Click here'.\n\n**Responsive design**: Mobile-first, then enhance.\n- **Mobile-first CSS**: Write base styles for mobile, then use `min-width` media queries to enhance for larger screens. Never start with desktop and try to cram it into mobile.\n- **Input method matters more than screen size**: Use `@media (pointer: fine)` for mouse/trackpad (smaller targets OK, hover effects work), `@media (pointer: coarse)` for touch (44px targets required, no hover-dependent UI). Use `@media (hover: none)` to detect devices that can't hover. Never require hover to reveal functionality.\n- **Safe areas**: Add `<meta name='viewport' content='width=device-width, initial-scale=1, viewport-fit=cover'>` and use `env(safe-area-inset-bottom)` for bottom navigation on notched phones. Fixed bottom bars must respect safe areas.\n- **Self-adjusting grids**: Use `grid-template-columns: repeat(auto-fit, minmax(280px, 1fr))` for card grids. Columns reflow naturally without breakpoint management.\n- **Container queries over media queries**: For reusable components, use `container-type: inline-size` on the parent and `@container (min-width: 400px)` on children. Components adapt to their container, not the viewport.\n- **No horizontal scroll**: Nothing should overflow the viewport width. Test at 320px width (smallest common phone). Use `overflow-x: hidden` on the body as a safety net but fix the root cause.\n- **Touch-friendly spacing**: On mobile, increase padding on list items and nav links. Thumb zone for primary actions is bottom-center of the screen.\n- **Responsive images**: Use `next/image` with `sizes` prop for responsive sizing. For art direction changes, use `<picture>` with `<source media='...'>`. Always set `width` and `height` to prevent layout shift.\n\n**Cognitive load**: Simpler apps feel better, even with the same features.\n- **Max 4 items per group**: Humans hold 4 items in working memory. Navigation menus: max 5 top-level items. Forms: max 4 fields per section. Dashboards: max 4 metrics visible without scrolling. Pricing: max 3 tiers.\n- **Single focus per view**: Every page has ONE primary task. If there are two equal CTAs, neither is primary. One primary action, everything else is secondary or tertiary.\n- **Sequential decisions**: Don't present all options at once. Multi-step forms beat one long form. Each step should have one decision.\n- **Progressive disclosure**: Show the essential first, reveal complexity on demand. Use expandable sections, tabs, or drill-down navigation. The default view should cover 80% of use cases.\n- **Visual grouping**: Related items must be visually grouped (proximity + shared background or border). Unrelated items must have clear separation. The Gestalt principle of proximity is the easiest way to reduce cognitive load.\n- **Reduce choice anxiety**: For important decisions, provide a recommended/default option. Highlight it visually. 'Most popular' badges on pricing plans reduce decision time.\n- **Keep context visible**: In multi-step flows, show a progress indicator and allow going back. Never make users remember what they entered on a previous screen.\n\n**Production hardening**: Designs that only work with perfect data aren't production-ready.\n- **Text overflow**: Use `text-overflow: ellipsis` + `overflow: hidden` for single-line text in constrained spaces. Use `-webkit-line-clamp` for multi-line. Add `min-width: 0` on flex items to prevent overflow.\n- **Extreme inputs**: Test with 100+ character names, emoji in text fields, and empty strings. The layout should not break.\n- **Error resilience**: Every API call needs error UI. Network failures, 404s, 500s all need clear messages with recovery options. Never show raw stack traces.\n\n**Landing page component patterns** (use these for professional, non-generic landing pages):\nBuild these components inline (shadcn + motion + Tailwind is enough):\n- **Animated number counters**: Use `@number-flow/react` (installed) for stat sections. `<NumberFlow value={count} />` with smooth digit transitions.\n- **Marquee / logo ticker**: CSS-only infinite scroll (`@keyframes marquee { from { transform: translateX(0) } to { transform: translateX(-50%) } }`) with duplicated content. Pause on hover.\n- **Bento grid**: CSS grid with varied `col-span` and `row-span`. Each cell gets a unique visual. Never make all cells the same size.\n- **Animated beam / connection lines**: SVG paths with `motion` stroke-dashoffset animation for 'how it works' sections.\n- **Shimmer borders**: `background: conic-gradient(...)` wrapper with animation for hero CTAs.\n- **Comparison tables**: Sticky-header table with check/x icons and row highlighting on the recommended plan.\n- **Testimonial carousel**: CSS scroll-snap for horizontal cards with avatar, quote, name, role. Auto-scroll paused on hover.\n- **Gradient mesh backgrounds**: Multiple layered `radial-gradient` backgrounds for hero sections.\nPick 3-5 per landing page based on the app's content. The goal: every landing page should look like it was designed by a human, not generated by AI.\n\n**Landing page navbar (non-negotiable):** Fully transparent (no background, no border, no backdrop-blur) and NOT sticky/fixed. It sits inside the hero section and scrolls naturally. White text on dark hero backgrounds. Primary CTA button in the nav uses the accent color (solid fill, rounded-md). Do NOT use `sticky`, `fixed`, `top-0`, or `backdrop-blur` on landing page navbars. Dashboard sidebar/nav IS fixed (different pattern).\n\n**Design for THIS app, not any app** (the #1 way to avoid generic AI output):\n- Every layout decision should be informed by what THIS app does. A gym check-in app needs a prominent search bar. A habit tracker needs a daily view. A CRM needs a pipeline. Don't default to the same dashboard-with-stats layout for everything.\n- Write copy that is SPECIFIC to the app's domain. Not 'Manage your data efficiently' but 'Check in members in under 3 seconds'. Every headline, empty state, and CTA should reference what the user actually does in this app.\n- Choose visual emphasis based on the primary action. If the user comes to log a workout, the workout form should be the biggest thing on the dashboard.\n- Use domain-appropriate metaphors. A fitness app uses progress rings. A project tracker uses kanban columns. A recipe app uses cards with photos. Don't use the same card grid for everything.\n\n**NEVER do these (AI slop anti-patterns)**:\nThe following are telltale signs of AI-generated design. Avoid all of them.\n*Visual patterns*:\n- Cyan-on-dark, purple-to-blue gradients, neon accents on dark backgrounds (the AI color palette)\n- Gradient text on headings or metrics (decorative noise, not meaningful)\n- Glassmorphism / blur effects used decoratively (only use blur for overlays/modals that need it)\n- Rounded rectangles with thick colored border on one side (lazy accent, never looks intentional)\n- Dark mode with glowing colored box-shadows on accent elements\n- Small rounded-square icon tiles stacked above headings (the icon-tile pattern)\n- Pure black (#000) backgrounds in dark mode (use tinted dark gray instead)\n- 3-column icon + title + paragraph feature grid (use asymmetric layouts, bento grids, or varied card sizes)\n- Nested cards inside cards (visual noise, flatten the hierarchy)\n- Everything center-aligned (use left-alignment for body content, reserve center for heroes/CTAs)\n- Monotonous spacing (same gap everywhere signals no designer touched this)\n*Copy patterns*:\n- Hero text like 'Transform your X' / 'One Day at a Time' / 'Join thousands' / 'Unlock the power of' (write SPECIFIC copy)\n- Generic feature descriptions ('Powerful analytics', 'Seamless integration', 'Lightning fast')\n- The hero metric template (big number, small label, supporting stats, gradient accent)\n- Repeating information users can already see. Every word must earn its place.\n*Functional patterns*:\n- Bounce/elastic easing on animations (feels dated, real objects decelerate smoothly, use Quart/Expo out)\n- Modals for things that could be inline (modals are a last resort, not a default)\n- Nav links to pages that don't exist. EVERY link in the sidebar/topnav MUST have a corresponding page.\n- FAKE FORMS. NEVER use `setTimeout` or `await new Promise` to simulate API calls. Every form MUST have a real server action (actions.ts with 'use server') that writes to the database. If a form doesn't persist data, the feature is BROKEN.\n\n**Favicon**: A default SVG favicon exists at app/icon.svg. On the landing page step, update it to match the app. Keep it simple (a single icon/letter on a rounded square, using the accent color).\n";var pr=`# Landing Page Rules
|
|
4124
4124
|
|
|
4125
4125
|
These rules apply to every landing page. They are non-negotiable.
|
|
4126
4126
|
|
|
@@ -4980,14 +4980,14 @@ If there's a pricing page:
|
|
|
4980
4980
|
## The Footer
|
|
4981
4981
|
|
|
4982
4982
|
A footer with the same five links ("Product / Pricing / Docs / Blog / Terms") is fine, but the company name / tagline should be specific. "StandupSync \u2014 async updates, human-sized" is better than "\xA9 2026 StandupSync Inc."
|
|
4983
|
-
`;function Zi(s){return new Promise(o=>{let
|
|
4984
|
-
`)}function zt(s){return s.entity??s.name??"Unknown"}function ta(s){return s.length===0?"":typeof s[0]=="string"?s.join(", "):s.map(o=>`${o.name} (${o.type})`).join(", ")}function vr(s){return s.path??s.route??s.name??""}function oa(s){let o=(s||"text").toLowerCase();return o==="string"||o==="varchar"||o==="char"?"text":o==="integer"||o==="int"||o==="number"||o==="float"||o==="decimal"||o==="double"?"number":o==="boolean"||o==="bool"?"boolean":o==="date"||o==="datetime"||o==="timestamp"?"date":o==="email"?"email":o==="url"||o==="uri"?"url":o==="enum"||o==="select"?"select":o==="text"||o==="longtext"||o==="textarea"?"textarea":"text"}function kr(s,o){if(!s.entities||s.entities.length===0)return o;let e=s.entities.map(t=>t.toLowerCase());return o.filter(t=>{let n=zt(t).toLowerCase();return e.some(a=>n.includes(a)||a.includes(n))})}function sa(s,o){if(!s.pages||s.pages.length===0)return[];let e=s.pages.map(t=>t.toLowerCase());return o.filter(t=>{let n=(t.name??"").toLowerCase(),a=vr(t).toLowerCase();return e.some(r=>n.includes(r)||r.includes(n)||a.includes(r))})}var ra=new Set(["landing","design","dashboard","crud","layout","admin","auth","schema","integration","multi-tenant","deploy","general"]);function na(s){let o=s.stepType;if(o&&ra.has(o))return o;if(s.integrationId)return"integration";let e=`${s.name} ${s.description}`.toLowerCase();return e.includes("crud")||e.includes("list")&&e.includes("create")?"crud":e.includes("auth")||e.includes("login")||e.includes("register")?"auth":e.includes("admin")&&(e.includes("panel")||e.includes("dashboard")||e.includes("manage")||e.includes("users"))?"admin":e.includes("dashboard")||e.includes("overview")||e.includes("analytics")?"dashboard":e.includes("schema")||e.includes("database")||e.includes("model")?"schema":e.includes("layout")||e.includes("sidebar")||e.includes("navigation")?"layout":e.includes("deploy")||e.includes("cloudflare")?"deploy":e.includes("organization")||e.includes("team")||e.includes("workspace")||e.includes("multi-tenant")||e.includes("invite member")?"multi-tenant":e.includes("landing")||e.includes("hero")||e.includes("marketing")||e.includes("homepage")?"landing":e.includes("design")||e.includes("theme")||e.includes("styling")||e.includes("ui polish")||e.includes("visual")?"design":"general"}function ia(s){switch(s){case"landing":case"design":return{min:6,max:10};case"integration":return{min:8,max:12};case"dashboard":case"admin":return{min:5,max:7};case"crud":case"multi-tenant":return{min:4,max:6};case"schema":return{min:3,max:4};case"layout":case"auth":return{min:3,max:5};case"deploy":return{min:1,max:2};default:return{min:4,max:6}}}function aa(s,o){let e=[];if(e.push("### Design choices (decided at plan time \u2014 follow these exactly):"),s.tone&&e.push(`- **App tone**: ${s.tone}`),s.fonts&&(e.push(`- **Heading font**: ${s.fonts.heading} (load from Google Fonts)`),e.push(`- **Body font**: ${s.fonts.body} (load from Google Fonts)`)),e.push("- **All color comes from CSS variables** \u2014 never use Tailwind palette utilities like `bg-emerald-500`, `text-blue-600`, `border-slate-200`. Use `bg-primary`, `text-primary-foreground`, `bg-muted`, `text-muted-foreground`, `border-border`, `bg-card`, `text-foreground`, `bg-destructive`, etc. The primary/accent is already wired in globals.css from the chosen design system."),e.push("- **Outbound URLs (invite links, email CTAs, absolute hrefs in server code):** use `process.env.BETTER_AUTH_URL` as the base. Do NOT use `process.env.NEXT_PUBLIC_APP_URL` \u2014 Next.js bakes every `NEXT_PUBLIC_*` literal into the production bundle at build time, so the scaffolded localhost default ships to prod and invite emails land on `http://localhost:3000`. Client components should use relative URLs (they resolve to the current origin automatically)."),s.borderRadius){let t={sharp:"2px",subtle:"6px",rounded:"12px",pill:"9999px"};e.push(`- **Border radius**: ${s.borderRadius} (${t[s.borderRadius]??s.borderRadius}) \u2014 set as --radius in globals.css`)}if(s.shadowStyle){let t={flat:"No shadows \u2014 use borders for separation",subtle:"shadow-sm on cards, shadow on hover",elevated:"shadow-md on cards, shadow-lg on modals, layered depth",dramatic:"shadow-lg with colored tinting, bold depth"};e.push(`- **Shadow style**: ${s.shadowStyle} \u2014 ${t[s.shadowStyle]??s.shadowStyle}`)}if(s.cardStyle){let t={filled:"bg-card with subtle background fill, no visible border",bordered:"border border-border on white/transparent background",elevated:"bg-card shadow-md, no border, lifted appearance",glass:"bg-white/60 backdrop-blur-sm border border-white/20, translucent"};e.push(`- **Card style**: ${s.cardStyle} \u2014 ${t[s.cardStyle]??s.cardStyle}`)}if(s.landingTone&&e.push(`- **Landing page tone**: ${s.landingTone}`),s.visualStrategy){let t=s.visualStrategy,n=s.heroPhoto!==!1,a=n&&!!t.heroImages?.length;if(e.push(""),e.push("### Visual strategy:"),a&&t.heroImages&&t.heroImages.length>0){e.push("**Hero image** \u2014 use this Unsplash photo as the landing page hero BACKGROUND:");let r=t.heroImages[0];e.push(`- URL: ${r.url}`),e.push(`- Alt text for img tag: "${r.alt||"Hero image"} \u2014 Photo by ${r.photographer} on Unsplash"`),e.push("- Use as full-bleed background behind the entire hero section with a dark overlay (bg-black/60 or similar for readability). The photo is atmosphere and context, NOT the main visual \u2014 the glassmorphic product card sits on top.")}else n&&!t.heroImages?.length?e.push("**Hero background** \u2014 the user requested a lifestyle photo, but no Unsplash image was fetched (likely a transient API issue). Fall back gracefully: use the design preset's gradient + glassmorphism, AND tell the user in your reply: 'I couldn't fetch a stock photo for the hero this time \u2014 using a CSS gradient instead. You can add a photo later by editing the hero section in app/page.tsx.'"):n||e.push("**Hero background** \u2014 user opted for CSS-only (no photo). Use the design preset's specified gradient, animated background, or glassmorphism. No Unsplash.");if(t.sectionImages?.length){e.push("**Section images available** \u2014 use these for feature sections, about sections, or testimonial backgrounds (NOT the hero):");for(let r of t.sectionImages)e.push(`- ${r.url} \u2014 alt: "${r.alt||"section image"} \u2014 Photo by ${r.photographer} on Unsplash"`)}(a||t.sectionImages?.length)&&e.push("For image attribution: put photographer credit in the img alt text (already provided above) and add an HTML comment <!-- Images from Unsplash --> near the images. Do NOT add visible attribution text on the page."),e.push(""),e.push("**Hero layout \u2014 split hero with product UI mockup (follow this exactly):**"),e.push("The hero uses a split layout with text on the left and a product preview on the right. This is non-negotiable for consumer apps and SaaS/tool apps alike."),e.push(""),e.push("```"),e.push("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"),e.push("\u2502 [Logo] [Sign In] [CTA \u2192] \u2502 \u2190 transparent nav, NOT sticky"),e.push("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),e.push("\u2502 \u2502"),e.push("\u2502 \u25CF Built for [audience] \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502"),e.push("\u2502 \u2502 Glassmorphic \u2502 \u2502"),e.push("\u2502 Big bold headline, \u2502 product mockup \u2502 \u2502"),e.push("\u2502 accent color on key word \u2502 card showing \u2502 \u2502"),e.push("\u2502 \u2502 real app data \u2502 \u2502"),e.push("\u2502 Description paragraph \u2502 (stats, table, \u2502 \u2502"),e.push("\u2502 \u2502 chart, etc.) \u2502 \u2502"),e.push("\u2502 [Primary CTA \u2192] [Secondary] \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502"),e.push("\u2502 \u2502"),e.push("\u2502 500+ 25K+ 99% \u2502"),e.push("\u2502 Label Label Label \u2502"),e.push("\u2502 \u2502"),a?e.push("\u2502 \u2190 full-bleed photo bg + dark overlay behind all \u2192 \u2502"):e.push("\u2502 \u2190 preset gradient / glass background behind all \u2192 \u2502"),e.push("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"),e.push("```"),e.push(""),e.push("**Left side (~55%)**: badge pill \u2192 bold headline (use accent color on ONE key word or phrase) \u2192 description \u2192 two CTA buttons (primary filled + secondary outline/ghost) \u2192 stats row with 3 proof points"),e.push("**Right side (~45%)**: A glassmorphic floating card that previews what the app looks like inside:"),e.push("- Style: `bg-white/10 backdrop-blur-lg border border-white/20 rounded-2xl shadow-2xl p-6` (over dark/photo bg) OR `bg-white/60 backdrop-blur-lg border border-black/5 rounded-2xl shadow-2xl p-6` (over light bg)"),e.push("- Content: Build realistic fake app data using styled divs \u2014 stat cards, mini table rows, schedule blocks, or charts that match what this specific app's dashboard shows"),e.push("- Must be DOMAIN-SPECIFIC: a library app shows book catalog rows, a gym app shows check-in stats, a CRM shows pipeline cards"),e.push("- Add subtle inner elements with `bg-white/5` or `bg-white/10` for depth"),e.push("**Stats row**: 3 proof-point numbers at the bottom of the left side (e.g., '500+ Gyms', '25K+ Members', '99% Uptime'). Match text color to the background contrast.")}return e.push(""),e.push(dr),e.join(`
|
|
4983
|
+
`;function Zi(s){return new Promise(o=>{let t=Xi({port:s,host:"127.0.0.1"});t.on("connect",()=>{t.destroy(),o(!0)}),t.on("error",()=>{o(!1)})})}var Wd=To.object({projectPath:To.string().optional().describe("Path to the project directory (default: cwd)"),step:To.number().optional().describe("Specific step number to implement (default: next incomplete step)")});function ea(s){let o=ct(s,"mistflow.json");if(!xt(o))return null;try{return JSON.parse(Co(o,"utf-8"))}catch{return null}}function wr(s,o){let t=ct(s,"mistflow.json");Po(t,JSON.stringify(o,null,2)+`
|
|
4984
|
+
`)}function zt(s){return s.entity??s.name??"Unknown"}function ta(s){return s.length===0?"":typeof s[0]=="string"?s.join(", "):s.map(o=>`${o.name} (${o.type})`).join(", ")}function vr(s){return s.path??s.route??s.name??""}function oa(s){let o=(s||"text").toLowerCase();return o==="string"||o==="varchar"||o==="char"?"text":o==="integer"||o==="int"||o==="number"||o==="float"||o==="decimal"||o==="double"?"number":o==="boolean"||o==="bool"?"boolean":o==="date"||o==="datetime"||o==="timestamp"?"date":o==="email"?"email":o==="url"||o==="uri"?"url":o==="enum"||o==="select"?"select":o==="text"||o==="longtext"||o==="textarea"?"textarea":"text"}function kr(s,o){if(!s.entities||s.entities.length===0)return o;let t=s.entities.map(e=>e.toLowerCase());return o.filter(e=>{let n=zt(e).toLowerCase();return t.some(a=>n.includes(a)||a.includes(n))})}function sa(s,o){if(!s.pages||s.pages.length===0)return[];let t=s.pages.map(e=>e.toLowerCase());return o.filter(e=>{let n=(e.name??"").toLowerCase(),a=vr(e).toLowerCase();return t.some(r=>n.includes(r)||r.includes(n)||a.includes(r))})}var ra=new Set(["landing","design","dashboard","crud","layout","admin","auth","schema","integration","multi-tenant","deploy","general"]);function na(s){let o=s.stepType;if(o&&ra.has(o))return o;if(s.integrationId)return"integration";let t=`${s.name} ${s.description}`.toLowerCase();return t.includes("crud")||t.includes("list")&&t.includes("create")?"crud":t.includes("auth")||t.includes("login")||t.includes("register")?"auth":t.includes("admin")&&(t.includes("panel")||t.includes("dashboard")||t.includes("manage")||t.includes("users"))?"admin":t.includes("dashboard")||t.includes("overview")||t.includes("analytics")?"dashboard":t.includes("schema")||t.includes("database")||t.includes("model")?"schema":t.includes("layout")||t.includes("sidebar")||t.includes("navigation")?"layout":t.includes("deploy")||t.includes("cloudflare")?"deploy":t.includes("organization")||t.includes("team")||t.includes("workspace")||t.includes("multi-tenant")||t.includes("invite member")?"multi-tenant":t.includes("landing")||t.includes("hero")||t.includes("marketing")||t.includes("homepage")?"landing":t.includes("design")||t.includes("theme")||t.includes("styling")||t.includes("ui polish")||t.includes("visual")?"design":"general"}function ia(s){switch(s){case"landing":case"design":return{min:6,max:10};case"integration":return{min:8,max:12};case"dashboard":case"admin":return{min:5,max:7};case"crud":case"multi-tenant":return{min:4,max:6};case"schema":return{min:3,max:4};case"layout":case"auth":return{min:3,max:5};case"deploy":return{min:1,max:2};default:return{min:4,max:6}}}function aa(s,o){let t=[];if(t.push("### Design choices (decided at plan time \u2014 follow these exactly):"),s.tone&&t.push(`- **App tone**: ${s.tone}`),s.fonts&&(t.push(`- **Heading font**: ${s.fonts.heading} (load from Google Fonts)`),t.push(`- **Body font**: ${s.fonts.body} (load from Google Fonts)`)),t.push("- **All color comes from CSS variables** \u2014 never use Tailwind palette utilities like `bg-emerald-500`, `text-blue-600`, `border-slate-200`. Use `bg-primary`, `text-primary-foreground`, `bg-muted`, `text-muted-foreground`, `border-border`, `bg-card`, `text-foreground`, `bg-destructive`, etc. The primary/accent is already wired in globals.css from the chosen design system."),t.push("- **Outbound URLs (invite links, email CTAs, absolute hrefs in server code):** use `process.env.BETTER_AUTH_URL` as the base. Do NOT use `process.env.NEXT_PUBLIC_APP_URL` \u2014 Next.js bakes every `NEXT_PUBLIC_*` literal into the production bundle at build time, so the scaffolded localhost default ships to prod and invite emails land on `http://localhost:3000`. Client components should use relative URLs (they resolve to the current origin automatically)."),s.borderRadius){let e={sharp:"2px",subtle:"6px",rounded:"12px",pill:"9999px"};t.push(`- **Border radius**: ${s.borderRadius} (${e[s.borderRadius]??s.borderRadius}) \u2014 set as --radius in globals.css`)}if(s.shadowStyle){let e={flat:"No shadows \u2014 use borders for separation",subtle:"shadow-sm on cards, shadow on hover",elevated:"shadow-md on cards, shadow-lg on modals, layered depth",dramatic:"shadow-lg with colored tinting, bold depth"};t.push(`- **Shadow style**: ${s.shadowStyle} \u2014 ${e[s.shadowStyle]??s.shadowStyle}`)}if(s.cardStyle){let e={filled:"bg-card with subtle background fill, no visible border",bordered:"border border-border on white/transparent background",elevated:"bg-card shadow-md, no border, lifted appearance",glass:"bg-white/60 backdrop-blur-sm border border-white/20, translucent"};t.push(`- **Card style**: ${s.cardStyle} \u2014 ${e[s.cardStyle]??s.cardStyle}`)}if(s.landingTone&&t.push(`- **Landing page tone**: ${s.landingTone}`),s.visualStrategy){let e=s.visualStrategy,n=s.heroPhoto!==!1,a=n&&!!e.heroImages?.length;if(t.push(""),t.push("### Visual strategy:"),a&&e.heroImages&&e.heroImages.length>0){t.push("**Hero image** \u2014 use this Unsplash photo as the landing page hero BACKGROUND:");let r=e.heroImages[0];t.push(`- URL: ${r.url}`),t.push(`- Alt text for img tag: "${r.alt||"Hero image"} \u2014 Photo by ${r.photographer} on Unsplash"`),t.push("- Use as full-bleed background behind the entire hero section with a dark overlay (bg-black/60 or similar for readability). The photo is atmosphere and context, NOT the main visual \u2014 the glassmorphic product card sits on top.")}else n&&!e.heroImages?.length?t.push("**Hero background** \u2014 the user requested a lifestyle photo, but no Unsplash image was fetched (likely a transient API issue). Fall back gracefully: use the design preset's gradient + glassmorphism, AND tell the user in your reply: 'I couldn't fetch a stock photo for the hero this time \u2014 using a CSS gradient instead. You can add a photo later by editing the hero section in app/page.tsx.'"):n||t.push("**Hero background** \u2014 user opted for CSS-only (no photo). Use the design preset's specified gradient, animated background, or glassmorphism. No Unsplash.");if(e.sectionImages?.length){t.push("**Section images available** \u2014 use these for feature sections, about sections, or testimonial backgrounds (NOT the hero):");for(let r of e.sectionImages)t.push(`- ${r.url} \u2014 alt: "${r.alt||"section image"} \u2014 Photo by ${r.photographer} on Unsplash"`)}(a||e.sectionImages?.length)&&t.push("For image attribution: put photographer credit in the img alt text (already provided above) and add an HTML comment <!-- Images from Unsplash --> near the images. Do NOT add visible attribution text on the page."),t.push(""),t.push("**Hero layout \u2014 split hero with product UI mockup (follow this exactly):**"),t.push("The hero uses a split layout with text on the left and a product preview on the right. This is non-negotiable for consumer apps and SaaS/tool apps alike."),t.push(""),t.push("```"),t.push("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"),t.push("\u2502 [Logo] [Sign In] [CTA \u2192] \u2502 \u2190 transparent nav, NOT sticky"),t.push("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),t.push("\u2502 \u2502"),t.push("\u2502 \u25CF Built for [audience] \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502"),t.push("\u2502 \u2502 Glassmorphic \u2502 \u2502"),t.push("\u2502 Big bold headline, \u2502 product mockup \u2502 \u2502"),t.push("\u2502 accent color on key word \u2502 card showing \u2502 \u2502"),t.push("\u2502 \u2502 real app data \u2502 \u2502"),t.push("\u2502 Description paragraph \u2502 (stats, table, \u2502 \u2502"),t.push("\u2502 \u2502 chart, etc.) \u2502 \u2502"),t.push("\u2502 [Primary CTA \u2192] [Secondary] \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502"),t.push("\u2502 \u2502"),t.push("\u2502 500+ 25K+ 99% \u2502"),t.push("\u2502 Label Label Label \u2502"),t.push("\u2502 \u2502"),a?t.push("\u2502 \u2190 full-bleed photo bg + dark overlay behind all \u2192 \u2502"):t.push("\u2502 \u2190 preset gradient / glass background behind all \u2192 \u2502"),t.push("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"),t.push("```"),t.push(""),t.push("**Left side (~55%)**: badge pill \u2192 bold headline (use accent color on ONE key word or phrase) \u2192 description \u2192 two CTA buttons (primary filled + secondary outline/ghost) \u2192 stats row with 3 proof points"),t.push("**Right side (~45%)**: A glassmorphic floating card that previews what the app looks like inside:"),t.push("- Style: `bg-white/10 backdrop-blur-lg border border-white/20 rounded-2xl shadow-2xl p-6` (over dark/photo bg) OR `bg-white/60 backdrop-blur-lg border border-black/5 rounded-2xl shadow-2xl p-6` (over light bg)"),t.push("- Content: Build realistic fake app data using styled divs \u2014 stat cards, mini table rows, schedule blocks, or charts that match what this specific app's dashboard shows"),t.push("- Must be DOMAIN-SPECIFIC: a library app shows book catalog rows, a gym app shows check-in stats, a CRM shows pipeline cards"),t.push("- Add subtle inner elements with `bg-white/5` or `bg-white/10` for depth"),t.push("**Stats row**: 3 proof-point numbers at the bottom of the left side (e.g., '500+ Gyms', '25K+ Members', '99% Uptime'). Match text color to the background contrast.")}return t.push(""),t.push(dr),t.join(`
|
|
4985
4985
|
`)}async function la(s){try{let o=await ps("nextjs",s);return{reminders:o.reminders,skill:o.skill}}catch{return{reminders:`### ${s} step
|
|
4986
4986
|
- Follow existing patterns in the codebase
|
|
4987
|
-
- Server Components by default, "use client" only when interactivity is needed`,skill:""}}}async function ca(s,o,e,t,n,a){let r=[];r.push(`## Step ${s.number}: ${s.name}`),r.push(""),r.push("### What to build:"),r.push(s.description),r.push(""),o.primaryAction&&(r.push("### Primary user action (non-negotiable):"),r.push(`- **Core action**: ${o.primaryAction.action}`),r.push(`- **User flow**: ${o.primaryAction.flow}`),r.push(`- **Dashboard must show**: ${o.primaryAction.dashboardSurface}`),r.push(""),r.push("The dashboard is an ACTION surface, not a stats display. Users must be able to complete the core action directly from the dashboard without navigating to a separate page. If this step builds the dashboard, make sure the primary action is front and center with inline forms/buttons \u2014 not behind a link to another page."),r.push(""));let l=["landing","design","dashboard","crud","layout","admin","general","auth"].includes(n);if(o.design&&l?(r.push(aa(o.design,{hasDesignPreset:!!o.landingDesign&&(n==="landing"||n==="design")})),r.push("")):o.design&&!l&&(r.push("### Design tokens (for reference only \u2014 this step is not UI-focused):"),o.design.fonts&&r.push(`- Fonts: ${o.design.fonts.heading} / ${o.design.fonts.body}`),r.push("- Colors come from CSS variables (`--color-primary`, `--color-background`, etc.) \u2014 not Tailwind palette names."),r.push("")),a){let h=cr(a);if(h.length>0){r.push("### Approved wireframe (MUST READ before writing any files):"),r.push("The user approved a wireframe sketch before building. **Read these files NOW before writing any code for this step:**");for(let w of h){let P=w.replace(a,"").replace(/^\//,"");r.push(`- \`${P}\``)}r.push(""),r.push("The wireframe defines the LAYOUT and INFORMATION HIERARCHY \u2014 what goes where, what's prominent, what's secondary. It includes HTML comments explaining WHY things are placed where they are."),r.push(""),r.push("The wireframe is intentionally rough (grayscale, system fonts). Your job is to:"),r.push("1. **Keep the same layout structure** \u2014 same information hierarchy, same element placement, same sections in the same order"),r.push("2. **Apply the design tokens** \u2014 colors, fonts, shadows, radius from the plan design choices above"),r.push("3. **Elevate the visual quality** \u2014 make it feel designed for THIS specific app, not generic"),r.push("4. **Respect the HTML comments** \u2014 they explain WHY things are placed where they are"),r.push("5. **If the wireframe shows a search bar at the top of the dashboard, your dashboard MUST have a search bar at the top** \u2014 do not rearrange the layout"),r.push("")}}o.roles&&Array.isArray(o.roles)&&o.roles.length>0&&(r.push("### Role system (from plan):"),r.push(`- Roles: ${o.roles.join(", ")}`),r.push(`- Default role for new signups: ${o.defaultRole??o.roles[0]}`),r.push("- Role helpers are in `lib/roles.ts` \u2014 use `getUserRole()` and `hasRole()` for access checks"),r.push("")),o.multiTenant&&(r.push("### Multi-tenant (from plan):"),r.push("- Organization tables are in `db/schema/organization.ts`"),r.push("- Org helpers are in `lib/org.ts` \u2014 use `getCurrentOrg()` to scope queries"),r.push("- All data queries MUST be scoped to the current org (filter by orgId)"),r.push("- Org switcher component is at `components/org-switcher.tsx`"),r.push("- CRITICAL: `getCurrentOrg()` returns null for new users who haven't created an org yet. The dashboard MUST handle this \u2014 if currentOrg is null, redirect to an onboarding page or show an inline 'Create your first team/workspace' form. NEVER call .id on a null org."),r.push("- WARNING: cookies().set() in server actions does NOT work on Mistflow Cloud's edge runtime. Do NOT use setCurrentOrgId() or any cookies().set() call inside server actions. Instead, pass the orgId as a form field or query param, or store the active org in the user's database record."),r.push("")),o.language&&(r.push(`### Language: ${o.language}`),r.push(`ALL user-facing text must be written in ${o.language}:`),r.push("- Page titles, headings, labels, button text, placeholder text"),r.push("- Navigation items, menu labels, footer text"),r.push("- Error messages, success messages, empty states"),r.push("- Landing page copy, marketing text, CTAs"),r.push("- Form labels and validation messages"),r.push("Code (variable names, comments, file names) stays in English."),r.push(`Set the HTML lang attribute to the appropriate locale code for ${o.language}.`),r.push(""));let c=["landing","design","auth","general","crud","dashboard"];o.audienceType&&c.includes(n)&&(o.audienceType==="b2c"?(r.push("### Audience: this app belongs to ONE business. The landing page talks TO their customers."),r.push("- Hero: what the customer gets ('Exceptional catering for your next event'), NOT what the tool does"),r.push("- CTAs: customer action ('Order Catering', 'Book Now'), NOT business action ('Get Started Free')"),r.push("- Testimonials: from customers ('They catered our wedding'), NOT from business owners"),r.push("- Features: customer benefits ('Specify your dietary needs'), NOT business benefits ('Track preferences')"),r.push("- Stats: social proof for customers ('2,400+ events served'), NOT internal metrics ('$48k revenue')"),r.push("- The business name IS the brand. Say it like a business homepage, not a SaaS onboarding."),r.push("")):o.audienceType==="b2b"?(r.push("### Audience: this is a SaaS platform. The landing page pitches TO business owners."),r.push("- Hero: the business pain + solution ('Catering orders managed in one place')"),r.push("- CTAs: business owner action ('Start Free Trial', 'Get Started')"),r.push("- Testimonials: from business owners who use the platform"),r.push("- Features: business benefits ('Track dietary preferences across all orders')"),r.push("- Stats: platform metrics ('500+ businesses', '50K+ orders processed')"),r.push("")):o.audienceType==="internal"&&(r.push("### Audience: internal staff tool. No marketing copy needed."),r.push("- No landing page. Auth page copy is functional: 'Sign in to continue'."),r.push("- Dashboard focuses on operational efficiency, not onboarding or sales."),r.push(""))),e.length>0&&(r.push("### Already completed:"),e.forEach(h=>r.push(`- ${h}`)),r.push(""));let u=o.dataModel?kr(s,o.dataModel):[];u.length>0&&(r.push("### Data model (from plan):"),u.forEach(h=>{let w=zt(h),P=ta(h.fields);r.push(`- **${w}**: ${P}`),r.push(` Schema file: \`db/schema/${w.toLowerCase().replace(/\s+/g,"-")}.ts\``)}),r.push(""));let m=o.pages?sa(s,o.pages):[];m.length>0&&(r.push("### Pages to create/update:"),m.forEach(h=>{let w=h.description?` \u2014 ${h.description}`:"";r.push(`- \`${vr(h)}\`${w}`)}),r.push("")),n==="crud"&&u.length>0&&u.forEach(h=>{let w=zt(h),P=w.toLowerCase().replace(/\s+/g,"-"),I=P.endsWith("s")?P:`${P}s`;r.push(`### Files for ${w} CRUD:`),r.push(`- List page: \`app/(dashboard)/${I}/page.tsx\` (Server Component)`),r.push(`- Detail page: \`app/(dashboard)/${I}/[id]/page.tsx\``),r.push(`- Create page: \`app/(dashboard)/${I}/new/page.tsx\``),r.push(`- Server Actions: \`app/(dashboard)/${I}/actions.ts\``),r.push(`- DataTable columns: \`components/${P}-table-columns.tsx\``),r.push(`- Form: \`components/${P}-form.tsx\``),r.push("")});let p=o.appStyle;if(l){r.push("## Design Doctrine (the standard for every UI step)"),r.push(""),r.push(ur),r.push(""),r.push("## Design Reference Library"),r.push(""),r.push("### Typography"),r.push(mr),r.push(""),r.push("### Color"),r.push(hr),r.push(""),r.push("### Motion"),r.push(gr),r.push(""),r.push("### Spatial Composition"),r.push(fr),r.push(""),r.push("### Interaction"),r.push(yr),r.push(""),r.push("### UX Writing"),r.push(br),r.push("");let h=a?ct(a,"DESIGN.md"):void 0,w=h&&xt(h)?(()=>{try{return Ao(h,"utf-8")}catch{return null}})():null;w&&(r.push("### Design system (source of truth: DESIGN.md):"),r.push(""),r.push("The project's DESIGN.md defines the visual identity. Follow it exactly. It's emitted in google-labs-code/design.md format (YAML front matter with colors/typography/rounded/spacing tokens, plus markdown rationale). All UI elements must use the project's CSS custom properties (--color-primary, --color-background, etc. \u2014 these are generated from the YAML tokens) and the fonts configured in layout.tsx. If DESIGN.md and this plan disagree, DESIGN.md wins. The user may have edited it."),r.push(""),r.push(w),r.push(""))}if(l){let h=or(o.summary??o.name,{tone:o.design?.tone,audienceType:o.audienceType,archetype:o.design?.archetype});if(h){let w=tr(h);w&&(r.push(`### App archetype: ${h}`),r.push(""),r.push(`This app matches the **${h}** archetype. Follow these component-level patterns for page composition, cards, navigation, spacing, and motion. `+(p?`The app style (${p}) provides visual identity (colors, fonts). The archetype provides layout and component patterns. Use both.`:"All visual styling comes from the project's CSS custom properties and fonts in layout.tsx.")),r.push(""),r.push(w),r.push(""))}}(n==="landing"||n==="design")&&(r.push(pr),r.push(""));let g=s.integrationId?rt(s.integrationId):void 0;if(g){let h=nt(g.id);if(r.push("### Integration blueprint (follow this closely):"),r.push(""),r.push(`Using integration: **${g.name}** (${g.category})`),h?.docsUrl&&r.push(`Official docs: ${h.docsUrl}`),h?.envVars?.length){r.push(""),r.push("**Required environment variables:**");for(let w of h.envVars)r.push(`- \`${w.key}\`: ${w.description} \u2014 Get it at ${w.setupUrl}`);r.push(""),r.push("**IMPORTANT: Never ask the user to paste API keys in chat.** Direct them to set keys in the Mistflow dashboard (Project Settings > Environment Variables) or at app.mistflow.ai. Use mist_config resource='env' action='list' to check if keys are set (has_value: true/false). Only proceed with deploy once all required keys are set.")}h?.packages?.length&&(r.push(""),r.push(`**Packages to install:** \`npm install ${h.packages.join(" ")}\``)),r.push(""),r.push("---"),r.push(g.prompt),r.push("---"),r.push(""),r.push("**Adaptation rules**: Follow the file structure and code patterns above. Replace placeholder values (app names, URLs, copy) with this app's specific content. Use the app's existing data models and route structure. Never ask the user to paste API keys or secrets in the chat. Direct them to set keys in the Mistflow dashboard."),r.push("")}let{reminders:b,skill:f}=await la(n);return r.push(b),r.push(""),f&&!(n==="landing"&&o.landingDesign==="freeform")&&(r.push(`### ${n} reference:`),r.push(f),r.push("")),l&&(r.push("## Self-Audit \u2014 run before submitting this file"),r.push(""),r.push(`Read the file you just wrote and answer each of these. If any answer is "yes", REDESIGN the failing piece \u2014 don't tweak classes on the same template. A different composition is required.`),r.push(""),r.push('1. **Pill badge at the top?** A small rounded label saying "Built for" / "New:" / "Made for" with a colored dot? \u2192 redesign the hero without it.'),r.push("2. **Fake browser chrome?** A rounded box with red/yellow/green dots and a fake URL bar? \u2192 delete it. Show real components instead, or no preview."),r.push("3. **Centered single-column hero?** Pill \u2192 headline \u2192 subhead \u2192 two CTAs stacked vertically? \u2192 redesign asymmetrically (see spatial.md)."),r.push("4. **Three checkmark benefit bullets** below the hero CTAs? \u2192 remove the triplet pattern."),r.push("5. **Tailwind palette utilities?** Any `bg-emerald-*`, `bg-amber-*`, `text-violet-*`, `border-slate-*`, `from-purple-*`, etc.? \u2192 replace with token classes (`bg-primary`, `bg-success`, `bg-muted`, `border-border`). No exceptions."),r.push("6. **Inter, Geist, Roboto, Arial, or system-ui** as the primary font? \u2192 pick something distinctive (see typography.md)."),r.push("7. **Purple gradient on white background** anywhere? \u2192 that's the single most overused AI-design pattern. Replace."),r.push('8. **Hardcoded hex values** (e.g. `style={{ color: "#10b981" }}`) or named CSS colors (`red`, `lightgrey`) in className or inline styles? \u2192 replace with CSS variables.'),r.push('9. **Generic copy** ("Boost your productivity", "The platform teams love", "Everything you need to")? \u2192 rewrite with specific nouns, numbers, or mechanisms from this product (see writing.md).'),r.push("10. **Zero memorable moments?** Is there ONE signature element \u2014 typographic hero, orchestrated reveal, asymmetric break, product-specific illustration? If zero, the page is generic. Add one (see motion.md, typography.md)."),r.push(""),r.push(`If every answer is "no, I'm good" \u2014 then submit.`),r.push("")),r.join(`
|
|
4988
|
-
`)}async function xr(s){let{projectPath:o,step:
|
|
4987
|
+
- Server Components by default, "use client" only when interactivity is needed`,skill:""}}}async function ca(s,o,t,e,n,a){let r=[];r.push(`## Step ${s.number}: ${s.name}`),r.push(""),r.push("### What to build:"),r.push(s.description),r.push(""),o.primaryAction&&(r.push("### Primary user action (non-negotiable):"),r.push(`- **Core action**: ${o.primaryAction.action}`),r.push(`- **User flow**: ${o.primaryAction.flow}`),r.push(`- **Dashboard must show**: ${o.primaryAction.dashboardSurface}`),r.push(""),r.push("The dashboard is an ACTION surface, not a stats display. Users must be able to complete the core action directly from the dashboard without navigating to a separate page. If this step builds the dashboard, make sure the primary action is front and center with inline forms/buttons \u2014 not behind a link to another page."),r.push(""));let l=["landing","design","dashboard","crud","layout","admin","general","auth"].includes(n);if(o.design&&l?(r.push(aa(o.design,{hasDesignPreset:!!o.landingDesign&&(n==="landing"||n==="design")})),r.push("")):o.design&&!l&&(r.push("### Design tokens (for reference only \u2014 this step is not UI-focused):"),o.design.fonts&&r.push(`- Fonts: ${o.design.fonts.heading} / ${o.design.fonts.body}`),r.push("- Colors come from CSS variables (`--color-primary`, `--color-background`, etc.) \u2014 not Tailwind palette names."),r.push("")),a){let h=cr(a);if(h.length>0){r.push("### Approved wireframe (MUST READ before writing any files):"),r.push("The user approved a wireframe sketch before building. **Read these files NOW before writing any code for this step:**");for(let w of h){let P=w.replace(a,"").replace(/^\//,"");r.push(`- \`${P}\``)}r.push(""),r.push("The wireframe defines the LAYOUT and INFORMATION HIERARCHY \u2014 what goes where, what's prominent, what's secondary. It includes HTML comments explaining WHY things are placed where they are."),r.push(""),r.push("The wireframe is intentionally rough (grayscale, system fonts). Your job is to:"),r.push("1. **Keep the same layout structure** \u2014 same information hierarchy, same element placement, same sections in the same order"),r.push("2. **Apply the design tokens** \u2014 colors, fonts, shadows, radius from the plan design choices above"),r.push("3. **Elevate the visual quality** \u2014 make it feel designed for THIS specific app, not generic"),r.push("4. **Respect the HTML comments** \u2014 they explain WHY things are placed where they are"),r.push("5. **If the wireframe shows a search bar at the top of the dashboard, your dashboard MUST have a search bar at the top** \u2014 do not rearrange the layout"),r.push("")}}o.roles&&Array.isArray(o.roles)&&o.roles.length>0&&(r.push("### Role system (from plan):"),r.push(`- Roles: ${o.roles.join(", ")}`),r.push(`- Default role for new signups: ${o.defaultRole??o.roles[0]}`),r.push("- Role helpers are in `lib/roles.ts` \u2014 use `getUserRole()` and `hasRole()` for access checks"),r.push("")),o.multiTenant&&(r.push("### Multi-tenant (from plan):"),r.push("- Organization tables are in `db/schema/organization.ts`"),r.push("- Org helpers are in `lib/org.ts` \u2014 use `getCurrentOrg()` to scope queries"),r.push("- All data queries MUST be scoped to the current org (filter by orgId)"),r.push("- Org switcher component is at `components/org-switcher.tsx`"),r.push("- CRITICAL: `getCurrentOrg()` returns null for new users who haven't created an org yet. The dashboard MUST handle this \u2014 if currentOrg is null, redirect to an onboarding page or show an inline 'Create your first team/workspace' form. NEVER call .id on a null org."),r.push("- WARNING: cookies().set() in server actions does NOT work on Mistflow Cloud's edge runtime. Do NOT use setCurrentOrgId() or any cookies().set() call inside server actions. Instead, pass the orgId as a form field or query param, or store the active org in the user's database record."),r.push("")),o.language&&(r.push(`### Language: ${o.language}`),r.push(`ALL user-facing text must be written in ${o.language}:`),r.push("- Page titles, headings, labels, button text, placeholder text"),r.push("- Navigation items, menu labels, footer text"),r.push("- Error messages, success messages, empty states"),r.push("- Landing page copy, marketing text, CTAs"),r.push("- Form labels and validation messages"),r.push("Code (variable names, comments, file names) stays in English."),r.push(`Set the HTML lang attribute to the appropriate locale code for ${o.language}.`),r.push(""));let c=["landing","design","auth","general","crud","dashboard"];o.audienceType&&c.includes(n)&&(o.audienceType==="b2c"?(r.push("### Audience: this app belongs to ONE business. The landing page talks TO their customers."),r.push("- Hero: what the customer gets ('Exceptional catering for your next event'), NOT what the tool does"),r.push("- CTAs: customer action ('Order Catering', 'Book Now'), NOT business action ('Get Started Free')"),r.push("- Testimonials: from customers ('They catered our wedding'), NOT from business owners"),r.push("- Features: customer benefits ('Specify your dietary needs'), NOT business benefits ('Track preferences')"),r.push("- Stats: social proof for customers ('2,400+ events served'), NOT internal metrics ('$48k revenue')"),r.push("- The business name IS the brand. Say it like a business homepage, not a SaaS onboarding."),r.push("")):o.audienceType==="b2b"?(r.push("### Audience: this is a SaaS platform. The landing page pitches TO business owners."),r.push("- Hero: the business pain + solution ('Catering orders managed in one place')"),r.push("- CTAs: business owner action ('Start Free Trial', 'Get Started')"),r.push("- Testimonials: from business owners who use the platform"),r.push("- Features: business benefits ('Track dietary preferences across all orders')"),r.push("- Stats: platform metrics ('500+ businesses', '50K+ orders processed')"),r.push("")):o.audienceType==="internal"&&(r.push("### Audience: internal staff tool. No marketing copy needed."),r.push("- No landing page. Auth page copy is functional: 'Sign in to continue'."),r.push("- Dashboard focuses on operational efficiency, not onboarding or sales."),r.push(""))),t.length>0&&(r.push("### Already completed:"),t.forEach(h=>r.push(`- ${h}`)),r.push(""));let u=o.dataModel?kr(s,o.dataModel):[];u.length>0&&(r.push("### Data model (from plan):"),u.forEach(h=>{let w=zt(h),P=ta(h.fields);r.push(`- **${w}**: ${P}`),r.push(` Schema file: \`db/schema/${w.toLowerCase().replace(/\s+/g,"-")}.ts\``)}),r.push(""));let m=o.pages?sa(s,o.pages):[];m.length>0&&(r.push("### Pages to create/update:"),m.forEach(h=>{let w=h.description?` \u2014 ${h.description}`:"";r.push(`- \`${vr(h)}\`${w}`)}),r.push("")),n==="crud"&&u.length>0&&u.forEach(h=>{let w=zt(h),P=w.toLowerCase().replace(/\s+/g,"-"),I=P.endsWith("s")?P:`${P}s`;r.push(`### Files for ${w} CRUD:`),r.push(`- List page: \`app/(dashboard)/${I}/page.tsx\` (Server Component)`),r.push(`- Detail page: \`app/(dashboard)/${I}/[id]/page.tsx\``),r.push(`- Create page: \`app/(dashboard)/${I}/new/page.tsx\``),r.push(`- Server Actions: \`app/(dashboard)/${I}/actions.ts\``),r.push(`- DataTable columns: \`components/${P}-table-columns.tsx\``),r.push(`- Form: \`components/${P}-form.tsx\``),r.push("")});let p=o.appStyle;if(l){r.push("## Design Doctrine (the standard for every UI step)"),r.push(""),r.push(ur),r.push(""),r.push("## Design Reference Library"),r.push(""),r.push("### Typography"),r.push(mr),r.push(""),r.push("### Color"),r.push(hr),r.push(""),r.push("### Motion"),r.push(gr),r.push(""),r.push("### Spatial Composition"),r.push(fr),r.push(""),r.push("### Interaction"),r.push(yr),r.push(""),r.push("### UX Writing"),r.push(br),r.push("");let h=a?ct(a,"DESIGN.md"):void 0,w=h&&xt(h)?(()=>{try{return Co(h,"utf-8")}catch{return null}})():null;w&&(r.push("### Design system (source of truth: DESIGN.md):"),r.push(""),r.push("The project's DESIGN.md defines the visual identity. Follow it exactly. It's emitted in google-labs-code/design.md format (YAML front matter with colors/typography/rounded/spacing tokens, plus markdown rationale). All UI elements must use the project's CSS custom properties (--color-primary, --color-background, etc. \u2014 these are generated from the YAML tokens) and the fonts configured in layout.tsx. If DESIGN.md and this plan disagree, DESIGN.md wins. The user may have edited it."),r.push(""),r.push(w),r.push(""))}if(l){let h=or(o.summary??o.name,{tone:o.design?.tone,audienceType:o.audienceType,archetype:o.design?.archetype});if(h){let w=tr(h);w&&(r.push(`### App archetype: ${h}`),r.push(""),r.push(`This app matches the **${h}** archetype. Follow these component-level patterns for page composition, cards, navigation, spacing, and motion. `+(p?`The app style (${p}) provides visual identity (colors, fonts). The archetype provides layout and component patterns. Use both.`:"All visual styling comes from the project's CSS custom properties and fonts in layout.tsx.")),r.push(""),r.push(w),r.push(""))}}(n==="landing"||n==="design")&&(r.push(pr),r.push(""));let g=s.integrationId?rt(s.integrationId):void 0;if(g){let h=nt(g.id);if(r.push("### Integration blueprint (follow this closely):"),r.push(""),r.push(`Using integration: **${g.name}** (${g.category})`),h?.docsUrl&&r.push(`Official docs: ${h.docsUrl}`),h?.envVars?.length){r.push(""),r.push("**Required environment variables:**");for(let w of h.envVars)r.push(`- \`${w.key}\`: ${w.description} \u2014 Get it at ${w.setupUrl}`);r.push(""),r.push("**IMPORTANT: Never ask the user to paste API keys in chat.** Direct them to set keys in the Mistflow dashboard (Project Settings > Environment Variables) or at app.mistflow.ai. Use mist_config resource='env' action='list' to check if keys are set (has_value: true/false). Only proceed with deploy once all required keys are set.")}h?.packages?.length&&(r.push(""),r.push(`**Packages to install:** \`npm install ${h.packages.join(" ")}\``)),r.push(""),r.push("---"),r.push(g.prompt),r.push("---"),r.push(""),r.push("**Adaptation rules**: Follow the file structure and code patterns above. Replace placeholder values (app names, URLs, copy) with this app's specific content. Use the app's existing data models and route structure. Never ask the user to paste API keys or secrets in the chat. Direct them to set keys in the Mistflow dashboard."),r.push("")}let{reminders:b,skill:f}=await la(n);return r.push(b),r.push(""),f&&!(n==="landing"&&o.landingDesign==="freeform")&&(r.push(`### ${n} reference:`),r.push(f),r.push("")),l&&(r.push("## Self-Audit \u2014 run before submitting this file"),r.push(""),r.push(`Read the file you just wrote and answer each of these. If any answer is "yes", REDESIGN the failing piece \u2014 don't tweak classes on the same template. A different composition is required.`),r.push(""),r.push('1. **Pill badge at the top?** A small rounded label saying "Built for" / "New:" / "Made for" with a colored dot? \u2192 redesign the hero without it.'),r.push("2. **Fake browser chrome?** A rounded box with red/yellow/green dots and a fake URL bar? \u2192 delete it. Show real components instead, or no preview."),r.push("3. **Centered single-column hero?** Pill \u2192 headline \u2192 subhead \u2192 two CTAs stacked vertically? \u2192 redesign asymmetrically (see spatial.md)."),r.push("4. **Three checkmark benefit bullets** below the hero CTAs? \u2192 remove the triplet pattern."),r.push("5. **Tailwind palette utilities?** Any `bg-emerald-*`, `bg-amber-*`, `text-violet-*`, `border-slate-*`, `from-purple-*`, etc.? \u2192 replace with token classes (`bg-primary`, `bg-success`, `bg-muted`, `border-border`). No exceptions."),r.push("6. **Inter, Geist, Roboto, Arial, or system-ui** as the primary font? \u2192 pick something distinctive (see typography.md)."),r.push("7. **Purple gradient on white background** anywhere? \u2192 that's the single most overused AI-design pattern. Replace."),r.push('8. **Hardcoded hex values** (e.g. `style={{ color: "#10b981" }}`) or named CSS colors (`red`, `lightgrey`) in className or inline styles? \u2192 replace with CSS variables.'),r.push('9. **Generic copy** ("Boost your productivity", "The platform teams love", "Everything you need to")? \u2192 rewrite with specific nouns, numbers, or mechanisms from this product (see writing.md).'),r.push("10. **Zero memorable moments?** Is there ONE signature element \u2014 typographic hero, orchestrated reveal, asymmetric break, product-specific illustration? If zero, the page is generic. Add one (see motion.md, typography.md)."),r.push(""),r.push(`If every answer is "no, I'm good" \u2014 then submit.`),r.push("")),r.join(`
|
|
4988
|
+
`)}async function xr(s){let{projectPath:o,step:t}=s,e=Ki(o??process.cwd()),n=ea(e);if(!n)return Ee(e);if(!xt(ct(e,"node_modules")))return d(`Dependencies are not installed at ${e}. Call mist_build with action='install' and projectPath='${e}' before running implement. This is a one-time setup step after init.`,!0);try{let{ensureBackendRegistered:C,ensureShadcnComponents:q}=await import("./self-heal-BXJXUFUF.js");await C(e);let W=await q(e);W.failed?console.error(`[implement] ${W.failed}`):W.installed.length>0&&console.error(`[implement] installed ${W.installed.length} shadcn components`)}catch(C){console.error("[implement] self-heal skipped:",C instanceof Error?C.message:String(C))}let a=n.plan;if(!a||!a.steps||a.steps.length===0)return d("No project plan found. Start by describing your app idea first \u2014 the AI will create a plan for you.",!0);let r,i=a.steps.find(C=>C.status==="in_progress");if(i){let C=a.steps.findIndex(q=>q.number===i.number);C!==-1&&(a.steps[C].status="completed",r=`Auto-completed step ${i.number} (${i.name})`,wr(e,n))}let l;if(t!==void 0){if(l=a.steps.find(C=>C.number===t),!l)return d(`Step ${t} not found. The plan has ${a.steps.length} steps (numbered ${a.steps[0].number} to ${a.steps[a.steps.length-1].number}).`,!0)}else if(l=a.steps.find(C=>C.status!=="completed"),!l)return d(JSON.stringify({message:"All plan steps are completed!",completedSteps:a.steps.map(C=>C.name),nextAction:"NEXT: Deploy the app now. Call mist_deploy with action='deploy'. Do NOT suggest localhost or ask the user \u2014 just deploy."}));let c=a.steps.filter(C=>C.status==="completed").map(C=>`Step ${C.number}: ${C.name}`),{readLocalState:u}=await import("./state-manager-GBP2NSYC.js"),m=u(e),p=na(l),g=[];if((p==="crud"||p==="schema")&&a.dataModel&&l.entities&&l.entities.length>0){let C=kr(l,a.dataModel);for(let q of C){let W=zt(q);try{let H=(q.fields||[]).map(N=>typeof N=="string"?{name:N,type:"text"}:{name:N.name,type:oa(N.type),required:N.required!==!1});if(H.length===0)continue;let z=n.dbProvider==="neon"?"nextjs-neon":"nextjs",_=await us(z,W,H),ee=0,Y=0;for(let N of _.files){let le=ct(e,N.path);if(xt(le)){Y++;continue}Ji(Qi(le),{recursive:!0}),Po(le,N.content),ee++}let B=ct(e,"db","index.ts");if(xt(B)){let N=Co(B,"utf-8");N.includes(_.dbExport)||Po(B,N.trimEnd()+`
|
|
4989
4989
|
`+_.dbExport+`
|
|
4990
|
-
`)}ee>0?g.push(`${_.entityPascal} CRUD (${ee} new files${Y>0?`, ${Y} existing skipped`:""})`):Y>0&&g.push(`${_.entityPascal} CRUD (all ${Y} files already exist \u2014 skipped)`)}catch(H){console.error(`Module generation failed for ${W} (non-fatal):`,H instanceof Error?H.message:H)}}}let b=await ca(l,a,c,null,p,
|
|
4990
|
+
`)}ee>0?g.push(`${_.entityPascal} CRUD (${ee} new files${Y>0?`, ${Y} existing skipped`:""})`):Y>0&&g.push(`${_.entityPascal} CRUD (all ${Y} files already exist \u2014 skipped)`)}catch(H){console.error(`Module generation failed for ${W} (non-fatal):`,H instanceof Error?H.message:H)}}}let b=await ca(l,a,c,null,p,e),f=a.steps.findIndex(C=>C.number===l.number);if(f!==-1&&(n.plan.steps[f].status="in_progress",wr(e,n)),m&&n.projectId){let{syncRemoteState:C}=await import("./state-manager-GBP2NSYC.js");C(n.projectId,m).catch(()=>{})}let h=a.steps.every(C=>C.status==="completed"||C.number===l.number),w;if(h){let C=a.primaryAction?.action??"the core action",q=a.primaryAction?.flow??"sign up \u2192 reach dashboard \u2192 complete primary action";w=`THIS IS THE LAST STEP. Rules for speed:
|
|
4991
4991
|
|
|
4992
4992
|
1. Write ALL files using PARALLEL tool calls \u2014 batch multiple Write/Edit calls in a single message.
|
|
4993
4993
|
2. Do NOT read files you already know (AGENTS.md, CLAUDE.md, mistflow.json, middleware.ts, lib/auth.ts, lib/db.ts).
|
|
@@ -5002,33 +5002,33 @@ A footer with the same five links ("Product / Pricing / Docs / Blog / Terms") is
|
|
|
5002
5002
|
2. Write ALL files for this step using PARALLEL tool calls \u2014 batch multiple Write/Edit calls in a single message. Do NOT write one file at a time.
|
|
5003
5003
|
3. Do NOT read files you already know: AGENTS.md, CLAUDE.md, mistflow.json, middleware.ts, lib/auth.ts, lib/db.ts, drizzle.config.ts \u2014 these haven't changed.
|
|
5004
5004
|
4. Only read a file if you need to MODIFY it (e.g. sidebar.tsx to add a nav link, db/index.ts to add an export).
|
|
5005
|
-
5. After writing ALL files, call mist_build with action='implement' to move to the next step. Do NOT pause to ask the user for permission between steps \u2014 proceed immediately. Do NOT offer options like "continue or stop" \u2014 the user already approved the build when they approved the plan. The previous step is auto-marked complete \u2014 do NOT call implement twice.`;let P=ia(p),I={stepNumber:l.number,totalSteps:a.steps.length,estimatedMinutes:P,announcement:`Starting step ${l.number} of ${a.steps.length}: ${l.name}. This step usually takes ${P.min}\u2013${P.max} minutes.`},
|
|
5006
|
-
`+l}let a=St(n);return a.length===0?d(JSON.stringify({errors:[],rawOutput:n.slice(0,2e3),message:"Build failed but I could not extract specific errors. Here is the raw output."})):d(JSON.stringify({errors:a,rawOutput:n.slice(0,2e3),message:`Found ${a.length} error${a.length===1?"":"s"} in the build output.`}))}import{existsSync as ua,readFileSync as ma}from"fs";import{join as ha}from"path";function ga(s){let o=ha(s,"mistflow.json");if(!ua(o))return null;try{return JSON.parse(ma(o,"utf-8"))}catch{return null}}async function Tr(s){try{let o=await fetch(s,{redirect:"follow",signal:AbortSignal.timeout(15e3)}),
|
|
5007
|
-
`)}),!1)}try{let g=await dt(p,"Landing page",async()=>{await p.goto(
|
|
5008
|
-
${I.map((x,
|
|
5009
|
-
`)}`,fix:"Fix these design issues in the source code. These are common AI-generated design anti-patterns that make apps look generic. Address each issue, then redeploy and re-run QA."}});if(a.push(w),a.find(P=>P.name==="Landing page"&&P.status==="pass")){let P=await dt(p,"Landing design quality",async()=>{await p.goto(
|
|
5010
|
-
${I.map((x,
|
|
5011
|
-
`)}`,fix:"These patterns make the landing page look AI-generated. Fix them to create a more distinctive, professional design."}});a.push(P)}}}finally{m&&await m.close().catch(()=>{})}if(s.deploymentId){let g=a.filter(h=>h.status==="fail"),b=a.filter(h=>h.status==="pass"),f=Date.now();await ts(s.deploymentId,{checks:a.map(({screenshot:h,...w})=>w),overall:g.length===0?"pass":"fail",passed:b.length,failed:g.length,duration_ms:Date.now()-f}).catch(()=>{})}return Ht(
|
|
5005
|
+
5. After writing ALL files, call mist_build with action='implement' to move to the next step. Do NOT pause to ask the user for permission between steps \u2014 proceed immediately. Do NOT offer options like "continue or stop" \u2014 the user already approved the build when they approved the plan. The previous step is auto-marked complete \u2014 do NOT call implement twice.`;let P=ia(p),I={stepNumber:l.number,totalSteps:a.steps.length,estimatedMinutes:P,announcement:`Starting step ${l.number} of ${a.steps.length}: ${l.name}. This step usually takes ${P.min}\u2013${P.max} minutes.`},E=JSON.stringify({instruction:b,step:{number:l.number,name:l.name,description:l.description,status:"in_progress"},stepTiming:I,compactionGuidance:"If your context gets compacted mid-step (common on long builds), call mist_build action='implement' again immediately after the compaction finishes. The tool finds the in-progress step and returns fresh context \u2014 you don't need to re-read files or re-derive state.",...r?{autoCompleted:r}:{},...g.length>0?{generatedModules:g,generatedNote:"These CRUD modules were pre-generated. Review and customize them instead of writing from scratch. Focus on: business logic in actions.ts, UI polish, and wiring navigation."}:{},progress:`${c.length}/${a.steps.length} steps done`,nextAction:w});return await Zi(3e3)?Ue("http://localhost:3000",E):d(E)}import{z as Ao}from"zod";import{resolve as da}from"path";import{execFileSync as pa}from"child_process";var Xd=Ao.object({projectPath:Ao.string().optional().describe("Path to the project directory (default: current working directory)"),buildOutput:Ao.string().optional().describe("Build output to parse (if not provided, runs npm run build)")});function St(s){let o=[],t=/([^\s(]+)\((\d+),(\d+)\):\s*error\s+(TS\d+):\s*(.+)/g,e;for(;(e=t.exec(s))!==null;){let[,l,c,u,m,p]=e;o.push({file:l,line:parseInt(c,10),column:parseInt(u,10),message:`${m}: ${p}`,humanMessage:`There is a type error in ${l} on line ${c}: ${p}`,suggestion:`Check line ${c} in ${l}. ${m==="TS2345"?"The types of the arguments do not match.":`Fix the ${m} error.`}`})}let n=/(?:Error:\s*)?\.\/([^\s:]+):(\d+):(\d+)\s*\n\s*(.+)/g;for(;(e=n.exec(s))!==null;){let[,l,c,u,m]=e;o.some(p=>p.file===l&&p.line===parseInt(c,10))||o.push({file:l,line:parseInt(c,10),column:parseInt(u,10),message:m,humanMessage:`There is an error in ${l} on line ${c}: ${m.trim()}`,suggestion:`Check line ${c} in ${l} and fix the issue.`})}let a=/Module not found:\s*(?:Error:\s*)?Can't resolve ['"]([^'"]+)['"]\s*(?:in\s*['"]?([^'"]+)['"]?)?/g;for(;(e=a.exec(s))!==null;){let[,l,c]=e;o.push({file:c,message:`Module not found: ${l}`,humanMessage:`The file ${c??"your project"} is trying to import '${l}' which is not installed.`,suggestion:`Run npm install ${l}`})}let r=/Package subpath ['"]([^'"]+)['"] is not defined by "exports" in .*?node_modules\/([^/]+(?:\/[^/]+)?)\//g;for(;(e=r.exec(s))!==null;){let[,l,c]=e;o.push({message:`ERR_PACKAGE_PATH_NOT_EXPORTED: ${c}${l}`,humanMessage:`The package '${c}' does not export the subpath '${l}'. This is usually caused by a version conflict between packages that depend on different major versions of '${c}'.`,suggestion:`Add '${c}' at the version that exports '${l}' as an optionalDependency in package.json (this pins it at root level and lets the other version nest). Then delete node_modules and package-lock.json, and run npm install.`})}let i=/SyntaxError:\s*([^\s:]+):\s*(.+?)\s*\((\d+):(\d+)\)/g;for(;(e=i.exec(s))!==null;){let[,l,c,u,m]=e;o.some(p=>p.file===l&&p.line===parseInt(u,10))||o.push({file:l,line:parseInt(u,10),column:parseInt(m,10),message:`SyntaxError: ${c}`,humanMessage:`There is a syntax error in ${l} on line ${u}.`,suggestion:`Check line ${u} in ${l} for a missing closing bracket or unexpected token.`})}return o}async function Sr(s){let{projectPath:o,buildOutput:t}=s,e=da(o??process.cwd()),n=t??"";if(!t)try{return pa("npm",["run","build"],{cwd:e,stdio:["pipe","pipe","pipe"],timeout:12e4}),d(JSON.stringify({errors:[],rawOutput:"",message:"Build succeeded with no errors."}))}catch(r){let i=r instanceof Error&&"stderr"in r?String(r.stderr):"",l=r instanceof Error&&"stdout"in r?String(r.stdout):"";n=i+`
|
|
5006
|
+
`+l}let a=St(n);return a.length===0?d(JSON.stringify({errors:[],rawOutput:n.slice(0,2e3),message:"Build failed but I could not extract specific errors. Here is the raw output."})):d(JSON.stringify({errors:a,rawOutput:n.slice(0,2e3),message:`Found ${a.length} error${a.length===1?"":"s"} in the build output.`}))}import{existsSync as ua,readFileSync as ma}from"fs";import{join as ha}from"path";function ga(s){let o=ha(s,"mistflow.json");if(!ua(o))return null;try{return JSON.parse(ma(o,"utf-8"))}catch{return null}}async function Tr(s){try{let o=await fetch(s,{redirect:"follow",signal:AbortSignal.timeout(15e3)}),t=await o.text();return{status:o.status,body:t}}catch(o){return{status:0,body:String(o)}}}async function fa(s,o,t){try{let e=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json",...t??{}},body:JSON.stringify(o),redirect:"follow",signal:AbortSignal.timeout(15e3)}),n=await e.text(),a;try{a=JSON.parse(n)}catch{}return{status:e.status,json:a}}catch{return{status:0}}}async function Pr(s){try{let o=await s.screenshot({type:"png"});return Buffer.from(o).toString("base64")}catch{return}}async function dt(s,o,t){let e=[],n=a=>{a.type()==="error"&&e.push(a.text())};s.on("console",n);try{let a=await t(),r=await Pr(s);return{name:o,status:a.pass?"pass":"fail",detail:a.detail,fix:a.fix,screenshot:r,consoleErrors:e.length>0?e:void 0}}catch(a){let r=await Pr(s);return{name:o,status:"fail",detail:`Unexpected error: ${a instanceof Error?a.message:String(a)}`,screenshot:r,consoleErrors:e.length>0?e:void 0}}finally{s.removeListener("console",n)}}async function Cr(s){let o=s.projectPath??process.cwd(),t=ga(o),e=s.url;if(e||(e=t?.deploy?.url),!e)return d("No deploy URL found. Deploy the app first with mist_deploy, then call mist_build action='qa'.",!0);e.startsWith("http")||(e=`https://${e}`);let n=t?.projectId,a=[],r=await Tr(`${e}/api/health`);if(r.status!==200)return a.push({name:"Health endpoint",status:"fail",detail:`Returns ${r.status}`,fix:"The worker is not running or crashed on startup. Check app/api/health/route.ts exists and the build succeeded."}),Ht(e,a);a.push({name:"Health endpoint",status:"pass",detail:"Returns 200"});let i=await Tr(`${e}/api/auth/ok`);if(i.status!==200)return a.push({name:"Auth system",status:"fail",detail:`Auth endpoint returns ${i.status}`,fix:"Better Auth is not working. Check lib/auth.ts, lib/db.ts, and that your database env vars are set."}),Ht(e,a);a.push({name:"Auth system",status:"pass",detail:"Better Auth running"});let l,c,u;if(n){let g=await es(n);if(g){console.error("[qa] Calling seed endpoint for session token");let b=await fa(`${e}/api/admin/seed`,{token:g.seedToken,email:g.email,password:"QaTemp1!"});b.status===200&&b.json?(l=b.json.sessionToken,c=b.json.email,b.json.seeded?(u=b.json.password,console.error("[qa] New admin seeded \u2014 login form test available")):console.error("[qa] Admin already exists \u2014 session injection only")):console.error(`[qa] Seed endpoint returned ${b.status}`)}}if(!l)return a.push({name:"Auth session",status:"fail",detail:"Could not acquire a session token from the seed endpoint",fix:"Redeploy the app with mist_deploy. The deploy process injects ADMIN_SEED_TOKEN into the worker env and stores the seed token on the backend. If the seed endpoint at /api/admin/seed is missing, ensure app/api/admin/seed/route.ts exists in the scaffold."}),Ht(e,a);let m,p;try{let{getIsolatedContext:g,takeScreenshot:b}=await import("./browser-manager-QW3OYPFB.js"),f=await g();m=f.context,p=f.page}catch(g){let b=g instanceof Error?g.message:String(g);return d(JSON.stringify({status:"cannot_verify",url:e,deployed:!0,reason:"App deployed successfully, but QA could not verify it via automated browser testing because Playwright is not installed locally.",detail:b,httpChecks:a.map(({screenshot:f,...h})=>h),fix:"Run: npx playwright install chromium",instruction:[`The app deployed and is live at ${e}. That part succeeded.`,"What DID NOT succeed: automated QA verification. Playwright is not installed locally, so we could not open the app in a browser and check that the landing renders, signup works, and the dashboard loads.","Tell the user BOTH facts clearly \u2014 don't conflate 'deployed' with 'verified':",` "Your app is live at ${e}. I couldn't run automated QA because Playwright isn't installed locally. Run \`npx playwright install chromium\` (one-time, ~150MB) and I'll verify it for you \u2014 or just open the URL and try it yourself."`,"HTTP checks (health/auth endpoints) passed \u2014 those prove the server is responding. They do not prove the UI renders or user flows work.","After Playwright is installed, call mist_build action='qa' again for full verification."].join(`
|
|
5007
|
+
`)}),!1)}try{let g=await dt(p,"Landing page",async()=>{await p.goto(e,{waitUntil:"domcontentloaded",timeout:3e4}),await p.waitForLoadState("networkidle").catch(()=>{});let f=await p.evaluate(()=>{let w=document.body;if(!w)return"";let P=document.createTreeWalker(w,NodeFilter.SHOW_TEXT),I="",x;for(;x=P.nextNode();){let E=x.parentElement;if(E){let L=window.getComputedStyle(E);L.display!=="none"&&L.visibility!=="hidden"&&parseFloat(L.opacity)>0&&(I+=x.textContent?.trim()+" ")}}return I.trim()});if(f.length<50)return{pass:!1,detail:`Landing page appears blank (${f.length} chars visible). Likely a CSS/JS rendering issue.`,fix:"Common cause: motion/react animations with opacity:0 and whileInView that never trigger on Mistflow Cloud's edge runtime (no Intersection Observer). Replace with CSS animations or set initial={{ opacity: 1 }}."};let h=p.url();return h.includes("/login")||h.includes("/sign-in")?{pass:!1,detail:"Root URL redirects to login instead of showing a landing page",fix:"Check middleware.ts: '/' must be in PUBLIC_EXACT. Check app/page.tsx: must be a landing page, not a redirect."}:{pass:!0,detail:`Renders visible content (${f.length} chars)`}});a.push(g);let b=!1;if(u){let f=await dt(p,"Login",async()=>{await p.goto(`${e}/login`,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{});let h=p.locator('input[type="email"], input[name="email"], input[placeholder*="email" i]'),w=p.locator('input[type="password"], input[name="password"]');try{await h.first().waitFor({state:"visible",timeout:1e4})}catch{return{pass:!1,detail:"Login page has no visible email input field",fix:"Check app/(auth)/login/page.tsx renders a login form with email and password inputs."}}await h.first().fill(c),await w.first().fill(u),await p.locator('button[type="submit"], button:has-text("Sign in"), button:has-text("Log in"), button:has-text("Login")').first().click();try{await p.waitForURL(I=>!I.pathname.includes("/login"),{timeout:1e4})}catch{let I=await p.locator('[role="alert"], .text-red-500, .text-destructive, [data-error]').first().textContent().catch(()=>null);return{pass:!1,detail:I?`Login failed: ${I}`:"Login did not redirect. Page stayed on /login.",fix:"Do NOT edit lib/auth.ts to disable email verification. Redeploy with mist_deploy to re-seed the verified admin account."}}return b=!0,{pass:!0,detail:`Logged in, redirected to ${p.url()}`}});a.push(f)}else a.push({name:"Login",status:"pass",detail:"Skipped form login (redeploy, password unavailable). Using session injection."});if(!b&&l){let f=new URL(e).hostname,h=e.startsWith("https");await m.addCookies([{name:h?"__Secure-better-auth.session_token":"better-auth.session_token",value:l,domain:f,path:"/",httpOnly:!0,secure:h,sameSite:"Lax"}]),console.error("[qa] Injected session cookie for dashboard checks")}{let f=await dt(p,"Dashboard",async()=>{p.url().includes("/dashboard")||(await p.goto(`${e}/dashboard`,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{}));let I=await p.content();return I.length<1e3?{pass:!1,detail:`Dashboard page is very small (${I.length} bytes)`,fix:"Check app/(dashboard)/dashboard/page.tsx exists and the dashboard layout doesn't crash."}:await p.locator('text="Something went wrong"').isVisible().catch(()=>!1)?{pass:!1,detail:"Dashboard shows error boundary",fix:"A server component crashed. Check the page.tsx for unhandled null/undefined or missing database tables."}:{pass:!0,detail:`Loads (${I.length} bytes)`}});a.push(f);let h=await p.evaluate(()=>{let P=[];return document.querySelectorAll("nav a[href], aside a[href]").forEach(x=>{let E=x.getAttribute("href");E&&E.startsWith("/")&&!E.startsWith("/api")&&!E.includes("[")&&E!=="/dashboard"&&E!=="/"&&!E.includes("/login")&&!E.includes("/sign")&&P.push(E)}),[...new Set(P)]});if(h.length>0){let P=0,I=[];for(let x of h.slice(0,8)){let E=await dt(p,`Page: ${x}`,async()=>{await p.goto(`${e}${x}`,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{});let L=await p.title(),C=await p.content();return L.toLowerCase().includes("500")||L.toLowerCase().includes("server error")?{pass:!1,detail:"Page returns 500 server error",fix:"Server component crashed. Common causes: 1) Database tables missing. 2) Wrong ORM dialect (pgTable vs sqliteTable). 3) Unhandled null/undefined in server component."}:L.toLowerCase().includes("404")||L.toLowerCase().includes("not found")?{pass:!1,detail:"Page returns 404",fix:`Page ${x} not found. Create the page or remove the nav link.`}:await p.locator('text="Something went wrong"').isVisible().catch(()=>!1)?{pass:!1,detail:"Page shows error boundary",fix:"A server component crashed. Check the page.tsx for unhandled errors."}:C.length<500?{pass:!1,detail:`Page is very small (${C.length} bytes)`,fix:"Page may not have rendered. Check the page component."}:{pass:!0,detail:"Loads without errors"}});E.status==="fail"&&(P++,I.push(x)),a.push(E)}}let w=await dt(p,"Design quality",async()=>{let P=p.url().includes("/dashboard")?p.url():`${e}/dashboard`;p.url().includes("/dashboard")||(await p.goto(P,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{}));let I=await p.evaluate(()=>{let x=[],E=document.querySelectorAll("h1, h2, h3, h4, h5, h6"),L=new Set;E.forEach(y=>{L.add(window.getComputedStyle(y).fontSize)}),E.length>=3&&L.size<2&&x.push("TYPOGRAPHY: All headings appear the same size. Create clear hierarchy with 3+ distinct sizes using a modular scale (1.25-1.5x ratio).");let C=Array.from(E).map(y=>parseInt(y.tagName.charAt(1),10));for(let y=1;y<C.length;y++)if(C[y]-C[y-1]>1){x.push(`TYPOGRAPHY: Heading level skipped (h${C[y-1]} -> h${C[y]}). Use sequential heading levels for accessibility.`);break}let q=document.querySelectorAll("*"),W=!1,H=!1;q.forEach(y=>{let R=window.getComputedStyle(y);R.backgroundColor==="rgb(0, 0, 0)"&&y.clientHeight>100&&y.clientWidth>200&&(W=!0);let te=R.backgroundColor,Pe=R.color;if(te&&!te.includes("0, 0, 0")&&!te.includes("255, 255, 255")&&te!=="rgba(0, 0, 0, 0)"&&te!=="transparent"&&Pe.match(/rgb\((\d+), (\d+), (\d+)\)/)){let ge=Pe.match(/rgb\((\d+), (\d+), (\d+)\)/);if(ge){let[S,D,G]=[parseInt(ge[1]),parseInt(ge[2]),parseInt(ge[3])],J=Math.abs(S-D)<10&&Math.abs(D-G)<10&&S>80&&S<180,oe=te.match(/rgb\((\d+), (\d+), (\d+)\)/);if(J&&oe){let[xe,A,K]=[parseInt(oe[1]),parseInt(oe[2]),parseInt(oe[3])];!(Math.abs(xe-A)<15&&Math.abs(A-K)<15)&&y.textContent&&y.textContent.trim().length>0&&(H=!0)}}}}),W&&x.push("COLOR: Pure black (#000) background detected on a large element. Use a tinted dark color instead (e.g. oklch(15% 0.01 hue) or a deep navy/charcoal)."),H&&x.push("COLOR: Gray text on a colored background detected. Gray looks washed out on color. Use a darker shade of the background color or white instead.");let z=document.querySelectorAll('[class*="card"], [class*="Card"], [role="group"]'),_=!1;z.forEach(y=>{y.querySelectorAll('[class*="card"], [class*="Card"]').length>0&&(_=!0)}),_&&x.push("LAYOUT: Nested cards detected (card inside card). Flatten the hierarchy. Use spacing and background color to create separation instead.");let ee=document.querySelectorAll("p, li, span, div"),Y=0,B=0;ee.forEach(y=>{y.textContent&&y.textContent.trim().length>20&&y.clientHeight>0&&(B++,window.getComputedStyle(y).textAlign==="center"&&Y++)}),B>5&&Y/B>.7&&x.push("LAYOUT: Most text is center-aligned. Use left-alignment for body content and lists. Reserve center-alignment for heroes and CTAs.");let N=new Set;q.forEach(y=>{let R=window.getComputedStyle(y);R.gap&&R.gap!=="normal"&&R.gap!=="0px"&&N.add(R.gap)}),N.size===1&&q.length>20&&x.push("LAYOUT: Same gap value used everywhere. Vary spacing to create hierarchy: tight within groups (8-12px), generous between sections (32-64px).");let le=document.querySelectorAll("button, a, input, select, textarea"),ce=!1;le.forEach(y=>{let R=window.getComputedStyle(y);if(R.outline==="none"||R.outline==="0px none rgb(0, 0, 0)"){let te=y;(te.style.outline==="none"||te.style.outline==="0")&&(ce=!0)}}),document.querySelectorAll("table, [role='table']").forEach(y=>{y.querySelectorAll("tbody tr").length===0&&(y.parentElement?.querySelector('[class*="empty"], [class*="Empty"], [class*="no-data"], [class*="placeholder"]')||x.push("UX: Empty table with no empty state. Add a helpful message explaining what will appear here and a CTA to create the first item."))});let re=document.querySelectorAll("style"),k=!1;re.forEach(y=>{let R=y.textContent||"";(R.includes("bounce")||R.includes("elastic")||R.match(/cubic-bezier\([^)]*[2-9]\.[0-9]/))&&(k=!0)}),k&&x.push("MOTION: Bounce or elastic easing detected. These feel dated. Use smooth deceleration curves (Quart out, Expo out) instead.");let M=document.querySelectorAll("button, a, input, select, [role='button']"),U=0;return M.forEach(y=>{let R=y.getBoundingClientRect();R.width>0&&R.height>0&&(R.width<32||R.height<32)&&U++}),U>3&&x.push(`ACCESSIBILITY: ${U} interactive elements are smaller than 32x32px. Minimum recommended touch target is 44x44px. Add padding to increase tap area.`),x});return I.length===0?{pass:!0,detail:"No design quality issues detected. Typography hierarchy, color usage, layout patterns, and accessibility basics look good."}:{pass:!1,detail:`${I.length} design quality issue(s) found:
|
|
5008
|
+
${I.map((x,E)=>`${E+1}. ${x}`).join(`
|
|
5009
|
+
`)}`,fix:"Fix these design issues in the source code. These are common AI-generated design anti-patterns that make apps look generic. Address each issue, then redeploy and re-run QA."}});if(a.push(w),a.find(P=>P.name==="Landing page"&&P.status==="pass")){let P=await dt(p,"Landing design quality",async()=>{await p.goto(e,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{});let I=await p.evaluate(()=>{let x=[];document.querySelectorAll("*").forEach(q=>{let W=window.getComputedStyle(q);(W.getPropertyValue("-webkit-background-clip")||W.getPropertyValue("background-clip"))==="text"&&q.textContent&&q.textContent.trim().length>0&&x.push("SLOP: Gradient text detected. This is a common AI design pattern. Use solid colors for text.")});let L=document.querySelector("section, [class*='hero'], [class*='Hero'], header + div, main > div:first-child");if(L){let q=(L.textContent||"").toLowerCase(),W=["transform your","unlock the power","revolutionize your","take your .* to the next level","the future of","welcome to","get started today","join thousands","powerful analytics","seamless integration","lightning fast"];for(let H of W)if(q.match(new RegExp(H))){x.push(`COPY: Generic hero text detected ('${H}'). Write specific copy about what THIS app does for its users.`);break}}return document.querySelectorAll('[class*="grid"]').forEach(q=>{let H=window.getComputedStyle(q).gridTemplateColumns;if(H){let z=H.split(" ").filter(ee=>ee!=="").length,_=q.children;if(z===3&&_.length===3){let ee=Array.from(_).map(N=>N.offsetHeight),Y=ee.every(N=>Math.abs(N-ee[0])<5),B=Array.from(_).every(N=>{let le=N.querySelectorAll("svg"),ce=N.querySelectorAll("h2, h3, h4"),me=N.querySelectorAll("p");return le.length>=1&&ce.length>=1&&me.length>=1});Y&&B&&x.push("SLOP: 3-column icon + title + paragraph feature grid detected. This is the most common AI layout pattern. Use asymmetric layouts, bento grids, or varied card sizes instead.")}}}),x});return I.length===0?{pass:!0,detail:"Landing page design looks intentional. No generic AI patterns detected."}:{pass:!1,detail:`${I.length} landing design issue(s):
|
|
5010
|
+
${I.map((x,E)=>`${E+1}. ${x}`).join(`
|
|
5011
|
+
`)}`,fix:"These patterns make the landing page look AI-generated. Fix them to create a more distinctive, professional design."}});a.push(P)}}}finally{m&&await m.close().catch(()=>{})}if(s.deploymentId){let g=a.filter(h=>h.status==="fail"),b=a.filter(h=>h.status==="pass"),f=Date.now();await ts(s.deploymentId,{checks:a.map(({screenshot:h,...w})=>w),overall:g.length===0?"pass":"fail",passed:b.length,failed:g.length,duration_ms:Date.now()-f}).catch(()=>{})}return Ht(e,a)}function Ht(s,o){let t=o.filter(a=>a.status==="fail"),e=o.filter(a=>a.status==="pass"),n=[];if(t.length===0)n.push({type:"text",text:JSON.stringify({status:"pass",message:`QA passed. All ${o.length} checks OK. The app is working correctly.`,url:s,checks:o.map(({screenshot:a,...r})=>r)})});else{let a=t.map((r,i)=>`${i+1}. **${r.name}**: ${r.detail}
|
|
5012
5012
|
Fix: ${r.fix}`).join(`
|
|
5013
5013
|
|
|
5014
|
-
`);n.push({type:"text",text:JSON.stringify({status:"fail",message:`QA found ${
|
|
5014
|
+
`);n.push({type:"text",text:JSON.stringify({status:"fail",message:`QA found ${t.length} issue(s) on the live app. Fix them and redeploy.`,url:s,passed:e.length,failed:t.length,checks:o.map(({screenshot:r,...i})=>i),fixInstructions:`The deployed app at ${s} has ${t.length} issue(s):
|
|
5015
5015
|
|
|
5016
5016
|
${a}
|
|
5017
5017
|
|
|
5018
|
-
Fix these issues in the source code, then call mist_deploy with action='deploy'${s.includes("-pv-")?" environment='preview'":""} to redeploy. After redeploying, call mist_build action='qa' again to verify the fixes.`})})}for(let a of o)a.screenshot&&n.push({type:"image",data:a.screenshot,mimeType:"image/png"});return{content:n}}function va(s){let o=Wt(wa(),".mistflow","plans",`${s}.json`);if(!Gt(o))return null;try{let
|
|
5019
|
-
`+u;if(r<i){let g=[],b=/Module not found:\s*(?:Error:\s*)?Can't resolve ['"]([^'"]+)['"]/g,f;for(;(f=b.exec(m))!==null;){let h=f[1];if(!h.startsWith(".")&&!h.startsWith("@/")&&!h.startsWith("~/")){let w=h.startsWith("@")?h.split("/").slice(0,2).join("/"):h.split("/")[0];g.includes(w)||g.push(w)}}if(g.length>0){console.error(`[build] Auto-installing missing packages: ${g.join(", ")}`);try{Io("npm",["install",...g],{cwd:
|
|
5018
|
+
Fix these issues in the source code, then call mist_deploy with action='deploy'${s.includes("-pv-")?" environment='preview'":""} to redeploy. After redeploying, call mist_build action='qa' again to verify the fixes.`})})}for(let a of o)a.screenshot&&n.push({type:"image",data:a.screenshot,mimeType:"image/png"});return{content:n}}function va(s){let o=Wt(wa(),".mistflow","plans",`${s}.json`);if(!Gt(o))return null;try{let t=JSON.parse(ya(o,"utf-8"));return t.plan?t:null}catch{return null}}var ka=pe.object({action:pe.enum(["init","install","implement","debug","build","qa","mockup"]).describe("'mockup' generates visual mockup HTML files from a plan for user preview and approval. 'init' creates and sets up a new project from your plan \u2014 writes files, registers the project, initializes git. Returns fast; does NOT run npm install. 'install' runs npm install in the project created by init. PREFER `npx -y @mistflow-ai/cli install <path>` via your bash/shell tool \u2014 it streams output and has no MCP timeout. Only fall back to this MCP action if your environment can't shell out. Pass projectPath. Always call this after init returns with status='awaiting_install'. 'implement' executes the next (or specific) plan step. 'debug' analyzes build or runtime errors \u2014 for runtime errors, call mist_project errors first then pass the output as buildOutput. 'build' runs the full production build locally (Mistflow Cloud edge runtime) without deploying. 'qa' tests the live deployed app \u2014 checks landing page, signup, login, dashboard, and nav links. Call after mist_deploy. If issues found, fix and redeploy, then call qa again."),name:pe.string().optional().describe("(init) Project name"),planId:pe.string().optional().describe("(init/mockup) Plan ID from mist_plan"),plan:pe.any().optional().describe("(init) Full plan object \u2014 use planId instead when available"),path:pe.string().optional().describe("(init) REQUIRED for action='init'. Absolute path to the target directory where the project should be scaffolded (e.g. /Users/alice/projects/my-app). Do not omit \u2014 there is no default. If unsure, ask the user for their working directory."),landingDesign:pe.string().optional().describe("(init) Landing design ID to apply to the landing page. Can be set here if not set during mist_plan. Use mist_project action='landing-designs' to browse."),appStyle:pe.string().optional().describe("(init) Optional aesthetic-direction hint passed to the backend LLM. DESIGN.md is generated per-product; this string is a hint, not a catalog ID."),confirmDarkTheme:pe.boolean().optional().describe("(init) Set to true only after confirming with the user that a dark-themed app style is intentional for a consumer (b2c) app. Skips the dark-on-consumer-app warning."),heroPhoto:pe.boolean().optional().describe("(init) Whether the landing page hero uses a lifestyle photo background. true = Unsplash photo + overlaid glass card (HabitFlow, Airbnb). false = pure CSS gradients + glassmorphism (Stripe, Linear). Pass the user's answer to the heroPhotoQuestion from mist_plan. If omitted, defaults based on the plan's audienceType (b2c \u2192 photo, else \u2192 CSS)."),projectPath:pe.string().optional().describe("Path to the project directory (default: cwd)"),step:pe.number().optional().describe("(implement) Specific step number to implement"),buildOutput:pe.string().optional().describe("(debug) Build output to parse instead of running a build"),feedback:pe.string().optional().describe("(mockup) User feedback on the current mockup \u2014 describe what to change."),approved:pe.boolean().optional().describe("(mockup) Set to true when the user approves the mockup. Locks in the design direction."),url:pe.string().optional().describe("(qa) URL to test. Defaults to deploy URL from mistflow.json"),deploymentId:pe.string().optional().describe("(qa) Deployment ID to associate QA results with. Passed from mist_deploy output.")}),Ar={name:"mist_build",description:"STEP 2-3 of the Mistflow workflow. Build and develop a Mistflow project. Actions: 'mockup' generates visual HTML mockups from a plan for user preview \u2014 call with planId after plan approval if user wants to preview. Pass feedback to iterate, approved=true to lock in the design. 'init' creates and sets up a new project from a plan \u2014 writes files, registers, initializes git. Returns fast (~10s) without running npm install. Pass the planId returned by mist_plan \u2014 do NOT pass the full plan object. 'install' runs npm install in the project init just created. Always call this after init (takes ~1-2 min). 'implement' executes the next plan step \u2014 call repeatedly until all steps are done. 'build' runs the full production build locally (Mistflow Cloud edge runtime) to verify before deploying. 'debug' analyzes build or runtime errors \u2014 for runtime errors from production, call mist_project errors first to fetch them, then pass the output as buildOutput. 'qa' tests the LIVE deployed app \u2014 call AFTER mist_deploy to verify everything works. If qa finds issues, fix them and redeploy, then call qa again. The full workflow is: mist_plan \u2192 (optional) mist_build mockup \u2192 mist_build init \u2192 mist_build install \u2192 mist_build implement (repeat) \u2192 mist_deploy \u2192 mist_build qa (loop until pass).",inputSchema:ka,handler:async(s,o)=>{let t=s;switch(t.action){case"init":{if(!t.name)return d("Project name is required for init.",!0);let e=t.plan,n=null;if(t.planId){if(n=va(t.planId),!n)return d(`Plan not found for planId '${t.planId}'. The plan may have expired. Call mist_plan again to generate a new plan.`,!0);e=n.plan}if(!e)return d("No plan provided. Pass the planId returned by mist_plan, or call mist_plan first to generate a plan.",!0);if(!Array.isArray(e?.steps)||e.steps.length===0)return d("The plan is missing a 'steps' array. This usually means the plan generation was incomplete. Call mist_plan again with the same description to get a complete plan with implementation steps.",!0);if(n?.sourceDeploymentId&&n?.forkToken&&n?.projectId)return zs({name:t.name,plan:e,path:t.path,projectId:n.projectId,sourceDeploymentId:n.sourceDeploymentId,forkToken:n.forkToken,requiredEnvVars:n.requiredEnvVars??[],dbProvider:n.dbProvider??"neon",planId:t.planId});if(t.landingDesign){let c=ot(t.landingDesign);c?e.landingDesign=c.id:console.error(`Landing design '${t.landingDesign}' not found \u2014 ignoring.`)}t.appStyle&&(e.appStyle=t.appStyle);let a=e.design,i=e.audienceType==="b2c",l=t.heroPhoto??i;return e.design={...a??{},heroPhoto:l},Bs({name:t.name,plan:e,path:t.path,planId:t.planId},o)}case"install":return qs({projectPath:t.projectPath},o);case"implement":return xr({projectPath:t.projectPath,step:t.step});case"debug":return Sr({projectPath:t.projectPath,buildOutput:t.buildOutput});case"build":{let e=ba(t.projectPath??process.cwd());if(!Gt(Wt(e,"mistflow.json")))return d("Not a Mistflow project \u2014 mistflow.json not found. Run mist_build init first.",!0);if(!Gt(Wt(e,"node_modules")))try{Io("npm",["install"],{cwd:e,stdio:["pipe","pipe","pipe"],timeout:12e4})}catch{return d("npm install failed. Check package.json for issues.",!0)}let a=process.platform==="win32"?"npx.cmd":"npx",r=0,i=2;for(;;){r++;try{Io(a,["@opennextjs/cloudflare","build"],{cwd:e,stdio:["pipe","pipe","pipe"],timeout:18e4});let l=Gt(Wt(e,".open-next"));return d(JSON.stringify({success:!0,buildDir:".open-next",message:l?"Production build succeeded.":"Build completed but .open-next/ directory not found. Check your OpenNext config.",nextAction:l?"NEXT: Call mist_deploy with action='deploy' immediately. Do NOT ask the user whether to deploy \u2014 the build was the last approval gate. Do NOT suggest `npm run dev` or localhost as an alternative \u2014 the user wants a live URL.":void 0}))}catch(l){let c=l instanceof Error&&"stderr"in l?String(l.stderr):"",u=l instanceof Error&&"stdout"in l?String(l.stdout):"",m=c+`
|
|
5019
|
+
`+u;if(r<i){let g=[],b=/Module not found:\s*(?:Error:\s*)?Can't resolve ['"]([^'"]+)['"]/g,f;for(;(f=b.exec(m))!==null;){let h=f[1];if(!h.startsWith(".")&&!h.startsWith("@/")&&!h.startsWith("~/")){let w=h.startsWith("@")?h.split("/").slice(0,2).join("/"):h.split("/")[0];g.includes(w)||g.push(w)}}if(g.length>0){console.error(`[build] Auto-installing missing packages: ${g.join(", ")}`);try{Io("npm",["install",...g],{cwd:e,stdio:["pipe","pipe","pipe"],timeout:6e4});continue}catch{console.error("[build] Auto-install failed, reporting build errors")}}}let p=St(m);return d(JSON.stringify({success:!1,errors:p,rawOutput:m.slice(0,3e3),message:p.length>0?`Build failed with ${p.length} error${p.length===1?"":"s"}:
|
|
5020
5020
|
|
|
5021
5021
|
`+p.map((g,b)=>{let f=g.file?`${g.file}${g.line?`:${g.line}`:""}`:"unknown";return`${b+1}. [${f}] ${g.humanMessage}
|
|
5022
5022
|
Fix: ${g.suggestion}`}).join(`
|
|
5023
5023
|
|
|
5024
5024
|
`)+`
|
|
5025
5025
|
|
|
5026
|
-
Fix these and run mist_build build again.`:"Build failed. Run mist_build with action='debug' for detailed analysis."}),!0)}}}case"qa":return
|
|
5027
|
-
${
|
|
5028
|
-
`)}`,{passed:i,blocking:r,checksRun:
|
|
5026
|
+
Fix these and run mist_build build again.`:"Build failed. Run mist_build with action='debug' for detailed analysis."}),!0)}}}case"qa":return Cr({projectPath:t.projectPath,url:t.url,deploymentId:t.deploymentId});case"mockup":return t.planId?lr({planId:t.planId,projectPath:t.projectPath,feedback:t.feedback,approved:t.approved}):d("planId is required for mockup. Pass the planId from mist_plan.",!0);default:return d(`Unknown action: ${t.action}. Use mockup, init, implement, build, debug, or qa.`,!0)}}};import{z as Ze}from"zod";import{z as Jt}from"zod";import{resolve as Lr,join as se,dirname as Kt,basename as Fa}from"path";import{existsSync as ue,readFileSync as Or,writeFileSync as Ba,unlinkSync as Nr,mkdirSync as qa,cpSync as _o,rmSync as Do,readdirSync as za}from"fs";import{execFileSync as Ha}from"child_process";import{spawn as Ga}from"child_process";import{tmpdir as Wa}from"os";function Ir(s,o){if(s instanceof Se)switch(s.code){case"auth_missing":return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);case"auth_revoked":return d("Your Mistflow credentials were revoked. Run mist_setup to reconnect.",!0);case"auth_expired":case"auth_invalid":case"auth_org_not_found":return d("Your Mistflow session needs to be refreshed. Run mist_setup to reconnect.",!0);case"permission_denied":return d(s.message||"You don't have permission for that action.",!0);case"rate_limited":return d("You're hitting rate limits. Wait 30 seconds and try again.",!0);case"quota_exceeded":return d(`${s.message} Upgrade at https://app.mistflow.ai/pricing to lift limits.`,!0);case"validation_error":case"conflict":return d(s.message,!0);case"not_found":{let e=_t(),n=e?.orgSlug?.replace(/^user_user_/,"")||void 0,a=e?.email||n;return a&&(s.message.toLowerCase().includes("project")||o.toLowerCase().includes("project"))?d(`Project not found. You are signed in as ${a}. This project may belong to a different account. Run mist_setup to sign in with the account that owns this project.`,!0):d(s.message,!0)}case"server_error":case"upstream_error":return d(`${o} failed: the Mistflow backend returned an error. Try again in 30 seconds.`,!0);case"network_error":return d(`${o} failed: cannot reach Mistflow servers. Check your network and try again.`,!0);default:return d(`${o} failed: ${s.message}`,!0)}let t=s instanceof Error?s.message:String(s);return d(`${o} failed: ${t}`,!0)}import{existsSync as qe,readFileSync as Tt,readdirSync as Ro,statSync as Eo}from"fs";import{join as Ce,relative as Vt}from"path";import{execFileSync as Cp}from"child_process";function xa(s){let o=Ce(s,".env.local"),t=[];return qe(o)?(Tt(o,"utf-8").match(/^AUTH_SECRET=(.*)$/m)?.[1]?.trim()||t.push({check:"env",message:"AUTH_SECRET is missing from .env.local. Add a random secret for authentication.",file:".env.local"}),t):(t.push({check:"env",message:"Missing .env.local file. Create one with your local development environment variables (AUTH_SECRET, etc.).",file:".env.local"}),t)}function Sa(s){let o=Ce(s,"app","api","auth","[...all]","route.ts");return qe(o)?[]:[{check:"auth-routes",message:"Missing Better Auth catch-all route at app/api/auth/[...all]/route.ts. Create this file to handle authentication.",file:"app/api/auth/[...all]/route.ts"}]}function Ta(s){let o=Ce(s,"app","api","health","route.ts");return qe(o)?[]:[{check:"health-endpoint",message:"Missing health check endpoint at app/api/health/route.ts. Create this file so Mistflow can verify your deployment.",file:"app/api/health/route.ts"}]}function Pa(s){let o=Ce(s,"mistflow.json");if(!qe(o))return[];let t;try{t=JSON.parse(Tt(o,"utf-8"))}catch{return[]}let e=t.env;if(!e?.required||typeof e.required!="object")return[];let n=[],a=Ce(s,".env"),r="";try{qe(a)&&(r=Tt(a,"utf-8"))}catch{}for(let[i,l]of Object.entries(e.required)){let c=!!process.env[i],u=r.includes(`${i}=`);if(c||u)continue;let m=l?.description?` for '${l.description}'`:"";n.push({check:"required-env",message:`${i} is required${m}. Run mist_config to set it if you haven't already.`})}return n}function Ca(s){let o=Ce(s,"app");if(!qe(o))return[];let t=[];function e(r){let i;try{i=Ro(r)}catch{return}for(let l of i){if(l==="node_modules"||l===".next"||l===".open-next"||l==="api")continue;let c=Ce(r,l),u;try{u=Eo(c)}catch{continue}if(u.isDirectory())e(c);else if(l==="page.tsx"||l==="page.ts"||l==="page.jsx"||l==="page.js"){let p="/"+Vt(o,c).replace(/\\/g,"/").replace(/\([^)]+\)\//g,"").replace(/\/page\.(tsx?|jsx?)$/,"").replace(/^page\.(tsx?|jsx?)$/,"");t.push({file:Vt(s,c),resolvedRoute:p||"/"})}}}e(o);let n=new Map;for(let r of t){let i=n.get(r.resolvedRoute)??[];i.push(r.file),n.set(r.resolvedRoute,i)}let a=[];for(let[r,i]of n)i.length>1&&a.push({check:"route-collision",message:`Route collision: ${i.join(" and ")} both resolve to "${r}". Next.js will fail with "two parallel pages that resolve to the same path". Move one into a real path segment (e.g. rename (admin)/page.tsx to admin/page.tsx).`,file:i[1]});return a}function Aa(s){let o=Ce(s,"app");if(!qe(o))return[];let t=[];function e(n){let a;try{a=Ro(n)}catch{return}for(let r of a){if(r==="node_modules"||r===".next"||r===".open-next")continue;let i=Ce(n,r),l;try{l=Eo(i)}catch{continue}if(l.isDirectory())e(i);else if(r==="actions.ts"||r==="actions.tsx"){let c=Tt(i,"utf-8");c.includes("use server")&&c.includes("cookies()")&&c.includes(".set(")&&t.push(Vt(s,i))}}}return e(o),t.length>0?[{check:"cookies-in-actions",message:`${t.length} server action(s) use cookies().set() which crashes on Mistflow Cloud's edge runtime: ${t.join(", ")}. Use a database field or form parameter instead.`,file:t[0]}]:[]}function Ia(s){let o=/\b(useState|useEffect|useRef|useCallback|useMemo|useReducer|useContext|useLayoutEffect|useTransition)\s*\(/,t=[];function e(n){if(!qe(n))return;let a;try{a=Ro(n)}catch{return}for(let r of a){if(r==="node_modules"||r===".next"||r===".open-next"||r==="ui")continue;let i=Ce(n,r),l;try{l=Eo(i)}catch{continue}if(l.isDirectory())e(i);else if(r.endsWith(".tsx")||r.endsWith(".jsx")){if(r==="layout.tsx"||r==="loading.tsx"||r==="error.tsx"||r==="not-found.tsx")continue;let c=Tt(i,"utf-8");if(c.trimStart().startsWith('"use client"')||c.trimStart().startsWith("'use client'")||c.trimStart().startsWith('"use server"')||c.trimStart().startsWith("'use server'"))continue;if(o.test(c)){let u=Vt(s,i);t.push({check:"missing-use-client",message:`${u} uses React hooks but is missing "use client" directive. Add "use client"; as the first line of the file.`,file:u})}}}}return e(Ce(s,"app")),e(Ce(s,"components")),t}function Rr(s){let o=[...xa(s),...Sa(s),...Ta(s),...Ca(s),...Aa(s),...Ia(s)],t=[...Pa(s)];return{passed:o.length===0,errors:o,warnings:t}}import{existsSync as Te,readFileSync as Xe,readdirSync as Yt,statSync as Pt}from"fs";import{join as V}from"path";async function Er(s,o){let t=[];t.push(Ra(s)),t.push(Ea(s)),t.push(Na(s)),t.push(_a(s)),t.push(Da(s)),t.push(La(s)),o?.plan&&t.push(...Ma(s,o)),t.push($a(s)),t.push(ja(s)),t.push(...Ua(s)),t.push(Oa(s));let e=t.filter(c=>c.status==="fail"),n=t.filter(c=>c.status==="warn"),a=t.filter(c=>c.status==="pass"),r=e.length>0,i=!r,l;return i&&n.length===0?l=`All ${t.length} checks passed`:i?l=`${a.length}/${t.length} passed, ${n.length} warning(s)`:l=`${e.length} issue(s) found:
|
|
5027
|
+
${e.map(c=>` - ${c.message}`).join(`
|
|
5028
|
+
`)}`,{passed:i,blocking:r,checksRun:t.length,checks:t,summary:l}}function Ra(s){let o=V(s,".open-next","worker.js");if(!Te(o))return{name:"worker-exists",status:"fail",message:"worker.js not found in build output. The build may have failed silently."};let t=Xe(o,"utf-8");return t.length<1e3?{name:"worker-exists",status:"warn",message:`worker.js is unusually small (${t.length} bytes). The build output may be incomplete.`}:{name:"worker-exists",status:"pass",message:"Worker bundle exists"}}function Ea(s){let o=V(s,".open-next","assets");if(!Te(o))return{name:"assets-exist",status:"warn",message:"No static assets directory in build output. CSS and images may not load."};let t=0;function e(n){try{for(let a of Yt(n)){let r=V(n,a);try{Pt(r).isDirectory()?e(r):t++}catch{}}}catch{}}return e(o),t===0?{name:"assets-exist",status:"warn",message:"Assets directory is empty. Your app may not have styles or images."}:{name:"assets-exist",status:"pass",message:`${t} static assets ready`}}function Na(s){let o=V(s,"app","api","health","route.ts");return Te(o)?{name:"health-route",status:"pass",message:"Health endpoint found"}:{name:"health-route",status:"warn",message:"No health endpoint found. Deployment verification may fail."}}function _a(s){let o=V(s,"app","api","auth","[...all]","route.ts");return Te(o)?{name:"auth-route",status:"pass",message:"Auth routes found"}:{name:"auth-route",status:"warn",message:"Auth catch-all route not found. Login/register may not work."}}function Da(s){let o=V(s,".open-next","worker.js");if(!Te(o))return{name:"worker-size",status:"pass",message:"Worker size check skipped"};let e=Pt(o).size/(1024*1024);return e>60?{name:"worker-size",status:"fail",message:`Worker bundle is ${e.toFixed(1)}MB \u2014 exceeds Mistflow Cloud's 64MB worker bundle limit.`}:e>30?{name:"worker-size",status:"warn",message:`Worker bundle is ${e.toFixed(1)}MB \u2014 large but within Mistflow Cloud limits. May be slow to upload.`}:{name:"worker-size",status:"pass",message:`Worker bundle: ${e.toFixed(1)}MB`}}function Ma(s,o){let t=[],e=new Set;if(o.plan?.pages)for(let r of o.plan.pages){let i=r.path??r.route??r.name;i&&e.add(i.replace(/^\//,""))}if(e.size===0)return[];let n=0,a=[];for(let r of e){if(r.startsWith("api/")||r==="login"||r==="register"||r==="sign-in"||r==="sign-up"){n++;continue}[V(s,"app","(dashboard)",r,"page.tsx"),V(s,"app","(dashboard)",r,"page.ts"),V(s,"app",r,"page.tsx"),V(s,"app",r,"page.ts"),V(s,"app","(admin)",r,"page.tsx")].some(l=>Te(l))?n++:a.push(`/${r}`)}return a.length===0?t.push({name:"plan-routes",status:"pass",message:`All ${e.size} planned pages found`}):a.length<=2?t.push({name:"plan-routes",status:"warn",message:`${n}/${e.size} planned pages found. Missing: ${a.join(", ")}`}):t.push({name:"plan-routes",status:"warn",message:`Only ${n}/${e.size} planned pages found. ${a.length} pages missing.`}),t}function $a(s){let o=V(s,"app");if(!Te(o))return{name:"empty-pages",status:"pass",message:"App directory check skipped"};let t=[];function e(n){try{for(let a of Yt(n)){let r=V(n,a);try{if(Pt(r).isDirectory())e(r);else if(a==="page.tsx"||a==="page.ts"){let l=Xe(r,"utf-8").trim();if(l.length<50||l.includes("export default function")&&l.includes("TODO")){let c=r.replace(s+"/","");t.push(c)}}}catch{}}}catch{}}return e(o),t.length>0?{name:"empty-pages",status:"warn",message:`${t.length} page(s) appear to be empty/placeholder: ${t.slice(0,3).join(", ")}`}:{name:"empty-pages",status:"pass",message:"No empty pages detected"}}function ja(s){let o=V(s,"app","page.tsx");if(!Te(o))return{name:"landing-page",status:"warn",message:"No root page.tsx found"};let t=Xe(o,"utf-8");if(t.includes('redirect("/login")')||t.includes('redirect("/register")')){let e=V(s,"middleware.ts"),n=Te(e)?Xe(e,"utf-8"):"";if(!(n.includes('"/"')||n.includes("'/'")))return{name:"landing-page",status:"fail",message:"Landing page (app/page.tsx) is just a redirect to /login, and middleware does not allow '/' as public. Users will never see a landing page."}}return t.length<200?{name:"landing-page",status:"warn",message:`Landing page is very small (${t.length} chars) \u2014 may be a placeholder.`}:{name:"landing-page",status:"pass",message:"Landing page has content"}}function La(s){let o=V(s,"app");if(!Te(o))return{name:"cookies-in-actions",status:"pass",message:"No app directory"};let t=[];function e(n){try{for(let a of Yt(n)){if(a==="node_modules"||a===".next"||a===".open-next")continue;let r=V(n,a);try{if(Pt(r).isDirectory())e(r);else if(a==="actions.ts"||a==="actions.tsx"){let l=Xe(r,"utf-8");l.includes("use server")&&l.includes("cookies()")&&l.includes(".set(")&&t.push(r.replace(s+"/",""))}}catch{}}}catch{}}return e(o),t.length>0?{name:"cookies-in-actions",status:"fail",message:`${t.length} server action(s) use cookies().set() which crashes on Mistflow Cloud's edge runtime: ${t.join(", ")}. Use a database field or form parameter instead.`}:{name:"cookies-in-actions",status:"pass",message:"No cookies().set() in server actions"}}function Oa(s){let o=V(s,"app");if(!Te(o))return{name:"fake-forms",status:"pass",message:"No app directory"};let t=[];function e(n){try{for(let a of Yt(n)){if(a==="node_modules"||a===".next"||a===".open-next")continue;let r=V(n,a);try{if(Pt(r).isDirectory())e(r);else if(a.endsWith(".tsx")||a.endsWith(".ts")){let l=Xe(r,"utf-8");if((l.includes("setTimeout")||l.includes("new Promise"))&&l.includes("Simulate")||l.includes("simulate")||l.includes("// TODO")&&l.includes("API")){let c=r.replace(s+"/","");t.push(c)}}}catch{}}}catch{}}return e(o),t.length>0?{name:"fake-forms",status:"fail",message:`${t.length} file(s) have fake/simulated API calls instead of real server actions: ${t.slice(0,3).join(", ")}. Forms must use 'use server' actions that write to the database.`}:{name:"fake-forms",status:"pass",message:"No fake form handlers detected"}}function Ua(s){let t=[V(s,"components","sidebar.tsx"),V(s,"components","topnav.tsx"),V(s,"components","nav.tsx")].find(i=>Te(i));if(!t)return[];let a=(Xe(t,"utf-8").match(/href:\s*"([^"]+)"/g)??[]).map(i=>i.replace(/href:\s*"/,"").replace(/"$/,"")).filter(i=>!i.startsWith("/api")&&!i.includes("["));if(a.length===0)return[];let r=[];for(let i of a){let l=i.replace(/^\//,"");if(!l||l==="")continue;[V(s,"app","(dashboard)",l,"page.tsx"),V(s,"app","(dashboard)",l,"page.ts"),V(s,"app","(app)",l,"page.tsx"),V(s,"app",l,"page.tsx"),V(s,"app",l,"page.ts")].some(u=>Te(u))||r.push(i)}return r.length>0?[{name:"nav-links",status:"fail",message:`Sidebar/nav links to pages that don't exist: ${r.join(", ")}. These will 404.`}]:[{name:"nav-links",status:"pass",message:`All ${a.length} nav links have matching pages`}]}function Me(s,o){return Ha("git",s,{cwd:o,encoding:"utf-8",timeout:3e4,stdio:["pipe","pipe","pipe"]}).trim()}function No(s){try{return Me(["rev-parse","--is-inside-work-tree"],s),!0}catch{return!1}}function _r(s){try{return Me(["status","--porcelain"],s).length>0}catch{return!1}}function Dr(s,o){return Me(["add","-A"],s),Me(["commit","-m",o,"--allow-empty-message"],s),Me(["rev-parse","HEAD"],s)}function Va(s){return Me(["rev-parse","HEAD"],s)}function Mr(s){try{return Me(["remote","get-url","origin"],s),!0}catch{return!1}}function Ya(s){try{let o=Me(["rev-parse","--abbrev-ref","HEAD"],s);return Me(["push","origin",o],s),{success:!0}}catch(o){return{success:!1,error:o instanceof Error?o.message:"push failed"}}}function Ja(s){let o=Kt(Lr(s)),t=Kt(o)===o?o:"/";for(;o!==t&&o!==Kt(o);){if(ue(se(o,"pnpm-workspace.yaml"))||ue(se(o,"lerna.json")))return o;let e=se(o,"package.json");if(ue(e))try{if(JSON.parse(Or(e,"utf-8")).workspaces)return o}catch{}o=Kt(o)}return null}function Ka(s){let o=se(Wa(),"mistflow-build");qa(o,{recursive:!0});let t=se(o,`${Fa(s)}-${Date.now()}`);return _o(s,t,{recursive:!0,filter:e=>{let n=e.slice(s.length);return!(n.startsWith("/.git")||n.startsWith("\\.git")||n==="/node_modules"||n.startsWith("/node_modules/")||n==="/.open-next"||n.startsWith("/.open-next/")||n==="/.next"||n.startsWith("/.next/"))}}),t}function Qa(s,o){let t=se(s,".open-next"),e=se(s,".next");if(ue(t)){let n=se(o,".open-next");ue(n)&&Do(n,{recursive:!0}),_o(t,n,{recursive:!0})}if(ue(e)){let n=se(o,".next");ue(n)&&Do(n,{recursive:!0}),_o(e,n,{recursive:!0})}}function Xa(s){try{Do(s,{recursive:!0,force:!0})}catch{console.error(`[deploy] Failed to clean up isolated build dir: ${s}`)}}function pt(s,o,t,e,n,a){return new Promise(r=>{let i=Ga(s,o,{cwd:t,stdio:["pipe","pipe","pipe"],timeout:e,...a?{env:a}:{}}),l="",c="";i.stdout?.on("data",u=>{let m=u.toString();if(c+=m,n)for(let p of m.split(`
|
|
5029
5029
|
`).filter(Boolean))n(p)}),i.stderr?.on("data",u=>{let m=u.toString();if(l+=m,n)for(let p of m.split(`
|
|
5030
|
-
`).filter(Boolean))n(p)}),i.on("close",(u,m)=>{r({success:u===0,stdout:c,stderr:l,signal:m})}),i.on("error",u=>{r({success:!1,stdout:c,stderr:l+u.message})})})}var Gp=Jt.object({projectPath:Jt.string().optional().describe("Path to the project directory (default: current working directory)"),message:Jt.string().optional().describe("Deploy message"),environment:Jt.enum(["production","preview"]).optional().default("production").describe("Target environment: 'production' (default) or 'preview' for a shareable URL")});function Za(s){return new Promise(o=>setTimeout(o,s))}function $r(s){switch(s){case"pending":return"Provisioning database...";case"building":return"Building your app...";case"deploying":return"Deploying to Mistflow Cloud...";case"verifying":return"Verifying deployment...";default:return`Status: ${s}`}}function Mo(s){let o=se(s,"mistflow.json");if(ue(o))try{return JSON.parse(Or(o,"utf-8"))}catch{}return{}}function el(s,o){let
|
|
5031
|
-
`)}async function Ur(s,o){let
|
|
5030
|
+
`).filter(Boolean))n(p)}),i.on("close",(u,m)=>{r({success:u===0,stdout:c,stderr:l,signal:m})}),i.on("error",u=>{r({success:!1,stdout:c,stderr:l+u.message})})})}var Gp=Jt.object({projectPath:Jt.string().optional().describe("Path to the project directory (default: current working directory)"),message:Jt.string().optional().describe("Deploy message"),environment:Jt.enum(["production","preview"]).optional().default("production").describe("Target environment: 'production' (default) or 'preview' for a shareable URL")});function Za(s){return new Promise(o=>setTimeout(o,s))}function $r(s){switch(s){case"pending":return"Provisioning database...";case"building":return"Building your app...";case"deploying":return"Deploying to Mistflow Cloud...";case"verifying":return"Verifying deployment...";default:return`Status: ${s}`}}function Mo(s){let o=se(s,"mistflow.json");if(ue(o))try{return JSON.parse(Or(o,"utf-8"))}catch{}return{}}function el(s,o){let t=se(s,"mistflow.json"),e=Mo(s),n=e.deploy?.count??e.deployCount??0;e.deploy={url:o,count:n+1,lastDeployedAt:new Date().toISOString()};let a=e.plan?.steps;if(Array.isArray(a))for(let r of a)r.status==="in_progress"&&(r.status="completed");delete e.deployUrl,delete e.deployCount,Ba(t,JSON.stringify(e,null,2)+`
|
|
5031
|
+
`)}async function Ur(s,o){let e=process.platform==="win32"?"npx.cmd":"npx",n=0,a=se(s,"node_modules",".bin","opennextjs-cloudflare"),r=ue(a),i={...process.env,NODE_ENV:"production"},l=await pt(r?a:e,r?["build"]:["@opennextjs/cloudflare","build"],s,3e5,p=>{p.includes("Compiling")?o?.("Compiling your app..."):p.includes("Collecting page data")?o?.("Collecting page data..."):p.includes("Generating static pages")?o?.("Generating static pages..."):p.match(/^[○●◐λƒ]\s/)?n++:p.includes("Creating Cloudflare worker")?o?.("Packaging for Mistflow Cloud..."):p.includes("Build completed")&&o?.("Build completed!")},i);if(l.success)return{success:!0,buildStats:n>0?`${n} routes compiled`:"build complete"};let c=l.stderr+`
|
|
5032
5032
|
`+l.stdout;if(l.signal==="SIGKILL"||c.includes("SIGKILL")||c.includes("exit code: 137"))return{success:!1,signal:"SIGKILL",error:"Your app ran out of memory while building. This sometimes happens with complex projects. Try deploying again \u2014 if it keeps failing, we'll help you figure it out."};let u=St(c);if(u.length>0){let p=u.map((g,b)=>{let f=`${b+1}. ${g.humanMessage}`;return g.suggestion&&(f+=`
|
|
5033
5033
|
Fix: ${g.suggestion}`),f}).join(`
|
|
5034
5034
|
|
|
@@ -5038,15 +5038,15 @@ ${p}`}}let m=c.split(`
|
|
|
5038
5038
|
`).filter(p=>p.includes("error")||p.includes("Error")).slice(0,10);return{success:!1,error:m.length>0?`OpenNext build failed:
|
|
5039
5039
|
${m.join(`
|
|
5040
5040
|
`)}`:`OpenNext build failed:
|
|
5041
|
-
${c.slice(-500)}`}}async function tl(s,o){let
|
|
5042
|
-
${a.stderr.slice(-300)}`};await pt(n,["dedupe"],
|
|
5041
|
+
${c.slice(-500)}`}}async function tl(s,o){let t=Ja(s);if(t)return console.error(`[deploy] Project is inside monorepo at ${t} \u2014 building in isolated temp directory`),o?.("Detected parent project folder \u2014 building in isolated directory..."),jr(s,o);let e=await Ur(s,o);return!e.success&&e.signal==="SIGKILL"?(console.error("[deploy] Build was OOM-killed \u2014 retrying in isolated temp directory"),o?.("Build ran out of memory \u2014 retrying with a fresh setup..."),jr(s,o)):e}async function jr(s,o){let t;try{o?.("Copying project to isolated build directory..."),t=Ka(s),o?.("Installing dependencies...");let n=process.platform==="win32"?"npm.cmd":"npm",a=await pt(n,["install","--prefer-offline"],t,12e4);if(!a.success)return{success:!1,error:`Failed to install dependencies in isolated build:
|
|
5042
|
+
${a.stderr.slice(-300)}`};await pt(n,["dedupe"],t,6e4);let r=await Ur(t,o);return r.success&&(o?.("Copying build artifacts..."),Qa(t,s)),{...r,builtInIsolation:t}}finally{t&&Xa(t)}}async function ol(s,o,t){if(!ue(se(s,"db","schema")))return{success:!0,skipped:!0,skipReason:"No database structure found"};let e=se(s,"db","schema");try{if(za(e).filter(g=>g.endsWith(".ts")).length===0)return{success:!0,skipped:!0,skipReason:"No database files found in db/schema/"}}catch{return{success:!0,skipped:!0,skipReason:"Could not read db/schema/ directory"}}if(!ue(se(s,"drizzle.config.ts")))return{success:!0,skipped:!0,skipReason:"No drizzle.config.ts found"};let n;try{n=await Zo(o)}catch{return console.error("[deploy] Could not fetch DB credentials \u2014 skipping local schema push"),{success:!0,skipped:!0,skipReason:"Could not fetch database credentials \u2014 backend will handle the database update"}}let{db_provider:a,credentials:r}=n;if(a==="neon"){if(!r.DATABASE_URL)return console.error("[deploy] No DATABASE_URL found \u2014 skipping local schema push"),{success:!0,skipped:!0,skipReason:"No DATABASE_URL configured \u2014 set it with mist_config"}}else if(!r.TURSO_URL||!r.TURSO_AUTH_TOKEN)return console.error("[deploy] No Turso credentials found \u2014 skipping local schema push"),{success:!0,skipped:!0,skipReason:"No Turso credentials configured"};let i={PATH:process.env.PATH??"",HOME:process.env.HOME??"",NODE_PATH:process.env.NODE_PATH??"",TMPDIR:process.env.TMPDIR??"",...r},c=process.platform==="win32"?"npx.cmd":"npx",m=await pt(c,t?["drizzle-kit","push","--force"]:["drizzle-kit","push"],s,6e4,p=>{let g=p.replace(/(?:TURSO_AUTH_TOKEN|DATABASE_URL|AUTH_SECRET)=[^\s&]*/gi,b=>b.split("=")[0]+"=REDACTED").replace(/postgresql:\/\/[^@]*@/g,"postgresql://REDACTED@").replace(/libsql:\/\/[^\s]*/g,"libsql://REDACTED");console.error(`[drizzle-kit] ${g}`)},i);if(!m.success){let p=(m.stderr+`
|
|
5043
5043
|
`+m.stdout).trim(),g=p.toLowerCase();if(g.includes("data-loss")||g.includes("cannot be reverted"))return{success:!1,error:"Database update blocked: your database has existing data that would be deleted. The update includes changes that would remove existing data. If you're OK with losing the data, deploy again with forceSchema: true."};let b=p.split(`
|
|
5044
5044
|
`).filter(h=>h.includes("error")||h.includes("Error")||h.includes("ERR")).slice(0,5);return{success:!1,error:`Database update failed:
|
|
5045
5045
|
${b.length>0?b.join(`
|
|
5046
|
-
`):p.slice(-500)}`}}return{success:!0}}async function Fr(s,o){let{projectPath:
|
|
5046
|
+
`):p.slice(-500)}`}}return{success:!0}}async function Fr(s,o){let{projectPath:t,message:e,environment:n="production",forceSchema:a}=s,r=n,i=Lr(t??process.cwd());if(!be())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let l=Rr(i);if(!l.passed){let k=l.errors.map(M=>{let U=`[${M.check}] ${M.message}`;return M.file&&(U+=` (${M.file}${M.line?`:${M.line}`:""})`),U}).join(`
|
|
5047
5047
|
`);return d(`Deploy blocked \u2014 fix these issues first:
|
|
5048
5048
|
|
|
5049
|
-
${k}`,!0)}let c=l.warnings.map(k=>`[${k.check}] ${k.message}`),u;if(
|
|
5049
|
+
${k}`,!0)}let c=l.warnings.map(k=>`[${k.check}] ${k.message}`),u;if(No(i))if(_r(i))try{let k=Mo(i).deploy?.count??0,M=e?`Deploy v${k+1}: ${e}`:`Deploy v${k+1}`;u=Dr(i,M)}catch{console.error("[deploy] Pre-deploy git commit failed, continuing")}else try{u=Va(i)}catch{}let m=se(i,"mistflow.json");if(!ue(m))return d("No mistflow.json found. Run mist_build (action: 'init') first to set up your project.",!0);let p;try{let{ensureBackendRegistered:k}=await import("./self-heal-BXJXUFUF.js");p=await k(i,{forceSync:!0})}catch(k){let M=k instanceof Se?k.message:"Check your internet connection.";return d(`Could not register project with Mistflow: ${M}
|
|
5050
5050
|
|
|
5051
5051
|
Try deploying again in a moment.`,!0)}if(p||(p=Re(i)?.projectId),!p)return d("Could not register project with Mistflow \u2014 you may not be signed in. Run mist_setup to authenticate, then redeploy.",!0);if(p&&r==="production")try{let k=await Go(p),M=k,U=M.deploy_count??k.deployCount??0;(M.deploy_strategy??k.deploy_strategy)==="staging"&&U>0&&(r="preview",console.error("[deploy] Staging mode enabled \u2014 auto-redirecting to preview"))}catch{}let g=[],b=Date.now(),f=(k,M)=>{let U={phase:k,message:M};return g.push(U),U},h=(k,M)=>{k.durationMs=Date.now()-b,M&&(k.message=M)};if(o){let k=Ke(o.server,o.progressToken,()=>g[g.length-1]?.message??"Deploying...");o.cleanup=()=>k.stop()}let w=!1;if(p&&r!=="preview"){let k=f("schema","Updating database structure..."),M=await ol(i,p,a);if(M.skipped)h(k,M.skipReason??"Database update skipped");else if(M.success)w=!0,h(k,"Database updated successfully");else return h(k,"Database update failed"),d(`Deploy blocked \u2014 database update failed:
|
|
5052
5052
|
|
|
@@ -5054,45 +5054,45 @@ ${M.error}
|
|
|
5054
5054
|
|
|
5055
5055
|
Try deploying again in a moment. If it keeps failing, check your database files in db/schema/.`,!0)}let P=f("build","Compiling your app for Mistflow Cloud..."),I=Date.now(),x=await tl(i,k=>{P.message=k});if(!x.success)return d(`Deploy blocked \u2014 OpenNext build failed:
|
|
5056
5056
|
|
|
5057
|
-
${x.error}`,!0);h(P,`Build complete \u2014 ${x.buildStats??"ready"} (${((Date.now()-I)/1e3).toFixed(0)}s)`);let
|
|
5057
|
+
${x.error}`,!0);h(P,`Build complete \u2014 ${x.buildStats??"ready"} (${((Date.now()-I)/1e3).toFixed(0)}s)`);let E=f("qa","Running smoke tests..."),L=Re(i),C=await Er(i,L);if(C.passed)h(E,`Smoke test passed \u2014 ${C.checksRun} checks OK`);else if(h(E,`Smoke test: ${C.summary}`),C.blocking)return d(`Deploy blocked \u2014 smoke test failed:
|
|
5058
5058
|
|
|
5059
|
-
${
|
|
5059
|
+
${C.summary}
|
|
5060
5060
|
|
|
5061
|
-
Fix these issues and try again.`,!0);let q=se(i,".open-next");if(!ue(q))return d("Build succeeded but .open-next/ directory not found. Check your OpenNext configuration.",!0);f("package","Packaging build artifacts...");let W=se(i,".open-next-build.tar.gz"),H=[".open-next"];if(ue(se(i,"db"))&&H.push("db"),ue(se(i,"drizzle.config.ts"))&&H.push("drizzle.config.ts"),ue(se(i,"package.json"))&&H.push("package.json"),!(await pt("tar",["-czf",W,"-C",i,...H],i,6e4)).success)return d("Failed to create build archive. Check disk space and permissions.",!0);let _;{let k=se(i,".mistflow-source.tar.gz");(await pt("tar",["-czf",k,"-C",i,"--exclude",".open-next","--exclude","node_modules","--exclude",".git","--exclude",".next","--exclude",".open-next-build.tar.gz","--exclude",".mistflow-source.tar.gz","."],i,6e4)).success?_=k:console.error("[deploy] Source archive creation failed, continuing without it")}f("upload","Uploading to Mistflow...");let ee=_t()?.email,Y,B;try{let k=await Yo(p,W,r,ee,w,_,u);if(Y=k.deployment_id??k.id,!Y)return d("Upload succeeded but no deployment ID was returned. Check the Mistflow dashboard.",!0);B=k.status}catch(k){return Ir(k,"Deploy")}finally{try{
|
|
5062
|
-
`),
|
|
5061
|
+
Fix these issues and try again.`,!0);let q=se(i,".open-next");if(!ue(q))return d("Build succeeded but .open-next/ directory not found. Check your OpenNext configuration.",!0);f("package","Packaging build artifacts...");let W=se(i,".open-next-build.tar.gz"),H=[".open-next"];if(ue(se(i,"db"))&&H.push("db"),ue(se(i,"drizzle.config.ts"))&&H.push("drizzle.config.ts"),ue(se(i,"package.json"))&&H.push("package.json"),!(await pt("tar",["-czf",W,"-C",i,...H],i,6e4)).success)return d("Failed to create build archive. Check disk space and permissions.",!0);let _;{let k=se(i,".mistflow-source.tar.gz");(await pt("tar",["-czf",k,"-C",i,"--exclude",".open-next","--exclude","node_modules","--exclude",".git","--exclude",".next","--exclude",".open-next-build.tar.gz","--exclude",".mistflow-source.tar.gz","."],i,6e4)).success?_=k:console.error("[deploy] Source archive creation failed, continuing without it")}f("upload","Uploading to Mistflow...");let ee=_t()?.email,Y,B;try{let k=await Yo(p,W,r,ee,w,_,u);if(Y=k.deployment_id??k.id,!Y)return d("Upload succeeded but no deployment ID was returned. Check the Mistflow dashboard.",!0);B=k.status}catch(k){return Ir(k,"Deploy")}finally{try{Nr(W)}catch{}if(_)try{Nr(_)}catch{}}f("deploying","Deploying to the edge...");let N=Date.now(),le=24e4,ce=3e3,me=[$r(B)],re=B;for(;Date.now()-N<le;){await Za(ce);let k;try{k=await Oe(Y)}catch{continue}if(k.status!==re&&(me.push($r(k.status)),re=k.status),k.status==="live"){let M=((Date.now()-N)/1e3).toFixed(0),U=k.url??"";if(!U)return d("Deployment marked as live but no URL was returned. Check the Mistflow dashboard.",!0);let y=r==="preview";if(!y){el(i,U);try{let{readLocalState:X,syncRemoteState:Ae}=await import("./state-manager-GBP2NSYC.js"),v=X(i);v&&p&&(v.deployCount=(v.deployCount??0)+1,Ae(p,v).catch(()=>{}))}catch{}if(No(i)&&Mr(i))try{_r(i)&&Dr(i,"Update deploy metadata"),Ya(i)}catch{}}let R=y?"Preview":"App",te=Mo(i),Pe=te.name,ge=typeof Pe=="string"?Pe:"my app",S=te.features,D=Array.isArray(S)?S.length:0,G=te.plan,J=G&&typeof G=="object"&&"steps"in G?G.steps:void 0,oe=Array.isArray(J)?J.length:0,xe=g.map(X=>X.message),A={url:U,time:`${M}s`,deploymentId:Y,environment:r,statusLog:me,deployTimeline:xe,message:y?`${R} is live at ${U} \u2014 preview deployed in ${M}s. This URL expires in 72 hours.`:`Your app is live at ${U} \u2014 deployed in ${M}s.`};if(y)A.instruction=["STAGING FLOW: The preview is deployed with an isolated database. Verify it before going live.","","1. Call mist_build with action='qa' and url='"+U+"' to test the preview.","2. If QA passes \u2014 tell the user the preview looks good and ask: 'Ready to go live?'","3. If QA finds issues \u2014 fix them, then call mist_deploy action='deploy' environment='preview' to redeploy the preview.","4. When user confirms \u2014 call mist_deploy action='promote' to push to production (~10s).","","Show the preview URL to the user so they can check it themselves while QA runs."].join(`
|
|
5062
|
+
`),A.nextAction=`MANDATORY: Call mist_build with action='qa' and url='${U}' to verify the preview. After QA passes, ask user to confirm, then call mist_deploy action='promote'.`,A.qaRequired=!0,A.qaUrl=U,A.previewDeploymentId=Y,A.promoteAction=`mist_deploy action='promote' deploymentId='${Y}'`;else{let X=encodeURIComponent(`Just built "${ge}" with AI and deployed it live in ${M}s.
|
|
5063
5063
|
|
|
5064
5064
|
${oe} steps, ${D} features, zero config.
|
|
5065
5065
|
|
|
5066
5066
|
${U}
|
|
5067
5067
|
|
|
5068
|
-
Built with @mistflow`),
|
|
5068
|
+
Built with @mistflow`),Ae=encodeURIComponent(`I just described an app idea and got a live, working URL in ${M} seconds.
|
|
5069
5069
|
|
|
5070
5070
|
"${ge}" \u2014 ${oe} build steps, ${D} features, fully deployed.
|
|
5071
5071
|
|
|
5072
5072
|
${U}
|
|
5073
5073
|
|
|
5074
|
-
Built with Mistflow (mistflow.ai)`);
|
|
5075
|
-
`)},
|
|
5076
|
-
`),
|
|
5077
|
-
`),m.nextAction=`MANDATORY: Call mist_build with action='qa' and url='${u}' to verify production.`,m.qaRequired=!0,m.qaUrl=u,u?Ue(u,JSON.stringify(m)):d(JSON.stringify(m))}if(l.status==="failed")return d(`Promote failed: ${l.error??"Check the Mistflow dashboard for details."}`,!0)}catch{}}return d(`Promote is taking longer than expected. Deployment ID: ${a}`,!0)}import{z as Hr}from"zod";import{spawn as ml,execFileSync as Gr}from"child_process";import{existsSync as Zt,readFileSync as Wr,writeFileSync as hl,mkdirSync as gl}from"fs";import{join as ut,resolve as fl}from"path";import{homedir as Vr}from"os";import{createConnection as yl}from"net";import{existsSync as pl,readFileSync as ul}from"fs";function Xt(s){let o=new Set;if(!pl(s))return o;let
|
|
5078
|
-
`)){let n=
|
|
5074
|
+
Built with Mistflow (mistflow.ai)`);A.share={tweetUrl:`https://twitter.com/intent/tweet?text=${X}`,linkedInUrl:`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(U)}`,celebration:["","================================================",` ${ge} is LIVE!`,"================================================","",` ${U}`,"",` Deployed in ${M}s`,` ${D>0?`${D} features`:""}${D>0&&oe>0?" \xB7 ":""}${oe>0?`${oe} build steps`:""}`,""," Share it:",` Twitter \u2192 https://twitter.com/intent/tweet?text=${X}`,` LinkedIn \u2192 https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(U)}`,"","================================================"].join(`
|
|
5075
|
+
`)},A.instruction=["IMPORTANT: The app is deployed but NOT verified yet. Before celebrating:","","1. Call mist_build with action='qa' to test the live app.","2. If QA passes \u2014 present the URL prominently and show the celebration block above.","3. If QA finds issues \u2014 fix them, redeploy (mist_deploy action='deploy'), and run qa again.","4. Keep looping until QA passes. Only celebrate when all checks are green.","","Do NOT show the URL to the user until QA passes. A broken app is worse than no app."].join(`
|
|
5076
|
+
`),A.nextAction=`MANDATORY: Call mist_build with action='qa' and url='${U}' to verify the app works. Do NOT tell the user the app is ready until QA passes.`,A.qaRequired=!0,A.qaUrl=U}te.hasAdmin&&!y&&ee&&(A.adminSetup={message:`Your app is live. You're the admin \u2014 sign up at ${U}/signup with ${ee} to create your admin account. You'll pick your own password; the /admin panel unlocks as soon as you sign up.`}),c.length>0&&(A.warnings=c);let ne=[];if(!y){let X=JSON.stringify(te).toLowerCase();ne.push({action:"Add a custom domain",command:"mist_config resource='domain' action='add' domain='yourdomain.com'",reason:"Give your app a professional URL instead of the default .mistflow.app domain.",priority:"medium"}),No(i)&&!Mr(i)&&ne.push({action:"Back up to GitHub",command:"Create a repo at github.com/new, then tell me the URL and I'll push your code there",reason:"Your source code is saved with every deploy, but GitHub gives you an extra backup and lets you collaborate.",priority:"medium"});let Ae=X.includes("user")||X.includes("account")||X.includes("member"),v=X.includes("stripe")||X.includes("payment")||X.includes("billing");Ae&&!v&&ne.push({action:"Add payments",command:"Tell the AI: 'Add Stripe payments to my app'",reason:"Your app has user accounts \u2014 you could monetize with subscriptions or one-time payments.",priority:"low"}),ne.push({action:"Share your app",command:"mist_project action='share'",reason:"Generate a shareable link so others can fork and customize your app.",priority:"low"}),ne.push({action:"Make changes",command:"Describe what you want to change, then run mist_deploy action='deploy'",reason:"Edit your code and redeploy in seconds. Your app is yours to evolve.",priority:"low"}),ne.push({action:"See analytics",command:`Visit ${qo()} to see pageviews and visitors`,reason:"Track how people are using your app.",priority:"low"})}return ne.length>0&&(A.nextSteps=ne),Ue(U,JSON.stringify(A))}if(k.status==="failed")return d(k.error??"Deployment failed. Check the Mistflow dashboard for details.",!0)}return d(`Deploy is taking longer than expected. Your deploy ID is ${Y} \u2014 check status later.`,!0)}import{z as Qt}from"zod";import{resolve as sl,join as rl}from"path";import{execFileSync as nl}from"child_process";var Zp=Qt.object({projectPath:Qt.string().optional().describe("Path to the project directory (default: cwd)"),action:Qt.enum(["redeploy","rollback"]).describe("Action to perform: 'redeploy' re-deploys the latest build, 'rollback' reverts to a specific previous deployment"),deploymentId:Qt.string().optional().describe("Deployment ID to rollback to (required for 'rollback')")});function ze(s,o){return nl("git",s,{cwd:o,encoding:"utf-8",timeout:3e4,stdio:["pipe","pipe","pipe"]}).trim()}function Br(s){try{return ze(["rev-parse","--is-inside-work-tree"],s),!0}catch{return!1}}async function il(s,o,t,e){if(o&&Br(s))try{ze(["cat-file","-t",o],s);let n=!1;try{ze(["status","--porcelain"],s).length>0&&(ze(["stash","push","-m","mistflow-rollback-auto-stash"],s),n=!0)}catch{}return ze(["reset","--hard",o],s),ze(["commit","--allow-empty","-m","Rollback to previous deploy"],s),{method:"git",success:!0,...n?{warning:"Your uncommitted changes were saved to git stash. Run `git stash pop` to restore them."}:{}}}catch{}if(t&&e)try{let{existsSync:n,mkdirSync:a,rmSync:r}=await import("fs"),i=rl(s,".mistflow-rollback-source.tar.gz");await ds(e,i);let{spawn:l}=await import("child_process");await new Promise((c,u)=>{let m=l("tar",["-xzf",i,"-C",s,"--exclude","node_modules","--exclude",".git"],{cwd:s,stdio:"pipe"});m.on("close",p=>p===0?c():u(new Error(`tar exit ${p}`))),m.on("error",u)});try{r(i)}catch{}if(Br(s))try{ze(["add","-A"],s),ze(["commit","-m","Rollback to previous deploy (from source snapshot)"],s)}catch{}return{method:"r2",success:!0}}catch(n){return{method:"r2",success:!1,error:n instanceof Error?n.message:"Source download failed"}}return{method:"none",success:!1,error:"No source snapshot available for this deployment"}}function al(s){return new Promise(o=>setTimeout(o,s))}function ll(s){switch(s){case"pending":return"Provisioning...";case"building":return"Building...";case"deploying":return"Deploying to Mistflow Cloud...";case"verifying":return"Verifying deployment...";default:return`Status: ${s}`}}async function qr(s,o,t){let e=Date.now(),n=12e4,a=3e3,r=[],i="";for(;Date.now()-e<n;){await al(a);let l;try{l=await Oe(s)}catch{continue}if(l.status!==i&&(r.push(ll(l.status)),i=l.status),l.status==="live"){let c=((Date.now()-e)/1e3).toFixed(0),u=l.url??"";if(t)try{await t()}catch{}return d(JSON.stringify({url:u,time:`${c}s`,deploymentId:s,statusLog:r,message:u?`${o} complete \u2014 live at ${u} in ${c}s.`:`${o} complete in ${c}s.`}))}if(l.status==="failed")return d(l.error??`${o} failed. Check the Mistflow dashboard for details.`,!0)}return d(`${o} is taking longer than expected. Deployment ID: ${s} \u2014 check status later.`,!0)}async function $o(s){let{projectPath:o,action:t,deploymentId:e}=s,n=sl(o??process.cwd());if(!be())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let r=Re(n)?.projectId;if(!r)return d("No project ID found. Deploy your project first with mist_deploy, or initialize with mist_plan + mist_build.",!0);try{switch(t){case"redeploy":{let i=await as(r);return qr(i.deployment_id,"Redeploy")}case"rollback":{if(!e)return d("Deployment ID is required for rollback. Use mist_project (action: 'deployments') to see previous deployment IDs.",!0);let i=await cs(e);return qr(i.deployment_id,"Rollback",async()=>{let l=await il(n,i.git_commit_sha,i.source_artifact_key,e);l.success||console.error(`[rollback] Local source restore failed: ${l.error}`),l.warning&&console.error(`[rollback] ${l.warning}`)})}default:return d(`Unknown action: ${t}. Use redeploy or rollback.`,!0)}}catch(i){if(i instanceof Se)return d(i.message,!0);let l=i instanceof Error?i.message:"An unexpected error occurred";return d(l,!0)}}import{resolve as cl}from"path";function dl(s){return new Promise(o=>setTimeout(o,s))}async function zr(s){let o=cl(s.projectPath??process.cwd());if(!be())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let e=Re(o)?.projectId;if(!e)return d("No project ID found. Deploy the project first.",!0);let n=s.deploymentId;if(!n)try{let c=(await yt(e)).find(u=>u.environment==="preview"&&u.status==="live");if(!c)return d("No live preview found to promote. Deploy with staging mode first, then call promote after QA passes.",!0);n=c.id}catch{return d("Could not list deployments. Check your connection.",!0)}console.error(`[promote] Promoting preview ${n} to production...`);let a;try{a=(await ls(e,n)).deployment_id}catch(l){let c=l instanceof Error?l.message:"Promote failed";return d(`Promote failed: ${c}`,!0)}let r=Date.now(),i=12e4;for(;Date.now()-r<i;){await dl(3e3);try{let l=await Oe(a);if(l.status==="live"){let c=((Date.now()-r)/1e3).toFixed(0),u=l.url??"",m={url:u,time:`${c}s`,deploymentId:a,environment:"production",promoted:!0,message:`Promoted to production at ${u} in ${c}s. Same build that passed QA on preview.`};return m.instruction=["IMPORTANT: The app has been promoted to production. Run a quick QA check to verify.","","1. Call mist_build with action='qa' to test the live production app.","2. If QA passes \u2014 celebrate! Present the URL to the user.","3. If QA finds issues \u2014 these are likely environment differences (auth, DNS). Report them."].join(`
|
|
5077
|
+
`),m.nextAction=`MANDATORY: Call mist_build with action='qa' and url='${u}' to verify production.`,m.qaRequired=!0,m.qaUrl=u,u?Ue(u,JSON.stringify(m)):d(JSON.stringify(m))}if(l.status==="failed")return d(`Promote failed: ${l.error??"Check the Mistflow dashboard for details."}`,!0)}catch{}}return d(`Promote is taking longer than expected. Deployment ID: ${a}`,!0)}import{z as Hr}from"zod";import{spawn as ml,execFileSync as Gr}from"child_process";import{existsSync as Zt,readFileSync as Wr,writeFileSync as hl,mkdirSync as gl}from"fs";import{join as ut,resolve as fl}from"path";import{homedir as Vr}from"os";import{createConnection as yl}from"net";import{existsSync as pl,readFileSync as ul}from"fs";function Xt(s){let o=new Set;if(!pl(s))return o;let t=ul(s,"utf-8");for(let e of t.split(`
|
|
5078
|
+
`)){let n=e.trim();if(!n||n.startsWith("#"))continue;let a=n.indexOf("=");if(a>0){let r=n.slice(0,a).trim(),i=n.slice(a+1).trim();i&&i!=='""'&&i!=="''"&&o.add(r)}}return o}var bl=Hr.object({projectPath:Hr.string().optional().describe("Path to the project directory (default: current working directory)")});function Yr(){return ut(Vr(),".mistflow","processes.json")}function Jr(){let s=Yr();if(!Zt(s))return[];try{return JSON.parse(Wr(s,"utf-8"))}catch{return[]}}function Kr(s){let o=ut(Vr(),".mistflow");Zt(o)||gl(o,{recursive:!0}),hl(Yr(),JSON.stringify(s,null,2))}function wl(){let s=Jr(),o=[];for(let t of s)try{process.kill(t.pid,0),o.push(t)}catch{}Kr(o)}function Qr(s){return new Promise(o=>{let t=yl({port:s,host:"127.0.0.1"});t.on("connect",()=>{t.destroy(),o(!0)}),t.on("error",()=>{o(!1)})})}async function vl(s,o,t){let e=Date.now();for(;Date.now()-e<o;){if(await Qr(s))return!0;await new Promise(n=>setTimeout(n,t))}return!1}function kl(s){return Zt(ut(s,"mistflow.json"))}function xl(s){let o=ut(s,"mistflow.json");if(!Zt(o))return[];let t;try{t=JSON.parse(Wr(o,"utf-8"))}catch{return[]}let e=t.env?.required;if(!e||typeof e!="object")return[];let n=Object.keys(e);if(n.length===0)return[];let a=Xt(ut(s,".env.local"));return n.filter(r=>!a.has(r))}var Xr={name:"mist_preview",description:"Build the app and start a local production server on localhost:3000 for previewing. Use when the user says 'mist preview'.",inputSchema:bl,handler:async s=>{let t=fl(s.projectPath??process.cwd()),e=3e3;if(!kl(t))return Ee(t);let n=xl(t);if(n.length>0)return d(`Missing required environment variables in .env.local: ${n.join(", ")}. Add them to ${ut(t,".env.local")} before previewing.`,!0);wl();let a=await Qr(e),r=Jr(),i=r.some(m=>m.type==="dev-server"&&m.port===e);if(a&&!i)return d(`Port ${e} is in use. Stop the other process or I will use a different port.`,!0);let l=[...r];if(!a){try{Gr("npx",["drizzle-kit","push"],{cwd:t,stdio:["pipe","pipe","pipe"],timeout:3e4})}catch{console.error("[preview] drizzle-kit push failed, continuing...")}try{Gr("npm",["run","build"],{cwd:t,stdio:["pipe","pipe","pipe"],timeout:18e4})}catch(b){let f=b instanceof Error&&"stderr"in b?String(b.stderr).slice(-1500):"",h=b instanceof Error&&"stdout"in b?String(b.stdout).slice(-1500):"",w=(f+`
|
|
5079
5079
|
`+h).trim();return d(`Build failed. Fix the errors before previewing:
|
|
5080
5080
|
|
|
5081
|
-
${w}`,!0)}let m=ml("npx",["next","start","-p",String(
|
|
5081
|
+
${w}`,!0)}let m=ml("npx",["next","start","-p",String(e)],{cwd:t,detached:!0,stdio:["ignore","pipe","pipe"]}),p="";if(m.stderr?.on("data",b=>{p+=b.toString()}),m.pid&&(m.unref(),l.push({pid:m.pid,type:"dev-server",port:e,startedAt:new Date().toISOString()}),Kr(l)),!await vl(e,15e3,500)){let b=p?`Server failed to start:
|
|
5082
5082
|
|
|
5083
|
-
${p.slice(-1e3)}`:"Server failed to start within 15s. Check for runtime errors.";return d(b,!0)}}let c=`http://localhost:${
|
|
5084
|
-
`),nextSteps:b}))}let a=[];if(o.completedStep!==void 0){let i=n.plan;if(i?.steps){let l=i.steps.findIndex(c=>c.number===o.completedStep);if(l===-1)return d(`Step ${o.completedStep} not found in the plan.`,!0);i.steps[l].status="completed",a.push(`Step ${o.completedStep} marked as completed`)}}o.addEnvVar&&(n.env||(n.env={required:{}}),n.env.required||(n.env.required={}),n.env.required[o.addEnvVar.key]={description:o.addEnvVar.description,setupUrl:o.addEnvVar.setupUrl},a.push(`Added required env var: ${o.addEnvVar.key}`)),Ml(
|
|
5085
|
-
`),n.projectId&&import("./state-manager-GBP2NSYC.js").then(async({readLocalState:i,syncRemoteState:l})=>{let c=i(
|
|
5083
|
+
${p.slice(-1e3)}`:"Server failed to start within 15s. Check for runtime errors.";return d(b,!0)}}let c=`http://localhost:${e}`,u=JSON.stringify({localUrl:c,message:`Preview is live at ${c}. Run mist_deploy to get your permanent URL on mistflow.app.`});return Ue(c,u)}};import{resolve as Sl,join as Tl}from"path";import{existsSync as Pl,readFileSync as Cl}from"fs";var jo="test@mistflow.dev",Zr="MistflowTest123!",Al="Test User";function en(s){let o=Tl(s,"mistflow.json");if(!Pl(o))return null;try{return JSON.parse(Cl(o,"utf-8"))}catch{return null}}function Il(s){let o=JSON.stringify(s).toLowerCase();return["auth","login","sign-in","sign-up","signin","signup"].some(t=>o.includes(t))}function Rl(s){let o=s.plan;if(!o?.steps)return[];let t=new Set;for(let n of o.steps)if(n.pages)for(let a of n.pages)t.add(a);let e=new Set(["login","signup","sign-in","sign-up","signin","signout","sign-out","logout"]);return[...t].filter(n=>!e.has(n.toLowerCase())).slice(0,3)}function El(s){let o=s.deploy;return o?.url?o.url:typeof s.deployUrl=="string"?s.deployUrl:null}async function tn(s){let o=Sl(s.projectPath??process.cwd()),t=s.verifyUrl,e=null;if(t)e=en(o);else{if(e=en(o),!e)return d("No mistflow.json found. Run mist_deploy first, or pass verifyUrl explicitly.",!0);if(t=El(e)??void 0,!t)return d("No deploy URL found in mistflow.json. Deploy your app first with mist_deploy.",!0)}t.startsWith("http")||(t=`https://${t}`);let n=e?Il(e):!1,a=e?Rl(e):[],r;try{r=await Et()}catch{return d("Browser not available. Install Playwright to use verify: npx playwright install chromium",!0)}let i={verified:!0,url:t,authTested:!1,testUser:null,pages:[],message:""},l=[];try{await r.goto(t,{waitUntil:"domcontentloaded",timeout:3e4}),await r.waitForLoadState("networkidle").catch(()=>{})}catch{return i.verified=!1,i.message=`Could not load ${t}. The app may not be deployed yet or the URL may be incorrect.`,d(JSON.stringify(i),!0)}let c=await r.title(),u=c.toLowerCase().includes("error")||c.toLowerCase().includes("404")?"error":"ok";i.pages.push({path:"/",status:u,title:c});try{let f=await Le(r,!1);l.push({data:f.toString("base64"),mimeType:"image/png"})}catch{}if(u==="error"&&(i.verified=!1),n)try{(await r.evaluate(async h=>{let w=await fetch("/api/auth/sign-up/email",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)});return{status:w.status,ok:w.ok}},{email:jo,password:Zr,name:Al})).ok||await r.evaluate(async h=>{let w=await fetch("/api/auth/sign-in/email",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)});return{status:w.status,ok:w.ok}},{email:jo,password:Zr}),await r.reload({waitUntil:"domcontentloaded",timeout:15e3}),await r.waitForLoadState("networkidle").catch(()=>{}),i.authTested=!0,i.testUser={email:jo};try{let h=await Le(r,!1);l.push({data:h.toString("base64"),mimeType:"image/png"})}catch{}}catch{console.error("[verify] Auth test failed, continuing with public pages")}for(let f of a){let h=f.startsWith("/")?f:`/${f}`;try{await r.goto(`${t}${h}`,{waitUntil:"domcontentloaded",timeout:15e3}),await r.waitForLoadState("networkidle").catch(()=>{});let w=await r.title(),P=w.toLowerCase().includes("404")||w.toLowerCase().includes("not found")?"error":"ok";i.pages.push({path:h,status:P,title:w}),P==="error"&&(i.verified=!1);try{let I=await Le(r,!1);l.push({data:I.toString("base64"),mimeType:"image/png"})}catch{}}catch{i.pages.push({path:h,status:"error",title:"Timeout"}),i.verified=!1}}let m=i.pages.filter(f=>f.status==="ok").length,p=i.pages.length,g=i.authTested?" Auth login successful.":"";i.message=i.verified?`Verified ${m}/${p} pages.${g} App looks good.`:`Verified ${m}/${p} pages \u2014 some issues found.${g} Check screenshots.`;let b=[{type:"text",text:JSON.stringify(i)}];for(let f of l)b.push({type:"image",data:f.data,mimeType:f.mimeType});return{content:b}}var Nl=Ze.object({action:Ze.enum(["deploy","promote","preview","redeploy","rollback","verify"]).describe("'deploy' builds and deploys to Mistflow Cloud (auto-redirects to preview if staging mode is enabled). 'promote' promotes a verified preview to production (~10s, reuses the preview build). 'preview' builds the app and starts a local production server on localhost:3000. 'redeploy' re-deploys the latest build without rebuilding. 'rollback' reverts to a specific previous deployment. 'verify' navigates the deployed app, tests auth, and screenshots pages to confirm it works."),projectPath:Ze.string().optional().describe("Path to the project directory (default: cwd)"),environment:Ze.enum(["production","preview"]).optional().describe("(deploy) Target environment. Defaults to 'production'. Projects with staging mode auto-redirect to preview."),forceSchema:Ze.boolean().optional().describe("(deploy) Reset the database structure. Warning: this deletes existing data. Only use when the user confirms this is OK."),deploymentId:Ze.string().optional().describe("(rollback/promote) Deployment ID to rollback to, or preview deployment ID to promote"),verifyUrl:Ze.string().optional().describe("(verify) URL to verify. Defaults to deploy URL from mistflow.json")}),on={name:"mist_deploy",description:"STEP 4 (final) of the Mistflow workflow. Deploy a Mistflow project. Call this AFTER all mist_build implement steps are done. If the project has staging mode enabled (configurable in dashboard), the tool automatically deploys to preview first with an isolated database. After QA passes, call action='promote' to go live (~10s, reuses the same build artifact). Actions: 'deploy' (default), 'promote' (promote preview to production), 'preview' (local dev server), 'redeploy', 'rollback', 'verify'. The workflow is: mist_plan \u2192 mist_build init \u2192 implement (repeat) \u2192 mist_build build \u2192 mist_deploy \u2192 mist_build qa.",inputSchema:Nl,handler:async(s,o)=>{let t=s;switch(t.action){case"deploy":return Fr({projectPath:t.projectPath,environment:t.environment??"production",forceSchema:t.forceSchema},o);case"promote":return zr({projectPath:t.projectPath,deploymentId:t.deploymentId});case"preview":return Xr.handler({projectPath:t.projectPath});case"redeploy":return $o({projectPath:t.projectPath,action:"redeploy"});case"rollback":return $o({projectPath:t.projectPath,action:"rollback",deploymentId:t.deploymentId});case"verify":return tn({projectPath:t.projectPath,verifyUrl:t.verifyUrl});default:return d(`Unknown action: ${t.action}. Use deploy, promote, preview, redeploy, rollback, or verify.`,!0)}}};import{z as ke}from"zod";import{resolve as eo}from"path";import{existsSync as to,readFileSync as oo}from"fs";import{join as so}from"path";import{z as He}from"zod";import{resolve as _l,join as sn}from"path";import{existsSync as Dl,readFileSync as rn,writeFileSync as Ml}from"fs";var $l=He.object({action:He.enum(["get","update"]).default("get").describe("'get' reads current project state. 'update' modifies it."),projectPath:He.string().optional().describe("Path to the project directory (default: current working directory)"),completedStep:He.number().optional().describe("(update only) Mark a plan step as completed by step number"),addEnvVar:He.object({key:He.string(),description:He.string().optional(),setupUrl:He.string().optional()}).optional().describe("(update only) Add a required env var to the project manifest")}),nn={name:"mist_state",description:"Read or update project state in mistflow.json. Use action='get' to load plan progress, env var status, and deploy info. Use action='update' to mark plan steps complete or add required env vars. Use when the user says 'mist status', 'mist state', or 'mist update state'.",inputSchema:$l,handler:async s=>{let o=s,t=_l(o.projectPath??process.cwd()),e=sn(t,"mistflow.json");if(!Dl(e))return Ee(t);let n;try{n=JSON.parse(rn(e,"utf-8"))}catch{return d("Failed to parse mistflow.json.",!0)}if(o.action==="get"){if(!n.projectId)try{let{ensureBackendRegistered:h}=await import("./self-heal-BXJXUFUF.js");await h(t)&&(n=JSON.parse(rn(e,"utf-8")))}catch{}let i=n.plan,l=i?.steps?.filter(h=>h.status==="completed").length??0,c=i?.steps?.length??0,u=Xt(sn(t,".env.local")),m=n.env?.required?Object.entries(n.env.required).map(([h,w])=>({name:h,description:w?.description,configured:u.has(h)})):[];n.projectId&&import("./state-manager-GBP2NSYC.js").then(({fetchRemoteState:h})=>h(n.projectId)).catch(()=>{});let p=[`Project: ${n.name}`];if(i){p.push(`Plan: ${i.summary??i.name??"unnamed"} \u2014 ${l}/${c} steps complete`);for(let h of i.steps){let w=h.status==="completed"?"\u2713":h.status==="in_progress"?"\u2192":" ";p.push(` [${w}] ${h.number}. ${h.name}`)}}let g=m.filter(h=>!h.configured);g.length>0&&p.push(`Missing env vars: ${g.map(h=>h.name).join(", ")}`),n.deploy?.url?p.push(`Deployed: ${n.deploy.url} (${n.deploy.count??0} deploys)`):p.push("Not deployed yet");let b=[],f=i?.steps?.find(h=>h.status!=="completed");return f?b.push(`NEXT: Call mist_build with action='implement' to work on step ${f.number} (${f.name}).`):i&&l===c&&(n.deploy?.url||b.push("NEXT: All steps complete! Call mist_deploy with action='deploy' to deploy the app now. Do NOT ask the user \u2014 just deploy.")),g.length>0&&b.push(`Missing env vars in .env.local: ${g.map(h=>h.name).join(", ")}`),d(JSON.stringify({name:n.name,projectId:n.projectId,planProgress:i?{name:i.name,summary:i.summary,totalSteps:c,completedSteps:l,steps:i.steps}:null,envStatus:m,deploy:n.deploy??null,contextMessage:p.join(`
|
|
5084
|
+
`),nextSteps:b}))}let a=[];if(o.completedStep!==void 0){let i=n.plan;if(i?.steps){let l=i.steps.findIndex(c=>c.number===o.completedStep);if(l===-1)return d(`Step ${o.completedStep} not found in the plan.`,!0);i.steps[l].status="completed",a.push(`Step ${o.completedStep} marked as completed`)}}o.addEnvVar&&(n.env||(n.env={required:{}}),n.env.required||(n.env.required={}),n.env.required[o.addEnvVar.key]={description:o.addEnvVar.description,setupUrl:o.addEnvVar.setupUrl},a.push(`Added required env var: ${o.addEnvVar.key}`)),Ml(e,JSON.stringify(n,null,2)+`
|
|
5085
|
+
`),n.projectId&&import("./state-manager-GBP2NSYC.js").then(async({readLocalState:i,syncRemoteState:l})=>{let c=i(t);c&&await l(n.projectId,c)}).catch(()=>{});let r=[];if(o.completedStep!==void 0){let l=n.plan?.steps?.find(c=>c.status!=="completed");l?r.push(`NEXT: Call mist_build with action='implement' to work on step ${l.number} (${l.name}). Do this now.`):r.push("NEXT: All steps complete! Call mist_deploy with action='deploy' to deploy the app now. Do NOT suggest localhost.")}return o.addEnvVar&&(r.push(`Add ${o.addEnvVar.key} to your .env.local file`),o.addEnvVar.setupUrl&&r.push(`Get the value from: ${o.addEnvVar.setupUrl}`)),d(JSON.stringify({updated:!0,changes:a,message:a.length>0?`Project state saved. ${a.join(". ")}.`:"No changes made.",nextSteps:r.length>0?r:void 0}))}};var jl=ke.object({action:ke.enum(["get","update","share","landing-designs","integrations","errors","logs","deployments","version"]).default("get").describe("'get' reads current project state. 'update' marks steps complete or adds env vars. 'share' makes the project a shareable template. 'landing-designs' lists curated landing page hero designs. 'integrations' lists third-party service integration blueprints (Stripe, Resend, ElevenLabs, etc.) with setup guides. 'errors' fetches runtime errors from the deployed app. 'logs' fetches deploy logs for a specific deployment. 'deployments' lists deployment history. 'version' reports the installed @mistflow-ai/mcp version and whether an upgrade is available."),projectPath:ke.string().optional().describe("Path to the project directory (default: cwd)"),completedStep:ke.number().optional().describe("(update) Mark a plan step as completed by step number"),addEnvVar:ke.object({key:ke.string(),description:ke.string().optional(),setupUrl:ke.string().optional()}).optional().describe("(update) Add a required env var to the project manifest"),templateDescription:ke.string().optional().describe("(share) Short description of what this template builds"),category:ke.string().optional().describe("(landing-designs) Filter by category"),presetId:ke.string().optional().describe("(landing-designs) Get full details for a specific landing design by ID"),integrationId:ke.string().optional().describe("(integrations) Get full details for a specific integration preset by ID (e.g. 'stripe-payments', 'resend-email', 'elevenlabs-voice')"),period:ke.string().optional().describe("(errors) Time period for errors: '1h', '24h', '7d' (default: '7d')"),deploymentId:ke.string().optional().describe("(logs) Deployment ID to fetch logs for. If omitted, fetches logs for the latest deployment.")}),an={name:"mist_project",description:"Read or update Mistflow project state. 'get' loads plan progress, env vars, and deploy info. 'update' marks plan steps complete or adds env vars (note: mist_build implement auto-marks the previous step, so manual updates are rarely needed). 'share' makes the project a forkable template with a shareable URL. 'landing-designs' lists curated landing page hero designs \u2014 pass an ID to mist_plan's landingDesign field to apply it. 'integrations' lists third-party service integration blueprints (Stripe, Resend, ElevenLabs, OpenAI, Twilio, etc.) \u2014 these are auto-injected during implementation when the plan includes matching integration steps. 'errors' fetches runtime errors from the live deployed app (same data shown on the dashboard). 'logs' fetches deploy logs for a deployment (phase-by-phase progress with error details). 'deployments' lists deployment history with status and error messages.",inputSchema:jl,handler:async s=>{let o=s;if(["share","errors","logs","deployments"].includes(o.action)&&!be())return d("You need to sign in first. Run mist_setup to connect your account.",!0);switch(o.action){case"get":case"update":return nn.handler({action:o.action,projectPath:o.projectPath,completedStep:o.completedStep,addEnvVar:o.addEnvVar});case"share":{let e=eo(o.projectPath??process.cwd()),n=so(e,"mistflow.json");if(!to(n))return Ee(e);let a;try{a=JSON.parse(oo(n,"utf-8"))}catch{return d("Could not read mistflow.json.",!0)}let r=a.projectId;if(!r)return d("No project ID found. Deploy the project first to register it.",!0);try{let i=await fs(r,{isTemplate:!0,description:o.templateDescription});return d(JSON.stringify({shareUrl:i.share_url,shareToken:i.share_token,message:`Your project is now a shareable template!
|
|
5086
5086
|
|
|
5087
5087
|
Anyone can fork it: ${i.share_url}
|
|
5088
5088
|
|
|
5089
5089
|
Others can use it in their AI editor:
|
|
5090
|
-
"build me something like ${i.share_url}"`}))}catch(i){let l=i instanceof Error?i.message:"Failed to share project";return d(l,!0)}}case"landing-designs":{if(o.presetId){let r=ot(o.presetId);if(!r)return d(`Preset '${o.presetId}' not found. Use mist_project action='presets' without presetId to list all available presets.`,!0);let i=xs(o.presetId);return d(JSON.stringify({preset:{id:r.id,title:r.title,category:r.category,description:i?.description??"",style:i?.style??"",theme:i?.theme??"dark",colors:i?.colors??[],tags:i?.tags??[],promptLength:r.prompt.length},message:`Landing design "${r.title}" (${r.category}) \u2014 ${i?.description??""}. To use it, pass landingDesign="${r.id}" when calling mist_plan.`}))}let
|
|
5091
|
-
`)}async function cn(s){let{projectPath:o,action:e,domain:t,domainId:n}=s,a=Ol(o??process.cwd());if(!be())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let i=Re(a)?.projectId;if(!i)return d("No project ID found. Deploy your project first with mist_deploy, or initialize with mist_plan + mist_build.",!0);try{switch(e){case"add":{if(!t)return d("Domain name is required. Provide the domain like 'myapp.com' or 'app.mycompany.com'.",!0);let l=await Qo(i,t),c=await Je(i);return Lo(a,c.map(u=>({domain:u.domain,status:u.status}))),d(JSON.stringify({added:!0,domain:l.domain,status:l.status,instructions:l.instructions,message:`Domain '${l.domain}' added. Set up DNS records as described, then use action 'verify' to check status.`}))}case"list":{let l=await Je(i);return l.length===0?d(JSON.stringify({domains:[],message:"No custom domains configured. Use action 'add' to add one."})):d(JSON.stringify({domains:l.map(c=>({id:c.id,domain:c.domain,status:c.status,ssl:c.ssl_status,error:c.error_message}))}))}case"verify":{if(!n){if(t){let m=(await Je(i)).find(p=>p.domain===t);if(m){let p=await lo(i,m.id);return d(JSON.stringify({domain:p.domain,status:p.status,ssl:p.ssl_status,error:p.error_message,message:p.status==="active"?`Domain '${p.domain}' is active and serving traffic.`:`Domain '${p.domain}' is ${p.status}. Make sure DNS records are configured correctly.`}))}return d(`Domain '${t}' not found. Use action 'list' to see configured domains.`,!0)}return d("Provide either domainId or domain name to verify.",!0)}let l=await lo(i,n),c=await Je(i);return Lo(a,c.map(u=>({domain:u.domain,status:u.status}))),d(JSON.stringify({domain:l.domain,status:l.status,ssl:l.ssl_status,error:l.error_message,message:l.status==="active"?`Domain '${l.domain}' is active and serving traffic.`:`Domain '${l.domain}' is ${l.status}. Make sure DNS records are configured correctly.`}))}case"remove":{if(!n&&!t)return d("Provide either domainId or domain name to remove.",!0);let l=n;if(!l&&t){let m=(await Je(i)).find(p=>p.domain===t);if(!m)return d(`Domain '${t}' not found.`,!0);l=m.id}await Xo(i,l);let c=await Je(i);return Lo(a,c.map(u=>({domain:u.domain,status:u.status}))),d(JSON.stringify({removed:!0,message:"Domain removed. It may take a few minutes for DNS changes to propagate."}))}default:return d(`Unknown action: ${e}. Use add, list, verify, or remove.`,!0)}}catch(l){if(l instanceof Se)return d(l.message,!0);let c=l instanceof Error?l.message:"An unexpected error occurred";return d(c,!0)}}var zl=_e.object({resource:_e.enum(["env","domain"]).describe("'env' manages app secrets and configuration values. 'domain' manages custom domains."),action:_e.string().describe("Action to perform. env: 'set', 'list', 'delete'. domain: 'add', 'list', 'verify', 'remove'."),projectPath:_e.string().optional().describe("Path to the project directory (default: cwd)"),key:_e.string().optional().describe("(env) Variable name"),value:_e.string().optional().describe("(env set) Variable value"),category:_e.string().optional().describe("(env set) Category"),description:_e.string().optional().describe("(env set) Description"),setupUrl:_e.string().optional().describe("(env set) URL to obtain the value"),domain:_e.string().optional().describe("(domain) Domain name"),domainId:_e.string().optional().describe("(domain) Domain ID")}),dn={name:"mist_config",description:"Manage project configuration: app secrets and custom domains. Set resource='env' to manage encrypted app secrets (set, list, delete). Set resource='domain' to manage custom domains (add, list, verify, remove). Use when the user says 'mist env' or 'mist domain'.",inputSchema:zl,handler:async s=>{let o=s;switch(o.resource){case"env":return ln({projectPath:o.projectPath,action:o.action,key:o.key,value:o.value,category:o.category,description:o.description,setupUrl:o.setupUrl});case"domain":return cn({projectPath:o.projectPath,action:o.action,domain:o.domain,domainId:o.domainId});default:return d(`Unknown resource: ${o.resource}. Use env or domain.`,!0)}}};import{z as et}from"zod";var Hl=et.object({action:et.enum(["navigate","go_back","go_forward","click","type","fill","select_option","press_key","hover","screenshot","snapshot"]).describe("Action to perform. Navigation: navigate|go_back|go_forward. Interaction: click|type|fill|select_option|press_key|hover. Visual: screenshot (returns image) | snapshot (returns accessibility tree)."),url:et.string().optional().describe("URL to navigate to. Required for 'navigate'; optional for 'screenshot' (navigates before capturing)."),selector:et.string().optional().describe("CSS selector of the target element. Required for: click, type, fill, select_option, hover. Optional for screenshot (captures just that element)."),value:et.string().optional().describe("Text to type/fill, option to select, or key to press (e.g. 'Enter', 'Tab'). Required for: type, fill, select_option, press_key."),fullPage:et.boolean().default(!1).describe("For 'screenshot': capture the full scrollable page instead of just the viewport."),includeScreenshot:et.boolean().default(!1).describe("For navigate/interact actions: also return a screenshot alongside the accessibility snapshot.")}),pn={name:"mist_browser",description:"Unified browser tool for navigating, interacting with, and capturing the app. Use 'navigate' to open a URL, interaction actions (click/type/fill/etc.) to test flows, 'snapshot' to inspect the accessibility tree, and 'screenshot' for a visual capture. Use after mist_preview to verify UI, test flows, and iterate on design.",inputSchema:Hl,handler:async s=>{let o=s,e=await Nt();if(o.action==="navigate"){if(!o.url)return d("URL is required for 'navigate'.",!0);let a=[],r=c=>{c.type()==="error"&&a.push(c.text())};e.on("console",r),await e.goto(o.url,{waitUntil:"domcontentloaded",timeout:3e4}),await e.waitForLoadState("networkidle").catch(()=>{});let i=[],l=c=>i.push(c.message);if(e.on("pageerror",l),await e.waitForTimeout(500),e.removeListener("console",r),e.removeListener("pageerror",l),a.length>0||i.length>0){let c=await Et(e),u=[{type:"text",text:JSON.stringify({url:e.url(),title:await e.title(),snapshot:c,consoleErrors:a,pageErrors:i,hasErrors:!0})}];if(o.includeScreenshot){let m=await Le(e);u.push({type:"image",data:m.toString("base64"),mimeType:"image/png"})}return{content:u}}}else if(o.action==="go_back")await e.goBack({waitUntil:"domcontentloaded",timeout:1e4});else if(o.action==="go_forward")await e.goForward({waitUntil:"domcontentloaded",timeout:1e4});else if(o.action==="click"){if(!o.selector)return d("Selector is required for 'click'.",!0);await e.click(o.selector,{timeout:1e4}),await e.waitForLoadState("domcontentloaded").catch(()=>{}),await e.waitForTimeout(500)}else if(o.action==="type"){if(!o.selector)return d("Selector is required for 'type'.",!0);if(!o.value)return d("Value is required for 'type'.",!0);await e.type(o.selector,o.value,{delay:50})}else if(o.action==="fill"){if(!o.selector)return d("Selector is required for 'fill'.",!0);if(!o.value)return d("Value is required for 'fill'.",!0);await e.fill(o.selector,o.value)}else if(o.action==="select_option"){if(!o.selector)return d("Selector is required for 'select_option'.",!0);if(!o.value)return d("Value is required for 'select_option'.",!0);await e.selectOption(o.selector,o.value)}else if(o.action==="hover"){if(!o.selector)return d("Selector is required for 'hover'.",!0);await e.hover(o.selector,{timeout:1e4})}else if(o.action==="press_key"){if(!o.value)return d("Value is required for 'press_key' (e.g. 'Enter').",!0);await e.keyboard.press(o.value),await e.waitForLoadState("domcontentloaded").catch(()=>{}),await e.waitForTimeout(500)}else if(o.action==="screenshot"){o.url&&(await e.goto(o.url,{waitUntil:"domcontentloaded",timeout:3e4}),await e.waitForLoadState("networkidle").catch(()=>{}));let a;if(o.selector){let r=await e.$(o.selector);if(!r)return d(`Element not found: ${o.selector}`,!0);a=await r.screenshot({type:"png"})}else a=await Le(e,o.fullPage);return{content:[{type:"text",text:JSON.stringify({url:e.url(),title:await e.title(),message:`Screenshot captured (${o.fullPage?"full page":"viewport"})`})},{type:"image",data:a.toString("base64"),mimeType:"image/png"}]}}else if(o.action==="snapshot"){let a=await Et(e);return{content:[{type:"text",text:JSON.stringify({url:e.url(),title:await e.title(),snapshot:a})}]}}let t=await Et(e),n=[{type:"text",text:JSON.stringify({url:e.url(),title:await e.title(),snapshot:t})}];if(o.includeScreenshot){let a=await Le(e);n.push({type:"image",data:a.toString("base64"),mimeType:"image/png"})}return{content:n}}};import{existsSync as $e,readFileSync as It,writeFileSync as mt}from"fs";import{join as De}from"path";import{z as Ct}from"zod";function un(s){let o=De(s,"mistflow.json");if(!$e(o))return{result:{name:"Project",status:"fail",message:"No mistflow.json found. This is not a Mistflow project.",fix:"Run mist_plan to design your app, then mist_build init to scaffold it."},config:null};let e;try{e=JSON.parse(It(o,"utf-8"))}catch{return{result:{name:"Project",status:"fail",message:"mistflow.json exists but contains invalid JSON.",fix:"Check mistflow.json for syntax errors. If corrupted beyond repair, delete it and re-run mist_build init."},config:null}}if(!e.name||typeof e.name!="string")return{result:{name:"Project",status:"warn",message:"mistflow.json is missing the 'name' field."},config:e};let t=e.projectId,n=t?`, id: ${t}`:", no projectId";return{result:{name:"Project",status:"pass",message:`${e.name}${n}`},config:e}}async function Gl(){let s=Bo();if(!s.ok)return{result:{name:"Auth",status:"fail",message:s.reason==="missing"?"No credentials found.":"Credentials file is malformed.",fix:"Run mist_setup to log in."},creds:null,authValid:!1};try{let o=zo(),e=await fetch(`${Ye()}/api/org`,{headers:o,signal:AbortSignal.timeout(1e4)});try{Uo(e.headers)}catch{}if(!e.ok)return e.status===401?{result:{name:"Auth",status:"fail",message:"API key is invalid or revoked.",fix:"Run mist_setup to re-authenticate."},creds:s.creds,authValid:!1}:{result:{name:"Auth",status:"warn",message:`Server returned ${e.status}. Credentials may still be valid.`},creds:s.creds,authValid:!1};let t=await e.json(),n=t.slug??s.creds.orgSlug??"unknown",a=t.plan?`, plan: ${t.plan}`:"";return{result:{name:"Auth",status:"pass",message:`org: ${n}${a}`},creds:s.creds,authValid:!0}}catch(o){return o instanceof Se?{result:{name:"Auth",status:"fail",message:`Auth check failed: ${o.message}`,fix:"Run mist_setup to re-authenticate."},creds:s.creds,authValid:!1}:{result:{name:"Auth",status:"warn",message:"Could not reach API to validate credentials. Network issue?"},creds:s.creds,authValid:!1}}}async function Wl(){let s=Date.now();try{let o=await Dt("nextjs"),e=Date.now()-s;return{result:{name:"API",status:"pass",message:`${Ye()} reachable (${e}ms)`},scaffold:o}}catch(o){let e=Date.now()-s;return{result:{name:"API",status:"fail",message:o instanceof Se?o.message:`Timeout or network error after ${e}ms`,fix:"Check your network connection. If using --api-url, verify the backend is running."},scaffold:null}}}function Vl(){let s=gt();if(!s.backendSignalReceived)return{name:"MCP version",status:"warn",message:`v${s.current} installed, but no backend signal received to compare against.`};let o={none:"up to date",patch:"patch update available",minor:"minor update available",major:"major update available",unsupported:"no longer supported"};return s.severity==="none"?{name:"MCP version",status:"pass",message:`v${s.current} (latest)`}:s.severity==="unsupported"?{name:"MCP version",status:"fail",message:`v${s.current} is ${o[s.severity]}. Minimum: v${s.minSupported}.`,fix:`Run \`${s.upgradeCmd}\` then restart your editor.`}:{name:"MCP version",status:"warn",message:`v${s.current} installed, v${s.latest} available (${o[s.severity]}).`,fix:`Run \`${s.upgradeCmd}\` then restart your editor.`}}function Yl(s,o,e,t){let n=De(s,"AGENTS.md"),a=De(s,"CLAUDE.md"),r=$e(n),i=o.methodologyVersion??"",l=e?.version??"";if(!r){if(!t||!e?.methodology)return{name:"AGENTS.md",status:"fail",message:"Missing. The host AI has no methodology context for this project.",fix:e?"Run mist_doctor without reportOnly to auto-restore it.":"Cannot restore: API unreachable. Fix connectivity first."};let c=mn(e.methodology,o);return mt(n,c),mt(a,c),{name:"AGENTS.md",status:"fix",message:`Restored from methodology v${l}.`}}if(t&&!$e(a)){let c=It(n,"utf-8");mt(a,c)}if(l&&i&&l!==i){if(!t||!e?.methodology)return{name:"AGENTS.md",status:"warn",message:`Methodology v${i} installed, v${l} available.`,fix:"Run mist_doctor to update it."};let c=mn(e.methodology,o);mt(n,c),mt(a,c);try{let u=De(s,"mistflow.json"),m=JSON.parse(It(u,"utf-8"));m.methodologyVersion=l,mt(u,JSON.stringify(m,null,2)+`
|
|
5092
|
-
`)}catch{}return{name:"AGENTS.md",status:"fix",message:`Updated methodology v${i} -> v${l}.`}}return{name:"AGENTS.md",status:"pass",message:i?`v${i}`:"present"}}async function Jl(s,o,e
|
|
5093
|
-
`+It(r,"utf-8"))}catch{}}for(let[a,r]of Object.entries(
|
|
5090
|
+
"build me something like ${i.share_url}"`}))}catch(i){let l=i instanceof Error?i.message:"Failed to share project";return d(l,!0)}}case"landing-designs":{if(o.presetId){let r=ot(o.presetId);if(!r)return d(`Preset '${o.presetId}' not found. Use mist_project action='presets' without presetId to list all available presets.`,!0);let i=xs(o.presetId);return d(JSON.stringify({preset:{id:r.id,title:r.title,category:r.category,description:i?.description??"",style:i?.style??"",theme:i?.theme??"dark",colors:i?.colors??[],tags:i?.tags??[],promptLength:r.prompt.length},message:`Landing design "${r.title}" (${r.category}) \u2014 ${i?.description??""}. To use it, pass landingDesign="${r.id}" when calling mist_plan.`}))}let e=Ts(o.category??void 0),n=ho(o.category),a=Ss(n);return d(JSON.stringify({count:e.length,presets:e.map(r=>({id:r.id,title:r.title,category:r.category,description:r.description,style:r.style,theme:r.theme,colors:r.colors})),formatted:a,message:`${e.length} landing designs available.${o.category?` Filtered by: ${o.category}.`:""} To use one, pass landingDesign="<id>" when calling mist_plan. The design blueprint will be injected during the landing page implementation step. Browse them at ${ft()}/designs?tab=landing-designs.`}))}case"integrations":{if(o.integrationId){let r=rt(o.integrationId);if(!r)return d(`Integration '${o.integrationId}' not found. Use mist_project action='integrations' without integrationId to list all available integrations.`,!0);let i=nt(r.id);return d(JSON.stringify({integration:{id:r.id,name:r.name,category:r.category,description:i?.description??"",packages:i?.packages??[],envVars:i?.envVars??[],docsUrl:i?.docsUrl??"",difficulty:i?.difficulty??"medium"},message:`Integration "${r.name}" (${r.category}) \u2014 ${i?.description??""}. This blueprint is auto-injected during implementation when your plan has a matching integration step. Required env vars: ${i?.envVars?.map(l=>l.key).join(", ")||"none"}. Docs: ${i?.docsUrl??"n/a"}.`}))}let e=As(o.category??void 0),n=fo(o.category??void 0),a=Cs(n);return d(JSON.stringify({count:e.length,integrations:e.map(r=>({id:r.id,name:r.name,category:r.category,description:r.description,packages:r.packages,difficulty:r.difficulty,envVars:r.envVars.map(i=>i.key)})),formatted:a,message:`${e.length} integration blueprints available.${o.category?` Filtered by: ${o.category}.`:""} Integration blueprints are auto-injected during implementation when your plan includes a matching integration step. Use integrationId to see full details including env vars and setup URLs.`}))}case"errors":{let e=eo(o.projectPath??process.cwd()),n=so(e,"mistflow.json");if(!to(n))return Ee(e);let a;try{a=JSON.parse(oo(n,"utf-8"))}catch{return d("Could not read mistflow.json.",!0)}let r=a.projectId;if(!r)return d("No project ID found. Deploy the project first.",!0);try{let i=await is(r,o.period??"7d");return i.total===0?d(JSON.stringify({total:0,period:i.period,message:`No runtime errors in the last ${i.period}. The app is running clean.`})):d(JSON.stringify({total:i.total,period:i.period,errors:i.errors,message:`${i.total} runtime error(s) in the last ${i.period}. Review the errors above and use mist_build debug to investigate.`}))}catch(i){let l=i instanceof Error?i.message:"Failed to fetch errors";return d(l,!0)}}case"logs":{let e=eo(o.projectPath??process.cwd()),n=so(e,"mistflow.json");if(!to(n))return Ee(e);let a;try{a=JSON.parse(oo(n,"utf-8"))}catch{return d("Could not read mistflow.json.",!0)}let r=a.projectId;if(!r)return d("No project ID found. Deploy the project first.",!0);let i=o.deploymentId;if(!i)try{let l=await yt(r);if(l.length===0)return d("No deployments found for this project.",!0);i=l[0].id}catch(l){let c=l instanceof Error?l.message:"Failed to fetch deployments";return d(c,!0)}try{let[l,c]=await Promise.all([ns(i),Oe(i)]),u=l.filter(p=>p.level==="error"),m=l.filter(p=>p.level==="warn");return d(JSON.stringify({deploymentId:i,status:c.status,errorMessage:c.error??null,totalLogs:l.length,errorCount:u.length,warnCount:m.length,logs:l.map(p=>({time:p.timestamp,level:p.level,phase:p.phase,message:p.message})),message:c.status==="failed"?`Deployment failed. ${u.length} error(s) found in logs. Review the logs above to diagnose the issue.`:`Deployment status: ${c.status}. ${l.length} log entries (${u.length} errors, ${m.length} warnings).`}))}catch(l){let c=l instanceof Error?l.message:"Failed to fetch deploy logs";return d(c,!0)}}case"deployments":{let e=eo(o.projectPath??process.cwd()),n=so(e,"mistflow.json");if(!to(n))return Ee(e);let a;try{a=JSON.parse(oo(n,"utf-8"))}catch{return d("Could not read mistflow.json.",!0)}let r=a.projectId;if(!r)return d("No project ID found. Deploy the project first.",!0);try{let i=await yt(r);return d(JSON.stringify({total:i.length,deployments:i.map(l=>({id:l.id,status:l.status,errorMessage:l.error_message,durationSeconds:l.duration_seconds,isRollback:!!l.rollback_from_id,createdAt:l.created_at})),message:`${i.length} deployment(s) found. Use mist_project action='logs' deploymentId='<id>' to see detailed logs for any deployment.`}))}catch(i){let l=i instanceof Error?i.message:"Failed to fetch deployments";return d(l,!0)}}case"version":{gt().backendSignalReceived||await Ho();let e=gt(),n=e.severity==="none",a={none:"up to date",patch:"patch update available",minor:"minor update available",major:"major update available",unsupported:"UNSUPPORTED \u2014 upgrade required"};return d(JSON.stringify({current:e.current,latest:e.latest||"unknown",minSupported:e.minSupported||"unknown",severity:e.severity,upToDate:n,upgradeCmd:e.upgradeCmd,changelogUrl:e.changelogUrl,backendSignalReceived:e.backendSignalReceived,message:e.backendSignalReceived?`Mistflow MCP ${e.current} (${a[e.severity]??e.severity}). Latest: ${e.latest}.${n?"":` Run \`${e.upgradeCmd}\` and restart your editor to upgrade.`}`:`Mistflow MCP ${e.current}. The backend hasn't replied yet \u2014 make one other API call (e.g. mist_project action='get') then retry to see the latest version.`}))}default:return d(`Unknown action: ${o.action}. Use get, update, share, landing-designs, integrations, errors, logs, deployments, or version.`,!0)}}};import{z as _e}from"zod";import{z as Ge}from"zod";import{resolve as Ll}from"path";var Zu=Ge.object({projectPath:Ge.string().optional().describe("Path to the project directory (default: cwd)"),action:Ge.enum(["set","list","delete"]).describe("Action to perform"),key:Ge.string().optional().describe("Environment variable name (required for 'set' and 'delete')"),value:Ge.string().optional().describe("Environment variable value (required for 'set')"),category:Ge.string().optional().describe("Category for the env var (default: 'custom')"),description:Ge.string().optional().describe("Description of what this env var is for"),setupUrl:Ge.string().optional().describe("URL where the user can obtain this value (e.g. Stripe dashboard)")});async function ln(s){let{projectPath:o,action:t,key:e,value:n,category:a,description:r,setupUrl:i}=s,l=Ll(o??process.cwd());if(!be())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let u=Re(l)?.projectId;if(!u)return d("No project ID found. Deploy your project first with mist_deploy, or initialize with mist_plan + mist_build.",!0);try{switch(t){case"set":return e?n?(await ss(u,e,n,{category:a,description:r,setupUrl:i}),d(JSON.stringify({set:!0,key:e,message:`Environment variable '${e}' has been set. It will be available on your next deployment.`}))):d("Value is required. Provide the env var value.",!0):d("Key is required. Provide the env var name like 'STRIPE_SECRET_KEY'.",!0);case"list":{let m=await os(u);return m.length===0?d(JSON.stringify({envVars:[],message:"No environment variables configured. Use action 'set' to add one."})):d(JSON.stringify({envVars:m.map(p=>({key:p.key,category:p.category,description:p.description,hasValue:p.has_value})),message:`${m.length} environment variable(s) configured.`}))}case"delete":return e?(await rs(u,e),d(JSON.stringify({deleted:!0,key:e,message:`Environment variable '${e}' has been removed.`}))):d("Key is required. Provide the env var name to delete.",!0);default:return d(`Unknown action: ${t}. Use set, list, or delete.`,!0)}}catch(m){if(m instanceof Se)return d(m.message,!0);let p=m instanceof Error?m.message:"An unexpected error occurred";return d(p,!0)}}import{z as Ct}from"zod";import{resolve as Ol,join as Ul}from"path";import{existsSync as Fl,readFileSync as Bl,writeFileSync as ql}from"fs";var am=Ct.object({projectPath:Ct.string().optional().describe("Path to the project directory (default: cwd)"),action:Ct.enum(["add","list","verify","remove"]).describe("Action to perform"),domain:Ct.string().optional().describe("Domain name (required for 'add' and 'remove')"),domainId:Ct.string().optional().describe("Domain ID (required for 'verify' and 'remove')")});function Lo(s,o){let t=Ul(s,"mistflow.json");if(!Fl(t))return;let e;try{e=JSON.parse(Bl(t,"utf-8"))}catch{return}e.domains=o,ql(t,JSON.stringify(e,null,2)+`
|
|
5091
|
+
`)}async function cn(s){let{projectPath:o,action:t,domain:e,domainId:n}=s,a=Ol(o??process.cwd());if(!be())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let i=Re(a)?.projectId;if(!i)return d("No project ID found. Deploy your project first with mist_deploy, or initialize with mist_plan + mist_build.",!0);try{switch(t){case"add":{if(!e)return d("Domain name is required. Provide the domain like 'myapp.com' or 'app.mycompany.com'.",!0);let l=await Qo(i,e),c=await Je(i);return Lo(a,c.map(u=>({domain:u.domain,status:u.status}))),d(JSON.stringify({added:!0,domain:l.domain,status:l.status,instructions:l.instructions,message:`Domain '${l.domain}' added. Set up DNS records as described, then use action 'verify' to check status.`}))}case"list":{let l=await Je(i);return l.length===0?d(JSON.stringify({domains:[],message:"No custom domains configured. Use action 'add' to add one."})):d(JSON.stringify({domains:l.map(c=>({id:c.id,domain:c.domain,status:c.status,ssl:c.ssl_status,error:c.error_message}))}))}case"verify":{if(!n){if(e){let m=(await Je(i)).find(p=>p.domain===e);if(m){let p=await lo(i,m.id);return d(JSON.stringify({domain:p.domain,status:p.status,ssl:p.ssl_status,error:p.error_message,message:p.status==="active"?`Domain '${p.domain}' is active and serving traffic.`:`Domain '${p.domain}' is ${p.status}. Make sure DNS records are configured correctly.`}))}return d(`Domain '${e}' not found. Use action 'list' to see configured domains.`,!0)}return d("Provide either domainId or domain name to verify.",!0)}let l=await lo(i,n),c=await Je(i);return Lo(a,c.map(u=>({domain:u.domain,status:u.status}))),d(JSON.stringify({domain:l.domain,status:l.status,ssl:l.ssl_status,error:l.error_message,message:l.status==="active"?`Domain '${l.domain}' is active and serving traffic.`:`Domain '${l.domain}' is ${l.status}. Make sure DNS records are configured correctly.`}))}case"remove":{if(!n&&!e)return d("Provide either domainId or domain name to remove.",!0);let l=n;if(!l&&e){let m=(await Je(i)).find(p=>p.domain===e);if(!m)return d(`Domain '${e}' not found.`,!0);l=m.id}await Xo(i,l);let c=await Je(i);return Lo(a,c.map(u=>({domain:u.domain,status:u.status}))),d(JSON.stringify({removed:!0,message:"Domain removed. It may take a few minutes for DNS changes to propagate."}))}default:return d(`Unknown action: ${t}. Use add, list, verify, or remove.`,!0)}}catch(l){if(l instanceof Se)return d(l.message,!0);let c=l instanceof Error?l.message:"An unexpected error occurred";return d(c,!0)}}var zl=_e.object({resource:_e.enum(["env","domain"]).describe("'env' manages app secrets and configuration values. 'domain' manages custom domains."),action:_e.string().describe("Action to perform. env: 'set', 'list', 'delete'. domain: 'add', 'list', 'verify', 'remove'."),projectPath:_e.string().optional().describe("Path to the project directory (default: cwd)"),key:_e.string().optional().describe("(env) Variable name"),value:_e.string().optional().describe("(env set) Variable value"),category:_e.string().optional().describe("(env set) Category"),description:_e.string().optional().describe("(env set) Description"),setupUrl:_e.string().optional().describe("(env set) URL to obtain the value"),domain:_e.string().optional().describe("(domain) Domain name"),domainId:_e.string().optional().describe("(domain) Domain ID")}),dn={name:"mist_config",description:"Manage project configuration: app secrets and custom domains. Set resource='env' to manage encrypted app secrets (set, list, delete). Set resource='domain' to manage custom domains (add, list, verify, remove). Use when the user says 'mist env' or 'mist domain'.",inputSchema:zl,handler:async s=>{let o=s;switch(o.resource){case"env":return ln({projectPath:o.projectPath,action:o.action,key:o.key,value:o.value,category:o.category,description:o.description,setupUrl:o.setupUrl});case"domain":return cn({projectPath:o.projectPath,action:o.action,domain:o.domain,domainId:o.domainId});default:return d(`Unknown resource: ${o.resource}. Use env or domain.`,!0)}}};import{z as et}from"zod";var Hl=et.object({action:et.enum(["navigate","go_back","go_forward","click","type","fill","select_option","press_key","hover","screenshot","snapshot"]).describe("Action to perform. Navigation: navigate|go_back|go_forward. Interaction: click|type|fill|select_option|press_key|hover. Visual: screenshot (returns image) | snapshot (returns accessibility tree)."),url:et.string().optional().describe("URL to navigate to. Required for 'navigate'; optional for 'screenshot' (navigates before capturing)."),selector:et.string().optional().describe("CSS selector of the target element. Required for: click, type, fill, select_option, hover. Optional for screenshot (captures just that element)."),value:et.string().optional().describe("Text to type/fill, option to select, or key to press (e.g. 'Enter', 'Tab'). Required for: type, fill, select_option, press_key."),fullPage:et.boolean().default(!1).describe("For 'screenshot': capture the full scrollable page instead of just the viewport."),includeScreenshot:et.boolean().default(!1).describe("For navigate/interact actions: also return a screenshot alongside the accessibility snapshot.")}),pn={name:"mist_browser",description:"Unified browser tool for navigating, interacting with, and capturing the app. Use 'navigate' to open a URL, interaction actions (click/type/fill/etc.) to test flows, 'snapshot' to inspect the accessibility tree, and 'screenshot' for a visual capture. Use after mist_preview to verify UI, test flows, and iterate on design.",inputSchema:Hl,handler:async s=>{let o=s,t=await Et();if(o.action==="navigate"){if(!o.url)return d("URL is required for 'navigate'.",!0);let a=[],r=c=>{c.type()==="error"&&a.push(c.text())};t.on("console",r),await t.goto(o.url,{waitUntil:"domcontentloaded",timeout:3e4}),await t.waitForLoadState("networkidle").catch(()=>{});let i=[],l=c=>i.push(c.message);if(t.on("pageerror",l),await t.waitForTimeout(500),t.removeListener("console",r),t.removeListener("pageerror",l),a.length>0||i.length>0){let c=await Nt(t),u=[{type:"text",text:JSON.stringify({url:t.url(),title:await t.title(),snapshot:c,consoleErrors:a,pageErrors:i,hasErrors:!0})}];if(o.includeScreenshot){let m=await Le(t);u.push({type:"image",data:m.toString("base64"),mimeType:"image/png"})}return{content:u}}}else if(o.action==="go_back")await t.goBack({waitUntil:"domcontentloaded",timeout:1e4});else if(o.action==="go_forward")await t.goForward({waitUntil:"domcontentloaded",timeout:1e4});else if(o.action==="click"){if(!o.selector)return d("Selector is required for 'click'.",!0);await t.click(o.selector,{timeout:1e4}),await t.waitForLoadState("domcontentloaded").catch(()=>{}),await t.waitForTimeout(500)}else if(o.action==="type"){if(!o.selector)return d("Selector is required for 'type'.",!0);if(!o.value)return d("Value is required for 'type'.",!0);await t.type(o.selector,o.value,{delay:50})}else if(o.action==="fill"){if(!o.selector)return d("Selector is required for 'fill'.",!0);if(!o.value)return d("Value is required for 'fill'.",!0);await t.fill(o.selector,o.value)}else if(o.action==="select_option"){if(!o.selector)return d("Selector is required for 'select_option'.",!0);if(!o.value)return d("Value is required for 'select_option'.",!0);await t.selectOption(o.selector,o.value)}else if(o.action==="hover"){if(!o.selector)return d("Selector is required for 'hover'.",!0);await t.hover(o.selector,{timeout:1e4})}else if(o.action==="press_key"){if(!o.value)return d("Value is required for 'press_key' (e.g. 'Enter').",!0);await t.keyboard.press(o.value),await t.waitForLoadState("domcontentloaded").catch(()=>{}),await t.waitForTimeout(500)}else if(o.action==="screenshot"){o.url&&(await t.goto(o.url,{waitUntil:"domcontentloaded",timeout:3e4}),await t.waitForLoadState("networkidle").catch(()=>{}));let a;if(o.selector){let r=await t.$(o.selector);if(!r)return d(`Element not found: ${o.selector}`,!0);a=await r.screenshot({type:"png"})}else a=await Le(t,o.fullPage);return{content:[{type:"text",text:JSON.stringify({url:t.url(),title:await t.title(),message:`Screenshot captured (${o.fullPage?"full page":"viewport"})`})},{type:"image",data:a.toString("base64"),mimeType:"image/png"}]}}else if(o.action==="snapshot"){let a=await Nt(t);return{content:[{type:"text",text:JSON.stringify({url:t.url(),title:await t.title(),snapshot:a})}]}}let e=await Nt(t),n=[{type:"text",text:JSON.stringify({url:t.url(),title:await t.title(),snapshot:e})}];if(o.includeScreenshot){let a=await Le(t);n.push({type:"image",data:a.toString("base64"),mimeType:"image/png"})}return{content:n}}};import{existsSync as $e,readFileSync as It,writeFileSync as mt}from"fs";import{join as De}from"path";import{z as At}from"zod";function un(s){let o=De(s,"mistflow.json");if(!$e(o))return{result:{name:"Project",status:"fail",message:"No mistflow.json found. This is not a Mistflow project.",fix:"Run mist_plan to design your app, then mist_build init to scaffold it."},config:null};let t;try{t=JSON.parse(It(o,"utf-8"))}catch{return{result:{name:"Project",status:"fail",message:"mistflow.json exists but contains invalid JSON.",fix:"Check mistflow.json for syntax errors. If corrupted beyond repair, delete it and re-run mist_build init."},config:null}}if(!t.name||typeof t.name!="string")return{result:{name:"Project",status:"warn",message:"mistflow.json is missing the 'name' field."},config:t};let e=t.projectId,n=e?`, id: ${e}`:", no projectId";return{result:{name:"Project",status:"pass",message:`${t.name}${n}`},config:t}}async function Gl(){let s=Bo();if(!s.ok)return{result:{name:"Auth",status:"fail",message:s.reason==="missing"?"No credentials found.":"Credentials file is malformed.",fix:"Run mist_setup to log in."},creds:null,authValid:!1};try{let o=zo(),t=await fetch(`${Ye()}/api/org`,{headers:o,signal:AbortSignal.timeout(1e4)});try{Uo(t.headers)}catch{}if(!t.ok)return t.status===401?{result:{name:"Auth",status:"fail",message:"API key is invalid or revoked.",fix:"Run mist_setup to re-authenticate."},creds:s.creds,authValid:!1}:{result:{name:"Auth",status:"warn",message:`Server returned ${t.status}. Credentials may still be valid.`},creds:s.creds,authValid:!1};let e=await t.json(),n=e.slug??s.creds.orgSlug??"unknown",a=e.plan?`, plan: ${e.plan}`:"";return{result:{name:"Auth",status:"pass",message:`org: ${n}${a}`},creds:s.creds,authValid:!0}}catch(o){return o instanceof Se?{result:{name:"Auth",status:"fail",message:`Auth check failed: ${o.message}`,fix:"Run mist_setup to re-authenticate."},creds:s.creds,authValid:!1}:{result:{name:"Auth",status:"warn",message:"Could not reach API to validate credentials. Network issue?"},creds:s.creds,authValid:!1}}}async function Wl(){let s=Date.now();try{let o=await Dt("nextjs"),t=Date.now()-s;return{result:{name:"API",status:"pass",message:`${Ye()} reachable (${t}ms)`},scaffold:o}}catch(o){let t=Date.now()-s;return{result:{name:"API",status:"fail",message:o instanceof Se?o.message:`Timeout or network error after ${t}ms`,fix:"Check your network connection. If using --api-url, verify the backend is running."},scaffold:null}}}function Vl(){let s=gt();if(!s.backendSignalReceived)return{name:"MCP version",status:"warn",message:`v${s.current} installed, but no backend signal received to compare against.`};let o={none:"up to date",patch:"patch update available",minor:"minor update available",major:"major update available",unsupported:"no longer supported"};return s.severity==="none"?{name:"MCP version",status:"pass",message:`v${s.current} (latest)`}:s.severity==="unsupported"?{name:"MCP version",status:"fail",message:`v${s.current} is ${o[s.severity]}. Minimum: v${s.minSupported}.`,fix:`Run \`${s.upgradeCmd}\` then restart your editor.`}:{name:"MCP version",status:"warn",message:`v${s.current} installed, v${s.latest} available (${o[s.severity]}).`,fix:`Run \`${s.upgradeCmd}\` then restart your editor.`}}function Yl(s,o,t,e){let n=De(s,"AGENTS.md"),a=De(s,"CLAUDE.md"),r=$e(n),i=o.methodologyVersion??"",l=t?.version??"";if(!r){if(!e||!t?.methodology)return{name:"AGENTS.md",status:"fail",message:"Missing. The host AI has no methodology context for this project.",fix:t?"Run mist_doctor without reportOnly to auto-restore it.":"Cannot restore: API unreachable. Fix connectivity first."};let c=mn(t.methodology,o);return mt(n,c),mt(a,c),{name:"AGENTS.md",status:"fix",message:`Restored from methodology v${l}.`}}if(e&&!$e(a)){let c=It(n,"utf-8");mt(a,c)}if(l&&i&&l!==i){if(!e||!t?.methodology)return{name:"AGENTS.md",status:"warn",message:`Methodology v${i} installed, v${l} available.`,fix:"Run mist_doctor to update it."};let c=mn(t.methodology,o);mt(n,c),mt(a,c);try{let u=De(s,"mistflow.json"),m=JSON.parse(It(u,"utf-8"));m.methodologyVersion=l,mt(u,JSON.stringify(m,null,2)+`
|
|
5092
|
+
`)}catch{}return{name:"AGENTS.md",status:"fix",message:`Updated methodology v${i} -> v${l}.`}}return{name:"AGENTS.md",status:"pass",message:i?`v${i}`:"present"}}async function Jl(s,o,t,e){let n=o.projectId;if(!n)return{name:"State sync",status:"skip",message:"No projectId. State sync not applicable without a linked project."};if(!t)return{name:"State sync",status:"skip",message:"Skipped (not authenticated)."};let a=ys(s),r=await bs(n);if(!a&&!r)return{name:"State sync",status:"warn",message:"No local or remote state found."};if(!a&&r){if(e){let{writeLocalState:i}=await import("./state-manager-GBP2NSYC.js");return i(s,r),{name:"State sync",status:"fix",message:"Local state was missing. Restored from remote."}}return{name:"State sync",status:"warn",message:"Local .mistflow/state.json is missing but remote state exists.",fix:"Run mist_doctor to restore it from the server."}}return a&&!r?{name:"State sync",status:"warn",message:"Local state exists but no remote state found. Remote sync may have failed."}:a&&a.projectId!==n?{name:"State sync",status:"warn",message:`state.json projectId (${a.projectId}) doesn't match mistflow.json projectId (${n}).`}:{name:"State sync",status:"pass",message:`deployCount: ${a.deployCount}, features: ${a.features.length}`}}function Kl(s){let o=[],t=[];if($e(De(s,"package.json"))?$e(De(s,"node_modules"))||o.push("node_modules not installed (run `npx -y @mistflow-ai/cli install`)"):o.push("missing package.json"),!$e(De(s,".env.local")))o.push("missing .env.local");else try{It(De(s,".env.local"),"utf-8").match(/^AUTH_SECRET=(.+)$/m)||o.push("AUTH_SECRET not set in .env.local")}catch{o.push(".env.local exists but is not readable")}let e=De(s,"app","api","auth","[...all]","route.ts");$e(e)||t.push("missing app/api/auth/[...all]/route.ts");let n=De(s,"app","api","health","route.ts");return $e(n)||t.push("missing app/api/health/route.ts (needed for deploy verification)"),o.length>0?{name:"Structure",status:"fail",message:o.join("; "),fix:o.map(a=>a.includes("node_modules")?"Run `npx -y @mistflow-ai/cli install` in the project directory (streams output, no MCP 60s timeout). Plain `npm install` also works.":a.includes(".env.local")?"Create .env.local with AUTH_SECRET=<random-secret>.":a.includes("AUTH_SECRET")?"Add AUTH_SECRET=<random-secret> to .env.local.":a.includes("package.json")?"This project is missing package.json. Was it scaffolded correctly?":"").filter(Boolean).join(" ")}:t.length>0?{name:"Structure",status:"warn",message:t.join("; ")}:{name:"Structure",status:"pass",message:"all required files present"}}function Ql(s,o){let t=o.env;if(!t?.required||typeof t.required!="object"||Object.keys(t.required).length===0)return{name:"Env vars",status:"pass",message:"no required env vars declared"};let e=[],n="";for(let a of[".env.local",".env"]){let r=De(s,a);try{$e(r)&&(n+=`
|
|
5093
|
+
`+It(r,"utf-8"))}catch{}}for(let[a,r]of Object.entries(t.required)){let i=n.includes(`${a}=`),l=!!process.env[a];if(!i&&!l){let c=r?.description?` (${r.description})`:"";e.push(`${a}${c}`)}}return e.length>0?{name:"Env vars",status:"warn",message:`${e.length} required but not set: ${e.join(", ")}`,fix:"Set them via mist_config or add to .env.local."}:{name:"Env vars",status:"pass",message:`${Object.keys(t.required).length} required, all set`}}function Xl(s){let o=s.plan;if(!o?.steps||o.steps.length===0)return{name:"Plan",status:"skip",message:"No plan found in mistflow.json."};let t=o.steps.length,e=o.steps.filter(r=>r.status==="completed").length,n=o.steps.filter(r=>r.status==="in_progress").length,a=t-e-n;if(e===t)return{name:"Plan",status:"pass",message:`${e}/${t} steps completed`};if(n>0){let r=o.steps.find(i=>i.status==="in_progress");return{name:"Plan",status:"warn",message:`${e}/${t} completed, step ${r?.number} "${r?.name}" in progress`,fix:"Run mist_build implement to continue."}}return e===0?{name:"Plan",status:"warn",message:`${t} steps planned, none started.`,fix:"Run mist_build implement to start building."}:{name:"Plan",status:"warn",message:`${e}/${t} completed, ${a} remaining.`,fix:"Run mist_build implement to continue."}}function mn(s,o){let t=o.dbProvider;return t==="neon"||!t?s.replace(/sqliteTable/g,"pgTable").replace(/drizzle-orm\/sqlite-core/g,"drizzle-orm/pg-core").replace(/Use `text` for dates \(SQLite stores dates as text\)/g,"Use `timestamp` for dates and `boolean` for booleans (native Postgres types)").replace(/text\("created_at"\)\.notNull\(\)\.default\(sql`\(CURRENT_TIMESTAMP\)`\)/g,'timestamp("created_at").notNull().defaultNow()').replace(/text\("updated_at"\)\.notNull\(\)\.default\(sql`\(CURRENT_TIMESTAMP\)`\)/g,'timestamp("updated_at").notNull().defaultNow()').replace(/import { sqliteTable, text, integer } from "drizzle-orm\/sqlite-core";\nimport { sql } from "drizzle-orm";/g,'import { pgTable, text, timestamp, boolean } from "drizzle-orm/pg-core";').replace(/`drizzle-kit push` for SQLite\/Turso/g,"`drizzle-kit push` for Postgres"):s}function Zl(s){let o={pass:"PASS",warn:"WARN",fail:"FAIL",fix:"FIXED",skip:"SKIP"},t=Math.max(...s.map(u=>u.name.length)),e=s.map(u=>{let m=".".repeat(t-u.name.length+4),p=o[u.status].padEnd(5);return` ${u.name} ${m} ${p} ${u.message}`}),n=s.filter(u=>u.status==="fix").length,a=s.filter(u=>u.status==="fail").length,r=s.filter(u=>u.status==="warn").length,i=[];n>0&&i.push(`${n} fixed`),a>0&&i.push(`${a} failure${a>1?"s":""}`),r>0&&i.push(`${r} warning${r>1?"s":""}`);let l=`mist_doctor results:
|
|
5094
5094
|
|
|
5095
|
-
`+
|
|
5095
|
+
`+e.join(`
|
|
5096
5096
|
`);i.length>0?l+=`
|
|
5097
5097
|
|
|
5098
5098
|
${i.join(", ")}`:l+=`
|
|
@@ -5100,17 +5100,21 @@ Others can use it in their AI editor:
|
|
|
5100
5100
|
All checks passed.`;let c=s.filter(u=>(u.status==="fail"||u.status==="warn")&&u.fix);if(c.length>0){l+=`
|
|
5101
5101
|
|
|
5102
5102
|
To fix:`;for(let u of c)l+=`
|
|
5103
|
-
- ${u.fix}`}return l}var hn=
|
|
5103
|
+
- ${u.fix}`}return l}var hn=At.object({projectPath:At.string().optional().describe("Path to the project directory. Defaults to the current working directory."),checks:At.array(At.enum(["project","auth","api","version","methodology","state","structure","env","plan"])).optional().describe("Run only specific checks. Omit to run all."),reportOnly:At.boolean().optional().describe("If true, report issues without auto-fixing them.")}),gn={name:"mist_doctor",description:"Diagnose project health: checks auth, API connectivity, AGENTS.md methodology, project state, version alignment, and structure. Auto-fixes safe issues (missing AGENTS.md, stale state). Run when something feels off.",inputSchema:hn,handler:async s=>{let o=hn.parse(s),t=o.projectPath||process.cwd(),e=!o.reportOnly,n=!o.checks,a=o.checks??[],r=f=>n||a.includes(f),i=[],l=null;if(r("project")){let f=un(t);i.push(f.result),l=f.config}else l=un(t).config;let c=!1;if(r("auth")||r("state")){let f=await Gl();r("auth")&&i.push(f.result),c=f.authValid}let m=null;if(r("api")||r("methodology")){let f=await Wl();r("api")&&i.push(f.result),m=f.scaffold}r("version")&&i.push(Vl()),l?(r("methodology")&&i.push(Yl(t,l,m,e)),r("state")&&i.push(await Jl(t,l,c,e)),r("structure")&&i.push(Kl(t)),r("env")&&i.push(Ql(t,l)),r("plan")&&i.push(Xl(l))):n&&(i.push({name:"AGENTS.md",status:"skip",message:"Skipped (not a Mistflow project)."}),i.push({name:"State sync",status:"skip",message:"Skipped (not a Mistflow project)."}),i.push({name:"Structure",status:"skip",message:"Skipped (not a Mistflow project)."}),i.push({name:"Env vars",status:"skip",message:"Skipped (not a Mistflow project)."}),i.push({name:"Plan",status:"skip",message:"Skipped (not a Mistflow project)."}));let g=Zl(i),b=i.some(f=>f.status==="fail");return d(g,b)}};var ro=new ec({name:"mistflow",version:"0.3.0"},{capabilities:{tools:{}},instructions:`Mistflow is a full-stack app builder that creates and deploys web apps from natural language descriptions. When a user asks to build, create, or make a web app, website, landing page, dashboard, internal tool, marketplace, content site, or browser game, use Mistflow tools. Mistflow creates NEW apps from scratch. It does NOT modify existing non-Mistflow codebases.
|
|
5104
5104
|
|
|
5105
5105
|
New app workflow:
|
|
5106
5106
|
1. mist_plan - pass the user's description EXACTLY as written. Do NOT expand, rephrase, or add features. If the tool returns status "confirm_new_project" (safety gate when inside an existing codebase), you MUST ask the user whether to scaffold a new Mistflow app or edit the existing code. If it returns status "clarify", present the discovery questions to the user, collect answers, and call mist_plan again with the conversationId and answers.
|
|
5107
5107
|
2. mist_build mockup (optional) - generates a visual HTML wireframe for user preview. Iterative: pass feedback to refine, approved=true to lock in the design.
|
|
5108
5108
|
3. mist_build init - scaffolds the project from the plan and initializes git. Pass the planId from mist_plan. Returns in ~10s; does NOT run npm install.
|
|
5109
|
-
4.
|
|
5109
|
+
4. Install dependencies: PREFER running \`npx -y @mistflow-ai/cli install <projectPath>\` via your shell/bash tool (streams output, no 60s MCP timeout). Fall back to mist_build action='install' only if your environment can't shell out.
|
|
5110
5110
|
5. mist_build implement - executes plan steps one at a time. Call repeatedly until all steps are done. It auto-marks the previous step as completed on each call.
|
|
5111
5111
|
6. mist_deploy - deploys to a live URL at <app-name>.mistflow.app. If staging mode is enabled, auto-deploys to a preview URL first (isolated database, expires in 72h). After QA passes, call mist_deploy promote to go live. Use mist_deploy preview for a local production server on localhost:3000.
|
|
5112
5112
|
7. mist_build qa - tests the LIVE deployed app. Call AFTER deploy. Do NOT show the URL to the user until QA passes. If issues found, fix and redeploy, then qa again.
|
|
5113
5113
|
|
|
5114
|
+
Companion CLI (\`@mistflow-ai/cli\`, invoke as \`mist\` or via \`npx -y @mistflow-ai/cli\`):
|
|
5115
|
+
- \`mist install <path>\` \u2014 npm install with live stdout, no 60s MCP timeout. The RECOMMENDED install path.
|
|
5116
|
+
- \`mist login\`, \`mist deploy\`, \`mist status\`, \`mist logs\`, \`mist projects\`, \`mist env\`, \`mist domains\`, \`mist rollback\` \u2014 shell-friendly mirrors of MCP actions. Use CLI for CI/scripted flows; use MCP tools (mist_plan, mist_deploy, mist_config, etc.) for interactive planning that needs AI context.
|
|
5117
|
+
|
|
5114
5118
|
IMPORTANT \u2014 chaining discipline: once the user approves the plan, the init \u2192 install \u2192 implement (repeat) \u2192 build \u2192 deploy \u2192 qa chain is expected. Do NOT pause between these calls to ask the user "should I continue?" or offer options like "full build vs step-by-step." The tool itself will return a status requiring user input when it actually needs one (e.g. confirm_new_project, confirm_dark_theme, awaiting promotion). Otherwise, chain calls continuously. Brief one-line status updates ("Starting step 3 of 7: Google Maps") are fine and encouraged; permission requests are not. Idea is for them to get the mist deployed url without needing to understand or manage the complexity behind it.
|
|
5115
5119
|
|
|
5116
5120
|
Design presets (optional, between steps 1 and 3):
|
|
@@ -5134,4 +5138,4 @@ Other tools:
|
|
|
5134
5138
|
- mist_project: read/update project state, browse landing designs and app styles, view runtime errors, deploy logs, deployment history, and check MCP version.
|
|
5135
5139
|
- mist_config: manage encrypted app secrets (env vars) and custom domains.
|
|
5136
5140
|
- mist_browser: navigate, interact with, and screenshot the app during preview or after deploy.
|
|
5137
|
-
- mist_doctor: diagnose project health. Checks auth, API connectivity, AGENTS.md methodology, MCP version, project state, structure, and env vars. Auto-fixes safe issues (missing/outdated AGENTS.md, missing local state). Run when something feels off or tools behave unexpectedly.`}),fn=[ks,Ls,
|
|
5141
|
+
- mist_doctor: diagnose project health. Checks auth, API connectivity, AGENTS.md methodology, MCP version, project state, structure, and env vars. Auto-fixes safe issues (missing/outdated AGENTS.md, missing local state). Run when something feels off or tools behave unexpectedly.`}),fn=[ks,Ls,Ar,on,an,dn,pn,gn];ro.setRequestHandler(sc,async()=>({tools:fn.map(s=>({name:s.name,description:s.description,inputSchema:rc(s.inputSchema)}))}));ro.setRequestHandler(oc,async s=>{let o=fn.find(t=>t.name===s.params.name);if(!o)return d(`Unknown tool: ${s.params.name}`,!0);try{let t=o.inputSchema.safeParse(s.params.arguments);if(!t.success){let a=t.error.issues.map(r=>`${r.path.join(".")}: ${r.message}`).join(", ");return d(`Invalid input: ${a}`,!0)}let e=s.params._meta?.progressToken,n={server:ro,progressToken:e};try{return await o.handler(t.data,n)}finally{n.cleanup?.()}}catch(t){let e=t instanceof Error?t.message:"An unexpected error occurred";return console.error("Tool error:",t),d(e,!0)}});async function nc(){let s=process.argv.indexOf("--api-url");s!==-1&&process.argv[s+1]&&(process.env.MISTFLOW_API_URL=process.argv[s+1]),process.argv.includes("--local")&&!process.env.MISTFLOW_API_URL&&(process.env.MISTFLOW_API_URL="http://localhost:9100");let o=new tc;await ro.connect(o),console.error(`Mistflow MCP server running on stdio (API: ${process.env.MISTFLOW_API_URL||"https://api.mistflow.ai"})`)}nc().catch(s=>{console.error("Fatal error:",s),process.exit(1)});
|