vibespot 1.1.1 → 1.3.0

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.
Files changed (56) hide show
  1. package/LICENSE +103 -33
  2. package/README.md +55 -6
  3. package/assets/blog-rules.md +251 -0
  4. package/assets/email-rules.md +390 -0
  5. package/assets/humanify-guide.md +300 -101
  6. package/assets/plan-templates/agency-services.md +42 -0
  7. package/assets/plan-templates/blog-content-hub.md +50 -0
  8. package/assets/plan-templates/ecommerce-product.md +42 -0
  9. package/assets/plan-templates/email-announcement.md +41 -0
  10. package/assets/plan-templates/email-event-invite.md +43 -0
  11. package/assets/plan-templates/email-newsletter.md +41 -0
  12. package/assets/plan-templates/email-re-engagement.md +42 -0
  13. package/assets/plan-templates/email-welcome.md +41 -0
  14. package/assets/plan-templates/event-registration.md +42 -0
  15. package/assets/plan-templates/portfolio.md +41 -0
  16. package/assets/plan-templates/restaurant.md +42 -0
  17. package/assets/plan-templates/saas-landing.md +42 -0
  18. package/dist/index.js +1485 -397
  19. package/dist/index.js.map +1 -1
  20. package/package.json +11 -7
  21. package/starters/01-saas-landing.json +43 -0
  22. package/starters/02-portfolio.json +39 -0
  23. package/starters/03-restaurant.json +39 -0
  24. package/starters/04-event.json +39 -0
  25. package/starters/05-coming-soon.json +32 -0
  26. package/starters/06-blog-content-hub.json +75 -0
  27. package/starters/06-email-welcome.json +60 -0
  28. package/starters/07-email-announcement.json +60 -0
  29. package/starters/08-email-newsletter.json +52 -0
  30. package/ui/chat.js +1604 -155
  31. package/ui/code-editor.js +49 -7
  32. package/ui/dashboard.js +551 -83
  33. package/ui/docs/docs.css +29 -0
  34. package/ui/docs/index.html +274 -117
  35. package/ui/docs/screenshots/brand-kit-preview.png +0 -0
  36. package/ui/docs/screenshots/content-type-dropdown.png +0 -0
  37. package/ui/docs/screenshots/editor-full-layout.png +0 -0
  38. package/ui/docs/screenshots/inline-wysiwyg-editing.png +0 -0
  39. package/ui/docs/screenshots/multi-page-tree.png +0 -0
  40. package/ui/docs/screenshots/onboarding-walkthrough.png +0 -0
  41. package/ui/docs/screenshots/split-pane-view.png +0 -0
  42. package/ui/docs/screenshots/visual-controls-toolbar.png +0 -0
  43. package/ui/docs/screenshots/workspace-tabs.png +0 -0
  44. package/ui/email-preview.js +109 -0
  45. package/ui/field-editor.js +71 -0
  46. package/ui/icons.js +120 -0
  47. package/ui/index.html +882 -515
  48. package/ui/inline-edit.js +710 -0
  49. package/ui/marketplace.js +218 -0
  50. package/ui/plan.js +0 -0
  51. package/ui/preview.js +219 -1
  52. package/ui/section-controls.js +628 -0
  53. package/ui/settings.js +84 -28
  54. package/ui/setup.js +1016 -118
  55. package/ui/styles.css +6119 -2456
  56. package/ui/upload-panel.js +47 -20
package/dist/index.js CHANGED
@@ -1,9 +1,16 @@
1
- var Vc=Object.defineProperty;var L=(e,t)=>()=>(e&&(t=e(e=0)),t);var ke=(e,t)=>{for(var n in t)Vc(e,n,{get:t[n],enumerable:!0})};import Qp from"path";import{fileURLToPath as tg}from"url";var f=L(()=>{"use strict"});import{readFileSync as Xs,writeFileSync as Kc,mkdirSync as Pi,existsSync as Rn}from"fs";import{dirname as zc,join as et}from"path";function E(e){return Xs(e,"utf-8")}function G(e,t){Pi(zc(e),{recursive:!0}),Kc(e,t,"utf-8")}function k(e){return Rn(e)}function Te(e){Pi(e,{recursive:!0})}function Fn(e){let t=[et(import.meta.dirname,"../../assets",e),et(import.meta.dirname,"../assets",e),et(process.cwd(),"assets",e)];for(let n of t)if(Rn(n))return n;throw new Error(`Asset not found: ${e}`)}function Nt(){if(_t)return _t;let e=[et(import.meta.dirname,"../../package.json"),et(import.meta.dirname,"../package.json"),et(process.cwd(),"package.json")];for(let t of e)if(Rn(t))try{let n=JSON.parse(Xs(t,"utf-8"));if(n.name==="vibespot"&&n.version)return _t=n.version,_t}catch{}return _t="dev",_t}function Mi(){if(On)return On;let e=[et(import.meta.dirname,"../../CHANGELOG.md"),et(import.meta.dirname,"../CHANGELOG.md"),et(process.cwd(),"CHANGELOG.md")];for(let t of e)if(Rn(t))try{return On=Xs(t,"utf-8"),On}catch{}return""}var _t,On,te=L(()=>{"use strict";f();_t="";On=""});import{execSync as Oi}from"child_process";function J(e,t={}){try{return{stdout:Oi(e,{encoding:"utf-8",stdio:["pipe","pipe","pipe"],timeout:12e4,...t}).trim(),stderr:"",success:!0}}catch(n){let s=n,o=(s.stdout??"").toString().trim(),i=(s.stderr??"").toString().trim();return{stdout:o,stderr:i,success:!1}}}function Ri(e,t={}){try{return Oi(e,{stdio:"inherit",timeout:3e5,...t}),!0}catch{return!1}}var ht=L(()=>{"use strict";f()});var ji={};ke(ji,{addHubSpotAccount:()=>qt,getActiveHubSpotAccount:()=>ut,getApiKeyForEngine:()=>be,getConfigDir:()=>Xc,getHubSpotPak:()=>Se,isCliToolEnabled:()=>Xt,loadConfig:()=>P,maskApiKey:()=>jn,removeHubSpotAccount:()=>Zs,saveConfig:()=>W,setActiveHubSpotAccount:()=>Qs,setCliToolEnabled:()=>eo});import{join as Fi}from"path";import{homedir as Yc}from"os";import{chmodSync as qc}from"fs";function P(){if(!k(Jn))return{};try{let e=JSON.parse(E(Jn));return e.aiEngine==="api"&&(e.aiEngine="anthropic-api"),e}catch{return{}}}function be(e,t){let n=t||P();switch(e){case"anthropic-api":case"api":return n.anthropicApiKey||process.env.ANTHROPIC_API_KEY;case"openai-api":return n.openaiApiKey||process.env.OPENAI_API_KEY;case"gemini-api":return n.geminiApiKey||process.env.GEMINI_API_KEY||process.env.GOOGLE_AI_API_KEY;default:return}}function jn(e){return e.length<=12?"***":e.slice(0,7)+"..."+e.slice(-4)}function W(e){let n={...P(),...e};if(G(Jn,JSON.stringify(n,null,2)),process.platform!=="win32")try{qc(Jn,384)}catch{}}function Xc(){return Ji}function ut(){let e=P();if(!e.hubspotAccounts?.length)return null;let t=e.activeHubSpotAccount;if(t){let n=e.hubspotAccounts.find(s=>s.portalId===t);if(n)return n}return e.hubspotAccounts[0]||null}function qt(e,t,n,s){let i=P().hubspotAccounts||[],a=i.findIndex(l=>l.portalId===t),r={portalId:t,portalName:n,personalAccessKey:e,dataCenter:s,addedAt:new Date().toISOString()};a>=0?i[a]=r:i.push(r),W({hubspotAccounts:i,activeHubSpotAccount:t})}function Zs(e){let t=P(),n=(t.hubspotAccounts||[]).filter(o=>o.portalId!==e),s={hubspotAccounts:n};t.activeHubSpotAccount===e&&(s.activeHubSpotAccount=n[0]?.portalId||void 0),W(s)}function Qs(e){W({activeHubSpotAccount:e})}function Se(){return ut()?.personalAccessKey||null}function Xt(e){return P().enabledCLITools?.includes(e)??!1}function eo(e,t){let n=P(),s=new Set(n.enabledCLITools||[]);t?s.add(e):s.delete(e),W({enabledCLITools:[...s]})}var Ji,Jn,Q=L(()=>{"use strict";f();te();Ji=Fi(Yc(),".vibespot"),Jn=Fi(Ji,"config.json")});var so={};ke(so,{OAUTH_EXTRA_HEADERS:()=>Zt,OAUTH_SYSTEM_PREFIX:()=>Mt,clearOAuthTokens:()=>Ln,getOAuthTokenInfo:()=>Qt,getValidAccessToken:()=>no,hasValidOAuthToken:()=>Le,saveInitialToken:()=>to});import{join as Zc}from"path";import{homedir as Qc}from"os";import{chmodSync as ed,unlinkSync as td}from"fs";function Hn(){if(!k(Pt))return null;try{return JSON.parse(E(Pt))}catch{return null}}function Di(e){if(G(Pt,JSON.stringify(e,null,2)),process.platform!=="win32")try{ed(Pt,384)}catch{}}async function id(e){let t=await fetch(sd,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"refresh_token",refresh_token:e,client_id:nd})});if(!t.ok)throw Ln(),new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let n=await t.json();Di({access_token:n.access_token,refresh_token:n.refresh_token||e,expires_at:Date.now()+(n.expires_in||28800)*1e3})}function to(e,t=""){Di({access_token:e,refresh_token:t,expires_at:Date.now()+28800*1e3})}function Le(){let e=Hn();return e?e.expires_at>Date.now():!1}async function no(){let e=Hn();if(!e)return null;if(e.expires_at-Date.now()>od)return e.access_token;if(e.refresh_token){Dn||(Dn=id(e.refresh_token).finally(()=>{Dn=null}));try{await Dn}catch{return null}return Hn()?.access_token??null}return e.access_token}function Qt(){let e=Hn();return e?{expiresAt:new Date(e.expires_at).toISOString()}:null}function Ln(){if(k(Pt))try{td(Pt)}catch{}}var nd,sd,Pt,od,Zt,Mt,Dn,tt=L(()=>{"use strict";f();te();nd="9d1c250a-e61b-44d9-88ed-5944d1962f5e",sd="https://console.anthropic.com/v1/oauth/token",Pt=Zc(Qc(),".vibespot","claude-oauth.json"),od=300*1e3,Zt={"user-agent":"claude-cli/2.1.75","x-app":"cli","anthropic-beta":"oauth-2025-04-20"},Mt="You are Claude Code, Anthropic's official CLI for Claude.";Dn=null});import{readFileSync as ld}from"fs";import{basename as cd}from"path";async function Gi(e){let t=Ui.get(e);if(t&&t.expiresAt-Date.now()>md)return t;let n=await fetch(`${nt}/localdevauth/v1/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({encodedOAuthRefreshToken:e})});if(!n.ok){let i=await n.text().catch(()=>"");throw new Error(n.status===401||n.status===403?"Invalid or expired Personal Access Key":`Token exchange failed (${n.status}): ${i.slice(0,200)}`)}let s=await n.json(),o={accessToken:s.oauthAccessToken,expiresAt:s.expiresAtMillis,hubId:s.hubId,hubName:s.hubName||""};return Ui.set(e,o),o}async function Ot(e){let{accessToken:t}=await Gi(e);return{Authorization:`Bearer ${t}`}}function Kn(e){return e.replace(/^\/+/,"").split("/").filter(Boolean).map(encodeURIComponent).join("/")}function pd(e){return e.startsWith("pat-eu1-")?"eu1":e.startsWith("pat-na1-")?"na1":e.startsWith("CiRldTE")?"eu1":"na1"}function gd(e){return new Promise(t=>setTimeout(t,e))}async function an(e,t){let n=`HTTP ${e.status}`,s,o;try{let i=await e.json();if(i.message&&typeof i.message=="string"&&(n=i.message),i.category&&typeof i.category=="string"&&(s=i.category),i.errors&&Array.isArray(i.errors)&&i.errors.length>0){let a=i.errors[0];o=a.message||JSON.stringify(a)}}catch{try{let i=await e.text();i&&(n=i.slice(0,500))}catch{}}return{status:e.status,message:t?`${n} (${t})`:n,category:s,detail:o}}async function ln(e,t,n=dd){for(let s=0;s<=n;s++){let o=await fetch(e,t);if(o.status===429||o.status>=500&&s<n){let i=ud*Math.pow(2,s);await gd(i);continue}return o}return fetch(e,t)}async function zn(e){let t=await Gi(e),n=`${nt}/account-info/v3/details`,s=await ln(n,{headers:await Ot(e)});if(!s.ok){let r=await an(s);throw new Error(`Failed to get account info: ${r.message}`)}let o=await s.json(),i=String(o.portalId||t.hubId||""),a=t.hubName||o.uiDomain||i;return{portalId:i,portalName:a,dataCenter:pd(e)}}async function Wi(e,t,n){let s=ld(n),o=cd(n),i=new FormData,a=new Blob([s]);i.append("file",a,o);let r=`${nt}/cms/v3/source-code/published/content/${Kn(t)}`,l=await ln(r,{method:"PUT",headers:await Ot(e),body:i});if(!l.ok){let c=await an(l,t);return{success:!1,path:t,error:c}}return{success:!0,path:t}}async function ao(e,t){let n=`${nt}/cms/v3/source-code/published/content/${Kn(t)}`,s=await ln(n,{method:"DELETE",headers:await Ot(e)});if(!s.ok&&s.status!==404){let o=await an(s,t);throw new Error(`Failed to delete ${t}: ${o.message}`)}}async function Vi(e,t){let n=`${nt}/cms/v3/source-code/published/content/${Kn(t)}`,s=await ln(n,{method:"GET",headers:await Ot(e)});if(!s.ok){let i=await an(s,t);throw new Error(`Failed to download ${t}: ${i.message}`)}let o=await s.arrayBuffer();return Buffer.from(o)}async function Yn(e,t){let n=`${nt}/cms/v3/source-code/published/metadata/${Kn(t)}`,s=await ln(n,{method:"GET",headers:await Ot(e)});if(s.status===404)return null;if(!s.ok){let o=await an(s,t);throw new Error(`Failed to get metadata for ${t}: ${o.message}`)}return await s.json()}async function Ki(e){let t=await Ot(e),n=[`${nt}/cms/v3/source-code/published/metadata`,`${nt}/cms/v3/source-code/published/metadata/`,`${nt}/designmanager/v1/portals/content/listing`];for(let s of n)try{let o=await fetch(s,{method:"GET",headers:t});if(o.ok){let i=await o.json(),a=i.children||i.objects||(Array.isArray(i)?i:null);if(a&&a.length>0)return a.filter(r=>r.folder)}}catch{}return[]}var nt,dd,ud,md,Ui,bt=L(()=>{"use strict";f();nt="https://api.hubapi.com",dd=3,ud=1e3,md=300*1e3,Ui=new Map});var Zi={};ke(Zi,{createThemeScaffold:()=>cn});import{mkdirSync as mt,writeFileSync as Zn}from"fs";import{join as Pe}from"path";function cn(e,t){mt(e,{recursive:!0}),mt(Pe(e,"templates"),{recursive:!0}),mt(Pe(e,"modules"),{recursive:!0}),mt(Pe(e,"css"),{recursive:!0}),mt(Pe(e,"js"),{recursive:!0}),mt(Pe(e,"images"),{recursive:!0}),mt(Pe(e,"assets"),{recursive:!0});let n={label:t,preview_path:"./templates/home.html",screenshot_path:"./images/template-previews/home.png",enable_domain_stylesheets:!1,version:"1.0.0",author:{name:"vibeSpot",url:"https://github.com/borismichel/vibespot"}};Zn(Pe(e,"theme.json"),JSON.stringify(n,null,2)+`
2
- `),Zn(Pe(e,"fields.json"),`[]
1
+ var tp=Object.defineProperty;var R=(t,e)=>()=>(t&&(e=t(t=0)),e);var Be=(t,e)=>{for(var n in e)tp(t,n,{get:e[n],enumerable:!0})};import Gb from"path";import{fileURLToPath as Kb}from"url";var y=R(()=>{"use strict"});import en from"chalk";function bt(t){return ia?en:en.hex(t)}var rt,ia,_,at=R(()=>{"use strict";y();rt={accent:"#FF7A59",accentBright:"#FF9A7A",success:"#00BDA5",info:"#0066FF",warn:"#FFB020",error:"#E23D2D",muted:"#8B8D91",vibes:"#00BDD6"},ia=!!process.env.NO_COLOR;_={accent:bt(rt.accent),accentBright:bt(rt.accentBright),success:bt(rt.success),info:bt(rt.info),warn:bt(rt.warn),error:bt(rt.error),muted:bt(rt.muted),vibes:bt(rt.vibes),heading:ia?en.bold:en.bold.hex(rt.accent),command:bt(rt.accentBright),dim:en.dim,bold:en.bold}});import{readFileSync as li,writeFileSync as np,mkdirSync as ra,existsSync as ks}from"fs";import{dirname as aa,join as St}from"path";import{fileURLToPath as sp}from"url";function M(t){return li(t,"utf-8")}function J(t,e){ra(aa(t),{recursive:!0}),np(t,e,"utf-8")}function v(t){return ks(t)}function Ie(t){ra(t,{recursive:!0})}function Ts(t){let e=[St(nn,"../../assets",t),St(nn,"../assets",t),St(process.cwd(),"assets",t)];for(let n of e)if(ks(n))return n;throw new Error(`Asset not found: ${t}`)}function sn(){if(tn)return tn;let t=[St(nn,"../../package.json"),St(nn,"../package.json"),St(process.cwd(),"package.json")];for(let e of t)if(ks(e))try{let n=JSON.parse(li(e,"utf-8"));if(n.name==="vibespot"&&n.version)return tn=n.version,tn}catch{}return tn="dev",tn}function la(){if(Cs)return Cs;let t=[St(nn,"../../CHANGELOG.md"),St(nn,"../CHANGELOG.md"),St(process.cwd(),"CHANGELOG.md")];for(let e of t)if(ks(e))try{return Cs=li(e,"utf-8"),Cs}catch{}return""}var nn,tn,Cs,ne=R(()=>{"use strict";y();nn=aa(sp(import.meta.url));tn="";Cs=""});import{execSync as ca,execFileSync as op}from"child_process";function te(t,e={}){try{return{stdout:ca(t,{encoding:"utf-8",stdio:["pipe","pipe","pipe"],timeout:12e4,...e}).trim(),stderr:"",success:!0}}catch(n){let s=n,o=(s.stdout??"").toString().trim(),i=(s.stderr??"").toString().trim();return{stdout:o,stderr:i,success:!1}}}function X(t,e={}){try{return{stdout:op("git",t,{encoding:"utf-8",stdio:["pipe","pipe","pipe"],timeout:12e4,...e}).toString().trim(),stderr:"",success:!0}}catch(n){let s=n,o=(s.stdout??"").toString().trim(),i=(s.stderr??"").toString().trim();return{stdout:o,stderr:i,success:!1}}}function da(t,e={}){try{return ca(t,{stdio:"inherit",timeout:3e5,...e}),!0}catch{return!1}}var Jt=R(()=>{"use strict";y()});var pa={};Be(pa,{addHubSpotAccount:()=>An,getActiveHubSpotAccount:()=>It,getApiKeyForEngine:()=>Oe,getConfigDir:()=>ap,getHubSpotPak:()=>Fe,isCliToolEnabled:()=>$n,loadConfig:()=>O,maskApiKey:()=>$s,removeHubSpotAccount:()=>ci,saveConfig:()=>Y,setActiveHubSpotAccount:()=>di,setCliToolEnabled:()=>ui});import{join as ua}from"path";import{homedir as ip}from"os";import{chmodSync as rp}from"fs";function O(){if(!v(As))return{};try{let t=JSON.parse(M(As));return t.aiEngine==="api"&&(t.aiEngine="anthropic-api"),t}catch{return{}}}function Oe(t,e){let n=e||O();switch(t){case"anthropic-api":case"api":return n.anthropicApiKey||process.env.ANTHROPIC_API_KEY;case"openai-api":return n.openaiApiKey||process.env.OPENAI_API_KEY;case"gemini-api":return n.geminiApiKey||process.env.GEMINI_API_KEY||process.env.GOOGLE_AI_API_KEY;default:return}}function $s(t){return t.length<=12?"***":t.slice(0,7)+"..."+t.slice(-4)}function Y(t){let n={...O(),...t};if(J(As,JSON.stringify(n,null,2)),process.platform!=="win32")try{rp(As,384)}catch{}}function ap(){return ma}function It(){let t=O();if(!t.hubspotAccounts?.length)return null;let e=t.activeHubSpotAccount;if(e){let n=t.hubspotAccounts.find(s=>s.portalId===e);if(n)return n}return t.hubspotAccounts[0]||null}function An(t,e,n,s){let i=O().hubspotAccounts||[],r=i.findIndex(l=>l.portalId===e),a={portalId:e,portalName:n,personalAccessKey:t,dataCenter:s,addedAt:new Date().toISOString()};r>=0?i[r]=a:i.push(a),Y({hubspotAccounts:i,activeHubSpotAccount:e})}function ci(t){let e=O(),n=(e.hubspotAccounts||[]).filter(o=>o.portalId!==t),s={hubspotAccounts:n};e.activeHubSpotAccount===t&&(s.activeHubSpotAccount=n[0]?.portalId||void 0),Y(s)}function di(t){Y({activeHubSpotAccount:t})}function Fe(){return It()?.personalAccessKey||null}function $n(t){return O().enabledCLITools?.includes(t)??!1}function ui(t,e){let n=O(),s=new Set(n.enabledCLITools||[]);e?s.add(t):s.delete(t),Y({enabledCLITools:[...s]})}var ma,As,Q=R(()=>{"use strict";y();ne();ma=ua(ip(),".vibespot"),As=ua(ma,"config.json")});var gi={};Be(gi,{OAUTH_EXTRA_HEADERS:()=>_n,OAUTH_SYSTEM_PREFIX:()=>rn,clearOAuthTokens:()=>Es,getOAuthTokenInfo:()=>Mn,getValidAccessToken:()=>pi,hasValidOAuthToken:()=>lt,saveInitialToken:()=>mi});import{join as lp}from"path";import{homedir as cp}from"os";import{chmodSync as dp,unlinkSync as up}from"fs";function Ms(){if(!v(on))return null;try{return JSON.parse(M(on))}catch{return null}}function ga(t){if(J(on,JSON.stringify(t,null,2)),process.platform!=="win32")try{dp(on,384)}catch{}}async function fp(t){let e=await fetch(pp,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"refresh_token",refresh_token:t,client_id:mp})});if(!e.ok)throw Es(),new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let n=await e.json();ga({access_token:n.access_token,refresh_token:n.refresh_token||t,expires_at:Date.now()+(n.expires_in||28800)*1e3})}function mi(t,e=""){ga({access_token:t,refresh_token:e,expires_at:Date.now()+28800*1e3})}function lt(){let t=Ms();return t?t.expires_at>Date.now():!1}async function pi(){let t=Ms();if(!t)return null;if(t.expires_at-Date.now()>gp)return t.access_token;if(t.refresh_token){_s||(_s=fp(t.refresh_token).finally(()=>{_s=null}));try{await _s}catch{return null}return Ms()?.access_token??null}return t.access_token}function Mn(){let t=Ms();return t?{expiresAt:new Date(t.expires_at).toISOString()}:null}function Es(){if(v(on))try{up(on)}catch{}}var mp,pp,on,gp,_n,rn,_s,xt=R(()=>{"use strict";y();ne();mp="9d1c250a-e61b-44d9-88ed-5944d1962f5e",pp="https://console.anthropic.com/v1/oauth/token",on=lp(cp(),".vibespot","claude-oauth.json"),gp=300*1e3,_n={"user-agent":"claude-cli/2.1.75","x-app":"cli","anthropic-beta":"oauth-2025-04-20"},rn="You are Claude Code, Anthropic's official CLI for Claude.";_s=null});import{join as Is}from"path";import{homedir as Ps}from"os";import{readFileSync as fa,existsSync as Rs,readdirSync as hp}from"fs";function En(){let t=te("node --version");return{name:"Node.js",found:t.success,version:t.stdout.replace(/^v/,""),path:te(`${Bt} node`).stdout}}function In(){let t=te("git --version");return{name:"Git",found:t.success,version:t.stdout.replace("git version ",""),path:te(`${Bt} git`).stdout}}function ct(){let t=te("hs --version");return{name:"HubSpot CLI",found:t.success,version:t.stdout,path:te(`${Bt} hs`).stdout}}function Pn(){let t=te("claude --version");if(!t.success)return{name:"Claude Code",found:!1,version:"",path:"",authenticated:!1,authDetail:"Not installed"};let e=Is(Ps(),".claude"),n=!1,s="Not signed in \u2014 run `claude` to authenticate";try{if(Rs(e)){let o=hp(e);(o.some(r=>r.includes("credentials")||r.includes("auth")||r.includes("token")||r===".credentials.json")||o.length>2)&&(n=!0,s="Authenticated")}}catch{}return{name:"Claude Code",found:!0,version:t.stdout,path:te(`${Bt} claude`).stdout,authenticated:n,authDetail:s}}function Rn(t){try{let e=Is(Ps(),".hscli","config.yml");if(!Rs(e))return"na1";let n=fa(e,"utf-8"),s=n.indexOf(`accountId: ${t}`);if(s===-1)return"na1";let o=n.indexOf("personalAccessKey:",s);if(o===-1)return"na1";let r=n.slice(o,o+300).match(/personalAccessKey:[\s>-]*\n\s+(\S+)/);if(!r)return"na1";if(r[1].startsWith("CiRldTE"))return"eu1"}catch{}return"na1"}function dt(){let t=te("hs accounts list");if(!t.success||!t.stdout)return{authenticated:!1,portalName:"",portalId:"",accounts:[]};let e=[],n="",s="",o=t.stdout.match(/Account:\s*(.+?)\s*\((\d+)\)/);o&&(n=o[1].trim(),s=o[2].trim());let i=t.stdout.split(`
2
+ `);for(let r of i){let a=r.match(/^\s*(.+?)\s+(\d{5,})\s+(.*)/);if(a&&!/Account ID/i.test(r)&&!/^-+$/.test(r.trim())&&!/^Name\s/i.test(r.trim())){let l=a[1].trim(),c=a[2].trim(),d=a[3]?.trim()||"unknown";e.push({name:l,portalId:c,authType:d,isDefault:c===s})}}return o?{authenticated:!0,portalName:n,portalId:s,accounts:e}:e.length>0?{authenticated:!0,portalName:e[0].name,portalId:e[0].portalId,accounts:e}:{authenticated:t.stdout.length>0,portalName:"",portalId:"",accounts:[]}}function Nn(){let t=te("gemini --version");if(!t.success)return{name:"Gemini CLI",found:!1,version:"",path:"",authenticated:!1,authDetail:"Not installed"};let e=Is(Ps(),".config","gcloud","application_default_credentials.json"),n=Rs(e),s=!!(process.env.GEMINI_API_KEY||process.env.GOOGLE_API_KEY||process.env.GOOGLE_AI_API_KEY),o=n||s;return{name:"Gemini CLI",found:!0,version:t.stdout,path:te(`${Bt} gemini`).stdout,authenticated:o,authDetail:o?"Authenticated":"Run `gemini` to sign in with Google"}}function On(){let t=te("codex --version");if(!t.success)return{name:"OpenAI Codex CLI",found:!1,version:"",path:"",authenticated:!1,authDetail:"Not installed"};let e=!!process.env.OPENAI_API_KEY,n=!1;try{let i=Is(Ps(),".codex","auth.json");Rs(i)&&(n=fa(i,"utf-8").length>10)}catch{}let s=e||n,o=n?"Authenticated (OAuth)":e?"Authenticated (API key)":"Not authenticated";return{name:"OpenAI Codex CLI",found:!0,version:t.stdout,path:te(`${Bt} codex`).stdout,authenticated:s,authDetail:o}}function hi(){let t=te("gh --version");return{name:"GitHub CLI",found:t.success,version:t.stdout.split(`
3
+ `)[0]?.replace("gh version ","").split(" ")[0]||"",path:te(`${Bt} gh`).stdout}}function yi(){let t=te("gh auth status 2>&1");if(!t.success&&!t.stdout)return{authenticated:!1,username:""};let e=t.stdout||t.stderr||"",n=e.match(/Logged in to github\.com.*account\s+(\S+)/);if(n)return{authenticated:!0,username:n[1]};let s=e.match(/account\s+(\S+)/);return s&&e.includes("Logged in")?{authenticated:!0,username:s[1]}:{authenticated:e.includes("Logged in"),username:""}}function ha(){return!!process.env.ANTHROPIC_API_KEY}function Ns(t){return parseInt(t.split(".")[0],10)>=18}function ya(t){let e=parseInt(t.split(".")[0],10);return!isNaN(e)&&e>=8}function yp(){let t=O(),e=t.hubspotUploadMode||"api",n=t.hubspotAccounts||[],s=n.map(i=>({name:i.portalName,portalId:i.portalId,authType:"personalaccesskey",isDefault:i.portalId===(t.activeHubSpotAccount||n[0]?.portalId)})),o=It();return{authenticated:!!o,portalName:o?.portalName||"",portalId:o?.portalId||"",dataCenter:o?o.dataCenter:"na1",accounts:s,uploadMode:e}}function Os(){let t=O(),e=En(),n=In(),s=t.hubspotUploadMode||"api",o;if(s==="cli"){let S=ct(),x=S.found?dt():{authenticated:!1,portalName:"",portalId:"",accounts:[]},w=x.portalId?Rn(x.portalId):"na1";o={...S,...x,dataCenter:w,uploadMode:"cli"}}else o={name:"HubSpot API",found:!0,version:"v3",path:"",...yp()};let i=hi(),r=i.found?yi():{authenticated:!1,username:""},a={authenticated:lt(),expiresAt:Mn()?.expiresAt},l=t.enabledCLITools||[],c=$n("claude-code")?Pn():{...fi,name:"Claude Code"},d=$n("gemini-cli")?Nn():{...fi,name:"Gemini CLI"},u=$n("codex-cli")?On():{...fi,name:"OpenAI Codex CLI"};function m(S,...x){if(S)return{configured:!0,masked:$s(S),source:"config"};for(let w of x)if(process.env[w])return{configured:!0,masked:$s(process.env[w]),source:"env"};return{configured:!1,masked:"",source:null}}let g=m(t.anthropicApiKey,"ANTHROPIC_API_KEY"),h=m(t.openaiApiKey,"OPENAI_API_KEY"),f=m(t.geminiApiKey,"GEMINI_API_KEY","GOOGLE_AI_API_KEY"),b=[];return c.found&&c.authenticated&&b.push("claude-code"),a.authenticated&&b.push("claude-oauth"),g.configured&&b.push("anthropic-api"),h.configured&&b.push("openai-api"),d.found&&d.authenticated&&b.push("gemini-cli"),f.configured&&b.push("gemini-api"),u.found&&u.authenticated&&b.push("codex-cli"),{tools:{node:e,git:n,hubspot:o,github:{...i,...r},claudeCode:c,claudeOAuth:a,geminiCli:d,codexCli:u},apiKeys:{anthropic:g,openai:h,gemini:f},activeEngine:t.aiEngine||null,availableEngines:b,enabledCLITools:l}}var Bt,fi,Ht=R(()=>{"use strict";y();Jt();Q();xt();Bt=process.platform==="win32"?"where":"which";fi={name:"",found:!1,version:"",path:"",authenticated:!1,authDetail:"Disabled"}});import{readFileSync as bp}from"fs";import{basename as Sp}from"path";async function Sa(t){let e=ba.get(t);if(e&&e.expiresAt-Date.now()>wp)return e;let n=await fetch(`${vt}/localdevauth/v1/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({encodedOAuthRefreshToken:t})});if(!n.ok){let i=await n.text().catch(()=>"");throw new Error(n.status===401||n.status===403?"Invalid or expired Personal Access Key":`Token exchange failed (${n.status}): ${i.slice(0,200)}`)}let s=await n.json(),o={accessToken:s.oauthAccessToken,expiresAt:s.expiresAtMillis,hubId:s.hubId,hubName:s.hubName||""};return ba.set(t,o),o}async function an(t){let{accessToken:e}=await Sa(t);return{Authorization:`Bearer ${e}`}}function Fs(t){return t.replace(/^\/+/,"").split("/").filter(Boolean).map(encodeURIComponent).join("/")}function Cp(t){return t.startsWith("pat-eu1-")?"eu1":t.startsWith("pat-na1-")?"na1":t.startsWith("CiRldTE")?"eu1":"na1"}function kp(t){return new Promise(e=>setTimeout(e,t))}async function Fn(t,e){let n=`HTTP ${t.status}`,s,o;try{let i=await t.json();if(i.message&&typeof i.message=="string"&&(n=i.message),i.category&&typeof i.category=="string"&&(s=i.category),i.errors&&Array.isArray(i.errors)&&i.errors.length>0){let r=i.errors[0];o=r.message||JSON.stringify(r)}}catch{try{let i=await t.text();i&&(n=i.slice(0,500))}catch{}}return{status:t.status,message:e?`${n} (${e})`:n,category:s,detail:o}}async function jn(t,e,n=xp){for(let s=0;s<=n;s++){let o=await fetch(t,e);if(o.status===429||o.status>=500&&s<n){let i=vp*Math.pow(2,s);await kp(i);continue}return o}return fetch(t,e)}async function js(t){let e=await Sa(t),n=`${vt}/account-info/v3/details`,s=await jn(n,{headers:await an(t)});if(!s.ok){let a=await Fn(s);throw new Error(`Failed to get account info: ${a.message}`)}let o=await s.json(),i=String(o.portalId||e.hubId||""),r=e.hubName||o.uiDomain||i;return{portalId:i,portalName:r,dataCenter:Cp(t)}}async function xa(t,e,n){let s=bp(n),o=Sp(n),i=new FormData,r=new Blob([s]);i.append("file",r,o);let a=`${vt}/cms/v3/source-code/published/content/${Fs(e)}`,l=await jn(a,{method:"PUT",headers:await an(t),body:i});if(!l.ok){let c=await Fn(l,e);return{success:!1,path:e,error:c}}return{success:!0,path:e}}async function bi(t,e){let n=`${vt}/cms/v3/source-code/published/content/${Fs(e)}`,s=await jn(n,{method:"DELETE",headers:await an(t)});if(!s.ok&&s.status!==404){let o=await Fn(s,e);throw new Error(`Failed to delete ${e}: ${o.message}`)}}async function va(t,e){let n=`${vt}/cms/v3/source-code/published/content/${Fs(e)}`,s=await jn(n,{method:"GET",headers:await an(t)});if(!s.ok){let i=await Fn(s,e);throw new Error(`Failed to download ${e}: ${i.message}`)}let o=await s.arrayBuffer();return Buffer.from(o)}async function Ds(t,e){let n=`${vt}/cms/v3/source-code/published/metadata/${Fs(e)}`,s=await jn(n,{method:"GET",headers:await an(t)});if(s.status===404)return null;if(!s.ok){let o=await Fn(s,e);throw new Error(`Failed to get metadata for ${e}: ${o.message}`)}return await s.json()}async function wa(t){let e=await an(t),n=[`${vt}/cms/v3/source-code/published/metadata`,`${vt}/cms/v3/source-code/published/metadata/`,`${vt}/designmanager/v1/portals/content/listing`];for(let s of n)try{let o=await fetch(s,{method:"GET",headers:e});if(o.ok){let i=await o.json(),r=i.children||i.objects||(Array.isArray(i)?i:null);if(r&&r.length>0)return r.filter(a=>a.folder)}}catch{}return[]}var vt,xp,vp,wp,ba,Ut=R(()=>{"use strict";y();vt="https://api.hubapi.com",xp=3,vp=1e3,wp=300*1e3,ba=new Map});import*as se from"@clack/prompts";function Si(t){se.isCancel(t)&&(se.cancel(_.muted("Operation cancelled.")),process.exit(0))}async function me(t){se.intro(_.heading(t))}async function pe(t){se.outro(_.success(t))}async function ut(t,e){se.note(t,e?_.heading(e):void 0)}async function be(t){let e=await se.text({message:_.accent(t.message),placeholder:t.placeholder,defaultValue:t.defaultValue,validate:t.validate});return Si(e),e}async function Ae(t){let e=await se.confirm({message:_.accent(t.message),initialValue:t.initialValue??!0});return Si(e),e}async function wt(t){let e=await se.select({message:_.accent(t.message),options:t.options});return Si(e),e}async function Pe(){let t=se.spinner();return{start:e=>t.start(_.muted(e)),stop:e=>t.stop(_.success(e)),message:e=>t.message(_.muted(e))}}function j(t){se.log.info(t)}function G(t){se.log.success(_.success(t))}function ee(t){se.log.warn(_.warn(t))}function z(t){se.log.error(_.error(t))}var Ye=R(()=>{"use strict";y();at()});import{readdirSync as xi,statSync as Tp}from"fs";import{join as ge,basename as vi,extname as Ap}from"path";function Ca(t){return typeof t!="string"||t.length===0||t.length>2048||/[\s;&|`$()<>\\]/.test(t)?!1:!!(/^https?:\/\/[^\s]+$/.test(t)||/^git@[\w.-]+:[\w./~+-]+$/.test(t))}function ka(t){let e=[],n=[ge(t,"src/components/landing"),ge(t,"src/components/sections"),ge(t,"src/components"),ge(t,"src/pages"),ge(t,"app/components"),ge(t,"components")];for(let s of n)if(v(s))try{let o=xi(s);for(let i of o){let r=ge(s,i);if(!Tp(r).isFile())continue;let l=Ap(i);if(![".tsx",".jsx"].includes(l))continue;let c=vi(i,l);if(c.startsWith("ui")||c==="index")continue;let d=M(r),u=$p(c,d);e.push({name:c,path:r,description:u})}}catch{}return e}function $p(t,e){let n=[];return/carousel|slider|swiper|embla/i.test(e)&&n.push("carousel"),/accordion|collapsible|expand/i.test(e)&&n.push("accordion"),/form|submit|input.*email/i.test(e)&&n.push("form"),/nav|navigation|menu/i.test(e)&&n.push("navigation"),/hero|headline|tagline/i.test(e)&&n.push("hero"),/footer|copyright/i.test(e)&&n.push("footer"),/testimonial|quote|review/i.test(e)&&n.push("testimonials"),/pricing|plan|tier/i.test(e)&&n.push("pricing"),/faq|question.*answer/i.test(e)&&n.push("FAQ"),/feature|benefit|advantage/i.test(e)&&n.push("features"),/contact|get.in.touch/i.test(e)&&n.push("contact"),/cta|call.to.action/i.test(e)&&n.push("CTA"),/team|member|bio/i.test(e)&&n.push("team"),n.length===0?t.replace(/Section$/,"").replace(/([A-Z])/g," $1").trim():n.join(", ")}function Ta(t){let e=[ge(t,"src/index.css"),ge(t,"src/globals.css"),ge(t,"src/app/globals.css"),ge(t,"app/globals.css")],n=0,s=[];for(let o of e){if(!v(o))continue;let i=M(o),r=i.match(/--[\w-]+:/g);r&&(n+=r.length);let a=i.match(/font-family:\s*['"]([^'"]+)['"]/g);if(a)for(let c of a){let d=c.match(/['"]([^'"]+)['"]/)?.[1];d&&!s.includes(d)&&s.push(d)}let l=i.match(/@import\s+url\([^)]*fonts\.googleapis\.com[^)]*family=([^&)]+)/g);if(l)for(let c of l){let d=c.match(/family=([^&)]+)/)?.[1]?.replace(/\+/g," ");d&&!s.includes(d)&&s.push(d)}}return{varCount:n,fonts:s}}function Aa(t){let e=[],n=ge(t,"src/hooks");if(v(n))try{let o=xi(n);for(let i of o)/scroll/i.test(i)&&e.push("Scroll animations"),/intersection/i.test(i)&&e.push("Scroll animations")}catch{}let s=ge(t,"src/components/landing");if(v(s))try{let o=xi(s);for(let i of o){if(!i.endsWith(".tsx")&&!i.endsWith(".jsx"))continue;let r=M(ge(s,i));/carousel|embla|swiper/i.test(r)&&!e.includes("Carousel")&&e.push("Carousel"),/accordion|collapsible/i.test(r)&&!e.includes("Accordion")&&e.push("Accordion"),/typing|typewriter/i.test(r)&&!e.includes("Typing animation")&&e.push("Typing animation"),/parallax|requestAnimationFrame/i.test(r)&&!e.includes("Parallax")&&e.push("Parallax")}}catch{}return e.length===0&&e.push("Scroll animations"),e}function $a(t){let e,n=!1;if(t.startsWith("http")||t.startsWith("git@")){if(!Ca(t))throw new Error(`Refusing to clone unsafe source URL: ${t}. Only http(s):// and git@host:path URLs without shell metacharacters are allowed.`);n=!0;let l=vi(t.replace(/\.git$/,""))||"react-source";if(e=ge(process.cwd(),"workspace",l),!v(e)){let c=X(["clone","--depth","1","--",t,e]);if(!c.success)throw new Error(`Failed to clone ${t}: ${c.stderr}`)}}else if(e=t,!v(e))throw new Error(`Directory not found: ${e}`);let s=ka(e),o=v(ge(e,"tailwind.config.ts"))||v(ge(e,"tailwind.config.js")),{varCount:i,fonts:r}=Ta(e),a=Aa(e);return{sourceDir:e,wasCloned:n,components:s,hasTailwind:o,cssVarCount:i,fonts:r,interactions:a}}async function Js(){await me("Source Project");let t=await be({message:"GitHub URL or local path to your React project:",placeholder:"https://github.com/user/my-lovable-page",validate:h=>{if(!h.trim())return"Please enter a URL or path"}}),e,n=!1;if(t.startsWith("http")||t.startsWith("git@")){Ca(t)||(z("Refusing to clone unsafe source URL. Only http(s):// and git@host:path URLs without shell metacharacters are allowed."),process.exit(1)),n=!0;let h=vi(t.replace(/\.git$/,""))||"react-source";if(e=ge(process.cwd(),"workspace",h),v(e))G(`Using existing clone: ${_.dim(e)}`);else{let f=await Pe();f.start("Cloning repository..."),X(["clone","--depth","1","--",t,e]).success||(f.stop("Clone failed"),z(`Failed to clone ${t}. Check the URL and your access permissions.`),process.exit(1)),f.stop(`Cloned to ${_.dim(e)}`)}}else e=t,v(e)||(z(`Directory not found: ${e}`),process.exit(1)),G(`Using local source: ${_.dim(e)}`);let s=await Pe();s.start("Analyzing project structure...");let o=ka(e),i=v(ge(e,"tailwind.config.ts"))||v(ge(e,"tailwind.config.js")),{varCount:r,fonts:a}=Ta(e),l=Aa(e);s.stop(`Found ${o.length} landing page components`),o.length===0&&(ee("No components found. Make sure the React source has .tsx/.jsx files in src/components/"),process.exit(1));let c=o.map((h,f)=>` ${_.dim(`${f+1}.`)} ${_.bold(h.name)} ${_.muted(`\u2014 ${h.description}`)}`).join(`
4
+ `),d=i?`Tailwind + custom CSS (${r} variables)`:`Custom CSS (${r} variables)`,u=a.length>0?a.join(", "):"System fonts",m=l.join(", ");return await ut(`${c}
5
+
6
+ CSS: ${d}
7
+ JS: ${m}
8
+ Font: ${u}`,`${o.length} components detected`),await Ae({message:"Does this look right?"})||(z("Please adjust your source directory and try again."),process.exit(0)),await pe("Source analyzed!"),{sourceDir:e,wasCloned:n,components:o,hasTailwind:i,cssVarCount:r,fonts:a,interactions:l}}var Bs=R(()=>{"use strict";y();Jt();ne();Ye();at()});var _a={};Be(_a,{addEmailTemplateToTheme:()=>ln,createThemeScaffold:()=>Ln});import{mkdirSync as Ct,writeFileSync as Dn}from"fs";import{join as He}from"path";function Ln(t,e){Ct(t,{recursive:!0}),Ct(He(t,"templates"),{recursive:!0}),Ct(He(t,"modules"),{recursive:!0}),Ct(He(t,"css"),{recursive:!0}),Ct(He(t,"js"),{recursive:!0}),Ct(He(t,"images"),{recursive:!0}),Ct(He(t,"assets"),{recursive:!0});let n={label:e,preview_path:"./templates/home.html",screenshot_path:"./images/template-previews/home.png",enable_domain_stylesheets:!1,version:"1.0.0",author:{name:"vibeSpot",url:"https://github.com/borismichel/vibespot"}};Dn(He(t,"theme.json"),JSON.stringify(n,null,2)+`
9
+ `),Dn(He(t,"fields.json"),`[]
3
10
  `);let s=`<!--
4
11
  templateType: page
5
12
  isAvailableForNewContent: false
6
- label: ${t} (placeholder)
13
+ label: ${e} (placeholder)
7
14
  screenshotPath: ../images/template-previews/home.png
8
15
  -->
9
16
  {% extends "./layouts/base.html" %}
@@ -11,11 +18,11 @@ var Vc=Object.defineProperty;var L=(e,t)=>()=>(e&&(t=e(e=0)),t);var ke=(e,t)=>{f
11
18
  {% block body %}
12
19
  {% dnd_area "main_content"
13
20
  label="Main Content",
14
- class="body-container body-container--${t}"
21
+ class="body-container body-container--${e}"
15
22
  %}
16
23
  {% end_dnd_area %}
17
24
  {% endblock body %}
18
- `;Zn(Pe(e,"templates","home.html"),s);let o=`<!--
25
+ `;Dn(He(t,"templates","home.html"),s);let o=`<!--
19
26
  templateType: none
20
27
  isAvailableForNewContent: false
21
28
  label: Base Layout
@@ -38,8 +45,47 @@ var Vc=Object.defineProperty;var L=(e,t)=>()=>(e&&(t=e(e=0)),t);var ke=(e,t)=>{f
38
45
  {{ standard_footer_includes }}
39
46
  </body>
40
47
  </html>
41
- `;mt(Pe(e,"templates","layouts"),{recursive:!0}),Zn(Pe(e,"templates","layouts","base.html"),o)}var Qn=L(()=>{"use strict";f()});var er={};ke(er,{fetchTheme:()=>dn});import{mkdirSync as Qi,writeFileSync as bd}from"fs";import{join as Sd,dirname as xd}from"path";async function mo(e,t){let n=await Yn(e,t);if(!n)return[];if(!n.folder)return[n.path||t];let s=[],o=n.children||[];for(let i of o){let a=typeof i=="string"?i:i.name;if(!a)continue;let r=`${t}/${a}`;if(typeof i=="string")s.push(...await mo(e,r));else{let l=i;l.folder?s.push(...await mo(e,l.path||r)):s.push(l.path||r)}}return s}async function vd(e,t,n){let s=0;async function o(){for(;s<e.length;){let a=s++;await n(e[a])}}let i=Array.from({length:Math.min(t,e.length)},()=>o());await Promise.all(i)}async function dn(e,t,n,s={}){let o=s.concurrency??5,i=await mo(e,t);if(i.length===0)throw new Error(`Theme "${t}" not found on HubSpot or is empty`);Qi(n,{recursive:!0}),await vd(i,o,async a=>{let r=a.startsWith(t+"/")?a.slice(t.length+1):a,l=Sd(n,r);Qi(xd(l),{recursive:!0});let c=await Vi(e,a);bd(l,c),s.onFile?.(r)})}var es=L(()=>{"use strict";f();bt()});function Ft(e){let t=tr.get(e);if(t!==void 0)return t;try{t=E(Fn(e))}catch{t=""}return tr.set(e,t),t}function ce(){return Ft("conversion-guide.md")||"Conversion guide not found. Using built-in rules."}function po(){return Ft("design-guide.md")}function go(){return Ft("content-guide.md")}function Me(){return Ft("hubspot-rules.md")}function fo(){return Ft("humanify-guide.md")}function ho(e){let t=Ft("page-types.md");if(!t)return"";let s={landing_page:"## Landing Page",blog_post:"## Blog Post",website_page:"## Website Page",module_only:"## Module Only"}[e];if(!s)return"";let o=t.indexOf(s);if(o<0)return"";let i=t.indexOf(`
42
- ## `,o+s.length);return i>=0?t.slice(o,i).trim():t.slice(o).trim()}function nr(e){return`You are a HubSpot CMS expert converting React/Tailwind pages to native HubSpot modules.
48
+ `;Ct(He(t,"templates","layouts"),{recursive:!0}),Dn(He(t,"templates","layouts","base.html"),o)}function ln(t,e){let n=`<!--
49
+ templateType: email
50
+ isAvailableForNewContent: true
51
+ label: ${e} Email Template
52
+ screenshotPath: ../images/template-previews/email.png
53
+ -->
54
+ <!DOCTYPE html>
55
+ <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
56
+ <head>
57
+ <meta charset="utf-8">
58
+ <meta name="viewport" content="width=device-width, initial-scale=1">
59
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
60
+ <!--[if mso]>
61
+ <noscript>
62
+ <xml>
63
+ <o:OfficeDocumentSettings>
64
+ <o:AllowPNG/>
65
+ <o:PixelsPerInch>96</o:PixelsPerInch>
66
+ </o:OfficeDocumentSettings>
67
+ </xml>
68
+ </noscript>
69
+ <![endif]-->
70
+ {{ standard_header_includes }}
71
+ {{ dnd_area_stylesheet }}
72
+ </head>
73
+ <body style="margin:0;padding:0;background-color:#f4f4f4;font-family:Arial,Helvetica,sans-serif;-webkit-font-smoothing:antialiased;">
74
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color:#f4f4f4;">
75
+ <tr>
76
+ <td align="center" style="padding:20px 0;">
77
+ {% dnd_area "main"
78
+ label="Email Content"
79
+ %}
80
+ {% end_dnd_area %}
81
+ </td>
82
+ </tr>
83
+ </table>
84
+ {{ standard_footer_includes }}
85
+ </body>
86
+ </html>
87
+ `;Ct(He(t,"templates"),{recursive:!0}),Dn(He(t,"templates","email.html"),n)}var Jn=R(()=>{"use strict";y()});var Ea={};Be(Ea,{fetchTheme:()=>Bn});import{mkdirSync as Ma,writeFileSync as _p}from"fs";import{join as Mp,dirname as Ep}from"path";async function wi(t,e){let n=await Ds(t,e);if(!n)return[];if(!n.folder)return[n.path||e];let s=[],o=n.children||[];for(let i of o){let r=typeof i=="string"?i:i.name;if(!r)continue;let a=`${e}/${r}`;if(typeof i=="string")s.push(...await wi(t,a));else{let l=i;l.folder?s.push(...await wi(t,l.path||a)):s.push(l.path||a)}}return s}async function Ip(t,e,n){let s=0;async function o(){for(;s<t.length;){let r=s++;await n(t[r])}}let i=Array.from({length:Math.min(e,t.length)},()=>o());await Promise.all(i)}async function Bn(t,e,n,s={}){let o=s.concurrency??5,i=await wi(t,e);if(i.length===0)throw new Error(`Theme "${e}" not found on HubSpot or is empty`);Ma(n,{recursive:!0}),await Ip(i,o,async r=>{let a=r.startsWith(e+"/")?r.slice(e.length+1):r,l=Mp(n,a);Ma(Ep(l),{recursive:!0});let c=await va(t,r);_p(l,c),s.onFile?.(a)})}var Hs=R(()=>{"use strict";y();Ut()});function Pt(t){let e=Ia.get(t);if(e!==void 0)return e;try{e=M(Ts(t))}catch{e=""}return Ia.set(t,e),e}function fe(){return Pt("conversion-guide.md")||"Conversion guide not found. Using built-in rules."}function Un(){return Pt("design-guide.md")}function Ci(){return Pt("content-guide.md")}function je(){return Pt("hubspot-rules.md")}function ki(){return Pt("humanify-guide.md")}function Pa(){return Pt("email-rules.md")}function Ra(){return Pt("blog-rules.md")}function Ti(t){let e=Pt("page-types.md");if(!e)return"";let s={landing_page:"## Landing Page",blog_post:"## Blog Post",website_page:"## Website Page",module_only:"## Module Only"}[t];if(!s)return"";let o=e.indexOf(s);if(o<0)return"";let i=e.indexOf(`
88
+ ## `,o+s.length);return i>=0?e.slice(o,i).trim():e.slice(o).trim()}function Na(t){return`You are a HubSpot CMS expert converting React/Tailwind pages to native HubSpot modules.
43
89
 
44
90
  ## Rules
45
91
  Follow the conversion guide below EXACTLY. Key rules:
@@ -56,10 +102,10 @@ Follow the conversion guide below EXACTLY. Key rules:
56
102
  - Convert React hooks to vanilla JS (no React, no npm packages)
57
103
 
58
104
  ## HubSpot CMS Rules
59
- ${Me()}
105
+ ${je()}
60
106
 
61
107
  ## Conversion Guide
62
- ${e}`}function sr(e,t,n){return`Convert this React component to a HubSpot module named "${t}".
108
+ ${t}`}function Oa(t,e,n){return`Convert this React component to a HubSpot module named "${e}".
63
109
 
64
110
  Return a JSON object with these keys:
65
111
  - fieldsJson: complete fields.json content (as JSON string)
@@ -72,9 +118,9 @@ Design system CSS variables available:
72
118
  ${n}
73
119
 
74
120
  React component source:
75
- ${e}
121
+ ${t}
76
122
 
77
- Return ONLY valid JSON, no markdown fences.`}function or(e,t,n){return`Create a shared CSS file for a HubSpot CMS landing page.
123
+ Return ONLY valid JSON, no markdown fences.`}function Fa(t,e,n){return`Create a shared CSS file for a HubSpot CMS landing page.
78
124
 
79
125
  Extract the design system from the source CSS and Tailwind config below.
80
126
  Use the class prefix ".${n}-" for all custom classes.
@@ -93,12 +139,12 @@ Requirements:
93
139
  - Responsive grid fallbacks
94
140
 
95
141
  Source CSS:
96
- ${e}
142
+ ${t}
97
143
 
98
144
  Tailwind config:
99
- ${t}
145
+ ${e}
100
146
 
101
- Return ONLY the CSS content, no markdown fences.`}function ir(e,t,n){return`Create a shared vanilla JS file for a HubSpot CMS landing page.
147
+ Return ONLY the CSS content, no markdown fences.`}function ja(t,e,n){return`Create a shared vanilla JS file for a HubSpot CMS landing page.
102
148
 
103
149
  Convert the React hooks and interactive components below to plain JavaScript.
104
150
  Use the class prefix "${n}-" to match the CSS.
@@ -111,14 +157,14 @@ Requirements:
111
157
  - DOMContentLoaded / readyState check
112
158
 
113
159
  React hooks source:
114
- ${e}
160
+ ${t}
115
161
 
116
162
  Interactive component sources:
117
- ${t}
163
+ ${e}
118
164
 
119
- Return ONLY the JavaScript content, no markdown fences.`}function rr(e,t,n){return`Create a HubSpot page template that assembles these modules:
165
+ Return ONLY the JavaScript content, no markdown fences.`}function Da(t,e,n){return`Create a HubSpot page template that assembles these modules:
120
166
 
121
- ${e.map((s,o)=>`${o+1}. ${s}.module`).join(`
167
+ ${t.map((s,o)=>`${o+1}. ${s}.module`).join(`
122
168
  `)}
123
169
 
124
170
  Template requirements:
@@ -129,32 +175,39 @@ Template requirements:
129
175
  - Empty header and footer blocks (modules handle them)
130
176
  - Wrap content in <div class="${n}-page">
131
177
  - Each module in its own dnd_section with padding zeroed and full_width=true
132
- - dnd_area label: "${t} Landing Page"
133
-
134
- Return ONLY the template HTML content, no markdown fences.`}var tr,ot=L(()=>{"use strict";f();te();tr=new Map});var _r=L(()=>{"use strict";f()});import{existsSync as rt,writeFileSync as Yd,mkdirSync as qd}from"fs";import{join as Ve}from"path";function Pr(e){return/^[0-9a-f]{4,40}$/i.test(e)}function Oe(){return ps!==null||(ps=J("git --version").success),ps}function gs(e){if(!Oe())return!1;if(rt(Ve(e,".git")))return Nr(e),!0;let t=J("git init",{cwd:e});return t.success?(Xd(e),Nr(e),J("git add -A",{cwd:e}),J('git commit -m "Initial theme"',{cwd:e}),!0):(console.warn(`[project-git] git init failed in ${e}: ${t.stderr}`),!1)}function Nr(e){let t=Ve(e,".vibespot");rt(t)||qd(t,{recursive:!0})}function Xd(e){let t=Ve(e,".gitignore");Yd(t,[".vibespot/","node_modules/",""].join(`
135
- `),"utf-8")}function St(e,t){if(!Oe()||!rt(Ve(e,".git"))||(J("git add -A",{cwd:e}),J("git diff --cached --quiet",{cwd:e}).success))return null;let s=t.length>72?t.slice(0,69)+"...":t,o=J(`git commit -m "${s.replace(/"/g,'\\"')}"`,{cwd:e});if(!o.success)return console.warn(`[project-git] commit failed: ${o.stderr}`),null;let i=J("git rev-parse --short HEAD",{cwd:e});return i.success?i.stdout:null}function bo(e,t,n,s){if(!Oe()||!rt(Ve(e,".git")))return null;for(let u of s){let m=Ve(e,u);rt(m)&&J(`git add "${u}"`,{cwd:e})}if(J("git diff --cached --quiet",{cwd:e}).success)return null;let i=`[${t}] `,a=72-i.length,r=n.length>a?n.slice(0,a-3)+"...":n,l=i+r,c=J(`git commit -m "${l.replace(/"/g,'\\"')}"`,{cwd:e});if(!c.success)return console.warn(`[project-git] template commit failed: ${c.stderr}`),null;let d=J("git rev-parse --short HEAD",{cwd:e});return d.success?d.stdout:null}function Mr(e,t=50){if(!Oe())return[];if(!rt(Ve(e,".git")))return[];let n=J(`git log --pretty=format:"%h|%H|%s|%at" -n ${t}`,{cwd:e});if(!n.success||!n.stdout.trim())return[];let s=[];for(let o of n.stdout.split(`
136
- `)){let i=o.split("|");if(i.length<4)continue;let a=parseInt(i[3],10)*1e3;s.push({hash:i[0],fullHash:i[1],message:i[2],timestamp:a,date:new Date(a).toISOString()})}return s}function Or(e,t,n=50){if(!Oe())return[];if(!rt(Ve(e,".git")))return[];let s=t.replace(/[[\]\\]/g,"\\$&"),o=J(`git log --grep="\\[${s}\\]" --pretty=format:"%h|%H|%s|%at" -n ${n}`,{cwd:e});if(!o.success||!o.stdout.trim())return[];let i=[];for(let a of o.stdout.split(`
137
- `)){let r=a.split("|");if(r.length<4)continue;let l=parseInt(r[3],10)*1e3;i.push({hash:r[0],fullHash:r[1],message:r[2],timestamp:l,date:new Date(l).toISOString()})}return i}function Rr(e,t){if(!Oe())return{success:!1,error:"Git not available"};if(!rt(Ve(e,".git")))return{success:!1,error:"Not a git repo"};if(!Pr(t))return{success:!1,error:"Invalid commit hash"};let n=J(`git cat-file -t ${t}`,{cwd:e});if(!n.success||n.stdout.trim()!=="commit")return{success:!1,error:`Commit ${t} not found`};let s=J(`git log --format="%s" -1 ${t}`,{cwd:e}),o=s.success?s.stdout:t,i=J(`git checkout ${t} -- .`,{cwd:e});if(!i.success)return{success:!1,error:`Checkout failed: ${i.stderr}`};let a=`Rollback to: ${o}`.slice(0,72);return J(`git commit -m "${a.replace(/"/g,'\\"')}"`,{cwd:e}),{success:!0}}function Fr(e,t,n,s){if(!Oe())return{success:!1,error:"Git not available"};if(!rt(Ve(e,".git")))return{success:!1,error:"Not a git repo"};if(!Pr(n))return{success:!1,error:"Invalid commit hash"};let o=J(`git cat-file -t ${n}`,{cwd:e});if(!o.success||o.stdout.trim()!=="commit")return{success:!1,error:`Commit ${n} not found`};let i=J(`git log --format="%s" -1 ${n}`,{cwd:e}),a=i.success?i.stdout:n,r=0;for(let d of s)J(`git checkout ${n} -- "${d}"`,{cwd:e}).success&&r++;if(r===0)return{success:!1,error:"No files could be restored from that commit"};J("git add -A",{cwd:e});let c=`${`[${t}] `}Rollback to: ${a}`.slice(0,72);return J(`git commit -m "${c.replace(/"/g,'\\"')}"`,{cwd:e}),{success:!0}}var ps,jt=L(()=>{"use strict";f();ht();ps=null});import{appendFileSync as Zd,mkdirSync as Qd,readdirSync as eu,unlinkSync as tu}from"fs";import{join as wo}from"path";import{homedir as nu}from"os";function ou(){if(!xo)try{Qd(fs,{recursive:!0}),xo=!0}catch{}}function iu(){if(!vo){vo=!0;try{let e=Date.now()-su*864e5;for(let t of eu(fs)){if(!t.startsWith("vibespot-")||!t.endsWith(".log"))continue;let n=t.slice(9,19),s=new Date(n).getTime();if(s&&s<e)try{tu(wo(fs,t))}catch{}}}catch{}}}function ru(){let t=new Date().toISOString().slice(0,10);return wo(fs,`vibespot-${t}.log`)}function au(){return new Date().toISOString().slice(11,23)}function So(e,t){if(ou(),!!xo){vo||iu();try{Zd(ru(),`${au()} ${e} ${t}
138
- `)}catch{}}}var fs,su,xo,vo,A,ie=L(()=>{"use strict";f();fs=wo(nu(),".vibespot","logs"),su=7,xo=!1,vo=!1;A={info(e,t,n){let s=n?`[${e}] ${t} ${JSON.stringify(n)}`:`[${e}] ${t}`;console.log(s),So("INFO",s)},warn(e,t,n){let s=n?`[${e}] ${t} ${JSON.stringify(n)}`:`[${e}] ${t}`;console.warn(s),So("WARN",s)},error(e,t,n){let s=n instanceof Error?n.message:n?String(n):"",o=s?`[${e}] ${t}: ${s}`:`[${e}] ${t}`;console.error(o),So("ERROR",o)}}});import{readFileSync as lu,existsSync as jr,writeFileSync as cu,mkdirSync as du,rmSync as uu}from"fs";import{join as hs}from"path";function xt(e){let t=v();t&&(t.modules=e.modules,t.moduleOrder=e.moduleOrder,t.sharedCss=e.sharedCss,t.sharedJs=e.sharedJs,t.template=e.template,t.messages=e.messages)}function pt(){let e=v();if(!e)return;let t=xe();t&&(t.modules=e.modules,t.moduleOrder=e.moduleOrder,t.sharedCss=e.sharedCss,t.sharedJs=e.sharedJs,t.template=e.template,t.messages=e.messages)}function Re(e,t,n){let s=v();if(!s)return;let o={role:e,content:t,timestamp:Date.now()};n&&(o.pipeline=n),s.messages.push(o),s.updatedAt=Date.now(),pt(),pu()}function Dr(e){let t=v();t&&(t.assets||(t.assets=[]),t.assets.push(e),t.updatedAt=Date.now(),j())}function Jr(e){return e.toLowerCase().replace(/[\s\-_]+/g,"")}function mu(e,t){let n=Jr(e),s=Jr(t);return n===s?!0:n.length<4||s.length<4?!1:n.includes(s)||s.includes(n)}function oe(e){let t=v();if(t){if(e.sharedCss!==void 0&&(t.sharedCss=e.sharedCss),e.sharedJs!==void 0&&(t.sharedJs=e.sharedJs),e.template!==void 0&&(t.template=e.template),e.modules)for(let n of e.modules){let s=n.moduleName.toLowerCase(),o=t.modules.findIndex(i=>i.moduleName.toLowerCase()===s);if(o>=0)t.modules[o]=n;else{let i=t.modules.find(a=>mu(a.moduleName,n.moduleName));i&&A.warn("session-state",`Module "${n.moduleName}" looks like a renamed variant of existing "${i.moduleName}" \u2014 adding as a new module. This usually indicates the Module Planner re-named an existing module. Check the prompt's "preserve existing names" rule.`),t.modules.push(n),t.moduleOrder.some(a=>a.toLowerCase()===s)||t.moduleOrder.push(n.moduleName)}}t.updatedAt=Date.now(),pt()}}function Ke(e){let t=v();t&&(t.moduleOrder=e,t.updatedAt=Date.now(),pt())}function Hr(e){let t=v();if(t){t.modules=t.modules.filter(n=>n.moduleName!==e),t.moduleOrder=t.moduleOrder.filter(n=>n!==e);for(let n of t.templates)n.modules=n.modules.filter(s=>s.moduleName!==e),n.moduleOrder=n.moduleOrder.filter(s=>s!==e);if(t.themePath){let n=hs(t.themePath,"modules",`${e}.module`);jr(n)&&uu(n,{recursive:!0,force:!0})}t.updatedAt=Date.now(),pt()}}function Lr(e){let t=v();t&&(t.moduleOrder=t.moduleOrder.filter(n=>n!==e),t.updatedAt=Date.now(),pt())}function Br(e,t,n){let s=v();if(!s)return;let o=s.modules.find(i=>i.moduleName===e);if(o)try{let i=JSON.parse(o.fieldsJson);Gr(i,t,n),o.fieldsJson=JSON.stringify(i,null,2),s.updatedAt=Date.now(),pt()}catch{}}function X(){let e=v();if(!e)return[];let t=[];for(let n of e.moduleOrder){let s=e.modules.find(o=>o.moduleName===n);s&&t.push(s)}for(let n of e.modules)e.moduleOrder.includes(n.moduleName)||t.push(n);return t}function pu(){let e=v();if(e)try{let t=hs(e.themePath,".vibespot");du(t,{recursive:!0});let n={sessionId:e.id,themeName:e.themeName,messages:e.messages,updatedAt:Date.now()};cu(hs(t,"chat.json"),JSON.stringify(n,null,2),"utf-8")}catch{}}function Ur(e){let t=hs(e,".vibespot","chat.json");if(!jr(t))return[];try{let n=JSON.parse(lu(t,"utf-8"));return Array.isArray(n.messages)?n.messages:[]}catch{return[]}}function Gr(e,t,n){let s=t.split("."),o=s[0],i=e.find(a=>a.name===o);i&&(s.length===1?i.default=n:i.children&&Gr(i.children,s.slice(1).join("."),n))}var pn=L(()=>{"use strict";f();gn();Dt();ie()});import{existsSync as Co,rmSync as ko}from"fs";import{join as fn}from"path";function ys(e){if(e.templates&&e.templates.length>0)return;if(!e.modules||e.modules.length===0){e.templates=[],e.activeTemplateId="";return}let t=`lp-${e.themeName}`,n={id:t,label:`${e.themeName} Landing Page`,pageType:"landing_page",templateFile:`templates/lp-${e.themeName}.html`,modules:[...e.modules],moduleOrder:[...e.moduleOrder],sharedCss:e.sharedCss||"",sharedJs:e.sharedJs||"",template:e.template||"",messages:[...e.messages]};e.templates=[n],e.activeTemplateId=t}function xe(){let e=v();return!e||!e.activeTemplateId||!e.templates?.length?null:e.templates.find(t=>t.id===e.activeTemplateId)||null}function Ao(e){let t=v();if(!t)return!1;let n=t.templates.find(s=>s.id===e);return n?(t.activeTemplateId=e,xt(n),t.updatedAt=Date.now(),!0):!1}function bs(e,t){let n=v();if(!n)throw new Error("No active session");let s=t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),i=`${e==="blog_post"?"bp":e==="website_page"?"wp":e==="module_only"?"mo":"lp"}-${s}`,a={id:i,label:t,pageType:e,templateFile:e==="module_only"?"":`templates/${i}.html`,modules:[],moduleOrder:[],sharedCss:"",sharedJs:"",template:"",messages:[]};return n.templates.push(a),n.activeTemplateId=i,xt(a),n.updatedAt=Date.now(),a}function Wr(e,t){let n=v();if(!n)return null;let s=n.templates.find(c=>c.id===e);if(!s)return null;let o=t||`${s.label} (Copy)`,i=o.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),r=`${s.pageType==="blog_post"?"bp":s.pageType==="website_page"?"wp":s.pageType==="module_only"?"mo":"lp"}-${i}`,l={id:r,label:o,pageType:s.pageType,templateFile:s.pageType==="module_only"?"":`templates/${r}.html`,modules:s.modules.map(c=>({...c})),moduleOrder:[...s.moduleOrder],sharedCss:s.sharedCss,sharedJs:s.sharedJs,template:s.template,messages:[]};return n.templates.push(l),n.activeTemplateId=r,xt(l),n.updatedAt=Date.now(),l}function Vr(e,t){let n=v();if(!n)return!1;let s=n.templates.find(o=>o.id===e);return s?(s.label=t,n.updatedAt=Date.now(),!0):!1}function Kr(e,t=!1){let n=v();if(!n)return!1;let s=n.templates.findIndex(i=>i.id===e);if(s<0)return!1;let o=n.templates.splice(s,1)[0];if(n.themePath){let i=fn(n.themePath,"templates"),a=`${o.id}.html`,r=fn(i,a);if(Co(r)&&ko(r,{force:!0}),o.pageType==="blog_post"){let l=fn(i,`${o.id}-listing.html`);Co(l)&&ko(l,{force:!0})}}if(t&&o.modules.length>0){let i=new Set;for(let r of n.templates)for(let l of r.modules)i.add(l.moduleName);for(let r of n.modules)i.add(r.moduleName);let a=o.modules.map(r=>r.moduleName).filter(r=>!i.has(r));if(n.themePath&&a.length>0){let r=fn(n.themePath,"modules");for(let l of a){let c=fn(r,`${l}.module`);Co(c)&&ko(c,{recursive:!0,force:!0})}}}return n.activeTemplateId===e&&(n.templates.length>0?Ao(n.templates[0].id):(n.activeTemplateId="",n.modules=[],n.moduleOrder=[],n.sharedCss="",n.sharedJs="",n.template="",n.messages=[])),n.updatedAt=Date.now(),!0}function at(){let e=v();if(!e)return[];let t=new Map;for(let n of e.templates)for(let s of n.modules){let o=t.get(s.moduleName);o?o.usedIn.push(n.label):t.set(s.moduleName,{module:s,usedIn:[n.label]})}return Array.from(t.values())}var Dt=L(()=>{"use strict";f();gn();pn()});import{readFileSync as lt,readdirSync as _o,existsSync as ve,writeFileSync as Ss,mkdirSync as zr,rmSync as $o,renameSync as To}from"fs";import{join as ue,dirname as gu}from"path";import{homedir as fu}from"os";function xs(){if(Ht)return Ht;try{return ve(Io)?(Ht=JSON.parse(lt(Io,"utf-8")),Ht):Eo()}catch{return Eo()}}function vs(e){Ht=e;try{zr(re,{recursive:!0}),Ss(Io,JSON.stringify(e),"utf-8")}catch{}}function Eo(){if(!ve(re))return[];let e=[];for(let t of _o(re).filter(n=>n.endsWith(".json")&&n!=="_index.json"))try{let n=JSON.parse(lt(ue(re,t),"utf-8")),s=n.templates||[];e.push({id:n.id,themeName:n.themeName,updatedAt:n.updatedAt,moduleCount:s.reduce((o,i)=>o+(i.modules?.length||0),0),templateCount:s.length})}catch{}return Ht=e,vs(e),e}function hu(e){let t=xs(),n=e.templates||[],s={id:e.id,themeName:e.themeName,updatedAt:e.updatedAt,moduleCount:n.reduce((i,a)=>i+(a.modules?.length||0),0),templateCount:n.length},o=t.findIndex(i=>i.id===e.id);o>=0?t[o]=s:t.push(s),vs(t)}function yu(e){let t=xs().filter(n=>n.id!==e);vs(t)}function bu(e){let t=xs().filter(n=>n.themeName!==e);vs(t)}function v(){return we}function Su(){return`vibe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function vt(e,t){let n={id:Su(),themePath:e,themeName:t,templates:[],activeTemplateId:"",messages:[],modules:[],sharedCss:"",sharedJs:"",template:"",moduleOrder:[],createdAt:Date.now(),updatedAt:Date.now()};return we=n,gs(e),n}function j(){if(!we)return;zr(re,{recursive:!0});let e=ue(re,`${we.id}.json`);Ss(e,JSON.stringify(we,null,2),"utf-8"),hu(we)}function ws(e){let t=ue(re,e+".json");if(!ve(t))return null;try{let n=JSON.parse(lt(t,"utf-8"));return n.templates||(n.templates=[]),n.activeTemplateId||(n.activeTemplateId=""),ys(n),we=n,n}catch{return null}}function Lt(){return ve(re)?xs():[]}function Yr(e,t=!1){let n=ue(re,e+".json"),s="";if(t)try{let o=JSON.parse(lt(n,"utf-8"));s=o.themeName||"",o.themePath&&ve(o.themePath)&&$o(o.themePath,{recursive:!0,force:!0})}catch{}else try{s=JSON.parse(lt(n,"utf-8")).themeName||""}catch{}try{ve(n)&&$o(n)}catch{}if(s&&ve(re)){for(let o of _o(re).filter(i=>i.endsWith(".json")&&i!=="_index.json"))try{JSON.parse(lt(ue(re,o),"utf-8")).themeName===s&&$o(ue(re,o))}catch{}bu(s)}else yu(e);we?.id===e&&(we=null)}function qr(e,t){let n=ue(re,e+".json");if(!ve(n))return{ok:!1,error:"Session not found"};let s;try{s=JSON.parse(lt(n,"utf-8"))}catch{return{ok:!1,error:"Failed to read session"}}let o=s.themeName;if(o===t)return{ok:!0};let i=s.themePath,a=ue(gu(i),t);if(ve(i)){if(ve(a))return{ok:!1,error:"A project with that name already exists"};try{To(i,a)}catch(m){return{ok:!1,error:`Failed to rename folder: ${m instanceof Error?m.message:String(m)}`}}let r=ue(a,"css",`${o}-theme.css`),l=ue(a,"css",`${t}-theme.css`);if(ve(r))try{To(r,l)}catch{}let c=ue(a,"js",`${o}-animations.js`),d=ue(a,"js",`${t}-animations.js`);if(ve(c))try{To(c,d)}catch{}let u=ue(a,"theme.json");if(ve(u))try{let m=JSON.parse(lt(u,"utf-8"));m.label=t,m.name=t,Ss(u,JSON.stringify(m,null,2),"utf-8")}catch{}}if(ve(re))for(let r of _o(re).filter(l=>l.endsWith(".json")&&l!=="_index.json"))try{let l=JSON.parse(lt(ue(re,r),"utf-8"));l.themeName===o&&(l.themeName=t,l.themePath=a,l.updatedAt=Date.now(),Ss(ue(re,r),JSON.stringify(l,null,2),"utf-8"))}catch{}return we&&we.themeName===o&&(we.themeName=t,we.themePath=a,we.updatedAt=Date.now()),Eo(),{ok:!0}}var re,Io,Ht,we,gn=L(()=>{"use strict";f();jt();Dt();re=ue(fu(),".vibespot","sessions"),Io=ue(re,"_index.json"),Ht=null;we=null});import{readFileSync as No,readdirSync as yn,existsSync as me,writeFileSync as Ee,mkdirSync as hn,rmSync as Xr}from"fs";import{join as D}from"path";function ae(e){try{return No(e,"utf-8")}catch{return""}}function xu(e){let t=[];for(let n of e.moduleOrder){let s=e.modules.find(o=>o.moduleName===n);s&&t.push(s)}for(let n of e.modules)e.moduleOrder.includes(n.moduleName)||t.push(n);return t}function vu(e,t){let n=ae(e);if(!n||t==="home.html"||t.endsWith("-listing.html"))return null;let s=t.replace(/\.html$/,""),o="landing_page";s.startsWith("bp-")?o="blog_post":s.startsWith("wp-")?o="website_page":s.startsWith("mo-")&&(o="module_only");let i=s,a=n.match(/<!--[\s\S]*?label:\s*"?([^"\n]+)"?\s*[\s\S]*?-->/);a&&(i=a[1].trim());let r=/dnd_module\s+path=["']\.\.\/modules\/(.+?)\.module["']/g,l=[],c;for(;(c=r.exec(n))!==null;)l.push(c[1]);return{id:s,label:i,pageType:o,moduleNames:l,templateContent:n,filename:t}}function wu(e,t,n,s,o){if(!me(e))return[];let i=[],a=yn(e).filter(r=>r.endsWith(".html")&&r!=="home.html");for(let r of a){let l=D(e,r),c=vu(l,r);if(!c||c.moduleNames.length===0&&i.length>0)continue;let d=[],u=[];for(let m of c.moduleNames){let g=t.get(m);g&&(d.push(g),u.push(m))}i.push({id:c.id,label:c.label,pageType:c.pageType,templateFile:`templates/${c.filename}`,modules:d,moduleOrder:u,sharedCss:n,sharedJs:s,template:c.templateContent,messages:i.length===0?[...o]:[]})}return i}function bn(e){let t=v();if(!t)return;let n=Ur(e);n.length>0&&t.messages.length===0&&(t.messages=n),gs(e);let s=D(e,"modules");if(!me(s))return;let o=yn(s,{withFileTypes:!0});for(let b of o){if(!b.isDirectory()||!b.name.endsWith(".module"))continue;let x=D(s,b.name),w=b.name.replace(/\.module$/,""),S={moduleName:w,fieldsJson:ae(D(x,"fields.json")),metaJson:ae(D(x,"meta.json")),moduleHtml:ae(D(x,"module.html")),moduleCss:ae(D(x,"module.css")),moduleJs:ae(D(x,"module.js"))||void 0};S.fieldsJson&&S.moduleHtml&&(t.modules.push(S),t.moduleOrder.push(w))}let i=D(e,"css"),a=D(e,"js"),r="",l="";if(me(i)){let b=yn(i).filter(x=>x.endsWith("-theme.css"));b.length>0&&(r=ae(D(i,b[0])),t.sharedCss=r)}if(me(a)){let b=yn(a).filter(x=>x.endsWith("-animations.js"));b.length>0&&(l=ae(D(a,b[0])),t.sharedJs=l)}let c=D(e,".vibespot","styleguide.md"),d=D(e,".vibespot","brandvoice.md"),u=D(e,".vibespot","theme-context.md"),m=D(e,".vibespot","plan.md");(me(c)||me(d)||me(u)||me(m))&&(t.brandAssets||(t.brandAssets={}),me(c)&&(t.brandAssets.styleguide=ae(c)),me(d)&&(t.brandAssets.brandvoice=ae(d)),me(u)&&(t.brandAssets.themeContext=ae(u)),me(m)&&(t.brandAssets.plan=ae(m)));let g=D(e,"templates"),y=new Map(t.modules.map(b=>[b.moduleName,b])),h=wu(g,y,r,l,t.messages);if(h.length>0){t.templates=h,t.activeTemplateId=h[0].id;let b=h[0].moduleOrder;if(b.length>0){let x=new Set(t.moduleOrder),w=b.filter(S=>x.has(S));for(let S of t.moduleOrder)w.includes(S)||w.push(S);t.moduleOrder=w}xt(h[0])}else t.templates||(t.templates=[]),t.activeTemplateId||(t.activeTemplateId=""),ys(t)}function _e(){let e=v();if(!e)return;let t=e.themePath,n=new Map;if(e.templates.length>0)for(let l of e.templates)for(let c of l.modules)n.set(c.moduleName,c);for(let l of e.modules)n.set(l.moduleName,l);let s=D(t,"modules");hn(s,{recursive:!0});for(let l of n.values())hn(D(s,`${l.moduleName}.module`),{recursive:!0});for(let l of n.values()){let c=D(s,`${l.moduleName}.module`);Ee(D(c,"fields.json"),l.fieldsJson,"utf-8"),Ee(D(c,"meta.json"),l.metaJson,"utf-8"),Ee(D(c,"module.html"),l.moduleHtml,"utf-8"),Ee(D(c,"module.css"),l.moduleCss,"utf-8"),l.moduleJs&&Ee(D(c,"module.js"),l.moduleJs,"utf-8")}if(e.sharedCss){let l=D(t,"css");hn(l,{recursive:!0}),Ee(D(l,`${e.themeName}-theme.css`),e.sharedCss,"utf-8")}if(e.sharedJs){let l=D(t,"js");hn(l,{recursive:!0}),Ee(D(l,`${e.themeName}-animations.js`),e.sharedJs,"utf-8")}let o=D(t,"templates");hn(o,{recursive:!0});let i=D(o,"home.html");(e.templates.length>0||e.modules.length>0)&&me(i)&&Xr(i,{force:!0});let r=new Set;if(e.templates.length>0)for(let l of e.templates){if(l.pageType==="module_only"||l.modules.length===0)continue;let c=l.template||Au(l),d=Zr(c,l.label,l.pageType),u=`${l.id}.html`;Ee(D(o,u),d,"utf-8"),r.add(u),l.pageType==="blog_post"&&($u(o,l),r.add(`${l.id}-listing.html`))}else if(e.modules.length>0){let l=e.template||Tu(),c=Zr(l,`${e.themeName} Landing Page`),d=`lp-${e.themeName}.html`;Ee(D(o,d),c,"utf-8"),r.add(d)}try{for(let l of yn(o))l.startsWith("lp-")&&l.endsWith(".html")&&!r.has(l)&&Xr(D(o,l),{force:!0})}catch{}Cu(),ku()}function Qr(){let e=v();e&&(e.modules=[],e.moduleOrder=[],e.sharedCss="",e.sharedJs="",e.template="",bn(e.themePath),e.updatedAt=Date.now(),pt())}function ea(){let e=v();if(!e)return;let t=xe();if(!t)return;let n=e.themePath,s=D(n,"modules");t.modules=[];for(let o of t.moduleOrder){let i=D(s,`${o}.module`);if(!me(i))continue;let a={moduleName:o,fieldsJson:ae(D(i,"fields.json")),metaJson:ae(D(i,"meta.json")),moduleHtml:ae(D(i,"module.html")),moduleCss:ae(D(i,"module.css")),moduleJs:ae(D(i,"module.js"))||void 0};a.fieldsJson&&a.moduleHtml&&t.modules.push(a)}if(t.templateFile){let o=D(n,t.templateFile);me(o)&&(t.template=ae(o))}xt(t),e.updatedAt=Date.now()}function Cu(){let e=v();if(!e)return;let t=D(e.themePath,"templates","layouts","base.html");if(me(t))try{let n=No(t,"utf-8");if(n.includes("template_js"))return;let s='{{ require_js(get_asset_url("../../js/main.js")) }}';n.includes(s)?n=n.replace(s,s+`
178
+ - dnd_area label: "${e} Landing Page"
179
+
180
+ Return ONLY the template HTML content, no markdown fences.`}var Ia,Ue=R(()=>{"use strict";y();ne();Ia=new Map});import{join as ce}from"path";import{readdirSync as Ze,rmSync as Vp}from"fs";function Xs(t){let e=[];for(let n of t){let s=`${n.message}${n.detail?` \u2014 ${n.detail}`:""}`,o=!1;/textarea|unknown.*field.*type/i.test(s)&&(o=!0),/reserved.*name|missing field name|field null/i.test(s)&&(o=!0),/could not resolve.*now/i.test(s)&&(o=!0),/hubdb|do not have access/i.test(s)&&(o=!0),/invalid default value|link.*invalid|deserializ/i.test(s)&&(o=!0),/color.*invalid/i.test(s)&&(o=!0),/dnd.area.*only.*have.*name.*main/i.test(s)&&(o=!0),e.push({file:n.file||"unknown",message:s,fixable:o})}return e}function Zs(t){let e=[];if(/textarea.*not.*valid|unknown.*field.*type/i.test(t)){let n=t.match(/(?:in|file:?)\s+(\S+fields\.json)/i);e.push({file:n?.[1]||"fields.json",message:'"textarea" is not a valid field type',fixable:!0})}if(/missing field name|field null/i.test(t)){let n=t.match(/(?:in|file:?)\s+(\S+fields\.json)/i);e.push({file:n?.[1]||"fields.json",message:'"name" is a reserved field name',fixable:!0})}if(/could not resolve.*now/i.test(t)&&e.push({file:"module.html",message:"now() is not a valid HubL function",fixable:!0}),/hubdb|do not have access to hubdb/i.test(t)&&e.push({file:"templates",message:"HubDB requires CMS Hub Pro/Enterprise",fixable:!0}),/invalid default value|link.*field.*invalid/i.test(t)){let n=t.match(/field.*?(\w+)\s+has an invalid/i);e.push({file:n?.[1]||"fields.json",message:"Link field has invalid default value",fixable:!0})}if(/failed to deserialize/i.test(t)){let n=t.match(/file '([^']+)'/i);e.push({file:n?.[1]||"fields.json",message:"fields.json deserialization error",fixable:!0})}return/format for the color value is invalid/i.test(t)&&e.push({file:"fields.json",message:"Color field has invalid format (rgba/rgb/named \u2014 must be hex)",fixable:!0}),/dnd.area.*only.*have.*name.*main/i.test(t)&&e.push({file:"templates/email.html",message:'Dnd area can only have name "main"',fixable:!0}),e}function Qs(t){let e=[];return Wa(t)&&e.push("textarea \u2192 text"),Ka(t)&&e.push("name \u2192 item_name"),Va(t)&&e.push("now() \u2192 local_dt"),za(t)&&e.push("Removed HubDB templates"),Ya(t)&&e.push("Fixed link field defaults"),qa(t)&&e.push("Fixed rgba/invalid color values \u2192 hex"),zp(t)&&e.push("Stripped CDN @import statements"),Za(t)&&e.push('dnd_area \u2192 "main" in email templates'),Qa(t)&&e.push("Added {{ dnd_area_stylesheet }} to email templates"),e}function Ga(t,e){return e.message.includes("textarea")?Wa(t):e.message.includes("reserved field name")?Ka(t):e.message.includes("now()")?Va(t):e.message.includes("HubDB")?za(t):e.message.includes("invalid default value")||e.message.includes("deserialization")?Ya(t):e.message.includes("invalid format")&&e.message.includes("color")?qa(t):e.message.includes("dnd")||e.message.includes("Dnd area")?Za(t):e.message.includes("dnd_area_stylesheet")?Qa(t):!1}function Wa(t){let e=!1,n=ce(t,"modules");if(!v(n))return!1;for(let s of Ze(n)){if(!s.endsWith(".module"))continue;let o=ce(n,s,"fields.json");if(!v(o))continue;let i=M(o);i.includes('"textarea"')&&(i=i.replace(/"textarea"/g,'"text"'),J(o,i),e=!0)}return e}function Ka(t){let e=!1,n=ce(t,"modules");if(!v(n))return!1;for(let s of Ze(n)){if(!s.endsWith(".module"))continue;let o=ce(n,s,"fields.json");if(!v(o))continue;let i=M(o);/"name":\s*"name"/g.test(i)&&(i=i.replace(/"name":\s*"name"/g,'"name": "item_name"'),J(o,i),e=!0)}return e}function Va(t){let e=!1,n=ce(t,"modules");if(!v(n))return!1;for(let s of Ze(n)){if(!s.endsWith(".module"))continue;let o=ce(n,s,"module.html");if(!v(o))continue;let i=M(o);i.includes("now()")&&(i=i.replace(/now\(\)/g,"local_dt"),J(o,i),e=!0)}return e}function za(t){let e=!1,n=ce(t,"templates");if(!v(n))return!1;for(let s of Ze(n)){if(!s.endsWith(".html"))continue;let o=ce(n,s),i=M(o);(i.includes("hubdb_table")||i.includes("hubdb_table_rows"))&&(Vp(o),e=!0)}return e}function Ya(t){let e=!1,n=ce(t,"modules");if(!v(n))return!1;for(let s of Ze(n)){if(!s.endsWith(".module"))continue;let o=ce(n,s,"fields.json");if(v(o))try{let i=JSON.parse(M(o));el(i)&&(J(o,JSON.stringify(i,null,2)+`
181
+ `),e=!0)}catch{}}return e}function zp(t){let e=!1,n=ce(t,"css");if(v(n))for(let o of Ze(n)){if(!o.endsWith(".css"))continue;let i=ce(n,o),r=M(i),a=r.replace(/@import\s+url\(['"]?https?:\/\/[^)]+['"]?\)\s*;?/gi,"");a!==r&&(J(i,a),e=!0)}let s=ce(t,"modules");if(v(s))for(let o of Ze(s)){if(!o.endsWith(".module"))continue;let i=ce(s,o,"module.css");if(!v(i))continue;let r=M(i),a=r.replace(/@import\s+url\(['"]?https?:\/\/[^)]+['"]?\)\s*;?/gi,"");a!==r&&(J(i,a),e=!0)}if(v(s))for(let o of Ze(s)){if(!o.endsWith(".module"))continue;let i=ce(s,o,"module.html");if(!v(i))continue;let r=M(i),a=r.replace(/<link[^>]+href=['"]https?:\/\/[^'"]+['"][^>]*>/gi,"");a!==r&&(J(i,a),e=!0)}return e}function qa(t){let e=!1,n=ce(t,"modules");if(!v(n))return!1;for(let s of Ze(n)){if(!s.endsWith(".module"))continue;let o=ce(n,s,"fields.json");if(v(o))try{let i=JSON.parse(M(o));Xa(i)&&(J(o,JSON.stringify(i,null,2)+`
182
+ `),e=!0)}catch{}}return e}function Xa(t){let e=!1;for(let n of t){if(typeof n!="object"||n===null)continue;let s=n;if(s.type==="color"&&s.default&&typeof s.default=="object"){let o=s.default,i=o.color;if(typeof i=="string"&&!Yp(i)){let r=qp(i);r&&(o.color=r.hex,r.opacity!==void 0&&(o.opacity=r.opacity),e=!0)}}Array.isArray(s.children)&&Xa(s.children)&&(e=!0)}return e}function Yp(t){return/^#[0-9a-fA-F]{6}$/.test(t)}function qp(t){let e=t.match(/^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/);if(e)return{hex:`#${e[1]}${e[1]}${e[2]}${e[2]}${e[3]}${e[3]}`};let n=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/i);if(n){let i=Math.min(255,parseInt(n[1])),r=Math.min(255,parseInt(n[2])),a=Math.min(255,parseInt(n[3])),l=`#${i.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}`,c=n[4]!==void 0?Math.round(parseFloat(n[4])*100):void 0;return{hex:l,opacity:c}}let s={white:"#ffffff",black:"#000000",red:"#ff0000",green:"#008000",blue:"#0000ff",yellow:"#ffff00",orange:"#ffa500",purple:"#800080",gray:"#808080",grey:"#808080",transparent:"#000000"},o=t.toLowerCase().trim();return s[o]?{hex:s[o],opacity:o==="transparent"?0:void 0}:null}function Za(t){let e=!1,n=ce(t,"templates");if(!v(n))return!1;for(let s of Ze(n)){if(!s.endsWith(".html"))continue;let o=ce(n,s),i=M(o);if(!/templateType:\s*email/i.test(i))continue;let r=i.replace(/\{%\s*dnd_area\s+"(?!main")([^"]+)"/g,'{% dnd_area "main"');r!==i&&(J(o,r),e=!0)}return e}function Qa(t){let e=!1,n=ce(t,"templates");if(!v(n))return!1;for(let s of Ze(n)){if(!s.endsWith(".html"))continue;let o=ce(n,s),i=M(o);if(!/templateType:\s*email/i.test(i)||i.includes("dnd_area_stylesheet"))continue;let r=i.replace(/(\{\{\s*standard_header_includes\s*\}\})/,`$1
183
+ {{ dnd_area_stylesheet }}`);r!==i&&(J(o,r),e=!0)}return e}function el(t){let e=!1;for(let n of t){if(typeof n!="object"||n===null)continue;let s=n;if(s.type==="link"){let o=s.default;if(typeof o=="string"||o===void 0||o===null||typeof o=="object"&&!o.url){let r=typeof o=="string"?o:"";s.default={url:{href:r,type:"EXTERNAL"},open_in_new_tab:!1,no_follow:!1},e=!0}}Array.isArray(s.children)&&el(s.children)&&(e=!0)}return e}var eo=R(()=>{"use strict";y();ne()});import{readdirSync as Xp}from"fs";import{join as Zp,relative as Qp}from"path";function tl(t){let e=[];for(let n of Xp(t,{withFileTypes:!0})){if(eg.has(n.name)||n.name.startsWith(".")&&n.name!==".gitkeep")continue;let s=Zp(t,n.name);n.isDirectory()?e.push(...tl(s)):n.isFile()&&e.push(s)}return e}async function tg(t,e,n){let s=0;async function o(){for(;s<t.length;){let r=s++;await n(t[r])}}let i=Array.from({length:Math.min(e,t.length)},()=>o());await Promise.all(i)}async function to(t,e,n,s={}){let o=s.concurrency??5,i=tl(e),r=i.length,a=0,l=0,c=[];return await tg(i,o,async d=>{let u=Qp(e,d).replace(/\\/g,"/"),m=`${n}/${u}`;s.onFileStart?.(u);let g=await xa(t,m,d);if(g.success)a++,s.onFileComplete?.(u);else{l++;let h={file:u,status:g.error?.status||0,message:g.error?.message||"Unknown error",category:g.error?.category,detail:g.error?.detail};c.push(h),s.onFileError?.(u,h)}s.onProgress?.(a+l,r)}),{success:l===0,uploaded:a,failed:l,total:r,errors:c}}var eg,Ai=R(()=>{"use strict";y();Ut();Ut();eg=new Set([".git","node_modules",".vibespot",".DS_Store"])});var dl=R(()=>{"use strict";y()});import{existsSync as kt,writeFileSync as ig,mkdirSync as rg}from"fs";import{join as pt}from"path";function ml(t){return/^[0-9a-f]{4,40}$/i.test(t)}function pl(t){return Number.isInteger(t)&&t>0&&t<1e3}function Qe(){return no!==null||(no=X(["--version"]).success),no}function so(t){if(!Qe())return!1;if(kt(pt(t,".git")))return ul(t),!0;let e=X(["init"],{cwd:t});return e.success?(ag(t),ul(t),X(["add","-A"],{cwd:t}),X(["commit","-m","Initial theme"],{cwd:t}),!0):(console.warn(`[project-git] git init failed in ${t}: ${e.stderr}`),!1)}function ul(t){let e=pt(t,".vibespot");kt(e)||rg(e,{recursive:!0})}function ag(t){let e=pt(t,".gitignore");ig(e,[".vibespot/","node_modules/",""].join(`
184
+ `),"utf-8")}function Gt(t,e){if(!Qe()||!kt(pt(t,".git"))||(X(["add","-A"],{cwd:t}),X(["diff","--cached","--quiet"],{cwd:t}).success))return null;let s=e.length>72?e.slice(0,69)+"...":e,o=X(["commit","-m",s],{cwd:t});if(!o.success)return console.warn(`[project-git] commit failed: ${o.stderr}`),null;let i=X(["rev-parse","--short","HEAD"],{cwd:t});return i.success?i.stdout:null}function _i(t,e,n,s){if(!Qe()||!kt(pt(t,".git")))return null;for(let u of s){let m=pt(t,u);kt(m)&&X(["add","--",u],{cwd:t})}if(X(["diff","--cached","--quiet"],{cwd:t}).success)return null;let i=`[${e}] `,r=72-i.length,a=n.length>r?n.slice(0,r-3)+"...":n,l=i+a,c=X(["commit","-m",l],{cwd:t});if(!c.success)return console.warn(`[project-git] template commit failed: ${c.stderr}`),null;let d=X(["rev-parse","--short","HEAD"],{cwd:t});return d.success?d.stdout:null}function gl(t){let e=[],n=null;for(let s of t.split(`
185
+ `)){let o=s.trimEnd();if(o.startsWith("COMMIT|")){n&&e.push(n);let i=o.slice(7).split("|");if(i.length<4){n=null;continue}let r=parseInt(i[3],10)*1e3;n={hash:i[0],fullHash:i[1],message:i[2],timestamp:r,date:new Date(r).toISOString(),changedFiles:[],changedModules:[]}}else o&&n&&n.changedFiles.push(o)}n&&e.push(n);for(let s of e){if(!s.changedFiles)continue;let o=new Set;for(let i of s.changedFiles){let r=i.match(/^modules\/([^/]+)\.module(?:\/|$)/);r&&o.add(r[1])}s.changedModules=[...o]}return e}function fl(t,e=50){if(!Qe())return[];if(!kt(pt(t,".git")))return[];if(!pl(e))return[];let n=X(["log","--name-only","--pretty=format:COMMIT|%h|%H|%s|%at","-n",String(e)],{cwd:t});return!n.success||!n.stdout.trim()?[]:gl(n.stdout)}function hl(t,e,n=50){if(!Qe())return[];if(!kt(pt(t,".git")))return[];if(!pl(n))return[];let s=e.replace(/[\\.*+?^${}()|[\]/]/g,"\\$&"),o=X(["log",`--grep=\\[${s}\\]`,"--name-only","--pretty=format:COMMIT|%h|%H|%s|%at","-n",String(n)],{cwd:t});return!o.success||!o.stdout.trim()?[]:gl(o.stdout)}function yl(t,e){if(!Qe())return{success:!1,error:"Git not available"};if(!kt(pt(t,".git")))return{success:!1,error:"Not a git repo"};if(!ml(e))return{success:!1,error:"Invalid commit hash"};let n=X(["cat-file","-t",e],{cwd:t});if(!n.success||n.stdout.trim()!=="commit")return{success:!1,error:`Commit ${e} not found`};let s=X(["log","--format=%s","-1",e],{cwd:t}),o=s.success?s.stdout:e,i=X(["checkout",e,"--","."],{cwd:t});if(!i.success)return{success:!1,error:`Checkout failed: ${i.stderr}`};let r=`Rollback to: ${o}`.slice(0,72);return X(["commit","-m",r],{cwd:t}),{success:!0}}function bl(t,e,n,s){if(!Qe())return{success:!1,error:"Git not available"};if(!kt(pt(t,".git")))return{success:!1,error:"Not a git repo"};if(!ml(n))return{success:!1,error:"Invalid commit hash"};let o=X(["cat-file","-t",n],{cwd:t});if(!o.success||o.stdout.trim()!=="commit")return{success:!1,error:`Commit ${n} not found`};let i=X(["log","--format=%s","-1",n],{cwd:t}),r=i.success?i.stdout:n,a=0;for(let d of s)X(["checkout",n,"--",d],{cwd:t}).success&&a++;if(a===0)return{success:!1,error:"No files could be restored from that commit"};X(["add","-A"],{cwd:t});let c=`${`[${e}] `}Rollback to: ${r}`.slice(0,72);return X(["commit","-m",c],{cwd:t}),{success:!0}}var no,dn=R(()=>{"use strict";y();Jt();no=null});import{appendFileSync as lg,mkdirSync as cg,readdirSync as dg,unlinkSync as ug}from"fs";import{join as Pi}from"path";import{homedir as mg}from"os";function gg(){if(!Ei)try{cg(oo,{recursive:!0}),Ei=!0}catch{}}function fg(){if(!Ii){Ii=!0;try{let t=Date.now()-pg*864e5;for(let e of dg(oo)){if(!e.startsWith("vibespot-")||!e.endsWith(".log"))continue;let n=e.slice(9,19),s=new Date(n).getTime();if(s&&s<t)try{ug(Pi(oo,e))}catch{}}}catch{}}}function hg(){let e=new Date().toISOString().slice(0,10);return Pi(oo,`vibespot-${e}.log`)}function yg(){return new Date().toISOString().slice(11,23)}function Mi(t,e){if(gg(),!!Ei){Ii||fg();try{lg(hg(),`${yg()} ${t} ${e}
186
+ `)}catch{}}}var oo,pg,Ei,Ii,E,de=R(()=>{"use strict";y();oo=Pi(mg(),".vibespot","logs"),pg=7,Ei=!1,Ii=!1;E={info(t,e,n){let s=n?`[${t}] ${e} ${JSON.stringify(n)}`:`[${t}] ${e}`;console.log(s),Mi("INFO",s)},warn(t,e,n){let s=n?`[${t}] ${e} ${JSON.stringify(n)}`:`[${t}] ${e}`;console.warn(s),Mi("WARN",s)},error(t,e,n){let s=n instanceof Error?n.message:n?String(n):"",o=s?`[${t}] ${e}: ${s}`:`[${t}] ${e}`;console.error(o),Mi("ERROR",o)}}});import{readFileSync as bg,existsSync as xl,writeFileSync as Sg,mkdirSync as xg,rmSync as vg}from"fs";import{join as io}from"path";function Wt(t){let e=C();e&&(e.modules=t.modules,e.moduleOrder=t.moduleOrder,e.sharedCss=t.sharedCss,e.sharedJs=t.sharedJs,e.template=t.template,e.messages=t.messages,e.brandAssets||(e.brandAssets={}),e.brandAssets.plan=t.plan)}function et(){let t=C();if(!t)return;let e=Ce();if(!e){if(t.modules.length===0)return;let n={modules:t.modules,moduleOrder:t.moduleOrder,sharedCss:t.sharedCss,sharedJs:t.sharedJs,template:t.template,messages:t.messages,plan:t.brandAssets?.plan};e=Tt("landing_page",`${t.themeName} Landing Page`),t.activeTemplateId=e.id,t.modules=n.modules,t.moduleOrder=n.moduleOrder,t.sharedCss=n.sharedCss,t.sharedJs=n.sharedJs,t.template=n.template,t.messages=n.messages,t.brandAssets&&(t.brandAssets.plan=n.plan)}e.modules=t.modules,e.moduleOrder=t.moduleOrder,e.sharedCss=t.sharedCss,e.sharedJs=t.sharedJs,e.template=t.template,e.messages=t.messages,e.plan=t.brandAssets?.plan}function tt(t,e,n){let s=C();if(!s)return;let o={role:t,content:e,timestamp:Date.now()};n&&(o.pipeline=n),s.messages.push(o),s.updatedAt=Date.now(),et(),Cg()}function vl(t){let e=C();e&&(e.assets||(e.assets=[]),e.assets.push(t),e.updatedAt=Date.now(),D())}function Sl(t){return t.toLowerCase().replace(/[\s\-_]+/g,"")}function wg(t,e){let n=Sl(t),s=Sl(e);if(n===s)return!0;if(n.length<4||s.length<4)return!1;let o=n.length<=s.length?n:s,i=n.length<=s.length?s:n;return i.includes(o)?o.length/i.length>=.8:!1}function De(t){let e=C();if(e){if(t.sharedCss!==void 0&&(e.sharedCss=t.sharedCss),t.sharedJs!==void 0&&(e.sharedJs=t.sharedJs),t.template!==void 0&&(e.template=t.template),t.modules)for(let n of t.modules){let s=n.moduleName.toLowerCase(),o=e.modules.findIndex(i=>i.moduleName.toLowerCase()===s);if(o>=0)e.modules[o]=n;else{let i=e.modules.find(r=>wg(r.moduleName,n.moduleName));i&&E.warn("session-state",`Module "${n.moduleName}" looks like a renamed variant of existing "${i.moduleName}" \u2014 adding as a new module. This usually indicates the Module Planner re-named an existing module. Check the prompt's "preserve existing names" rule.`),e.modules.push(n),e.moduleOrder.some(r=>r.toLowerCase()===s)||e.moduleOrder.push(n.moduleName)}}e.updatedAt=Date.now(),et()}}function Rt(t){let e=C();e&&(e.moduleOrder=t,e.updatedAt=Date.now(),et())}function wl(t){let e=C();if(e){e.modules=e.modules.filter(n=>n.moduleName!==t),e.moduleOrder=e.moduleOrder.filter(n=>n!==t);for(let n of e.templates)n.modules=n.modules.filter(s=>s.moduleName!==t),n.moduleOrder=n.moduleOrder.filter(s=>s!==t);if(e.themePath){let n=io(e.themePath,"modules",`${t}.module`);xl(n)&&vg(n,{recursive:!0,force:!0})}e.updatedAt=Date.now(),et()}}function Cl(t){let e=C();e&&(e.moduleOrder=e.moduleOrder.filter(n=>n!==t),e.updatedAt=Date.now(),et())}function kl(t,e,n){let s=C();if(!s)return;let o=s.modules.find(i=>i.moduleName===t);if(o)try{let i=JSON.parse(o.fieldsJson);$l(i,e,n),o.fieldsJson=JSON.stringify(i,null,2),s.updatedAt=Date.now(),et()}catch{}}function Se(){let t=C();if(!t)return[];let e=[];for(let n of t.moduleOrder){let s=t.modules.find(o=>o.moduleName===n);s&&e.push(s)}for(let n of t.modules)t.moduleOrder.includes(n.moduleName)||e.push(n);return e}function Cg(){let t=C();if(t)try{let e=io(t.themePath,".vibespot");xg(e,{recursive:!0});let n={sessionId:t.id,themeName:t.themeName,messages:t.messages,updatedAt:Date.now()};Sg(io(e,"chat.json"),JSON.stringify(n,null,2),"utf-8")}catch{}}function Tl(t){let e=io(t,".vibespot","chat.json");if(!xl(e))return[];try{let n=JSON.parse(bg(e,"utf-8"));return Array.isArray(n.messages)?n.messages:[]}catch{return[]}}function Al(t){let e=C();if(e){for(let n of e.templates)n.sharedCss=t.sharedCss,n.sharedJs=t.sharedJs;e.sharedCss=t.sharedCss,e.sharedJs=t.sharedJs;for(let n of t.pages){let s=t.pageLabels.get(n.pageId),o=s?.label||n.pageId,i=s?.pageType||"website_page",r=e.templates.find(a=>a.id===n.templateId);r||(r=Tt(i,o),r.id=n.templateId,r.templateFile=`templates/${n.templateId}.html`),r.modules=n.modules,r.moduleOrder=n.moduleOrder,r.sharedCss=t.sharedCss,r.sharedJs=t.sharedJs}t.pages.length>0&&Kn(t.pages[0].templateId),e.updatedAt=Date.now()}}function $l(t,e,n){let s=e.split("."),o=s[0],i=t.find(r=>r.name===o);i&&(s.length===1?i.default=n:i.children&&$l(i.children,s.slice(1).join("."),n))}var Wn=R(()=>{"use strict";y();Vn();Nt();de()});import{existsSync as ro,rmSync as ao}from"fs";import{join as un}from"path";function lo(t){if(t.templates&&t.templates.length>0)return;if(!t.modules||t.modules.length===0){t.templates=[],t.activeTemplateId="";return}let e=`lp-${t.themeName}`,n={id:e,label:`${t.themeName} Landing Page`,pageType:"landing_page",templateFile:`templates/lp-${t.themeName}.html`,modules:[...t.modules],moduleOrder:[...t.moduleOrder],sharedCss:t.sharedCss||"",sharedJs:t.sharedJs||"",template:t.template||"",messages:[...t.messages]};t.templates=[n],t.activeTemplateId=e}function Ce(){let t=C();return!t||!t.activeTemplateId||!t.templates?.length?null:t.templates.find(e=>e.id===t.activeTemplateId)||null}function Kn(t){let e=C();if(!e)return!1;let n=e.templates.find(s=>s.id===t);return n?(e.activeTemplateId=t,Wt(n),e.updatedAt=Date.now(),!0):!1}function Tt(t,e,n){let s=C();if(!s)throw new Error("No active session");let o=e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),i=n==="email",a=`${i?"email":t==="blog_post"?"bp":t==="website_page"?"wp":t==="module_only"?"mo":"lp"}-${o}`,l={id:a,label:e,pageType:t,contentMode:n,templateFile:i?"templates/email.html":t==="module_only"?"":`templates/${a}.html`,modules:[],moduleOrder:[],sharedCss:"",sharedJs:"",template:"",messages:[]};return s.templates.push(l),s.activeTemplateId=a,Wt(l),s.updatedAt=Date.now(),l}function _l(t,e){let n=C();if(!n)return null;let s=n.templates.find(c=>c.id===t);if(!s)return null;let o=e||`${s.label} (Copy)`,i=o.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),a=`${s.pageType==="blog_post"?"bp":s.pageType==="website_page"?"wp":s.pageType==="module_only"?"mo":"lp"}-${i}`,l={id:a,label:o,pageType:s.pageType,templateFile:s.pageType==="module_only"?"":`templates/${a}.html`,modules:s.modules.map(c=>({...c})),moduleOrder:[...s.moduleOrder],sharedCss:s.sharedCss,sharedJs:s.sharedJs,template:s.template,messages:[],plan:s.plan};return n.templates.push(l),n.activeTemplateId=a,Wt(l),n.updatedAt=Date.now(),l}function Ml(t){let e=C();if(!e||!Array.isArray(t)||t.length===0)return!1;let n=new Map(e.templates.map(i=>[i.id,i])),s=new Set,o=[];for(let i of t){let r=n.get(i);!r||s.has(i)||(o.push(r),s.add(i))}for(let i of e.templates)s.has(i.id)||o.push(i);return o.length!==e.templates.length?!1:(e.templates=o,e.updatedAt=Date.now(),!0)}function El(t,e){let n=C();if(!n)return!1;let s=n.templates.find(o=>o.id===t);return s?(s.label=e,n.updatedAt=Date.now(),!0):!1}function Il(t,e=!1){let n=C();if(!n)return!1;let s=n.templates.findIndex(i=>i.id===t);if(s<0)return!1;let o=n.templates.splice(s,1)[0];if(n.themePath){let i=un(n.themePath,"templates"),r=`${o.id}.html`,a=un(i,r);if(ro(a)&&ao(a,{force:!0}),o.pageType==="blog_post"){let l=un(i,`${o.id}-listing.html`);ro(l)&&ao(l,{force:!0})}}if(e&&o.modules.length>0){let i=new Set;for(let a of n.templates)for(let l of a.modules)i.add(l.moduleName);for(let a of n.modules)i.add(a.moduleName);let r=o.modules.map(a=>a.moduleName).filter(a=>!i.has(a));if(n.themePath&&r.length>0){let a=un(n.themePath,"modules");for(let l of r){let c=un(a,`${l}.module`);ro(c)&&ao(c,{recursive:!0,force:!0})}}}if(n.activeTemplateId===t&&(n.templates.length>0?Kn(n.templates[0].id):(n.activeTemplateId="",n.modules=[],n.moduleOrder=[],n.sharedCss="",n.sharedJs="",n.template="",n.messages=[],n.brandAssets&&delete n.brandAssets.plan)),o.plan&&n.themePath&&!n.templates.some(r=>!!r.plan)){let r=un(n.themePath,".vibespot","plan.md");ro(r)&&ao(r,{force:!0})}return n.updatedAt=Date.now(),!0}function At(){let t=C();if(!t)return[];let e=new Map;for(let n of t.templates)for(let s of n.modules){let o=e.get(s.moduleName);o?o.usedIn.push(n.label):e.set(s.moduleName,{module:s,usedIn:[n.label]})}for(let n of t.modules)e.has(n.moduleName)||e.set(n.moduleName,{module:n,usedIn:[]});return Array.from(e.values())}var Nt=R(()=>{"use strict";y();Vn();Wn()});import{readFileSync as gt,readdirSync as ji,existsSync as $e,writeFileSync as zn,mkdirSync as co,rmSync as Ri,renameSync as Ni,cpSync as kg}from"fs";import{join as ue,dirname as Pl}from"path";import{homedir as Tg}from"os";function uo(){if(mn)return mn;try{return $e(Oi)?(mn=JSON.parse(gt(Oi,"utf-8")),mn):Fi()}catch{return Fi()}}function mo(t){mn=t;try{co(ae,{recursive:!0}),zn(Oi,JSON.stringify(t),"utf-8")}catch{}}function Fi(){if(!$e(ae))return[];let t=[];for(let e of ji(ae).filter(n=>n.endsWith(".json")&&n!=="_index.json"))try{let n=JSON.parse(gt(ue(ae,e),"utf-8")),s=n.templates||[];t.push({id:n.id,themeName:n.themeName,updatedAt:n.updatedAt,moduleCount:s.reduce((o,i)=>o+(i.modules?.length||0),0),templateCount:s.length,pageCount:s.filter(o=>o.contentMode!=="email").length,emailCount:s.filter(o=>o.contentMode==="email").length,hasBrandAssets:!!(n.brandAssets&&(n.brandAssets.styleguide||n.brandAssets.brandvoice||n.brandAssets.brandKit)),isImported:!!n.isImported})}catch{}return mn=t,mo(t),t}function Rl(t){let e=uo(),n=t.templates||[],s={id:t.id,themeName:t.themeName,updatedAt:t.updatedAt,moduleCount:n.reduce((i,r)=>i+(r.modules?.length||0),0),templateCount:n.length,pageCount:n.filter(i=>i.contentMode!=="email").length,emailCount:n.filter(i=>i.contentMode==="email").length,hasBrandAssets:!!(t.brandAssets&&(t.brandAssets.styleguide||t.brandAssets.brandvoice||t.brandAssets.brandKit)),isImported:!!t.isImported},o=e.findIndex(i=>i.id===t.id);o>=0?e[o]=s:e.push(s),mo(e)}function Ag(t){let e=uo().filter(n=>n.id!==t);mo(e)}function $g(t){let e=uo().filter(n=>n.themeName!==t);mo(e)}function C(){return Le}function Nl(){return`vibe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function pn(t,e,n={}){let s={id:Nl(),themePath:t,themeName:e,isImported:!!n.isImported,templates:[],activeTemplateId:"",messages:[],modules:[],sharedCss:"",sharedJs:"",template:"",moduleOrder:[],createdAt:Date.now(),updatedAt:Date.now()};return Le=s,so(t),s}function D(){if(!Le)return;co(ae,{recursive:!0});let t=ue(ae,`${Le.id}.json`);zn(t,JSON.stringify(Le,null,2),"utf-8"),Rl(Le)}function po(t){let e=ue(ae,t+".json");if(!$e(e))return null;try{let n=JSON.parse(gt(e,"utf-8"));if(n.templates||(n.templates=[]),n.activeTemplateId||(n.activeTemplateId=""),lo(n),n.brandAssets?.plan&&n.templates?.length>0){let s=n.templates.find(o=>o.id===n.activeTemplateId)||n.templates[0];s.plan||(s.plan=n.brandAssets.plan)}return Le=n,n}catch{return null}}function gn(){return $e(ae)?uo():[]}function Ol(t,e=!1){let n=ue(ae,t+".json"),s="";if(e)try{let o=JSON.parse(gt(n,"utf-8"));s=o.themeName||"",o.themePath&&$e(o.themePath)&&Ri(o.themePath,{recursive:!0,force:!0})}catch{}else try{s=JSON.parse(gt(n,"utf-8")).themeName||""}catch{}try{$e(n)&&Ri(n)}catch{}if(s&&$e(ae)){for(let o of ji(ae).filter(i=>i.endsWith(".json")&&i!=="_index.json"))try{JSON.parse(gt(ue(ae,o),"utf-8")).themeName===s&&Ri(ue(ae,o))}catch{}$g(s)}else Ag(t);Le?.id===t&&(Le=null)}function Fl(t,e){let n=ue(ae,t+".json");if(!$e(n))return{ok:!1,error:"Session not found"};let s;try{s=JSON.parse(gt(n,"utf-8"))}catch{return{ok:!1,error:"Failed to read session"}}let o=s.themeName;if(o===e)return{ok:!0};let i=s.themePath,r=ue(Pl(i),e);if($e(i)){if($e(r))return{ok:!1,error:"A project with that name already exists"};try{Ni(i,r)}catch(m){return{ok:!1,error:`Failed to rename folder: ${m instanceof Error?m.message:String(m)}`}}let a=ue(r,"css",`${o}-theme.css`),l=ue(r,"css",`${e}-theme.css`);if($e(a))try{Ni(a,l)}catch{}let c=ue(r,"js",`${o}-animations.js`),d=ue(r,"js",`${e}-animations.js`);if($e(c))try{Ni(c,d)}catch{}let u=ue(r,"theme.json");if($e(u))try{let m=JSON.parse(gt(u,"utf-8"));m.label=e,m.name=e,zn(u,JSON.stringify(m,null,2),"utf-8")}catch{}}if($e(ae))for(let a of ji(ae).filter(l=>l.endsWith(".json")&&l!=="_index.json"))try{let l=JSON.parse(gt(ue(ae,a),"utf-8"));l.themeName===o&&(l.themeName=e,l.themePath=r,l.updatedAt=Date.now(),zn(ue(ae,a),JSON.stringify(l,null,2),"utf-8"))}catch{}return Le&&Le.themeName===o&&(Le.themeName=e,Le.themePath=r,Le.updatedAt=Date.now()),Fi(),{ok:!0}}function jl(t){let e=ue(ae,t+".json");if(!$e(e))return{ok:!1,error:"Session not found"};let n;try{n=JSON.parse(gt(e,"utf-8"))}catch{return{ok:!1,error:"Failed to read session"}}let s=n.themeName.replace(/-copy(-\d+)?$/,""),o=Pl(n.themePath),i=`${s}-copy`,r=1;for(;$e(ue(o,i));)r++,i=`${s}-copy-${r}`;let a=ue(o,i);if($e(n.themePath))try{kg(n.themePath,a,{recursive:!0})}catch(d){return{ok:!1,error:`Failed to copy files: ${d instanceof Error?d.message:String(d)}`}}else co(a,{recursive:!0});let l=Nl(),c={...JSON.parse(JSON.stringify(n)),id:l,themeName:i,themePath:a,createdAt:Date.now(),updatedAt:Date.now(),messages:[]};return co(ae,{recursive:!0}),zn(ue(ae,`${l}.json`),JSON.stringify(c,null,2),"utf-8"),Rl(c),{ok:!0,newName:i,newSessionId:l}}var ae,Oi,mn,Le,Vn=R(()=>{"use strict";y();dn();Nt();ae=ue(Tg(),".vibespot","sessions"),Oi=ue(ae,"_index.json"),mn=null;Le=null});import{readFileSync as _g,readdirSync as Jl,statSync as Di}from"fs";import{createHash as Mg}from"crypto";import{join as he,relative as Eg}from"path";function ho(t){let e=[];if(!v(t))return tf(t,[{severity:"error",rule:"theme.path.missing",message:`Theme directory not found: ${t}`}]);let n=fn(t),s=Xg(t),o=Qg(t),i=ef(t),r=Og(t);Object.keys(n.cssVariables).length===0&&e.push({severity:"info",rule:"design.cssVariables.empty",message:"No :root CSS custom properties found in theme CSS.",fix:"Run with --apply-tokens to seed a :root block from inferred palette/typography."}),n.palette.length===0&&e.push({severity:"info",rule:"design.palette.empty",message:"Could not infer a colour palette from the theme CSS."}),s.orphanModules.length>0&&e.push({severity:"warning",rule:"modules.orphan",message:`${s.orphanModules.length} module(s) are not referenced by any template: ${s.orphanModules.join(", ")}`,fix:"Either reference these modules from a template or remove them."}),s.templates.length===0&&s.modules.length>0&&e.push({severity:"warning",rule:"templates.missing",message:"Theme has modules but no page templates wiring them together.",fix:"Add a templates/<name>.html that includes the modules via dnd_module."});for(let l of o)e.push({severity:"info",rule:"field.unsupported-pattern",file:`modules/${l.module}.module/fields.json`,message:`${l.module}.${l.field}: ${l.reason}`,fix:"vibeSpot will preserve this field as-is. Edit it in HubSpot if changes are needed."});for(let l of i)e.push({severity:"warning",rule:"roundtrip.preserve-pattern",file:l.file,message:`${l.pattern}: ${l.detail}`,fix:"vibeSpot avoids modifying this. Don't ask the AI to refactor it."});r.hasSnapshot&&r.filesChanged>0&&e.push({severity:"info",rule:"roundtrip.snapshot.diff",message:`${r.filesChanged} file(s) differ from the imported theme snapshot.`,fix:"Review report.roundTripDiff before re-uploading if you need to preserve imported files exactly."});let a=i.filter(l=>l.pattern==="hubl.macro").length;return{themePath:t,designTokens:n,graph:s,fieldFlags:o,roundTripRisks:i,roundTripDiff:r,findings:e,summary:{moduleCount:s.modules.length,templateCount:s.templates.length,orphanCount:s.orphanModules.length,paletteSize:n.palette.length,cssVarCount:Object.keys(n.cssVariables).length,customMacroCount:a,roundTripChangedCount:r.filesChanged}}}function Yn(t){let e=[];for(let[n,s]of Object.entries(t.cssVariables))e.push(` ${n}: ${s};`);return Object.keys(t.cssVariables).length===0&&(t.palette.slice(0,8).forEach((n,s)=>{let o=s===0?"primary":s===1?"secondary":`accent-${s-1}`;e.push(` --color-${o}: ${n.value};`)}),t.fontFamilies[0]&&e.push(` --font-family-base: ${t.fontFamilies[0]};`),t.fontFamilies[1]&&e.push(` --font-family-heading: ${t.fontFamilies[1]};`)),e.length===0?"":`:root {
187
+ ${e.join(`
188
+ `)}
189
+ }
190
+ `}function yo(t,e){let n=he(t,"css");if(v(n))try{for(let r of Jl(n))if(r.endsWith("-theme.css"))return null}catch{}let s=fn(t),o=Yn(s);if(!o)return null;let i=he(n,`${e}-theme.css`);return J(i,o),i}function qn(t){return he(t,Ig)}function Rg(t,e=new Date().toISOString()){return{version:1,createdAt:e,files:Ul(t)}}function Li(t,e){let n=Rg(t,e),s=qn(t);return J(s,JSON.stringify(n,null,2)+`
191
+ `),s}function Bl(t){let e=qn(t);return v(e)?null:Li(t)}function Ng(t){let e=qn(t);if(!v(e))return null;try{let n=JSON.parse(M(e));return sf(n)?n:null}catch{return null}}function Og(t){let e=qn(t),n=Ng(t);if(!n)return{hasSnapshot:!1,snapshotPath:e,filesChanged:0,added:0,modified:0,deleted:0,files:[]};let s=new Map(n.files.map(d=>[d.path,d])),o=Ul(t),i=new Map(o.map(d=>[d.path,d])),r=[];for(let d of n.files){let u=i.get(d.path);u?u.sha256!==d.sha256&&r.push({file:d.path,status:"modified",beforeSha256:d.sha256,afterSha256:u.sha256,beforeSize:d.size,afterSize:u.size,beforeLines:fo(d.text),afterLines:fo(u.text)}):r.push({file:d.path,status:"deleted",beforeSha256:d.sha256,beforeSize:d.size,beforeLines:fo(d.text)})}for(let d of o)s.has(d.path)||r.push({file:d.path,status:"added",afterSha256:d.sha256,afterSize:d.size,afterLines:fo(d.text)});r.sort((d,u)=>d.file.localeCompare(u.file));let a=r.filter(d=>d.status==="added").length,l=r.filter(d=>d.status==="modified").length,c=r.filter(d=>d.status==="deleted").length;return{hasSnapshot:!0,snapshotPath:e,filesChanged:r.length,added:a,modified:l,deleted:c,files:r}}function fn(t){let e=qg(t),n={},s=new Map,o=new Map,i=new Set,r=new Set,a=new Set,l=new Set,c=new Set;for(let u of e){let m;try{m=M(u)}catch{continue}let g,h=new RegExp(Gg.source,"g");for(;(g=h.exec(m))!==null;){let f=g[1],b=new RegExp(Wg.source,"g"),S;for(;(S=b.exec(f))!==null;){let x=S[1].trim(),w=S[2].trim();n[x]||(n[x]=w);let P=w.match(/#[0-9a-fA-F]{3,8}\b|rgba?\([^)]+\)|hsla?\([^)]+\)/);if(P){let F=Dl(P[0]);o.set(F,x)}}}for(let f of[Fg,jg,Dg]){let b=new RegExp(f.source,"g"),S;for(;(S=b.exec(m))!==null;){let x=Dl(S[0]);x&&s.set(x,(s.get(x)??0)+1)}}go(m,Lg,i,Vg),go(m,Jg,r,f=>f.trim()),Kg(m,a),go(m,Hg,l,f=>f.trim()),go(m,Ug,c,f=>f.trim())}let d=[...s.entries()].filter(([u])=>!Yg(u)).sort((u,m)=>m[1]-u[1]).slice(0,12).map(([u,m])=>({value:u,count:m,varName:o.get(u)}));return{cssVariables:n,palette:d,fontFamilies:[...i].slice(0,8),fontSizes:[...r].slice(0,16),spacing:[...a].slice(0,16),radii:[...l].slice(0,8),shadows:[...c].slice(0,8)}}function go(t,e,n,s){let o=new RegExp(e.source,"g"),i;for(;(i=o.exec(t))!==null;){let r=s(i[1]);r&&!r.startsWith("var(")&&n.add(r)}}function Kg(t,e){let n=new RegExp(Bg.source,"g"),s;for(;(s=n.exec(t))!==null;){let o=s[1].trim();if(!o.startsWith("var("))for(let i of o.split(/\s+/))/^-?\d+(\.\d+)?(rem|em|px|%)$/.test(i)&&e.add(i)}}function Vg(t){return t.split(",")[0].trim().replace(/^["']|["']$/g,"")}function Dl(t){let e=t.trim().toLowerCase();if(e.startsWith("#")){if(/^#[0-9a-f]{3}$/.test(e)){let[,n,s,o]=e.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/);return`#${n}${n}${s}${s}${o}${o}`}return e}return e.replace(/\s+/g,"")}function Yg(t){return zg.has(t)}function qg(t){let e=[],n=he(t,"css");if(v(n))for(let o of Ot(n))o.endsWith(".css")&&e.push(he(n,o));let s=he(t,"modules");if(v(s))for(let o of Ot(s)){if(!o.endsWith(".module"))continue;let i=he(s,o,"module.css");v(i)&&e.push(i)}return e}function Xg(t){let e=he(t,"modules"),n=he(t,"templates"),s=new Set,o=new Map;if(v(e))for(let c of Ot(e)){if(!c.endsWith(".module"))continue;let d=c.replace(/\.module$/,"");s.add(d),o.set(d,v(he(e,c,"module.js")))}let i=[],r=new Map;if(v(n))for(let c of Ot(n)){if(!c.endsWith(".html")||c==="home.html")continue;let d=he(n,c),u;try{u=Di(d)}catch{continue}if(!u.isFile())continue;let m;try{m=M(d)}catch{continue}let g=Ji(m);for(let f of g){let b=r.get(f)??new Set;b.add(c),r.set(f,b)}let h=c.replace(/\.html$/,"");i.push({id:h,file:`templates/${c}`,modules:of(g)})}let a=[...s].sort().map(c=>({name:c,templates:[...r.get(c)??[]].sort(),hasJs:o.get(c)??!1})),l=a.filter(c=>c.templates.length===0).map(c=>c.name);return{templates:i,modules:a,orphanModules:l}}function Ji(t){let e=[],n=/{%\s*dnd_module\b[\s\S]*?%}/g,s;for(;(s=n.exec(t))!==null;){let o=s[0].match(/\bpath\s*=\s*["']([^"']+)["']/);if(!o)continue;let i=o[1].match(/(?:^|\/)modules\/(.+)$/);if(!i)continue;let r=i[1].replace(/\.module$/,"");r&&e.push(r)}return e}function Qg(t){let e=[],n=he(t,"modules");if(!v(n))return e;for(let s of Ot(n)){if(!s.endsWith(".module"))continue;let o=s.replace(/\.module$/,""),i=he(n,s,"fields.json");if(!v(i))continue;let r;try{r=JSON.parse(M(i))}catch{continue}Array.isArray(r)&&Hl(r,o,e,0)}return e}function Hl(t,e,n,s){for(let o of t){if(typeof o!="object"||o===null)continue;let i=o,r=typeof i.name=="string"?i.name:"(unnamed)",a=typeof i.type=="string"?i.type:"";if(a==="group"&&s>=1&&n.push({module:e,field:r,reason:"deeply nested group (>1 level)"}),(a==="group"||a==="module")&&i.occurrence){let l=i.occurrence;l.max!==void 0&&l.max!==1&&n.push({module:e,field:r,reason:"repeater (occurrence) field"})}(a==="hubdb_table"||a==="hubdbtable")&&n.push({module:e,field:r,reason:"HubDB-backed field"}),(a==="crm_object"||a==="crm_object_property")&&n.push({module:e,field:r,reason:"CRM object field"}),a==="embed"&&typeof i.embed=="object"&&n.push({module:e,field:r,reason:"rich embed field"}),a&&!Zg.has(a)&&a!=="module"&&n.push({module:e,field:r,reason:`field type "${a}" not in vibeSpot's generation set`}),i.visibility&&typeof i.visibility=="object"&&n.push({module:e,field:r,reason:"conditional visibility rule"}),Array.isArray(i.children)&&Hl(i.children,e,n,s+1)}}function ef(t){let e=[],n=he(t,"modules");if(v(n))for(let i of Ot(n)){if(!i.endsWith(".module"))continue;let r=i.replace(/\.module$/,""),a=he(n,i,"module.html");v(a)&&Ll(a,t,r,e);let l=he(n,i,"module.js");if(v(l))try{M(l).trim().length>0&&e.push({file:Bi(t,l),pattern:"module.js.custom",detail:`${r}: module ships custom JS \u2014 preserve verbatim`})}catch{}}let s=he(t,"templates");if(v(s))for(let i of Ot(s)){if(!i.endsWith(".html"))continue;let r=he(s,i);if(!v(r))continue;let a;try{a=Di(r)}catch{continue}a.isFile()&&Ll(r,t,i,e)}let o=he(t,"import_modules.json");return v(o)&&e.push({file:"import_modules.json",pattern:"theme.import_modules",detail:"Theme declares import_modules.json \u2014 preserve to avoid breaking HubSpot pre-install"}),e}function Ll(t,e,n,s){let o;try{o=M(t)}catch{return}let i=Bi(e,t);/{%\s*macro\s+\w+/.test(o)&&s.push({file:i,pattern:"hubl.macro",detail:`${n}: contains custom HubL {% macro %}`}),/{%\s*raw\s*%}/.test(o)&&s.push({file:i,pattern:"hubl.raw",detail:`${n}: contains {% raw %} block`});let r=/{%\s*include\s+["']([^"']+)["']/g,a;for(;(a=r.exec(o))!==null;){let l=a[1];!l.startsWith("../modules/")&&!l.startsWith("./modules/")&&!l.includes("/layouts/")&&s.push({file:i,pattern:"hubl.include",detail:`${n}: includes partial "${l}" outside modules/`})}}function tf(t,e){let n={hasSnapshot:!1,snapshotPath:qn(t),filesChanged:0,added:0,modified:0,deleted:0,files:[]};return{themePath:t,designTokens:{cssVariables:{},palette:[],fontFamilies:[],fontSizes:[],spacing:[],radii:[],shadows:[]},graph:{templates:[],modules:[],orphanModules:[]},fieldFlags:[],roundTripRisks:[],roundTripDiff:n,findings:e,summary:{moduleCount:0,templateCount:0,orphanCount:0,paletteSize:0,cssVarCount:0,customMacroCount:0,roundTripChangedCount:0}}}function Ul(t){let e=[];function n(s){for(let o of Ot(s)){if(o===".git"||o===".vibespot"||o==="node_modules")continue;let i=he(s,o),r;try{r=Di(i)}catch{continue}if(r.isDirectory()){n(i);continue}if(!r.isFile())continue;let a=Bi(t,i),l=_g(i),c={path:a,sha256:Mg("sha256").update(l).digest("hex"),size:l.length};nf(a)&&(c.text=l.toString("utf8")),e.push(c)}}return n(t),e.sort((s,o)=>s.path.localeCompare(o.path))}function nf(t){let e=t.lastIndexOf(".");return e<0?!1:Pg.has(t.slice(e).toLowerCase())}function sf(t){if(typeof t!="object"||t===null)return!1;let e=t;return e.version!==1||typeof e.createdAt!="string"||!Array.isArray(e.files)?!1:e.files.every(n=>{if(typeof n!="object"||n===null)return!1;let s=n;return typeof s.path=="string"&&typeof s.sha256=="string"&&typeof s.size=="number"&&(s.text===void 0||typeof s.text=="string")})}function fo(t){if(t!==void 0)return t.length===0?0:t.split(/\r\n|\r|\n/).length}function Ot(t){try{return Jl(t)}catch{return[]}}function Bi(t,e){return Eg(t,e).split("\\").join("/")}function of(t){return[...new Set(t)]}var Ig,Pg,Fg,jg,Dg,Lg,Jg,Bg,Hg,Ug,Gg,Wg,zg,Zg,bo=R(()=>{"use strict";y();ne();Ig=".vibespot/import-snapshot.json",Pg=new Set([".css",".html",".htm",".js",".json",".md",".txt",".svg",".yml",".yaml"]);Fg=/#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\b/g,jg=/\brgba?\([^)]+\)/g,Dg=/\bhsla?\([^)]+\)/g,Lg=/font-family\s*:\s*([^;}\n]+)/g,Jg=/font-size\s*:\s*([^;}\n]+)/g,Bg=/(?:padding|margin|gap)(?:-(?:top|right|bottom|left))?\s*:\s*([^;}\n]+)/g,Hg=/border-radius\s*:\s*([^;}\n]+)/g,Ug=/box-shadow\s*:\s*([^;}\n]+)/g,Gg=/:root\s*\{([\s\S]*?)\}/g,Wg=/(--[\w-]+)\s*:\s*([^;}\n]+)/g;zg=new Set(["#000000","#ffffff","transparent","currentcolor","inherit","initial"]);Zg=new Set(["text","richtext","image","url","boolean","choice","number","color","icon","link","menu","video","form","cta","blog","tag","page","email","logo","embed","alignment","border","spacing","font","background","gradient","textalignment","group"])});import{readFileSync as Hi,readdirSync as Zn,existsSync as xe,writeFileSync as Ke,mkdirSync as Xn,rmSync as Gl}from"fs";import{join as U}from"path";function ve(t){try{return Hi(t,"utf-8")}catch{return""}}function Kl(t){let e=[];for(let n of t.moduleOrder){let s=t.modules.find(o=>o.moduleName===n);s&&e.push(s)}for(let n of t.modules)t.moduleOrder.includes(n.moduleName)||e.push(n);return e}function rf(t,e){let n=ve(t);if(!n||e==="home.html"||e.endsWith("-listing.html"))return null;let s=e.replace(/\.html$/,""),o=/templateType:\s*email\b/i.test(n),i="landing_page",r;o?(i="module_only",r="email"):s.startsWith("bp-")?i="blog_post":s.startsWith("wp-")?i="website_page":s.startsWith("mo-")&&(i="module_only");let a=s,l=n.match(/<!--[\s\S]*?label:\s*"?([^"\n]+)"?\s*[\s\S]*?-->/);l&&(a=l[1].trim());let c=Ji(n);return{id:s,label:a,pageType:i,contentMode:r,moduleNames:c,templateContent:n,filename:e}}function af(t,e,n,s,o){if(!xe(t))return[];let i=[],r=Zn(t).filter(a=>a.endsWith(".html")&&a!=="home.html");for(let a of r){let l=U(t,a),c=rf(l,a);if(!c||c.moduleNames.length===0&&i.length>0)continue;let d=[],u=[];for(let m of c.moduleNames){let g=e.get(m);g&&(d.push(g),u.push(m))}i.push({id:c.id,label:c.label,pageType:c.pageType,contentMode:c.contentMode,templateFile:`templates/${c.filename}`,modules:d,moduleOrder:u,sharedCss:c.contentMode==="email"?"":n,sharedJs:c.contentMode==="email"?"":s,template:c.templateContent,messages:i.length===0?[...o]:[]})}return i}function So(t){let e=C();if(!e)return;let n=Tl(t);n.length>0&&e.messages.length===0&&(e.messages=n),so(t),Bl(t);let s=U(t,"modules");if(!xe(s))return;let o=Zn(s,{withFileTypes:!0});for(let S of o){if(!S.isDirectory()||!S.name.endsWith(".module"))continue;let x=U(s,S.name),w=S.name.replace(/\.module$/,""),P={moduleName:w,fieldsJson:ve(U(x,"fields.json")),metaJson:ve(U(x,"meta.json")),moduleHtml:ve(U(x,"module.html")),moduleCss:ve(U(x,"module.css")),moduleJs:ve(U(x,"module.js"))||void 0};P.fieldsJson&&P.moduleHtml&&(e.modules.push(P),e.moduleOrder.push(w))}let i=U(t,"css"),r=U(t,"js"),a="",l="";if(xe(i)){let S=Zn(i).filter(x=>x.endsWith("-theme.css"));S.length>0&&(a=ve(U(i,S[0])),e.sharedCss=a)}if(xe(r)){let S=Zn(r).filter(x=>x.endsWith("-animations.js"));S.length>0&&(l=ve(U(r,S[0])),e.sharedJs=l)}if(!a&&e.modules.length>0){let S=fn(t),x=Yn(S);x&&(e.sharedCss=x,a=x)}let c=U(t,".vibespot","styleguide.md"),d=U(t,".vibespot","brandvoice.md"),u=U(t,".vibespot","theme-context.md"),m=U(t,".vibespot","plan.md"),g=U(t,".vibespot","brand-kit.json");if((xe(c)||xe(d)||xe(u)||xe(m)||xe(g))&&(e.brandAssets||(e.brandAssets={}),xe(c)&&(e.brandAssets.styleguide=ve(c)),xe(d)&&(e.brandAssets.brandvoice=ve(d)),xe(u)&&(e.brandAssets.themeContext=ve(u)),xe(m)&&(e.brandAssets.plan=ve(m)),xe(g)))try{e.brandAssets.brandKit=JSON.parse(ve(g))}catch{}let h=U(t,"templates"),f=new Map(e.modules.map(S=>[S.moduleName,S])),b=af(h,f,a,l,e.messages);if(b.length>0){e.templates=b,e.activeTemplateId=b[0].id,e.brandAssets?.plan&&!b[0].plan&&(b[0].plan=e.brandAssets.plan);let S=b[0].moduleOrder;if(S.length>0){let x=new Set(e.moduleOrder),w=S.filter(P=>x.has(P));for(let P of e.moduleOrder)w.includes(P)||w.push(P);e.moduleOrder=w}Wt(b[0])}else e.templates||(e.templates=[]),e.activeTemplateId||(e.activeTemplateId=""),lo(e)}function ke(){let t=C();if(!t)return;let e=t.themePath,n=new Map;if(t.templates.length>0)for(let l of t.templates)for(let c of l.modules)n.set(c.moduleName,c);for(let l of t.modules)n.set(l.moduleName,l);let s=U(e,"modules");Xn(s,{recursive:!0});for(let l of n.values())Xn(U(s,`${l.moduleName}.module`),{recursive:!0});for(let l of n.values()){let c=U(s,`${l.moduleName}.module`);Ke(U(c,"fields.json"),l.fieldsJson,"utf-8"),Ke(U(c,"meta.json"),l.metaJson,"utf-8"),Ke(U(c,"module.html"),l.moduleHtml,"utf-8"),Ke(U(c,"module.css"),l.moduleCss,"utf-8"),l.moduleJs&&Ke(U(c,"module.js"),l.moduleJs,"utf-8")}if(t.sharedCss){let l=U(e,"css");Xn(l,{recursive:!0}),Ke(U(l,`${t.themeName}-theme.css`),t.sharedCss,"utf-8")}if(t.sharedJs){let l=U(e,"js");Xn(l,{recursive:!0}),Ke(U(l,`${t.themeName}-animations.js`),t.sharedJs,"utf-8")}let o=U(e,"templates");Xn(o,{recursive:!0});let i=U(o,"home.html");(t.templates.length>0||t.modules.length>0)&&xe(i)&&Gl(i,{force:!0});let a=new Set;if(t.templates.length>0)for(let l of t.templates){if(l.contentMode==="email"){if(l.modules.length===0)continue;let m=uf(l),g=l.templateFile?l.templateFile.replace("templates/",""):"email.html";Ke(U(o,g),m,"utf-8"),a.add(g);continue}if(l.pageType==="module_only"||l.modules.length===0)continue;let c=l.template||df(l),d=Wl(c,l.label,l.pageType),u=`${l.id}.html`;Ke(U(o,u),d,"utf-8"),a.add(u),l.pageType==="blog_post"&&(mf(o,l),a.add(`${l.id}-listing.html`))}else if(t.modules.length>0){let l=t.template||pf(),c=Wl(l,`${t.themeName} Landing Page`),d=`lp-${t.themeName}.html`;Ke(U(o,d),c,"utf-8"),a.add(d)}try{for(let l of Zn(o))l.startsWith("lp-")&&l.endsWith(".html")&&!a.has(l)&&Gl(U(o,l),{force:!0})}catch{}lf(),cf()}function Vl(){let t=C();t&&(t.modules=[],t.moduleOrder=[],t.sharedCss="",t.sharedJs="",t.template="",So(t.themePath),t.updatedAt=Date.now(),et())}function zl(){let t=C();if(!t)return;let e=Ce();if(!e)return;let n=t.themePath,s=U(n,"modules");e.modules=[];for(let o of e.moduleOrder){let i=U(s,`${o}.module`);if(!xe(i))continue;let r={moduleName:o,fieldsJson:ve(U(i,"fields.json")),metaJson:ve(U(i,"meta.json")),moduleHtml:ve(U(i,"module.html")),moduleCss:ve(U(i,"module.css")),moduleJs:ve(U(i,"module.js"))||void 0};r.fieldsJson&&r.moduleHtml&&e.modules.push(r)}if(e.templateFile){let o=U(n,e.templateFile);xe(o)&&(e.template=ve(o))}Wt(e),t.updatedAt=Date.now()}function lf(){let t=C();if(!t)return;let e=U(t.themePath,"templates","layouts","base.html");if(xe(e))try{let n=Hi(e,"utf-8");if(n.includes("template_js"))return;let s='{{ require_js(get_asset_url("../../js/main.js")) }}';n.includes(s)?n=n.replace(s,s+`
139
192
  {% if template_js %}
140
193
  {{ require_js(get_asset_url(template_js)) }}
141
194
  {% endif %}`):n=n.replace("{{ standard_footer_includes }}",`{% if template_js %}
142
195
  {{ require_js(get_asset_url(template_js)) }}
143
196
  {% endif %}
144
- {{ standard_footer_includes }}`),Ee(t,n,"utf-8")}catch{}}function ku(){let e=v();if(!e)return;let t=D(e.themePath,"theme.json");if(me(t))try{let n=JSON.parse(No(t,"utf-8"));n.label=e.themeName,n.name=e.themeName,Ee(t,JSON.stringify(n,null,2),"utf-8")}catch{}}function Zr(e,t,n="landing_page"){return e.includes("templateType")?e:`<!--
197
+ {{ standard_footer_includes }}`),Ke(e,n,"utf-8")}catch{}}function cf(){let t=C();if(!t)return;let e=U(t.themePath,"theme.json");if(xe(e))try{let n=JSON.parse(Hi(e,"utf-8"));n.label=t.themeName,n.name=t.themeName,Ke(e,JSON.stringify(n,null,2),"utf-8")}catch{}}function Wl(t,e,n="landing_page"){return t.includes("templateType")?t:`<!--
145
198
  templateType: ${n==="blog_post"?"blog_post":"page"}
146
199
  isAvailableForNewContent: true
147
- label: "${t}"
200
+ label: "${e}"
148
201
  -->
149
- `+e}function Au(e){if(e.modules.length===0)return"";let n=v().themeName,o=xu(e).map(a=>` {% dnd_section padding={"top":"0","bottom":"0","left":"0","right":"0"}, full_width=true %}
150
- {% dnd_module path="../modules/${a.moduleName}.module" %}
202
+ `+t}function df(t){if(t.modules.length===0)return"";let n=C().themeName,o=Kl(t).map(r=>` {% dnd_section padding={"top":"0","bottom":"0","left":"0","right":"0"}, full_width=true %}
203
+ {% dnd_module path="../modules/${r.moduleName}.module" %}
151
204
  {% end_dnd_module %}
152
205
  {% end_dnd_section %}`).join(`
153
206
 
154
207
  `);return`<!--
155
- templateType: ${e.pageType==="blog_post"?"blog_post":"page"}
208
+ templateType: ${t.pageType==="blog_post"?"blog_post":"page"}
156
209
  isAvailableForNewContent: true
157
- label: "${e.label}"
210
+ label: "${t.label}"
158
211
  -->
159
212
  {% extends "./layouts/base.html" %}
160
213
 
@@ -166,7 +219,7 @@ Return ONLY the template HTML content, no markdown fences.`}var tr,ot=L(()=>{"us
166
219
 
167
220
  {% block body %}
168
221
  <div class="${n}-page">
169
- {% dnd_area "main_content" label="${e.label}" %}
222
+ {% dnd_area "main_content" label="${t.label}" %}
170
223
 
171
224
  ${o}
172
225
 
@@ -177,10 +230,57 @@ ${o}
177
230
 
178
231
  {% block footer %}
179
232
  {% endblock footer %}
180
- `}function $u(e,t){let n=`<!--
233
+ `}function uf(t){let n=Kl(t).map(s=>` {% dnd_section %}
234
+ {% dnd_module path="../modules/${s.moduleName}.module" %}
235
+ {% end_dnd_module %}
236
+ {% end_dnd_section %}`).join(`
237
+
238
+ `);return`<!--
239
+ templateType: email
240
+ isAvailableForNewContent: true
241
+ label: "${t.label}"
242
+ screenshotPath: ../images/template-previews/email.png
243
+ -->
244
+ <!DOCTYPE html>
245
+ <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
246
+ <head>
247
+ <meta charset="utf-8">
248
+ <meta name="viewport" content="width=device-width, initial-scale=1">
249
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
250
+ <!--[if mso]>
251
+ <noscript>
252
+ <xml>
253
+ <o:OfficeDocumentSettings>
254
+ <o:AllowPNG/>
255
+ <o:PixelsPerInch>96</o:PixelsPerInch>
256
+ </o:OfficeDocumentSettings>
257
+ </xml>
258
+ </noscript>
259
+ <![endif]-->
260
+ {{ standard_header_includes }}
261
+ {{ dnd_area_stylesheet }}
262
+ </head>
263
+ <body style="margin:0;padding:0;background-color:#f4f4f4;font-family:Arial,Helvetica,sans-serif;-webkit-font-smoothing:antialiased;">
264
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color:#f4f4f4;">
265
+ <tr>
266
+ <td align="center" style="padding:20px 0;">
267
+ {% dnd_area "main"
268
+ label="Email Content"
269
+ %}
270
+
271
+ ${n}
272
+
273
+ {% end_dnd_area %}
274
+ </td>
275
+ </tr>
276
+ </table>
277
+ {{ standard_footer_includes }}
278
+ </body>
279
+ </html>
280
+ `}function mf(t,e){let n=`<!--
181
281
  templateType: blog_listing
182
282
  isAvailableForNewContent: true
183
- label: "${t.label} - Listing"
283
+ label: "${e.label} - Listing"
184
284
  -->
185
285
  {% extends "./layouts/base.html" %}
186
286
 
@@ -202,7 +302,7 @@ ${o}
202
302
  {% endif %}
203
303
  </div>
204
304
  {% endblock body %}
205
- `;Ee(D(e,`${t.id}-listing.html`),n,"utf-8")}function Tu(){let e=v();if(!e||e.modules.length===0)return"";let t=e.themeName,s=X().map(o=>` {% dnd_section padding={"top":"0","bottom":"0","left":"0","right":"0"}, full_width=true %}
305
+ `;Ke(U(t,`${e.id}-listing.html`),n,"utf-8")}function pf(){let t=C();if(!t||t.modules.length===0)return"";let e=t.themeName,s=Se().map(o=>` {% dnd_section padding={"top":"0","bottom":"0","left":"0","right":"0"}, full_width=true %}
206
306
  {% dnd_module path="../modules/${o.moduleName}.module" %}
207
307
  {% end_dnd_module %}
208
308
  {% end_dnd_section %}`).join(`
@@ -210,38 +310,38 @@ ${o}
210
310
  `);return`<!--
211
311
  templateType: page
212
312
  isAvailableForNewContent: true
213
- label: "${t} Landing Page"
313
+ label: "${e} Landing Page"
214
314
  -->
215
315
  {% extends "./layouts/base.html" %}
216
316
 
217
- {% set template_css = "../../css/${t}-theme.css" %}
218
- {% set template_js = "../../js/${t}-animations.js" %}
317
+ {% set template_css = "../../css/${e}-theme.css" %}
318
+ {% set template_js = "../../js/${e}-animations.js" %}
219
319
 
220
320
  {% block header %}
221
321
  {% endblock header %}
222
322
 
223
323
  {% block body %}
224
- <div class="${t}-page">
225
- {% dnd_area "main_content" label="${t} Landing Page" %}
324
+ <div class="${e}-page">
325
+ {% dnd_area "main_content" label="${e} Landing Page" %}
226
326
 
227
327
  ${s}
228
328
 
229
329
  {% end_dnd_area %}
230
330
  </div>
231
- {{ require_js(get_asset_url("../../js/${t}-animations.js")) }}
331
+ {{ require_js(get_asset_url("../../js/${e}-animations.js")) }}
232
332
  {% endblock body %}
233
333
 
234
334
  {% block footer %}
235
335
  {% endblock footer %}
236
- `}var Po=L(()=>{"use strict";f();gn();pn();Dt();jt()});var ta=L(()=>{"use strict";f();_r();gn();pn();Po();Dt()});var pe=L(()=>{"use strict";f();ta()});function Cs(e){let t={};for(let n of e)n.type==="group"&&n.occurrence&&Array.isArray(n.default)?t[n.name]=n.default:n.type==="group"&&n.children?t[n.name]=Cs(n.children):t[n.name]=n.default??"";return t}function Oo(e,t){let n=e;return n=Fu(n),n=ia(n,t),n=ra(n,t),n=aa(n,t),n=ju(n),n}function Ro(e){let t=[e.sharedCss||"",...e.moduleCssArray].filter(Boolean).map(o=>`<style>${o}</style>`).join(`
237
- `),n=[e.sharedJs||"",...e.moduleJsArray].filter(Boolean).map(o=>`<script>${o}</script>`).join(`
238
- `),s=e.renderedModules.join(`
336
+ `}var Ui=R(()=>{"use strict";y();Vn();Wn();Nt();dn();bo()});var Yl=R(()=>{"use strict";y();dl();Vn();Wn();Ui();Nt()});var we=R(()=>{"use strict";y();Yl()});function Qn(t){let e={};for(let n of t)n.type==="group"&&n.occurrence&&Array.isArray(n.default)?e[n.name]=n.default:n.type==="group"&&n.children?e[n.name]=Qn(n.children):e[n.name]=n.default??"";return e}function xo(t,e){let n=t;return n=wf(n),n=Ql(n,e),n=ec(n,e),n=tc(n,e),n=kf(n),n}function Wi(t){let e=[t.sharedCss||"",...t.moduleCssArray].filter(Boolean).map(o=>`<style>${o}</style>`).join(`
337
+ `),n=[t.sharedJs||"",...t.moduleJsArray].filter(Boolean).map(o=>`<script>${o}</script>`).join(`
338
+ `),s=t.renderedModules.join(`
239
339
  `);return`<!DOCTYPE html>
240
340
  <html lang="en">
241
341
  <head>
242
342
  <meta charset="utf-8">
243
343
  <meta name="viewport" content="width=device-width, initial-scale=1">
244
- ${t}
344
+ ${e}
245
345
  <style>
246
346
  html{scroll-behavior:smooth}
247
347
  .vsp-img-wrap{position:relative;display:inline-block}
@@ -280,11 +380,11 @@ document.querySelectorAll('img').forEach(function(img){
280
380
  });
281
381
  </script>
282
382
  </body>
283
- </html>`}function Fu(e){return e=e.replace(Iu,""),e=e.replace(Eu,""),e=e.replace(_u,""),na.lastIndex=0,e=e.replace(na,(t,n)=>`/theme-assets/${n}`),sa.lastIndex=0,e=e.replace(sa,""),e=e.replace(Nu,""),e=e.replace(Pu,""),e=e.replace(Mu,""),e=e.replace(Ou,""),e=e.replace(Ru,""),e}function ia(e,t){let n=e,s=0;for(;s<30;){s++;let o=Ju(n);if(!o)break;let{varName:i,iterExpr:a,body:r,start:l,end:c}=o,d=Du(a,t),u="";Array.isArray(d)&&(u=d.map((m,g)=>{let y={...t,[i]:m,loop:{index:g+1,index0:g,first:g===0,last:g===d.length-1,length:d.length}},h=ia(r,y);return h=ra(h,y),h=aa(h,y),h}).join("")),n=n.slice(0,l)+u+n.slice(c)}return n}function Ju(e){let t=/\{%[-\s]*for\s+(\w+)\s+in\s+([\w.]+(?:\([^)]*\))?(?:\|[\w(),"' ]+)*)\s*-?%\}/g,n=/\{%[-\s]*(for\s|endfor)\s*.*?-?%\}/g,s=t.exec(e);if(!s)return null;let o=s[1],i=s[2],a=s.index+s[0].length;n.lastIndex=a;let r=1,l;for(;(l=n.exec(e))!==null;)if(l[1].startsWith("for"))r++;else if(r--,r===0){let c=e.slice(a,l.index);return{varName:o,iterExpr:i,body:c,start:s.index,end:l.index+l[0].length}}return null}function ra(e,t){let n=e,s=0;for(;Mo.test(n)&&s<50;)s++,n=n.replace(Mo,(o,i,a)=>{let r=a.split(/\{%[-\s]*else\s*-?%\}/),l=r[0],c=r[1]||"",d=l.split(/\{%[-\s]*elif\s+(.*?)\s*-?%\}/);if(d.length>1){if(Bt(i,t))return d[0];for(let u=1;u<d.length;u+=2){let m=d[u],g=d[u+1]||"";if(Bt(m,t))return g}return c}return Bt(i,t)?l:c}),Mo.lastIndex=0;return n}function aa(e,t){return e.replace(/\{\{[-\s]*(.*?)[-\s]*\}\}/g,(n,s)=>{let i=s.trim().split("|"),a=i[0].trim(),r=wt(t,a);for(let c=1;c<i.length;c++)r=ca(r,i[c].trim());if(r==null)return"";if(typeof r=="object")return JSON.stringify(r);let l=String(r);return l=l.replace(/\\n/g," ").replace(/\n/g," "),l})}function ju(e){return e=e.replace(/\{%.*?%\}/gs,""),e=e.replace(/\{\{.*?\}\}/gs,""),e}function Du(e,t){let n=e.match(/^range\(\s*(.+?)\s*,\s*(.+?)\s*\)$/);if(n){let o=oa(n[1],t),i=oa(n[2],t),a=[];for(let r=o;r<i;r++)a.push(r);return a}let s=e.match(/^(.+?)\|split\(['"](.+?)['"]\)$/);if(s){let o=wt(t,s[1].trim());return typeof o=="string"?o.split(s[2]):[]}return wt(t,e)}function oa(e,t){let s=e.trim().split("|"),o=s[0].trim();if(!isNaN(Number(o)))return Number(o);let i=wt(t,o);for(let a=1;a<s.length;a++)i=ca(i,s[a].trim());return Number(i)||0}function wt(e,t){let n=t.split("."),s=e;for(let o of n){if(s==null||typeof s!="object")return;s=s[o]}return s}function Bt(e,t){let n=e.trim();if(n.startsWith("not "))return!Bt(n.slice(4),t);if(n.includes(" and "))return n.split(" and ").every(i=>Bt(i,t));if(n.includes(" or "))return n.split(" or ").some(i=>Bt(i,t));let s=n.match(/^(.+?)\s*(==|!=|>=|<=|>|<)\s*(.+)$/);if(s){let i=wt(t,s[1].trim()),a=s[2],r=s[3].trim();switch(typeof r=="string"&&r.startsWith('"')&&r.endsWith('"')||typeof r=="string"&&r.startsWith("'")&&r.endsWith("'")?r=r.slice(1,-1):isNaN(Number(r))?r=wt(t,r):r=Number(r),a){case"==":return i==r;case"!=":return i!=r;case">":return Number(i)>Number(r);case"<":return Number(i)<Number(r);case">=":return Number(i)>=Number(r);case"<=":return Number(i)<=Number(r)}}let o=wt(t,n);return la(o)}function la(e){return!(e==null||e===""||e===0||e===!1||Array.isArray(e)&&e.length===0)}function ca(e,t){let n=e==null?"":String(e),s=t.match(/^(\w+)\((.*)\)$/),o=s?s[1]:t,i=s?s[2].replace(/^["']|["']$/g,""):void 0;switch(o){case"escape":case"e":return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");case"lower":return n.toLowerCase();case"upper":return n.toUpperCase();case"capitalize":return n.charAt(0).toUpperCase()+n.slice(1);case"trim":return n.trim();case"truncate":if(i){let a=parseInt(i,10);return n.length>a?n.slice(0,a)+"...":n}return n;case"default":return la(e)?e:i??"";case"length":return Array.isArray(e)?e.length:n.length;case"join":return Array.isArray(e)?e.join(i??", "):n;case"int":case"float":return Number(n)||0;case"abs":return Math.abs(Number(n));case"round":return Math.round(Number(n));default:return e}}var Iu,Eu,_u,na,sa,Nu,Pu,Mu,Ou,Ru,Mo,da=L(()=>{"use strict";f();Iu=/\{%[-\s]*require_(css|js)\b.*?%\}/gs,Eu=/\{%[-\s]*end_require_(css|js)\s*%\}/gs,_u=/\{\{[-\s]*require_(css|js)\(.*?\)\s*\}\}/gs,na=/\{\{[-\s]*get_asset_url\(["'](?:[^"'\/]+\/)?assets\/(.*?)["']\)\s*\}\}/gs,sa=/\{\{[-\s]*get_asset_url\(.*?\)\s*\}\}/gs,Nu=/\{%[-\s]*(end_)?(dnd_area|dnd_section|dnd_column|dnd_row|dnd_module)\b.*?%\}/gs,Pu=/\{%[-\s]*module\b.*?%\}/gs,Mu=/\{%[-\s]*(extends|block|endblock|set)\b.*?%\}/gs,Ou=/\{#.*?#\}/gs,Ru=/\{\{[-\s]*content\.\w+.*?\}\}/gs,Mo=/\{%[-\s]*if\s+(.*?)\s*-?%\}((?:(?!\{%[-\s]*if\s)[\s\S])*?)\{%[-\s]*endif\s*-?%\}/g});var jo={};ke(jo,{buildModulePreviewHtml:()=>Jo,buildPreviewHtml:()=>Fo});function Hu(e){if(!e)return{bg:"#0f0f14",surface:"#1a1a20",text:"#ffffff",textMuted:"#666",border:"#333"};let t=(r,l)=>{for(let c of r){let d=new RegExp(`${c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*:\\s*([^;})]+)`,"i"),u=e.match(d);if(u)return u[1].trim()}return l},n=t(["--bg","--background","--color-bg","--bg-primary","--body-bg"],"#0f0f14"),s=t(["--surface","--bg-secondary","--card-bg","--color-surface"],n),o=t(["--text","--color-text","--text-primary","--fg","--foreground"],"#ffffff"),i=t(["--text-muted","--text-secondary","--muted","--color-text-muted"],"#666"),a=t(["--border","--border-color","--color-border"],"#333");return{bg:n,surface:s,text:o,textMuted:i,border:a}}function Fo(){let e=v();if(!e)return ua();let t=X(),n=e.moduleOrder||[];if(t.length===0&&n.length===0)return ua();let s=[],o=[],i=[],a=new Set;for(let c of t){if(c.moduleHtml.includes("dnd_area")||c.moduleHtml.includes("extends "))continue;let d;try{let g=JSON.parse(c.fieldsJson);d={module:Cs(g)}}catch{d={module:{}}}let u=Oo(c.moduleHtml,d),m=c.moduleName.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");s.push(`<div class="vibespot-module" id="${m}" data-module="${c.moduleName}">${u}</div>`),a.add(c.moduleName),c.moduleCss&&o.push(c.moduleCss),c.moduleJs&&i.push(c.moduleJs)}let r=Hu(e.sharedCss);for(let c of n)if(!a.has(c)){let d=c.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");s.push(`<div class="vibespot-module vibespot-module--pending" id="${d}" data-module="${c}">
383
+ </html>`}function wf(t){return t=t.replace(gf,""),t=t.replace(ff,""),t=t.replace(hf,""),ql.lastIndex=0,t=t.replace(ql,(e,n)=>`/theme-assets/${n}`),Xl.lastIndex=0,t=t.replace(Xl,""),t=t.replace(yf,""),t=t.replace(bf,""),t=t.replace(Sf,""),t=t.replace(xf,""),t=t.replace(vf,""),t}function Ql(t,e){let n=t,s=0;for(;s<30;){s++;let o=Cf(n);if(!o)break;let{varName:i,iterExpr:r,body:a,start:l,end:c}=o,d=Tf(r,e),u="";Array.isArray(d)&&(u=d.map((m,g)=>{let h={...e,[i]:m,loop:{index:g+1,index0:g,first:g===0,last:g===d.length-1,length:d.length}},f=Ql(a,h);return f=ec(f,h),f=tc(f,h),f}).join("")),n=n.slice(0,l)+u+n.slice(c)}return n}function Cf(t){let e=/\{%[-\s]*for\s+(\w+)\s+in\s+([\w.]+(?:\([^)]*\))?(?:\|[\w(),"' ]+)*)\s*-?%\}/g,n=/\{%[-\s]*(for\s|endfor)\s*.*?-?%\}/g,s=e.exec(t);if(!s)return null;let o=s[1],i=s[2],r=s.index+s[0].length;n.lastIndex=r;let a=1,l;for(;(l=n.exec(t))!==null;)if(l[1].startsWith("for"))a++;else if(a--,a===0){let c=t.slice(r,l.index);return{varName:o,iterExpr:i,body:c,start:s.index,end:l.index+l[0].length}}return null}function ec(t,e){let n=t,s=0;for(;Gi.test(n)&&s<50;)s++,n=n.replace(Gi,(o,i,r)=>{let a=r.split(/\{%[-\s]*else\s*-?%\}/),l=a[0],c=a[1]||"",d=l.split(/\{%[-\s]*elif\s+(.*?)\s*-?%\}/);if(d.length>1){if(hn(i,e))return d[0];for(let u=1;u<d.length;u+=2){let m=d[u],g=d[u+1]||"";if(hn(m,e))return g}return c}return hn(i,e)?l:c}),Gi.lastIndex=0;return n}function tc(t,e){return t.replace(/\{\{[-\s]*(.*?)[-\s]*\}\}/g,(n,s)=>{let i=s.trim().split("|"),r=i[0].trim(),a=Kt(e,r);for(let c=1;c<i.length;c++)a=sc(a,i[c].trim());if(a==null)return"";if(typeof a=="object")return JSON.stringify(a);let l=String(a);return l=l.replace(/\\n/g," ").replace(/\n/g," "),l})}function kf(t){return t=t.replace(/\{%.*?%\}/gs,""),t=t.replace(/\{\{.*?\}\}/gs,""),t}function Tf(t,e){let n=t.match(/^range\(\s*(.+?)\s*,\s*(.+?)\s*\)$/);if(n){let o=Zl(n[1],e),i=Zl(n[2],e),r=[];for(let a=o;a<i;a++)r.push(a);return r}let s=t.match(/^(.+?)\|split\(['"](.+?)['"]\)$/);if(s){let o=Kt(e,s[1].trim());return typeof o=="string"?o.split(s[2]):[]}return Kt(e,t)}function Zl(t,e){let s=t.trim().split("|"),o=s[0].trim();if(!isNaN(Number(o)))return Number(o);let i=Kt(e,o);for(let r=1;r<s.length;r++)i=sc(i,s[r].trim());return Number(i)||0}function Kt(t,e){let n=e.split("."),s=t;for(let o of n){if(s==null||typeof s!="object")return;s=s[o]}return s}function hn(t,e){let n=t.trim();if(n.startsWith("not "))return!hn(n.slice(4),e);if(n.includes(" and "))return n.split(" and ").every(i=>hn(i,e));if(n.includes(" or "))return n.split(" or ").some(i=>hn(i,e));let s=n.match(/^(.+?)\s*(==|!=|>=|<=|>|<)\s*(.+)$/);if(s){let i=Kt(e,s[1].trim()),r=s[2],a=s[3].trim();switch(typeof a=="string"&&a.startsWith('"')&&a.endsWith('"')||typeof a=="string"&&a.startsWith("'")&&a.endsWith("'")?a=a.slice(1,-1):isNaN(Number(a))?a=Kt(e,a):a=Number(a),r){case"==":return i==a;case"!=":return i!=a;case">":return Number(i)>Number(a);case"<":return Number(i)<Number(a);case">=":return Number(i)>=Number(a);case"<=":return Number(i)<=Number(a)}}let o=Kt(e,n);return nc(o)}function nc(t){return!(t==null||t===""||t===0||t===!1||Array.isArray(t)&&t.length===0)}function sc(t,e){let n=t==null?"":String(t),s=e.match(/^(\w+)\((.*)\)$/),o=s?s[1]:e,i=s?s[2].replace(/^["']|["']$/g,""):void 0;switch(o){case"escape":case"e":return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");case"lower":return n.toLowerCase();case"upper":return n.toUpperCase();case"capitalize":return n.charAt(0).toUpperCase()+n.slice(1);case"trim":return n.trim();case"truncate":if(i){let r=parseInt(i,10);return n.length>r?n.slice(0,r)+"...":n}return n;case"default":return nc(t)?t:i??"";case"length":return Array.isArray(t)?t.length:n.length;case"join":return Array.isArray(t)?t.join(i??", "):n;case"int":case"float":return Number(n)||0;case"abs":return Math.abs(Number(n));case"round":return Math.round(Number(n));default:return t}}var gf,ff,hf,ql,Xl,yf,bf,Sf,xf,vf,Gi,oc=R(()=>{"use strict";y();gf=/\{%[-\s]*require_(css|js)\b.*?%\}/gs,ff=/\{%[-\s]*end_require_(css|js)\s*%\}/gs,hf=/\{\{[-\s]*require_(css|js)\(.*?\)\s*\}\}/gs,ql=/\{\{[-\s]*get_asset_url\(["'](?:[^"'\/]+\/)?assets\/(.*?)["']\)\s*\}\}/gs,Xl=/\{\{[-\s]*get_asset_url\(.*?\)\s*\}\}/gs,yf=/\{%[-\s]*(end_)?(dnd_area|dnd_section|dnd_column|dnd_row|dnd_module)\b.*?%\}/gs,bf=/\{%[-\s]*module\b.*?%\}/gs,Sf=/\{%[-\s]*(extends|block|endblock|set)\b.*?%\}/gs,xf=/\{#.*?#\}/gs,vf=/\{\{[-\s]*content\.\w+.*?\}\}/gs,Gi=/\{%[-\s]*if\s+(.*?)\s*-?%\}((?:(?!\{%[-\s]*if\s)[\s\S])*?)\{%[-\s]*endif\s*-?%\}/g});var vo={};Be(vo,{buildModulePreviewHtml:()=>zi,buildPreviewHtml:()=>Vi});function Af(t){if(yn()==="email")return!0;for(let e of t)try{let n=JSON.parse(e.metaJson);if(Array.isArray(n.host_template_types)&&n.host_template_types.includes("EMAIL"))return!0}catch{}return!1}function $f(t){if(!t)return{bg:"#0f0f14",surface:"#1a1a20",text:"#ffffff",textMuted:"#666",border:"#333"};let e=(a,l)=>{for(let c of a){let d=new RegExp(`${c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*:\\s*([^;})]+)`,"i"),u=t.match(d);if(u)return u[1].trim()}return l},n=e(["--bg","--background","--color-bg","--bg-primary","--body-bg"],"#0f0f14"),s=e(["--surface","--bg-secondary","--card-bg","--color-surface"],n),o=e(["--text","--color-text","--text-primary","--fg","--foreground"],"#ffffff"),i=e(["--text-muted","--text-secondary","--muted","--color-text-muted"],"#666"),r=e(["--border","--border-color","--color-border"],"#333");return{bg:n,surface:s,text:o,textMuted:i,border:r}}function Ki(t,e){if(!Array.isArray(e))return t;let n=new Map;for(let o of e)n.set(o.name,o.type);let s=t;return s=s.replace(/(<([a-zA-Z]\w*)(\s[^>]*)?>)\s*(\{\{\s*module\.(\w+)(?:\.\w+)*(?:\|[^}]*)?\s*\}\})\s*(<\/\2>)/g,(o,i,r,a,l,c,d)=>{if(i.includes("data-vs-field"))return o;let u=n.get(c)||"text";return`${i.replace(/>$/,` data-vs-field="${c}" data-vs-type="${u}">`)}${l}${d}`}),s=s.replace(/(<img\b)([^>]*?)\bsrc\s*=\s*["']\{\{\s*module\.(\w+)\.src\s*\}\}["']([^>]*?>)/g,(o,i,r,a)=>o.includes("data-vs-field")?o:o.replace("<img",`<img data-vs-field="${a}" data-vs-type="image"`)),s=s.replace(/(<a\b)([^>]*?)\bhref\s*=\s*["']\{\{\s*module\.(\w+)\.url\.href\s*\}\}["']([^>]*?>)/g,(o,i,r,a)=>o.includes("data-vs-link")?o:o.replace("<a",`<a data-vs-link="${a}"`)),s}function Vi(){let t=C();if(!t)return ic();let e=Se(),n=t.moduleOrder||[];if(e.length===0&&n.length===0)return ic();if(Af(e))return _f(e,n);let s=[],o=[],i=[],r=new Set;for(let c of e){if(c.moduleHtml.includes("dnd_area")||c.moduleHtml.includes("extends "))continue;let d,u=[];try{let f=JSON.parse(c.fieldsJson);u=Array.isArray(f)?f:[],d={module:Qn(u)}}catch{d={module:{}}}let m=Ki(c.moduleHtml,u),g=xo(m,d),h=c.moduleName.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");s.push(`<div class="vibespot-module" id="${h}" data-module="${c.moduleName}">${g}</div>`),r.add(c.moduleName),c.moduleCss&&o.push(c.moduleCss),c.moduleJs&&i.push(c.moduleJs)}let a=$f(t.sharedCss);for(let c of n)if(!r.has(c)){let d=c.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");s.push(`<div class="vibespot-module vibespot-module--pending" id="${d}" data-module="${c}">
284
384
  <div class="vibespot-placeholder">
285
385
  <div class="vibespot-placeholder__name">${c}</div>
286
386
  </div>
287
- </div>`)}let l=`body{background:${r.bg}}.vibespot-placeholder{display:flex;align-items:center;justify-content:center;min-height:200px;padding:3rem;background:${r.surface};border:1px dashed ${r.border};border-radius:12px;margin:1rem 0}.vibespot-placeholder__name{font-size:1.5rem;font-weight:600;font-family:system-ui,sans-serif;color:${r.textMuted};letter-spacing:.5px;animation:vp-fade 2s ease-in-out infinite}@keyframes vp-fade{0%,100%{opacity:.3}50%{opacity:.8}}`;return Ro({renderedModules:s,sharedCss:e.sharedCss,moduleCssArray:[l,...o],sharedJs:e.sharedJs,moduleJsArray:i})}function ua(){return`<!DOCTYPE html>
387
+ </div>`)}let l=`body{background:${a.bg}}.vibespot-placeholder{display:flex;align-items:center;justify-content:center;min-height:200px;padding:3rem;background:${a.surface};border:1px dashed ${a.border};border-radius:12px;margin:1rem 0}.vibespot-placeholder__name{font-size:1.5rem;font-weight:600;font-family:system-ui,sans-serif;color:${a.textMuted};letter-spacing:.5px;animation:vp-fade 2s ease-in-out infinite}@keyframes vp-fade{0%,100%{opacity:.3}50%{opacity:.8}}`;return Wi({renderedModules:s,sharedCss:t.sharedCss,moduleCssArray:[l,...o],sharedJs:t.sharedJs,moduleJsArray:i})}function ic(){return`<!DOCTYPE html>
288
388
  <html lang="en">
289
389
  <head>
290
390
  <meta charset="utf-8">
@@ -335,11 +435,61 @@ document.querySelectorAll('img').forEach(function(img){
335
435
  <div class="welcome__sub">Build Something Great</div>
336
436
  </div>
337
437
  </body>
338
- </html>`}function Jo(e){let t=v();if(!t)return"";let n;for(let i of t.templates)if(n=i.modules.find(a=>a.moduleName===e),n)break;if(n||(n=t.modules.find(i=>i.moduleName===e)),!n)return"";let s;try{let i=JSON.parse(n.fieldsJson);s={module:Cs(i)}}catch{s={module:{}}}let o=Oo(n.moduleHtml,s);return Ro({renderedModules:[`<div class="vibespot-module" data-module="${n.moduleName}">${o}</div>`],sharedCss:t.sharedCss,moduleCssArray:n.moduleCss?[n.moduleCss]:[],sharedJs:t.sharedJs,moduleJsArray:n.moduleJs?[n.moduleJs]:[]})}var ks=L(()=>{"use strict";f();da();pe()});function ze(e){try{return JSON.parse(e)}catch{}let t=e,n=-1;for(let s=0;s<20;s++)try{return JSON.parse(t)}catch(o){if(!(o instanceof SyntaxError))return null;let i=/position (\d+)/.exec(o.message);if(!i)return null;let a=parseInt(i[1],10);if(a<=n)return null;n=a;let r=Math.max(0,a-5),c=t.slice(r,a+1).lastIndexOf('"');if(c===-1)return null;let d=r+c;if(d>0&&t[d-1]==="\\")return null;t=t.slice(0,d)+'\\"'+t.slice(d+1)}return null}function Sn(e){let t=e.indexOf('"modules"');if(t===-1)return null;let n=e.indexOf("[",t);if(n===-1)return null;let s=-1,o=0,i=!1,a=!1;for(let d=n+1;d<e.length;d++){let u=e[d];if(a){a=!1;continue}if(u==="\\"){a=!0;continue}if(u==='"'){i=!i;continue}i||(u==="{"&&o++,u==="}"&&(o--,o===0&&(s=d)))}if(s===-1)return null;let l=e.slice(0,s+1)+"]}",c=l.trimStart().startsWith("{")?l:"{"+l;return ze(c)}function Do(e){return{moduleName:String(e.moduleName||""),fieldsJson:typeof e.fieldsJson=="string"?e.fieldsJson:JSON.stringify(e.fieldsJson,null,2),metaJson:typeof e.metaJson=="string"?e.metaJson:JSON.stringify(e.metaJson,null,2),moduleHtml:String(e.moduleHtml||""),moduleCss:String(e.moduleCss||""),moduleJs:e.moduleJs?String(e.moduleJs):void 0}}function ma(e,t){let n=!1,s,o=/```vibespot-modules\s*\n?([\s\S]*?)```/g;for(;(s=o.exec(e))!==null;)try{A.info("parse","Found vibespot-modules block",{length:s[1].length});let i=ze(s[1]);if(!i||typeof i!="object")throw A.warn("parse","tryParseJSON returned non-object",{result:typeof i}),new Error("Invalid JSON after repair");let a=i;a.modules&&Array.isArray(a.modules)&&(oe({modules:a.modules.map(r=>Do(r)),sharedCss:a.sharedCss!==void 0?String(a.sharedCss):void 0,sharedJs:a.sharedJs!==void 0?String(a.sharedJs):void 0}),n=!0)}catch(i){A.warn("parse","Failed to parse vibespot-modules block",{error:i instanceof Error?i.message:String(i)})}if(!n){let i=/```(?:json)?\s*\n([\s\S]*?)```/g;for(;(s=i.exec(e))!==null;)if(s[1].includes('"modules"'))try{let a=ze(s[1]);if(!a||typeof a!="object")throw new Error("Invalid JSON after repair");let r=a;r.modules&&Array.isArray(r.modules)&&(oe({modules:r.modules.map(l=>Do(l)),sharedCss:r.sharedCss!==void 0?String(r.sharedCss):void 0,sharedJs:r.sharedJs!==void 0?String(r.sharedJs):void 0}),n=!0)}catch(a){A.warn("parse","Failed to parse JSON module block",{error:a instanceof Error?a.message:String(a)})}}if(!n&&(e.match(/```/g)||[]).length%2!==0&&e.includes('"modules"')){A.info("parse","Detected truncated response (odd fence count), attempting salvage");let a=e.lastIndexOf("```"),r=e.slice(a+3);r=r.replace(/^[\w-]*\s*\n?/,"");let l=Sn(r);if(l){let c=l;c.modules&&Array.isArray(c.modules)&&c.modules.length>0&&(A.info("parse","Salvaged modules from truncated response",{count:c.modules.length}),oe({modules:c.modules.map(d=>Do(d)),sharedCss:c.sharedCss!==void 0?String(c.sharedCss):void 0,sharedJs:c.sharedJs!==void 0?String(c.sharedJs):void 0}),n=!0,t&&t("Response was truncated \u2014 some modules may be incomplete. Try sending your request again for the full set."))}}if(!n){A.info("parse","No modules applied",{responseLength:e.length,hasVibespot:e.includes("vibespot-modules"),hasModules:e.includes('"modules"'),fenceCount:(e.match(/```/g)||[]).length});let i=e.includes("vibespot-modules")||e.includes('"modules"'),a=/\bmodule|modul/i.test(e)&&(/\bcreated?\b|\berstellt\b|\bgenerat/i.test(e)||/\|.*\|.*\|/m.test(e));if(i||a){let r=i?"Module changes could not be applied \u2014 the AI response contained invalid JSON. Try sending your request again.":"The AI described modules but did not include the required structured data. Try sending your request again.";A.warn("parse",r),t&&t(r)}}}var As=L(()=>{"use strict";f();pe();ie()});function Ut(){let e=v();return e?{pageType:xe()?.pageType,brandAssets:e.brandAssets}:{}}function pa(e,t,n=!1,s,o){let a=[{type:"text",text:Bu(t,n)}];if(n){let l=`## HubSpot CMS Rules
339
- ${Me()}
438
+ </html>`}function zi(t){let e=C();if(!e)return"";let n;for(let a of e.templates)if(n=a.modules.find(l=>l.moduleName===t),n)break;if(n||(n=e.modules.find(a=>a.moduleName===t)),!n)return"";let s,o=[];try{let a=JSON.parse(n.fieldsJson);o=Array.isArray(a)?a:[],s={module:Qn(o)}}catch{s={module:{}}}let i=Ki(n.moduleHtml,o),r=xo(i,s);return Wi({renderedModules:[`<div class="vibespot-module" data-module="${n.moduleName}">${r}</div>`],sharedCss:e.sharedCss,moduleCssArray:n.moduleCss?[n.moduleCss]:[],sharedJs:e.sharedJs,moduleJsArray:n.moduleJs?[n.moduleJs]:[]})}function _f(t,e){let n=[],s=new Set;for(let i of t){let r,a=[];try{let u=JSON.parse(i.fieldsJson);a=Array.isArray(u)?u:[],r={module:Qn(a)}}catch{r={module:{}}}let l=Ki(i.moduleHtml,a),c=xo(l,r),d=i.moduleName.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");n.push(`<div class="vibespot-module" id="${d}" data-module="${i.moduleName}">${c}</div>`),s.add(i.moduleName)}for(let i of e)if(!s.has(i)){let r=i.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");n.push(`<div class="vibespot-module vibespot-module--pending" id="${r}" data-module="${i}">
439
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="max-width:600px;margin:0 auto;">
440
+ <tr><td style="padding:40px 30px;text-align:center;background-color:#ffffff;border:1px dashed #ddd;">
441
+ <p style="font-family:Arial,Helvetica,sans-serif;font-size:14px;color:#999;">${i}</p>
442
+ </td></tr>
443
+ </table>
444
+ </div>`)}return`<!DOCTYPE html>
445
+ <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
446
+ <head>
447
+ <meta charset="utf-8">
448
+ <meta name="viewport" content="width=device-width, initial-scale=1">
449
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
450
+ <title>Email Preview</title>
451
+ <style>
452
+ html, body { margin: 0; padding: 0; overflow-x: hidden; }
453
+ body {
454
+ background-color: #e8e8e8;
455
+ font-family: Arial, Helvetica, sans-serif;
456
+ -webkit-font-smoothing: antialiased;
457
+ }
458
+ .vibespot-email-wrapper {
459
+ padding: 30px 20px;
460
+ background-color: #e8e8e8;
461
+ min-height: 100vh;
462
+ }
463
+ .vibespot-module { margin: 0 auto; max-width: 600px; }
464
+ .vibespot-module--pending table { opacity: 0.6; }
465
+ html { scroll-behavior: smooth; }
466
+ img { max-width: 100% !important; height: auto !important; }
467
+ table { max-width: 100% !important; }
468
+ td { word-break: break-word; }
469
+ @media screen and (max-width: 620px) {
470
+ .vibespot-email-wrapper { padding: 10px 8px; }
471
+ table[width] { width: 100% !important; }
472
+ img[width] { width: 100% !important; height: auto !important; }
473
+ }
474
+ </style>
475
+ </head>
476
+ <body>
477
+ <div class="vibespot-email-wrapper">
478
+ ${n.join(`
479
+ `)}
480
+ </div>
481
+ <script>
482
+ document.addEventListener('click', function(e) {
483
+ var a = e.target.closest('a[href^="#"]');
484
+ if (a) { e.preventDefault(); var t = document.querySelector(a.getAttribute('href')); if (t) t.scrollIntoView({ behavior: 'smooth' }); }
485
+ });
486
+ </script>
487
+ </body>
488
+ </html>`}var es=R(()=>{"use strict";y();oc();we();ts()});function ft(t){try{return JSON.parse(t)}catch{}let e=t,n=-1;for(let s=0;s<20;s++)try{return JSON.parse(e)}catch(o){if(!(o instanceof SyntaxError))return null;let i=/position (\d+)/.exec(o.message);if(!i)return null;let r=parseInt(i[1],10);if(r<=n)return null;n=r;let a=Math.max(0,r-5),c=e.slice(a,r+1).lastIndexOf('"');if(c===-1)return null;let d=a+c;if(d>0&&e[d-1]==="\\")return null;e=e.slice(0,d)+'\\"'+e.slice(d+1)}return null}function ns(t){let e=t.indexOf('"modules"');if(e===-1)return null;let n=t.indexOf("[",e);if(n===-1)return null;let s=-1,o=0,i=!1,r=!1;for(let d=n+1;d<t.length;d++){let u=t[d];if(r){r=!1;continue}if(u==="\\"){r=!0;continue}if(u==='"'){i=!i;continue}i||(u==="{"&&o++,u==="}"&&(o--,o===0&&(s=d)))}if(s===-1)return null;let l=t.slice(0,s+1)+"]}",c=l.trimStart().startsWith("{")?l:"{"+l;return ft(c)}function Yi(t){return{moduleName:String(t.moduleName||""),fieldsJson:typeof t.fieldsJson=="string"?t.fieldsJson:JSON.stringify(t.fieldsJson,null,2),metaJson:typeof t.metaJson=="string"?t.metaJson:JSON.stringify(t.metaJson,null,2),moduleHtml:String(t.moduleHtml||""),moduleCss:String(t.moduleCss||""),moduleJs:t.moduleJs?String(t.moduleJs):void 0}}function rc(t,e){let n=!1,s,o=/```vibespot-modules\s*\n?([\s\S]*?)```/g;for(;(s=o.exec(t))!==null;)try{E.info("parse","Found vibespot-modules block",{length:s[1].length});let i=ft(s[1]);if(!i||typeof i!="object")throw E.warn("parse","tryParseJSON returned non-object",{result:typeof i}),new Error("Invalid JSON after repair");let r=i;r.modules&&Array.isArray(r.modules)&&(De({modules:r.modules.map(a=>Yi(a)),sharedCss:r.sharedCss!==void 0?String(r.sharedCss):void 0,sharedJs:r.sharedJs!==void 0?String(r.sharedJs):void 0}),n=!0)}catch(i){E.warn("parse","Failed to parse vibespot-modules block",{error:i instanceof Error?i.message:String(i)})}if(!n){let i=/```(?:json)?\s*\n([\s\S]*?)```/g;for(;(s=i.exec(t))!==null;)if(s[1].includes('"modules"'))try{let r=ft(s[1]);if(!r||typeof r!="object")throw new Error("Invalid JSON after repair");let a=r;a.modules&&Array.isArray(a.modules)&&(De({modules:a.modules.map(l=>Yi(l)),sharedCss:a.sharedCss!==void 0?String(a.sharedCss):void 0,sharedJs:a.sharedJs!==void 0?String(a.sharedJs):void 0}),n=!0)}catch(r){E.warn("parse","Failed to parse JSON module block",{error:r instanceof Error?r.message:String(r)})}}if(!n&&(t.match(/```/g)||[]).length%2!==0&&t.includes('"modules"')){E.info("parse","Detected truncated response (odd fence count), attempting salvage");let r=t.lastIndexOf("```"),a=t.slice(r+3);a=a.replace(/^[\w-]*\s*\n?/,"");let l=ns(a);if(l){let c=l;c.modules&&Array.isArray(c.modules)&&c.modules.length>0&&(E.info("parse","Salvaged modules from truncated response",{count:c.modules.length}),De({modules:c.modules.map(d=>Yi(d)),sharedCss:c.sharedCss!==void 0?String(c.sharedCss):void 0,sharedJs:c.sharedJs!==void 0?String(c.sharedJs):void 0}),n=!0,e&&e("Response was truncated \u2014 some modules may be incomplete. Try sending your request again for the full set."))}}if(!n){E.info("parse","No modules applied",{responseLength:t.length,hasVibespot:t.includes("vibespot-modules"),hasModules:t.includes('"modules"'),fenceCount:(t.match(/```/g)||[]).length});let i=t.includes("vibespot-modules")||t.includes('"modules"'),r=/\bmodule|modul/i.test(t)&&(/\bcreated?\b|\berstellt\b|\bgenerat/i.test(t)||/\|.*\|.*\|/m.test(t));if(i||r){let a=i?"Module changes could not be applied \u2014 the AI response contained invalid JSON. Try sending your request again.":"The AI described modules but did not include the required structured data. Try sending your request again.";E.warn("parse",a),e&&e(a)}}}var wo=R(()=>{"use strict";y();we();de()});function bn(){let t=C();return t?{pageType:Ce()?.pageType,brandAssets:t.brandAssets}:{}}function ac(t,e,n=!1,s,o){let r=[{type:"text",text:Ef(e,n)}];if(n){let l=`## HubSpot CMS Rules
489
+ ${je()}
340
490
 
341
491
  ## Conversion Guide Reference
342
- ${e}`;a.push({type:"text",text:l,cache_control:{type:"ephemeral"}})}else{let l=`## Design Quality
492
+ ${t}`;r.push({type:"text",text:l,cache_control:{type:"ephemeral"}})}else{let l=`## Design Quality
343
493
  - Use modern, clean design with proper spacing and typography
344
494
  - Include responsive CSS (mobile breakpoint at 767px)
345
495
  - Add scroll animation classes where appropriate
@@ -362,22 +512,22 @@ When using scroll-animate classes (opacity: 0 \u2192 visible), you MUST include
362
512
  This makes elements appear after 3 seconds if JS never adds the .visible class. Once JS runs normally and adds .visible, the animation is cancelled.
363
513
 
364
514
  ## Design Guide
365
- ${po()}
515
+ ${Un()}
366
516
 
367
517
  ## Content & Copywriting Guide
368
- ${go()}
518
+ ${Ci()}
369
519
 
370
520
  ## HubSpot CMS Rules
371
- ${Me()}
521
+ ${je()}
372
522
 
373
523
  ## Conversion Guide Reference
374
- ${e}`;a.push({type:"text",text:l,cache_control:{type:"ephemeral"}})}let r=Lu(s,o);return r&&a.push({type:"text",text:r}),a.push({type:"text",text:"## REMINDER \u2014 Output Format (CRITICAL)\nYour response MUST contain a ```vibespot-modules code block with the full JSON. Without this block, no modules will be created. Do NOT respond with only text, tables, or descriptions. The JSON block is mandatory."}),a}function Lu(e,t){let n=[];if(e){let s=ho(e);s&&n.push(`## Page Type Context
375
- ${s}`)}if(t?.styleguide&&n.push(`## Brand Style Guide
376
- ${t.styleguide}`),t?.brandvoice&&n.push(`## Brand Voice
377
- ${t.brandvoice}`),t?.humanify!==!1){let s=fo();s&&n.push(`## Anti-AI Copy Rules (Humanify)
524
+ ${t}`;r.push({type:"text",text:l,cache_control:{type:"ephemeral"}})}let a=Mf(s,o);return a&&r.push({type:"text",text:a}),r.push({type:"text",text:"## REMINDER \u2014 Output Format (CRITICAL)\nYour response MUST contain a ```vibespot-modules code block with the full JSON. Without this block, no modules will be created. Do NOT respond with only text, tables, or descriptions. The JSON block is mandatory."}),r}function Mf(t,e){let n=[];if(t){let s=Ti(t);s&&n.push(`## Page Type Context
525
+ ${s}`)}if(e?.styleguide&&n.push(`## Brand Style Guide
526
+ ${e.styleguide}`),e?.brandvoice&&n.push(`## Brand Voice
527
+ ${e.brandvoice}`),e?.humanify!==!1){let s=ki();s&&n.push(`## Anti-AI Copy Rules (Humanify)
378
528
  ${s}`)}return n.join(`
379
529
 
380
- `)}function Bu(e,t){return`You are vibeSpot, an AI that builds HubSpot CMS landing pages from natural language descriptions.
530
+ `)}function Ef(t,e){return`You are vibeSpot, an AI that builds HubSpot CMS landing pages from natural language descriptions.
381
531
 
382
532
  ## Your Role
383
533
  You generate native HubSpot CMS modules directly from user descriptions. Every module you create is immediately compatible with HubSpot's drag-and-drop page editor.
@@ -419,8 +569,8 @@ NEVER respond with only a text summary. The vibespot-modules JSON block is manda
419
569
  - NEVER use "name": "name" (reserved) \u2014 use "item_name" instead
420
570
  - NEVER put literal \\n newline sequences in field default values \u2014 use plain text without line breaks
421
571
  - Wrap style fields in a "styles" group with "tab": "STYLE"
422
- - All CSS classes must use a unique prefix "${e}-" to avoid theme conflicts
423
- - Use BEM naming: ${e}-module__element--modifier
572
+ - All CSS classes must use a unique prefix "${t}-" to avoid theme conflicts
573
+ - Use BEM naming: ${t}-module__element--modifier
424
574
  - metaJson must include: host_template_types: ["PAGE"], is_available_for_new_content: true
425
575
  - For repeater groups, use "occurrence": { "min": 0, "max": 100 } and iterate with {% for %}
426
576
  - Color fields: type "color", default { "color": "#hex", "opacity": 100 }
@@ -429,9 +579,9 @@ NEVER respond with only a text summary. The vibespot-modules JSON block is manda
429
579
 
430
580
  ## Images & Media
431
581
  - Users can upload images that get placed in the theme's assets/ folder automatically
432
- - When the user uploads an image and wants it on the page, reference it with: {{ get_asset_url("${e}/assets/filename.ext") }}
433
- - IMPORTANT: get_asset_url() paths must include the theme name prefix "${e}/" because HubSpot resolves from the Design Manager root
434
- - For background images with uploaded assets: style="background-image: url('{{ get_asset_url(\\"${e}/assets/filename.ext\\") }}')"
582
+ - When the user uploads an image and wants it on the page, reference it with: {{ get_asset_url("${t}/assets/filename.ext") }}
583
+ - IMPORTANT: get_asset_url() paths must include the theme name prefix "${t}/" because HubSpot resolves from the Design Manager root
584
+ - For background images with uploaded assets: style="background-image: url('{{ get_asset_url(\\"${t}/assets/filename.ext\\") }}')"
435
585
  - For images without an uploaded asset, use image fields (type "image") with placehold.co defaults
436
586
  - ALWAYS use image fields (type "image") so users can swap images in the page editor
437
587
  - Use placehold.co URLs as defaults so the preview looks complete (e.g. https://placehold.co/800x600/1a1a2e/ffffff?text=Hero+Image)
@@ -446,7 +596,7 @@ NEVER respond with only a text summary. The vibespot-modules JSON block is manda
446
596
  - The id should be the moduleName lowercased with spaces replaced by hyphens (e.g. "Pricing Cards" \u2192 id="pricing-cards")
447
597
  - For navigation/menu modules, use anchor links that match these ids: e.g. href="#features"
448
598
  - Always include smooth scrolling behavior in navigation link clicks
449
- - For nav modules, make menu items editable via a repeater group with "label" (text) and "anchor" (text) fields`+(t?`
599
+ - For nav modules, make menu items editable via a repeater group with "label" (text) and "anchor" (text) fields`+(e?`
450
600
 
451
601
  ## When modifying existing modules
452
602
  The current template's modules are listed in page order in the user message. This sequence forms the page narrative.
@@ -456,7 +606,7 @@ The current template's modules are listed in page order in the user message. Thi
456
606
  - **Rearrange**: When the user asks to reorder sections, include a "moduleOrder" array in the vibespot-modules JSON with the new sequence of module names.
457
607
  - **Remove**: When the user asks to remove a section, omit it from the output.
458
608
  - **Preserve**: Always include ALL modules you want to keep (modified + unchanged) in your output. Modules omitted from the output will be removed from the page.
459
- - **Design consistency**: Match the existing theme's design language \u2014 reuse the same CSS custom properties, class naming prefix, spacing scale, and typography.`:"")}function xn(e,t,n=!1,s,o){let i=`You are vibeSpot, an AI that builds HubSpot CMS landing pages from natural language descriptions.
609
+ - **Design consistency**: Match the existing theme's design language \u2014 reuse the same CSS custom properties, class naming prefix, spacing scale, and typography.`:"")}function ss(t,e,n=!1,s,o){let i=`You are vibeSpot, an AI that builds HubSpot CMS landing pages from natural language descriptions.
460
610
 
461
611
  ## Your Role
462
612
  You generate native HubSpot CMS modules directly from user descriptions. Every module you create is immediately compatible with HubSpot's drag-and-drop page editor.
@@ -498,8 +648,8 @@ NEVER respond with only a text summary. The vibespot-modules JSON block is manda
498
648
  - NEVER use "name": "name" (reserved) \u2014 use "item_name" instead
499
649
  - NEVER put literal \\n newline sequences in field default values \u2014 use plain text without line breaks
500
650
  - Wrap style fields in a "styles" group with "tab": "STYLE"
501
- - All CSS classes must use a unique prefix "${t}-" to avoid theme conflicts
502
- - Use BEM naming: ${t}-module__element--modifier
651
+ - All CSS classes must use a unique prefix "${e}-" to avoid theme conflicts
652
+ - Use BEM naming: ${e}-module__element--modifier
503
653
  - metaJson must include: host_template_types: ["PAGE"], is_available_for_new_content: true
504
654
  - For repeater groups, use "occurrence": { "min": 0, "max": 100 } and iterate with {% for %}
505
655
  - Color fields: type "color", default { "color": "#hex", "opacity": 100 }
@@ -508,9 +658,9 @@ NEVER respond with only a text summary. The vibespot-modules JSON block is manda
508
658
 
509
659
  ## Images & Media
510
660
  - Users can upload images that get placed in the theme's assets/ folder automatically
511
- - When the user uploads an image and wants it on the page, reference it with: {{ get_asset_url("${t}/assets/filename.ext") }}
512
- - IMPORTANT: get_asset_url() paths must include the theme name prefix "${t}/" because HubSpot resolves from the Design Manager root
513
- - For background images with uploaded assets: style="background-image: url('{{ get_asset_url(\\"${t}/assets/filename.ext\\") }}')"
661
+ - When the user uploads an image and wants it on the page, reference it with: {{ get_asset_url("${e}/assets/filename.ext") }}
662
+ - IMPORTANT: get_asset_url() paths must include the theme name prefix "${e}/" because HubSpot resolves from the Design Manager root
663
+ - For background images with uploaded assets: style="background-image: url('{{ get_asset_url(\\"${e}/assets/filename.ext\\") }}')"
514
664
  - For images without an uploaded asset, use image fields (type "image") with placehold.co defaults
515
665
  - ALWAYS use image fields (type "image") so users can swap images in the page editor
516
666
  - Use placehold.co URLs as defaults so the preview looks complete (e.g. https://placehold.co/800x600/1a1a2e/ffffff?text=Hero+Image)
@@ -535,25 +685,25 @@ The current template's modules are listed in page order in the user message. Thi
535
685
  - **Rearrange**: When the user asks to reorder sections, include a "moduleOrder" array in the vibespot-modules JSON with the new sequence of module names.
536
686
  - **Remove**: When the user asks to remove a section, omit it from the output.
537
687
  - **Preserve**: Always include ALL modules you want to keep (modified + unchanged) in your output. Modules omitted from the output will be removed from the page.
538
- - **Design consistency**: Match the existing theme's design language \u2014 reuse the same CSS custom properties, class naming prefix, spacing scale, and typography.`,a=s?ho(s):"",r=a?`
688
+ - **Design consistency**: Match the existing theme's design language \u2014 reuse the same CSS custom properties, class naming prefix, spacing scale, and typography.`,r=s?Ti(s):"",a=r?`
539
689
 
540
690
  ## Page Type Context
541
- ${a}`:"",l="";if(o?.styleguide&&(l+=`
691
+ ${r}`:"",l="";if(o?.styleguide&&(l+=`
542
692
 
543
693
  ## Brand Style Guide
544
694
  ${o.styleguide}`),o?.brandvoice&&(l+=`
545
695
 
546
696
  ## Brand Voice
547
- ${o.brandvoice}`),o?.humanify!==!1){let d=fo();d&&(l+=`
697
+ ${o.brandvoice}`),o?.humanify!==!1){let d=ki();d&&(l+=`
548
698
 
549
699
  ## Anti-AI Copy Rules (Humanify)
550
- ${d}`)}let c="\n\n## REMINDER \u2014 Output Format (CRITICAL)\nYour response MUST contain a ```vibespot-modules code block with the full JSON. Without this block, no modules will be created. Do NOT respond with only text, tables, or descriptions. The JSON block is mandatory.";return n?i+r+l+`
700
+ ${d}`)}let c="\n\n## REMINDER \u2014 Output Format (CRITICAL)\nYour response MUST contain a ```vibespot-modules code block with the full JSON. Without this block, no modules will be created. Do NOT respond with only text, tables, or descriptions. The JSON block is mandatory.";return n?i+a+l+`
551
701
 
552
702
  ## HubSpot CMS Rules
553
- ${Me()}
703
+ ${je()}
554
704
 
555
705
  ## Conversion Guide Reference
556
- ${e}`+c:i+r+l+`
706
+ ${t}`+c:i+a+l+`
557
707
 
558
708
  ## Design Quality
559
709
  - Use modern, clean design with proper spacing and typography
@@ -578,140 +728,173 @@ When using scroll-animate classes (opacity: 0 \u2192 visible), you MUST include
578
728
  This makes elements appear after 3 seconds if JS never adds the .visible class. Once JS runs normally and adds .visible, the animation is cancelled.
579
729
 
580
730
  ## Design Guide
581
- ${po()}
731
+ ${Un()}
582
732
 
583
733
  ## Content & Copywriting Guide
584
- ${go()}
734
+ ${Ci()}
585
735
 
586
736
  ## HubSpot CMS Rules
587
- ${Me()}
737
+ ${je()}
588
738
 
589
739
  ## Conversion Guide Reference
590
- ${e}`+c}function vn(){let e=v(),t=[],n=e.modules,s=n.length;if(s>0){t.push(`
740
+ ${t}`+c}function os(){let t=C(),e=[],n=t.modules,s=n.length;if(s>0){e.push(`
591
741
 
592
742
  ## Page Narrative (module sequence)
593
- `),t.push(`This template has ${s} module${s===1?"":"s"} in this order:
594
- `);for(let r=0;r<s;r++)t.push(`${r+1}. ${n[r].moduleName}
595
- `);t.push(`
743
+ `),e.push(`This template has ${s} module${s===1?"":"s"} in this order:
744
+ `);for(let a=0;a<s;a++)e.push(`${a+1}. ${n[a].moduleName}
745
+ `);e.push(`
596
746
  When the user asks to modify this page, decide whether to MODIFY existing modules, ADD new ones at the right narrative position, REARRANGE the sequence, or REMOVE sections. Always include ALL modules you want to keep in your output.
597
- `),t.push(`
747
+ `),e.push(`
598
748
  ## Current Module State
599
- `);for(let r=0;r<s;r++){let l=n[r];t.push(`
600
- ### ${r+1}/${s}: ${l.moduleName}.module
601
- `),t.push(`**fields.json:**
749
+ `);for(let a=0;a<s;a++){let l=n[a];e.push(`
750
+ ### ${a+1}/${s}: ${l.moduleName}.module
751
+ `),e.push(`**fields.json:**
602
752
  \`\`\`json
603
753
  ${l.fieldsJson}
604
754
  \`\`\`
605
- `),t.push(`**module.html:**
755
+ `),e.push(`**module.html:**
606
756
  \`\`\`html
607
757
  ${l.moduleHtml}
608
758
  \`\`\`
609
- `),t.push(`**module.css:**
759
+ `),e.push(`**module.css:**
610
760
  \`\`\`css
611
761
  ${l.moduleCss}
612
762
  \`\`\`
613
- `),l.moduleJs&&t.push(`**module.js:**
763
+ `),l.moduleJs&&e.push(`**module.js:**
614
764
  \`\`\`js
615
765
  ${l.moduleJs}
616
766
  \`\`\`
617
- `)}e.sharedCss&&t.push(`
767
+ `)}t.sharedCss&&e.push(`
618
768
  ### Shared CSS
619
769
  \`\`\`css
620
- ${e.sharedCss}
770
+ ${t.sharedCss}
621
771
  \`\`\`
622
- `),e.sharedJs&&t.push(`
772
+ `),t.sharedJs&&e.push(`
623
773
  ### Shared JS
624
774
  \`\`\`js
625
- ${e.sharedJs}
775
+ ${t.sharedJs}
626
776
  \`\`\`
627
- `)}let o=at(),i=new Set(e.modules.map(r=>r.moduleName)),a=o.filter(r=>!i.has(r.module.moduleName));if(a.length>0){t.push(`
777
+ `)}let o=At(),i=new Set(t.modules.map(a=>a.moduleName)),r=o.filter(a=>!i.has(a.module.moduleName));if(r.length>0){e.push(`
628
778
 
629
779
  ## Available modules in this theme (reusable)
630
- `);for(let r of a)t.push(`- ${r.module.moduleName} (used in: ${r.usedIn.join(", ")})
631
- `);t.push(`
780
+ `);for(let a of r)e.push(`- ${a.module.moduleName} (used in: ${a.usedIn.join(", ")})
781
+ `);e.push(`
632
782
  The user can ask to reuse any of these modules by name.
633
- `)}return t.join("")}function Ho(e,t){let n=v(),s=n.messages.slice(-20);s.length>0&&s[s.length-1].role==="user"&&s[s.length-1].content===e&&(s=s.slice(0,-1));let o=s.map(d=>({role:d.role,content:d.content})),i=vn(),a="";if(n.assets?.length){let d=n.assets.filter(u=>u.type==="image"&&u.usage==="asset");d.length>0&&(a=`
783
+ `)}return e.join("")}function qi(t,e){let n=C(),s=n.messages.slice(-20);s.length>0&&s[s.length-1].role==="user"&&s[s.length-1].content===t&&(s=s.slice(0,-1));let o=s.map(d=>({role:d.role,content:d.content})),i=os(),r="";if(n.assets?.length){let d=n.assets.filter(u=>u.type==="image"&&u.usage==="asset");d.length>0&&(r=`
634
784
 
635
785
  ## Available Theme Assets
636
786
  These images are in the theme's assets/ folder. Reference them with get_asset_url("${n.themeName}/assets/filename"):
637
787
  ${d.map(u=>`- ${u.filename} (${u.originalName}) \u2192 get_asset_url("${n.themeName}/assets/${u.filename}")`).join(`
638
- `)}`)}let r=e;i&&(r+=`
788
+ `)}`)}let a=t;i&&(a+=`
639
789
 
640
790
  ---
641
- ${i}`),a&&(r+=a),r+="\n\n---\nRemember: respond with a ```vibespot-modules JSON block containing ALL modules. No text-only responses.";let l=t&&t.length>0;if(l)for(let d of t)d.type==="document"&&d.extractedText&&(r+=`
791
+ ${i}`),r&&(a+=r),a+="\n\n---\nRemember: respond with a ```vibespot-modules JSON block containing ALL modules. No text-only responses.";let l=e&&e.length>0;if(l)for(let d of e)d.type==="document"&&d.extractedText&&(a+=`
642
792
 
643
793
  ---
644
794
  [Attached document: ${d.originalName}]
645
- ${d.extractedText}`),d.type==="image"&&d.usage==="asset"&&d.assetPath&&(r+=`
795
+ ${d.extractedText}`),d.type==="image"&&d.usage==="asset"&&d.assetPath&&(a+=`
646
796
 
647
- [Uploaded image: ${d.originalName} \u2192 available as get_asset_url("${d.assetPath}")]`);let c=l?t.filter(d=>d.type==="image"&&d.base64):[];if(c.length>0){let d=[];for(let u of c)d.push({type:"image",source:{type:"base64",media_type:u.mimeType,data:u.base64}});d.push({type:"text",text:r}),o.push({role:"user",content:d})}else o.push({role:"user",content:r});return o}var ga=L(()=>{"use strict";f();ot();pe()});import{spawn as fa}from"child_process";async function ha(){return Lo||(Lo=(await import("@anthropic-ai/sdk")).default),Lo}function ya(e){if(!e?.length)return"";let t=[];for(let n of e)n.type==="image"&&n.usage==="asset"&&n.assetPath&&t.push(`
648
- [Uploaded image: ${n.originalName} \u2192 use get_asset_url("${n.assetPath}")]`),n.type==="document"&&n.extractedText&&t.push(`
797
+ [Uploaded image: ${d.originalName} \u2192 available as get_asset_url("${d.assetPath}")]`);let c=l?e.filter(d=>d.type==="image"&&d.base64):[];if(c.length>0){let d=[];for(let u of c)d.push({type:"image",source:{type:"base64",media_type:u.mimeType,data:u.base64}});d.push({type:"text",text:a}),o.push({role:"user",content:d})}else o.push({role:"user",content:a});return o}var lc=R(()=>{"use strict";y();Ue();we()});import{spawn as cc}from"child_process";async function dc(){return Xi||(Xi=(await import("@anthropic-ai/sdk")).default),Xi}function uc(t){if(!t?.length)return"";let e=[];for(let n of t)n.type==="image"&&n.usage==="asset"&&n.assetPath&&e.push(`
798
+ [Uploaded image: ${n.originalName} \u2192 use get_asset_url("${n.assetPath}")]`),n.type==="document"&&n.extractedText&&e.push(`
649
799
 
650
800
  ---
651
801
  [Attached document: ${n.originalName}]
652
- ${n.extractedText}`);return t.join("")}async function ba(e,t,n,s,o,i,a){for(let r=0;;r++)try{let l="",c=0,d=i||(()=>{});d(ye[0]);let u=setInterval(()=>{c++,d(ye[Math.min(c,ye.length-1)])},6e3);try{let m=e.messages.stream({model:s,max_tokens:48e3,system:t,messages:n});for await(let g of m)if(g.type==="content_block_delta"&&g.delta.type==="text_delta"){let y=g.delta.text;l+=y,o(y)}}finally{clearInterval(u)}a&&a(l);return}catch(l){let c=l.status,d=l.error?.type;if(!(c===429||d==="rate_limit_error"||l instanceof Error&&l.message.includes("429"))||r>=Bo.length)throw l;let m=Bo[r];A.warn("ai-engine",`Rate limited (429), attempt ${r+1}/${Bo.length} \u2014 waiting ${m}s`),i&&i(`Rate limited by Anthropic API \u2014 retrying in ${m}s...`),await new Promise(g=>setTimeout(g,m*1e3)),i&&i("Retrying...")}}function Sa(e,t,n){let s=ce(),i=v().modules.length>0,a=Ho(e,n),r=Ut(),l=pa(s,t,i,r.pageType,r.brandAssets);return{messages:a,systemBlocks:l,conversionGuide:s,editMode:i}}async function xa(e,t,n,s,o,i,a,r){let l=await ha(),c=new l({apiKey:t}),{messages:d,systemBlocks:u}=Sa(e,n,r);A.info("anthropic","API call",{model:s,systemBlockCount:u.length,cachedBlocks:u.filter(m=>m.cache_control).length,messageCount:d.length}),await ba(c,u,d,s,o,i,a)}async function va(e,t,n,s,o,i,a){let r=await no();if(!r)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let l=await ha(),c=new l({authToken:r,defaultHeaders:Zt}),{messages:d,systemBlocks:u}=Sa(e,t,a),m=[{type:"text",text:Mt},...u];A.info("anthropic-oauth","API call",{model:n,systemBlockCount:m.length,cachedBlocks:m.filter(g=>g.cache_control).length,messageCount:d.length}),await ba(c,m,d,n,s,o,i)}async function wa(e,t,n,s,o,i,a,r){let l=ce(),c=v().modules.length>0,d=Ho(e,r),u=Ut(),m=d.map(O=>typeof O.content=="string"?O:{role:O.role,content:O.content.map(R=>R.type==="text"?{type:"text",text:R.text}:{type:"image_url",image_url:{url:`data:${R.source.media_type};base64,${R.source.data}`}})}),g=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({model:s,max_tokens:48e3,stream:!0,messages:[{role:"system",content:xn(l,n,c,u.pageType,u.brandAssets)},...m]})});if(!g.ok){let O=await g.text();throw new Error(`OpenAI API error (${g.status}): ${O}`)}let y=0,h=i||(()=>{});h(ye[0]);let b=setInterval(()=>{y++,h(ye[Math.min(y,ye.length-1)])},6e3),x="",w=g.body.getReader(),S=new TextDecoder,M="";try{for(;;){let{done:O,value:R}=await w.read();if(O)break;M+=S.decode(R,{stream:!0});let H=M.split(`
653
- `);M=H.pop()||"";for(let z of H){if(!z.startsWith("data: "))continue;let _=z.slice(6).trim();if(_==="[DONE]")break;try{let C=JSON.parse(_).choices?.[0]?.delta?.content;C&&(x+=C,o(C))}catch{}}}}finally{clearInterval(b)}a&&a(x)}async function Ca(e,t,n,s,o,i,a){let r=ce(),l=v(),c=l.modules.length>0,d=vn(),u=Ut(),m=[];for(let _ of l.messages.slice(-20))m.push({role:_.role==="assistant"?"model":"user",parts:[{text:_.content}]});let g=d?`${e}
802
+ ${n.extractedText}`);return e.join("")}async function mc(t,e,n,s,o,i,r){for(let a=0;;a++)try{let l="",c=0,d=i||(()=>{});d(Re[0]);let u=setInterval(()=>{c++,d(Re[Math.min(c,Re.length-1)])},6e3);try{let m=t.messages.stream({model:s,max_tokens:48e3,system:e,messages:n});for await(let g of m)if(g.type==="content_block_delta"&&g.delta.type==="text_delta"){let h=g.delta.text;l+=h,o(h)}}finally{clearInterval(u)}r&&r(l);return}catch(l){let c=l.status,d=l.error?.type;if(!(c===429||d==="rate_limit_error"||l instanceof Error&&l.message.includes("429"))||a>=Zi.length)throw l;let m=Zi[a];E.warn("ai-engine",`Rate limited (429), attempt ${a+1}/${Zi.length} \u2014 waiting ${m}s`),i&&i(`Rate limited by Anthropic API \u2014 retrying in ${m}s...`),await new Promise(g=>setTimeout(g,m*1e3)),i&&i("Retrying...")}}function pc(t,e,n){let s=fe(),i=C().modules.length>0,r=qi(t,n),a=bn(),l=ac(s,e,i,a.pageType,a.brandAssets);return{messages:r,systemBlocks:l,conversionGuide:s,editMode:i}}async function gc(t,e,n,s,o,i,r,a){let l=await dc(),c=new l({apiKey:e}),{messages:d,systemBlocks:u}=pc(t,n,a);E.info("anthropic","API call",{model:s,systemBlockCount:u.length,cachedBlocks:u.filter(m=>m.cache_control).length,messageCount:d.length}),await mc(c,u,d,s,o,i,r)}async function fc(t,e,n,s,o,i,r){let a=await pi();if(!a)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let l=await dc(),c=new l({authToken:a,defaultHeaders:_n}),{messages:d,systemBlocks:u}=pc(t,e,r),m=[{type:"text",text:rn},...u];E.info("anthropic-oauth","API call",{model:n,systemBlockCount:m.length,cachedBlocks:m.filter(g=>g.cache_control).length,messageCount:d.length}),await mc(c,m,d,n,s,o,i)}async function hc(t,e,n,s,o,i,r,a){let l=fe(),c=C().modules.length>0,d=qi(t,a),u=bn(),m=d.map(F=>typeof F.content=="string"?F:{role:F.role,content:F.content.map(H=>H.type==="text"?{type:"text",text:H.text}:{type:"image_url",image_url:{url:`data:${H.source.media_type};base64,${H.source.data}`}})}),g=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify({model:s,max_tokens:48e3,stream:!0,messages:[{role:"system",content:ss(l,n,c,u.pageType,u.brandAssets)},...m]})});if(!g.ok){let F=await g.text();throw new Error(`OpenAI API error (${g.status}): ${F}`)}let h=0,f=i||(()=>{});f(Re[0]);let b=setInterval(()=>{h++,f(Re[Math.min(h,Re.length-1)])},6e3),S="",x=g.body.getReader(),w=new TextDecoder,P="";try{for(;;){let{done:F,value:H}=await x.read();if(F)break;P+=w.decode(H,{stream:!0});let L=P.split(`
803
+ `);P=L.pop()||"";for(let V of L){if(!V.startsWith("data: "))continue;let B=V.slice(6).trim();if(B==="[DONE]")break;try{let T=JSON.parse(B).choices?.[0]?.delta?.content;T&&(S+=T,o(T))}catch{}}}}finally{clearInterval(b)}r&&r(S)}async function yc(t,e,n,s,o,i,r){let a=fe(),l=C(),c=l.modules.length>0,d=os(),u=bn(),m=[];for(let B of l.messages.slice(-20))m.push({role:B.role==="assistant"?"model":"user",parts:[{text:B.content}]});let g=d?`${t}
654
804
 
655
805
  ---
656
- ${d}`:e;if(a?.length)for(let _ of a)_.type==="document"&&_.extractedText&&(g+=`
806
+ ${d}`:t;if(r?.length)for(let B of r)B.type==="document"&&B.extractedText&&(g+=`
657
807
 
658
808
  ---
659
- [Attached document: ${_.originalName}]
660
- ${_.extractedText}`),_.type==="image"&&_.usage==="asset"&&_.assetPath&&(g+=`
809
+ [Attached document: ${B.originalName}]
810
+ ${B.extractedText}`),B.type==="image"&&B.usage==="asset"&&B.assetPath&&(g+=`
661
811
 
662
- [Uploaded image: ${_.originalName} \u2192 available as get_asset_url("${_.assetPath}")]`);let y=[];if(a?.length)for(let _ of a)_.type==="image"&&_.base64&&y.push({inlineData:{mimeType:_.mimeType,data:_.base64}});y.push({text:g}),m.push({role:"user",parts:y});let b=`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse&key=${t}`,x=await fetch(b,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({systemInstruction:{parts:[{text:xn(r,n,c,u.pageType,u.brandAssets)}]},contents:m,generationConfig:{maxOutputTokens:48e3}})});if(!x.ok){let _=await x.text();throw new Error(`Gemini API error (${x.status}): ${_}`)}let w=0,S=o||(()=>{});S(ye[0]);let M=setInterval(()=>{w++,S(ye[Math.min(w,ye.length-1)])},6e3),O="",R=x.body.getReader(),H=new TextDecoder,z="";try{for(;;){let{done:_,value:F}=await R.read();if(_)break;z+=H.decode(F,{stream:!0});let C=z.split(`
663
- `);z=C.pop()||"";for(let I of C){if(!I.startsWith("data: "))continue;let Z=I.slice(6).trim();try{let ft=JSON.parse(Z).candidates?.[0]?.content?.parts?.[0]?.text;ft&&(O+=ft,s(ft))}catch{}}}}finally{clearInterval(M)}i&&i(O)}function Uo(e,t,n={},s){return new Promise((o,i)=>{let a={...process.env};delete a.CLAUDECODE;let r=fa("claude",e,{stdio:["pipe","pipe","pipe"],env:a}),l="",c="",d="",u=!1,m=null,g=S=>{u||(u=!0,S())},y=S=>{try{if(S.type==="assistant"&&S.message?.content){for(let M of S.message.content)if(M.type==="text"&&typeof M.text=="string"){let O=M.text;l+=O,n.onChunk&&n.onChunk(O)}else if(M.type==="tool_use"){let O=M;O.name&&n.onToolUse&&n.onToolUse(O.name,O.input)}}S.type==="result"&&(m=S,!l&&typeof S.result=="string"&&(l=S.result,n.onChunk&&n.onChunk(S.result))),n.onEvent&&n.onEvent(S)}catch{}};r.stdout.on("data",S=>{d+=S.toString();let M;for(;(M=d.indexOf(`
664
- `))>=0;){let O=d.slice(0,M).trim();if(d=d.slice(M+1),!!O)try{y(JSON.parse(O))}catch{}}}),r.stderr.on("data",S=>{c+=S.toString()}),r.on("error",S=>g(()=>i(new Error(`claude failed to start: ${S.message}`)))),r.on("close",S=>{if(d.trim()){try{y(JSON.parse(d.trim()))}catch{}d=""}g(()=>{S!==0||m&&m.is_error?i(new Error(`claude exited with code ${S}.
812
+ [Uploaded image: ${B.originalName} \u2192 available as get_asset_url("${B.assetPath}")]`);let h=[];if(r?.length)for(let B of r)B.type==="image"&&B.base64&&h.push({inlineData:{mimeType:B.mimeType,data:B.base64}});h.push({text:g}),m.push({role:"user",parts:h});let b=`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse&key=${e}`,S=await fetch(b,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({systemInstruction:{parts:[{text:ss(a,n,c,u.pageType,u.brandAssets)}]},contents:m,generationConfig:{maxOutputTokens:48e3}})});if(!S.ok){let B=await S.text();throw new Error(`Gemini API error (${S.status}): ${B}`)}let x=0,w=o||(()=>{});w(Re[0]);let P=setInterval(()=>{x++,w(Re[Math.min(x,Re.length-1)])},6e3),F="",H=S.body.getReader(),L=new TextDecoder,V="";try{for(;;){let{done:B,value:N}=await H.read();if(B)break;V+=L.decode(N,{stream:!0});let T=V.split(`
813
+ `);V=T.pop()||"";for(let I of T){if(!I.startsWith("data: "))continue;let k=I.slice(6).trim();try{let oe=JSON.parse(k).candidates?.[0]?.content?.parts?.[0]?.text;oe&&(F+=oe,s(oe))}catch{}}}}finally{clearInterval(P)}i&&i(F)}function Qi(t,e,n={},s){return new Promise((o,i)=>{let r={...process.env};delete r.CLAUDECODE;let a=cc("claude",t,{stdio:["pipe","pipe","pipe"],env:r}),l="",c="",d="",u=!1,m=null,g=w=>{u||(u=!0,w())},h=w=>{try{if(w.type==="assistant"&&w.message?.content){for(let P of w.message.content)if(P.type==="text"&&typeof P.text=="string"){let F=P.text;l+=F,n.onChunk&&n.onChunk(F)}else if(P.type==="tool_use"){let F=P;F.name&&n.onToolUse&&n.onToolUse(F.name,F.input)}}w.type==="result"&&(m=w,!l&&typeof w.result=="string"&&(l=w.result,n.onChunk&&n.onChunk(w.result))),n.onEvent&&n.onEvent(w)}catch{}};a.stdout.on("data",w=>{d+=w.toString();let P;for(;(P=d.indexOf(`
814
+ `))>=0;){let F=d.slice(0,P).trim();if(d=d.slice(P+1),!!F)try{h(JSON.parse(F))}catch{}}}),a.stderr.on("data",w=>{c+=w.toString()}),a.on("error",w=>g(()=>i(new Error(`claude failed to start: ${w.message}`)))),a.on("close",w=>{if(d.trim()){try{h(JSON.parse(d.trim()))}catch{}d=""}g(()=>{w!==0||m&&m.is_error?i(new Error(`claude exited with code ${w}.
665
815
  `+(c?`Stderr: ${c.slice(0,500)}
666
- `:"")+(l?`Output: ${l.slice(0,500)}`:"No output"))):o(l)})}),r.stdin.on("error",()=>{}),r.stdin.write(t)?r.stdin.end():r.stdin.once("drain",()=>r.stdin.end());let b=s||6e5,x=Math.round(b/6e4),w=setTimeout(()=>{r.kill(),g(()=>i(new Error(`claude (stream-json) timed out after ${x} minutes.
816
+ `:"")+(l?`Output: ${l.slice(0,500)}`:"No output"))):o(l)})}),a.stdin.on("error",()=>{}),a.stdin.write(e)?a.stdin.end():a.stdin.once("drain",()=>a.stdin.end());let b=s||6e5,S=Math.round(b/6e4),x=setTimeout(()=>{a.kill(),g(()=>i(new Error(`claude (stream-json) timed out after ${S} minutes.
667
817
  `+(c?`Stderr: ${c.slice(0,500)}
668
- `:"")+`Partial output (${l.length} chars): ${l.slice(0,500)}`)))},b);r.on("close",()=>clearTimeout(w))})}function Go(e,t,n,s,o){return new Promise((i,a)=>{let r={...process.env};delete r.CLAUDECODE;let l=fa(e,t,{stdio:["pipe","pipe","pipe"],env:r}),c="",d="",u=!1,m=x=>{u||(u=!0,x())};l.stdout.on("data",x=>{let w=x.toString();c+=w,s&&s(w)}),l.stderr.on("data",x=>{d+=x.toString()}),l.on("error",x=>m(()=>a(new Error(`${e} failed to start: ${x.message}`)))),l.on("close",x=>{m(()=>{x!==0?a(new Error(`${e} exited with code ${x}.
818
+ `:"")+`Partial output (${l.length} chars): ${l.slice(0,500)}`)))},b);a.on("close",()=>clearTimeout(x))})}function er(t,e,n,s,o){return new Promise((i,r)=>{let a={...process.env};delete a.CLAUDECODE;let l=cc(t,e,{stdio:["pipe","pipe","pipe"],env:a}),c="",d="",u=!1,m=S=>{u||(u=!0,S())};l.stdout.on("data",S=>{let x=S.toString();c+=x,s&&s(x)}),l.stderr.on("data",S=>{d+=S.toString()}),l.on("error",S=>m(()=>r(new Error(`${t} failed to start: ${S.message}`)))),l.on("close",S=>{m(()=>{S!==0?r(new Error(`${t} exited with code ${S}.
669
819
  `+(d?`Stderr: ${d.slice(0,500)}
670
- `:"")+(c?`Output: ${c.slice(0,500)}`:"No output"))):i(c)})}),l.stdin.on("error",()=>{}),l.stdin.write(n)?l.stdin.end():l.stdin.once("drain",()=>l.stdin.end());let y=o||6e5,h=Math.round(y/6e4),b=setTimeout(()=>{l.kill(),m(()=>a(new Error(`${e} timed out after ${h} minutes.
820
+ `:"")+(c?`Output: ${c.slice(0,500)}`:"No output"))):i(c)})}),l.stdin.on("error",()=>{}),l.stdin.write(n)?l.stdin.end():l.stdin.once("drain",()=>l.stdin.end());let h=o||6e5,f=Math.round(h/6e4),b=setTimeout(()=>{l.kill(),m(()=>r(new Error(`${t} timed out after ${f} minutes.
671
821
  `+(d?`Stderr: ${d.slice(0,500)}
672
- `:"")+`Partial output (${c.length} chars): ${c.slice(0,500)}`)))},y);l.on("close",()=>clearTimeout(b))})}async function ka(e,t,n,s,o,i){let a=ce(),r=P(),l=v().modules.length>0,c=Ut(),d=xn(a,t,l,c.pageType,c.brandAssets);d+=`
822
+ `:"")+`Partial output (${c.length} chars): ${c.slice(0,500)}`)))},h);l.on("close",()=>clearTimeout(b))})}async function bc(t,e,n,s,o,i){let r=fe(),a=O(),l=C().modules.length>0,c=bn(),d=ss(r,e,l,c.pageType,c.brandAssets);d+=`
673
823
 
674
824
  ## User Request
675
- `+e,d+=vn(),d+=ya(i),d+="\n\n---\nRemember: respond with a ```vibespot-modules JSON block containing ALL modules. No text-only responses.";let u=["--print"];r.claudeCodeModel&&u.push("--model",r.claudeCodeModel),r.webSearch&&u.push("--allowedTools=WebSearch"),u.push("--output-format","stream-json","--include-partial-messages","--verbose");let m=0,g=s||(()=>{});g(ye[0]);let y=setInterval(()=>{m++;let h=ye[Math.min(m,ye.length-1)];g(h)},6e3);try{let h=await Uo(u,d,{onChunk:b=>n(b),onToolUse:(b,x)=>{g(Uu(b,x))}});o&&o(h)}finally{clearInterval(y)}}function Uu(e,t){let n=t||{};switch(e){case"WebSearch":case"web_search":return`Searching: "${String(n.query||"")}"`;case"WebFetch":return`Fetching: ${String(n.url||"")}`;case"Read":return`Reading ${String(n.file_path||n.path||"file")}`;case"Edit":case"Write":return`Editing ${String(n.file_path||n.path||"file")}`;case"Bash":return`Running: ${String(n.command||"").slice(0,60)}`;case"Grep":return`Searching for "${String(n.pattern||"")}"`;case"Glob":return`Globbing ${String(n.pattern||"")}`;default:return`Using ${e}`}}async function Wo(e,t,n,s,o,i,a){let r=ce(),l=v().modules.length>0,c=Ut(),d=xn(r,n,l,c.pageType,c.brandAssets);d+=`
825
+ `+t,d+=os(),d+=uc(i),d+="\n\n---\nRemember: respond with a ```vibespot-modules JSON block containing ALL modules. No text-only responses.";let u=["--print"];a.claudeCodeModel&&u.push("--model",a.claudeCodeModel),a.webSearch&&u.push("--allowedTools=WebSearch"),u.push("--output-format","stream-json","--include-partial-messages","--verbose");let m=0,g=s||(()=>{});g(Re[0]);let h=setInterval(()=>{m++;let f=Re[Math.min(m,Re.length-1)];g(f)},6e3);try{let f=await Qi(u,d,{onChunk:b=>n(b),onToolUse:(b,S)=>{g(If(b,S))}});o&&o(f)}finally{clearInterval(h)}}function If(t,e){let n=e||{};switch(t){case"WebSearch":case"web_search":return`Searching: "${String(n.query||"")}"`;case"WebFetch":return`Fetching: ${String(n.url||"")}`;case"Read":return`Reading ${String(n.file_path||n.path||"file")}`;case"Edit":case"Write":return`Editing ${String(n.file_path||n.path||"file")}`;case"Bash":return`Running: ${String(n.command||"").slice(0,60)}`;case"Grep":return`Searching for "${String(n.pattern||"")}"`;case"Glob":return`Globbing ${String(n.pattern||"")}`;default:return`Using ${t}`}}async function tr(t,e,n,s,o,i,r){let a=fe(),l=C().modules.length>0,c=bn(),d=ss(a,n,l,c.pageType,c.brandAssets);d+=`
676
826
 
677
827
  ## User Request
678
- `+t,d+=vn(),d+=ya(a),d+="\n\n---\nRemember: respond with a ```vibespot-modules JSON block containing ALL modules. No text-only responses.";let u,m;e==="gemini"?(u="gemini",m=[]):(u="codex",m=["exec","--full-auto"]);let g=0,y=o||(()=>{});y(ye[0]);let h=setInterval(()=>{g++;let b=ye[Math.min(g,ye.length-1)];y(b)},6e3);try{let b=await Go(u,m,d,x=>{s(x)});i&&i(b)}finally{clearInterval(h)}}var Lo,ye,Bo,Vo=L(()=>{"use strict";f();ot();Q();tt();pe();ga();ie();Lo=null;ye=["Analyzing your request...","Reading the conversion guide...","Planning module structure...","Generating HTML templates...","Writing CSS styles...","Creating field definitions...","Building module metadata...","Assembling theme assets...","Polishing the output...","Almost there \u2014 hang tight..."],Bo=[10,20,40,60,120]});function p(e,t,n){e.writeHead(t,{"Content-Type":"application/json"}),e.end(JSON.stringify(n))}function B(e,t){let n=[];e.on("data",s=>n.push(s)),e.on("end",()=>t(Buffer.concat(n).toString("utf-8")))}function Ye(e,t,n){B(e,s=>{try{n(JSON.parse(s||"{}"))}catch{p(t,400,{error:"Invalid JSON in request body"})}})}var Fe=L(()=>{"use strict";f()});import{createWriteStream as Gu,mkdirSync as Aa,existsSync as Ko,readFileSync as zo}from"fs";import{join as Ct,extname as Wu}from"path";import{randomUUID as Vu}from"crypto";import Ku from"busboy";function Xu(e,t){if(Ta.has(t))return t;let n=e.slice(e.lastIndexOf(".")).toLowerCase();return qu[n]??t}function Zu(e){return e.replace(/[^a-zA-Z0-9._-]/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").toLowerCase()}function Qu(e,t){if(!Ko(Ct(e,t)))return t;let n=Wu(t),s=t.slice(0,-n.length||void 0),o=1;for(;Ko(Ct(e,`${s}-${o}${n}`));)o++;return`${s}-${o}${n}`}async function em(e){let t=(await import("pdf-parse")).default,n=zo(e);return(await t(n)).text}async function tm(e){return(await(await import("mammoth")).extractRawText({path:e})).value}function nm(e){return zo(e,"utf-8")}function Ia(e,t){let n=v();if(!n){p(t,400,{error:"No active session"});return}if(!(e.headers["content-type"]||"").includes("multipart/form-data")){p(t,400,{error:"Expected multipart/form-data"});return}let o=[],i=[],a=0,r=[],l=Ku({headers:e.headers,limits:{fileSize:zu,files:10}});l.on("file",(c,d,u)=>{let{filename:m,mimeType:g}=u;a++;let y=Xu(m,g);if(!Ta.has(y)){i.push(`Unsupported file type: ${m} (${g})`),d.resume();return}let h=$a.has(y),b=Zu(m),x=Vu(),w,S;h?(w=Ct(n.themePath,"assets"),Aa(w,{recursive:!0}),S=Qu(w,b)):(w=Ct(n.themePath,".vibespot","uploads"),Aa(w,{recursive:!0}),S=`${x}-${b}`);let M=Ct(w,S),O=Gu(M),R=0,H=!1;d.on("data",z=>{R+=z.length}),d.on("limit",()=>{H=!0,i.push(`File too large (>10MB): ${m}`)}),d.pipe(O),r.push(new Promise(z=>{O.on("finish",()=>{if(!H){let _={id:x,filename:S,originalName:m,type:h?"image":"document",usage:h?"asset":"context",mimeType:y,size:R,addedAt:new Date().toISOString()};o.push(_),Dr(_)}z()}),O.on("error",()=>{i.push(`Failed to write: ${m}`),z()})}))}),l.on("finish",async()=>{await Promise.all(r);for(let c of o)if(c.type==="document"){let d=Ct(n.themePath,".vibespot","uploads",c.filename);try{c.mimeType==="application/pdf"?c.extractedText=await em(d):c.mimeType==="application/vnd.openxmlformats-officedocument.wordprocessingml.document"?c.extractedText=await tm(d):c.extractedText=nm(d),A.info("upload",`Extracted text from ${c.originalName} (${c.extractedText.length} chars)`)}catch(u){A.warn("upload",`Failed to extract text from ${c.originalName}: ${u}`),c.extractedText=`[Could not extract text from ${c.originalName}]`}}if(a===0){p(t,400,{error:"No files uploaded"});return}p(t,200,{files:o.map(c=>({id:c.id,filename:c.filename,originalName:c.originalName,type:c.type,usage:c.usage,size:c.size})),errors:i.length>0?i:void 0})}),l.on("error",c=>{A.error("upload",`Busboy error: ${c}`),p(t,500,{error:"Upload failed"})}),e.pipe(l)}function $s(e){let t=v();return t?.assets?e.map(n=>{let s=t.assets.find(i=>i.id===n);if(!s)return null;let o={id:s.id,filename:s.filename,originalName:s.originalName,type:s.type,usage:s.usage,mimeType:s.mimeType};if(s.type==="image"){let i=Ct(t.themePath,"assets",s.filename);Ko(i)&&(o.base64=zo(i).toString("base64")),o.assetPath=`${t.themeName}/assets/${s.filename}`}else s.type==="document"&&(o.extractedText=s.extractedText);return o}).filter(n=>n!==null):[]}var zu,$a,Yu,Ta,qu,Yo=L(()=>{"use strict";f();Fe();pe();ie();zu=10*1024*1024,$a=new Set(["image/png","image/jpeg","image/jpg","image/svg+xml","image/webp","image/gif"]),Yu=new Set(["application/pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/markdown","text/plain"]),Ta=new Set([...$a,...Yu]),qu={".md":"text/markdown",".txt":"text/plain",".markdown":"text/markdown"}});var Pa={};ke(Pa,{callAgent:()=>Ce,callAgentAPI:()=>Na,isAgenticCapable:()=>Cn,isCLIEngine:()=>Gt,resolveThinkingBudget:()=>Qo});async function Ts(e,t){for(let n=0;;n++)try{return await e()}catch(s){let o=s.status,i=s.error?.type;if(!(o===429||i==="rate_limit_error"||s instanceof Error&&s.message.includes("429"))||n>=qo.length)throw s;let r=qo[n];A.warn("agent-adapter",`Rate limited (429), attempt ${n+1}/${qo.length} \u2014 waiting ${r}s`),t&&t(`Rate limited \u2014 retrying in ${r}s...`),await new Promise(l=>setTimeout(l,r*1e3)),t&&t("Retrying...")}}function wn(e){if(e&&typeof e=="object"&&!Array.isArray(e)){let t=e;for(let n of["fieldsJson","metaJson"])t[n]&&typeof t[n]=="object"&&(t[n]=JSON.stringify(t[n]))}return e}async function Ea(){return Xo||(Xo=(await import("@anthropic-ai/sdk")).default),Xo}async function sm(e,t,n,s,o){let i=await Ea(),a=new i({apiKey:e,...s?{defaultHeaders:s}:{}}),r=n.messages,l=n.systemPrompt;if(n.systemBlocks?l=o?[{type:"text",text:o},...n.systemBlocks]:n.systemBlocks:o&&(l=[{type:"text",text:o},{type:"text",text:n.systemPrompt}]),n.structuredOutput){let c={name:n.structuredOutput.name,description:`Return the result as structured JSON matching the ${n.structuredOutput.name} schema.`,input_schema:n.structuredOutput.schema,cache_control:{type:"ephemeral"}};return Ts(async()=>{let d=await a.messages.create({model:t,max_tokens:n.maxTokens||16e3,system:l,messages:r,tools:[c],tool_choice:{type:"tool",name:n.structuredOutput.name},...n.thinkingBudgetTokens?{thinking:{type:"enabled",budget_tokens:n.thinkingBudgetTokens}}:{}});for(let m of d.content)if(m.type==="tool_use")return{type:"structured",data:wn(m.input)};return{type:"text",text:d.content.filter(m=>m.type==="text").map(m=>m.text).join("")}},n.onStatus)}return Ts(async()=>{let c="",d=a.messages.stream({model:t,max_tokens:n.maxTokens||16e3,system:l,messages:r,...n.enableWebSearch?{tools:[{type:"web_search_20250305",name:"web_search"}]}:{},...n.thinkingBudgetTokens?{thinking:{type:"enabled",budget_tokens:n.thinkingBudgetTokens}}:{}});for await(let u of d)u.type==="content_block_delta"&&u.delta.type==="text_delta"&&(c+=u.delta.text,n.onChunk&&n.onChunk(u.delta.text));return{type:"text",text:c}},n.onStatus)}async function om(e,t,n){let s=await Ea(),o=new s({authToken:e,defaultHeaders:Zt}),i=n.messages,a;if(n.systemBlocks?a=[{type:"text",text:Mt},...n.systemBlocks]:a=[{type:"text",text:Mt},{type:"text",text:n.systemPrompt}],n.structuredOutput){let r={name:n.structuredOutput.name,description:`Return the result as structured JSON matching the ${n.structuredOutput.name} schema.`,input_schema:n.structuredOutput.schema,cache_control:{type:"ephemeral"}};return Ts(async()=>{let l=await o.messages.create({model:t,max_tokens:n.maxTokens||16e3,system:a,messages:i,tools:[r],tool_choice:{type:"tool",name:n.structuredOutput.name},...n.thinkingBudgetTokens?{thinking:{type:"enabled",budget_tokens:n.thinkingBudgetTokens}}:{}});for(let d of l.content)if(d.type==="tool_use")return{type:"structured",data:wn(d.input)};return{type:"text",text:l.content.filter(d=>d.type==="text").map(d=>d.text).join("")}},n.onStatus)}return Ts(async()=>{let r="",l=o.messages.stream({model:t,max_tokens:n.maxTokens||16e3,system:a,messages:i,...n.enableWebSearch?{tools:[{type:"web_search_20250305",name:"web_search"}]}:{},...n.thinkingBudgetTokens?{thinking:{type:"enabled",budget_tokens:n.thinkingBudgetTokens}}:{}});for await(let c of l)c.type==="content_block_delta"&&c.delta.type==="text_delta"&&(r+=c.delta.text,n.onChunk&&n.onChunk(c.delta.text));return{type:"text",text:r}},n.onStatus)}function Zo(e){let t={...e};if(t.type==="object"&&(t.additionalProperties=!1,t.properties&&typeof t.properties=="object")){let n={};for(let[s,o]of Object.entries(t.properties))n[s]=o&&typeof o=="object"?Zo(o):o;t.properties=n}return t.items&&typeof t.items=="object"&&(t.items=Zo(t.items)),t}async function im(e,t,n){let s=[{role:"system",content:n.systemPrompt},...n.messages.map(l=>({role:l.role,content:typeof l.content=="string"?l.content:l.content.map(c=>({type:"text",text:c.text}))}))],o={model:t,max_tokens:n.maxTokens||16e3,messages:s};n.structuredOutput&&(o.response_format={type:"json_schema",json_schema:{name:n.structuredOutput.name,strict:!0,schema:Zo(n.structuredOutput.schema)}});let i=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(o)});if(!i.ok){let l=await i.text(),c=i.status;if(c===429){let d=new Error(`OpenAI rate limit: ${l}`);throw d.status=429,d}throw new Error(`OpenAI API error (${c}): ${l}`)}let r=(await i.json()).choices?.[0]?.message?.content||"";if(n.structuredOutput)try{return{type:"structured",data:wn(JSON.parse(r))}}catch{return A.warn("agent-adapter","OpenAI structured output parse failed, returning raw text"),{type:"text",text:r}}return{type:"text",text:r}}async function rm(e,t,n){let s=t||"gemini-2.5-flash",o=n.messages.map(d=>({role:d.role==="assistant"?"model":"user",parts:typeof d.content=="string"?[{text:d.content}]:d.content.map(u=>({text:u.text}))})),i={systemInstruction:{parts:[{text:n.systemPrompt}]},contents:o,generationConfig:{maxOutputTokens:n.maxTokens||16e3,...n.structuredOutput?{responseMimeType:"application/json",responseSchema:n.structuredOutput.schema}:{}}},a=`https://generativelanguage.googleapis.com/v1beta/models/${s}:generateContent?key=${e}`,r=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok){let d=await r.text(),u=r.status;if(u===429){let m=new Error(`Gemini rate limit: ${d}`);throw m.status=429,m}throw new Error(`Gemini API error (${u}): ${d}`)}let c=(await r.json()).candidates?.[0]?.content?.parts?.[0]?.text||"";if(n.structuredOutput)try{return{type:"structured",data:wn(JSON.parse(c))}}catch{return A.warn("agent-adapter","Gemini structured output parse failed, returning raw text"),{type:"text",text:c}}return{type:"text",text:c}}function am(e,t){switch(e){case"claude-code":{let n=P(),s=["--print"];return n.claudeCodeModel&&s.push("--model",n.claudeCodeModel),t?.enableWebSearch&&s.push("--allowedTools=WebSearch"),{bin:"claude",args:s}}case"gemini-cli":return{bin:"gemini",args:[]};case"codex-cli":return{bin:"codex",args:["exec","--full-auto"]};default:throw new Error(`Not a CLI engine: ${e}`)}}function lm(e){let t=[e.systemPrompt];for(let n of e.messages){let s=n.role==="user"?"User":"Assistant",o=typeof n.content=="string"?n.content:n.content.map(i=>i.text).join(`
679
- `);t.push(`
828
+ `+e,d+=os(),d+=uc(r),d+="\n\n---\nRemember: respond with a ```vibespot-modules JSON block containing ALL modules. No text-only responses.";let u,m;t==="gemini"?(u="gemini",m=[]):(u="codex",m=["exec","--full-auto"]);let g=0,h=o||(()=>{});h(Re[0]);let f=setInterval(()=>{g++;let b=Re[Math.min(g,Re.length-1)];h(b)},6e3);try{let b=await er(u,m,d,S=>{s(S)});i&&i(b)}finally{clearInterval(f)}}var Xi,Re,Zi,nr=R(()=>{"use strict";y();Ue();Q();xt();we();lc();de();Xi=null;Re=["Analyzing your request...","Reading the conversion guide...","Planning module structure...","Generating HTML templates...","Writing CSS styles...","Creating field definitions...","Building module metadata...","Assembling theme assets...","Polishing the output...","Almost there \u2014 hang tight..."],Zi=[10,20,40,60,120]});function p(t,e,n){t.writeHead(e,{"Content-Type":"application/json"}),t.end(JSON.stringify(n))}function W(t,e){let n=[];t.on("data",s=>n.push(s)),t.on("end",()=>e(Buffer.concat(n).toString("utf-8")))}function Ve(t,e,n){W(t,s=>{try{n(JSON.parse(s||"{}"))}catch{p(e,400,{error:"Invalid JSON in request body"})}})}var ze=R(()=>{"use strict";y()});import{createWriteStream as Pf,mkdirSync as Sc,existsSync as sr,readFileSync as or}from"fs";import{join as Vt,extname as Rf}from"path";import{randomUUID as Nf}from"crypto";import Of from"busboy";function Lf(t,e){if(vc.has(e))return e;let n=t.slice(t.lastIndexOf(".")).toLowerCase();return Df[n]??e}function Jf(t){return t.replace(/[^a-zA-Z0-9._-]/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").toLowerCase()}function Bf(t,e){if(!sr(Vt(t,e)))return e;let n=Rf(e),s=e.slice(0,-n.length||void 0),o=1;for(;sr(Vt(t,`${s}-${o}${n}`));)o++;return`${s}-${o}${n}`}async function Hf(t){let e=(await import("pdf-parse")).default,n=or(t);return(await e(n)).text}async function Uf(t){return(await(await import("mammoth")).extractRawText({path:t})).value}function Gf(t){return or(t,"utf-8")}function wc(t,e){let n=C();if(!n){p(e,400,{error:"No active session"});return}if(!(t.headers["content-type"]||"").includes("multipart/form-data")){p(e,400,{error:"Expected multipart/form-data"});return}let o=[],i=[],r=0,a=[],l=Of({headers:t.headers,limits:{fileSize:Ff,files:10}});l.on("file",(c,d,u)=>{let{filename:m,mimeType:g}=u;r++;let h=Lf(m,g);if(!vc.has(h)){i.push(`Unsupported file type: ${m} (${g})`),d.resume();return}let f=xc.has(h),b=Jf(m),S=Nf(),x,w;f?(x=Vt(n.themePath,"assets"),Sc(x,{recursive:!0}),w=Bf(x,b)):(x=Vt(n.themePath,".vibespot","uploads"),Sc(x,{recursive:!0}),w=`${S}-${b}`);let P=Vt(x,w),F=Pf(P),H=0,L=!1;d.on("data",V=>{H+=V.length}),d.on("limit",()=>{L=!0,i.push(`File too large (>10MB): ${m}`)}),d.pipe(F),a.push(new Promise(V=>{F.on("finish",()=>{if(!L){let B={id:S,filename:w,originalName:m,type:f?"image":"document",usage:f?"asset":"context",mimeType:h,size:H,addedAt:new Date().toISOString()};o.push(B),vl(B)}V()}),F.on("error",()=>{i.push(`Failed to write: ${m}`),V()})}))}),l.on("finish",async()=>{await Promise.all(a);for(let c of o)if(c.type==="document"){let d=Vt(n.themePath,".vibespot","uploads",c.filename);try{c.mimeType==="application/pdf"?c.extractedText=await Hf(d):c.mimeType==="application/vnd.openxmlformats-officedocument.wordprocessingml.document"?c.extractedText=await Uf(d):c.extractedText=Gf(d),E.info("upload",`Extracted text from ${c.originalName} (${c.extractedText.length} chars)`)}catch(u){E.warn("upload",`Failed to extract text from ${c.originalName}: ${u}`),c.extractedText=`[Could not extract text from ${c.originalName}]`}}if(r===0){p(e,400,{error:"No files uploaded"});return}p(e,200,{files:o.map(c=>({id:c.id,filename:c.filename,originalName:c.originalName,type:c.type,usage:c.usage,size:c.size})),errors:i.length>0?i:void 0})}),l.on("error",c=>{E.error("upload",`Busboy error: ${c}`),p(e,500,{error:"Upload failed"})}),t.pipe(l)}function Co(t){let e=C();return e?.assets?t.map(n=>{let s=e.assets.find(i=>i.id===n);if(!s)return null;let o={id:s.id,filename:s.filename,originalName:s.originalName,type:s.type,usage:s.usage,mimeType:s.mimeType};if(s.type==="image"){let i=Vt(e.themePath,"assets",s.filename);sr(i)&&(o.base64=or(i).toString("base64")),o.assetPath=`${e.themeName}/assets/${s.filename}`}else s.type==="document"&&(o.extractedText=s.extractedText);return o}).filter(n=>n!==null):[]}var Ff,xc,jf,vc,Df,ir=R(()=>{"use strict";y();ze();we();de();Ff=10*1024*1024,xc=new Set(["image/png","image/jpeg","image/jpg","image/svg+xml","image/webp","image/gif"]),jf=new Set(["application/pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/markdown","text/plain"]),vc=new Set([...xc,...jf]),Df={".md":"text/markdown",".txt":"text/plain",".markdown":"text/markdown"}});var Ac={};Be(Ac,{callAgent:()=>_e,callAgentAPI:()=>Tc,isAgenticCapable:()=>rs,isCLIEngine:()=>xn,resolveThinkingBudget:()=>Sn});async function ko(t,e){for(let n=0;;n++)try{return await t()}catch(s){let o=s.status,i=s.error?.type;if(!(o===429||i==="rate_limit_error"||s instanceof Error&&s.message.includes("429"))||n>=rr.length)throw s;let a=rr[n];E.warn("agent-adapter",`Rate limited (429), attempt ${n+1}/${rr.length} \u2014 waiting ${a}s`),e&&e(`Rate limited \u2014 retrying in ${a}s...`),await new Promise(l=>setTimeout(l,a*1e3)),e&&e("Retrying...")}}function is(t){if(t&&typeof t=="object"&&!Array.isArray(t)){let e=t;for(let n of["fieldsJson","metaJson"])e[n]&&typeof e[n]=="object"&&(e[n]=JSON.stringify(e[n]))}return t}async function Cc(){return ar||(ar=(await import("@anthropic-ai/sdk")).default),ar}async function Wf(t,e,n,s,o){let i=await Cc(),r=new i({apiKey:t,...s?{defaultHeaders:s}:{}}),a=n.messages,l=n.systemPrompt;if(n.systemBlocks?l=o?[{type:"text",text:o},...n.systemBlocks]:n.systemBlocks:o&&(l=[{type:"text",text:o},{type:"text",text:n.systemPrompt}]),n.structuredOutput){let c={name:n.structuredOutput.name,description:`Return the result as structured JSON matching the ${n.structuredOutput.name} schema.`,input_schema:n.structuredOutput.schema,cache_control:{type:"ephemeral"}};return ko(async()=>{let d=await r.messages.create({model:e,max_tokens:n.maxTokens||16e3,system:l,messages:a,tools:[c],tool_choice:{type:"tool",name:n.structuredOutput.name},...n.thinkingBudgetTokens?{thinking:{type:"enabled",budget_tokens:n.thinkingBudgetTokens}}:{}});for(let m of d.content)if(m.type==="tool_use")return{type:"structured",data:is(m.input)};return{type:"text",text:d.content.filter(m=>m.type==="text").map(m=>m.text).join("")}},n.onStatus)}return ko(async()=>{let c="",d=r.messages.stream({model:e,max_tokens:n.maxTokens||16e3,system:l,messages:a,...n.enableWebSearch?{tools:[{type:"web_search_20250305",name:"web_search"}]}:{},...n.thinkingBudgetTokens?{thinking:{type:"enabled",budget_tokens:n.thinkingBudgetTokens}}:{}});for await(let u of d)u.type==="content_block_delta"&&u.delta.type==="text_delta"&&(c+=u.delta.text,n.onChunk&&n.onChunk(u.delta.text));return{type:"text",text:c}},n.onStatus)}async function Kf(t,e,n){let s=await Cc(),o=new s({authToken:t,defaultHeaders:_n}),i=n.messages,r;if(n.systemBlocks?r=[{type:"text",text:rn},...n.systemBlocks]:r=[{type:"text",text:rn},{type:"text",text:n.systemPrompt}],n.structuredOutput){let a={name:n.structuredOutput.name,description:`Return the result as structured JSON matching the ${n.structuredOutput.name} schema.`,input_schema:n.structuredOutput.schema,cache_control:{type:"ephemeral"}};return ko(async()=>{let l=await o.messages.create({model:e,max_tokens:n.maxTokens||16e3,system:r,messages:i,tools:[a],tool_choice:{type:"tool",name:n.structuredOutput.name},...n.thinkingBudgetTokens?{thinking:{type:"enabled",budget_tokens:n.thinkingBudgetTokens}}:{}});for(let d of l.content)if(d.type==="tool_use")return{type:"structured",data:is(d.input)};return{type:"text",text:l.content.filter(d=>d.type==="text").map(d=>d.text).join("")}},n.onStatus)}return ko(async()=>{let a="",l=o.messages.stream({model:e,max_tokens:n.maxTokens||16e3,system:r,messages:i,...n.enableWebSearch?{tools:[{type:"web_search_20250305",name:"web_search"}]}:{},...n.thinkingBudgetTokens?{thinking:{type:"enabled",budget_tokens:n.thinkingBudgetTokens}}:{}});for await(let c of l)c.type==="content_block_delta"&&c.delta.type==="text_delta"&&(a+=c.delta.text,n.onChunk&&n.onChunk(c.delta.text));return{type:"text",text:a}},n.onStatus)}function lr(t){let e={...t};if(e.type==="object"&&(e.additionalProperties=!1,e.properties&&typeof e.properties=="object")){let n={};for(let[s,o]of Object.entries(e.properties))n[s]=o&&typeof o=="object"?lr(o):o;e.properties=n}return e.items&&typeof e.items=="object"&&(e.items=lr(e.items)),e}async function Vf(t,e,n){let s=[{role:"system",content:n.systemPrompt},...n.messages.map(l=>({role:l.role,content:typeof l.content=="string"?l.content:l.content.map(c=>({type:"text",text:c.text}))}))],o={model:e,max_tokens:n.maxTokens||16e3,messages:s};n.structuredOutput&&(o.response_format={type:"json_schema",json_schema:{name:n.structuredOutput.name,strict:!0,schema:lr(n.structuredOutput.schema)}});let i=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(o)});if(!i.ok){let l=await i.text(),c=i.status;if(c===429){let d=new Error(`OpenAI rate limit: ${l}`);throw d.status=429,d}throw new Error(`OpenAI API error (${c}): ${l}`)}let a=(await i.json()).choices?.[0]?.message?.content||"";if(n.structuredOutput)try{return{type:"structured",data:is(JSON.parse(a))}}catch{return E.warn("agent-adapter","OpenAI structured output parse failed, returning raw text"),{type:"text",text:a}}return{type:"text",text:a}}async function zf(t,e,n){let s=e||"gemini-2.5-flash",o=n.messages.map(d=>({role:d.role==="assistant"?"model":"user",parts:typeof d.content=="string"?[{text:d.content}]:d.content.map(u=>({text:u.text}))})),i={systemInstruction:{parts:[{text:n.systemPrompt}]},contents:o,generationConfig:{maxOutputTokens:n.maxTokens||16e3,...n.structuredOutput?{responseMimeType:"application/json",responseSchema:n.structuredOutput.schema}:{}}},r=`https://generativelanguage.googleapis.com/v1beta/models/${s}:generateContent?key=${t}`,a=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!a.ok){let d=await a.text(),u=a.status;if(u===429){let m=new Error(`Gemini rate limit: ${d}`);throw m.status=429,m}throw new Error(`Gemini API error (${u}): ${d}`)}let c=(await a.json()).candidates?.[0]?.content?.parts?.[0]?.text||"";if(n.structuredOutput)try{return{type:"structured",data:is(JSON.parse(c))}}catch{return E.warn("agent-adapter","Gemini structured output parse failed, returning raw text"),{type:"text",text:c}}return{type:"text",text:c}}function Yf(t,e,n){switch(t){case"claude-code":{let s=["--print"];return e&&s.push("--model",e),n?.enableWebSearch&&s.push("--allowedTools=WebSearch"),{bin:"claude",args:s}}case"gemini-cli":{let s=[];return e&&s.push("-m",e),{bin:"gemini",args:s}}case"codex-cli":{let s=["exec","--full-auto"];return e&&s.push("-m",e),{bin:"codex",args:s}}default:throw new Error(`Not a CLI engine: ${t}`)}}function qf(t){let e=[t.systemPrompt];for(let n of t.messages){let s=n.role==="user"?"User":"Assistant",o=typeof n.content=="string"?n.content:n.content.map(i=>i.text).join(`
829
+ `);e.push(`
680
830
 
681
831
  ## ${s}
682
- ${o}`)}if(e.structuredOutput){let n=_a(e.structuredOutput.schema);t.push(`
832
+ ${o}`)}if(t.structuredOutput){let n=kc(t.structuredOutput.schema);e.push(`
683
833
 
684
834
  ## Output Format \u2014 CRITICAL
685
835
  Respond with a JSON code block. Wrap your JSON in \`\`\`json fences. No prose or explanation before or after the code block.
686
836
 
687
837
  The JSON must match this structure:
688
- ${n}`)}return t.join("")}function _a(e,t=0){let n=" ".repeat(t),s=e.properties,o=e.required||[];if(!s)return`${n}${JSON.stringify(e)}`;let i=["{"];for(let[a,r]of Object.entries(s)){let l=o.includes(a)?" (required)":"",c=r.type||"any",d=r.description?` \u2014 ${r.description}`:"",u=r.enum?` [${r.enum.join(", ")}]`:"";if(c==="array"&&r.items){let m=r.items.type||"object";i.push(`${n} "${a}": ${c}<${m}>${l}${d}${u}`)}else c==="object"&&r.properties?i.push(`${n} "${a}": ${_a(r,t+1)}${l}${d}`):i.push(`${n} "${a}": ${c}${l}${d}${u}`)}return i.push(`${n}}`),i.join(`
689
- `)}function cm(e){let t=e.trim(),n=ze(t);if(n&&typeof n=="object")return n;let s=t.match(/```(?:json|vibespot-modules)?\s*\n([\s\S]*?)```/i);if(s){let r=s[1].trim(),l=ze(r);if(l&&typeof l=="object")return l;let c=Sn(r);if(c&&typeof c=="object")return c}let o=t.indexOf("{"),i=t.lastIndexOf("}");if(o!==-1&&i>o){let r=t.slice(o,i+1),l=ze(r);if(l&&typeof l=="object")return l;let c=Sn(r);if(c&&typeof c=="object")return c}let a=Sn(t);return a&&typeof a=="object"?a:null}async function dm(e,t,n){let{bin:s,args:o}=am(e,n),i=lm(n),a;if(e==="claude-code"){let l=[...o,"--output-format","stream-json","--include-partial-messages","--verbose"];a=await Uo(l,i,{onChunk:n.onChunk,onToolUse:(c,d)=>{if(!n.onStatus)return;let u=um(c,d);n.onStatus(u)}})}else a=await Go(s,o,i,n.onChunk);if(!n.structuredOutput)return{type:"text",text:a};let r=cm(a);return r?{type:"structured",data:wn(r)}:(A.warn("agent-cli",`${e}: failed to parse structured output, returning text`,{outputPreview:a.slice(0,500),outputLength:a.length}),{type:"text",text:a})}function um(e,t){let n=t||{};switch(e){case"WebSearch":case"web_search":return`Searching: "${String(n.query||"")}"`;case"WebFetch":return`Fetching: ${String(n.url||"")}`;case"Read":return`Reading ${String(n.file_path||n.path||"file")}`;case"Edit":case"Write":return`Editing ${String(n.file_path||n.path||"file")}`;case"Bash":return`Running: ${String(n.command||"").slice(0,60)}`;case"Grep":return`Searching for "${String(n.pattern||"")}"`;case"Glob":return`Globbing ${String(n.pattern||"")}`;default:return`Using ${e}`}}async function Na(e,t,n,s){switch(A.info("agent-adapter",`${e} API call`,{model:n,structured:!!s.structuredOutput,schemaName:s.structuredOutput?.name,systemPromptLength:s.systemPrompt.length,messageCount:s.messages.length}),e){case"anthropic-api":return sm(t,n,s);case"claude-oauth":{let{getValidAccessToken:o}=await Promise.resolve().then(()=>(tt(),so)),i=await o();if(!i)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");return om(i,n,s)}case"openai-api":return im(t,n,s);case"gemini-api":return rm(t,n,s);default:throw new Error(`Unsupported API engine: ${e}`)}}async function Ce(e,t,n,s){return mm.has(e)?Na(e,t,n,s):(A.info("agent-adapter",`${e} CLI call`,{structured:!!s.structuredOutput,schemaName:s.structuredOutput?.name,systemPromptLength:s.systemPrompt.length,messageCount:s.messages.length}),dm(e,n,s))}function Qo(e){if(e!=="anthropic-api"&&e!=="claude-oauth")return 0;let t=P();if(!t.extendedThinking)return 0;switch(t.extendedThinkingBudget){case"high":return 32e3;case"low":return 4e3;default:return 16e3}}function Cn(e){return e==="anthropic-api"||e==="claude-oauth"||e==="openai-api"||e==="gemini-api"||e==="claude-code"||e==="gemini-cli"||e==="codex-cli"}function Gt(e){return e==="claude-code"||e==="gemini-cli"||e==="codex-cli"}var qo,Xo,mm,qe=L(()=>{"use strict";f();Vo();As();Q();tt();ie();qo=[10,20,40,60,120];Xo=null;mm=new Set(["anthropic-api","claude-oauth","openai-api","gemini-api"])});function Ma(e,t,n,s){let o=t.length>0?`Current template modules (in page order):
690
- ${t.map((r,l)=>`${l+1}. ${r}`).join(`
691
- `)}`:"No modules yet (new page).",i=n.length>0?`
838
+ ${n}`)}return e.join("")}function kc(t,e=0){let n=" ".repeat(e),s=t.properties,o=t.required||[];if(!s)return`${n}${JSON.stringify(t)}`;let i=["{"];for(let[r,a]of Object.entries(s)){let l=o.includes(r)?" (required)":"",c=a.type||"any",d=a.description?` \u2014 ${a.description}`:"",u=a.enum?` [${a.enum.join(", ")}]`:"";if(c==="array"&&a.items){let m=a.items.type||"object";i.push(`${n} "${r}": ${c}<${m}>${l}${d}${u}`)}else c==="object"&&a.properties?i.push(`${n} "${r}": ${kc(a,e+1)}${l}${d}`):i.push(`${n} "${r}": ${c}${l}${d}${u}`)}return i.push(`${n}}`),i.join(`
839
+ `)}function Xf(t){let e=t.trim(),n=ft(e);if(n&&typeof n=="object")return n;let s=e.match(/```(?:json|vibespot-modules)?\s*\n([\s\S]*?)```/i);if(s){let a=s[1].trim(),l=ft(a);if(l&&typeof l=="object")return l;let c=ns(a);if(c&&typeof c=="object")return c}let o=e.indexOf("{"),i=e.lastIndexOf("}");if(o!==-1&&i>o){let a=e.slice(o,i+1),l=ft(a);if(l&&typeof l=="object")return l;let c=ns(a);if(c&&typeof c=="object")return c}let r=ns(e);return r&&typeof r=="object"?r:null}async function Zf(t,e,n){let{bin:s,args:o}=Yf(t,e,n),i=qf(n),r;if(t==="claude-code"){let l=[...o,"--output-format","stream-json","--include-partial-messages","--verbose"];r=await Qi(l,i,{onChunk:n.onChunk,onToolUse:(c,d)=>{if(!n.onStatus)return;let u=Qf(c,d);n.onStatus(u)}})}else r=await er(s,o,i,n.onChunk);if(!n.structuredOutput)return{type:"text",text:r};let a=Xf(r);return a?{type:"structured",data:is(a)}:(E.warn("agent-cli",`${t}: failed to parse structured output, returning text`,{outputPreview:r.slice(0,500),outputLength:r.length}),{type:"text",text:r})}function Qf(t,e){let n=e||{};switch(t){case"WebSearch":case"web_search":return`Searching: "${String(n.query||"")}"`;case"WebFetch":return`Fetching: ${String(n.url||"")}`;case"Read":return`Reading ${String(n.file_path||n.path||"file")}`;case"Edit":case"Write":return`Editing ${String(n.file_path||n.path||"file")}`;case"Bash":return`Running: ${String(n.command||"").slice(0,60)}`;case"Grep":return`Searching for "${String(n.pattern||"")}"`;case"Glob":return`Globbing ${String(n.pattern||"")}`;default:return`Using ${t}`}}async function Tc(t,e,n,s){switch(E.info("agent-adapter",`${t} API call`,{model:n,structured:!!s.structuredOutput,schemaName:s.structuredOutput?.name,systemPromptLength:s.systemPrompt.length,messageCount:s.messages.length}),t){case"anthropic-api":return Wf(e,n,s);case"claude-oauth":{let{getValidAccessToken:o}=await Promise.resolve().then(()=>(xt(),gi)),i=await o();if(!i)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");return Kf(i,n,s)}case"openai-api":return Vf(e,n,s);case"gemini-api":return zf(e,n,s);default:throw new Error(`Unsupported API engine: ${t}`)}}async function _e(t,e,n,s){return eh.has(t)?Tc(t,e,n,s):(E.info("agent-adapter",`${t} CLI call`,{structured:!!s.structuredOutput,schemaName:s.structuredOutput?.name,systemPromptLength:s.systemPrompt.length,messageCount:s.messages.length}),Zf(t,n,s))}function Sn(t){if(t!=="anthropic-api"&&t!=="claude-oauth")return 0;let e=O();if(!e.extendedThinking)return 0;switch(e.extendedThinkingBudget){case"high":return 32e3;case"low":return 4e3;default:return 16e3}}function rs(t){return t==="anthropic-api"||t==="claude-oauth"||t==="openai-api"||t==="gemini-api"||t==="claude-code"||t==="gemini-cli"||t==="codex-cli"}function xn(t){return t==="claude-code"||t==="gemini-cli"||t==="codex-cli"}var rr,ar,eh,nt=R(()=>{"use strict";y();nr();wo();Q();xt();de();rr=[10,20,40,60,120];ar=null;eh=new Set(["anthropic-api","claude-oauth","openai-api","gemini-api"])});function $c(t,e,n,s,o){let i=e.length>0?`Current template modules (in page order):
840
+ ${e.map((c,d)=>`${d+1}. ${c}`).join(`
841
+ `)}`:"No modules yet (new page).",r=n.length>0?`
692
842
 
693
843
  Module library (reusable from other templates):
694
- ${n.map(r=>`- ${r.name} (used in: ${r.usedIn.join(", ")})`).join(`
844
+ ${n.map(c=>`- ${c.name} (used in: ${c.usedIn.join(", ")})`).join(`
695
845
  `)}`:"",a=s?`
696
846
 
697
847
  ## Product Context
698
- ${s}`:"";return`You are the Intent Analyzer for vibeSpot, a HubSpot CMS page builder.
848
+ ${s}`:"",l=o?.pages&&o.pages.length>1?`
849
+
850
+ ## Multi-Page Site Context
851
+ This is a multi-page site. Currently editing: **${o.activePageLabel||"unknown"}**
852
+ All pages:
853
+ ${o.pages.map(c=>`- ${c.label} (${c.id}, ${c.moduleCount} modules)`).join(`
854
+ `)}
855
+
856
+ The user's message applies to the current page unless they reference another page by name or say "all pages" / "every page" / "the whole site".`:"";return`You are the Intent Analyzer for vibeSpot, a HubSpot CMS builder that generates pages, email templates, and blog templates.
699
857
 
700
- Your job: classify the user's request and plan which modules need work. You do NOT generate module code \u2014 you only plan.
858
+ Your job: classify the user's request, determine the content type (page, email, or blog), and plan which modules need work. You do NOT generate module code \u2014 you only plan.
701
859
 
702
- ## Theme: "${e}"
860
+ ## Theme: "${t}"
703
861
 
704
- ${o}${i}${a}
862
+ ${i}${r}${a}${l}
863
+
864
+ ## Content Type Detection
865
+
866
+ Set \`contentType\` based on the user's request:
867
+ - **"page"** (default) \u2014 Landing pages, website pages, any page-type content
868
+ - **"email"** \u2014 Email templates, newsletters, email campaigns, transactional emails
869
+ - **"blog"** \u2014 Blog listing pages, blog post templates, content hubs, article layouts
870
+
871
+ Trigger words for email: "email", "email template", "newsletter", "email campaign", "welcome email", "announcement email", "drip", "email sequence", "email blast", "transactional email".
872
+
873
+ Trigger words for blog: "blog", "blog post", "blog listing", "blog template", "article", "content hub", "blog page", "blog layout", "editorial", "publication", "magazine layout", "posts page".
874
+
875
+ If ambiguous, default to "page". The content type affects downstream pipeline behavior (email uses table-based layout; blog uses HubSpot blog variables and reading-optimized design).
705
876
 
706
877
  ## Classification Rules
707
878
 
708
- 1. **create** \u2014 User wants a new page from scratch (e.g., "build me a landing page for...")
709
- 2. **modify** \u2014 User wants to change existing modules (e.g., "make the hero button red", "update the pricing")
710
- 3. **add** \u2014 User wants new modules added to the existing page (e.g., "add a testimonials section")
711
- 4. **remove** \u2014 User wants modules removed (e.g., "remove the footer")
712
- 5. **rearrange** \u2014 User wants to reorder modules (e.g., "move pricing above features")
713
- 6. **style_change** \u2014 User wants design system changes that affect shared CSS/multiple modules (e.g., "change the color scheme to blue")
714
- 7. **question** \u2014 User is asking a question, not requesting changes (e.g., "what modules do I have?"). Provide the answer directly.
879
+ 1. **create** \u2014 User wants a new single page/email/blog from scratch (e.g., "build me a landing page for...", "create a welcome email", "build a blog for my company")
880
+ 2. **create_site** \u2014 User wants a multi-page website (e.g., "build a website with home, about, and contact pages", "create a 5-page site for..."). Use when the user mentions multiple pages, a website (not just a page), or a site with navigation. Output \`pages\` array with each page's label, purpose, pageType, and slug, plus \`sharedModules\` listing shared module names (e.g., "site-header", "site-footer").
881
+ 3. **modify** \u2014 User wants to change existing modules (e.g., "make the hero button red", "update the pricing")
882
+ 4. **add** \u2014 User wants new modules added to the existing page/email (e.g., "add a testimonials section")
883
+ 5. **remove** \u2014 User wants modules removed (e.g., "remove the footer")
884
+ 6. **rearrange** \u2014 User wants to reorder modules (e.g., "move pricing above features")
885
+ 7. **style_change** \u2014 User wants design system changes that affect shared CSS/multiple modules (e.g., "change the color scheme to blue")
886
+ 8. **question** \u2014 User is asking a question, not requesting changes (e.g., "what modules do I have?"). Provide the answer directly.
887
+
888
+ ## Multi-Page Site Rules (create_site only)
889
+
890
+ When classifying as \`create_site\`:
891
+ - Populate the \`pages\` array with one entry per page. Each page needs: id (kebab-case), label (human-readable), pageType ("landing_page" or "website_page"), purpose (1-sentence), slug (URL path without leading /).
892
+ - Populate \`sharedModules\` with names of modules shared across all pages (typically ["site-header", "site-footer"]).
893
+ - Always include at least a header and footer in sharedModules.
894
+ - Page IDs should be descriptive: "wp-home", "wp-about", "wp-contact", etc.
895
+ - Set \`designSystemChanges: true\` (site creation always needs a design system)
896
+ - If the user says "website" or "site" without specifying pages, infer reasonable pages (e.g., Home, About, Contact)
897
+ - All guides are needed for site creation: design, content, conversion, hubspot_rules, humanify
715
898
 
716
899
  ## Key Rules
717
900
 
@@ -742,11 +925,15 @@ CRITICAL: When the user corrects a misclassification (e.g., "I was referencing t
742
925
  If the user asks for multiple things (e.g., "make hero taller AND add testimonials"), capture ALL parts:
743
926
  - Affected existing modules in \`affectedModules\`
744
927
  - New modules in \`newModules\`
745
- - Set the broadest applicable intent (prefer "modify" + newModules over splitting)`}var Oa,Ra=L(()=>{"use strict";f();Oa={type:"object",properties:{intent:{type:"string",enum:["create","modify","add","remove","rearrange","style_change","question"]},affectedModules:{type:"array",items:{type:"string"},description:"Names of existing modules that need changes"},unchangedModules:{type:"array",items:{type:"string"},description:"Names of existing modules that stay as-is"},newModules:{type:"array",items:{type:"object",properties:{name:{type:"string"},description:{type:"string"},position:{type:"number"}},required:["name","description","position"]},description:"New modules to create"},reuseModules:{type:"array",items:{type:"object",properties:{name:{type:"string"},sourceTemplate:{type:"string"},position:{type:"number"}},required:["name","sourceTemplate","position"]},description:"Modules to copy from the library (immutable structure)"},guidesNeeded:{type:"array",items:{type:"string",enum:["design","content","conversion","hubspot_rules","humanify"]}},designSystemChanges:{type:"boolean",description:"True if shared CSS / design system needs regeneration"},answer:{type:"string",description:'For "question" intent only \u2014 the answer to return directly'}},required:["intent","affectedModules","unchangedModules","newModules","guidesNeeded","designSystemChanges"]}});async function Fa(e,t,n,s,o,i,a){i({type:"agent_step",step:"analyzing",label:"Analyzing your request..."});let r=t.modules.map(g=>g.moduleName),l=Ma(t.themeName,r,a,t.brandAssets?.themeContext),c=[],d=t.messages.slice(-6);for(let g of d)if(g.role==="user"||g.role==="assistant"){let y=g.role==="assistant"&&g.content.length>300?g.content.slice(0,300)+"...":g.content;c.push({role:g.role,content:y})}c.push({role:"user",content:e});let u=await Ce(n,s,o,{systemPrompt:l,messages:c,structuredOutput:{schema:Oa,name:"pipeline_plan"},maxTokens:2e3});if(u.type!=="structured"){A.warn("intent-analyzer","Did not get structured output, falling back");let g=t.modules.length===0;return{intent:g?"create":"modify",affectedModules:g?[]:r,unchangedModules:[],newModules:[],guidesNeeded:["design","content","conversion","hubspot_rules","humanify"],designSystemChanges:g}}let m=u.data;return m.affectedModules=m.affectedModules||[],m.unchangedModules=m.unchangedModules||[],m.newModules=m.newModules||[],m.guidesNeeded=m.guidesNeeded||[],A.info("intent-analyzer","Plan",{intent:m.intent,affected:m.affectedModules.length,unchanged:m.unchangedModules.length,new:m.newModules.length,reuse:m.reuseModules?.length||0,designSystem:m.designSystemChanges}),i({type:"agent_decision",step:"analyzing",decision:pm(m)}),m}function pm(e){let t=[`Intent: ${e.intent}`];return e.affectedModules.length>0&&t.push(`Modifying: ${e.affectedModules.join(", ")}`),e.unchangedModules.length>0&&t.push(`Unchanged: ${e.unchangedModules.join(", ")}`),e.newModules.length>0&&t.push(`New: ${e.newModules.map(n=>n.name).join(", ")}`),e.reuseModules?.length&&t.push(`Reuse: ${e.reuseModules.map(n=>`${n.name} from ${n.sourceTemplate}`).join(", ")}`),e.designSystemChanges&&t.push("Design system changes: yes"),t.join(" | ")}var Ja=L(()=>{"use strict";f();qe();Ra();ie()});function ei(e,t){let n=[];return n.push(`You are the Design System Architect for vibeSpot, a HubSpot CMS page builder.
928
+ - Set the broadest applicable intent (prefer "modify" + newModules over splitting)
929
+
930
+ ## Content Type Detection
931
+
932
+ Set \`contentType\` to "email" when the user explicitly asks for an email template, newsletter, email campaign, welcome email, promotional email, or similar email content. Leave as "page" (default) for landing pages, websites, and web content.`}var _c,Mc=R(()=>{"use strict";y();_c={type:"object",properties:{intent:{type:"string",enum:["create","create_site","modify","add","remove","rearrange","style_change","question"]},contentType:{type:"string",enum:["page","email","blog"],description:'Content type: "page" (default), "email" for email templates, or "blog" for blog templates'},affectedModules:{type:"array",items:{type:"string"},description:"Names of existing modules that need changes"},unchangedModules:{type:"array",items:{type:"string"},description:"Names of existing modules that stay as-is"},newModules:{type:"array",items:{type:"object",properties:{name:{type:"string"},description:{type:"string"},position:{type:"number"}},required:["name","description","position"]},description:"New modules to create"},reuseModules:{type:"array",items:{type:"object",properties:{name:{type:"string"},sourceTemplate:{type:"string"},position:{type:"number"}},required:["name","sourceTemplate","position"]},description:"Modules to copy from the library (immutable structure)"},guidesNeeded:{type:"array",items:{type:"string",enum:["design","content","conversion","hubspot_rules","humanify"]}},designSystemChanges:{type:"boolean",description:"True if shared CSS / design system needs regeneration"},answer:{type:"string",description:'For "question" intent only \u2014 the answer to return directly'},pages:{type:"array",items:{type:"object",properties:{id:{type:"string",description:"Kebab-case page ID (e.g. wp-home)"},label:{type:"string",description:"Human-readable page name"},pageType:{type:"string",enum:["landing_page","website_page","blog_post"]},purpose:{type:"string",description:"One-sentence page purpose"},slug:{type:"string",description:"URL path without leading /"}},required:["id","label","pageType","purpose","slug"]},description:'For "create_site" intent \u2014 list of pages to generate'},sharedModules:{type:"array",items:{type:"string"},description:'For "create_site" intent \u2014 module names shared across all pages (e.g. site-header, site-footer)'}},required:["intent","affectedModules","unchangedModules","newModules","guidesNeeded","designSystemChanges"]}});async function Ec(t,e,n,s,o,i,r){i({type:"agent_step",step:"analyzing",label:"Analyzing your request..."});let a=e.modules.map(g=>g.moduleName),l=$c(e.themeName,a,r,e.brandAssets?.themeContext,e.sitePages?{activePageLabel:e.activePageLabel,pages:e.sitePages}:void 0),c=[],d=e.messages.slice(-6);for(let g of d)if(g.role==="user"||g.role==="assistant"){let h=g.role==="assistant"&&g.content.length>300?g.content.slice(0,300)+"...":g.content;c.push({role:g.role,content:h})}c.push({role:"user",content:t});let u=await _e(n,s,o,{systemPrompt:l,messages:c,structuredOutput:{schema:_c,name:"pipeline_plan"},maxTokens:2e3});if(u.type!=="structured"){E.warn("intent-analyzer","Did not get structured output, falling back");let g=e.modules.length===0;return{intent:g?"create":"modify",affectedModules:g?[]:a,unchangedModules:[],newModules:[],guidesNeeded:["design","content","conversion","hubspot_rules","humanify"],designSystemChanges:g}}let m=u.data;return m.affectedModules=m.affectedModules||[],m.unchangedModules=m.unchangedModules||[],m.newModules=m.newModules||[],m.guidesNeeded=m.guidesNeeded||[],e.contentMode==="email"?m.contentType="email":m.contentType=m.contentType==="email"?"email":"page",E.info("intent-analyzer","Plan",{intent:m.intent,affected:m.affectedModules.length,unchanged:m.unchangedModules.length,new:m.newModules.length,reuse:m.reuseModules?.length||0,designSystem:m.designSystemChanges}),i({type:"agent_decision",step:"analyzing",decision:th(m)}),m}function th(t){let e=[`Intent: ${t.intent}`];return t.affectedModules.length>0&&e.push(`Modifying: ${t.affectedModules.join(", ")}`),t.unchangedModules.length>0&&e.push(`Unchanged: ${t.unchangedModules.join(", ")}`),t.newModules.length>0&&e.push(`New: ${t.newModules.map(n=>n.name).join(", ")}`),t.reuseModules?.length&&e.push(`Reuse: ${t.reuseModules.map(n=>`${n.name} from ${n.sourceTemplate}`).join(", ")}`),t.designSystemChanges&&e.push("Design system changes: yes"),e.join(" | ")}var Ic=R(()=>{"use strict";y();nt();Mc();de()});function To(t,e){let n=[];n.push(`You are the Design System Architect for vibeSpot, a HubSpot CMS page builder.
746
933
 
747
934
  Your job: create a complete, production-ready CSS design system for a landing page theme. You produce the :root custom properties, shared utility/component CSS, and optional shared JS (scroll animations). Downstream agents will use YOUR CSS classes and variables to build individual modules.
748
935
 
749
- ## Theme: "${e}"
936
+ ## Theme: "${t}"
750
937
 
751
938
  ## Output Requirements
752
939
 
@@ -754,36 +941,36 @@ Your job: create a complete, production-ready CSS design system for a landing pa
754
941
  A flat object mapping CSS custom property names to values. Every variable your CSS references MUST be defined here. Include ALL of these categories:
755
942
 
756
943
  **Colors** (at minimum):
757
- - --${e}-color-bg: page background
758
- - --${e}-color-surface: card/section background
759
- - --${e}-color-dark: dark section background
760
- - --${e}-color-dark-surface: card bg inside dark sections
761
- - --${e}-color-text: primary text color
762
- - --${e}-color-text-inverse: text on dark backgrounds
763
- - --${e}-color-text-muted: secondary/muted text
764
- - --${e}-color-primary: primary brand color
765
- - --${e}-color-primary-dark: darker variant for hover states
766
- - --${e}-color-accent: accent/highlight color
767
- - --${e}-color-accent-light: light tint for pill/badge backgrounds
768
- - --${e}-color-border: default border color
769
- - --${e}-color-border-hover: border on hover
944
+ - --${t}-color-bg: page background
945
+ - --${t}-color-surface: card/section background
946
+ - --${t}-color-dark: dark section background
947
+ - --${t}-color-dark-surface: card bg inside dark sections
948
+ - --${t}-color-text: primary text color
949
+ - --${t}-color-text-inverse: text on dark backgrounds
950
+ - --${t}-color-text-muted: secondary/muted text
951
+ - --${t}-color-primary: primary brand color
952
+ - --${t}-color-primary-dark: darker variant for hover states
953
+ - --${t}-color-accent: accent/highlight color
954
+ - --${t}-color-accent-light: light tint for pill/badge backgrounds
955
+ - --${t}-color-border: default border color
956
+ - --${t}-color-border-hover: border on hover
770
957
 
771
958
  **Typography**:
772
- - --${e}-font-display: display/heading font stack (system fonts only)
773
- - --${e}-font-body: body text font stack (system fonts only)
774
- - --${e}-size-h1 through --${e}-size-h3: heading sizes using clamp()
775
- - --${e}-size-body, --${e}-size-lg, --${e}-size-small, --${e}-size-label
776
- - --${e}-leading-tight, --${e}-leading-snug, --${e}-leading-body: line heights
777
- - --${e}-tracking-tight, --${e}-tracking-wide: letter spacing
959
+ - --${t}-font-display: display/heading font stack (system fonts only)
960
+ - --${t}-font-body: body text font stack (system fonts only)
961
+ - --${t}-size-h1 through --${t}-size-h3: heading sizes using clamp()
962
+ - --${t}-size-body, --${t}-size-lg, --${t}-size-small, --${t}-size-label
963
+ - --${t}-leading-tight, --${t}-leading-snug, --${t}-leading-body: line heights
964
+ - --${t}-tracking-tight, --${t}-tracking-wide: letter spacing
778
965
 
779
966
  **Spacing**:
780
- - --${e}-space-xs through --${e}-space-xl, --${e}-space-section
781
- - --${e}-max-width: content max-width (1152-1280px)
967
+ - --${t}-space-xs through --${t}-space-xl, --${t}-space-section
968
+ - --${t}-max-width: content max-width (1152-1280px)
782
969
 
783
970
  **Effects**:
784
- - --${e}-radius-sm, --${e}-radius-md, --${e}-radius-lg, --${e}-radius-full
785
- - --${e}-shadow-card-hover, --${e}-shadow-button
786
- - --${e}-transition-fast, --${e}-transition-base, --${e}-transition-slow
971
+ - --${t}-radius-sm, --${t}-radius-md, --${t}-radius-lg, --${t}-radius-full
972
+ - --${t}-shadow-card-hover, --${t}-shadow-button
973
+ - --${t}-transition-fast, --${t}-transition-base, --${t}-transition-slow
787
974
 
788
975
  ### sharedCss
789
976
  Complete CSS file content. MUST include:
@@ -791,15 +978,15 @@ Complete CSS file content. MUST include:
791
978
  2. Reset (box-sizing, margin, padding)
792
979
  3. Body styles referencing your variables
793
980
  4. Typography rules (h1-h6, p)
794
- 5. Layout utilities (.${e}-container, .${e}-section, .${e}-section--dark)
795
- 6. Grid system (.${e}-grid, .${e}-grid--2/3/4 with responsive breakpoints)
796
- 7. Card component (.${e}-card with hover lift)
797
- 8. Button component (.${e}-btn, .${e}-btn--primary, .${e}-btn--secondary)
981
+ 5. Layout utilities (.${t}-container, .${t}-section, .${t}-section--dark)
982
+ 6. Grid system (.${t}-grid, .${t}-grid--2/3/4 with responsive breakpoints)
983
+ 7. Card component (.${t}-card with hover lift)
984
+ 8. Button component (.${t}-btn, .${t}-btn--primary, .${t}-btn--secondary)
798
985
  CRITICAL: Re-declare color, text-decoration:none, and font-family on :hover/:focus \u2014 HubSpot overrides link hover styles
799
- 9. Pill/badge (.${e}-pill)
986
+ 9. Pill/badge (.${t}-pill)
800
987
  10. Decorative elements (at least one background treatment: grid pattern, noise, gradient orb)
801
988
  11. Scroll animation CSS ([data-animate], [data-animate-stagger]) with 3s CSS-only fallback
802
- 12. Section label (.${e}-label) \u2014 uppercase, letter-spacing, accent color
989
+ 12. Section label (.${t}-label) \u2014 uppercase, letter-spacing, accent color
803
990
  13. Stat number styling
804
991
  14. Responsive mobile styles (@media max-width: 767px)
805
992
 
@@ -807,8 +994,8 @@ Complete CSS file content. MUST include:
807
994
  IntersectionObserver-based scroll animation JS. Wrap in IIFE.
808
995
 
809
996
  ## CSS Rules \u2014 CRITICAL
810
- - All classes MUST use prefix "${e}-"
811
- - Use BEM naming: ${e}-module__element--modifier
997
+ - All classes MUST use prefix "${t}-"
998
+ - Use BEM naming: ${t}-module__element--modifier
812
999
  - Use system font stacks ONLY (no Google Fonts @import, no external CDN)
813
1000
  - Every var() reference in CSS must have a matching declaration in :root
814
1001
  - No Tailwind, no Sass, no PostCSS
@@ -816,41 +1003,60 @@ IntersectionObserver-based scroll animation JS. Wrap in IIFE.
816
1003
 
817
1004
  ## Font Strategy
818
1005
  Use system font stacks that approximate the desired aesthetic. Pick TWO stacks:
819
- - Display: for headings (e.g., Georgia, "Times New Roman", serif for editorial)
820
- - Body: for text (e.g., system-ui, -apple-system, "Segoe UI", sans-serif)
821
-
822
- Good system font stacks by style:
823
- | Style | Display Stack | Body Stack |
824
- |-------|--------------|------------|
825
- | Editorial | Georgia, Cambria, "Times New Roman", serif | system-ui, -apple-system, "Segoe UI", sans-serif |
826
- | Modern | system-ui, -apple-system, sans-serif | "Segoe UI", Roboto, sans-serif |
827
- | Warm | Optima, Candara, "Noto Sans", sans-serif | "Trebuchet MS", system-ui, sans-serif |
828
- | Monospace/Tech | "SF Mono", "Cascadia Code", "Fira Code", monospace | system-ui, sans-serif |
829
- | Geometric | Futura, "Century Gothic", "Trebuchet MS", sans-serif | system-ui, sans-serif |`),n.push(`
1006
+ - Display: for headings
1007
+ - Body: for text
1008
+
1009
+ **Choose the pairing that best fits the content's mood** \u2014 don't default to the same one every time:
1010
+ | Style | Display Stack | Body Stack | Best for |
1011
+ |-------|--------------|------------|----------|
1012
+ | Editorial | Georgia, Cambria, "Times New Roman", serif | system-ui, -apple-system, "Segoe UI", sans-serif | Media, luxury, culture |
1013
+ | Modern | system-ui, -apple-system, sans-serif | "Segoe UI", Roboto, sans-serif | SaaS, tech, startups |
1014
+ | Warm | Optima, Candara, "Noto Sans", sans-serif | "Trebuchet MS", system-ui, sans-serif | Local business, food, wellness |
1015
+ | Monospace/Tech | "SF Mono", "Cascadia Code", "Fira Code", monospace | system-ui, sans-serif | Developer tools, data, cyber |
1016
+ | Geometric | Futura, "Century Gothic", "Trebuchet MS", sans-serif | system-ui, sans-serif | Architecture, design, fashion |
1017
+ | Classic | "Book Antiqua", Palatino, "Palatino Linotype", serif | Georgia, "Times New Roman", serif | Law, finance, heritage |
1018
+ | Friendly | "Comic Sans MS", Chalkboard, cursive | "Trebuchet MS", system-ui, sans-serif | Kids, casual, fun brands |
1019
+ | Contrast pair | Georgia, serif (display) | system-ui, sans-serif (body) | When you want serif/sans tension |`),n.push(`
830
1020
 
831
1021
  ## Design Guide
832
- ${Ba()}`),t?.styleguide&&n.push(`
1022
+ ${Fc()}`),e?.styleguide&&n.push(`
833
1023
 
834
1024
  ## Brand Style Guide
835
- ${t.styleguide}`),t?.themeContext&&n.push(`
1025
+ ${e.styleguide}`),e?.themeContext&&n.push(`
836
1026
 
837
1027
  ## Product Context
838
- ${t.themeContext}`),n.join("")}function ja(e,t){let n=ei(e),o=n.indexOf(`
1028
+ ${e.themeContext}`);let s=e?.brandKit&&(e.brandKit.colors?.primary||e.brandKit.colors?.secondary||e.brandKit.colors?.accent||e.brandKit.fonts?.heading||e.brandKit.fonts?.body);if(s){let o=[],i=e.brandKit;i.colors?.primary&&o.push(`- Primary color: ${i.colors.primary}`),i.colors?.secondary&&o.push(`- Secondary color: ${i.colors.secondary}`),i.colors?.accent&&o.push(`- Accent color: ${i.colors.accent}`),i.fonts?.heading&&o.push(`- Heading font: ${i.fonts.heading}`),i.fonts?.body&&o.push(`- Body font: ${i.fonts.body}`),i.logoUrl&&o.push(`- Logo URL: ${i.logoUrl}`),o.length>0&&n.push(`
1029
+
1030
+ ## Brand Kit \u2014 MANDATORY Design Constraints
1031
+ The following brand identity values MUST be used. Do NOT substitute or override them:
1032
+ ${o.join(`
1033
+ `)}`)}return!s&&!e?.styleguide&&n.push(`
1034
+
1035
+ ## No Brand Provided \u2014 Follow the Generation Recipe
1036
+ No brand colors, fonts, or styleguide have been set. You MUST follow these rules to create a unique design:
1037
+
1038
+ ${Oc()}`),n.join("")}function cr(t,e){let n=To(t),o=n.indexOf(`
839
1039
 
840
1040
  ## Design Guide
841
- `);if(o===-1)return[{type:"text",text:n}];let i=n.slice(0,o),a=`## Design Guide
842
- ${Ba()}`,r=[{type:"text",text:i},{type:"text",text:a,cache_control:{type:"ephemeral"}}],l=[];return t?.styleguide&&l.push(`## Brand Style Guide
843
- ${t.styleguide}`),t?.themeContext&&l.push(`## Product Context
844
- ${t.themeContext}`),l.length>0&&r.push({type:"text",text:l.join(`
1041
+ `);if(o===-1)return[{type:"text",text:n}];let i=n.slice(0,o),r=`## Design Guide
1042
+ ${Fc()}`,a=[{type:"text",text:i},{type:"text",text:r,cache_control:{type:"ephemeral"}}],l=[];e?.styleguide&&l.push(`## Brand Style Guide
1043
+ ${e.styleguide}`),e?.themeContext&&l.push(`## Product Context
1044
+ ${e.themeContext}`);let c=e?.brandKit&&(e.brandKit.colors?.primary||e.brandKit.colors?.secondary||e.brandKit.colors?.accent||e.brandKit.fonts?.heading||e.brandKit.fonts?.body);if(c){let d=[],u=e.brandKit;u.colors?.primary&&d.push(`- Primary color: ${u.colors.primary}`),u.colors?.secondary&&d.push(`- Secondary color: ${u.colors.secondary}`),u.colors?.accent&&d.push(`- Accent color: ${u.colors.accent}`),u.fonts?.heading&&d.push(`- Heading font: ${u.fonts.heading}`),u.fonts?.body&&d.push(`- Body font: ${u.fonts.body}`),u.logoUrl&&d.push(`- Logo URL: ${u.logoUrl}`),d.length>0&&l.push(`## Brand Kit \u2014 MANDATORY Design Constraints
1045
+ The following brand identity values MUST be used. Do NOT substitute or override them:
1046
+ ${d.join(`
1047
+ `)}`)}return!c&&!e?.styleguide&&l.push(`## No Brand Provided \u2014 Follow the Generation Recipe
1048
+ No brand colors, fonts, or styleguide have been set. You MUST follow these rules to create a unique design:
845
1049
 
846
- `)}),r}function gm(e){let t=[...new Set([...e.matchAll(/\.([a-zA-Z][\w-]*)/g)].map(i=>`.${i[1]}`))],n=[...new Set([...e.matchAll(/(--[\w-]+)\s*:/g)].map(i=>i[1]))],s=[...new Set([...e.matchAll(/@media\s*\([^)]+\)/g)].map(i=>i[0]))],o=[];return n.length>0&&o.push(`CSS Variables: ${n.join(", ")}`),t.length>0&&o.push(`CSS Classes: ${t.join(", ")}`),s.length>0&&o.push(`Breakpoints: ${s.join(", ")}`),o.join(`
847
- `)}function Ha(e,t,n,s){let o=[],i=gm(t);return o.push(`You are the Module Planner for vibeSpot, a HubSpot CMS page builder.
1050
+ ${Oc()}`),l.length>0&&a.push({type:"text",text:l.join(`
1051
+
1052
+ `)}),a}function nh(t){let e=[...new Set([...t.matchAll(/\.([a-zA-Z][\w-]*)/g)].map(i=>`.${i[1]}`))],n=[...new Set([...t.matchAll(/(--[\w-]+)\s*:/g)].map(i=>i[1]))],s=[...new Set([...t.matchAll(/@media\s*\([^)]+\)/g)].map(i=>i[0]))],o=[];return n.length>0&&o.push(`CSS Variables: ${n.join(", ")}`),e.length>0&&o.push(`CSS Classes: ${e.join(", ")}`),s.length>0&&o.push(`Breakpoints: ${s.join(", ")}`),o.join(`
1053
+ `)}function Rc(t,e,n,s){let o=[],i=nh(e);return o.push(`You are the Module Planner for vibeSpot, a HubSpot CMS page builder.
848
1054
 
849
1055
  Your job: plan the modules for a landing page. You define what each module contains (content brief) and how it should be laid out. You do NOT write module code \u2014 downstream Module Developers handle that.
850
1056
 
851
1057
  The Design System has already been created. Your module plans MUST reference the existing CSS classes and variables.
852
1058
 
853
- ## Theme: "${e}"
1059
+ ## Theme: "${t}"
854
1060
 
855
1061
  ## Available CSS Classes & Variables
856
1062
  Reference these in your layoutNotes:
@@ -867,7 +1073,7 @@ ${i}
867
1073
  ### Content & layout
868
1074
  - Content briefs: describe the actual copy/content each module needs (headlines, body text, CTAs, stats)
869
1075
  - Layout notes: describe the visual layout using the available CSS classes above
870
- - Reference specific CSS classes from the shared CSS in your layout notes (e.g., "Use ${e}-grid--3 for card layout, ${e}-section--dark for background")
1076
+ - Reference specific CSS classes from the shared CSS in your layout notes (e.g., "Use ${t}-grid--3 for card layout, ${t}-section--dark for background")
871
1077
 
872
1078
  ### Module order
873
1079
  - \`moduleOrder\`: list **all** modules' names in the order they should appear on the page, including:
@@ -875,7 +1081,7 @@ ${i}
875
1081
  - any "Existing Modules to Keep" the user listed (these are not in \`modules\`, but still belong in \`moduleOrder\`)`),(!s||s.includes("content"))&&o.push(`
876
1082
 
877
1083
  ## Content & Copywriting Guide
878
- ${fm()}`),n?.brandvoice&&o.push(`
1084
+ ${sh()}`),n?.brandvoice&&o.push(`
879
1085
 
880
1086
  ## Brand Voice
881
1087
  ${n.brandvoice}`),n?.themeContext&&o.push(`
@@ -884,7 +1090,63 @@ ${n.brandvoice}`),n?.themeContext&&o.push(`
884
1090
  ${n.themeContext}`),n?.humanify!==!1&&s?.includes("humanify")&&o.push(`
885
1091
 
886
1092
  ## Anti-AI Copy Rules
887
- ${hm()}`),o.join("")}function Ba(){return`### Design Philosophy
1093
+ ${oh()}`),o.join("")}function Oc(){let t=Un(),e=Pc(t,"## 4. Color System","## 5."),n=Pc(t,"### Recommended Font Pairings","### Typography Scale"),s=[];return s.push(`### Step 1: Derive the aesthetic from the content
1094
+ Read the user's request carefully. What industry? What audience? What mood?
1095
+ Map it to ONE of these aesthetic directions \u2014 then commit fully:
1096
+
1097
+ | Business Type | Aesthetic | Color Direction | Font Mood |
1098
+ |--------------|-----------|----------------|-----------|
1099
+ | SaaS / Tech startup | Cool minimal or Bold tech | Blues, teals, electric purples, neon greens \u2014 COOL tones | Geometric sans or monospace |
1100
+ | Restaurant / Food | Warm editorial | Deep greens, burgundy, cream, terracotta \u2014 WARM but rich | Serif display + clean body |
1101
+ | Agency / Consultancy | Bold confident | Black + a single bold accent (red, orange, electric blue) | Strong geometric display |
1102
+ | E-commerce / DTC | Playful or Premium | Depends on product: pastels for beauty, dark for luxury, bright for fun | Varies \u2014 match the product vibe |
1103
+ | Finance / Legal | Dark luxury or Classic | Navy, charcoal, forest green, gold \u2014 DARK and authoritative | Classic serif or refined sans |
1104
+ | Health / Wellness | Soft organic | Sage, lavender, soft sky, warm sand \u2014 MUTED and calming | Rounded sans or warm serif |
1105
+ | Education / Non-profit | Warm and approachable | Warm blues, soft greens, sunny yellows \u2014 FRIENDLY | Humanist sans, readable |
1106
+ | Real estate / Architecture | Minimal luxe | Off-whites, charcoal, muted golds \u2014 MINIMAL | Thin geometric or editorial serif |
1107
+ | Developer tools / Data | Dark mode tech | Near-black bg, neon accent (cyan, lime, pink) \u2014 HIGH CONTRAST | Monospace display + clean sans body |
1108
+ | Creative / Portfolio | Expressive | Unexpected: magenta + teal, black + coral, deep purple + lime \u2014 BOLD | Anything distinctive |
1109
+ | Events / Entertainment | Energetic | Vibrant saturated colors, gradients OK \u2014 HIGH ENERGY | Bold display, fun pairings |
1110
+ | Local service / Trades | Trustworthy practical | Navy, forest green, or deep red with clean white \u2014 SOLID | Clean readable sans |
1111
+
1112
+ ### Step 2: Pick ORIGINAL colors
1113
+ Do NOT copy any palette you've seen before. Generate new hex values by:
1114
+ 1. Pick a background hue that fits the aesthetic (dark? warm white? cool gray? tinted?)
1115
+ 2. Pick a primary that CONTRASTS with the bg and matches the industry mood
1116
+ 3. Pick an accent that complements the primary (analogous, split-complementary, or triadic)
1117
+ 4. Derive surface, text, muted, border colors from these three anchors
1118
+ 5. Verify contrast: body text \u2265 4.5:1, large text \u2265 3:1 against their backgrounds
1119
+
1120
+ **BANNED combinations** (too common, feels like a template):
1121
+ - White bg + blue primary + light blue accent
1122
+ - White bg + purple/violet primary
1123
+ - Cream/beige bg + brown/orange primary + gold accent
1124
+ - Any combination you've generated in the last 10 sessions`),n&&s.push(`### Step 3: Choose fonts from the design guide
1125
+ These are ideal web font pairings. Since HubSpot CMS uses system fonts, pick the CLOSEST system font stack that matches the mood of the ideal pairing:
1126
+
1127
+ ${n}
1128
+
1129
+ **System font mapping** \u2014 use these to approximate the above:
1130
+ - Serif display (Playfair, Cormorant, Fraunces) \u2192 Georgia, Cambria, "Times New Roman", serif
1131
+ - Clean body serif (Source Serif) \u2192 Georgia, "Times New Roman", serif
1132
+ - Geometric sans (Satoshi, Outfit, Cabinet) \u2192 Futura, "Century Gothic", "Trebuchet MS", sans-serif
1133
+ - Modern sans (DM Sans, Plus Jakarta, General Sans) \u2192 system-ui, -apple-system, "Segoe UI", sans-serif
1134
+ - Humanist sans (Libre Franklin, Nunito) \u2192 Optima, Candara, "Noto Sans", sans-serif
1135
+ - Monospace (Space Mono, JetBrains) \u2192 "SF Mono", "Cascadia Code", "Fira Code", monospace
1136
+ - Bold display (Archivo Black, Bebas Neue, Syne) \u2192 Impact, "Arial Black", sans-serif
1137
+ - Classic serif (Book Antiqua) \u2192 "Book Antiqua", Palatino, "Palatino Linotype", serif
1138
+
1139
+ Choose the pairing that matches the MOOD of the content, not the same one every time.`),e&&s.push(`### Reference: Design Guide Color Philosophy
1140
+ ${e}`),s.push(`### Step 4: Verify uniqueness
1141
+ Before finalizing, ask yourself:
1142
+ - Would this palette look DIFFERENT from a page I just designed for a different topic?
1143
+ - Is the primary color something other than blue, brown, or purple?
1144
+ - Would the user be surprised (pleasantly) by this color choice?
1145
+ - Does the font pairing match the industry, not just "safe defaults"?
1146
+
1147
+ If any answer is "no," go bolder. The user wants personality, not safety.`),s.join(`
1148
+
1149
+ `)}function Pc(t,e,n){let s=t.indexOf(e);if(s===-1)return"";let o=t.indexOf(n,s);return o===-1?t.slice(s):t.slice(s,o).trim()}function Fc(){return`### Design Philosophy
888
1150
  You are a senior UI designer. Every page must look professionally designed, not like AI output.
889
1151
  Avoid "AI slop": purple gradients on white, cookie-cutter card grids, no personality.
890
1152
 
@@ -895,12 +1157,12 @@ Before designing, decide on:
895
1157
 
896
1158
  When a user gives a simple prompt like "build me a landing page for a coffee shop," internally expand it:
897
1159
  - Pick an aesthetic (warm, editorial, slightly vintage)
898
- - Pick specific colors (cream bg #faf7f2, espresso #3c1e0e, gold accent #c4956a)
1160
+ - Pick ORIGINAL colors derived from the topic (coffee \u2192 think espresso browns, cream tones, warm gold \u2014 but pick your own unique hex values every time)
899
1161
  - Decide hero style (full-bleed image background, overlaid text)
900
1162
  - Choose layout approach (asymmetric sections, large visual areas)
901
1163
  - Add texture (subtle paper/grain noise overlay)
902
1164
  - Set animations (scroll-triggered reveals)
903
- The user gives the "what," you decide the "how it should look and feel."
1165
+ The user gives the "what," you decide the "how it should look and feel." Every project gets a fresh, unique palette.
904
1166
 
905
1167
  ### Typography Scale
906
1168
  Include these in the CSS custom properties:
@@ -917,14 +1179,18 @@ letter-spacing: -0.02em to -0.04em for large headings (tighter = more premium)
917
1179
  ### Color Palettes
918
1180
  Pick a dominant (70%), secondary (25%), accent (5%). Ensure WCAG AA contrast (4.5:1 body, 3:1 large text).
919
1181
 
920
- \`\`\`
921
- DARK LUXURY: --bg: #0a0a0a; --surface: #141414; --text: #e8e8e8; --primary: #c9a84c; --accent: #e8d5a3
922
- WARM EARTH: --bg: #faf7f2; --surface: #f0ebe3; --text: #2d2418; --primary: #8b5e3c; --accent: #c4956a
923
- COOL MINIMAL: --bg: #fafafa; --surface: #f1f1f1; --text: #1a1a1a; --primary: #0055ff; --accent: #00c4ff
924
- FOREST: --bg: #0f1a0f; --surface: #1a2e1a; --text: #d4e8d0; --primary: #4ade80; --accent: #22c55e
925
- EDITORIAL CREAM:--bg: #fffdf5; --surface: #f5f0e8; --text: #1c1917; --primary: #dc2626; --accent: #f97316
926
- NOIR: --bg: #000000; --surface: #111111; --text: #ffffff; --primary: #ffffff; --accent: #666666
927
- \`\`\`
1182
+ **CRITICAL: Every project MUST have a unique palette derived from its specific content.** The palette should feel inevitable for the topic \u2014 like a designer hand-picked it for this exact business.
1183
+
1184
+ Derive colors from the CONTENT, not from defaults:
1185
+ - Read the topic/industry from the user's request
1186
+ - Think about what colors that industry evokes (coffee \u2192 deep browns; ocean resort \u2192 teals; cybersecurity \u2192 dark + neon)
1187
+ - Pick a bg, primary, and accent that tell that specific story
1188
+ - Never default to warm beige/brown/orange \u2014 that's only right for earthy/organic topics
1189
+
1190
+ **BANNED default combinations** (too commonly generated):
1191
+ - Cream/beige bg (#faf7f2 etc.) + brown primary + gold/orange accent \u2014 unless the topic is explicitly earthy (coffee, bakery, farmhouse)
1192
+ - White bg + blue primary + light blue accent \u2014 unless the topic is explicitly corporate/finance
1193
+ - Any palette with all warm tones (beige + brown + orange + gold) \u2014 mix temperature
928
1194
 
929
1195
  ### Layout Patterns
930
1196
  1. **Split hero**: Content left, visual right (50/50 or 60/40)
@@ -987,7 +1253,7 @@ Include these in shared CSS:
987
1253
  | All animations same speed | Stagger with increasing delays |
988
1254
  | Skip hover/focus states | Every interactive element needs feedback |
989
1255
  | Use \`<br>\` tags for spacing | Use proper margin/padding |
990
- | Put everything in a shadowed card | Vary: full-bleed, contained, floating |`}function fm(){return`### Mandatory Page Sections (generate all)
1256
+ | Put everything in a shadowed card | Vary: full-bleed, contained, floating |`}function sh(){return`### Mandatory Page Sections (generate all)
991
1257
  1. **Navigation Bar** \u2014 Logo, 4-5 nav links, CTA button, sticky on scroll
992
1258
  2. **Hero** \u2014 Badge/pill, primary headline, subheadline, primary + secondary CTA, trust signals, visual element
993
1259
  3. **Social Proof Bar** \u2014 Logo strip of 4-6 clients OR stats bar (compact, py-8)
@@ -1075,7 +1341,7 @@ Alternate backgrounds every 2-3 sections to create visual "chapters." Sprinkle t
1075
1341
  - Invent plausible specifics: neighborhood names, "48 hours" not "quickly", "\u20AC49" not "affordable"
1076
1342
  - Keep paragraphs to 2-3 sentences max
1077
1343
  - Aim for 6th-grade reading level
1078
- - Include section labels (UPPERCASE, letter-spacing 0.1em, accent color, 2-3 words) above every headline`}function hm(){return`### Banned Punctuation
1344
+ - Include section labels (UPPERCASE, letter-spacing 0.1em, accent color, 2-3 words) above every headline`}function oh(){return`### Banned Punctuation
1079
1345
  - **Em dashes (\u2014)**: NEVER use. Biggest AI tell. Replace with periods, commas, or parentheses.
1080
1346
  - **Semicolons**: Feel academic, not conversational. Use periods instead.
1081
1347
  - **Exclamation marks**: One per page maximum. Zero is ideal for B2B.
@@ -1105,38 +1371,387 @@ seamless, cutting-edge, groundbreaking, game-changer, revolutionary, transformat
1105
1371
  - Use plain short words: use > utilize, start > commence, help > facilitate
1106
1372
  - Vary sentence length aggressively: mix 3-word, 12-word, and 25-word sentences
1107
1373
  - Front-load the benefit in the first 5 words
1108
- - Write like you'd explain it in a bar \u2014 if you wouldn't say it holding a beer, rewrite it`}var Da,La,Ua=L(()=>{"use strict";f();Da={type:"object",properties:{cssVariables:{type:"object",description:"CSS custom property name \u2192 value map. Every var() used in sharedCss must be defined here."},sharedCss:{type:"string",description:"Complete shared CSS file. MUST start with :root {} block defining all cssVariables, followed by reset, typography, layout, components, animations, and responsive styles."},sharedJs:{type:"string",description:"Optional shared JS for scroll animations (IntersectionObserver). Wrap in IIFE. Empty string if not needed."},aesthetic:{type:"string",description:"Brief description of the chosen aesthetic direction (e.g., 'dark luxury with warm gold accents')"}},required:["cssVariables","sharedCss","aesthetic"]};La={type:"object",properties:{modules:{type:"array",items:{type:"object",properties:{name:{type:"string",description:"Module identifier. If this module already exists in the project, use the existing name verbatim. For new modules, use kebab-case (e.g., 'hero', 'pricing-cards')."},description:{type:"string",description:"What this module does"},contentBrief:{type:"string",description:"Specific content: headlines, body copy, stats, CTAs"},layoutNotes:{type:"string",description:"Visual layout approach referencing shared CSS classes"}},required:["name","description","contentBrief","layoutNotes"]}},moduleOrder:{type:"array",items:{type:"string"},description:"Module names in page display order"},narrative:{type:"string",description:"Brief description of the page story/flow"}},required:["modules","moduleOrder","narrative"]}});async function Ga(e,t,n,s,o,i,a){a({type:"agent_step",step:"designing",label:"Creating design system..."});let r=s==="anthropic-api"||s==="claude-oauth",l=ei(n.themeName,n.brandAssets),c=r?ja(n.themeName,n.brandAssets):void 0,d=`## User Request
1109
- ${e}`;n.modules.length>0&&t.designSystemChanges&&(d+=`
1374
+ - Write like you'd explain it in a bar \u2014 if you wouldn't say it holding a beer, rewrite it`}var dr,Nc,jc=R(()=>{"use strict";y();Ue();dr={type:"object",properties:{cssVariables:{type:"object",description:"CSS custom property name \u2192 value map. Every var() used in sharedCss must be defined here."},sharedCss:{type:"string",description:"Complete shared CSS file. MUST start with :root {} block defining all cssVariables, followed by reset, typography, layout, components, animations, and responsive styles."},sharedJs:{type:"string",description:"Optional shared JS for scroll animations (IntersectionObserver). Wrap in IIFE. Empty string if not needed."},aesthetic:{type:"string",description:"Brief description of the chosen aesthetic direction (e.g., 'dark luxury with warm gold accents')"}},required:["cssVariables","sharedCss","aesthetic"]};Nc={type:"object",properties:{modules:{type:"array",items:{type:"object",properties:{name:{type:"string",description:"Module identifier. If this module already exists in the project, use the existing name verbatim. For new modules, use kebab-case (e.g., 'hero', 'pricing-cards')."},description:{type:"string",description:"What this module does"},contentBrief:{type:"string",description:"Specific content: headlines, body copy, stats, CTAs"},layoutNotes:{type:"string",description:"Visual layout approach referencing shared CSS classes"}},required:["name","description","contentBrief","layoutNotes"]}},moduleOrder:{type:"array",items:{type:"string"},description:"Module names in page display order"},narrative:{type:"string",description:"Brief description of the page story/flow"}},required:["modules","moduleOrder","narrative"]}});function ur(t){if(!t)return"";let e=[];return t.colors&&(t.colors.primary&&e.push(`- Primary color: ${t.colors.primary}`),t.colors.secondary&&e.push(`- Secondary color: ${t.colors.secondary}`),t.colors.accent&&e.push(`- Accent color: ${t.colors.accent}`)),t.fonts&&(t.fonts.heading&&e.push(`- Heading font: ${t.fonts.heading}`),t.fonts.body&&e.push(`- Body font: ${t.fonts.body}`)),t.logoUrl&&e.push(`- Logo URL: ${t.logoUrl}`),e.length===0?"":`
1375
+
1376
+ ## Brand Kit \u2014 MANDATORY Design Constraints
1377
+ The following brand identity values MUST be used. Do NOT substitute or override them:
1378
+ ${e.join(`
1379
+ `)}`}function Ao(t,e){let n=[];n.push(`You are the Email Design Token Architect for vibeSpot, a HubSpot email template builder.
1380
+
1381
+ Your job: create a complete set of inline-safe design tokens for an email template. Email clients do NOT support CSS custom properties (var()), external stylesheets, flexbox, grid, or JavaScript. All styling must be inline.
1382
+
1383
+ You produce a token map (colors, fonts, sizes) and a style guide string that downstream email module developers will reference when writing inline styles.
1384
+
1385
+ ## Theme: "${t}"
1386
+
1387
+ ## Output Requirements
1388
+
1389
+ ### cssVariables
1390
+ A flat object mapping token names to literal CSS values. These are NOT CSS custom properties \u2014 they are a reference map for module developers to copy into inline styles. Use descriptive names:
1391
+
1392
+ **Colors** (choose original values that fit the topic \u2014 no default palette):
1393
+ - bg-color: email body background
1394
+ - content-bg: main content area background
1395
+ - text-color: primary text color
1396
+ - text-muted: secondary text color
1397
+ - text-light: light text for footers
1398
+ - heading-color: heading text color
1399
+ - primary-color: primary brand/CTA color
1400
+ - primary-hover: darker primary for button states
1401
+ - accent-color: accent/highlight color
1402
+ - border-color: divider/border color
1403
+ - footer-bg: footer background color
1404
+
1405
+ **Typography** (web-safe stacks only \u2014 pick the pairing that fits the mood):
1406
+ - font-heading: heading font stack
1407
+ - font-body: body font stack
1408
+ - size-h1: main heading size in px (e.g., "28px")
1409
+ - size-h2: section heading size in px (e.g., "22px")
1410
+ - size-h3: subheading size in px (e.g., "18px")
1411
+ - size-body: body text size in px (e.g., "16px")
1412
+ - size-small: small/footer text size in px (e.g., "13px")
1413
+ - line-height: body line height (e.g., "1.5")
1414
+
1415
+ **Spacing** (px only):
1416
+ - content-width: email content width (always "600")
1417
+ - padding-section: vertical section padding (e.g., "40")
1418
+ - padding-cell: cell padding (e.g., "20")
1419
+ - padding-button: button padding (e.g., "14px 32px")
1420
+
1421
+ ### sharedCss
1422
+ For email, this MUST be an empty string "". Email modules use inline styles only.
1423
+
1424
+ ### sharedJs
1425
+ MUST be omitted or empty string. No JavaScript in email.
1426
+
1427
+ ### aesthetic
1428
+ Brief description of the chosen email design direction (e.g., "clean professional with warm coral accents").
1429
+
1430
+ ## Email Design Rules \u2014 CRITICAL
1431
+
1432
+ ### Font Strategy
1433
+ Use ONLY web-safe font stacks. These are the only fonts guaranteed across email clients:
1434
+
1435
+ | Style | Stack |
1436
+ |-------|-------|
1437
+ | Sans-serif | Arial, Helvetica, sans-serif |
1438
+ | Serif | Georgia, "Times New Roman", Times, serif |
1439
+ | Modern sans | Verdana, Geneva, sans-serif |
1440
+ | Compact | Tahoma, Geneva, sans-serif |
1441
+ | Monospace | "Courier New", Courier, monospace |
1442
+
1443
+ Do NOT use: system-ui, -apple-system, Segoe UI, Inter, or any Google Fonts.
1444
+
1445
+ ### Color Rules
1446
+ - Use hex colors only (no rgb(), hsl(), or named colors)
1447
+ - Ensure WCAG AA contrast (4.5:1 for body text, 3:1 for large text)
1448
+ - CTA buttons need high contrast against both email body and content area backgrounds
1449
+ - Consider dark mode: some clients invert colors. Use medium-contrast ratios that work inverted.
1450
+
1451
+ ### Size Rules
1452
+ - All font sizes in px (never rem, em, or clamp())
1453
+ - Line heights as unitless numbers (1.5) or px values
1454
+ - Container width always 600px
1455
+ - Padding/margin in px only
1456
+ - Button padding generous: at least 12px vertical, 28px horizontal
1457
+
1458
+ ### What NOT to generate
1459
+ - No CSS custom properties (var())
1460
+ - No calc(), clamp(), or CSS functions
1461
+ - No @media queries (module developers may add progressive enhancement)
1462
+ - No animation, transition, or transform values
1463
+ - No box-shadow or text-shadow (poor email support)
1464
+ - No flexbox or grid references
1465
+ - No external font imports`),n.push(`
1466
+
1467
+ ## Email Design Guide
1468
+ ${Lc()}`),e?.styleguide&&n.push(`
1469
+
1470
+ ## Brand Style Guide
1471
+ ${e.styleguide}`),e?.themeContext&&n.push(`
1472
+
1473
+ ## Product Context
1474
+ ${e.themeContext}`);let s=ur(e?.brandKit);return s?n.push(s):e?.styleguide||n.push(`
1475
+
1476
+ ## No Brand Provided \u2014 Be Creative
1477
+ No brand colors or fonts have been set. Invent an original color palette that fits the email's topic and audience. Do NOT fall back to generic grays and blues. Choose web-safe font pairings (heading + body) that match the mood \u2014 vary between serif, sans-serif, and other stacks based on what fits.`),n.join("")}function mr(t,e){let n=Ao(t),o=n.indexOf(`
1478
+
1479
+ ## Email Design Guide
1480
+ `);if(o===-1)return[{type:"text",text:n}];let i=n.slice(0,o),r=`## Email Design Guide
1481
+ ${Lc()}`,a=[{type:"text",text:i},{type:"text",text:r,cache_control:{type:"ephemeral"}}],l=[];e?.styleguide&&l.push(`## Brand Style Guide
1482
+ ${e.styleguide}`),e?.themeContext&&l.push(`## Product Context
1483
+ ${e.themeContext}`);let c=ur(e?.brandKit);return c?l.push(c):e?.styleguide||l.push(`## No Brand Provided \u2014 Be Creative
1484
+ No brand colors or fonts have been set. Invent an original color palette that fits the email's topic and audience. Do NOT fall back to generic grays and blues. Choose web-safe font pairings (heading + body) that match the mood \u2014 vary between serif, sans-serif, and other stacks based on what fits.`),l.length>0&&a.push({type:"text",text:l.join(`
1485
+
1486
+ `)}),a}function Dc(t,e,n,s){let o=[],i=Object.entries(e).map(([a,l])=>` ${a}: ${l}`).join(`
1487
+ `);o.push(`You are the Email Module Planner for vibeSpot, a HubSpot email template builder.
1488
+
1489
+ Your job: plan the modules (sections) for an email template. You define what each section contains and how it should look. You do NOT write module code \u2014 downstream Email Module Developers handle that.
1490
+
1491
+ The Design Tokens have already been created. Your module plans MUST reference these tokens for consistent styling.
1492
+
1493
+ ## Theme: "${t}"
1494
+
1495
+ ## Design Tokens
1496
+ These literal values will be used in inline styles by module developers:
1497
+
1498
+ ${i}
1499
+
1500
+ ## Email Structure Rules
1501
+
1502
+ ### Standard Email Sections
1503
+ Plan modules from this list (use what fits the email type):
1504
+
1505
+ 1. **preheader** \u2014 Hidden preview text for inbox (always include)
1506
+ 2. **header** \u2014 Logo, optional nav links (keep simple)
1507
+ 3. **hero** \u2014 Main headline, hero image or illustration, primary CTA
1508
+ 4. **body-content** \u2014 Main message text, product details, or story
1509
+ 5. **features** / **highlights** \u2014 2-3 feature cards or product highlights
1510
+ 6. **cta-block** \u2014 Standalone call-to-action section
1511
+ 7. **testimonial** \u2014 Customer quote or social proof
1512
+ 8. **footer** \u2014 Unsubscribe link, physical address, social links (required by law)
1513
+
1514
+ ### Module Planning Rules
1515
+ - Every email MUST have: preheader, header, at least one content section, footer
1516
+ - Footer MUST include unsubscribe link and physical address (CAN-SPAM/GDPR)
1517
+ - Keep emails focused: 3-6 modules total (shorter emails perform better)
1518
+ - Each module is a self-contained table-based section
1519
+ - Module names: kebab-case identifiers (e.g., "hero", "feature-grid", "cta-block")
1520
+
1521
+ ### Content Briefs
1522
+ - Be specific about copy: write actual headlines, body text, CTA labels
1523
+ - Include placeholder image dimensions (e.g., "hero image 600x300")
1524
+ - Specify button copy with action verbs ("Shop the Collection", "Read the Full Story")
1525
+
1526
+ ### Layout Notes
1527
+ - All layouts are table-based (no flexbox/grid)
1528
+ - Reference design tokens by name (e.g., "Use primary-color for CTA background")
1529
+ - Specify alignment (center, left) and padding values
1530
+ - For multi-column sections: describe as "2-column table layout" or "3-column table layout"
1531
+ - Max content width: 600px (email standard)
1532
+
1533
+ ## Output Rules
1534
+
1535
+ ### modules array
1536
+ Each module needs: name, description, contentBrief, layoutNotes
1537
+
1538
+ ### moduleOrder
1539
+ List all module names in display order (top to bottom)
1540
+
1541
+ ### narrative
1542
+ One sentence describing the email's purpose and flow`),(!s||s.includes("content"))&&o.push(`
1543
+
1544
+ ## Email Content Guide
1545
+ ${ih()}`),n?.brandvoice&&o.push(`
1546
+
1547
+ ## Brand Voice
1548
+ ${n.brandvoice}`),n?.themeContext&&o.push(`
1549
+
1550
+ ## Product Context
1551
+ ${n.themeContext}`),n?.humanify!==!1&&s?.includes("humanify")&&o.push(`
1552
+
1553
+ ## Anti-AI Copy Rules
1554
+ ${rh()}`);let r=ur(n?.brandKit);return r&&o.push(r),o.join("")}function Lc(){return`### Email Design Philosophy
1555
+ Design for the inbox, not the browser. Email templates must look clean and professional in Gmail, Outlook, Apple Mail, and Yahoo Mail simultaneously.
1556
+
1557
+ ### Color Strategy
1558
+ - **Background**: light gray (#f4f4f4 to #eeeeee) for email body, white (#ffffff) for content area
1559
+ - **Text**: dark but not pure black (#333333 body, #1a1a1a headings) \u2014 pure black on white strains eyes
1560
+ - **CTA buttons**: high-saturation brand color, minimum 44px touch target height
1561
+ - **Dividers**: light borders (#e0e0e0 to #dddddd), 1px solid
1562
+
1563
+ ### Typography Strategy
1564
+ - Headings: 24-32px, bold, short line length (max 8 words)
1565
+ - Body: 15-17px (16px is the sweet spot), line-height 1.5-1.6
1566
+ - Small/legal: 12-13px, muted color
1567
+ - Button text: 15-17px, bold, uppercase optional
1568
+
1569
+ ### Layout Strategy
1570
+ - 600px container (fits all clients including Outlook desktop)
1571
+ - Single-column for mobile friendliness (stacks naturally)
1572
+ - 2-column max for feature grids (stack to 1-col on mobile)
1573
+ - Generous padding: 40-60px vertical between sections, 20-30px horizontal
1574
+ - White space is your friend \u2014 cramped emails get deleted
1575
+
1576
+ ### CTA Button Design
1577
+ - Minimum 44px height (touch target)
1578
+ - 14-16px vertical padding, 28-40px horizontal
1579
+ - Rounded corners via border-radius (degrades gracefully in Outlook)
1580
+ - VML fallback for Outlook (module developer handles this)
1581
+ - One primary CTA per email (secondary CTAs as text links)
1582
+
1583
+ ### Image Guidelines
1584
+ - Hero images: 600px wide, 2:1 to 3:1 aspect ratio
1585
+ - Always include alt text (images blocked by default in many clients)
1586
+ - Use display:block to prevent gaps in Outlook
1587
+ - Product images: consistent sizing within a row`}function ih(){return`### Email Types and Structure
1588
+
1589
+ **Welcome / Onboarding Email**
1590
+ - Warm greeting with first-name personalization
1591
+ - 1-2 sentence value reminder (why they signed up)
1592
+ - 3 numbered getting-started steps
1593
+ - Single primary CTA
1594
+ - Tone: friendly, concise, action-oriented
1595
+
1596
+ **Product Announcement**
1597
+ - Bold headline announcing the update
1598
+ - Hero image or product screenshot
1599
+ - 3-4 key benefits (not features \u2014 what it means for them)
1600
+ - Primary CTA to try/see the feature
1601
+ - Tone: excited but not breathless
1602
+
1603
+ **Newsletter / Digest**
1604
+ - Curated 3-5 content pieces with thumbnails
1605
+ - Brief summary (2-3 sentences) per item
1606
+ - "Read more" links per item + one main CTA
1607
+ - Tone: informative, scannable
1608
+
1609
+ **Event Invitation**
1610
+ - Event name, date, time, location (prominent)
1611
+ - 2-3 sentence description of value
1612
+ - Speaker/host info if applicable
1613
+ - Single "Register" / "RSVP" CTA
1614
+ - Tone: professional, creates urgency without hype
1615
+
1616
+ **Re-engagement**
1617
+ - Acknowledge the absence directly ("We miss you")
1618
+ - Highlight what they're missing (new features, content)
1619
+ - Incentive if applicable (discount, free resource)
1620
+ - Single "Come back" CTA
1621
+ - Tone: genuine, no guilt-tripping
1622
+
1623
+ ### Subject Line & Preheader
1624
+ - Subject: 6-10 words, specific benefit or curiosity gap
1625
+ - Preheader: extends the subject line, 40-90 characters
1626
+ - Do NOT repeat the subject line in the preheader
1627
+
1628
+ ### Email Copy Rules
1629
+ - Front-load the key message in the first 2 sentences
1630
+ - One idea per paragraph, 2-3 sentences max
1631
+ - Use "you" more than "we"
1632
+ - Specific > vague: "saves 3 hours/week" beats "saves time"
1633
+ - CTA copy = verb + benefit: "Start Your Trial", "See the Results"`}function rh(){return`### Email-Specific Anti-AI Rules
1634
+ - No em dashes (\u2014) in email copy. Period.
1635
+ - No "I hope this email finds you well"
1636
+ - No "In today's fast-paced world"
1637
+ - No "We're thrilled/excited/delighted to announce"
1638
+ - Open with the point, not a preamble
1639
+ - One exclamation mark per email maximum
1640
+ - Avoid tricolon structures ("Fast, reliable, secure")
1641
+ - Write like a colleague, not a press release
1642
+ - Every sentence must earn its place \u2014 if removing it doesn't hurt, remove it`}var pr,Jc=R(()=>{"use strict";y();pr={type:"object",properties:{cssVariables:{type:"object",description:"Token name \u2192 literal CSS value map. NOT CSS custom properties. These are reference values for inline styles (e.g., 'bg-color': '#f4f4f4', 'font-body': 'Arial, Helvetica, sans-serif')."},sharedCss:{type:"string",description:"MUST be empty string for email templates. Email uses inline styles only."},sharedJs:{type:"string",description:"MUST be empty string for email templates. No JavaScript in email."},aesthetic:{type:"string",description:"Brief description of the chosen email design direction."}},required:["cssVariables","sharedCss","aesthetic"]}});async function Bc(t,e,n,s,o,i,r){let a=e.contentType==="email";r({type:"agent_step",step:"designing",label:a?"Creating email design tokens...":"Creating design system..."});let l=s==="anthropic-api"||s==="claude-oauth",c=a?Ao(n.themeName,n.brandAssets):To(n.themeName,n.brandAssets),d=l?a?mr(n.themeName,n.brandAssets):cr(n.themeName,n.brandAssets):void 0,u=`## User Request
1643
+ ${t}`;n.modules.length>0&&e.designSystemChanges&&(u+=`
1110
1644
 
1111
1645
  ## Current Shared CSS (update this)
1112
1646
  \`\`\`css
1113
1647
  ${n.sharedCss}
1114
- \`\`\``);let u=Qo(s),m=await Ce(s,o,i,{systemPrompt:l,systemBlocks:c,messages:[{role:"user",content:d}],structuredOutput:{schema:Da,name:"design_system"},maxTokens:16e3,...u>0?{thinkingBudgetTokens:u}:{}}),g;m.type!=="structured"?(A.warn("page-architect","Design system: did not get structured output, using fallback"),g={cssVariables:{},sharedCss:n.sharedCss||"",sharedJs:n.sharedJs||"",aesthetic:"default"}):(g=m.data,A.info("page-architect","Design system created",{aesthetic:g.aesthetic,varCount:Object.keys(g.cssVariables||{}).length,cssLength:g.sharedCss?.length||0}));let y=g.sharedCss||"",h=g.cssVariables;h&&typeof h=="object"&&Object.keys(h).length>0&&(y.includes(":root")||(y=`:root {
1115
- ${Object.entries(h).map(([F,C])=>` ${F.startsWith("--")?F:`--${F}`}: ${C};`).join(`
1648
+ \`\`\``);let m=Sn(s),h=await _e(s,o,i,{systemPrompt:c,systemBlocks:d,messages:[{role:"user",content:u}],structuredOutput:{schema:a?pr:dr,name:"design_system"},maxTokens:16e3,...m>0?{thinkingBudgetTokens:m}:{}}),f;h.type!=="structured"?(E.warn("page-architect","Design system: did not get structured output, using fallback"),f={cssVariables:{},sharedCss:n.sharedCss||"",sharedJs:n.sharedJs||"",aesthetic:"default"}):(f=h.data,E.info("page-architect","Design system created",{aesthetic:f.aesthetic,varCount:Object.keys(f.cssVariables||{}).length,cssLength:f.sharedCss?.length||0}));let b=a?"":f.sharedCss||"",S=f.cssVariables;!a&&S&&typeof S=="object"&&Object.keys(S).length>0&&(b.includes(":root")||(b=`:root {
1649
+ ${Object.entries(S).map(([F,H])=>` ${F.startsWith("--")?F:`--${F}`}: ${H};`).join(`
1116
1650
  `)}
1117
1651
  }
1118
1652
 
1119
- ${y}`));let b=[],x=/\b(Montserrat|Inter|Poppins|Raleway|Playfair|Lato|Roboto|Open\s?Sans|Nunito|Merriweather|Oswald|Source\s?Sans|Fira\s?Sans|Work\s?Sans|Manrope|Plus\s?Jakarta)\b/gi,w=[...new Set((e.match(x)||[]).map(_=>_.trim()))];if(w.length>0){let _=w.filter(C=>y.toLowerCase().includes(C.toLowerCase())),F=w.filter(C=>!_.includes(C));F.length>0&&b.push(`Note: ${F.join(", ")} not available \u2014 HubSpot modules use system font stacks (no external font imports allowed)`)}let S=[`Design system: ${g.aesthetic||"created"} | ${Object.keys(h||{}).length} variables, ${y.length} chars CSS`,...b];a({type:"agent_decision",step:"designing",decision:S.join(`
1120
- `)}),a({type:"design_system_ready",sharedCss:y,sharedJs:g.sharedJs||"",aesthetic:g.aesthetic||""}),a({type:"agent_step",step:"designing",label:"Planning modules..."});let M=Ha(n.themeName,y,n.brandAssets,t.guidesNeeded),O=`## User Request
1121
- ${e}`;if(t.newModules.length>0&&(O+=`
1653
+ ${b}`));let x=Object.keys(S||{}).length,w=a?[`Email design tokens: ${f.aesthetic||"created"} | ${x} tokens`]:[`Design system: ${f.aesthetic||"created"} | ${x} variables, ${b.length} chars CSS`];return r({type:"agent_decision",step:"designing",decision:w.join(`
1654
+ `)}),r({type:"design_system_ready",sharedCss:b,sharedJs:f.sharedJs||"",aesthetic:f.aesthetic||""}),{...f,sharedCss:b}}async function Hc(t,e,n,s,o,i,r){let a=e.contentType==="email";r({type:"agent_step",step:"designing",label:a?"Creating email design tokens...":"Creating design system..."});let l=s==="anthropic-api"||s==="claude-oauth",c=a?Ao(n.themeName,n.brandAssets):To(n.themeName,n.brandAssets),d=l?a?mr(n.themeName,n.brandAssets):cr(n.themeName,n.brandAssets):void 0,u=`## User Request
1655
+ ${t}`;n.modules.length>0&&e.designSystemChanges&&(u+=`
1656
+
1657
+ ## Current Shared CSS (update this)
1658
+ \`\`\`css
1659
+ ${n.sharedCss}
1660
+ \`\`\``);let m=Sn(s),h=await _e(s,o,i,{systemPrompt:c,systemBlocks:d,messages:[{role:"user",content:u}],structuredOutput:{schema:a?pr:dr,name:"design_system"},maxTokens:16e3,...m>0?{thinkingBudgetTokens:m}:{}}),f;h.type!=="structured"?(E.warn("page-architect","Design system: did not get structured output, using fallback"),f={cssVariables:{},sharedCss:n.sharedCss||"",sharedJs:n.sharedJs||"",aesthetic:"default"}):(f=h.data,E.info("page-architect","Design system created",{aesthetic:f.aesthetic,varCount:Object.keys(f.cssVariables||{}).length,cssLength:f.sharedCss?.length||0}));let b=a?"":f.sharedCss||"",S=f.cssVariables;!a&&S&&typeof S=="object"&&Object.keys(S).length>0&&(b.includes(":root")||(b=`:root {
1661
+ ${Object.entries(S).map(([k,K])=>` ${k.startsWith("--")?k:`--${k}`}: ${K};`).join(`
1662
+ `)}
1663
+ }
1664
+
1665
+ ${b}`));let x=[],w=/\b(Montserrat|Inter|Poppins|Raleway|Playfair|Lato|Roboto|Open\s?Sans|Nunito|Merriweather|Oswald|Source\s?Sans|Fira\s?Sans|Work\s?Sans|Manrope|Plus\s?Jakarta)\b/gi,P=[...new Set((t.match(w)||[]).map(I=>I.trim()))];if(P.length>0){let I=P.filter(K=>b.toLowerCase().includes(K.toLowerCase())),k=P.filter(K=>!I.includes(K));k.length>0&&x.push(`Note: ${k.join(", ")} not available \u2014 HubSpot modules use system font stacks (no external font imports allowed)`)}let F=Object.keys(S||{}).length,H=a?[`Email design tokens: ${f.aesthetic||"created"} | ${F} tokens`]:[`Design system: ${f.aesthetic||"created"} | ${F} variables, ${b.length} chars CSS`,...x];r({type:"agent_decision",step:"designing",decision:H.join(`
1666
+ `)}),r({type:"design_system_ready",sharedCss:b,sharedJs:f.sharedJs||"",aesthetic:f.aesthetic||""}),r({type:"agent_step",step:"designing",label:"Planning modules..."});let L=a?Dc(n.themeName,S||{},n.brandAssets,e.guidesNeeded):Rc(n.themeName,b,n.brandAssets,e.guidesNeeded),V=`## User Request
1667
+ ${t}`;if(e.newModules.length>0&&(V+=`
1122
1668
 
1123
1669
  ## Planned Modules
1124
- ${t.newModules.map((_,F)=>`${F+1}. **${_.name}** \u2014 ${_.description}`).join(`
1125
- `)}`),n.modules.length>0){let _=new Set(t.affectedModules),F=n.modules.filter(I=>_.has(I.moduleName)),C=n.modules.filter(I=>!_.has(I.moduleName));F.length>0&&(O+=`
1670
+ ${e.newModules.map((I,k)=>`${k+1}. **${I.name}** \u2014 ${I.description}`).join(`
1671
+ `)}`),n.modules.length>0){let I=new Set(e.affectedModules),k=n.modules.filter(oe=>I.has(oe.moduleName)),K=n.modules.filter(oe=>!I.has(oe.moduleName));k.length>0&&(V+=`
1126
1672
 
1127
1673
  ## Existing Modules to Re-plan (PRESERVE THESE EXACT NAMES)
1128
1674
  These already exist and are being regenerated. Your output's module names MUST match these exactly \u2014 do NOT rename, retitle-case, or "improve" them. Their content/layout may change; their identifier must not.
1129
- `+F.map(I=>`- \`${I.moduleName}\``).join(`
1130
- `)),C.length>0&&(O+=`
1675
+ `+k.map(oe=>`- \`${oe.moduleName}\``).join(`
1676
+ `)),K.length>0&&(V+=`
1131
1677
 
1132
1678
  ## Existing Modules to Keep (do not re-plan)
1133
1679
  These stay as-is. Do NOT include them in your output. They will appear in the final \`moduleOrder\` (you can reference them by name when you list it).
1134
- `+C.map(I=>`- \`${I.moduleName}\``).join(`
1135
- `))}let R=await Ce(s,o,i,{systemPrompt:M,messages:[{role:"user",content:O}],structuredOutput:{schema:La,name:"module_plan"},maxTokens:8e3,...u>0?{thinkingBudgetTokens:u}:{}}),H,z={modules:t.newModules.map(_=>({name:_.name,description:_.description,contentBrief:"Generate appropriate content",layoutNotes:"Use responsive layout"})),moduleOrder:t.newModules.map(_=>_.name),narrative:"Page generated from user request"};if(R.type!=="structured")A.warn("page-architect","Module planner: did not get structured output, using fallback"),H=z;else{let _=R.data;Array.isArray(_?.modules)&&_.modules.length>0?(H=_,H.moduleOrder=H.moduleOrder||H.modules.map(F=>F.name),H.narrative=H.narrative||"Page generated from user request"):(A.warn("page-architect","Module planner: structured output missing 'modules' array, using fallback",{keys:_?Object.keys(_):[]}),H=z),A.info("page-architect","Module plan",{moduleCount:H.modules.length})}return a({type:"agent_decision",step:"designing",decision:`Page: ${H.narrative} | ${H.modules.length} modules planned`}),{designSystem:{cssVariables:g.cssVariables||{},sharedCss:y,sharedJs:g.sharedJs},modules:H.modules,moduleOrder:H.moduleOrder,narrative:H.narrative}}var Wa=L(()=>{"use strict";f();qe();Ua();ie()});function Is(e){let t=0,n=[];return async function(o){t>=e&&await new Promise(i=>n.push(i)),t++;try{return await o()}finally{t--,n.length>0&&n.shift()()}}}var ti=L(()=>{"use strict";f()});function kn(e,t,n,s){let o=[];return o.push(`You are a Module Developer for vibeSpot, a HubSpot CMS page builder.
1680
+ `+K.map(oe=>`- \`${oe.moduleName}\``).join(`
1681
+ `))}let B=await _e(s,o,i,{systemPrompt:L,messages:[{role:"user",content:V}],structuredOutput:{schema:Nc,name:"module_plan"},maxTokens:8e3,...m>0?{thinkingBudgetTokens:m}:{}}),N,T={modules:e.newModules.map(I=>({name:I.name,description:I.description,contentBrief:"Generate appropriate content",layoutNotes:"Use responsive layout"})),moduleOrder:e.newModules.map(I=>I.name),narrative:"Page generated from user request"};if(B.type!=="structured")E.warn("page-architect","Module planner: did not get structured output, using fallback"),N=T;else{let I=B.data;Array.isArray(I?.modules)&&I.modules.length>0?(N=I,N.moduleOrder=N.moduleOrder||N.modules.map(k=>k.name),N.narrative=N.narrative||"Page generated from user request"):(E.warn("page-architect","Module planner: structured output missing 'modules' array, using fallback",{keys:I?Object.keys(I):[]}),N=T),E.info("page-architect","Module plan",{moduleCount:N.modules.length})}return r({type:"agent_decision",step:"designing",decision:`Page: ${N.narrative} | ${N.modules.length} modules planned`}),{designSystem:{cssVariables:f.cssVariables||{},sharedCss:b,sharedJs:f.sharedJs},modules:N.modules,moduleOrder:N.moduleOrder,narrative:N.narrative}}var Uc=R(()=>{"use strict";y();nt();jc();Jc();de()});function ah(t){let e=[...new Set([...t.matchAll(/\.([a-zA-Z][\w-]*)/g)].map(i=>`.${i[1]}`))],n=[...new Set([...t.matchAll(/(--[\w-]+)\s*:/g)].map(i=>i[1]))],s=[...new Set([...t.matchAll(/@media\s*\([^)]+\)/g)].map(i=>i[0]))],o=[];return n.length>0&&o.push(`CSS Variables: ${n.join(", ")}`),e.length>0&&o.push(`CSS Classes: ${e.join(", ")}`),s.length>0&&o.push(`Breakpoints: ${s.join(", ")}`),o.join(`
1682
+ `)}function Gc(t,e,n,s,o){let i=ah(s),r=e.map(c=>`- **${c.label}** (${c.pageType}, slug: "${c.slug}"): ${c.purpose}`).join(`
1683
+ `),a=n.map(c=>`- **${c}**`).join(`
1684
+ `),l=[];return l.push(`You are the Site Module Planner for vibeSpot, a HubSpot CMS page builder.
1685
+
1686
+ Your job: plan modules for a MULTI-PAGE website. You plan ALL pages in one pass to ensure cross-page coherence. You also plan shared modules (header, footer, navigation) that appear on every page identically.
1687
+
1688
+ ## Theme: "${t}"
1689
+
1690
+ ## Site Map
1691
+ ${r}
1692
+
1693
+ ## Shared Modules (appear on EVERY page)
1694
+ ${a}
1695
+
1696
+ Plan these shared modules ONCE. They will be automatically added to every page's template.
1697
+
1698
+ ## Available CSS Classes & Variables
1699
+ Reference these in your layoutNotes:
1700
+
1701
+ ${i}
1702
+
1703
+ ## Shared Module Rules
1704
+
1705
+ ### site-header (Navigation)
1706
+ - Logo on the left, nav links center or right, CTA button far right
1707
+ - Nav links: one for each page in the site map. Use relative hrefs matching slugs:
1708
+ ${e.map(c=>` - "${c.label}" \u2192 href="/${c.slug}"`).join(`
1709
+ `)}
1710
+ - Active page link uses CSS class "${t}-nav__link--active"
1711
+ - Sticky with backdrop-blur, transitions on scroll
1712
+ - Mobile: hamburger menu with slide-in nav
1713
+
1714
+ ### site-footer
1715
+ - Consistent across all pages
1716
+ - Brand name, link columns (include page links), contact info, social icons, copyright
1717
+ - Include navigation links matching the header
1718
+
1719
+ ## Per-Page Module Rules
1720
+ For each page, plan modules specific to that page's purpose. Do NOT include shared modules (${n.join(", ")}) in per-page module lists or per-page moduleOrder \u2014 they are automatically prepended/appended.
1721
+
1722
+ Each page should have distinct content appropriate to its purpose. Aim for:
1723
+ - 4-8 unique modules per page (not counting shared modules)
1724
+ - Content appropriate to the page's purpose
1725
+ - Consistent use of design system classes across all pages
1726
+
1727
+ ## Module Naming
1728
+ - Use kebab-case identifiers (e.g., "hero", "team-grid", "contact-form")
1729
+ - Page-specific modules that might conflict across pages should be prefixed with a short page identifier (e.g., "home-hero", "about-hero") unless the content is genuinely different enough that the name alone distinguishes it
1730
+ - Shared modules use the exact names from the shared modules list above
1731
+
1732
+ ## Output Structure
1733
+ Return a JSON object with:
1734
+ - \`sharedModules\`: array of shared module specs (planned once, used everywhere)
1735
+ - \`pages\`: array of per-page blueprints, each with:
1736
+ - \`pageId\`: matching the page ID from the site map
1737
+ - \`modules\`: array of module specs for that page only (excluding shared)
1738
+ - \`moduleOrder\`: ordered list of per-page module names only (excluding shared)
1739
+ - \`narrative\`: brief description of the overall site story/flow`),o?.brandvoice&&l.push(`
1740
+
1741
+ ## Brand Voice
1742
+ ${o.brandvoice}`),o?.themeContext&&l.push(`
1743
+
1744
+ ## Product Context
1745
+ ${o.themeContext}`),l.join("")}var Wc,Kc=R(()=>{"use strict";y();Wc={type:"object",properties:{sharedModules:{type:"array",items:{type:"object",properties:{name:{type:"string",description:"Shared module identifier (e.g., site-header, site-footer)"},description:{type:"string"},contentBrief:{type:"string",description:"Content for this shared module"},layoutNotes:{type:"string",description:"Layout referencing shared CSS classes"}},required:["name","description","contentBrief","layoutNotes"]},description:"Modules shared across all pages (header, footer)"},pages:{type:"array",items:{type:"object",properties:{pageId:{type:"string",description:"Matches the page ID from the site map"},modules:{type:"array",items:{type:"object",properties:{name:{type:"string"},description:{type:"string"},contentBrief:{type:"string"},layoutNotes:{type:"string"}},required:["name","description","contentBrief","layoutNotes"]}},moduleOrder:{type:"array",items:{type:"string"},description:"Per-page module names in display order (excluding shared modules)"}},required:["pageId","modules","moduleOrder"]}},narrative:{type:"string",description:"Brief description of the overall site story and how pages connect"}},required:["sharedModules","pages","narrative"]}});async function zc(t,e,n,s,o,i,r,a){a({type:"agent_step",step:"planning_site",label:`Planning modules for ${e.pages?.length||0} pages...`});let l=e.pages||[],c=e.sharedModules||["site-header","site-footer"],d=Gc(n.themeName,l,c,s,n.brandAssets),u=`## User Request
1746
+ ${t}
1747
+
1748
+ ## Site Map
1749
+ ${l.map(x=>`- ${x.label} (${x.slug}): ${x.purpose}`).join(`
1750
+ `)}`,m=Sn(o),g=await _e(o,i,r,{systemPrompt:d,messages:[{role:"user",content:u}],structuredOutput:{schema:Wc,name:"site_module_plan"},maxTokens:16e3,...m>0?{thinkingBudgetTokens:m}:{}});if(g.type!=="structured")return E.warn("site-planner","Did not get structured output, building fallback"),Vc(e,c,s);let h=g.data;if(!Array.isArray(h?.pages)||!Array.isArray(h?.sharedModules))return E.warn("site-planner","Structured output missing expected fields",{keys:h?Object.keys(h):[]}),Vc(e,c,s);let f=h.sharedModules.map(x=>({name:x.name,description:x.description,contentBrief:x.contentBrief,layoutNotes:x.layoutNotes})),b=h.pages.map(x=>({pageId:x.pageId,modules:(x.modules||[]).map(w=>({name:w.name,description:w.description,contentBrief:w.contentBrief,layoutNotes:w.layoutNotes})),moduleOrder:x.moduleOrder||[]})),S=f.length+b.reduce((x,w)=>x+w.modules.length,0);return E.info("site-planner","Site plan complete",{pages:b.length,sharedModules:f.length,totalModules:S}),a({type:"agent_decision",step:"planning_site",decision:`${b.length} pages planned, ${f.length} shared modules, ${S} total modules`}),a({type:"site_blueprint_ready",pages:b.map(x=>{let w=l.find(P=>P.id===x.pageId);return{pageId:x.pageId,label:w?.label||x.pageId,moduleCount:x.modules.length}}),sharedModuleCount:f.length}),{designSystem:{cssVariables:{},sharedCss:s},pages:b,sharedModules:f,narrative:h.narrative||"Multi-page site generated from user request"}}function Vc(t,e,n){let s=t.pages||[];return{designSystem:{cssVariables:{},sharedCss:n},pages:s.map(o=>({pageId:o.id,modules:[{name:`${o.slug}-hero`,description:`Hero section for ${o.label}`,contentBrief:`Create a hero for the ${o.label} page: ${o.purpose}`,layoutNotes:"Use responsive layout matching the design system"},{name:`${o.slug}-content`,description:`Main content for ${o.label}`,contentBrief:`Create main content for the ${o.label} page: ${o.purpose}`,layoutNotes:"Use responsive layout matching the design system"}],moduleOrder:[`${o.slug}-hero`,`${o.slug}-content`]})),sharedModules:e.map(o=>({name:o,description:`Shared ${o} module`,contentBrief:`Generate ${o} for the site`,layoutNotes:"Use responsive layout matching the design system"})),narrative:"Multi-page site (fallback plan)"}}var Yc=R(()=>{"use strict";y();nt();Kc();de()});function $o(t){let e=0,n=[];return async function(o){e>=t&&await new Promise(i=>n.push(i)),e++;try{return await o()}finally{e--,n.length>0&&n.shift()()}}}var gr=R(()=>{"use strict";y()});function as(t,e,n,s){let o=[];return o.push(`You are a Module Developer for vibeSpot, a HubSpot CMS page builder.
1136
1751
 
1137
1752
  Your job: generate ONE HubSpot CMS module. You receive a module specification and must produce the complete module code.
1138
1753
 
1139
- ## Theme: "${e}"
1754
+ ## Theme: "${t}"
1140
1755
 
1141
1756
  ## Output Rules \u2014 CRITICAL
1142
1757
  You produce a single module with these fields:
@@ -1148,8 +1763,8 @@ You produce a single module with these fields:
1148
1763
  - **moduleJs**: Optional vanilla JS wrapped in IIFE, or null
1149
1764
 
1150
1765
  ## CSS Rules
1151
- - All CSS classes must use prefix "${e}-"
1152
- - Use BEM naming: ${e}-moduleName__element--modifier
1766
+ - All CSS classes must use prefix "${t}-"
1767
+ - Use BEM naming: ${t}-moduleName__element--modifier
1153
1768
  - Reference the theme's CSS custom properties (shown below)
1154
1769
  - No CDN imports (@import url(), external <link> tags)
1155
1770
  - Use system font stacks \u2014 no Google Fonts
@@ -1166,7 +1781,7 @@ You produce a single module with these fields:
1166
1781
  - For repeater groups, use "occurrence": { "min": 0, "max": 100 }
1167
1782
 
1168
1783
  ## Images & Assets
1169
- - Use get_asset_url("${e}/assets/filename.ext") for uploaded assets
1784
+ - Use get_asset_url("${t}/assets/filename.ext") for uploaded assets
1170
1785
  - For placeholder images, use image fields with placehold.co defaults
1171
1786
  - Size placeholders appropriately (hero: 1920x800, cards: 600x400, icons: 200x200)
1172
1787
 
@@ -1176,37 +1791,37 @@ You produce a single module with these fields:
1176
1791
  - Include smooth scroll behavior in nav click handlers
1177
1792
 
1178
1793
  ## metaJson Template
1179
- { "host_template_types": ["PAGE"], "is_available_for_new_content": true }`),t&&o.push(`
1794
+ { "host_template_types": ["PAGE"], "is_available_for_new_content": true }`),e&&o.push(`
1180
1795
 
1181
1796
  ## Theme Shared CSS (use these custom properties)
1182
1797
  \`\`\`css
1183
- ${t}
1798
+ ${e}
1184
1799
  \`\`\``),(!n||n.includes("hubspot_rules"))&&o.push(`
1185
1800
 
1186
1801
  ## HubSpot CMS Rules
1187
- ${Me()}`),(!n||n.includes("conversion"))&&o.push(`
1802
+ ${je()}`),(!n||n.includes("conversion"))&&o.push(`
1188
1803
 
1189
1804
  ## Conversion Guide
1190
- ${ce()}`),s?.themeContext&&o.push(`
1805
+ ${fe()}`),s?.themeContext&&o.push(`
1191
1806
 
1192
1807
  ## Product Context
1193
1808
  ${s.themeContext}`),s?.humanify!==!1&&n?.includes("humanify")&&o.push(`
1194
1809
 
1195
1810
  ## Anti-AI Copy Rules
1196
- ${Va()}`),o.join("")}function Es(e,t,n,s){let o=[],i=kn(e,"",[],s?{...s,humanify:!1}:void 0);t&&(i+=`
1811
+ ${qc()}`),o.join("")}function _o(t,e,n,s){let o=[],i=as(t,"",[],s?{...s,humanify:!1}:void 0);e&&(i+=`
1197
1812
 
1198
1813
  ## Theme Shared CSS (use these custom properties)
1199
1814
  \`\`\`css
1200
- ${t}
1201
- \`\`\``),o.push({type:"text",text:i});let a=[];(!n||n.includes("hubspot_rules"))&&a.push(`## HubSpot CMS Rules
1202
- ${Me()}`),(!n||n.includes("conversion"))&&a.push(`## Conversion Guide
1203
- ${ce()}`),a.length>0&&o.push({type:"text",text:a.join(`
1815
+ ${e}
1816
+ \`\`\``),o.push({type:"text",text:i});let r=[];(!n||n.includes("hubspot_rules"))&&r.push(`## HubSpot CMS Rules
1817
+ ${je()}`),(!n||n.includes("conversion"))&&r.push(`## Conversion Guide
1818
+ ${fe()}`),r.length>0&&o.push({type:"text",text:r.join(`
1204
1819
 
1205
- `),cache_control:{type:"ephemeral"}});let r=[];return s?.themeContext&&r.push(`## Product Context
1206
- ${s.themeContext}`),s?.humanify!==!1&&n?.includes("humanify")&&r.push(`## Anti-AI Copy Rules
1207
- ${Va()}`),r.length>0&&o.push({type:"text",text:r.join(`
1820
+ `),cache_control:{type:"ephemeral"}});let a=[];return s?.themeContext&&a.push(`## Product Context
1821
+ ${s.themeContext}`),s?.humanify!==!1&&n?.includes("humanify")&&a.push(`## Anti-AI Copy Rules
1822
+ ${qc()}`),a.length>0&&o.push({type:"text",text:a.join(`
1208
1823
 
1209
- `)}),o}function Va(){return`### Banned Punctuation
1824
+ `)}),o}function qc(){return`### Banned Punctuation
1210
1825
  - **Em dashes (\u2014)**: NEVER use. Replace with periods, commas, or parentheses. Hyphens for compounds fine.
1211
1826
  - **Semicolons**: Use periods instead in marketing copy.
1212
1827
  - **Exclamation marks**: One per page max. Zero ideal for B2B.
@@ -1245,14 +1860,14 @@ Never end with: "The future of [X] is here", "Your journey starts here", "Join t
1245
1860
  - Keep slightly imperfect (fragments OK, mild hedging like "honestly didn't think")
1246
1861
  - Full names, specific roles (not "John D., CEO")
1247
1862
  - Never start with "This product is..." \u2014 start with the person's situation
1248
- - Vary length and voice across testimonials`}function Ka(e,t,n){let s=[];return s.push(`## User Request
1249
- ${e}`),s.push(`
1863
+ - Vary length and voice across testimonials`}function Xc(t,e,n){let s=[];return s.push(`## User Request
1864
+ ${t}`),s.push(`
1250
1865
 
1251
1866
  ## Module Specification
1252
- - **Name**: ${t.name}
1253
- - **Description**: ${t.description}
1254
- - **Content Brief**: ${t.contentBrief}
1255
- - **Layout Notes**: ${t.layoutNotes}`),n&&(s.push(`
1867
+ - **Name**: ${e.name}
1868
+ - **Description**: ${e.description}
1869
+ - **Content Brief**: ${e.contentBrief}
1870
+ - **Layout Notes**: ${e.layoutNotes}`),n&&(s.push(`
1256
1871
 
1257
1872
  ## Existing Module Code (modify this)
1258
1873
  **fields.json:**
@@ -1272,21 +1887,487 @@ ${n.moduleCss}
1272
1887
  **module.js:**
1273
1888
  \`\`\`js
1274
1889
  ${n.moduleJs}
1275
- \`\`\``)),s.join("")}var _s,ni=L(()=>{"use strict";f();ot();_s={type:"object",properties:{moduleName:{type:"string"},fieldsJson:{type:"string",description:"Complete fields.json content as a JSON string"},metaJson:{type:"string",description:"Complete meta.json content as a JSON string"},moduleHtml:{type:"string",description:"Complete module.html HubL template content"},moduleCss:{type:"string",description:"Complete module.css vanilla CSS content"},moduleJs:{type:"string",description:"Optional module.js vanilla JS content, or empty string if not needed"}},required:["moduleName","fieldsJson","metaJson","moduleHtml","moduleCss"]}});async function za(e,t,n,s,o,i,a,r,l,c,d){l({type:"agent_step",step:"developing",label:`Generating ${t.length} module${t.length===1?"":"s"}...`});let u=o==="anthropic-api"||o==="claude-oauth",m=kn(s,n,c,d),g=u?Es(s,n,c,d):void 0,y=Is(r),h=t.length,b=t.map((w,S)=>y(async()=>{l({type:"module_progress",module:w.name,status:"generating",current:S+1,total:h});let M="";for(let O=0;O<2;O++)try{O>0&&(A.warn("module-developer",`${w.name}: retrying after failure (attempt ${O+1})`),l({type:"module_progress",module:w.name,status:"retrying",current:S+1,total:h}));let R=await Ya(e,w,m,o,i,a,0,g);return l({type:"module_progress",module:w.name,status:"complete",current:S+1,total:h,moduleFiles:R}),{moduleName:w.name,module:R}}catch(R){M=R instanceof Error?R.message:typeof R=="object"&&R!==null?JSON.stringify(R):String(R),A.error("module-developer",`Failed: ${w.name} (attempt ${O+1})`,{error:M})}return l({type:"module_progress",module:w.name,status:"failed",current:S+1,total:h}),{moduleName:w.name,error:M}}));return(await Promise.allSettled(b)).map(w=>w.status==="fulfilled"?w.value:{moduleName:"unknown",error:w.reason instanceof Error?w.reason.message:String(w.reason)})}async function Ya(e,t,n,s,o,i,a=0,r){let l=Ka(e,t,t.existingCode),c=await Ce(s,o,i,{systemPrompt:n,systemBlocks:r,messages:[{role:"user",content:l}],structuredOutput:{schema:_s,name:"module_output"},maxTokens:16e3});if(c.type!=="structured"){if(a<2)return A.warn("module-developer",`${t.name}: no structured output, retry ${a+1}`),Ya(e,t,n,s,o,i,a+1,r);throw new Error(`Module "${t.name}" failed to produce structured output after ${a+1} attempts`)}let d=c.data,u=typeof d.fieldsJson=="string"?d.fieldsJson:JSON.stringify(d.fieldsJson,null,2),m=typeof d.metaJson=="string"?d.metaJson:JSON.stringify(d.metaJson,null,2);return{moduleName:t.name,fieldsJson:u,metaJson:m,moduleHtml:String(d.moduleHtml||""),moduleCss:String(d.moduleCss||""),moduleJs:d.moduleJs?String(d.moduleJs):void 0}}var qa=L(()=>{"use strict";f();qe();ti();ni();ie()});function Ns(e,t,n){return n({type:"agent_step",step:"quality_check",label:"Quality check..."}),e.map(s=>{let o=[],i={...s};i.fieldsJson=Xa(i.fieldsJson,i.moduleName,"fieldsJson",o),i.metaJson=Xa(i.metaJson,i.moduleName,"metaJson",o),i.fieldsJson=ym(i.fieldsJson,i.moduleName,o),i.fieldsJson=bm(i.fieldsJson,i.moduleName,o),i.moduleCss=Sm(i.moduleCss,i.moduleName,"moduleCss",o),i.moduleCss=vm(i.moduleCss,i.moduleName,t,o),i.moduleHtml=wm(i.moduleHtml,i.moduleName,t,o),i.moduleHtml=km(i.moduleHtml,i.moduleName,o),i.metaJson=Am(i.metaJson,i.moduleName,o);let a=o.every(r=>r.autoFixed);return o.length>0&&A.info("validator",`${i.moduleName}: ${o.length} issues`,{autoFixed:o.filter(r=>r.autoFixed).length,unfixed:o.filter(r=>!r.autoFixed).length}),{module:i,issues:o,valid:a}})}function Xa(e,t,n,s){return!e||e.trim()===""?(s.push({module:t,field:n,message:`Empty ${n}`,autoFixed:n==="metaJson"}),n==="metaJson"?JSON.stringify({host_template_types:["PAGE"],is_available_for_new_content:!0}):e):(ze(e)===null&&s.push({module:t,field:n,message:`Invalid JSON in ${n}`,autoFixed:!1}),e)}function ym(e,t,n){let s=e;return/"name"\s*:\s*"name"/g.test(s)&&(n.push({module:t,field:"fieldsJson",message:'"name" is a reserved field name \u2192 renamed to "item_name"',autoFixed:!0}),s=s.replace(/"name"\s*:\s*"name"/g,'"name": "item_name"')),/"name"\s*:\s*"label"/g.test(s)&&(n.push({module:t,field:"fieldsJson",message:'"label" is a reserved field name \u2192 renamed to "section_label"',autoFixed:!0}),s=s.replace(/"name"\s*:\s*"label"/g,'"name": "section_label"')),s}function bm(e,t,n){let s=e;return/"type"\s*:\s*"textarea"/g.test(s)&&(n.push({module:t,field:"fieldsJson",message:'"textarea" is deprecated \u2192 changed to "text"',autoFixed:!0}),s=s.replace(/"type"\s*:\s*"textarea"/g,'"type": "text"')),s}function Sm(e,t,n,s){if(!e)return e;let o=e,i=/@import\s+url\([^)]*(?:fonts\.googleapis|cdnjs|unpkg|jsdelivr)[^)]*\)\s*;?/gi;return i.test(o)&&(s.push({module:t,field:n,message:"CDN @import removed (external imports not allowed)",autoFixed:!0}),o=o.replace(i,"/* CDN import removed */")),o}function Za(e){return xm.has(e)||e.startsWith("body-wrapper")||e.startsWith("dnd-")||e.startsWith("row-")||e.startsWith("hs-")||e.startsWith("hs_")}function vm(e,t,n,s){if(!e)return e;let o=n+"-",i=/\.([a-zA-Z][\w-]*)/g,a=new Set,r;for(;(r=i.exec(e))!==null;){let c=r[1];!c.startsWith(o)&&!Za(c)&&a.add(c)}if(a.size<=3)return e;let l=e;for(let c of a){let d=new RegExp(`\\.${Cm(c)}(?=[\\s,{:+~>\\[\\]])`,"g");l=l.replace(d,`.${o}${c}`)}return l!==e&&s.push({module:t,field:"moduleCss",message:`${a.size} CSS classes auto-prefixed with "${o}"`,autoFixed:!0}),l}function wm(e,t,n,s){if(!e)return e;let o=n+"-",i=/class="([^"]*)"/g,a=!1,r=e.replace(i,(l,c)=>{let d=c.split(/\s+/),u=!1,m=d.map(g=>g&&!g.startsWith(o)&&!Za(g)&&/^[a-zA-Z][\w-]*$/.test(g)?(u=!0,o+g):g);return u?(a=!0,`class="${m.join(" ")}"`):l});return a&&s.push({module:t,field:"moduleHtml",message:`HTML class references auto-prefixed with "${o}"`,autoFixed:!0}),r}function Cm(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function km(e,t,n){if(!e)return e;let s=e,o=/\{%[-~]?\s*(if|for|block|macro|endif|endfor|endblock|endmacro)\b[^%]*%\}/g,i=[],a;for(;(a=o.exec(s))!==null;){let c=a[1],d=!c.startsWith("end"),u=d?c:c.replace("end","");i.push({tag:c,isOpen:d,baseTag:u,start:a.index,end:a.index+a[0].length})}let r=[],l=[];for(let c=0;c<i.length;c++)if(i[c].isOpen)r.push(c);else{let d=-1;for(let u=r.length-1;u>=0;u--)if(i[r[u]].baseTag===i[c].baseTag){d=u;break}d!==-1?r.splice(d,1):l.push(c)}if(l.length>0){for(let c=l.length-1;c>=0;c--){let d=i[l[c]];s=s.slice(0,d.start)+`<!-- removed orphan {% ${d.tag} %} -->`+s.slice(d.end)}n.push({module:t,field:"moduleHtml",message:`Removed ${l.length} orphan closing tag${l.length===1?"":"s"} with no matching opener`,autoFixed:!0})}if(r.length>0){let c=r.map(u=>i[u].baseTag),d=c.reverse().map(u=>`{% end${u} %}`).join(`
1890
+ \`\`\``)),s.join("")}var ls,fr=R(()=>{"use strict";y();Ue();ls={type:"object",properties:{moduleName:{type:"string"},fieldsJson:{type:"string",description:"Complete fields.json content as a JSON string"},metaJson:{type:"string",description:"Complete meta.json content as a JSON string"},moduleHtml:{type:"string",description:"Complete module.html HubL template content"},moduleCss:{type:"string",description:"Complete module.css vanilla CSS content"},moduleJs:{type:"string",description:"Optional module.js vanilla JS content, or empty string if not needed"}},required:["moduleName","fieldsJson","metaJson","moduleHtml","moduleCss"]}});function hr(t,e){let n=[];if(n.push(`You are an Email Module Developer for vibeSpot, a HubSpot CMS builder.
1891
+
1892
+ Your job: generate ONE HubSpot CMS email module. You receive a module specification and must produce the complete module code optimized for email client rendering.
1893
+
1894
+ ## Theme: "${t}"
1895
+
1896
+ ## CRITICAL: Email vs. Page Differences
1897
+ This is an EMAIL module, not a page module. Email clients (Gmail, Outlook, Apple Mail) have severe rendering limitations:
1898
+ - **NO flexbox, NO grid** \u2014 use HTML tables with role="presentation" for ALL layout
1899
+ - **NO <style> blocks** \u2014 ALL CSS must be inline on every element
1900
+ - **NO CSS custom properties** (var()) \u2014 use literal values
1901
+ - **NO JavaScript** \u2014 module.js must be empty/null
1902
+ - **NO external assets** \u2014 no require_css(), require_js(), get_asset_url(), scope_css
1903
+ - **NO modern CSS** \u2014 no calc(), transform, animation, transition, position, overflow, float
1904
+ - **Container width: 600px** \u2014 the universal email safe width
1905
+
1906
+ ## Output Rules \u2014 CRITICAL
1907
+ You produce a single module with these fields:
1908
+ - **moduleName**: Exact module name (title-case, e.g., "Email Hero")
1909
+ - **fieldsJson**: Valid JSON string \u2014 the module's fields.json content
1910
+ - **metaJson**: Valid JSON string \u2014 must include host_template_types: ["EMAIL"], is_available_for_new_content: true
1911
+ - **moduleHtml**: HubL template using TABLE-BASED layout with ALL CSS inline
1912
+ - **moduleCss**: Empty string (all CSS is inline in moduleHtml)
1913
+ - **moduleJs**: null or empty string (no JS in email)
1914
+
1915
+ ## Layout Rules \u2014 Table-Based Only
1916
+
1917
+ ALL layout MUST use nested tables:
1918
+
1919
+ \`\`\`html
1920
+ <!-- Outer wrapper: centers content -->
1921
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%">
1922
+ <tr>
1923
+ <td align="center" style="padding: 0;">
1924
+ <!-- Inner container: 600px fixed width -->
1925
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600" style="max-width: 600px;">
1926
+ <tr>
1927
+ <td style="padding: 40px 30px;">
1928
+ <!-- Module content here -->
1929
+ </td>
1930
+ </tr>
1931
+ </table>
1932
+ </td>
1933
+ </tr>
1934
+ </table>
1935
+ \`\`\`
1936
+
1937
+ For multi-column layouts, use table cells with explicit widths:
1938
+
1939
+ \`\`\`html
1940
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%">
1941
+ <tr>
1942
+ <td width="50%" valign="top" style="padding-right: 10px;">Left</td>
1943
+ <td width="50%" valign="top" style="padding-left: 10px;">Right</td>
1944
+ </tr>
1945
+ </table>
1946
+ \`\`\`
1947
+
1948
+ ## CSS Rules \u2014 Inline Only
1949
+ - ALL CSS must be inline style attributes on every element
1950
+ - moduleCss must be an empty string \u2014 there are no external stylesheets in email
1951
+ - Use web-safe font stacks: Arial, Helvetica, sans-serif / Georgia, Times New Roman, serif
1952
+ - Font sizes in px only (never rem/em)
1953
+ - Use unitless line-height (1.5) or px (24px)
1954
+ - Repeat font-family on every text element
1955
+ - Set margin: 0 on all headings and paragraphs
1956
+ - No border-radius in Outlook desktop \u2014 include but accept degradation
1957
+
1958
+ ## Inline Style Patterns
1959
+
1960
+ \`\`\`html
1961
+ <!-- Heading -->
1962
+ <h1 style="margin: 0 0 16px 0; font-family: Arial, Helvetica, sans-serif; font-size: 28px; font-weight: bold; line-height: 1.2; color: #1a1a2e;">
1963
+ {{ module.heading }}
1964
+ </h1>
1965
+
1966
+ <!-- Body text -->
1967
+ <p style="margin: 0 0 16px 0; font-family: Arial, Helvetica, sans-serif; font-size: 16px; line-height: 1.5; color: #4a4a4a;">
1968
+ {{ module.body_text }}
1969
+ </p>
1970
+
1971
+ <!-- Button (bulletproof) -->
1972
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0">
1973
+ <tr>
1974
+ <td align="center" style="border-radius: 4px; background-color: #e8613a;">
1975
+ <a href="{{ module.cta_link.url.href }}" target="_blank"
1976
+ style="display: inline-block; padding: 14px 32px; font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold; color: #ffffff; text-decoration: none; border-radius: 4px; background-color: #e8613a;">
1977
+ {{ module.cta_text }}
1978
+ </a>
1979
+ </td>
1980
+ </tr>
1981
+ </table>
1982
+
1983
+ <!-- Image -->
1984
+ <img src="{{ module.hero_image.src }}" alt="{{ module.hero_image.alt }}"
1985
+ width="560" height="300"
1986
+ style="display: block; border: 0; outline: none; text-decoration: none; max-width: 100%; height: auto;" />
1987
+ \`\`\`
1988
+
1989
+ ## MSO Conditionals \u2014 Outlook Desktop
1990
+
1991
+ Wrap the outer container with MSO conditionals so Outlook desktop respects the 600px width:
1992
+
1993
+ \`\`\`html
1994
+ <!--[if mso]>
1995
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"><tr><td>
1996
+ <![endif]-->
1997
+ <div style="max-width: 600px; margin: 0 auto;">
1998
+ <!-- content -->
1999
+ </div>
2000
+ <!--[if mso]>
2001
+ </td></tr></table>
2002
+ <![endif]-->
2003
+ \`\`\`
2004
+
2005
+ ## Field Rules
2006
+ - Use "type": "text" (NEVER "textarea" \u2014 it's deprecated)
2007
+ - NEVER use "name": "name" (reserved) \u2014 use "item_name" instead
2008
+ - NEVER use "name": "label" (reserved) \u2014 use "section_label" instead
2009
+ - NEVER put literal \\n in field defaults
2010
+ - Color fields: type "color", default { "color": "#hex", "opacity": 100 }
2011
+ - Link fields: type "link", default { "url": { "href": "#", "type": "EXTERNAL" }, "open_in_new_tab": true, "no_follow": false }
2012
+ - Image fields: type "image", default { "src": "https://placehold.co/560x300/1a1a2e/ffffff?text=Replace+in+HubSpot", "alt": "Placeholder", "width": 560, "height": 300 }
2013
+ - For repeater groups, use "occurrence": { "min": 0, "max": 10 }
2014
+
2015
+ ## Images
2016
+ - Use image fields with placehold.co defaults \u2014 no get_asset_url()
2017
+ - Maximum image width: 560px (600px container minus 20px padding each side)
2018
+ - Always set explicit width and height attributes AND style
2019
+ - Always include alt text, display: block, border: 0
2020
+
2021
+ ## HubL for Email \u2014 Safe Subset ONLY
2022
+ Allowed:
2023
+ - {{ module.field_name }} / {{ module.field_name|escape }}
2024
+ - {% if %} / {% endif %}, {% for %} / {% endfor %}
2025
+ - {{ module.color_field.color }}, {{ module.link_field.url.href }}, {{ module.image_field.src }}
2026
+ - {{ unsubscribe_link }}, {{ site_settings.company_name }}, {{ view_as_page_url }}
2027
+
2028
+ NEVER use:
2029
+ - require_css() / require_js()
2030
+ - scope_css
2031
+ - get_asset_url()
2032
+ - now() / local_dt
2033
+ - dnd_area / dnd_section / dnd_module
2034
+
2035
+ ## metaJson Template
2036
+ { "host_template_types": ["EMAIL"], "is_available_for_new_content": true }
2037
+
2038
+ ## Email-Specific Required Elements
2039
+ Modules that serve as email footers MUST include:
2040
+ - Unsubscribe link: <a href="{{ unsubscribe_link }}">Unsubscribe</a>
2041
+ - Physical address: {{ site_settings.company_street_address_1 }}, {{ site_settings.company_city }}, {{ site_settings.company_state }}
2042
+ - Company name: {{ site_settings.company_name }}`),e?.themeContext&&n.push(`
2043
+
2044
+ ## Product Context
2045
+ ${e.themeContext}`),e?.humanify!==!1&&n.push(`
2046
+
2047
+ ## Anti-AI Copy Rules
2048
+ ${Qc()}`),e?.brandKit){let s=[];e.brandKit.colors&&(e.brandKit.colors.primary&&s.push(`- Primary color: ${e.brandKit.colors.primary}`),e.brandKit.colors.secondary&&s.push(`- Secondary color: ${e.brandKit.colors.secondary}`),e.brandKit.colors.accent&&s.push(`- Accent color: ${e.brandKit.colors.accent}`)),e.brandKit.fonts&&(e.brandKit.fonts.heading&&s.push(`- Heading font: ${e.brandKit.fonts.heading}`),e.brandKit.fonts.body&&s.push(`- Body font: ${e.brandKit.fonts.body}`)),e.brandKit.logoUrl&&s.push(`- Logo URL: ${e.brandKit.logoUrl}`),s.length>0&&n.push(`
2049
+
2050
+ ## Brand Kit \u2014 MANDATORY Design Constraints
2051
+ The following brand identity values MUST be used. Do NOT substitute or override them:
2052
+ ${s.join(`
2053
+ `)}`)}return n.join("")}function Zc(t,e){let n=[],s=hr(t,{...e,humanify:!1});n.push({type:"text",text:s});let o;try{o=Pa()}catch{o=""}o&&n.push({type:"text",text:`## Email Template Rules Reference
2054
+ ${o}`,cache_control:{type:"ephemeral"}});let i=[];return e?.themeContext&&i.push(`## Product Context
2055
+ ${e.themeContext}`),e?.humanify!==!1&&i.push(`## Anti-AI Copy Rules
2056
+ ${Qc()}`),i.length>0&&n.push({type:"text",text:i.join(`
2057
+
2058
+ `)}),n}function Qc(){return`### Banned Punctuation
2059
+ - **Em dashes (\u2014)**: NEVER use. Replace with periods, commas, or parentheses.
2060
+ - **Semicolons**: Use periods instead.
2061
+ - **Exclamation marks**: One per email max. Zero ideal for B2B.
2062
+
2063
+ ### Banned Words
2064
+ **HARD BANNED:**
2065
+ delve, tapestry, multifaceted, utilize, harness, bolster, underscore, illuminate, facilitate, fostering, garner, pivotal, commence, endeavor, myriad, plethora, pertinent, aforementioned, beacon, synergy, paradigm, bespoke, holistic, spearhead, embark, reimagine, cultivate, cornerstone
2066
+
2067
+ **SOFT BANNED (rewrite unless truly earned):**
2068
+ seamless, cutting-edge, groundbreaking, game-changer, revolutionary, transformative, innovative, robust, comprehensive, elevate, unlock, streamline, optimize, curated
2069
+
2070
+ ### Banned Openers
2071
+ Never start with: "In today's", "In an era", "Whether you're", "Imagine a world", "Here's the thing", "Say goodbye to", "Gone are the days"
2072
+
2073
+ ### Positive Rules
2074
+ - Be concrete: "42 minutes" not "fast", "\u20AC29/month" not "affordable"
2075
+ - Use plain words: use > utilize, start > commence, help > facilitate
2076
+ - Front-load the benefit in the first 5 words
2077
+ - Email subject lines: specific, benefit-first, under 50 chars`}function ed(t,e,n){let s=[];return s.push(`## User Request
2078
+ ${t}`),s.push(`
2079
+
2080
+ ## Email Module Specification
2081
+ - **Name**: ${e.name}
2082
+ - **Description**: ${e.description}
2083
+ - **Content Brief**: ${e.contentBrief}
2084
+ - **Layout Notes**: ${e.layoutNotes}
2085
+
2086
+ REMEMBER: This is an EMAIL module. ALL layout must use tables. ALL CSS must be inline. NO external stylesheets. NO JavaScript.`),n&&s.push(`
2087
+
2088
+ ## Existing Module Code (modify this)
2089
+ **fields.json:**
2090
+ \`\`\`json
2091
+ ${n.fieldsJson}
2092
+ \`\`\`
2093
+
2094
+ **module.html:**
2095
+ \`\`\`html
2096
+ ${n.moduleHtml}
2097
+ \`\`\``),s.join("")}var td,nd=R(()=>{"use strict";y();Ue();td={type:"object",properties:{moduleName:{type:"string"},fieldsJson:{type:"string",description:"Complete fields.json content as a JSON string"},metaJson:{type:"string",description:'Complete meta.json content \u2014 must include host_template_types: ["EMAIL"]'},moduleHtml:{type:"string",description:"Complete module.html with TABLE-BASED layout and ALL CSS inline. No <style> blocks."},moduleCss:{type:"string",description:"Must be empty string \u2014 all CSS is inline in moduleHtml for email"},moduleJs:{type:"string",description:"Must be empty string \u2014 no JavaScript in email"}},required:["moduleName","fieldsJson","metaJson","moduleHtml"]}});function yr(t,e,n,s){let o=[];o.push(`You are a Blog Module Developer for vibeSpot, a HubSpot CMS builder.
2098
+
2099
+ Your job: generate ONE HubSpot CMS blog module. You receive a module specification and must produce the complete module code optimized for blog templates.
2100
+
2101
+ ## Theme: "${t}"
2102
+
2103
+ ## CRITICAL: Blog Template Context
2104
+ This is a BLOG module. Blog modules are used in HubSpot blog post and blog listing templates. They differ from page modules in these key ways:
2105
+ - **Blog post modules** use HubSpot blog variables (\`{{ content.post_body }}\`, \`{{ content.author }}\`, \`{{ content.tag_list }}\`, etc.)
2106
+ - **Blog listing modules** use \`{% for content in contents %}\` to loop over posts
2107
+ - **Reading-optimized design** \u2014 wider line heights, constrained content width (680-720px), generous spacing
2108
+ - **host_template_types** must be \`["BLOG_POST"]\`, \`["BLOG_LISTING"]\`, or \`["BLOG_POST", "BLOG_LISTING"]\`
2109
+
2110
+ ## Output Rules \u2014 CRITICAL
2111
+ You produce a single module with these fields:
2112
+ - **moduleName**: Exact module name (kebab-case, e.g., "blog-post-header")
2113
+ - **fieldsJson**: Valid JSON string \u2014 the module's fields.json content
2114
+ - **metaJson**: Valid JSON string \u2014 must include the correct host_template_types and is_available_for_new_content: true
2115
+ - **moduleHtml**: HubL template using blog variables where appropriate
2116
+ - **moduleCss**: Vanilla CSS (no Tailwind, no Sass, no CDN imports)
2117
+ - **moduleJs**: Optional vanilla JS wrapped in IIFE, or null
2118
+
2119
+ ## CSS Rules
2120
+ - All CSS classes must use prefix "${t}-"
2121
+ - Use BEM naming: ${t}-moduleName__element--modifier
2122
+ - Reference the theme's CSS custom properties (shown below)
2123
+ - No CDN imports (@import url(), external <link> tags)
2124
+ - Use system font stacks \u2014 no Google Fonts
2125
+
2126
+ ## Reading-Optimized Design Tokens
2127
+ Blog modules should use these design principles:
2128
+ - Body text: 18-20px for long-form readability
2129
+ - Line height: 1.6-1.8 for body copy
2130
+ - Content width: 680-720px max for article body
2131
+ - Generous paragraph spacing: 1.5em between paragraphs
2132
+ - Clear heading hierarchy with adequate spacing
2133
+ - High contrast for body text (WCAG AA minimum)
2134
+
2135
+ ## Shared CSS (use these variables)
2136
+ \`\`\`css
2137
+ ${e||"/* No shared CSS yet \u2014 create appropriate custom properties */"}
2138
+ \`\`\`
2139
+
2140
+ ## HubSpot Blog Variables \u2014 Use These
2141
+
2142
+ ### Blog Post Variables
2143
+ \`\`\`
2144
+ {{ content.name }} \u2014 Post title
2145
+ {{ content.post_body }} \u2014 Full post body HTML
2146
+ {{ content.featured_image }} \u2014 Featured image URL
2147
+ {{ content.featured_image_alt_text }} \u2014 Featured image alt text
2148
+ {{ content.publish_date }} \u2014 Publish date
2149
+ {{ content.blog_post_author }} \u2014 Author name
2150
+ {{ content.author.display_name }} \u2014 Author display name
2151
+ {{ content.author.avatar }} \u2014 Author avatar URL
2152
+ {{ content.author.bio }} \u2014 Author bio
2153
+ {{ content.tag_list }} \u2014 Tags (iterable)
2154
+ {{ content.topic_list }} \u2014 Topics (iterable)
2155
+ {{ content.absolute_url }} \u2014 Canonical URL
2156
+ {{ content.meta_description }} \u2014 Excerpt / meta description
2157
+ \`\`\`
2158
+
2159
+ ### Blog Listing Variables
2160
+ \`\`\`html
2161
+ {% for content in contents %}
2162
+ {{ content.name }} \u2014 Post title
2163
+ {{ content.absolute_url }} \u2014 Post URL
2164
+ {{ content.featured_image }} \u2014 Featured image
2165
+ {{ content.meta_description }} \u2014 Excerpt
2166
+ {{ content.publish_date }} \u2014 Date
2167
+ {{ content.blog_post_author }} \u2014 Author
2168
+ {% endfor %}
2169
+
2170
+ {{ group.public_title }} \u2014 Blog name
2171
+ {{ group.description }} \u2014 Blog description
2172
+ \`\`\`
2173
+
2174
+ ### Date Formatting
2175
+ \`\`\`html
2176
+ {{ content.publish_date|datetimeformat('%B %d, %Y') }}
2177
+ \`\`\`
2178
+
2179
+ ### Pagination (for listing modules)
2180
+ \`\`\`html
2181
+ {% if last_page_num > 1 %}
2182
+ {% if current_page_num > 1 %}
2183
+ <a href="{{ blog_page_link(current_page_num - 1) }}">Previous</a>
2184
+ {% endif %}
2185
+ {% for page_num in range(1, last_page_num + 1) %}
2186
+ {% if page_num == current_page_num %}
2187
+ <span>{{ page_num }}</span>
2188
+ {% else %}
2189
+ <a href="{{ blog_page_link(page_num) }}">{{ page_num }}</a>
2190
+ {% endif %}
2191
+ {% endfor %}
2192
+ {% if current_page_num < last_page_num %}
2193
+ <a href="{{ blog_page_link(current_page_num + 1) }}">Next</a>
2194
+ {% endif %}
2195
+ {% endif %}
2196
+ \`\`\`
2197
+
2198
+ ### Tag Filtering
2199
+ \`\`\`html
2200
+ {% set topics = blog_topics(group.id, 250) %}
2201
+ {% for topic in topics %}
2202
+ <a href="{{ blog_tag_url(group.id, topic.slug) }}">{{ topic.name }}</a>
2203
+ {% endfor %}
2204
+ \`\`\`
2205
+
2206
+ ### Related Posts
2207
+ \`\`\`html
2208
+ {% set recent = blog_recent_posts(group.id, 3) %}
2209
+ {% for post in recent %}
2210
+ {% if post.absolute_url != content.absolute_url %}
2211
+ <a href="{{ post.absolute_url }}">{{ post.name }}</a>
2212
+ {% endif %}
2213
+ {% endfor %}
2214
+ \`\`\`
2215
+
2216
+ ## Field Rules
2217
+ - Use "type": "text" (NEVER "textarea" \u2014 it's deprecated)
2218
+ - NEVER use "name": "name" (reserved) \u2014 use "item_name" instead
2219
+ - NEVER use "name": "label" (reserved) \u2014 use "section_label" instead
2220
+ - NEVER put literal \\n in field defaults
2221
+ - Wrap style fields in a "styles" group with "tab": "STYLE"
2222
+ - Color fields: type "color", default { "color": "#hex", "opacity": 100 }
2223
+ - Link fields: type "link", default { "url": { "href": "#", "type": "EXTERNAL" }, "open_in_new_tab": true, "no_follow": false }
2224
+ - Image fields: type "image", default { "src": "https://placehold.co/800x450/1a1a2e/ffffff?text=Replace+in+HubSpot", "alt": "Placeholder", "width": 800, "height": 450 }
2225
+ - For repeater groups, use "occurrence": { "min": 0, "max": 10 }
2226
+
2227
+ ## metaJson Templates
2228
+
2229
+ For blog post modules:
2230
+ { "host_template_types": ["BLOG_POST"], "is_available_for_new_content": true }
2231
+
2232
+ For blog listing modules:
2233
+ { "host_template_types": ["BLOG_LISTING"], "is_available_for_new_content": true }
2234
+
2235
+ For modules usable in both:
2236
+ { "host_template_types": ["BLOG_POST", "BLOG_LISTING"], "is_available_for_new_content": true }
2237
+
2238
+ ## Module Type Detection
2239
+ Determine the correct host_template_types from the module specification:
2240
+ - Modules with "listing", "grid", "archive", "index", "pagination", "topic-filter", "category" in the name/description \u2192 BLOG_LISTING
2241
+ - Modules with "post-body", "post-header", "author-bio", "related-posts", "comments", "share" in the name/description \u2192 BLOG_POST
2242
+ - Generic modules like "newsletter-signup", "sidebar" \u2192 both ["BLOG_POST", "BLOG_LISTING"]
2243
+
2244
+ ## Key Patterns
2245
+
2246
+ ### Blog Post Body Wrapper
2247
+ The blog post body module wraps \`{{ content.post_body }}\` with reading-optimized styles:
2248
+ \`\`\`html
2249
+ <article class="${t}-post-body">
2250
+ <div class="${t}-post-body__content">
2251
+ {{ content.post_body }}
2252
+ </div>
2253
+ </article>
2254
+ \`\`\`
2255
+
2256
+ ### Post Card (for listing)
2257
+ \`\`\`html
2258
+ {% for content in contents %}
2259
+ <article class="${t}-post-card">
2260
+ {% if content.featured_image %}
2261
+ <img src="{{ content.featured_image }}" alt="{{ content.featured_image_alt_text }}"
2262
+ class="${t}-post-card__image" loading="lazy" />
2263
+ {% endif %}
2264
+ <div class="${t}-post-card__content">
2265
+ <span class="${t}-post-card__date">
2266
+ {{ content.publish_date|datetimeformat('%B %d, %Y') }}
2267
+ </span>
2268
+ <h2 class="${t}-post-card__title">
2269
+ <a href="{{ content.absolute_url }}">{{ content.name }}</a>
2270
+ </h2>
2271
+ <p class="${t}-post-card__excerpt">{{ content.meta_description|truncate(160) }}</p>
2272
+ <span class="${t}-post-card__author">{{ content.blog_post_author }}</span>
2273
+ </div>
2274
+ </article>
2275
+ {% endfor %}
2276
+ \`\`\``),s?.themeContext&&o.push(`
2277
+
2278
+ ## Product Context
2279
+ ${s.themeContext}`),s?.humanify!==!1&&o.push(`
2280
+
2281
+ ## Anti-AI Copy Rules
2282
+ ${od()}`);let i=[];if(n?.includes("conversion"))try{let r=fe();r&&i.push(`## Conversion Guide
2283
+ ${r}`)}catch{}if(n?.includes("hubspot_rules"))try{let r=je();r&&i.push(`## HubSpot Rules
2284
+ ${r}`)}catch{}return i.length>0&&o.push(`
2285
+
2286
+ ${i.join(`
2287
+
2288
+ `)}`),o.join("")}function sd(t,e,n,s){let o=[],i=yr(t,e,void 0,{...s,humanify:!1});o.push({type:"text",text:i});let r;try{r=Ra()}catch{r=""}r&&o.push({type:"text",text:`## Blog Template Rules Reference
2289
+ ${r}`,cache_control:{type:"ephemeral"}});let a=[];if(n?.includes("conversion"))try{let c=fe();c&&a.push(`## Conversion Guide
2290
+ ${c}`)}catch{}if(n?.includes("hubspot_rules"))try{let c=je();c&&a.push(`## HubSpot Rules
2291
+ ${c}`)}catch{}a.length>0&&o.push({type:"text",text:a.join(`
2292
+
2293
+ `),cache_control:{type:"ephemeral"}});let l=[];return s?.themeContext&&l.push(`## Product Context
2294
+ ${s.themeContext}`),s?.humanify!==!1&&l.push(`## Anti-AI Copy Rules
2295
+ ${od()}`),l.length>0&&o.push({type:"text",text:l.join(`
2296
+
2297
+ `)}),o}function od(){return`### Banned Punctuation
2298
+ - **Em dashes (\u2014)**: NEVER use. Replace with periods, commas, or parentheses.
2299
+ - **Semicolons**: Use periods instead.
2300
+ - **Exclamation marks**: Maximum one per page. Zero ideal for B2B.
2301
+
2302
+ ### Banned Words
2303
+ **HARD BANNED:**
2304
+ delve, tapestry, multifaceted, utilize, harness, bolster, underscore, illuminate, facilitate, fostering, garner, pivotal, commence, endeavor, myriad, plethora, pertinent, aforementioned, beacon, synergy, paradigm, bespoke, holistic, spearhead, embark, reimagine, cultivate, cornerstone
2305
+
2306
+ **SOFT BANNED (rewrite unless truly earned):**
2307
+ seamless, cutting-edge, groundbreaking, game-changer, revolutionary, transformative, innovative, robust, comprehensive, elevate, unlock, streamline, optimize, curated
2308
+
2309
+ ### Banned Openers
2310
+ Never start with: "In today's", "In an era", "Whether you're", "Imagine a world", "Here's the thing", "Say goodbye to", "Gone are the days"
2311
+
2312
+ ### Positive Rules
2313
+ - Be concrete: "42 minutes" not "fast", "\u20AC29/month" not "affordable"
2314
+ - Use plain words: use > utilize, start > commence, help > facilitate
2315
+ - Front-load the benefit in the first 5 words
2316
+ - Blog headlines: specific, benefit-first, no clickbait`}function id(t,e,n){let s=[];return s.push(`## User Request
2317
+ ${t}`),s.push(`
2318
+
2319
+ ## Blog Module Specification
2320
+ - **Name**: ${e.name}
2321
+ - **Description**: ${e.description}
2322
+ - **Content Brief**: ${e.contentBrief}
2323
+ - **Layout Notes**: ${e.layoutNotes}
2324
+
2325
+ REMEMBER: This is a BLOG module. Use HubSpot blog variables where appropriate (content.post_body, content.author, content.tag_list, etc.). Set the correct host_template_types in meta.json (BLOG_POST, BLOG_LISTING, or both).`),n&&s.push(`
2326
+
2327
+ ## Existing Module Code (modify this)
2328
+ **fields.json:**
2329
+ \`\`\`json
2330
+ ${n.fieldsJson}
2331
+ \`\`\`
2332
+
2333
+ **module.html:**
2334
+ \`\`\`html
2335
+ ${n.moduleHtml}
2336
+ \`\`\`
2337
+
2338
+ **module.css:**
2339
+ \`\`\`css
2340
+ ${n.moduleCss}
2341
+ \`\`\``),s.join("")}var rd,ad=R(()=>{"use strict";y();Ue();Ue();rd={type:"object",properties:{moduleName:{type:"string"},fieldsJson:{type:"string",description:"Complete fields.json content as a JSON string"},metaJson:{type:"string",description:'Complete meta.json content \u2014 must include host_template_types with "BLOG_POST" and/or "BLOG_LISTING"'},moduleHtml:{type:"string",description:"Complete module.html using HubSpot blog variables where appropriate"},moduleCss:{type:"string",description:"Complete module.css with reading-optimized styles"},moduleJs:{type:"string",description:"Optional module.js (vanilla JS in IIFE) or empty string"}},required:["moduleName","fieldsJson","metaJson","moduleHtml","moduleCss"]}});async function cs(t,e,n,s,o,i,r,a,l,c,d,u){let m=u==="email",g=u==="blog",h=m?"email module":g?"blog module":"module";l({type:"agent_step",step:"developing",label:`Generating ${e.length} ${h}${e.length===1?"":"s"}...`});let f=o==="anthropic-api"||o==="claude-oauth",b=m?hr(s,d):g?yr(s,n,c,d):as(s,n,c,d),S=f?m?Zc(s,d):g?sd(s,n,c,d):_o(s,n,c,d):void 0,x=$o(a),w=e.length,P=m?td:g?rd:ls,F=e.map((L,V)=>x(async()=>{l({type:"module_progress",module:L.name,status:"generating",current:V+1,total:w});let B="";for(let N=0;N<2;N++)try{N>0&&(E.warn("module-developer",`${L.name}: retrying after failure (attempt ${N+1})`),l({type:"module_progress",module:L.name,status:"retrying",current:V+1,total:w}));let T=await ld(t,L,b,o,i,r,0,S,m,P,g);return l({type:"module_progress",module:L.name,status:"complete",current:V+1,total:w,moduleFiles:T}),{moduleName:L.name,module:T}}catch(T){B=T instanceof Error?T.message:typeof T=="object"&&T!==null?JSON.stringify(T):String(T),E.error("module-developer",`Failed: ${L.name} (attempt ${N+1})`,{error:B})}return l({type:"module_progress",module:L.name,status:"failed",current:V+1,total:w}),{moduleName:L.name,error:B}}));return(await Promise.allSettled(F)).map(L=>L.status==="fulfilled"?L.value:{moduleName:"unknown",error:L.reason instanceof Error?L.reason.message:String(L.reason)})}async function ld(t,e,n,s,o,i,r=0,a,l=!1,c=ls,d=!1){let u=l?ed(t,e,e.existingCode):d?id(t,e,e.existingCode):Xc(t,e,e.existingCode),m=await _e(s,o,i,{systemPrompt:n,systemBlocks:a,messages:[{role:"user",content:u}],structuredOutput:{schema:c,name:"module_output"},maxTokens:16e3});if(m.type!=="structured"){if(r<2)return E.warn("module-developer",`${e.name}: no structured output, retry ${r+1}`),ld(t,e,n,s,o,i,r+1,a,l,c,d);throw new Error(`Module "${e.name}" failed to produce structured output after ${r+1} attempts`)}let g=m.data,h=typeof g.fieldsJson=="string"?g.fieldsJson:JSON.stringify(g.fieldsJson,null,2),f=typeof g.metaJson=="string"?g.metaJson:JSON.stringify(g.metaJson,null,2);return{moduleName:e.name,fieldsJson:h,metaJson:f,moduleHtml:String(g.moduleHtml||""),moduleCss:l?"":String(g.moduleCss||""),moduleJs:l?void 0:g.moduleJs?String(g.moduleJs):void 0}}var cd=R(()=>{"use strict";y();nt();gr();fr();nd();ad();de()});function zt(t,e,n,s,o){let i=s==="email",r=s==="blog";return n({type:"agent_step",step:"quality_check",label:i?"Email quality check...":r?"Blog quality check...":"Quality check..."}),t.map(a=>{let l=[],c={...a};c.fieldsJson=dd(c.fieldsJson,c.moduleName,"fieldsJson",l,i),c.metaJson=dd(c.metaJson,c.moduleName,"metaJson",l,i,r),c.fieldsJson=lh(c.fieldsJson,c.moduleName,l),c.fieldsJson=ch(c.fieldsJson,c.moduleName,l),i?c=Sh(c,l):(c.moduleCss=dh(c.moduleCss,c.moduleName,"moduleCss",l),c.moduleCss=mh(c.moduleCss,c.moduleName,e,l),c.moduleHtml=ph(c.moduleHtml,c.moduleName,e,l),r&&(c=xh(c,l))),c.moduleHtml=fh(c.moduleHtml,c.moduleName,l),c.metaJson=hh(c.metaJson,c.moduleName,l,i,r),o&&bh(c,o,l);let d=l.every(u=>u.autoFixed);return l.length>0&&E.info("validator",`${c.moduleName}: ${l.length} issues`,{autoFixed:l.filter(u=>u.autoFixed).length,unfixed:l.filter(u=>!u.autoFixed).length}),{module:c,issues:l,valid:d}})}function dd(t,e,n,s,o=!1,i=!1){return!t||t.trim()===""?(s.push({module:e,field:n,message:`Empty ${n}`,autoFixed:n==="metaJson"}),n==="metaJson"?JSON.stringify({host_template_types:[o?"EMAIL":i?"BLOG_POST":"PAGE"],is_available_for_new_content:!0}):t):ft(t)===null?(s.push({module:e,field:n,message:`Invalid JSON in ${n} \u2014 reset to empty`,autoFixed:!0}),n==="fieldsJson"?"[]":JSON.stringify({host_template_types:[o?"EMAIL":i?"BLOG_POST":"PAGE"],is_available_for_new_content:!0})):t}function lh(t,e,n){let s=t;return/"name"\s*:\s*"name"/g.test(s)&&(n.push({module:e,field:"fieldsJson",message:'"name" is a reserved field name \u2192 renamed to "item_name"',autoFixed:!0}),s=s.replace(/"name"\s*:\s*"name"/g,'"name": "item_name"')),/"name"\s*:\s*"label"/g.test(s)&&(n.push({module:e,field:"fieldsJson",message:'"label" is a reserved field name \u2192 renamed to "section_label"',autoFixed:!0}),s=s.replace(/"name"\s*:\s*"label"/g,'"name": "section_label"')),s}function ch(t,e,n){let s=t;return/"type"\s*:\s*"textarea"/g.test(s)&&(n.push({module:e,field:"fieldsJson",message:'"textarea" is deprecated \u2192 changed to "text"',autoFixed:!0}),s=s.replace(/"type"\s*:\s*"textarea"/g,'"type": "text"')),s}function dh(t,e,n,s){if(!t)return t;let o=t,i=/@import\s+url\([^)]*(?:fonts\.googleapis|cdnjs|unpkg|jsdelivr)[^)]*\)\s*;?/gi;return i.test(o)&&(s.push({module:e,field:n,message:"CDN @import removed (external imports not allowed)",autoFixed:!0}),o=o.replace(i,"/* CDN import removed */")),o}function ud(t){return uh.has(t)||t.startsWith("body-wrapper")||t.startsWith("dnd-")||t.startsWith("row-")||t.startsWith("hs-")||t.startsWith("hs_")}function mh(t,e,n,s){if(!t)return t;let o=n+"-",i=/\.([a-zA-Z][\w-]*)/g,r=new Set,a;for(;(a=i.exec(t))!==null;){let c=a[1];!c.startsWith(o)&&!ud(c)&&r.add(c)}if(r.size<=3)return t;let l=t;for(let c of r){let d=new RegExp(`\\.${gh(c)}(?=[\\s,{:+~>\\[\\]])`,"g");l=l.replace(d,`.${o}${c}`)}return l!==t&&s.push({module:e,field:"moduleCss",message:`${r.size} CSS classes auto-prefixed with "${o}"`,autoFixed:!0}),l}function ph(t,e,n,s){if(!t)return t;let o=n+"-",i=/class="([^"]*)"/g,r=!1,a=t.replace(i,(l,c)=>{let d=/(\{%[-~]?[\s\S]*?[-~]?%\}|\{\{[\s\S]*?\}\})/g,u=c.split(d),m=!1,g=u.map((h,f)=>f%2===1?h:h.split(/(\s+)/).map(b=>/^\s*$/.test(b)?b:b&&!b.startsWith(o)&&!ud(b)&&/^[a-zA-Z][\w-]*$/.test(b)?(m=!0,o+b):b).join("")).join("");return m?(r=!0,`class="${g}"`):l});return r&&s.push({module:e,field:"moduleHtml",message:`HTML class references auto-prefixed with "${o}"`,autoFixed:!0}),a}function gh(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function fh(t,e,n){if(!t)return t;let s=t,i=["if","elif","else","endif","for","endfor","set","do","block","endblock","macro","endmacro","call","endcall","filter","endfilter","raw","endraw","include","import","from","extends","print","unless","endunless","is","not","and","or","in"].join("|"),r=new RegExp(`\\b[a-zA-Z][\\w-]*-(${i})\\b(?!-)`,"g"),a=/(\{%[-~]?[\s\S]*?[-~]?%\})/g,l=!1;s=s.replace(a,h=>h.replace(r,(b,S)=>(l=!0,S))),l&&n.push({module:e,field:"moduleHtml",message:"Stripped CSS-class prefix from HubL keywords inside {% %} tags",autoFixed:!0});let c=/\{%[-~]?\s*(if|for|block|macro|endif|endfor|endblock|endmacro)\b[^%]*%\}/g,d=[],u;for(;(u=c.exec(s))!==null;){let h=u[1],f=!h.startsWith("end"),b=f?h:h.replace("end","");d.push({tag:h,isOpen:f,baseTag:b,start:u.index,end:u.index+u[0].length})}let m=[],g=[];for(let h=0;h<d.length;h++)if(d[h].isOpen)m.push(h);else{let f=-1;for(let b=m.length-1;b>=0;b--)if(d[m[b]].baseTag===d[h].baseTag){f=b;break}f!==-1?m.splice(f,1):g.push(h)}if(g.length>0){for(let h=g.length-1;h>=0;h--){let f=d[g[h]];s=s.slice(0,f.start)+`<!-- removed orphan {% ${f.tag} %} -->`+s.slice(f.end)}n.push({module:e,field:"moduleHtml",message:`Removed ${g.length} orphan closing tag${g.length===1?"":"s"} with no matching opener`,autoFixed:!0})}if(m.length>0){let h=m.map(b=>d[b].baseTag),f=h.reverse().map(b=>`{% end${b} %}`).join(`
1276
2342
  `);s=`${s}
1277
- ${d}`,n.push({module:t,field:"moduleHtml",message:`Added ${c.length} missing closing tag${c.length===1?"":"s"}: ${c.map(u=>`{% end${u} %}`).join(", ")}`,autoFixed:!0})}return/\bnow\(\)/.test(s)&&(s=s.replace(/\bnow\(\)/g,"local_dt"),n.push({module:t,field:"moduleHtml",message:"Replaced now() with local_dt (now() is not valid HubL)",autoFixed:!0})),s}function Am(e,t,n){let s=ze(e);if(!s||typeof s!="object")return e;let o=s,i=!1;return o.host_template_types||(o.host_template_types=["PAGE"],i=!0),o.is_available_for_new_content===void 0&&(o.is_available_for_new_content=!0,i=!0),i?(n.push({module:t,field:"metaJson",message:"Added missing meta.json required fields",autoFixed:!0}),JSON.stringify(o,null,2)):e}var xm,si=L(()=>{"use strict";f();As();ie();xm=new Set(["visible","active","scroll-animate","hidden","open","closed","fade-in","fade-out","is-active","is-open","is-visible"])});import{execSync as $m}from"child_process";async function Qa(e,t,n,s,o,i,a,r){let l=Date.now(),c=i;if(Gt(n)){let C={"claude-code":"claude","gemini-cli":"gemini","codex-cli":"codex"}[n];if(C)try{$m(`command -v ${C}`,{stdio:"ignore"})}catch{throw new Error(`CLI engine "${n}" requires "${C}" to be installed and on your PATH.`)}}let d=await Fa(e,t,n,s,o,a,r);if(d.intent==="question"&&d.answer){let F=Date.now()-l;return a({type:"pipeline_complete",modulesGenerated:0,modulesUnchanged:t.modules.length,durationMs:F,answer:d.answer}),{modules:[...t.modules],moduleOrder:t.moduleOrder,sharedCss:t.sharedCss,sharedJs:t.sharedJs,assistantMessage:d.answer,stats:{modulesGenerated:0,modulesUnchanged:t.modules.length,modulesFailed:0,durationMs:F}}}let u=null,m=t.sharedCss,g=t.sharedJs;(d.intent==="create"||d.designSystemChanges)&&(u=await Ga(e,d,t,n,s,o,a),m=u.designSystem.sharedCss||m,g=u.designSystem.sharedJs||g,a({type:"blueprint_ready",moduleOrder:u.moduleOrder,sharedCss:m,sharedJs:g}));let h=[];if(u)for(let F of u.modules)h.push({name:F.name,description:F.description,contentBrief:F.contentBrief,layoutNotes:F.layoutNotes});else{for(let F of d.newModules)h.push({name:F.name,description:F.description,contentBrief:"Generate appropriate content based on the user request",layoutNotes:"Use responsive layout matching the existing design system"});for(let F of d.affectedModules){let C=t.modules.find(I=>I.moduleName===F);C&&h.push({name:F,description:`Modify existing module: ${F}`,contentBrief:"Apply the user's requested changes",layoutNotes:"Preserve existing layout unless changes are requested",existingCode:C})}}let b=[],x=[];if(h.length>0){let F=await za(e,h,m,t.themeName,n,s,o,c,a,d.guidesNeeded,t.brandAssets);for(let C of F)C.module?b.push(C.module):x.push(C.moduleName)}let w=null;if(b.length>0){w=Ns(b,t.themeName,a),b=w.map(C=>C.module);let F=w.reduce((C,I)=>C+I.issues.length,0);if(F>0){let C=w.reduce((Z,Mn)=>Z+Mn.issues.filter(ft=>ft.autoFixed).length,0);A.info("pipeline",`Quality check: ${F} issues, ${C} auto-fixed`);let I=w.flatMap(Z=>Z.issues).map(Z=>`${Z.autoFixed?"\u2713":"\u26A0"} ${Z.module}: ${Z.message}`).join(`
1278
- `);a({type:"agent_decision",step:"quality_check",decision:`${F} issues found, ${C} auto-fixed
1279
- ${I}`})}else a({type:"agent_decision",step:"quality_check",decision:"All modules passed quality checks"})}let S=Tm(t,d,b,u,r),M=Im(t,d,u,S);if(u?.moduleOrder?.length){let F=new Set(u.moduleOrder),C=S.filter(I=>!F.has(I.moduleName)).map(I=>I.moduleName);C.length>0&&a({type:"agent_decision",step:"quality_check",decision:`\u26A0 ${C.length} module${C.length===1?"":"s"} missing from page order \u2014 auto-inserted: ${C.join(", ")}`})}let O=Date.now()-l,R=b.length,H=d.unchangedModules.length,z=w?w.flatMap(F=>F.issues):[],_=Em(d,R,H,x,O,u,z);return x.length>0?a({type:"pipeline_partial",succeeded:b.map(F=>F.moduleName),failed:x,durationMs:O}):a({type:"pipeline_complete",modulesGenerated:R,modulesUnchanged:H,durationMs:O}),{modules:S,moduleOrder:M,sharedCss:m,sharedJs:g,assistantMessage:_,stats:{modulesGenerated:R,modulesUnchanged:H,modulesFailed:x.length,durationMs:O}}}function Tm(e,t,n,s,o){let i=[],a=new Set;for(let r of n)i.push(r),a.add(r.moduleName);for(let r of t.unchangedModules){if(a.has(r))continue;let l=e.modules.find(c=>c.moduleName===r);l&&(i.push(l),a.add(r))}if(t.reuseModules)for(let r of t.reuseModules){if(a.has(r.name))continue;let l=o.find(c=>c.name===r.name&&c.module);l&&l.module&&(i.push(l.module),a.add(r.name))}return i}function Im(e,t,n,s){if(n?.moduleOrder?.length){let r=[...n.moduleOrder],l=new Set(r);for(let c of s)if(!l.has(c.moduleName)){let d=r.findIndex(u=>u.toLowerCase().includes("footer"));d!==-1?r.splice(d,0,c.moduleName):r.push(c.moduleName),l.add(c.moduleName),A.warn("pipeline",`Module "${c.moduleName}" missing from blueprint order \u2014 inserted`)}return r}if(t.intent==="create")return s.map(r=>r.moduleName);let o=[...e.moduleOrder],i=[...t.newModules.map(r=>({name:r.name,position:r.position})),...(t.reuseModules||[]).map(r=>({name:r.name,position:r.position}))].sort((r,l)=>r.position-l.position);for(let r of i){let l=Math.min(r.position,o.length);o.splice(l,0,r.name)}let a=new Set(s.map(r=>r.moduleName));return o.filter(r=>a.has(r))}function Em(e,t,n,s,o,i,a){let r=Math.round(o/1e3),l=[];if(e.intent==="create")l.push(`Created ${t} module${t===1?"":"s"} in ${r}s.`);else if(e.intent==="modify"||e.intent==="style_change")l.push(`Updated ${t} module${t===1?"":"s"} in ${r}s.`),n>0&&l.push(`${n} module${n===1?"":"s"} unchanged.`);else if(e.intent==="add"){let u=e.newModules.map(m=>m.name).join(", ");l.push(`Added ${u} in ${r}s.`)}else e.intent==="remove"?l.push(`Removed modules in ${r}s.`):e.intent==="rearrange"&&l.push(`Rearranged modules in ${r}s.`);i?.narrative&&l.push(`
2343
+ ${f}`,n.push({module:e,field:"moduleHtml",message:`Added ${h.length} missing closing tag${h.length===1?"":"s"}: ${h.map(b=>`{% end${b} %}`).join(", ")}`,autoFixed:!0})}return/\bnow\(\)/.test(s)&&(s=s.replace(/\bnow\(\)/g,"local_dt"),n.push({module:e,field:"moduleHtml",message:"Replaced now() with local_dt (now() is not valid HubL)",autoFixed:!0})),s}function hh(t,e,n,s=!1,o=!1){let i=ft(t);if(!i||typeof i!="object")return t;let r=i,a=!1;if(r.host_template_types){if(s)r.host_template_types.includes("EMAIL")||(r.host_template_types=["EMAIL"],a=!0,n.push({module:e,field:"metaJson",message:'Fixed host_template_types to ["EMAIL"] for email module',autoFixed:!0}));else if(o){let l=r.host_template_types;l.includes("BLOG_POST")||l.includes("BLOG_LISTING")||(r.host_template_types=["BLOG_POST"],a=!0,n.push({module:e,field:"metaJson",message:"Fixed host_template_types to include blog type for blog module",autoFixed:!0}))}}else{let l=s?"EMAIL":o?"BLOG_POST":"PAGE";r.host_template_types=[l],a=!0}return r.is_available_for_new_content===void 0&&(r.is_available_for_new_content=!0,a=!0),a?(n.push({module:e,field:"metaJson",message:"Added missing meta.json required fields",autoFixed:!0}),JSON.stringify(r,null,2)):t}function md(t,e){let n=[],s=new Set(e.map(o=>`/${o}`));for(let o of t){if(!o.moduleName.includes("header")&&!o.moduleName.includes("nav")&&!o.moduleName.includes("footer"))continue;let i=/href=["'](\/?[a-z0-9][a-z0-9-]*(?:\/[a-z0-9-]*)*)["']/gi,r,a=[];for(;(r=i.exec(o.moduleHtml))!==null;){let l=r[1];l.startsWith("/")||(l="/"+l),!(l==="/"||l.startsWith("/http")||l.startsWith("/#"))&&a.push(l)}for(let l of a)s.has(l)||n.push({module:o.moduleName,message:`Nav link "${l}" does not match any page slug (valid: ${e.map(c=>"/"+c).join(", ")})`,autoFixed:!1})}return n}function bh(t,e,n){let s=new Set;if(e.colors?.primary&&s.add(e.colors.primary.toLowerCase()),e.colors?.secondary&&s.add(e.colors.secondary.toLowerCase()),e.colors?.accent&&s.add(e.colors.accent.toLowerCase()),s.size===0&&!e.fonts?.heading&&!e.fonts?.body)return;let o=(t.moduleHtml||"")+(t.moduleCss||"");if(s.size>0){let i=new Set;for(let a of o.matchAll(yh))i.add(a[0].toLowerCase());let r=new Set(["#ffffff","#000000","#f4f4f4","#f5f5f5","#fafafa","#eeeeee","#e0e0e0","#dddddd","#cccccc","#999999","#666666","#333333","#1a1a1a","#111111","#222222","#444444","#555555","#777777","#888888","#aaaaaa","#bbbbbb"]);for(let a of i)if(!r.has(a)&&!s.has(a)){n.push({module:t.moduleName,field:"moduleHtml",message:`Off-brand color ${a} (brand colors: ${[...s].join(", ")})`,autoFixed:!1});break}}if(e.fonts?.heading||e.fonts?.body){let i=[];e.fonts.heading&&i.push(e.fonts.heading.toLowerCase()),e.fonts.body&&i.push(e.fonts.body.toLowerCase());let r=/font-family:\s*([^;}"]+)/gi;for(let a of o.matchAll(r)){let l=a[1].toLowerCase().trim();if(!i.some(c=>l.includes(c))){n.push({module:t.moduleName,field:"moduleHtml",message:`Off-brand font "${a[1].trim()}" (brand fonts: ${i.join(", ")})`,autoFixed:!1});break}}}}function Sh(t,e){let n={...t},s=n.moduleHtml;n.moduleCss&&n.moduleCss.trim()&&(e.push({module:t.moduleName,field:"moduleCss",message:"Cleared moduleCss \u2014 email modules must use inline styles only",autoFixed:!0}),n.moduleCss=""),n.moduleJs&&n.moduleJs.trim()&&(e.push({module:t.moduleName,field:"moduleJs",message:"Cleared moduleJs \u2014 email clients do not support JavaScript",autoFixed:!0}),n.moduleJs=void 0),/<style[\s>]/i.test(s)&&(s=s.replace(/<style[^>]*>[\s\S]*?<\/style>/gi,""),e.push({module:t.moduleName,field:"moduleHtml",message:"Removed <style> blocks \u2014 email clients strip them",autoFixed:!0})),/display\s*:\s*flex/i.test(s)&&e.push({module:t.moduleName,field:"moduleHtml",message:"Contains display:flex \u2014 not supported in email clients",autoFixed:!1}),/display\s*:\s*grid/i.test(s)&&e.push({module:t.moduleName,field:"moduleHtml",message:"Contains display:grid \u2014 not supported in email clients",autoFixed:!1}),/var\s*\(/i.test(s)&&e.push({module:t.moduleName,field:"moduleHtml",message:"Contains var() \u2014 CSS custom properties not supported in email",autoFixed:!1});let o=/\{[{%].*?(?:require_css|require_js|scope_css|get_asset_url)\s*\(.*?\}[}%]/g;o.test(s)&&(s=s.replace(o,""),e.push({module:t.moduleName,field:"moduleHtml",message:"Removed banned HubL functions for email (require_css, require_js, scope_css, get_asset_url)",autoFixed:!0}));let i=/<link[^>]*href="https?:\/\/[^"]*(?:fonts\.googleapis|cdnjs|unpkg|jsdelivr)[^"]*"[^>]*\/?>/gi;return i.test(s)&&(s=s.replace(i,""),e.push({module:t.moduleName,field:"moduleHtml",message:"Removed CDN <link> tags \u2014 external resources not supported in email",autoFixed:!0})),n.moduleHtml=s,n}function xh(t,e){let n={...t},s=n.moduleHtml;return/\{\{[\s]*content\.body[\s]*\}\}/g.test(s)&&(s=s.replace(/\{\{[\s]*content\.body[\s]*\}\}/g,"{{ content.post_body }}"),e.push({module:t.moduleName,field:"moduleHtml",message:"Fixed content.body \u2192 content.post_body (correct blog variable)",autoFixed:!0})),/\{\{[\s]*content\.title[\s]*\}\}/g.test(s)&&(s=s.replace(/\{\{[\s]*content\.title[\s]*\}\}/g,"{{ content.name }}"),e.push({module:t.moduleName,field:"moduleHtml",message:"Fixed content.title \u2192 content.name (correct blog variable)",autoFixed:!0})),/\{\{[\s]*content\.author_name[\s]*\}\}/g.test(s)&&(s=s.replace(/\{\{[\s]*content\.author_name[\s]*\}\}/g,"{{ content.blog_post_author }}"),e.push({module:t.moduleName,field:"moduleHtml",message:"Fixed content.author_name \u2192 content.blog_post_author",autoFixed:!0})),/\{\{[\s]*content\.date[\s]*\}\}/g.test(s)&&(s=s.replace(/\{\{[\s]*content\.date[\s]*\}\}/g,"{{ content.publish_date }}"),e.push({module:t.moduleName,field:"moduleHtml",message:"Fixed content.date \u2192 content.publish_date",autoFixed:!0})),/\{\{[\s]*content\.image[\s]*\}\}/g.test(s)&&(s=s.replace(/\{\{[\s]*content\.image[\s]*\}\}/g,"{{ content.featured_image }}"),e.push({module:t.moduleName,field:"moduleHtml",message:"Fixed content.image \u2192 content.featured_image",autoFixed:!0})),/\{%.*dnd_area.*%\}/g.test(s)&&e.push({module:t.moduleName,field:"moduleHtml",message:"Contains dnd_area \u2014 blog templates typically use fixed module positions",autoFixed:!1}),/\{\{[\s]*content\.publish_date[\s]*\}\}/g.test(s)&&e.push({module:t.moduleName,field:"moduleHtml",message:"publish_date used without |datetimeformat filter \u2014 dates may render as raw timestamps",autoFixed:!1}),n.moduleHtml=s,n}var uh,yh,br=R(()=>{"use strict";y();wo();de();uh=new Set(["visible","active","scroll-animate","hidden","open","closed","fade-in","fade-out","is-active","is-open","is-visible"]);yh=/#[0-9a-fA-F]{6}\b/g});import{execSync as vh}from"child_process";async function pd(t,e,n,s,o,i,r,a){let l=Date.now(),c=i;if(xn(n)){let T={"claude-code":"claude","gemini-cli":"gemini","codex-cli":"codex"}[n];if(T)try{vh(`command -v ${T}`,{stdio:"ignore"})}catch{throw new Error(`CLI engine "${n}" requires "${T}" to be installed and on your PATH.`)}}let d=await Ec(t,e,n,s,o,r,a);if(d.intent==="question"&&d.answer){let N=Date.now()-l;return r({type:"pipeline_complete",modulesGenerated:0,modulesUnchanged:e.modules.length,durationMs:N,answer:d.answer}),{modules:[...e.modules],moduleOrder:e.moduleOrder,sharedCss:e.sharedCss,sharedJs:e.sharedJs,assistantMessage:d.answer,stats:{modulesGenerated:0,modulesUnchanged:e.modules.length,modulesFailed:0,durationMs:N}}}if(d.intent==="create_site"&&d.pages&&d.pages.length>0)return wh(t,d,e,n,s,o,i,r,l);let u=null,m=e.sharedCss,g=e.sharedJs;(d.intent==="create"||d.designSystemChanges)&&(u=await Hc(t,d,e,n,s,o,r),d.contentType!=="email"&&(m=u.designSystem.sharedCss||m,g=u.designSystem.sharedJs||g),r({type:"blueprint_ready",moduleOrder:u.moduleOrder,sharedCss:m,sharedJs:g}));let f=[];if(u)for(let N of u.modules)f.push({name:N.name,description:N.description,contentBrief:N.contentBrief,layoutNotes:N.layoutNotes});else{for(let N of d.newModules)f.push({name:N.name,description:N.description,contentBrief:"Generate appropriate content based on the user request",layoutNotes:"Use responsive layout matching the existing design system"});for(let N of d.affectedModules){let T=e.modules.find(I=>I.moduleName===N);T&&f.push({name:N,description:`Modify existing module: ${N}`,contentBrief:"Apply the user's requested changes",layoutNotes:"Preserve existing layout unless changes are requested",existingCode:T})}}let b=[],S=[];if(f.length>0){let N=await cs(t,f,m,e.themeName,n,s,o,c,r,d.guidesNeeded,e.brandAssets,d.contentType);for(let T of N)T.module?b.push(T.module):S.push(T.moduleName)}let x=null;if(b.length>0){x=zt(b,e.themeName,r,d.contentType,e.brandAssets?.brandKit);let N=x.filter(I=>I.issues.some(k=>k.field==="fieldsJson"&&k.message.includes("reset to empty"))).map(I=>I.module.moduleName);if(N.length>0){let I=N.map(k=>f.find(K=>K.name===k)).filter(k=>k!=null);if(I.length>0){E.info("pipeline",`Retrying ${I.length} module(s) with broken fieldsJson: ${I.map(K=>K.name).join(", ")}`),r({type:"agent_decision",step:"quality_check",decision:`Regenerating ${I.length} module(s) with invalid fields JSON...`});let k=await cs(t,I,m,e.themeName,n,s,o,c,r,d.guidesNeeded,e.brandAssets,d.contentType);for(let K of k)if(K.module){let oe=b.findIndex(it=>it.moduleName===K.moduleName);oe>=0&&(b[oe]=K.module)}x=zt(b,e.themeName,r,d.contentType,e.brandAssets?.brandKit)}}b=x.map(I=>I.module);let T=x.reduce((I,k)=>I+k.issues.length,0);if(T>0){let I=x.reduce((K,oe)=>K+oe.issues.filter(it=>it.autoFixed).length,0);E.info("pipeline",`Quality check: ${T} issues, ${I} auto-fixed`);let k=x.flatMap(K=>K.issues).map(K=>`${K.autoFixed?"\u2713":"\u26A0"} ${K.module}: ${K.message}`).join(`
2344
+ `);r({type:"agent_decision",step:"quality_check",decision:`${T} issues found, ${I} auto-fixed
2345
+ ${k}`})}else r({type:"agent_decision",step:"quality_check",decision:"All modules passed quality checks"})}let w=kh(e,d,b,u,a),P=Th(e,d,u,w);if(u?.moduleOrder?.length){let N=new Set(u.moduleOrder),T=w.filter(I=>!N.has(I.moduleName)).map(I=>I.moduleName);T.length>0&&r({type:"agent_decision",step:"quality_check",decision:`\u26A0 ${T.length} module${T.length===1?"":"s"} missing from page order \u2014 auto-inserted: ${T.join(", ")}`})}let F=Date.now()-l,H=b.length,L=d.unchangedModules.length,V=x?x.flatMap(N=>N.issues):[],B=Ah(d,H,L,S,F,u,V);return S.length>0?r({type:"pipeline_partial",succeeded:b.map(N=>N.moduleName),failed:S,durationMs:F}):r({type:"pipeline_complete",modulesGenerated:H,modulesUnchanged:L,durationMs:F,assistantMessage:B}),{modules:w,moduleOrder:P,sharedCss:m,sharedJs:g,assistantMessage:B,contentType:d.contentType,stats:{modulesGenerated:H,modulesUnchanged:L,modulesFailed:S.length,durationMs:F}}}async function wh(t,e,n,s,o,i,r,a,l){let c=e.pages,d=e.sharedModules||["site-header","site-footer"],u=await Bc(t,e,n,s,o,i,a),m=u.sharedCss||n.sharedCss,g=u.sharedJs||n.sharedJs;a({type:"blueprint_ready",moduleOrder:d,sharedCss:m,sharedJs:g});let h=await zc(t,e,n,m,s,o,i,a);a({type:"agent_step",step:"developing",label:`Generating modules for ${c.length} pages...`});let f=[];for(let k of h.sharedModules)f.push({...k});for(let k of h.pages)for(let K of k.modules)f.push({name:K.name,description:K.description,contentBrief:K.contentBrief,layoutNotes:K.layoutNotes});let b=c.map(k=>`- "${k.label}" \u2192 /${k.slug}`).join(`
2346
+ `);for(let k of f)(k.name.includes("header")||k.name.includes("nav"))&&(k.layoutNotes+=`
2347
+
2348
+ ## Site Navigation
2349
+ This is a multi-page site. Include navigation links to all pages:
2350
+ ${b}
2351
+ Use relative href paths. Add CSS class "${n.themeName}-nav__link--active" on the current page's link.`);let S=await cs(t,f,m,n.themeName,s,o,i,r,a,e.guidesNeeded,n.brandAssets,e.contentType),x=[],w=[];for(let k of S)k.module?x.push(k.module):w.push(k.moduleName);let P=x,F=[];if(x.length>0){let k=zt(x,n.themeName,a,e.contentType,n.brandAssets?.brandKit),K=k.filter(ie=>ie.issues.some(ye=>ye.field==="fieldsJson"&&ye.message.includes("reset to empty"))).map(ie=>ie.module.moduleName);if(K.length>0){let ie=K.map(ye=>f.find(le=>le.name===ye)).filter(ye=>ye!=null);if(ie.length>0){E.info("pipeline",`Retrying ${ie.length} module(s) with broken fieldsJson`),a({type:"agent_decision",step:"quality_check",decision:`Regenerating ${ie.length} module(s) with invalid fields JSON...`});let ye=await cs(t,ie,m,n.themeName,s,o,i,r,a,e.guidesNeeded,n.brandAssets,e.contentType);for(let le of ye)if(le.module){let Je=x.findIndex(ws=>ws.moduleName===le.moduleName);Je>=0&&(x[Je]=le.module)}k=zt(x,n.themeName,a,e.contentType,n.brandAssets?.brandKit)}}P=k.map(ie=>ie.module),F=k.flatMap(ie=>ie.issues);let oe=md(P,c.map(ie=>ie.slug));F.push(...oe);let it=F.length;if(it>0){let ie=F.filter(ye=>ye.autoFixed).length;a({type:"agent_decision",step:"quality_check",decision:`${it} issues found, ${ie} auto-fixed`})}else a({type:"agent_decision",step:"quality_check",decision:"All modules passed quality checks"})}let H=new Map(P.map(k=>[k.moduleName,k])),L=h.sharedModules.map(k=>H.get(k.name)).filter(k=>!!k),V=new Map(c.map(k=>[k.id,k])),B=h.pages.map(k=>{let K=k.modules.map(le=>H.get(le.name)).filter(le=>!!le),oe=d.filter(le=>le.includes("header")||le.includes("nav")),it=d.filter(le=>le.includes("footer")),ie=[...oe,...k.moduleOrder,...it],ye=V.get(k.pageId);return{pageId:k.pageId,templateId:k.pageId,label:ye?.label||k.pageId,pageType:ye?.pageType||"website_page",modules:[...L,...K],moduleOrder:ie}}),N=Date.now()-l,T=Ch(c,x.length,w,N,h.narrative,F);return w.length>0?a({type:"pipeline_partial",succeeded:x.map(k=>k.moduleName),failed:w,durationMs:N}):a({type:"pipeline_complete",modulesGenerated:x.length,modulesUnchanged:0,durationMs:N,assistantMessage:T}),{modules:P,moduleOrder:P.map(k=>k.moduleName),sharedCss:m,sharedJs:g||"",assistantMessage:T,stats:{modulesGenerated:x.length,modulesUnchanged:0,modulesFailed:w.length,durationMs:N},multiPage:{pages:B,sharedModules:L,sharedCss:m,sharedJs:g||"",assistantMessage:T,stats:{pagesGenerated:c.length,modulesGenerated:x.length,modulesFailed:w.length,durationMs:N}}}}function Ch(t,e,n,s,o,i){let r=Math.round(s/1e3),a=[];a.push(`Created ${t.length}-page site with ${e} modules in ${r}s.`),a.push(`
2352
+
2353
+ **Pages:** ${t.map(d=>d.label).join(", ")}`),o&&a.push(`
2354
+
2355
+ ${o}`),n.length>0&&a.push(`
2356
+
2357
+ **Failed:** ${n.join(", ")}. You can retry these individually.`);let l=i.filter(d=>!d.autoFixed),c=i.filter(d=>d.autoFixed);if(c.length>0||l.length>0){let d=[];c.length>0&&d.push(`**Auto-fixed:** ${c.map(u=>`${u.module}: ${u.message}`).join(", ")}`),l.length>0&&d.push(`**Warnings:** ${l.map(u=>`${u.module}: ${u.message}`).join(", ")}`),a.push(`
2358
+
2359
+ ${d.join(`
2360
+ `)}`)}return a.join("")}function kh(t,e,n,s,o){let i=[],r=new Set;for(let a of n)i.push(a),r.add(a.moduleName);for(let a of e.unchangedModules){if(r.has(a))continue;let l=t.modules.find(c=>c.moduleName===a);l&&(i.push(l),r.add(a))}if(e.reuseModules)for(let a of e.reuseModules){if(r.has(a.name))continue;let l=o.find(c=>c.name===a.name&&c.module);l&&l.module&&(i.push(l.module),r.add(a.name))}return i}function Th(t,e,n,s){if(n?.moduleOrder?.length){let a=[...n.moduleOrder],l=new Set(a);for(let c of s)if(!l.has(c.moduleName)){let d=a.findIndex(u=>u.toLowerCase().includes("footer"));d!==-1?a.splice(d,0,c.moduleName):a.push(c.moduleName),l.add(c.moduleName),E.warn("pipeline",`Module "${c.moduleName}" missing from blueprint order \u2014 inserted`)}return a}if(e.intent==="create")return s.map(a=>a.moduleName);let o=[...t.moduleOrder],i=[...e.newModules.map(a=>({name:a.name,position:a.position})),...(e.reuseModules||[]).map(a=>({name:a.name,position:a.position}))].sort((a,l)=>a.position-l.position);for(let a of i){let l=Math.min(a.position,o.length);o.splice(l,0,a.name)}let r=new Set(s.map(a=>a.moduleName));return o.filter(a=>r.has(a))}function Ah(t,e,n,s,o,i,r){let a=Math.round(o/1e3),l=[];if(t.intent==="create")l.push(`Created ${e} module${e===1?"":"s"} in ${a}s.`);else if(t.intent==="modify"||t.intent==="style_change")l.push(`Updated ${e} module${e===1?"":"s"} in ${a}s.`),n>0&&l.push(`${n} module${n===1?"":"s"} unchanged.`);else if(t.intent==="add"){let u=t.newModules.map(m=>m.name).join(", ");l.push(`Added ${u} in ${a}s.`)}else t.intent==="remove"?l.push(`Removed modules in ${a}s.`):t.intent==="rearrange"&&l.push(`Rearranged modules in ${a}s.`);i?.narrative&&l.push(`
1280
2361
 
1281
2362
  ${i.narrative}`),s.length>0&&l.push(`
1282
2363
 
1283
- **Failed:** ${s.join(", ")}. You can retry these individually.`);let c=a.filter(u=>!u.autoFixed),d=a.filter(u=>u.autoFixed);if(d.length>0||c.length>0){let u=[];d.length>0&&u.push(`**Auto-fixed:** ${d.map(m=>`${m.module}: ${m.message}`).join(", ")}`),c.length>0&&u.push(`**Warnings:** ${c.map(m=>`${m.module}: ${m.message}`).join(", ")}`),l.push(`
2364
+ **Failed:** ${s.join(", ")}. You can retry these individually.`);let c=r.filter(u=>!u.autoFixed),d=r.filter(u=>u.autoFixed);if(d.length>0||c.length>0){let u=[];d.length>0&&u.push(`**Auto-fixed:** ${d.map(m=>`${m.module}: ${m.message}`).join(", ")}`),c.length>0&&u.push(`**Warnings:** ${c.map(m=>`${m.module}: ${m.message}`).join(", ")}`),l.push(`
1284
2365
 
1285
2366
  ${u.join(`
1286
- `)}`)}return l.join("")}var el=L(()=>{"use strict";f();qe();Ja();Wa();qa();si();ie();qe()});var il={};ke(il,{runFigmaConversion:()=>_m});import{basename as sl}from"path";async function _m(e,t,n,s,o,i,a,r,l){let c=Date.now();a({type:"agent_step",step:"designing",label:"Building design system from Figma tokens..."});let{sharedCss:d,sharedJs:u}=Nm(e.designTokens,t);a({type:"design_system_ready",sharedCss:d,sharedJs:u,aesthetic:"Figma import"}),a({type:"agent_decision",step:"designing",decision:`Generated CSS variables and utility classes from ${e.designTokens.colors.length} colors, ${e.designTokens.typography.length} typography styles`});let{specs:m,moduleOrder:g}=Mm(e.sections,e.assets,t);a({type:"blueprint_ready",moduleOrder:g,sharedCss:d,sharedJs:u}),a({type:"agent_decision",step:"designing",decision:`Mapped ${m.length} Figma sections to modules: ${g.join(", ")}`}),a({type:"agent_step",step:"developing",label:`Converting ${m.length} modules...`});let y=n==="anthropic-api"||n==="claude-oauth",h=kn(t,d,["hubspot_rules","conversion"],r),b=y?Es(t,d,["hubspot_rules","conversion"],r):void 0,x=Is(i),w=m.length,S=m.map((I,Z)=>{let Mn=e.sections[Z];return x(async()=>{a({type:"module_progress",module:I.name,status:"generating",current:Z+1,total:w});let ft=Fm(Mn,I,e.assets,t,l!==!1),qs="";for(let Yt=0;Yt<2;Yt++)try{Yt>0&&(A.warn("figma-pipeline",`${I.name}: retrying (attempt ${Yt+1})`),a({type:"module_progress",module:I.name,status:"retrying",current:Z+1,total:w}));let It=await Ce(n,s,o,{systemPrompt:h,systemBlocks:b,messages:[{role:"user",content:ft}],structuredOutput:{schema:_s,name:"module_output"},maxTokens:16e3});if(It.type!=="structured")throw new Error("No structured output returned");let je=It.data,_i={moduleName:I.name,fieldsJson:typeof je.fieldsJson=="string"?je.fieldsJson:JSON.stringify(je.fieldsJson,null,2),metaJson:typeof je.metaJson=="string"?je.metaJson:JSON.stringify(je.metaJson,null,2),moduleHtml:String(je.moduleHtml||""),moduleCss:String(je.moduleCss||""),moduleJs:je.moduleJs?String(je.moduleJs):void 0};return a({type:"module_progress",module:I.name,status:"complete",current:Z+1,total:w,moduleFiles:_i}),{moduleName:I.name,module:_i}}catch(It){qs=It instanceof Error?It.message:String(It),A.error("figma-pipeline",`Failed: ${I.name} (attempt ${Yt+1}): ${qs}`)}return a({type:"module_progress",module:I.name,status:"failed",current:Z+1,total:w}),{moduleName:I.name,error:qs}})}),O=(await Promise.allSettled(S)).map(I=>I.status==="fulfilled"?I.value:{moduleName:"unknown",error:String(I.reason)}),R=O.filter(I=>I.module).map(I=>I.module),H=O.filter(I=>I.error).map(I=>I.moduleName),_=Ns(R,t,a).map(I=>I.module),F=Date.now()-c,C=Math.round(F/1e3);return H.length>0?a({type:"pipeline_partial",succeeded:_.map(I=>I.moduleName),failed:H,durationMs:F}):a({type:"pipeline_complete",modulesGenerated:_.length,modulesUnchanged:0,durationMs:F}),{modules:_,moduleOrder:g,sharedCss:d,sharedJs:u,assistantMessage:`Imported ${_.length} modules from Figma design "${e.fileName}" in ${C}s.`,stats:{modulesGenerated:_.length,modulesUnchanged:0,modulesFailed:H.length,durationMs:F}}}function Ps(e){let t=parseInt(e.slice(1,3),16)/255,n=parseInt(e.slice(3,5),16)/255,s=parseInt(e.slice(5,7),16)/255,o=Math.max(t,n,s),i=Math.min(t,n,s),a=(o+i)/2;if(o===i)return{h:0,s:0,l:a};let r=o-i,l=a>.5?r/(2-o-i):r/(o+i),c=0;return o===t?c=((n-s)/r+(n<s?6:0))/6:o===n?c=((s-t)/r+2)/6:c=((t-n)/r+4)/6,{h:c*360,s:l,l:a}}function Nm(e,t){let n=[],s=t,o=[...e.colors].sort((C,I)=>I.occurrences-C.occurrences),i=o.filter(C=>C.usage==="background"||C.usage==="fill"),a=o.filter(C=>C.usage==="text"),r=i[0]||o[0],l=r?Ps(r.hex).l<.4:!1;r&&n.push(` --${s}-color-bg: ${r.hex}`);let c=a[0]||(l?o.find(C=>Ps(C.hex).l>.7):o.find(C=>Ps(C.hex).l<.3));c&&n.push(` --${s}-color-text: ${c.hex}`);let d=new Set([r?.hex,c?.hex].filter(Boolean)),u=o.filter(C=>!d.has(C.hex));if(u[0]&&(n.push(` --${s}-color-primary: ${u[0].hex}`),d.add(u[0].hex)),u[1]&&(n.push(` --${s}-color-accent: ${u[1].hex}`),d.add(u[1].hex)),u.filter(C=>!d.has(C.hex)).slice(0,6).forEach((C,I)=>n.push(` --${s}-color-${I+1}: ${C.hex}`)),r){let C=Ps(r.hex).l;n.push(` --${s}-color-surface: ${l?tl(r.hex,.05):nl(r.hex,.03)}`),n.push(` --${s}-color-border: ${l?tl(r.hex,.15):nl(r.hex,.12)}`)}let g=e.typography.filter(C=>C.role==="heading"||C.role==="subheading"),y=e.typography.filter(C=>C.role==="body"||C.role==="label"||C.role==="caption"),h=g[0]?.fontFamily||y[0]?.fontFamily||"system-ui",b=y[0]?.fontFamily||h;n.push(` --${s}-font-display: "${h}", system-ui, sans-serif`),n.push(` --${s}-font-body: "${b}", system-ui, sans-serif`);let x=g.sort((C,I)=>I.fontSize-C.fontSize);x[0]&&n.push(` --${s}-size-h1: ${x[0].fontSize}px`),x[1]&&n.push(` --${s}-size-h2: ${x[1].fontSize}px`),x[2]&&n.push(` --${s}-size-h3: ${x[2].fontSize}px`);let w=y.sort((C,I)=>I.occurrences-C.occurrences)[0];w&&n.push(` --${s}-size-body: ${w.fontSize}px`);let S=[...new Set(e.spacing.map(C=>C.value))].sort((C,I)=>C-I),M=["xs","sm","md","lg","xl","2xl","section"];S.slice(0,M.length).forEach((C,I)=>{n.push(` --${s}-space-${M[I]}: ${C}px`)});let O=e.effects.filter(C=>C.type==="shadow"),R=e.effects.filter(C=>C.type==="radius");O[0]&&n.push(` --${s}-shadow: ${O[0].cssValue}`),R.sort((C,I)=>parseFloat(C.cssValue)-parseFloat(I.cssValue)),R[0]&&n.push(` --${s}-radius: ${R[0].cssValue}`),R[1]&&n.push(` --${s}-radius-lg: ${R[1].cssValue}`);let H=`:root {
2367
+ `)}`)}return l.join("")}var gd=R(()=>{"use strict";y();nt();Ic();Uc();Yc();cd();br();de();nt()});var Sd={};Be(Sd,{runFigmaConversion:()=>$h});import{basename as yd}from"path";async function $h(t,e,n,s,o,i,r,a,l){let c=Date.now();r({type:"agent_step",step:"designing",label:"Building design system from Figma tokens..."});let{sharedCss:d,sharedJs:u}=_h(t.designTokens,e);r({type:"design_system_ready",sharedCss:d,sharedJs:u,aesthetic:"Figma import"}),r({type:"agent_decision",step:"designing",decision:`Generated CSS variables and utility classes from ${t.designTokens.colors.length} colors, ${t.designTokens.typography.length} typography styles`});let{specs:m,moduleOrder:g}=Eh(t.sections,t.assets,e);r({type:"blueprint_ready",moduleOrder:g,sharedCss:d,sharedJs:u}),r({type:"agent_decision",step:"designing",decision:`Mapped ${m.length} Figma sections to modules: ${g.join(", ")}`}),r({type:"agent_step",step:"developing",label:`Converting ${m.length} modules...`});let h=n==="anthropic-api"||n==="claude-oauth",f=as(e,d,["hubspot_rules","conversion"],a),b=h?_o(e,d,["hubspot_rules","conversion"],a):void 0,S=$o(i),x=m.length,w=m.map((k,K)=>{let oe=t.sections[K];return S(async()=>{r({type:"module_progress",module:k.name,status:"generating",current:K+1,total:x});let it=Rh(oe,k,t.assets,e,l!==!1),ie="";for(let ye=0;ye<2;ye++)try{ye>0&&(E.warn("figma-pipeline",`${k.name}: retrying (attempt ${ye+1})`),r({type:"module_progress",module:k.name,status:"retrying",current:K+1,total:x}));let le=await _e(n,s,o,{systemPrompt:f,systemBlocks:b,messages:[{role:"user",content:it}],structuredOutput:{schema:ls,name:"module_output"},maxTokens:16e3});if(le.type!=="structured")throw new Error("No structured output returned");let Je=le.data,ws={moduleName:k.name,fieldsJson:typeof Je.fieldsJson=="string"?Je.fieldsJson:JSON.stringify(Je.fieldsJson,null,2),metaJson:typeof Je.metaJson=="string"?Je.metaJson:JSON.stringify(Je.metaJson,null,2),moduleHtml:String(Je.moduleHtml||""),moduleCss:String(Je.moduleCss||""),moduleJs:Je.moduleJs?String(Je.moduleJs):void 0};return r({type:"module_progress",module:k.name,status:"complete",current:K+1,total:x,moduleFiles:ws}),{moduleName:k.name,module:ws}}catch(le){ie=le instanceof Error?le.message:String(le),E.error("figma-pipeline",`Failed: ${k.name} (attempt ${ye+1}): ${ie}`)}return r({type:"module_progress",module:k.name,status:"failed",current:K+1,total:x}),{moduleName:k.name,error:ie}})}),F=(await Promise.allSettled(w)).map(k=>k.status==="fulfilled"?k.value:{moduleName:"unknown",error:String(k.reason)}),H=F.filter(k=>k.module).map(k=>k.module),L=F.filter(k=>k.error).map(k=>k.moduleName),B=zt(H,e,r).map(k=>k.module),N=Date.now()-c,T=Math.round(N/1e3),I=`Imported ${B.length} modules from Figma design "${t.fileName}" in ${T}s.`;return L.length>0?r({type:"pipeline_partial",succeeded:B.map(k=>k.moduleName),failed:L,durationMs:N}):r({type:"pipeline_complete",modulesGenerated:B.length,modulesUnchanged:0,durationMs:N,assistantMessage:I}),{modules:B,moduleOrder:g,sharedCss:d,sharedJs:u,assistantMessage:I,stats:{modulesGenerated:B.length,modulesUnchanged:0,modulesFailed:L.length,durationMs:N}}}function Mo(t){let e=parseInt(t.slice(1,3),16)/255,n=parseInt(t.slice(3,5),16)/255,s=parseInt(t.slice(5,7),16)/255,o=Math.max(e,n,s),i=Math.min(e,n,s),r=(o+i)/2;if(o===i)return{h:0,s:0,l:r};let a=o-i,l=r>.5?a/(2-o-i):a/(o+i),c=0;return o===e?c=((n-s)/a+(n<s?6:0))/6:o===n?c=((s-e)/a+2)/6:c=((e-n)/a+4)/6,{h:c*360,s:l,l:r}}function _h(t,e){let n=[],s=e,o=[...t.colors].sort((T,I)=>I.occurrences-T.occurrences),i=o.filter(T=>T.usage==="background"||T.usage==="fill"),r=o.filter(T=>T.usage==="text"),a=i[0]||o[0],l=a?Mo(a.hex).l<.4:!1;a&&n.push(` --${s}-color-bg: ${a.hex}`);let c=r[0]||(l?o.find(T=>Mo(T.hex).l>.7):o.find(T=>Mo(T.hex).l<.3));c&&n.push(` --${s}-color-text: ${c.hex}`);let d=new Set([a?.hex,c?.hex].filter(Boolean)),u=o.filter(T=>!d.has(T.hex));if(u[0]&&(n.push(` --${s}-color-primary: ${u[0].hex}`),d.add(u[0].hex)),u[1]&&(n.push(` --${s}-color-accent: ${u[1].hex}`),d.add(u[1].hex)),u.filter(T=>!d.has(T.hex)).slice(0,6).forEach((T,I)=>n.push(` --${s}-color-${I+1}: ${T.hex}`)),a){let T=Mo(a.hex).l;n.push(` --${s}-color-surface: ${l?fd(a.hex,.05):hd(a.hex,.03)}`),n.push(` --${s}-color-border: ${l?fd(a.hex,.15):hd(a.hex,.12)}`)}let g=t.typography.filter(T=>T.role==="heading"||T.role==="subheading"),h=t.typography.filter(T=>T.role==="body"||T.role==="label"||T.role==="caption"),f=g[0]?.fontFamily||h[0]?.fontFamily||"system-ui",b=h[0]?.fontFamily||f;n.push(` --${s}-font-display: "${f}", system-ui, sans-serif`),n.push(` --${s}-font-body: "${b}", system-ui, sans-serif`);let S=g.sort((T,I)=>I.fontSize-T.fontSize);S[0]&&n.push(` --${s}-size-h1: ${S[0].fontSize}px`),S[1]&&n.push(` --${s}-size-h2: ${S[1].fontSize}px`),S[2]&&n.push(` --${s}-size-h3: ${S[2].fontSize}px`);let x=h.sort((T,I)=>I.occurrences-T.occurrences)[0];x&&n.push(` --${s}-size-body: ${x.fontSize}px`);let w=[...new Set(t.spacing.map(T=>T.value))].sort((T,I)=>T-I),P=["xs","sm","md","lg","xl","2xl","section"];w.slice(0,P.length).forEach((T,I)=>{n.push(` --${s}-space-${P[I]}: ${T}px`)});let F=t.effects.filter(T=>T.type==="shadow"),H=t.effects.filter(T=>T.type==="radius");F[0]&&n.push(` --${s}-shadow: ${F[0].cssValue}`),H.sort((T,I)=>parseFloat(T.cssValue)-parseFloat(I.cssValue)),H[0]&&n.push(` --${s}-radius: ${H[0].cssValue}`),H[1]&&n.push(` --${s}-radius-lg: ${H[1].cssValue}`);let L=`:root {
1287
2368
  ${n.join(`;
1288
2369
  `)};
1289
- }`,z=`
2370
+ }`,V=`
1290
2371
  /* Reset */
1291
2372
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
1292
2373
 
@@ -1370,8 +2451,8 @@ body {
1370
2451
  h1 { font-size: 2rem; }
1371
2452
  h2 { font-size: 1.5rem; }
1372
2453
  h3 { font-size: 1.25rem; }
1373
- }`;return{sharedCss:H+`
1374
- `+z,sharedJs:`(function() {
2454
+ }`;return{sharedCss:L+`
2455
+ `+V,sharedJs:`(function() {
1375
2456
  var observer = new IntersectionObserver(function(entries) {
1376
2457
  entries.forEach(function(entry) {
1377
2458
  if (entry.isIntersecting) {
@@ -1381,11 +2462,11 @@ body {
1381
2462
  });
1382
2463
  }, { threshold: 0.1 });
1383
2464
  document.querySelectorAll('[data-animate]').forEach(function(el) { observer.observe(el); });
1384
- })();`}}function tl(e,t){return ol(e,t)}function nl(e,t){return ol(e,-t)}function ol(e,t){let n=parseInt(e.slice(1,3),16),s=parseInt(e.slice(3,5),16),o=parseInt(e.slice(5,7),16);return n=Math.min(255,Math.max(0,Math.round(n+255*t))),s=Math.min(255,Math.max(0,Math.round(s+255*t))),o=Math.min(255,Math.max(0,Math.round(o+255*t))),`#${n.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}function Pm(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9]+/g,"-").replace(/(^-|-$)/g,"").toLowerCase()}function Mm(e,t,n){let s=new Set,o=[];for(let i of e){let a=Pm(i.name);if(s.has(a)){let d=2;for(;s.has(`${a}-${d}`);)d++;a=`${a}-${d}`}s.add(a);let r=Om(i.textContent),l=Rm(i,t,n),c=`Figma section "${i.name}" \u2014 ${i.width}x${i.height}px, ${i.textContent.length} text elements, ${i.children.length} children`;o.push({name:a,description:c,contentBrief:r,layoutNotes:l})}return{specs:o,moduleOrder:o.map(i=>i.name)}}function Om(e){let t={};for(let o of e){let i=o.role;t[i]||(t[i]=[]),t[i].push(o.text)}let n=[],s=["headline","subheadline","body","cta","label","caption"];for(let o of s)if(t[o])for(let i of t[o])n.push(`**${o}** (use as field default): "${i}"`);return n.join(`
1385
- `)}function Rm(e,t,n){let s=[];if(s.push(`Dimensions: ${e.width}x${e.height}px`),e.backgroundColor&&s.push(`Background: ${e.backgroundColor}`),e.layoutMode&&s.push(`Layout: ${e.layoutMode}`),e.itemSpacing&&s.push(`Gap: ${e.itemSpacing}px`),(e.paddingTop||e.paddingRight||e.paddingBottom||e.paddingLeft)&&s.push(`Padding: ${e.paddingTop||0}px ${e.paddingRight||0}px ${e.paddingBottom||0}px ${e.paddingLeft||0}px`),e.children.length>0){s.push(`
1386
- Children (${e.children.length}):`);for(let o of e.children){let i=` - ${o.type} "${o.name}" (${o.width}x${o.height})`;o.layoutMode&&(i+=` [${o.layoutMode}]`),o.childCount>0&&(i+=` [${o.childCount} children]`),o.characters&&(i+=` text: "${o.characters.slice(0,60)}"`),s.push(i)}}if(t.length>0){s.push(`
1387
- Available image assets:`);for(let o of t){let i=sl(o.localPath);s.push(` - get_asset_url("${n}/assets/${i}") \u2014 ${o.name}`)}}return s.join(`
1388
- `)}function Fm(e,t,n,s,o){let i=[];if(i.push(`## Figma Design Translation
2465
+ })();`}}function fd(t,e){return bd(t,e)}function hd(t,e){return bd(t,-e)}function bd(t,e){let n=parseInt(t.slice(1,3),16),s=parseInt(t.slice(3,5),16),o=parseInt(t.slice(5,7),16);return n=Math.min(255,Math.max(0,Math.round(n+255*e))),s=Math.min(255,Math.max(0,Math.round(s+255*e))),o=Math.min(255,Math.max(0,Math.round(o+255*e))),`#${n.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}function Mh(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9]+/g,"-").replace(/(^-|-$)/g,"").toLowerCase()}function Eh(t,e,n){let s=new Set,o=[];for(let i of t){let r=Mh(i.name);if(s.has(r)){let d=2;for(;s.has(`${r}-${d}`);)d++;r=`${r}-${d}`}s.add(r);let a=Ih(i.textContent),l=Ph(i,e,n),c=`Figma section "${i.name}" \u2014 ${i.width}x${i.height}px, ${i.textContent.length} text elements, ${i.children.length} children`;o.push({name:r,description:c,contentBrief:a,layoutNotes:l})}return{specs:o,moduleOrder:o.map(i=>i.name)}}function Ih(t){let e={};for(let o of t){let i=o.role;e[i]||(e[i]=[]),e[i].push(o.text)}let n=[],s=["headline","subheadline","body","cta","label","caption"];for(let o of s)if(e[o])for(let i of e[o])n.push(`**${o}** (use as field default): "${i}"`);return n.join(`
2466
+ `)}function Ph(t,e,n){let s=[];if(s.push(`Dimensions: ${t.width}x${t.height}px`),t.backgroundColor&&s.push(`Background: ${t.backgroundColor}`),t.layoutMode&&s.push(`Layout: ${t.layoutMode}`),t.itemSpacing&&s.push(`Gap: ${t.itemSpacing}px`),(t.paddingTop||t.paddingRight||t.paddingBottom||t.paddingLeft)&&s.push(`Padding: ${t.paddingTop||0}px ${t.paddingRight||0}px ${t.paddingBottom||0}px ${t.paddingLeft||0}px`),t.children.length>0){s.push(`
2467
+ Children (${t.children.length}):`);for(let o of t.children){let i=` - ${o.type} "${o.name}" (${o.width}x${o.height})`;o.layoutMode&&(i+=` [${o.layoutMode}]`),o.childCount>0&&(i+=` [${o.childCount} children]`),o.characters&&(i+=` text: "${o.characters.slice(0,60)}"`),s.push(i)}}if(e.length>0){s.push(`
2468
+ Available image assets:`);for(let o of e){let i=yd(o.localPath);s.push(` - get_asset_url("${n}/assets/${i}") \u2014 ${o.name}`)}}return s.join(`
2469
+ `)}function Rh(t,e,n,s,o){let i=[];if(i.push(`## Figma Design Translation
1389
2470
 
1390
2471
  TRANSLATE this Figma section into a HubSpot CMS module. This is a CONVERSION, not creation.
1391
2472
  - Use the EXACT text content from the design as field default values
@@ -1405,17 +2486,17 @@ The Figma design shows the DESKTOP layout. You MUST add responsive CSS:
1405
2486
  - Hide purely decorative elements if they break mobile layout
1406
2487
  - Add a \`@media (max-width: 1023px)\` block for tablet if the layout has 3+ columns
1407
2488
 
1408
- ## Section: "${e.name}" (${e.width}x${e.height}px)`),e.backgroundColor&&i.push(`Background: ${e.backgroundColor}`),(e.layoutMode||e.itemSpacing||e.paddingTop)&&(i.push(`
1409
- ### Layout`),e.layoutMode&&i.push(`Direction: ${e.layoutMode}`),e.itemSpacing&&i.push(`Gap: ${e.itemSpacing}px`),(e.paddingTop||e.paddingRight||e.paddingBottom||e.paddingLeft)&&i.push(`Padding: ${e.paddingTop||0}px ${e.paddingRight||0}px ${e.paddingBottom||0}px ${e.paddingLeft||0}px`)),e.textContent.length>0){i.push(`
1410
- ### Text Content \u2014 USE THESE AS FIELD DEFAULTS`);for(let a of e.textContent)i.push(`- **${a.role}** (${a.fontSize}px, weight ${a.fontWeight}): "${a.text}"`)}if(e.children.length>0){i.push(`
1411
- ### Structure (${e.children.length} children)`);for(let a of e.children){let r=`- ${a.type} "${a.name}" (${a.width}x${a.height})`;a.layoutMode&&(r+=` layout: ${a.layoutMode}`),a.childCount>0&&(r+=`, ${a.childCount} children`),a.characters&&(r+=`
1412
- text: "${a.characters.slice(0,100)}"`),i.push(r)}}if(n.length>0)if(o){i.push(`
1413
- ### Available Image Assets \u2014 USE get_asset_url()`),i.push("Images are uploaded as theme assets. Reference them with get_asset_url():");for(let a of n){let r=sl(a.localPath);i.push(`- \`get_asset_url("${s}/assets/${r}")\` \u2014 ${a.name}`)}}else{i.push(`
1414
- ### Images \u2014 USE IMAGE FIELDS WITH PLACEHOLDERS`),i.push('Do NOT use get_asset_url(). Instead, create "image" type fields in fields.json for each image.'),i.push('Set a descriptive default.src (e.g. "https://placehold.co/600x400?text=Hero+Image") and default.alt text.'),i.push("In the module HTML, use: {{ module.field_name.src }} and {{ module.field_name.alt }}"),i.push("This gives content editors full control to replace images in HubSpot.");for(let a of n)i.push(`- "${a.name}" \u2014 create an image field for this`)}return i.push(`
2489
+ ## Section: "${t.name}" (${t.width}x${t.height}px)`),t.backgroundColor&&i.push(`Background: ${t.backgroundColor}`),(t.layoutMode||t.itemSpacing||t.paddingTop)&&(i.push(`
2490
+ ### Layout`),t.layoutMode&&i.push(`Direction: ${t.layoutMode}`),t.itemSpacing&&i.push(`Gap: ${t.itemSpacing}px`),(t.paddingTop||t.paddingRight||t.paddingBottom||t.paddingLeft)&&i.push(`Padding: ${t.paddingTop||0}px ${t.paddingRight||0}px ${t.paddingBottom||0}px ${t.paddingLeft||0}px`)),t.textContent.length>0){i.push(`
2491
+ ### Text Content \u2014 USE THESE AS FIELD DEFAULTS`);for(let r of t.textContent)i.push(`- **${r.role}** (${r.fontSize}px, weight ${r.fontWeight}): "${r.text}"`)}if(t.children.length>0){i.push(`
2492
+ ### Structure (${t.children.length} children)`);for(let r of t.children){let a=`- ${r.type} "${r.name}" (${r.width}x${r.height})`;r.layoutMode&&(a+=` layout: ${r.layoutMode}`),r.childCount>0&&(a+=`, ${r.childCount} children`),r.characters&&(a+=`
2493
+ text: "${r.characters.slice(0,100)}"`),i.push(a)}}if(n.length>0)if(o){i.push(`
2494
+ ### Available Image Assets \u2014 USE get_asset_url()`),i.push("Images are uploaded as theme assets. Reference them with get_asset_url():");for(let r of n){let a=yd(r.localPath);i.push(`- \`get_asset_url("${s}/assets/${a}")\` \u2014 ${r.name}`)}}else{i.push(`
2495
+ ### Images \u2014 USE IMAGE FIELDS WITH PLACEHOLDERS`),i.push('Do NOT use get_asset_url(). Instead, create "image" type fields in fields.json for each image.'),i.push('Set a descriptive default.src (e.g. "https://placehold.co/600x400?text=Hero+Image") and default.alt text.'),i.push("In the module HTML, use: {{ module.field_name.src }} and {{ module.field_name.alt }}"),i.push("This gives content editors full control to replace images in HubSpot.");for(let r of n)i.push(`- "${r.name}" \u2014 create an image field for this`)}return i.push(`
1415
2496
  ## Module Specification
1416
- - **Name**: ${t.name}
1417
- - **Description**: ${t.description}`),i.join(`
1418
- `)}var rl=L(()=>{"use strict";f();qe();ti();ni();si();ie()});var al={};ke(al,{buildPlanModePrompt:()=>Jm});function Jm(e,t,n,s,o){let i=jm(o,!!t?.plan),a=[];return a.push(`You are vibeSpot's plan-mode assistant for the theme "${e}".
2497
+ - **Name**: ${e.name}
2498
+ - **Description**: ${e.description}`),i.join(`
2499
+ `)}var xd=R(()=>{"use strict";y();nt();gr();fr();br();de()});var vd={};Be(vd,{buildPlanModePrompt:()=>Nh});function Nh(t,e,n,s,o){let i=Oh(o,!!e?.plan),r=[];return r.push(`You are vibeSpot's plan-mode assistant for the theme "${t}".
1419
2500
 
1420
2501
  Plan mode is a DELIBERATION PHASE. Your job is to help the user articulate what they want to build BEFORE any code is generated. You do NOT write modules, HTML, or CSS in this mode. You ask questions, surface gaps, and maintain a living plan document.
1421
2502
 
@@ -1479,42 +2560,47 @@ Drive toward filling these gaps in priority order:
1479
2560
  4. **Sections / modules** \u2014 high-level page structure (hero, features, testimonials, pricing, FAQ, footer, etc.)
1480
2561
  5. **Content** \u2014 actual copy, value props, social proof, key messages
1481
2562
  6. **Brand voice and visual style** \u2014 formal/casual, palette preferences, reference sites
1482
- 7. **Constraints** \u2014 must-haves, must-avoids, integrations needed`),t?.styleguide&&a.push(`## Available styleguide
2563
+ 7. **Constraints** \u2014 must-haves, must-avoids, integrations needed`),e?.styleguide&&r.push(`## Available styleguide
1483
2564
 
1484
2565
  The theme already has a styleguide. Reference its colors, typography, and tokens in the plan rather than asking about them again.
1485
2566
 
1486
2567
  \`\`\`
1487
- ${oi(t.styleguide,1500)}
1488
- \`\`\``),t?.brandvoice&&a.push(`## Available brand voice
2568
+ ${Sr(e.styleguide,1500)}
2569
+ \`\`\``),e?.brandvoice&&r.push(`## Available brand voice
1489
2570
 
1490
2571
  \`\`\`
1491
- ${oi(t.brandvoice,1e3)}
1492
- \`\`\``),t?.themeContext&&a.push(`## Theme context
2572
+ ${Sr(e.brandvoice,1e3)}
2573
+ \`\`\``),e?.themeContext&&r.push(`## Theme context
1493
2574
 
1494
2575
  \`\`\`
1495
- ${oi(t.themeContext,1e3)}
1496
- \`\`\``),n.length>0&&a.push(`## Existing modules in this theme
2576
+ ${Sr(e.themeContext,1e3)}
2577
+ \`\`\``),n.length>0&&r.push(`## Existing modules in this theme
1497
2578
 
1498
2579
  These already exist on the page \u2014 you can keep, modify, or remove them in the plan, or reference them as reusable:
1499
2580
 
1500
- ${n.map(r=>`- ${r}`).join(`
1501
- `)}`),s.length>0&&a.push(`## Module library (reusable across templates)
2581
+ ${n.map(a=>`- ${a}`).join(`
2582
+ `)}`),s.length>0&&r.push(`## Module library (reusable across templates)
1502
2583
 
1503
2584
  These modules exist in other templates and could be reused here. Reference them by name in the plan if appropriate.
1504
2585
 
1505
- ${s.map(r=>`- **${r.name}** (used in: ${r.usedIn.join(", ")})`).join(`
1506
- `)}`),t?.plan&&a.push(`## Current plan (continue refining)
2586
+ ${s.map(a=>`- **${a.name}** (used in: ${a.usedIn.join(", ")})`).join(`
2587
+ `)}`),e?.plan&&r.push(`## Current plan (continue refining)
1507
2588
 
1508
2589
  The plan in progress so far. Build on it \u2014 preserve what's there, only update sections that are changing based on the user's latest message.
1509
2590
 
1510
2591
  \`\`\`markdown
1511
- ${t.plan}
1512
- \`\`\``),a.push(`## Phase guidance for this turn
2592
+ ${e.plan}
2593
+ \`\`\``),r.push(`## Phase guidance for this turn
1513
2594
 
1514
- ${i}`),a.join(`
2595
+ ${i}`),r.join(`
1515
2596
 
1516
- `)}function jm(e,t){return e===0&&!t?"**Phase 1: UNDERSTAND.** This is the user's first message in plan mode. Acknowledge what they said, then ask 2\u20133 high-leverage questions to surface gaps. The plan block should be a skeleton with TBDs and an **Open questions** section. Do NOT propose specific sections or content yet \u2014 you don't know enough.":e<=2&&!t?"**Phase 2: RESEARCH & DRAFT.** Take what the user has shared and produce a real first draft of the plan: goal, audience, primary CTA, and a proposed module list with brief descriptions. Reference existing modules/styleguide where applicable. Ask 1\u20132 narrow follow-ups to fill remaining gaps. Don't be exhaustive \u2014 a directionally-correct draft is better than asking 10 more questions.":`**Phase 3: REFINE.** A plan exists. Update it based on the user's latest message \u2014 change only what they're asking to change, preserve the rest. Confirm what you've updated in your conversational reply ("I changed the hero CTA to 'Get started free' and added a logos bar before the features section."). Ask narrow clarifying questions only when the user's edit creates a new ambiguity.`}function oi(e,t){return e.length<=t?e:e.slice(0,t)+`
1517
- ... [truncated]`}var ll=L(()=>{"use strict";f()});var dl={};ke(dl,{applyPipelineResult:()=>At,handleAgenticGenerate:()=>Ms,handleFigmaImport:()=>$n,handleGenerate:()=>Dm,handleGenerateStream:()=>An,handlePlanModeStream:()=>ci,isGenerating:()=>Wt,isPlanModeActive:()=>di,resolveAgenticEngine:()=>Vt,setParseWarningCallback:()=>ai,shouldUseAgenticMode:()=>ui});import{execSync as ii}from"child_process";function ai(e){ri=e}function Wt(){return ct!==null}function kt(e){if(ct){let t=v();if(!t||t.id!==ct){A.warn("ai-handler","Session changed during generation \u2014 discarding AI output");return}}Re("assistant",e),ma(e,ri||void 0),j()}async function An(e,t,n,s){let o=v();if(!o)throw new Error("No active session");ct=o.id;let a=s?.length?$s(s):void 0;try{let r=P(),l=r.aiEngine||li();switch(l){case"anthropic-api":case"api":{let c=be("anthropic-api",r);if(!c)throw new Error("Anthropic API key not configured. Open Settings to add one.");await xa(e,c,o.themeName,r.anthropicApiModel||"claude-sonnet-4-6",t,n,kt,a);break}case"claude-oauth":{await va(e,o.themeName,r.anthropicApiModel||"claude-sonnet-4-6",t,n,kt,a);break}case"openai-api":{let c=be("openai-api",r);if(!c)throw new Error("OpenAI API key not configured. Open Settings to add one.");await wa(e,c,o.themeName,r.openaiApiModel||"gpt-4o",t,n,kt,a);break}case"gemini-api":{let c=be("gemini-api",r);if(!c)throw new Error("Gemini API key not configured. Open Settings to add one.");await Ca(e,c,o.themeName,t,n,kt,a);break}case"claude-code":await ka(e,o.themeName,t,n,kt,a);break;case"gemini-cli":await Wo("gemini",e,o.themeName,t,n,kt,a);break;case"codex-cli":await Wo("codex",e,o.themeName,t,n,kt,a);break;default:throw new Error(`Unknown AI engine: ${l}. Open Settings to configure one.`)}}finally{ct=null,ri=null}}function li(){let e=P();if(Le())return"claude-oauth";if(e.anthropicApiKey||process.env.ANTHROPIC_API_KEY)return"anthropic-api";if(e.openaiApiKey||process.env.OPENAI_API_KEY)return"openai-api";if(e.geminiApiKey||process.env.GEMINI_API_KEY||process.env.GOOGLE_AI_API_KEY)return"gemini-api";try{return ii("claude --version",{stdio:"pipe"}),"claude-code"}catch{}try{return ii("gemini --version",{stdio:"pipe"}),"gemini-cli"}catch{}try{return ii("codex --version",{stdio:"pipe"}),"codex-cli"}catch{}throw new Error("No AI engine available. Open Settings to configure one.")}async function Dm(e){let t="";return await An(e,n=>{t+=n}),t}function cl(){let e=v(),t=xe(),n=t?[...t.modules]:[...e.modules],s=t?[...t.moduleOrder]:[...e.moduleOrder];return{modules:n,moduleOrder:s,sharedCss:t?.sharedCss||e.sharedCss,sharedJs:t?.sharedJs||e.sharedJs,messages:[...e.messages],themeName:e.themeName,themePath:e.themePath,brandAssets:e.brandAssets?{...e.brandAssets}:void 0}}function Vt(e){let t=e.aiEngine||li();if(!Cn(t))throw new Error("Agentic pipeline is not available for this engine.");if(Gt(t)){let o="";return t==="claude-code"&&(o=e.claudeCodeModel||""),{engine:t,apiKey:"",model:o}}let n;if(t==="claude-oauth"){if(!Le())throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");n="oauth"}else n=be(t,e);if(!n)throw new Error(`API key not configured for ${t}. Open Settings to add one.`);let s;switch(t){case"anthropic-api":case"claude-oauth":s=e.anthropicApiModel||"claude-sonnet-4-6";break;case"openai-api":s=e.openaiApiModel||"gpt-4o";break;case"gemini-api":s="gemini-2.5-flash";break;default:s=""}return{engine:t,apiKey:n,model:s}}async function Ms(e,t,n){let s=v();if(!s)throw new Error("No active session");let o=s.id;ct=o;try{let i=P(),{engine:a,apiKey:r,model:l}=Vt(i),c=i.agenticConcurrency||20,d=cl(),u=d.brandAssets?.plan,m=e;u&&u.trim()&&(m=`## Approved plan
2597
+ `)}function Oh(t,e){return t===0&&!e?"**Phase 1: UNDERSTAND.** This is the user's first message in plan mode. Acknowledge what they said, then ask 2\u20133 high-leverage questions to surface gaps. The plan block should be a skeleton with TBDs and an **Open questions** section. Do NOT propose specific sections or content yet \u2014 you don't know enough.":t===0&&e?`**Phase 1-T: TEMPLATED START.** The user picked a plan-mode template, so a structured plan already exists. Your job on this turn is to:
2598
+ - Briefly acknowledge the template and that you'll work from this structure (1\u20132 sentences in chat).
2599
+ - Pick 2\u20133 of the highest-leverage items from the plan's **Open questions** section and ask the user about them. Prefer questions about: product/page name + one-line pitch, primary CTA, and target audience. Save tone/visual questions for later turns.
2600
+ - Do NOT propose new sections or rewrite the existing structure on this turn \u2014 the user explicitly chose this scaffold. Keep the plan block VERBATIM (same headings, same sections, same open-questions list) and only re-emit it.
2601
+ - If the user's first message already supplies content (e.g. "It's for Acme, a fintech startup, primary CTA is book a demo"), thread that into the plan's TBDs and check those items off the **Open questions** list before asking your follow-ups.
2602
+ - Use \`vibespot-choices\` chips when one of your questions is multiple-choice (e.g. "Primary CTA?", "Cuisine?").`:t<=2&&!e?"**Phase 2: RESEARCH & DRAFT.** Take what the user has shared and produce a real first draft of the plan: goal, audience, primary CTA, and a proposed module list with brief descriptions. Reference existing modules/styleguide where applicable. Ask 1\u20132 narrow follow-ups to fill remaining gaps. Don't be exhaustive \u2014 a directionally-correct draft is better than asking 10 more questions.":`**Phase 3: REFINE.** A plan exists. Update it based on the user's latest message \u2014 change only what they're asking to change, preserve the rest. Confirm what you've updated in your conversational reply ("I changed the hero CTA to 'Get started free' and added a logos bar before the features section."). Ask narrow clarifying questions only when the user's edit creates a new ambiguity.`}function Sr(t,e){return t.length<=e?t:t.slice(0,e)+`
2603
+ ... [truncated]`}var wd=R(()=>{"use strict";y()});var $r={};Be($r,{applyPipelineResult:()=>qt,handleAgenticGenerate:()=>Eo,handleFigmaImport:()=>us,handleGenerate:()=>Fh,handleGenerateStream:()=>ds,handlePlanModeStream:()=>kr,isGenerating:()=>Ft,isPlanModeActive:()=>Tr,resolveAgenticEngine:()=>vn,setParseWarningCallback:()=>wr,shouldUseAgenticMode:()=>Ar});import{execSync as xr}from"child_process";function wr(t){vr=t}function Ft(){return $t!==null}function Yt(t){if($t){let e=C();if(!e||e.id!==$t){E.warn("ai-handler","Session changed during generation \u2014 discarding AI output");return}}tt("assistant",t),rc(t,vr||void 0),D()}async function ds(t,e,n,s){let o=C();if(!o)throw new Error("No active session");$t=o.id;let r=s?.length?Co(s):void 0;try{let a=O(),l=a.aiEngine||Cr();switch(l){case"anthropic-api":case"api":{let c=Oe("anthropic-api",a);if(!c)throw new Error("Anthropic API key not configured. Open Settings to add one.");await gc(t,c,o.themeName,a.anthropicApiModel||"claude-sonnet-4-6",e,n,Yt,r);break}case"claude-oauth":{await fc(t,o.themeName,a.anthropicApiModel||"claude-sonnet-4-6",e,n,Yt,r);break}case"openai-api":{let c=Oe("openai-api",a);if(!c)throw new Error("OpenAI API key not configured. Open Settings to add one.");await hc(t,c,o.themeName,a.openaiApiModel||"gpt-4o",e,n,Yt,r);break}case"gemini-api":{let c=Oe("gemini-api",a);if(!c)throw new Error("Gemini API key not configured. Open Settings to add one.");await yc(t,c,o.themeName,e,n,Yt,r);break}case"claude-code":await bc(t,o.themeName,e,n,Yt,r);break;case"gemini-cli":await tr("gemini",t,o.themeName,e,n,Yt,r);break;case"codex-cli":await tr("codex",t,o.themeName,e,n,Yt,r);break;default:throw new Error(`Unknown AI engine: ${l}. Open Settings to configure one.`)}}finally{$t=null,vr=null}}function Cr(){let t=O();if(lt())return"claude-oauth";if(t.anthropicApiKey||process.env.ANTHROPIC_API_KEY)return"anthropic-api";if(t.openaiApiKey||process.env.OPENAI_API_KEY)return"openai-api";if(t.geminiApiKey||process.env.GEMINI_API_KEY||process.env.GOOGLE_AI_API_KEY)return"gemini-api";try{return xr("claude --version",{stdio:"pipe"}),"claude-code"}catch{}try{return xr("gemini --version",{stdio:"pipe"}),"gemini-cli"}catch{}try{return xr("codex --version",{stdio:"pipe"}),"codex-cli"}catch{}throw new Error("No AI engine available. Open Settings to configure one.")}async function Fh(t){let e="";return await ds(t,n=>{e+=n}),e}function Cd(){let t=C(),e=Ce(),n=e?[...e.modules]:[...t.modules],s=e?[...e.moduleOrder]:[...t.moduleOrder],o={modules:n,moduleOrder:s,sharedCss:e?.sharedCss||t.sharedCss,sharedJs:e?.sharedJs||t.sharedJs,messages:[...t.messages],themeName:t.themeName,themePath:t.themePath,contentMode:e?.contentMode,brandAssets:t.brandAssets?{...t.brandAssets}:void 0};return t.templates.length>1&&(o.activePageLabel=e?.label,o.sitePages=t.templates.map(i=>({id:i.id,label:i.label,pageType:i.pageType,moduleCount:i.modules.length}))),o}function vn(t){let e=t.aiEngine||Cr();if(!rs(e))throw new Error("Agentic pipeline is not available for this engine.");if(xn(e)){let o="";return e==="claude-code"&&(o=t.claudeCodeModel||""),{engine:e,apiKey:"",model:o}}let n;if(e==="claude-oauth"){if(!lt())throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");n="oauth"}else n=Oe(e,t);if(!n)throw new Error(`API key not configured for ${e}. Open Settings to add one.`);let s;switch(e){case"anthropic-api":case"claude-oauth":s=t.anthropicApiModel||"claude-sonnet-4-6";break;case"openai-api":s=t.openaiApiModel||"gpt-5.5";break;case"gemini-api":s=t.geminiApiModel||"gemini-2.5-pro";break;case"claude-code":s=t.claudeCodeModel||"";break;case"codex-cli":s=t.codexCliModel||"";break;case"gemini-cli":s=t.geminiCliModel||"";break;default:s=""}return{engine:e,apiKey:n,model:s}}async function Eo(t,e,n){let s=C();if(!s)throw new Error("No active session");let o=s.id;$t=o;try{let i=O(),{engine:r,apiKey:a,model:l}=vn(i),c=i.agenticConcurrency||20,d=Cd(),u=d.brandAssets?.plan,m=t;u&&u.trim()&&(m=`## Approved plan
1518
2604
 
1519
2605
  Build the page according to this plan exactly. The user reviewed and approved it; do not deviate from its goal, audience, sections, or content unless the user message below explicitly requests changes.
1520
2606
 
@@ -1524,32 +2610,39 @@ ${u}
1524
2610
 
1525
2611
  ## User message
1526
2612
 
1527
- ${e}`);let g=n?.length?$s(n):void 0;if(g?.length)for(let S of g)S.type==="document"&&S.extractedText&&(m+=`
2613
+ ${t}`);let g=n?.length?Co(n):void 0;if(g?.length)for(let w of g)w.type==="document"&&w.extractedText&&(m+=`
1528
2614
 
1529
2615
  ---
1530
- [Attached document: ${S.originalName}]
1531
- ${S.extractedText}`),S.type==="image"&&S.usage==="asset"&&S.assetPath&&(m+=`
2616
+ [Attached document: ${w.originalName}]
2617
+ ${w.extractedText}`),w.type==="image"&&w.usage==="asset"&&w.assetPath&&(m+=`
1532
2618
 
1533
- [Uploaded image: ${S.originalName} \u2192 available as get_asset_url("${S.assetPath}")]`);let y=at(),h=new Set(d.modules.map(S=>S.moduleName)),b=y.filter(S=>!h.has(S.module.moduleName)).map(S=>({name:S.module.moduleName,usedIn:S.usedIn})),x=await Qa(m,d,a,r,l,c,t,b),w=v();if(!w||w.id!==o)throw A.warn("ai-handler","Session changed during agentic generation \u2014 discarding output"),new Error("Session changed during generation");return x}finally{ct=null}}async function $n(e,t,n,s){let o=v();if(!o)throw new Error("No active session");let i=o.id;ct=i;try{let{runFigmaConversion:a}=await Promise.resolve().then(()=>(rl(),il)),r=P(),{engine:l,apiKey:c,model:d}=Vt(r),u=r.agenticConcurrency||20,m=cl(),g=await a(e,t,l,c,d,u,n,m.brandAssets,s?.useAssets),y=v();if(!y||y.id!==i)throw A.warn("ai-handler","Session changed during Figma import \u2014 discarding output"),new Error("Session changed during generation");return g}finally{ct=null}}function At(e,t){oe({modules:e.modules,sharedCss:e.sharedCss,sharedJs:e.sharedJs}),Ke(e.moduleOrder),Re("assistant",e.assistantMessage,t),j()}async function ci(e,t,n){let s=v();if(!s)throw new Error("No active session");let o=P(),{engine:i,apiKey:a,model:r}=Vt(o),[{buildPlanModePrompt:l},{callAgent:c}]=await Promise.all([Promise.resolve().then(()=>(ll(),al)),Promise.resolve().then(()=>(qe(),Pa))]),d=s.messages.filter(S=>S.role==="assistant").length,u=s.modules.map(S=>S.moduleName),m=at(),g=new Set(u),y=m.filter(S=>!g.has(S.module.moduleName)).map(S=>({name:S.module.moduleName,usedIn:S.usedIn})),h=l(s.themeName,s.brandAssets,u,y,d),b=n?.length?$s(n):void 0,x=e;if(b?.length)for(let S of b)S.type==="document"&&S.extractedText&&(x+=`
2619
+ [Uploaded image: ${w.originalName} \u2192 available as get_asset_url("${w.assetPath}")]`);let h=At(),f=new Set(d.modules.map(w=>w.moduleName)),b=h.filter(w=>!f.has(w.module.moduleName)).map(w=>({name:w.module.moduleName,usedIn:w.usedIn})),S=await pd(m,d,r,a,l,c,e,b),x=C();if(!x||x.id!==o)throw E.warn("ai-handler","Session changed during agentic generation \u2014 discarding output"),new Error("Session changed during generation");return S}finally{$t=null}}async function us(t,e,n,s){let o=C();if(!o)throw new Error("No active session");let i=o.id;$t=i;try{let{runFigmaConversion:r}=await Promise.resolve().then(()=>(xd(),Sd)),a=O(),{engine:l,apiKey:c,model:d}=vn(a),u=a.agenticConcurrency||20,m=Cd(),g=await r(t,e,l,c,d,u,n,m.brandAssets,s?.useAssets),h=C();if(!h||h.id!==i)throw E.warn("ai-handler","Session changed during Figma import \u2014 discarding output"),new Error("Session changed during generation");return g}finally{$t=null}}function qt(t,e){let n=t.multiPage;if(n&&n.pages.length>0){let s=new Map;for(let o of n.pages)s.set(o.pageId,{label:o.label||o.pageId,pageType:o.pageType||"website_page"});Al({pages:n.pages,sharedModules:n.sharedModules,sharedCss:n.sharedCss,sharedJs:n.sharedJs,pageLabels:s})}else if(De({modules:t.modules,sharedCss:t.sharedCss,sharedJs:t.sharedJs}),Rt(t.moduleOrder),t.contentType==="email"){let o=Ce();o&&!o.contentMode&&(o.contentMode="email")}tt("assistant",t.assistantMessage,e),D()}async function kr(t,e,n){let s=C();if(!s)throw new Error("No active session");let o=O(),{engine:i,apiKey:r,model:a}=vn(o),[{buildPlanModePrompt:l},{callAgent:c}]=await Promise.all([Promise.resolve().then(()=>(wd(),vd)),Promise.resolve().then(()=>(nt(),Ac))]),d=s.messages.filter(w=>w.role==="assistant").length,u=s.modules.map(w=>w.moduleName),m=At(),g=new Set(u),h=m.filter(w=>!g.has(w.module.moduleName)).map(w=>({name:w.module.moduleName,usedIn:w.usedIn})),f=l(s.themeName,s.brandAssets,u,h,d),b=n?.length?Co(n):void 0,S=t;if(b?.length)for(let w of b)w.type==="document"&&w.extractedText&&(S+=`
1534
2620
 
1535
2621
  ---
1536
- [Attached document: ${S.originalName}]
1537
- ${S.extractedText}`);let w=await c(i,a,r,{systemPrompt:h,messages:[{role:"user",content:x}],maxTokens:8e3,onChunk:t,enableWebSearch:!!o.webSearch});return w.type==="text"?w.text:JSON.stringify(w.data)}function di(){return!!P().planMode}function ui(){let e=P(),t=e.aiEngine||li();return Cn(t)?e.agenticMode===void 0?{useAgentic:!1,needsPrompt:!0}:{useAgentic:e.agenticMode,needsPrompt:!1}:{useAgentic:!1,needsPrompt:!1,reason:"Agentic pipeline is not available for this engine."}}var ri,ct,Tn=L(()=>{"use strict";f();Q();pe();As();ie();Vo();tt();Yo();el();ri=null;ct=null});var Ls={};ke(Ls,{collectThemeFiles:()=>ec,extractDesignContext:()=>dp});import{existsSync as js,readdirSync as Ds,readFileSync as rp}from"fs";import{join as Xe}from"path";import{spawn as ap}from"child_process";async function Ql(){return yi||(yi=(await import("@anthropic-ai/sdk")).default),yi}function _n(e){try{return rp(e,"utf-8")}catch{return""}}function ec(e){let t=[],n=0;function s(r,l){if(!l.trim())return!0;let c=`
1538
- ### ${r}
2622
+ [Attached document: ${w.originalName}]
2623
+ ${w.extractedText}`);let x=await c(i,r,a,{systemPrompt:f,messages:[{role:"user",content:S}],maxTokens:8e3,onChunk:e,enableWebSearch:!!o.webSearch});return x.type==="text"?x.text:JSON.stringify(x.data)}function Tr(){return!!O().planMode}function Ar(){let t=O(),e=t.aiEngine||Cr();return rs(e)?t.agenticMode===void 0?{useAgentic:!1,needsPrompt:!0}:{useAgentic:t.agenticMode,needsPrompt:!1}:{useAgentic:!1,needsPrompt:!1,reason:"Agentic pipeline is not available for this engine."}}var vr,$t,wn=R(()=>{"use strict";y();Q();we();wo();de();nr();xt();ir();gd();vr=null;$t=null});import{readFileSync as jh,readdirSync as Dh,existsSync as Lh}from"fs";import{dirname as Jh,join as Io}from"path";import{fileURLToPath as Bh}from"url";function Uh(t){let e=t.match(Hh);if(!e)return null;let[,n,s]=e,o={};for(let i of n.split(/\r?\n/)){let r=i.indexOf(":");if(r===-1)continue;let a=i.slice(0,r).trim(),l=i.slice(r+1).trim();(l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'"))&&(l=l.slice(1,-1)),a&&(o[a]=l)}return{fields:o,body:s.trimStart()}}function Gh(t){let e=Uh(t);if(!e)return null;let{fields:n,body:s}=e,o=n.id,i=n.label,r=n.description??"";if(!o||!i)return null;let a=n.order?Number(n.order):NaN,l=n.contentType==="email"?"email":void 0;return{id:o,label:i,description:r,icon:n.icon||void 0,order:Number.isFinite(a)?a:9999,contentType:l,body:s.trimEnd()+`
2624
+ `}}function Wh(){let t=[Io(kd,"../../assets/plan-templates"),Io(kd,"../assets/plan-templates"),Io(process.cwd(),"assets/plan-templates")];for(let e of t)if(Lh(e))return e;return null}function Td(){if(jt)return jt;let t=Wh();if(!t)return jt=[],jt;let e=[],n=[];try{n=Dh(t)}catch{return jt=[],jt}for(let s of n)if(s.endsWith(".md"))try{let o=jh(Io(t,s),"utf-8"),i=Gh(o);i&&e.push(i)}catch{}return e.sort((s,o)=>s.order!==o.order?s.order-o.order:s.label.localeCompare(o.label)),jt=e,jt}function Ad(t){return Td().find(e=>e.id===t)??null}function $d(){return Td().map(({id:t,label:e,description:n,icon:s,order:o,contentType:i})=>({id:t,label:e,description:n,icon:s,order:o,contentType:i}))}var kd,Hh,jt,_d=R(()=>{"use strict";y();kd=Jh(Bh(import.meta.url)),Hh=/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/;jt=null});import{existsSync as Md,mkdirSync as Kh,writeFileSync as Vh,rmSync as zh}from"fs";import{join as Ed}from"path";function Id(t){return Ed(t,".vibespot",Yh)}function Po(t){let e=C();if(!e)return null;e.brandAssets||(e.brandAssets={}),e.brandAssets.plan=t;let n=Ce();n&&(n.plan=t);try{let s=Ed(e.themePath,".vibespot");Md(s)||Kh(s,{recursive:!0}),Vh(Id(e.themePath),t,"utf-8")}catch(s){E.warn("plan",`Failed to write plan.md: ${s instanceof Error?s.message:String(s)}`)}return D(),t}function _r(){let t=C();if(!t)return;t.brandAssets&&delete t.brandAssets.plan;let e=Ce();e&&delete e.plan;try{let n=Id(t.themePath);Md(n)&&zh(n)}catch(n){E.warn("plan",`Failed to remove plan.md: ${n instanceof Error?n.message:String(n)}`)}D()}function Pd(t,e){Ve(t,e,n=>{if(!C()){p(e,400,{error:"No active session"});return}let o=typeof n.markdown=="string"?n.markdown:"";if(!o.trim()){p(e,400,{error:"Plan content cannot be empty"});return}Po(o),p(e,200,{ok:!0,plan:o})})}function Rd(t,e){Ve(t,e,()=>{_r(),Y({planMode:!1}),p(e,200,{ok:!0})})}function Nd(t,e){p(e,200,{templates:$d()})}function Od(t,e){Ve(t,e,n=>{if(!C()){p(e,400,{error:"No active session"});return}let o=typeof n.templateId=="string"?n.templateId.trim():"";if(!o){p(e,400,{error:"templateId is required"});return}let i=Ad(o);if(!i){p(e,404,{error:`Unknown plan template: ${o}`});return}Po(i.body),Y({planMode:!0}),p(e,200,{ok:!0,templateId:i.id,label:i.label,plan:i.body})})}var Yh,Fd=R(()=>{"use strict";y();ze();we();Nt();Q();de();_d();Yh="plan.md"});function jd(t){let e,n,s;for(Mr.lastIndex=0;(s=Mr.exec(t))!==null;)e=s[1].trim();let o;for(Er.lastIndex=0;(o=Er.exec(t))!==null;)try{let r=JSON.parse(o[1].trim());r&&typeof r.question=="string"&&Array.isArray(r.options)&&r.options.every(a=>typeof a=="string")&&r.options.length>0&&(n={question:r.question,options:r.options})}catch{}return{cleanedContent:t.replace(Mr,"").replace(Er,"").replace(/\n{3,}/g,`
2625
+
2626
+ `).trim(),plan:e,choices:n}}var Mr,Er,Dd=R(()=>{"use strict";y();Mr=/```vibespot-plan\s*\n([\s\S]*?)```/g,Er=/```vibespot-choices\s*\n([\s\S]*?)```/g});import{spawn as Ir}from"child_process";function Ld(t,e,n){t.stdout?.on("data",o=>{e.output+=o.toString()}),t.stderr?.on("data",o=>{e.output+=o.toString()}),t.on("close",o=>{e.status=o===0?"completed":"failed",e.exitCode=o,e.completedAt=Date.now()}),t.on("error",o=>{e.status="failed",e.output+=`
2627
+ Process error: ${o.message}`,e.completedAt=Date.now()}),setTimeout(()=>{e.status==="running"&&(t.kill(),e.status="failed",e.output+=`
2628
+ Process timed out`,e.completedAt=Date.now())},n||3e5)}function ms(t,e,n,s){let o=`job-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,6)}`,i={id:o,command:`${t} ${e.join(" ")}`,description:n,status:"running",output:"",exitCode:null,startedAt:Date.now(),completedAt:null};Dt.set(o,i);let r=Ir(t,e,{cwd:s?.cwd,stdio:[s?.stdin?"pipe":"ignore","pipe","pipe"],env:{...process.env,...s?.env},shell:process.platform==="win32"});return s?.stdin&&r.stdin&&(r.stdin.write(s.stdin),r.stdin.end()),Ld(r,i,s?.timeout),o}function Xt(t,e,n){let s=`job-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,6)}`,o={id:s,command:t,description:e,status:"running",output:"",exitCode:null,startedAt:Date.now(),completedAt:null};Dt.set(s,o);let i=t.split(" "),r=Ir(i[0],i.slice(1),{cwd:n?.cwd,stdio:["ignore","pipe","pipe"],env:{...process.env,...n?.env},shell:!0});return Ld(r,o,n?.timeout),s}function Ro(t){return Dt.get(t)}function qh(){let t=Date.now()-18e5;for(let[e,n]of Dt)n.completedAt&&n.completedAt<t&&Dt.delete(e)}function No(t,e,n){let s=`job-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,6)}`,o={id:s,command:t,description:e,status:"running",output:"",exitCode:null,startedAt:Date.now(),completedAt:null,listeners:new Set};Dt.set(s,o);let i=t.split(" "),r=Ir(i[0],i.slice(1),{cwd:n?.cwd,stdio:["ignore","pipe","pipe"],env:{...process.env,...n?.env},shell:!0}),a=c=>{for(let d of o.listeners)try{d(c)}catch{}};r.stdout?.on("data",c=>{let d=c.toString();o.output+=d,a(d)}),r.stderr?.on("data",c=>{let d=c.toString();o.output+=d,a(d)}),r.on("close",c=>{o.status=c===0?"completed":"failed",o.exitCode=c,o.completedAt=Date.now(),o.listeners.clear()}),r.on("error",c=>{o.status="failed",o.output+=`
2629
+ Process error: ${c.message}`,o.completedAt=Date.now(),o.listeners.clear()});let l=n?.timeout||3e5;return setTimeout(()=>{o.status==="running"&&(r.kill(),o.status="failed",o.output+=`
2630
+ Process timed out`,o.completedAt=Date.now(),o.listeners.clear())},l),s}function Jd(t,e){let n=Dt.get(t);if(!n||!("listeners"in n))return;let s=n;if(s.output)try{e(s.output)}catch{}s.listeners.add(e)}function Bd(t,e){let n=Dt.get(t);!n||!("listeners"in n)||n.listeners.delete(e)}var Dt,Oo=R(()=>{"use strict";y();Dt=new Map;setInterval(qh,600*1e3)});import{readFileSync as Xh,readdirSync as Zh,existsSync as Qh}from"fs";import{dirname as ey,join as Fo}from"path";import{fileURLToPath as ty}from"url";function ny(){let t=[Fo(Hd,"../../starters"),Fo(Hd,"../starters"),Fo(process.cwd(),"starters")];for(let e of t)if(Qh(e))return e;return null}function Ud(){if(Cn!==null)return Cn;let t=ny();if(!t)return Cn=[],Cn;let e=[];for(let n of Zh(t).filter(s=>s.endsWith(".json")).sort())try{let s=JSON.parse(Xh(Fo(t,n),"utf-8"));e.push({id:s.id,name:s.name,description:s.description,category:s.category||"General",contentType:s.contentType==="email"?"email":void 0,modules:s.modules||[],moduleOrder:s.moduleOrder||[],sharedCss:s.sharedCss||"",sharedJs:s.sharedJs||""})}catch{}return Cn=e,Cn}function Gd(){return Ud().map(t=>({id:t.id,name:t.name,description:t.description,category:t.category,contentType:t.contentType,moduleCount:t.modules.length}))}function Pr(t){return Ud().find(e=>e.id===t)||null}var Hd,Cn,Wd=R(()=>{"use strict";y();Hd=ey(ty(import.meta.url)),Cn=null});var gs={};Be(gs,{collectThemeFiles:()=>Vd,extractDesignContext:()=>ay});import{existsSync as jo,readdirSync as Do,readFileSync as sy}from"fs";import{join as ht}from"path";import{spawn as oy}from"child_process";async function Kd(){return Rr||(Rr=(await import("@anthropic-ai/sdk")).default),Rr}function ps(t){try{return sy(t,"utf-8")}catch{return""}}function Vd(t){let e=[],n=0;function s(a,l){if(!l.trim())return!0;let c=`
2631
+ ### ${a}
1539
2632
  \`\`\`
1540
2633
  ${l}
1541
2634
  \`\`\`
1542
- `;return n+c.length>lp?!1:(t.push(c),n+=c.length,!0)}let o=_n(Xe(e,"theme.json"));o&&s("theme.json",o);let i=Xe(e,"css");if(js(i)){for(let r of Ds(i).filter(l=>l.endsWith(".css")))if(!s(`css/${r}`,_n(Xe(i,r))))break}let a=Xe(e,"modules");if(js(a))for(let r of Ds(a).filter(l=>l.endsWith(".module"))){let l=Xe(a,r),c=_n(Xe(l,"module.css"));if(c&&!s(`modules/${r}/module.css`,c))break}if(js(a))for(let r of Ds(a).filter(l=>l.endsWith(".module"))){let l=Xe(a,r),c=_n(Xe(l,"module.html"));if(c&&!s(`modules/${r}/module.html`,c))break}if(js(a))for(let r of Ds(a).filter(l=>l.endsWith(".module"))){let l=Xe(a,r),c=_n(Xe(l,"fields.json"));if(c&&!s(`modules/${r}/fields.json`,c))break}return t.join("")}function cp(){if(!Hs)try{Hs=E(Fn("extraction-prompt.md"))}catch{Hs=""}return Hs}function bi(e,t,n){return new Promise((s,o)=>{let i={...process.env};delete i.CLAUDECODE;let a=ap(e,t,{stdio:["pipe","pipe","pipe"],env:i,shell:!0}),r="",l="";a.stdout.on("data",c=>{r+=c.toString()}),a.stderr.on("data",c=>{l+=c.toString()}),a.on("error",c=>o(new Error(`${e} failed to start: ${c.message}`))),a.on("close",c=>{c===0||r.trim()?s(r.trim()):o(new Error(`${e} exited with code ${c}: ${l.trim()}`))}),a.stdin.write(n),a.stdin.end()})}async function dp(e,t){t?.({status:"Collecting theme files..."});let n=ec(e);if(!n.trim())throw new Error("No CSS, HTML, or fields.json files found in theme.");let s=cp();if(!s)throw new Error("Extraction prompt not found (assets/extraction-prompt.md).");let o=`Analyze this HubSpot CMS theme and extract the design system:
1543
- ${n}`;t?.({status:"Analyzing design patterns..."});let i=P(),a=i.aiEngine||"anthropic-api",r="";switch(a){case"anthropic-api":case"api":{let l=be("anthropic-api");if(!l)throw new Error("Anthropic API key not configured. Open Settings to add one.");let c=await Ql();r=(await new c({apiKey:l}).messages.create({model:i.anthropicApiModel||"claude-sonnet-4-6",max_tokens:8e3,system:[{type:"text",text:s,cache_control:{type:"ephemeral"}}],messages:[{role:"user",content:o}]})).content.map(m=>m.type==="text"?m.text:"").join("");break}case"claude-oauth":{let{getValidAccessToken:l,OAUTH_EXTRA_HEADERS:c,OAUTH_SYSTEM_PREFIX:d}=await Promise.resolve().then(()=>(tt(),so)),u=await l();if(!u)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let m=await Ql();r=(await new m({authToken:u,defaultHeaders:c}).messages.create({model:i.anthropicApiModel||"claude-sonnet-4-6",max_tokens:8e3,system:[{type:"text",text:d},{type:"text",text:s,cache_control:{type:"ephemeral"}}],messages:[{role:"user",content:o}]})).content.map(h=>h.type==="text"?h.text:"").join("");break}case"openai-api":{let l=be("openai-api");if(!l)throw new Error("OpenAI API key not configured. Open Settings to add one.");let c=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${l}`},body:JSON.stringify({model:i.openaiApiModel||"gpt-4o",max_tokens:8e3,messages:[{role:"system",content:s},{role:"user",content:o}]})});if(!c.ok)throw new Error(`OpenAI API error: ${c.status} ${await c.text()}`);r=(await c.json()).choices?.[0]?.message?.content||"";break}case"gemini-api":{let l=be("gemini-api");if(!l)throw new Error("Gemini API key not configured. Open Settings to add one.");let c=i.geminiApiModel||"gemini-2.5-flash",d=await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${c}:generateContent?key=${l}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({system_instruction:{parts:[{text:s}]},contents:[{role:"user",parts:[{text:o}]}],generationConfig:{maxOutputTokens:8e3}})});if(!d.ok)throw new Error(`Gemini API error: ${d.status} ${await d.text()}`);r=(await d.json()).candidates?.[0]?.content?.parts?.map(m=>m.text).join("")||"";break}case"claude-code":{let l=`${s}
2635
+ `;return n+c.length>iy?!1:(e.push(c),n+=c.length,!0)}let o=ps(ht(t,"theme.json"));o&&s("theme.json",o);let i=ht(t,"css");if(jo(i)){for(let a of Do(i).filter(l=>l.endsWith(".css")))if(!s(`css/${a}`,ps(ht(i,a))))break}let r=ht(t,"modules");if(jo(r))for(let a of Do(r).filter(l=>l.endsWith(".module"))){let l=ht(r,a),c=ps(ht(l,"module.css"));if(c&&!s(`modules/${a}/module.css`,c))break}if(jo(r))for(let a of Do(r).filter(l=>l.endsWith(".module"))){let l=ht(r,a),c=ps(ht(l,"module.html"));if(c&&!s(`modules/${a}/module.html`,c))break}if(jo(r))for(let a of Do(r).filter(l=>l.endsWith(".module"))){let l=ht(r,a),c=ps(ht(l,"fields.json"));if(c&&!s(`modules/${a}/fields.json`,c))break}return e.join("")}function ry(){if(!Lo)try{Lo=M(Ts("extraction-prompt.md"))}catch{Lo=""}return Lo}function Nr(t,e,n){return new Promise((s,o)=>{let i={...process.env};delete i.CLAUDECODE;let r=oy(t,e,{stdio:["pipe","pipe","pipe"],env:i,shell:!0}),a="",l="";r.stdout.on("data",c=>{a+=c.toString()}),r.stderr.on("data",c=>{l+=c.toString()}),r.on("error",c=>o(new Error(`${t} failed to start: ${c.message}`))),r.on("close",c=>{c===0||a.trim()?s(a.trim()):o(new Error(`${t} exited with code ${c}: ${l.trim()}`))}),r.stdin.write(n),r.stdin.end()})}async function ay(t,e){e?.({status:"Collecting theme files..."});let n=Vd(t);if(!n.trim())throw new Error("No CSS, HTML, or fields.json files found in theme.");let s=ry();if(!s)throw new Error("Extraction prompt not found (assets/extraction-prompt.md).");let o=`Analyze this HubSpot CMS theme and extract the design system:
2636
+ ${n}`;e?.({status:"Analyzing design patterns..."});let i=O(),r=i.aiEngine||"anthropic-api",a="";switch(r){case"anthropic-api":case"api":{let l=Oe("anthropic-api");if(!l)throw new Error("Anthropic API key not configured. Open Settings to add one.");let c=await Kd();a=(await new c({apiKey:l}).messages.create({model:i.anthropicApiModel||"claude-sonnet-4-6",max_tokens:8e3,system:[{type:"text",text:s,cache_control:{type:"ephemeral"}}],messages:[{role:"user",content:o}]})).content.map(m=>m.type==="text"?m.text:"").join("");break}case"claude-oauth":{let{getValidAccessToken:l,OAUTH_EXTRA_HEADERS:c,OAUTH_SYSTEM_PREFIX:d}=await Promise.resolve().then(()=>(xt(),gi)),u=await l();if(!u)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let m=await Kd();a=(await new m({authToken:u,defaultHeaders:c}).messages.create({model:i.anthropicApiModel||"claude-sonnet-4-6",max_tokens:8e3,system:[{type:"text",text:d},{type:"text",text:s,cache_control:{type:"ephemeral"}}],messages:[{role:"user",content:o}]})).content.map(f=>f.type==="text"?f.text:"").join("");break}case"openai-api":{let l=Oe("openai-api");if(!l)throw new Error("OpenAI API key not configured. Open Settings to add one.");let c=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${l}`},body:JSON.stringify({model:i.openaiApiModel||"gpt-4o",max_tokens:8e3,messages:[{role:"system",content:s},{role:"user",content:o}]})});if(!c.ok)throw new Error(`OpenAI API error: ${c.status} ${await c.text()}`);a=(await c.json()).choices?.[0]?.message?.content||"";break}case"gemini-api":{let l=Oe("gemini-api");if(!l)throw new Error("Gemini API key not configured. Open Settings to add one.");let c=i.geminiApiModel||"gemini-2.5-flash",d=await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${c}:generateContent?key=${l}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({system_instruction:{parts:[{text:s}]},contents:[{role:"user",parts:[{text:o}]}],generationConfig:{maxOutputTokens:8e3}})});if(!d.ok)throw new Error(`Gemini API error: ${d.status} ${await d.text()}`);a=(await d.json()).candidates?.[0]?.content?.parts?.map(m=>m.text).join("")||"";break}case"claude-code":{let l=`${s}
1544
2637
 
1545
2638
  ## User Request
1546
- ${o}`,c=["--print"];i.claudeCodeModel&&c.push("--model",i.claudeCodeModel),r=await bi("claude",c,l);break}case"gemini-cli":{let l=`${s}
2639
+ ${o}`,c=["--print"];i.claudeCodeModel&&c.push("--model",i.claudeCodeModel),a=await Nr("claude",c,l);break}case"gemini-cli":{let l=`${s}
1547
2640
 
1548
2641
  ## User Request
1549
- ${o}`;r=await bi("gemini",[],l);break}case"codex-cli":{let l=`${s}
2642
+ ${o}`;a=await Nr("gemini",[],l);break}case"codex-cli":{let l=`${s}
1550
2643
 
1551
2644
  ## User Request
1552
- ${o}`;r=await bi("codex",[],l);break}default:throw new Error(`Unknown AI engine: ${a}. Open Settings to configure one.`)}if(!r.trim())throw new Error("AI returned empty response.");return t?.({status:"Design extraction complete."}),r}var yi,lp,Hs,Bs=L(()=>{"use strict";f();te();Q();yi=null;lp=8e4;Hs=""});var tc={};ke(tc,{extractBrandvoice:()=>up});async function up(e,t,n,s){if(!e||e.length<50)return null;let o=`You are a brand strategist. Analyze the rendered landing page HTML below and extract a concise brand voice guide. The HTML contains the actual text content with all template variables resolved to their default values.
2645
+ ${o}`;a=await Nr("codex",[],l);break}default:throw new Error(`Unknown AI engine: ${r}. Open Settings to configure one.`)}if(!a.trim())throw new Error("AI returned empty response.");return e?.({status:"Design extraction complete."}),a}var Rr,iy,Lo,fs=R(()=>{"use strict";y();ne();Q();Rr=null;iy=8e4;Lo=""});var Or={};Be(Or,{extractBrandvoice:()=>ly});async function ly(t,e,n,s){if(!t||t.length<50)return null;let o=`You are a brand strategist. Analyze the rendered landing page HTML below and extract a concise brand voice guide. The HTML contains the actual text content with all template variables resolved to their default values.
1553
2646
 
1554
2647
  Return a markdown document with these sections (skip any section where the content provides no signal):
1555
2648
 
@@ -1569,7 +2662,7 @@ Typical sentence length, structure, use of questions, imperatives, etc.
1569
2662
  ## Dos and Don'ts
1570
2663
  3-4 practical rules for writing in this voice (e.g., "Do: Lead with benefits, not features", "Don't: Use jargon without context").
1571
2664
 
1572
- Keep it actionable \u2014 this guide will be fed to AI to maintain consistent copy across pages.`;try{let i=await Ce(t,n,s,{systemPrompt:o,messages:[{role:"user",content:e}],maxTokens:1e3}),a=i.type==="text"?i.text:JSON.stringify(i.data);return!a||a.trim().length<20?null:(A.info("brandvoice-extractor",`Extracted brand voice (${a.length} chars)`),a.trim())}catch(i){let a=i instanceof Error?i.message:String(i);return A.warn("brandvoice-extractor",`Brand voice extraction failed: ${a}`),null}}var nc=L(()=>{"use strict";f();qe();ie()});var Si={};ke(Si,{extractThemeContext:()=>mp});async function mp(e,t,n,s,o){if(!e||e.length<50)return null;let a=`You are a content analyst. Extract a concise product/company brief from the rendered landing page HTML below. The HTML contains the actual text content (headings, paragraphs, button labels, image alt text, etc.) with all template variables resolved to their default values.
2665
+ Keep it actionable \u2014 this guide will be fed to AI to maintain consistent copy across pages.`;try{let i=await _e(e,n,s,{systemPrompt:o,messages:[{role:"user",content:t}],maxTokens:1e3}),r=i.type==="text"?i.text:JSON.stringify(i.data);return!r||r.trim().length<20?null:(E.info("brandvoice-extractor",`Extracted brand voice (${r.length} chars)`),r.trim())}catch(i){let r=i instanceof Error?i.message:String(i);return E.warn("brandvoice-extractor",`Brand voice extraction failed: ${r}`),null}}var Fr=R(()=>{"use strict";y();nt();de()});var Jo={};Be(Jo,{extractThemeContext:()=>cy});async function cy(t,e,n,s,o){if(!t||t.length<50)return null;let r=`You are a content analyst. Extract a concise product/company brief from the rendered landing page HTML below. The HTML contains the actual text content (headings, paragraphs, button labels, image alt text, etc.) with all template variables resolved to their default values.
1573
2666
 
1574
2667
  Return a markdown document with these sections (skip any section where the content provides no information):
1575
2668
 
@@ -1588,42 +2681,69 @@ Communication style (e.g., professional, casual, technical, friendly).
1588
2681
  ## Key Terminology
1589
2682
  Specific terms, product names, or branded language used consistently.
1590
2683
 
1591
- Keep it concise \u2014 this brief is used as context for AI-generated content on other pages in the same theme.${t?`
2684
+ Keep it concise \u2014 this brief is used as context for AI-generated content on other pages in the same theme.${e?`
1592
2685
 
1593
2686
  Existing product context (update if the new content adds info, keep what's still accurate):
1594
- ${t}`:""}`;try{let r=await Ce(n,s,o,{systemPrompt:a,messages:[{role:"user",content:e}],maxTokens:1e3}),l=r.type==="text"?r.text:JSON.stringify(r.data);return!l||l.trim().length<20?null:(A.info("context-extractor",`Extracted theme context (${l.length} chars)`),l.trim())}catch(r){let l=r instanceof Error?r.message:String(r);return A.warn("context-extractor",`Theme context extraction failed: ${l}`),null}}var xi=L(()=>{"use strict";f();qe();ie()});import{writeFileSync as bp,mkdirSync as $c}from"fs";import{join as Gs}from"path";import{randomUUID as Sp}from"crypto";function Tc(e){let t=e.match(xp);if(!t)return null;let n=t[1],s=t[2]?decodeURIComponent(t[2].replace(/-/g," ")):void 0,o;try{let a=new URL(e).searchParams.get("node-id");a&&(o=a.replace(/-/g,":"))}catch{}return{fileKey:n,nodeId:o,fileName:s}}async function Vs(e,t){let n=await fetch(`${vp}${e}`,{headers:{"X-Figma-Token":t}});if(!n.ok){let s=await n.text().catch(()=>""),o=new Error(`Figma API ${n.status}: ${s.slice(0,200)}`);throw o.status=n.status,o}return n.json()}async function Ci(e,t){for(let n=0;;n++)try{return await e()}catch(s){if(!(s.status===429)||n>=Ac.length)throw s;let a=Ac[n];A.warn("figma",`Rate limited (429), attempt ${n+1} \u2014 waiting ${a}s`),t&&t(`Figma rate limited \u2014 retrying in ${a}s...`),await new Promise(r=>setTimeout(r,a*1e3))}}function Tt(e,t,n=0){if(t(e,n),e.children)for(let s of e.children)Tt(s,t,n+1)}function Ic(e,t){if(e.id===t)return e;if(e.children)for(let n of e.children){let s=Ic(n,t);if(s)return s}return null}function wp(e,t){if(t){let s=Ic(e,t);if(!s)return[];if(s.type==="FRAME"||s.type==="COMPONENT"||s.type==="COMPONENT_SET"){let o=(s.children||[]).filter(i=>wi.has(i.type));return o.length>0?o:[s]}return s.children?s.children.filter(o=>wi.has(o.type)):[]}let n=e.children?.[0];return n?.children?n.children.filter(s=>wi.has(s.type)):[]}function Ws(e){let t=Math.round(e.r*255),n=Math.round(e.g*255),s=Math.round(e.b*255);return`#${t.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}function Cp(e){let t=new Map;for(let n of e)Tt(n,s=>{if(s.fills){for(let o of s.fills)if(o.type==="SOLID"&&o.color){let i=Ws(o.color),a=t.get(i),r=s.type==="TEXT",l=r?"text":"fill";a?(a.occurrences++,r&&a.usage!=="text"&&(a.usage="text")):t.set(i,{hex:i,opacity:o.opacity??o.color.a,occurrences:1,usage:l})}}if(s.strokes){for(let o of s.strokes)if(o.type==="SOLID"&&o.color){let i=Ws(o.color),a=t.get(i);a?a.occurrences++:t.set(i,{hex:i,opacity:1,occurrences:1,usage:"border"})}}});return[...t.values()].sort((n,s)=>s.occurrences-n.occurrences)}function kp(e){let t=new Map;for(let n of e)Tt(n,s=>{if(s.type!=="TEXT"||!s.style)return;let o=s.style,i=o.fontSize||16,a=o.fontWeight||400,r=o.lineHeightPx?Math.round(o.lineHeightPx/i*100)/100:1.5,l=o.letterSpacing||0,c=o.fontFamily||"sans-serif",d="body";i>=32?d="heading":i>=20?d="subheading":i<=12?d="caption":a>=600&&i<=14&&(d="label");let u=`${c}-${i}-${a}`,m=t.get(u);m?m.occurrences++:t.set(u,{fontFamily:c,fontSize:i,fontWeight:a,lineHeight:r,letterSpacing:l,role:d,occurrences:1})});return[...t.values()].sort((n,s)=>s.fontSize-n.fontSize)}function Ap(e){let t=[],n=new Set;for(let s of e)Tt(s,o=>{if(!o.layoutMode||o.layoutMode==="NONE")return;if(o.itemSpacing&&o.itemSpacing>0){let c=`gap-${o.itemSpacing}-${o.name}`;n.has(c)||(n.add(c),t.push({context:`${o.name} gap`,value:o.itemSpacing,type:"gap"}))}let i=o.paddingTop||0,a=o.paddingRight||0,r=o.paddingBottom||0,l=o.paddingLeft||0;if(i>0||a>0||r>0||l>0){let c=`pad-${i}-${a}-${r}-${l}-${o.name}`;if(!n.has(c)){n.add(c);let d=i===r&&l===a&&i===l?i:Math.max(i,a,r,l);t.push({context:`${o.name} padding`,value:d,type:"padding"})}}});return t}function $p(e){let t=[],n=new Set;for(let s of e)Tt(s,o=>{if(o.effects){for(let i of o.effects)if(i.type==="DROP_SHADOW"&&i.color&&i.offset){let{r:a,g:r,b:l,a:c}=i.color,d=`${i.offset.x}px ${i.offset.y}px ${i.radius||0}px rgba(${Math.round(a*255)},${Math.round(r*255)},${Math.round(l*255)},${Math.round(c*100)/100})`;n.has(d)||(n.add(d),t.push({type:"shadow",cssValue:d,context:o.name}))}}if(o.cornerRadius&&o.cornerRadius>0){let i=`${o.cornerRadius}px`;n.has(`radius-${i}`)||(n.add(`radius-${i}`),t.push({type:"radius",cssValue:i,context:o.name}))}});return t}function Tp(e,t){let n=[];return Tt(e,s=>{if(s.type!=="TEXT"||!s.characters?.trim())return;let o=s.style?.fontSize||16,i=s.style?.fontWeight||400,a="body";o>=32?a="headline":o>=20?a="subheadline":o<=12?a="caption":i>=600&&o<=16&&(a="label"),i>=600&&s.characters.length<40&&o>=14&&o<32&&(a="cta"),n.push({text:s.characters,fontSize:o,fontWeight:i,role:a,sectionName:t})}),n}function Ip(e){let t=e.absoluteBoundingBox;return{name:e.name,type:e.type,nodeId:e.id,width:t?.width||0,height:t?.height||0,layoutMode:e.layoutMode==="NONE"?void 0:e.layoutMode,childCount:e.children?.length||0,characters:e.type==="TEXT"?e.characters:void 0}}function Ep(e){if(e.fills){for(let t of e.fills)if(t.type==="SOLID"&&t.color)return Ws(t.color)}if(e.backgroundColor)return Ws(e.backgroundColor)}function _p(e){return e.map(t=>{let n=t.absoluteBoundingBox;return{name:t.name,nodeId:t.id,width:n?.width||0,height:n?.height||0,textContent:Tp(t,t.name),children:(t.children||[]).slice(0,20).map(Ip),backgroundColor:Ep(t),layoutMode:t.layoutMode==="NONE"?void 0:t.layoutMode,itemSpacing:t.itemSpacing,paddingTop:t.paddingTop,paddingRight:t.paddingRight,paddingBottom:t.paddingBottom,paddingLeft:t.paddingLeft}})}function Np(e){let t=[];for(let n of e)Tt(n,s=>{if(s.fills){for(let o of s.fills)if(o.type==="IMAGE"&&o.imageRef){t.push({nodeId:s.id,name:s.name||"image"});break}}});return t}async function Ec(e,t){let n=await fetch(e);if(!n.ok)throw new Error(`Failed to download image: ${n.status}`);let s=Buffer.from(await n.arrayBuffer());bp(t,s)}async function Pp(e,t,n,s,o){if(t.length===0)return new Map;$c(s,{recursive:!0});let a=t.map(c=>c.id).join(",");o&&o("Exporting frame screenshots...");let r=await Ci(()=>Vs(`/v1/images/${e}?ids=${a}&format=png&scale=2`,n),o),l=new Map;for(let[c,d]of Object.entries(r.images)){if(!d)continue;let u=c.replace(/:/g,"-"),m=Gs(s,`frame-${u}.png`);try{await Ec(d,m),l.set(c,m),A.info("figma",`Downloaded frame screenshot: ${m}`)}catch(g){A.warn("figma",`Failed to download frame ${c}: ${g}`)}}return l}async function Mp(e,t,n,s,o){if(t.length===0)return[];$c(s,{recursive:!0});let i=50,a=[];for(let r=0;r<t.length;r+=i){let l=t.slice(r,r+i),c=l.map(u=>u.nodeId).join(",");o&&o(`Exporting images (${r+1}-${Math.min(r+i,t.length)} of ${t.length})...`);let d=await Ci(()=>Vs(`/v1/images/${e}?ids=${c}&format=png&scale=2`,n),o);for(let u of l){let m=d.images[u.nodeId];if(!m)continue;let y=`${u.name.replace(/[^a-zA-Z0-9-_]/g,"-").toLowerCase()}-${Sp().slice(0,6)}.png`,h=Gs(s,y);try{await Ec(m,h),a.push({name:u.name,localPath:h,nodeId:u.nodeId,format:"png"}),A.info("figma",`Downloaded asset: ${y}`)}catch(b){A.warn("figma",`Failed to download image ${u.name}: ${b}`)}}}return a}async function _c(e,t,n,s,o){o&&o("Fetching Figma file...");let i=t?`/v1/files/${e}?ids=${t}&geometry=paths`:`/v1/files/${e}?geometry=paths`,a=await Ci(()=>Vs(i,n),o);A.info("figma",`Fetched file: ${a.name}`);let r=wp(a.document,t);if(r.length===0)throw new Error("No frames found in the Figma file. The file may be empty or structured differently.");A.info("figma",`Found ${r.length} top-level frames`),o&&o(`Found ${r.length} sections. Extracting design tokens...`);let l={colors:Cp(r),typography:kp(r),spacing:Ap(r),effects:$p(r)};A.info("figma","Design tokens extracted",{colors:l.colors.length,typography:l.typography.length,spacing:l.spacing.length,effects:l.effects.length}),o&&o("Mapping page structure...");let c=_p(r),d=Gs(s,".vibespot","figma-frames"),u=await Pp(e,r,n,d,o),m=c.map(b=>({...b,frameImagePath:u.get(b.nodeId)||""}));o&&o("Extracting image assets...");let g=Np(r),y=Gs(s,"assets"),h=await Mp(e,g,n,y,o);return A.info("figma",`Extraction complete: ${m.length} sections, ${h.length} assets`),{fileName:a.name,fileUrl:`https://www.figma.com/design/${e}`,designTokens:l,sections:m,assets:h}}function Nc(e){let t=e.fileName.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,30);return{fileName:e.fileName,fileUrl:e.fileUrl,sectionNames:e.sections.map(n=>n.name),sectionCount:e.sections.length,colorPalette:e.designTokens.colors.slice(0,10).map(n=>n.hex),fontFamilies:[...new Set(e.designTokens.typography.map(n=>n.fontFamily))],textBlockCount:e.sections.reduce((n,s)=>n+s.textContent.length,0),assetCount:e.assets.length,suggestedThemeName:t}}async function Pc(e){return await Vs("/v1/me",e)}var xp,vp,Ac,wi,Mc=L(()=>{"use strict";f();ie();xp=/figma\.com\/(?:design|file|proto)\/([a-zA-Z0-9]+)(?:\/([^?]*))?/;vp="https://api.figma.com",Ac=[10,20,40,60,120];wi=new Set(["FRAME","COMPONENT","COMPONENT_SET","SECTION"])});var Dc={};ke(Dc,{getCachedExtraction:()=>jc,handleFigmaExtractRoute:()=>Ai,handleFigmaGenerateRoute:()=>$i,handleFigmaTestTokenRoute:()=>ki});import{randomUUID as Oc}from"crypto";import{existsSync as Rc,mkdirSync as Fc,writeFileSync as Op,copyFileSync as Rp}from"fs";import{join as Ks,basename as Fp}from"path";function Jc(){let e=Date.now();for(let[t,n]of Nn)n.expires<e&&Nn.delete(t)}function jc(e){Jc();let t=Nn.get(e);return t?(Nn.delete(e),t.extraction):null}function ki(e,t){Ye(e,t,async n=>{let s=n.token||P().figmaToken;if(!s){p(t,400,{ok:!1,error:"No Figma token provided"});return}try{let o=await Pc(s);p(t,200,{ok:!0,user:o})}catch(o){let i=o instanceof Error?o.message:String(o);A.warn("figma",`Token test failed: ${i}`),p(t,200,{ok:!1,error:"Invalid or expired Figma token"})}})}function Ai(e,t){Ye(e,t,async n=>{let s=n.url;if(!s){p(t,400,{error:"Missing 'url' field"});return}let o=n.token||P().figmaToken;if(!o){p(t,400,{error:"No Figma token configured. Add one in Settings."});return}let i=Tc(s);if(!i){p(t,400,{error:"Not a valid Figma URL. Expected: figma.com/design/<key>/..."});return}let r=v()?.themePath||`/tmp/vibespot-figma-${Oc().slice(0,8)}`;t.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});let l=c=>{t.write(`data: ${JSON.stringify(c)}
2687
+ ${e}`:""}`;try{let a=await _e(n,s,o,{systemPrompt:r,messages:[{role:"user",content:t}],maxTokens:1e3}),l=a.type==="text"?a.text:JSON.stringify(a.data);return!l||l.trim().length<20?null:(E.info("context-extractor",`Extracted theme context (${l.length} chars)`),l.trim())}catch(a){let l=a instanceof Error?a.message:String(a);return E.warn("context-extractor",`Theme context extraction failed: ${l}`),null}}var Bo=R(()=>{"use strict";y();nt();de()});import{join as zd}from"path";function dy(t){let e=[];return t.brandAssets?.styleguide||e.push("styleguide"),t.brandAssets?.brandvoice||e.push("brandvoice"),t.brandAssets?.themeContext||e.push("themeContext"),e}function uy(t,e,n){t.brandAssets||(t.brandAssets={}),t.brandAssets[e]=n,t.updatedAt=Date.now();let s=e==="themeContext"?"theme-context.md":`${e}.md`,o=zd(t.themePath,".vibespot");Ie(o),J(zd(o,s),n)}async function Yd(t,e){let n=dy(t),s={attempted:[],extracted:[],skipped:[],errors:[]};if(n.length===0)return s;let o=my(e)?e:{...await py(t),...e??{}};n.includes("styleguide")&&await jr(t,"styleguide",s,()=>o.extractStyleguide(t));let i=n.filter(a=>a==="brandvoice"||a==="themeContext");if(i.length===0)return s;let r="";try{r=o.buildPreviewHtml()}catch(a){let l=a instanceof Error?a.message:String(a);for(let c of i)s.skipped.push(c),s.errors.push({asset:c,message:`Could not render preview HTML: ${l}`});return s}if(!r||r.length<50){for(let a of i)s.skipped.push(a);return s}return n.includes("brandvoice")&&await jr(t,"brandvoice",s,()=>o.extractBrandvoice(t,r)),n.includes("themeContext")&&await jr(t,"themeContext",s,()=>o.extractThemeContext(t,r)),s}async function jr(t,e,n,s){n.attempted.push(e);try{let o=await s();if(!o){n.skipped.push(e);return}uy(t,e,o),n.extracted.push(e)}catch(o){let i=o instanceof Error?o.message:String(o);n.skipped.push(e),n.errors.push({asset:e,message:i}),E.warn("brand-enrichment",`${e} enrichment skipped: ${i}`)}}function my(t){return!!t?.extractStyleguide&&!!t.extractBrandvoice&&!!t.extractThemeContext&&!!t.buildPreviewHtml}async function py(t){let{extractDesignContext:e}=await Promise.resolve().then(()=>(fs(),gs)),{buildPreviewHtml:n}=await Promise.resolve().then(()=>(es(),vo)),{resolveAgenticEngine:s}=await Promise.resolve().then(()=>(wn(),$r)),{extractBrandvoice:o}=await Promise.resolve().then(()=>(Fr(),Or)),{extractThemeContext:i}=await Promise.resolve().then(()=>(Bo(),Jo)),r=O();return{extractStyleguide:()=>e(t.themePath),buildPreviewHtml:n,extractBrandvoice:async(a,l)=>{let{engine:c,apiKey:d,model:u}=s(r);return o(l,c,d,u)},extractThemeContext:async(a,l)=>{let{engine:c,apiKey:d,model:u}=s(r);return i(l,a.brandAssets?.themeContext,c,d,u)}}}var qd=R(()=>{"use strict";y();ne();Q();de()});import{existsSync as kn,readdirSync as Xd,rmSync as gy,writeFileSync as Zt,mkdirSync as Ho}from"fs";import{join as Me,basename as fy}from"path";import{homedir as hy}from"os";import{execFileSync as Qd}from"child_process";function Go(){if(Uo&&Date.now()-Uo.ts<yy)return Uo.data;let t=[];if(kn(st))try{for(let e of Xd(st,{withFileTypes:!0}))if(e.isDirectory()){let n=Me(st,e.name,"theme.json");if(kn(n)){let s=0,o=Me(st,e.name,"modules");if(kn(o))try{s=Xd(o,{withFileTypes:!0}).filter(i=>i.isDirectory()).length}catch{}t.push({name:e.name,moduleCount:s})}}}catch{}return Uo={data:t,ts:Date.now()},t}function tu(t){let e=C(),n=Os(),s=!1;try{Qd("hs",["--version"],{encoding:"utf-8",stdio:"pipe",...eu}),s=!0}catch{}let o=gn().sort((r,a)=>a.updatedAt-r.updatedAt),i=Go();p(t,200,{hasActiveSession:!!e,activeSession:e?{id:e.id,themeName:e.themeName,moduleCount:e.modules.length,isImported:!!e.isImported}:null,hsInstalled:s,aiAvailable:n.availableEngines.length>0,availableEngines:n.availableEngines,activeEngine:n.activeEngine,sessions:o,localThemes:i,contentMode:yn()})}function nu(t,e){W(t,n=>{try{if(Ft()){p(e,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{name:s,starterId:o,assetType:i}=JSON.parse(n);if(!s||typeof s!="string"){p(e,400,{error:"Theme name is required"});return}let r=s.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"");if(!r){p(e,400,{error:"Theme name must contain at least one alphanumeric character"});return}let a=Me(st,r);if(Ie(st),kn(a)&&gy(a,{recursive:!0,force:!0}),o&&typeof o=="string"&&!Pr(o)){p(e,400,{error:`Starter template "${o}" not found`});return}Ln(a,r),pn(a,r),o&&typeof o=="string"?(by(a,r,o),ke()):i==="email"&&(Tt("module_only","Email","email"),ln(a,r)),D(),p(e,200,{ok:!0,themeName:r,themePath:a,starterId:o||void 0})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function by(t,e,n){let s=Pr(n);if(!s)return;let o=C();if(!o)return;let i=s.contentType==="email",r=s.modules.map(u=>({...u})),a=[...s.moduleOrder],l=i?`email-${e}`:`lp-${e}`,c={id:l,label:`${s.name}`,pageType:i?"module_only":"landing_page",contentMode:i?"email":void 0,templateFile:i?"templates/email.html":`templates/${l}.html`,modules:r,moduleOrder:a,sharedCss:s.sharedCss,sharedJs:s.sharedJs,template:"",messages:[]};i&&ln(t,e),o.templates=[c],o.activeTemplateId=l,o.modules=r,o.moduleOrder=a,o.sharedCss=s.sharedCss,o.sharedJs=s.sharedJs;let d=Me(t,"modules");Ho(d,{recursive:!0});for(let u of s.modules){let m=Me(d,`${u.moduleName}.module`);Ho(m,{recursive:!0}),Zt(Me(m,"fields.json"),u.fieldsJson,"utf-8"),Zt(Me(m,"meta.json"),u.metaJson,"utf-8"),Zt(Me(m,"module.html"),u.moduleHtml,"utf-8"),Zt(Me(m,"module.css"),u.moduleCss,"utf-8"),u.moduleJs&&Zt(Me(m,"module.js"),u.moduleJs,"utf-8")}if(s.sharedCss){let u=Me(t,"css");Ho(u,{recursive:!0}),Zt(Me(u,`${e}-theme.css`),s.sharedCss,"utf-8")}if(s.sharedJs){let u=Me(t,"js");Ho(u,{recursive:!0}),Zt(Me(u,`${e}-animations.js`),s.sharedJs,"utf-8")}}function su(t){p(t,200,{starters:Gd()})}function ou(t,e){W(t,n=>{try{if(Ft()){p(e,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{name:s}=JSON.parse(n);if(!s||typeof s!="string"){p(e,400,{error:"Theme name is required"});return}let o=s.replace(/^\/+|\/+$/g,"");if(!o){p(e,400,{error:"Theme name is required"});return}let i=Fe(),r=O(),a=o.includes("/")||o.includes("@")?o.replace(/[@/]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""):o,l=Me(st,a);Ie(st),r.hubspotUploadMode==="cli"||!i?(async()=>{Qd("hs",["cms","fetch",o,l],{encoding:"utf-8",stdio:"pipe",...eu});let c=await Zd(l,a);p(e,200,{ok:!0,themeName:a,themePath:l,moduleCount:c.moduleCount,brandEnrichment:c.brandEnrichment})})().catch(c=>{p(e,500,{error:c instanceof Error?c.message:String(c)})}):Bn(i,o,l).then(async()=>{let c=await Zd(l,a);p(e,200,{ok:!0,themeName:a,themePath:l,moduleCount:c.moduleCount,brandEnrichment:c.brandEnrichment})}).catch(c=>{p(e,500,{error:c instanceof Error?c.message:String(c)})})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}async function Zd(t,e){pn(t,e,{isImported:!0}),So(t),D();let n=C(),s={attempted:[],extracted:[],skipped:[],errors:[]};return n&&(s=await Yd(n),D()),{moduleCount:n?.modules.length||0,brandEnrichment:s}}function iu(t,e){W(t,n=>{try{if(Ft()){p(e,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{path:s}=JSON.parse(n);if(!s||typeof s!="string"){p(e,400,{error:"Theme path is required"});return}let o=s;if(kn(o)||(o=Me(st,s)),!kn(o)){p(e,400,{error:`Theme folder not found: ${s}`});return}let i=fy(o);pn(o,i),So(o),D(),p(e,200,{ok:!0,themeName:i,themePath:o,moduleCount:C()?.modules.length||0})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function ru(t,e){W(t,n=>{try{if(Ft()){p(e,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{sessionId:s}=JSON.parse(n);if(!s||typeof s!="string"){p(e,400,{error:"Session ID is required"});return}let o=po(s);if(!o){p(e,404,{error:"Session not found"});return}p(e,200,{ok:!0,themeName:o.themeName,themePath:o.themePath,moduleCount:o.modules.length,messageCount:o.messages.length})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function au(t,e){W(t,n=>{try{let{apiKey:s}=JSON.parse(n);if(!s||typeof s!="string"){p(e,400,{error:"API key is required"});return}Y({anthropicApiKey:s}),p(e,200,{ok:!0})}catch(s){p(e,400,{error:s instanceof Error?s.message:String(s)})}})}function lu(t){let e=Fe();if(!e){p(t,200,{themes:[],error:"No HubSpot account connected"});return}(async()=>{let n=await wa(e);if(n.length===0){p(t,200,{themes:[]});return}let s=[],o=n.map(async a=>{let l=a.path||a.name;try{let c=await Ds(e,`${l}/theme.json`);c&&!c.folder&&s.push({name:a.name,path:l})}catch{}});await Promise.all(o),s.sort((a,l)=>a.name.localeCompare(l.name));let i=Go(),r=new Set(i.map(a=>a.name));p(t,200,{themes:s.map(a=>({...a,existsLocally:r.has(a.name)}))})})().catch(n=>{p(t,200,{themes:[],error:n instanceof Error?n.message:String(n)})})}var eu,st,Uo,yy,Wo=R(()=>{"use strict";y();ze();Q();Jn();Hs();Ut();we();Nt();wn();Ht();Q();ne();Wd();ts();qd();eu=process.platform==="win32"?{shell:!0}:{},st=Me(hy(),"vibespot-themes"),Uo=null,yy=5e3});import{existsSync as Sy,readFileSync as xy,appendFileSync as vy}from"fs";import{join as cu}from"path";import{homedir as du}from"os";function ky(t){let e=t.match(/^gpt-(\d+(?:\.\d+)?)(?:-(.+))?$/);if(e){let n=e[1],s=e[2];if(!s)return`GPT-${n}`;let o=s.replace(/-/g," ").replace(/\b\w/g,i=>i.toUpperCase());return`GPT-${n} ${o}`}return t.startsWith("codex-")?`Codex ${t.slice(6).replace(/-/g," ").replace(/\b\w/g,s=>s.toUpperCase())}`:/^o\d/.test(t)?t.replace(/-/g," "):t}async function Ty(t){let e=await fetch("https://api.anthropic.com/v1/models",{headers:{"x-api-key":t,"anthropic-version":"2023-06-01"}});return e.ok?(await e.json()).data.filter(s=>!s.id.startsWith("claude-3-")&&!s.id.startsWith("claude-2")).map(s=>({id:s.id,label:s.display_name})):[]}async function Ay(t){let e=await fetch("https://api.openai.com/v1/models",{headers:{Authorization:`Bearer ${t}`}});return e.ok?(await e.json()).data.map(s=>s.id):[]}function uu(t,e){return t.filter(n=>e.test(n)).sort((n,s)=>n.localeCompare(s)).map(n=>({id:n,label:ky(n)}))}async function $y(t){let e=await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${t}`);return e.ok?(await e.json()).models.filter(s=>s.name.includes("gemini-2")).map(s=>({id:s.name.replace("models/",""),label:s.displayName})):[]}async function _y(){if(Date.now()-hs.ts<wy&&Object.keys(hs.data).length>0)return hs.data;let t=O(),e={...mu},n=[],s=Oe("anthropic-api",t);s&&n.push(Ty(s).then(r=>{r.length&&(e["anthropic-api"]=r,e["claude-oauth"]=r)}).catch(()=>{}));let o=Oe("openai-api",t);o&&n.push(Ay(o).then(r=>{if(!r.length)return;let a=uu(r,pu);a.length&&(e["openai-api"]=a);let l=uu(r,Cy);l.length&&(e["codex-cli"]=l)}).catch(()=>{}));let i=Oe("gemini-api",t);return i&&n.push($y(i).then(r=>{r.length&&(e["gemini-api"]=r,e["gemini-cli"]=r)}).catch(()=>{})),await Promise.all(n),hs.data=e,hs.ts=Date.now(),e}function gu(t){let e=Os(),n=O(),s={aiEngine:n.aiEngine||null,claudeCodeModel:n.claudeCodeModel||null,anthropicApiModel:n.anthropicApiModel||null,openaiApiModel:n.openaiApiModel||null,codexCliModel:n.codexCliModel||null,geminiCliModel:n.geminiCliModel||null,geminiApiModel:n.geminiApiModel||null,hubspotUploadMode:n.hubspotUploadMode||"api",hubspotAccounts:(n.hubspotAccounts||[]).map(a=>({portalId:a.portalId,portalName:a.portalName,dataCenter:a.dataCenter})),activeHubSpotAccount:n.activeHubSpotAccount||null,enabledCLITools:n.enabledCLITools||[],agenticMode:n.agenticMode,agenticConcurrency:n.agenticConcurrency,planMode:n.planMode||!1,extendedThinking:n.extendedThinking||!1,extendedThinkingBudget:n.extendedThinkingBudget||"medium",webSearch:n.webSearch||!1,figmaToken:n.figmaToken?"\u2022\u2022\u2022\u2022"+n.figmaToken.slice(-4):null},o=gn().length,i=Go().length,r=sn();_y().then(a=>{p(t,200,{version:r,environment:e,config:s,models:a,sessionCount:o,localThemeCount:i})}).catch(()=>{p(t,200,{version:r,environment:e,config:s,models:mu,sessionCount:o,localThemeCount:i})})}function fu(t,e){W(t,n=>{try{let{engine:s,model:o}=JSON.parse(n);if(!["claude-code","anthropic-api","claude-oauth","openai-api","gemini-cli","gemini-api","codex-cli"].includes(s)){p(e,400,{error:`Invalid engine: ${s}`});return}let r={aiEngine:s};if(o)switch(s){case"claude-code":r.claudeCodeModel=o;break;case"anthropic-api":case"claude-oauth":r.anthropicApiModel=o;break;case"openai-api":r.openaiApiModel=o;break;case"codex-cli":r.codexCliModel=o;break;case"gemini-cli":r.geminiCliModel=o;break;case"gemini-api":r.geminiApiModel=o;break}Y(r),p(e,200,{ok:!0,engine:s})}catch(s){p(e,400,{error:s instanceof Error?s.message:String(s)})}})}function hu(t,e){W(t,n=>{try{let{provider:s,apiKey:o}=JSON.parse(n);if(!s||typeof s!="string"){p(e,400,{error:"provider is required"});return}if(!o){let l={};switch(s){case"anthropic":l.anthropicApiKey="";break;case"openai":l.openaiApiKey="";break;case"gemini":l.geminiApiKey="";break;case"figma":l.figmaToken="";break;default:p(e,400,{error:`Unknown provider: ${s}`});return}Y(l),p(e,200,{ok:!0,provider:s,deleted:!0});return}let i={};switch(s){case"anthropic":i.anthropicApiKey=o;break;case"openai":i.openaiApiKey=o;break;case"gemini":i.geminiApiKey=o;break;case"figma":i.figmaToken=o;break;default:p(e,400,{error:`Unknown provider: ${s}`});return}Y(i);let r=null;if(!O().aiEngine){let c={anthropic:"anthropic-api",openai:"openai-api",gemini:"gemini-api"}[s];c&&(Y({aiEngine:c}),r=c)}p(e,200,{ok:!0,provider:s,autoSelectedEngine:r})}catch(s){p(e,400,{error:s instanceof Error?s.message:String(s)})}})}function yu(t,e){W(t,n=>{try{let{tool:s}=JSON.parse(n),o={hubspot:{cmd:"npm install -g @hubspot/cli",desc:"Installing HubSpot CLI"},claude:{cmd:"npm install -g @anthropic-ai/claude-code",desc:"Installing Claude Code"},gemini:{cmd:"npm install -g @google/gemini-cli",desc:"Installing Gemini CLI"},codex:{cmd:process.platform==="darwin"?"brew install --cask codex":"npm install -g @openai/codex",desc:"Installing OpenAI Codex"},gh:{cmd:process.platform==="darwin"?"brew install gh":"npm install -g @cli/gh",desc:"Installing GitHub CLI"}},i=o[s];if(!i){p(e,400,{error:`Unknown tool: ${s}. Valid: ${Object.keys(o).join(", ")}`});return}let r=Xt(i.cmd,i.desc,{timeout:12e4});p(e,200,{ok:!0,jobId:r})}catch(s){p(e,400,{error:s instanceof Error?s.message:String(s)})}})}function bu(t,e){W(t,n=>{try{let s=JSON.parse(n||"{}"),o=O(),i=o.hubspotUploadMode||"api";if(s.personalAccessKey)if(i==="api"){js(s.personalAccessKey).then(r=>{An(s.personalAccessKey,r.portalId,r.portalName,r.dataCenter),p(e,200,{ok:!0,portalName:r.portalName,portalId:r.portalId,dataCenter:r.dataCenter})}).catch(r=>{p(e,400,{error:r instanceof Error?r.message:String(r)})});return}else{if(!ct().found){p(e,400,{error:"HubSpot CLI not installed",needsInstall:!0});return}let a=ms("hs",["auth",`--pak=${s.personalAccessKey}`],"Authenticating with HubSpot",{timeout:3e4});p(e,200,{ok:!0,jobId:a});return}if(i==="api"){let r=o.hubspotAccounts||[];if(r.length>0&&!s.force){let a=r.find(l=>l.portalId===o.activeHubSpotAccount)||r[0];p(e,200,{ok:!0,alreadyAuthenticated:!0,portalName:a.portalName,portalId:a.portalId});return}}else{if(!ct().found){p(e,400,{error:"HubSpot CLI not installed",needsInstall:!0});return}let a=dt();if(a.authenticated&&!s.force){p(e,200,{ok:!0,alreadyAuthenticated:!0,portalName:a.portalName,portalId:a.portalId});return}}p(e,200,{needsKey:!0,instructions:"Create a personal access key in HubSpot",url:"https://app.hubspot.com/portal-recommend/l?slug=personal-access-key",steps:["Click the link above to open HubSpot","Select your account","Create a Personal Access Key with CMS permissions","Copy the key and paste it below"]})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function Su(t,e){W(t,n=>{try{let s=JSON.parse(n||"{}");if(!hi().found){p(e,400,{error:"GitHub CLI not installed",needsInstall:!0});return}let i=yi();if(i.authenticated&&!s.force){p(e,200,{ok:!0,alreadyAuthenticated:!0,username:i.username});return}if(s.token){let a=ms("gh",["auth","login","--with-token"],"Authenticating with GitHub",{timeout:3e4,stdin:s.token});p(e,200,{ok:!0,jobId:a});return}let r=Xt("gh auth login --web --git-protocol https","GitHub authentication (check your browser)",{timeout:3e5});p(e,200,{ok:!0,jobId:r,browserAuthRequired:!0})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function xu(t,e){W(t,n=>{try{let{portalId:s,action:o}=JSON.parse(n);if((O().hubspotUploadMode||"api")==="api"){if(o==="remove"&&s){ci(s),p(e,200,{ok:!0});return}if(s){di(s),p(e,200,{ok:!0});return}}else{if(!ct().found){p(e,400,{error:"HubSpot CLI not installed"});return}let l=String(s).replace(/[^0-9]/g,"");if(!l){p(e,400,{error:"Invalid portalId"});return}if(o==="remove"){let c=ms("hs",["accounts","remove",l],`Removing HubSpot account ${l}`,{timeout:15e3});p(e,200,{ok:!0,jobId:c});return}if(l){let c=ms("hs",["accounts","use",l],`Switching to HubSpot account ${l}`,{timeout:15e3});p(e,200,{ok:!0,jobId:c});return}}p(e,400,{error:"portalId required"})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function vu(t){let e=Xt("gh auth logout --hostname github.com -y","Logging out of GitHub",{timeout:15e3});p(t,200,{ok:!0,jobId:e})}function wu(t,e){W(t,n=>{try{let{cli:s,apiKey:o}=JSON.parse(n||"{}");switch(s){case"claude":{let i=Xt("CLAUDECODE= claude --print -p 'reply OK'","Authenticating Claude Code (check your browser if prompted)",{timeout:12e4});p(e,200,{ok:!0,jobId:i,hint:"If Claude Code opens a browser window, complete the sign-in there."});break}case"gemini":{let i=Xt("gemini -p 'reply OK'","Authenticating Gemini CLI (check your browser if prompted)",{timeout:12e4});p(e,200,{ok:!0,jobId:i,hint:"If Gemini opens a browser window, complete the sign-in there."});break}case"codex":{if(o&&o.trim()){let i=o.trim();if(process.env.OPENAI_API_KEY=i,Y({openaiApiKey:i}),process.platform!=="win32"){let r=/^[A-Za-z0-9_\-.:]+$/.test(i)?i:"";if(r){let a=`export OPENAI_API_KEY="${r}"`,l=process.env.SHELL?.includes("zsh")?cu(du(),".zshrc"):cu(du(),".bashrc");try{(Sy(l)?xy(l,"utf-8"):"").includes("OPENAI_API_KEY")||vy(l,`
2688
+ # Added by vibeSpot
2689
+ ${a}
2690
+ `)}catch{}}}p(e,200,{ok:!0,message:"API key saved"})}else{let i=Xt("codex login","Authenticating Codex CLI (check your browser if prompted)",{timeout:12e4});p(e,200,{ok:!0,jobId:i,hint:"Complete the sign-in in your browser."})}break}default:p(e,400,{error:`Unknown CLI: ${s}`})}}catch(s){p(e,400,{error:s instanceof Error?s.message:String(s)})}})}function Cu(t,e){W(t,n=>{try{let{mode:s}=JSON.parse(n);if(s!=="api"&&s!=="cli"){p(e,400,{error:`Invalid mode: ${s}. Must be "api" or "cli".`});return}Y({hubspotUploadMode:s}),p(e,200,{ok:!0,mode:s})}catch(s){p(e,400,{error:s instanceof Error?s.message:String(s)})}})}function ku(t,e){W(t,n=>{try{let{toolId:s,enabled:o}=JSON.parse(n);if(!s||typeof o!="boolean"){p(e,400,{error:"toolId (string) and enabled (boolean) required"});return}ui(s,o),p(e,200,{ok:!0,toolId:s,enabled:o})}catch(s){p(e,400,{error:s instanceof Error?s.message:String(s)})}})}function Tu(t,e){W(t,n=>{try{let s=JSON.parse(n),o=["agenticMode","agenticConcurrency","planMode","extendedThinking","extendedThinkingBudget","webSearch"];if(s.extendedThinkingBudget!==void 0&&!["low","medium","high"].includes(s.extendedThinkingBudget)){p(e,400,{error:"extendedThinkingBudget must be 'low' | 'medium' | 'high'"});return}let i={};for(let r of o)r in s&&(i[r]=s[r]);if(Object.keys(i).length===0){p(e,400,{error:"No valid settings fields provided"});return}Y(i),p(e,200,{ok:!0,updated:Object.keys(i)})}catch(s){p(e,400,{error:s instanceof Error?s.message:String(s)})}})}function Au(t,e){let n=t.replace("/api/settings/job/","");if(!n){p(e,400,{error:"Job ID required"});return}let s=Ro(n);if(!s){p(e,404,{error:"Job not found"});return}p(e,200,{id:s.id,status:s.status,description:s.description,output:s.output,exitCode:s.exitCode,startedAt:s.startedAt,completedAt:s.completedAt})}var hs,wy,mu,pu,Cy,$u=R(()=>{"use strict";y();ze();Q();we();Wo();Ht();Ut();ne();Oo();hs={data:{},ts:0},wy=600*1e3,mu={"claude-code":[{id:"claude-opus-4-7",label:"Claude Opus 4.7"},{id:"claude-opus-4-6",label:"Claude Opus 4.6"},{id:"claude-sonnet-4-6",label:"Claude Sonnet 4.6 (default)"},{id:"claude-sonnet-4-5",label:"Claude Sonnet 4.5"},{id:"claude-haiku-4-5",label:"Claude Haiku 4.5"}],"codex-cli":[{id:"gpt-5.5",label:"GPT-5.5 (default)"},{id:"gpt-5.5-pro",label:"GPT-5.5 Pro"},{id:"gpt-5.3-codex",label:"GPT-5.3 Codex"},{id:"gpt-5.2-codex",label:"GPT-5.2 Codex"},{id:"gpt-5.1-codex-max",label:"GPT-5.1 Codex Max"},{id:"gpt-5.1-codex-mini",label:"GPT-5.1 Codex Mini"},{id:"gpt-5.4-mini",label:"GPT-5.4 Mini"},{id:"gpt-5.4-nano",label:"GPT-5.4 Nano"},{id:"codex-mini-latest",label:"Codex Mini (latest)"}],"anthropic-api":[{id:"claude-opus-4-7",label:"Claude Opus 4.7"},{id:"claude-opus-4-6",label:"Claude Opus 4.6"},{id:"claude-sonnet-4-6",label:"Claude Sonnet 4.6 (default)"},{id:"claude-sonnet-4-5",label:"Claude Sonnet 4.5"},{id:"claude-haiku-4-5-20251001",label:"Claude Haiku 4.5"}],"claude-oauth":[{id:"claude-opus-4-7",label:"Claude Opus 4.7"},{id:"claude-opus-4-6",label:"Claude Opus 4.6"},{id:"claude-sonnet-4-6",label:"Claude Sonnet 4.6 (default)"},{id:"claude-sonnet-4-5",label:"Claude Sonnet 4.5"},{id:"claude-haiku-4-5-20251001",label:"Claude Haiku 4.5"}],"openai-api":[{id:"gpt-5.5",label:"GPT-5.5 (default)"},{id:"gpt-5.5-pro",label:"GPT-5.5 Pro"},{id:"gpt-5.4-mini",label:"GPT-5.4 Mini"},{id:"gpt-5.4-nano",label:"GPT-5.4 Nano"},{id:"gpt-5.3-codex",label:"GPT-5.3 Codex"}],"gemini-api":[{id:"gemini-2.5-pro",label:"Gemini 2.5 Pro (default)"},{id:"gemini-2.5-flash",label:"Gemini 2.5 Flash"},{id:"gemini-2.0-flash",label:"Gemini 2.0 Flash"}],"gemini-cli":[{id:"gemini-2.5-pro",label:"Gemini 2.5 Pro (default)"},{id:"gemini-2.5-flash",label:"Gemini 2.5 Flash"},{id:"gemini-2.0-flash",label:"Gemini 2.0 Flash"}]},pu=/^(gpt-[45](\.\d+)?(-[a-z0-9-]+)?|o[1-4](-(mini|pro|nano)(-high)?)?|codex(-[a-z0-9-]+)?)$/,Cy=pu});function _u(t,e){W(t,n=>{try{let{access_token:s,refresh_token:o}=JSON.parse(n);if(!s||typeof s!="string"){p(e,400,{error:"access_token is required"});return}mi(s.trim(),(o||"").trim());let i=O();(!i.aiEngine||i.aiEngine!=="claude-oauth")&&Y({aiEngine:"claude-oauth"}),p(e,200,{ok:!0})}catch(s){p(e,400,{error:s instanceof Error?s.message:String(s)})}})}function Mu(t,e){let n=lt(),s=Mn();p(e,200,{authenticated:n,expiresAt:s?.expiresAt||null})}function Eu(t,e){try{Es(),O().aiEngine==="claude-oauth"&&Y({aiEngine:void 0}),p(e,200,{ok:!0})}catch(n){p(e,500,{error:n instanceof Error?n.message:String(n)})}}var Iu=R(()=>{"use strict";y();ze();Q();xt()});import{existsSync as My,rmSync as Ey}from"fs";import{join as Iy}from"path";function Pu(t,e,n){if(t==="GET"){let s=C(),o=gn().sort((i,r)=>r.updatedAt-i.updatedAt);p(n,200,{activeTheme:s?{id:s.id,themeName:s.themeName,isImported:!!s.isImported}:null,sessions:o});return}if(t==="DELETE"){W(e,s=>{try{let{sessionId:o,deleteFiles:i}=JSON.parse(s);Ol(o,i),p(n,200,{ok:!0})}catch(o){p(n,500,{error:o instanceof Error?o.message:String(o)})}});return}p(n,405,{error:"Method not allowed"})}function Ru(t,e){W(t,n=>{try{let{sessionId:s}=JSON.parse(n),o=po(s);if(!o){p(e,404,{error:"Session not found"});return}p(e,200,{ok:!0,themeName:o.themeName,themePath:o.themePath})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function Nu(t,e){W(t,n=>{try{let{themeName:s}=JSON.parse(n);if(!s||typeof s!="string"){p(e,400,{error:"Theme name is required"});return}if(/[\/\\]|\.\./.test(s)||s==="."||!s.replace(/[^a-z0-9]/gi,"")){p(e,400,{error:"Invalid theme name"});return}let o=Iy(st,s);if(!My(o)){p(e,404,{error:"Theme not found on disk"});return}Ey(o,{recursive:!0,force:!0}),p(e,200,{ok:!0})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function Ou(t,e){W(t,n=>{try{let{sessionId:s,newName:o}=JSON.parse(n);if(!s||!o||typeof o!="string"){p(e,400,{error:"sessionId and newName are required"});return}let i=o.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/^-|-$/g,"").replace(/-{2,}/g,"-");if(!i){p(e,400,{error:"Invalid name"});return}let r=Fl(s,i);r.ok?p(e,200,{ok:!0,newName:i}):p(e,400,{error:r.error})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function Fu(t,e){W(t,n=>{try{let{sessionId:s}=JSON.parse(n);if(!s){p(e,400,{error:"sessionId is required"});return}let o=jl(s);o.ok?p(e,200,{ok:!0,newName:o.newName,newSessionId:o.newSessionId}):p(e,400,{error:o.error})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}var ju=R(()=>{"use strict";y();ze();we();Wo()});import{existsSync as ys,readFileSync as Py,rmSync as Ko}from"fs";import{join as Ne,basename as Ry}from"path";import{execFileSync as Ny}from"child_process";function Bu(t){let e=C();if(!e){p(t,404,{error:"No active session"});return}let n=At();p(t,200,{themeName:e.themeName,themePath:e.themePath,templates:e.templates.map(s=>({id:s.id,label:s.label,pageType:s.contentMode==="email"?"email":s.pageType,moduleCount:s.modules.length,messageCount:s.messages.length})),activeTemplateId:e.activeTemplateId,moduleLibrary:n.map(s=>({moduleName:s.module.moduleName,usedIn:s.usedIn})),brandAssets:{hasStyleguide:!!e.brandAssets?.styleguide,hasBrandvoice:!!e.brandAssets?.brandvoice,hasThemeContext:!!e.brandAssets?.themeContext,humanify:e.brandAssets?.humanify!==!1,hasBrandKit:!!e.brandAssets?.brandKit&&Object.keys(e.brandAssets.brandKit).length>0,brandKit:e.brandAssets?.brandKit||null}})}function Hu(t){let e=C();if(!e){p(t,404,{error:"No active session"});return}let n=e.themePath;if(!ys(n)){p(t,404,{error:"Theme directory not found"});return}let s=e.themeName||"theme",o=Ne(n,".."),i=Ry(n);try{let r=`${s}.zip`,a=Ne(o,r);ys(a)&&Ko(a),Ny("zip",["-r",r,i,"-x",`${i}/.git/*`,`${i}/.vibespot/*`,`${i}/node_modules/*`],{cwd:o,timeout:3e4,...Oy});let l=Py(a);Ko(a),t.writeHead(200,{"Content-Type":"application/zip","Content-Disposition":`attachment; filename="${r}"`,"Content-Length":l.length}),t.end(l)}catch(r){E.error("download-zip","Failed to create zip archive",r),p(t,500,{error:"Failed to create zip archive"})}}function Uu(t,e,n){let s=C();if(!s){p(n,404,{error:"No active session"});return}if(t==="GET"){p(n,200,{templates:s.templates.map(o=>({id:o.id,label:o.label,pageType:o.contentMode==="email"?"email":o.pageType,moduleCount:o.modules.length})),activeTemplateId:s.activeTemplateId});return}if(t==="POST"){W(e,o=>{try{let{pageType:i,label:r}=JSON.parse(o);if(!i||!r){p(n,400,{error:"pageType and label are required"});return}if(!["landing_page","blog_post","website_page","module_only","email"].includes(i)){p(n,400,{error:`Invalid pageType: ${i}`});return}let l=i==="email",d=Tt(l?"module_only":i,r,l?"email":void 0);l&&s.themePath&&ln(s.themePath,s.themeName),D(),p(n,200,{ok:!0,template:{id:d.id,label:d.label,pageType:d.pageType}})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}if(t==="DELETE"){W(e,o=>{try{let{templateId:i,deleteModules:r}=JSON.parse(o);if(!i){p(n,400,{error:"templateId is required"});return}if(!Il(i,!!r)){p(n,404,{error:"Template not found"});return}D(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}p(n,405,{error:"Method not allowed"})}function Gu(t,e){W(t,n=>{try{let{templateId:s}=JSON.parse(n);if(!s){p(e,400,{error:"templateId is required"});return}if(!Kn(s)){p(e,404,{error:"Template not found"});return}D();let i=C();p(e,200,{ok:!0,modules:Se().map(r=>r.moduleName),messageCount:i?.messages.length||0})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function Wu(t,e){W(t,n=>{try{let{templateId:s,newLabel:o}=JSON.parse(n);if(!s||!o||typeof o!="string"){p(e,400,{error:"templateId and newLabel are required"});return}if(!El(s,o.trim())){p(e,404,{error:"Template not found"});return}D(),p(e,200,{ok:!0,newLabel:o.trim()})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function Ku(t,e){W(t,n=>{try{let{templateIds:s}=JSON.parse(n);if(!Array.isArray(s)||s.some(i=>typeof i!="string")){p(e,400,{error:"templateIds must be an array of strings"});return}if(!Ml(s)){p(e,400,{error:"Reorder rejected (length mismatch or no session)"});return}D(),p(e,200,{ok:!0})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function Vu(t,e){W(t,n=>{try{let{templateId:s,label:o}=JSON.parse(n);if(!s){p(e,400,{error:"templateId is required"});return}let i=_l(s,o);if(!i){p(e,404,{error:"Template not found"});return}D(),p(e,200,{ok:!0,template:{id:i.id,label:i.label,pageType:i.pageType,moduleCount:i.modules.length}})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function zu(t){let e=At();p(t,200,{modules:e.map(n=>({moduleName:n.module.moduleName,usedIn:n.usedIn,fieldsJson:n.module.fieldsJson}))})}function Yu(t,e,n){let s=C();if(!s){p(n,404,{error:"No active session"});return}W(e,o=>{try{let{moduleName:i}=JSON.parse(o);if(!i){p(n,400,{error:"moduleName is required"});return}let a=At().find(d=>d.module.moduleName===i);if(!a){p(n,404,{error:`Module "${i}" not found in library`});return}let l={...a.module};s.modules.find(d=>d.moduleName===l.moduleName)||(s.modules.push(l),s.moduleOrder.push(l.moduleName),s.updatedAt=Date.now()),D(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}})}function qu(t,e,n){let s=C();if(!s){p(n,404,{error:"No active session"});return}if(t==="GET"){p(n,200,{styleguide:s.brandAssets?.styleguide||null,brandvoice:s.brandAssets?.brandvoice||null,themeContext:s.brandAssets?.themeContext||null});return}if(t==="POST"){W(e,o=>{try{let{type:i,content:r}=JSON.parse(o);if(!i){p(n,400,{error:"type is required"});return}if(s.brandAssets||(s.brandAssets={}),i==="humanify"){s.brandAssets.humanify=r==="on",s.updatedAt=Date.now(),D(),p(n,200,{ok:!0});return}if(!r){p(n,400,{error:"content is required"});return}if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(n,400,{error:`Invalid type: ${i}. Must be "styleguide", "brandvoice", or "themeContext"`});return}let a=i,l=a==="themeContext"?"theme-context.md":`${a}.md`;s.brandAssets[a]=r,s.updatedAt=Date.now();let c=Ne(s.themePath,".vibespot");Ie(c),J(Ne(c,l),r);let d=null;a==="styleguide"&&(d=Dr(s,r)),D(),p(n,200,{ok:!0,brandKit:d})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}if(t==="DELETE"){W(e,o=>{try{let{type:i}=JSON.parse(o);if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(n,400,{error:`Invalid type: ${i}`});return}let r=i;s.brandAssets&&delete s.brandAssets[r],s.updatedAt=Date.now();let a=r==="themeContext"?"theme-context.md":`${r}.md`,l=Ne(s.themePath,".vibespot",a);ys(l)&&Ko(l),D(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}p(n,405,{error:"Method not allowed"})}function Zu(t,e){p(e,200,Xu)}function jy(t){let e=[],n=[],s=t.split(`
2691
+ `),o=!1,i=!1;for(let r of s){let a=r.trim();if(/^##\s+color/i.test(a)){o=!0,i=!1;continue}if(/^##\s+typography/i.test(a)){i=!0,o=!1;continue}if(/^##\s+/.test(a)&&!(/color/i.test(a)||/typography/i.test(a))){o=!1,i=!1;continue}if(o){let l=a.match(Fy);if(l)for(let c of l)e.includes(c.toLowerCase())||e.push(c.toLowerCase())}if(i){let l=Du.exec(a);if(Du.lastIndex=0,l){let c=l[1].trim().replace(/['"`]/g,"").split(",")[0].trim();c&&!n.includes(c)&&n.push(c)}if(/\bheading|body|display|monospace\b/i.test(a)&&!l){let c=a.split(":").slice(1).join(":").trim();if(c){let d=c.replace(/['"`*]/g,"").split(",")[0].trim().split("(")[0].trim();d&&d.length<60&&!/^\d/.test(d)&&!n.includes(d)&&n.push(d)}}}}return{colors:e.slice(0,6),fonts:n.slice(0,4)}}function Dr(t,e){let{colors:n,fonts:s}=jy(e);if(n.length===0&&s.length===0)return null;t.brandAssets||(t.brandAssets={});let o=t.brandAssets.brandKit||{};if(n.length>0&&(o.colors||(o.colors={}),n[0]&&(o.colors.primary=n[0]),n[1]&&(o.colors.secondary=n[1]),n[2]&&(o.colors.accent=n[2])),s.length>0){o.fonts||(o.fonts={});let r=a=>{let l=a.toLowerCase(),c=Xu.find(d=>d.name.toLowerCase()===l);return c?c.stack:a};s[0]&&(o.fonts.heading=r(s[0])),s[1]?o.fonts.body=r(s[1]):s[0]&&(o.fonts.body=r(s[0]))}t.brandAssets.brandKit=o;let i=Ne(t.themePath,".vibespot");return Ie(i),J(Ne(i,"brand-kit.json"),JSON.stringify(o,null,2)),o}function Qu(t,e,n){let s=C();if(!s){p(n,404,{error:"No active session"});return}if(t==="GET"){p(n,200,s.brandAssets?.brandKit||{});return}if(t==="POST"){W(e,o=>{try{let i=JSON.parse(o);s.brandAssets||(s.brandAssets={});let r={};if(i.colors&&typeof i.colors=="object"){let l={};for(let c of["primary","secondary","accent"])typeof i.colors[c]=="string"&&Dy.test(i.colors[c])&&(l[c]=i.colors[c]);Object.keys(l).length>0&&(r.colors=l)}if(i.fonts&&typeof i.fonts=="object"){let l={};for(let c of["heading","body"])typeof i.fonts[c]=="string"&&i.fonts[c].trim()&&(l[c]=i.fonts[c].trim());Object.keys(l).length>0&&(r.fonts=l)}typeof i.logoUrl=="string"&&i.logoUrl.trim()&&(r.logoUrl=i.logoUrl.trim()),s.brandAssets.brandKit=r,s.updatedAt=Date.now();let a=Ne(s.themePath,".vibespot");Ie(a),J(Ne(a,"brand-kit.json"),JSON.stringify(r,null,2)),D(),p(n,200,{ok:!0,brandKit:r})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}if(t==="DELETE"){s.brandAssets&&delete s.brandAssets.brandKit,s.updatedAt=Date.now();let o=Ne(s.themePath,".vibespot","brand-kit.json");ys(o)&&Ko(o),D(),p(n,200,{ok:!0});return}p(n,405,{error:"Method not allowed"})}function Lu(t,e,n){if(!t)return;t.brandAssets||(t.brandAssets={}),t.brandAssets[e]=n,t.updatedAt=Date.now();let s=e==="themeContext"?"theme-context.md":`${e}.md`,o=Ne(t.themePath,".vibespot");Ie(o),J(Ne(o,s),n)}async function Ju(t,e,n){if(e==="styleguide"){let{extractDesignContext:m}=await Promise.resolve().then(()=>(fs(),gs));return m(n||t.themePath)}let{resolveAgenticEngine:s}=await Promise.resolve().then(()=>(wn(),$r)),{loadConfig:o}=await Promise.resolve().then(()=>(Q(),pa)),i=o(),{engine:r,apiKey:a,model:l}=s(i),{buildPreviewHtml:c}=await Promise.resolve().then(()=>(es(),vo)),d=c();if(!d||d.length<50)return null;if(e==="brandvoice"){let{extractBrandvoice:m}=await Promise.resolve().then(()=>(Fr(),Or));return m(d,r,a,l)}let{extractThemeContext:u}=await Promise.resolve().then(()=>(Bo(),Jo));return u(d,t.brandAssets?.themeContext,r,a,l)}function em(t,e){let n=C();if(!n){p(e,404,{error:"No active session"});return}W(t,s=>{(async()=>{try{let o=s?JSON.parse(s):{},i=o.type||"styleguide",r=o.sourcePath;if(i==="all"){let c=["styleguide","brandvoice","themeContext"],d=await Promise.allSettled(c.map(g=>Ju(n,g,r))),u={};for(let g=0;g<c.length;g++){let h=d[g],f=h.status==="fulfilled"?h.value:null;f&&Lu(n,c[g],f),u[c[g]]=f}let m=null;u.styleguide&&(m=Dr(n,u.styleguide)),D(),p(e,200,{ok:!0,type:"all",extracted:u,brandKit:m});return}if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(e,400,{error:`Invalid type: ${i}`});return}let a=await Ju(n,i,r);if(!a){p(e,200,{ok:!1,type:i,error:"No content to extract from"});return}Lu(n,i,a);let l=null;i==="styleguide"&&(l=Dr(n,a)),D(),p(e,200,{ok:!0,type:i,content:a,brandKit:l})}catch(o){p(e,500,{error:o instanceof Error?o.message:String(o)})}})()})}function tm(t,e){let n=C();if(!n){p(e,404,{error:"No active session"});return}W(t,s=>{(async()=>{try{let{source:o,themeName:i,localPath:r}=JSON.parse(s),a;if(o==="hubspot"){if(!i){p(e,400,{error:"themeName is required for HubSpot import"});return}let u=Fe();if(!u){p(e,400,{error:"No HubSpot account connected"});return}let m=i.replace(/^\/+|\/+$/g,"");if(!m){p(e,400,{error:"Invalid theme name"});return}let g=m.replace(/[@/]/g,"_").replace(/_+/g,"_"),{homedir:h}=await import("os"),f=Ne(h(),"vibespot-themes",".references",g);Ie(f);let{fetchTheme:b}=await Promise.resolve().then(()=>(Hs(),Ea));await b(u,m,f),a=f}else if(o==="local"){if(!r){p(e,400,{error:"localPath is required for local import"});return}if(!ys(r)){p(e,400,{error:`Path not found: ${r}`});return}a=r}else{p(e,400,{error:"source must be 'hubspot' or 'local'"});return}let{extractDesignContext:l}=await Promise.resolve().then(()=>(fs(),gs)),c=await l(a);n.brandAssets||(n.brandAssets={}),n.brandAssets.styleguide=c,n.updatedAt=Date.now();let d=Ne(n.themePath,".vibespot");Ie(d),J(Ne(d,"styleguide.md"),c),D(),p(e,200,{ok:!0,styleguide:c,source:a})}catch(o){p(e,500,{error:o instanceof Error?o.message:String(o)})}})()})}var Oy,Xu,Fy,Du,Dy,nm=R(()=>{"use strict";y();ze();de();Q();Jn();we();ne();Oy=process.platform==="win32"?{shell:!0}:{};Xu=[{name:"System Default",stack:"system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",category:"system"},{name:"Inter",stack:"Inter, system-ui, sans-serif",category:"sans-serif"},{name:"DM Sans",stack:"'DM Sans', system-ui, sans-serif",category:"sans-serif"},{name:"Open Sans",stack:"'Open Sans', system-ui, sans-serif",category:"sans-serif"},{name:"Roboto",stack:"Roboto, system-ui, sans-serif",category:"sans-serif"},{name:"Lato",stack:"Lato, system-ui, sans-serif",category:"sans-serif"},{name:"Montserrat",stack:"Montserrat, system-ui, sans-serif",category:"sans-serif"},{name:"Poppins",stack:"Poppins, system-ui, sans-serif",category:"sans-serif"},{name:"Nunito",stack:"Nunito, system-ui, sans-serif",category:"sans-serif"},{name:"Raleway",stack:"Raleway, system-ui, sans-serif",category:"sans-serif"},{name:"Work Sans",stack:"'Work Sans', system-ui, sans-serif",category:"sans-serif"},{name:"Source Sans 3",stack:"'Source Sans 3', system-ui, sans-serif",category:"sans-serif"},{name:"Manrope",stack:"Manrope, system-ui, sans-serif",category:"sans-serif"},{name:"Plus Jakarta Sans",stack:"'Plus Jakarta Sans', system-ui, sans-serif",category:"sans-serif"},{name:"Outfit",stack:"Outfit, system-ui, sans-serif",category:"sans-serif"},{name:"Space Grotesk",stack:"'Space Grotesk', system-ui, sans-serif",category:"sans-serif"},{name:"Albert Sans",stack:"'Albert Sans', system-ui, sans-serif",category:"sans-serif"},{name:"Figtree",stack:"Figtree, system-ui, sans-serif",category:"sans-serif"},{name:"Helvetica",stack:"Helvetica, Arial, sans-serif",category:"sans-serif"},{name:"Arial",stack:"Arial, Helvetica, sans-serif",category:"sans-serif"},{name:"Verdana",stack:"Verdana, Geneva, sans-serif",category:"sans-serif"},{name:"Georgia",stack:"Georgia, 'Times New Roman', serif",category:"serif"},{name:"Playfair Display",stack:"'Playfair Display', Georgia, serif",category:"serif"},{name:"Merriweather",stack:"Merriweather, Georgia, serif",category:"serif"},{name:"Lora",stack:"Lora, Georgia, serif",category:"serif"},{name:"PT Serif",stack:"'PT Serif', Georgia, serif",category:"serif"},{name:"Libre Baskerville",stack:"'Libre Baskerville', Georgia, serif",category:"serif"},{name:"Source Serif 4",stack:"'Source Serif 4', Georgia, serif",category:"serif"},{name:"Cormorant Garamond",stack:"'Cormorant Garamond', Garamond, serif",category:"serif"},{name:"Times New Roman",stack:"'Times New Roman', Times, serif",category:"serif"},{name:"Sora",stack:"Sora, system-ui, sans-serif",category:"display"},{name:"Clash Display",stack:"'Clash Display', system-ui, sans-serif",category:"display"},{name:"Cabinet Grotesk",stack:"'Cabinet Grotesk', system-ui, sans-serif",category:"display"},{name:"Satoshi",stack:"Satoshi, system-ui, sans-serif",category:"display"},{name:"General Sans",stack:"'General Sans', system-ui, sans-serif",category:"display"},{name:"JetBrains Mono",stack:"'JetBrains Mono', 'Fira Code', monospace",category:"monospace"},{name:"Fira Code",stack:"'Fira Code', 'Courier New', monospace",category:"monospace"},{name:"Source Code Pro",stack:"'Source Code Pro', monospace",category:"monospace"},{name:"Courier New",stack:"'Courier New', Courier, monospace",category:"monospace"}];Fy=/#[0-9a-fA-F]{6}\b/g,Du=/font[- ]?famil(?:y|ies)\s*[:=]\s*([^\n]+)/gi;Dy=/^#[0-9a-fA-F]{6}$/});import{join as Ly}from"path";function sm(t,e){let n=C();if(!n){p(e,404,{error:"No active session"});return}p(e,200,{id:n.id,themeName:n.themeName,themePath:n.themePath,messageCount:n.messages.length,moduleCount:n.modules.length,moduleOrder:n.moduleOrder})}function om(t,e,n){let s=C();if(!s){p(n,404,{error:"No active session"});return}if(t==="GET"){let o=Se();p(n,200,{modules:o.map(i=>({moduleName:i.moduleName,fieldsJson:i.fieldsJson,moduleHtml:i.moduleHtml,moduleCss:i.moduleCss,moduleJs:i.moduleJs||null})),sharedCss:s.sharedCss,sharedJs:s.sharedJs});return}if(t==="DELETE"){Ve(e,n,o=>{o.deleteEntirely?wl(o.moduleName):Cl(o.moduleName),D(),p(n,200,{ok:!0})});return}p(n,405,{error:"Method not allowed"})}function im(t,e){let n=C();if(!n){p(e,404,{error:"No active session"});return}W(t,s=>{try{let o=JSON.parse(s);if(o.shared){if(o.shared==="css")n.sharedCss=o.content;else if(o.shared==="js")n.sharedJs=o.content;else{p(e,400,{error:"Invalid shared type"});return}let c=Ce();c&&(o.shared==="css"?c.sharedCss=o.content:c.sharedJs=o.content),n.updatedAt=Date.now(),et(),D(),ke(),p(e,200,{ok:!0});return}let{moduleName:i,fileType:r,content:a}=o;if(!i||!r){p(e,400,{error:"moduleName and fileType required"});return}let l=n.modules.find(c=>c.moduleName===i);if(!l){p(e,404,{error:`Module "${i}" not found`});return}switch(r){case"html":l.moduleHtml=a;break;case"css":l.moduleCss=a;break;case"js":l.moduleJs=a||void 0;break;case"fields":try{JSON.parse(a)}catch{p(e,400,{error:"Invalid JSON in fields.json"});return}l.fieldsJson=a;break;default:p(e,400,{error:`Invalid fileType: ${r}`});return}n.updatedAt=Date.now(),et(),D(),ke(),p(e,200,{ok:!0})}catch(o){p(e,400,{error:String(o)})}})}function rm(t,e){Ve(t,e,n=>{Array.isArray(n.order)?(Rt(n.order),D(),p(e,200,{ok:!0})):p(e,400,{error:"order must be an array"})})}async function am(t){let e=C();if(!e){p(t,404,{error:"No active session"});return}try{ke();let n=Qs(e.themePath),s=No(`hs cms upload "${e.themePath}" "${e.themeName}"`,"Uploading to HubSpot",{cwd:Ly(e.themePath,".."),timeout:18e4});p(t,200,{ok:!0,jobId:s,fixes:n})}catch(n){p(t,500,{error:String(n)})}}function lm(t,e){W(t,n=>{try{let{moduleName:s,fieldPath:o,value:i}=JSON.parse(n);kl(s,o,i),D(),p(e,200,{ok:!0})}catch(s){p(e,400,{error:String(s)})}})}function cm(t,e){W(t,n=>{try{let{url:s}=JSON.parse(n);if(!s||typeof s!="string"){p(e,400,{error:"url is required"});return}let o=$a(s),i=o.components.map(a=>`- ${a.name}: ${a.description}`).join(`
2692
+ `),r={sourceDir:o.sourceDir,componentCount:o.components.length,components:o.components.map(a=>({name:a.name,description:a.description})),hasTailwind:o.hasTailwind,cssVarCount:o.cssVarCount,fonts:o.fonts,interactions:o.interactions,conversionPrompt:`Import and convert the React landing page from ${s} to native HubSpot modules.
2693
+
2694
+ Source analysis found ${o.components.length} components:
2695
+ ${i}
2696
+
2697
+ Design system: ${o.hasTailwind?"Tailwind CSS":"Custom CSS"}, ${o.cssVarCount} CSS variables
2698
+ Fonts: ${o.fonts.length>0?o.fonts.join(", "):"System fonts"}
2699
+ Interactions: ${o.interactions.join(", ")}
2700
+
2701
+ Read the React source files from ${o.sourceDir} and convert each component to a HubSpot module. Preserve the design, layout, colors, and content. Generate fields.json so marketers can edit all text, images, colors, and links in the HubSpot page editor.`};p(e,200,r)}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}function dm(t,e){let n=C();if(!n){p(e,404,{error:"No active session"});return}if(!Qe()){p(e,200,{available:!1,commits:[]});return}let o=new URL(t.url||"/","http://localhost").searchParams.get("templateId"),i=o?hl(n.themePath,o,50):fl(n.themePath,50);p(e,200,{available:!0,commits:i,filtered:!!o})}function um(t,e){W(t,n=>{try{let s=C();if(!s){p(e,404,{error:"No active session"});return}let{hash:o,templateId:i}=JSON.parse(n);if(!o||typeof o!="string"){p(e,400,{error:"Commit hash is required"});return}if(tt("assistant",`Rolled back to version ${o.slice(0,7)}.`),i){let r=s.templates.find(c=>c.id===i);if(!r){p(e,404,{error:"Template not found"});return}let a=r.moduleOrder.map(c=>`modules/${c}.module`);r.templateFile&&a.push(r.templateFile);let l=bl(s.themePath,i,o,a);if(!l.success){p(e,500,{error:l.error||"Rollback failed"});return}zl()}else{let r=yl(s.themePath,o);if(!r.success){p(e,500,{error:r.error||"Rollback failed"});return}Vl()}D(),p(e,200,{ok:!0,modules:Se().map(r=>r.moduleName)})}catch(s){p(e,500,{error:s instanceof Error?s.message:String(s)})}})}var mm=R(()=>{"use strict";y();ze();we();eo();Oo();Bs();dn()});import{writeFileSync as Jy,mkdirSync as gm}from"fs";import{join as Vo}from"path";import{randomUUID as By}from"crypto";function fm(t){let e=t.match(Hy);if(!e)return null;let n=e[1],s=e[2]?decodeURIComponent(e[2].replace(/-/g," ")):void 0,o;try{let r=new URL(t).searchParams.get("node-id");r&&(o=r.replace(/-/g,":"))}catch{}return{fileKey:n,nodeId:o,fileName:s}}async function Yo(t,e){let n=await fetch(`${Uy}${t}`,{headers:{"X-Figma-Token":e}});if(!n.ok){let s=await n.text().catch(()=>""),o=new Error(`Figma API ${n.status}: ${s.slice(0,200)}`);throw o.status=n.status,o}return n.json()}async function Jr(t,e){for(let n=0;;n++)try{return await t()}catch(s){if(!(s.status===429)||n>=pm.length)throw s;let r=pm[n];E.warn("figma",`Rate limited (429), attempt ${n+1} \u2014 waiting ${r}s`),e&&e(`Figma rate limited \u2014 retrying in ${r}s...`),await new Promise(a=>setTimeout(a,r*1e3))}}function Qt(t,e,n=0){if(e(t,n),t.children)for(let s of t.children)Qt(s,e,n+1)}function hm(t,e){if(t.id===e)return t;if(t.children)for(let n of t.children){let s=hm(n,e);if(s)return s}return null}function Gy(t,e){if(e){let s=hm(t,e);if(!s)return[];if(s.type==="FRAME"||s.type==="COMPONENT"||s.type==="COMPONENT_SET"){let o=(s.children||[]).filter(i=>Lr.has(i.type));return o.length>0?o:[s]}return s.children?s.children.filter(o=>Lr.has(o.type)):[]}let n=t.children?.[0];return n?.children?n.children.filter(s=>Lr.has(s.type)):[]}function zo(t){let e=Math.round(t.r*255),n=Math.round(t.g*255),s=Math.round(t.b*255);return`#${e.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`}function Wy(t){let e=new Map;for(let n of t)Qt(n,s=>{if(s.fills){for(let o of s.fills)if(o.type==="SOLID"&&o.color){let i=zo(o.color),r=e.get(i),a=s.type==="TEXT",l=a?"text":"fill";r?(r.occurrences++,a&&r.usage!=="text"&&(r.usage="text")):e.set(i,{hex:i,opacity:o.opacity??o.color.a,occurrences:1,usage:l})}}if(s.strokes){for(let o of s.strokes)if(o.type==="SOLID"&&o.color){let i=zo(o.color),r=e.get(i);r?r.occurrences++:e.set(i,{hex:i,opacity:1,occurrences:1,usage:"border"})}}});return[...e.values()].sort((n,s)=>s.occurrences-n.occurrences)}function Ky(t){let e=new Map;for(let n of t)Qt(n,s=>{if(s.type!=="TEXT"||!s.style)return;let o=s.style,i=o.fontSize||16,r=o.fontWeight||400,a=o.lineHeightPx?Math.round(o.lineHeightPx/i*100)/100:1.5,l=o.letterSpacing||0,c=o.fontFamily||"sans-serif",d="body";i>=32?d="heading":i>=20?d="subheading":i<=12?d="caption":r>=600&&i<=14&&(d="label");let u=`${c}-${i}-${r}`,m=e.get(u);m?m.occurrences++:e.set(u,{fontFamily:c,fontSize:i,fontWeight:r,lineHeight:a,letterSpacing:l,role:d,occurrences:1})});return[...e.values()].sort((n,s)=>s.fontSize-n.fontSize)}function Vy(t){let e=[],n=new Set;for(let s of t)Qt(s,o=>{if(!o.layoutMode||o.layoutMode==="NONE")return;if(o.itemSpacing&&o.itemSpacing>0){let c=`gap-${o.itemSpacing}-${o.name}`;n.has(c)||(n.add(c),e.push({context:`${o.name} gap`,value:o.itemSpacing,type:"gap"}))}let i=o.paddingTop||0,r=o.paddingRight||0,a=o.paddingBottom||0,l=o.paddingLeft||0;if(i>0||r>0||a>0||l>0){let c=`pad-${i}-${r}-${a}-${l}-${o.name}`;if(!n.has(c)){n.add(c);let d=i===a&&l===r&&i===l?i:Math.max(i,r,a,l);e.push({context:`${o.name} padding`,value:d,type:"padding"})}}});return e}function zy(t){let e=[],n=new Set;for(let s of t)Qt(s,o=>{if(o.effects){for(let i of o.effects)if(i.type==="DROP_SHADOW"&&i.color&&i.offset){let{r,g:a,b:l,a:c}=i.color,d=`${i.offset.x}px ${i.offset.y}px ${i.radius||0}px rgba(${Math.round(r*255)},${Math.round(a*255)},${Math.round(l*255)},${Math.round(c*100)/100})`;n.has(d)||(n.add(d),e.push({type:"shadow",cssValue:d,context:o.name}))}}if(o.cornerRadius&&o.cornerRadius>0){let i=`${o.cornerRadius}px`;n.has(`radius-${i}`)||(n.add(`radius-${i}`),e.push({type:"radius",cssValue:i,context:o.name}))}});return e}function Yy(t,e){let n=[];return Qt(t,s=>{if(s.type!=="TEXT"||!s.characters?.trim())return;let o=s.style?.fontSize||16,i=s.style?.fontWeight||400,r="body";o>=32?r="headline":o>=20?r="subheadline":o<=12?r="caption":i>=600&&o<=16&&(r="label"),i>=600&&s.characters.length<40&&o>=14&&o<32&&(r="cta"),n.push({text:s.characters,fontSize:o,fontWeight:i,role:r,sectionName:e})}),n}function qy(t){let e=t.absoluteBoundingBox;return{name:t.name,type:t.type,nodeId:t.id,width:e?.width||0,height:e?.height||0,layoutMode:t.layoutMode==="NONE"?void 0:t.layoutMode,childCount:t.children?.length||0,characters:t.type==="TEXT"?t.characters:void 0}}function Xy(t){if(t.fills){for(let e of t.fills)if(e.type==="SOLID"&&e.color)return zo(e.color)}if(t.backgroundColor)return zo(t.backgroundColor)}function Zy(t){return t.map(e=>{let n=e.absoluteBoundingBox;return{name:e.name,nodeId:e.id,width:n?.width||0,height:n?.height||0,textContent:Yy(e,e.name),children:(e.children||[]).slice(0,20).map(qy),backgroundColor:Xy(e),layoutMode:e.layoutMode==="NONE"?void 0:e.layoutMode,itemSpacing:e.itemSpacing,paddingTop:e.paddingTop,paddingRight:e.paddingRight,paddingBottom:e.paddingBottom,paddingLeft:e.paddingLeft}})}function Qy(t){let e=[];for(let n of t)Qt(n,s=>{if(s.fills){for(let o of s.fills)if(o.type==="IMAGE"&&o.imageRef){e.push({nodeId:s.id,name:s.name||"image"});break}}});return e}async function ym(t,e){let n=await fetch(t);if(!n.ok)throw new Error(`Failed to download image: ${n.status}`);let s=Buffer.from(await n.arrayBuffer());Jy(e,s)}async function eb(t,e,n,s,o){if(e.length===0)return new Map;gm(s,{recursive:!0});let r=e.map(c=>c.id).join(",");o&&o("Exporting frame screenshots...");let a=await Jr(()=>Yo(`/v1/images/${t}?ids=${r}&format=png&scale=2`,n),o),l=new Map;for(let[c,d]of Object.entries(a.images)){if(!d)continue;let u=c.replace(/:/g,"-"),m=Vo(s,`frame-${u}.png`);try{await ym(d,m),l.set(c,m),E.info("figma",`Downloaded frame screenshot: ${m}`)}catch(g){E.warn("figma",`Failed to download frame ${c}: ${g}`)}}return l}async function tb(t,e,n,s,o){if(e.length===0)return[];gm(s,{recursive:!0});let i=50,r=[];for(let a=0;a<e.length;a+=i){let l=e.slice(a,a+i),c=l.map(u=>u.nodeId).join(",");o&&o(`Exporting images (${a+1}-${Math.min(a+i,e.length)} of ${e.length})...`);let d=await Jr(()=>Yo(`/v1/images/${t}?ids=${c}&format=png&scale=2`,n),o);for(let u of l){let m=d.images[u.nodeId];if(!m)continue;let h=`${u.name.replace(/[^a-zA-Z0-9-_]/g,"-").toLowerCase()}-${By().slice(0,6)}.png`,f=Vo(s,h);try{await ym(m,f),r.push({name:u.name,localPath:f,nodeId:u.nodeId,format:"png"}),E.info("figma",`Downloaded asset: ${h}`)}catch(b){E.warn("figma",`Failed to download image ${u.name}: ${b}`)}}}return r}async function bm(t,e,n,s,o){o&&o("Fetching Figma file...");let i=e?`/v1/files/${t}?ids=${e}&geometry=paths`:`/v1/files/${t}?geometry=paths`,r=await Jr(()=>Yo(i,n),o);E.info("figma",`Fetched file: ${r.name}`);let a=Gy(r.document,e);if(a.length===0)throw new Error("No frames found in the Figma file. The file may be empty or structured differently.");E.info("figma",`Found ${a.length} top-level frames`),o&&o(`Found ${a.length} sections. Extracting design tokens...`);let l={colors:Wy(a),typography:Ky(a),spacing:Vy(a),effects:zy(a)};E.info("figma","Design tokens extracted",{colors:l.colors.length,typography:l.typography.length,spacing:l.spacing.length,effects:l.effects.length}),o&&o("Mapping page structure...");let c=Zy(a),d=Vo(s,".vibespot","figma-frames"),u=await eb(t,a,n,d,o),m=c.map(b=>({...b,frameImagePath:u.get(b.nodeId)||""}));o&&o("Extracting image assets...");let g=Qy(a),h=Vo(s,"assets"),f=await tb(t,g,n,h,o);return E.info("figma",`Extraction complete: ${m.length} sections, ${f.length} assets`),{fileName:r.name,fileUrl:`https://www.figma.com/design/${t}`,designTokens:l,sections:m,assets:f}}function Sm(t){let e=t.fileName.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,30);return{fileName:t.fileName,fileUrl:t.fileUrl,sectionNames:t.sections.map(n=>n.name),sectionCount:t.sections.length,colorPalette:t.designTokens.colors.slice(0,10).map(n=>n.hex),fontFamilies:[...new Set(t.designTokens.typography.map(n=>n.fontFamily))],textBlockCount:t.sections.reduce((n,s)=>n+s.textContent.length,0),assetCount:t.assets.length,suggestedThemeName:e}}async function xm(t){return await Yo("/v1/me",t)}var Hy,Uy,pm,Lr,vm=R(()=>{"use strict";y();de();Hy=/figma\.com\/(?:design|file|proto)\/([a-zA-Z0-9]+)(?:\/([^?]*))?/;Uy="https://api.figma.com",pm=[10,20,40,60,120];Lr=new Set(["FRAME","COMPONENT","COMPONENT_SET","SECTION"])});var $m={};Be($m,{getCachedExtraction:()=>Am,handleFigmaExtractRoute:()=>Hr,handleFigmaGenerateRoute:()=>Ur,handleFigmaTestTokenRoute:()=>Br});import{randomUUID as wm}from"crypto";import{existsSync as Cm,mkdirSync as km,writeFileSync as nb,copyFileSync as sb}from"fs";import{join as qo,basename as ob}from"path";function Tm(){let t=Date.now();for(let[e,n]of bs)n.expires<t&&bs.delete(e)}function Am(t){Tm();let e=bs.get(t);return e?(bs.delete(t),e.extraction):null}function Br(t,e){Ve(t,e,async n=>{let s=n.token||O().figmaToken;if(!s){p(e,400,{ok:!1,error:"No Figma token provided"});return}try{let o=await xm(s);p(e,200,{ok:!0,user:o})}catch(o){let i=o instanceof Error?o.message:String(o);E.warn("figma",`Token test failed: ${i}`),p(e,200,{ok:!1,error:"Invalid or expired Figma token"})}})}function Hr(t,e){Ve(t,e,async n=>{let s=n.url;if(!s){p(e,400,{error:"Missing 'url' field"});return}let o=n.token||O().figmaToken;if(!o){p(e,400,{error:"No Figma token configured. Add one in Settings."});return}let i=fm(s);if(!i){p(e,400,{error:"Not a valid Figma URL. Expected: figma.com/design/<key>/..."});return}let a=C()?.themePath||`/tmp/vibespot-figma-${wm().slice(0,8)}`;e.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});let l=c=>{e.write(`data: ${JSON.stringify(c)}
2702
+
2703
+ `)};try{let c=await bm(i.fileKey,i.nodeId,o,a,m=>l({type:"progress",message:m})),d=wm();Tm(),bs.set(d,{extraction:c,expires:Date.now()+ib});let u=Sm(c);l({type:"complete",ok:!0,extractionId:d,summary:u})}catch(c){let d=c instanceof Error?c.message:String(c);E.error("figma",`Extraction failed: ${d}`);let u=d;d.includes("403")?u="Cannot access this file. Check sharing permissions and your token.":d.includes("404")?u="Figma file not found. Check the URL.":d.includes("429")&&(u="Figma rate limited. Try again in a minute."),l({type:"complete",ok:!1,error:u})}e.end()})}function rb(t){let{designTokens:e,fileName:n}=t,s=[`# Styleguide \u2014 ${n}`,""];if(e.colors.length>0){s.push("## Colors","");let o=[...e.colors].sort((a,l)=>l.count-a.count),i=o[0],r=o[1];i&&s.push(`- **Primary:** \`${i.hex}\` (${i.name||"dominant color"})`),r&&s.push(`- **Secondary:** \`${r.hex}\` (${r.name||"accent color"})`),s.push(""),s.push("### Full palette","");for(let a of o.slice(0,15)){let l=a.name?`${a.name}`:`${a.count}\xD7 used`;s.push(`- \`${a.hex}\` \u2014 ${l}`)}s.push("")}if(e.typography.length>0){s.push("## Typography","");let o=[...new Set(e.typography.map(r=>r.fontFamily))];s.push(`**Font families:** ${o.join(", ")}`,""),s.push("| Role | Family | Size | Weight |"),s.push("|------|--------|------|--------|");let i=new Set;for(let r of e.typography){let a=`${r.role}-${r.fontSize}-${r.fontWeight}`;i.has(a)||(i.add(a),s.push(`| ${r.role} | ${r.fontFamily} | ${r.fontSize}px | ${r.fontWeight} |`))}s.push("")}if(e.spacing.length>0){s.push("## Spacing","");let o=[...new Set(e.spacing.map(i=>i.value))].sort((i,r)=>i-r);s.push(`**Scale:** ${o.join("px, ")}px`,"");for(let i of e.spacing)s.push(`- **${i.property}** (${i.context}): ${i.value}px`);s.push("")}if(e.effects.length>0){s.push("## Effects","");for(let o of e.effects)o.boxShadow&&s.push(`- **Box shadow:** \`${o.boxShadow}\``),o.borderRadius&&s.push(`- **Border radius:** ${o.borderRadius}px`);s.push("")}return s.join(`
2704
+ `)}function Ur(t,e){Ve(t,e,async n=>{let s=n.extractionId,o=n.themeName,i=n.useAssets!==!1;if(!s||!o){p(e,400,{error:"Missing extractionId or themeName"});return}let r=Am(s);if(!r){p(e,400,{error:"Extraction expired or not found. Please re-extract."});return}let a=C();if(!a){p(e,400,{error:"No active session. Create a theme first."});return}e.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});let l=c=>{e.write(`data: ${JSON.stringify(c)}
1595
2705
 
1596
- `)};try{let c=await _c(i.fileKey,i.nodeId,o,r,m=>l({type:"progress",message:m})),d=Oc();Jc(),Nn.set(d,{extraction:c,expires:Date.now()+Jp});let u=Nc(c);l({type:"complete",ok:!0,extractionId:d,summary:u})}catch(c){let d=c instanceof Error?c.message:String(c);A.error("figma",`Extraction failed: ${d}`);let u=d;d.includes("403")?u="Cannot access this file. Check sharing permissions and your token.":d.includes("404")?u="Figma file not found. Check the URL.":d.includes("429")&&(u="Figma rate limited. Try again in a minute."),l({type:"complete",ok:!1,error:u})}t.end()})}function jp(e){let{designTokens:t,fileName:n}=e,s=[`# Styleguide \u2014 ${n}`,""];if(t.colors.length>0){s.push("## Colors","");let o=[...t.colors].sort((r,l)=>l.count-r.count),i=o[0],a=o[1];i&&s.push(`- **Primary:** \`${i.hex}\` (${i.name||"dominant color"})`),a&&s.push(`- **Secondary:** \`${a.hex}\` (${a.name||"accent color"})`),s.push(""),s.push("### Full palette","");for(let r of o.slice(0,15)){let l=r.name?`${r.name}`:`${r.count}\xD7 used`;s.push(`- \`${r.hex}\` \u2014 ${l}`)}s.push("")}if(t.typography.length>0){s.push("## Typography","");let o=[...new Set(t.typography.map(a=>a.fontFamily))];s.push(`**Font families:** ${o.join(", ")}`,""),s.push("| Role | Family | Size | Weight |"),s.push("|------|--------|------|--------|");let i=new Set;for(let a of t.typography){let r=`${a.role}-${a.fontSize}-${a.fontWeight}`;i.has(r)||(i.add(r),s.push(`| ${a.role} | ${a.fontFamily} | ${a.fontSize}px | ${a.fontWeight} |`))}s.push("")}if(t.spacing.length>0){s.push("## Spacing","");let o=[...new Set(t.spacing.map(i=>i.value))].sort((i,a)=>i-a);s.push(`**Scale:** ${o.join("px, ")}px`,"");for(let i of t.spacing)s.push(`- **${i.property}** (${i.context}): ${i.value}px`);s.push("")}if(t.effects.length>0){s.push("## Effects","");for(let o of t.effects)o.boxShadow&&s.push(`- **Box shadow:** \`${o.boxShadow}\``),o.borderRadius&&s.push(`- **Border radius:** ${o.borderRadius}px`);s.push("")}return s.join(`
1597
- `)}function $i(e,t){Ye(e,t,async n=>{let s=n.extractionId,o=n.themeName,i=n.useAssets!==!1;if(!s||!o){p(t,400,{error:"Missing extractionId or themeName"});return}let a=jc(s);if(!a){p(t,400,{error:"Extraction expired or not found. Please re-extract."});return}let r=v();if(!r){p(t,400,{error:"No active session. Create a theme first."});return}t.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});let l=c=>{t.write(`data: ${JSON.stringify(c)}
2706
+ `)};try{l({type:"progress",message:"Generating styleguide from design tokens..."});let c=rb(r),d=qo(a.themePath,".vibespot");if(Cm(d)||km(d,{recursive:!0}),nb(qo(d,"styleguide.md"),c),a.brandAssets||(a.brandAssets={}),a.brandAssets.styleguide=c,D(),l({type:"progress",message:"Styleguide saved."}),a.templates.length===0)Tt("landing_page","Landing Page");else{a.modules=[],a.moduleOrder=[],a.sharedCss="",a.sharedJs="";let f=a.templates.find(b=>b.id===a.activeTemplateId);f&&(f.modules=[],f.moduleOrder=[],f.sharedCss="",f.sharedJs="")}if(D(),i&&r.assets.length>0){let f=qo(a.themePath,"assets");km(f,{recursive:!0});let b=0;for(let S of r.assets)if(Cm(S.localPath)){let x=qo(f,ob(S.localPath));try{sb(S.localPath,x),S.localPath=x,b++}catch{}}b>0&&l({type:"progress",message:`Copied ${b} image assets to theme.`})}l({type:"progress",message:"Starting AI conversion..."});let u=[],m=[],g=await us(r,o,f=>{if(f.type==="agent_step")u.push({step:f.step,label:f.label}),l({type:"progress",message:`${f.label}...`});else if(f.type==="agent_decision"){let b=u[u.length-1];b&&(b.decisions||(b.decisions=[]),b.decisions.push(f.decision)),l({type:"progress",message:` ${f.decision}`})}else f.type==="design_system_ready"?De({sharedCss:f.sharedCss,sharedJs:f.sharedJs}):f.type==="blueprint_ready"?(De({sharedCss:f.sharedCss,sharedJs:f.sharedJs}),Rt(f.moduleOrder),l({type:"progress",message:`Planned ${f.moduleOrder.length} modules`})):f.type==="module_progress"&&(f.status==="generating"?l({type:"progress",message:`Generating module: ${f.module}`}):f.status==="complete"&&f.moduleFiles?(De({modules:[{moduleName:f.module,fieldsJson:f.moduleFiles.fieldsJson,metaJson:f.moduleFiles.metaJson,moduleHtml:f.moduleFiles.moduleHtml,moduleCss:f.moduleFiles.moduleCss,moduleJs:f.moduleFiles.moduleJs}]}),m.push({name:f.module,status:"complete"}),l({type:"progress",message:`Module complete: ${f.module}`})):f.status==="failed"&&(m.push({name:f.module,status:"failed"}),l({type:"progress",message:`Module failed: ${f.module}`})))},{useAssets:i});qt(g,{steps:u,modules:m,stats:g.stats}),ke(),Gt(a.themePath,`Figma import: ${r.fileName}`);let h=Se().map(f=>f.moduleName);l({type:"progress",message:`Conversion complete \u2014 ${h.length} modules generated`}),l({type:"complete",ok:!0,modules:h})}catch(c){let d=c instanceof Error?c.message:String(c);E.error("figma",`Generate failed: ${d}`),l({type:"complete",ok:!1,error:d})}e.end()})}var bs,ib,Gr=R(()=>{"use strict";y();ze();Q();de();vm();we();Wn();Ui();dn();wn();Nt();bs=new Map,ib=1800*1e3});import{readdirSync as Vr,statSync as ab}from"fs";import{join as q,relative as lb}from"path";function Tn(t){let e=q(t,_t);if(!v(e))return null;try{return JSON.parse(M(e))}catch{return null}}function Zo(t,e){let n=q(t,_t);J(n,JSON.stringify(e,null,2)+`
2707
+ `)}function Ss(t){let e=[];if(!v(t))return e.push({severity:"error",rule:"theme.path.missing",message:`Theme directory not found: ${t}`}),Wr(t,e,null);let n=Kr(q(t,"theme.json"));if(!n)return e.push({severity:"error",rule:"theme.json.missing",file:"theme.json",message:"theme.json is missing or invalid JSON",fix:"Recreate the theme so theme.json is generated, or restore it from version control."}),Wr(t,e,Tn(t));ub(t,n,e),mb(t,n,e),pb(t,e),fb(t,e),hb(t,e),yb(t,e);let s=Tn(t);return bb(s,e),Wr(t,e,s)}function Wr(t,e,n){let s=e.filter(r=>r.severity==="error").length,o=e.filter(r=>r.severity==="warning").length,i=e.filter(r=>r.severity==="info").length;return{themePath:t,passed:s===0,errorCount:s,warningCount:o,infoCount:i,findings:e,metadata:n}}function ub(t,e,n){let s={documentation_url:'Add a "documentation_url" entry pointing to public docs for the theme.',license:'Add a "license" entry \u2014 an SPDX identifier or URL (e.g. "MIT").',example_url:'Add an "example_url" entry pointing to a public live preview of the theme.'};for(let r of cb)yt(e,r)||n.push({severity:"error",rule:`theme.json.${r}.missing`,file:"theme.json",message:`theme.json is missing required field "${r}"`,fix:s[r]??`Add a "${r}" entry to theme.json.`});for(let r of db)(!(r in e)||typeof e[r]!="boolean")&&n.push({severity:"error",rule:`theme.json.${r}.missing`,file:"theme.json",message:`theme.json must declare boolean "${r}"`,fix:`Add "${r}": true (or false) to theme.json.`});let o=e.author;!o||typeof o!="object"?n.push({severity:"error",rule:"theme.json.author.missing",file:"theme.json",message:'theme.json is missing required "author" block',fix:'Add { "author": { "name": "...", "email": "...", "url": "..." } } to theme.json.'}):(yt(o,"name")||n.push({severity:"error",rule:"theme.json.author.name.missing",file:"theme.json",message:"theme.json author.name is missing",fix:"Provide a publisher name in theme.json author.name."}),yt(o,"email")||n.push({severity:"error",rule:"theme.json.author.email.missing",file:"theme.json",message:"theme.json author.email is missing",fix:"Provide a contact email in theme.json author.email."}),yt(o,"url")||n.push({severity:"error",rule:"theme.json.author.url.missing",file:"theme.json",message:"theme.json author.url is missing",fix:"Add a public URL for the publisher (homepage or support page)."}));let i=e.preview_path;if(typeof i=="string"&&i.length>0){let r=Im(t,i);v(r)||n.push({severity:"error",rule:"theme.json.preview_path.invalid",file:"theme.json",message:`preview_path "${i}" does not point to an existing file`,fix:"Update preview_path to a real template, e.g. ./templates/home.html."})}}function mb(t,e,n){let s=e.screenshot_path;if(typeof s!="string"||s.length===0)return;let o=Im(t,s);if(!v(o)){n.push({severity:"error",rule:"theme.json.screenshot.missing",file:"theme.json",message:`Screenshot not found at ${s}`,fix:"Place a 1500\xD71000 PNG at the screenshot_path declared in theme.json."});return}/\.(png|jpg|jpeg)$/i.test(s)||n.push({severity:"warning",rule:"theme.json.screenshot.format",file:s,message:"Screenshot should be a PNG or JPG",fix:"Re-export the screenshot as PNG (1500\xD71000) or JPG."})}function pb(t,e){let n=q(t,"modules");if(!v(n)){e.push({severity:"warning",rule:"modules.empty",message:"Theme has no modules/ directory",fix:"Generate at least one module before submitting to Marketplace."});return}let s=0,o=[];try{o=Vr(n)}catch{return}for(let i of o){if(!i.endsWith(".module"))continue;s++;let r=q(n,i);gb(t,r,i,e)}s===0&&e.push({severity:"warning",rule:"modules.empty",message:"Theme has no .module directories",fix:"Generate at least one module before submitting to Marketplace."})}function gb(t,e,n,s){let o=Kr(q(e,"meta.json")),i=ot(t,q(e,"meta.json"));o?(yt(o,"label")||s.push({severity:"error",rule:"module.meta.label.missing",file:i,message:`${n}: meta.json is missing "label"`,fix:`Add a "label" entry to the module's meta.json.`,autoFixable:!0}),o.is_available_for_new_content===!1&&s.push({severity:"info",rule:"module.meta.unavailable",file:i,message:`${n}: is_available_for_new_content=false (won\u2019t be selectable in HubSpot UI)`})):s.push({severity:"error",rule:"module.meta.missing",file:i,message:`${n}: meta.json is missing or invalid`,fix:"Recreate the module so meta.json is generated."});let r=q(e,"fields.json"),a=ot(t,r);if(!v(r))s.push({severity:"warning",rule:"module.fields.missing",file:a,message:`${n}: fields.json is missing`,fix:"Add a fields.json (an empty array [] is acceptable for static modules)."});else{let c=Kr(r);Array.isArray(c)?Mm(c,n,a,s):s.push({severity:"warning",rule:"module.fields.invalid",file:a,message:`${n}: fields.json is not a JSON array`})}let l=q(e,"module.html");v(l)||s.push({severity:"error",rule:"module.html.missing",file:ot(t,l),message:`${n}: module.html is missing`,fix:"Recreate the module so module.html is generated."})}function Mm(t,e,n,s){for(let o of t){if(typeof o!="object"||o===null)continue;let i=o,r=typeof i.name=="string"?i.name:"(unnamed)";yt(i,"label")||s.push({severity:"error",rule:"module.field.label.missing",file:n,message:`${e}.${r}: field is missing "label"`,fix:`Add a human-readable "label" to the "${r}" field in fields.json.`,autoFixable:!0}),!yt(i,"help_text")&&i.type!=="group"&&s.push({severity:"info",rule:"module.field.help_text.missing",file:n,message:`${e}.${r}: consider adding "help_text"`,fix:`Add a short "help_text" describing what "${r}" controls.`}),Array.isArray(i.children)&&Mm(i.children,e,n,s)}}function fb(t,e){let n=[],s=q(t,"css");Xo(s,".css").forEach(i=>{_m(i,n,t)});let o=q(t,"modules");if(v(o))for(let i of xs(o)){if(!i.endsWith(".module"))continue;let r=q(o,i);["module.css","module.html"].forEach(a=>{let l=q(r,a);v(l)&&_m(l,n,t)})}for(let i of n)e.push({severity:"error",rule:"asset.cdn-import",file:i.file,message:`External CDN reference found: ${i.match}`,fix:"Remove external @import / <link> URLs and bundle the asset locally.",autoFixable:!0})}function _m(t,e,n){let s;try{s=M(t)}catch{return}let o=s.match(/@import\s+url\(['"]?https?:\/\/[^)\s'"]+['"]?\)/i);o&&e.push({file:ot(n,t),match:o[0]});let i=s.match(/<link[^>]+href=['"]https?:\/\/[^'"]+['"][^>]*>/i);i&&e.push({file:ot(n,t),match:i[0]});let r=s.match(/<script[^>]+src=['"]https?:\/\/[^'"]+['"][^>]*>/i);r&&e.push({file:ot(n,t),match:r[0]})}function hb(t,e){let n=[{rule:"asset.hardcoded.hubfs",re:/https?:\/\/[\w.-]*hubfs[\w.-]*\/(\d+)\//i,message:"Hardcoded portal-specific HubFS URL detected"},{rule:"asset.hardcoded.usercontent",re:/hubspotusercontent[-\w]*\.net\/(\w+\/)?(\d+)\//i,message:"Hardcoded portal-specific HubSpot user-content URL detected"},{rule:"asset.hardcoded.preview",re:/\d+\.hs-sites\.com|hubspotpagebuilder\.com\/\d+/i,message:"Hardcoded portal preview URL detected"}],s=[],o=q(t,"css");Xo(o,".css").forEach(a=>s.push(a));let i=q(t,"js");Xo(i,".js").forEach(a=>s.push(a));let r=q(t,"modules");if(v(r))for(let a of xs(r))a.endsWith(".module")&&["module.html","module.css","module.js"].forEach(l=>{let c=q(r,a,l);v(c)&&s.push(c)});for(let a of s){let l;try{l=M(a)}catch{continue}for(let c of n){let d=l.match(c.re);d&&e.push({severity:"error",rule:c.rule,file:ot(t,a),message:`${c.message}: ${d[0]}`,fix:"Replace portal-specific URLs with theme-relative paths or HubSpot tokens like get_asset_url."})}}}function yb(t,e){let n=q(t,"modules");if(v(n))for(let s of xs(n)){if(!s.endsWith(".module"))continue;let o=q(n,s,"module.html");if(!v(o))continue;let i;try{i=M(o)}catch{continue}let r=/<img\b([^>]*)>/gi,a;for(;a=r.exec(i);){let c=a[1];/\balt\s*=/.test(c)||e.push({severity:"warning",rule:"a11y.img.alt-missing",file:ot(t,o),message:`${s}: <img> without alt attribute`,fix:'Add an alt attribute (alt="" is fine for purely decorative images).'})}/<(section|article|header|footer|main|nav|aside|h[1-6])\b/i.test(i)||e.push({severity:"info",rule:"a11y.semantics.missing",file:ot(t,o),message:`${s}: module.html has no semantic landmarks (section/article/header/etc.)`,fix:"Wrap the module's main content in a <section> with a heading."})}}function bb(t,e){if(!t){e.push({severity:"warning",rule:"marketplace.json.missing",file:_t,message:"marketplace.json sidecar not found",fix:"Run `vibespot marketplace edit` (CLI) or open the Marketplace panel in the editor to fill in listing details."});return}t.category?Lt.includes(t.category)||e.push({severity:"warning",rule:"marketplace.json.category.unknown",file:_t,message:`marketplace.json category "${t.category}" is not a recognized HubSpot Marketplace category`,fix:`Use one of: ${Lt.join(", ")}.`}):e.push({severity:"warning",rule:"marketplace.json.category.missing",file:_t,message:"marketplace.json has no category",fix:`Pick one of: ${Lt.join(", ")}.`}),(!t.description||t.description.trim().length<40)&&e.push({severity:"warning",rule:"marketplace.json.description.short",file:_t,message:"marketplace.json description is missing or short (<40 chars)",fix:"Provide a 1\u20132 sentence description of the theme for the Marketplace listing."}),t.supportUrl||e.push({severity:"warning",rule:"marketplace.json.supportUrl.missing",file:_t,message:"marketplace.json has no supportUrl",fix:"Add a public support URL where buyers can reach the publisher."});let n=t.features?.length??0;n<2?e.push({severity:"warning",rule:"marketplace.json.features.too_few",file:_t,message:`marketplace.json needs at least 2 features (has ${n})`,fix:"Add 2\u20135 short bullet points highlighting what the theme does well."}):n>5&&e.push({severity:"warning",rule:"marketplace.json.features.too_many",file:_t,message:`marketplace.json has ${n} features but HubSpot allows at most 5`,fix:"Trim the features list to 5 or fewer entries."})}function Qo(t){let e=[],n=[],s=q(t,"modules");if(v(s))for(let i of xs(s)){if(!i.endsWith(".module"))continue;let r=q(s,i),a=i.replace(/\.module$/,""),l=q(r,"meta.json");if(v(l))try{let d=JSON.parse(M(l));yt(d,"label")||(d.label=Pm(a),J(l,JSON.stringify(d,null,2)+`
2708
+ `),e.push(`${i}: filled meta.label = "${d.label}"`))}catch{n.push(`${i}: meta.json could not be parsed`)}let c=q(r,"fields.json");if(v(c))try{let d=JSON.parse(M(c));if(Array.isArray(d)){let u=Em(d);u>0&&(J(c,JSON.stringify(d,null,2)+`
2709
+ `),e.push(`${i}: filled ${u} missing field label(s)`))}}catch{n.push(`${i}: fields.json could not be parsed`)}}let o=Sb(t);for(let i of o)e.push(`${i}: stripped external CDN reference(s)`);return{applied:e,skipped:n}}function Sb(t){let e=[],n=/@import\s+url\(['"]?https?:\/\/[^)]+['"]?\)\s*;?/gi,s=/<link[^>]+href=['"]https?:\/\/[^'"]+['"][^>]*>/gi,o=/<script[^>]+src=['"]https?:\/\/[^'"]+['"][^>]*><\/script>/gi,i=/<script[^>]+src=['"]https?:\/\/[^'"]+['"][^>]*\/>/gi;function r(c){let d;try{d=M(c)}catch{return}let u=d.replace(n,"");u!==d&&(J(c,u),e.push(ot(t,c)))}function a(c){let d;try{d=M(c)}catch{return}let u=d.replace(s,"");u=u.replace(o,""),u=u.replace(i,""),u=u.replace(n,""),u!==d&&(J(c,u),e.push(ot(t,c)))}Xo(q(t,"css"),".css").forEach(r);let l=q(t,"modules");if(v(l))for(let c of xs(l)){if(!c.endsWith(".module"))continue;let d=q(l,c),u=q(d,"module.css"),m=q(d,"module.html");v(u)&&r(u),v(m)&&a(m)}return e}function Em(t){let e=0;for(let n of t){if(typeof n!="object"||n===null)continue;let s=n;!yt(s,"label")&&yt(s,"name")&&(s.label=Pm(String(s.name)),e++),Array.isArray(s.children)&&(e+=Em(s.children))}return e}function Kr(t){if(!v(t))return null;try{let e=JSON.parse(M(t));return e&&typeof e=="object"?e:null}catch{return null}}function yt(t,e){let n=t[e];return typeof n=="string"?n.trim().length>0:Array.isArray(n)?n.length>0:n!=null&&n!==""}function Im(t,e){let n=e.replace(/^\.?\//,"");return q(t,n)}function ot(t,e){return lb(t,e).split("\\").join("/")}function xs(t){try{return Vr(t)}catch{return[]}}function Xo(t,e){if(!v(t))return[];try{let n=[];for(let s of Vr(t)){let o=q(t,s);ab(o).isFile()&&s.endsWith(e)&&n.push(o)}return n}catch{return[]}}function Pm(t){return t.replace(/[-_]+/g," ").split(" ").filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}var Lt,cb,db,_t,zr=R(()=>{"use strict";y();ne();Lt=["Business Services","Education","Events","Health & Wellness","Hospitality","Marketing & SEO","Non-profit","Portfolio","Real Estate","Restaurant & Food","Retail & E-commerce","SaaS & Technology","Travel","Other"],cb=["label","preview_path","screenshot_path","version","documentation_url","license","example_url"],db=["enable_domain_stylesheets","is_available_for_new_content"],_t="marketplace.json"});function Yr(t){let e=C();if(!e)return p(t,400,{error:"No active theme. Open or create a theme first."}),null;try{ke()}catch{}return e.themePath}function Rm(t,e){let n=Yr(e);if(!n)return;let s=Ss(n);p(e,200,{report:s,categories:Lt})}function Nm(t,e){let n=Yr(e);if(!n)return;let s=Qo(n),o=Ss(n);p(e,200,{fix:s,report:o})}function Om(t,e,n){let s=Yr(n);if(s){if(t==="GET"){p(n,200,{metadata:Tn(s),categories:Lt});return}if(t==="POST"){Ve(e,n,o=>{let i={category:typeof o.category=="string"?o.category:void 0,description:typeof o.description=="string"?o.description:void 0,features:Array.isArray(o.features)?o.features.filter(r=>typeof r=="string"&&r.trim().length>0):void 0,supportUrl:typeof o.supportUrl=="string"?o.supportUrl:void 0,documentationUrl:typeof o.documentationUrl=="string"?o.documentationUrl:void 0,pricingTier:o.pricingTier==="free"||o.pricingTier==="paid"?o.pricingTier:void 0,tags:Array.isArray(o.tags)?o.tags.filter(r=>typeof r=="string"):void 0};Zo(s,i),p(n,200,{ok:!0,metadata:i})});return}p(n,405,{error:"Method not allowed"})}}var Fm=R(()=>{"use strict";y();ze();we();zr()});function xb(t){let e=C();if(!e)return p(t,400,{error:"No active theme. Open or fetch a theme first."}),null;try{ke()}catch{}return e.themePath}function jm(t,e){let n=xb(e);if(!n)return;let s=ho(n);p(e,200,{report:s})}function Dm(t,e){let n=C();if(!n){p(e,400,{error:"No active theme. Open or fetch a theme first."});return}let s=fn(n.themePath),o=Yn(s);if(!o){p(e,200,{applied:!1,reason:"No tokens to apply."});return}if(!n.sharedCss||n.sharedCss.trim().length===0){n.sharedCss=o,n.updatedAt=Date.now(),D(),p(e,200,{applied:!0,written:"session.sharedCss",rootBlock:o});return}let i=yo(n.themePath,n.themeName);i?p(e,200,{applied:!0,written:i,rootBlock:o}):p(e,200,{applied:!1,reason:"Theme already has shared CSS."})}var Lm=R(()=>{"use strict";y();ze();we();bo()});import{createServer as vb}from"http";import{readFileSync as Xr,existsSync as vs}from"fs";import{join as Et,extname as Bm}from"path";import{WebSocketServer as wb,WebSocket as Cb}from"ws";function Ee(t){ti&&ti.readyState===Cb.OPEN&&ti.send(JSON.stringify(t))}function ei(t){ni.push(t),Ee(t)}function Mt(){ni=[]}function qr(t,e){return n=>{if(n.type==="module_progress"&&n.moduleFiles){let{moduleFiles:s,...o}=n;ei(o)}else ei(n);if(n.type==="agent_step")t.push({step:n.step,label:n.label});else if(n.type==="agent_decision"){let s=t[t.length-1];s&&(s.decisions||(s.decisions=[]),s.decisions.push(n.decision))}else n.type==="design_system_ready"?De({sharedCss:n.sharedCss,sharedJs:n.sharedJs}):n.type==="blueprint_ready"?(De({sharedCss:n.sharedCss,sharedJs:n.sharedJs}),Rt(n.moduleOrder),ei({type:"modules_updated",modules:Se().map(s=>s.moduleName)})):n.type==="module_progress"&&n.status==="complete"&&n.moduleFiles?(De({modules:[{moduleName:n.module,fieldsJson:n.moduleFiles.fieldsJson,metaJson:n.moduleFiles.metaJson,moduleHtml:n.moduleFiles.moduleHtml,moduleCss:n.moduleFiles.moduleCss,moduleJs:n.moduleFiles.moduleJs}]}),ei({type:"modules_updated",modules:Se().map(s=>s.moduleName)}),e.push({name:n.module,status:"complete"})):n.type==="module_progress"&&n.status==="failed"&&e.push({name:n.module,status:"failed"})}}function yn(){return Um}function si(t){let{port:e,uiDir:n}=t;Um=t.contentMode||"page";let s=vb((i,r)=>kb(i,r,n)),o=new wb({server:s});return o.on("connection",i=>Ab(i)),new Promise((i,r)=>{s.on("error",a=>{a.code==="EADDRINUSE"?s.listen(e+1,"0.0.0.0",()=>{i({port:e+1,close:()=>{s.close(),o.close()}})}):r(a)}),s.listen(e,"0.0.0.0",()=>{i({port:e,close:()=>{s.close(),o.close()}})})})}function kb(t,e,n){let s=new URL(t.url||"/",`http://${t.headers.host}`),o=t.method||"GET";if(e.setHeader("X-Content-Type-Options","nosniff"),e.setHeader("X-Frame-Options","DENY"),e.setHeader("X-XSS-Protection","1; mode=block"),e.setHeader("Referrer-Policy","strict-origin-when-cross-origin"),s.pathname.startsWith("/api/")){Tb(o,s.pathname,t,e);return}if(s.pathname==="/preview"){let i=Vi();e.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),e.end(i);return}if(s.pathname==="/module-preview"){let i=s.searchParams.get("module")||"",r=zi(i);e.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),e.end(r||"<!-- module not found -->");return}if(s.pathname.startsWith("/theme-assets/")){$b(s.pathname.slice(14),e);return}if(s.pathname==="/docs"){e.writeHead(301,{Location:"/docs/"}),e.end();return}if(s.pathname.startsWith("/docs/")){let i=s.pathname.slice(5)||"/index.html";Jm(i,Et(n,"docs"),t,e);return}Jm(s.pathname,n,t,e)}function Tb(t,e,n,s){let o=n.headers.origin||"";if(/^https?:\/\/(localhost|127\.0\.0\.1|100\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|10\.\d+\.\d+\.\d+)(:\d+)?$/.test(o)&&s.setHeader("Access-Control-Allow-Origin",o),s.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS"),s.setHeader("Access-Control-Allow-Headers","Content-Type"),t==="OPTIONS"){s.writeHead(204),s.end();return}switch(e){case"/api/session":sm(t,s);break;case"/api/modules":om(t,n,s);break;case"/api/modules/reorder":rm(n,s);break;case"/api/modules/code":im(n,s);break;case"/api/upload":am(s);break;case"/api/upload-files":t==="POST"?wc(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/field":lm(n,s);break;case"/api/import":cm(n,s);break;case"/api/setup":tu(s);break;case"/api/setup/create":nu(n,s);break;case"/api/setup/fetch":ou(n,s);break;case"/api/setup/open":iu(n,s);break;case"/api/setup/resume":ru(n,s);break;case"/api/setup/apikey":au(n,s);break;case"/api/setup/remote-themes":t==="GET"?lu(s):p(s,405,{error:"Method not allowed"});break;case"/api/starters":t==="GET"?su(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/status":t==="GET"?gu(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/engine":t==="POST"?fu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/apikey":t==="POST"?hu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/install":t==="POST"?yu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-auth":t==="POST"?bu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/gh-auth":t==="POST"?Su(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-switch":t==="POST"?xu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/gh-logout":t==="POST"?vu(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/cli-auth":t==="POST"?wu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-mode":t==="POST"?Cu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/cli-toggle":t==="POST"?ku(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/save":t==="POST"?_u(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/status":t==="GET"?Mu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/logout":t==="POST"?Eu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings":t==="POST"?Tu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/changelog":t==="GET"?p(s,200,{changelog:la()}):p(s,405,{error:"Method not allowed"});break;case"/api/themes":Pu(t,n,s);break;case"/api/themes/switch":t==="POST"?Ru(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/delete-local":t==="POST"?Nu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/rename":t==="POST"?Ou(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/duplicate":t==="POST"?Fu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/history":t==="GET"?dm(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/rollback":t==="POST"?um(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/dashboard":t==="GET"?Bu(s):p(s,405,{error:"Method not allowed"});break;case"/api/templates":Uu(t,n,s);break;case"/api/templates/activate":t==="POST"?Gu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/rename":t==="POST"?Wu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/clone":t==="POST"?Vu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/reorder":t==="POST"?Ku(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/module-library":t==="GET"?zu(s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets":qu(t,n,s);break;case"/api/brand-kit":Qu(t,n,s);break;case"/api/fonts":t==="GET"?Zu(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets/extract":t==="POST"?em(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets/import-reference":t==="POST"?tm(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/download-zip":t==="GET"?Hu(s):p(s,405,{error:"Method not allowed"});break;case"/api/figma/test-token":t==="POST"?Br(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/figma/extract":t==="POST"?Hr(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/figma/generate":t==="POST"?Ur(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/plan/edit":t==="POST"?Pd(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/plan/discard":t==="POST"?Rd(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/plan/templates":t==="GET"?Nd(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/plan/template":t==="POST"?Od(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/marketplace/check":t==="GET"?Rm(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/marketplace/fix":t==="POST"?Nm(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/marketplace/listing":Om(t,n,s);break;case"/api/inverse/analyze":t==="GET"?jm(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/inverse/apply-tokens":t==="POST"?Dm(n,s):p(s,405,{error:"Method not allowed"});break;default:e.startsWith("/api/settings/job/")&&t==="GET"?Au(e,s):e.match(/^\/api\/templates\/[^/]+\/add-module$/)&&t==="POST"?Yu(e,n,s):p(s,404,{error:"Not found"})}}function Ab(t){t.on("message",async n=>{let s;try{s=JSON.parse(n.toString())}catch{t.send(JSON.stringify({type:"error",message:"Invalid JSON"}));return}switch(s.type){case"chat":{let o=String(s.message||"");if(!o.trim())return;let i=Array.isArray(s.fileIds)?s.fileIds:void 0;if(Tr()){tt("user",o),D();try{t.send(JSON.stringify({type:"stream_status",content:"Planning..."}));let a="",l=await kr(o,d=>{a+=d,t.send(JSON.stringify({type:"stream",content:d}))},i),c=jd(l||a);c.plan&&(Po(c.plan),t.send(JSON.stringify({type:"plan_updated",plan:c.plan}))),c.choices&&t.send(JSON.stringify({type:"plan_choices",question:c.choices.question,options:c.choices.options})),tt("assistant",c.cleanedContent),D(),t.send(JSON.stringify({type:"plan_complete",cleanedContent:c.cleanedContent})),t.send(JSON.stringify({type:"generation_complete"}))}catch(a){t.send(JSON.stringify({type:"error",message:a instanceof Error?a.message:String(a)}))}break}tt("user",o),D();let r=Ar();r.needsPrompt&&t.send(JSON.stringify({type:"agentic_prompt"}));try{if(r.useAgentic){Mt();let l=[],c=[],d=await Eo(o,qr(l,c),i);qt(d,{steps:l,modules:c,stats:d.stats})}else wr(l=>{Ee({type:"parse_warning",message:l})}),await ds(o,l=>{Ee({type:"stream",content:l})},l=>{Ee({type:"stream_status",content:l})},i);let a=C();if(a){ke();let l=Ce(),c=null;if(l){let d=l.moduleOrder.map(u=>`modules/${u}.module`);l.templateFile&&d.push(l.templateFile),l.sharedCss&&d.push(`css/${a.themeName}-theme.css`),l.sharedJs&&d.push(`js/${a.themeName}-animations.js`),c=_i(a.themePath,l.id,o,d)}else c=Gt(a.themePath,o);c&&Ee({type:"version_created",hash:c})}Ee({type:"generation_complete"});{let l=C();Ee({type:"modules_updated",modules:Se().map(c=>c.moduleName),templateId:l?.activeTemplateId||null,templates:(l?.templates||[]).map(c=>({id:c.id,label:c.label,pageType:c.pageType,moduleCount:c.modules.length}))})}Mt();{let l=C();l&&r.useAgentic&&!l.brandAssets?.styleguide&&!l.brandAssets?.brandvoice&&!l.brandAssets?.themeContext&&Ee({type:"suggest_brand_extraction"})}}catch(a){Mt(),Ee({type:"error",message:a instanceof Error?a.message:String(a)})}break}case"figma_import":{let o=String(s.extractionId||""),i=String(s.themeName||"");if(!o||!i){t.send(JSON.stringify({type:"error",message:"Missing extractionId or themeName"}));break}let{getCachedExtraction:r}=await Promise.resolve().then(()=>(Gr(),$m)),a=r(o);if(!a){t.send(JSON.stringify({type:"error",message:"Extraction expired or not found. Please re-extract."}));break}try{let l=C();if(!l||l.themeName!==i){let{join:m}=await import("path"),{homedir:g}=await import("os"),{existsSync:h}=await import("fs"),{createThemeScaffold:f}=await Promise.resolve().then(()=>(Jn(),_a)),b=m(g(),"vibespot-themes"),S=m(b,i);if(!h(b)){let{mkdirSync:x}=await import("fs");x(b,{recursive:!0})}h(S)||f(S,i),pn(S,i),D()}Ee({type:"figma_import_started",fileName:a.fileName}),Mt();let c=[],d=[],u=await us(a,i,qr(c,d));qt(u,{steps:c,modules:d,stats:u.stats}),ke(),Gt(C().themePath,`Figma import: ${a.fileName}`),Ee({type:"generation_complete"});{let m=C();Ee({type:"modules_updated",modules:Se().map(g=>g.moduleName),templateId:m?.activeTemplateId||null,templates:(m?.templates||[]).map(g=>({id:g.id,label:g.label,pageType:g.pageType,moduleCount:g.modules.length}))})}Mt()}catch(l){Mt(),Ee({type:"error",message:l instanceof Error?l.message:String(l)})}break}case"extract_brand_assets":{let o=C();if(!o){t.send(JSON.stringify({type:"error",message:"No active session"}));break}(async()=>{try{let i=O(),{engine:r,apiKey:a,model:l}=vn(i),{buildPreviewHtml:c}=await Promise.resolve().then(()=>(es(),vo)),d=c();if(!d||d.length<50)return;let{extractThemeContext:u}=await Promise.resolve().then(()=>(Bo(),Jo)),m=await u(d,o.brandAssets?.themeContext,r,a,l),{mkdirSync:g,writeFileSync:h}=await import("fs");if(m){o.brandAssets||(o.brandAssets={}),o.brandAssets.themeContext=m,o.updatedAt=Date.now();let f=Et(o.themePath,".vibespot");vs(f)||g(f,{recursive:!0}),h(Et(f,"theme-context.md"),m),D(),t.send(JSON.stringify({type:"brand_asset_extracted",assetType:"themeContext"}))}if(!o.brandAssets?.styleguide)try{let{extractDesignContext:f}=await Promise.resolve().then(()=>(fs(),gs)),b=await f(o.themePath);if(b){o.brandAssets||(o.brandAssets={}),o.brandAssets.styleguide=b,o.updatedAt=Date.now();let S=Et(o.themePath,".vibespot");vs(S)||g(S,{recursive:!0}),h(Et(S,"styleguide.md"),b),D(),t.send(JSON.stringify({type:"brand_asset_extracted",assetType:"styleguide"}))}}catch{}t.send(JSON.stringify({type:"brand_extraction_complete"}))}catch(i){t.send(JSON.stringify({type:"brand_extraction_error",message:i instanceof Error?i.message:String(i)}))}})();break}case"start_upload":{let o=C();if(!o){t.send(JSON.stringify({type:"error",message:"No active session"}));break}try{ke();let i=Qs(o.themePath);if(i.length>0&&t.send(JSON.stringify({type:"upload_status",phase:"autofix",fixes:i})),(O().hubspotUploadMode||"api")==="api"){let l=Fe();if(!l){t.send(JSON.stringify({type:"upload_failed",output:"No HubSpot account configured. Open Settings \u2192 HubSpot to add one.",errors:[{file:"",message:"No HubSpot account configured",fixable:!1}]}));break}t.send(JSON.stringify({type:"upload_started",jobId:"api-upload"}));let c=await to(l,o.themePath,o.themeName,{onFileStart:d=>{t.send(JSON.stringify({type:"upload_output",chunk:`Uploading ${d}
2710
+ `}))},onFileComplete:d=>{t.send(JSON.stringify({type:"upload_output",chunk:` \u2713 ${d}
2711
+ `}))},onFileError:(d,u)=>{t.send(JSON.stringify({type:"upload_output",chunk:` \u2717 ${d}: ${u.message}
2712
+ `}))},onProgress:(d,u)=>{t.send(JSON.stringify({type:"upload_progress",completed:d,total:u}))}});if(c.success){let d=It();t.send(JSON.stringify({type:"upload_complete",output:`Uploaded ${c.uploaded} files`,portalId:d?.portalId||"",dataCenter:d?.dataCenter||"na1",themeName:o.themeName,contentMode:yn()}))}else{let d=Xs(c.errors);t.send(JSON.stringify({type:"upload_failed",output:c.errors.map(u=>`${u.file}: ${u.message}`).join(`
2713
+ `),errors:d}))}}else{let l=No(`hs cms upload "${o.themePath}" "${o.themeName}"`,"Uploading to HubSpot",{cwd:Et(o.themePath,".."),timeout:18e4});t.send(JSON.stringify({type:"upload_started",jobId:l}));let c=u=>{t.send(JSON.stringify({type:"upload_output",chunk:u}))};Jd(l,c);let d=setInterval(()=>{let u=Ro(l);if(!(!u||u.status==="running"))if(clearInterval(d),Bd(l,c),u.status==="completed"){let m=dt(),g=m.portalId?Rn(m.portalId):"na1";t.send(JSON.stringify({type:"upload_complete",output:u.output,portalId:m.portalId||"",dataCenter:g,themeName:o.themeName,contentMode:yn()}))}else{let m=Zs(u.output);t.send(JSON.stringify({type:"upload_failed",output:u.output,errors:m,exitCode:u.exitCode}))}},500)}}catch(i){t.send(JSON.stringify({type:"error",message:i instanceof Error?i.message:String(i)}))}break}case"upload_fix_with_ai":{let o=String(s.errorContext||"");if(!o.trim()){t.send(JSON.stringify({type:"error",message:"No error context provided"}));break}let i=`The HubSpot upload ("hs cms upload") failed. Below is the upload log output containing the errors.
1598
2714
 
1599
- `)};try{l({type:"progress",message:"Generating styleguide from design tokens..."});let c=jp(a),d=Ks(r.themePath,".vibespot");if(Rc(d)||Fc(d,{recursive:!0}),Op(Ks(d,"styleguide.md"),c),r.brandAssets||(r.brandAssets={}),r.brandAssets.styleguide=c,j(),l({type:"progress",message:"Styleguide saved."}),r.templates.length===0)bs("landing_page","Landing Page");else{r.modules=[],r.moduleOrder=[],r.sharedCss="",r.sharedJs="";let h=r.templates.find(b=>b.id===r.activeTemplateId);h&&(h.modules=[],h.moduleOrder=[],h.sharedCss="",h.sharedJs="")}if(j(),i&&a.assets.length>0){let h=Ks(r.themePath,"assets");Fc(h,{recursive:!0});let b=0;for(let x of a.assets)if(Rc(x.localPath)){let w=Ks(h,Fp(x.localPath));try{Rp(x.localPath,w),x.localPath=w,b++}catch{}}b>0&&l({type:"progress",message:`Copied ${b} image assets to theme.`})}l({type:"progress",message:"Starting AI conversion..."});let u=[],m=[],g=await $n(a,o,h=>{if(h.type==="agent_step")u.push({step:h.step,label:h.label}),l({type:"progress",message:`${h.label}...`});else if(h.type==="agent_decision"){let b=u[u.length-1];b&&(b.decisions||(b.decisions=[]),b.decisions.push(h.decision)),l({type:"progress",message:` ${h.decision}`})}else h.type==="design_system_ready"?oe({sharedCss:h.sharedCss,sharedJs:h.sharedJs}):h.type==="blueprint_ready"?(oe({sharedCss:h.sharedCss,sharedJs:h.sharedJs}),Ke(h.moduleOrder),l({type:"progress",message:`Planned ${h.moduleOrder.length} modules`})):h.type==="module_progress"&&(h.status==="generating"?l({type:"progress",message:`Generating module: ${h.module}`}):h.status==="complete"&&h.moduleFiles?(oe({modules:[{moduleName:h.module,fieldsJson:h.moduleFiles.fieldsJson,metaJson:h.moduleFiles.metaJson,moduleHtml:h.moduleFiles.moduleHtml,moduleCss:h.moduleFiles.moduleCss,moduleJs:h.moduleFiles.moduleJs}]}),m.push({name:h.module,status:"complete"}),l({type:"progress",message:`Module complete: ${h.module}`})):h.status==="failed"&&(m.push({name:h.module,status:"failed"}),l({type:"progress",message:`Module failed: ${h.module}`})))},{useAssets:i});At(g,{steps:u,modules:m,stats:g.stats}),_e(),St(r.themePath,`Figma import: ${a.fileName}`);let y=X().map(h=>h.moduleName);l({type:"progress",message:`Conversion complete \u2014 ${y.length} modules generated`}),l({type:"complete",ok:!0,modules:y})}catch(c){let d=c instanceof Error?c.message:String(c);A.error("figma",`Generate failed: ${d}`),l({type:"complete",ok:!1,error:d})}t.end()})}var Nn,Jp,Ti=L(()=>{"use strict";f();Fe();Q();ie();Mc();pe();pn();Po();jt();Tn();Dt();Nn=new Map,Jp=1800*1e3});f();f();import{Command as Yp}from"commander";f();f();f();import Et from"chalk";var De={accent:"#FF7A59",accentBright:"#FF9A7A",success:"#00BDA5",info:"#0066FF",warn:"#FFB020",error:"#E23D2D",muted:"#8B8D91",vibes:"#00BDD6"},Ni=!!process.env.NO_COLOR;function Qe(e){return Ni?Et:Et.hex(e)}var N={accent:Qe(De.accent),accentBright:Qe(De.accentBright),success:Qe(De.success),info:Qe(De.info),warn:Qe(De.warn),error:Qe(De.error),muted:Qe(De.muted),vibes:Qe(De.vibes),heading:Ni?Et.bold:Et.bold.hex(De.accent),command:Qe(De.accentBright),dim:Et.dim,bold:Et.bold};te();function He(){let e=N.vibes,t=N.accent,n=N.muted,s=[`${e("\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2584\u2584\u2584\u2584\u2584")}${e(" \u224B\u224B\u224B\u224B\u224B\u224B\u224B\u224B ")}${t("\u2584\u2584\u2584\u2584\u2584 \u2588\u2588\u2588\u2588\u2588 \u2584\u2584\u2584\u2584 \u2580\u2580\u2588\u2588\u2580\u2580")}`,`${e("\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}${e(" \u224B\u224B\u224B\u224B\u224B\u224B ")}${t("\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}`,`${e("\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588 ")}${e(" \u224B\u224B\u224B\u224B ")}${t("\u2580\u2580\u2580\u2584 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}`,`${e(" \u2588\u2584\u2584\u2588\u2580 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}${e(" \u224B\u224B\u224B\u224B\u224B\u224B ")}${t(" \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}`,`${e(" \u2580\u2580\u2580 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2580\u2580\u2580\u2580\u2580")}${e(" \u224B\u224B\u224B\u224B\u224B\u224B\u224B\u224B ")}${t("\u2580\u2580\u2580\u2580 \u2588\u2588 \u2580\u2580\u2580\u2580 \u2588\u2588 ")}`];console.log();for(let o of s)console.log(` ${o}`);console.log(),console.log(` ${n("AI-powered HubSpot Landing Pages")} ${N.dim(`v${Nt()}`)}`),console.log()}f();f();ht();Q();tt();import{join as Bn}from"path";import{homedir as Un}from"os";import{readFileSync as Hi,existsSync as Gn,readdirSync as rd}from"fs";var yt=process.platform==="win32"?"where":"which";function en(){let e=J("node --version");return{name:"Node.js",found:e.success,version:e.stdout.replace(/^v/,""),path:J(`${yt} node`).stdout}}function tn(){let e=J("git --version");return{name:"Git",found:e.success,version:e.stdout.replace("git version ",""),path:J(`${yt} git`).stdout}}function Be(){let e=J("hs --version");return{name:"HubSpot CLI",found:e.success,version:e.stdout,path:J(`${yt} hs`).stdout}}function nn(){let e=J("claude --version");if(!e.success)return{name:"Claude Code",found:!1,version:"",path:"",authenticated:!1,authDetail:"Not installed"};let t=Bn(Un(),".claude"),n=!1,s="Not signed in \u2014 run `claude` to authenticate";try{if(Gn(t)){let o=rd(t);(o.some(a=>a.includes("credentials")||a.includes("auth")||a.includes("token")||a===".credentials.json")||o.length>2)&&(n=!0,s="Authenticated")}}catch{}return{name:"Claude Code",found:!0,version:e.stdout,path:J(`${yt} claude`).stdout,authenticated:n,authDetail:s}}function sn(e){try{let t=Bn(Un(),".hscli","config.yml");if(!Gn(t))return"na1";let n=Hi(t,"utf-8"),s=n.indexOf(`accountId: ${e}`);if(s===-1)return"na1";let o=n.indexOf("personalAccessKey:",s);if(o===-1)return"na1";let a=n.slice(o,o+300).match(/personalAccessKey:[\s>-]*\n\s+(\S+)/);if(!a)return"na1";if(a[1].startsWith("CiRldTE"))return"eu1"}catch{}return"na1"}function Ue(){let e=J("hs accounts list");if(!e.success||!e.stdout)return{authenticated:!1,portalName:"",portalId:"",accounts:[]};let t=[],n="",s="",o=e.stdout.match(/Account:\s*(.+?)\s*\((\d+)\)/);o&&(n=o[1].trim(),s=o[2].trim());let i=e.stdout.split(`
1600
- `);for(let a of i){let r=a.match(/^\s*(.+?)\s+(\d{5,})\s+(.*)/);if(r&&!/Account ID/i.test(a)&&!/^-+$/.test(a.trim())&&!/^Name\s/i.test(a.trim())){let l=r[1].trim(),c=r[2].trim(),d=r[3]?.trim()||"unknown";t.push({name:l,portalId:c,authType:d,isDefault:c===s})}}return o?{authenticated:!0,portalName:n,portalId:s,accounts:t}:t.length>0?{authenticated:!0,portalName:t[0].name,portalId:t[0].portalId,accounts:t}:{authenticated:e.stdout.length>0,portalName:"",portalId:"",accounts:[]}}function on(){let e=J("gemini --version");if(!e.success)return{name:"Gemini CLI",found:!1,version:"",path:"",authenticated:!1,authDetail:"Not installed"};let t=Bn(Un(),".config","gcloud","application_default_credentials.json"),n=Gn(t),s=!!(process.env.GEMINI_API_KEY||process.env.GOOGLE_API_KEY||process.env.GOOGLE_AI_API_KEY),o=n||s;return{name:"Gemini CLI",found:!0,version:e.stdout,path:J(`${yt} gemini`).stdout,authenticated:o,authDetail:o?"Authenticated":"Run `gemini` to sign in with Google"}}function rn(){let e=J("codex --version");if(!e.success)return{name:"OpenAI Codex CLI",found:!1,version:"",path:"",authenticated:!1,authDetail:"Not installed"};let t=!!process.env.OPENAI_API_KEY,n=!1;try{let i=Bn(Un(),".codex","auth.json");Gn(i)&&(n=Hi(i,"utf-8").length>10)}catch{}let s=t||n,o=n?"Authenticated (OAuth)":t?"Authenticated (API key)":"Not authenticated";return{name:"OpenAI Codex CLI",found:!0,version:e.stdout,path:J(`${yt} codex`).stdout,authenticated:s,authDetail:o}}function io(){let e=J("gh --version");return{name:"GitHub CLI",found:e.success,version:e.stdout.split(`
1601
- `)[0]?.replace("gh version ","").split(" ")[0]||"",path:J(`${yt} gh`).stdout}}function ro(){let e=J("gh auth status 2>&1");if(!e.success&&!e.stdout)return{authenticated:!1,username:""};let t=e.stdout||e.stderr||"",n=t.match(/Logged in to github\.com.*account\s+(\S+)/);if(n)return{authenticated:!0,username:n[1]};let s=t.match(/account\s+(\S+)/);return s&&t.includes("Logged in")?{authenticated:!0,username:s[1]}:{authenticated:t.includes("Logged in"),username:""}}function Li(){return!!process.env.ANTHROPIC_API_KEY}function Wn(e){return parseInt(e.split(".")[0],10)>=18}function Bi(e){let t=parseInt(e.split(".")[0],10);return!isNaN(t)&&t>=8}function ad(){let e=P(),t=e.hubspotUploadMode||"api",n=e.hubspotAccounts||[],s=n.map(i=>({name:i.portalName,portalId:i.portalId,authType:"personalaccesskey",isDefault:i.portalId===(e.activeHubSpotAccount||n[0]?.portalId)})),o=ut();return{authenticated:!!o,portalName:o?.portalName||"",portalId:o?.portalId||"",dataCenter:o?o.dataCenter:"na1",accounts:s,uploadMode:t}}var oo={name:"",found:!1,version:"",path:"",authenticated:!1,authDetail:"Disabled"};function Vn(){let e=P(),t=en(),n=tn(),s=e.hubspotUploadMode||"api",o;if(s==="cli"){let x=Be(),w=x.found?Ue():{authenticated:!1,portalName:"",portalId:"",accounts:[]},S=w.portalId?sn(w.portalId):"na1";o={...x,...w,dataCenter:S,uploadMode:"cli"}}else o={name:"HubSpot API",found:!0,version:"v3",path:"",...ad()};let i=io(),a=i.found?ro():{authenticated:!1,username:""},r={authenticated:Le(),expiresAt:Qt()?.expiresAt},l=e.enabledCLITools||[],c=Xt("claude-code")?nn():{...oo,name:"Claude Code"},d=Xt("gemini-cli")?on():{...oo,name:"Gemini CLI"},u=Xt("codex-cli")?rn():{...oo,name:"OpenAI Codex CLI"};function m(x,...w){if(x)return{configured:!0,masked:jn(x),source:"config"};for(let S of w)if(process.env[S])return{configured:!0,masked:jn(process.env[S]),source:"env"};return{configured:!1,masked:"",source:null}}let g=m(e.anthropicApiKey,"ANTHROPIC_API_KEY"),y=m(e.openaiApiKey,"OPENAI_API_KEY"),h=m(e.geminiApiKey,"GEMINI_API_KEY","GOOGLE_AI_API_KEY"),b=[];return c.found&&c.authenticated&&b.push("claude-code"),r.authenticated&&b.push("claude-oauth"),g.configured&&b.push("anthropic-api"),y.configured&&b.push("openai-api"),d.found&&d.authenticated&&b.push("gemini-cli"),h.configured&&b.push("gemini-api"),u.found&&u.authenticated&&b.push("codex-cli"),{tools:{node:t,git:n,hubspot:o,github:{...i,...a},claudeCode:c,claudeOAuth:r,geminiCli:d,codexCli:u},apiKeys:{anthropic:g,openai:y,gemini:h},activeEngine:e.aiEngine||null,availableEngines:b,enabledCLITools:l}}tt();ht();Q();bt();f();import*as Y from"@clack/prompts";function lo(e){Y.isCancel(e)&&(Y.cancel(N.muted("Operation cancelled.")),process.exit(0))}async function ge(e){Y.intro(N.heading(e))}async function fe(e){Y.outro(N.success(e))}async function Ge(e,t){Y.note(e,t?N.heading(t):void 0)}async function Ne(e){let t=await Y.text({message:N.accent(e.message),placeholder:e.placeholder,defaultValue:e.defaultValue,validate:e.validate});return lo(t),t}async function le(e){let t=await Y.confirm({message:N.accent(e.message),initialValue:e.initialValue??!0});return lo(t),t}async function Rt(e){let t=await Y.select({message:N.accent(e.message),options:e.options});return lo(t),t}async function he(){let e=Y.spinner();return{start:t=>e.start(N.muted(t)),stop:t=>e.stop(N.success(t)),message:t=>e.message(N.muted(t))}}function ne(e){Y.log.info(e)}function U(e){Y.log.success(N.success(e))}function q(e){Y.log.warn(N.warn(e))}function V(e){Y.log.error(N.error(e))}async function qn(){await ge("Checking your environment");let e=en();e.found||(V("Node.js not found. Install it from https://nodejs.org"),process.exit(1)),Wn(e.version)||(V(`Node.js ${e.version} is too old. Version 18+ required. Update at https://nodejs.org`),process.exit(1)),U(`Node.js v${e.version}`);let t=tn();t.found||(V("Git not found. Install it from https://git-scm.com"),process.exit(1)),U(`Git ${t.version}`);let n=P(),s=n.hubspotUploadMode!=="cli",o="",i="";if(s){let b=Se(),x=ut();if(b)o=x?.portalId||"",i=x?.portalName||"",U(`HubSpot${i?`: ${i}`:""}${o?` (${o})`:""} \u2014 API mode`);else{q("No HubSpot account connected"),await Ge(`You need a Personal Access Key to deploy themes.
2715
+ IMPORTANT: Be verbose in your response. For each error:
2716
+ 1. State exactly which file has the problem and what the error is
2717
+ 2. Explain WHY this error occurs (e.g. "HubSpot doesn't support textarea field type" or "field name 'name' is reserved in HubSpot modules")
2718
+ 3. Describe the specific fix you're applying (e.g. "Changing field type from textarea to text" or "Renaming field from 'name' to 'item_name'")
2719
+ 4. Apply the fix to the module files
2720
+
2721
+ CRITICAL: After fixing the reported errors, scan ALL other module files in the theme for the same issues. For example, if you fix "name" \u2192 "item_name" in one module, check every other module's fields.json for the same problem. Fix all occurrences, not just the ones in the error log.
2722
+
2723
+ After fixing all errors, summarize the changes you made.
2724
+
2725
+ Upload log:
2726
+ ${o}`;tt("user",i),D(),t.send(JSON.stringify({type:"upload_fix_started"}));try{await ds(i,a=>{t.send(JSON.stringify({type:"stream",content:a})),t.send(JSON.stringify({type:"upload_fix_stream",content:a}))});let r=C();if(r){ke();let a=Gt(r.themePath,"AI fix: upload errors");a&&t.send(JSON.stringify({type:"version_created",hash:a}))}t.send(JSON.stringify({type:"upload_fix_complete"}));{let a=C();t.send(JSON.stringify({type:"modules_updated",modules:Se().map(l=>l.moduleName),templateId:a?.activeTemplateId||null,templates:(a?.templates||[]).map(l=>({id:l.id,label:l.label,pageType:l.pageType,moduleCount:l.modules.length}))}))}}catch(r){t.send(JSON.stringify({type:"upload_failed",output:r instanceof Error?r.message:String(r),errors:[{file:"AI fix",message:r instanceof Error?r.message:String(r),fixable:!1}]}))}break}case"ping":t.send(JSON.stringify({type:"pong"}));break;case"plan_approve":{let o=C();if(!o){t.send(JSON.stringify({type:"error",message:"No active session"}));break}let i=o.brandAssets?.plan;if(!i||!i.trim()){t.send(JSON.stringify({type:"error",message:"No plan to approve. Send a chat message first."}));break}Y({planMode:!1});let r="Implement the approved plan.";tt("user",r),D();try{Mt();let a=[],l=[],c=await Eo(r,qr(a,l));qt(c,{steps:a,modules:l,stats:c.stats});let d=C();if(d){ke();let u=Ce(),m=null;if(u){let g=u.moduleOrder.map(h=>`modules/${h}.module`);u.templateFile&&g.push(u.templateFile),u.sharedCss&&g.push(`css/${d.themeName}-theme.css`),u.sharedJs&&g.push(`js/${d.themeName}-animations.js`),m=_i(d.themePath,u.id,"Approved plan: implementation",g)}else m=Gt(d.themePath,"Approved plan: implementation");m&&Ee({type:"version_created",hash:m})}Ee({type:"generation_complete"});{let u=C();Ee({type:"modules_updated",modules:Se().map(m=>m.moduleName),templateId:u?.activeTemplateId||null,templates:(u?.templates||[]).map(m=>({id:m.id,label:m.label,pageType:m.pageType,moduleCount:m.modules.length}))})}Mt()}catch(a){Mt(),Ee({type:"error",message:a instanceof Error?a.message:String(a)})}break}case"plan_discard":{_r(),Y({planMode:!1}),t.send(JSON.stringify({type:"plan_discarded"}));break}default:t.send(JSON.stringify({type:"error",message:`Unknown type: ${s.type}`}))}}),ti=t;let e=C();if(e){let n=O(),s={"claude-code":"Claude Code","anthropic-api":"Anthropic API","claude-oauth":"Claude (OAuth)","openai-api":"OpenAI API","gemini-cli":"Gemini CLI","gemini-api":"Gemini API","codex-cli":"Codex CLI",api:"Anthropic API"},o=Ft(),i=Ce();if(t.send(JSON.stringify({type:"init",sessionId:e.id,themeName:e.themeName,modules:Se().map(r=>r.moduleName),messageCount:e.messages.length,messages:e.messages,gitAvailable:Qe(),engine:n.aiEngine?s[n.aiEngine]||n.aiEngine:"",updatedAt:e.updatedAt,templateId:i?.id||null,pageType:i?.pageType||null,templates:(e.templates||[]).map(r=>({id:r.id,label:r.label,pageType:r.pageType,moduleCount:r.modules.length})),planMode:!!n.planMode,plan:e.brandAssets?.plan||"",isGenerating:o})),o&&ni.length>0)for(let r of ni)t.send(JSON.stringify(r))}else t.send(JSON.stringify({type:"needs_setup"}))}function $b(t,e){let n=C();if(!n){e.writeHead(404,{"Content-Type":"text/plain"}),e.end("No session");return}let s=Et(n.themePath,"assets",t);if(!vs(s)){e.writeHead(404,{"Content-Type":"text/plain"}),e.end("Asset not found");return}let o=Bm(s),i=Hm[o]||"application/octet-stream",r=Xr(s);e.writeHead(200,{"Content-Type":i,"Cache-Control":"no-cache"}),e.end(r)}function Jm(t,e,n,s){let i=Et(e,t==="/"?"/index.html":t);if(!vs(i)){let c=Et(e,"index.html");if(vs(c)){let d=Xr(c);s.writeHead(200,{"Content-Type":"text/html","Cache-Control":"no-cache"}),s.end(d)}else s.writeHead(404,{"Content-Type":"text/plain"}),s.end("Not found");return}let r=Bm(i),a=Hm[r]||"application/octet-stream",l=r===".html";try{let c=Xr(i);s.writeHead(200,{"Content-Type":a,"Cache-Control":"no-store"}),s.end(c)}catch{s.writeHead(500,{"Content-Type":"text/plain"}),s.end("Internal Server Error")}}var Hm,ti,ni,Um,ts=R(()=>{"use strict";y();we();dn();es();wn();Fd();Dd();Q();Ht();eo();Oo();Ai();ze();ne();Wo();$u();Iu();ju();nm();mm();ir();Gr();Fm();Lm();Hm={".html":"text/html",".css":"text/css",".js":"application/javascript",".json":"application/json",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".webp":"image/webp",".gif":"image/gif",".ico":"image/x-icon",".woff2":"font/woff2"},ti=null,ni=[];Um="page"});y();y();import{Command as Jb}from"commander";y();y();at();ne();function Te(){let t=_.vibes,e=_.accent,n=_.muted,s=[`${t("\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2584\u2584\u2584\u2584\u2584")}${t(" \u224B\u224B\u224B\u224B\u224B\u224B\u224B\u224B ")}${e("\u2584\u2584\u2584\u2584\u2584 \u2588\u2588\u2588\u2588\u2588 \u2584\u2584\u2584\u2584 \u2580\u2580\u2588\u2588\u2580\u2580")}`,`${t("\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}${t(" \u224B\u224B\u224B\u224B\u224B\u224B ")}${e("\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}`,`${t("\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588 ")}${t(" \u224B\u224B\u224B\u224B ")}${e("\u2580\u2580\u2580\u2584 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}`,`${t(" \u2588\u2584\u2584\u2588\u2580 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}${t(" \u224B\u224B\u224B\u224B\u224B\u224B ")}${e(" \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588 ")}`,`${t(" \u2580\u2580\u2580 \u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2580\u2580\u2580\u2580\u2580")}${t(" \u224B\u224B\u224B\u224B\u224B\u224B\u224B\u224B ")}${e("\u2580\u2580\u2580\u2580 \u2588\u2588 \u2580\u2580\u2580\u2580 \u2588\u2588 ")}`];console.log();for(let o of s)console.log(` ${o}`);console.log(),console.log(` ${n("AI-powered HubSpot Landing Pages")} ${_.dim(`v${sn()}`)}`),console.log()}y();Ht();xt();Jt();Q();Ut();Ye();at();async function Ls(){await me("Checking your environment");let t=En();t.found||(z("Node.js not found. Install it from https://nodejs.org"),process.exit(1)),Ns(t.version)||(z(`Node.js ${t.version} is too old. Version 18+ required. Update at https://nodejs.org`),process.exit(1)),G(`Node.js v${t.version}`);let e=In();e.found||(z("Git not found. Install it from https://git-scm.com"),process.exit(1)),G(`Git ${e.version}`);let n=O(),s=n.hubspotUploadMode!=="cli",o="",i="";if(s){let b=Fe(),S=It();if(b)o=S?.portalId||"",i=S?.portalName||"",G(`HubSpot${i?`: ${i}`:""}${o?` (${o})`:""} \u2014 API mode`);else{ee("No HubSpot account connected"),await ut(`You need a Personal Access Key to deploy themes.
1602
2727
  Create one at: https://app.hubspot.com/l/personal-access-key
1603
- Make sure the Content scope is enabled.`,"HubSpot connection required");let w=await Ne({message:"Paste your Personal Access Key:",placeholder:"pat-na1-...",validate:M=>M.trim()?void 0:"Key is required"}),S=await he();S.start("Validating key...");try{let M=await zn(w);qt(w,M.portalId,M.portalName,M.dataCenter),b=w,o=M.portalId,i=M.portalName,S.stop(`Connected to ${M.portalName} (${M.portalId})`)}catch(M){S.stop("Validation failed"),V(`Invalid key: ${M instanceof Error?M.message:String(M)}`),process.exit(1)}}}else{let b=Be();if(b.found)U(`HubSpot CLI v${b.version}`);else{q("HubSpot CLI not found"),await le({message:"Install HubSpot CLI globally?"})||(V("HubSpot CLI is required in CLI mode. Install: npm install -g @hubspot/cli"),process.exit(1));let S=await he();S.start("Installing HubSpot CLI..."),J("npm install -g @hubspot/cli").success||(S.stop("Failed"),V("Try: npm install -g @hubspot/cli"),process.exit(1)),b=Be(),S.stop(`HubSpot CLI v${b.version} installed`)}let x=Ue();if(x.authenticated)U(`HubSpot portal${x.portalName?`: ${x.portalName}`:""} (ID: ${x.portalId})`);else{q("HubSpot not authenticated"),await le({message:"Run `hs init` now?"})||(V("Run `hs init` manually."),process.exit(1));let S=await he();S.start("Waiting for HubSpot authentication..."),Ri("hs init")||(S.stop("Authentication failed"),process.exit(1)),x=Ue(),S.stop(`Connected to portal${x.portalName?`: ${x.portalName}`:""} (ID: ${x.portalId})`)}o=x.portalId,i=x.portalName}let a=nn(),r=on(),l=rn(),c=Li(),d={"claude-code":"Claude Code",api:"Anthropic API","anthropic-api":"Anthropic API","claude-oauth":"Claude (OAuth)","openai-api":"OpenAI API","gemini-api":"Gemini API","gemini-cli":"Gemini CLI","codex-cli":"OpenAI Codex"},u=Le(),m,g=n.aiEngine,y=[];if(a.found&&y.push({value:"claude-code",label:"Claude Code",hint:g==="claude-code"?"last used \u2014 recommended":"uses your existing Claude subscription \u2014 recommended"}),u&&y.push({value:"claude-oauth",label:"Claude (OAuth)",hint:g==="claude-oauth"?"last used":"uses your Claude Pro/Max subscription via OAuth"}),r.found&&y.push({value:"gemini-cli",label:"Gemini CLI",hint:g==="gemini-cli"?"last used":"uses your existing Gemini setup"}),l.found&&y.push({value:"codex-cli",label:"OpenAI Codex",hint:g==="codex-cli"?"last used":"uses your existing OpenAI setup"}),c&&y.push({value:"api",label:"Anthropic API",hint:g==="api"?"last used":"uses your API key"}),g&&y.sort((b,x)=>b.value===g?-1:x.value===g?1:0),y.length===1)m=y[0].value,U(`AI engine: ${d[m]} (auto-detected)`);else if(y.length>1)m=await Rt({message:"Choose your AI engine:",options:y});else if(await Ge(`You need an AI coding assistant to power the conversion.
2728
+ Make sure the Content scope is enabled.`,"HubSpot connection required");let x=await be({message:"Paste your Personal Access Key:",placeholder:"pat-na1-...",validate:P=>P.trim()?void 0:"Key is required"}),w=await Pe();w.start("Validating key...");try{let P=await js(x);An(x,P.portalId,P.portalName,P.dataCenter),b=x,o=P.portalId,i=P.portalName,w.stop(`Connected to ${P.portalName} (${P.portalId})`)}catch(P){w.stop("Validation failed"),z(`Invalid key: ${P instanceof Error?P.message:String(P)}`),process.exit(1)}}}else{let b=ct();if(b.found)G(`HubSpot CLI v${b.version}`);else{ee("HubSpot CLI not found"),await Ae({message:"Install HubSpot CLI globally?"})||(z("HubSpot CLI is required in CLI mode. Install: npm install -g @hubspot/cli"),process.exit(1));let w=await Pe();w.start("Installing HubSpot CLI..."),te("npm install -g @hubspot/cli").success||(w.stop("Failed"),z("Try: npm install -g @hubspot/cli"),process.exit(1)),b=ct(),w.stop(`HubSpot CLI v${b.version} installed`)}let S=dt();if(S.authenticated)G(`HubSpot portal${S.portalName?`: ${S.portalName}`:""} (ID: ${S.portalId})`);else{ee("HubSpot not authenticated"),await Ae({message:"Run `hs init` now?"})||(z("Run `hs init` manually."),process.exit(1));let w=await Pe();w.start("Waiting for HubSpot authentication..."),da("hs init")||(w.stop("Authentication failed"),process.exit(1)),S=dt(),w.stop(`Connected to portal${S.portalName?`: ${S.portalName}`:""} (ID: ${S.portalId})`)}o=S.portalId,i=S.portalName}let r=Pn(),a=Nn(),l=On(),c=ha(),d={"claude-code":"Claude Code",api:"Anthropic API","anthropic-api":"Anthropic API","claude-oauth":"Claude (OAuth)","openai-api":"OpenAI API","gemini-api":"Gemini API","gemini-cli":"Gemini CLI","codex-cli":"OpenAI Codex"},u=lt(),m,g=n.aiEngine,h=[];if(r.found&&h.push({value:"claude-code",label:"Claude Code",hint:g==="claude-code"?"last used \u2014 recommended":"uses your existing Claude subscription \u2014 recommended"}),u&&h.push({value:"claude-oauth",label:"Claude (OAuth)",hint:g==="claude-oauth"?"last used":"uses your Claude Pro/Max subscription via OAuth"}),a.found&&h.push({value:"gemini-cli",label:"Gemini CLI",hint:g==="gemini-cli"?"last used":"uses your existing Gemini setup"}),l.found&&h.push({value:"codex-cli",label:"OpenAI Codex",hint:g==="codex-cli"?"last used":"uses your existing OpenAI setup"}),c&&h.push({value:"api",label:"Anthropic API",hint:g==="api"?"last used":"uses your API key"}),g&&h.sort((b,S)=>b.value===g?-1:S.value===g?1:0),h.length===1)m=h[0].value,G(`AI engine: ${d[m]} (auto-detected)`);else if(h.length>1)m=await wt({message:"Choose your AI engine:",options:h});else if(await ut(`You need an AI coding assistant to power the conversion.
1604
2729
 
1605
- ${N.bold("Option 1:")} Install Claude Code ${N.muted("(recommended)")}
2730
+ ${_.bold("Option 1:")} Install Claude Code ${_.muted("(recommended)")}
1606
2731
  https://claude.ai/code
1607
2732
 
1608
- ${N.bold("Option 2:")} Install Gemini CLI
2733
+ ${_.bold("Option 2:")} Install Gemini CLI
1609
2734
  https://github.com/google-gemini/gemini-cli
1610
2735
 
1611
- ${N.bold("Option 3:")} Install OpenAI Codex
2736
+ ${_.bold("Option 3:")} Install OpenAI Codex
1612
2737
  https://github.com/openai/codex
1613
2738
 
1614
- ${N.bold("Option 4:")} Set an Anthropic API key
2739
+ ${_.bold("Option 4:")} Set an Anthropic API key
1615
2740
  export ANTHROPIC_API_KEY=sk-ant-...
1616
- (get one at https://console.anthropic.com)`,"AI engine required"),m=await Rt({message:"Which will you set up?",options:[{value:"claude-code",label:"Claude Code",hint:"I'll install it now"},{value:"gemini-cli",label:"Gemini CLI",hint:"I'll install it now"},{value:"codex-cli",label:"OpenAI Codex",hint:"I'll install it now"},{value:"api",label:"Anthropic API",hint:"I'll enter my key"}]}),m==="api"){let b=await Ne({message:"Enter your Anthropic API key:",placeholder:"sk-ant-api03-...",validate:x=>x.startsWith("sk-ant-")?void 0:"Key should start with sk-ant-"});process.env.ANTHROPIC_API_KEY=b,W({anthropicApiKey:b})}let h;return m==="claude-code"&&(h=await Rt({message:"Which model?",options:[{value:"sonnet",label:"Sonnet",hint:"fast, recommended"},{value:"opus",label:"Opus",hint:"most capable"},{value:"haiku",label:"Haiku",hint:"fastest, cheapest"}]})),W({aiEngine:m}),await fe("Environment ready!"),{aiEngine:m,model:h,portalId:o,portalName:i}}f();ht();te();import{readdirSync as co,statSync as fd}from"fs";import{join as se,basename as uo,extname as hd}from"path";function zi(e){let t=[],n=[se(e,"src/components/landing"),se(e,"src/components/sections"),se(e,"src/components"),se(e,"src/pages"),se(e,"app/components"),se(e,"components")];for(let s of n)if(k(s))try{let o=co(s);for(let i of o){let a=se(s,i);if(!fd(a).isFile())continue;let l=hd(i);if(![".tsx",".jsx"].includes(l))continue;let c=uo(i,l);if(c.startsWith("ui")||c==="index")continue;let d=E(a),u=yd(c,d);t.push({name:c,path:a,description:u})}}catch{}return t}function yd(e,t){let n=[];return/carousel|slider|swiper|embla/i.test(t)&&n.push("carousel"),/accordion|collapsible|expand/i.test(t)&&n.push("accordion"),/form|submit|input.*email/i.test(t)&&n.push("form"),/nav|navigation|menu/i.test(t)&&n.push("navigation"),/hero|headline|tagline/i.test(t)&&n.push("hero"),/footer|copyright/i.test(t)&&n.push("footer"),/testimonial|quote|review/i.test(t)&&n.push("testimonials"),/pricing|plan|tier/i.test(t)&&n.push("pricing"),/faq|question.*answer/i.test(t)&&n.push("FAQ"),/feature|benefit|advantage/i.test(t)&&n.push("features"),/contact|get.in.touch/i.test(t)&&n.push("contact"),/cta|call.to.action/i.test(t)&&n.push("CTA"),/team|member|bio/i.test(t)&&n.push("team"),n.length===0?e.replace(/Section$/,"").replace(/([A-Z])/g," $1").trim():n.join(", ")}function Yi(e){let t=[se(e,"src/index.css"),se(e,"src/globals.css"),se(e,"src/app/globals.css"),se(e,"app/globals.css")],n=0,s=[];for(let o of t){if(!k(o))continue;let i=E(o),a=i.match(/--[\w-]+:/g);a&&(n+=a.length);let r=i.match(/font-family:\s*['"]([^'"]+)['"]/g);if(r)for(let c of r){let d=c.match(/['"]([^'"]+)['"]/)?.[1];d&&!s.includes(d)&&s.push(d)}let l=i.match(/@import\s+url\([^)]*fonts\.googleapis\.com[^)]*family=([^&)]+)/g);if(l)for(let c of l){let d=c.match(/family=([^&)]+)/)?.[1]?.replace(/\+/g," ");d&&!s.includes(d)&&s.push(d)}}return{varCount:n,fonts:s}}function qi(e){let t=[],n=se(e,"src/hooks");if(k(n))try{let o=co(n);for(let i of o)/scroll/i.test(i)&&t.push("Scroll animations"),/intersection/i.test(i)&&t.push("Scroll animations")}catch{}let s=se(e,"src/components/landing");if(k(s))try{let o=co(s);for(let i of o){if(!i.endsWith(".tsx")&&!i.endsWith(".jsx"))continue;let a=E(se(s,i));/carousel|embla|swiper/i.test(a)&&!t.includes("Carousel")&&t.push("Carousel"),/accordion|collapsible/i.test(a)&&!t.includes("Accordion")&&t.push("Accordion"),/typing|typewriter/i.test(a)&&!t.includes("Typing animation")&&t.push("Typing animation"),/parallax|requestAnimationFrame/i.test(a)&&!t.includes("Parallax")&&t.push("Parallax")}}catch{}return t.length===0&&t.push("Scroll animations"),t}function Xi(e){let t,n=!1;if(e.startsWith("http")||e.startsWith("git@")){n=!0;let l=uo(e.replace(/\.git$/,""))||"react-source";if(t=se(process.cwd(),"workspace",l),!k(t)){let c=J(`git clone --depth 1 "${e}" "${t}"`);if(!c.success)throw new Error(`Failed to clone ${e}: ${c.stderr}`)}}else if(t=e,!k(t))throw new Error(`Directory not found: ${t}`);let s=zi(t),o=k(se(t,"tailwind.config.ts"))||k(se(t,"tailwind.config.js")),{varCount:i,fonts:a}=Yi(t),r=qi(t);return{sourceDir:t,wasCloned:n,components:s,hasTailwind:o,cssVarCount:i,fonts:a,interactions:r}}async function Xn(){await ge("Source Project");let e=await Ne({message:"GitHub URL or local path to your React project:",placeholder:"https://github.com/user/my-lovable-page",validate:y=>{if(!y.trim())return"Please enter a URL or path"}}),t,n=!1;if(e.startsWith("http")||e.startsWith("git@")){n=!0;let y=uo(e.replace(/\.git$/,""))||"react-source";if(t=se(process.cwd(),"workspace",y),k(t))U(`Using existing clone: ${N.dim(t)}`);else{let h=await he();h.start("Cloning repository..."),J(`git clone --depth 1 "${e}" "${t}"`).success||(h.stop("Clone failed"),V(`Failed to clone ${e}. Check the URL and your access permissions.`),process.exit(1)),h.stop(`Cloned to ${N.dim(t)}`)}}else t=e,k(t)||(V(`Directory not found: ${t}`),process.exit(1)),U(`Using local source: ${N.dim(t)}`);let s=await he();s.start("Analyzing project structure...");let o=zi(t),i=k(se(t,"tailwind.config.ts"))||k(se(t,"tailwind.config.js")),{varCount:a,fonts:r}=Yi(t),l=qi(t);s.stop(`Found ${o.length} landing page components`),o.length===0&&(q("No components found. Make sure the React source has .tsx/.jsx files in src/components/"),process.exit(1));let c=o.map((y,h)=>` ${N.dim(`${h+1}.`)} ${N.bold(y.name)} ${N.muted(`\u2014 ${y.description}`)}`).join(`
1617
- `),d=i?`Tailwind + custom CSS (${a} variables)`:`Custom CSS (${a} variables)`,u=r.length>0?r.join(", "):"System fonts",m=l.join(", ");return await Ge(`${c}
1618
-
1619
- CSS: ${d}
1620
- JS: ${m}
1621
- Font: ${u}`,`${o.length} components detected`),await le({message:"Does this look right?"})||(V("Please adjust your source directory and try again."),process.exit(0)),await fe("Source analyzed!"),{sourceDir:t,wasCloned:n,components:o,hasTailwind:i,cssVarCount:a,fonts:r,interactions:l}}f();ht();te();import{join as un}from"path";Q();Qn();es();async function ts(){await ge("HubSpot Theme Setup");let e=await Rt({message:"Do you have an existing HubSpot theme?",options:[{value:"fetch",label:"Fetch my existing theme from HubSpot",hint:"downloads your current theme"},{value:"create",label:"Start fresh (HubSpot Boilerplate)",hint:"creates a new starter theme"}]}),t,n,s=un(process.cwd(),"workspace");if(Te(s),e==="fetch"){t=await Ne({message:"What's your theme name in HubSpot?",placeholder:"My-Company-Theme",validate:u=>u.trim()?void 0:"Theme name is required"}),n=un(s,t);let l=await he();l.start("Fetching theme from HubSpot...");let c=P(),d=Se();if(c.hubspotUploadMode==="cli"||!d)J(`hs cms fetch "${t}" "${n}"`).success||(l.stop("Fetch failed"),V(`Could not fetch theme "${t}". Check the name in HubSpot Design Manager.`),process.exit(1));else try{await dn(d,t,n)}catch(u){l.stop("Fetch failed"),V(`Could not fetch theme "${t}": ${u instanceof Error?u.message:String(u)}`),process.exit(1)}l.stop(`Theme fetched: ${N.dim(n)}`)}else{t=await Ne({message:"Name for your new theme:",placeholder:"my-theme",defaultValue:"my-theme"}),n=un(s,t);let l=await he();l.start("Creating theme...");try{cn(n,t)}catch(c){l.stop("Creation failed"),V(`Could not create theme "${t}": ${c instanceof Error?c.message:String(c)}`),process.exit(1)}l.stop(`Theme created: ${N.dim(n)}`)}await ge("Checking theme compatibility");let o=un(n,"templates/layouts/base.html");k(o)||(V(`base.html not found at ${o}. Your theme may have a different structure.`),process.exit(1)),U("base.html found");let i=E(o),a=!1;if(i.includes("template_css"))U("template_css support");else{q("Missing template_css support in base.html");let l=i.indexOf("theme-overrides.css")!==-1?i.indexOf("{{",i.lastIndexOf(`
2741
+ (get one at https://console.anthropic.com)`,"AI engine required"),m=await wt({message:"Which will you set up?",options:[{value:"claude-code",label:"Claude Code",hint:"I'll install it now"},{value:"gemini-cli",label:"Gemini CLI",hint:"I'll install it now"},{value:"codex-cli",label:"OpenAI Codex",hint:"I'll install it now"},{value:"api",label:"Anthropic API",hint:"I'll enter my key"}]}),m==="api"){let b=await be({message:"Enter your Anthropic API key:",placeholder:"sk-ant-api03-...",validate:S=>S.startsWith("sk-ant-")?void 0:"Key should start with sk-ant-"});process.env.ANTHROPIC_API_KEY=b,Y({anthropicApiKey:b})}let f;return m==="claude-code"&&(f=await wt({message:"Which model?",options:[{value:"sonnet",label:"Sonnet",hint:"fast, recommended"},{value:"opus",label:"Opus",hint:"most capable"},{value:"haiku",label:"Haiku",hint:"fastest, cheapest"}]})),Y({aiEngine:m}),await pe("Environment ready!"),{aiEngine:m,model:f,portalId:o,portalName:i}}Bs();y();Jt();ne();Ye();at();Q();Jn();Hs();import{join as Hn}from"path";async function Us(){await me("HubSpot Theme Setup");let t=await wt({message:"Do you have an existing HubSpot theme?",options:[{value:"fetch",label:"Fetch my existing theme from HubSpot",hint:"downloads your current theme"},{value:"create",label:"Start fresh (HubSpot Boilerplate)",hint:"creates a new starter theme"}]}),e,n,s=Hn(process.cwd(),"workspace");if(Ie(s),t==="fetch"){e=await be({message:"What's your theme name in HubSpot?",placeholder:"My-Company-Theme",validate:u=>u.trim()?void 0:"Theme name is required"}),n=Hn(s,e);let l=await Pe();l.start("Fetching theme from HubSpot...");let c=O(),d=Fe();if(c.hubspotUploadMode==="cli"||!d)te(`hs cms fetch "${e}" "${n}"`).success||(l.stop("Fetch failed"),z(`Could not fetch theme "${e}". Check the name in HubSpot Design Manager.`),process.exit(1));else try{await Bn(d,e,n)}catch(u){l.stop("Fetch failed"),z(`Could not fetch theme "${e}": ${u instanceof Error?u.message:String(u)}`),process.exit(1)}l.stop(`Theme fetched: ${_.dim(n)}`)}else{e=await be({message:"Name for your new theme:",placeholder:"my-theme",defaultValue:"my-theme"}),n=Hn(s,e);let l=await Pe();l.start("Creating theme...");try{Ln(n,e)}catch(c){l.stop("Creation failed"),z(`Could not create theme "${e}": ${c instanceof Error?c.message:String(c)}`),process.exit(1)}l.stop(`Theme created: ${_.dim(n)}`)}await me("Checking theme compatibility");let o=Hn(n,"templates/layouts/base.html");v(o)||(z(`base.html not found at ${o}. Your theme may have a different structure.`),process.exit(1)),G("base.html found");let i=M(o),r=!1;if(i.includes("template_css"))G("template_css support");else{ee("Missing template_css support in base.html");let l=i.indexOf("theme-overrides.css")!==-1?i.indexOf("{{",i.lastIndexOf(`
1622
2742
  `,i.indexOf("theme-overrides.css"))):i.lastIndexOf("require_css");if(l>0){let c=i.lastIndexOf(`
1623
2743
  `,l);i=i.slice(0,c)+`
1624
2744
  {% if template_css %}
1625
2745
  {{ require_css(get_asset_url(template_css)) }}
1626
- {% endif %}`+i.slice(c),a=!0}}if(i.includes("template_js"))U("template_js support");else{q("Missing template_js support in base.html");let l=i.indexOf("require_js");if(l>0){let c=i.indexOf(`
2746
+ {% endif %}`+i.slice(c),r=!0}}if(i.includes("template_js"))G("template_js support");else{ee("Missing template_js support in base.html");let l=i.indexOf("require_js");if(l>0){let c=i.indexOf(`
1627
2747
  `,l),d=i.indexOf(`
1628
2748
  `,c+1),u=`
1629
2749
  {% if template_js %}
@@ -1631,17 +2751,17 @@ ${N.bold("Option 4:")} Set an Anthropic API key
1631
2751
  {% endif %}`,m=i.indexOf("}}",l)+2+i.slice(i.indexOf("}}",l)+2).indexOf(`
1632
2752
  `)+1;i=i.slice(0,i.indexOf(`
1633
2753
  `,i.indexOf("}}",l)+2))+u+i.slice(i.indexOf(`
1634
- `,i.indexOf("}}",l)+2)),a=!0}}if(a){let l=await he();l.start("Patching base.html..."),G(o,i),l.stop("base.html patched with template_css/template_js support")}let r=un(n,".hsignore");if(k(r)){let l=E(r);l.includes("docs/")||(G(r,l+`
2754
+ `,i.indexOf("}}",l)+2)),r=!0}}if(r){let l=await Pe();l.start("Patching base.html..."),J(o,i),l.stop("base.html patched with template_css/template_js support")}let a=Hn(n,".hsignore");if(v(a)){let l=M(a);l.includes("docs/")||(J(a,l+`
1635
2755
  docs/
1636
- `),U("Added docs/ to .hsignore"))}else G(r,`docs/
2756
+ `),G("Added docs/ to .hsignore"))}else J(a,`docs/
1637
2757
  *.md
1638
2758
  node_modules/
1639
2759
  .git
1640
- `),U("Created .hsignore");return await fe("Theme ready!"),{themePath:n,themeName:t}}f();import{join as Ie}from"path";import{readdirSync as mn,rmSync as cr}from"fs";f();ot();te();import{spawn as wd}from"child_process";import{join as K,basename as Cd}from"path";import{readdirSync as We,statSync as ar,writeFileSync as kd}from"fs";var Ad=new Set(["about.html","blog-index.html","blog-post.html","contact.html","home.html","hubdb.html","landing-page.html","pricing.html","qa-test.html","base.html"]),ns=class{model;reported=new Set;moduleCount=0;expectedModules=0;constructor(t){this.model=t}async convert(t){let{sourceDir:n,themePath:s,onProgress:o}=t,i=t.conversionGuide||ce();this.reported.clear(),this.moduleCount=0,this.expectedModules=0;let a=this.countSourceComponents(n),r=this.listModules(s),l=this.listDir(K(s,"css")),c=this.listDir(K(s,"js")),d=this.listDir(K(s,"templates")),u=this.buildFullPrompt(n,s,i);o("convert",`Starting Claude Code (${a} source components found)...`);let m="",g="",y=setInterval(()=>{this.reportProgress(s,r,l,c,d,o)},3e3);try{await new Promise((w,S)=>{let M={...process.env};delete M.CLAUDECODE;let O=["--print","--max-turns","50","--allowedTools","Read,Glob,Grep,Write,Edit,Bash"];this.model&&O.push("--model",this.model);let R=wd("claude",O,{cwd:s,stdio:["pipe","pipe","pipe"],env:M,shell:!0});R.stdout.on("data",H=>{m+=H.toString()}),R.stderr.on("data",H=>{g+=H.toString()}),R.on("error",H=>S(new Error(`Claude Code failed to start: ${H.message}`))),R.on("close",H=>{H!==0?S(new Error(`Claude Code exited with code ${H}.
2760
+ `),G("Created .hsignore");return await pe("Theme ready!"),{themePath:n,themeName:e}}y();import{join as qe}from"path";import{readdirSync as Gn,rmSync as Ba}from"fs";y();Ue();ne();import{spawn as Pp}from"child_process";import{join as Z,basename as Rp}from"path";import{readdirSync as mt,statSync as La,writeFileSync as Np}from"fs";var Op=new Set(["about.html","blog-index.html","blog-post.html","contact.html","home.html","hubdb.html","landing-page.html","pricing.html","qa-test.html","base.html"]),Gs=class{model;reported=new Set;moduleCount=0;expectedModules=0;constructor(e){this.model=e}async convert(e){let{sourceDir:n,themePath:s,onProgress:o}=e,i=e.conversionGuide||fe();this.reported.clear(),this.moduleCount=0,this.expectedModules=0;let r=this.countSourceComponents(n),a=this.listModules(s),l=this.listDir(Z(s,"css")),c=this.listDir(Z(s,"js")),d=this.listDir(Z(s,"templates")),u=this.buildFullPrompt(n,s,i);o("convert",`Starting Claude Code (${r} source components found)...`);let m="",g="",h=setInterval(()=>{this.reportProgress(s,a,l,c,d,o)},3e3);try{await new Promise((x,w)=>{let P={...process.env};delete P.CLAUDECODE;let F=["--print","--max-turns","50","--allowedTools","Read,Glob,Grep,Write,Edit,Bash"];this.model&&F.push("--model",this.model);let H=Pp("claude",F,{cwd:s,stdio:["pipe","pipe","pipe"],env:P,shell:!0});H.stdout.on("data",L=>{m+=L.toString()}),H.stderr.on("data",L=>{g+=L.toString()}),H.on("error",L=>w(new Error(`Claude Code failed to start: ${L.message}`))),H.on("close",L=>{L!==0?w(new Error(`Claude Code exited with code ${L}.
1641
2761
  `+(g?`Stderr: ${g.slice(0,500)}
1642
- `:"")+(m?`Output: ${m.slice(0,500)}`:"No output"))):w()}),R.stdin.on("error",()=>{}),R.stdin.write(u),R.stdin.end(),setTimeout(()=>{R.kill(),S(new Error("Claude Code timed out after 30 minutes"))},18e5)})}finally{clearInterval(y)}let h=K(s,"..","vibespot-conversion.log");try{let S=["=== vibeSpot Conversion Log ===",`Timestamp: ${new Date().toISOString()}`,`Source: ${n}`,`Theme: ${s}`,`Model: ${this.model||"default"}`,"","=== PROMPT SENT ===",u.slice(0,500)+`
2762
+ `:"")+(m?`Output: ${m.slice(0,500)}`:"No output"))):x()}),H.stdin.on("error",()=>{}),H.stdin.write(u),H.stdin.end(),setTimeout(()=>{H.kill(),w(new Error("Claude Code timed out after 30 minutes"))},18e5)})}finally{clearInterval(h)}let f=Z(s,"..","vibespot-conversion.log");try{let w=["=== vibeSpot Conversion Log ===",`Timestamp: ${new Date().toISOString()}`,`Source: ${n}`,`Theme: ${s}`,`Model: ${this.model||"default"}`,"","=== PROMPT SENT ===",u.slice(0,500)+`
1643
2763
  ... (truncated, full guide follows)`,"","=== CLAUDE CODE STDOUT ===",m||"(empty)","","=== CLAUDE CODE STDERR ===",g||"(empty)",""].join(`
1644
- `);kd(h,S,"utf-8"),o("status",`Log written to ${Cd(h)}`)}catch{}o("scan","Scanning generated files...");let b=this.scanGeneratedFiles(s);if(b.modules.filter(w=>!r.has(w.moduleName+".module")).length===0){let w=m.slice(0,1500)||"(no output)",S=g.slice(0,500);throw new Error(`Claude Code did not create any new module files.
2764
+ `);Np(f,w,"utf-8"),o("status",`Log written to ${Rp(f)}`)}catch{}o("scan","Scanning generated files...");let b=this.scanGeneratedFiles(s);if(b.modules.filter(x=>!a.has(x.moduleName+".module")).length===0){let x=m.slice(0,1500)||"(no output)",w=g.slice(0,500);throw new Error(`Claude Code did not create any new module files.
1645
2765
 
1646
2766
  This usually means the model described the conversion instead of using Write tool to create files.
1647
2767
 
@@ -1650,23 +2770,23 @@ Possible causes:
1650
2770
  - Claude Code hit a rate limit or API error
1651
2771
  - The source directory was not accessible
1652
2772
 
1653
- Source: ${t.sourceDir}
2773
+ Source: ${e.sourceDir}
1654
2774
  Theme: ${s}
1655
- `+(S?`
2775
+ `+(w?`
1656
2776
  Stderr:
1657
- ${S}
2777
+ ${w}
1658
2778
  `:"")+`
1659
2779
  Claude output:
1660
- ${w}`)}return b}reportProgress(t,n,s,o,i,a){let r=0,l=this.listDir(K(t,"css"));for(let m of l){if(s.has(m)||!m.endsWith(".css"))continue;let g=`css:${m}`;this.reported.has(g)||(this.reported.add(g),a("created",`Shared CSS (${m})`),r++)}let c=this.listDir(K(t,"js"));for(let m of c){if(o.has(m)||!m.endsWith(".js"))continue;let g=`js:${m}`;this.reported.has(g)||(this.reported.add(g),a("created",`Shared JS (${m})`),r++)}this.expectedModules===0&&(this.expectedModules=this.detectExpectedModules(t,i));let d=this.listModules(t);for(let m of d){if(n.has(m))continue;let g=`module:${m}`;if(!this.reported.has(g)){this.reported.add(g),this.moduleCount++;let y=this.expectedModules>0?`[${this.moduleCount}/${this.expectedModules}]`:`[${this.moduleCount}]`;a("created",`Module ${y}: ${m.replace(".module","")}`),r++}}let u=this.listDir(K(t,"templates"));for(let m of u){if(i.has(m)||!m.endsWith(".html"))continue;let g=`template:${m}`;this.reported.has(g)||(this.reported.add(g),a("created",`Page template (${m})`),r++)}if(r===0)if(this.moduleCount>0){let m=this.expectedModules>0?`/${this.expectedModules}`:"";a("status",`${this.moduleCount}${m} modules created, conversion continuing...`)}else this.reported.size>0?a("status","Shared assets created, building modules..."):a("status","Claude Code is analyzing source files...")}buildFullPrompt(t,n,s){return`You are converting a React landing page to native HubSpot CMS modules.
2780
+ ${x}`)}return b}reportProgress(e,n,s,o,i,r){let a=0,l=this.listDir(Z(e,"css"));for(let m of l){if(s.has(m)||!m.endsWith(".css"))continue;let g=`css:${m}`;this.reported.has(g)||(this.reported.add(g),r("created",`Shared CSS (${m})`),a++)}let c=this.listDir(Z(e,"js"));for(let m of c){if(o.has(m)||!m.endsWith(".js"))continue;let g=`js:${m}`;this.reported.has(g)||(this.reported.add(g),r("created",`Shared JS (${m})`),a++)}this.expectedModules===0&&(this.expectedModules=this.detectExpectedModules(e,i));let d=this.listModules(e);for(let m of d){if(n.has(m))continue;let g=`module:${m}`;if(!this.reported.has(g)){this.reported.add(g),this.moduleCount++;let h=this.expectedModules>0?`[${this.moduleCount}/${this.expectedModules}]`:`[${this.moduleCount}]`;r("created",`Module ${h}: ${m.replace(".module","")}`),a++}}let u=this.listDir(Z(e,"templates"));for(let m of u){if(i.has(m)||!m.endsWith(".html"))continue;let g=`template:${m}`;this.reported.has(g)||(this.reported.add(g),r("created",`Page template (${m})`),a++)}if(a===0)if(this.moduleCount>0){let m=this.expectedModules>0?`/${this.expectedModules}`:"";r("status",`${this.moduleCount}${m} modules created, conversion continuing...`)}else this.reported.size>0?r("status","Shared assets created, building modules..."):r("status","Claude Code is analyzing source files...")}buildFullPrompt(e,n,s){return`You are converting a React landing page to native HubSpot CMS modules.
1661
2781
 
1662
- SOURCE DIRECTORY: ${t}
2782
+ SOURCE DIRECTORY: ${e}
1663
2783
  THEME DIRECTORY: ${n}
1664
2784
 
1665
2785
  IMPORTANT \u2014 YOU MUST CREATE REAL FILES:
1666
2786
  You have access to Write, Edit, Read, Glob, Grep, and Bash tools. You MUST use the Write tool to create each file. Do NOT just describe or list what files should be created \u2014 actually call the Write tool for every single file. If you do not call Write, no files will be created and the conversion will fail.
1667
2787
 
1668
2788
  STEP-BY-STEP PROCESS:
1669
- 1. Use Glob to find all .tsx/.jsx files in ${t}/src/
2789
+ 1. Use Glob to find all .tsx/.jsx files in ${e}/src/
1670
2790
  2. Use Read to read each component file and understand the page structure
1671
2791
  3. Use Write to create a shared CSS file at ${n}/css/<name>-theme.css
1672
2792
  - Include CSS custom properties, design system variables, utility classes
@@ -1700,16 +2820,16 @@ CSS QUALITY: The converted page must visually match the original React page. Eve
1700
2820
  Do NOT run hs upload \u2014 I will handle that separately.
1701
2821
 
1702
2822
  HUBSPOT CMS RULES:
1703
- ${Me()}
2823
+ ${je()}
1704
2824
 
1705
2825
  CONVERSION GUIDE:
1706
- ${s}`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=K(t,"css");if(k(s)){for(let r of We(s))if(r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=E(K(s,r));break}}let o=K(t,"js");if(k(o)){for(let r of We(o))if(r.endsWith(".js")&&r!=="main.js"){n.sharedJs=E(K(o,r));break}}let i=K(t,"templates");if(k(i)){for(let r of We(i))if(r.startsWith("lp-")&&r.endsWith(".html")){n.template=E(K(i,r));break}if(!n.template){for(let r of We(i))if(r.endsWith(".html")&&!Ad.has(r)&&!r.startsWith("system")){let l=E(K(i,r));if(l.includes("dnd_area")){n.template=l;break}}}if(!n.template){for(let r of We(i))if(r.endsWith(".html")&&!r.startsWith("system")&&r!=="base.html"){let l=E(K(i,r));if(l.includes("dnd_area")){n.template=l;break}}}}let a=K(t,"modules");if(k(a))for(let r of We(a)){if(!r.endsWith(".module"))continue;let l=K(a,r);if(!ar(l).isDirectory())continue;let c={moduleName:r.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=K(l,"fields.json");k(d)&&(c.fieldsJson=E(d));let u=K(l,"meta.json");k(u)&&(c.metaJson=E(u));let m=K(l,"module.html");k(m)&&(c.moduleHtml=E(m));let g=K(l,"module.css");k(g)&&(c.moduleCss=E(g));let y=K(l,"module.js");k(y)&&(c.moduleJs=E(y)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}listModules(t){let n=K(t,"modules");return k(n)?new Set(We(n).filter(s=>s.endsWith(".module"))):new Set}listDir(t){return k(t)?new Set(We(t)):new Set}detectExpectedModules(t,n){let s=K(t,"templates");if(!k(s))return 0;for(let o of We(s))if(!n.has(o)&&!(!o.endsWith(".html")||o==="base.html"||o.startsWith("system")))try{let i=E(K(s,o));if(i.includes("dnd_area")){let a=i.match(/dnd_module/g);return a?a.length:0}}catch{}return 0}countSourceComponents(t){let n=K(t,"src");return k(n)?this.countComponentsRecursive(n):0}countComponentsRecursive(t){let n=0;for(let s of We(t)){let o=K(t,s);try{ar(o).isDirectory()&&s!=="node_modules"&&s!==".git"?n+=this.countComponentsRecursive(o):/\.(tsx|jsx)$/.test(s)&&!s.includes(".test.")&&!s.includes(".spec.")&&n++}catch{}}return n}};f();ot();te();import $d from"@anthropic-ai/sdk";import{join as ee,basename as Td}from"path";import{readdirSync as lr}from"fs";var ss=class{client;model="claude-sonnet-4-6";constructor(t){this.client=new $d({apiKey:t||process.env.ANTHROPIC_API_KEY})}async convert(t){let{sourceDir:n,themePath:s,conversionGuide:o,onProgress:i}=t,a=nr(o),r=Td(n)||"page",l=r.toLowerCase().replace(/[^a-z0-9]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").slice(0,15);i("css","Analyzing design system...");let c=this.findAndReadCSS(n),d=this.findAndReadTailwind(n),u=await this.complete(a,or(c,d,l)),m=ee(s,"css",`${l}-theme.css`);G(m,u),i("css-done",`Created css/${l}-theme.css`),i("js","Creating shared JavaScript...");let g=this.findAndReadHooks(n),y=this.findInteractiveComponents(n),h=await this.complete(a,ir(g,y,l)),b=ee(s,"js",`${l}-animations.js`);G(b,h),i("js-done",`Created js/${l}-animations.js`),i("modules","Building modules...");let x=this.findComponents(n),w=[];for(let R=0;R<x.length;R++){let H=x[R],z=H.name.replace(/Section$/,"").replace(/([A-Z])/g," $1").trim();i("module",`Building ${z}.module (${R+1}/${x.length})...`);let _=E(H.path),F=await this.complete(a,sr(_,z,`See css/${l}-theme.css`));try{let C=JSON.parse(F),I={moduleName:z,fieldsJson:typeof C.fieldsJson=="string"?C.fieldsJson:JSON.stringify(C.fieldsJson,null,2),metaJson:typeof C.metaJson=="string"?C.metaJson:JSON.stringify(C.metaJson,null,2),moduleHtml:C.moduleHtml||"",moduleCss:C.moduleCss||"",moduleJs:C.moduleJs||void 0},Z=ee(s,"modules",`${z}.module`);Te(Z),G(ee(Z,"fields.json"),I.fieldsJson),G(ee(Z,"meta.json"),I.metaJson),G(ee(Z,"module.html"),I.moduleHtml),G(ee(Z,"module.css"),I.moduleCss),I.moduleJs&&G(ee(Z,"module.js"),I.moduleJs),w.push(I),i("module-done",`${z}.module (${this.countFiles(I)} files)`)}catch{i("module-error",`Failed to parse ${z} \u2014 skipping`)}}i("template","Creating page template...");let S=w.map(R=>R.moduleName),M=await this.complete(a,rr(S,r,l)),O=ee(s,"templates",`lp-${l}.html`);return G(O,M),i("template-done",`Created templates/lp-${l}.html`),{sharedCss:u,sharedJs:h,template:M,modules:w}}async complete(t,n){return(await this.client.messages.create({model:this.model,max_tokens:8192,system:[{type:"text",text:t,cache_control:{type:"ephemeral"}}],messages:[{role:"user",content:n}]})).content.find(i=>i.type==="text")?.text||""}findAndReadCSS(t){let n=[ee(t,"src/index.css"),ee(t,"src/globals.css"),ee(t,"src/app/globals.css"),ee(t,"app/globals.css")];for(let s of n)if(k(s))return E(s);return""}findAndReadTailwind(t){let n=[ee(t,"tailwind.config.ts"),ee(t,"tailwind.config.js"),ee(t,"tailwind.config.mjs")];for(let s of n)if(k(s))return E(s);return""}findAndReadHooks(t){let n=ee(t,"src/hooks");if(!k(n))return"";try{return lr(n).filter(s=>s.endsWith(".ts")||s.endsWith(".tsx")).map(s=>`// ${s}
1707
- ${E(ee(n,s))}`).join(`
2826
+ ${s}`}scanGeneratedFiles(e){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=Z(e,"css");if(v(s)){for(let a of mt(s))if(a.endsWith(".css")&&a!=="theme-overrides.css"&&a!=="main.css"&&a!=="style.css"){n.sharedCss=M(Z(s,a));break}}let o=Z(e,"js");if(v(o)){for(let a of mt(o))if(a.endsWith(".js")&&a!=="main.js"){n.sharedJs=M(Z(o,a));break}}let i=Z(e,"templates");if(v(i)){for(let a of mt(i))if(a.startsWith("lp-")&&a.endsWith(".html")){n.template=M(Z(i,a));break}if(!n.template){for(let a of mt(i))if(a.endsWith(".html")&&!Op.has(a)&&!a.startsWith("system")){let l=M(Z(i,a));if(l.includes("dnd_area")){n.template=l;break}}}if(!n.template){for(let a of mt(i))if(a.endsWith(".html")&&!a.startsWith("system")&&a!=="base.html"){let l=M(Z(i,a));if(l.includes("dnd_area")){n.template=l;break}}}}let r=Z(e,"modules");if(v(r))for(let a of mt(r)){if(!a.endsWith(".module"))continue;let l=Z(r,a);if(!La(l).isDirectory())continue;let c={moduleName:a.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=Z(l,"fields.json");v(d)&&(c.fieldsJson=M(d));let u=Z(l,"meta.json");v(u)&&(c.metaJson=M(u));let m=Z(l,"module.html");v(m)&&(c.moduleHtml=M(m));let g=Z(l,"module.css");v(g)&&(c.moduleCss=M(g));let h=Z(l,"module.js");v(h)&&(c.moduleJs=M(h)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}listModules(e){let n=Z(e,"modules");return v(n)?new Set(mt(n).filter(s=>s.endsWith(".module"))):new Set}listDir(e){return v(e)?new Set(mt(e)):new Set}detectExpectedModules(e,n){let s=Z(e,"templates");if(!v(s))return 0;for(let o of mt(s))if(!n.has(o)&&!(!o.endsWith(".html")||o==="base.html"||o.startsWith("system")))try{let i=M(Z(s,o));if(i.includes("dnd_area")){let r=i.match(/dnd_module/g);return r?r.length:0}}catch{}return 0}countSourceComponents(e){let n=Z(e,"src");return v(n)?this.countComponentsRecursive(n):0}countComponentsRecursive(e){let n=0;for(let s of mt(e)){let o=Z(e,s);try{La(o).isDirectory()&&s!=="node_modules"&&s!==".git"?n+=this.countComponentsRecursive(o):/\.(tsx|jsx)$/.test(s)&&!s.includes(".test.")&&!s.includes(".spec.")&&n++}catch{}}return n}};y();Ue();ne();import Fp from"@anthropic-ai/sdk";import{join as re,basename as jp}from"path";import{readdirSync as Ja}from"fs";var Ws=class{client;model="claude-sonnet-4-6";constructor(e){this.client=new Fp({apiKey:e||process.env.ANTHROPIC_API_KEY})}async convert(e){let{sourceDir:n,themePath:s,conversionGuide:o,onProgress:i}=e,r=Na(o),a=jp(n)||"page",l=a.toLowerCase().replace(/[^a-z0-9]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").slice(0,15);i("css","Analyzing design system...");let c=this.findAndReadCSS(n),d=this.findAndReadTailwind(n),u=await this.complete(r,Fa(c,d,l)),m=re(s,"css",`${l}-theme.css`);J(m,u),i("css-done",`Created css/${l}-theme.css`),i("js","Creating shared JavaScript...");let g=this.findAndReadHooks(n),h=this.findInteractiveComponents(n),f=await this.complete(r,ja(g,h,l)),b=re(s,"js",`${l}-animations.js`);J(b,f),i("js-done",`Created js/${l}-animations.js`),i("modules","Building modules...");let S=this.findComponents(n),x=[];for(let H=0;H<S.length;H++){let L=S[H],V=L.name.replace(/Section$/,"").replace(/([A-Z])/g," $1").trim();i("module",`Building ${V}.module (${H+1}/${S.length})...`);let B=M(L.path),N=await this.complete(r,Oa(B,V,`See css/${l}-theme.css`));try{let T=JSON.parse(N),I={moduleName:V,fieldsJson:typeof T.fieldsJson=="string"?T.fieldsJson:JSON.stringify(T.fieldsJson,null,2),metaJson:typeof T.metaJson=="string"?T.metaJson:JSON.stringify(T.metaJson,null,2),moduleHtml:T.moduleHtml||"",moduleCss:T.moduleCss||"",moduleJs:T.moduleJs||void 0},k=re(s,"modules",`${V}.module`);Ie(k),J(re(k,"fields.json"),I.fieldsJson),J(re(k,"meta.json"),I.metaJson),J(re(k,"module.html"),I.moduleHtml),J(re(k,"module.css"),I.moduleCss),I.moduleJs&&J(re(k,"module.js"),I.moduleJs),x.push(I),i("module-done",`${V}.module (${this.countFiles(I)} files)`)}catch{i("module-error",`Failed to parse ${V} \u2014 skipping`)}}i("template","Creating page template...");let w=x.map(H=>H.moduleName),P=await this.complete(r,Da(w,a,l)),F=re(s,"templates",`lp-${l}.html`);return J(F,P),i("template-done",`Created templates/lp-${l}.html`),{sharedCss:u,sharedJs:f,template:P,modules:x}}async complete(e,n){return(await this.client.messages.create({model:this.model,max_tokens:8192,system:[{type:"text",text:e,cache_control:{type:"ephemeral"}}],messages:[{role:"user",content:n}]})).content.find(i=>i.type==="text")?.text||""}findAndReadCSS(e){let n=[re(e,"src/index.css"),re(e,"src/globals.css"),re(e,"src/app/globals.css"),re(e,"app/globals.css")];for(let s of n)if(v(s))return M(s);return""}findAndReadTailwind(e){let n=[re(e,"tailwind.config.ts"),re(e,"tailwind.config.js"),re(e,"tailwind.config.mjs")];for(let s of n)if(v(s))return M(s);return""}findAndReadHooks(e){let n=re(e,"src/hooks");if(!v(n))return"";try{return Ja(n).filter(s=>s.endsWith(".ts")||s.endsWith(".tsx")).map(s=>`// ${s}
2827
+ ${M(re(n,s))}`).join(`
1708
2828
 
1709
- `)}catch{return""}}findInteractiveComponents(t){let n=this.findComponents(t),s=[];for(let o of n){let i=E(o.path);/carousel|accordion|typing|parallax|embla|swiper|collapsible/i.test(i)&&s.push(`// ${o.name}
2829
+ `)}catch{return""}}findInteractiveComponents(e){let n=this.findComponents(e),s=[];for(let o of n){let i=M(o.path);/carousel|accordion|typing|parallax|embla|swiper|collapsible/i.test(i)&&s.push(`// ${o.name}
1710
2830
  ${i}`)}return s.join(`
1711
2831
 
1712
- `)}findComponents(t){let n=[ee(t,"src/components/landing"),ee(t,"src/components/sections"),ee(t,"src/components")];for(let s of n)if(k(s))try{return lr(s).filter(o=>(o.endsWith(".tsx")||o.endsWith(".jsx"))&&!o.startsWith("ui")&&o!=="index.tsx"&&o!=="index.jsx").map(o=>({name:o.replace(/\.(tsx|jsx)$/,""),path:ee(s,o)}))}catch{continue}return[]}countFiles(t){let n=3;return t.moduleCss&&n++,t.moduleJs&&n++,n}};f();ot();te();import{spawn as Id}from"child_process";import{join as Ae}from"path";import{readdirSync as os,statSync as Ed}from"fs";var is=class{async convert(t){let{sourceDir:n,themePath:s,onProgress:o}=t,i=t.conversionGuide||ce(),a=this.buildFullPrompt(n,s,i);return o("convert","Running Gemini CLI (this may take a few minutes)..."),await new Promise((r,l)=>{let c=Id("gemini",["-p",a],{cwd:s,stdio:["pipe","pipe","pipe"],env:{...process.env},shell:!0}),d="",u="";c.stdout.on("data",m=>{d+=m.toString()}),c.stderr.on("data",m=>{u+=m.toString()}),c.on("error",m=>l(new Error(`Gemini CLI failed: ${m.message}`))),c.on("close",m=>{m!==0&&u&&!d?l(new Error(`Gemini CLI failed: ${u}`)):r()}),setTimeout(()=>{c.kill(),l(new Error("Gemini CLI timed out after 10 minutes"))},6e5)}),o("scan","Scanning generated files..."),this.scanGeneratedFiles(s)}buildFullPrompt(t,n,s){return`Read the conversion guide below, then convert the React landing page at ${t} into native HubSpot CMS modules for the theme at ${n}.
2832
+ `)}findComponents(e){let n=[re(e,"src/components/landing"),re(e,"src/components/sections"),re(e,"src/components")];for(let s of n)if(v(s))try{return Ja(s).filter(o=>(o.endsWith(".tsx")||o.endsWith(".jsx"))&&!o.startsWith("ui")&&o!=="index.tsx"&&o!=="index.jsx").map(o=>({name:o.replace(/\.(tsx|jsx)$/,""),path:re(s,o)}))}catch{continue}return[]}countFiles(e){let n=3;return e.moduleCss&&n++,e.moduleJs&&n++,n}};y();Ue();ne();import{spawn as Dp}from"child_process";import{join as Ge}from"path";import{readdirSync as Ks,statSync as Lp}from"fs";var Vs=class{async convert(e){let{sourceDir:n,themePath:s,onProgress:o}=e,i=e.conversionGuide||fe(),r=this.buildFullPrompt(n,s,i);return o("convert","Running Gemini CLI (this may take a few minutes)..."),await new Promise((a,l)=>{let c=Dp("gemini",["-p",r],{cwd:s,stdio:["pipe","pipe","pipe"],env:{...process.env},shell:!0}),d="",u="";c.stdout.on("data",m=>{d+=m.toString()}),c.stderr.on("data",m=>{u+=m.toString()}),c.on("error",m=>l(new Error(`Gemini CLI failed: ${m.message}`))),c.on("close",m=>{m!==0&&u&&!d?l(new Error(`Gemini CLI failed: ${u}`)):a()}),setTimeout(()=>{c.kill(),l(new Error("Gemini CLI timed out after 10 minutes"))},6e5)}),o("scan","Scanning generated files..."),this.scanGeneratedFiles(s)}buildFullPrompt(e,n,s){return`Read the conversion guide below, then convert the React landing page at ${e} into native HubSpot CMS modules for the theme at ${n}.
1713
2833
 
1714
2834
  INSTRUCTIONS:
1715
2835
  1. Analyze all .tsx/.jsx components in the React source
@@ -1724,7 +2844,7 @@ CONVERSION GUIDE:
1724
2844
  ${s}
1725
2845
 
1726
2846
  Do NOT run hs upload \u2014 I will handle that separately.
1727
- Create all files directly in the theme directory.`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=Ae(t,"css");if(k(s)){for(let r of os(s))if((r.includes("theme")||r.includes("page"))&&r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=E(Ae(s,r));break}}let o=Ae(t,"js");if(k(o)){for(let r of os(o))if((r.includes("animation")||r.includes("page"))&&r.endsWith(".js")&&r!=="main.js"){n.sharedJs=E(Ae(o,r));break}}let i=Ae(t,"templates");if(k(i)){for(let r of os(i))if(r.endsWith(".html")&&!r.startsWith("system")&&r!=="base.html"){let l=E(Ae(i,r));if(l.includes("dnd_area")){n.template=l;break}}}let a=Ae(t,"modules");if(k(a))for(let r of os(a)){if(!r.endsWith(".module"))continue;let l=Ae(a,r);if(!Ed(l).isDirectory())continue;let c={moduleName:r.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=Ae(l,"fields.json");k(d)&&(c.fieldsJson=E(d));let u=Ae(l,"meta.json");k(u)&&(c.metaJson=E(u));let m=Ae(l,"module.html");k(m)&&(c.moduleHtml=E(m));let g=Ae(l,"module.css");k(g)&&(c.moduleCss=E(g));let y=Ae(l,"module.js");k(y)&&(c.moduleJs=E(y)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}};f();ot();te();import{spawn as _d}from"child_process";import{join as $e}from"path";import{readdirSync as rs,statSync as Nd}from"fs";var as=class{async convert(t){let{sourceDir:n,themePath:s,onProgress:o}=t,i=t.conversionGuide||ce(),a=this.buildFullPrompt(n,s,i);return o("convert","Running OpenAI Codex (this may take a few minutes)..."),await new Promise((r,l)=>{let c=_d("codex",["exec","--full-auto",a],{cwd:s,stdio:["pipe","pipe","pipe"],env:{...process.env},shell:!0}),d="",u="";c.stdout.on("data",m=>{d+=m.toString()}),c.stderr.on("data",m=>{u+=m.toString()}),c.on("error",m=>l(new Error(`Codex CLI failed: ${m.message}`))),c.on("close",m=>{m!==0&&u&&!d?l(new Error(`Codex CLI failed: ${u}`)):r()}),setTimeout(()=>{c.kill(),l(new Error("Codex CLI timed out after 10 minutes"))},6e5)}),o("scan","Scanning generated files..."),this.scanGeneratedFiles(s)}buildFullPrompt(t,n,s){return`Read the conversion guide below, then convert the React landing page at ${t} into native HubSpot CMS modules for the theme at ${n}.
2847
+ Create all files directly in the theme directory.`}scanGeneratedFiles(e){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=Ge(e,"css");if(v(s)){for(let a of Ks(s))if((a.includes("theme")||a.includes("page"))&&a.endsWith(".css")&&a!=="theme-overrides.css"&&a!=="main.css"&&a!=="style.css"){n.sharedCss=M(Ge(s,a));break}}let o=Ge(e,"js");if(v(o)){for(let a of Ks(o))if((a.includes("animation")||a.includes("page"))&&a.endsWith(".js")&&a!=="main.js"){n.sharedJs=M(Ge(o,a));break}}let i=Ge(e,"templates");if(v(i)){for(let a of Ks(i))if(a.endsWith(".html")&&!a.startsWith("system")&&a!=="base.html"){let l=M(Ge(i,a));if(l.includes("dnd_area")){n.template=l;break}}}let r=Ge(e,"modules");if(v(r))for(let a of Ks(r)){if(!a.endsWith(".module"))continue;let l=Ge(r,a);if(!Lp(l).isDirectory())continue;let c={moduleName:a.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=Ge(l,"fields.json");v(d)&&(c.fieldsJson=M(d));let u=Ge(l,"meta.json");v(u)&&(c.metaJson=M(u));let m=Ge(l,"module.html");v(m)&&(c.moduleHtml=M(m));let g=Ge(l,"module.css");v(g)&&(c.moduleCss=M(g));let h=Ge(l,"module.js");v(h)&&(c.moduleJs=M(h)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}};y();Ue();ne();import{spawn as Jp}from"child_process";import{join as We}from"path";import{readdirSync as zs,statSync as Bp}from"fs";var Ys=class{async convert(e){let{sourceDir:n,themePath:s,onProgress:o}=e,i=e.conversionGuide||fe(),r=this.buildFullPrompt(n,s,i);return o("convert","Running OpenAI Codex (this may take a few minutes)..."),await new Promise((a,l)=>{let c=Jp("codex",["exec","--full-auto",r],{cwd:s,stdio:["pipe","pipe","pipe"],env:{...process.env},shell:!0}),d="",u="";c.stdout.on("data",m=>{d+=m.toString()}),c.stderr.on("data",m=>{u+=m.toString()}),c.on("error",m=>l(new Error(`Codex CLI failed: ${m.message}`))),c.on("close",m=>{m!==0&&u&&!d?l(new Error(`Codex CLI failed: ${u}`)):a()}),setTimeout(()=>{c.kill(),l(new Error("Codex CLI timed out after 10 minutes"))},6e5)}),o("scan","Scanning generated files..."),this.scanGeneratedFiles(s)}buildFullPrompt(e,n,s){return`Read the conversion guide below, then convert the React landing page at ${e} into native HubSpot CMS modules for the theme at ${n}.
1728
2848
 
1729
2849
  INSTRUCTIONS:
1730
2850
  1. Analyze all .tsx/.jsx components in the React source
@@ -1739,79 +2859,47 @@ CONVERSION GUIDE:
1739
2859
  ${s}
1740
2860
 
1741
2861
  Do NOT run hs upload \u2014 I will handle that separately.
1742
- Create all files directly in the theme directory.`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=$e(t,"css");if(k(s)){for(let r of rs(s))if((r.includes("theme")||r.includes("page"))&&r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=E($e(s,r));break}}let o=$e(t,"js");if(k(o)){for(let r of rs(o))if((r.includes("animation")||r.includes("page"))&&r.endsWith(".js")&&r!=="main.js"){n.sharedJs=E($e(o,r));break}}let i=$e(t,"templates");if(k(i)){for(let r of rs(i))if(r.endsWith(".html")&&!r.startsWith("system")&&r!=="base.html"){let l=E($e(i,r));if(l.includes("dnd_area")){n.template=l;break}}}let a=$e(t,"modules");if(k(a))for(let r of rs(a)){if(!r.endsWith(".module"))continue;let l=$e(a,r);if(!Nd(l).isDirectory())continue;let c={moduleName:r.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=$e(l,"fields.json");k(d)&&(c.fieldsJson=E(d));let u=$e(l,"meta.json");k(u)&&(c.metaJson=E(u));let m=$e(l,"module.html");k(m)&&(c.moduleHtml=E(m));let g=$e(l,"module.css");k(g)&&(c.moduleCss=E(g));let y=$e(l,"module.js");k(y)&&(c.moduleJs=E(y)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}};ot();te();function Pd(e,t){switch(e){case"claude-code":return new ns(t);case"gemini-cli":return new is;case"codex-cli":return new as;case"api":return new ss}}async function ls(e){await ge("Converting React to HubSpot Modules"),await Ge(`AI will now analyze your React code and create
1743
- HubSpot-native modules. This takes 2-5 minutes.`,"AI Conversion");let t=Pd(e.aiEngine,e.model),n=ce(),s=await he();s.start("Starting AI conversion...");let o=Date.now(),i=await t.convert({sourceDir:e.sourceDir,themePath:e.themePath,conversionGuide:n,onProgress:(y,h)=>{y==="created"?U(h):s.message(h)}}),a=((Date.now()-o)/1e3).toFixed(0);s.stop(`AI conversion complete (${a}s)`);let r=Md(e.themePath);for(let y of r)U(`Auto-fixed: ${y}`);let l=Od(e.themePath,i),c=[];for(let y of l){let h=y.passed?"\u2705":"\u274C",b=y.passed?"":y.critical?" (CRITICAL)":" (cosmetic)";c.push(`${h} ${y.label}${b}`)}let d=l.filter(y=>y.passed).length;c.push(`
1744
- ${d}/${l.length} checks passed`),await Ge(c.join(`
1745
- `),"Conversion Checklist");let u=l.filter(y=>!y.passed&&y.critical),m=l.filter(y=>!y.passed&&!y.critical);if(u.length>0){if(V(`${u.length} critical issue(s) \u2014 upload will likely fail:
1746
- `+u.map(h=>` - ${h.label}`).join(`
1747
- `)),!await le({message:"Continue with upload anyway?",initialValue:!1}))throw new Error("Conversion aborted due to critical checklist failures.")}else m.length>0&&q(`${m.length} non-critical issue(s) \u2014 page will work but may look incomplete:
1748
- `+m.map(y=>` - ${y.label}`).join(`
1749
- `));let g=Ie(e.themePath,"..","vibespot-conversion.log");return k(g)&&(await le({message:"Keep conversion log file for debugging?",initialValue:!1})?U(`Log saved: ${g}`):cr(g)),await fe("Files ready for upload!"),i}function Md(e){let t=[];Rd(e),Fd(e);let n=Ie(e,"modules");if(k(n))for(let o of mn(n)){if(!o.endsWith(".module"))continue;let i=Ie(n,o,"fields.json");if(!k(i))continue;let a=o.replace(".module",""),r=E(i),l=!1;r.includes('"textarea"')&&(r=r.replace(/"textarea"/g,'"text"'),l=!0,t.push(`${a}: "textarea" \u2192 "text"`)),/"name":\s*"name"/.test(r)&&(r=r.replace(/"name":\s*"name"/g,'"name": "item_name"'),l=!0,t.push(`${a}: reserved field name "name" \u2192 "item_name"`));try{let d=JSON.parse(r),u=!1;dr(d)&&(u=!0,t.push(`${a}: fixed choice field format`)),ur(d)&&(u=!0,t.push(`${a}: fixed link field default value`)),u&&(r=JSON.stringify(d,null,2)+`
1750
- `,l=!0)}catch{t.push(`${a}: fields.json has invalid JSON \u2014 manual fix needed`)}l&&G(i,r);let c=Ie(n,o,"module.html");if(k(c)){let d=E(c);d.includes("now()")&&(d=d.replace(/now\(\)/g,"local_dt"),G(c,d),t.push(`${a}: now() \u2192 local_dt`))}}let s=Ie(e,"templates");if(k(s))for(let o of mn(s)){if(!o.endsWith(".html"))continue;let i=Ie(s,o),a=E(i);(a.includes("hubdb_table")||a.includes("hubdb_table_rows"))&&(cr(i),t.push(`Removed ${o} (HubDB requires CMS Hub Pro/Enterprise)`))}return t}function dr(e){let t=!1;for(let n of e){if(typeof n!="object"||n===null)continue;let s=n;s.type==="choice"&&Array.isArray(s.choices)&&s.choices.some(i=>typeof i=="string")&&(s.choices=s.choices.map(i=>{if(typeof i=="string"){let a=i.charAt(0).toUpperCase()+i.slice(1);return[i,a]}return i}),t=!0),Array.isArray(s.children)&&dr(s.children)&&(t=!0)}return t}function ur(e){let t=!1;for(let n of e){if(typeof n!="object"||n===null)continue;let s=n;if(s.type==="link"){let o=s.default;if(typeof o=="string"||o===void 0||o===null||typeof o=="object"&&!o.url){let a=typeof o=="string"?o:"";s.default={url:{href:a,type:"EXTERNAL"},open_in_new_tab:!1,no_follow:!1},t=!0}}Array.isArray(s.children)&&ur(s.children)&&(t=!0)}return t}function Od(e,t){let n=[],s=t.modules.length;n.push({label:`Modules created (${s})`,passed:s>0,critical:!0});let o=!0;for(let u of t.modules)if(u.fieldsJson.includes('"textarea"')||/"name":\s*"name"/.test(u.fieldsJson)){o=!1;break}n.push({label:"fields.json valid (no textarea, no reserved names)",passed:s>0&&o,critical:!0});let i=t.modules.every(u=>u.moduleHtml.length>0);n.push({label:"module.html created for each module",passed:s>0&&i,critical:!0});let a=t.modules.filter(u=>!u.moduleCss).map(u=>u.moduleName),r=a.length===0;n.push({label:r?"module.css created for each module":`module.css missing for: ${a.join(", ")}`,passed:s>0&&r,critical:!1});let l=t.modules.some(u=>u.fieldsJson.includes('"STYLE"'));n.push({label:"Style tab fields (color pickers)",passed:l,critical:!1}),n.push({label:"Shared CSS with design system variables",passed:t.sharedCss.length>50,critical:!1}),n.push({label:"Shared JS for scroll animations",passed:t.sharedJs.length>50,critical:!1}),n.push({label:"Page template with dnd_area",passed:t.template.length>0&&t.template.includes("dnd_area"),critical:!0});let c=Ie(e,"templates"),d=!1;if(k(c))for(let u of mn(c)){if(!u.endsWith(".html")||u==="base.html"||u.startsWith("system"))continue;let m=E(Ie(c,u));if(m.includes("dnd_area")&&/templateType\s*:\s*page/i.test(m)){d=!0;break}}return n.push({label:"Template annotations (templateType: page)",passed:d,critical:!0}),n}function Rd(e){let t=Ie(e,"templates");if(k(t))for(let n of mn(t)){if(!n.endsWith(".html")||n==="base.html"||n.startsWith("system"))continue;let s=Ie(t,n),o=E(s);if(!o.includes("dnd_area")&&!o.includes("extends"))continue;let i=/templateType\s*:\s*page/i.test(o),a=/isAvailableForNewContent\s*:\s*true/i.test(o);if(i&&a)continue;let r=n.replace(".html","").replace(/[-_]/g," ").replace(/\b\w/g,l=>l.toUpperCase());if(o.includes("<!--")&&o.indexOf("-->")<200){let l=o.indexOf("-->"),c=o.slice(0,l);i||(c+=`
1751
- templateType: page`),a||(c+=`
2862
+ Create all files directly in the theme directory.`}scanGeneratedFiles(e){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=We(e,"css");if(v(s)){for(let a of zs(s))if((a.includes("theme")||a.includes("page"))&&a.endsWith(".css")&&a!=="theme-overrides.css"&&a!=="main.css"&&a!=="style.css"){n.sharedCss=M(We(s,a));break}}let o=We(e,"js");if(v(o)){for(let a of zs(o))if((a.includes("animation")||a.includes("page"))&&a.endsWith(".js")&&a!=="main.js"){n.sharedJs=M(We(o,a));break}}let i=We(e,"templates");if(v(i)){for(let a of zs(i))if(a.endsWith(".html")&&!a.startsWith("system")&&a!=="base.html"){let l=M(We(i,a));if(l.includes("dnd_area")){n.template=l;break}}}let r=We(e,"modules");if(v(r))for(let a of zs(r)){if(!a.endsWith(".module"))continue;let l=We(r,a);if(!Bp(l).isDirectory())continue;let c={moduleName:a.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=We(l,"fields.json");v(d)&&(c.fieldsJson=M(d));let u=We(l,"meta.json");v(u)&&(c.metaJson=M(u));let m=We(l,"module.html");v(m)&&(c.moduleHtml=M(m));let g=We(l,"module.css");v(g)&&(c.moduleCss=M(g));let h=We(l,"module.js");v(h)&&(c.moduleJs=M(h)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}};Ue();ne();Ye();function Hp(t,e){switch(t){case"claude-code":return new Gs(e);case"gemini-cli":return new Vs;case"codex-cli":return new Ys;case"api":return new Ws}}async function qs(t){await me("Converting React to HubSpot Modules"),await ut(`AI will now analyze your React code and create
2863
+ HubSpot-native modules. This takes 2-5 minutes.`,"AI Conversion");let e=Hp(t.aiEngine,t.model),n=fe(),s=await Pe();s.start("Starting AI conversion...");let o=Date.now(),i=await e.convert({sourceDir:t.sourceDir,themePath:t.themePath,conversionGuide:n,onProgress:(h,f)=>{h==="created"?G(f):s.message(f)}}),r=((Date.now()-o)/1e3).toFixed(0);s.stop(`AI conversion complete (${r}s)`);let a=Up(t.themePath);for(let h of a)G(`Auto-fixed: ${h}`);let l=Gp(t.themePath,i),c=[];for(let h of l){let f=h.passed?"\u2705":"\u274C",b=h.passed?"":h.critical?" (CRITICAL)":" (cosmetic)";c.push(`${f} ${h.label}${b}`)}let d=l.filter(h=>h.passed).length;c.push(`
2864
+ ${d}/${l.length} checks passed`),await ut(c.join(`
2865
+ `),"Conversion Checklist");let u=l.filter(h=>!h.passed&&h.critical),m=l.filter(h=>!h.passed&&!h.critical);if(u.length>0){if(z(`${u.length} critical issue(s) \u2014 upload will likely fail:
2866
+ `+u.map(f=>` - ${f.label}`).join(`
2867
+ `)),!await Ae({message:"Continue with upload anyway?",initialValue:!1}))throw new Error("Conversion aborted due to critical checklist failures.")}else m.length>0&&ee(`${m.length} non-critical issue(s) \u2014 page will work but may look incomplete:
2868
+ `+m.map(h=>` - ${h.label}`).join(`
2869
+ `));let g=qe(t.themePath,"..","vibespot-conversion.log");return v(g)&&(await Ae({message:"Keep conversion log file for debugging?",initialValue:!1})?G(`Log saved: ${g}`):Ba(g)),await pe("Files ready for upload!"),i}function Up(t){let e=[];Wp(t),Kp(t);let n=qe(t,"modules");if(v(n))for(let o of Gn(n)){if(!o.endsWith(".module"))continue;let i=qe(n,o,"fields.json");if(!v(i))continue;let r=o.replace(".module",""),a=M(i),l=!1;a.includes('"textarea"')&&(a=a.replace(/"textarea"/g,'"text"'),l=!0,e.push(`${r}: "textarea" \u2192 "text"`)),/"name":\s*"name"/.test(a)&&(a=a.replace(/"name":\s*"name"/g,'"name": "item_name"'),l=!0,e.push(`${r}: reserved field name "name" \u2192 "item_name"`));try{let d=JSON.parse(a),u=!1;Ha(d)&&(u=!0,e.push(`${r}: fixed choice field format`)),Ua(d)&&(u=!0,e.push(`${r}: fixed link field default value`)),u&&(a=JSON.stringify(d,null,2)+`
2870
+ `,l=!0)}catch{e.push(`${r}: fields.json has invalid JSON \u2014 manual fix needed`)}l&&J(i,a);let c=qe(n,o,"module.html");if(v(c)){let d=M(c);d.includes("now()")&&(d=d.replace(/now\(\)/g,"local_dt"),J(c,d),e.push(`${r}: now() \u2192 local_dt`))}}let s=qe(t,"templates");if(v(s))for(let o of Gn(s)){if(!o.endsWith(".html"))continue;let i=qe(s,o),r=M(i);(r.includes("hubdb_table")||r.includes("hubdb_table_rows"))&&(Ba(i),e.push(`Removed ${o} (HubDB requires CMS Hub Pro/Enterprise)`))}return e}function Ha(t){let e=!1;for(let n of t){if(typeof n!="object"||n===null)continue;let s=n;s.type==="choice"&&Array.isArray(s.choices)&&s.choices.some(i=>typeof i=="string")&&(s.choices=s.choices.map(i=>{if(typeof i=="string"){let r=i.charAt(0).toUpperCase()+i.slice(1);return[i,r]}return i}),e=!0),Array.isArray(s.children)&&Ha(s.children)&&(e=!0)}return e}function Ua(t){let e=!1;for(let n of t){if(typeof n!="object"||n===null)continue;let s=n;if(s.type==="link"){let o=s.default;if(typeof o=="string"||o===void 0||o===null||typeof o=="object"&&!o.url){let r=typeof o=="string"?o:"";s.default={url:{href:r,type:"EXTERNAL"},open_in_new_tab:!1,no_follow:!1},e=!0}}Array.isArray(s.children)&&Ua(s.children)&&(e=!0)}return e}function Gp(t,e){let n=[],s=e.modules.length;n.push({label:`Modules created (${s})`,passed:s>0,critical:!0});let o=!0;for(let u of e.modules)if(u.fieldsJson.includes('"textarea"')||/"name":\s*"name"/.test(u.fieldsJson)){o=!1;break}n.push({label:"fields.json valid (no textarea, no reserved names)",passed:s>0&&o,critical:!0});let i=e.modules.every(u=>u.moduleHtml.length>0);n.push({label:"module.html created for each module",passed:s>0&&i,critical:!0});let r=e.modules.filter(u=>!u.moduleCss).map(u=>u.moduleName),a=r.length===0;n.push({label:a?"module.css created for each module":`module.css missing for: ${r.join(", ")}`,passed:s>0&&a,critical:!1});let l=e.modules.some(u=>u.fieldsJson.includes('"STYLE"'));n.push({label:"Style tab fields (color pickers)",passed:l,critical:!1}),n.push({label:"Shared CSS with design system variables",passed:e.sharedCss.length>50,critical:!1}),n.push({label:"Shared JS for scroll animations",passed:e.sharedJs.length>50,critical:!1}),n.push({label:"Page template with dnd_area",passed:e.template.length>0&&e.template.includes("dnd_area"),critical:!0});let c=qe(t,"templates"),d=!1;if(v(c))for(let u of Gn(c)){if(!u.endsWith(".html")||u==="base.html"||u.startsWith("system"))continue;let m=M(qe(c,u));if(m.includes("dnd_area")&&/templateType\s*:\s*page/i.test(m)){d=!0;break}}return n.push({label:"Template annotations (templateType: page)",passed:d,critical:!0}),n}function Wp(t){let e=qe(t,"templates");if(v(e))for(let n of Gn(e)){if(!n.endsWith(".html")||n==="base.html"||n.startsWith("system"))continue;let s=qe(e,n),o=M(s);if(!o.includes("dnd_area")&&!o.includes("extends"))continue;let i=/templateType\s*:\s*page/i.test(o),r=/isAvailableForNewContent\s*:\s*true/i.test(o);if(i&&r)continue;let a=n.replace(".html","").replace(/[-_]/g," ").replace(/\b\w/g,l=>l.toUpperCase());if(o.includes("<!--")&&o.indexOf("-->")<200){let l=o.indexOf("-->"),c=o.slice(0,l);i||(c+=`
2871
+ templateType: page`),r||(c+=`
1752
2872
  isAvailableForNewContent: true`),/label\s*:/i.test(c)||(c+=`
1753
- label: ${r}`),o=c+o.slice(l)}else o=`<!--
2873
+ label: ${a}`),o=c+o.slice(l)}else o=`<!--
1754
2874
  templateType: page
1755
2875
  isAvailableForNewContent: true
1756
- label: ${r}
2876
+ label: ${a}
1757
2877
  -->
1758
- `+o;G(s,o),U(`Template "${n}" \u2014 annotations verified`)}}function Fd(e){let t=Ie(e,"modules");if(k(t))for(let n of mn(t)){if(!n.endsWith(".module"))continue;let s=Ie(t,n,"meta.json");if(k(s))try{let o=JSON.parse(E(s)),i=!1;(!o.host_template_types||!o.host_template_types.includes("PAGE"))&&(o.host_template_types=["PAGE"],i=!0),o.is_available_for_new_content||(o.is_available_for_new_content=!0,i=!0),i&&G(s,JSON.stringify(o,null,2)+`
1759
- `)}catch{}}}f();ht();import{join as wr,basename as Vd}from"path";f();te();import{join as de}from"path";import{readdirSync as it,rmSync as Jd}from"fs";function cs(e){let t=[];for(let n of e){let s=`${n.message}${n.detail?` \u2014 ${n.detail}`:""}`,o=!1;/textarea|unknown.*field.*type/i.test(s)&&(o=!0),/reserved.*name|missing field name|field null/i.test(s)&&(o=!0),/could not resolve.*now/i.test(s)&&(o=!0),/hubdb|do not have access/i.test(s)&&(o=!0),/invalid default value|link.*invalid|deserializ/i.test(s)&&(o=!0),/color.*invalid/i.test(s)&&(o=!0),t.push({file:n.file||"unknown",message:s,fixable:o})}return t}function ds(e){let t=[];if(/textarea.*not.*valid|unknown.*field.*type/i.test(e)){let n=e.match(/(?:in|file:?)\s+(\S+fields\.json)/i);t.push({file:n?.[1]||"fields.json",message:'"textarea" is not a valid field type',fixable:!0})}if(/missing field name|field null/i.test(e)){let n=e.match(/(?:in|file:?)\s+(\S+fields\.json)/i);t.push({file:n?.[1]||"fields.json",message:'"name" is a reserved field name',fixable:!0})}if(/could not resolve.*now/i.test(e)&&t.push({file:"module.html",message:"now() is not a valid HubL function",fixable:!0}),/hubdb|do not have access to hubdb/i.test(e)&&t.push({file:"templates",message:"HubDB requires CMS Hub Pro/Enterprise",fixable:!0}),/invalid default value|link.*field.*invalid/i.test(e)){let n=e.match(/field.*?(\w+)\s+has an invalid/i);t.push({file:n?.[1]||"fields.json",message:"Link field has invalid default value",fixable:!0})}if(/failed to deserialize/i.test(e)){let n=e.match(/file '([^']+)'/i);t.push({file:n?.[1]||"fields.json",message:"fields.json deserialization error",fixable:!0})}return/format for the color value is invalid/i.test(e)&&t.push({file:"fields.json",message:"Color field has invalid format (rgba/rgb/named \u2014 must be hex)",fixable:!0}),t}function us(e){let t=[];return pr(e)&&t.push("textarea \u2192 text"),gr(e)&&t.push("name \u2192 item_name"),fr(e)&&t.push("now() \u2192 local_dt"),hr(e)&&t.push("Removed HubDB templates"),yr(e)&&t.push("Fixed link field defaults"),br(e)&&t.push("Fixed rgba/invalid color values \u2192 hex"),jd(e)&&t.push("Stripped CDN @import statements"),t}function mr(e,t){return t.message.includes("textarea")?pr(e):t.message.includes("reserved field name")?gr(e):t.message.includes("now()")?fr(e):t.message.includes("HubDB")?hr(e):t.message.includes("invalid default value")||t.message.includes("deserialization")?yr(e):t.message.includes("invalid format")&&t.message.includes("color")?br(e):!1}function pr(e){let t=!1,n=de(e,"modules");if(!k(n))return!1;for(let s of it(n)){if(!s.endsWith(".module"))continue;let o=de(n,s,"fields.json");if(!k(o))continue;let i=E(o);i.includes('"textarea"')&&(i=i.replace(/"textarea"/g,'"text"'),G(o,i),t=!0)}return t}function gr(e){let t=!1,n=de(e,"modules");if(!k(n))return!1;for(let s of it(n)){if(!s.endsWith(".module"))continue;let o=de(n,s,"fields.json");if(!k(o))continue;let i=E(o);/"name":\s*"name"/g.test(i)&&(i=i.replace(/"name":\s*"name"/g,'"name": "item_name"'),G(o,i),t=!0)}return t}function fr(e){let t=!1,n=de(e,"modules");if(!k(n))return!1;for(let s of it(n)){if(!s.endsWith(".module"))continue;let o=de(n,s,"module.html");if(!k(o))continue;let i=E(o);i.includes("now()")&&(i=i.replace(/now\(\)/g,"local_dt"),G(o,i),t=!0)}return t}function hr(e){let t=!1,n=de(e,"templates");if(!k(n))return!1;for(let s of it(n)){if(!s.endsWith(".html"))continue;let o=de(n,s),i=E(o);(i.includes("hubdb_table")||i.includes("hubdb_table_rows"))&&(Jd(o),t=!0)}return t}function yr(e){let t=!1,n=de(e,"modules");if(!k(n))return!1;for(let s of it(n)){if(!s.endsWith(".module"))continue;let o=de(n,s,"fields.json");if(k(o))try{let i=JSON.parse(E(o));xr(i)&&(G(o,JSON.stringify(i,null,2)+`
1760
- `),t=!0)}catch{}}return t}function jd(e){let t=!1,n=de(e,"css");if(k(n))for(let o of it(n)){if(!o.endsWith(".css"))continue;let i=de(n,o),a=E(i),r=a.replace(/@import\s+url\(['"]?https?:\/\/[^)]+['"]?\)\s*;?/gi,"");r!==a&&(G(i,r),t=!0)}let s=de(e,"modules");if(k(s))for(let o of it(s)){if(!o.endsWith(".module"))continue;let i=de(s,o,"module.css");if(!k(i))continue;let a=E(i),r=a.replace(/@import\s+url\(['"]?https?:\/\/[^)]+['"]?\)\s*;?/gi,"");r!==a&&(G(i,r),t=!0)}if(k(s))for(let o of it(s)){if(!o.endsWith(".module"))continue;let i=de(s,o,"module.html");if(!k(i))continue;let a=E(i),r=a.replace(/<link[^>]+href=['"]https?:\/\/[^'"]+['"][^>]*>/gi,"");r!==a&&(G(i,r),t=!0)}return t}function br(e){let t=!1,n=de(e,"modules");if(!k(n))return!1;for(let s of it(n)){if(!s.endsWith(".module"))continue;let o=de(n,s,"fields.json");if(k(o))try{let i=JSON.parse(E(o));Sr(i)&&(G(o,JSON.stringify(i,null,2)+`
1761
- `),t=!0)}catch{}}return t}function Sr(e){let t=!1;for(let n of e){if(typeof n!="object"||n===null)continue;let s=n;if(s.type==="color"&&s.default&&typeof s.default=="object"){let o=s.default,i=o.color;if(typeof i=="string"&&!Dd(i)){let a=Hd(i);a&&(o.color=a.hex,a.opacity!==void 0&&(o.opacity=a.opacity),t=!0)}}Array.isArray(s.children)&&Sr(s.children)&&(t=!0)}return t}function Dd(e){return/^#[0-9a-fA-F]{6}$/.test(e)}function Hd(e){let t=e.match(/^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/);if(t)return{hex:`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`};let n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/i);if(n){let i=Math.min(255,parseInt(n[1])),a=Math.min(255,parseInt(n[2])),r=Math.min(255,parseInt(n[3])),l=`#${i.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`,c=n[4]!==void 0?Math.round(parseFloat(n[4])*100):void 0;return{hex:l,opacity:c}}let s={white:"#ffffff",black:"#000000",red:"#ff0000",green:"#008000",blue:"#0000ff",yellow:"#ffff00",orange:"#ffa500",purple:"#800080",gray:"#808080",grey:"#808080",transparent:"#000000"},o=e.toLowerCase().trim();return s[o]?{hex:s[o],opacity:o==="transparent"?0:void 0}:null}function xr(e){let t=!1;for(let n of e){if(typeof n!="object"||n===null)continue;let s=n;if(s.type==="link"){let o=s.default;if(typeof o=="string"||o===void 0||o===null||typeof o=="object"&&!o.url){let a=typeof o=="string"?o:"";s.default={url:{href:a,type:"EXTERNAL"},open_in_new_tab:!1,no_follow:!1},t=!0}}Array.isArray(s.children)&&xr(s.children)&&(t=!0)}return t}Q();f();bt();bt();import{readdirSync as Ld}from"fs";import{join as Bd,relative as Ud}from"path";var Gd=new Set([".git","node_modules",".vibespot",".DS_Store"]);function vr(e){let t=[];for(let n of Ld(e,{withFileTypes:!0})){if(Gd.has(n.name)||n.name.startsWith(".")&&n.name!==".gitkeep")continue;let s=Bd(e,n.name);n.isDirectory()?t.push(...vr(s)):n.isFile()&&t.push(s)}return t}async function Wd(e,t,n){let s=0;async function o(){for(;s<e.length;){let a=s++;await n(e[a])}}let i=Array.from({length:Math.min(t,e.length)},()=>o());await Promise.all(i)}async function ms(e,t,n,s={}){let o=s.concurrency??5,i=vr(t),a=i.length,r=0,l=0,c=[];return await Wd(i,o,async d=>{let u=Ud(t,d).replace(/\\/g,"/"),m=`${n}/${u}`;s.onFileStart?.(u);let g=await Wi(e,m,d);if(g.success)r++,s.onFileComplete?.(u);else{l++;let y={file:u,status:g.error?.status||0,message:g.error?.message||"Unknown error",category:g.error?.category,detail:g.error?.detail};c.push(y),s.onFileError?.(u,y)}s.onProgress?.(r+l,a)}),{success:l===0,uploaded:r,failed:l,total:a,errors:c}}function Kd(e){return(e.match(/^Uploaded file /gm)||[]).length}async function Jt(e){await ge("Uploading to HubSpot");let t=Vd(e)||e,n=P(),s=Se(),o=n.hubspotUploadMode!=="cli"&&!!s,i=await he(),a=3;for(let r=1;r<=a;r++){i.start(r===1?"Uploading theme...":`Retrying upload (attempt ${r}/${a})...`);let l=[],c=0,d=!1;if(o){let m=await ms(s,e,t,{onFileComplete:()=>{c++}});d=m.success,d?c=m.uploaded:l=cs(m.errors)}else{let m=J(`hs cms upload "${e}" "${t}"`,{cwd:wr(e,"..")}),g=[m.stdout,m.stderr].filter(Boolean).join(`
1762
- `);c=Kd(g),d=m.success,d||(l=ds(g))}if(d)return i.stop(`All files uploaded! (${c} files)`),await fe("Upload complete!"),!0;if(c>0?i.stop(`${c} files uploaded, but some errors occurred`):i.stop("Upload failed"),l.length===0){if(V("Upload failed with unknown error."),c>0&&(q(`Most files uploaded successfully. The theme may already be usable in HubSpot.
1763
- You can check your HubSpot Design Manager to verify.`),await le({message:"Continue anyway (theme is likely uploaded)?",initialValue:!0})))return!0;if(r<a){if(!await le({message:"Try uploading again?"}))break;continue}break}let u=!1;for(let m of l)m.fixable?mr(e,m)?(U(`Auto-fixed: ${m.message}`),u=!0):q(`Could not auto-fix: ${m.message}`):V(m.message);if(!(u&&r<a)){if(c>0&&(q(`${c} files uploaded successfully despite errors.
1764
- The theme may work \u2014 check HubSpot Design Manager.`),await le({message:"Continue anyway?",initialValue:!0})))return!0;if(!u){if(i.start("Cleaning up stuck modules..."),o)try{await ao(s,`${t}/modules`)}catch{}else J(`hs cms delete "${t}/modules"`,{cwd:wr(e,"..")});i.stop("Cleaned up modules, retrying...")}}}return V("Upload failed after multiple attempts."),!1}f();import{execFileSync as yo}from"child_process";import{rmSync as zd}from"fs";import{basename as Cr}from"path";te();async function kr(e){let{portalId:t,sourceDir:n,themePath:s,wasCloned:o}=e;await ge("You're all set!");let a=sn(t)==="eu1"?"app-eu1.hubspot.com":"app.hubspot.com";if(await Ge(`Your React page has been converted and uploaded to HubSpot.
2878
+ `+o;J(s,o),G(`Template "${n}" \u2014 annotations verified`)}}function Kp(t){let e=qe(t,"modules");if(v(e))for(let n of Gn(e)){if(!n.endsWith(".module"))continue;let s=qe(e,n,"meta.json");if(v(s))try{let o=JSON.parse(M(s)),i=!1;(!o.host_template_types||!o.host_template_types.includes("PAGE"))&&(o.host_template_types=["PAGE"],i=!0),o.is_available_for_new_content||(o.is_available_for_new_content=!0,i=!0),i&&J(s,JSON.stringify(o,null,2)+`
2879
+ `)}catch{}}}y();Jt();Ye();eo();Q();Ai();import{join as nl,basename as ng}from"path";function sg(t){return(t.match(/^Uploaded file /gm)||[]).length}async function cn(t){await me("Uploading to HubSpot");let e=ng(t)||t,n=O(),s=Fe(),o=n.hubspotUploadMode!=="cli"&&!!s,i=await Pe(),r=3;for(let a=1;a<=r;a++){i.start(a===1?"Uploading theme...":`Retrying upload (attempt ${a}/${r})...`);let l=[],c=0,d=!1;if(o){let m=await to(s,t,e,{onFileComplete:()=>{c++}});d=m.success,d?c=m.uploaded:l=Xs(m.errors)}else{let m=te(`hs cms upload "${t}" "${e}"`,{cwd:nl(t,"..")}),g=[m.stdout,m.stderr].filter(Boolean).join(`
2880
+ `);c=sg(g),d=m.success,d||(l=Zs(g))}if(d)return i.stop(`All files uploaded! (${c} files)`),await pe("Upload complete!"),!0;if(c>0?i.stop(`${c} files uploaded, but some errors occurred`):i.stop("Upload failed"),l.length===0){if(z("Upload failed with unknown error."),c>0&&(ee(`Most files uploaded successfully. The theme may already be usable in HubSpot.
2881
+ You can check your HubSpot Design Manager to verify.`),await Ae({message:"Continue anyway (theme is likely uploaded)?",initialValue:!0})))return!0;if(a<r){if(!await Ae({message:"Try uploading again?"}))break;continue}break}let u=!1;for(let m of l)m.fixable?Ga(t,m)?(G(`Auto-fixed: ${m.message}`),u=!0):ee(`Could not auto-fix: ${m.message}`):z(m.message);if(!(u&&a<r)){if(c>0&&(ee(`${c} files uploaded successfully despite errors.
2882
+ The theme may work \u2014 check HubSpot Design Manager.`),await Ae({message:"Continue anyway?",initialValue:!0})))return!0;if(!u){if(i.start("Cleaning up stuck modules..."),o)try{await bi(s,`${e}/modules`)}catch{}else te(`hs cms delete "${e}/modules"`,{cwd:nl(t,"..")});i.stop("Cleaned up modules, retrying...")}}}return z("Upload failed after multiple attempts."),!1}y();Ye();at();Ht();ne();import{execFileSync as $i}from"child_process";import{rmSync as og}from"fs";import{basename as sl}from"path";async function ol(t){let{portalId:e,sourceDir:n,themePath:s,wasCloned:o}=t;await me("You're all set!");let r=Rn(e)==="eu1"?"app-eu1.hubspot.com":"app.hubspot.com";if(await ut(`Your React page has been converted and uploaded to HubSpot.
1765
2883
  The theme and modules are now in your account, but you still
1766
- need to ${N.bold("create a new landing page")} that uses them.
2884
+ need to ${_.bold("create a new landing page")} that uses them.
1767
2885
 
1768
2886
  Next steps:
1769
2887
 
1770
- ${N.bold("1.")} Go to HubSpot ${N.muted("\u2192")} Content ${N.muted("\u2192")} Landing Pages ${N.muted("\u2192")} Create
1771
- ${N.bold("2.")} Choose your uploaded theme from the theme picker
1772
- ${N.bold("3.")} Select the landing page template that was just created
1773
- ${N.bold("4.")} Your converted modules will appear \u2014 drag them onto the page
1774
- ${N.bold("5.")} Click each section to edit text, images, and colors
1775
- ${N.bold("6.")} Upload images via File Manager ${N.muted("(Settings \u2192 Files)")}
1776
- ${N.bold("7.")} Preview and publish!`,"What's next"),await le({message:"Open HubSpot Landing Pages in your browser?"})){let c=t?`https://${a}/page-ui/${t}/management/pages/landing`:`https://${a}`;try{let d=process.platform;d==="darwin"?yo("open",[c],{stdio:"ignore"}):d==="win32"?yo("cmd",["/c","start","",c],{stdio:"ignore"}):yo("xdg-open",[c],{stdio:"ignore"}),U("Opening HubSpot Landing Pages...")}catch{ne(`Open this URL in your browser: ${N.info(c)}`)}}let l=[];if(o&&k(n)&&l.push({path:n,label:`Cloned source (${Cr(n)})`}),k(s)&&l.push({path:s,label:`Theme directory (${Cr(s)})`}),l.length>0&&await le({message:"Clean up local working directories?"}))for(let d of l)try{zd(d.path,{recursive:!0,force:!0}),U(`Removed ${d.label}`)}catch{q(`Could not remove ${d.label} \u2014 delete manually if needed.`)}await fe(`Thanks for using hub${N.vibes("Vibes")}! ${N.vibes("~")}`)}Q();async function Ar(){He();let e=await qn(),t=await Xn();W({lastSourcePath:t.sourceDir});let n=await ts();W({lastThemePath:n.themePath}),await ls({aiEngine:e.aiEngine,model:e.model,sourceDir:t.sourceDir,themePath:n.themePath}),await Jt(n.themePath),await kr({portalId:e.portalId,sourceDir:t.sourceDir,themePath:n.themePath,wasCloned:t.wasCloned})}f();async function $r(){He(),await qn()}f();Q();async function Tr(){He();let e=P();e.aiEngine||(V("AI engine not configured. Run `vibespot init` first or use the full wizard with `vibespot`."),process.exit(1));let t=await Xn(),n=await ts();await ls({aiEngine:e.aiEngine,sourceDir:t.sourceDir,themePath:n.themePath})}f();Q();async function Ir(){He();let e=P();if(e.lastThemePath)if(await le({message:`Upload from ${e.lastThemePath}?`}))await Jt(e.lastThemePath);else{let n=await Ne({message:"Path to your HubSpot theme directory:",placeholder:"./my-theme"});await Jt(n)}else{let t=await Ne({message:"Path to your HubSpot theme directory:",placeholder:"./my-theme",validate:n=>n.trim()?void 0:"Path is required"});await Jt(t)}}f();Q();async function Er(){He(),await ge("Environment Diagnostics");let e=0,t=en();t.found?Wn(t.version)?U(`Node.js v${t.version}`):(q(`Node.js v${t.version} \u2014 too old (need 18+)`),ne(" Update at https://nodejs.org"),e++):(V("Node.js \u2014 not installed"),ne(" Install from https://nodejs.org"),e++);let n=tn();n.found?U(`Git ${n.version}`):(V("Git \u2014 not installed"),ne(" Install from https://git-scm.com"),e++);let s=Be();if(!s.found)q("HubSpot CLI \u2014 not installed (only needed for deployment)"),ne(" Install: npm install -g @hubspot/cli");else if(!Bi(s.version))q(`HubSpot CLI v${s.version} \u2014 too old (need v8+)`),ne(" Update: npm install -g @hubspot/cli@latest"),e++;else{U(`HubSpot CLI v${s.version}`);let m=Ue();m.authenticated?U(`HubSpot portal${m.portalName?`: ${m.portalName}`:""} (ID: ${m.portalId})`):(q("HubSpot \u2014 not authenticated"),ne(" Run: hs init"))}let o=nn();o.found?U(`Claude Code ${o.version} at ${o.path}`):ne(N.muted("Claude Code \u2014 not installed"));let i=on();i.found?U(`Gemini CLI ${i.version} at ${i.path}`):ne(N.muted("Gemini CLI \u2014 not installed"));let a=rn();a.found?U(`OpenAI Codex ${a.version} at ${a.path}`):ne(N.muted("OpenAI Codex \u2014 not installed"));let r=P(),l=!!(r.anthropicApiKey||process.env.ANTHROPIC_API_KEY),c=!!(r.openaiApiKey||process.env.OPENAI_API_KEY),d=!!(r.geminiApiKey||process.env.GEMINI_API_KEY||process.env.GOOGLE_AI_API_KEY);l?U("Anthropic API key configured"):ne(N.muted("Anthropic API key \u2014 not set")),c?U("OpenAI API key configured"):ne(N.muted("OpenAI API key \u2014 not set")),d?U("Google AI API key configured"):ne(N.muted("Google AI API key \u2014 not set"));let u={"claude-code":"Claude Code",api:"Anthropic API","anthropic-api":"Anthropic API","claude-oauth":"Claude (OAuth)","openai-api":"OpenAI API","gemini-api":"Gemini API","gemini-cli":"Gemini CLI","codex-cli":"OpenAI Codex"};r.aiEngine&&U(`AI engine: ${u[r.aiEngine]||r.aiEngine}`),r.lastThemePath&&ne(N.muted(`Last theme: ${r.lastThemePath}`)),!o.found&&!i.found&&!a.found&&!l&&!c&&!d&&(q("No AI engine available"),ne(" Fastest: Set an API key (ANTHROPIC_API_KEY, OPENAI_API_KEY, or GEMINI_API_KEY)"),ne(" Or install: Claude Code \u2014 https://claude.ai/code"),ne(" Gemini CLI \u2014 https://github.com/google-gemini/gemini-cli"),ne(" Codex CLI \u2014 https://github.com/openai/codex"),e++),console.log(),e===0?await fe("Everything looks good!"):await fe(N.warn(`${e} issue${e>1?"s":""} found \u2014 see above`))}f();import{join as zs}from"path";import{existsSync as Vp}from"fs";import{execFileSync as Ei}from"child_process";import Ys from"chalk";f();pe();jt();ks();Tn();import{createServer as Dp}from"http";import{readFileSync as Ii,existsSync as Pn}from"fs";import{join as dt,extname as Lc}from"path";import{createHash as Hp}from"crypto";import{WebSocketServer as Lp}from"ws";f();Fe();pe();Q();ie();import{existsSync as ul,mkdirSync as Hm,writeFileSync as Lm,rmSync as Bm}from"fs";import{join as ml}from"path";var Um="plan.md";function pl(e){return ml(e,".vibespot",Um)}function mi(e){let t=v();if(!t)return null;t.brandAssets||(t.brandAssets={}),t.brandAssets.plan=e;try{let n=ml(t.themePath,".vibespot");ul(n)||Hm(n,{recursive:!0}),Lm(pl(t.themePath),e,"utf-8")}catch(n){A.warn("plan",`Failed to write plan.md: ${n instanceof Error?n.message:String(n)}`)}return j(),e}function pi(){let e=v();if(e){e.brandAssets&&delete e.brandAssets.plan;try{let t=pl(e.themePath);ul(t)&&Bm(t)}catch(t){A.warn("plan",`Failed to remove plan.md: ${t instanceof Error?t.message:String(t)}`)}j()}}function gl(e,t){Ye(e,t,n=>{if(!v()){p(t,400,{error:"No active session"});return}let o=typeof n.markdown=="string"?n.markdown:"";if(!o.trim()){p(t,400,{error:"Plan content cannot be empty"});return}mi(o),p(t,200,{ok:!0,plan:o})})}function fl(e,t){Ye(e,t,()=>{pi(),W({planMode:!1}),p(t,200,{ok:!0})})}f();var gi=/```vibespot-plan\s*\n([\s\S]*?)```/g,fi=/```vibespot-choices\s*\n([\s\S]*?)```/g;function hl(e){let t,n,s;for(gi.lastIndex=0;(s=gi.exec(e))!==null;)t=s[1].trim();let o;for(fi.lastIndex=0;(o=fi.exec(e))!==null;)try{let a=JSON.parse(o[1].trim());a&&typeof a.question=="string"&&Array.isArray(a.options)&&a.options.every(r=>typeof r=="string")&&a.options.length>0&&(n={question:a.question,options:a.options})}catch{}return{cleanedContent:e.replace(gi,"").replace(fi,"").replace(/\n{3,}/g,`
1777
-
1778
- `).trim(),plan:t,choices:n}}Q();f();import{spawn as hi}from"child_process";var gt=new Map;function yl(e,t,n){e.stdout?.on("data",o=>{t.output+=o.toString()}),e.stderr?.on("data",o=>{t.output+=o.toString()}),e.on("close",o=>{t.status=o===0?"completed":"failed",t.exitCode=o,t.completedAt=Date.now()}),e.on("error",o=>{t.status="failed",t.output+=`
1779
- Process error: ${o.message}`,t.completedAt=Date.now()}),setTimeout(()=>{t.status==="running"&&(e.kill(),t.status="failed",t.output+=`
1780
- Process timed out`,t.completedAt=Date.now())},n||3e5)}function In(e,t,n,s){let o=`job-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,6)}`,i={id:o,command:`${e} ${t.join(" ")}`,description:n,status:"running",output:"",exitCode:null,startedAt:Date.now(),completedAt:null};gt.set(o,i);let a=hi(e,t,{cwd:s?.cwd,stdio:[s?.stdin?"pipe":"ignore","pipe","pipe"],env:{...process.env,...s?.env},shell:process.platform==="win32"});return s?.stdin&&a.stdin&&(a.stdin.write(s.stdin),a.stdin.end()),yl(a,i,s?.timeout),o}function $t(e,t,n){let s=`job-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,6)}`,o={id:s,command:e,description:t,status:"running",output:"",exitCode:null,startedAt:Date.now(),completedAt:null};gt.set(s,o);let i=e.split(" "),a=hi(i[0],i.slice(1),{cwd:n?.cwd,stdio:["ignore","pipe","pipe"],env:{...process.env,...n?.env},shell:!0});return yl(a,o,n?.timeout),s}function Os(e){return gt.get(e)}function Gm(){let e=Date.now()-18e5;for(let[t,n]of gt)n.completedAt&&n.completedAt<e&&gt.delete(t)}setInterval(Gm,600*1e3);function Rs(e,t,n){let s=`job-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,6)}`,o={id:s,command:e,description:t,status:"running",output:"",exitCode:null,startedAt:Date.now(),completedAt:null,listeners:new Set};gt.set(s,o);let i=e.split(" "),a=hi(i[0],i.slice(1),{cwd:n?.cwd,stdio:["ignore","pipe","pipe"],env:{...process.env,...n?.env},shell:!0}),r=c=>{for(let d of o.listeners)try{d(c)}catch{}};a.stdout?.on("data",c=>{let d=c.toString();o.output+=d,r(d)}),a.stderr?.on("data",c=>{let d=c.toString();o.output+=d,r(d)}),a.on("close",c=>{o.status=c===0?"completed":"failed",o.exitCode=c,o.completedAt=Date.now(),o.listeners.clear()}),a.on("error",c=>{o.status="failed",o.output+=`
1781
- Process error: ${c.message}`,o.completedAt=Date.now(),o.listeners.clear()});let l=n?.timeout||3e5;return setTimeout(()=>{o.status==="running"&&(a.kill(),o.status="failed",o.output+=`
1782
- Process timed out`,o.completedAt=Date.now(),o.listeners.clear())},l),s}function bl(e,t){let n=gt.get(e);if(!n||!("listeners"in n))return;let s=n;if(s.output)try{t(s.output)}catch{}s.listeners.add(t)}function Sl(e,t){let n=gt.get(e);!n||!("listeners"in n)||n.listeners.delete(t)}Fe();te();f();Fe();Q();Qn();es();bt();pe();Tn();import{existsSync as Kt,readdirSync as xl,rmSync as Wm}from"fs";import{join as zt,basename as Vm}from"path";import{homedir as Km}from"os";import{execFileSync as vl}from"child_process";Q();te();var wl=process.platform==="win32"?{shell:!0}:{},Je=zt(Km(),"vibespot-themes"),Fs=null,zm=5e3;function Js(){if(Fs&&Date.now()-Fs.ts<zm)return Fs.data;let e=[];if(Kt(Je))try{for(let t of xl(Je,{withFileTypes:!0}))if(t.isDirectory()){let n=zt(Je,t.name,"theme.json");if(Kt(n)){let s=0,o=zt(Je,t.name,"modules");if(Kt(o))try{s=xl(o,{withFileTypes:!0}).filter(i=>i.isDirectory()).length}catch{}e.push({name:t.name,moduleCount:s})}}}catch{}return Fs={data:e,ts:Date.now()},e}function Cl(e){let t=v(),n=Vn(),s=!1;try{vl("hs",["--version"],{encoding:"utf-8",stdio:"pipe",...wl}),s=!0}catch{}let o=Lt().sort((a,r)=>r.updatedAt-a.updatedAt).slice(0,10),i=Js();p(e,200,{hasActiveSession:!!t,activeSession:t?{id:t.id,themeName:t.themeName,moduleCount:t.modules.length}:null,hsInstalled:s,aiAvailable:n.availableEngines.length>0,availableEngines:n.availableEngines,activeEngine:n.activeEngine,sessions:o,localThemes:i})}function kl(e,t){B(e,n=>{try{if(Wt()){p(t,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{name:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Theme name is required"});return}let o=s.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,""),i=zt(Je,o);Te(Je),Kt(i)&&Wm(i,{recursive:!0,force:!0}),cn(i,o),vt(i,o),j(),p(t,200,{ok:!0,themeName:o,themePath:i})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Al(e,t){B(e,n=>{try{if(Wt()){p(t,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{name:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Theme name is required"});return}let o=s.replace(/^\/+|\/+$/g,"");if(!o){p(t,400,{error:"Theme name is required"});return}let i=Se(),a=P(),r=o.includes("/")||o.includes("@")?o.replace(/[@/]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""):o,l=zt(Je,r);Te(Je),a.hubspotUploadMode==="cli"||!i?(vl("hs",["cms","fetch",o,l],{encoding:"utf-8",stdio:"pipe",...wl}),vt(l,r),bn(l),j(),p(t,200,{ok:!0,themeName:r,themePath:l,moduleCount:v()?.modules.length||0})):dn(i,o,l).then(()=>{vt(l,r),bn(l),j(),p(t,200,{ok:!0,themeName:r,themePath:l,moduleCount:v()?.modules.length||0})}).catch(c=>{p(t,500,{error:c instanceof Error?c.message:String(c)})})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function $l(e,t){B(e,n=>{try{if(Wt()){p(t,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{path:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Theme path is required"});return}let o=s;if(Kt(o)||(o=zt(Je,s)),!Kt(o)){p(t,400,{error:`Theme folder not found: ${s}`});return}let i=Vm(o);vt(o,i),bn(o),j(),p(t,200,{ok:!0,themeName:i,themePath:o,moduleCount:v()?.modules.length||0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Tl(e,t){B(e,n=>{try{if(Wt()){p(t,409,{error:"Cannot switch projects while AI is generating.",generating:!0});return}let{sessionId:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Session ID is required"});return}let o=ws(s);if(!o){p(t,404,{error:"Session not found"});return}p(t,200,{ok:!0,themeName:o.themeName,themePath:o.themePath,moduleCount:o.modules.length,messageCount:o.messages.length})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Il(e,t){B(e,n=>{try{let{apiKey:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"API key is required"});return}W({anthropicApiKey:s}),p(t,200,{ok:!0})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function El(e){let t=Se();if(!t){p(e,200,{themes:[],error:"No HubSpot account connected"});return}(async()=>{let n=await Ki(t);if(n.length===0){p(e,200,{themes:[]});return}let s=[],o=n.map(async r=>{let l=r.path||r.name;try{let c=await Yn(t,`${l}/theme.json`);c&&!c.folder&&s.push({name:r.name,path:l})}catch{}});await Promise.all(o),s.sort((r,l)=>r.name.localeCompare(l.name));let i=Js(),a=new Set(i.map(r=>r.name));p(e,200,{themes:s.map(r=>({...r,existsLocally:a.has(r.name)}))})})().catch(n=>{p(e,200,{themes:[],error:n instanceof Error?n.message:String(n)})})}f();Fe();Q();pe();import{existsSync as Ym,readFileSync as qm,appendFileSync as Xm}from"fs";import{join as _l}from"path";import{homedir as Nl}from"os";bt();te();var En={data:{},ts:0},Zm=600*1e3,Pl={"claude-code":[{id:"sonnet",label:"Claude Sonnet (default)"},{id:"opus",label:"Claude Opus"},{id:"haiku",label:"Claude Haiku"}],"codex-cli":[{id:"o4-mini",label:"o4 Mini (default)"},{id:"o3",label:"o3"},{id:"gpt-4o",label:"GPT-4o"}]};async function Qm(e){let t=await fetch("https://api.anthropic.com/v1/models",{headers:{"x-api-key":e,"anthropic-version":"2023-06-01"}});return t.ok?(await t.json()).data.filter(s=>!s.id.startsWith("claude-3-")&&!s.id.startsWith("claude-2")).map(s=>({id:s.id,label:s.display_name})):[]}async function ep(e){let t=await fetch("https://api.openai.com/v1/models",{headers:{Authorization:`Bearer ${e}`}});if(!t.ok)return[];let n=await t.json(),s=/^(gpt-4o|gpt-4o-mini|o[1-4](-mini)?|o[1-4]-pro)$/;return n.data.filter(o=>s.test(o.id)).sort((o,i)=>o.id.localeCompare(i.id)).map(o=>({id:o.id,label:o.id}))}async function tp(e){let t=await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${e}`);return t.ok?(await t.json()).models.filter(s=>s.name.includes("gemini-2")).map(s=>({id:s.name.replace("models/",""),label:s.displayName})):[]}async function np(){if(Date.now()-En.ts<Zm&&Object.keys(En.data).length>0)return En.data;let e=P(),t={...Pl},n=[],s=be("anthropic-api",e);s&&n.push(Qm(s).then(a=>{a.length&&(t["anthropic-api"]=a,t["claude-oauth"]=a)}).catch(()=>{}));let o=be("openai-api",e);o&&n.push(ep(o).then(a=>{a.length&&(t["openai-api"]=a)}).catch(()=>{}));let i=be("gemini-api",e);return i&&n.push(tp(i).then(a=>{a.length&&(t["gemini-api"]=a,t["gemini-cli"]=a)}).catch(()=>{})),await Promise.all(n),En.data=t,En.ts=Date.now(),t}function Ml(e){let t=Vn(),n=P(),s={aiEngine:n.aiEngine||null,claudeCodeModel:n.claudeCodeModel||null,anthropicApiModel:n.anthropicApiModel||null,openaiApiModel:n.openaiApiModel||null,hubspotUploadMode:n.hubspotUploadMode||"api",hubspotAccounts:(n.hubspotAccounts||[]).map(r=>({portalId:r.portalId,portalName:r.portalName,dataCenter:r.dataCenter})),activeHubSpotAccount:n.activeHubSpotAccount||null,enabledCLITools:n.enabledCLITools||[],agenticMode:n.agenticMode,agenticConcurrency:n.agenticConcurrency,planMode:n.planMode||!1,extendedThinking:n.extendedThinking||!1,extendedThinkingBudget:n.extendedThinkingBudget||"medium",webSearch:n.webSearch||!1,figmaToken:n.figmaToken?"\u2022\u2022\u2022\u2022"+n.figmaToken.slice(-4):null},o=Lt().length,i=Js().length,a=Nt();np().then(r=>{p(e,200,{version:a,environment:t,config:s,models:r,sessionCount:o,localThemeCount:i})}).catch(()=>{p(e,200,{version:a,environment:t,config:s,models:Pl,sessionCount:o,localThemeCount:i})})}function Ol(e,t){B(e,n=>{try{let{engine:s,model:o}=JSON.parse(n);if(!["claude-code","anthropic-api","claude-oauth","openai-api","gemini-cli","gemini-api","codex-cli"].includes(s)){p(t,400,{error:`Invalid engine: ${s}`});return}let a={aiEngine:s};if(o)switch(s){case"claude-code":a.claudeCodeModel=o;break;case"anthropic-api":case"claude-oauth":a.anthropicApiModel=o;break;case"openai-api":a.openaiApiModel=o;break}W(a),p(t,200,{ok:!0,engine:s})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Rl(e,t){B(e,n=>{try{let{provider:s,apiKey:o}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"provider is required"});return}if(!o){let l={};switch(s){case"anthropic":l.anthropicApiKey="";break;case"openai":l.openaiApiKey="";break;case"gemini":l.geminiApiKey="";break;case"figma":l.figmaToken="";break;default:p(t,400,{error:`Unknown provider: ${s}`});return}W(l),p(t,200,{ok:!0,provider:s,deleted:!0});return}let i={};switch(s){case"anthropic":i.anthropicApiKey=o;break;case"openai":i.openaiApiKey=o;break;case"gemini":i.geminiApiKey=o;break;case"figma":i.figmaToken=o;break;default:p(t,400,{error:`Unknown provider: ${s}`});return}W(i);let a=null;if(!P().aiEngine){let c={anthropic:"anthropic-api",openai:"openai-api",gemini:"gemini-api"}[s];c&&(W({aiEngine:c}),a=c)}p(t,200,{ok:!0,provider:s,autoSelectedEngine:a})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Fl(e,t){B(e,n=>{try{let{tool:s}=JSON.parse(n),o={hubspot:{cmd:"npm install -g @hubspot/cli",desc:"Installing HubSpot CLI"},claude:{cmd:"npm install -g @anthropic-ai/claude-code",desc:"Installing Claude Code"},gemini:{cmd:"npm install -g @google/gemini-cli",desc:"Installing Gemini CLI"},codex:{cmd:process.platform==="darwin"?"brew install --cask codex":"npm install -g @openai/codex",desc:"Installing OpenAI Codex"},gh:{cmd:process.platform==="darwin"?"brew install gh":"npm install -g @cli/gh",desc:"Installing GitHub CLI"}},i=o[s];if(!i){p(t,400,{error:`Unknown tool: ${s}. Valid: ${Object.keys(o).join(", ")}`});return}let a=$t(i.cmd,i.desc,{timeout:12e4});p(t,200,{ok:!0,jobId:a})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Jl(e,t){B(e,n=>{try{let s=JSON.parse(n||"{}"),o=P(),i=o.hubspotUploadMode||"api";if(s.personalAccessKey)if(i==="api"){zn(s.personalAccessKey).then(a=>{qt(s.personalAccessKey,a.portalId,a.portalName,a.dataCenter),p(t,200,{ok:!0,portalName:a.portalName,portalId:a.portalId,dataCenter:a.dataCenter})}).catch(a=>{p(t,400,{error:a instanceof Error?a.message:String(a)})});return}else{if(!Be().found){p(t,400,{error:"HubSpot CLI not installed",needsInstall:!0});return}let r=In("hs",["auth",`--pak=${s.personalAccessKey}`],"Authenticating with HubSpot",{timeout:3e4});p(t,200,{ok:!0,jobId:r});return}if(i==="api"){let a=o.hubspotAccounts||[];if(a.length>0&&!s.force){let r=a.find(l=>l.portalId===o.activeHubSpotAccount)||a[0];p(t,200,{ok:!0,alreadyAuthenticated:!0,portalName:r.portalName,portalId:r.portalId});return}}else{if(!Be().found){p(t,400,{error:"HubSpot CLI not installed",needsInstall:!0});return}let r=Ue();if(r.authenticated&&!s.force){p(t,200,{ok:!0,alreadyAuthenticated:!0,portalName:r.portalName,portalId:r.portalId});return}}p(t,200,{needsKey:!0,instructions:"Create a personal access key in HubSpot",url:"https://app.hubspot.com/portal-recommend/l?slug=personal-access-key",steps:["Click the link above to open HubSpot","Select your account","Create a Personal Access Key with CMS permissions","Copy the key and paste it below"]})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function jl(e,t){B(e,n=>{try{let s=JSON.parse(n||"{}");if(!io().found){p(t,400,{error:"GitHub CLI not installed",needsInstall:!0});return}let i=ro();if(i.authenticated&&!s.force){p(t,200,{ok:!0,alreadyAuthenticated:!0,username:i.username});return}if(s.token){let r=In("gh",["auth","login","--with-token"],"Authenticating with GitHub",{timeout:3e4,stdin:s.token});p(t,200,{ok:!0,jobId:r});return}let a=$t("gh auth login --web --git-protocol https","GitHub authentication (check your browser)",{timeout:3e5});p(t,200,{ok:!0,jobId:a,browserAuthRequired:!0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Dl(e,t){B(e,n=>{try{let{portalId:s,action:o}=JSON.parse(n);if((P().hubspotUploadMode||"api")==="api"){if(o==="remove"&&s){Zs(s),p(t,200,{ok:!0});return}if(s){Qs(s),p(t,200,{ok:!0});return}}else{if(!Be().found){p(t,400,{error:"HubSpot CLI not installed"});return}let l=String(s).replace(/[^0-9]/g,"");if(!l){p(t,400,{error:"Invalid portalId"});return}if(o==="remove"){let c=In("hs",["accounts","remove",l],`Removing HubSpot account ${l}`,{timeout:15e3});p(t,200,{ok:!0,jobId:c});return}if(l){let c=In("hs",["accounts","use",l],`Switching to HubSpot account ${l}`,{timeout:15e3});p(t,200,{ok:!0,jobId:c});return}}p(t,400,{error:"portalId required"})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Hl(e){let t=$t("gh auth logout --hostname github.com -y","Logging out of GitHub",{timeout:15e3});p(e,200,{ok:!0,jobId:t})}function Ll(e,t){B(e,n=>{try{let{cli:s,apiKey:o}=JSON.parse(n||"{}");switch(s){case"claude":{let i=$t("CLAUDECODE= claude --print -p 'reply OK'","Authenticating Claude Code (check your browser if prompted)",{timeout:12e4});p(t,200,{ok:!0,jobId:i,hint:"If Claude Code opens a browser window, complete the sign-in there."});break}case"gemini":{let i=$t("gemini -p 'reply OK'","Authenticating Gemini CLI (check your browser if prompted)",{timeout:12e4});p(t,200,{ok:!0,jobId:i,hint:"If Gemini opens a browser window, complete the sign-in there."});break}case"codex":{if(o&&o.trim()){let i=o.trim();if(process.env.OPENAI_API_KEY=i,W({openaiApiKey:i}),process.platform!=="win32"){let a=/^[A-Za-z0-9_\-.:]+$/.test(i)?i:"";if(a){let r=`export OPENAI_API_KEY="${a}"`,l=process.env.SHELL?.includes("zsh")?_l(Nl(),".zshrc"):_l(Nl(),".bashrc");try{(Ym(l)?qm(l,"utf-8"):"").includes("OPENAI_API_KEY")||Xm(l,`
1783
- # Added by vibeSpot
1784
- ${r}
1785
- `)}catch{}}}p(t,200,{ok:!0,message:"API key saved"})}else{let i=$t("codex login","Authenticating Codex CLI (check your browser if prompted)",{timeout:12e4});p(t,200,{ok:!0,jobId:i,hint:"Complete the sign-in in your browser."})}break}default:p(t,400,{error:`Unknown CLI: ${s}`})}}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Bl(e,t){B(e,n=>{try{let{mode:s}=JSON.parse(n);if(s!=="api"&&s!=="cli"){p(t,400,{error:`Invalid mode: ${s}. Must be "api" or "cli".`});return}W({hubspotUploadMode:s}),p(t,200,{ok:!0,mode:s})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Ul(e,t){B(e,n=>{try{let{toolId:s,enabled:o}=JSON.parse(n);if(!s||typeof o!="boolean"){p(t,400,{error:"toolId (string) and enabled (boolean) required"});return}eo(s,o),p(t,200,{ok:!0,toolId:s,enabled:o})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Gl(e,t){B(e,n=>{try{let s=JSON.parse(n),o=["agenticMode","agenticConcurrency","planMode","extendedThinking","extendedThinkingBudget","webSearch"];if(s.extendedThinkingBudget!==void 0&&!["low","medium","high"].includes(s.extendedThinkingBudget)){p(t,400,{error:"extendedThinkingBudget must be 'low' | 'medium' | 'high'"});return}let i={};for(let a of o)a in s&&(i[a]=s[a]);if(Object.keys(i).length===0){p(t,400,{error:"No valid settings fields provided"});return}W(i),p(t,200,{ok:!0,updated:Object.keys(i)})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Wl(e,t){let n=e.replace("/api/settings/job/","");if(!n){p(t,400,{error:"Job ID required"});return}let s=Os(n);if(!s){p(t,404,{error:"Job not found"});return}p(t,200,{id:s.id,status:s.status,description:s.description,output:s.output,exitCode:s.exitCode,startedAt:s.startedAt,completedAt:s.completedAt})}f();Fe();Q();tt();function Vl(e,t){B(e,n=>{try{let{access_token:s,refresh_token:o}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"access_token is required"});return}to(s.trim(),(o||"").trim());let i=P();(!i.aiEngine||i.aiEngine!=="claude-oauth")&&W({aiEngine:"claude-oauth"}),p(t,200,{ok:!0})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Kl(e,t){let n=Le(),s=Qt();p(t,200,{authenticated:n,expiresAt:s?.expiresAt||null})}function zl(e,t){try{Ln(),P().aiEngine==="claude-oauth"&&W({aiEngine:void 0}),p(t,200,{ok:!0})}catch(n){p(t,500,{error:n instanceof Error?n.message:String(n)})}}f();Fe();pe();import{existsSync as sp,rmSync as op}from"fs";import{join as ip}from"path";function Yl(e,t,n){if(e==="GET"){let s=v(),o=Lt().sort((i,a)=>a.updatedAt-i.updatedAt);p(n,200,{activeTheme:s?{id:s.id,themeName:s.themeName}:null,sessions:o});return}if(e==="DELETE"){B(t,s=>{try{let{sessionId:o,deleteFiles:i}=JSON.parse(s);Yr(o,i),p(n,200,{ok:!0})}catch(o){p(n,500,{error:o instanceof Error?o.message:String(o)})}});return}p(n,405,{error:"Method not allowed"})}function ql(e,t){B(e,n=>{try{let{sessionId:s}=JSON.parse(n),o=ws(s);if(!o){p(t,404,{error:"Session not found"});return}p(t,200,{ok:!0,themeName:o.themeName,themePath:o.themePath})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Xl(e,t){B(e,n=>{try{let{themeName:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"Theme name is required"});return}let o=ip(Je,s);if(!sp(o)){p(t,404,{error:"Theme not found on disk"});return}op(o,{recursive:!0,force:!0}),p(t,200,{ok:!0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Zl(e,t){B(e,n=>{try{let{sessionId:s,newName:o}=JSON.parse(n);if(!s||!o||typeof o!="string"){p(t,400,{error:"sessionId and newName are required"});return}let i=o.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/^-|-$/g,"").replace(/-{2,}/g,"-");if(!i){p(t,400,{error:"Invalid name"});return}let a=qr(s,i);a.ok?p(t,200,{ok:!0,newName:i}):p(t,400,{error:a.error})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}f();Fe();ie();Q();pe();te();import{existsSync as Us,readFileSync as pp,rmSync as vi}from"fs";import{join as Ze,basename as gp}from"path";import{execFileSync as fp}from"child_process";var hp=process.platform==="win32"?{shell:!0}:{};function ic(e){let t=v();if(!t){p(e,404,{error:"No active session"});return}let n=at();p(e,200,{themeName:t.themeName,themePath:t.themePath,templates:t.templates.map(s=>({id:s.id,label:s.label,pageType:s.pageType,moduleCount:s.modules.length,messageCount:s.messages.length})),activeTemplateId:t.activeTemplateId,moduleLibrary:n.map(s=>({moduleName:s.module.moduleName,usedIn:s.usedIn})),brandAssets:{hasStyleguide:!!t.brandAssets?.styleguide,hasBrandvoice:!!t.brandAssets?.brandvoice,hasThemeContext:!!t.brandAssets?.themeContext,humanify:t.brandAssets?.humanify!==!1}})}function rc(e){let t=v();if(!t){p(e,404,{error:"No active session"});return}let n=t.themePath;if(!Us(n)){p(e,404,{error:"Theme directory not found"});return}let s=t.themeName||"theme",o=Ze(n,".."),i=gp(n);try{let a=`${s}.zip`,r=Ze(o,a);Us(r)&&vi(r),fp("zip",["-r",a,i,"-x",`${i}/.git/*`,`${i}/.vibespot/*`,`${i}/node_modules/*`],{cwd:o,timeout:3e4,...hp});let l=pp(r);vi(r),e.writeHead(200,{"Content-Type":"application/zip","Content-Disposition":`attachment; filename="${a}"`,"Content-Length":l.length}),e.end(l)}catch(a){A.error("download-zip","Failed to create zip archive",a),p(e,500,{error:"Failed to create zip archive"})}}function ac(e,t,n){let s=v();if(!s){p(n,404,{error:"No active session"});return}if(e==="GET"){p(n,200,{templates:s.templates.map(o=>({id:o.id,label:o.label,pageType:o.pageType,moduleCount:o.modules.length})),activeTemplateId:s.activeTemplateId});return}if(e==="POST"){B(t,o=>{try{let{pageType:i,label:a}=JSON.parse(o);if(!i||!a){p(n,400,{error:"pageType and label are required"});return}if(!["landing_page","blog_post","website_page","module_only"].includes(i)){p(n,400,{error:`Invalid pageType: ${i}`});return}let l=bs(i,a);j(),p(n,200,{ok:!0,template:{id:l.id,label:l.label,pageType:l.pageType}})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}if(e==="DELETE"){B(t,o=>{try{let{templateId:i,deleteModules:a}=JSON.parse(o);if(!i){p(n,400,{error:"templateId is required"});return}if(!Kr(i,!!a)){p(n,404,{error:"Template not found"});return}j(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}p(n,405,{error:"Method not allowed"})}function lc(e,t){B(e,n=>{try{let{templateId:s}=JSON.parse(n);if(!s){p(t,400,{error:"templateId is required"});return}if(!Ao(s)){p(t,404,{error:"Template not found"});return}j();let i=v();p(t,200,{ok:!0,modules:X().map(a=>a.moduleName),messageCount:i?.messages.length||0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function cc(e,t){B(e,n=>{try{let{templateId:s,newLabel:o}=JSON.parse(n);if(!s||!o||typeof o!="string"){p(t,400,{error:"templateId and newLabel are required"});return}if(!Vr(s,o.trim())){p(t,404,{error:"Template not found"});return}j(),p(t,200,{ok:!0,newLabel:o.trim()})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function dc(e,t){B(e,n=>{try{let{templateId:s,label:o}=JSON.parse(n);if(!s){p(t,400,{error:"templateId is required"});return}let i=Wr(s,o);if(!i){p(t,404,{error:"Template not found"});return}j(),p(t,200,{ok:!0,template:{id:i.id,label:i.label,pageType:i.pageType,moduleCount:i.modules.length}})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function uc(e){let t=at();p(e,200,{modules:t.map(n=>({moduleName:n.module.moduleName,usedIn:n.usedIn,fieldsJson:n.module.fieldsJson}))})}function mc(e,t,n){let s=v();if(!s){p(n,404,{error:"No active session"});return}B(t,o=>{try{let{moduleName:i}=JSON.parse(o);if(!i){p(n,400,{error:"moduleName is required"});return}let r=at().find(d=>d.module.moduleName===i);if(!r){p(n,404,{error:`Module "${i}" not found in library`});return}let l={...r.module};s.modules.find(d=>d.moduleName===l.moduleName)||(s.modules.push(l),s.moduleOrder.push(l.moduleName),s.updatedAt=Date.now()),j(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}})}function pc(e,t,n){let s=v();if(!s){p(n,404,{error:"No active session"});return}if(e==="GET"){p(n,200,{styleguide:s.brandAssets?.styleguide||null,brandvoice:s.brandAssets?.brandvoice||null,themeContext:s.brandAssets?.themeContext||null});return}if(e==="POST"){B(t,o=>{try{let{type:i,content:a}=JSON.parse(o);if(!i){p(n,400,{error:"type is required"});return}if(s.brandAssets||(s.brandAssets={}),i==="humanify"){s.brandAssets.humanify=a==="on",s.updatedAt=Date.now(),j(),p(n,200,{ok:!0});return}if(!a){p(n,400,{error:"content is required"});return}if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(n,400,{error:`Invalid type: ${i}. Must be "styleguide", "brandvoice", or "themeContext"`});return}let r=i,l=r==="themeContext"?"theme-context.md":`${r}.md`;s.brandAssets[r]=a,s.updatedAt=Date.now();let c=Ze(s.themePath,".vibespot");Te(c),G(Ze(c,l),a),j(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}if(e==="DELETE"){B(t,o=>{try{let{type:i}=JSON.parse(o);if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(n,400,{error:`Invalid type: ${i}`});return}let a=i;s.brandAssets&&delete s.brandAssets[a],s.updatedAt=Date.now();let r=a==="themeContext"?"theme-context.md":`${a}.md`,l=Ze(s.themePath,".vibespot",r);Us(l)&&vi(l),j(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}p(n,405,{error:"Method not allowed"})}function sc(e,t,n){if(!e)return;e.brandAssets||(e.brandAssets={}),e.brandAssets[t]=n,e.updatedAt=Date.now();let s=t==="themeContext"?"theme-context.md":`${t}.md`,o=Ze(e.themePath,".vibespot");Te(o),G(Ze(o,s),n)}async function oc(e,t,n){if(t==="styleguide"){let{extractDesignContext:m}=await Promise.resolve().then(()=>(Bs(),Ls));return m(n||e.themePath)}let{resolveAgenticEngine:s}=await Promise.resolve().then(()=>(Tn(),dl)),{loadConfig:o}=await Promise.resolve().then(()=>(Q(),ji)),i=o(),{engine:a,apiKey:r,model:l}=s(i),{buildPreviewHtml:c}=await Promise.resolve().then(()=>(ks(),jo)),d=c();if(!d||d.length<50)return null;if(t==="brandvoice"){let{extractBrandvoice:m}=await Promise.resolve().then(()=>(nc(),tc));return m(d,a,r,l)}let{extractThemeContext:u}=await Promise.resolve().then(()=>(xi(),Si));return u(d,e.brandAssets?.themeContext,a,r,l)}function gc(e,t){let n=v();if(!n){p(t,404,{error:"No active session"});return}B(e,s=>{(async()=>{try{let o=s?JSON.parse(s):{},i=o.type||"styleguide",a=o.sourcePath;if(i==="all"){let l=["styleguide","brandvoice","themeContext"],c=await Promise.allSettled(l.map(u=>oc(n,u,a))),d={};for(let u=0;u<l.length;u++){let m=c[u],g=m.status==="fulfilled"?m.value:null;g&&sc(n,l[u],g),d[l[u]]=g}j(),p(t,200,{ok:!0,type:"all",extracted:d});return}if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(t,400,{error:`Invalid type: ${i}`});return}let r=await oc(n,i,a);if(!r){p(t,200,{ok:!1,type:i,error:"No content to extract from"});return}sc(n,i,r),j(),p(t,200,{ok:!0,type:i,content:r})}catch(o){p(t,500,{error:o instanceof Error?o.message:String(o)})}})()})}function fc(e,t){let n=v();if(!n){p(t,404,{error:"No active session"});return}B(e,s=>{(async()=>{try{let{source:o,themeName:i,localPath:a}=JSON.parse(s),r;if(o==="hubspot"){if(!i){p(t,400,{error:"themeName is required for HubSpot import"});return}let u=Se();if(!u){p(t,400,{error:"No HubSpot account connected"});return}let m=i.replace(/^\/+|\/+$/g,"");if(!m){p(t,400,{error:"Invalid theme name"});return}let g=m.replace(/[@/]/g,"_").replace(/_+/g,"_"),{homedir:y}=await import("os"),h=Ze(y(),"vibespot-themes",".references",g);Te(h);let{fetchTheme:b}=await Promise.resolve().then(()=>(es(),er));await b(u,m,h),r=h}else if(o==="local"){if(!a){p(t,400,{error:"localPath is required for local import"});return}if(!Us(a)){p(t,400,{error:`Path not found: ${a}`});return}r=a}else{p(t,400,{error:"source must be 'hubspot' or 'local'"});return}let{extractDesignContext:l}=await Promise.resolve().then(()=>(Bs(),Ls)),c=await l(r);n.brandAssets||(n.brandAssets={}),n.brandAssets.styleguide=c,n.updatedAt=Date.now();let d=Ze(n.themePath,".vibespot");Te(d),G(Ze(d,"styleguide.md"),c),j(),p(t,200,{ok:!0,styleguide:c,source:r})}catch(o){p(t,500,{error:o instanceof Error?o.message:String(o)})}})()})}f();Fe();pe();import{join as yp}from"path";jt();function hc(e,t){let n=v();if(!n){p(t,404,{error:"No active session"});return}p(t,200,{id:n.id,themeName:n.themeName,themePath:n.themePath,messageCount:n.messages.length,moduleCount:n.modules.length,moduleOrder:n.moduleOrder})}function yc(e,t,n){let s=v();if(!s){p(n,404,{error:"No active session"});return}if(e==="GET"){let o=X();p(n,200,{modules:o.map(i=>({moduleName:i.moduleName,fieldsJson:i.fieldsJson,moduleHtml:i.moduleHtml,moduleCss:i.moduleCss,moduleJs:i.moduleJs||null})),sharedCss:s.sharedCss,sharedJs:s.sharedJs});return}if(e==="DELETE"){Ye(t,n,o=>{o.deleteEntirely?Hr(o.moduleName):Lr(o.moduleName),j(),p(n,200,{ok:!0})});return}p(n,405,{error:"Method not allowed"})}function bc(e,t){let n=v();if(!n){p(t,404,{error:"No active session"});return}B(e,s=>{try{let o=JSON.parse(s);if(o.shared){if(o.shared==="css")n.sharedCss=o.content;else if(o.shared==="js")n.sharedJs=o.content;else{p(t,400,{error:"Invalid shared type"});return}let c=xe();c&&(o.shared==="css"?c.sharedCss=o.content:c.sharedJs=o.content),n.updatedAt=Date.now(),j(),_e(),p(t,200,{ok:!0});return}let{moduleName:i,fileType:a,content:r}=o;if(!i||!a){p(t,400,{error:"moduleName and fileType required"});return}let l=n.modules.find(c=>c.moduleName===i);if(!l){p(t,404,{error:`Module "${i}" not found`});return}switch(a){case"html":l.moduleHtml=r;break;case"css":l.moduleCss=r;break;case"js":l.moduleJs=r||void 0;break;case"fields":try{JSON.parse(r)}catch{p(t,400,{error:"Invalid JSON in fields.json"});return}l.fieldsJson=r;break;default:p(t,400,{error:`Invalid fileType: ${a}`});return}n.updatedAt=Date.now(),j(),_e(),p(t,200,{ok:!0})}catch(o){p(t,400,{error:String(o)})}})}function Sc(e,t){Ye(e,t,n=>{Array.isArray(n.order)?(Ke(n.order),j(),p(t,200,{ok:!0})):p(t,400,{error:"order must be an array"})})}async function xc(e){let t=v();if(!t){p(e,404,{error:"No active session"});return}try{_e();let n=us(t.themePath),s=Rs(`hs cms upload "${t.themePath}" "${t.themeName}"`,"Uploading to HubSpot",{cwd:yp(t.themePath,".."),timeout:18e4});p(e,200,{ok:!0,jobId:s,fixes:n})}catch(n){p(e,500,{error:String(n)})}}function vc(e,t){B(e,n=>{try{let{moduleName:s,fieldPath:o,value:i}=JSON.parse(n);Br(s,o,i),j(),p(t,200,{ok:!0})}catch(s){p(t,400,{error:String(s)})}})}function wc(e,t){B(e,n=>{try{let{url:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"url is required"});return}let o=Xi(s),i=o.components.map(r=>`- ${r.name}: ${r.description}`).join(`
1786
- `),a={sourceDir:o.sourceDir,componentCount:o.components.length,components:o.components.map(r=>({name:r.name,description:r.description})),hasTailwind:o.hasTailwind,cssVarCount:o.cssVarCount,fonts:o.fonts,interactions:o.interactions,conversionPrompt:`Import and convert the React landing page from ${s} to native HubSpot modules.
1787
-
1788
- Source analysis found ${o.components.length} components:
1789
- ${i}
1790
-
1791
- Design system: ${o.hasTailwind?"Tailwind CSS":"Custom CSS"}, ${o.cssVarCount} CSS variables
1792
- Fonts: ${o.fonts.length>0?o.fonts.join(", "):"System fonts"}
1793
- Interactions: ${o.interactions.join(", ")}
1794
-
1795
- Read the React source files from ${o.sourceDir} and convert each component to a HubSpot module. Preserve the design, layout, colors, and content. Generate fields.json so marketers can edit all text, images, colors, and links in the HubSpot page editor.`};p(t,200,a)}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Cc(e,t){let n=v();if(!n){p(t,404,{error:"No active session"});return}if(!Oe()){p(t,200,{available:!1,commits:[]});return}let o=new URL(e.url||"/","http://localhost").searchParams.get("templateId"),i=o?Or(n.themePath,o,50):Mr(n.themePath,50);p(t,200,{available:!0,commits:i,filtered:!!o})}function kc(e,t){B(e,n=>{try{let s=v();if(!s){p(t,404,{error:"No active session"});return}let{hash:o,templateId:i}=JSON.parse(n);if(!o||typeof o!="string"){p(t,400,{error:"Commit hash is required"});return}if(Re("assistant",`Rolled back to version ${o.slice(0,7)}.`),i){let a=s.templates.find(c=>c.id===i);if(!a){p(t,404,{error:"Template not found"});return}let r=a.moduleOrder.map(c=>`modules/${c}.module`);a.templateFile&&r.push(a.templateFile);let l=Fr(s.themePath,i,o,r);if(!l.success){p(t,500,{error:l.error||"Rollback failed"});return}ea()}else{let a=Rr(s.themePath,o);if(!a.success){p(t,500,{error:a.error||"Rollback failed"});return}Qr()}j(),p(t,200,{ok:!0,modules:X().map(a=>a.moduleName)})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}Yo();Ti();var Bc={".html":"text/html",".css":"text/css",".js":"application/javascript",".json":"application/json",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".webp":"image/webp",".gif":"image/gif",".ico":"image/x-icon",".woff2":"font/woff2"};function Uc(e){let{port:t,uiDir:n}=e,s=Dp((i,a)=>Bp(i,a,n)),o=new Lp({server:s});return o.on("connection",i=>Gp(i)),new Promise((i,a)=>{s.on("error",r=>{r.code==="EADDRINUSE"?s.listen(t+1,()=>{i({port:t+1,close:()=>{s.close(),o.close()}})}):a(r)}),s.listen(t,()=>{i({port:t,close:()=>{s.close(),o.close()}})})})}function Bp(e,t,n){let s=new URL(e.url||"/",`http://${e.headers.host}`),o=e.method||"GET";if(t.setHeader("X-Content-Type-Options","nosniff"),t.setHeader("X-Frame-Options","DENY"),t.setHeader("X-XSS-Protection","1; mode=block"),t.setHeader("Referrer-Policy","strict-origin-when-cross-origin"),s.pathname.startsWith("/api/")){Up(o,s.pathname,e,t);return}if(s.pathname==="/preview"){let i=Fo();t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(i);return}if(s.pathname==="/module-preview"){let i=s.searchParams.get("module")||"",a=Jo(i);t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(a||"<!-- module not found -->");return}if(s.pathname.startsWith("/theme-assets/")){Wp(s.pathname.slice(14),t);return}if(s.pathname==="/docs"){t.writeHead(301,{Location:"/docs/"}),t.end();return}if(s.pathname.startsWith("/docs/")){let i=s.pathname.slice(5)||"/index.html";Hc(i,dt(n,"docs"),e,t);return}Hc(s.pathname,n,e,t)}function Up(e,t,n,s){let o=n.headers.origin||"";if(/^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(o)&&s.setHeader("Access-Control-Allow-Origin",o),s.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS"),s.setHeader("Access-Control-Allow-Headers","Content-Type"),e==="OPTIONS"){s.writeHead(204),s.end();return}switch(t){case"/api/session":hc(e,s);break;case"/api/modules":yc(e,n,s);break;case"/api/modules/reorder":Sc(n,s);break;case"/api/modules/code":bc(n,s);break;case"/api/upload":xc(s);break;case"/api/upload-files":e==="POST"?Ia(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/field":vc(n,s);break;case"/api/import":wc(n,s);break;case"/api/setup":Cl(s);break;case"/api/setup/create":kl(n,s);break;case"/api/setup/fetch":Al(n,s);break;case"/api/setup/open":$l(n,s);break;case"/api/setup/resume":Tl(n,s);break;case"/api/setup/apikey":Il(n,s);break;case"/api/setup/remote-themes":e==="GET"?El(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/status":e==="GET"?Ml(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/engine":e==="POST"?Ol(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/apikey":e==="POST"?Rl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/install":e==="POST"?Fl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-auth":e==="POST"?Jl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/gh-auth":e==="POST"?jl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-switch":e==="POST"?Dl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/gh-logout":e==="POST"?Hl(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/cli-auth":e==="POST"?Ll(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-mode":e==="POST"?Bl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/cli-toggle":e==="POST"?Ul(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/save":e==="POST"?Vl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/status":e==="GET"?Kl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/logout":e==="POST"?zl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings":e==="POST"?Gl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/changelog":e==="GET"?p(s,200,{changelog:Mi()}):p(s,405,{error:"Method not allowed"});break;case"/api/themes":Yl(e,n,s);break;case"/api/themes/switch":e==="POST"?ql(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/delete-local":e==="POST"?Xl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/rename":e==="POST"?Zl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/history":e==="GET"?Cc(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/rollback":e==="POST"?kc(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/dashboard":e==="GET"?ic(s):p(s,405,{error:"Method not allowed"});break;case"/api/templates":ac(e,n,s);break;case"/api/templates/activate":e==="POST"?lc(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/rename":e==="POST"?cc(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/clone":e==="POST"?dc(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/module-library":e==="GET"?uc(s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets":pc(e,n,s);break;case"/api/brand-assets/extract":e==="POST"?gc(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets/import-reference":e==="POST"?fc(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/download-zip":e==="GET"?rc(s):p(s,405,{error:"Method not allowed"});break;case"/api/figma/test-token":e==="POST"?ki(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/figma/extract":e==="POST"?Ai(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/figma/generate":e==="POST"?$i(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/plan/edit":e==="POST"?gl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/plan/discard":e==="POST"?fl(n,s):p(s,405,{error:"Method not allowed"});break;default:t.startsWith("/api/settings/job/")&&e==="GET"?Wl(t,s):t.match(/^\/api\/templates\/[^/]+\/add-module$/)&&e==="POST"?mc(t,n,s):p(s,404,{error:"Not found"})}}function Gp(e){e.on("message",async n=>{let s;try{s=JSON.parse(n.toString())}catch{e.send(JSON.stringify({type:"error",message:"Invalid JSON"}));return}switch(s.type){case"chat":{let o=String(s.message||"");if(!o.trim())return;let i=Array.isArray(s.fileIds)?s.fileIds:void 0;if(di()){Re("user",o),j();try{e.send(JSON.stringify({type:"stream_status",content:"Planning..."}));let r="",l=await ci(o,d=>{r+=d,e.send(JSON.stringify({type:"stream",content:d}))},i),c=hl(l||r);c.plan&&(mi(c.plan),e.send(JSON.stringify({type:"plan_updated",plan:c.plan}))),c.choices&&e.send(JSON.stringify({type:"plan_choices",question:c.choices.question,options:c.choices.options})),Re("assistant",c.cleanedContent),j(),e.send(JSON.stringify({type:"plan_complete",cleanedContent:c.cleanedContent})),e.send(JSON.stringify({type:"generation_complete"}))}catch(r){e.send(JSON.stringify({type:"error",message:r instanceof Error?r.message:String(r)}))}break}Re("user",o),j();let a=ui();a.needsPrompt&&e.send(JSON.stringify({type:"agentic_prompt"}));try{if(a.useAgentic){let l=[],c=[],d=await Ms(o,u=>{if(u.type==="module_progress"&&u.moduleFiles){let{moduleFiles:m,...g}=u;e.send(JSON.stringify(g))}else e.send(JSON.stringify(u));if(u.type==="agent_step")l.push({step:u.step,label:u.label});else if(u.type==="agent_decision"){let m=l[l.length-1];m&&(m.decisions||(m.decisions=[]),m.decisions.push(u.decision))}else u.type==="design_system_ready"?oe({sharedCss:u.sharedCss,sharedJs:u.sharedJs}):u.type==="blueprint_ready"?(oe({sharedCss:u.sharedCss,sharedJs:u.sharedJs}),Ke(u.moduleOrder),e.send(JSON.stringify({type:"modules_updated",modules:X().map(m=>m.moduleName)}))):u.type==="module_progress"&&u.status==="complete"&&u.moduleFiles?(oe({modules:[{moduleName:u.module,fieldsJson:u.moduleFiles.fieldsJson,metaJson:u.moduleFiles.metaJson,moduleHtml:u.moduleFiles.moduleHtml,moduleCss:u.moduleFiles.moduleCss,moduleJs:u.moduleFiles.moduleJs}]}),e.send(JSON.stringify({type:"modules_updated",modules:X().map(m=>m.moduleName)})),c.push({name:u.module,status:"complete"})):u.type==="module_progress"&&u.status==="failed"&&c.push({name:u.module,status:"failed"})},i);At(d,{steps:l,modules:c,stats:d.stats})}else ai(l=>{e.send(JSON.stringify({type:"parse_warning",message:l}))}),await An(o,l=>{e.send(JSON.stringify({type:"stream",content:l}))},l=>{e.send(JSON.stringify({type:"stream_status",content:l}))},i);let r=v();if(r){_e();let l=xe(),c=null;if(l){let d=l.moduleOrder.map(u=>`modules/${u}.module`);l.templateFile&&d.push(l.templateFile),l.sharedCss&&d.push(`css/${r.themeName}-theme.css`),l.sharedJs&&d.push(`js/${r.themeName}-animations.js`),c=bo(r.themePath,l.id,o,d)}else c=St(r.themePath,o);c&&e.send(JSON.stringify({type:"version_created",hash:c}))}e.send(JSON.stringify({type:"generation_complete"})),e.send(JSON.stringify({type:"modules_updated",modules:X().map(l=>l.moduleName)}));{let l=v();l&&a.useAgentic&&!l.brandAssets?.styleguide&&!l.brandAssets?.brandvoice&&!l.brandAssets?.themeContext&&e.send(JSON.stringify({type:"suggest_brand_extraction"}))}}catch(r){e.send(JSON.stringify({type:"error",message:r instanceof Error?r.message:String(r)}))}break}case"figma_import":{let o=String(s.extractionId||""),i=String(s.themeName||"");if(!o||!i){e.send(JSON.stringify({type:"error",message:"Missing extractionId or themeName"}));break}let{getCachedExtraction:a}=await Promise.resolve().then(()=>(Ti(),Dc)),r=a(o);if(!r){e.send(JSON.stringify({type:"error",message:"Extraction expired or not found. Please re-extract."}));break}try{let l=v();if(!l||l.themeName!==i){let{join:m}=await import("path"),{homedir:g}=await import("os"),{existsSync:y}=await import("fs"),{createThemeScaffold:h}=await Promise.resolve().then(()=>(Qn(),Zi)),b=m(g(),"vibespot-themes"),x=m(b,i);if(!y(b)){let{mkdirSync:w}=await import("fs");w(b,{recursive:!0})}y(x)||h(x,i),vt(x,i),j()}e.send(JSON.stringify({type:"figma_import_started",fileName:r.fileName}));let c=[],d=[],u=await $n(r,i,m=>{if(m.type==="module_progress"&&m.moduleFiles){let{moduleFiles:g,...y}=m;e.send(JSON.stringify(y))}else e.send(JSON.stringify(m));if(m.type==="agent_step")c.push({step:m.step,label:m.label});else if(m.type==="agent_decision"){let g=c[c.length-1];g&&(g.decisions||(g.decisions=[]),g.decisions.push(m.decision))}else m.type==="design_system_ready"?oe({sharedCss:m.sharedCss,sharedJs:m.sharedJs}):m.type==="blueprint_ready"?(oe({sharedCss:m.sharedCss,sharedJs:m.sharedJs}),Ke(m.moduleOrder),e.send(JSON.stringify({type:"modules_updated",modules:X().map(g=>g.moduleName)}))):m.type==="module_progress"&&m.status==="complete"&&m.moduleFiles?(oe({modules:[{moduleName:m.module,fieldsJson:m.moduleFiles.fieldsJson,metaJson:m.moduleFiles.metaJson,moduleHtml:m.moduleFiles.moduleHtml,moduleCss:m.moduleFiles.moduleCss,moduleJs:m.moduleFiles.moduleJs}]}),e.send(JSON.stringify({type:"modules_updated",modules:X().map(g=>g.moduleName)})),d.push({name:m.module,status:"complete"})):m.type==="module_progress"&&m.status==="failed"&&d.push({name:m.module,status:"failed"})});At(u,{steps:c,modules:d,stats:u.stats}),_e(),St(v().themePath,`Figma import: ${r.fileName}`),e.send(JSON.stringify({type:"generation_complete"})),e.send(JSON.stringify({type:"modules_updated",modules:X().map(m=>m.moduleName)}))}catch(l){e.send(JSON.stringify({type:"error",message:l instanceof Error?l.message:String(l)}))}break}case"extract_brand_assets":{let o=v();if(!o){e.send(JSON.stringify({type:"error",message:"No active session"}));break}(async()=>{try{let i=P(),{engine:a,apiKey:r,model:l}=Vt(i),{buildPreviewHtml:c}=await Promise.resolve().then(()=>(ks(),jo)),d=c();if(!d||d.length<50)return;let{extractThemeContext:u}=await Promise.resolve().then(()=>(xi(),Si)),m=await u(d,o.brandAssets?.themeContext,a,r,l),{mkdirSync:g,writeFileSync:y}=await import("fs");if(m){o.brandAssets||(o.brandAssets={}),o.brandAssets.themeContext=m,o.updatedAt=Date.now();let h=dt(o.themePath,".vibespot");Pn(h)||g(h,{recursive:!0}),y(dt(h,"theme-context.md"),m),j(),e.send(JSON.stringify({type:"brand_asset_extracted",assetType:"themeContext"}))}if(!o.brandAssets?.styleguide)try{let{extractDesignContext:h}=await Promise.resolve().then(()=>(Bs(),Ls)),b=await h(o.themePath);if(b){o.brandAssets||(o.brandAssets={}),o.brandAssets.styleguide=b,o.updatedAt=Date.now();let x=dt(o.themePath,".vibespot");Pn(x)||g(x,{recursive:!0}),y(dt(x,"styleguide.md"),b),j(),e.send(JSON.stringify({type:"brand_asset_extracted",assetType:"styleguide"}))}}catch{}e.send(JSON.stringify({type:"brand_extraction_complete"}))}catch(i){e.send(JSON.stringify({type:"brand_extraction_error",message:i instanceof Error?i.message:String(i)}))}})();break}case"start_upload":{let o=v();if(!o){e.send(JSON.stringify({type:"error",message:"No active session"}));break}try{_e();let i=us(o.themePath);if(i.length>0&&e.send(JSON.stringify({type:"upload_status",phase:"autofix",fixes:i})),(P().hubspotUploadMode||"api")==="api"){let l=Se();if(!l){e.send(JSON.stringify({type:"upload_failed",output:"No HubSpot account configured. Open Settings \u2192 HubSpot to add one.",errors:[{file:"",message:"No HubSpot account configured",fixable:!1}]}));break}e.send(JSON.stringify({type:"upload_started",jobId:"api-upload"}));let c=await ms(l,o.themePath,o.themeName,{onFileStart:d=>{e.send(JSON.stringify({type:"upload_output",chunk:`Uploading ${d}
1796
- `}))},onFileComplete:d=>{e.send(JSON.stringify({type:"upload_output",chunk:` \u2713 ${d}
1797
- `}))},onFileError:(d,u)=>{e.send(JSON.stringify({type:"upload_output",chunk:` \u2717 ${d}: ${u.message}
1798
- `}))},onProgress:(d,u)=>{e.send(JSON.stringify({type:"upload_progress",completed:d,total:u}))}});if(c.success){let d=ut();e.send(JSON.stringify({type:"upload_complete",output:`Uploaded ${c.uploaded} files`,portalId:d?.portalId||"",dataCenter:d?.dataCenter||"na1",themeName:o.themeName}))}else{let d=cs(c.errors);e.send(JSON.stringify({type:"upload_failed",output:c.errors.map(u=>`${u.file}: ${u.message}`).join(`
1799
- `),errors:d}))}}else{let l=Rs(`hs cms upload "${o.themePath}" "${o.themeName}"`,"Uploading to HubSpot",{cwd:dt(o.themePath,".."),timeout:18e4});e.send(JSON.stringify({type:"upload_started",jobId:l}));let c=u=>{e.send(JSON.stringify({type:"upload_output",chunk:u}))};bl(l,c);let d=setInterval(()=>{let u=Os(l);if(!(!u||u.status==="running"))if(clearInterval(d),Sl(l,c),u.status==="completed"){let m=Ue(),g=m.portalId?sn(m.portalId):"na1";e.send(JSON.stringify({type:"upload_complete",output:u.output,portalId:m.portalId||"",dataCenter:g,themeName:o.themeName}))}else{let m=ds(u.output);e.send(JSON.stringify({type:"upload_failed",output:u.output,errors:m,exitCode:u.exitCode}))}},500)}}catch(i){e.send(JSON.stringify({type:"error",message:i instanceof Error?i.message:String(i)}))}break}case"upload_fix_with_ai":{let o=String(s.errorContext||"");if(!o.trim()){e.send(JSON.stringify({type:"error",message:"No error context provided"}));break}let i=`The HubSpot upload ("hs cms upload") failed. Below is the upload log output containing the errors.
1800
-
1801
- IMPORTANT: Be verbose in your response. For each error:
1802
- 1. State exactly which file has the problem and what the error is
1803
- 2. Explain WHY this error occurs (e.g. "HubSpot doesn't support textarea field type" or "field name 'name' is reserved in HubSpot modules")
1804
- 3. Describe the specific fix you're applying (e.g. "Changing field type from textarea to text" or "Renaming field from 'name' to 'item_name'")
1805
- 4. Apply the fix to the module files
1806
-
1807
- CRITICAL: After fixing the reported errors, scan ALL other module files in the theme for the same issues. For example, if you fix "name" \u2192 "item_name" in one module, check every other module's fields.json for the same problem. Fix all occurrences, not just the ones in the error log.
1808
-
1809
- After fixing all errors, summarize the changes you made.
1810
-
1811
- Upload log:
1812
- ${o}`;Re("user",i),j(),e.send(JSON.stringify({type:"upload_fix_started"}));try{await An(i,r=>{e.send(JSON.stringify({type:"stream",content:r})),e.send(JSON.stringify({type:"upload_fix_stream",content:r}))});let a=v();if(a){_e();let r=St(a.themePath,"AI fix: upload errors");r&&e.send(JSON.stringify({type:"version_created",hash:r}))}e.send(JSON.stringify({type:"upload_fix_complete"})),e.send(JSON.stringify({type:"modules_updated",modules:X().map(r=>r.moduleName)}))}catch(a){e.send(JSON.stringify({type:"upload_failed",output:a instanceof Error?a.message:String(a),errors:[{file:"AI fix",message:a instanceof Error?a.message:String(a),fixable:!1}]}))}break}case"ping":e.send(JSON.stringify({type:"pong"}));break;case"plan_approve":{let o=v();if(!o){e.send(JSON.stringify({type:"error",message:"No active session"}));break}let i=o.brandAssets?.plan;if(!i||!i.trim()){e.send(JSON.stringify({type:"error",message:"No plan to approve. Send a chat message first."}));break}W({planMode:!1});let a="Implement the approved plan.";Re("user",a),j();try{let r=[],l=[],c=await Ms(a,u=>{if(u.type==="module_progress"&&u.moduleFiles){let{moduleFiles:m,...g}=u;e.send(JSON.stringify(g))}else e.send(JSON.stringify(u));if(u.type==="agent_step")r.push({step:u.step,label:u.label});else if(u.type==="agent_decision"){let m=r[r.length-1];m&&(m.decisions||(m.decisions=[]),m.decisions.push(u.decision))}else u.type==="design_system_ready"?oe({sharedCss:u.sharedCss,sharedJs:u.sharedJs}):u.type==="blueprint_ready"?(oe({sharedCss:u.sharedCss,sharedJs:u.sharedJs}),Ke(u.moduleOrder),e.send(JSON.stringify({type:"modules_updated",modules:X().map(m=>m.moduleName)}))):u.type==="module_progress"&&u.status==="complete"&&u.moduleFiles?(oe({modules:[{moduleName:u.module,fieldsJson:u.moduleFiles.fieldsJson,metaJson:u.moduleFiles.metaJson,moduleHtml:u.moduleFiles.moduleHtml,moduleCss:u.moduleFiles.moduleCss,moduleJs:u.moduleFiles.moduleJs}]}),e.send(JSON.stringify({type:"modules_updated",modules:X().map(m=>m.moduleName)})),l.push({name:u.module,status:"complete"})):u.type==="module_progress"&&u.status==="failed"&&l.push({name:u.module,status:"failed"})});At(c,{steps:r,modules:l,stats:c.stats});let d=v();if(d){_e();let u=xe(),m=null;if(u){let g=u.moduleOrder.map(y=>`modules/${y}.module`);u.templateFile&&g.push(u.templateFile),u.sharedCss&&g.push(`css/${d.themeName}-theme.css`),u.sharedJs&&g.push(`js/${d.themeName}-animations.js`),m=bo(d.themePath,u.id,"Approved plan: implementation",g)}else m=St(d.themePath,"Approved plan: implementation");m&&e.send(JSON.stringify({type:"version_created",hash:m}))}e.send(JSON.stringify({type:"generation_complete"})),e.send(JSON.stringify({type:"modules_updated",modules:X().map(u=>u.moduleName)}))}catch(r){e.send(JSON.stringify({type:"error",message:r instanceof Error?r.message:String(r)}))}break}case"plan_discard":{pi(),W({planMode:!1}),e.send(JSON.stringify({type:"plan_discarded"}));break}default:e.send(JSON.stringify({type:"error",message:`Unknown type: ${s.type}`}))}});let t=v();if(t){let n=P(),s={"claude-code":"Claude Code","anthropic-api":"Anthropic API","claude-oauth":"Claude (OAuth)","openai-api":"OpenAI API","gemini-cli":"Gemini CLI","gemini-api":"Gemini API","codex-cli":"Codex CLI",api:"Anthropic API"},o=xe();e.send(JSON.stringify({type:"init",sessionId:t.id,themeName:t.themeName,modules:X().map(i=>i.moduleName),messageCount:t.messages.length,messages:t.messages,gitAvailable:Oe(),engine:n.aiEngine?s[n.aiEngine]||n.aiEngine:"",templateId:o?.id||null,pageType:o?.pageType||null,templates:(t.templates||[]).map(i=>({id:i.id,label:i.label,pageType:i.pageType,moduleCount:i.modules.length})),planMode:!!n.planMode,plan:t.brandAssets?.plan||""}))}else e.send(JSON.stringify({type:"needs_setup"}))}function Wp(e,t){let n=v();if(!n){t.writeHead(404,{"Content-Type":"text/plain"}),t.end("No session");return}let s=dt(n.themePath,"assets",e);if(!Pn(s)){t.writeHead(404,{"Content-Type":"text/plain"}),t.end("Asset not found");return}let o=Lc(s),i=Bc[o]||"application/octet-stream",a=Ii(s);t.writeHead(200,{"Content-Type":i,"Cache-Control":"no-cache"}),t.end(a)}function Hc(e,t,n,s){let i=dt(t,e==="/"?"/index.html":e);if(!Pn(i)){let c=dt(t,"index.html");if(Pn(c)){let d=Ii(c);s.writeHead(200,{"Content-Type":"text/html","Cache-Control":"no-cache"}),s.end(d)}else s.writeHead(404,{"Content-Type":"text/plain"}),s.end("Not found");return}let a=Lc(i),r=Bc[a]||"application/octet-stream",l=a===".html";try{let c=Ii(i),d='"'+Hp("md5").update(c).digest("hex").slice(0,16)+'"';if(n.headers["if-none-match"]===d){s.writeHead(304),s.end();return}s.writeHead(200,{"Content-Type":r,"Cache-Control":"no-cache",ETag:d}),s.end(c)}catch{s.writeHead(500,{"Content-Type":"text/plain"}),s.end("Internal Server Error")}}pe();var Kp=4200;async function Gc(){let e=Ys.hex("#e8613a"),t=Ys.dim;console.log(""),console.log(e(" v vibeSpot")),console.log(t(` Starting...
1813
- `));let n=zp();n||(console.error(Ys.red(" Could not find UI assets. Is the package installed correctly?")),process.exit(1));try{let{port:s,close:o}=await Uc({port:Kp,uiDir:n}),i=`http://localhost:${s}`;console.log(e(` v ${i}`)),console.log(t(` Press Ctrl+C to stop
1814
- `));try{process.platform==="darwin"?Ei("open",[i],{stdio:"ignore"}):process.platform==="win32"?Ei("cmd",["/c","start","",i],{stdio:"ignore"}):Ei("xdg-open",[i],{stdio:"ignore"})}catch{}await new Promise(a=>{process.on("SIGINT",()=>{console.log(t(`
1815
- Saving session...`)),j(),o(),console.log(t(` Goodbye!
1816
- `)),a(),setTimeout(()=>process.exit(0),500)})})}catch(s){console.error(Ys.red(` Failed to start: ${s instanceof Error?s.message:String(s)}`)),process.exit(1)}}function zp(){let e=[zs(import.meta.dirname,"../../ui"),zs(import.meta.dirname,"../ui"),zs(process.cwd(),"ui")];for(let t of e)if(Vp(zs(t,"index.html")))return t;return null}te();function Wc(){let e=new Yp;return e.name("vibespot").description("AI-powered HubSpot CMS landing page builder").version(Nt()).action(Gc),e.command("wizard").description("Classic CLI wizard \u2014 step-by-step conversion flow").action(Ar),e.command("init").description("Check and install required tools").action($r),e.command("convert").description("Convert a React project to HubSpot modules").action(Tr),e.command("upload").description("Upload theme to HubSpot").action(Ir),e.command("doctor").description("Diagnose environment issues").action(Er),e}var qp=Wc();qp.parseAsync(process.argv).catch(e=>{console.error(e),process.exit(1)});
2888
+ ${_.bold("1.")} Go to HubSpot ${_.muted("\u2192")} Content ${_.muted("\u2192")} Landing Pages ${_.muted("\u2192")} Create
2889
+ ${_.bold("2.")} Choose your uploaded theme from the theme picker
2890
+ ${_.bold("3.")} Select the landing page template that was just created
2891
+ ${_.bold("4.")} Your converted modules will appear \u2014 drag them onto the page
2892
+ ${_.bold("5.")} Click each section to edit text, images, and colors
2893
+ ${_.bold("6.")} Upload images via File Manager ${_.muted("(Settings \u2192 Files)")}
2894
+ ${_.bold("7.")} Preview and publish!`,"What's next"),await Ae({message:"Open HubSpot Landing Pages in your browser?"})){let c=e?`https://${r}/page-ui/${e}/management/pages/landing`:`https://${r}`;try{let d=process.platform;d==="darwin"?$i("open",[c],{stdio:"ignore"}):d==="win32"?$i("cmd",["/c","start","",c],{stdio:"ignore"}):$i("xdg-open",[c],{stdio:"ignore"}),G("Opening HubSpot Landing Pages...")}catch{j(`Open this URL in your browser: ${_.info(c)}`)}}let l=[];if(o&&v(n)&&l.push({path:n,label:`Cloned source (${sl(n)})`}),v(s)&&l.push({path:s,label:`Theme directory (${sl(s)})`}),l.length>0&&await Ae({message:"Clean up local working directories?"}))for(let d of l)try{og(d.path,{recursive:!0,force:!0}),G(`Removed ${d.label}`)}catch{ee(`Could not remove ${d.label} \u2014 delete manually if needed.`)}await pe(`Thanks for using hub${_.vibes("Vibes")}! ${_.vibes("~")}`)}Q();async function il(){Te();let t=await Ls(),e=await Js();Y({lastSourcePath:e.sourceDir});let n=await Us();Y({lastThemePath:n.themePath}),await qs({aiEngine:t.aiEngine,model:t.model,sourceDir:e.sourceDir,themePath:n.themePath}),await cn(n.themePath),await ol({portalId:t.portalId,sourceDir:e.sourceDir,themePath:n.themePath,wasCloned:e.wasCloned})}y();async function rl(){Te(),await Ls()}y();Bs();Q();Ye();async function al(){Te();let t=O();t.aiEngine||(z("AI engine not configured. Run `vibespot init` first or use the full wizard with `vibespot`."),process.exit(1));let e=await Js(),n=await Us();await qs({aiEngine:t.aiEngine,sourceDir:e.sourceDir,themePath:n.themePath})}y();Q();Ye();async function ll(){Te();let t=O();if(t.lastThemePath)if(await Ae({message:`Upload from ${t.lastThemePath}?`}))await cn(t.lastThemePath);else{let n=await be({message:"Path to your HubSpot theme directory:",placeholder:"./my-theme"});await cn(n)}else{let e=await be({message:"Path to your HubSpot theme directory:",placeholder:"./my-theme",validate:n=>n.trim()?void 0:"Path is required"});await cn(e)}}y();Ht();Q();Ye();at();async function cl(){Te(),await me("Environment Diagnostics");let t=0,e=En();e.found?Ns(e.version)?G(`Node.js v${e.version}`):(ee(`Node.js v${e.version} \u2014 too old (need 18+)`),j(" Update at https://nodejs.org"),t++):(z("Node.js \u2014 not installed"),j(" Install from https://nodejs.org"),t++);let n=In();n.found?G(`Git ${n.version}`):(z("Git \u2014 not installed"),j(" Install from https://git-scm.com"),t++);let s=ct();if(!s.found)ee("HubSpot CLI \u2014 not installed (only needed for deployment)"),j(" Install: npm install -g @hubspot/cli");else if(!ya(s.version))ee(`HubSpot CLI v${s.version} \u2014 too old (need v8+)`),j(" Update: npm install -g @hubspot/cli@latest"),t++;else{G(`HubSpot CLI v${s.version}`);let m=dt();m.authenticated?G(`HubSpot portal${m.portalName?`: ${m.portalName}`:""} (ID: ${m.portalId})`):(ee("HubSpot \u2014 not authenticated"),j(" Run: hs init"))}let o=Pn();o.found?G(`Claude Code ${o.version} at ${o.path}`):j(_.muted("Claude Code \u2014 not installed"));let i=Nn();i.found?G(`Gemini CLI ${i.version} at ${i.path}`):j(_.muted("Gemini CLI \u2014 not installed"));let r=On();r.found?G(`OpenAI Codex ${r.version} at ${r.path}`):j(_.muted("OpenAI Codex \u2014 not installed"));let a=O(),l=!!(a.anthropicApiKey||process.env.ANTHROPIC_API_KEY),c=!!(a.openaiApiKey||process.env.OPENAI_API_KEY),d=!!(a.geminiApiKey||process.env.GEMINI_API_KEY||process.env.GOOGLE_AI_API_KEY);l?G("Anthropic API key configured"):j(_.muted("Anthropic API key \u2014 not set")),c?G("OpenAI API key configured"):j(_.muted("OpenAI API key \u2014 not set")),d?G("Google AI API key configured"):j(_.muted("Google AI API key \u2014 not set"));let u={"claude-code":"Claude Code",api:"Anthropic API","anthropic-api":"Anthropic API","claude-oauth":"Claude (OAuth)","openai-api":"OpenAI API","gemini-api":"Gemini API","gemini-cli":"Gemini CLI","codex-cli":"OpenAI Codex"};a.aiEngine&&G(`AI engine: ${u[a.aiEngine]||a.aiEngine}`),a.lastThemePath&&j(_.muted(`Last theme: ${a.lastThemePath}`)),!o.found&&!i.found&&!r.found&&!l&&!c&&!d&&(ee("No AI engine available"),j(" Fastest: Set an API key (ANTHROPIC_API_KEY, OPENAI_API_KEY, or GEMINI_API_KEY)"),j(" Or install: Claude Code \u2014 https://claude.ai/code"),j(" Gemini CLI \u2014 https://github.com/google-gemini/gemini-cli"),j(" Codex CLI \u2014 https://github.com/openai/codex"),t++),console.log(),t===0?await pe("Everything looks good!"):await pe(_.warn(`${t} issue${t>1?"s":""} found \u2014 see above`))}y();ts();we();import{dirname as _b,join as oi}from"path";import{existsSync as Mb}from"fs";import{fileURLToPath as Eb}from"url";import{execFileSync as Zr}from"child_process";import ii from"chalk";var Gm=_b(Eb(import.meta.url)),Ib=4200;async function Wm(){let t=ii.hex("#e8613a"),e=ii.dim;console.log(""),console.log(t(" v vibeSpot")),console.log(e(` Starting...
2895
+ `));let n=Pb();n||(console.error(ii.red(" Could not find UI assets. Is the package installed correctly?")),process.exit(1));try{let{port:s,close:o}=await si({port:Ib,uiDir:n}),i=`http://localhost:${s}`;console.log(t(` v ${i}`)),console.log(e(` Press Ctrl+C to stop
2896
+ `));try{process.platform==="darwin"?Zr("open",[i],{stdio:"ignore"}):process.platform==="win32"?Zr("cmd",["/c","start","",i],{stdio:"ignore"}):Zr("xdg-open",[i],{stdio:"ignore"})}catch{}await new Promise(r=>{process.on("SIGINT",()=>{console.log(e(`
2897
+ Saving session...`)),D(),o(),console.log(e(` Goodbye!
2898
+ `)),r(),setTimeout(()=>process.exit(0),500)})})}catch(s){console.error(ii.red(` Failed to start: ${s instanceof Error?s.message:String(s)}`)),process.exit(1)}}function Pb(){let t=[oi(Gm,"../../ui"),oi(Gm,"../ui"),oi(process.cwd(),"ui")];for(let e of t)if(Mb(oi(e,"index.html")))return e;return null}y();import{resolve as Km}from"path";import{existsSync as Qr}from"fs";at();Ye();Q();zr();async function Vm(t={}){let e=await Ym(t.path);if(t.fix){let o=Qo(e);if(o.applied.length>0){G(`Applied ${o.applied.length} auto-fix${o.applied.length===1?"":"es"}:`);for(let i of o.applied)j(` ${i}`)}else j(_.muted("No auto-fixable issues found."));if(o.skipped.length>0)for(let i of o.skipped)ee(i)}let n=Ss(e);if(t.json){process.stdout.write(JSON.stringify(n,null,2)+`
2899
+ `),n.passed||process.exit(1);return}Te(),await me("Marketplace check");let s=`${n.errorCount} error${ta(n.errorCount)}, ${n.warningCount} warning${ta(n.warningCount)}, ${n.infoCount} note${ta(n.infoCount)}`;n.passed?G(`Theme passes Marketplace checks (${s}).`):z(`Theme is not yet ready: ${s}.`),ea("Errors",n.findings.filter(o=>o.severity==="error")),ea("Warnings",n.findings.filter(o=>o.severity==="warning")),ea("Notes",n.findings.filter(o=>o.severity==="info")),n.passed||(j(""),j(`Tip: run ${_.accent("vibespot marketplace check --fix")} to apply auto-fixable issues, then re-check.`),process.exit(1)),await pe("Looks good! Submit the theme via your HubSpot Marketplace dashboard.")}async function zm(t={}){let e=await Ym(t.path);Te(),await me("Marketplace listing details");let n=Tn(e)??{},s=await wt({message:"Category",options:Lt.map(u=>({value:u,label:u}))}),o=await be({message:"Description (1\u20132 sentences shown on the listing)",placeholder:"A clean, fast SaaS landing page theme...",defaultValue:n.description??"",validate:u=>u.trim().length<40?"Aim for at least 40 characters.":void 0}),r=(await be({message:"Key features (comma-separated, 2\u20135 items)",placeholder:"Hero, Pricing, Testimonials, Footer",defaultValue:(n.features??[]).join(", "),validate:u=>{let m=u.split(",").map(g=>g.trim()).filter(Boolean).length;if(m<2)return"Provide at least 2 features.";if(m>5)return"Provide at most 5 features."}})).split(",").map(u=>u.trim()).filter(Boolean),a=await be({message:"Public support URL",placeholder:"https://example.com/support",defaultValue:n.supportUrl??"",validate:u=>u&&!/^https?:\/\//i.test(u)?"Must start with http(s)://":void 0}),l=await be({message:"Documentation URL (optional)",placeholder:"https://example.com/docs",defaultValue:n.documentationUrl??"",validate:u=>u&&!/^https?:\/\//i.test(u)?"Must start with http(s)://":void 0}),c=await wt({message:"Pricing tier",options:[{value:"free",label:"Free"},{value:"paid",label:"Paid"}]}),d={category:s,description:o.trim(),features:r,supportUrl:a.trim()||void 0,documentationUrl:l.trim()||void 0,pricingTier:c,tags:n.tags};Zo(e,d),G("Saved marketplace.json"),await pe(`Run ${_.accent("vibespot marketplace check")} to confirm the theme is ready to submit.`)}async function Ym(t){if(t){let o=Km(t);if(!Qr(o))throw new Error(`Theme not found: ${o}`);return o}let e=O();if(e.lastThemePath&&Qr(e.lastThemePath))return e.lastThemePath;Te();let n=await be({message:"Path to your HubSpot theme directory:",placeholder:"./my-theme",validate:o=>o.trim()?void 0:"Path is required"}),s=Km(n);if(!Qr(s))throw new Error(`Theme not found: ${s}`);return s}function ea(t,e){if(e.length!==0){j(""),j(_.heading(t));for(let n of e){let s=n.file?_.muted(`[${n.file}] `):"",o=n.severity==="error"?_.error("\u2717"):n.severity==="warning"?_.warn("!"):_.muted("\xB7");j(` ${o} ${s}${n.message}`),n.fix&&j(` ${_.muted("\u2192 "+n.fix)}`)}}}function ta(t){return t===1?"":"s"}y();import{resolve as qm}from"path";import{existsSync as na}from"fs";import{basename as Rb}from"path";at();Ye();Q();bo();async function Xm(t={}){let e=await Nb(t.path),n=Rb(e);if(t.applyTokens){let i=yo(e,n);i?G(`Wrote design tokens to ${i}`):j(_.muted("Skipped: theme already has shared CSS or no tokens were inferred."))}if(t.snapshot){let i=Li(e);t.json||G(`Wrote imported theme snapshot to ${i}`)}let s=ho(e);t.json&&(process.stdout.write(JSON.stringify(s,null,2)+`
2900
+ `),process.exit(0)),Te(),await me("Inverse pipeline analyzer");let o=s.summary;if(j(`${_.heading("Summary")} ${o.moduleCount} module(s), ${o.templateCount} template(s), ${o.orphanCount} orphan, ${o.paletteSize} colour(s), ${o.cssVarCount} CSS var(s), ${o.customMacroCount} macro(s)`),s.designTokens.palette.length>0){j(""),j(_.heading("Palette (top by frequency)"));for(let i of s.designTokens.palette.slice(0,6)){let r=i.varName?_.muted(` (${i.varName})`):"";j(` ${i.value} ${_.muted(`\xD7${i.count}`)}${r}`)}}if(s.designTokens.fontFamilies.length>0){j(""),j(_.heading("Typography"));for(let i of s.designTokens.fontFamilies.slice(0,4))j(` ${i}`)}if(s.graph.templates.length>0){j(""),j(_.heading("Template \u2192 modules"));for(let i of s.graph.templates)j(` ${i.id}: ${i.modules.length===0?_.muted("(empty)"):i.modules.join(", ")}`)}if(s.graph.orphanModules.length>0){j(""),j(_.heading("Orphan modules"));for(let i of s.graph.orphanModules)j(` ${i}`)}if(s.roundTripDiff.hasSnapshot){j(""),j(_.heading("Round-trip diff"));let i=s.roundTripDiff;if(i.filesChanged===0)j(` ${_.muted("No changes from imported snapshot.")}`);else{j(` ${i.filesChanged} changed file(s): ${i.added} added, ${i.modified} modified, ${i.deleted} deleted`);for(let r of i.files.slice(0,12))j(` ${r.status.padEnd(8)} ${r.file}`);i.files.length>12&&j(` ${_.muted(`...and ${i.files.length-12} more`)}`)}}sa("Errors",s.findings.filter(i=>i.severity==="error")),sa("Warnings",s.findings.filter(i=>i.severity==="warning")),sa("Notes",s.findings.filter(i=>i.severity==="info")),!t.applyTokens&&s.summary.cssVarCount===0&&s.designTokens.palette.length>0&&(j(""),j(`Tip: run ${_.accent("vibespot inverse --apply-tokens")} to seed a :root block from the inferred palette.`)),await pe("Analysis complete."),process.exit(0)}async function Nb(t){if(t){let o=qm(t);if(!na(o))throw new Error(`Theme not found: ${o}`);return o}let e=O();if(e.lastThemePath&&na(e.lastThemePath))return e.lastThemePath;Te();let n=await be({message:"Path to the imported HubSpot theme directory:",placeholder:"./my-theme",validate:o=>o.trim()?void 0:"Path is required"}),s=qm(n);if(!na(s))throw new Error(`Theme not found: ${s}`);return s}function sa(t,e){if(e.length!==0){j(""),j(_.heading(t));for(let n of e){let s=n.file?_.muted(`[${n.file}] `):"",o=n.severity==="error"?_.error("\u2717"):n.severity==="warning"?_.warn("!"):_.muted("\xB7");j(` ${o} ${s}${n.message}`),n.fix&&j(` ${_.muted("\u2192 "+n.fix)}`)}}}y();ts();we();import{dirname as Ob,join as ri}from"path";import{existsSync as Fb}from"fs";import{fileURLToPath as jb}from"url";import{execFileSync as oa}from"child_process";import ai from"chalk";var Zm=Ob(jb(import.meta.url)),Db=4200;async function Qm(){let t=ai.hex("#e8613a"),e=ai.dim;console.log(""),console.log(t(" v vibeSpot \u2014 Email Mode")),console.log(e(` Starting...
2901
+ `));let n=Lb();n||(console.error(ai.red(" Could not find UI assets. Is the package installed correctly?")),process.exit(1));try{let{port:s,close:o}=await si({port:Db,uiDir:n,contentMode:"email"}),i=`http://localhost:${s}`;console.log(t(` v ${i}`)),console.log(e(` Email template mode \u2014 Press Ctrl+C to stop
2902
+ `));try{process.platform==="darwin"?oa("open",[i],{stdio:"ignore"}):process.platform==="win32"?oa("cmd",["/c","start","",i],{stdio:"ignore"}):oa("xdg-open",[i],{stdio:"ignore"})}catch{}await new Promise(r=>{process.on("SIGINT",()=>{console.log(e(`
2903
+ Saving session...`)),D(),o(),console.log(e(` Goodbye!
2904
+ `)),r(),setTimeout(()=>process.exit(0),500)})})}catch(s){console.error(ai.red(` Failed to start: ${s instanceof Error?s.message:String(s)}`)),process.exit(1)}}function Lb(){let t=[ri(Zm,"../../ui"),ri(Zm,"../ui"),ri(process.cwd(),"ui")];for(let e of t)if(Fb(ri(e,"index.html")))return e;return null}ne();function ep(){let t=new Jb;t.name("vibespot").description("AI-powered HubSpot CMS landing page builder").version(sn()).action(Wm),t.command("wizard").description("Classic CLI wizard \u2014 step-by-step conversion flow").action(il),t.command("init").description("Check and install required tools").action(rl),t.command("convert").description("Convert a React project to HubSpot modules").action(al),t.command("upload").description("Upload theme to HubSpot").action(ll),t.command("doctor").description("Diagnose environment issues").action(cl);let e=t.command("marketplace").description("Prepare a theme for HubSpot Marketplace submission");return e.command("check").description("Audit the theme against Marketplace requirements").option("-p, --path <path>","Path to the theme directory").option("--json","Emit machine-readable JSON instead of formatted output").option("--fix","Apply auto-fixable findings before checking").action(n=>Vm(n)),e.command("edit").description("Edit Marketplace listing metadata (marketplace.json)").option("-p, --path <path>","Path to the theme directory").action(n=>zm(n)),t.command("email").description("Launch email template generation mode").action(Qm),t.command("inverse").description("Analyze an imported HubSpot theme: design tokens, module graph, field flags, round-trip risks").option("-p, --path <path>","Path to the theme directory").option("--json","Emit machine-readable JSON instead of formatted output").option("--apply-tokens","Seed css/<theme>-theme.css with the inferred :root block when missing").option("--snapshot","Capture the current theme as the imported round-trip baseline before analysis").action(n=>Xm(n)),t}var Bb=ep();Bb.parseAsync(process.argv).catch(t=>{console.error(t),process.exit(1)});
1817
2905
  //# sourceMappingURL=index.js.map