@mistflow-ai/mcp 0.4.0 → 0.4.1
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/api-client-RCNDMCPS.js +1 -0
- package/dist/{chunk-POG2UHKW.js → chunk-2X3ZTRP7.js} +1 -1
- package/dist/chunk-OIW7LXTF.js +23 -0
- package/dist/index.js +99 -99
- package/dist/{self-heal-IANGU6DO.js → self-heal-BXJXUFUF.js} +1 -1
- package/dist/state-manager-GBP2NSYC.js +1 -0
- package/package.json +1 -1
- package/dist/api-client-5AWPJEHX.js +0 -1
- package/dist/chunk-Y3F6QWAR.js +0 -23
- package/dist/state-manager-HGPAQSNJ.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as Ct,d as It,e as Me}from"./chunk-UNFTM4B3.js";import{b as
|
|
1
|
+
import{a as Ct,d as It,e as Me}from"./chunk-UNFTM4B3.js";import{b as hs,c as io,d as ao,e as gs}from"./chunk-2X3ZTRP7.js";import{A as ro,C as Yo,D as We,E as no,F as Jo,G as Ko,H as Qo,I as Xo,J as Zo,K as es,L as ts,M as os,N as ss,O as mt,P as rs,Q as ns,R as is,S as as,T as Nt,U as ls,V as cs,W as ds,X as ps,Y as us,_ as ms,b as jo,c as Lo,d as pt,e as Oo,f as so,g as Rt,h as fe,i as Ae,j as Ge,k as ut,l as Uo,m as xe,n as Fo,o as Bo,s as qo,t as zo,u as Ho,w as Go,x as $e,y as Wo,z as Vo}from"./chunk-OIW7LXTF.js";import{Server as Ql}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as Xl}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as Zl,ListToolsRequestSchema as ec}from"@modelcontextprotocol/sdk/types.js";import{zodToJsonSchema as tc}from"zod-to-json-schema";function d(s,o=!1){let e=s;try{let t=Lo();t&&(e=s+t)}catch{}return{content:[{type:"text",text:e}],isError:o}}function Ce(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 je(s,o){try{let{getPage:e,takeScreenshot:t}=await import("./browser-manager-QW3OYPFB.js"),n=await e();await n.goto(s,{waitUntil:"domcontentloaded",timeout:15e3}),await n.waitForLoadState("networkidle").catch(()=>{});let a=await t(n,!1);return{content:[{type:"text",text:o},{type:"image",data:a.toString("base64"),mimeType:"image/png"}]}}catch{return d(o)}}import{z as lo}from"zod";import{platform as
|
|
10
|
+
If you want to deploy an existing project, use your framework's deploy tools directly.`,!0)}async function je(s,o){try{let{getPage:e,takeScreenshot:t}=await import("./browser-manager-QW3OYPFB.js"),n=await e();await n.goto(s,{waitUntil:"domcontentloaded",timeout:15e3}),await n.waitForLoadState("networkidle").catch(()=>{});let a=await t(n,!1);return{content:[{type:"text",text:o},{type:"image",data:a.toString("base64"),mimeType:"image/png"}]}}catch{return d(o)}}import{z as lo}from"zod";import{platform as gn}from"os";import{execFile as fs}from"child_process";var fn=lo.object({apiKey:lo.string().optional().describe("API key (mist_...) for headless auth. Skips the device code flow entirely. Generate one at app.mistflow.ai/mcp-keys."),deviceCode:lo.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 yn(s){return"error"in s}function bn(s){return new Promise(o=>setTimeout(o,s))}function wn(s){return new Promise(o=>{let e=gn();e==="win32"?fs("cmd.exe",["/c","start","",s],t=>{t&&console.error("Could not open browser:",t.message),o(!t)}):fs(e==="darwin"?"open":"xdg-open",[s],n=>{n&&console.error("Could not open browser:",n.message),o(!n)}),setTimeout(()=>o(!1),5e3)})}var vn={fetch:globalThis.fetch,openBrowser:wn};async function ys(s,o,e,t){let n=e;for(let a=0;a<o;a++){await bn(n);let r;try{let l=await t.fetch(`${Ge()}/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(yn(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 so({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 kn(s,o=vn){let e=s;if(e?.apiKey)try{let r=await o.fetch(`${Ge()}/api/org`,{headers:{Authorization:`ApiKey ${e.apiKey}`}});if(!r.ok)return d("Invalid API key. Check the key and try again.",!0);let i=await r.json();return so({apiKey:e.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(e?.deviceCode){let r=await ys(e.deviceCode,6,5e3,o);return r||d(JSON.stringify({status:"pending",deviceCode:e.deviceCode,instruction:"The user hasn't approved yet. Wait ~15 seconds and call mist_setup again with the same deviceCode."}))}let t;try{let r=await o.fetch(`${Ge()}/auth/device`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!r.ok)return d("Cannot reach Mistflow servers. Check your internet connection.",!0);t=await r.json()}catch{return d("Cannot reach Mistflow servers. Check your internet connection.",!0)}let n=`${t.verification_uri}?code=${t.user_code}`;console.error(`
|
|
11
11
|
Sign in at: ${n}
|
|
12
12
|
Your code: ${t.user_code}
|
|
13
|
-
`);try{await o.openBrowser(n)}catch{}let a=await
|
|
13
|
+
`);try{await o.openBrowser(n)}catch{}let a=await ys(t.device_code,6,5e3,o);return a||d(JSON.stringify({status:"pending",deviceCode:t.device_code,signInUrl:n,userCode:t.user_code,instruction:"The user hasn't approved yet. Wait ~15 seconds, then call mist_setup again with deviceCode='"+t.device_code+"' to check if they approved."}))}var bs={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:fn,handler:s=>kn(s)};import{z as O}from"zod";import{existsSync as ht,mkdirSync as _t,readFileSync as Ns,readdirSync as Dn,statSync as Mn,unlinkSync as $n,writeFileSync as Dt}from"fs";import{dirname as jn,isAbsolute as Ln,join as be}from"path";import{homedir as Le}from"os";import{createHash as On,createHmac as Es,randomBytes as Un,randomUUID as Rs,timingSafeEqual as Fn}from"crypto";var co={},Qe=[];function Xe(s){let o=Qe.find(t=>t.id===s);if(o)return o;let e=s.toLowerCase().replace(/[^a-z0-9]/g,"");return Qe.find(t=>{let n=t.title.toLowerCase().replace(/[^a-z0-9]/g,"");return n===e||n.includes(e)||e.includes(n)})}function ws(s){return co[s]}function po(s){return s?Qe.filter(o=>o.category.toLowerCase()===s.toLowerCase()):Qe}function vs(s){let o=s??Qe;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 e={};for(let n of o){e[n.category]||(e[n.category]=[]);let a=co[n.id],r=a?` \u2014 ${a.description}`:"";e[n.category].push(`${n.id} \u2014 "${n.title}"${r}`)}let t=[];for(let[n,a]of Object.entries(e))t.push(`**${n}**:
|
|
14
14
|
${a.map(r=>` \u2022 ${r}`).join(`
|
|
15
15
|
`)}`);return t.join(`
|
|
16
16
|
|
|
17
|
-
`)}function
|
|
17
|
+
`)}function xn(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function ks(s){return(s?po(s):Qe).map(e=>{let t=co[e.id];return{id:e.id,slug:xn(e.title),title:e.title,category:e.category,description:t?.description??"",tags:t?.tags??[],theme:t?.theme??"dark",colors:t?.colors??[],style:t?.style??""}})}function xs(s,o){return[]}var uo={"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"}},Ze=[{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 Sn(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function et(s){let o=Ze.find(t=>t.id===s);if(o)return o;let e=s.toLowerCase().replace(/[^a-z0-9]/g,"");return Ze.find(t=>{let n=t.name.toLowerCase().replace(/[^a-z0-9]/g,"");return n===e||n.includes(e)||e.includes(n)})}function tt(s){return uo[s]}function mo(s){return s?Ze.filter(o=>o.category.toLowerCase()===s.toLowerCase()):Ze}function Ss(s){let o=s??Ze,e={};for(let n of o){e[n.category]||(e[n.category]=[]);let a=uo[n.id],r=a?` \u2014 ${a.description}`:"",i=a?.packages.length?` (${a.packages.join(", ")})`:"";e[n.category].push(`${n.id} \u2014 "${n.name}"${r}${i}`)}let t=[];for(let[n,a]of Object.entries(e))t.push(`**${n}**:
|
|
1438
1438
|
${a.map(r=>` - ${r}`).join(`
|
|
1439
1439
|
`)}`);return t.join(`
|
|
1440
1440
|
|
|
1441
|
-
`)}function
|
|
1442
|
-
`)}function
|
|
1441
|
+
`)}function Ts(s){return(s?mo(s):Ze).map(e=>{let t=uo[e.id];return{id:e.id,slug:Sn(e.name),name:e.name,category:e.category,description:t?.description??"",tags:t?.tags??[],envVars:t?.envVars??[],docsUrl:t?.docsUrl??"",packages:t?.packages??[],difficulty:t?.difficulty??"medium"}})}var Tn=[{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 Ps(s,o,e){let t=e?.suggestedName||Pn(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(e?.suggestedFeatures&&e.suggestedFeatures.length>0)i=e.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 Tn){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:t,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:e?.language||"English"}}function As(s){let o=s.features.filter(i=>i.checked),e=s.features.filter(i=>!i.checked),t={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: ${t[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(", ")}`)),e.length>0){r.push(""),r.push("**Available to add:**");for(let i of e)r.push(` \u25CB ${i.name} \u2014 ${i.description}`)}return r.join(`
|
|
1442
|
+
`)}function Pn(s){let o=s.match(/\b(?:called|named)\s+["']?([A-Za-z][A-Za-z0-9 ]{1,30})["']?/i);if(o)return ho(o[1]);let e=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&&!e.has(a)).slice(0,3);return n.length===0?"my-app":n.join("-")}function ho(s){return s.toLowerCase().replace(/[^a-z0-9\s]/g,"").trim().replace(/\s+/g,"-")}var An=["typographic","split-panel","terminal","full-bleed-photo","magazine-hero"],Cn=["sharp","soft","pill","organic"],In=["flat","paper-grain","film-grain","scanlines","gradient-mesh","noise","glassmorphic"];function go(s,o,e){return o.includes(s)?s:e}function ye(s){return String(s??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ot(s,o){return typeof s!="string"?o:/^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/.test(s.trim())?s.trim():o}function Rn(s){let o=new Set;for(let t of s)t.fonts?.display&&o.add(t.fonts.display),t.fonts?.body&&o.add(t.fonts.body);return o.size===0?"":`https://fonts.googleapis.com/css2?${[...o].map(t=>`family=${t.trim().replace(/\s+/g,"+").replace(/[^A-Za-z0-9+]/g,"")}:wght@400;700`).join("&")}&display=swap`}function Cs(s){let o=(s||"").trim(),e=o.toLowerCase(),t=/mono|courier|code/.test(e)?"ui-monospace, monospace":/serif|garamond|bodoni|fraunces|playfair|lora|sentient|migra|sectra|cormorant|abril|crimson/.test(e)?"Georgia, serif":"system-ui, sans-serif";return o?`"${o.replace(/"/g,"")}", ${t}`:t}function Nn(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 En(){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
|
|
1500
|
+
`}function _n(s,o,e,t){let n=ot(s.colors?.bg??"","#0f0f0f"),a=ot(s.colors?.fg??"","#f5f5f5"),r=ot(s.colors?.accent??"","#7c9cff"),i=ye(s.name),l=ye(s.hero_headline||s.name),c=ye(s.body_sample||s.summary||""),u=ye(s.cta_text||"Continue"),m=`<div class="hero-eyebrow" style="font-family:${e}">${i.toUpperCase()}</div>`,p=`<h2 class="hero-headline" style="font-family:${o}">${l}</h2>`,g=`<p class="hero-body" style="font-family:${e}">${c}</p>`,v=`<button class="hero-cta" style="background:${r};color:${n};font-family:${e};border-radius:${t.button}">${u}</button>`,f=go(s.hero_treatment,An,"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>
|
|
@@ -1540,7 +1540,7 @@ ${a.map(r=>` - ${r}`).join(`
|
|
|
1540
1540
|
${p}
|
|
1541
1541
|
${g}
|
|
1542
1542
|
<div class="hero-cta-row">${v}</div>
|
|
1543
|
-
`}function
|
|
1543
|
+
`}function Is(s,o){let e=Rn(o),t=o.map(n=>{let a=ot(n.colors?.bg??"","#0f0f0f"),r=ot(n.colors?.fg??"","#f5f5f5"),i=ot(n.colors?.accent??"","#7c9cff"),l=Cs(n.fonts?.display??""),c=Cs(n.fonts?.body??""),u=go(n.shape_lang,Cn,"soft"),m=go(n.texture,In,"flat"),p=Nn(u),g=_n(n,l,c,p),v=ye(n.name),f=ye(n.id),h=ye(n.fonts?.display??""),k=ye(n.fonts?.body??""),S=ye(n.summary||""),R=ye(n.decoration_hint||""),x=(I,q)=>`<div class="card-meta-row"><span class="card-meta-label">${I}</span><span class="card-meta-value">${q}</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">
|
|
@@ -1752,7 +1752,7 @@ ${a.map(r=>` - ${r}`).join(`
|
|
|
1752
1752
|
margin-top: 4px;
|
|
1753
1753
|
}
|
|
1754
1754
|
|
|
1755
|
-
${
|
|
1755
|
+
${En()}
|
|
1756
1756
|
|
|
1757
1757
|
/* \u2500\u2500 Card meta footer \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 */
|
|
1758
1758
|
.card-meta {
|
|
@@ -1881,22 +1881,22 @@ ${t}
|
|
|
1881
1881
|
</div>
|
|
1882
1882
|
</body>
|
|
1883
1883
|
</html>
|
|
1884
|
-
`}var Et="__mistflow_url_choice__",
|
|
1885
|
-
`)}),!0);if(y==="foreign"&&!g){if(!(v?
|
|
1886
|
-
`)}))}x="Note: You're inside an existing project. Mistflow will create the new app in a subdirectory. It won't modify this codebase."}else y==="foreign"&&g&&(x="Note: You're inside an existing project. Mistflow will create the new app in a subdirectory. It won't modify this codebase.")}if(i)try{if(!(await
|
|
1884
|
+
`}var Et="__mistflow_url_choice__",Bn=600*1e3;function _s(){let s=be(Le(),".mistflow","confirm-secret");if(ht(s))try{return Buffer.from(Ns(s,"utf-8").trim(),"hex")}catch{}let o=Un(32);return _t(be(Le(),".mistflow"),{recursive:!0}),Dt(s,o.toString("hex"),{mode:384}),o}function Ds(s){return On("sha256").update(s.trim().toLowerCase()).digest("hex").slice(0,16)}function qn(s,o){let e={cwd:s,d:Ds(o),exp:Date.now()+Bn},t=Buffer.from(JSON.stringify(e)).toString("base64url"),n=Es("sha256",_s()).update(t).digest("base64url");return`${t}.${n}`}function zn(s,o,e){let t=s.split(".");if(t.length!==2)return!1;let[n,a]=t,r=Es("sha256",_s()).update(n).digest("base64url"),i=Buffer.from(a),l=Buffer.from(r);if(i.length!==l.length||!Fn(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!==Ds(e))}catch{return!1}}function Hn(s){let o=s,e=Le(),t=!1;for(let n=0;n<64;n++){if(ht(be(o,"mistflow.json")))return"mistflow";if(!t&&ht(be(o,"package.json"))&&(t=!0),o===e)break;let a=jn(o);if(a===o)break;o=a}return t?"foreign":"none"}function Gn(s){let o=Le(),e=s.replace(/\/+$/,"");if(e===o||e==="/"||e===""||e==="/tmp"||e==="/private/tmp")return!0;let t=["Desktop","Documents","Downloads"];for(let n of t)if(e===be(o,n))return!0;return!1}var Wn=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 Vn(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[t,n]of o)if(t.test(s))return n;return s.replace(/[?.,!]/g,"").split(/\s+/).filter(t=>!["what","how","do","does","is","are","the","a","an","would","should","you","your","for","this","that","to","of","or","and","want","like","prefer"].includes(t.toLowerCase())).slice(0,2).join(" ").slice(0,12)||"Option"}function Yn(s){let o=be(Le(),".mistflow","plans",`${s}.json`);if(!ht(o))return null;try{return JSON.parse(Ns(o,"utf-8")).plan??null}catch{return null}}async function Jn(s){for(let t=0;t<60;t++){try{let n=await Wo(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 ${t+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 Kn(s){let{description:o,projectPath:e,conversationId:t,answers:n,existingPlan:a,existingPlanId:r,templateToken:i,remixDescription:l,autonomous:c,language:u,landingDesign:m,appStyle:p,brandMentioned:g,confirmToken:v,urlChoice:f,designConversationId:h,designDirection:k}=s,S=a;if(!S&&r&&(S=Yn(r)??void 0,!S))return d("Your previous plan is no longer available. Please describe your app again to generate a new plan.",!0);let R=t;if(!fe())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let x;if(!R&&!S&&!i){if(!Ln(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 y=Hn(e);if(y!=="mistflow"&&Gn(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(y==="foreign"&&!g){if(!(v?zn(v,e,o):!1)){let $=qn(e,o);return d(JSON.stringify({status:"confirm_new_project",projectPath:e,description:o,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.",v?"The previous confirmToken was invalid, expired, or did not match the current directory/description. Use the fresh token above.":""].filter(Boolean).join(`
|
|
1886
|
+
`)}))}x="Note: You're inside an existing project. Mistflow will create the new app in a subdirectory. It won't modify this codebase."}else y==="foreign"&&g&&(x="Note: You're inside an existing project. Mistflow will create the new app in a subdirectory. It won't modify this codebase.")}if(i)try{if(!(await ds(i)).plan)return d("This template has no plan to fork. Try a different template.",!0);let b=await ps(i),$=b.plan,E="";if(l&&b.has_source)try{let ge=await ro(b.plan,l),X=ge.plan??ge,At=ge.diff,ne=X?.steps??[],oo=new Set([...(At?.added??[]).map(Pe=>Pe.number),...(At?.modified??[]).map(Pe=>Pe.number)]),De=ne.map(Pe=>{let hn=Pe.number;return oo.has(hn)?{...Pe,status:"pending"}:{...Pe,status:"completed",source:"forked"}});X.steps=De,$=X;let He=De.filter(Pe=>Pe.status==="pending").length;E=` Remixed: ${De.filter(Pe=>Pe.status==="completed").length} steps unchanged, ${He} steps need re-implementation.`}catch(ge){console.error("[plan] Remix failed, using original plan:",ge),E=" (Remix failed \u2014 using original plan. You can modify it later.)"}let ae=Rs(),re=be(Le(),".mistflow","plans");_t(re,{recursive:!0}),Dt(be(re,`${ae}.json`),JSON.stringify({plan:$,projectId:b.id,sourceDeploymentId:b.source_deployment_id,forkToken:b.fork_token,requiredEnvVars:b.required_env_vars,dbProvider:b.db_provider}));let pe=$?.name??"forked-app",he=b.has_source,dt=he?"Source code will be restored during init. Run init promptly \u2014 the download token expires in 1 hour.":"",ze=b.deploy_url?` Instant deploy started \u2014 your app will be live at ${b.deploy_url} in under a minute.`:"";return d(JSON.stringify({planId:ae,forkedFrom:b.forked_from,projectId:b.id,hasSource:he,deployUrl:b.deploy_url,message:`Forked "${b.forked_from}" into your workspace.${E}${ze} ${dt} NEXT: Call mist_build with action='init', name='${pe}', and planId='${ae}' to create the project now.`}))}catch(y){let b=y instanceof Error?y.message:"Failed to fork template";return d(b,!0)}if(S){let y;try{y=await ro(S,o)}catch(re){let pe=re instanceof Error?re.message:"Failed to modify plan";return d(pe,!0)}let b=y.plan,$=y.diff,E=[];if($?.added?.length){let re=$.added.map(pe=>pe.title);E.push(`Added ${re.length} step(s): ${re.join(", ")}`)}if($?.removed?.length){let re=$.removed.map(pe=>pe.title);E.push(`Removed ${re.length} step(s): ${re.join(", ")}`)}if($?.modified?.length){let re=$.modified.map(pe=>pe.title);E.push(`Modified ${re.length} step(s): ${re.join(", ")}`)}let ae=E.length>0?E.join(". "):"No changes detected.";return d(JSON.stringify({plan:b,diff:$,message:`Plan modified. ${ae}. Update mistflow.json with the new plan, then continue with mist_build (action: 'implement').`}))}let I=f?.trim()||void 0,q=n;if(!I&&n&&Et in n&&(I=n[Et]),n&&Et in n){let{[Et]:y,...b}=n;q=Object.keys(b).length>0?b:void 0}if(I&&(I=I.replace(/^Keep\s+/i,"").replace(/\s*\(Recommended\)\s*$/i,"").replace(/\.mistflow\.app.*$/i,"").trim()||void 0),I){let y=I.toLowerCase().replace(/\s+/g,"-");/^[a-z0-9][a-z0-9-]{1,30}[a-z0-9]$/.test(y)?I=y:(console.error(`[mist_plan] Discarding urlChoice '${I}' \u2014 does not look like a subdomain. Backend will auto-generate.`),I=void 0)}let A;if(k){A={...k};let y={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[b,$]of Object.entries(y))k[b]!==void 0&&A[$]===void 0&&(A[$]=k[b])}let _;try{_=await Vo(o,{conversationId:R,answers:q,autonomous:c,language:u,designConversationId:h,designDirection:A})}catch(y){let b=y instanceof Error?y.message:"Failed to generate plan";return d(b,!0)}if(_.status==="design_clarify_pending"&&(_=await Jn(_)),_.status==="clarify"){let y=_.reflection||"",b=_.suggestedName||"",$=_.suggestedFeatures??[],E=_.questions??[],ae=E.some(ne=>Array.isArray(ne.options)&&typeof ne.options[0]=="object"&&ne.options[0]?.label),re={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"},pe=E.map(ne=>{let oo=ne.decisionKey&&re[ne.decisionKey]||Vn(ne.question),De;return ae&&Array.isArray(ne.options)?De=ne.options.map(He=>({label:He.label,description:He.description??""})):Array.isArray(ne.options)?De=ne.options.map((He,$o)=>({label:$o===0?`${He} (Recommended)`:String(He),description:ne.why??""})):De=[{label:"Yes (Recommended)",description:ne.why??""},{label:"No",description:""}],{question:ne.question,header:oo,options:De,multiSelect:!1}}),dt=_.decisions?.audienceType??null,ze=$.length>0?Ps(o,{primaryActor:null,primaryAction:null,surfaceType:null,audienceType:dt,multiRole:null,publicLanding:null,realMoney:null,scheduling:null,authModel:null,dbProvider:null,integrations:null},{suggestedName:b,suggestedFeatures:$,language:u}):null,ge=ze?As(ze):"",X=ho(b||"my-app").slice(0,32);try{let ne=await zo(X);!ne.available&&ne.suggestion&&(X=ne.suggestion)}catch{}ge&&(ge+=`
|
|
1887
1887
|
|
|
1888
|
-
**Your app URL:** https://${X}.mistflow.app`);let At={question:`Your app will be at ${X}.mistflow.app \u2014 want to customize the URL?`,header:"URL",options:[{label:`Keep ${X}.mistflow.app (Recommended)`,description:"This URL is available"},{label:"Choose a different URL",description:"Type your preferred subdomain"}],multiSelect:!1};return pe.push(At),d(JSON.stringify({status:"clarify",conversation_id:
|
|
1888
|
+
**Your app URL:** https://${X}.mistflow.app`);let At={question:`Your app will be at ${X}.mistflow.app \u2014 want to customize the URL?`,header:"URL",options:[{label:`Keep ${X}.mistflow.app (Recommended)`,description:"This URL is available"},{label:"Choose a different URL",description:"Type your preferred subdomain"}],multiSelect:!1};return pe.push(At),d(JSON.stringify({status:"clarify",conversation_id:_.conversation_id,questions:E,questionCount:E.length,suggestedFeatures:$,suggestedName:b,suggestedSubdomain:X,reflection:y,briefText:ge,askUserQuestions:pe,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:[...x?[x,""]:[],y?`${y}
|
|
1889
1889
|
`:"",ge?`Here's what I'd build:
|
|
1890
1890
|
|
|
1891
1891
|
${ge}
|
|
1892
|
-
`:"",`I have ${E.length} quick question${E.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: "${
|
|
1893
|
-
`)}))}if(
|
|
1894
|
-
`)}))}let N=j.plan,z=N.name??"Untitled App",ve=j.methodology,U=N.steps;if(!Array.isArray(U)||U.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 Y=N.publicPages;if(!Y||Array.isArray(Y)&&Y.length===0){let y=N.pages,b=U.some(E=>typeof E.name=="string"&&E.name.toLowerCase().includes("landing")||typeof E.title=="string"&&E.title.toLowerCase().includes("landing")),M=Array.isArray(y)&&y.some(E=>E.path==="/"||E.route==="/");b||M?Y=["/","/pricing"]:Y=["/"]}let W=N.primaryAction;if(!W){let y=N.features;if(Array.isArray(y)&&y.length>0){let M=y.find(ae=>typeof ae.priority=="string"&&ae.priority.toLowerCase()==="must-have")??y[0];W={entity:M.name??M.title??"item",action:"create",fromPage:"/dashboard"}}}let J=N.nonNegotiables;(!J||Array.isArray(J)&&J.length===0)&&(J=["Landing page renders correctly at / with content (not a redirect)","Core user action works end-to-end (create entity, see it in list)"]);let _=Is(),ie=be(Le(),".mistflow","plans");_t(ie,{recursive:!0});try{let b=Date.now();for(let M of[ie,be(Le(),".mistflow","mockup-state")])if(ht(M))for(let E of _n(M))try{let ae=be(M,E),re=Dn(ae).mtimeMs;b-re>6048e5&&Mn(ae)}catch{}}catch{}let ee;if(m){let y=Xe(m);y?ee=y.id:console.error(`Landing design '${m}' not found \u2014 ignoring. Use mist_project action='landing-designs' to browse available landing designs.`)}let ce=p||void 0,se=!!ee,T=U.some(y=>{let b=`${y.name??y.title} ${y.description??""}`.toLowerCase();return b.includes("landing")||b.includes("hero")||b.includes("marketing")||b.includes("homepage")}),$=!se&&T?ks(o,{maxResults:2}):[];$.length>0&&(ee=$[0].id,console.error(`Auto-assigned landing layout preset (default): ${$[0].title} (${ee})`));let F={name:N.name,summary:N.summary,dataModel:N.dataModel,pages:N.pages,features:N.features,steps:U.map(y=>({...y,name:y.name??y.title})),design:N.design,landingDesign:ee,appStyle:ce,dbProvider:N.dbProvider??"neon",authModel:N.authModel,audienceType:N.audienceType??"b2c",roles:N.roles,defaultRole:N.defaultRole,publicPages:Y,navStyle:N.navStyle,multiTenant:N.multiTenant,primaryAction:W,nonNegotiables:J,requestedSubdomain:I,...u&&u.toLowerCase()!=="english"?{language:u}:{}};Dt(be(ie,`${_}.json`),JSON.stringify({plan:F,methodology:ve}));let w=U.map(y=>`${y.number}. ${y.name??y.title}`),D="",K=[],ue;!se&&$.length>0&&(K=$.map(b=>({id:b.id,slug:b.slug,title:b.title,description:b.description,url:`${ut()}/designs?tab=landing-designs`})),ue={question:"What landing page style fits this app?",header:"Landing Design",options:[...$.map((b,M)=>({label:M===0?`${b.title} (Recommended)`:b.title,description:b.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 ${ut()}/designs?tab=landing-designs and pass the ID back.`}],multiSelect:!1},D=` 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: ${$.map(b=>b.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='${$[0].id}' explicitly.`);let ke="",P=[],L=void 0,Q=(N.audienceType??"b2c")==="b2c",oe={question:"Include a lifestyle photo in your landing page hero? Photos add warmth and human context; pure CSS stays cleaner.",header:"Hero",options:[{label:Q?"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:Q?"No, CSS only":"No, CSS only (Recommended)",description:"Animated gradients + glassmorphism, no photo \u2014 cleaner and more technical (like Stripe, Linear, Vercel)."}],multiSelect:!1},me=" 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.",C="",G=[];for(let y of U){let b=y.name??y.title,M=y.integrationId;if(M){let E=et(M);if(E){let ae=tt(E.id);G.push({step:b,presetId:E.id,presetName:E.name,envVars:ae?.envVars??[]})}}}if(G.length>0){let y=G.flatMap(E=>E.envVars),b=[...new Set(y.map(E=>E.key))];C=` This plan uses integrations (${G.map(E=>E.presetName).join(", ")}). Detailed blueprints will be auto-injected during each integration step.${b.length>0?` The user will need these API keys: ${b.join(", ")}.`:""}`}return d(JSON.stringify({planId:_,name:N.name,summary:N.summary,stepCount:U.length,steps:w,design:N.design,...ee?{landingDesign:ee}:{},...ce?{appStyle:ce}:{},...P.length>0?{recommendedAppStyles:P}:{},...L?{appStyleQuestion:L}:{},...K.length>0?{recommendedLandingDesigns:K}:{},...ue?{landingDesignQuestion:ue}:{},heroPhotoQuestion:oe,...G.length>0?{integrations:G.map(y=>({step:y.step,preset:y.presetId,name:y.presetName,envVars:y.envVars}))}:{},message:`Plan generated for "${z}" (${U.length} steps).${ee?` Landing layout "${ee}" set as default.`:""}${ce?` App style "${ce}" will be applied across all pages.`:""}${C}${ke}${D}${me}`,timingContext:`Planning took ~90 seconds. Building will take roughly ${Math.max(15,U.length*3)}\u2013${U.length*5} minutes total across ${U.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='${_}'. If the user says skip or "just build it", call mist_build with action='init', name='${z}', and planId='${_}' immediately.`,...x?{warning:x}:{}}))}var Ds={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:
|
|
1892
|
+
`:"",`I have ${E.length} quick question${E.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: "${_.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: "${X}".`,'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(_.status==="design_clarify"){let y=_.directions??[],b=_.plan.name??"your app",$;try{let he=y.map(X=>({id:X.id,name:X.name,summary:X.summary,hero_headline:X.hero_headline,cta_text:X.cta_text,body_sample:X.body_sample,fonts:X.fonts,colors:X.colors,hero_treatment:X.hero_treatment,shape_lang:X.shape_lang,texture:X.texture,decoration_hint:X.decoration_hint})),dt=Is(b,he),ze=be(e,".mistflow");_t(ze,{recursive:!0});let ge=be(ze,"design-directions.html");Dt(ge,dt,"utf-8"),$=ge}catch(he){console.error(`[mist_plan] design-directions preview render failed: ${he instanceof Error?he.message:String(he)}`)}let E=y.map(he=>({label:he.name,description:`${he.summary} \u2014 ${he.fonts?.display??""} + ${he.fonts?.body??""}`}));E.push({label:"Describe your own direction",description:"Skip the proposed options and give me a short description of how the app should feel."});let ae={question:`${b} is planned. Now pick the creative direction \u2014 this shapes fonts, colors, and overall feel.`,header:"Design",options:E,multiSelect:!1},re=$?`A visual preview of all ${y.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.",pe=$?`open "${$}"`:"";return d(JSON.stringify({status:"design_clarify",designConversationId:_.design_conversation_id,directions:y,previewPath:$,askUserQuestion:ae,instruction:[`The plan for "${b}" is ready. I've proposed ${y.length} creative directions \u2014 each commits to a specific aesthetic (fonts, colors, voice).`,"",re,pe?`Run this command for the user: ${pe}`:"","","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: "${_.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 N=_.plan,z=N.name??"Untitled App",ve=_.methodology,U=N.steps;if(!Array.isArray(U)||U.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 Y=N.publicPages;if(!Y||Array.isArray(Y)&&Y.length===0){let y=N.pages,b=U.some(E=>typeof E.name=="string"&&E.name.toLowerCase().includes("landing")||typeof E.title=="string"&&E.title.toLowerCase().includes("landing")),$=Array.isArray(y)&&y.some(E=>E.path==="/"||E.route==="/");b||$?Y=["/","/pricing"]:Y=["/"]}let W=N.primaryAction;if(!W){let y=N.features;if(Array.isArray(y)&&y.length>0){let $=y.find(ae=>typeof ae.priority=="string"&&ae.priority.toLowerCase()==="must-have")??y[0];W={entity:$.name??$.title??"item",action:"create",fromPage:"/dashboard"}}}let J=N.nonNegotiables;(!J||Array.isArray(J)&&J.length===0)&&(J=["Landing page renders correctly at / with content (not a redirect)","Core user action works end-to-end (create entity, see it in list)"]);let D=Rs(),ie=be(Le(),".mistflow","plans");_t(ie,{recursive:!0});try{let b=Date.now();for(let $ of[ie,be(Le(),".mistflow","mockup-state")])if(ht($))for(let E of Dn($))try{let ae=be($,E),re=Mn(ae).mtimeMs;b-re>6048e5&&$n(ae)}catch{}}catch{}let ee;if(m){let y=Xe(m);y?ee=y.id:console.error(`Landing design '${m}' not found \u2014 ignoring. Use mist_project action='landing-designs' to browse available landing designs.`)}let ce=p||void 0,se=!!ee,T=U.some(y=>{let b=`${y.name??y.title} ${y.description??""}`.toLowerCase();return b.includes("landing")||b.includes("hero")||b.includes("marketing")||b.includes("homepage")}),j=!se&&T?xs(o,{maxResults:2}):[];j.length>0&&(ee=j[0].id,console.error(`Auto-assigned landing layout preset (default): ${j[0].title} (${ee})`));let F={name:N.name,summary:N.summary,dataModel:N.dataModel,pages:N.pages,features:N.features,steps:U.map(y=>({...y,name:y.name??y.title})),design:N.design,landingDesign:ee,appStyle:ce,dbProvider:N.dbProvider??"neon",authModel:N.authModel,audienceType:N.audienceType??"b2c",roles:N.roles,defaultRole:N.defaultRole,publicPages:Y,navStyle:N.navStyle,multiTenant:N.multiTenant,primaryAction:W,nonNegotiables:J,requestedSubdomain:I,...u&&u.toLowerCase()!=="english"?{language:u}:{}};Dt(be(ie,`${D}.json`),JSON.stringify({plan:F,methodology:ve}));let w=U.map(y=>`${y.number}. ${y.name??y.title}`),M="",K=[],ue;!se&&j.length>0&&(K=j.map(b=>({id:b.id,slug:b.slug,title:b.title,description:b.description,url:`${ut()}/designs?tab=landing-designs`})),ue={question:"What landing page style fits this app?",header:"Landing Design",options:[...j.map((b,$)=>({label:$===0?`${b.title} (Recommended)`:b.title,description:b.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 ${ut()}/designs?tab=landing-designs and pass the ID back.`}],multiSelect:!1},M=` 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: ${j.map(b=>b.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='${j[0].id}' explicitly.`);let ke="",P=[],L=void 0,Q=(N.audienceType??"b2c")==="b2c",oe={question:"Include a lifestyle photo in your landing page hero? Photos add warmth and human context; pure CSS stays cleaner.",header:"Hero",options:[{label:Q?"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:Q?"No, CSS only":"No, CSS only (Recommended)",description:"Animated gradients + glassmorphism, no photo \u2014 cleaner and more technical (like Stripe, Linear, Vercel)."}],multiSelect:!1},me=" 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.",C="",G=[];for(let y of U){let b=y.name??y.title,$=y.integrationId;if($){let E=et($);if(E){let ae=tt(E.id);G.push({step:b,presetId:E.id,presetName:E.name,envVars:ae?.envVars??[]})}}}if(G.length>0){let y=G.flatMap(E=>E.envVars),b=[...new Set(y.map(E=>E.key))];C=` This plan uses integrations (${G.map(E=>E.presetName).join(", ")}). Detailed blueprints will be auto-injected during each integration step.${b.length>0?` The user will need these API keys: ${b.join(", ")}.`:""}`}return d(JSON.stringify({planId:D,name:N.name,summary:N.summary,stepCount:U.length,steps:w,design:N.design,...ee?{landingDesign:ee}:{},...ce?{appStyle:ce}:{},...P.length>0?{recommendedAppStyles:P}:{},...L?{appStyleQuestion:L}:{},...K.length>0?{recommendedLandingDesigns:K}:{},...ue?{landingDesignQuestion:ue}:{},heroPhotoQuestion:oe,...G.length>0?{integrations:G.map(y=>({step:y.step,preset:y.presetId,name:y.presetName,envVars:y.envVars}))}:{},message:`Plan generated for "${z}" (${U.length} steps).${ee?` Landing layout "${ee}" set as default.`:""}${ce?` App style "${ce}" will be applied across all pages.`:""}${C}${ke}${M}${me}`,timingContext:`Planning took ~90 seconds. Building will take roughly ${Math.max(15,U.length*3)}\u2013${U.length*5} minutes total across ${U.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='${D}'. If the user says skip or "just build it", call mist_build with action='init', name='${z}', and planId='${D}' immediately.`,...x?{warning:x}:{}}))}var Ms={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:Wn,handler:Kn};import{z as le}from"zod";import{existsSync as qt,readFileSync as ha}from"fs";import{join as zt,resolve as ga}from"path";import{homedir as fa}from"os";import{execFileSync as Po}from"child_process";import{z as Mt}from"zod";import{existsSync as Ie,mkdirSync as jt,writeFileSync as Oe,readFileSync as Lt,readdirSync as Qn,copyFileSync as Xn}from"fs";import{join as Z,resolve as Ot,dirname as ft,isAbsolute as yo}from"path";import{spawn as Zn}from"child_process";import{randomBytes as ei}from"crypto";import{simpleGit as Ls}from"simple-git";function gt(s,o,e,t=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:e()}}).catch(()=>{}))},t);return{stop:()=>{a||(a=!0,clearInterval(i))}}}function ti(s){let o=ft(Ot(s)),e=10,t=0;for(;t<e&&o!==ft(o);){if(Ie(Z(o,"pnpm-workspace.yaml"))||Ie(Z(o,"lerna.json")))return o;let n=Z(o,"package.json");if(Ie(n))try{if(JSON.parse(Lt(n,"utf-8")).workspaces)return o}catch{}o=ft(o),t++}return null}function yt(s,o,e,t,n,a){return new Promise(r=>{let i=Zn(s,o,{cwd:e,stdio:["pipe","pipe","pipe"],timeout:t,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
|
|
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")&&(t.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,"_"),t.typography[r]={};continue}let g=c.match(/^ {4}([a-zA-Z0-9_-]+):\s*(.+)$/);if(g&&r){t.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"?t.colors[p]=g:a==="rounded"?t.rounded[p]=g:a==="spacing"&&(t.spacing[p]=g)}}return t}function
|
|
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 Uc=Mt.object({name:Mt.string().min(1),plan:Mt.any(),path:Mt.string().optional()});function B(s,o,e){let t=Z(s,o);jt(ft(t),{recursive:!0}),Oe(t,e)}var oi={sharp:"0.125rem",subtle:"0.375rem",rounded:"0.75rem",pill:"9999px"},si=[["--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 ri(s){let o=s.match(/^---\n([\s\S]*?)\n---/);if(!o)return null;let e=o[1],t={theme:"light",colors:{},typography:{},rounded:{},spacing:{}},n=e.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")&&(t.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,"_"),t.typography[r]={};continue}let g=c.match(/^ {4}([a-zA-Z0-9_-]+):\s*(.+)$/);if(g&&r){t.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"?t.colors[p]=g:a==="rounded"?t.rounded[p]=g:a==="spacing"&&(t.spacing[p]=g)}}return t}function ni(s,o){let e=s.colors,n=[["--color-background",e.background],["--color-foreground",e.on_background??e.on_surface],["--color-card",e.surface??e.background],["--color-card-foreground",e.on_surface??e.on_background],["--color-popover",e.surface??e.background],["--color-popover-foreground",e.on_surface??e.on_background],["--color-muted",e.surface_variant??e.outline_variant??e.outline],["--color-muted-foreground",e.on_surface_variant??e.outline],["--color-border",e.outline_variant??e.outline],["--color-input",e.outline_variant??e.outline],["--color-primary",e.primary],["--color-primary-foreground",e.on_primary],["--color-ring",e.primary],["--color-secondary",e.secondary],["--color-secondary-foreground",e.on_secondary],["--color-accent",e.secondary],["--color-accent-foreground",e.on_secondary],["--color-destructive",e.error],["--color-destructive-foreground",e.on_error],["--color-success",e.success],["--color-success-foreground",e.on_success],["--color-warning",e.warning],["--color-warning-foreground",e.on_warning],["--color-info",e.info??e.primary],["--color-info-foreground",e.on_info??e.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,11 +1953,11 @@ ${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
|
|
1956
|
+
`}function ii(s,o,e){let t=s?.borderRadius??"subtle",n=oi[t]??"0.375rem";if(e){let r=ri(e);if(r)return ni(r,n)}return`@import "tailwindcss";
|
|
1957
1957
|
@import "tw-animate-css";
|
|
1958
1958
|
|
|
1959
1959
|
@theme {
|
|
1960
|
-
${[...
|
|
1960
|
+
${[...si.map(([r,i])=>` ${r}: ${i};`)," --radius-sm: 0.25rem;",` --radius-md: ${n};`," --radius-lg: 0.5rem;"," --radius-xl: 0.75rem;"].join(`
|
|
1961
1961
|
`)}
|
|
1962
1962
|
}
|
|
1963
1963
|
|
|
@@ -2007,7 +2007,7 @@ ${[...ti.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
|
|
2010
|
+
`}var $s={"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 js(s){let o=s.replace(/[^A-Za-z0-9_ -]/g,"");return $s[o]?$s[o]:o.replace(/\s+/g,"_")}function ai(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 li=new Set(["ar","he","fa","ur"]);function ci(s,o,e){let t=s.replace(/[\\"`$]/g,""),n=ai(e),r=li.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";
|
|
@@ -2023,7 +2023,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
2023
2023
|
</html>
|
|
2024
2024
|
);
|
|
2025
2025
|
}
|
|
2026
|
-
`;let c
|
|
2026
|
+
`;let c=js(i??l),u=js(l??i);return c===u?`import type { Metadata } from "next";
|
|
2027
2027
|
import { ${c} } from "next/font/google";
|
|
2028
2028
|
import { Toaster } from "sonner";
|
|
2029
2029
|
import "./globals.css";
|
|
@@ -2056,21 +2056,21 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
2056
2056
|
</html>
|
|
2057
2057
|
);
|
|
2058
2058
|
}
|
|
2059
|
-
`}function $t(s,...o){let e=JSON.stringify(s).toLowerCase();return o.some(t=>e.includes(t.toLowerCase()))}var
|
|
2060
|
-
`)}function
|
|
2059
|
+
`}function $t(s,...o){let e=JSON.stringify(s).toLowerCase();return o.some(t=>e.includes(t.toLowerCase()))}var di={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 fo(s){let o=s.toLowerCase().replace(/[^a-z]/g,"");for(let[e,t]of Object.entries(di))if(o.includes(e))return t;return"Circle"}function bt(s){return s.split("-").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ")}function pi(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 e=o.filter(a=>a==="/"),t=o.filter(a=>a!=="/"),n=[];n.push('import { NextRequest, NextResponse } from "next/server";'),n.push(""),n.push("const PUBLIC_PREFIXES = [");for(let a of t)n.push(' "'+a+'",');return n.push("];"),n.push(""),e.length>0&&(n.push('const PUBLIC_EXACT = ["'+e.join('", "')+'"];'),n.push("")),n.push("export function middleware(req: NextRequest) {"),n.push(" const { pathname, search } = req.nextUrl;"),n.push(""),e.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 ui(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"],t=(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??bt(c.replace(/^\//,"")),p=fo(m);return{label:m,href:u,icon:p}});t.some(l=>l.href==="/dashboard")||t.unshift({label:"Dashboard",href:"/dashboard",icon:"Home"});let n=s.authModel==="none",a=[...new Set(t.map(l=>l.icon))];n||a.push("LogOut");let r=bt(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 t)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
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 t)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
|
|
2063
|
-
`)}function
|
|
2062
|
+
`)}}function mi(s){if(!s.roles||s.roles.length===0)return null;let o=s.roles,e=s.defaultRole??o[0],t=[];t.push("export type Role = "+o.map(n=>'"'+n+'"').join(" | ")+";"),t.push(""),t.push("export const ROLES = ["+o.map(n=>'"'+n+'"').join(", ")+"] as const;"),t.push(""),t.push('export const DEFAULT_ROLE: Role = "'+e+'";'),t.push(""),t.push("export const ROLE_LABELS: Record<Role, string> = {");for(let n of o){let a=n.charAt(0).toUpperCase()+n.slice(1);t.push(' "'+n+'": "'+a+'",')}return t.push("};"),t.push(""),t.push("export function getUserRole(user: Record<string, unknown>): Role {"),t.push(" const role = (user.role as string) ?? DEFAULT_ROLE;"),t.push(" if (ROLES.includes(role as Role)) return role as Role;"),t.push(" return DEFAULT_ROLE;"),t.push("}"),t.push(""),t.push("export function hasRole(userRole: string | undefined, required: Role | Role[]): boolean {"),t.push(" if (!userRole) return false;"),t.push(" const allowed = Array.isArray(required) ? required : [required];"),t.push(" return allowed.includes(userRole as Role);"),t.push("}"),t.push(""),t.join(`
|
|
2063
|
+
`)}function hi(s){let o=bt(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
2064
|
`)}let e=s.publicPages?.includes("/"),t=s.design?.landingTone;if(e&&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">'),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
2065
|
`)}if(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 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
|
|
2068
|
-
`)}function
|
|
2069
|
-
`)}function
|
|
2070
|
-
`)}function
|
|
2071
|
-
`)}function
|
|
2072
|
-
`)}function
|
|
2073
|
-
`)}async function
|
|
2067
|
+
`)}function gi(s,o){let e=s.authModel==="none",t=[];e||(t.push('import { Suspense } from "react";'),t.push('import { headers } from "next/headers";'),t.push('import { redirect } from "next/navigation";'),t.push('import { auth } from "@/lib/auth";'),t.push('import { VerifiedBanner } from "@/components/auth/verified-banner";')),s.navStyle==="topbar"?t.push('import TopNav from "@/components/topnav";'):s.navStyle!=="none"&&t.push('import Sidebar from "@/components/sidebar";'),!e&&s.roles&&s.roles.length>0&&t.push('import { getUserRole } from "@/lib/roles";'),t.push(""),t.push("export default async function DashboardLayout({ children }: { children: React.ReactNode }) {"),e?t.push(' const user = { name: "Guest", email: "" };'):(t.push(" const session = await auth.api.getSession({ headers: await headers() });"),t.push(' if (!session) redirect("/login");'),t.push(""),s.roles&&s.roles.length>0?(t.push(" const role = getUserRole(session.user as Record<string, unknown>);"),t.push(" const user = { name: session.user.name, email: session.user.email, role };")):(t.push(" const user = {"),t.push(" name: session.user.name,"),t.push(" email: session.user.email,"),t.push(" role: (session.user as Record<string, unknown>).role as string | undefined,"),t.push(" };"))),t.push("");let n=e?"":"<Suspense fallback={null}><VerifiedBanner /></Suspense>";return s.navStyle==="topbar"?(t.push(" return ("),t.push(' <div className="min-h-screen">'),t.push(" <TopNav user={user} />"),t.push(' <main className="mx-auto max-w-7xl p-6">'+n+"{children}</main>"),t.push(" </div>"),t.push(" );")):s.navStyle==="none"?(t.push(" return ("),t.push(' <div className="min-h-screen">'),t.push(' <main className="mx-auto max-w-5xl p-6">'+n+"{children}</main>"),t.push(" </div>"),t.push(" );")):(t.push(" return ("),t.push(' <div className="flex flex-col md:flex-row min-h-screen">'),t.push(" <Sidebar user={user} />"),t.push(' <main className="flex-1 overflow-x-hidden p-4 md:p-6">'+n+"{children}</main>"),t.push(" </div>"),t.push(" );")),t.push("}"),t.push(""),t.join(`
|
|
2068
|
+
`)}function fi(s){let o=bt(s.name),e=s.dataModel??[],t=[];if(e.length>0){let n=e.map(r=>fo(r.entity??r.name??"item")),a=[...new Set(n)];t.push('import { Card, CardContent } from "@/components/ui/card";'),t.push("import { "+a.join(", ")+' } from "lucide-react";'),t.push("")}if(t.push("export default function DashboardPage() {"),t.push(" return ("),t.push(' <div className="space-y-6">'),t.push(" <div>"),t.push(' <h1 className="text-3xl font-bold">'+o+"</h1>"),s.summary&&t.push(' <p className="mt-1 text-muted-foreground">'+s.summary+"</p>"),t.push(" </div>"),e.length>0){t.push(' <div className="rounded-lg border p-8 text-center">'),t.push(' <h2 className="text-lg font-semibold">Get started</h2>'),t.push(` <p className="mt-1 text-sm text-muted-foreground">Here's what you can do</p>`),t.push(' <div className="mt-6 grid gap-3 sm:grid-cols-2 text-left">');for(let n of e){let a=n.entity??n.name??"Item",r=fo(a),i=bt(a.replace(/_/g,"-"));t.push(' <div className="flex items-center gap-3 rounded-md border p-3">'),t.push(" <"+r+' className="h-5 w-5 text-muted-foreground" />'),t.push(' <span className="text-sm font-medium">Add your first '+i+"</span>"),t.push(" </div>")}t.push(" </div>"),t.push(" </div>")}return t.push(" </div>"),t.push(" );"),t.push("}"),t.push(""),t.join(`
|
|
2069
|
+
`)}function yi(s,o=!1){if(!s.multiTenant)return null;let e=[];return o?(e.push('import { pgTable, text, timestamp, index } from "drizzle-orm/pg-core";'),e.push('import { user } from "./auth";'),e.push(""),e.push('export const organization = pgTable("organization", {'),e.push(' id: text("id").primaryKey(),'),e.push(' name: text("name").notNull(),'),e.push(' slug: text("slug").unique().notNull(),'),e.push(' createdAt: timestamp("created_at").defaultNow().notNull(),'),e.push(' updatedAt: timestamp("updated_at").defaultNow().notNull(),'),e.push("});"),e.push(""),e.push("export const orgMember = pgTable(")):(e.push('import { sqliteTable, text, index } from "drizzle-orm/sqlite-core";'),e.push('import { sql } from "drizzle-orm";'),e.push('import { user } from "./auth";'),e.push(""),e.push('export const organization = sqliteTable("organization", {'),e.push(' id: text("id").primaryKey(),'),e.push(' name: text("name").notNull(),'),e.push(' slug: text("slug").unique().notNull(),'),e.push(' createdAt: text("created_at").default(sql`CURRENT_TIMESTAMP`).notNull(),'),e.push(' updatedAt: text("updated_at").default(sql`CURRENT_TIMESTAMP`).notNull(),'),e.push("});"),e.push(""),e.push("export const orgMember = sqliteTable(")),e.push(' "org_member",'),e.push(" {"),e.push(' id: text("id").primaryKey(),'),e.push(' orgId: text("org_id").notNull().references(() => organization.id),'),e.push(' userId: text("user_id").notNull().references(() => user.id),'),e.push(' role: text("role").notNull(),'),o?e.push(' joinedAt: timestamp("joined_at").defaultNow().notNull(),'):e.push(' joinedAt: text("joined_at").default(sql`CURRENT_TIMESTAMP`).notNull(),'),e.push(" },"),e.push(" (table) => ({"),e.push(' orgIdx: index("org_member_org_idx").on(table.orgId),'),e.push(' userIdx: index("org_member_user_idx").on(table.userId),'),e.push(" }),"),e.push(");"),e.push(""),e.join(`
|
|
2070
|
+
`)}function bi(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
|
+
`)}function wi(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 vi(s,o,e){let t=[],n=s.split("-").map(l=>l.charAt(0).toUpperCase()+l.slice(1)).join(" ");t.push(`# ${n}`),t.push(""),o?.summary&&(t.push(o.summary),t.push(""));let a=o?.features??[];if(a.length>0){t.push("## Features"),t.push("");for(let l of a){let c=l.description?` \u2014 ${l.description}`:"";t.push(`- **${l.name}**${c}`)}t.push("")}t.push("## Tech Stack"),t.push(""),t.push("| Layer | Technology |"),t.push("|-------|------------|"),t.push("| Framework | Next.js 15 (App Router) |"),t.push("| Database | Mistflow Cloud (Postgres) + Drizzle ORM |"),t.push("| Auth | Better Auth (email/password, social login) |"),t.push("| Styling | Tailwind CSS + shadcn/ui |"),t.push("| Deployment | Mistflow Cloud |"),e.hasStripe&&t.push("| Payments | Stripe |"),e.hasResend&&t.push("| Email | Resend + React Email |"),e.hasStorage&&t.push("| File Storage | Mistflow Cloud (managed blob storage) |"),e.hasAdmin&&t.push("| Admin | Better Auth admin plugin |"),e.hasAI&&t.push("| AI | Vercel AI SDK + OpenAI |"),t.push("");let r=o?.pages??[];if(r.length>0){t.push("## Pages"),t.push(""),t.push("| Route | Description |"),t.push("|-------|-------------|");for(let l of r){let c=l.path??l.route??l.name??"",u=l.description??"";t.push(`| \`${c.startsWith("/")?c:"/"+c}\` | ${u} |`)}t.push("")}let i=o?.dataModel??[];if(i.length>0){t.push("## Data Model"),t.push("");for(let l of i){let c=l.entity??l.name??"Unknown";if(t.push(`### ${c}`),t.push(""),l.fields.length>0){if(typeof l.fields[0]=="string")t.push(`Fields: ${l.fields.join(", ")}`);else{t.push("| Field | Type |"),t.push("|-------|------|");for(let u of l.fields)t.push(`| ${u.name} | ${u.type} |`)}t.push("")}}}return t.push("## Getting Started"),t.push(""),t.push("### Prerequisites"),t.push(""),t.push("- Node.js 20+"),t.push("- npm"),t.push(""),t.push("### Install"),t.push(""),t.push("```bash"),t.push("npm install"),t.push("```"),t.push(""),t.push("### Set up environment"),t.push(""),t.push("Copy `.env.example` to `.env.local` and fill in the values:"),t.push(""),t.push("```bash"),t.push("cp .env.example .env.local"),t.push("```"),t.push(""),t.push("| Variable | Description | Required |"),t.push("|----------|-------------|----------|"),e.isNeon?t.push("| `DATABASE_URL` | Postgres connection URL | Yes |"):(t.push("| `TURSO_URL` | Database connection URL | Yes |"),t.push("| `TURSO_AUTH_TOKEN` | Database auth token | Yes |")),t.push("| `AUTH_SECRET` | Auth encryption secret (auto-generated) | Yes |"),e.hasStripe&&(t.push("| `STRIPE_SECRET_KEY` | Stripe secret key | Yes |"),t.push("| `STRIPE_WEBHOOK_SECRET` | Stripe webhook signing secret | Yes |"),t.push("| `NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY` | Stripe publishable key | Yes |")),e.hasResend&&(t.push("| `RESEND_API_KEY` | Resend API key | Yes |"),t.push("| `EMAIL_FROM` | Sender email address | Yes (production) |")),e.hasStorage&&(t.push("| `MISTFLOW_API_KEY` | Mistflow API key for file storage | Yes |"),t.push("| `MISTFLOW_PROJECT_ID` | Mistflow project ID | Yes |")),e.hasAI&&t.push("| `OPENAI_API_KEY` | OpenAI API key | Yes |"),t.push(""),t.push("### Local database"),t.push(""),e.isNeon?(t.push("For local development, start a local Postgres server:"),t.push(""),t.push("```bash"),t.push("# Using Docker:"),t.push("docker run -d --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:17"),t.push("# Or install via Homebrew: brew install postgresql@17 && brew services start postgresql@17"),t.push("```")):(t.push("For local development, start a local Turso server:"),t.push(""),t.push("```bash"),t.push("npx turso dev"),t.push("```")),t.push(""),t.push("Then set up the database:"),t.push(""),t.push("```bash"),t.push("npm run db:push"),t.push("```"),t.push(""),t.push("### Run"),t.push(""),t.push("```bash"),t.push("npm run dev"),t.push("```"),t.push(""),t.push("Open [http://localhost:3000](http://localhost:3000)."),t.push(""),t.push("## Project Structure"),t.push(""),t.push("```"),t.push("app/"),t.push(" (auth)/ Login and registration pages"),t.push(" (dashboard)/ Authenticated app pages"),e.hasAdmin&&t.push(" (admin)/ Admin panel pages"),t.push(" api/ API routes (auth, health, webhooks)"),t.push(" layout.tsx Root layout with fonts and providers"),t.push(" globals.css Design tokens and Tailwind config"),t.push("components/ Reusable UI components"),t.push("db/"),t.push(" schema/ Database table definitions"),t.push(" index.ts Schema exports"),t.push("lib/"),t.push(" auth.ts Better Auth server config"),t.push(" auth-client.ts Better Auth client config"),t.push(` db.ts ${e.isNeon?"Postgres":"SQLite"} database connection`),e.hasStripe&&t.push(" stripe.ts Stripe client"),e.hasResend&&(t.push(" resend.ts Resend client"),t.push(" email.ts Email send helpers")),e.hasStorage&&t.push(" storage.ts File upload/download helpers"),e.hasAI&&t.push(" ai.ts AI client (Vercel AI SDK + OpenAI)"),e.hasResend&&t.push("emails/ React Email templates"),t.push("```"),t.push(""),t.push("## Deploy"),t.push(""),t.push("Deploy to production with Mistflow:"),t.push(""),t.push("```"),t.push("# In your AI editor (Claude Code, Cursor, etc.):"),t.push("mist_deploy action='deploy'"),t.push("```"),t.push(""),t.push("Your app will be live at `https://<app-name>.mistflow.app`."),t.push(""),o?.design&&(t.push("## Design"),t.push(""),o.design.tone&&t.push(`- **Tone**: ${o.design.tone}`),o.design.fonts&&(t.push(`- **Heading font**: ${o.design.fonts.heading}`),t.push(`- **Body font**: ${o.design.fonts.body}`)),o.design.accentColor&&t.push(`- **Accent color**: ${o.design.accentColor}`),o.design.borderRadius&&t.push(`- **Border radius**: ${o.design.borderRadius}`),t.push("")),t.push("---"),t.push(""),t.push("Built with [Mistflow](https://mistflow.ai)"),t.push(""),t.join(`
|
|
2073
|
+
`)}async function Os(s,o){let{name:e,plan:t,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(!yo(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=Ot(n),i=t?.design,l=t?.appStyle,c=t?$t(t,"stripe","payment","billing","subscription","checkout","pricing"):!1,u=!0,m=t?$t(t,"upload","file storage","image upload","profile picture","attachment","gallery","media","blob"):!1,p=t?$t(t,"admin panel","admin dashboard","admin management"):!1,g=t?$t(t,"ai integration","openai","llm","ai chat","chatbot","gpt"):!1,v=t,f=!0;if(Ie(r))return d(`A project already exists at this location (${r}). Choose a different name, or delete the existing folder first.`,!0);jt(r,{recursive:!0});try{let P=Z(ft(r),".mistflow","mockups");if(Ie(P)){let L=Qn(P).filter(H=>H.endsWith(".html"));if(L.length>0){let H=Z(r,".mistflow","mockups");jt(H,{recursive:!0});for(let Q of L)Xn(Z(P,Q),Z(H,Q));console.error(`Copied ${L.length} mockup file(s) into project`)}}}catch(P){console.error("Could not copy mockup files:",P instanceof Error?P.message:P)}let h=null;try{h=await Nt("nextjs")}catch(P){console.error("Could not fetch scaffold from API, using minimal scaffold:",P instanceof Error?P.message:P)}if(h){let P=e.toLowerCase().replace(/[^a-z0-9-]/g,"-");for(let C of h.files){if(C.path==="package.json"||C.path==="middleware.ts"||C.path==="components/sidebar.tsx"||C.path==="components/topnav.tsx"||C.path==="app/(dashboard)/layout.tsx"||C.path==="app/(dashboard)/page.tsx"||C.path==="app/(dashboard)/dashboard/page.tsx"||!c&&(C.path.includes("stripe")||C.path.includes("webhook/stripe"))||!u&&(C.path.includes("resend")||C.path.includes("emails/"))||!p&&(C.path.includes("(admin)")||C.path.includes("admin-sidebar"))||f&&(C.path==="lib/db.ts"||C.path==="lib/auth.ts"||C.path==="drizzle.config.ts"||C.path==="db/schema/auth.ts"))continue;let G=C.content.replace(/\{\{APP_NAME\}\}/g,e).replace(/\{\{WORKER_NAME\}\}/g,P);if(f&&C.path==="next.config.ts"&&(G=G.replace(/serverExternalPackages:\s*\[[^\]]*\],?/g,'serverExternalPackages: ["@electric-sql/pglite"],')),C.path==="next.config.ts"){let y=ti(r);y&&(console.error(`[init] Project is inside monorepo at ${y} \u2014 adding outputFileTracingRoot`),G.includes("outputFileTracingRoot")||(G=G.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
|
|
|
@@ -2080,14 +2080,14 @@ const __dirname = dirname(fileURLToPath(import.meta.url));`),G=G.replace("images
|
|
|
2080
2080
|
`)),B(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
|
`)),B(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
|
`)),B(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 B(r,"package.json",JSON.stringify({name:e,version:"0.1.0",private:!0},null,2));let k=t?.designMd;B(r,"app/globals.css",
|
|
2083
|
+
`)))}else B(r,"package.json",JSON.stringify({name:e,version:"0.1.0",private:!0},null,2));let k=t?.designMd;B(r,"app/globals.css",ii(i,l,k)),B(r,"app/layout.tsx",ci(e,i,v?.language)),B(r,"README.md",vi(e,t,{hasStripe:c,hasResend:u,hasStorage:m,hasAdmin:p,hasAI:g,isNeon:f}));let S=[],R=t?.publicPages;if(Array.isArray(R))S=R;else if(typeof R=="string"){try{S=JSON.parse(R)}catch{S=[]}Array.isArray(S)||(S=[])}if(!S.includes("/")){let P=t?.steps?.some(H=>{let Q=((H.name??"")+" "+(H.description??"")).toLowerCase();return Q.includes("landing")||Q.includes("marketing")||Q.includes("homepage")}),L=t?.pages?.some(H=>H.path==="/");(P||L)&&(S=["/",...S])}let x={name:e,summary:t?.summary,authModel:t?.authModel,roles:t?.roles,defaultRole:t?.defaultRole,publicPages:S,navStyle:t?.navStyle,multiTenant:t?.multiTenant,pages:t?.pages,dataModel:t?.dataModel,design:t?.design},I=pi(x);I&&B(r,"middleware.ts",I);let q=ui(x);q&&B(r,q.path,q.content);let A=mi(x);if(A&&B(r,"lib/roles.ts",A),B(r,"app/page.tsx",hi(x)),B(r,"app/(dashboard)/layout.tsx",gi(x,p)),B(r,"app/(dashboard)/dashboard/page.tsx",fi(x)),x.multiTenant){let P=yi(x,f);P&&B(r,"db/schema/organization.ts",P);let L=bi(x);L&&B(r,"lib/org.ts",L);let H=wi(x);H&&B(r,"components/org-switcher.tsx",H)}B(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&&B(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&&(B(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
|
`)),B(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&&(B(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
|
`)),B(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&&(B(r,"lib/ai.ts",['import { createOpenAI } from "@ai-sdk/openai";',"","export const openai = createOpenAI({"," apiKey: process.env.OPENAI_API_KEY,","});",""].join(`
|
|
2089
2089
|
`)),B(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
|
|
2090
|
+
`)));let _={name:e,methodologyVersion:h?.version??"1.0",createdAt:new Date().toISOString(),...a?{planId:a}:{},plan:Array.isArray(t?.steps)?{...t,steps:t.steps.map(P=>({number:P.number,name:P.name??P.title,description:P.description,entities:P.entities,pages:P.pages,features:P.features,status:"pending"}))}:t,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:t?.authModel??"email",roles:t?.roles??null,navStyle:t?.navStyle??"sidebar",multiTenant:t?.multiTenant??!1,hasAdmin:p,hasResend:u,hasStorage:m,hasAI:g,deploy:null};B(r,"mistflow.json",JSON.stringify(_,null,2));let N=ei(32).toString("hex"),z=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=${N}
|
|
2112
2112
|
${z}${ve}${U}${Y}`),B(r,".env.example",`${J}
|
|
2113
2113
|
AUTH_SECRET=your-secret-here
|
|
2114
|
-
${z}${ve}${U}${Y}`);let
|
|
2115
|
-
${me}=${C}`}Oe(Q,oe)}try{let{getBaseUrl:Q,getAuthHeaders:oe}=await import("./api-client-
|
|
2114
|
+
${z}${ve}${U}${Y}`);let D=[],ie=(P,L)=>{D.push({phase:P,message:L})},ee=(P,L)=>{let H=D.find(Q=>Q.phase===P&&!Q.durationMs);H&&(H.durationMs=L)};if(o){let P=gt(o.server,o.progressToken,()=>D[D.length-1]?.message??"Setting up project...");o.cleanup=()=>P.stop()}let ce=v?.requestedSubdomain||void 0,se,T;ie("register","Registering project on Mistflow...");let j=Date.now();try{let P=await Ho(e,void 0,"neon",ce);se=P.id;let L=Z(r,"mistflow.json"),H=JSON.parse(Lt(L,"utf-8"));if(H.projectId=se,Oe(L,JSON.stringify(H,null,2)),io(r,ao(se,e)),P.managed_env&&Object.keys(P.managed_env).length>0){let Q=Z(r,".env.local"),oe=Ie(Q)?Lt(Q,"utf-8"):"";for(let[me,C]of Object.entries(P.managed_env)){let G=new RegExp(`^${me}=.*$`,"m");G.test(oe)?oe=oe.replace(G,`${me}=${C}`):oe+=`
|
|
2115
|
+
${me}=${C}`}Oe(Q,oe)}try{let{getBaseUrl:Q,getAuthHeaders:oe}=await import("./api-client-RCNDMCPS.js"),me=oe(),C=t?.features,G=t?.steps,y={};Array.isArray(C)&&C.length>0&&(y.features=C.map(b=>b.name)),t&&(y.plan=t),Array.isArray(G)&&G.length>0&&(y.provenance=G.map(b=>({feature:b.name??b.title??`Step ${b.number??"?"}`,user_intent:(b.description??"").slice(0,500),decisions:"Seeded from plan at init",tradeoffs:"",files_affected:[]}))),Object.keys(y).length>0&&await fetch(`${Q()}/api/projects/${encodeURIComponent(se)}/state`,{method:"PUT",headers:{...me,"Content-Type":"application/json"},body:JSON.stringify(y)})}catch{}D[D.length-1].message=`Registered as ${se.slice(0,8)}`}catch(P){let L=P instanceof Error?P.message:String(P);console.error("Could not register project on backend:",L),T=`Project created locally but NOT registered on Mistflow servers (${L}). Deploy will auto-register it.`,D[D.length-1].message="Registration skipped (offline \u2014 deploy will retry)"}ee("register",Date.now()-j),ie("git","Initializing git repository...");let F=Date.now();try{let P=Ls(r);await P.init(),await P.add("."),await P.commit("Initial Mistflow project setup"),D[D.length-1].message="Git repository initialized"}catch{console.error("Git initialization failed, continuing without git."),D[D.length-1].message="Git init skipped"}ee("git",Date.now()-F);let w=D.reduce((P,L)=>P+(L.durationMs??0),0),M={projectPath:r,projectId:se,status:"awaiting_install"},K=D.map(P=>{let L=P.durationMs?` (${(P.durationMs/1e3).toFixed(1)}s)`:"";return`${P.message}${L}`});M.progress=K,M.totalSetupTime=`${(w/1e3).toFixed(1)}s`;let ue=[];se||ue.push("Project was not registered with Mistflow (not signed in). Run mist_setup to sign in BEFORE deploying \u2014 deploy will fail without it."),T&&(M.registrationWarning=T),ue.length>0&&(M.warnings=ue);let ke=`NEXT: Call mist_build with action='install' and projectPath='${r}' immediately. Do NOT ask the user for permission \u2014 install is a required follow-up to init, not a decision point. This runs npm install (~1-2 min) as a separate tool call so it never blocks the init response. After install completes, call mist_build with action='implement' to build the first plan step \u2014 also without asking.`;return M.nextAction=se?ke:`${ke} 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(M))}async function Us(s,o){let{projectPath:e}=s;if(!e)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(!yo(e))return d(`mist_build install 'projectPath' must be an absolute path \u2014 received '${e}'.`,!0);let t=Ot(e);if(!Ie(Z(t,"package.json")))return d(`No package.json found at ${t}. Run mist_build init first to scaffold the project.`,!0);if(Ie(Z(t,"node_modules")))return d(JSON.stringify({status:"already_installed",projectPath:t,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=gt(o.server,o.progressToken,()=>n);o.cleanup=()=>u.stop()}let a={NPM_CONFIG_LEGACY_PEER_DEPS:"true"},r=Date.now(),i=0,l=await yt("npm",["install"],t,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 yt("npm",["install"],t,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 ${t}: ${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:t,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 Fs(s){let{name:o,plan:e,projectId:t,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(!yo(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=Ot(s.path);if(Ie(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:v}=await import("os"),f=u(Z(v(),"mistflow-fork-")),h=Z(f,"project");jt(h,{recursive:!0});let k=[],S=(x,I)=>k.push({phase:x,message:I}),R=(x,I)=>{let q=k.find(A=>A.phase===x);q&&(q.durationMs=I)};try{S("download","Downloading source code from template...");let x=Date.now(),I=Z(f,"source.tar.gz");try{await us(n,a,I)}catch(w){p(f,{recursive:!0,force:!0});let M=w instanceof Error?w.message:"Source download failed";return d(`Source code download failed: ${M}. You can still build from the plan \u2014 run mist_build init without the source (omit planId and pass the plan directly).`,!0)}R("download",Date.now()-x),k[k.length-1].message="Source code downloaded",S("extract","Extracting source code...");let q=Date.now(),A=await yt("tar",["-xzf",I,"-C",h,"--exclude","node_modules","--exclude",".git"],h,6e4);if(!A.success)return p(f,{recursive:!0,force:!0}),d(`Failed to extract source archive: ${A.error}`,!0);if(R("extract",Date.now()-q),!Ie(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 _=[".mistflow",".env.local",".env.example","local.db","local.pg"];for(let w of _){let M=Z(h,w);Ie(M)&&p(M,{recursive:!0,force:!0})}let N={name:o,projectId:t,template:"nextjs",createdAt:new Date().toISOString(),planId:l??void 0,plan:e,dbProvider:i};Oe(Z(h,"mistflow.json"),JSON.stringify(N,null,2));let z=r.map(w=>{let M=w.description?`# ${w.description}`:`# ${w.key}`,K=w.setup_url?` (${w.setup_url})`:"";return`${M}${K}
|
|
2116
2116
|
${w.key}=`});Oe(Z(h,".env.local"),z.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
|
-
`),S("setup","Setting up project directory...");let U=Date.now();try{m(h,c)}catch(w){if(w.code==="EXDEV")g(h,c,{recursive:!0}),p(h,{recursive:!0,force:!0});else throw w}R("setup",Date.now()-U),S("install","Installing packages...");let Y=Date.now(),W=0,J=await yt("npm",["install"],c,12e4,w=>{let
|
|
2130
|
+
`),S("setup","Setting up project directory...");let U=Date.now();try{m(h,c)}catch(w){if(w.code==="EXDEV")g(h,c,{recursive:!0}),p(h,{recursive:!0,force:!0});else throw w}R("setup",Date.now()-U),S("install","Installing packages...");let Y=Date.now(),W=0,J=await yt("npm",["install"],c,12e4,w=>{let M=w.match(/added (\d+) packages/);M&&(W=parseInt(M[1],10))});if(J.success||(console.error("[initFromSource] npm install failed, retrying..."),J=await yt("npm",["install"],c,12e4,w=>{let M=w.match(/added (\d+) packages/);M&&(W=parseInt(M[1],10))})),!J.success)return d(`Source code was restored at ${c} but package installation failed: ${J.error}. Run "npm install" manually.`,!0);R("install",Date.now()-Y),k[k.length-1].message=`Installed ${W||"all"} packages`,S("git","Initializing git repository...");let D=Date.now();try{let w=Ls(c);await w.init(),await w.add("."),await w.commit("Forked from Mistflow template"),k[k.length-1].message="Git repository initialized"}catch{console.error("Git initialization failed, continuing without git."),k[k.length-1].message="Git init skipped"}R("git",Date.now()-D);try{let{markLocalSetupDone:w}=await import("./api-client-RCNDMCPS.js");await w(t)}catch{console.error("[initFromSource] Could not mark local_setup_done on backend, continuing.")}let ie=JSON.parse(Lt(Z(c,"mistflow.json"),"utf-8"));ie.projectId=t,Oe(Z(c,"mistflow.json"),JSON.stringify(ie,null,2)),io(c,ao(t,o));let ee=e.steps,ce=ee?.filter(w=>w.status==="completed").length??0,se=ee?.filter(w=>w.status==="pending").length??0,T=ee?.length??0,j=r.length>0?`
|
|
2131
2131
|
|
|
2132
2132
|
Environment variables needed:
|
|
2133
2133
|
`+r.map(w=>` \u2022 ${w.key}${w.description?` \u2014 ${w.description}`:""}`).join(`
|
|
2134
|
-
`):"",F=se>0?`Source code restored with ${ce}/${T} steps complete. ${se} steps need implementation \u2014 call mist_build with action='implement' to apply your changes.`:`Source code fully restored (${T} steps complete). Configure your .env.local, then deploy with mist_deploy.`;return d(JSON.stringify({status:"success",projectPath:c,projectId:t,planStepsCompleted:ce,planStepsTotal:T,pendingSteps:se,progress:k,nextAction:F
|
|
2134
|
+
`):"",F=se>0?`Source code restored with ${ce}/${T} steps complete. ${se} steps need implementation \u2014 call mist_build with action='implement' to apply your changes.`:`Source code fully restored (${T} steps complete). Configure your .env.local, then deploy with mist_deploy.`;return d(JSON.stringify({status:"success",projectPath:c,projectId:t,planStepsCompleted:ce,planStepsTotal:T,pendingSteps:se,progress:k,nextAction:F+j}))}finally{try{p(f,{recursive:!0,force:!0})}catch{}}}import{z as ko}from"zod";import{existsSync as wt,readFileSync as So,writeFileSync as xo,mkdirSync as Wi}from"fs";import{join as nt,resolve as Vi,dirname as Yi}from"path";import{createConnection as Ji}from"net";var Bs=`# 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
|
|
|
@@ -2298,7 +2298,7 @@ All colors from project CSS custom properties. Key guidance for consumer-warm:
|
|
|
2298
2298
|
- Small touch targets. Phone-first means \`h-12\` minimum.
|
|
2299
2299
|
- Empty states that just say "No data." Be encouraging.
|
|
2300
2300
|
- Dark theme as default. Consumer warm apps default to light.
|
|
2301
|
-
`;var
|
|
2301
|
+
`;var qs=`# Consumer Bold Archetype
|
|
2302
2302
|
|
|
2303
2303
|
Component-level design guidance for energetic, achievement-driven consumer apps. Fitness, workouts, sports, gaming, social platforms, competitive tracking.
|
|
2304
2304
|
|
|
@@ -2469,7 +2469,7 @@ Social/competitive apps need an activity feed:
|
|
|
2469
2469
|
- Card-only layouts with no hierarchy. Use hero cards + supporting cards.
|
|
2470
2470
|
- Missing achievement/progress systems. The gamification IS the product.
|
|
2471
2471
|
- Light-touch buttons. CTAs should be unmissable.
|
|
2472
|
-
`;var
|
|
2472
|
+
`;var zs=`# Professional Clean Archetype
|
|
2473
2473
|
|
|
2474
2474
|
Component-level design guidance for service and appointment-based apps. Booking systems, clinics, salons, real estate, consulting, restaurants, event management.
|
|
2475
2475
|
|
|
@@ -2681,7 +2681,7 @@ h-10 w-10 rounded-full bg-[deterministic-color] flex items-center justify-center
|
|
|
2681
2681
|
- Missing status workflows. Every booking/appointment needs a clear state machine.
|
|
2682
2682
|
- Dark theme as default. Clients associate light themes with professionalism.
|
|
2683
2683
|
- Emoji in the UI. Professional context.
|
|
2684
|
-
`;var
|
|
2684
|
+
`;var Hs=`# Education Structured Archetype
|
|
2685
2685
|
|
|
2686
2686
|
Component-level design guidance for learning, education, and knowledge apps. Course platforms, quiz apps, flashcards, LMS, student portals, tutorial sites, documentation tools.
|
|
2687
2687
|
|
|
@@ -2881,7 +2881,7 @@ border-2 border-destructive bg-destructive/5 rounded-xl p-4
|
|
|
2881
2881
|
- Hero metrics. "2,847 XP" is gaming, not learning. Use "4 of 12 lessons" instead.
|
|
2882
2882
|
- Long lesson pages with no progress indicator. Users need to know where they are.
|
|
2883
2883
|
- Multiple competing elements per view. One thing at a time. One question at a time.
|
|
2884
|
-
`;var
|
|
2884
|
+
`;var Gs=`# Marketplace Browse Archetype
|
|
2885
2885
|
|
|
2886
2886
|
Component-level design guidance for browsing, listing, and shopping apps. Marketplaces, directories, shops, classifieds, rental platforms, food delivery, product catalogs.
|
|
2887
2887
|
|
|
@@ -3105,7 +3105,7 @@ border-b border-border/30 py-4
|
|
|
3105
3105
|
- Small product images. The image is the primary decision-making element.
|
|
3106
3106
|
- No empty state for zero search results. "No results for 'xyz'. Try broader terms."
|
|
3107
3107
|
- Desktop-only filter sidebar without mobile equivalent. Use a slide-out sheet on mobile.
|
|
3108
|
-
`;var
|
|
3108
|
+
`;var Ws=`# SaaS Analytical Archetype
|
|
3109
3109
|
|
|
3110
3110
|
Component-level design guidance for B2B SaaS tools, CRMs, analytics dashboards, admin panels, ops tooling, and team productivity apps. This is the biggest category \u2014 most apps that don't fit consumer, marketplace, or booking archetypes land here.
|
|
3111
3111
|
|
|
@@ -3286,7 +3286,7 @@ The most recognizable B2B SaaS landing pattern.
|
|
|
3286
3286
|
- **Inter as the only font.** Pair it with a distinctive heading font or swap it entirely.
|
|
3287
3287
|
- **Centered text + centered image below.** The most overused AI hero. Use split or offset layouts.
|
|
3288
3288
|
- **Animation on every element.** Efficient motion only: hero entrance, card reveals on scroll, number counters. Nothing else.
|
|
3289
|
-
`;var
|
|
3289
|
+
`;var Vs=`# Content Editorial Archetype
|
|
3290
3290
|
|
|
3291
3291
|
Component-level design guidance for blogs, newsletters, magazines, publications, documentation sites, knowledge bases, and wiki-style content tools. Substack, The Verge, Medium, Linear's changelog, Stripe's docs are the reference bar.
|
|
3292
3292
|
|
|
@@ -3493,7 +3493,7 @@ Below the hero: 3 featured pieces laid out as a horizontal strip with **oversize
|
|
|
3493
3493
|
- **Dark mode as default for a reading tool.** Offer it as a toggle, not the default.
|
|
3494
3494
|
- **Flashy motion while reading.** Scroll hijacking, parallax on body text, animated backgrounds behind paragraphs \u2014 all break reading flow.
|
|
3495
3495
|
- **More than 2 fonts.** Heading + body is enough. Adding a third font for captions or metadata dilutes the identity.
|
|
3496
|
-
`;var
|
|
3496
|
+
`;var Ys=`# Devtool Technical Archetype
|
|
3497
3497
|
|
|
3498
3498
|
Component-level design guidance for developer tools, APIs, CLIs, SDKs, infrastructure platforms, monitoring/observability, AI/ML platforms, deployment targets, and CI/CD tooling. Vercel, Linear, Supabase, Sentry, Warp, Raycast, Cursor, Neon, Anthropic Console are the reference bar.
|
|
3499
3499
|
|
|
@@ -3682,7 +3682,7 @@ Numbers styled as terminal output: \`> 47,293 deploys this week\`, \`> 99.98% up
|
|
|
3682
3682
|
- **Marketing testimonials.** Replace with GitHub star count, StackOverflow mentions, a few short founder-quoted specifics ("Cut our deploy time from 12min to 18sec" from a named engineer at a known company).
|
|
3683
3683
|
- **Feature cards with rocket / lightning / puzzle icons.** Use technical icons (terminal, code, database, network) or skip icons entirely.
|
|
3684
3684
|
- **Motion on code blocks** while the user is trying to read them. Type out ONCE on load, then leave them alone.
|
|
3685
|
-
`;var
|
|
3685
|
+
`;var Js=`# Creative Showcase Archetype
|
|
3686
3686
|
|
|
3687
3687
|
Component-level design guidance for portfolios, design agencies, creative studios, photographers, artists, architects, filmmakers, and any brand whose primary selling point is "look at the work we've made." Apple, Dribbble, Behance, Pentagram, IDEO are the reference bar.
|
|
3688
3688
|
|
|
@@ -3899,7 +3899,7 @@ Premium agency touch: on first load, a full-screen loading component shows the s
|
|
|
3899
3899
|
- **Scroll hijacking through the whole site.** Use sparingly \u2014 one or two scroll-pinned sections maximum.
|
|
3900
3900
|
- **Mystery-meat navigation.** Clever is bad here. "Work / About / Contact" is fine. Don't make visitors guess.
|
|
3901
3901
|
- **No contact info.** The primary purpose of this site is to generate inquiries. Make it stupid-easy to contact you.
|
|
3902
|
-
`;var
|
|
3902
|
+
`;var Ks=`# Finance Clarity Archetype
|
|
3903
3903
|
|
|
3904
3904
|
Component-level design guidance for fintech apps, invoicing tools, expense trackers, budget apps, payroll, accounting software, banking dashboards, and any product where **money is the primary data type**. Stripe, Wise, Revolut, Mercury, Brex, QuickBooks, Ramp are the reference bar.
|
|
3905
3905
|
|
|
@@ -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 Ks={"consumer-warm":{id:"consumer-warm",name:"Consumer Warm",description:"Personal, lifestyle, and wellness apps (habits, journals, recipes, mood, meditation)",content:Fs},"consumer-bold":{id:"consumer-bold",name:"Consumer Bold",description:"Energetic, achievement-driven apps (fitness, workouts, sports, gaming, social)",content:Bs},"professional-clean":{id:"professional-clean",name:"Professional Clean",description:"Service and appointment-based apps (booking, clinics, salons, real estate, restaurants)",content:qs},"education-structured":{id:"education-structured",name:"Education Structured",description:"Learning and knowledge apps (courses, quizzes, flashcards, LMS, tutorials)",content:zs},"marketplace-browse":{id:"marketplace-browse",name:"Marketplace Browse",description:"Browsing and shopping apps (marketplaces, directories, shops, catalogs, food delivery)",content:Hs},"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:Gs},"content-editorial":{id:"content-editorial",name:"Content Editorial",description:"Blogs, newsletters, magazines, publications, documentation, knowledge bases",content:Ws},"devtool-technical":{id:"devtool-technical",name:"Devtool Technical",description:"Developer tools, APIs, CLIs, SDKs, infrastructure, monitoring, AI/ML platforms",content:Vs},"creative-showcase":{id:"creative-showcase",name:"Creative Showcase",description:"Portfolios, design agencies, creative studios, photographers, artists",content:Ys},"finance-clarity":{id:"finance-clarity",name:"Finance Clarity",description:"Fintech, invoicing, expense tracking, budgeting, payroll, accounting, banking",content:Js}};function Qs(s){return Ks[s]?.content}function Xs(s,o){let e=o?.archetype;if(e&&e in Ks)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 Ut,mkdirSync as er,readFileSync as tr,readdirSync as or,writeFileSync as Ri}from"fs";import{join as rt,resolve as Ni}from"path";import{homedir as vo}from"os";function st(s){return s.entity??s.name??"Unknown"}function Ve(s){return typeof s=="string"?s:s.name}function wo(s){return typeof s=="string"?"text":s.type}function Zs(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[Ve(r)]=Ei(Ve(r),wo(r),st(s),n);t.push(a)}return t}function Ei(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 _i(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:st(m),fields:(m.fields||[]).map(p=>({name:Ve(p),type:wo(p)})),sampleData:Zs(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=>st(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=>st(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=st(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=>Ve(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:Ve(g),type:wo(g)})),sampleData:Zs(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=st(m);(m.fields||[]).find(v=>Ve(v).toLowerCase()==="name"||Ve(v).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 Di(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(`
|
|
4121
|
+
`;var Qs={"consumer-warm":{id:"consumer-warm",name:"Consumer Warm",description:"Personal, lifestyle, and wellness apps (habits, journals, recipes, mood, meditation)",content:Bs},"consumer-bold":{id:"consumer-bold",name:"Consumer Bold",description:"Energetic, achievement-driven apps (fitness, workouts, sports, gaming, social)",content:qs},"professional-clean":{id:"professional-clean",name:"Professional Clean",description:"Service and appointment-based apps (booking, clinics, salons, real estate, restaurants)",content:zs},"education-structured":{id:"education-structured",name:"Education Structured",description:"Learning and knowledge apps (courses, quizzes, flashcards, LMS, tutorials)",content:Hs},"marketplace-browse":{id:"marketplace-browse",name:"Marketplace Browse",description:"Browsing and shopping apps (marketplaces, directories, shops, catalogs, food delivery)",content:Gs},"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:Ws},"content-editorial":{id:"content-editorial",name:"Content Editorial",description:"Blogs, newsletters, magazines, publications, documentation, knowledge bases",content:Vs},"devtool-technical":{id:"devtool-technical",name:"Devtool Technical",description:"Developer tools, APIs, CLIs, SDKs, infrastructure, monitoring, AI/ML platforms",content:Ys},"creative-showcase":{id:"creative-showcase",name:"Creative Showcase",description:"Portfolios, design agencies, creative studios, photographers, artists",content:Js},"finance-clarity":{id:"finance-clarity",name:"Finance Clarity",description:"Fintech, invoicing, expense tracking, budgeting, payroll, accounting, banking",content:Ks}};function Xs(s){return Qs[s]?.content}function Zs(s,o){let e=o?.archetype;if(e&&e in Qs)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 Ut,mkdirSync as tr,readFileSync as or,readdirSync as sr,writeFileSync as Ei}from"fs";import{join as rt,resolve as _i}from"path";import{homedir as vo}from"os";function st(s){return s.entity??s.name??"Unknown"}function Ve(s){return typeof s=="string"?s:s.name}function wo(s){return typeof s=="string"?"text":s.type}function er(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[Ve(r)]=Di(Ve(r),wo(r),st(s),n);t.push(a)}return t}function Di(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 Mi(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:st(m),fields:(m.fields||[]).map(p=>({name:Ve(p),type:wo(p)})),sampleData:er(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=>st(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=>st(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=st(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=>Ve(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:Ve(g),type:wo(g)})),sampleData:er(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=st(m);(m.fields||[]).find(v=>Ve(v).toLowerCase()==="name"||Ve(v).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 $i(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
4122
|
**${n.name}** \u2014 fields: ${n.fields.map(a=>`${a.name} (${a.type})`).join(", ")}`),e.push("```json"),e.push(JSON.stringify(n.sampleData,null,2)),e.push("```");e.push("")}}e.push("## Navigation"),e.push(`**Style**: ${s.navigation.style} (use this layout)`),e.push("**Items**:");for(let t of s.navigation.items)e.push(`- ${t.label} \u2192 \`${t.route}\``);if(e.push(""),s.primaryAction&&(e.push("## Primary action (this drives the layout)"),e.push(`- **Action**: ${s.primaryAction.action}`),e.push(`- **Flow**: ${s.primaryAction.flow}`),e.push(`- **Dashboard must show**: ${s.primaryAction.dashboardSurface}`),e.push(""),e.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."),e.push("")),s.edgeCases.length>0){e.push("## Edge cases to consider"),e.push("Add HTML comments in the wireframe where these matter:");for(let t of s.edgeCases)e.push(`- ${t}`);e.push("")}return e.push("## Design direction (DO NOT apply to wireframe \u2014 this is for reference only)"),e.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.`),e.push("The wireframe is grayscale and rough. These tokens will be applied during the actual build."),e.push(""),e.push("## After writing the wireframe"),e.push(""),e.push("1. Write the file to `.mistflow/mockups/mockup-{planId}.html` (replace `{planId}` with the actual plan ID)"),e.push("2. Open it: `open .mistflow/mockups/mockup-{planId}.html`"),e.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?"`),e.join(`
|
|
4123
|
-
`)}function sr(s){return rt(vo(),".mistflow","mockup-state",`${s}.json`)}function Mi(s){let o=sr(s);if(!Ut(o))return null;try{return JSON.parse(tr(o,"utf-8"))}catch{return null}}function bo(s,o){let e=rt(vo(),".mistflow","mockup-state");er(e,{recursive:!0}),Ri(sr(s),JSON.stringify(o,null,2))}async function rr(s){let{planId:o,feedback:e,approved:t}=s,n=Ni(s.projectPath??process.cwd()),a=rt(vo(),".mistflow","plans",`${o}.json`);if(!Ut(a))return d(`Plan not found for planId '${o}'. Call mist_plan to generate a plan first.`,!0);let r;try{r=JSON.parse(tr(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=Mi(o);l||(l={planId:o,iterationCount:0,approved:!1,screens:[],feedback:[]});let c=rt(n,".mistflow","mockups");if(er(c,{recursive:!0}),t){l.approved=!0,bo(o,l);let g=Ut(c)?or(c).filter(v=>v.endsWith(".html")):[];return d(JSON.stringify({status:"approved",message:`Wireframe approved after ${l.iterationCount} iteration(s). Layout direction is locked in.`,mockupFiles:g.map(v=>`.mistflow/mockups/${v}`),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++,bo(o,l);let u=_i(i);l.screens=u.screens.map(g=>g.name),bo(o,l);let m=Di(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 nr(s){let o=rt(s,".mistflow","mockups");return Ut(o)?or(o).filter(e=>e.endsWith(".html")).map(e=>rt(o,e)):[]}var ir="\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 ar=`# Landing Page Rules
|
|
4123
|
+
`)}function rr(s){return rt(vo(),".mistflow","mockup-state",`${s}.json`)}function ji(s){let o=rr(s);if(!Ut(o))return null;try{return JSON.parse(or(o,"utf-8"))}catch{return null}}function bo(s,o){let e=rt(vo(),".mistflow","mockup-state");tr(e,{recursive:!0}),Ei(rr(s),JSON.stringify(o,null,2))}async function nr(s){let{planId:o,feedback:e,approved:t}=s,n=_i(s.projectPath??process.cwd()),a=rt(vo(),".mistflow","plans",`${o}.json`);if(!Ut(a))return d(`Plan not found for planId '${o}'. Call mist_plan to generate a plan first.`,!0);let r;try{r=JSON.parse(or(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=ji(o);l||(l={planId:o,iterationCount:0,approved:!1,screens:[],feedback:[]});let c=rt(n,".mistflow","mockups");if(tr(c,{recursive:!0}),t){l.approved=!0,bo(o,l);let g=Ut(c)?sr(c).filter(v=>v.endsWith(".html")):[];return d(JSON.stringify({status:"approved",message:`Wireframe approved after ${l.iterationCount} iteration(s). Layout direction is locked in.`,mockupFiles:g.map(v=>`.mistflow/mockups/${v}`),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++,bo(o,l);let u=Mi(i);l.screens=u.screens.map(g=>g.name),bo(o,l);let m=$i(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 ir(s){let o=rt(s,".mistflow","mockups");return Ut(o)?sr(o).filter(e=>e.endsWith(".html")).map(e=>rt(o,e)):[]}var ar="\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 lr=`# Landing Page Rules
|
|
4124
4124
|
|
|
4125
4125
|
These rules apply to every landing page. They are non-negotiable.
|
|
4126
4126
|
|
|
@@ -4517,7 +4517,7 @@ app/
|
|
|
4517
4517
|
\`\`\`
|
|
4518
4518
|
|
|
4519
4519
|
Each section is a separate component file. The page.tsx simply imports and stacks them. Do NOT build one monolithic page component.
|
|
4520
|
-
`;var
|
|
4520
|
+
`;var cr=`# Design Doctrine
|
|
4521
4521
|
|
|
4522
4522
|
This is the standard for every UI you generate. It is not aspirational. It is the floor.
|
|
4523
4523
|
|
|
@@ -4583,7 +4583,7 @@ Before submitting any UI file, read it with this checklist and regenerate if any
|
|
|
4583
4583
|
8. Is there ONE memorable moment on the page (signature typography / orchestrated motion / unexpected layout)? **If zero, add one. If three, keep the strongest one.**
|
|
4584
4584
|
|
|
4585
4585
|
If any answer fails, the UI is not ready. Redesign \u2014 not tweak \u2014 the failing piece.
|
|
4586
|
-
`;var
|
|
4586
|
+
`;var dr=`# Typography
|
|
4587
4587
|
|
|
4588
4588
|
Typography is the cheapest way to escape AI slop and the most visible place it shows up. Every generic landing uses Inter. Every remarkable landing picks something you'd notice.
|
|
4589
4589
|
|
|
@@ -4671,7 +4671,7 @@ Pick exactly one:
|
|
|
4671
4671
|
- **Mixed case display** \u2014 Title Case for proper nouns, SmallCaps for the verb. Editorial feel.
|
|
4672
4672
|
|
|
4673
4673
|
Do NOT use: gradient text (\`bg-clip-text\`) on one word of the headline. That effect is the most overused generic-AI marker.
|
|
4674
|
-
`;var
|
|
4674
|
+
`;var pr="# Color\n\nColor is a commitment, not a palette swatch. The #1 failure mode in AI-generated landings is an evenly-distributed palette: a little emerald here, a little amber there, a gradient, a badge. That's visual hedging \u2014 it signals \"I couldn't pick a point of view.\"\n\nPick one color. Use it with intent.\n\n## The Token System\n\nEvery color on every screen goes through a CSS variable defined in `globals.css`. You do not hand-pick hex values in JSX. You do not use Tailwind palette utilities (`bg-emerald-500`, `text-blue-600`, `border-slate-200`). If a color isn't in the token scheme, it doesn't exist for this app.\n\n### Core tokens\n\n- `--color-background` \u2014 page background\n- `--color-foreground` \u2014 default body text\n- `--color-card` \u2014 elevated surface (cards, panels)\n- `--color-card-foreground` \u2014 text on cards\n- `--color-muted` \u2014 low-emphasis surface fill\n- `--color-muted-foreground` \u2014 secondary text (\u2265 WCAG AA contrast vs background)\n- `--color-border` \u2014 subtle dividers\n- `--color-input` \u2014 form input borders\n- `--color-popover` / `--color-popover-foreground` \u2014 dropdowns, tooltips, menus\n\n### Interactive tokens\n\n- `--color-primary` \u2014 primary CTAs, links, active tab, focus ring\n- `--color-primary-foreground` \u2014 text on primary (derived for WCAG AA contrast)\n- `--color-ring` \u2014 focus outline (same hue as primary)\n- `--color-secondary` / `--color-secondary-foreground` \u2014 quieter than primary, more than muted\n- `--color-accent` / `--color-accent-foreground` \u2014 hover states on neutrals\n\n### Semantic tokens\n\n- `--color-success` \u2014 confirmation, \"verified\" banners, positive states\n- `--color-warning` \u2014 pending states, attention, non-destructive caution\n- `--color-destructive` / `--color-destructive-foreground` \u2014 errors, irreversible actions\n- `--color-info` \u2014 neutral system messages, tips\n\n**You use these semantic tokens for all status UI.** When you need a \"green checkmark\" you reach for `text-success`, not `text-emerald-500`. When you need an amber alert you reach for `bg-warning/10 text-warning`, not `bg-amber-50 text-amber-700`.\n\n## Usage Rules\n\n**Primary color:**\n- Primary CTAs, links, the active navigation tab, focus rings.\n- NOT for headings. Black or foreground-colored headings are stronger.\n- NOT for large surface fills (it's a splash of color, not a wash).\n- NOT for borders except focus rings.\n- One bold use of primary beats twenty sprinkled uses.\n\n**Neutrals do the structural work:**\n- Background, cards, borders \u2014 all come from the neutral scale.\n- Text hierarchy via opacity on foreground (`text-foreground`, `text-foreground/80`, `text-muted-foreground`) \u2014 not different colors.\n\n**Semantic colors:**\n- Use `bg-success/10 text-success border border-success/30` for success banners (reproducibility: a light-tinted version of the success color for surface, the solid version for text and border).\n- Same shape for warning, info, destructive.\n\n## Dark Mode\n\nCommit to one theme. If DESIGN.md says the app is dark-themed, make it unambiguously dark \u2014 `#0c0c0c` / near-black base, not neutral-900. If light-themed, commit to light.\n\nDo NOT auto-swap based on `prefers-color-scheme` when the design system declared a theme direction. The appStyle chose a theme for a reason; respect it.\n\n## Forbidden\n\n- Palette utilities: `bg-emerald-500`, `text-blue-600`, `border-slate-200`, `from-purple-500`, `via-pink-300`, `to-amber-400`. Every one of these in your output is a slop indicator.\n- Hex literals inside `className` or inline `style` props.\n- Named colors from CSS (`red`, `lightgrey`, `rebeccapurple`) \u2014 never used in production UI; always a sign of rushed work.\n- Purple gradients on white. The single most overused AI-design pattern.\n- Three-color gradient pills. Rainbow badges. \"Vibrant\" anything.\n\n## Contrast\n\nEvery text/surface pair in DESIGN.md is already WCAG AA-verified by Mistflow's contrast test. You do not need to re-check \u2014 the tokens are safe by construction. You DO need to:\n\n- Not override token combinations with hardcoded classes that might fail contrast.\n- Maintain contrast for overlays (text on images, modals on scrims). When stacking text over a gradient or image, include a scrim (`bg-background/80 backdrop-blur-sm`) so body text stays \u2265 4.5:1.\n\n## Getting Color Wrong\n\nThe specific failure mode to avoid: a page where primary is used in five places, all small and incidental \u2014 a checkmark, a hover state, a tiny badge. That's AI hedging. Either use primary confidently on a hero CTA and mean it, OR don't use primary on the page at all and let neutrals carry the identity.\n";var ur=`# Motion
|
|
4675
4675
|
|
|
4676
4676
|
Motion is the most-ignored dimension of AI-generated UI. Generic landings either have no motion or sprinkle tiny fades on everything. Remarkable landings pick ONE orchestrated moment and execute it precisely.
|
|
4677
4677
|
|
|
@@ -4749,7 +4749,7 @@ Primary CTA has a 2px vertical translate on \`:active\` with 80ms \`--ease-quart
|
|
|
4749
4749
|
## One-Line Motion Rule
|
|
4750
4750
|
|
|
4751
4751
|
If the motion you're about to add could be described as "subtle animation on scroll", delete it. Design motion is specific, named, and described in one sentence: "the headline lines drop in from above with a 50ms stagger at page load." If you can't describe it that specifically, you don't have a motion design \u2014 you have motion noise.
|
|
4752
|
-
`;var
|
|
4752
|
+
`;var mr=`# Spatial Composition
|
|
4753
4753
|
|
|
4754
4754
|
Layout is where AI-slop is most visible. A centered single-column hero with a pill, headline, subhead, and two CTAs is the most-recognizable generic-SaaS pattern on the internet. It is the layout you must not use.
|
|
4755
4755
|
|
|
@@ -4819,7 +4819,7 @@ To signal "designed, not templated":
|
|
|
4819
4819
|
Negative space is a design element. A hero with \`py-32\` and a tight \`max-w-2xl\` text block in a wide viewport reads as confident. A hero that fills every pixel with checkmarks, logos, and counters reads as scared.
|
|
4820
4820
|
|
|
4821
4821
|
Pick: generous breathing (luxury / refined / editorial) OR controlled density (dashboards / industrial / brutalist). Never a mushy middle.
|
|
4822
|
-
`;var
|
|
4822
|
+
`;var hr=`# Interaction
|
|
4823
4823
|
|
|
4824
4824
|
Every interactive element has a designed state for every phase: rest, hover, focus, active, disabled. The difference between remarkable and adequate lives in these states.
|
|
4825
4825
|
|
|
@@ -4904,7 +4904,7 @@ Small moments that add up to "designed":
|
|
|
4904
4904
|
- **Empty states** offer a specific next action, not "No data yet".
|
|
4905
4905
|
|
|
4906
4906
|
These micro-interactions are the texture of a designed product. Ship them.
|
|
4907
|
-
`;var
|
|
4907
|
+
`;var gr=`# UX Writing
|
|
4908
4908
|
|
|
4909
4909
|
Copy is design. A remarkable page has copy that could only be about this specific product. A generic page has copy that could describe a hundred.
|
|
4910
4910
|
|
|
@@ -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
|
|
4984
|
-
`)}function Ft(s){return s.entity??s.name??"Unknown"}function Ki(s){return s.length===0?"":typeof s[0]=="string"?s.join(", "):s.map(o=>`${o.name} (${o.type})`).join(", ")}function fr(s){return s.path??s.route??s.name??""}function Qi(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 yr(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=Ft(t).toLowerCase();return e.some(a=>n.includes(a)||a.includes(n))})}function Xi(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=fr(t).toLowerCase();return e.some(r=>n.includes(r)||r.includes(n)||a.includes(r))})}var Zi=new Set(["landing","design","dashboard","crud","layout","admin","auth","schema","integration","multi-tenant","deploy","general"]);function ea(s){let o=s.stepType;if(o&&Zi.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 ta(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 oa(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(ir),e.join(`
|
|
4985
|
-
`)}async function
|
|
4983
|
+
`;function Ki(s){return new Promise(o=>{let e=Ji({port:s,host:"127.0.0.1"});e.on("connect",()=>{e.destroy(),o(!0)}),e.on("error",()=>{o(!1)})})}var qd=ko.object({projectPath:ko.string().optional().describe("Path to the project directory (default: cwd)"),step:ko.number().optional().describe("Specific step number to implement (default: next incomplete step)")});function Qi(s){let o=nt(s,"mistflow.json");if(!wt(o))return null;try{return JSON.parse(So(o,"utf-8"))}catch{return null}}function fr(s,o){let e=nt(s,"mistflow.json");xo(e,JSON.stringify(o,null,2)+`
|
|
4984
|
+
`)}function Ft(s){return s.entity??s.name??"Unknown"}function Xi(s){return s.length===0?"":typeof s[0]=="string"?s.join(", "):s.map(o=>`${o.name} (${o.type})`).join(", ")}function yr(s){return s.path??s.route??s.name??""}function Zi(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 br(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=Ft(t).toLowerCase();return e.some(a=>n.includes(a)||a.includes(n))})}function ea(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=yr(t).toLowerCase();return e.some(r=>n.includes(r)||r.includes(n)||a.includes(r))})}var ta=new Set(["landing","design","dashboard","crud","layout","admin","auth","schema","integration","multi-tenant","deploy","general"]);function oa(s){let o=s.stepType;if(o&&ta.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 sa(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 ra(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(ar),e.join(`
|
|
4985
|
+
`)}async function na(s){try{let o=await ls("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 ra(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(oa(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=nr(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 k of h){let S=k.replace(a,"").replace(/^\//,"");r.push(`- \`${S}\``)}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?yr(s,o.dataModel):[];u.length>0&&(r.push("### Data model (from plan):"),u.forEach(h=>{let k=Ft(h),S=Ki(h.fields);r.push(`- **${k}**: ${S}`),r.push(` Schema file: \`db/schema/${k.toLowerCase().replace(/\s+/g,"-")}.ts\``)}),r.push(""));let m=o.pages?Xi(s,o.pages):[];m.length>0&&(r.push("### Pages to create/update:"),m.forEach(h=>{let k=h.description?` \u2014 ${h.description}`:"";r.push(`- \`${fr(h)}\`${k}`)}),r.push("")),n==="crud"&&u.length>0&&u.forEach(h=>{let k=Ft(h),S=k.toLowerCase().replace(/\s+/g,"-"),R=S.endsWith("s")?S:`${S}s`;r.push(`### Files for ${k} CRUD:`),r.push(`- List page: \`app/(dashboard)/${R}/page.tsx\` (Server Component)`),r.push(`- Detail page: \`app/(dashboard)/${R}/[id]/page.tsx\``),r.push(`- Create page: \`app/(dashboard)/${R}/new/page.tsx\``),r.push(`- Server Actions: \`app/(dashboard)/${R}/actions.ts\``),r.push(`- DataTable columns: \`components/${S}-table-columns.tsx\``),r.push(`- Form: \`components/${S}-form.tsx\``),r.push("")});let p=o.appStyle;if(l){r.push("## Design Doctrine (the standard for every UI step)"),r.push(""),r.push(lr),r.push(""),r.push("## Design Reference Library"),r.push(""),r.push("### Typography"),r.push(cr),r.push(""),r.push("### Color"),r.push(dr),r.push(""),r.push("### Motion"),r.push(pr),r.push(""),r.push("### Spatial Composition"),r.push(ur),r.push(""),r.push("### Interaction"),r.push(mr),r.push(""),r.push("### UX Writing"),r.push(hr),r.push("");let h=a?nt(a,"DESIGN.md"):void 0,k=h&&wt(h)?(()=>{try{return So(h,"utf-8")}catch{return null}})():null;k&&(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(k),r.push(""))}if(l){let h=Xs(o.summary??o.name,{tone:o.design?.tone,audienceType:o.audienceType,archetype:o.design?.archetype});if(h){let k=Qs(h);k&&(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(k),r.push(""))}}(n==="landing"||n==="design")&&(r.push(ar),r.push(""));let g=s.integrationId?et(s.integrationId):void 0;if(g){let h=tt(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 k of h.envVars)r.push(`- \`${k.key}\`: ${k.description} \u2014 Get it at ${k.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:v,skill:f}=await sa(n);return r.push(v),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
|
|
4987
|
+
- Server Components by default, "use client" only when interactivity is needed`,skill:""}}}async function ia(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(ra(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=ir(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 k of h){let S=k.replace(a,"").replace(/^\//,"");r.push(`- \`${S}\``)}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?br(s,o.dataModel):[];u.length>0&&(r.push("### Data model (from plan):"),u.forEach(h=>{let k=Ft(h),S=Xi(h.fields);r.push(`- **${k}**: ${S}`),r.push(` Schema file: \`db/schema/${k.toLowerCase().replace(/\s+/g,"-")}.ts\``)}),r.push(""));let m=o.pages?ea(s,o.pages):[];m.length>0&&(r.push("### Pages to create/update:"),m.forEach(h=>{let k=h.description?` \u2014 ${h.description}`:"";r.push(`- \`${yr(h)}\`${k}`)}),r.push("")),n==="crud"&&u.length>0&&u.forEach(h=>{let k=Ft(h),S=k.toLowerCase().replace(/\s+/g,"-"),R=S.endsWith("s")?S:`${S}s`;r.push(`### Files for ${k} CRUD:`),r.push(`- List page: \`app/(dashboard)/${R}/page.tsx\` (Server Component)`),r.push(`- Detail page: \`app/(dashboard)/${R}/[id]/page.tsx\``),r.push(`- Create page: \`app/(dashboard)/${R}/new/page.tsx\``),r.push(`- Server Actions: \`app/(dashboard)/${R}/actions.ts\``),r.push(`- DataTable columns: \`components/${S}-table-columns.tsx\``),r.push(`- Form: \`components/${S}-form.tsx\``),r.push("")});let p=o.appStyle;if(l){r.push("## Design Doctrine (the standard for every UI step)"),r.push(""),r.push(cr),r.push(""),r.push("## Design Reference Library"),r.push(""),r.push("### Typography"),r.push(dr),r.push(""),r.push("### Color"),r.push(pr),r.push(""),r.push("### Motion"),r.push(ur),r.push(""),r.push("### Spatial Composition"),r.push(mr),r.push(""),r.push("### Interaction"),r.push(hr),r.push(""),r.push("### UX Writing"),r.push(gr),r.push("");let h=a?nt(a,"DESIGN.md"):void 0,k=h&&wt(h)?(()=>{try{return So(h,"utf-8")}catch{return null}})():null;k&&(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(k),r.push(""))}if(l){let h=Zs(o.summary??o.name,{tone:o.design?.tone,audienceType:o.audienceType,archetype:o.design?.archetype});if(h){let k=Xs(h);k&&(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(k),r.push(""))}}(n==="landing"||n==="design")&&(r.push(lr),r.push(""));let g=s.integrationId?et(s.integrationId):void 0;if(g){let h=tt(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 k of h.envVars)r.push(`- \`${k.key}\`: ${k.description} \u2014 Get it at ${k.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:v,skill:f}=await na(n);return r.push(v),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 wr(s){let{projectPath:o,step:e}=s,t=Vi(o??process.cwd()),n=Qi(t);if(!n)return Ce(t);if(!wt(nt(t,"node_modules")))return d(`Dependencies are not installed at ${t}. Call mist_build with action='install' and projectPath='${t}' before running implement. This is a one-time setup step after init.`,!0);try{let{ensureBackendRegistered:A,ensureShadcnComponents:_}=await import("./self-heal-BXJXUFUF.js");await A(t);let N=await _(t);N.failed?console.error(`[implement] ${N.failed}`):N.installed.length>0&&console.error(`[implement] installed ${N.installed.length} shadcn components`)}catch(A){console.error("[implement] self-heal skipped:",A instanceof Error?A.message:String(A))}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(A=>A.status==="in_progress");if(i){let A=a.steps.findIndex(_=>_.number===i.number);A!==-1&&(a.steps[A].status="completed",r=`Auto-completed step ${i.number} (${i.name})`,fr(t,n))}let l;if(e!==void 0){if(l=a.steps.find(A=>A.number===e),!l)return d(`Step ${e} 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(A=>A.status!=="completed"),!l)return d(JSON.stringify({message:"All plan steps are completed!",completedSteps:a.steps.map(A=>A.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(A=>A.status==="completed").map(A=>`Step ${A.number}: ${A.name}`),{readLocalState:u}=await import("./state-manager-GBP2NSYC.js"),m=u(t),p=oa(l),g=[];if((p==="crud"||p==="schema")&&a.dataModel&&l.entities&&l.entities.length>0){let A=br(l,a.dataModel);for(let _ of A){let N=Ft(_);try{let z=(_.fields||[]).map(D=>typeof D=="string"?{name:D,type:"text"}:{name:D.name,type:Zi(D.type),required:D.required!==!1});if(z.length===0)continue;let ve=n.dbProvider==="neon"?"nextjs-neon":"nextjs",U=await cs(ve,N,z),Y=0,W=0;for(let D of U.files){let ie=nt(t,D.path);if(wt(ie)){W++;continue}Wi(Yi(ie),{recursive:!0}),xo(ie,D.content),Y++}let J=nt(t,"db","index.ts");if(wt(J)){let D=So(J,"utf-8");D.includes(U.dbExport)||xo(J,D.trimEnd()+`
|
|
4989
4989
|
`+U.dbExport+`
|
|
4990
|
-
`)}Y>0?g.push(`${U.entityPascal} CRUD (${Y} new files${W>0?`, ${W} existing skipped`:""})`):W>0&&g.push(`${U.entityPascal} CRUD (all ${W} files already exist \u2014 skipped)`)}catch(z){console.error(`Module generation failed for ${N} (non-fatal):`,z instanceof Error?z.message:z)}}}let v=await
|
|
4990
|
+
`)}Y>0?g.push(`${U.entityPascal} CRUD (${Y} new files${W>0?`, ${W} existing skipped`:""})`):W>0&&g.push(`${U.entityPascal} CRUD (all ${W} files already exist \u2014 skipped)`)}catch(z){console.error(`Module generation failed for ${N} (non-fatal):`,z instanceof Error?z.message:z)}}}let v=await ia(l,a,c,null,p,t),f=a.steps.findIndex(A=>A.number===l.number);if(f!==-1&&(n.plan.steps[f].status="in_progress",fr(t,n)),m&&n.projectId){let{syncRemoteState:A}=await import("./state-manager-GBP2NSYC.js");A(n.projectId,m).catch(()=>{})}let h=a.steps.every(A=>A.status==="completed"||A.number===l.number),k;if(h){let A=a.primaryAction?.action??"the core action",_=a.primaryAction?.flow??"sign up \u2192 reach dashboard \u2192 complete primary action";k=`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,20 +5002,20 @@ 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 S=
|
|
5006
|
-
`+l}let a=vt(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
|
|
5007
|
-
`)}),!1)}try{let g=await it(p,"Landing page",async()=>{await p.goto(t,{waitUntil:"domcontentloaded",timeout:3e4}),await p.waitForLoadState("networkidle").catch(()=>{});let f=await p.evaluate(()=>{let k=document.body;if(!k)return"";let S=document.createTreeWalker(k,NodeFilter.SHOW_TEXT),R="",x;for(;x=S.nextNode();){let I=x.parentElement;if(I){let q=window.getComputedStyle(I);q.display!=="none"&&q.visibility!=="hidden"&&parseFloat(q.opacity)>0&&(R+=x.textContent?.trim()+" ")}}return R.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 v=!1;if(u){let f=await it(p,"Login",async()=>{await p.goto(`${t}/login`,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{});let h=p.locator('input[type="email"], input[name="email"], input[placeholder*="email" i]'),k=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 k.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(R=>!R.pathname.includes("/login"),{timeout:1e4})}catch{let R=await p.locator('[role="alert"], .text-red-500, .text-destructive, [data-error]').first().textContent().catch(()=>null);return{pass:!1,detail:R?`Login failed: ${R}`:"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 v=!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(!v&&l){let f=new URL(t).hostname,h=t.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 it(p,"Dashboard",async()=>{p.url().includes("/dashboard")||(await p.goto(`${t}/dashboard`,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{}));let R=await p.content();return R.length<1e3?{pass:!1,detail:`Dashboard page is very small (${R.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 (${R.length} bytes)`}});a.push(f);let h=await p.evaluate(()=>{let S=[];return document.querySelectorAll("nav a[href], aside a[href]").forEach(x=>{let I=x.getAttribute("href");I&&I.startsWith("/")&&!I.startsWith("/api")&&!I.includes("[")&&I!=="/dashboard"&&I!=="/"&&!I.includes("/login")&&!I.includes("/sign")&&S.push(I)}),[...new Set(S)]});if(h.length>0){let S=0,R=[];for(let x of h.slice(0,8)){let I=await it(p,`Page: ${x}`,async()=>{await p.goto(`${t}${x}`,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{});let q=await p.title(),A=await p.content();return q.toLowerCase().includes("500")||q.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."}:q.toLowerCase().includes("404")||q.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."}:A.length<500?{pass:!1,detail:`Page is very small (${A.length} bytes)`,fix:"Page may not have rendered. Check the page component."}:{pass:!0,detail:"Loads without errors"}});I.status==="fail"&&(S++,R.push(x)),a.push(I)}}let k=await it(p,"Design quality",async()=>{let S=p.url().includes("/dashboard")?p.url():`${t}/dashboard`;p.url().includes("/dashboard")||(await p.goto(S,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{}));let R=await p.evaluate(()=>{let x=[],I=document.querySelectorAll("h1, h2, h3, h4, h5, h6"),q=new Set;I.forEach(w=>{q.add(window.getComputedStyle(w).fontSize)}),I.length>=3&&q.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 A=Array.from(I).map(w=>parseInt(w.tagName.charAt(1),10));for(let w=1;w<A.length;w++)if(A[w]-A[w-1]>1){x.push(`TYPOGRAPHY: Heading level skipped (h${A[w-1]} -> h${A[w]}). Use sequential heading levels for accessibility.`);break}let
|
|
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 S=sa(p),R={stepNumber:l.number,totalSteps:a.steps.length,estimatedMinutes:S,announcement:`Starting step ${l.number} of ${a.steps.length}: ${l.name}. This step usually takes ${S.min}\u2013${S.max} minutes.`},I=JSON.stringify({instruction:v,step:{number:l.number,name:l.name,description:l.description,status:"in_progress"},stepTiming:R,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:k});return await Ki(3e3)?je("http://localhost:3000",I):d(I)}import{z as To}from"zod";import{resolve as aa}from"path";import{execFileSync as la}from"child_process";var Yd=To.object({projectPath:To.string().optional().describe("Path to the project directory (default: current working directory)"),buildOutput:To.string().optional().describe("Build output to parse (if not provided, runs npm run build)")});function vt(s){let o=[],e=/([^\s(]+)\((\d+),(\d+)\):\s*error\s+(TS\d+):\s*(.+)/g,t;for(;(t=e.exec(s))!==null;){let[,l,c,u,m,p]=t;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(;(t=n.exec(s))!==null;){let[,l,c,u,m]=t;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(;(t=a.exec(s))!==null;){let[,l,c]=t;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(;(t=r.exec(s))!==null;){let[,l,c]=t;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(;(t=i.exec(s))!==null;){let[,l,c,u,m]=t;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 vr(s){let{projectPath:o,buildOutput:e}=s,t=aa(o??process.cwd()),n=e??"";if(!e)try{return la("npm",["run","build"],{cwd:t,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=vt(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 ca,readFileSync as da}from"fs";import{join as pa}from"path";function ua(s){let o=pa(s,"mistflow.json");if(!ca(o))return null;try{return JSON.parse(da(o,"utf-8"))}catch{return null}}async function kr(s){try{let o=await fetch(s,{redirect:"follow",signal:AbortSignal.timeout(15e3)}),e=await o.text();return{status:o.status,body:e}}catch(o){return{status:0,body:String(o)}}}async function ma(s,o,e){try{let t=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json",...e??{}},body:JSON.stringify(o),redirect:"follow",signal:AbortSignal.timeout(15e3)}),n=await t.text(),a;try{a=JSON.parse(n)}catch{}return{status:t.status,json:a}}catch{return{status:0}}}async function xr(s){try{let o=await s.screenshot({type:"png"});return Buffer.from(o).toString("base64")}catch{return}}async function it(s,o,e){let t=[],n=a=>{a.type()==="error"&&t.push(a.text())};s.on("console",n);try{let a=await e(),r=await xr(s);return{name:o,status:a.pass?"pass":"fail",detail:a.detail,fix:a.fix,screenshot:r,consoleErrors:t.length>0?t:void 0}}catch(a){let r=await xr(s);return{name:o,status:"fail",detail:`Unexpected error: ${a instanceof Error?a.message:String(a)}`,screenshot:r,consoleErrors:t.length>0?t:void 0}}finally{s.removeListener("console",n)}}async function Sr(s){let o=s.projectPath??process.cwd(),e=ua(o),t=s.url;if(t||(t=e?.deploy?.url),!t)return d("No deploy URL found. Deploy the app first with mist_deploy, then call mist_build action='qa'.",!0);t.startsWith("http")||(t=`https://${t}`);let n=e?.projectId,a=[],r=await kr(`${t}/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."}),Bt(t,a);a.push({name:"Health endpoint",status:"pass",detail:"Returns 200"});let i=await kr(`${t}/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."}),Bt(t,a);a.push({name:"Auth system",status:"pass",detail:"Better Auth running"});let l,c,u;if(n){let g=await Qo(n);if(g){console.error("[qa] Calling seed endpoint for session token");let v=await ma(`${t}/api/admin/seed`,{token:g.seedToken,email:g.email,password:"QaTemp1!"});v.status===200&&v.json?(l=v.json.sessionToken,c=v.json.email,v.json.seeded?(u=v.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 ${v.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."}),Bt(t,a);let m,p;try{let{getIsolatedContext:g,takeScreenshot:v}=await import("./browser-manager-QW3OYPFB.js"),f=await g();m=f.context,p=f.page}catch(g){let v=g instanceof Error?g.message:String(g);return d(JSON.stringify({status:"cannot_verify",url:t,deployed:!0,reason:"App deployed successfully, but QA could not verify it via automated browser testing because Playwright is not installed locally.",detail:v,httpChecks:a.map(({screenshot:f,...h})=>h),fix:"Run: npx playwright install chromium",instruction:[`The app deployed and is live at ${t}. 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 ${t}. 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 it(p,"Landing page",async()=>{await p.goto(t,{waitUntil:"domcontentloaded",timeout:3e4}),await p.waitForLoadState("networkidle").catch(()=>{});let f=await p.evaluate(()=>{let k=document.body;if(!k)return"";let S=document.createTreeWalker(k,NodeFilter.SHOW_TEXT),R="",x;for(;x=S.nextNode();){let I=x.parentElement;if(I){let q=window.getComputedStyle(I);q.display!=="none"&&q.visibility!=="hidden"&&parseFloat(q.opacity)>0&&(R+=x.textContent?.trim()+" ")}}return R.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 v=!1;if(u){let f=await it(p,"Login",async()=>{await p.goto(`${t}/login`,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{});let h=p.locator('input[type="email"], input[name="email"], input[placeholder*="email" i]'),k=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 k.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(R=>!R.pathname.includes("/login"),{timeout:1e4})}catch{let R=await p.locator('[role="alert"], .text-red-500, .text-destructive, [data-error]').first().textContent().catch(()=>null);return{pass:!1,detail:R?`Login failed: ${R}`:"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 v=!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(!v&&l){let f=new URL(t).hostname,h=t.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 it(p,"Dashboard",async()=>{p.url().includes("/dashboard")||(await p.goto(`${t}/dashboard`,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{}));let R=await p.content();return R.length<1e3?{pass:!1,detail:`Dashboard page is very small (${R.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 (${R.length} bytes)`}});a.push(f);let h=await p.evaluate(()=>{let S=[];return document.querySelectorAll("nav a[href], aside a[href]").forEach(x=>{let I=x.getAttribute("href");I&&I.startsWith("/")&&!I.startsWith("/api")&&!I.includes("[")&&I!=="/dashboard"&&I!=="/"&&!I.includes("/login")&&!I.includes("/sign")&&S.push(I)}),[...new Set(S)]});if(h.length>0){let S=0,R=[];for(let x of h.slice(0,8)){let I=await it(p,`Page: ${x}`,async()=>{await p.goto(`${t}${x}`,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{});let q=await p.title(),A=await p.content();return q.toLowerCase().includes("500")||q.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."}:q.toLowerCase().includes("404")||q.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."}:A.length<500?{pass:!1,detail:`Page is very small (${A.length} bytes)`,fix:"Page may not have rendered. Check the page component."}:{pass:!0,detail:"Loads without errors"}});I.status==="fail"&&(S++,R.push(x)),a.push(I)}}let k=await it(p,"Design quality",async()=>{let S=p.url().includes("/dashboard")?p.url():`${t}/dashboard`;p.url().includes("/dashboard")||(await p.goto(S,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{}));let R=await p.evaluate(()=>{let x=[],I=document.querySelectorAll("h1, h2, h3, h4, h5, h6"),q=new Set;I.forEach(w=>{q.add(window.getComputedStyle(w).fontSize)}),I.length>=3&&q.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 A=Array.from(I).map(w=>parseInt(w.tagName.charAt(1),10));for(let w=1;w<A.length;w++)if(A[w]-A[w-1]>1){x.push(`TYPOGRAPHY: Heading level skipped (h${A[w-1]} -> h${A[w]}). Use sequential heading levels for accessibility.`);break}let _=document.querySelectorAll("*"),N=!1,z=!1;_.forEach(w=>{let M=window.getComputedStyle(w);M.backgroundColor==="rgb(0, 0, 0)"&&w.clientHeight>100&&w.clientWidth>200&&(N=!0);let K=M.backgroundColor,ue=M.color;if(K&&!K.includes("0, 0, 0")&&!K.includes("255, 255, 255")&&K!=="rgba(0, 0, 0, 0)"&&K!=="transparent"&&ue.match(/rgb\((\d+), (\d+), (\d+)\)/)){let ke=ue.match(/rgb\((\d+), (\d+), (\d+)\)/);if(ke){let[P,L,H]=[parseInt(ke[1]),parseInt(ke[2]),parseInt(ke[3])],Q=Math.abs(P-L)<10&&Math.abs(L-H)<10&&P>80&&P<180,oe=K.match(/rgb\((\d+), (\d+), (\d+)\)/);if(Q&&oe){let[me,C,G]=[parseInt(oe[1]),parseInt(oe[2]),parseInt(oe[3])];!(Math.abs(me-C)<15&&Math.abs(C-G)<15)&&w.textContent&&w.textContent.trim().length>0&&(z=!0)}}}}),N&&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)."),z&&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 ve=document.querySelectorAll('[class*="card"], [class*="Card"], [role="group"]'),U=!1;ve.forEach(w=>{w.querySelectorAll('[class*="card"], [class*="Card"]').length>0&&(U=!0)}),U&&x.push("LAYOUT: Nested cards detected (card inside card). Flatten the hierarchy. Use spacing and background color to create separation instead.");let Y=document.querySelectorAll("p, li, span, div"),W=0,J=0;Y.forEach(w=>{w.textContent&&w.textContent.trim().length>20&&w.clientHeight>0&&(J++,window.getComputedStyle(w).textAlign==="center"&&W++)}),J>5&&W/J>.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 D=new Set;_.forEach(w=>{let M=window.getComputedStyle(w);M.gap&&M.gap!=="normal"&&M.gap!=="0px"&&D.add(M.gap)}),D.size===1&&_.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 ie=document.querySelectorAll("button, a, input, select, textarea"),ee=!1;ie.forEach(w=>{let M=window.getComputedStyle(w);if(M.outline==="none"||M.outline==="0px none rgb(0, 0, 0)"){let K=w;(K.style.outline==="none"||K.style.outline==="0")&&(ee=!0)}}),document.querySelectorAll("table, [role='table']").forEach(w=>{w.querySelectorAll("tbody tr").length===0&&(w.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 se=document.querySelectorAll("style"),T=!1;se.forEach(w=>{let M=w.textContent||"";(M.includes("bounce")||M.includes("elastic")||M.match(/cubic-bezier\([^)]*[2-9]\.[0-9]/))&&(T=!0)}),T&&x.push("MOTION: Bounce or elastic easing detected. These feel dated. Use smooth deceleration curves (Quart out, Expo out) instead.");let j=document.querySelectorAll("button, a, input, select, [role='button']"),F=0;return j.forEach(w=>{let M=w.getBoundingClientRect();M.width>0&&M.height>0&&(M.width<32||M.height<32)&&F++}),F>3&&x.push(`ACCESSIBILITY: ${F} interactive elements are smaller than 32x32px. Minimum recommended touch target is 44x44px. Add padding to increase tap area.`),x});return R.length===0?{pass:!0,detail:"No design quality issues detected. Typography hierarchy, color usage, layout patterns, and accessibility basics look good."}:{pass:!1,detail:`${R.length} design quality issue(s) found:
|
|
5008
5008
|
${R.map((x,I)=>`${I+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(k),a.find(S=>S.name==="Landing page"&&S.status==="pass")){let S=await it(p,"Landing design quality",async()=>{await p.goto(t,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{});let R=await p.evaluate(()=>{let x=[];document.querySelectorAll("*").forEach(
|
|
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(k),a.find(S=>S.name==="Landing page"&&S.status==="pass")){let S=await it(p,"Landing design quality",async()=>{await p.goto(t,{waitUntil:"domcontentloaded",timeout:15e3}),await p.waitForLoadState("networkidle").catch(()=>{});let R=await p.evaluate(()=>{let x=[];document.querySelectorAll("*").forEach(_=>{let N=window.getComputedStyle(_);(N.getPropertyValue("-webkit-background-clip")||N.getPropertyValue("background-clip"))==="text"&&_.textContent&&_.textContent.trim().length>0&&x.push("SLOP: Gradient text detected. This is a common AI design pattern. Use solid colors for text.")});let q=document.querySelector("section, [class*='hero'], [class*='Hero'], header + div, main > div:first-child");if(q){let _=(q.textContent||"").toLowerCase(),N=["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 z of N)if(_.match(new RegExp(z))){x.push(`COPY: Generic hero text detected ('${z}'). Write specific copy about what THIS app does for its users.`);break}}return document.querySelectorAll('[class*="grid"]').forEach(_=>{let z=window.getComputedStyle(_).gridTemplateColumns;if(z){let ve=z.split(" ").filter(Y=>Y!=="").length,U=_.children;if(ve===3&&U.length===3){let Y=Array.from(U).map(D=>D.offsetHeight),W=Y.every(D=>Math.abs(D-Y[0])<5),J=Array.from(U).every(D=>{let ie=D.querySelectorAll("svg"),ee=D.querySelectorAll("h2, h3, h4"),ce=D.querySelectorAll("p");return ie.length>=1&&ee.length>=1&&ce.length>=1});W&&J&&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 R.length===0?{pass:!0,detail:"Landing page design looks intentional. No generic AI patterns detected."}:{pass:!1,detail:`${R.length} landing design issue(s):
|
|
5010
5010
|
${R.map((x,I)=>`${I+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(S)}}}finally{m&&await m.close().catch(()=>{})}if(s.deploymentId){let g=a.filter(h=>h.status==="fail"),v=a.filter(h=>h.status==="pass"),f=Date.now();await
|
|
5011
|
+
`)}`,fix:"These patterns make the landing page look AI-generated. Fix them to create a more distinctive, professional design."}});a.push(S)}}}finally{m&&await m.close().catch(()=>{})}if(s.deploymentId){let g=a.filter(h=>h.status==="fail"),v=a.filter(h=>h.status==="pass"),f=Date.now();await Xo(s.deploymentId,{checks:a.map(({screenshot:h,...k})=>k),overall:g.length===0?"pass":"fail",passed:v.length,failed:g.length,duration_ms:Date.now()-f}).catch(()=>{})}return Bt(t,a)}function Bt(s,o){let e=o.filter(a=>a.status==="fail"),t=o.filter(a=>a.status==="pass"),n=[];if(e.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=e.map((r,i)=>`${i+1}. **${r.name}**: ${r.detail}
|
|
5012
5012
|
Fix: ${r.fix}`).join(`
|
|
5013
5013
|
|
|
5014
5014
|
`);n.push({type:"text",text:JSON.stringify({status:"fail",message:`QA found ${e.length} issue(s) on the live app. Fix them and redeploy.`,url:s,passed:t.length,failed:e.length,checks:o.map(({screenshot:r,...i})=>i),fixInstructions:`The deployed app at ${s} has ${e.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
|
|
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 ya(s){let o=zt(fa(),".mistflow","plans",`${s}.json`);if(!qt(o))return null;try{let e=JSON.parse(ha(o,"utf-8"));return e.plan?e:null}catch{return null}}var ba=le.object({action:le.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. 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:le.string().optional().describe("(init) Project name"),planId:le.string().optional().describe("(init/mockup) Plan ID from mist_plan"),plan:le.any().optional().describe("(init) Full plan object \u2014 use planId instead when available"),path:le.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:le.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:le.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:le.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:le.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:le.string().optional().describe("Path to the project directory (default: cwd)"),step:le.number().optional().describe("(implement) Specific step number to implement"),buildOutput:le.string().optional().describe("(debug) Build output to parse instead of running a build"),feedback:le.string().optional().describe("(mockup) User feedback on the current mockup \u2014 describe what to change."),approved:le.boolean().optional().describe("(mockup) Set to true when the user approves the mockup. Locks in the design direction."),url:le.string().optional().describe("(qa) URL to test. Defaults to deploy URL from mistflow.json"),deploymentId:le.string().optional().describe("(qa) Deployment ID to associate QA results with. Passed from mist_deploy output.")}),Tr={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:ba,handler:async(s,o)=>{let e=s;switch(e.action){case"init":{if(!e.name)return d("Project name is required for init.",!0);let t=e.plan,n=null;if(e.planId){if(n=ya(e.planId),!n)return d(`Plan not found for planId '${e.planId}'. The plan may have expired. Call mist_plan again to generate a new plan.`,!0);t=n.plan}if(!t)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(t?.steps)||t.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 Fs({name:e.name,plan:t,path:e.path,projectId:n.projectId,sourceDeploymentId:n.sourceDeploymentId,forkToken:n.forkToken,requiredEnvVars:n.requiredEnvVars??[],dbProvider:n.dbProvider??"neon",planId:e.planId});if(e.landingDesign){let c=Xe(e.landingDesign);c?t.landingDesign=c.id:console.error(`Landing design '${e.landingDesign}' not found \u2014 ignoring.`)}e.appStyle&&(t.appStyle=e.appStyle);let a=t.design,i=t.audienceType==="b2c",l=e.heroPhoto??i;return t.design={...a??{},heroPhoto:l},Os({name:e.name,plan:t,path:e.path,planId:e.planId},o)}case"install":return Us({projectPath:e.projectPath},o);case"implement":return wr({projectPath:e.projectPath,step:e.step});case"debug":return vr({projectPath:e.projectPath,buildOutput:e.buildOutput});case"build":{let t=ga(e.projectPath??process.cwd());if(!qt(zt(t,"mistflow.json")))return d("Not a Mistflow project \u2014 mistflow.json not found. Run mist_build init first.",!0);if(!qt(zt(t,"node_modules")))try{Po("npm",["install"],{cwd:t,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{Po(a,["@opennextjs/cloudflare","build"],{cwd:t,stdio:["pipe","pipe","pipe"],timeout:18e4});let l=qt(zt(t,".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
5019
|
`+u;if(r<i){let g=[],v=/Module not found:\s*(?:Error:\s*)?Can't resolve ['"]([^'"]+)['"]/g,f;for(;(f=v.exec(m))!==null;){let h=f[1];if(!h.startsWith(".")&&!h.startsWith("@/")&&!h.startsWith("~/")){let k=h.startsWith("@")?h.split("/").slice(0,2).join("/"):h.split("/")[0];g.includes(k)||g.push(k)}}if(g.length>0){console.error(`[build] Auto-installing missing packages: ${g.join(", ")}`);try{Po("npm",["install",...g],{cwd:t,stdio:["pipe","pipe","pipe"],timeout:6e4});continue}catch{console.error("[build] Auto-install failed, reporting build errors")}}}let p=vt(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,v)=>{let f=g.file?`${g.file}${g.line?`:${g.line}`:""}`:"unknown";return`${v+1}. [${f}] ${g.humanMessage}
|
|
@@ -5023,12 +5023,12 @@ Fix these issues in the source code, then call mist_deploy with action='deploy'$
|
|
|
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
|
|
5026
|
+
Fix these and run mist_build build again.`:"Build failed. Run mist_build with action='debug' for detailed analysis."}),!0)}}}case"qa":return Sr({projectPath:e.projectPath,url:e.url,deploymentId:e.deploymentId});case"mockup":return e.planId?nr({planId:e.planId,projectPath:e.projectPath,feedback:e.feedback,approved:e.approved}):d("planId is required for mockup. Pass the planId from mist_plan.",!0);default:return d(`Unknown action: ${e.action}. Use mockup, init, implement, build, debug, or qa.`,!0)}}};import{z as Je}from"zod";import{z as Wt}from"zod";import{resolve as Mr,join as te,dirname as Vt,basename as La}from"path";import{existsSync as de,readFileSync as $r,writeFileSync as Oa,unlinkSync as Ir,mkdirSync as Ua,cpSync as Ro,rmSync as No,readdirSync as Fa}from"fs";import{execFileSync as Ba}from"child_process";import{spawn as qa}from"child_process";import{tmpdir as za}from"os";function Pr(s,o){if(s instanceof xe)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 t=Rt(),n=t?.orgSlug?.replace(/^user_user_/,"")||void 0,a=t?.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 e=s instanceof Error?s.message:String(s);return d(`${o} failed: ${e}`,!0)}import{existsSync as Ue,readFileSync as kt,readdirSync as Ao,statSync as Co}from"fs";import{join as Te,relative as Ht}from"path";import{execFileSync as xp}from"child_process";function wa(s){let o=Te(s,".env.local"),e=[];return Ue(o)?(kt(o,"utf-8").match(/^AUTH_SECRET=(.*)$/m)?.[1]?.trim()||e.push({check:"env",message:"AUTH_SECRET is missing from .env.local. Add a random secret for authentication.",file:".env.local"}),e):(e.push({check:"env",message:"Missing .env.local file. Create one with your local development environment variables (AUTH_SECRET, etc.).",file:".env.local"}),e)}function va(s){let o=Te(s,"app","api","auth","[...all]","route.ts");return Ue(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 ka(s){let o=Te(s,"app","api","health","route.ts");return Ue(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 xa(s){let o=Te(s,"mistflow.json");if(!Ue(o))return[];let e;try{e=JSON.parse(kt(o,"utf-8"))}catch{return[]}let t=e.env;if(!t?.required||typeof t.required!="object")return[];let n=[],a=Te(s,".env"),r="";try{Ue(a)&&(r=kt(a,"utf-8"))}catch{}for(let[i,l]of Object.entries(t.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 Sa(s){let o=Te(s,"app");if(!Ue(o))return[];let e=[];function t(r){let i;try{i=Ao(r)}catch{return}for(let l of i){if(l==="node_modules"||l===".next"||l===".open-next"||l==="api")continue;let c=Te(r,l),u;try{u=Co(c)}catch{continue}if(u.isDirectory())t(c);else if(l==="page.tsx"||l==="page.ts"||l==="page.jsx"||l==="page.js"){let p="/"+Ht(o,c).replace(/\\/g,"/").replace(/\([^)]+\)\//g,"").replace(/\/page\.(tsx?|jsx?)$/,"").replace(/^page\.(tsx?|jsx?)$/,"");e.push({file:Ht(s,c),resolvedRoute:p||"/"})}}}t(o);let n=new Map;for(let r of e){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 Ta(s){let o=Te(s,"app");if(!Ue(o))return[];let e=[];function t(n){let a;try{a=Ao(n)}catch{return}for(let r of a){if(r==="node_modules"||r===".next"||r===".open-next")continue;let i=Te(n,r),l;try{l=Co(i)}catch{continue}if(l.isDirectory())t(i);else if(r==="actions.ts"||r==="actions.tsx"){let c=kt(i,"utf-8");c.includes("use server")&&c.includes("cookies()")&&c.includes(".set(")&&e.push(Ht(s,i))}}}return t(o),e.length>0?[{check:"cookies-in-actions",message:`${e.length} server action(s) use cookies().set() which crashes on Mistflow Cloud's edge runtime: ${e.join(", ")}. Use a database field or form parameter instead.`,file:e[0]}]:[]}function Pa(s){let o=/\b(useState|useEffect|useRef|useCallback|useMemo|useReducer|useContext|useLayoutEffect|useTransition)\s*\(/,e=[];function t(n){if(!Ue(n))return;let a;try{a=Ao(n)}catch{return}for(let r of a){if(r==="node_modules"||r===".next"||r===".open-next"||r==="ui")continue;let i=Te(n,r),l;try{l=Co(i)}catch{continue}if(l.isDirectory())t(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=kt(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=Ht(s,i);e.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 t(Te(s,"app")),t(Te(s,"components")),e}function Ar(s){let o=[...wa(s),...va(s),...ka(s),...Sa(s),...Ta(s),...Pa(s)],e=[...xa(s)];return{passed:o.length===0,errors:o,warnings:e}}import{existsSync as Se,readFileSync as Ye,readdirSync as Gt,statSync as xt}from"fs";import{join as V}from"path";async function Cr(s,o){let e=[];e.push(Aa(s)),e.push(Ca(s)),e.push(Ia(s)),e.push(Ra(s)),e.push(Na(s)),e.push(Ma(s)),o?.plan&&e.push(...Ea(s,o)),e.push(_a(s)),e.push(Da(s)),e.push(...ja(s)),e.push($a(s));let t=e.filter(c=>c.status==="fail"),n=e.filter(c=>c.status==="warn"),a=e.filter(c=>c.status==="pass"),r=t.length>0,i=!r,l;return i&&n.length===0?l=`All ${e.length} checks passed`:i?l=`${a.length}/${e.length} passed, ${n.length} warning(s)`:l=`${t.length} issue(s) found:
|
|
5027
5027
|
${t.map(c=>` - ${c.message}`).join(`
|
|
5028
|
-
`)}`,{passed:i,blocking:r,checksRun:e.length,checks:e,summary:l}}function
|
|
5028
|
+
`)}`,{passed:i,blocking:r,checksRun:e.length,checks:e,summary:l}}function Aa(s){let o=V(s,".open-next","worker.js");if(!Se(o))return{name:"worker-exists",status:"fail",message:"worker.js not found in build output. The build may have failed silently."};let e=Ye(o,"utf-8");return e.length<1e3?{name:"worker-exists",status:"warn",message:`worker.js is unusually small (${e.length} bytes). The build output may be incomplete.`}:{name:"worker-exists",status:"pass",message:"Worker bundle exists"}}function Ca(s){let o=V(s,".open-next","assets");if(!Se(o))return{name:"assets-exist",status:"warn",message:"No static assets directory in build output. CSS and images may not load."};let e=0;function t(n){try{for(let a of Gt(n)){let r=V(n,a);try{xt(r).isDirectory()?t(r):e++}catch{}}}catch{}}return t(o),e===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:`${e} static assets ready`}}function Ia(s){let o=V(s,"app","api","health","route.ts");return Se(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 Ra(s){let o=V(s,"app","api","auth","[...all]","route.ts");return Se(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 Na(s){let o=V(s,".open-next","worker.js");if(!Se(o))return{name:"worker-size",status:"pass",message:"Worker size check skipped"};let t=xt(o).size/(1024*1024);return t>60?{name:"worker-size",status:"fail",message:`Worker bundle is ${t.toFixed(1)}MB \u2014 exceeds Mistflow Cloud's 64MB worker bundle limit.`}:t>30?{name:"worker-size",status:"warn",message:`Worker bundle is ${t.toFixed(1)}MB \u2014 large but within Mistflow Cloud limits. May be slow to upload.`}:{name:"worker-size",status:"pass",message:`Worker bundle: ${t.toFixed(1)}MB`}}function Ea(s,o){let e=[],t=new Set;if(o.plan?.pages)for(let r of o.plan.pages){let i=r.path??r.route??r.name;i&&t.add(i.replace(/^\//,""))}if(t.size===0)return[];let n=0,a=[];for(let r of t){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=>Se(l))?n++:a.push(`/${r}`)}return a.length===0?e.push({name:"plan-routes",status:"pass",message:`All ${t.size} planned pages found`}):a.length<=2?e.push({name:"plan-routes",status:"warn",message:`${n}/${t.size} planned pages found. Missing: ${a.join(", ")}`}):e.push({name:"plan-routes",status:"warn",message:`Only ${n}/${t.size} planned pages found. ${a.length} pages missing.`}),e}function _a(s){let o=V(s,"app");if(!Se(o))return{name:"empty-pages",status:"pass",message:"App directory check skipped"};let e=[];function t(n){try{for(let a of Gt(n)){let r=V(n,a);try{if(xt(r).isDirectory())t(r);else if(a==="page.tsx"||a==="page.ts"){let l=Ye(r,"utf-8").trim();if(l.length<50||l.includes("export default function")&&l.includes("TODO")){let c=r.replace(s+"/","");e.push(c)}}}catch{}}}catch{}}return t(o),e.length>0?{name:"empty-pages",status:"warn",message:`${e.length} page(s) appear to be empty/placeholder: ${e.slice(0,3).join(", ")}`}:{name:"empty-pages",status:"pass",message:"No empty pages detected"}}function Da(s){let o=V(s,"app","page.tsx");if(!Se(o))return{name:"landing-page",status:"warn",message:"No root page.tsx found"};let e=Ye(o,"utf-8");if(e.includes('redirect("/login")')||e.includes('redirect("/register")')){let t=V(s,"middleware.ts"),n=Se(t)?Ye(t,"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 e.length<200?{name:"landing-page",status:"warn",message:`Landing page is very small (${e.length} chars) \u2014 may be a placeholder.`}:{name:"landing-page",status:"pass",message:"Landing page has content"}}function Ma(s){let o=V(s,"app");if(!Se(o))return{name:"cookies-in-actions",status:"pass",message:"No app directory"};let e=[];function t(n){try{for(let a of Gt(n)){if(a==="node_modules"||a===".next"||a===".open-next")continue;let r=V(n,a);try{if(xt(r).isDirectory())t(r);else if(a==="actions.ts"||a==="actions.tsx"){let l=Ye(r,"utf-8");l.includes("use server")&&l.includes("cookies()")&&l.includes(".set(")&&e.push(r.replace(s+"/",""))}}catch{}}}catch{}}return t(o),e.length>0?{name:"cookies-in-actions",status:"fail",message:`${e.length} server action(s) use cookies().set() which crashes on Mistflow Cloud's edge runtime: ${e.join(", ")}. Use a database field or form parameter instead.`}:{name:"cookies-in-actions",status:"pass",message:"No cookies().set() in server actions"}}function $a(s){let o=V(s,"app");if(!Se(o))return{name:"fake-forms",status:"pass",message:"No app directory"};let e=[];function t(n){try{for(let a of Gt(n)){if(a==="node_modules"||a===".next"||a===".open-next")continue;let r=V(n,a);try{if(xt(r).isDirectory())t(r);else if(a.endsWith(".tsx")||a.endsWith(".ts")){let l=Ye(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+"/","");e.push(c)}}}catch{}}}catch{}}return t(o),e.length>0?{name:"fake-forms",status:"fail",message:`${e.length} file(s) have fake/simulated API calls instead of real server actions: ${e.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 ja(s){let e=[V(s,"components","sidebar.tsx"),V(s,"components","topnav.tsx"),V(s,"components","nav.tsx")].find(i=>Se(i));if(!e)return[];let a=(Ye(e,"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=>Se(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 Ee(s,o){return Ba("git",s,{cwd:o,encoding:"utf-8",timeout:3e4,stdio:["pipe","pipe","pipe"]}).trim()}function Io(s){try{return Ee(["rev-parse","--is-inside-work-tree"],s),!0}catch{return!1}}function Rr(s){try{return Ee(["status","--porcelain"],s).length>0}catch{return!1}}function Nr(s,o){return Ee(["add","-A"],s),Ee(["commit","-m",o,"--allow-empty-message"],s),Ee(["rev-parse","HEAD"],s)}function Ha(s){return Ee(["rev-parse","HEAD"],s)}function Er(s){try{return Ee(["remote","get-url","origin"],s),!0}catch{return!1}}function Ga(s){try{let o=Ee(["rev-parse","--abbrev-ref","HEAD"],s);return Ee(["push","origin",o],s),{success:!0}}catch(o){return{success:!1,error:o instanceof Error?o.message:"push failed"}}}function Wa(s){let o=Vt(Mr(s)),e=Vt(o)===o?o:"/";for(;o!==e&&o!==Vt(o);){if(de(te(o,"pnpm-workspace.yaml"))||de(te(o,"lerna.json")))return o;let t=te(o,"package.json");if(de(t))try{if(JSON.parse($r(t,"utf-8")).workspaces)return o}catch{}o=Vt(o)}return null}function Va(s){let o=te(za(),"mistflow-build");Ua(o,{recursive:!0});let e=te(o,`${La(s)}-${Date.now()}`);return Ro(s,e,{recursive:!0,filter:t=>{let n=t.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/"))}}),e}function Ya(s,o){let e=te(s,".open-next"),t=te(s,".next");if(de(e)){let n=te(o,".open-next");de(n)&&No(n,{recursive:!0}),Ro(e,n,{recursive:!0})}if(de(t)){let n=te(o,".next");de(n)&&No(n,{recursive:!0}),Ro(t,n,{recursive:!0})}}function Ja(s){try{No(s,{recursive:!0,force:!0})}catch{console.error(`[deploy] Failed to clean up isolated build dir: ${s}`)}}function at(s,o,e,t,n,a){return new Promise(r=>{let i=qa(s,o,{cwd:e,stdio:["pipe","pipe","pipe"],timeout:t,...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
|
|
5031
|
-
`)}async function
|
|
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 Bp=Wt.object({projectPath:Wt.string().optional().describe("Path to the project directory (default: current working directory)"),message:Wt.string().optional().describe("Deploy message"),environment:Wt.enum(["production","preview"]).optional().default("production").describe("Target environment: 'production' (default) or 'preview' for a shareable URL")});function Ka(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 Eo(s){let o=te(s,"mistflow.json");if(de(o))try{return JSON.parse($r(o,"utf-8"))}catch{}return{}}function Qa(s,o){let e=te(s,"mistflow.json"),t=Eo(s),n=t.deploy?.count??t.deployCount??0;t.deploy={url:o,count:n+1,lastDeployedAt:new Date().toISOString()};let a=t.plan?.steps;if(Array.isArray(a))for(let r of a)r.status==="in_progress"&&(r.status="completed");delete t.deployUrl,delete t.deployCount,Oa(e,JSON.stringify(t,null,2)+`
|
|
5031
|
+
`)}async function jr(s,o){let t=process.platform==="win32"?"npx.cmd":"npx",n=0,a=te(s,"node_modules",".bin","opennextjs-cloudflare"),r=de(a),i={...process.env,NODE_ENV:"production"},l=await at(r?a:t,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=vt(c);if(u.length>0){let p=u.map((g,v)=>{let f=`${v+1}. ${g.humanMessage}`;return g.suggestion&&(f+=`
|
|
5033
5033
|
Fix: ${g.suggestion}`),f}).join(`
|
|
5034
5034
|
|
|
@@ -5038,59 +5038,59 @@ ${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
|
|
5042
|
-
${a.stderr.slice(-300)}`};await at(n,["dedupe"],e,6e4);let r=await
|
|
5041
|
+
${c.slice(-500)}`}}async function Xa(s,o){let e=Wa(s);if(e)return console.error(`[deploy] Project is inside monorepo at ${e} \u2014 building in isolated temp directory`),o?.("Detected parent project folder \u2014 building in isolated directory..."),Dr(s,o);let t=await jr(s,o);return!t.success&&t.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..."),Dr(s,o)):t}async function Dr(s,o){let e;try{o?.("Copying project to isolated build directory..."),e=Va(s),o?.("Installing dependencies...");let n=process.platform==="win32"?"npm.cmd":"npm",a=await at(n,["install","--prefer-offline"],e,12e4);if(!a.success)return{success:!1,error:`Failed to install dependencies in isolated build:
|
|
5042
|
+
${a.stderr.slice(-300)}`};await at(n,["dedupe"],e,6e4);let r=await jr(e,o);return r.success&&(o?.("Copying build artifacts..."),Ya(e,s)),{...r,builtInIsolation:e}}finally{e&&Ja(e)}}async function Za(s,o,e){if(!de(te(s,"db","schema")))return{success:!0,skipped:!0,skipReason:"No database structure found"};let t=te(s,"db","schema");try{if(Fa(t).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(!de(te(s,"drizzle.config.ts")))return{success:!0,skipped:!0,skipReason:"No drizzle.config.ts found"};let n;try{n=await Ko(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 at(c,e?["drizzle-kit","push","--force"]:["drizzle-kit","push"],s,6e4,p=>{let g=p.replace(/(?:TURSO_AUTH_TOKEN|DATABASE_URL|AUTH_SECRET)=[^\s&]*/gi,v=>v.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 v=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
|
${v.length>0?v.join(`
|
|
5046
|
-
`):p.slice(-500)}`}}return{success:!0}}async function
|
|
5046
|
+
`):p.slice(-500)}`}}return{success:!0}}async function Lr(s,o){let{projectPath:e,message:t,environment:n="production",forceSchema:a}=s,r=n,i=Mr(e??process.cwd());if(!fe())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let l=Ar(i);if(!l.passed){let T=l.errors.map(j=>{let F=`[${j.check}] ${j.message}`;return j.file&&(F+=` (${j.file}${j.line?`:${j.line}`:""})`),F}).join(`
|
|
5047
5047
|
`);return d(`Deploy blocked \u2014 fix these issues first:
|
|
5048
5048
|
|
|
5049
|
-
${T}`,!0)}let c=l.warnings.map(T=>`[${T.check}] ${T.message}`),u;if(Io(i))if(
|
|
5049
|
+
${T}`,!0)}let c=l.warnings.map(T=>`[${T.check}] ${T.message}`),u;if(Io(i))if(Rr(i))try{let T=Eo(i).deploy?.count??0,j=t?`Deploy v${T+1}: ${t}`:`Deploy v${T+1}`;u=Nr(i,j)}catch{console.error("[deploy] Pre-deploy git commit failed, continuing")}else try{u=Ha(i)}catch{}let m=te(i,"mistflow.json");if(!de(m))return d("No mistflow.json found. Run mist_build (action: 'init') first to set up your project.",!0);let p;try{let{ensureBackendRegistered:T}=await import("./self-heal-BXJXUFUF.js");p=await T(i,{forceSync:!0})}catch(T){let j=T instanceof xe?T.message:"Check your internet connection.";return d(`Could not register project with Mistflow: ${j}
|
|
5050
5050
|
|
|
5051
|
-
Try deploying again in a moment.`,!0)}if(p||(p=Ae(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 T=await qo(p)
|
|
5051
|
+
Try deploying again in a moment.`,!0)}if(p||(p=Ae(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 T=await qo(p),j=T,F=j.deploy_count??T.deployCount??0;(j.deploy_strategy??T.deploy_strategy)==="staging"&&F>0&&(r="preview",console.error("[deploy] Staging mode enabled \u2014 auto-redirecting to preview"))}catch{}let g=[],v=Date.now(),f=(T,j)=>{let F={phase:T,message:j};return g.push(F),F},h=(T,j)=>{T.durationMs=Date.now()-v,j&&(T.message=j)};if(o){let T=gt(o.server,o.progressToken,()=>g[g.length-1]?.message??"Deploying...");o.cleanup=()=>T.stop()}let k=!1;if(p&&r!=="preview"){let T=f("schema","Updating database structure..."),j=await Za(i,p,a);if(j.skipped)h(T,j.skipReason??"Database update skipped");else if(j.success)k=!0,h(T,"Database updated successfully");else return h(T,"Database update failed"),d(`Deploy blocked \u2014 database update failed:
|
|
5052
5052
|
|
|
5053
|
-
${
|
|
5053
|
+
${j.error}
|
|
5054
5054
|
|
|
5055
|
-
Try deploying again in a moment. If it keeps failing, check your database files in db/schema/.`,!0)}let S=f("build","Compiling your app for Mistflow Cloud..."),R=Date.now(),x=await
|
|
5055
|
+
Try deploying again in a moment. If it keeps failing, check your database files in db/schema/.`,!0)}let S=f("build","Compiling your app for Mistflow Cloud..."),R=Date.now(),x=await Xa(i,T=>{S.message=T});if(!x.success)return d(`Deploy blocked \u2014 OpenNext build failed:
|
|
5056
5056
|
|
|
5057
|
-
${x.error}`,!0);h(S,`Build complete \u2014 ${x.buildStats??"ready"} (${((Date.now()-R)/1e3).toFixed(0)}s)`);let I=f("qa","Running smoke tests..."),q=Ae(i),A=await
|
|
5057
|
+
${x.error}`,!0);h(S,`Build complete \u2014 ${x.buildStats??"ready"} (${((Date.now()-R)/1e3).toFixed(0)}s)`);let I=f("qa","Running smoke tests..."),q=Ae(i),A=await Cr(i,q);if(A.passed)h(I,`Smoke test passed \u2014 ${A.checksRun} checks OK`);else if(h(I,`Smoke test: ${A.summary}`),A.blocking)return d(`Deploy blocked \u2014 smoke test failed:
|
|
5058
5058
|
|
|
5059
5059
|
${A.summary}
|
|
5060
5060
|
|
|
5061
|
-
Fix these issues and try again.`,!0);let
|
|
5062
|
-
`),C.nextAction=`MANDATORY: Call mist_build with action='qa' and url='${F}' to verify the preview. After QA passes, ask user to confirm, then call mist_deploy action='promote'.`,C.qaRequired=!0,C.qaUrl=F,C.previewDeploymentId=W,C.promoteAction=`mist_deploy action='promote' deploymentId='${W}'`;else{let b=encodeURIComponent(`Just built "${ke}" with AI and deployed it live in ${
|
|
5061
|
+
Fix these issues and try again.`,!0);let _=te(i,".open-next");if(!de(_))return d("Build succeeded but .open-next/ directory not found. Check your OpenNext configuration.",!0);f("package","Packaging build artifacts...");let N=te(i,".open-next-build.tar.gz"),z=[".open-next"];if(de(te(i,"db"))&&z.push("db"),de(te(i,"drizzle.config.ts"))&&z.push("drizzle.config.ts"),de(te(i,"package.json"))&&z.push("package.json"),!(await at("tar",["-czf",N,"-C",i,...z],i,6e4)).success)return d("Failed to create build archive. Check disk space and permissions.",!0);let U;{let T=te(i,".mistflow-source.tar.gz");(await at("tar",["-czf",T,"-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?U=T:console.error("[deploy] Source archive creation failed, continuing without it")}f("upload","Uploading to Mistflow...");let Y=Rt()?.email,W,J;try{let T=await Go(p,N,r,Y,k,U,u);if(W=T.deployment_id??T.id,!W)return d("Upload succeeded but no deployment ID was returned. Check the Mistflow dashboard.",!0);J=T.status}catch(T){return Pr(T,"Deploy")}finally{try{Ir(N)}catch{}if(U)try{Ir(U)}catch{}}f("deploying","Deploying to the edge...");let D=Date.now(),ie=24e4,ee=3e3,ce=[_r(J)],se=J;for(;Date.now()-D<ie;){await Ka(ee);let T;try{T=await $e(W)}catch{continue}if(T.status!==se&&(ce.push(_r(T.status)),se=T.status),T.status==="live"){let j=((Date.now()-D)/1e3).toFixed(0),F=T.url??"";if(!F)return d("Deployment marked as live but no URL was returned. Check the Mistflow dashboard.",!0);let w=r==="preview";if(!w){Qa(i,F);try{let{readLocalState:b,syncRemoteState:$}=await import("./state-manager-GBP2NSYC.js"),E=b(i);E&&p&&(E.deployCount=(E.deployCount??0)+1,$(p,E).catch(()=>{}))}catch{}if(Io(i)&&Er(i))try{Rr(i)&&Nr(i,"Update deploy metadata"),Ga(i)}catch{}}let M=w?"Preview":"App",K=Eo(i),ue=K.name,ke=typeof ue=="string"?ue:"my app",P=K.features,L=Array.isArray(P)?P.length:0,H=K.plan,Q=H&&typeof H=="object"&&"steps"in H?H.steps:void 0,oe=Array.isArray(Q)?Q.length:0,me=g.map(b=>b.message),C={url:F,time:`${j}s`,deploymentId:W,environment:r,statusLog:ce,deployTimeline:me,message:w?`${M} is live at ${F} \u2014 preview deployed in ${j}s. This URL expires in 72 hours.`:`Your app is live at ${F} \u2014 deployed in ${j}s.`};if(w)C.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='"+F+"' 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
|
+
`),C.nextAction=`MANDATORY: Call mist_build with action='qa' and url='${F}' to verify the preview. After QA passes, ask user to confirm, then call mist_deploy action='promote'.`,C.qaRequired=!0,C.qaUrl=F,C.previewDeploymentId=W,C.promoteAction=`mist_deploy action='promote' deploymentId='${W}'`;else{let b=encodeURIComponent(`Just built "${ke}" with AI and deployed it live in ${j}s.
|
|
5063
5063
|
|
|
5064
5064
|
${oe} steps, ${L} features, zero config.
|
|
5065
5065
|
|
|
5066
5066
|
${F}
|
|
5067
5067
|
|
|
5068
|
-
Built with @mistflow`)
|
|
5068
|
+
Built with @mistflow`),$=encodeURIComponent(`I just described an app idea and got a live, working URL in ${j} seconds.
|
|
5069
5069
|
|
|
5070
5070
|
"${ke}" \u2014 ${oe} build steps, ${L} features, fully deployed.
|
|
5071
5071
|
|
|
5072
5072
|
${F}
|
|
5073
5073
|
|
|
5074
|
-
Built with Mistflow (mistflow.ai)`);C.share={tweetUrl:`https://twitter.com/intent/tweet?text=${b}`,linkedInUrl:`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(F)}`,celebration:["","================================================",` ${ke} is LIVE!`,"================================================","",` ${F}`,"",` Deployed in ${
|
|
5074
|
+
Built with Mistflow (mistflow.ai)`);C.share={tweetUrl:`https://twitter.com/intent/tweet?text=${b}`,linkedInUrl:`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(F)}`,celebration:["","================================================",` ${ke} is LIVE!`,"================================================","",` ${F}`,"",` Deployed in ${j}s`,` ${L>0?`${L} features`:""}${L>0&&oe>0?" \xB7 ":""}${oe>0?`${oe} build steps`:""}`,""," Share it:",` Twitter \u2192 https://twitter.com/intent/tweet?text=${b}`,` LinkedIn \u2192 https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(F)}`,"","================================================"].join(`
|
|
5075
5075
|
`)},C.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
|
-
`),C.nextAction=`MANDATORY: Call mist_build with action='qa' and url='${F}' to verify the app works. Do NOT tell the user the app is ready until QA passes.`,C.qaRequired=!0,C.qaUrl=F}K.hasAdmin&&!w&&Y&&(C.adminSetup={message:`Your app is live. You're the admin \u2014 sign up at ${F}/signup with ${Y} to create your admin account. You'll pick your own password; the /admin panel unlocks as soon as you sign up.`}),c.length>0&&(C.warnings=c);let y=[];if(!w){let b=JSON.stringify(K).toLowerCase();y.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"}),Io(i)&&!
|
|
5077
|
-
`),m.nextAction=`MANDATORY: Call mist_build with action='qa' and url='${u}' to verify production.`,m.qaRequired=!0,m.qaUrl=u,u?je(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
|
|
5078
|
-
`)){let n=t.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
|
|
5076
|
+
`),C.nextAction=`MANDATORY: Call mist_build with action='qa' and url='${F}' to verify the app works. Do NOT tell the user the app is ready until QA passes.`,C.qaRequired=!0,C.qaUrl=F}K.hasAdmin&&!w&&Y&&(C.adminSetup={message:`Your app is live. You're the admin \u2014 sign up at ${F}/signup with ${Y} to create your admin account. You'll pick your own password; the /admin panel unlocks as soon as you sign up.`}),c.length>0&&(C.warnings=c);let y=[];if(!w){let b=JSON.stringify(K).toLowerCase();y.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"}),Io(i)&&!Er(i)&&y.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 $=b.includes("user")||b.includes("account")||b.includes("member"),E=b.includes("stripe")||b.includes("payment")||b.includes("billing");$&&!E&&y.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"}),y.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"}),y.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"}),y.push({action:"See analytics",command:`Visit ${Uo()} to see pageviews and visitors`,reason:"Track how people are using your app.",priority:"low"})}return y.length>0&&(C.nextSteps=y),je(F,JSON.stringify(C))}if(T.status==="failed")return d(T.error??"Deployment failed. Check the Mistflow dashboard for details.",!0)}return d(`Deploy is taking longer than expected. Your deploy ID is ${W} \u2014 check status later.`,!0)}import{z as Yt}from"zod";import{resolve as el,join as tl}from"path";import{execFileSync as ol}from"child_process";var Jp=Yt.object({projectPath:Yt.string().optional().describe("Path to the project directory (default: cwd)"),action:Yt.enum(["redeploy","rollback"]).describe("Action to perform: 'redeploy' re-deploys the latest build, 'rollback' reverts to a specific previous deployment"),deploymentId:Yt.string().optional().describe("Deployment ID to rollback to (required for 'rollback')")});function Fe(s,o){return ol("git",s,{cwd:o,encoding:"utf-8",timeout:3e4,stdio:["pipe","pipe","pipe"]}).trim()}function Or(s){try{return Fe(["rev-parse","--is-inside-work-tree"],s),!0}catch{return!1}}async function sl(s,o,e,t){if(o&&Or(s))try{Fe(["cat-file","-t",o],s);let n=!1;try{Fe(["status","--porcelain"],s).length>0&&(Fe(["stash","push","-m","mistflow-rollback-auto-stash"],s),n=!0)}catch{}return Fe(["reset","--hard",o],s),Fe(["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(e&&t)try{let{existsSync:n,mkdirSync:a,rmSync:r}=await import("fs"),i=tl(s,".mistflow-rollback-source.tar.gz");await as(t,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(Or(s))try{Fe(["add","-A"],s),Fe(["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 rl(s){return new Promise(o=>setTimeout(o,s))}function nl(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 Ur(s,o,e){let t=Date.now(),n=12e4,a=3e3,r=[],i="";for(;Date.now()-t<n;){await rl(a);let l;try{l=await $e(s)}catch{continue}if(l.status!==i&&(r.push(nl(l.status)),i=l.status),l.status==="live"){let c=((Date.now()-t)/1e3).toFixed(0),u=l.url??"";if(e)try{await e()}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:e,deploymentId:t}=s,n=el(o??process.cwd());if(!fe())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let r=Ae(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(e){case"redeploy":{let i=await rs(r);return Ur(i.deployment_id,"Redeploy")}case"rollback":{if(!t)return d("Deployment ID is required for rollback. Use mist_project (action: 'deployments') to see previous deployment IDs.",!0);let i=await is(t);return Ur(i.deployment_id,"Rollback",async()=>{let l=await sl(n,i.git_commit_sha,i.source_artifact_key,t);l.success||console.error(`[rollback] Local source restore failed: ${l.error}`),l.warning&&console.error(`[rollback] ${l.warning}`)})}default:return d(`Unknown action: ${e}. Use redeploy or rollback.`,!0)}}catch(i){if(i instanceof xe)return d(i.message,!0);let l=i instanceof Error?i.message:"An unexpected error occurred";return d(l,!0)}}import{resolve as il}from"path";function al(s){return new Promise(o=>setTimeout(o,s))}async function Fr(s){let o=il(s.projectPath??process.cwd());if(!fe())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let t=Ae(o)?.projectId;if(!t)return d("No project ID found. Deploy the project first.",!0);let n=s.deploymentId;if(!n)try{let c=(await mt(t)).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 ns(t,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 al(3e3);try{let l=await $e(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?je(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 Br}from"zod";import{spawn as dl,execFileSync as qr}from"child_process";import{existsSync as Kt,readFileSync as zr,writeFileSync as pl,mkdirSync as ul}from"fs";import{join as lt,resolve as ml}from"path";import{homedir as Hr}from"os";import{createConnection as hl}from"net";import{existsSync as ll,readFileSync as cl}from"fs";function Jt(s){let o=new Set;if(!ll(s))return o;let e=cl(s,"utf-8");for(let t of e.split(`
|
|
5078
|
+
`)){let n=t.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 gl=Br.object({projectPath:Br.string().optional().describe("Path to the project directory (default: current working directory)")});function Gr(){return lt(Hr(),".mistflow","processes.json")}function Wr(){let s=Gr();if(!Kt(s))return[];try{return JSON.parse(zr(s,"utf-8"))}catch{return[]}}function Vr(s){let o=lt(Hr(),".mistflow");Kt(o)||ul(o,{recursive:!0}),pl(Gr(),JSON.stringify(s,null,2))}function fl(){let s=Wr(),o=[];for(let e of s)try{process.kill(e.pid,0),o.push(e)}catch{}Vr(o)}function Yr(s){return new Promise(o=>{let e=hl({port:s,host:"127.0.0.1"});e.on("connect",()=>{e.destroy(),o(!0)}),e.on("error",()=>{o(!1)})})}async function yl(s,o,e){let t=Date.now();for(;Date.now()-t<o;){if(await Yr(s))return!0;await new Promise(n=>setTimeout(n,e))}return!1}function bl(s){return Kt(lt(s,"mistflow.json"))}function wl(s){let o=lt(s,"mistflow.json");if(!Kt(o))return[];let e;try{e=JSON.parse(zr(o,"utf-8"))}catch{return[]}let t=e.env?.required;if(!t||typeof t!="object")return[];let n=Object.keys(t);if(n.length===0)return[];let a=Jt(lt(s,".env.local"));return n.filter(r=>!a.has(r))}var Jr={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:gl,handler:async s=>{let e=ml(s.projectPath??process.cwd()),t=3e3;if(!bl(e))return Ce(e);let n=wl(e);if(n.length>0)return d(`Missing required environment variables in .env.local: ${n.join(", ")}. Add them to ${lt(e,".env.local")} before previewing.`,!0);fl();let a=await Yr(t),r=Wr(),i=r.some(m=>m.type==="dev-server"&&m.port===t);if(a&&!i)return d(`Port ${t} is in use. Stop the other process or I will use a different port.`,!0);let l=[...r];if(!a){try{qr("npx",["drizzle-kit","push"],{cwd:e,stdio:["pipe","pipe","pipe"],timeout:3e4})}catch{console.error("[preview] drizzle-kit push failed, continuing...")}try{qr("npm",["run","build"],{cwd:e,stdio:["pipe","pipe","pipe"],timeout:18e4})}catch(v){let f=v instanceof Error&&"stderr"in v?String(v.stderr).slice(-1500):"",h=v instanceof Error&&"stdout"in v?String(v.stdout).slice(-1500):"",k=(f+`
|
|
5079
5079
|
`+h).trim();return d(`Build failed. Fix the errors before previewing:
|
|
5080
5080
|
|
|
5081
|
-
${k}`,!0)}let m=
|
|
5081
|
+
${k}`,!0)}let m=dl("npx",["next","start","-p",String(t)],{cwd:e,detached:!0,stdio:["ignore","pipe","pipe"]}),p="";if(m.stderr?.on("data",v=>{p+=v.toString()}),m.pid&&(m.unref(),l.push({pid:m.pid,type:"dev-server",port:t,startedAt:new Date().toISOString()}),Vr(l)),!await yl(t,15e3,500)){let v=p?`Server failed to start:
|
|
5082
5082
|
|
|
5083
|
-
${p.slice(-1e3)}`:"Server failed to start within 15s. Check for runtime errors.";return d(v,!0)}}let c=`http://localhost:${t}`,u=JSON.stringify({localUrl:c,message:`Preview is live at ${c}. Run mist_deploy to get your permanent URL on mistflow.app.`});return je(c,u)}};import{resolve as
|
|
5084
|
-
`),nextSteps:v}))}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}`)),
|
|
5085
|
-
`),n.projectId&&import("./state-manager-
|
|
5083
|
+
${p.slice(-1e3)}`:"Server failed to start within 15s. Check for runtime errors.";return d(v,!0)}}let c=`http://localhost:${t}`,u=JSON.stringify({localUrl:c,message:`Preview is live at ${c}. Run mist_deploy to get your permanent URL on mistflow.app.`});return je(c,u)}};import{resolve as vl,join as kl}from"path";import{existsSync as xl,readFileSync as Sl}from"fs";var Do="test@mistflow.dev",Kr="MistflowTest123!",Tl="Test User";function Qr(s){let o=kl(s,"mistflow.json");if(!xl(o))return null;try{return JSON.parse(Sl(o,"utf-8"))}catch{return null}}function Pl(s){let o=JSON.stringify(s).toLowerCase();return["auth","login","sign-in","sign-up","signin","signup"].some(e=>o.includes(e))}function Al(s){let o=s.plan;if(!o?.steps)return[];let e=new Set;for(let n of o.steps)if(n.pages)for(let a of n.pages)e.add(a);let t=new Set(["login","signup","sign-in","sign-up","signin","signout","sign-out","logout"]);return[...e].filter(n=>!t.has(n.toLowerCase())).slice(0,3)}function Cl(s){let o=s.deploy;return o?.url?o.url:typeof s.deployUrl=="string"?s.deployUrl:null}async function Xr(s){let o=vl(s.projectPath??process.cwd()),e=s.verifyUrl,t=null;if(e)t=Qr(o);else{if(t=Qr(o),!t)return d("No mistflow.json found. Run mist_deploy first, or pass verifyUrl explicitly.",!0);if(e=Cl(t)??void 0,!e)return d("No deploy URL found in mistflow.json. Deploy your app first with mist_deploy.",!0)}e.startsWith("http")||(e=`https://${e}`);let n=t?Pl(t):!1,a=t?Al(t):[],r;try{r=await Ct()}catch{return d("Browser not available. Install Playwright to use verify: npx playwright install chromium",!0)}let i={verified:!0,url:e,authTested:!1,testUser:null,pages:[],message:""},l=[];try{await r.goto(e,{waitUntil:"domcontentloaded",timeout:3e4}),await r.waitForLoadState("networkidle").catch(()=>{})}catch{return i.verified=!1,i.message=`Could not load ${e}. 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 Me(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 k=await fetch("/api/auth/sign-up/email",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)});return{status:k.status,ok:k.ok}},{email:Do,password:Kr,name:Tl})).ok||await r.evaluate(async h=>{let k=await fetch("/api/auth/sign-in/email",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)});return{status:k.status,ok:k.ok}},{email:Do,password:Kr}),await r.reload({waitUntil:"domcontentloaded",timeout:15e3}),await r.waitForLoadState("networkidle").catch(()=>{}),i.authTested=!0,i.testUser={email:Do};try{let h=await Me(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(`${e}${h}`,{waitUntil:"domcontentloaded",timeout:15e3}),await r.waitForLoadState("networkidle").catch(()=>{});let k=await r.title(),S=k.toLowerCase().includes("404")||k.toLowerCase().includes("not found")?"error":"ok";i.pages.push({path:h,status:S,title:k}),S==="error"&&(i.verified=!1);try{let R=await Me(r,!1);l.push({data:R.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 v=[{type:"text",text:JSON.stringify(i)}];for(let f of l)v.push({type:"image",data:f.data,mimeType:f.mimeType});return{content:v}}var Il=Je.object({action:Je.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:Je.string().optional().describe("Path to the project directory (default: cwd)"),environment:Je.enum(["production","preview"]).optional().describe("(deploy) Target environment. Defaults to 'production'. Projects with staging mode auto-redirect to preview."),forceSchema:Je.boolean().optional().describe("(deploy) Reset the database structure. Warning: this deletes existing data. Only use when the user confirms this is OK."),deploymentId:Je.string().optional().describe("(rollback/promote) Deployment ID to rollback to, or preview deployment ID to promote"),verifyUrl:Je.string().optional().describe("(verify) URL to verify. Defaults to deploy URL from mistflow.json")}),Zr={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:Il,handler:async(s,o)=>{let e=s;switch(e.action){case"deploy":return Lr({projectPath:e.projectPath,environment:e.environment??"production",forceSchema:e.forceSchema},o);case"promote":return Fr({projectPath:e.projectPath,deploymentId:e.deploymentId});case"preview":return Jr.handler({projectPath:e.projectPath});case"redeploy":return _o({projectPath:e.projectPath,action:"redeploy"});case"rollback":return _o({projectPath:e.projectPath,action:"rollback",deploymentId:e.deploymentId});case"verify":return Xr({projectPath:e.projectPath,verifyUrl:e.verifyUrl});default:return d(`Unknown action: ${e.action}. Use deploy, promote, preview, redeploy, rollback, or verify.`,!0)}}};import{z as we}from"zod";import{resolve as Qt}from"path";import{existsSync as Xt,readFileSync as Zt}from"fs";import{join as eo}from"path";import{z as Be}from"zod";import{resolve as Rl,join as en}from"path";import{existsSync as Nl,readFileSync as tn,writeFileSync as El}from"fs";var _l=Be.object({action:Be.enum(["get","update"]).default("get").describe("'get' reads current project state. 'update' modifies it."),projectPath:Be.string().optional().describe("Path to the project directory (default: current working directory)"),completedStep:Be.number().optional().describe("(update only) Mark a plan step as completed by step number"),addEnvVar:Be.object({key:Be.string(),description:Be.string().optional(),setupUrl:Be.string().optional()}).optional().describe("(update only) Add a required env var to the project manifest")}),on={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,e=Rl(o.projectPath??process.cwd()),t=en(e,"mistflow.json");if(!Nl(t))return Ce(e);let n;try{n=JSON.parse(tn(t,"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(e)&&(n=JSON.parse(tn(t,"utf-8")))}catch{}let i=n.plan,l=i?.steps?.filter(h=>h.status==="completed").length??0,c=i?.steps?.length??0,u=Jt(en(e,".env.local")),m=n.env?.required?Object.entries(n.env.required).map(([h,k])=>({name:h,description:k?.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 k=h.status==="completed"?"\u2713":h.status==="in_progress"?"\u2192":" ";p.push(` [${k}] ${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 v=[],f=i?.steps?.find(h=>h.status!=="completed");return f?v.push(`NEXT: Call mist_build with action='implement' to work on step ${f.number} (${f.name}).`):i&&l===c&&(n.deploy?.url||v.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&&v.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:v}))}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}`)),El(t,JSON.stringify(n,null,2)+`
|
|
5085
|
+
`),n.projectId&&import("./state-manager-GBP2NSYC.js").then(async({readLocalState:i,syncRemoteState:l})=>{let c=i(e);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 Dl=we.object({action:we.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:we.string().optional().describe("Path to the project directory (default: cwd)"),completedStep:we.number().optional().describe("(update) Mark a plan step as completed by step number"),addEnvVar:we.object({key:we.string(),description:we.string().optional(),setupUrl:we.string().optional()}).optional().describe("(update) Add a required env var to the project manifest"),templateDescription:we.string().optional().describe("(share) Short description of what this template builds"),category:we.string().optional().describe("(landing-designs) Filter by category"),presetId:we.string().optional().describe("(landing-designs) Get full details for a specific landing design by ID"),integrationId:we.string().optional().describe("(integrations) Get full details for a specific integration preset by ID (e.g. 'stripe-payments', 'resend-email', 'elevenlabs-voice')"),period:we.string().optional().describe("(errors) Time period for errors: '1h', '24h', '7d' (default: '7d')"),deploymentId:we.string().optional().describe("(logs) Deployment ID to fetch logs for. If omitted, fetches logs for the latest deployment.")}),sn={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:Dl,handler:async s=>{let o=s;if(["share","errors","logs","deployments"].includes(o.action)&&!fe())return d("You need to sign in first. Run mist_setup to connect your account.",!0);switch(o.action){case"get":case"update":return on.handler({action:o.action,projectPath:o.projectPath,completedStep:o.completedStep,addEnvVar:o.addEnvVar});case"share":{let t=Qt(o.projectPath??process.cwd()),n=eo(t,"mistflow.json");if(!Xt(n))return Ce(t);let a;try{a=JSON.parse(Zt(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 ms(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=Xe(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=
|
|
5091
|
-
`)}async function rn(s){let{projectPath:o,action:e,domain:t,domainId:n}=s,a=Dl(o??process.cwd());if(!fe())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let i=Ae(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 Vo(i,t),c=await We(i);return Mo(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 We(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 We(i)).find(p=>p.domain===t);if(m){let p=await no(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 no(i,n),c=await We(i);return Mo(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 We(i)).find(p=>p.domain===t);if(!m)return d(`Domain '${t}' not found.`,!0);l=m.id}await Yo(i,l);let c=await We(i);return Mo(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 xe)return d(l.message,!0);let c=l instanceof Error?l.message:"An unexpected error occurred";return d(c,!0)}}var Ol=Re.object({resource:Re.enum(["env","domain"]).describe("'env' manages app secrets and configuration values. 'domain' manages custom domains."),action:Re.string().describe("Action to perform. env: 'set', 'list', 'delete'. domain: 'add', 'list', 'verify', 'remove'."),projectPath:Re.string().optional().describe("Path to the project directory (default: cwd)"),key:Re.string().optional().describe("(env) Variable name"),value:Re.string().optional().describe("(env set) Variable value"),category:Re.string().optional().describe("(env set) Category"),description:Re.string().optional().describe("(env set) Description"),setupUrl:Re.string().optional().describe("(env set) URL to obtain the value"),domain:Re.string().optional().describe("(domain) Domain name"),domainId:Re.string().optional().describe("(domain) Domain ID")}),nn={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:Ol,handler:async s=>{let o=s;switch(o.resource){case"env":return sn({projectPath:o.projectPath,action:o.action,key:o.key,value:o.value,category:o.category,description:o.description,setupUrl:o.setupUrl});case"domain":return rn({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 Ke}from"zod";var Ul=Ke.object({action:Ke.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:Ke.string().optional().describe("URL to navigate to. Required for 'navigate'; optional for 'screenshot' (navigates before capturing)."),selector:Ke.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:Ke.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:Ke.boolean().default(!1).describe("For 'screenshot': capture the full scrollable page instead of just the viewport."),includeScreenshot:Ke.boolean().default(!1).describe("For navigate/interact actions: also return a screenshot alongside the accessibility snapshot.")}),an={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:Ul,handler:async s=>{let o=s,e=await Ct();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 It(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 Me(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 Me(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 It(e);return{content:[{type:"text",text:JSON.stringify({url:e.url(),title:await e.title(),snapshot:a})}]}}let t=await It(e),n=[{type:"text",text:JSON.stringify({url:e.url(),title:await e.title(),snapshot:t})}];if(o.includeScreenshot){let a=await Me(e);n.push({type:"image",data:a.toString("base64"),mimeType:"image/png"})}return{content:n}}};import{existsSync as _e,readFileSync as Pt,writeFileSync as ct}from"fs";import{join as Ne}from"path";import{z as Tt}from"zod";function ln(s){let o=Ne(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(Pt(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 Fl(){let s=Oo();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=Fo(),e=await fetch(`${Ge()}/api/org`,{headers:o,signal:AbortSignal.timeout(1e4)});try{jo(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 xe?{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 Bl(){let s=Date.now();try{let o=await Nt("nextjs"),e=Date.now()-s;return{result:{name:"API",status:"pass",message:`${Ge()} reachable (${e}ms)`},scaffold:o}}catch(o){let e=Date.now()-s;return{result:{name:"API",status:"fail",message:o instanceof xe?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 ql(){let s=pt();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 zl(s,o,e,t){let n=Ne(s,"AGENTS.md"),a=Ne(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=cn(e.methodology,o);return ct(n,c),ct(a,c),{name:"AGENTS.md",status:"fix",message:`Restored from methodology v${l}.`}}if(t&&!_e(a)){let c=Pt(n,"utf-8");ct(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=cn(e.methodology,o);ct(n,c),ct(a,c);try{let u=Ne(s,"mistflow.json"),m=JSON.parse(Pt(u,"utf-8"));m.methodologyVersion=l,ct(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
|
|
5093
|
-
`+Pt(r,"utf-8"))}catch{}}for(let[a,r]of Object.entries(e.required)){let i=n.includes(`${a}=`),l=!!process.env[a];if(!i&&!l){let c=r?.description?` (${r.description})`:"";t.push(`${a}${c}`)}}return t.length>0?{name:"Env vars",status:"warn",message:`${t.length} required but not set: ${t.join(", ")}`,fix:"Set them via mist_config or add to .env.local."}:{name:"Env vars",status:"pass",message:`${Object.keys(e.required).length} required, all set`}}function
|
|
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=Xe(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=ws(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 t=ks(o.category??void 0),n=po(o.category),a=vs(n);return d(JSON.stringify({count:t.length,presets:t.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:`${t.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 ${ut()}/designs?tab=landing-designs.`}))}case"integrations":{if(o.integrationId){let r=et(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=tt(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 t=Ts(o.category??void 0),n=mo(o.category??void 0),a=Ss(n);return d(JSON.stringify({count:t.length,integrations:t.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:`${t.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 t=Qt(o.projectPath??process.cwd()),n=eo(t,"mistflow.json");if(!Xt(n))return Ce(t);let a;try{a=JSON.parse(Zt(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 ss(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 t=Qt(o.projectPath??process.cwd()),n=eo(t,"mistflow.json");if(!Xt(n))return Ce(t);let a;try{a=JSON.parse(Zt(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 mt(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([os(i),$e(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 t=Qt(o.projectPath??process.cwd()),n=eo(t,"mistflow.json");if(!Xt(n))return Ce(t);let a;try{a=JSON.parse(Zt(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 mt(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":{pt().backendSignalReceived||await Bo();let t=pt(),n=t.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:t.current,latest:t.latest||"unknown",minSupported:t.minSupported||"unknown",severity:t.severity,upToDate:n,upgradeCmd:t.upgradeCmd,changelogUrl:t.changelogUrl,backendSignalReceived:t.backendSignalReceived,message:t.backendSignalReceived?`Mistflow MCP ${t.current} (${a[t.severity]??t.severity}). Latest: ${t.latest}.${n?"":` Run \`${t.upgradeCmd}\` and restart your editor to upgrade.`}`:`Mistflow MCP ${t.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 Re}from"zod";import{z as qe}from"zod";import{resolve as Ml}from"path";var Ju=qe.object({projectPath:qe.string().optional().describe("Path to the project directory (default: cwd)"),action:qe.enum(["set","list","delete"]).describe("Action to perform"),key:qe.string().optional().describe("Environment variable name (required for 'set' and 'delete')"),value:qe.string().optional().describe("Environment variable value (required for 'set')"),category:qe.string().optional().describe("Category for the env var (default: 'custom')"),description:qe.string().optional().describe("Description of what this env var is for"),setupUrl:qe.string().optional().describe("URL where the user can obtain this value (e.g. Stripe dashboard)")});async function rn(s){let{projectPath:o,action:e,key:t,value:n,category:a,description:r,setupUrl:i}=s,l=Ml(o??process.cwd());if(!fe())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let u=Ae(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(e){case"set":return t?n?(await es(u,t,n,{category:a,description:r,setupUrl:i}),d(JSON.stringify({set:!0,key:t,message:`Environment variable '${t}' 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 Zo(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 t?(await ts(u,t),d(JSON.stringify({deleted:!0,key:t,message:`Environment variable '${t}' has been removed.`}))):d("Key is required. Provide the env var name to delete.",!0);default:return d(`Unknown action: ${e}. Use set, list, or delete.`,!0)}}catch(m){if(m instanceof xe)return d(m.message,!0);let p=m instanceof Error?m.message:"An unexpected error occurred";return d(p,!0)}}import{z as St}from"zod";import{resolve as $l,join as jl}from"path";import{existsSync as Ll,readFileSync as Ol,writeFileSync as Ul}from"fs";var sm=St.object({projectPath:St.string().optional().describe("Path to the project directory (default: cwd)"),action:St.enum(["add","list","verify","remove"]).describe("Action to perform"),domain:St.string().optional().describe("Domain name (required for 'add' and 'remove')"),domainId:St.string().optional().describe("Domain ID (required for 'verify' and 'remove')")});function Mo(s,o){let e=jl(s,"mistflow.json");if(!Ll(e))return;let t;try{t=JSON.parse(Ol(e,"utf-8"))}catch{return}t.domains=o,Ul(e,JSON.stringify(t,null,2)+`
|
|
5091
|
+
`)}async function nn(s){let{projectPath:o,action:e,domain:t,domainId:n}=s,a=$l(o??process.cwd());if(!fe())return d("No Mistflow credentials found. Run mist_setup to connect your account.",!0);let i=Ae(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 Yo(i,t),c=await We(i);return Mo(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 We(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 We(i)).find(p=>p.domain===t);if(m){let p=await no(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 no(i,n),c=await We(i);return Mo(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 We(i)).find(p=>p.domain===t);if(!m)return d(`Domain '${t}' not found.`,!0);l=m.id}await Jo(i,l);let c=await We(i);return Mo(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 xe)return d(l.message,!0);let c=l instanceof Error?l.message:"An unexpected error occurred";return d(c,!0)}}var Fl=Re.object({resource:Re.enum(["env","domain"]).describe("'env' manages app secrets and configuration values. 'domain' manages custom domains."),action:Re.string().describe("Action to perform. env: 'set', 'list', 'delete'. domain: 'add', 'list', 'verify', 'remove'."),projectPath:Re.string().optional().describe("Path to the project directory (default: cwd)"),key:Re.string().optional().describe("(env) Variable name"),value:Re.string().optional().describe("(env set) Variable value"),category:Re.string().optional().describe("(env set) Category"),description:Re.string().optional().describe("(env set) Description"),setupUrl:Re.string().optional().describe("(env set) URL to obtain the value"),domain:Re.string().optional().describe("(domain) Domain name"),domainId:Re.string().optional().describe("(domain) Domain ID")}),an={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:Fl,handler:async s=>{let o=s;switch(o.resource){case"env":return rn({projectPath:o.projectPath,action:o.action,key:o.key,value:o.value,category:o.category,description:o.description,setupUrl:o.setupUrl});case"domain":return nn({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 Ke}from"zod";var Bl=Ke.object({action:Ke.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:Ke.string().optional().describe("URL to navigate to. Required for 'navigate'; optional for 'screenshot' (navigates before capturing)."),selector:Ke.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:Ke.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:Ke.boolean().default(!1).describe("For 'screenshot': capture the full scrollable page instead of just the viewport."),includeScreenshot:Ke.boolean().default(!1).describe("For navigate/interact actions: also return a screenshot alongside the accessibility snapshot.")}),ln={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:Bl,handler:async s=>{let o=s,e=await Ct();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 It(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 Me(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 Me(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 It(e);return{content:[{type:"text",text:JSON.stringify({url:e.url(),title:await e.title(),snapshot:a})}]}}let t=await It(e),n=[{type:"text",text:JSON.stringify({url:e.url(),title:await e.title(),snapshot:t})}];if(o.includeScreenshot){let a=await Me(e);n.push({type:"image",data:a.toString("base64"),mimeType:"image/png"})}return{content:n}}};import{existsSync as _e,readFileSync as Pt,writeFileSync as ct}from"fs";import{join as Ne}from"path";import{z as Tt}from"zod";function cn(s){let o=Ne(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(Pt(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 ql(){let s=Oo();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=Fo(),e=await fetch(`${Ge()}/api/org`,{headers:o,signal:AbortSignal.timeout(1e4)});try{jo(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 xe?{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 zl(){let s=Date.now();try{let o=await Nt("nextjs"),e=Date.now()-s;return{result:{name:"API",status:"pass",message:`${Ge()} reachable (${e}ms)`},scaffold:o}}catch(o){let e=Date.now()-s;return{result:{name:"API",status:"fail",message:o instanceof xe?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 Hl(){let s=pt();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 Gl(s,o,e,t){let n=Ne(s,"AGENTS.md"),a=Ne(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=dn(e.methodology,o);return ct(n,c),ct(a,c),{name:"AGENTS.md",status:"fix",message:`Restored from methodology v${l}.`}}if(t&&!_e(a)){let c=Pt(n,"utf-8");ct(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=dn(e.methodology,o);ct(n,c),ct(a,c);try{let u=Ne(s,"mistflow.json"),m=JSON.parse(Pt(u,"utf-8"));m.methodologyVersion=l,ct(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 Wl(s,o,e,t){let n=o.projectId;if(!n)return{name:"State sync",status:"skip",message:"No projectId. State sync not applicable without a linked project."};if(!e)return{name:"State sync",status:"skip",message:"Skipped (not authenticated)."};let a=hs(s),r=await gs(n);if(!a&&!r)return{name:"State sync",status:"warn",message:"No local or remote state found."};if(!a&&r){if(t){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 Vl(s){let o=[],e=[];if(_e(Ne(s,"package.json"))?_e(Ne(s,"node_modules"))||o.push("node_modules not installed (run npm install)"):o.push("missing package.json"),!_e(Ne(s,".env.local")))o.push("missing .env.local");else try{Pt(Ne(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 t=Ne(s,"app","api","auth","[...all]","route.ts");_e(t)||e.push("missing app/api/auth/[...all]/route.ts");let n=Ne(s,"app","api","health","route.ts");return _e(n)||e.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 `npm install` in the project directory.":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(" ")}:e.length>0?{name:"Structure",status:"warn",message:e.join("; ")}:{name:"Structure",status:"pass",message:"all required files present"}}function Yl(s,o){let e=o.env;if(!e?.required||typeof e.required!="object"||Object.keys(e.required).length===0)return{name:"Env vars",status:"pass",message:"no required env vars declared"};let t=[],n="";for(let a of[".env.local",".env"]){let r=Ne(s,a);try{_e(r)&&(n+=`
|
|
5093
|
+
`+Pt(r,"utf-8"))}catch{}}for(let[a,r]of Object.entries(e.required)){let i=n.includes(`${a}=`),l=!!process.env[a];if(!i&&!l){let c=r?.description?` (${r.description})`:"";t.push(`${a}${c}`)}}return t.length>0?{name:"Env vars",status:"warn",message:`${t.length} required but not set: ${t.join(", ")}`,fix:"Set them via mist_config or add to .env.local."}:{name:"Env vars",status:"pass",message:`${Object.keys(e.required).length} required, all set`}}function Jl(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 e=o.steps.length,t=o.steps.filter(r=>r.status==="completed").length,n=o.steps.filter(r=>r.status==="in_progress").length,a=e-t-n;if(t===e)return{name:"Plan",status:"pass",message:`${t}/${e} steps completed`};if(n>0){let r=o.steps.find(i=>i.status==="in_progress");return{name:"Plan",status:"warn",message:`${t}/${e} completed, step ${r?.number} "${r?.name}" in progress`,fix:"Run mist_build implement to continue."}}return t===0?{name:"Plan",status:"warn",message:`${e} steps planned, none started.`,fix:"Run mist_build implement to start building."}:{name:"Plan",status:"warn",message:`${t}/${e} completed, ${a} remaining.`,fix:"Run mist_build implement to continue."}}function dn(s,o){let e=o.dbProvider;return e==="neon"||!e?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 Kl(s){let o={pass:"PASS",warn:"WARN",fail:"FAIL",fix:"FIXED",skip:"SKIP"},e=Math.max(...s.map(u=>u.name.length)),t=s.map(u=>{let m=".".repeat(e-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
|
`+t.join(`
|
|
5096
5096
|
`);i.length>0?l+=`
|
|
@@ -5100,7 +5100,7 @@ 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
|
|
5103
|
+
- ${u.fix}`}return l}var pn=Tt.object({projectPath:Tt.string().optional().describe("Path to the project directory. Defaults to the current working directory."),checks:Tt.array(Tt.enum(["project","auth","api","version","methodology","state","structure","env","plan"])).optional().describe("Run only specific checks. Omit to run all."),reportOnly:Tt.boolean().optional().describe("If true, report issues without auto-fixing them.")}),un={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:pn,handler:async s=>{let o=pn.parse(s),e=o.projectPath||process.cwd(),t=!o.reportOnly,n=!o.checks,a=o.checks??[],r=f=>n||a.includes(f),i=[],l=null;if(r("project")){let f=cn(e);i.push(f.result),l=f.config}else l=cn(e).config;let c=!1;if(r("auth")||r("state")){let f=await ql();r("auth")&&i.push(f.result),c=f.authValid}let m=null;if(r("api")||r("methodology")){let f=await zl();r("api")&&i.push(f.result),m=f.scaffold}r("version")&&i.push(Hl()),l?(r("methodology")&&i.push(Gl(e,l,m,t)),r("state")&&i.push(await Wl(e,l,c,t)),r("structure")&&i.push(Vl(e)),r("env")&&i.push(Yl(e,l)),r("plan")&&i.push(Jl(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=Kl(i),v=i.some(f=>f.status==="fail");return d(g,v)}};var to=new Ql({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.
|
|
@@ -5134,4 +5134,4 @@ Other tools:
|
|
|
5134
5134
|
- mist_project: read/update project state, browse landing designs and app styles, view runtime errors, deploy logs, deployment history, and check MCP version.
|
|
5135
5135
|
- mist_config: manage encrypted app secrets (env vars) and custom domains.
|
|
5136
5136
|
- 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.`}),
|
|
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.`}),mn=[bs,Ms,Tr,Zr,sn,an,ln,un];to.setRequestHandler(ec,async()=>({tools:mn.map(s=>({name:s.name,description:s.description,inputSchema:tc(s.inputSchema)}))}));to.setRequestHandler(Zl,async s=>{let o=mn.find(e=>e.name===s.params.name);if(!o)return d(`Unknown tool: ${s.params.name}`,!0);try{let e=o.inputSchema.safeParse(s.params.arguments);if(!e.success){let a=e.error.issues.map(r=>`${r.path.join(".")}: ${r.message}`).join(", ");return d(`Invalid input: ${a}`,!0)}let t=s.params._meta?.progressToken,n={server:to,progressToken:t};try{return await o.handler(e.data,n)}finally{n.cleanup?.()}}catch(e){let t=e instanceof Error?e.message:"An unexpected error occurred";return console.error("Tool error:",e),d(t,!0)}});async function oc(){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 Xl;await to.connect(o),console.error(`Mistflow MCP server running on stdio (API: ${process.env.MISTFLOW_API_URL||"https://api.mistflow.ai"})`)}oc().catch(s=>{console.error("Fatal error:",s),process.exit(1)});
|