vibespot 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var Nl=Object.defineProperty;var j=(e,t)=>()=>(e&&(t=e(e=0)),t);var tt=(e,t)=>{for(var n in t)Nl(e,n,{get:t[n],enumerable:!0})};import sm from"path";import{fileURLToPath as im}from"url";var g=j(()=>{"use strict"});import{readFileSync as Ts,writeFileSync as Rl,mkdirSync as Vo,existsSync as Sn}from"fs";import{dirname as Fl,join as Ve}from"path";function A(e){return Ts(e,"utf-8")}function H(e,t){Vo(Fl(e),{recursive:!0}),Rl(e,t,"utf-8")}function b(e){return Sn(e)}function Ae(e){Vo(e,{recursive:!0})}function vn(e){let t=[Ve(import.meta.dirname,"../../assets",e),Ve(import.meta.dirname,"../assets",e),Ve(process.cwd(),"assets",e)];for(let n of t)if(Sn(n))return n;throw new Error(`Asset not found: ${e}`)}function wt(){if(xt)return xt;let e=[Ve(import.meta.dirname,"../../package.json"),Ve(import.meta.dirname,"../package.json"),Ve(process.cwd(),"package.json")];for(let t of e)if(Sn(t))try{let n=JSON.parse(Ts(t,"utf-8"));if(n.name==="vibespot"&&n.version)return xt=n.version,xt}catch{}return xt="dev",xt}function Ko(){if(bn)return bn;let e=[Ve(import.meta.dirname,"../../CHANGELOG.md"),Ve(import.meta.dirname,"../CHANGELOG.md"),Ve(process.cwd(),"CHANGELOG.md")];for(let t of e)if(Sn(t))try{return bn=Ts(t,"utf-8"),bn}catch{}return""}var xt,bn,Q=j(()=>{"use strict";g();xt="";bn=""});import{execSync as Yo}from"child_process";function $(e,t={}){try{return{stdout:Yo(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 zo(e,t={}){try{return Yo(e,{stdio:"inherit",timeout:3e5,...t}),!0}catch{return!1}}var ut=j(()=>{"use strict";g()});var Qo={};tt(Qo,{addHubSpotAccount:()=>Jt,getActiveHubSpotAccount:()=>nt,getApiKeyForEngine:()=>ge,getConfigDir:()=>Dl,getHubSpotPak:()=>he,isCliToolEnabled:()=>Dt,loadConfig:()=>_,maskApiKey:()=>wn,removeHubSpotAccount:()=>$s,saveConfig:()=>K,setActiveHubSpotAccount:()=>Es,setCliToolEnabled:()=>_s});import{join as qo}from"path";import{homedir as jl}from"os";import{chmodSync as Jl}from"fs";function _(){if(!b(xn))return{};try{let e=JSON.parse(A(xn));return e.aiEngine==="api"&&(e.aiEngine="anthropic-api"),e}catch{return{}}}function ge(e,t){let n=t||_();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 wn(e){return e.length<=12?"***":e.slice(0,7)+"..."+e.slice(-4)}function K(e){let n={..._(),...e};if(H(xn,JSON.stringify(n,null,2)),process.platform!=="win32")try{Jl(xn,384)}catch{}}function Dl(){return Xo}function nt(){let e=_();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 Jt(e,t,n,s){let i=_().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),K({hubspotAccounts:i,activeHubSpotAccount:t})}function $s(e){let t=_(),n=(t.hubspotAccounts||[]).filter(o=>o.portalId!==e),s={hubspotAccounts:n};t.activeHubSpotAccount===e&&(s.activeHubSpotAccount=n[0]?.portalId||void 0),K(s)}function Es(e){K({activeHubSpotAccount:e})}function he(){return nt()?.personalAccessKey||null}function Dt(e){return _().enabledCLITools?.includes(e)??!1}function _s(e,t){let n=_(),s=new Set(n.enabledCLITools||[]);t?s.add(e):s.delete(e),K({enabledCLITools:[...s]})}var Xo,xn,Z=j(()=>{"use strict";g();Q();Xo=qo(jl(),".vibespot"),xn=qo(Xo,"config.json")});var Ms={};tt(Ms,{OAUTH_EXTRA_HEADERS:()=>Ht,OAUTH_SYSTEM_PREFIX:()=>At,clearOAuthTokens:()=>kn,getOAuthTokenInfo:()=>Lt,getValidAccessToken:()=>Os,hasValidOAuthToken:()=>Re,saveInitialToken:()=>Ps});import{join as Hl}from"path";import{homedir as Ll}from"os";import{chmodSync as Gl,unlinkSync as Ul}from"fs";function An(){if(!b(Ct))return null;try{return JSON.parse(A(Ct))}catch{return null}}function Zo(e){if(H(Ct,JSON.stringify(e,null,2)),process.platform!=="win32")try{Gl(Ct,384)}catch{}}async function Kl(e){let t=await fetch(Wl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"refresh_token",refresh_token:e,client_id:Bl})});if(!t.ok)throw kn(),new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let n=await t.json();Zo({access_token:n.access_token,refresh_token:n.refresh_token||e,expires_at:Date.now()+(n.expires_in||28800)*1e3})}function Ps(e,t=""){Zo({access_token:e,refresh_token:t,expires_at:Date.now()+28800*1e3})}function Re(){let e=An();return e?e.expires_at>Date.now():!1}async function Os(){let e=An();if(!e)return null;if(e.expires_at-Date.now()>Vl)return e.access_token;if(e.refresh_token){Cn||(Cn=Kl(e.refresh_token).finally(()=>{Cn=null}));try{await Cn}catch{return null}return An()?.access_token??null}return e.access_token}function Lt(){let e=An();return e?{expiresAt:new Date(e.expires_at).toISOString()}:null}function kn(){if(b(Ct))try{Ul(Ct)}catch{}}var Bl,Wl,Ct,Vl,Ht,At,Cn,Ke=j(()=>{"use strict";g();Q();Bl="9d1c250a-e61b-44d9-88ed-5944d1962f5e",Wl="https://console.anthropic.com/v1/oauth/token",Ct=Hl(Ll(),".vibespot","claude-oauth.json"),Vl=300*1e3,Ht={"user-agent":"claude-cli/2.1.75","x-app":"cli","anthropic-beta":"oauth-2025-04-20"},At="You are Claude Code, Anthropic's official CLI for Claude.";Cn=null});import{readFileSync as ql}from"fs";import{basename as Xl}from"path";async function oi(e){let t=si.get(e);if(t&&t.expiresAt-Date.now()>ec)return t;let n=await fetch(`${Ye}/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 si.set(e,o),o}async function kt(e){let{accessToken:t}=await oi(e);return{Authorization:`Bearer ${t}`}}function Pn(e){return e.replace(/^\/+/,"").split("/").filter(Boolean).map(encodeURIComponent).join("/")}function tc(e){return e.startsWith("pat-eu1-")?"eu1":e.startsWith("pat-na1-")?"na1":e.startsWith("CiRldTE")?"eu1":"na1"}function nc(e){return new Promise(t=>setTimeout(t,e))}async function Yt(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 zt(e,t,n=Ql){for(let s=0;s<=n;s++){let o=await fetch(e,t);if(o.status===429||o.status>=500&&s<n){let i=Zl*Math.pow(2,s);await nc(i);continue}return o}return fetch(e,t)}async function On(e){let t=await oi(e),n=`${Ye}/account-info/v3/details`,s=await zt(n,{headers:await kt(e)});if(!s.ok){let r=await Yt(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:tc(e)}}async function ii(e,t,n){let s=ql(n),o=Xl(n),i=new FormData,a=new Blob([s]);i.append("file",a,o);let r=`${Ye}/cms/v3/source-code/published/content/${Pn(t)}`,l=await zt(r,{method:"PUT",headers:await kt(e),body:i});if(!l.ok){let c=await Yt(l,t);return{success:!1,path:t,error:c}}return{success:!0,path:t}}async function js(e,t){let n=`${Ye}/cms/v3/source-code/published/content/${Pn(t)}`,s=await zt(n,{method:"DELETE",headers:await kt(e)});if(!s.ok&&s.status!==404){let o=await Yt(s,t);throw new Error(`Failed to delete ${t}: ${o.message}`)}}async function ri(e,t){let n=`${Ye}/cms/v3/source-code/published/content/${Pn(t)}`,s=await zt(n,{method:"GET",headers:await kt(e)});if(!s.ok){let i=await Yt(s,t);throw new Error(`Failed to download ${t}: ${i.message}`)}let o=await s.arrayBuffer();return Buffer.from(o)}async function Mn(e,t){let n=`${Ye}/cms/v3/source-code/published/metadata/${Pn(t)}`,s=await zt(n,{method:"GET",headers:await kt(e)});if(s.status===404)return null;if(!s.ok){let o=await Yt(s,t);throw new Error(`Failed to get metadata for ${t}: ${o.message}`)}return await s.json()}async function ai(e){let t=await kt(e),n=[`${Ye}/cms/v3/source-code/published/metadata`,`${Ye}/cms/v3/source-code/published/metadata/`,`${Ye}/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 Ye,Ql,Zl,ec,si,pt=j(()=>{"use strict";g();Ye="https://api.hubapi.com",Ql=3,Zl=1e3,ec=300*1e3,si=new Map});var pi={};tt(pi,{fetchTheme:()=>qt});import{mkdirSync as mi,writeFileSync as rc}from"fs";import{join as ac,dirname as lc}from"path";async function Ls(e,t){let n=await Mn(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 Ls(e,r));else{let l=i;l.folder?s.push(...await Ls(e,l.path||r)):s.push(l.path||r)}}return s}async function cc(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 qt(e,t,n,s={}){let o=s.concurrency??5,i=await Ls(e,t);if(i.length===0)throw new Error(`Theme "${t}" not found on HubSpot or is empty`);mi(n,{recursive:!0}),await cc(i,o,async a=>{let r=a.startsWith(t+"/")?a.slice(t.length+1):a,l=ac(n,r);mi(lc(l),{recursive:!0});let c=await ri(e,a);rc(l,c),s.onFile?.(r)})}var Jn=j(()=>{"use strict";g();pt()});function Tt(e){let t=fi.get(e);if(t!==void 0)return t;try{t=A(vn(e))}catch{t=""}return fi.set(e,t),t}function oe(){return Tt("conversion-guide.md")||"Conversion guide not found. Using built-in rules."}function Gs(){return Tt("design-guide.md")}function Us(){return Tt("content-guide.md")}function Ee(){return Tt("hubspot-rules.md")}function Bs(){return Tt("humanify-guide.md")}function Ws(e){let t=Tt("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(`
1
+ var Rl=Object.defineProperty;var j=(e,t)=>()=>(e&&(t=e(e=0)),t);var nt=(e,t)=>{for(var n in t)Rl(e,n,{get:t[n],enumerable:!0})};import rm from"path";import{fileURLToPath as lm}from"url";var g=j(()=>{"use strict"});import{readFileSync as Ts,writeFileSync as Fl,mkdirSync as Vo,existsSync as Sn}from"fs";import{dirname as jl,join as Ve}from"path";function A(e){return Ts(e,"utf-8")}function H(e,t){Vo(jl(e),{recursive:!0}),Fl(e,t,"utf-8")}function b(e){return Sn(e)}function Ae(e){Vo(e,{recursive:!0})}function vn(e){let t=[Ve(import.meta.dirname,"../../assets",e),Ve(import.meta.dirname,"../assets",e),Ve(process.cwd(),"assets",e)];for(let n of t)if(Sn(n))return n;throw new Error(`Asset not found: ${e}`)}function wt(){if(xt)return xt;let e=[Ve(import.meta.dirname,"../../package.json"),Ve(import.meta.dirname,"../package.json"),Ve(process.cwd(),"package.json")];for(let t of e)if(Sn(t))try{let n=JSON.parse(Ts(t,"utf-8"));if(n.name==="vibespot"&&n.version)return xt=n.version,xt}catch{}return xt="dev",xt}function Ko(){if(bn)return bn;let e=[Ve(import.meta.dirname,"../../CHANGELOG.md"),Ve(import.meta.dirname,"../CHANGELOG.md"),Ve(process.cwd(),"CHANGELOG.md")];for(let t of e)if(Sn(t))try{return bn=Ts(t,"utf-8"),bn}catch{}return""}var xt,bn,Q=j(()=>{"use strict";g();xt="";bn=""});import{execSync as Yo}from"child_process";function $(e,t={}){try{return{stdout:Yo(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 zo(e,t={}){try{return Yo(e,{stdio:"inherit",timeout:3e5,...t}),!0}catch{return!1}}var ut=j(()=>{"use strict";g()});var Qo={};nt(Qo,{addHubSpotAccount:()=>Jt,getActiveHubSpotAccount:()=>st,getApiKeyForEngine:()=>ge,getConfigDir:()=>Hl,getHubSpotPak:()=>he,isCliToolEnabled:()=>Dt,loadConfig:()=>_,maskApiKey:()=>wn,removeHubSpotAccount:()=>$s,saveConfig:()=>K,setActiveHubSpotAccount:()=>Es,setCliToolEnabled:()=>_s});import{join as qo}from"path";import{homedir as Jl}from"os";import{chmodSync as Dl}from"fs";function _(){if(!b(xn))return{};try{let e=JSON.parse(A(xn));return e.aiEngine==="api"&&(e.aiEngine="anthropic-api"),e}catch{return{}}}function ge(e,t){let n=t||_();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 wn(e){return e.length<=12?"***":e.slice(0,7)+"..."+e.slice(-4)}function K(e){let n={..._(),...e};if(H(xn,JSON.stringify(n,null,2)),process.platform!=="win32")try{Dl(xn,384)}catch{}}function Hl(){return Xo}function st(){let e=_();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 Jt(e,t,n,s){let i=_().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),K({hubspotAccounts:i,activeHubSpotAccount:t})}function $s(e){let t=_(),n=(t.hubspotAccounts||[]).filter(o=>o.portalId!==e),s={hubspotAccounts:n};t.activeHubSpotAccount===e&&(s.activeHubSpotAccount=n[0]?.portalId||void 0),K(s)}function Es(e){K({activeHubSpotAccount:e})}function he(){return st()?.personalAccessKey||null}function Dt(e){return _().enabledCLITools?.includes(e)??!1}function _s(e,t){let n=_(),s=new Set(n.enabledCLITools||[]);t?s.add(e):s.delete(e),K({enabledCLITools:[...s]})}var Xo,xn,Z=j(()=>{"use strict";g();Q();Xo=qo(Jl(),".vibespot"),xn=qo(Xo,"config.json")});var Os={};nt(Os,{OAUTH_EXTRA_HEADERS:()=>Ht,OAUTH_SYSTEM_PREFIX:()=>At,clearOAuthTokens:()=>kn,getOAuthTokenInfo:()=>Lt,getValidAccessToken:()=>Ms,hasValidOAuthToken:()=>Re,saveInitialToken:()=>Ps});import{join as Ll}from"path";import{homedir as Gl}from"os";import{chmodSync as Ul,unlinkSync as Bl}from"fs";function An(){if(!b(Ct))return null;try{return JSON.parse(A(Ct))}catch{return null}}function Zo(e){if(H(Ct,JSON.stringify(e,null,2)),process.platform!=="win32")try{Ul(Ct,384)}catch{}}async function Yl(e){let t=await fetch(Vl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"refresh_token",refresh_token:e,client_id:Wl})});if(!t.ok)throw kn(),new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let n=await t.json();Zo({access_token:n.access_token,refresh_token:n.refresh_token||e,expires_at:Date.now()+(n.expires_in||28800)*1e3})}function Ps(e,t=""){Zo({access_token:e,refresh_token:t,expires_at:Date.now()+28800*1e3})}function Re(){let e=An();return e?e.expires_at>Date.now():!1}async function Ms(){let e=An();if(!e)return null;if(e.expires_at-Date.now()>Kl)return e.access_token;if(e.refresh_token){Cn||(Cn=Yl(e.refresh_token).finally(()=>{Cn=null}));try{await Cn}catch{return null}return An()?.access_token??null}return e.access_token}function Lt(){let e=An();return e?{expiresAt:new Date(e.expires_at).toISOString()}:null}function kn(){if(b(Ct))try{Bl(Ct)}catch{}}var Wl,Vl,Ct,Kl,Ht,At,Cn,Ke=j(()=>{"use strict";g();Q();Wl="9d1c250a-e61b-44d9-88ed-5944d1962f5e",Vl="https://console.anthropic.com/v1/oauth/token",Ct=Ll(Gl(),".vibespot","claude-oauth.json"),Kl=300*1e3,Ht={"user-agent":"claude-cli/2.1.75","x-app":"cli","anthropic-beta":"oauth-2025-04-20"},At="You are Claude Code, Anthropic's official CLI for Claude.";Cn=null});import{readFileSync as Xl}from"fs";import{basename as Ql}from"path";async function oi(e){let t=si.get(e);if(t&&t.expiresAt-Date.now()>tc)return t;let n=await fetch(`${Ye}/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 si.set(e,o),o}async function kt(e){let{accessToken:t}=await oi(e);return{Authorization:`Bearer ${t}`}}function Pn(e){return e.replace(/^\/+/,"").split("/").filter(Boolean).map(encodeURIComponent).join("/")}function nc(e){return e.startsWith("pat-eu1-")?"eu1":e.startsWith("pat-na1-")?"na1":e.startsWith("CiRldTE")?"eu1":"na1"}function sc(e){return new Promise(t=>setTimeout(t,e))}async function Yt(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 zt(e,t,n=Zl){for(let s=0;s<=n;s++){let o=await fetch(e,t);if(o.status===429||o.status>=500&&s<n){let i=ec*Math.pow(2,s);await sc(i);continue}return o}return fetch(e,t)}async function Mn(e){let t=await oi(e),n=`${Ye}/account-info/v3/details`,s=await zt(n,{headers:await kt(e)});if(!s.ok){let r=await Yt(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:nc(e)}}async function ii(e,t,n){let s=Xl(n),o=Ql(n),i=new FormData,a=new Blob([s]);i.append("file",a,o);let r=`${Ye}/cms/v3/source-code/published/content/${Pn(t)}`,l=await zt(r,{method:"PUT",headers:await kt(e),body:i});if(!l.ok){let c=await Yt(l,t);return{success:!1,path:t,error:c}}return{success:!0,path:t}}async function js(e,t){let n=`${Ye}/cms/v3/source-code/published/content/${Pn(t)}`,s=await zt(n,{method:"DELETE",headers:await kt(e)});if(!s.ok&&s.status!==404){let o=await Yt(s,t);throw new Error(`Failed to delete ${t}: ${o.message}`)}}async function ri(e,t){let n=`${Ye}/cms/v3/source-code/published/content/${Pn(t)}`,s=await zt(n,{method:"GET",headers:await kt(e)});if(!s.ok){let i=await Yt(s,t);throw new Error(`Failed to download ${t}: ${i.message}`)}let o=await s.arrayBuffer();return Buffer.from(o)}async function On(e,t){let n=`${Ye}/cms/v3/source-code/published/metadata/${Pn(t)}`,s=await zt(n,{method:"GET",headers:await kt(e)});if(s.status===404)return null;if(!s.ok){let o=await Yt(s,t);throw new Error(`Failed to get metadata for ${t}: ${o.message}`)}return await s.json()}async function ai(e){let t=await kt(e),n=[`${Ye}/cms/v3/source-code/published/metadata`,`${Ye}/cms/v3/source-code/published/metadata/`,`${Ye}/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 Ye,Zl,ec,tc,si,pt=j(()=>{"use strict";g();Ye="https://api.hubapi.com",Zl=3,ec=1e3,tc=300*1e3,si=new Map});var pi={};nt(pi,{fetchTheme:()=>qt});import{mkdirSync as mi,writeFileSync as ac}from"fs";import{join as lc,dirname as cc}from"path";async function Ls(e,t){let n=await On(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 Ls(e,r));else{let l=i;l.folder?s.push(...await Ls(e,l.path||r)):s.push(l.path||r)}}return s}async function dc(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 qt(e,t,n,s={}){let o=s.concurrency??5,i=await Ls(e,t);if(i.length===0)throw new Error(`Theme "${t}" not found on HubSpot or is empty`);mi(n,{recursive:!0}),await dc(i,o,async a=>{let r=a.startsWith(t+"/")?a.slice(t.length+1):a,l=lc(n,r);mi(cc(l),{recursive:!0});let c=await ri(e,a);ac(l,c),s.onFile?.(r)})}var Jn=j(()=>{"use strict";g();pt()});function Tt(e){let t=fi.get(e);if(t!==void 0)return t;try{t=A(vn(e))}catch{t=""}return fi.set(e,t),t}function oe(){return Tt("conversion-guide.md")||"Conversion guide not found. Using built-in rules."}function Gs(){return Tt("design-guide.md")}function Us(){return Tt("content-guide.md")}function Ee(){return Tt("hubspot-rules.md")}function Bs(){return Tt("humanify-guide.md")}function Ws(e){let t=Tt("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(`
2
2
  ## `,o+s.length);return i>=0?t.slice(o,i).trim():t.slice(o).trim()}function gi(e){return`You are a HubSpot CMS expert converting React/Tailwind pages to native HubSpot modules.
3
3
 
4
4
  ## Rules
@@ -91,21 +91,21 @@ Template requirements:
91
91
  - Each module in its own dnd_section with padding zeroed and full_width=true
92
92
  - dnd_area label: "${t} Landing Page"
93
93
 
94
- Return ONLY the template HTML content, no markdown fences.`}var fi,qe=j(()=>{"use strict";g();Q();fi=new Map});var Ui=j(()=>{"use strict";g()});import{existsSync as Qe,writeFileSync as jc,mkdirSync as Jc}from"fs";import{join as He}from"path";function Wi(e){return/^[0-9a-f]{4,40}$/i.test(e)}function _e(){return Xn!==null||(Xn=$("git --version").success),Xn}function Qn(e){if(!_e())return!1;if(Qe(He(e,".git")))return Bi(e),!0;let t=$("git init",{cwd:e});return t.success?(Dc(e),Bi(e),$("git add -A",{cwd:e}),$('git commit -m "Initial theme"',{cwd:e}),!0):(console.warn(`[project-git] git init failed in ${e}: ${t.stderr}`),!1)}function Bi(e){let t=He(e,".vibespot");Qe(t)||Jc(t,{recursive:!0})}function Dc(e){let t=He(e,".gitignore");jc(t,[".vibespot/","node_modules/",""].join(`
94
+ Return ONLY the template HTML content, no markdown fences.`}var fi,qe=j(()=>{"use strict";g();Q();fi=new Map});var Ui=j(()=>{"use strict";g()});import{existsSync as Qe,writeFileSync as Jc,mkdirSync as Dc}from"fs";import{join as He}from"path";function Wi(e){return/^[0-9a-f]{4,40}$/i.test(e)}function _e(){return Xn!==null||(Xn=$("git --version").success),Xn}function Qn(e){if(!_e())return!1;if(Qe(He(e,".git")))return Bi(e),!0;let t=$("git init",{cwd:e});return t.success?(Hc(e),Bi(e),$("git add -A",{cwd:e}),$('git commit -m "Initial theme"',{cwd:e}),!0):(console.warn(`[project-git] git init failed in ${e}: ${t.stderr}`),!1)}function Bi(e){let t=He(e,".vibespot");Qe(t)||Dc(t,{recursive:!0})}function Hc(e){let t=He(e,".gitignore");Jc(t,[".vibespot/","node_modules/",""].join(`
95
95
  `),"utf-8")}function Ks(e,t){if(!_e()||!Qe(He(e,".git"))||($("git add -A",{cwd:e}),$("git diff --cached --quiet",{cwd:e}).success))return null;let s=t.length>72?t.slice(0,69)+"...":t,o=$(`git commit -m "${s.replace(/"/g,'\\"')}"`,{cwd:e});if(!o.success)return console.warn(`[project-git] commit failed: ${o.stderr}`),null;let i=$("git rev-parse --short HEAD",{cwd:e});return i.success?i.stdout:null}function Vi(e,t,n,s){if(!_e()||!Qe(He(e,".git")))return null;for(let u of s){let m=He(e,u);Qe(m)&&$(`git add "${u}"`,{cwd:e})}if($("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=$(`git commit -m "${l.replace(/"/g,'\\"')}"`,{cwd:e});if(!c.success)return console.warn(`[project-git] template commit failed: ${c.stderr}`),null;let d=$("git rev-parse --short HEAD",{cwd:e});return d.success?d.stdout:null}function Ki(e,t=50){if(!_e())return[];if(!Qe(He(e,".git")))return[];let n=$(`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(`
96
96
  `)){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 Yi(e,t,n=50){if(!_e())return[];if(!Qe(He(e,".git")))return[];let s=t.replace(/[[\]\\]/g,"\\$&"),o=$(`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(`
97
- `)){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 zi(e,t){if(!_e())return{success:!1,error:"Git not available"};if(!Qe(He(e,".git")))return{success:!1,error:"Not a git repo"};if(!Wi(t))return{success:!1,error:"Invalid commit hash"};let n=$(`git cat-file -t ${t}`,{cwd:e});if(!n.success||n.stdout.trim()!=="commit")return{success:!1,error:`Commit ${t} not found`};let s=$(`git log --format="%s" -1 ${t}`,{cwd:e}),o=s.success?s.stdout:t,i=$(`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 $(`git commit -m "${a.replace(/"/g,'\\"')}"`,{cwd:e}),{success:!0}}function qi(e,t,n,s){if(!_e())return{success:!1,error:"Git not available"};if(!Qe(He(e,".git")))return{success:!1,error:"Not a git repo"};if(!Wi(n))return{success:!1,error:"Invalid commit hash"};let o=$(`git cat-file -t ${n}`,{cwd:e});if(!o.success||o.stdout.trim()!=="commit")return{success:!1,error:`Commit ${n} not found`};let i=$(`git log --format="%s" -1 ${n}`,{cwd:e}),a=i.success?i.stdout:n,r=0;for(let d of s)$(`git checkout ${n} -- "${d}"`,{cwd:e}).success&&r++;if(r===0)return{success:!1,error:"No files could be restored from that commit"};$("git add -A",{cwd:e});let c=`${`[${t}] `}Rollback to: ${a}`.slice(0,72);return $(`git commit -m "${c.replace(/"/g,'\\"')}"`,{cwd:e}),{success:!0}}var Xn,Zt=j(()=>{"use strict";g();ut();Xn=null});import{readFileSync as Hc,existsSync as Xi,writeFileSync as Lc,mkdirSync as Gc,rmSync as Uc}from"fs";import{join as Zn}from"path";function ft(e){let t=S();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 ot(){let e=S();if(!e)return;let t=Ce();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 it(e,t,n){let s=S();if(!s)return;let o={role:e,content:t,timestamp:Date.now()};n&&(o.pipeline=n),s.messages.push(o),s.updatedAt=Date.now(),ot(),Bc()}function Qi(e){let t=S();t&&(t.assets||(t.assets=[]),t.assets.push(e),t.updatedAt=Date.now(),D())}function Le(e){let t=S();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);o>=0?t.modules[o]=n:(t.modules.push(n),t.moduleOrder.some(i=>i.toLowerCase()===s)||t.moduleOrder.push(n.moduleName))}t.updatedAt=Date.now(),ot()}}function Et(e){let t=S();t&&(t.moduleOrder=e,t.updatedAt=Date.now(),ot())}function Zi(e){let t=S();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=Zn(t.themePath,"modules",`${e}.module`);Xi(n)&&Uc(n,{recursive:!0,force:!0})}t.updatedAt=Date.now(),ot()}}function er(e){let t=S();t&&(t.moduleOrder=t.moduleOrder.filter(n=>n!==e),t.updatedAt=Date.now(),ot())}function tr(e,t,n){let s=S();if(!s)return;let o=s.modules.find(i=>i.moduleName===e);if(o)try{let i=JSON.parse(o.fieldsJson);sr(i,t,n),o.fieldsJson=JSON.stringify(i,null,2),s.updatedAt=Date.now(),ot()}catch{}}function me(){let e=S();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 Bc(){let e=S();if(e)try{let t=Zn(e.themePath,".vibespot");Gc(t,{recursive:!0});let n={sessionId:e.id,themeName:e.themeName,messages:e.messages,updatedAt:Date.now()};Lc(Zn(t,"chat.json"),JSON.stringify(n,null,2),"utf-8")}catch{}}function nr(e){let t=Zn(e,".vibespot","chat.json");if(!Xi(t))return[];try{let n=JSON.parse(Hc(t,"utf-8"));return Array.isArray(n.messages)?n.messages:[]}catch{return[]}}function sr(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&&sr(i.children,s.slice(1).join("."),n))}var es=j(()=>{"use strict";g();tn();en()});import{existsSync as Ys,rmSync as zs}from"fs";import{join as nn}from"path";function ts(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 Ce(){let e=S();return!e||!e.activeTemplateId||!e.templates?.length?null:e.templates.find(t=>t.id===e.activeTemplateId)||null}function qs(e){let t=S();if(!t)return!1;let n=t.templates.find(s=>s.id===e);return n?(t.activeTemplateId=e,ft(n),t.updatedAt=Date.now(),!0):!1}function or(e,t){let n=S();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,ft(a),n.updatedAt=Date.now(),a}function ir(e,t){let n=S();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,ft(l),n.updatedAt=Date.now(),l}function rr(e,t){let n=S();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 ar(e,t=!1){let n=S();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=nn(n.themePath,"templates"),a=`${o.id}.html`,r=nn(i,a);if(Ys(r)&&zs(r,{force:!0}),o.pageType==="blog_post"){let l=nn(i,`${o.id}-listing.html`);Ys(l)&&zs(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=nn(n.themePath,"modules");for(let l of a){let c=nn(r,`${l}.module`);Ys(c)&&zs(c,{recursive:!0,force:!0})}}}return n.activeTemplateId===e&&(n.templates.length>0?qs(n.templates[0].id):(n.activeTemplateId="",n.modules=[],n.moduleOrder=[],n.sharedCss="",n.sharedJs="",n.template="",n.messages=[])),n.updatedAt=Date.now(),!0}function rt(){let e=S();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 en=j(()=>{"use strict";g();tn();es()});import{readFileSync as Ze,readdirSync as to,existsSync as ye,writeFileSync as ns,mkdirSync as lr,rmSync as Xs,renameSync as Qs}from"fs";import{join as re,dirname as Wc}from"path";import{homedir as Vc}from"os";function ss(){if(_t)return _t;try{return ye(Zs)?(_t=JSON.parse(Ze(Zs,"utf-8")),_t):eo()}catch{return eo()}}function os(e){_t=e;try{lr(ne,{recursive:!0}),ns(Zs,JSON.stringify(e),"utf-8")}catch{}}function eo(){if(!ye(ne))return[];let e=[];for(let t of to(ne).filter(n=>n.endsWith(".json")&&n!=="_index.json"))try{let n=JSON.parse(Ze(re(ne,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 _t=e,os(e),e}function Kc(e){let t=ss(),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),os(t)}function Yc(e){let t=ss().filter(n=>n.id!==e);os(t)}function zc(e){let t=ss().filter(n=>n.themeName!==e);os(t)}function S(){return be}function qc(){return`vibe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function sn(e,t){let n={id:qc(),themePath:e,themeName:t,templates:[],activeTemplateId:"",messages:[],modules:[],sharedCss:"",sharedJs:"",template:"",moduleOrder:[],createdAt:Date.now(),updatedAt:Date.now()};return be=n,Qn(e),n}function D(){if(!be)return;lr(ne,{recursive:!0});let e=re(ne,`${be.id}.json`);ns(e,JSON.stringify(be,null,2),"utf-8"),Kc(be)}function is(e){let t=re(ne,e+".json");if(!ye(t))return null;try{let n=JSON.parse(Ze(t,"utf-8"));return n.templates||(n.templates=[]),n.activeTemplateId||(n.activeTemplateId=""),ts(n),be=n,n}catch{return null}}function Pt(){return ye(ne)?ss():[]}function cr(e,t=!1){let n=re(ne,e+".json"),s="";if(t)try{let o=JSON.parse(Ze(n,"utf-8"));s=o.themeName||"",o.themePath&&ye(o.themePath)&&Xs(o.themePath,{recursive:!0,force:!0})}catch{}else try{s=JSON.parse(Ze(n,"utf-8")).themeName||""}catch{}try{ye(n)&&Xs(n)}catch{}if(s&&ye(ne)){for(let o of to(ne).filter(i=>i.endsWith(".json")&&i!=="_index.json"))try{JSON.parse(Ze(re(ne,o),"utf-8")).themeName===s&&Xs(re(ne,o))}catch{}zc(s)}else Yc(e);be?.id===e&&(be=null)}function dr(e,t){let n=re(ne,e+".json");if(!ye(n))return{ok:!1,error:"Session not found"};let s;try{s=JSON.parse(Ze(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=re(Wc(i),t);if(ye(i)){if(ye(a))return{ok:!1,error:"A project with that name already exists"};try{Qs(i,a)}catch(m){return{ok:!1,error:`Failed to rename folder: ${m instanceof Error?m.message:String(m)}`}}let r=re(a,"css",`${o}-theme.css`),l=re(a,"css",`${t}-theme.css`);if(ye(r))try{Qs(r,l)}catch{}let c=re(a,"js",`${o}-animations.js`),d=re(a,"js",`${t}-animations.js`);if(ye(c))try{Qs(c,d)}catch{}let u=re(a,"theme.json");if(ye(u))try{let m=JSON.parse(Ze(u,"utf-8"));m.label=t,m.name=t,ns(u,JSON.stringify(m,null,2),"utf-8")}catch{}}if(ye(ne))for(let r of to(ne).filter(l=>l.endsWith(".json")&&l!=="_index.json"))try{let l=JSON.parse(Ze(re(ne,r),"utf-8"));l.themeName===o&&(l.themeName=t,l.themePath=a,l.updatedAt=Date.now(),ns(re(ne,r),JSON.stringify(l,null,2),"utf-8"))}catch{}return be&&be.themeName===o&&(be.themeName=t,be.themePath=a,be.updatedAt=Date.now()),eo(),{ok:!0}}var ne,Zs,_t,be,tn=j(()=>{"use strict";g();Zt();en();ne=re(Vc(),".vibespot","sessions"),Zs=re(ne,"_index.json"),_t=null;be=null});import{readFileSync as no,readdirSync as rn,existsSync as pe,writeFileSync as Ie,mkdirSync as on,rmSync as ur}from"fs";import{join as O}from"path";function ae(e){try{return no(e,"utf-8")}catch{return""}}function Xc(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 Qc(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 Zc(e,t,n,s,o){if(!pe(e))return[];let i=[],a=rn(e).filter(r=>r.endsWith(".html")&&r!=="home.html");for(let r of a){let l=O(e,r),c=Qc(l,r);if(!c||c.moduleNames.length===0&&i.length>0)continue;let d=[],u=[];for(let m of c.moduleNames){let f=t.get(m);f&&(d.push(f),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 an(e){let t=S();if(!t)return;let n=nr(e);n.length>0&&t.messages.length===0&&(t.messages=n),Qn(e);let s=O(e,"modules");if(!pe(s))return;let o=rn(s,{withFileTypes:!0});for(let y of o){if(!y.isDirectory()||!y.name.endsWith(".module"))continue;let v=O(s,y.name),C=y.name.replace(/\.module$/,""),k={moduleName:C,fieldsJson:ae(O(v,"fields.json")),metaJson:ae(O(v,"meta.json")),moduleHtml:ae(O(v,"module.html")),moduleCss:ae(O(v,"module.css")),moduleJs:ae(O(v,"module.js"))||void 0};k.fieldsJson&&k.moduleHtml&&(t.modules.push(k),t.moduleOrder.push(C))}let i=O(e,"css"),a=O(e,"js"),r="",l="";if(pe(i)){let y=rn(i).filter(v=>v.endsWith("-theme.css"));y.length>0&&(r=ae(O(i,y[0])),t.sharedCss=r)}if(pe(a)){let y=rn(a).filter(v=>v.endsWith("-animations.js"));y.length>0&&(l=ae(O(a,y[0])),t.sharedJs=l)}let c=O(e,".vibespot","styleguide.md"),d=O(e,".vibespot","brandvoice.md"),u=O(e,".vibespot","theme-context.md");(pe(c)||pe(d)||pe(u))&&(t.brandAssets||(t.brandAssets={}),pe(c)&&(t.brandAssets.styleguide=ae(c)),pe(d)&&(t.brandAssets.brandvoice=ae(d)),pe(u)&&(t.brandAssets.themeContext=ae(u)));let m=O(e,"templates"),f=new Map(t.modules.map(y=>[y.moduleName,y])),h=Zc(m,f,r,l,t.messages);if(h.length>0){t.templates=h,t.activeTemplateId=h[0].id;let y=h[0].moduleOrder;if(y.length>0){let v=new Set(t.moduleOrder),C=y.filter(k=>v.has(k));for(let k of t.moduleOrder)C.includes(k)||C.push(k);t.moduleOrder=C}ft(h[0])}else t.templates||(t.templates=[]),t.activeTemplateId||(t.activeTemplateId=""),ts(t)}function at(){let e=S();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=O(t,"modules");on(s,{recursive:!0});for(let l of n.values())on(O(s,`${l.moduleName}.module`),{recursive:!0});for(let l of n.values()){let c=O(s,`${l.moduleName}.module`);Ie(O(c,"fields.json"),l.fieldsJson,"utf-8"),Ie(O(c,"meta.json"),l.metaJson,"utf-8"),Ie(O(c,"module.html"),l.moduleHtml,"utf-8"),Ie(O(c,"module.css"),l.moduleCss,"utf-8"),l.moduleJs&&Ie(O(c,"module.js"),l.moduleJs,"utf-8")}if(e.sharedCss){let l=O(t,"css");on(l,{recursive:!0}),Ie(O(l,`${e.themeName}-theme.css`),e.sharedCss,"utf-8")}if(e.sharedJs){let l=O(t,"js");on(l,{recursive:!0}),Ie(O(l,`${e.themeName}-animations.js`),e.sharedJs,"utf-8")}let o=O(t,"templates");on(o,{recursive:!0});let i=O(o,"home.html");(e.templates.length>0||e.modules.length>0)&&pe(i)&&ur(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||nd(l),d=mr(c,l.label,l.pageType),u=`${l.id}.html`;Ie(O(o,u),d,"utf-8"),r.add(u),l.pageType==="blog_post"&&(sd(o,l),r.add(`${l.id}-listing.html`))}else if(e.modules.length>0){let l=e.template||od(),c=mr(l,`${e.themeName} Landing Page`),d=`lp-${e.themeName}.html`;Ie(O(o,d),c,"utf-8"),r.add(d)}try{for(let l of rn(o))l.startsWith("lp-")&&l.endsWith(".html")&&!r.has(l)&&ur(O(o,l),{force:!0})}catch{}ed(),td()}function pr(){let e=S();e&&(e.modules=[],e.moduleOrder=[],e.sharedCss="",e.sharedJs="",e.template="",an(e.themePath),e.updatedAt=Date.now(),ot())}function fr(){let e=S();if(!e)return;let t=Ce();if(!t)return;let n=e.themePath,s=O(n,"modules");t.modules=[];for(let o of t.moduleOrder){let i=O(s,`${o}.module`);if(!pe(i))continue;let a={moduleName:o,fieldsJson:ae(O(i,"fields.json")),metaJson:ae(O(i,"meta.json")),moduleHtml:ae(O(i,"module.html")),moduleCss:ae(O(i,"module.css")),moduleJs:ae(O(i,"module.js"))||void 0};a.fieldsJson&&a.moduleHtml&&t.modules.push(a)}if(t.templateFile){let o=O(n,t.templateFile);pe(o)&&(t.template=ae(o))}ft(t),e.updatedAt=Date.now()}function ed(){let e=S();if(!e)return;let t=O(e.themePath,"templates","layouts","base.html");if(pe(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+`
97
+ `)){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 zi(e,t){if(!_e())return{success:!1,error:"Git not available"};if(!Qe(He(e,".git")))return{success:!1,error:"Not a git repo"};if(!Wi(t))return{success:!1,error:"Invalid commit hash"};let n=$(`git cat-file -t ${t}`,{cwd:e});if(!n.success||n.stdout.trim()!=="commit")return{success:!1,error:`Commit ${t} not found`};let s=$(`git log --format="%s" -1 ${t}`,{cwd:e}),o=s.success?s.stdout:t,i=$(`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 $(`git commit -m "${a.replace(/"/g,'\\"')}"`,{cwd:e}),{success:!0}}function qi(e,t,n,s){if(!_e())return{success:!1,error:"Git not available"};if(!Qe(He(e,".git")))return{success:!1,error:"Not a git repo"};if(!Wi(n))return{success:!1,error:"Invalid commit hash"};let o=$(`git cat-file -t ${n}`,{cwd:e});if(!o.success||o.stdout.trim()!=="commit")return{success:!1,error:`Commit ${n} not found`};let i=$(`git log --format="%s" -1 ${n}`,{cwd:e}),a=i.success?i.stdout:n,r=0;for(let d of s)$(`git checkout ${n} -- "${d}"`,{cwd:e}).success&&r++;if(r===0)return{success:!1,error:"No files could be restored from that commit"};$("git add -A",{cwd:e});let c=`${`[${t}] `}Rollback to: ${a}`.slice(0,72);return $(`git commit -m "${c.replace(/"/g,'\\"')}"`,{cwd:e}),{success:!0}}var Xn,Zt=j(()=>{"use strict";g();ut();Xn=null});import{readFileSync as Lc,existsSync as Xi,writeFileSync as Gc,mkdirSync as Uc,rmSync as Bc}from"fs";import{join as Zn}from"path";function ft(e){let t=S();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 it(){let e=S();if(!e)return;let t=Ce();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 rt(e,t,n){let s=S();if(!s)return;let o={role:e,content:t,timestamp:Date.now()};n&&(o.pipeline=n),s.messages.push(o),s.updatedAt=Date.now(),it(),Wc()}function Qi(e){let t=S();t&&(t.assets||(t.assets=[]),t.assets.push(e),t.updatedAt=Date.now(),D())}function Le(e){let t=S();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);o>=0?t.modules[o]=n:(t.modules.push(n),t.moduleOrder.some(i=>i.toLowerCase()===s)||t.moduleOrder.push(n.moduleName))}t.updatedAt=Date.now(),it()}}function Et(e){let t=S();t&&(t.moduleOrder=e,t.updatedAt=Date.now(),it())}function Zi(e){let t=S();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=Zn(t.themePath,"modules",`${e}.module`);Xi(n)&&Bc(n,{recursive:!0,force:!0})}t.updatedAt=Date.now(),it()}}function er(e){let t=S();t&&(t.moduleOrder=t.moduleOrder.filter(n=>n!==e),t.updatedAt=Date.now(),it())}function tr(e,t,n){let s=S();if(!s)return;let o=s.modules.find(i=>i.moduleName===e);if(o)try{let i=JSON.parse(o.fieldsJson);sr(i,t,n),o.fieldsJson=JSON.stringify(i,null,2),s.updatedAt=Date.now(),it()}catch{}}function me(){let e=S();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 Wc(){let e=S();if(e)try{let t=Zn(e.themePath,".vibespot");Uc(t,{recursive:!0});let n={sessionId:e.id,themeName:e.themeName,messages:e.messages,updatedAt:Date.now()};Gc(Zn(t,"chat.json"),JSON.stringify(n,null,2),"utf-8")}catch{}}function nr(e){let t=Zn(e,".vibespot","chat.json");if(!Xi(t))return[];try{let n=JSON.parse(Lc(t,"utf-8"));return Array.isArray(n.messages)?n.messages:[]}catch{return[]}}function sr(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&&sr(i.children,s.slice(1).join("."),n))}var es=j(()=>{"use strict";g();tn();en()});import{existsSync as Ys,rmSync as zs}from"fs";import{join as nn}from"path";function ts(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 Ce(){let e=S();return!e||!e.activeTemplateId||!e.templates?.length?null:e.templates.find(t=>t.id===e.activeTemplateId)||null}function qs(e){let t=S();if(!t)return!1;let n=t.templates.find(s=>s.id===e);return n?(t.activeTemplateId=e,ft(n),t.updatedAt=Date.now(),!0):!1}function or(e,t){let n=S();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,ft(a),n.updatedAt=Date.now(),a}function ir(e,t){let n=S();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,ft(l),n.updatedAt=Date.now(),l}function rr(e,t){let n=S();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 ar(e,t=!1){let n=S();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=nn(n.themePath,"templates"),a=`${o.id}.html`,r=nn(i,a);if(Ys(r)&&zs(r,{force:!0}),o.pageType==="blog_post"){let l=nn(i,`${o.id}-listing.html`);Ys(l)&&zs(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=nn(n.themePath,"modules");for(let l of a){let c=nn(r,`${l}.module`);Ys(c)&&zs(c,{recursive:!0,force:!0})}}}return n.activeTemplateId===e&&(n.templates.length>0?qs(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=S();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 en=j(()=>{"use strict";g();tn();es()});import{readFileSync as Ze,readdirSync as to,existsSync as ye,writeFileSync as ns,mkdirSync as lr,rmSync as Xs,renameSync as Qs}from"fs";import{join as re,dirname as Vc}from"path";import{homedir as Kc}from"os";function ss(){if(_t)return _t;try{return ye(Zs)?(_t=JSON.parse(Ze(Zs,"utf-8")),_t):eo()}catch{return eo()}}function os(e){_t=e;try{lr(ne,{recursive:!0}),ns(Zs,JSON.stringify(e),"utf-8")}catch{}}function eo(){if(!ye(ne))return[];let e=[];for(let t of to(ne).filter(n=>n.endsWith(".json")&&n!=="_index.json"))try{let n=JSON.parse(Ze(re(ne,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 _t=e,os(e),e}function Yc(e){let t=ss(),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),os(t)}function zc(e){let t=ss().filter(n=>n.id!==e);os(t)}function qc(e){let t=ss().filter(n=>n.themeName!==e);os(t)}function S(){return be}function Xc(){return`vibe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function sn(e,t){let n={id:Xc(),themePath:e,themeName:t,templates:[],activeTemplateId:"",messages:[],modules:[],sharedCss:"",sharedJs:"",template:"",moduleOrder:[],createdAt:Date.now(),updatedAt:Date.now()};return be=n,Qn(e),n}function D(){if(!be)return;lr(ne,{recursive:!0});let e=re(ne,`${be.id}.json`);ns(e,JSON.stringify(be,null,2),"utf-8"),Yc(be)}function is(e){let t=re(ne,e+".json");if(!ye(t))return null;try{let n=JSON.parse(Ze(t,"utf-8"));return n.templates||(n.templates=[]),n.activeTemplateId||(n.activeTemplateId=""),ts(n),be=n,n}catch{return null}}function Pt(){return ye(ne)?ss():[]}function cr(e,t=!1){let n=re(ne,e+".json"),s="";if(t)try{let o=JSON.parse(Ze(n,"utf-8"));s=o.themeName||"",o.themePath&&ye(o.themePath)&&Xs(o.themePath,{recursive:!0,force:!0})}catch{}else try{s=JSON.parse(Ze(n,"utf-8")).themeName||""}catch{}try{ye(n)&&Xs(n)}catch{}if(s&&ye(ne)){for(let o of to(ne).filter(i=>i.endsWith(".json")&&i!=="_index.json"))try{JSON.parse(Ze(re(ne,o),"utf-8")).themeName===s&&Xs(re(ne,o))}catch{}qc(s)}else zc(e);be?.id===e&&(be=null)}function dr(e,t){let n=re(ne,e+".json");if(!ye(n))return{ok:!1,error:"Session not found"};let s;try{s=JSON.parse(Ze(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=re(Vc(i),t);if(ye(i)){if(ye(a))return{ok:!1,error:"A project with that name already exists"};try{Qs(i,a)}catch(m){return{ok:!1,error:`Failed to rename folder: ${m instanceof Error?m.message:String(m)}`}}let r=re(a,"css",`${o}-theme.css`),l=re(a,"css",`${t}-theme.css`);if(ye(r))try{Qs(r,l)}catch{}let c=re(a,"js",`${o}-animations.js`),d=re(a,"js",`${t}-animations.js`);if(ye(c))try{Qs(c,d)}catch{}let u=re(a,"theme.json");if(ye(u))try{let m=JSON.parse(Ze(u,"utf-8"));m.label=t,m.name=t,ns(u,JSON.stringify(m,null,2),"utf-8")}catch{}}if(ye(ne))for(let r of to(ne).filter(l=>l.endsWith(".json")&&l!=="_index.json"))try{let l=JSON.parse(Ze(re(ne,r),"utf-8"));l.themeName===o&&(l.themeName=t,l.themePath=a,l.updatedAt=Date.now(),ns(re(ne,r),JSON.stringify(l,null,2),"utf-8"))}catch{}return be&&be.themeName===o&&(be.themeName=t,be.themePath=a,be.updatedAt=Date.now()),eo(),{ok:!0}}var ne,Zs,_t,be,tn=j(()=>{"use strict";g();Zt();en();ne=re(Kc(),".vibespot","sessions"),Zs=re(ne,"_index.json"),_t=null;be=null});import{readFileSync as no,readdirSync as rn,existsSync as pe,writeFileSync as Ie,mkdirSync as on,rmSync as ur}from"fs";import{join as M}from"path";function ae(e){try{return no(e,"utf-8")}catch{return""}}function Qc(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 Zc(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 ed(e,t,n,s,o){if(!pe(e))return[];let i=[],a=rn(e).filter(r=>r.endsWith(".html")&&r!=="home.html");for(let r of a){let l=M(e,r),c=Zc(l,r);if(!c||c.moduleNames.length===0&&i.length>0)continue;let d=[],u=[];for(let m of c.moduleNames){let f=t.get(m);f&&(d.push(f),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 an(e){let t=S();if(!t)return;let n=nr(e);n.length>0&&t.messages.length===0&&(t.messages=n),Qn(e);let s=M(e,"modules");if(!pe(s))return;let o=rn(s,{withFileTypes:!0});for(let y of o){if(!y.isDirectory()||!y.name.endsWith(".module"))continue;let v=M(s,y.name),C=y.name.replace(/\.module$/,""),k={moduleName:C,fieldsJson:ae(M(v,"fields.json")),metaJson:ae(M(v,"meta.json")),moduleHtml:ae(M(v,"module.html")),moduleCss:ae(M(v,"module.css")),moduleJs:ae(M(v,"module.js"))||void 0};k.fieldsJson&&k.moduleHtml&&(t.modules.push(k),t.moduleOrder.push(C))}let i=M(e,"css"),a=M(e,"js"),r="",l="";if(pe(i)){let y=rn(i).filter(v=>v.endsWith("-theme.css"));y.length>0&&(r=ae(M(i,y[0])),t.sharedCss=r)}if(pe(a)){let y=rn(a).filter(v=>v.endsWith("-animations.js"));y.length>0&&(l=ae(M(a,y[0])),t.sharedJs=l)}let c=M(e,".vibespot","styleguide.md"),d=M(e,".vibespot","brandvoice.md"),u=M(e,".vibespot","theme-context.md");(pe(c)||pe(d)||pe(u))&&(t.brandAssets||(t.brandAssets={}),pe(c)&&(t.brandAssets.styleguide=ae(c)),pe(d)&&(t.brandAssets.brandvoice=ae(d)),pe(u)&&(t.brandAssets.themeContext=ae(u)));let m=M(e,"templates"),f=new Map(t.modules.map(y=>[y.moduleName,y])),h=ed(m,f,r,l,t.messages);if(h.length>0){t.templates=h,t.activeTemplateId=h[0].id;let y=h[0].moduleOrder;if(y.length>0){let v=new Set(t.moduleOrder),C=y.filter(k=>v.has(k));for(let k of t.moduleOrder)C.includes(k)||C.push(k);t.moduleOrder=C}ft(h[0])}else t.templates||(t.templates=[]),t.activeTemplateId||(t.activeTemplateId=""),ts(t)}function lt(){let e=S();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=M(t,"modules");on(s,{recursive:!0});for(let l of n.values())on(M(s,`${l.moduleName}.module`),{recursive:!0});for(let l of n.values()){let c=M(s,`${l.moduleName}.module`);Ie(M(c,"fields.json"),l.fieldsJson,"utf-8"),Ie(M(c,"meta.json"),l.metaJson,"utf-8"),Ie(M(c,"module.html"),l.moduleHtml,"utf-8"),Ie(M(c,"module.css"),l.moduleCss,"utf-8"),l.moduleJs&&Ie(M(c,"module.js"),l.moduleJs,"utf-8")}if(e.sharedCss){let l=M(t,"css");on(l,{recursive:!0}),Ie(M(l,`${e.themeName}-theme.css`),e.sharedCss,"utf-8")}if(e.sharedJs){let l=M(t,"js");on(l,{recursive:!0}),Ie(M(l,`${e.themeName}-animations.js`),e.sharedJs,"utf-8")}let o=M(t,"templates");on(o,{recursive:!0});let i=M(o,"home.html");(e.templates.length>0||e.modules.length>0)&&pe(i)&&ur(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||sd(l),d=mr(c,l.label,l.pageType),u=`${l.id}.html`;Ie(M(o,u),d,"utf-8"),r.add(u),l.pageType==="blog_post"&&(od(o,l),r.add(`${l.id}-listing.html`))}else if(e.modules.length>0){let l=e.template||id(),c=mr(l,`${e.themeName} Landing Page`),d=`lp-${e.themeName}.html`;Ie(M(o,d),c,"utf-8"),r.add(d)}try{for(let l of rn(o))l.startsWith("lp-")&&l.endsWith(".html")&&!r.has(l)&&ur(M(o,l),{force:!0})}catch{}td(),nd()}function pr(){let e=S();e&&(e.modules=[],e.moduleOrder=[],e.sharedCss="",e.sharedJs="",e.template="",an(e.themePath),e.updatedAt=Date.now(),it())}function fr(){let e=S();if(!e)return;let t=Ce();if(!t)return;let n=e.themePath,s=M(n,"modules");t.modules=[];for(let o of t.moduleOrder){let i=M(s,`${o}.module`);if(!pe(i))continue;let a={moduleName:o,fieldsJson:ae(M(i,"fields.json")),metaJson:ae(M(i,"meta.json")),moduleHtml:ae(M(i,"module.html")),moduleCss:ae(M(i,"module.css")),moduleJs:ae(M(i,"module.js"))||void 0};a.fieldsJson&&a.moduleHtml&&t.modules.push(a)}if(t.templateFile){let o=M(n,t.templateFile);pe(o)&&(t.template=ae(o))}ft(t),e.updatedAt=Date.now()}function td(){let e=S();if(!e)return;let t=M(e.themePath,"templates","layouts","base.html");if(pe(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+`
98
98
  {% if template_js %}
99
99
  {{ require_js(get_asset_url(template_js)) }}
100
100
  {% endif %}`):n=n.replace("{{ standard_footer_includes }}",`{% if template_js %}
101
101
  {{ require_js(get_asset_url(template_js)) }}
102
102
  {% endif %}
103
- {{ standard_footer_includes }}`),Ie(t,n,"utf-8")}catch{}}function td(){let e=S();if(!e)return;let t=O(e.themePath,"theme.json");if(pe(t))try{let n=JSON.parse(no(t,"utf-8"));n.label=e.themeName,n.name=e.themeName,Ie(t,JSON.stringify(n,null,2),"utf-8")}catch{}}function mr(e,t,n="landing_page"){return e.includes("templateType")?e:`<!--
103
+ {{ standard_footer_includes }}`),Ie(t,n,"utf-8")}catch{}}function nd(){let e=S();if(!e)return;let t=M(e.themePath,"theme.json");if(pe(t))try{let n=JSON.parse(no(t,"utf-8"));n.label=e.themeName,n.name=e.themeName,Ie(t,JSON.stringify(n,null,2),"utf-8")}catch{}}function mr(e,t,n="landing_page"){return e.includes("templateType")?e:`<!--
104
104
  templateType: ${n==="blog_post"?"blog_post":"page"}
105
105
  isAvailableForNewContent: true
106
106
  label: "${t}"
107
107
  -->
108
- `+e}function nd(e){if(e.modules.length===0)return"";let n=S().themeName,o=Xc(e).map(a=>` {% dnd_section padding={"top":"0","bottom":"0","left":"0","right":"0"}, full_width=true %}
108
+ `+e}function sd(e){if(e.modules.length===0)return"";let n=S().themeName,o=Qc(e).map(a=>` {% dnd_section padding={"top":"0","bottom":"0","left":"0","right":"0"}, full_width=true %}
109
109
  {% dnd_module path="../modules/${a.moduleName}.module" %}
110
110
  {% end_dnd_module %}
111
111
  {% end_dnd_section %}`).join(`
@@ -136,7 +136,7 @@ ${o}
136
136
 
137
137
  {% block footer %}
138
138
  {% endblock footer %}
139
- `}function sd(e,t){let n=`<!--
139
+ `}function od(e,t){let n=`<!--
140
140
  templateType: blog_listing
141
141
  isAvailableForNewContent: true
142
142
  label: "${t.label} - Listing"
@@ -161,7 +161,7 @@ ${o}
161
161
  {% endif %}
162
162
  </div>
163
163
  {% endblock body %}
164
- `;Ie(O(e,`${t.id}-listing.html`),n,"utf-8")}function od(){let e=S();if(!e||e.modules.length===0)return"";let t=e.themeName,s=me().map(o=>` {% dnd_section padding={"top":"0","bottom":"0","left":"0","right":"0"}, full_width=true %}
164
+ `;Ie(M(e,`${t.id}-listing.html`),n,"utf-8")}function id(){let e=S();if(!e||e.modules.length===0)return"";let t=e.themeName,s=me().map(o=>` {% dnd_section padding={"top":"0","bottom":"0","left":"0","right":"0"}, full_width=true %}
165
165
  {% dnd_module path="../modules/${o.moduleName}.module" %}
166
166
  {% end_dnd_module %}
167
167
  {% end_dnd_section %}`).join(`
@@ -192,7 +192,7 @@ ${s}
192
192
 
193
193
  {% block footer %}
194
194
  {% endblock footer %}
195
- `}var gr=j(()=>{"use strict";g();tn();es();en();Zt()});var hr=j(()=>{"use strict";g();Ui();tn();es();gr();en()});var Se=j(()=>{"use strict";g();hr()});function rs(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]=rs(n.children):t[n.name]=n.default??"";return t}function oo(e,t){let n=e;return n=pd(n),n=vr(n,t),n=xr(n,t),n=wr(n,t),n=gd(n),n}function io(e){let t=[e.sharedCss||"",...e.moduleCssArray].filter(Boolean).map(o=>`<style>${o}</style>`).join(`
195
+ `}var gr=j(()=>{"use strict";g();tn();es();en();Zt()});var hr=j(()=>{"use strict";g();Ui();tn();es();gr();en()});var Se=j(()=>{"use strict";g();hr()});function rs(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]=rs(n.children):t[n.name]=n.default??"";return t}function oo(e,t){let n=e;return n=fd(n),n=vr(n,t),n=xr(n,t),n=wr(n,t),n=hd(n),n}function io(e){let t=[e.sharedCss||"",...e.moduleCssArray].filter(Boolean).map(o=>`<style>${o}</style>`).join(`
196
196
  `),n=[e.sharedJs||"",...e.moduleJsArray].filter(Boolean).map(o=>`<script>${o}</script>`).join(`
197
197
  `),s=e.renderedModules.join(`
198
198
  `);return`<!DOCTYPE html>
@@ -239,7 +239,7 @@ document.querySelectorAll('img').forEach(function(img){
239
239
  });
240
240
  </script>
241
241
  </body>
242
- </html>`}function pd(e){return e=e.replace(id,""),e=e.replace(rd,""),e=e.replace(ad,""),yr.lastIndex=0,e=e.replace(yr,(t,n)=>`/theme-assets/${n}`),br.lastIndex=0,e=e.replace(br,""),e=e.replace(ld,""),e=e.replace(cd,""),e=e.replace(dd,""),e=e.replace(ud,""),e=e.replace(md,""),e}function vr(e,t){let n=e,s=0;for(;s<30;){s++;let o=fd(n);if(!o)break;let{varName:i,iterExpr:a,body:r,start:l,end:c}=o,d=hd(a,t),u="";Array.isArray(d)&&(u=d.map((m,f)=>{let h={...t,[i]:m,loop:{index:f+1,index0:f,first:f===0,last:f===d.length-1,length:d.length}},y=vr(r,h);return y=xr(y,h),y=wr(y,h),y}).join("")),n=n.slice(0,l)+u+n.slice(c)}return n}function fd(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 xr(e,t){let n=e,s=0;for(;so.test(n)&&s<50;)s++,n=n.replace(so,(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(Ot(i,t))return d[0];for(let u=1;u<d.length;u+=2){let m=d[u],f=d[u+1]||"";if(Ot(m,t))return f}return c}return Ot(i,t)?l:c}),so.lastIndex=0;return n}function wr(e,t){return e.replace(/\{\{[-\s]*(.*?)[-\s]*\}\}/g,(n,s)=>{let i=s.trim().split("|"),a=i[0].trim(),r=gt(t,a);for(let c=1;c<i.length;c++)r=Ar(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 gd(e){return e=e.replace(/\{%.*?%\}/gs,""),e=e.replace(/\{\{.*?\}\}/gs,""),e}function hd(e,t){let n=e.match(/^range\(\s*(.+?)\s*,\s*(.+?)\s*\)$/);if(n){let o=Sr(n[1],t),i=Sr(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=gt(t,s[1].trim());return typeof o=="string"?o.split(s[2]):[]}return gt(t,e)}function Sr(e,t){let s=e.trim().split("|"),o=s[0].trim();if(!isNaN(Number(o)))return Number(o);let i=gt(t,o);for(let a=1;a<s.length;a++)i=Ar(i,s[a].trim());return Number(i)||0}function gt(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 Ot(e,t){let n=e.trim();if(n.startsWith("not "))return!Ot(n.slice(4),t);if(n.includes(" and "))return n.split(" and ").every(i=>Ot(i,t));if(n.includes(" or "))return n.split(" or ").some(i=>Ot(i,t));let s=n.match(/^(.+?)\s*(==|!=|>=|<=|>|<)\s*(.+)$/);if(s){let i=gt(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=gt(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=gt(t,n);return Cr(o)}function Cr(e){return!(e==null||e===""||e===0||e===!1||Array.isArray(e)&&e.length===0)}function Ar(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 Cr(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 id,rd,ad,yr,br,ld,cd,dd,ud,md,so,kr=j(()=>{"use strict";g();id=/\{%[-\s]*require_(css|js)\b.*?%\}/gs,rd=/\{%[-\s]*end_require_(css|js)\s*%\}/gs,ad=/\{\{[-\s]*require_(css|js)\(.*?\)\s*\}\}/gs,yr=/\{\{[-\s]*get_asset_url\(["'](?:[^"'\/]+\/)?assets\/(.*?)["']\)\s*\}\}/gs,br=/\{\{[-\s]*get_asset_url\(.*?\)\s*\}\}/gs,ld=/\{%[-\s]*(end_)?(dnd_area|dnd_section|dnd_column|dnd_row|dnd_module)\b.*?%\}/gs,cd=/\{%[-\s]*module\b.*?%\}/gs,dd=/\{%[-\s]*(extends|block|endblock|set)\b.*?%\}/gs,ud=/\{#.*?#\}/gs,md=/\{\{[-\s]*content\.\w+.*?\}\}/gs,so=/\{%[-\s]*if\s+(.*?)\s*-?%\}((?:(?!\{%[-\s]*if\s)[\s\S])*?)\{%[-\s]*endif\s*-?%\}/g});var lo={};tt(lo,{buildModulePreviewHtml:()=>ao,buildPreviewHtml:()=>ro});function yd(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 ro(){let e=S();if(!e)return Ir();let t=me(),n=e.moduleOrder||[];if(t.length===0&&n.length===0)return Ir();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 f=JSON.parse(c.fieldsJson);d={module:rs(f)}}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=yd(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}">
242
+ </html>`}function fd(e){return e=e.replace(rd,""),e=e.replace(ad,""),e=e.replace(ld,""),yr.lastIndex=0,e=e.replace(yr,(t,n)=>`/theme-assets/${n}`),br.lastIndex=0,e=e.replace(br,""),e=e.replace(cd,""),e=e.replace(dd,""),e=e.replace(ud,""),e=e.replace(md,""),e=e.replace(pd,""),e}function vr(e,t){let n=e,s=0;for(;s<30;){s++;let o=gd(n);if(!o)break;let{varName:i,iterExpr:a,body:r,start:l,end:c}=o,d=yd(a,t),u="";Array.isArray(d)&&(u=d.map((m,f)=>{let h={...t,[i]:m,loop:{index:f+1,index0:f,first:f===0,last:f===d.length-1,length:d.length}},y=vr(r,h);return y=xr(y,h),y=wr(y,h),y}).join("")),n=n.slice(0,l)+u+n.slice(c)}return n}function gd(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 xr(e,t){let n=e,s=0;for(;so.test(n)&&s<50;)s++,n=n.replace(so,(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(Mt(i,t))return d[0];for(let u=1;u<d.length;u+=2){let m=d[u],f=d[u+1]||"";if(Mt(m,t))return f}return c}return Mt(i,t)?l:c}),so.lastIndex=0;return n}function wr(e,t){return e.replace(/\{\{[-\s]*(.*?)[-\s]*\}\}/g,(n,s)=>{let i=s.trim().split("|"),a=i[0].trim(),r=gt(t,a);for(let c=1;c<i.length;c++)r=Ar(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 hd(e){return e=e.replace(/\{%.*?%\}/gs,""),e=e.replace(/\{\{.*?\}\}/gs,""),e}function yd(e,t){let n=e.match(/^range\(\s*(.+?)\s*,\s*(.+?)\s*\)$/);if(n){let o=Sr(n[1],t),i=Sr(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=gt(t,s[1].trim());return typeof o=="string"?o.split(s[2]):[]}return gt(t,e)}function Sr(e,t){let s=e.trim().split("|"),o=s[0].trim();if(!isNaN(Number(o)))return Number(o);let i=gt(t,o);for(let a=1;a<s.length;a++)i=Ar(i,s[a].trim());return Number(i)||0}function gt(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 Mt(e,t){let n=e.trim();if(n.startsWith("not "))return!Mt(n.slice(4),t);if(n.includes(" and "))return n.split(" and ").every(i=>Mt(i,t));if(n.includes(" or "))return n.split(" or ").some(i=>Mt(i,t));let s=n.match(/^(.+?)\s*(==|!=|>=|<=|>|<)\s*(.+)$/);if(s){let i=gt(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=gt(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=gt(t,n);return Cr(o)}function Cr(e){return!(e==null||e===""||e===0||e===!1||Array.isArray(e)&&e.length===0)}function Ar(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 Cr(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 rd,ad,ld,yr,br,cd,dd,ud,md,pd,so,kr=j(()=>{"use strict";g();rd=/\{%[-\s]*require_(css|js)\b.*?%\}/gs,ad=/\{%[-\s]*end_require_(css|js)\s*%\}/gs,ld=/\{\{[-\s]*require_(css|js)\(.*?\)\s*\}\}/gs,yr=/\{\{[-\s]*get_asset_url\(["'](?:[^"'\/]+\/)?assets\/(.*?)["']\)\s*\}\}/gs,br=/\{\{[-\s]*get_asset_url\(.*?\)\s*\}\}/gs,cd=/\{%[-\s]*(end_)?(dnd_area|dnd_section|dnd_column|dnd_row|dnd_module)\b.*?%\}/gs,dd=/\{%[-\s]*module\b.*?%\}/gs,ud=/\{%[-\s]*(extends|block|endblock|set)\b.*?%\}/gs,md=/\{#.*?#\}/gs,pd=/\{\{[-\s]*content\.\w+.*?\}\}/gs,so=/\{%[-\s]*if\s+(.*?)\s*-?%\}((?:(?!\{%[-\s]*if\s)[\s\S])*?)\{%[-\s]*endif\s*-?%\}/g});var lo={};nt(lo,{buildModulePreviewHtml:()=>ao,buildPreviewHtml:()=>ro});function bd(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 ro(){let e=S();if(!e)return Ir();let t=me(),n=e.moduleOrder||[];if(t.length===0&&n.length===0)return Ir();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 f=JSON.parse(c.fieldsJson);d={module:rs(f)}}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=bd(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}">
243
243
  <div class="vibespot-placeholder">
244
244
  <div class="vibespot-placeholder__name">${c}</div>
245
245
  </div>
@@ -294,8 +294,8 @@ document.querySelectorAll('img').forEach(function(img){
294
294
  <div class="welcome__sub">Build Something Great</div>
295
295
  </div>
296
296
  </body>
297
- </html>`}function ao(e){let t=S();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:rs(i)}}catch{s={module:{}}}let o=oo(n.moduleHtml,s);return io({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 as=j(()=>{"use strict";g();kr();Se()});import{appendFileSync as bd,mkdirSync as Sd,readdirSync as vd,unlinkSync as xd}from"fs";import{join as po}from"path";import{homedir as wd}from"os";function Ad(){if(!uo)try{Sd(ls,{recursive:!0}),uo=!0}catch{}}function kd(){if(!mo){mo=!0;try{let e=Date.now()-Cd*864e5;for(let t of vd(ls)){if(!t.startsWith("vibespot-")||!t.endsWith(".log"))continue;let n=t.slice(9,19),s=new Date(n).getTime();if(s&&s<e)try{xd(po(ls,t))}catch{}}}catch{}}}function Id(){let t=new Date().toISOString().slice(0,10);return po(ls,`vibespot-${t}.log`)}function Td(){return new Date().toISOString().slice(11,23)}function co(e,t){if(Ad(),!!uo){mo||kd();try{bd(Id(),`${Td()} ${e} ${t}
298
- `)}catch{}}}var ls,Cd,uo,mo,T,ve=j(()=>{"use strict";g();ls=po(wd(),".vibespot","logs"),Cd=7,uo=!1,mo=!1;T={info(e,t,n){let s=n?`[${e}] ${t} ${JSON.stringify(n)}`:`[${e}] ${t}`;console.log(s),co("INFO",s)},warn(e,t,n){let s=n?`[${e}] ${t} ${JSON.stringify(n)}`:`[${e}] ${t}`;console.warn(s),co("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),co("ERROR",o)}}});function Ge(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 ln(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 Ge(c)}function fo(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 Tr(e,t){let n=!1,s,o=/```vibespot-modules\s*\n?([\s\S]*?)```/g;for(;(s=o.exec(e))!==null;)try{T.info("parse","Found vibespot-modules block",{length:s[1].length});let i=Ge(s[1]);if(!i||typeof i!="object")throw T.warn("parse","tryParseJSON returned non-object",{result:typeof i}),new Error("Invalid JSON after repair");let a=i;a.modules&&Array.isArray(a.modules)&&(Le({modules:a.modules.map(r=>fo(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){T.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=Ge(s[1]);if(!a||typeof a!="object")throw new Error("Invalid JSON after repair");let r=a;r.modules&&Array.isArray(r.modules)&&(Le({modules:r.modules.map(l=>fo(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){T.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"')){T.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=ln(r);if(l){let c=l;c.modules&&Array.isArray(c.modules)&&c.modules.length>0&&(T.info("parse","Salvaged modules from truncated response",{count:c.modules.length}),Le({modules:c.modules.map(d=>fo(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){T.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.";T.warn("parse",r),t&&t(r)}}}var cs=j(()=>{"use strict";g();Se();ve()});function Mt(){let e=S();return e?{pageType:Ce()?.pageType,brandAssets:e.brandAssets}:{}}function $r(e,t,n=!1,s,o){let a=[{type:"text",text:Ed(t,n)}];if(n){let l=`## HubSpot CMS Rules
297
+ </html>`}function ao(e){let t=S();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:rs(i)}}catch{s={module:{}}}let o=oo(n.moduleHtml,s);return io({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 as=j(()=>{"use strict";g();kr();Se()});import{appendFileSync as Sd,mkdirSync as vd,readdirSync as xd,unlinkSync as wd}from"fs";import{join as po}from"path";import{homedir as Cd}from"os";function kd(){if(!uo)try{vd(ls,{recursive:!0}),uo=!0}catch{}}function Id(){if(!mo){mo=!0;try{let e=Date.now()-Ad*864e5;for(let t of xd(ls)){if(!t.startsWith("vibespot-")||!t.endsWith(".log"))continue;let n=t.slice(9,19),s=new Date(n).getTime();if(s&&s<e)try{wd(po(ls,t))}catch{}}}catch{}}}function Td(){let t=new Date().toISOString().slice(0,10);return po(ls,`vibespot-${t}.log`)}function $d(){return new Date().toISOString().slice(11,23)}function co(e,t){if(kd(),!!uo){mo||Id();try{Sd(Td(),`${$d()} ${e} ${t}
298
+ `)}catch{}}}var ls,Ad,uo,mo,T,ve=j(()=>{"use strict";g();ls=po(Cd(),".vibespot","logs"),Ad=7,uo=!1,mo=!1;T={info(e,t,n){let s=n?`[${e}] ${t} ${JSON.stringify(n)}`:`[${e}] ${t}`;console.log(s),co("INFO",s)},warn(e,t,n){let s=n?`[${e}] ${t} ${JSON.stringify(n)}`:`[${e}] ${t}`;console.warn(s),co("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),co("ERROR",o)}}});function Ge(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 ln(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 Ge(c)}function fo(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 Tr(e,t){let n=!1,s,o=/```vibespot-modules\s*\n?([\s\S]*?)```/g;for(;(s=o.exec(e))!==null;)try{T.info("parse","Found vibespot-modules block",{length:s[1].length});let i=Ge(s[1]);if(!i||typeof i!="object")throw T.warn("parse","tryParseJSON returned non-object",{result:typeof i}),new Error("Invalid JSON after repair");let a=i;a.modules&&Array.isArray(a.modules)&&(Le({modules:a.modules.map(r=>fo(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){T.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=Ge(s[1]);if(!a||typeof a!="object")throw new Error("Invalid JSON after repair");let r=a;r.modules&&Array.isArray(r.modules)&&(Le({modules:r.modules.map(l=>fo(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){T.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"')){T.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=ln(r);if(l){let c=l;c.modules&&Array.isArray(c.modules)&&c.modules.length>0&&(T.info("parse","Salvaged modules from truncated response",{count:c.modules.length}),Le({modules:c.modules.map(d=>fo(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){T.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.";T.warn("parse",r),t&&t(r)}}}var cs=j(()=>{"use strict";g();Se();ve()});function Ot(){let e=S();return e?{pageType:Ce()?.pageType,brandAssets:e.brandAssets}:{}}function $r(e,t,n=!1,s,o){let a=[{type:"text",text:_d(t,n)}];if(n){let l=`## HubSpot CMS Rules
299
299
  ${Ee()}
300
300
 
301
301
  ## Conversion Guide Reference
@@ -331,13 +331,13 @@ ${Us()}
331
331
  ${Ee()}
332
332
 
333
333
  ## Conversion Guide Reference
334
- ${e}`;a.push({type:"text",text:l,cache_control:{type:"ephemeral"}})}let r=$d(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 $d(e,t){let n=[];if(e){let s=Ws(e);s&&n.push(`## Page Type Context
334
+ ${e}`;a.push({type:"text",text:l,cache_control:{type:"ephemeral"}})}let r=Ed(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 Ed(e,t){let n=[];if(e){let s=Ws(e);s&&n.push(`## Page Type Context
335
335
  ${s}`)}if(t?.styleguide&&n.push(`## Brand Style Guide
336
336
  ${t.styleguide}`),t?.brandvoice&&n.push(`## Brand Voice
337
337
  ${t.brandvoice}`),t?.humanify!==!1){let s=Bs();s&&n.push(`## Anti-AI Copy Rules (Humanify)
338
338
  ${s}`)}return n.join(`
339
339
 
340
- `)}function Ed(e,t){return`You are vibeSpot, an AI that builds HubSpot CMS landing pages from natural language descriptions.
340
+ `)}function _d(e,t){return`You are vibeSpot, an AI that builds HubSpot CMS landing pages from natural language descriptions.
341
341
 
342
342
  ## Your Role
343
343
  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.
@@ -584,7 +584,7 @@ ${e.sharedCss}
584
584
  \`\`\`js
585
585
  ${e.sharedJs}
586
586
  \`\`\`
587
- `)}let o=rt(),i=new Set(e.modules.map(r=>r.moduleName)),a=o.filter(r=>!i.has(r.module.moduleName));if(a.length>0){t.push(`
587
+ `)}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(`
588
588
 
589
589
  ## Available modules in this theme (reusable)
590
590
  `);for(let r of a)t.push(`- ${r.module.moduleName} (used in: ${r.usedIn.join(", ")})
@@ -604,13 +604,13 @@ ${i}`),a&&(r+=a),r+="\n\n---\nRemember: respond with a ```vibespot-modules JSON
604
604
  [Attached document: ${d.originalName}]
605
605
  ${d.extractedText}`),d.type==="image"&&d.usage==="asset"&&d.assetPath&&(r+=`
606
606
 
607
- [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 Er=j(()=>{"use strict";g();qe();Se()});import{spawn as _d}from"child_process";async function _r(){return ho||(ho=(await import("@anthropic-ai/sdk")).default),ho}function Pr(e){if(!e?.length)return"";let t=[];for(let n of e)n.type==="image"&&n.usage==="asset"&&n.assetPath&&t.push(`
607
+ [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 Er=j(()=>{"use strict";g();qe();Se()});import{spawn as Pd}from"child_process";async function _r(){return ho||(ho=(await import("@anthropic-ai/sdk")).default),ho}function Pr(e){if(!e?.length)return"";let t=[];for(let n of e)n.type==="image"&&n.usage==="asset"&&n.assetPath&&t.push(`
608
608
  [Uploaded image: ${n.originalName} \u2192 use get_asset_url("${n.assetPath}")]`),n.type==="document"&&n.extractedText&&t.push(`
609
609
 
610
610
  ---
611
611
  [Attached document: ${n.originalName}]
612
- ${n.extractedText}`);return t.join("")}async function Or(e,t,n,s,o,i,a){for(let r=0;;r++)try{let l="",c=0,d=i||(()=>{});d(fe[0]);let u=setInterval(()=>{c++,d(fe[Math.min(c,fe.length-1)])},6e3);try{let m=e.messages.stream({model:s,max_tokens:48e3,system:t,messages:n});for await(let f of m)if(f.type==="content_block_delta"&&f.delta.type==="text_delta"){let h=f.delta.text;l+=h,o(h)}}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>=yo.length)throw l;let m=yo[r];T.warn("ai-engine",`Rate limited (429), attempt ${r+1}/${yo.length} \u2014 waiting ${m}s`),i&&i(`Rate limited by Anthropic API \u2014 retrying in ${m}s...`),await new Promise(f=>setTimeout(f,m*1e3)),i&&i("Retrying...")}}function Mr(e,t,n){let s=oe(),i=S().modules.length>0,a=go(e,n),r=Mt(),l=$r(s,t,i,r.pageType,r.brandAssets);return{messages:a,systemBlocks:l,conversionGuide:s,editMode:i}}async function Nr(e,t,n,s,o,i,a,r){let l=await _r(),c=new l({apiKey:t}),{messages:d,systemBlocks:u}=Mr(e,n,r);T.info("anthropic","API call",{model:s,systemBlockCount:u.length,cachedBlocks:u.filter(m=>m.cache_control).length,messageCount:d.length}),await Or(c,u,d,s,o,i,a)}async function Rr(e,t,n,s,o,i,a){let r=await Os();if(!r)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let l=await _r(),c=new l({authToken:r,defaultHeaders:Ht}),{messages:d,systemBlocks:u}=Mr(e,t,a),m=[{type:"text",text:At},...u];T.info("anthropic-oauth","API call",{model:n,systemBlockCount:m.length,cachedBlocks:m.filter(f=>f.cache_control).length,messageCount:d.length}),await Or(c,m,d,n,s,o,i)}async function Fr(e,t,n,s,o,i,a,r){let l=oe(),c=S().modules.length>0,d=go(e,r),u=Mt(),m=d.map(G=>typeof G.content=="string"?G:{role:G.role,content:G.content.map(E=>E.type==="text"?{type:"text",text:E.text}:{type:"image_url",image_url:{url:`data:${E.source.media_type};base64,${E.source.data}`}})}),f=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:cn(l,n,c,u.pageType,u.brandAssets)},...m]})});if(!f.ok){let G=await f.text();throw new Error(`OpenAI API error (${f.status}): ${G}`)}let h=0,y=i||(()=>{});y(fe[0]);let v=setInterval(()=>{h++,y(fe[Math.min(h,fe.length-1)])},6e3),C="",k=f.body.getReader(),P=new TextDecoder,M="";try{for(;;){let{done:G,value:E}=await k.read();if(G)break;M+=P.decode(E,{stream:!0});let R=M.split(`
613
- `);M=R.pop()||"";for(let W of R){if(!W.startsWith("data: "))continue;let L=W.slice(6).trim();if(L==="[DONE]")break;try{let F=JSON.parse(L).choices?.[0]?.delta?.content;F&&(C+=F,o(F))}catch{}}}}finally{clearInterval(v)}a&&a(C)}async function jr(e,t,n,s,o,i,a){let r=oe(),l=S(),c=l.modules.length>0,d=dn(),u=Mt(),m=[];for(let L of l.messages.slice(-20))m.push({role:L.role==="assistant"?"model":"user",parts:[{text:L.content}]});let f=d?`${e}
612
+ ${n.extractedText}`);return t.join("")}async function Mr(e,t,n,s,o,i,a){for(let r=0;;r++)try{let l="",c=0,d=i||(()=>{});d(fe[0]);let u=setInterval(()=>{c++,d(fe[Math.min(c,fe.length-1)])},6e3);try{let m=e.messages.stream({model:s,max_tokens:48e3,system:t,messages:n});for await(let f of m)if(f.type==="content_block_delta"&&f.delta.type==="text_delta"){let h=f.delta.text;l+=h,o(h)}}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>=yo.length)throw l;let m=yo[r];T.warn("ai-engine",`Rate limited (429), attempt ${r+1}/${yo.length} \u2014 waiting ${m}s`),i&&i(`Rate limited by Anthropic API \u2014 retrying in ${m}s...`),await new Promise(f=>setTimeout(f,m*1e3)),i&&i("Retrying...")}}function Or(e,t,n){let s=oe(),i=S().modules.length>0,a=go(e,n),r=Ot(),l=$r(s,t,i,r.pageType,r.brandAssets);return{messages:a,systemBlocks:l,conversionGuide:s,editMode:i}}async function Nr(e,t,n,s,o,i,a,r){let l=await _r(),c=new l({apiKey:t}),{messages:d,systemBlocks:u}=Or(e,n,r);T.info("anthropic","API call",{model:s,systemBlockCount:u.length,cachedBlocks:u.filter(m=>m.cache_control).length,messageCount:d.length}),await Mr(c,u,d,s,o,i,a)}async function Rr(e,t,n,s,o,i,a){let r=await Ms();if(!r)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let l=await _r(),c=new l({authToken:r,defaultHeaders:Ht}),{messages:d,systemBlocks:u}=Or(e,t,a),m=[{type:"text",text:At},...u];T.info("anthropic-oauth","API call",{model:n,systemBlockCount:m.length,cachedBlocks:m.filter(f=>f.cache_control).length,messageCount:d.length}),await Mr(c,m,d,n,s,o,i)}async function Fr(e,t,n,s,o,i,a,r){let l=oe(),c=S().modules.length>0,d=go(e,r),u=Ot(),m=d.map(G=>typeof G.content=="string"?G:{role:G.role,content:G.content.map(E=>E.type==="text"?{type:"text",text:E.text}:{type:"image_url",image_url:{url:`data:${E.source.media_type};base64,${E.source.data}`}})}),f=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:cn(l,n,c,u.pageType,u.brandAssets)},...m]})});if(!f.ok){let G=await f.text();throw new Error(`OpenAI API error (${f.status}): ${G}`)}let h=0,y=i||(()=>{});y(fe[0]);let v=setInterval(()=>{h++,y(fe[Math.min(h,fe.length-1)])},6e3),C="",k=f.body.getReader(),P=new TextDecoder,O="";try{for(;;){let{done:G,value:E}=await k.read();if(G)break;O+=P.decode(E,{stream:!0});let R=O.split(`
613
+ `);O=R.pop()||"";for(let W of R){if(!W.startsWith("data: "))continue;let L=W.slice(6).trim();if(L==="[DONE]")break;try{let F=JSON.parse(L).choices?.[0]?.delta?.content;F&&(C+=F,o(F))}catch{}}}}finally{clearInterval(v)}a&&a(C)}async function jr(e,t,n,s,o,i,a){let r=oe(),l=S(),c=l.modules.length>0,d=dn(),u=Ot(),m=[];for(let L of l.messages.slice(-20))m.push({role:L.role==="assistant"?"model":"user",parts:[{text:L.content}]});let f=d?`${e}
614
614
 
615
615
  ---
616
616
  ${d}`:e;if(a?.length)for(let L of a)L.type==="document"&&L.extractedText&&(f+=`
@@ -619,18 +619,18 @@ ${d}`:e;if(a?.length)for(let L of a)L.type==="document"&&L.extractedText&&(f+=`
619
619
  [Attached document: ${L.originalName}]
620
620
  ${L.extractedText}`),L.type==="image"&&L.usage==="asset"&&L.assetPath&&(f+=`
621
621
 
622
- [Uploaded image: ${L.originalName} \u2192 available as get_asset_url("${L.assetPath}")]`);let h=[];if(a?.length)for(let L of a)L.type==="image"&&L.base64&&h.push({inlineData:{mimeType:L.mimeType,data:L.base64}});h.push({text:f}),m.push({role:"user",parts:h});let v=`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse&key=${t}`,C=await fetch(v,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({systemInstruction:{parts:[{text:cn(r,n,c,u.pageType,u.brandAssets)}]},contents:m,generationConfig:{maxOutputTokens:48e3}})});if(!C.ok){let L=await C.text();throw new Error(`Gemini API error (${C.status}): ${L}`)}let k=0,P=o||(()=>{});P(fe[0]);let M=setInterval(()=>{k++,P(fe[Math.min(k,fe.length-1)])},6e3),G="",E=C.body.getReader(),R=new TextDecoder,W="";try{for(;;){let{done:L,value:U}=await E.read();if(L)break;W+=R.decode(U,{stream:!0});let F=W.split(`
623
- `);W=F.pop()||"";for(let X of F){if(!X.startsWith("data: "))continue;let le=X.slice(6).trim();try{let jt=JSON.parse(le).candidates?.[0]?.content?.parts?.[0]?.text;jt&&(G+=jt,s(jt))}catch{}}}}finally{clearInterval(M)}i&&i(G)}function ds(e,t,n,s){return new Promise((o,i)=>{let a={...process.env};delete a.CLAUDECODE;let r=_d(e,t,{stdio:["pipe","pipe","pipe"],env:a}),l="",c="",d=!1,u=h=>{d||(d=!0,h())};r.stdout.on("data",h=>{let y=h.toString();l+=y,s&&s(y)}),r.stderr.on("data",h=>{c+=h.toString()}),r.on("error",h=>u(()=>i(new Error(`${e} failed to start: ${h.message}`)))),r.on("close",h=>{u(()=>{h!==0?i(new Error(`${e} exited with code ${h}.
622
+ [Uploaded image: ${L.originalName} \u2192 available as get_asset_url("${L.assetPath}")]`);let h=[];if(a?.length)for(let L of a)L.type==="image"&&L.base64&&h.push({inlineData:{mimeType:L.mimeType,data:L.base64}});h.push({text:f}),m.push({role:"user",parts:h});let v=`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse&key=${t}`,C=await fetch(v,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({systemInstruction:{parts:[{text:cn(r,n,c,u.pageType,u.brandAssets)}]},contents:m,generationConfig:{maxOutputTokens:48e3}})});if(!C.ok){let L=await C.text();throw new Error(`Gemini API error (${C.status}): ${L}`)}let k=0,P=o||(()=>{});P(fe[0]);let O=setInterval(()=>{k++,P(fe[Math.min(k,fe.length-1)])},6e3),G="",E=C.body.getReader(),R=new TextDecoder,W="";try{for(;;){let{done:L,value:U}=await E.read();if(L)break;W+=R.decode(U,{stream:!0});let F=W.split(`
623
+ `);W=F.pop()||"";for(let X of F){if(!X.startsWith("data: "))continue;let le=X.slice(6).trim();try{let jt=JSON.parse(le).candidates?.[0]?.content?.parts?.[0]?.text;jt&&(G+=jt,s(jt))}catch{}}}}finally{clearInterval(O)}i&&i(G)}function ds(e,t,n,s){return new Promise((o,i)=>{let a={...process.env};delete a.CLAUDECODE;let r=Pd(e,t,{stdio:["pipe","pipe","pipe"],env:a}),l="",c="",d=!1,u=h=>{d||(d=!0,h())};r.stdout.on("data",h=>{let y=h.toString();l+=y,s&&s(y)}),r.stderr.on("data",h=>{c+=h.toString()}),r.on("error",h=>u(()=>i(new Error(`${e} failed to start: ${h.message}`)))),r.on("close",h=>{u(()=>{h!==0?i(new Error(`${e} exited with code ${h}.
624
624
  `+(c?`Stderr: ${c.slice(0,500)}
625
625
  `:"")+(l?`Output: ${l.slice(0,500)}`:"No output"))):o(l)})}),r.stdin.on("error",()=>{}),r.stdin.write(n)?r.stdin.end():r.stdin.once("drain",()=>r.stdin.end());let f=setTimeout(()=>{r.kill(),u(()=>i(new Error(`${e} timed out after 5 minutes.
626
626
  `+(c?`Stderr: ${c.slice(0,500)}
627
- `:"")+`Partial output (${l.length} chars): ${l.slice(0,500)}`)))},3e5);r.on("close",()=>clearTimeout(f))})}async function Jr(e,t,n,s,o,i){let a=oe(),r=_(),l=S().modules.length>0,c=Mt(),d=cn(a,t,l,c.pageType,c.brandAssets);d+=`
627
+ `:"")+`Partial output (${l.length} chars): ${l.slice(0,500)}`)))},3e5);r.on("close",()=>clearTimeout(f))})}async function Jr(e,t,n,s,o,i){let a=oe(),r=_(),l=S().modules.length>0,c=Ot(),d=cn(a,t,l,c.pageType,c.brandAssets);d+=`
628
628
 
629
629
  ## User Request
630
- `+e,d+=dn(),d+=Pr(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);let m=0,f=s||(()=>{});f(fe[0]);let h=setInterval(()=>{m++;let y=fe[Math.min(m,fe.length-1)];f(y)},6e3);try{let y=await ds("claude",u,d,v=>{n(v)});o&&o(y)}finally{clearInterval(h)}}async function bo(e,t,n,s,o,i,a){let r=oe(),l=S().modules.length>0,c=Mt(),d=cn(r,n,l,c.pageType,c.brandAssets);d+=`
630
+ `+e,d+=dn(),d+=Pr(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);let m=0,f=s||(()=>{});f(fe[0]);let h=setInterval(()=>{m++;let y=fe[Math.min(m,fe.length-1)];f(y)},6e3);try{let y=await ds("claude",u,d,v=>{n(v)});o&&o(y)}finally{clearInterval(h)}}async function bo(e,t,n,s,o,i,a){let r=oe(),l=S().modules.length>0,c=Ot(),d=cn(r,n,l,c.pageType,c.brandAssets);d+=`
631
631
 
632
632
  ## User Request
633
- `+t,d+=dn(),d+=Pr(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 f=0,h=o||(()=>{});h(fe[0]);let y=setInterval(()=>{f++;let v=fe[Math.min(f,fe.length-1)];h(v)},6e3);try{let v=await ds(u,m,d,C=>{s(C)});i&&i(v)}finally{clearInterval(y)}}var ho,fe,yo,So=j(()=>{"use strict";g();qe();Z();Ke();Se();Er();ve();ho=null;fe=["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..."],yo=[10,20,40,60,120]});function p(e,t,n){e.writeHead(t,{"Content-Type":"application/json"}),e.end(JSON.stringify(n))}function N(e,t){let n=[];e.on("data",s=>n.push(s)),e.on("end",()=>t(Buffer.concat(n).toString("utf-8")))}function vo(e,t,n){N(e,s=>{try{n(JSON.parse(s||"{}"))}catch{p(t,400,{error:"Invalid JSON in request body"})}})}var et=j(()=>{"use strict";g()});import{createWriteStream as Pd,mkdirSync as Dr,existsSync as xo,readFileSync as wo}from"fs";import{join as ht,extname as Od}from"path";import{randomUUID as Md}from"crypto";import Nd from"busboy";function Jd(e){return e.replace(/[^a-zA-Z0-9._-]/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").toLowerCase()}function Dd(e,t){if(!xo(ht(e,t)))return t;let n=Od(t),s=t.slice(0,-n.length||void 0),o=1;for(;xo(ht(e,`${s}-${o}${n}`));)o++;return`${s}-${o}${n}`}async function Hd(e){let t=(await import("pdf-parse")).default,n=wo(e);return(await t(n)).text}async function Ld(e){return(await(await import("mammoth")).extractRawText({path:e})).value}function Gd(e){return wo(e,"utf-8")}function Lr(e,t){let n=S();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=Nd({headers:e.headers,limits:{fileSize:Rd,files:10}});l.on("file",(c,d,u)=>{let{filename:m,mimeType:f}=u;if(a++,!jd.has(f)){i.push(`Unsupported file type: ${m} (${f})`),d.resume();return}let h=Hr.has(f),y=Jd(m),v=Md(),C,k;h?(C=ht(n.themePath,"assets"),Dr(C,{recursive:!0}),k=Dd(C,y)):(C=ht(n.themePath,".vibespot","uploads"),Dr(C,{recursive:!0}),k=`${v}-${y}`);let P=ht(C,k),M=Pd(P),G=0,E=!1;d.on("data",R=>{G+=R.length}),d.on("limit",()=>{E=!0,i.push(`File too large (>10MB): ${m}`)}),d.pipe(M),r.push(new Promise(R=>{M.on("finish",()=>{if(!E){let W={id:v,filename:k,originalName:m,type:h?"image":"document",usage:h?"asset":"context",mimeType:f,size:G,addedAt:new Date().toISOString()};o.push(W),Qi(W)}R()}),M.on("error",()=>{i.push(`Failed to write: ${m}`),R()})}))}),l.on("finish",async()=>{await Promise.all(r);for(let c of o)if(c.type==="document"){let d=ht(n.themePath,".vibespot","uploads",c.filename);try{c.mimeType==="application/pdf"?c.extractedText=await Hd(d):c.mimeType==="application/vnd.openxmlformats-officedocument.wordprocessingml.document"?c.extractedText=await Ld(d):c.extractedText=Gd(d),T.info("upload",`Extracted text from ${c.originalName} (${c.extractedText.length} chars)`)}catch(u){T.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=>{T.error("upload",`Busboy error: ${c}`),p(t,500,{error:"Upload failed"})}),e.pipe(l)}function Gr(e){let t=S();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=ht(t.themePath,"assets",s.filename);xo(i)&&(o.base64=wo(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 Rd,Hr,Fd,jd,Co=j(()=>{"use strict";g();et();Se();ve();Rd=10*1024*1024,Hr=new Set(["image/png","image/jpeg","image/jpg","image/svg+xml","image/webp","image/gif"]),Fd=new Set(["application/pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/markdown","text/plain"]),jd=new Set([...Hr,...Fd])});async function us(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>=Ao.length)throw s;let r=Ao[n];T.warn("agent-adapter",`Rate limited (429), attempt ${n+1}/${Ao.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 un(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 Ur(){return ko||(ko=(await import("@anthropic-ai/sdk")).default),ko}async function Ud(e,t,n,s,o){let i=await Ur(),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};return us(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}});for(let m of d.content)if(m.type==="tool_use")return{type:"structured",data:un(m.input)};return{type:"text",text:d.content.filter(m=>m.type==="text").map(m=>m.text).join("")}},n.onStatus)}return us(async()=>{let c="",d=a.messages.stream({model:t,max_tokens:n.maxTokens||16e3,system:l,messages:r});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 Bd(e,t,n){let s=await Ur(),o=new s({authToken:e,defaultHeaders:Ht}),i=n.messages,a;if(n.systemBlocks?a=[{type:"text",text:At},...n.systemBlocks]:a=[{type:"text",text:At},{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};return us(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}});for(let d of l.content)if(d.type==="tool_use")return{type:"structured",data:un(d.input)};return{type:"text",text:l.content.filter(d=>d.type==="text").map(d=>d.text).join("")}},n.onStatus)}return us(async()=>{let r="",l=o.messages.stream({model:t,max_tokens:n.maxTokens||16e3,system:a,messages:i});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 Io(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"?Io(o):o;t.properties=n}return t.items&&typeof t.items=="object"&&(t.items=Io(t.items)),t}async function Wd(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:Io(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:un(JSON.parse(r))}}catch{return T.warn("agent-adapter","OpenAI structured output parse failed, returning raw text"),{type:"text",text:r}}return{type:"text",text:r}}async function Vd(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:un(JSON.parse(c))}}catch{return T.warn("agent-adapter","Gemini structured output parse failed, returning raw text"),{type:"text",text:c}}return{type:"text",text:c}}function Kd(e){switch(e){case"claude-code":{let t=_(),n=["--print"];return t.claudeCodeModel&&n.push("--model",t.claudeCodeModel),{bin:"claude",args:n}}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 Yd(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(`
633
+ `+t,d+=dn(),d+=Pr(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 f=0,h=o||(()=>{});h(fe[0]);let y=setInterval(()=>{f++;let v=fe[Math.min(f,fe.length-1)];h(v)},6e3);try{let v=await ds(u,m,d,C=>{s(C)});i&&i(v)}finally{clearInterval(y)}}var ho,fe,yo,So=j(()=>{"use strict";g();qe();Z();Ke();Se();Er();ve();ho=null;fe=["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..."],yo=[10,20,40,60,120]});function p(e,t,n){e.writeHead(t,{"Content-Type":"application/json"}),e.end(JSON.stringify(n))}function N(e,t){let n=[];e.on("data",s=>n.push(s)),e.on("end",()=>t(Buffer.concat(n).toString("utf-8")))}function vo(e,t,n){N(e,s=>{try{n(JSON.parse(s||"{}"))}catch{p(t,400,{error:"Invalid JSON in request body"})}})}var et=j(()=>{"use strict";g()});import{createWriteStream as Md,mkdirSync as Dr,existsSync as xo,readFileSync as wo}from"fs";import{join as ht,extname as Od}from"path";import{randomUUID as Nd}from"crypto";import Rd from"busboy";function Dd(e){return e.replace(/[^a-zA-Z0-9._-]/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").toLowerCase()}function Hd(e,t){if(!xo(ht(e,t)))return t;let n=Od(t),s=t.slice(0,-n.length||void 0),o=1;for(;xo(ht(e,`${s}-${o}${n}`));)o++;return`${s}-${o}${n}`}async function Ld(e){let t=(await import("pdf-parse")).default,n=wo(e);return(await t(n)).text}async function Gd(e){return(await(await import("mammoth")).extractRawText({path:e})).value}function Ud(e){return wo(e,"utf-8")}function Lr(e,t){let n=S();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=Rd({headers:e.headers,limits:{fileSize:Fd,files:10}});l.on("file",(c,d,u)=>{let{filename:m,mimeType:f}=u;if(a++,!Jd.has(f)){i.push(`Unsupported file type: ${m} (${f})`),d.resume();return}let h=Hr.has(f),y=Dd(m),v=Nd(),C,k;h?(C=ht(n.themePath,"assets"),Dr(C,{recursive:!0}),k=Hd(C,y)):(C=ht(n.themePath,".vibespot","uploads"),Dr(C,{recursive:!0}),k=`${v}-${y}`);let P=ht(C,k),O=Md(P),G=0,E=!1;d.on("data",R=>{G+=R.length}),d.on("limit",()=>{E=!0,i.push(`File too large (>10MB): ${m}`)}),d.pipe(O),r.push(new Promise(R=>{O.on("finish",()=>{if(!E){let W={id:v,filename:k,originalName:m,type:h?"image":"document",usage:h?"asset":"context",mimeType:f,size:G,addedAt:new Date().toISOString()};o.push(W),Qi(W)}R()}),O.on("error",()=>{i.push(`Failed to write: ${m}`),R()})}))}),l.on("finish",async()=>{await Promise.all(r);for(let c of o)if(c.type==="document"){let d=ht(n.themePath,".vibespot","uploads",c.filename);try{c.mimeType==="application/pdf"?c.extractedText=await Ld(d):c.mimeType==="application/vnd.openxmlformats-officedocument.wordprocessingml.document"?c.extractedText=await Gd(d):c.extractedText=Ud(d),T.info("upload",`Extracted text from ${c.originalName} (${c.extractedText.length} chars)`)}catch(u){T.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=>{T.error("upload",`Busboy error: ${c}`),p(t,500,{error:"Upload failed"})}),e.pipe(l)}function Gr(e){let t=S();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=ht(t.themePath,"assets",s.filename);xo(i)&&(o.base64=wo(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 Fd,Hr,jd,Jd,Co=j(()=>{"use strict";g();et();Se();ve();Fd=10*1024*1024,Hr=new Set(["image/png","image/jpeg","image/jpg","image/svg+xml","image/webp","image/gif"]),jd=new Set(["application/pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/markdown","text/plain"]),Jd=new Set([...Hr,...jd])});async function us(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>=Ao.length)throw s;let r=Ao[n];T.warn("agent-adapter",`Rate limited (429), attempt ${n+1}/${Ao.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 un(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 Ur(){return ko||(ko=(await import("@anthropic-ai/sdk")).default),ko}async function Bd(e,t,n,s,o){let i=await Ur(),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};return us(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}});for(let m of d.content)if(m.type==="tool_use")return{type:"structured",data:un(m.input)};return{type:"text",text:d.content.filter(m=>m.type==="text").map(m=>m.text).join("")}},n.onStatus)}return us(async()=>{let c="",d=a.messages.stream({model:t,max_tokens:n.maxTokens||16e3,system:l,messages:r});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 Wd(e,t,n){let s=await Ur(),o=new s({authToken:e,defaultHeaders:Ht}),i=n.messages,a;if(n.systemBlocks?a=[{type:"text",text:At},...n.systemBlocks]:a=[{type:"text",text:At},{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};return us(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}});for(let d of l.content)if(d.type==="tool_use")return{type:"structured",data:un(d.input)};return{type:"text",text:l.content.filter(d=>d.type==="text").map(d=>d.text).join("")}},n.onStatus)}return us(async()=>{let r="",l=o.messages.stream({model:t,max_tokens:n.maxTokens||16e3,system:a,messages:i});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 Io(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"?Io(o):o;t.properties=n}return t.items&&typeof t.items=="object"&&(t.items=Io(t.items)),t}async function Vd(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:Io(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:un(JSON.parse(r))}}catch{return T.warn("agent-adapter","OpenAI structured output parse failed, returning raw text"),{type:"text",text:r}}return{type:"text",text:r}}async function Kd(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:un(JSON.parse(c))}}catch{return T.warn("agent-adapter","Gemini structured output parse failed, returning raw text"),{type:"text",text:c}}return{type:"text",text:c}}function Yd(e){switch(e){case"claude-code":{let t=_(),n=["--print"];return t.claudeCodeModel&&n.push("--model",t.claudeCodeModel),{bin:"claude",args:n}}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 zd(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(`
634
634
  `);t.push(`
635
635
 
636
636
  ## ${s}
@@ -641,7 +641,7 @@ Respond with a JSON code block. Wrap your JSON in \`\`\`json fences. No prose or
641
641
 
642
642
  The JSON must match this structure:
643
643
  ${n}`)}return t.join("")}function Br(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}": ${Br(r,t+1)}${l}${d}`):i.push(`${n} "${a}": ${c}${l}${d}${u}`)}return i.push(`${n}}`),i.join(`
644
- `)}function zd(e){let t=e.trim(),n=Ge(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=Ge(r);if(l&&typeof l=="object")return l;let c=ln(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=Ge(r);if(l&&typeof l=="object")return l;let c=ln(r);if(c&&typeof c=="object")return c}let a=ln(t);return a&&typeof a=="object"?a:null}async function qd(e,t,n){let{bin:s,args:o}=Kd(e),i=Yd(n),a=await ds(s,o,i,n.onChunk);if(!n.structuredOutput)return{type:"text",text:a};let r=zd(a);return r?{type:"structured",data:un(r)}:(T.warn("agent-cli",`${e}: failed to parse structured output, returning text`,{outputPreview:a.slice(0,500),outputLength:a.length}),{type:"text",text:a})}async function Qd(e,t,n,s){switch(T.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 Ud(t,n,s);case"claude-oauth":{let{getValidAccessToken:o}=await Promise.resolve().then(()=>(Ke(),Ms)),i=await o();if(!i)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");return Bd(i,n,s)}case"openai-api":return Wd(t,n,s);case"gemini-api":return Vd(t,n,s);default:throw new Error(`Unsupported API engine: ${e}`)}}async function Pe(e,t,n,s){return Xd.has(e)?Qd(e,t,n,s):(T.info("agent-adapter",`${e} CLI call`,{structured:!!s.structuredOutput,schemaName:s.structuredOutput?.name,systemPromptLength:s.systemPrompt.length,messageCount:s.messages.length}),qd(e,n,s))}function ms(e){return e==="anthropic-api"||e==="claude-oauth"||e==="openai-api"||e==="gemini-api"||e==="claude-code"||e==="gemini-cli"||e==="codex-cli"}function mn(e){return e==="claude-code"||e==="gemini-cli"||e==="codex-cli"}var Ao,ko,Xd,lt=j(()=>{"use strict";g();So();cs();Z();Ke();ve();Ao=[10,20,40,60,120];ko=null;Xd=new Set(["anthropic-api","claude-oauth","openai-api","gemini-api"])});function Wr(e,t,n,s){let o=t.length>0?`Current template modules (in page order):
644
+ `)}function qd(e){let t=e.trim(),n=Ge(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=Ge(r);if(l&&typeof l=="object")return l;let c=ln(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=Ge(r);if(l&&typeof l=="object")return l;let c=ln(r);if(c&&typeof c=="object")return c}let a=ln(t);return a&&typeof a=="object"?a:null}async function Xd(e,t,n){let{bin:s,args:o}=Yd(e),i=zd(n),a=await ds(s,o,i,n.onChunk);if(!n.structuredOutput)return{type:"text",text:a};let r=qd(a);return r?{type:"structured",data:un(r)}:(T.warn("agent-cli",`${e}: failed to parse structured output, returning text`,{outputPreview:a.slice(0,500),outputLength:a.length}),{type:"text",text:a})}async function Zd(e,t,n,s){switch(T.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 Bd(t,n,s);case"claude-oauth":{let{getValidAccessToken:o}=await Promise.resolve().then(()=>(Ke(),Os)),i=await o();if(!i)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");return Wd(i,n,s)}case"openai-api":return Vd(t,n,s);case"gemini-api":return Kd(t,n,s);default:throw new Error(`Unsupported API engine: ${e}`)}}async function Pe(e,t,n,s){return Qd.has(e)?Zd(e,t,n,s):(T.info("agent-adapter",`${e} CLI call`,{structured:!!s.structuredOutput,schemaName:s.structuredOutput?.name,systemPromptLength:s.systemPrompt.length,messageCount:s.messages.length}),Xd(e,n,s))}function ms(e){return e==="anthropic-api"||e==="claude-oauth"||e==="openai-api"||e==="gemini-api"||e==="claude-code"||e==="gemini-cli"||e==="codex-cli"}function mn(e){return e==="claude-code"||e==="gemini-cli"||e==="codex-cli"}var Ao,ko,Qd,ct=j(()=>{"use strict";g();So();cs();Z();Ke();ve();Ao=[10,20,40,60,120];ko=null;Qd=new Set(["anthropic-api","claude-oauth","openai-api","gemini-api"])});function Wr(e,t,n,s){let o=t.length>0?`Current template modules (in page order):
645
645
  ${t.map((r,l)=>`${l+1}. ${r}`).join(`
646
646
  `)}`:"No modules yet (new page).",i=n.length>0?`
647
647
 
@@ -697,7 +697,7 @@ CRITICAL: When the user corrects a misclassification (e.g., "I was referencing t
697
697
  If the user asks for multiple things (e.g., "make hero taller AND add testimonials"), capture ALL parts:
698
698
  - Affected existing modules in \`affectedModules\`
699
699
  - New modules in \`newModules\`
700
- - Set the broadest applicable intent (prefer "modify" + newModules over splitting)`}var Vr,Kr=j(()=>{"use strict";g();Vr={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 Yr(e,t,n,s,o,i,a){i({type:"agent_step",step:"analyzing",label:"Analyzing your request..."});let r=t.modules.map(f=>f.moduleName),l=Wr(t.themeName,r,a,t.brandAssets?.themeContext),c=[],d=t.messages.slice(-6);for(let f of d)if(f.role==="user"||f.role==="assistant"){let h=f.role==="assistant"&&f.content.length>300?f.content.slice(0,300)+"...":f.content;c.push({role:f.role,content:h})}c.push({role:"user",content:e});let u=await Pe(n,s,o,{systemPrompt:l,messages:c,structuredOutput:{schema:Vr,name:"pipeline_plan"},maxTokens:2e3});if(u.type!=="structured"){T.warn("intent-analyzer","Did not get structured output, falling back");let f=t.modules.length===0;return{intent:f?"create":"modify",affectedModules:f?[]:r,unchangedModules:[],newModules:[],guidesNeeded:["design","content","conversion","hubspot_rules","humanify"],designSystemChanges:f}}let m=u.data;return m.affectedModules=m.affectedModules||[],m.unchangedModules=m.unchangedModules||[],m.newModules=m.newModules||[],m.guidesNeeded=m.guidesNeeded||[],T.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:Zd(m)}),m}function Zd(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 zr=j(()=>{"use strict";g();lt();Kr();ve()});function To(e,t){let n=[];return n.push(`You are the Design System Architect for vibeSpot, a HubSpot CMS page builder.
700
+ - Set the broadest applicable intent (prefer "modify" + newModules over splitting)`}var Vr,Kr=j(()=>{"use strict";g();Vr={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 Yr(e,t,n,s,o,i,a){i({type:"agent_step",step:"analyzing",label:"Analyzing your request..."});let r=t.modules.map(f=>f.moduleName),l=Wr(t.themeName,r,a,t.brandAssets?.themeContext),c=[],d=t.messages.slice(-6);for(let f of d)if(f.role==="user"||f.role==="assistant"){let h=f.role==="assistant"&&f.content.length>300?f.content.slice(0,300)+"...":f.content;c.push({role:f.role,content:h})}c.push({role:"user",content:e});let u=await Pe(n,s,o,{systemPrompt:l,messages:c,structuredOutput:{schema:Vr,name:"pipeline_plan"},maxTokens:2e3});if(u.type!=="structured"){T.warn("intent-analyzer","Did not get structured output, falling back");let f=t.modules.length===0;return{intent:f?"create":"modify",affectedModules:f?[]:r,unchangedModules:[],newModules:[],guidesNeeded:["design","content","conversion","hubspot_rules","humanify"],designSystemChanges:f}}let m=u.data;return m.affectedModules=m.affectedModules||[],m.unchangedModules=m.unchangedModules||[],m.newModules=m.newModules||[],m.guidesNeeded=m.guidesNeeded||[],T.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:eu(m)}),m}function eu(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 zr=j(()=>{"use strict";g();ct();Kr();ve()});function To(e,t){let n=[];return n.push(`You are the Design System Architect for vibeSpot, a HubSpot CMS page builder.
701
701
 
702
702
  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.
703
703
 
@@ -821,7 +821,7 @@ ${t}
821
821
  - moduleOrder: list module names in the order they should appear on the page`),(!s||s.includes("content"))&&o.push(`
822
822
 
823
823
  ## Content & Copywriting Guide
824
- ${eu()}`),n?.brandvoice&&o.push(`
824
+ ${tu()}`),n?.brandvoice&&o.push(`
825
825
 
826
826
  ## Brand Voice
827
827
  ${n.brandvoice}`),n?.themeContext&&o.push(`
@@ -830,7 +830,7 @@ ${n.brandvoice}`),n?.themeContext&&o.push(`
830
830
  ${n.themeContext}`),n?.humanify!==!1&&s?.includes("humanify")&&o.push(`
831
831
 
832
832
  ## Anti-AI Copy Rules
833
- ${tu()}`),o.join("")}function ea(){return`### Design Philosophy
833
+ ${nu()}`),o.join("")}function ea(){return`### Design Philosophy
834
834
  You are a senior UI designer. Every page must look professionally designed, not like AI output.
835
835
  Avoid "AI slop": purple gradients on white, cookie-cutter card grids, no personality.
836
836
 
@@ -933,7 +933,7 @@ Include these in shared CSS:
933
933
  | All animations same speed | Stagger with increasing delays |
934
934
  | Skip hover/focus states | Every interactive element needs feedback |
935
935
  | Use \`<br>\` tags for spacing | Use proper margin/padding |
936
- | Put everything in a shadowed card | Vary: full-bleed, contained, floating |`}function eu(){return`### Mandatory Page Sections (generate all)
936
+ | Put everything in a shadowed card | Vary: full-bleed, contained, floating |`}function tu(){return`### Mandatory Page Sections (generate all)
937
937
  1. **Navigation Bar** \u2014 Logo, 4-5 nav links, CTA button, sticky on scroll
938
938
  2. **Hero** \u2014 Badge/pill, primary headline, subheadline, primary + secondary CTA, trust signals, visual element
939
939
  3. **Social Proof Bar** \u2014 Logo strip of 4-6 clients OR stats bar (compact, py-8)
@@ -1021,7 +1021,7 @@ Alternate backgrounds every 2-3 sections to create visual "chapters." Sprinkle t
1021
1021
  - Invent plausible specifics: neighborhood names, "48 hours" not "quickly", "\u20AC49" not "affordable"
1022
1022
  - Keep paragraphs to 2-3 sentences max
1023
1023
  - Aim for 6th-grade reading level
1024
- - Include section labels (UPPERCASE, letter-spacing 0.1em, accent color, 2-3 words) above every headline`}function tu(){return`### Banned Punctuation
1024
+ - Include section labels (UPPERCASE, letter-spacing 0.1em, accent color, 2-3 words) above every headline`}function nu(){return`### Banned Punctuation
1025
1025
  - **Em dashes (\u2014)**: NEVER use. Biggest AI tell. Replace with periods, commas, or parentheses.
1026
1026
  - **Semicolons**: Feel academic, not conversational. Use periods instead.
1027
1027
  - **Exclamation marks**: One per page maximum. Zero is ideal for B2B.
@@ -1063,16 +1063,16 @@ ${Object.entries(h).map(([W,L])=>` ${W.startsWith("--")?W:`--${W}`}: ${L};`).jo
1063
1063
  }
1064
1064
 
1065
1065
  ${f}`));let y=[],v=/\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,C=[...new Set((e.match(v)||[]).map(R=>R.trim()))];if(C.length>0){let R=C.filter(L=>f.toLowerCase().includes(L.toLowerCase())),W=C.filter(L=>!R.includes(L));W.length>0&&y.push(`Note: ${W.join(", ")} not available \u2014 HubSpot modules use system font stacks (no external font imports allowed)`)}let k=[`Design system: ${m.aesthetic||"created"} | ${Object.keys(h||{}).length} variables, ${f.length} chars CSS`,...y];a({type:"agent_decision",step:"designing",decision:k.join(`
1066
- `)}),a({type:"design_system_ready",sharedCss:f,sharedJs:m.sharedJs||"",aesthetic:m.aesthetic||""}),a({type:"agent_step",step:"designing",label:"Planning modules..."});let P=Qr(n.themeName,f,n.brandAssets,t.guidesNeeded),M=`## User Request
1067
- ${e}`;t.newModules.length>0&&(M+=`
1066
+ `)}),a({type:"design_system_ready",sharedCss:f,sharedJs:m.sharedJs||"",aesthetic:m.aesthetic||""}),a({type:"agent_step",step:"designing",label:"Planning modules..."});let P=Qr(n.themeName,f,n.brandAssets,t.guidesNeeded),O=`## User Request
1067
+ ${e}`;t.newModules.length>0&&(O+=`
1068
1068
 
1069
1069
  ## Planned Modules
1070
1070
  ${t.newModules.map((R,W)=>`${W+1}. **${R.name}** \u2014 ${R.description}`).join(`
1071
- `)}`),n.modules.length>0&&!t.designSystemChanges&&(M+=`
1071
+ `)}`),n.modules.length>0&&!t.designSystemChanges&&(O+=`
1072
1072
 
1073
1073
  ## Existing Modules (keeping)
1074
1074
  ${n.modules.map(R=>`- ${R.moduleName}`).join(`
1075
- `)}`);let G=await Pe(s,o,i,{systemPrompt:P,messages:[{role:"user",content:M}],structuredOutput:{schema:Zr,name:"module_plan"},maxTokens:8e3}),E;return G.type!=="structured"?(T.warn("page-architect","Module planner: did not get structured output, using fallback"),E={modules:t.newModules.map(R=>({name:R.name,description:R.description,contentBrief:"Generate appropriate content",layoutNotes:"Use responsive layout"})),moduleOrder:t.newModules.map(R=>R.name),narrative:"Page generated from user request"}):(E=G.data,T.info("page-architect","Module plan",{moduleCount:E.modules.length})),a({type:"agent_decision",step:"designing",decision:`Page: ${E.narrative} | ${E.modules.length} modules planned`}),{designSystem:{cssVariables:m.cssVariables||{},sharedCss:f,sharedJs:m.sharedJs},modules:E.modules,moduleOrder:E.moduleOrder,narrative:E.narrative}}var sa=j(()=>{"use strict";g();lt();ta();ve()});function oa(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 ia=j(()=>{"use strict";g()});function $o(e,t,n,s){let o=[];return o.push(`You are a Module Developer for vibeSpot, a HubSpot CMS page builder.
1075
+ `)}`);let G=await Pe(s,o,i,{systemPrompt:P,messages:[{role:"user",content:O}],structuredOutput:{schema:Zr,name:"module_plan"},maxTokens:8e3}),E;return G.type!=="structured"?(T.warn("page-architect","Module planner: did not get structured output, using fallback"),E={modules:t.newModules.map(R=>({name:R.name,description:R.description,contentBrief:"Generate appropriate content",layoutNotes:"Use responsive layout"})),moduleOrder:t.newModules.map(R=>R.name),narrative:"Page generated from user request"}):(E=G.data,T.info("page-architect","Module plan",{moduleCount:E.modules.length})),a({type:"agent_decision",step:"designing",decision:`Page: ${E.narrative} | ${E.modules.length} modules planned`}),{designSystem:{cssVariables:m.cssVariables||{},sharedCss:f,sharedJs:m.sharedJs},modules:E.modules,moduleOrder:E.moduleOrder,narrative:E.narrative}}var sa=j(()=>{"use strict";g();ct();ta();ve()});function oa(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 ia=j(()=>{"use strict";g()});function $o(e,t,n,s){let o=[];return o.push(`You are a Module Developer for vibeSpot, a HubSpot CMS page builder.
1076
1076
 
1077
1077
  Your job: generate ONE HubSpot CMS module. You receive a module specification and must produce the complete module code.
1078
1078
 
@@ -1212,24 +1212,24 @@ ${n.moduleCss}
1212
1212
  **module.js:**
1213
1213
  \`\`\`js
1214
1214
  ${n.moduleJs}
1215
- \`\`\``)),s.join("")}var ca,da=j(()=>{"use strict";g();qe();ca={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 ua(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=$o(s,n,c,d),f=u?ra(s,n,c,d):void 0,h=oa(r),y=t.length,v=t.map((k,P)=>h(async()=>{l({type:"module_progress",module:k.name,status:"generating",current:P+1,total:y});let M="";for(let G=0;G<2;G++)try{G>0&&(T.warn("module-developer",`${k.name}: retrying after failure (attempt ${G+1})`),l({type:"module_progress",module:k.name,status:"retrying",current:P+1,total:y}));let E=await ma(e,k,m,o,i,a,0,f);return l({type:"module_progress",module:k.name,status:"complete",current:P+1,total:y,moduleFiles:E}),{moduleName:k.name,module:E}}catch(E){M=E instanceof Error?E.message:typeof E=="object"&&E!==null?JSON.stringify(E):String(E),T.error("module-developer",`Failed: ${k.name} (attempt ${G+1})`,{error:M})}return l({type:"module_progress",module:k.name,status:"failed",current:P+1,total:y}),{moduleName:k.name,error:M}}));return(await Promise.allSettled(v)).map(k=>k.status==="fulfilled"?k.value:{moduleName:"unknown",error:k.reason instanceof Error?k.reason.message:String(k.reason)})}async function ma(e,t,n,s,o,i,a=0,r){let l=la(e,t,t.existingCode),c=await Pe(s,o,i,{systemPrompt:n,systemBlocks:r,messages:[{role:"user",content:l}],structuredOutput:{schema:ca,name:"module_output"},maxTokens:16e3});if(c.type!=="structured"){if(a<2)return T.warn("module-developer",`${t.name}: no structured output, retry ${a+1}`),ma(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 pa=j(()=>{"use strict";g();lt();ia();da();ve()});function ga(e,t,n){return n({type:"agent_step",step:"quality_check",label:"Quality check..."}),e.map(s=>{let o=[],i={...s};i.fieldsJson=fa(i.fieldsJson,i.moduleName,"fieldsJson",o),i.metaJson=fa(i.metaJson,i.moduleName,"metaJson",o),i.fieldsJson=nu(i.fieldsJson,i.moduleName,o),i.fieldsJson=su(i.fieldsJson,i.moduleName,o),i.moduleCss=ou(i.moduleCss,i.moduleName,"moduleCss",o),iu(i.moduleCss,i.moduleName,t,o),i.moduleHtml=ru(i.moduleHtml,i.moduleName,o),i.metaJson=au(i.metaJson,i.moduleName,o);let a=o.every(r=>r.autoFixed);return o.length>0&&T.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 fa(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):(Ge(e)===null&&s.push({module:t,field:n,message:`Invalid JSON in ${n}`,autoFixed:!1}),e)}function nu(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 su(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 ou(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 iu(e,t,n,s){if(!e)return;let o=/\.([a-zA-Z][\w-]*)/g,i,a=0;for(;(i=o.exec(e))!==null;){let r=i[1];r.startsWith(n+"-")||r==="visible"||r==="active"||r==="scroll-animate"||r.startsWith("body-wrapper")||r.startsWith("dnd-")||r.startsWith("row-")||a++}a>3&&s.push({module:t,field:"moduleCss",message:`${a} CSS classes without "${n}-" prefix`,autoFixed:!1})}function ru(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(`
1215
+ \`\`\``)),s.join("")}var ca,da=j(()=>{"use strict";g();qe();ca={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 ua(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=$o(s,n,c,d),f=u?ra(s,n,c,d):void 0,h=oa(r),y=t.length,v=t.map((k,P)=>h(async()=>{l({type:"module_progress",module:k.name,status:"generating",current:P+1,total:y});let O="";for(let G=0;G<2;G++)try{G>0&&(T.warn("module-developer",`${k.name}: retrying after failure (attempt ${G+1})`),l({type:"module_progress",module:k.name,status:"retrying",current:P+1,total:y}));let E=await ma(e,k,m,o,i,a,0,f);return l({type:"module_progress",module:k.name,status:"complete",current:P+1,total:y,moduleFiles:E}),{moduleName:k.name,module:E}}catch(E){O=E instanceof Error?E.message:typeof E=="object"&&E!==null?JSON.stringify(E):String(E),T.error("module-developer",`Failed: ${k.name} (attempt ${G+1})`,{error:O})}return l({type:"module_progress",module:k.name,status:"failed",current:P+1,total:y}),{moduleName:k.name,error:O}}));return(await Promise.allSettled(v)).map(k=>k.status==="fulfilled"?k.value:{moduleName:"unknown",error:k.reason instanceof Error?k.reason.message:String(k.reason)})}async function ma(e,t,n,s,o,i,a=0,r){let l=la(e,t,t.existingCode),c=await Pe(s,o,i,{systemPrompt:n,systemBlocks:r,messages:[{role:"user",content:l}],structuredOutput:{schema:ca,name:"module_output"},maxTokens:16e3});if(c.type!=="structured"){if(a<2)return T.warn("module-developer",`${t.name}: no structured output, retry ${a+1}`),ma(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 pa=j(()=>{"use strict";g();ct();ia();da();ve()});function ga(e,t,n){return n({type:"agent_step",step:"quality_check",label:"Quality check..."}),e.map(s=>{let o=[],i={...s};i.fieldsJson=fa(i.fieldsJson,i.moduleName,"fieldsJson",o),i.metaJson=fa(i.metaJson,i.moduleName,"metaJson",o),i.fieldsJson=su(i.fieldsJson,i.moduleName,o),i.fieldsJson=ou(i.fieldsJson,i.moduleName,o),i.moduleCss=iu(i.moduleCss,i.moduleName,"moduleCss",o),i.moduleCss=au(i.moduleCss,i.moduleName,t,o),i.moduleHtml=lu(i.moduleHtml,i.moduleName,t,o),i.moduleHtml=du(i.moduleHtml,i.moduleName,o),i.metaJson=uu(i.metaJson,i.moduleName,o);let a=o.every(r=>r.autoFixed);return o.length>0&&T.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 fa(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):(Ge(e)===null&&s.push({module:t,field:n,message:`Invalid JSON in ${n}`,autoFixed:!1}),e)}function su(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 ou(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 iu(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 ha(e){return ru.has(e)||e.startsWith("body-wrapper")||e.startsWith("dnd-")||e.startsWith("row-")||e.startsWith("hs-")||e.startsWith("hs_")}function au(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)&&!ha(c)&&a.add(c)}if(a.size<=3)return e;let l=e;for(let c of a){let d=new RegExp(`\\.${cu(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 lu(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(f=>f&&!f.startsWith(o)&&!ha(f)&&/^[a-zA-Z][\w-]*$/.test(f)?(u=!0,o+f):f);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 cu(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function du(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(`
1216
1216
  `);s=`${s}
1217
- ${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 au(e,t,n){let s=Ge(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 ha=j(()=>{"use strict";g();cs();ve()});import{execSync as lu}from"child_process";async function ya(e,t,n,s,o,i,a,r){let l=Date.now(),c=i;if(mn(n)){let F={"claude-code":"claude","gemini-cli":"gemini","codex-cli":"codex"}[n];if(F)try{lu(`command -v ${F}`,{stdio:"ignore"})}catch{throw new Error(`CLI engine "${n}" requires "${F}" to be installed and on your PATH.`)}}let d=await Yr(e,t,n,s,o,a,r);if(d.intent==="question"&&d.answer){let U=Date.now()-l;return a({type:"pipeline_complete",modulesGenerated:0,modulesUnchanged:t.modules.length,durationMs:U}),{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:U}}}let u=null,m=t.sharedCss,f=t.sharedJs;(d.intent==="create"||d.designSystemChanges)&&(u=await na(e,d,t,n,s,o,a),m=u.designSystem.sharedCss||m,f=u.designSystem.sharedJs||f,a({type:"blueprint_ready",moduleOrder:u.moduleOrder,sharedCss:m,sharedJs:f}));let y=[];if(u)for(let U of u.modules)y.push({name:U.name,description:U.description,contentBrief:U.contentBrief,layoutNotes:U.layoutNotes});else{for(let U of d.newModules)y.push({name:U.name,description:U.description,contentBrief:"Generate appropriate content based on the user request",layoutNotes:"Use responsive layout matching the existing design system"});for(let U of d.affectedModules){let F=t.modules.find(X=>X.moduleName===U);F&&y.push({name:U,description:`Modify existing module: ${U}`,contentBrief:"Apply the user's requested changes",layoutNotes:"Preserve existing layout unless changes are requested",existingCode:F})}}let v=[],C=[];if(y.length>0){let U=await ua(e,y,m,t.themeName,n,s,o,c,a,d.guidesNeeded,t.brandAssets);for(let F of U)F.module?v.push(F.module):C.push(F.moduleName)}let k=null;if(v.length>0){k=ga(v,t.themeName,a),v=k.map(F=>F.module);let U=k.reduce((F,X)=>F+X.issues.length,0);if(U>0){let F=k.reduce((le,Bo)=>le+Bo.issues.filter(jt=>jt.autoFixed).length,0);T.info("pipeline",`Quality check: ${U} issues, ${F} auto-fixed`);let X=k.flatMap(le=>le.issues).map(le=>`${le.autoFixed?"\u2713":"\u26A0"} ${le.module}: ${le.message}`).join(`
1217
+ ${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 uu(e,t,n){let s=Ge(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 ru,ya=j(()=>{"use strict";g();cs();ve();ru=new Set(["visible","active","scroll-animate","hidden","open","closed","fade-in","fade-out","is-active","is-open","is-visible"])});import{execSync as mu}from"child_process";async function ba(e,t,n,s,o,i,a,r){let l=Date.now(),c=i;if(mn(n)){let F={"claude-code":"claude","gemini-cli":"gemini","codex-cli":"codex"}[n];if(F)try{mu(`command -v ${F}`,{stdio:"ignore"})}catch{throw new Error(`CLI engine "${n}" requires "${F}" to be installed and on your PATH.`)}}let d=await Yr(e,t,n,s,o,a,r);if(d.intent==="question"&&d.answer){let U=Date.now()-l;return a({type:"pipeline_complete",modulesGenerated:0,modulesUnchanged:t.modules.length,durationMs:U,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:U}}}let u=null,m=t.sharedCss,f=t.sharedJs;(d.intent==="create"||d.designSystemChanges)&&(u=await na(e,d,t,n,s,o,a),m=u.designSystem.sharedCss||m,f=u.designSystem.sharedJs||f,a({type:"blueprint_ready",moduleOrder:u.moduleOrder,sharedCss:m,sharedJs:f}));let y=[];if(u)for(let U of u.modules)y.push({name:U.name,description:U.description,contentBrief:U.contentBrief,layoutNotes:U.layoutNotes});else{for(let U of d.newModules)y.push({name:U.name,description:U.description,contentBrief:"Generate appropriate content based on the user request",layoutNotes:"Use responsive layout matching the existing design system"});for(let U of d.affectedModules){let F=t.modules.find(X=>X.moduleName===U);F&&y.push({name:U,description:`Modify existing module: ${U}`,contentBrief:"Apply the user's requested changes",layoutNotes:"Preserve existing layout unless changes are requested",existingCode:F})}}let v=[],C=[];if(y.length>0){let U=await ua(e,y,m,t.themeName,n,s,o,c,a,d.guidesNeeded,t.brandAssets);for(let F of U)F.module?v.push(F.module):C.push(F.moduleName)}let k=null;if(v.length>0){k=ga(v,t.themeName,a),v=k.map(F=>F.module);let U=k.reduce((F,X)=>F+X.issues.length,0);if(U>0){let F=k.reduce((le,Bo)=>le+Bo.issues.filter(jt=>jt.autoFixed).length,0);T.info("pipeline",`Quality check: ${U} issues, ${F} auto-fixed`);let X=k.flatMap(le=>le.issues).map(le=>`${le.autoFixed?"\u2713":"\u26A0"} ${le.module}: ${le.message}`).join(`
1218
1218
  `);a({type:"agent_decision",step:"quality_check",decision:`${U} issues found, ${F} auto-fixed
1219
- ${X}`})}else a({type:"agent_decision",step:"quality_check",decision:"All modules passed quality checks"})}let P=cu(t,d,v,u,r),M=du(t,d,u,P);if(u?.moduleOrder?.length){let U=new Set(u.moduleOrder),F=P.filter(X=>!U.has(X.moduleName)).map(X=>X.moduleName);F.length>0&&a({type:"agent_decision",step:"quality_check",decision:`\u26A0 ${F.length} module${F.length===1?"":"s"} missing from page order \u2014 auto-inserted: ${F.join(", ")}`})}let G=Date.now()-l,E=v.length,R=d.unchangedModules.length,W=k?k.flatMap(U=>U.issues):[],L=uu(d,E,R,C,G,u,W);return C.length>0?a({type:"pipeline_partial",succeeded:v.map(U=>U.moduleName),failed:C,durationMs:G}):a({type:"pipeline_complete",modulesGenerated:E,modulesUnchanged:R,durationMs:G}),{modules:P,moduleOrder:M,sharedCss:m,sharedJs:f,assistantMessage:L,stats:{modulesGenerated:E,modulesUnchanged:R,modulesFailed:C.length,durationMs:G}}}function cu(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 du(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),T.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 uu(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(`
1219
+ ${X}`})}else a({type:"agent_decision",step:"quality_check",decision:"All modules passed quality checks"})}let P=pu(t,d,v,u,r),O=fu(t,d,u,P);if(u?.moduleOrder?.length){let U=new Set(u.moduleOrder),F=P.filter(X=>!U.has(X.moduleName)).map(X=>X.moduleName);F.length>0&&a({type:"agent_decision",step:"quality_check",decision:`\u26A0 ${F.length} module${F.length===1?"":"s"} missing from page order \u2014 auto-inserted: ${F.join(", ")}`})}let G=Date.now()-l,E=v.length,R=d.unchangedModules.length,W=k?k.flatMap(U=>U.issues):[],L=gu(d,E,R,C,G,u,W);return C.length>0?a({type:"pipeline_partial",succeeded:v.map(U=>U.moduleName),failed:C,durationMs:G}):a({type:"pipeline_complete",modulesGenerated:E,modulesUnchanged:R,durationMs:G}),{modules:P,moduleOrder:O,sharedCss:m,sharedJs:f,assistantMessage:L,stats:{modulesGenerated:E,modulesUnchanged:R,modulesFailed:C.length,durationMs:G}}}function pu(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 fu(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),T.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 gu(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(`
1220
1220
 
1221
1221
  ${i.narrative}`),s.length>0&&l.push(`
1222
1222
 
1223
1223
  **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(`
1224
1224
 
1225
1225
  ${u.join(`
1226
- `)}`)}return l.join("")}var ba=j(()=>{"use strict";g();lt();zr();sa();pa();ha();ve();lt()});var Sa={};tt(Sa,{applyPipelineResult:()=>No,handleAgenticGenerate:()=>Mo,handleGenerate:()=>mu,handleGenerateStream:()=>pn,isGenerating:()=>Nt,resolveAgenticEngine:()=>ps,setParseWarningCallback:()=>Po,shouldUseAgenticMode:()=>Ro});import{execSync as Eo}from"child_process";function Po(e){_o=e}function Nt(){return bt!==null}function yt(e){if(bt){let t=S();if(!t||t.id!==bt){T.warn("ai-handler","Session changed during generation \u2014 discarding AI output");return}}it("assistant",e),Tr(e,_o||void 0),D()}async function pn(e,t,n,s){let o=S();if(!o)throw new Error("No active session");bt=o.id;let a=s?.length?Gr(s):void 0;try{let r=_(),l=r.aiEngine||Oo();switch(l){case"anthropic-api":case"api":{let c=ge("anthropic-api",r);if(!c)throw new Error("Anthropic API key not configured. Open Settings to add one.");await Nr(e,c,o.themeName,r.anthropicApiModel||"claude-sonnet-4-6",t,n,yt,a);break}case"claude-oauth":{await Rr(e,o.themeName,r.anthropicApiModel||"claude-sonnet-4-6",t,n,yt,a);break}case"openai-api":{let c=ge("openai-api",r);if(!c)throw new Error("OpenAI API key not configured. Open Settings to add one.");await Fr(e,c,o.themeName,r.openaiApiModel||"gpt-4o",t,n,yt,a);break}case"gemini-api":{let c=ge("gemini-api",r);if(!c)throw new Error("Gemini API key not configured. Open Settings to add one.");await jr(e,c,o.themeName,t,n,yt,a);break}case"claude-code":await Jr(e,o.themeName,t,n,yt,a);break;case"gemini-cli":await bo("gemini",e,o.themeName,t,n,yt,a);break;case"codex-cli":await bo("codex",e,o.themeName,t,n,yt,a);break;default:throw new Error(`Unknown AI engine: ${l}. Open Settings to configure one.`)}}finally{bt=null,_o=null}}function Oo(){let e=_();if(Re())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 Eo("claude --version",{stdio:"pipe"}),"claude-code"}catch{}try{return Eo("gemini --version",{stdio:"pipe"}),"gemini-cli"}catch{}try{return Eo("codex --version",{stdio:"pipe"}),"codex-cli"}catch{}throw new Error("No AI engine available. Open Settings to configure one.")}async function mu(e){let t="";return await pn(e,n=>{t+=n}),t}function pu(){let e=S(),t=Ce(),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 ps(e){let t=e.aiEngine||Oo();if(!ms(t))throw new Error("Agentic pipeline is not available for this engine.");if(mn(t)){let o="";return t==="claude-code"&&(o=e.claudeCodeModel||""),{engine:t,apiKey:"",model:o}}let n;if(t==="claude-oauth"){if(!Re())throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");n="oauth"}else n=ge(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 Mo(e,t,n){let s=S();if(!s)throw new Error("No active session");let o=s.id;bt=o;try{let i=_(),{engine:a,apiKey:r,model:l}=ps(i),c=i.agenticConcurrency||20,d=pu(),u=rt(),m=new Set(d.modules.map(v=>v.moduleName)),f=u.filter(v=>!m.has(v.module.moduleName)).map(v=>({name:v.module.moduleName,usedIn:v.usedIn})),h=await ya(e,d,a,r,l,c,t,f),y=S();if(!y||y.id!==o)throw T.warn("ai-handler","Session changed during agentic generation \u2014 discarding output"),new Error("Session changed during generation");return h}finally{bt=null}}function No(e,t){Le({modules:e.modules,sharedCss:e.sharedCss,sharedJs:e.sharedJs}),Et(e.moduleOrder),it("assistant",e.assistantMessage,t),D()}function Ro(){let e=_(),t=e.aiEngine||Oo();return ms(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 _o,bt,fs=j(()=>{"use strict";g();Z();Se();cs();ve();So();Ke();Co();ba();_o=null;bt=null});var ws={};tt(ws,{collectThemeFiles:()=>sl,extractDesignContext:()=>Nu});import{existsSync as Ss,readdirSync as vs,readFileSync as _u}from"fs";import{join as Ue}from"path";import{spawn as Pu}from"child_process";async function nl(){return jo||(jo=(await import("@anthropic-ai/sdk")).default),jo}function hn(e){try{return _u(e,"utf-8")}catch{return""}}function sl(e){let t=[],n=0;function s(r,l){if(!l.trim())return!0;let c=`
1226
+ `)}`)}return l.join("")}var Sa=j(()=>{"use strict";g();ct();zr();sa();pa();ya();ve();ct()});var va={};nt(va,{applyPipelineResult:()=>No,handleAgenticGenerate:()=>Oo,handleGenerate:()=>hu,handleGenerateStream:()=>pn,isGenerating:()=>Nt,resolveAgenticEngine:()=>ps,setParseWarningCallback:()=>Po,shouldUseAgenticMode:()=>Ro});import{execSync as Eo}from"child_process";function Po(e){_o=e}function Nt(){return bt!==null}function yt(e){if(bt){let t=S();if(!t||t.id!==bt){T.warn("ai-handler","Session changed during generation \u2014 discarding AI output");return}}rt("assistant",e),Tr(e,_o||void 0),D()}async function pn(e,t,n,s){let o=S();if(!o)throw new Error("No active session");bt=o.id;let a=s?.length?Gr(s):void 0;try{let r=_(),l=r.aiEngine||Mo();switch(l){case"anthropic-api":case"api":{let c=ge("anthropic-api",r);if(!c)throw new Error("Anthropic API key not configured. Open Settings to add one.");await Nr(e,c,o.themeName,r.anthropicApiModel||"claude-sonnet-4-6",t,n,yt,a);break}case"claude-oauth":{await Rr(e,o.themeName,r.anthropicApiModel||"claude-sonnet-4-6",t,n,yt,a);break}case"openai-api":{let c=ge("openai-api",r);if(!c)throw new Error("OpenAI API key not configured. Open Settings to add one.");await Fr(e,c,o.themeName,r.openaiApiModel||"gpt-4o",t,n,yt,a);break}case"gemini-api":{let c=ge("gemini-api",r);if(!c)throw new Error("Gemini API key not configured. Open Settings to add one.");await jr(e,c,o.themeName,t,n,yt,a);break}case"claude-code":await Jr(e,o.themeName,t,n,yt,a);break;case"gemini-cli":await bo("gemini",e,o.themeName,t,n,yt,a);break;case"codex-cli":await bo("codex",e,o.themeName,t,n,yt,a);break;default:throw new Error(`Unknown AI engine: ${l}. Open Settings to configure one.`)}}finally{bt=null,_o=null}}function Mo(){let e=_();if(Re())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 Eo("claude --version",{stdio:"pipe"}),"claude-code"}catch{}try{return Eo("gemini --version",{stdio:"pipe"}),"gemini-cli"}catch{}try{return Eo("codex --version",{stdio:"pipe"}),"codex-cli"}catch{}throw new Error("No AI engine available. Open Settings to configure one.")}async function hu(e){let t="";return await pn(e,n=>{t+=n}),t}function yu(){let e=S(),t=Ce(),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 ps(e){let t=e.aiEngine||Mo();if(!ms(t))throw new Error("Agentic pipeline is not available for this engine.");if(mn(t)){let o="";return t==="claude-code"&&(o=e.claudeCodeModel||""),{engine:t,apiKey:"",model:o}}let n;if(t==="claude-oauth"){if(!Re())throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");n="oauth"}else n=ge(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 Oo(e,t,n){let s=S();if(!s)throw new Error("No active session");let o=s.id;bt=o;try{let i=_(),{engine:a,apiKey:r,model:l}=ps(i),c=i.agenticConcurrency||20,d=yu(),u=at(),m=new Set(d.modules.map(v=>v.moduleName)),f=u.filter(v=>!m.has(v.module.moduleName)).map(v=>({name:v.module.moduleName,usedIn:v.usedIn})),h=await ba(e,d,a,r,l,c,t,f),y=S();if(!y||y.id!==o)throw T.warn("ai-handler","Session changed during agentic generation \u2014 discarding output"),new Error("Session changed during generation");return h}finally{bt=null}}function No(e,t){Le({modules:e.modules,sharedCss:e.sharedCss,sharedJs:e.sharedJs}),Et(e.moduleOrder),rt("assistant",e.assistantMessage,t),D()}function Ro(){let e=_(),t=e.aiEngine||Mo();return ms(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 _o,bt,fs=j(()=>{"use strict";g();Z();Se();cs();ve();So();Ke();Co();Sa();_o=null;bt=null});var ws={};nt(ws,{collectThemeFiles:()=>ol,extractDesignContext:()=>Ju});import{existsSync as Ss,readdirSync as vs,readFileSync as Nu}from"fs";import{join as Ue}from"path";import{spawn as Ru}from"child_process";async function sl(){return jo||(jo=(await import("@anthropic-ai/sdk")).default),jo}function hn(e){try{return Nu(e,"utf-8")}catch{return""}}function ol(e){let t=[],n=0;function s(r,l){if(!l.trim())return!0;let c=`
1227
1227
  ### ${r}
1228
1228
  \`\`\`
1229
1229
  ${l}
1230
1230
  \`\`\`
1231
- `;return n+c.length>Ou?!1:(t.push(c),n+=c.length,!0)}let o=hn(Ue(e,"theme.json"));o&&s("theme.json",o);let i=Ue(e,"css");if(Ss(i)){for(let r of vs(i).filter(l=>l.endsWith(".css")))if(!s(`css/${r}`,hn(Ue(i,r))))break}let a=Ue(e,"modules");if(Ss(a))for(let r of vs(a).filter(l=>l.endsWith(".module"))){let l=Ue(a,r),c=hn(Ue(l,"module.css"));if(c&&!s(`modules/${r}/module.css`,c))break}if(Ss(a))for(let r of vs(a).filter(l=>l.endsWith(".module"))){let l=Ue(a,r),c=hn(Ue(l,"module.html"));if(c&&!s(`modules/${r}/module.html`,c))break}if(Ss(a))for(let r of vs(a).filter(l=>l.endsWith(".module"))){let l=Ue(a,r),c=hn(Ue(l,"fields.json"));if(c&&!s(`modules/${r}/fields.json`,c))break}return t.join("")}function Mu(){if(!xs)try{xs=A(vn("extraction-prompt.md"))}catch{xs=""}return xs}function Jo(e,t,n){return new Promise((s,o)=>{let i={...process.env};delete i.CLAUDECODE;let a=Pu(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 Nu(e,t){t?.({status:"Collecting theme files..."});let n=sl(e);if(!n.trim())throw new Error("No CSS, HTML, or fields.json files found in theme.");let s=Mu();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:
1232
- ${n}`;t?.({status:"Analyzing design patterns..."});let i=_(),a=i.aiEngine||"anthropic-api",r="";switch(a){case"anthropic-api":case"api":{let l=ge("anthropic-api");if(!l)throw new Error("Anthropic API key not configured. Open Settings to add one.");let c=await nl();r=(await new c({apiKey:l}).messages.create({model:i.anthropicApiModel||"claude-sonnet-4-6",max_tokens:8e3,system:s,messages:[{role:"user",content:o}]})).content.filter(m=>m.type==="text").map(m=>m.text).join("");break}case"claude-oauth":{let{getValidAccessToken:l,OAUTH_EXTRA_HEADERS:c,OAUTH_SYSTEM_PREFIX:d}=await Promise.resolve().then(()=>(Ke(),Ms)),u=await l();if(!u)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let m=await nl();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}],messages:[{role:"user",content:o}]})).content.filter(y=>y.type==="text").map(y=>y.text).join("");break}case"openai-api":{let l=ge("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=ge("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}
1231
+ `;return n+c.length>Fu?!1:(t.push(c),n+=c.length,!0)}let o=hn(Ue(e,"theme.json"));o&&s("theme.json",o);let i=Ue(e,"css");if(Ss(i)){for(let r of vs(i).filter(l=>l.endsWith(".css")))if(!s(`css/${r}`,hn(Ue(i,r))))break}let a=Ue(e,"modules");if(Ss(a))for(let r of vs(a).filter(l=>l.endsWith(".module"))){let l=Ue(a,r),c=hn(Ue(l,"module.css"));if(c&&!s(`modules/${r}/module.css`,c))break}if(Ss(a))for(let r of vs(a).filter(l=>l.endsWith(".module"))){let l=Ue(a,r),c=hn(Ue(l,"module.html"));if(c&&!s(`modules/${r}/module.html`,c))break}if(Ss(a))for(let r of vs(a).filter(l=>l.endsWith(".module"))){let l=Ue(a,r),c=hn(Ue(l,"fields.json"));if(c&&!s(`modules/${r}/fields.json`,c))break}return t.join("")}function ju(){if(!xs)try{xs=A(vn("extraction-prompt.md"))}catch{xs=""}return xs}function Jo(e,t,n){return new Promise((s,o)=>{let i={...process.env};delete i.CLAUDECODE;let a=Ru(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 Ju(e,t){t?.({status:"Collecting theme files..."});let n=ol(e);if(!n.trim())throw new Error("No CSS, HTML, or fields.json files found in theme.");let s=ju();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:
1232
+ ${n}`;t?.({status:"Analyzing design patterns..."});let i=_(),a=i.aiEngine||"anthropic-api",r="";switch(a){case"anthropic-api":case"api":{let l=ge("anthropic-api");if(!l)throw new Error("Anthropic API key not configured. Open Settings to add one.");let c=await sl();r=(await new c({apiKey:l}).messages.create({model:i.anthropicApiModel||"claude-sonnet-4-6",max_tokens:8e3,system:s,messages:[{role:"user",content:o}]})).content.filter(m=>m.type==="text").map(m=>m.text).join("");break}case"claude-oauth":{let{getValidAccessToken:l,OAUTH_EXTRA_HEADERS:c,OAUTH_SYSTEM_PREFIX:d}=await Promise.resolve().then(()=>(Ke(),Os)),u=await l();if(!u)throw new Error("Claude OAuth session expired. Please re-authenticate in Settings.");let m=await sl();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}],messages:[{role:"user",content:o}]})).content.filter(y=>y.type==="text").map(y=>y.text).join("");break}case"openai-api":{let l=ge("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=ge("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}
1233
1233
 
1234
1234
  ## User Request
1235
1235
  ${o}`,c=["--print"];i.claudeCodeModel&&c.push("--model",i.claudeCodeModel),r=await Jo("claude",c,l);break}case"gemini-cli":{let l=`${s}
@@ -1238,7 +1238,7 @@ ${o}`,c=["--print"];i.claudeCodeModel&&c.push("--model",i.claudeCodeModel),r=awa
1238
1238
  ${o}`;r=await Jo("gemini",[],l);break}case"codex-cli":{let l=`${s}
1239
1239
 
1240
1240
  ## User Request
1241
- ${o}`;r=await Jo("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 jo,Ou,xs,Cs=j(()=>{"use strict";g();Q();Z();jo=null;Ou=8e4;xs=""});var ol={};tt(ol,{extractBrandvoice:()=>Ru});async function Ru(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.
1241
+ ${o}`;r=await Jo("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 jo,Fu,xs,Cs=j(()=>{"use strict";g();Q();Z();jo=null;Fu=8e4;xs=""});var il={};nt(il,{extractBrandvoice:()=>Du});async function Du(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.
1242
1242
 
1243
1243
  Return a markdown document with these sections (skip any section where the content provides no signal):
1244
1244
 
@@ -1258,7 +1258,7 @@ Typical sentence length, structure, use of questions, imperatives, etc.
1258
1258
  ## Dos and Don'ts
1259
1259
  3-4 practical rules for writing in this voice (e.g., "Do: Lead with benefits, not features", "Don't: Use jargon without context").
1260
1260
 
1261
- Keep it actionable \u2014 this guide will be fed to AI to maintain consistent copy across pages.`;try{let i=await Pe(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:(T.info("brandvoice-extractor",`Extracted brand voice (${a.length} chars)`),a.trim())}catch(i){let a=i instanceof Error?i.message:String(i);return T.warn("brandvoice-extractor",`Brand voice extraction failed: ${a}`),null}}var il=j(()=>{"use strict";g();lt();ve()});var Do={};tt(Do,{extractThemeContext:()=>Fu});async function Fu(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.
1261
+ Keep it actionable \u2014 this guide will be fed to AI to maintain consistent copy across pages.`;try{let i=await Pe(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:(T.info("brandvoice-extractor",`Extracted brand voice (${a.length} chars)`),a.trim())}catch(i){let a=i instanceof Error?i.message:String(i);return T.warn("brandvoice-extractor",`Brand voice extraction failed: ${a}`),null}}var rl=j(()=>{"use strict";g();ct();ve()});var Do={};nt(Do,{extractThemeContext:()=>Hu});async function Hu(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.
1262
1262
 
1263
1263
  Return a markdown document with these sections (skip any section where the content provides no information):
1264
1264
 
@@ -1280,11 +1280,11 @@ Specific terms, product names, or branded language used consistently.
1280
1280
  Keep it concise \u2014 this brief is used as context for AI-generated content on other pages in the same theme.${t?`
1281
1281
 
1282
1282
  Existing product context (update if the new content adds info, keep what's still accurate):
1283
- ${t}`:""}`;try{let r=await Pe(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:(T.info("context-extractor",`Extracted theme context (${l.length} chars)`),l.trim())}catch(r){let l=r instanceof Error?r.message:String(r);return T.warn("context-extractor",`Theme context extraction failed: ${l}`),null}}var Ho=j(()=>{"use strict";g();lt();ve()});g();g();import{Command as Zu}from"commander";g();g();g();import vt from"chalk";var Me={accent:"#FF7A59",accentBright:"#FF9A7A",success:"#00BDA5",info:"#0066FF",warn:"#FFB020",error:"#E23D2D",muted:"#8B8D91",vibes:"#00BDD6"},Wo=!!process.env.NO_COLOR;function We(e){return Wo?vt:vt.hex(e)}var I={accent:We(Me.accent),accentBright:We(Me.accentBright),success:We(Me.success),info:We(Me.info),warn:We(Me.warn),error:We(Me.error),muted:We(Me.muted),vibes:We(Me.vibes),heading:Wo?vt.bold:vt.bold.hex(Me.accent),command:We(Me.accentBright),dim:vt.dim,bold:vt.bold};Q();function Ne(){let e=I.vibes,t=I.accent,n=I.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")} ${I.dim(`v${wt()}`)}`),console.log()}g();g();ut();Z();Ke();import{join as In}from"path";import{homedir as Tn}from"os";import{readFileSync as ei,existsSync as $n,readdirSync as Yl}from"fs";var mt=process.platform==="win32"?"where":"which";function Gt(){let e=$("node --version");return{name:"Node.js",found:e.success,version:e.stdout.replace(/^v/,""),path:$(`${mt} node`).stdout}}function Ut(){let e=$("git --version");return{name:"Git",found:e.success,version:e.stdout.replace("git version ",""),path:$(`${mt} git`).stdout}}function Fe(){let e=$("hs --version");return{name:"HubSpot CLI",found:e.success,version:e.stdout,path:$(`${mt} hs`).stdout}}function Bt(){let e=$("claude --version");if(!e.success)return{name:"Claude Code",found:!1,version:"",path:"",authenticated:!1,authDetail:"Not installed"};let t=In(Tn(),".claude"),n=!1,s="Not signed in \u2014 run `claude` to authenticate";try{if($n(t)){let o=Yl(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:$(`${mt} claude`).stdout,authenticated:n,authDetail:s}}function Wt(e){try{let t=In(Tn(),".hscli","config.yml");if(!$n(t))return"na1";let n=ei(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 je(){let e=$("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(`
1283
+ ${t}`:""}`;try{let r=await Pe(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:(T.info("context-extractor",`Extracted theme context (${l.length} chars)`),l.trim())}catch(r){let l=r instanceof Error?r.message:String(r);return T.warn("context-extractor",`Theme context extraction failed: ${l}`),null}}var Ho=j(()=>{"use strict";g();ct();ve()});g();g();import{Command as nm}from"commander";g();g();g();import vt from"chalk";var Oe={accent:"#FF7A59",accentBright:"#FF9A7A",success:"#00BDA5",info:"#0066FF",warn:"#FFB020",error:"#E23D2D",muted:"#8B8D91",vibes:"#00BDD6"},Wo=!!process.env.NO_COLOR;function We(e){return Wo?vt:vt.hex(e)}var I={accent:We(Oe.accent),accentBright:We(Oe.accentBright),success:We(Oe.success),info:We(Oe.info),warn:We(Oe.warn),error:We(Oe.error),muted:We(Oe.muted),vibes:We(Oe.vibes),heading:Wo?vt.bold:vt.bold.hex(Oe.accent),command:We(Oe.accentBright),dim:vt.dim,bold:vt.bold};Q();function Ne(){let e=I.vibes,t=I.accent,n=I.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")} ${I.dim(`v${wt()}`)}`),console.log()}g();g();ut();Z();Ke();import{join as In}from"path";import{homedir as Tn}from"os";import{readFileSync as ei,existsSync as $n,readdirSync as zl}from"fs";var mt=process.platform==="win32"?"where":"which";function Gt(){let e=$("node --version");return{name:"Node.js",found:e.success,version:e.stdout.replace(/^v/,""),path:$(`${mt} node`).stdout}}function Ut(){let e=$("git --version");return{name:"Git",found:e.success,version:e.stdout.replace("git version ",""),path:$(`${mt} git`).stdout}}function Fe(){let e=$("hs --version");return{name:"HubSpot CLI",found:e.success,version:e.stdout,path:$(`${mt} hs`).stdout}}function Bt(){let e=$("claude --version");if(!e.success)return{name:"Claude Code",found:!1,version:"",path:"",authenticated:!1,authDetail:"Not installed"};let t=In(Tn(),".claude"),n=!1,s="Not signed in \u2014 run `claude` to authenticate";try{if($n(t)){let o=zl(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:$(`${mt} claude`).stdout,authenticated:n,authDetail:s}}function Wt(e){try{let t=In(Tn(),".hscli","config.yml");if(!$n(t))return"na1";let n=ei(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 je(){let e=$("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(`
1284
1284
  `);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 Vt(){let e=$("gemini --version");if(!e.success)return{name:"Gemini CLI",found:!1,version:"",path:"",authenticated:!1,authDetail:"Not installed"};let t=In(Tn(),".config","gcloud","application_default_credentials.json"),n=$n(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:$(`${mt} gemini`).stdout,authenticated:o,authDetail:o?"Authenticated":"Run `gemini` to sign in with Google"}}function Kt(){let e=$("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=In(Tn(),".codex","auth.json");$n(i)&&(n=ei(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:$(`${mt} codex`).stdout,authenticated:s,authDetail:o}}function Rs(){let e=$("gh --version");return{name:"GitHub CLI",found:e.success,version:e.stdout.split(`
1285
- `)[0]?.replace("gh version ","").split(" ")[0]||"",path:$(`${mt} gh`).stdout}}function Fs(){let e=$("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 ti(){return!!process.env.ANTHROPIC_API_KEY}function En(e){return parseInt(e.split(".")[0],10)>=18}function ni(e){let t=parseInt(e.split(".")[0],10);return!isNaN(t)&&t>=8}function zl(){let e=_(),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=nt();return{authenticated:!!o,portalName:o?.portalName||"",portalId:o?.portalId||"",dataCenter:o?o.dataCenter:"na1",accounts:s,uploadMode:t}}var Ns={name:"",found:!1,version:"",path:"",authenticated:!1,authDetail:"Disabled"};function _n(){let e=_(),t=Gt(),n=Ut(),s=e.hubspotUploadMode||"api",o;if(s==="cli"){let C=Fe(),k=C.found?je():{authenticated:!1,portalName:"",portalId:"",accounts:[]},P=k.portalId?Wt(k.portalId):"na1";o={...C,...k,dataCenter:P,uploadMode:"cli"}}else o={name:"HubSpot API",found:!0,version:"v3",path:"",...zl()};let i=Rs(),a=i.found?Fs():{authenticated:!1,username:""},r={authenticated:Re(),expiresAt:Lt()?.expiresAt},l=e.enabledCLITools||[],c=Dt("claude-code")?Bt():{...Ns,name:"Claude Code"},d=Dt("gemini-cli")?Vt():{...Ns,name:"Gemini CLI"},u=Dt("codex-cli")?Kt():{...Ns,name:"OpenAI Codex CLI"};function m(C,...k){if(C)return{configured:!0,masked:wn(C),source:"config"};for(let P of k)if(process.env[P])return{configured:!0,masked:wn(process.env[P]),source:"env"};return{configured:!1,masked:"",source:null}}let f=m(e.anthropicApiKey,"ANTHROPIC_API_KEY"),h=m(e.openaiApiKey,"OPENAI_API_KEY"),y=m(e.geminiApiKey,"GEMINI_API_KEY","GOOGLE_AI_API_KEY"),v=[];return c.found&&c.authenticated&&v.push("claude-code"),r.authenticated&&v.push("claude-oauth"),f.configured&&v.push("anthropic-api"),h.configured&&v.push("openai-api"),d.found&&d.authenticated&&v.push("gemini-cli"),y.configured&&v.push("gemini-api"),u.found&&u.authenticated&&v.push("codex-cli"),{tools:{node:t,git:n,hubspot:o,github:{...i,...a},claudeCode:c,claudeOAuth:r,geminiCli:d,codexCli:u},apiKeys:{anthropic:f,openai:h,gemini:y},activeEngine:e.aiEngine||null,availableEngines:v,enabledCLITools:l}}Ke();ut();Z();pt();g();import*as Y from"@clack/prompts";function Js(e){Y.isCancel(e)&&(Y.cancel(I.muted("Operation cancelled.")),process.exit(0))}async function ce(e){Y.intro(I.heading(e))}async function de(e){Y.outro(I.success(e))}async function Je(e,t){Y.note(e,t?I.heading(t):void 0)}async function Te(e){let t=await Y.text({message:I.accent(e.message),placeholder:e.placeholder,defaultValue:e.defaultValue,validate:e.validate});return Js(t),t}async function se(e){let t=await Y.confirm({message:I.accent(e.message),initialValue:e.initialValue??!0});return Js(t),t}async function It(e){let t=await Y.select({message:I.accent(e.message),options:e.options});return Js(t),t}async function ue(){let e=Y.spinner();return{start:t=>e.start(I.muted(t)),stop:t=>e.stop(I.success(t)),message:t=>e.message(I.muted(t))}}function ee(e){Y.log.info(e)}function J(e){Y.log.success(I.success(e))}function z(e){Y.log.warn(I.warn(e))}function B(e){Y.log.error(I.error(e))}async function Nn(){await ce("Checking your environment");let e=Gt();e.found||(B("Node.js not found. Install it from https://nodejs.org"),process.exit(1)),En(e.version)||(B(`Node.js ${e.version} is too old. Version 18+ required. Update at https://nodejs.org`),process.exit(1)),J(`Node.js v${e.version}`);let t=Ut();t.found||(B("Git not found. Install it from https://git-scm.com"),process.exit(1)),J(`Git ${t.version}`);let n=_(),s=n.hubspotUploadMode!=="cli",o="",i="";if(s){let v=he(),C=nt();if(v)o=C?.portalId||"",i=C?.portalName||"",J(`HubSpot${i?`: ${i}`:""}${o?` (${o})`:""} \u2014 API mode`);else{z("No HubSpot account connected"),await Je(`You need a Personal Access Key to deploy themes.
1285
+ `)[0]?.replace("gh version ","").split(" ")[0]||"",path:$(`${mt} gh`).stdout}}function Fs(){let e=$("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 ti(){return!!process.env.ANTHROPIC_API_KEY}function En(e){return parseInt(e.split(".")[0],10)>=18}function ni(e){let t=parseInt(e.split(".")[0],10);return!isNaN(t)&&t>=8}function ql(){let e=_(),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=st();return{authenticated:!!o,portalName:o?.portalName||"",portalId:o?.portalId||"",dataCenter:o?o.dataCenter:"na1",accounts:s,uploadMode:t}}var Ns={name:"",found:!1,version:"",path:"",authenticated:!1,authDetail:"Disabled"};function _n(){let e=_(),t=Gt(),n=Ut(),s=e.hubspotUploadMode||"api",o;if(s==="cli"){let C=Fe(),k=C.found?je():{authenticated:!1,portalName:"",portalId:"",accounts:[]},P=k.portalId?Wt(k.portalId):"na1";o={...C,...k,dataCenter:P,uploadMode:"cli"}}else o={name:"HubSpot API",found:!0,version:"v3",path:"",...ql()};let i=Rs(),a=i.found?Fs():{authenticated:!1,username:""},r={authenticated:Re(),expiresAt:Lt()?.expiresAt},l=e.enabledCLITools||[],c=Dt("claude-code")?Bt():{...Ns,name:"Claude Code"},d=Dt("gemini-cli")?Vt():{...Ns,name:"Gemini CLI"},u=Dt("codex-cli")?Kt():{...Ns,name:"OpenAI Codex CLI"};function m(C,...k){if(C)return{configured:!0,masked:wn(C),source:"config"};for(let P of k)if(process.env[P])return{configured:!0,masked:wn(process.env[P]),source:"env"};return{configured:!1,masked:"",source:null}}let f=m(e.anthropicApiKey,"ANTHROPIC_API_KEY"),h=m(e.openaiApiKey,"OPENAI_API_KEY"),y=m(e.geminiApiKey,"GEMINI_API_KEY","GOOGLE_AI_API_KEY"),v=[];return c.found&&c.authenticated&&v.push("claude-code"),r.authenticated&&v.push("claude-oauth"),f.configured&&v.push("anthropic-api"),h.configured&&v.push("openai-api"),d.found&&d.authenticated&&v.push("gemini-cli"),y.configured&&v.push("gemini-api"),u.found&&u.authenticated&&v.push("codex-cli"),{tools:{node:t,git:n,hubspot:o,github:{...i,...a},claudeCode:c,claudeOAuth:r,geminiCli:d,codexCli:u},apiKeys:{anthropic:f,openai:h,gemini:y},activeEngine:e.aiEngine||null,availableEngines:v,enabledCLITools:l}}Ke();ut();Z();pt();g();import*as Y from"@clack/prompts";function Js(e){Y.isCancel(e)&&(Y.cancel(I.muted("Operation cancelled.")),process.exit(0))}async function ce(e){Y.intro(I.heading(e))}async function de(e){Y.outro(I.success(e))}async function Je(e,t){Y.note(e,t?I.heading(t):void 0)}async function Te(e){let t=await Y.text({message:I.accent(e.message),placeholder:e.placeholder,defaultValue:e.defaultValue,validate:e.validate});return Js(t),t}async function se(e){let t=await Y.confirm({message:I.accent(e.message),initialValue:e.initialValue??!0});return Js(t),t}async function It(e){let t=await Y.select({message:I.accent(e.message),options:e.options});return Js(t),t}async function ue(){let e=Y.spinner();return{start:t=>e.start(I.muted(t)),stop:t=>e.stop(I.success(t)),message:t=>e.message(I.muted(t))}}function ee(e){Y.log.info(e)}function J(e){Y.log.success(I.success(e))}function z(e){Y.log.warn(I.warn(e))}function B(e){Y.log.error(I.error(e))}async function Nn(){await ce("Checking your environment");let e=Gt();e.found||(B("Node.js not found. Install it from https://nodejs.org"),process.exit(1)),En(e.version)||(B(`Node.js ${e.version} is too old. Version 18+ required. Update at https://nodejs.org`),process.exit(1)),J(`Node.js v${e.version}`);let t=Ut();t.found||(B("Git not found. Install it from https://git-scm.com"),process.exit(1)),J(`Git ${t.version}`);let n=_(),s=n.hubspotUploadMode!=="cli",o="",i="";if(s){let v=he(),C=st();if(v)o=C?.portalId||"",i=C?.portalName||"",J(`HubSpot${i?`: ${i}`:""}${o?` (${o})`:""} \u2014 API mode`);else{z("No HubSpot account connected"),await Je(`You need a Personal Access Key to deploy themes.
1286
1286
  Create one at: https://app.hubspot.com/l/personal-access-key
1287
- Make sure the Content scope is enabled.`,"HubSpot connection required");let k=await Te({message:"Paste your Personal Access Key:",placeholder:"pat-na1-...",validate:M=>M.trim()?void 0:"Key is required"}),P=await ue();P.start("Validating key...");try{let M=await On(k);Jt(k,M.portalId,M.portalName,M.dataCenter),v=k,o=M.portalId,i=M.portalName,P.stop(`Connected to ${M.portalName} (${M.portalId})`)}catch(M){P.stop("Validation failed"),B(`Invalid key: ${M instanceof Error?M.message:String(M)}`),process.exit(1)}}}else{let v=Fe();if(v.found)J(`HubSpot CLI v${v.version}`);else{z("HubSpot CLI not found"),await se({message:"Install HubSpot CLI globally?"})||(B("HubSpot CLI is required in CLI mode. Install: npm install -g @hubspot/cli"),process.exit(1));let P=await ue();P.start("Installing HubSpot CLI..."),$("npm install -g @hubspot/cli").success||(P.stop("Failed"),B("Try: npm install -g @hubspot/cli"),process.exit(1)),v=Fe(),P.stop(`HubSpot CLI v${v.version} installed`)}let C=je();if(C.authenticated)J(`HubSpot portal${C.portalName?`: ${C.portalName}`:""} (ID: ${C.portalId})`);else{z("HubSpot not authenticated"),await se({message:"Run `hs init` now?"})||(B("Run `hs init` manually."),process.exit(1));let P=await ue();P.start("Waiting for HubSpot authentication..."),zo("hs init")||(P.stop("Authentication failed"),process.exit(1)),C=je(),P.stop(`Connected to portal${C.portalName?`: ${C.portalName}`:""} (ID: ${C.portalId})`)}o=C.portalId,i=C.portalName}let a=Bt(),r=Vt(),l=Kt(),c=ti(),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=Re(),m,f=n.aiEngine,h=[];if(a.found&&h.push({value:"claude-code",label:"Claude Code",hint:f==="claude-code"?"last used \u2014 recommended":"uses your existing Claude subscription \u2014 recommended"}),u&&h.push({value:"claude-oauth",label:"Claude (OAuth)",hint:f==="claude-oauth"?"last used":"uses your Claude Pro/Max subscription via OAuth"}),r.found&&h.push({value:"gemini-cli",label:"Gemini CLI",hint:f==="gemini-cli"?"last used":"uses your existing Gemini setup"}),l.found&&h.push({value:"codex-cli",label:"OpenAI Codex",hint:f==="codex-cli"?"last used":"uses your existing OpenAI setup"}),c&&h.push({value:"api",label:"Anthropic API",hint:f==="api"?"last used":"uses your API key"}),f&&h.sort((v,C)=>v.value===f?-1:C.value===f?1:0),h.length===1)m=h[0].value,J(`AI engine: ${d[m]} (auto-detected)`);else if(h.length>1)m=await It({message:"Choose your AI engine:",options:h});else if(await Je(`You need an AI coding assistant to power the conversion.
1287
+ Make sure the Content scope is enabled.`,"HubSpot connection required");let k=await Te({message:"Paste your Personal Access Key:",placeholder:"pat-na1-...",validate:O=>O.trim()?void 0:"Key is required"}),P=await ue();P.start("Validating key...");try{let O=await Mn(k);Jt(k,O.portalId,O.portalName,O.dataCenter),v=k,o=O.portalId,i=O.portalName,P.stop(`Connected to ${O.portalName} (${O.portalId})`)}catch(O){P.stop("Validation failed"),B(`Invalid key: ${O instanceof Error?O.message:String(O)}`),process.exit(1)}}}else{let v=Fe();if(v.found)J(`HubSpot CLI v${v.version}`);else{z("HubSpot CLI not found"),await se({message:"Install HubSpot CLI globally?"})||(B("HubSpot CLI is required in CLI mode. Install: npm install -g @hubspot/cli"),process.exit(1));let P=await ue();P.start("Installing HubSpot CLI..."),$("npm install -g @hubspot/cli").success||(P.stop("Failed"),B("Try: npm install -g @hubspot/cli"),process.exit(1)),v=Fe(),P.stop(`HubSpot CLI v${v.version} installed`)}let C=je();if(C.authenticated)J(`HubSpot portal${C.portalName?`: ${C.portalName}`:""} (ID: ${C.portalId})`);else{z("HubSpot not authenticated"),await se({message:"Run `hs init` now?"})||(B("Run `hs init` manually."),process.exit(1));let P=await ue();P.start("Waiting for HubSpot authentication..."),zo("hs init")||(P.stop("Authentication failed"),process.exit(1)),C=je(),P.stop(`Connected to portal${C.portalName?`: ${C.portalName}`:""} (ID: ${C.portalId})`)}o=C.portalId,i=C.portalName}let a=Bt(),r=Vt(),l=Kt(),c=ti(),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=Re(),m,f=n.aiEngine,h=[];if(a.found&&h.push({value:"claude-code",label:"Claude Code",hint:f==="claude-code"?"last used \u2014 recommended":"uses your existing Claude subscription \u2014 recommended"}),u&&h.push({value:"claude-oauth",label:"Claude (OAuth)",hint:f==="claude-oauth"?"last used":"uses your Claude Pro/Max subscription via OAuth"}),r.found&&h.push({value:"gemini-cli",label:"Gemini CLI",hint:f==="gemini-cli"?"last used":"uses your existing Gemini setup"}),l.found&&h.push({value:"codex-cli",label:"OpenAI Codex",hint:f==="codex-cli"?"last used":"uses your existing OpenAI setup"}),c&&h.push({value:"api",label:"Anthropic API",hint:f==="api"?"last used":"uses your API key"}),f&&h.sort((v,C)=>v.value===f?-1:C.value===f?1:0),h.length===1)m=h[0].value,J(`AI engine: ${d[m]} (auto-detected)`);else if(h.length>1)m=await It({message:"Choose your AI engine:",options:h});else if(await Je(`You need an AI coding assistant to power the conversion.
1288
1288
 
1289
1289
  ${I.bold("Option 1:")} Install Claude Code ${I.muted("(recommended)")}
1290
1290
  https://claude.ai/code
@@ -1297,12 +1297,12 @@ ${I.bold("Option 3:")} Install OpenAI Codex
1297
1297
 
1298
1298
  ${I.bold("Option 4:")} Set an Anthropic API key
1299
1299
  export ANTHROPIC_API_KEY=sk-ant-...
1300
- (get one at https://console.anthropic.com)`,"AI engine required"),m=await It({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 v=await Te({message:"Enter your Anthropic API key:",placeholder:"sk-ant-api03-...",validate:C=>C.startsWith("sk-ant-")?void 0:"Key should start with sk-ant-"});process.env.ANTHROPIC_API_KEY=v,K({anthropicApiKey:v})}let y;return m==="claude-code"&&(y=await It({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"}]})),K({aiEngine:m}),await de("Environment ready!"),{aiEngine:m,model:y,portalId:o,portalName:i}}g();ut();Q();import{readdirSync as Ds,statSync as sc}from"fs";import{join as te,basename as Hs,extname as oc}from"path";function li(e){let t=[],n=[te(e,"src/components/landing"),te(e,"src/components/sections"),te(e,"src/components"),te(e,"src/pages"),te(e,"app/components"),te(e,"components")];for(let s of n)if(b(s))try{let o=Ds(s);for(let i of o){let a=te(s,i);if(!sc(a).isFile())continue;let l=oc(i);if(![".tsx",".jsx"].includes(l))continue;let c=Hs(i,l);if(c.startsWith("ui")||c==="index")continue;let d=A(a),u=ic(c,d);t.push({name:c,path:a,description:u})}}catch{}return t}function ic(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 ci(e){let t=[te(e,"src/index.css"),te(e,"src/globals.css"),te(e,"src/app/globals.css"),te(e,"app/globals.css")],n=0,s=[];for(let o of t){if(!b(o))continue;let i=A(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 di(e){let t=[],n=te(e,"src/hooks");if(b(n))try{let o=Ds(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=te(e,"src/components/landing");if(b(s))try{let o=Ds(s);for(let i of o){if(!i.endsWith(".tsx")&&!i.endsWith(".jsx"))continue;let a=A(te(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 ui(e){let t,n=!1;if(e.startsWith("http")||e.startsWith("git@")){n=!0;let l=Hs(e.replace(/\.git$/,""))||"react-source";if(t=te(process.cwd(),"workspace",l),!b(t)){let c=$(`git clone --depth 1 "${e}" "${t}"`);if(!c.success)throw new Error(`Failed to clone ${e}: ${c.stderr}`)}}else if(t=e,!b(t))throw new Error(`Directory not found: ${t}`);let s=li(t),o=b(te(t,"tailwind.config.ts"))||b(te(t,"tailwind.config.js")),{varCount:i,fonts:a}=ci(t),r=di(t);return{sourceDir:t,wasCloned:n,components:s,hasTailwind:o,cssVarCount:i,fonts:a,interactions:r}}async function Rn(){await ce("Source Project");let e=await Te({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"}}),t,n=!1;if(e.startsWith("http")||e.startsWith("git@")){n=!0;let h=Hs(e.replace(/\.git$/,""))||"react-source";if(t=te(process.cwd(),"workspace",h),b(t))J(`Using existing clone: ${I.dim(t)}`);else{let y=await ue();y.start("Cloning repository..."),$(`git clone --depth 1 "${e}" "${t}"`).success||(y.stop("Clone failed"),B(`Failed to clone ${e}. Check the URL and your access permissions.`),process.exit(1)),y.stop(`Cloned to ${I.dim(t)}`)}}else t=e,b(t)||(B(`Directory not found: ${t}`),process.exit(1)),J(`Using local source: ${I.dim(t)}`);let s=await ue();s.start("Analyzing project structure...");let o=li(t),i=b(te(t,"tailwind.config.ts"))||b(te(t,"tailwind.config.js")),{varCount:a,fonts:r}=ci(t),l=di(t);s.stop(`Found ${o.length} landing page components`),o.length===0&&(z("No components found. Make sure the React source has .tsx/.jsx files in src/components/"),process.exit(1));let c=o.map((h,y)=>` ${I.dim(`${y+1}.`)} ${I.bold(h.name)} ${I.muted(`\u2014 ${h.description}`)}`).join(`
1300
+ (get one at https://console.anthropic.com)`,"AI engine required"),m=await It({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 v=await Te({message:"Enter your Anthropic API key:",placeholder:"sk-ant-api03-...",validate:C=>C.startsWith("sk-ant-")?void 0:"Key should start with sk-ant-"});process.env.ANTHROPIC_API_KEY=v,K({anthropicApiKey:v})}let y;return m==="claude-code"&&(y=await It({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"}]})),K({aiEngine:m}),await de("Environment ready!"),{aiEngine:m,model:y,portalId:o,portalName:i}}g();ut();Q();import{readdirSync as Ds,statSync as oc}from"fs";import{join as te,basename as Hs,extname as ic}from"path";function li(e){let t=[],n=[te(e,"src/components/landing"),te(e,"src/components/sections"),te(e,"src/components"),te(e,"src/pages"),te(e,"app/components"),te(e,"components")];for(let s of n)if(b(s))try{let o=Ds(s);for(let i of o){let a=te(s,i);if(!oc(a).isFile())continue;let l=ic(i);if(![".tsx",".jsx"].includes(l))continue;let c=Hs(i,l);if(c.startsWith("ui")||c==="index")continue;let d=A(a),u=rc(c,d);t.push({name:c,path:a,description:u})}}catch{}return t}function rc(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 ci(e){let t=[te(e,"src/index.css"),te(e,"src/globals.css"),te(e,"src/app/globals.css"),te(e,"app/globals.css")],n=0,s=[];for(let o of t){if(!b(o))continue;let i=A(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 di(e){let t=[],n=te(e,"src/hooks");if(b(n))try{let o=Ds(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=te(e,"src/components/landing");if(b(s))try{let o=Ds(s);for(let i of o){if(!i.endsWith(".tsx")&&!i.endsWith(".jsx"))continue;let a=A(te(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 ui(e){let t,n=!1;if(e.startsWith("http")||e.startsWith("git@")){n=!0;let l=Hs(e.replace(/\.git$/,""))||"react-source";if(t=te(process.cwd(),"workspace",l),!b(t)){let c=$(`git clone --depth 1 "${e}" "${t}"`);if(!c.success)throw new Error(`Failed to clone ${e}: ${c.stderr}`)}}else if(t=e,!b(t))throw new Error(`Directory not found: ${t}`);let s=li(t),o=b(te(t,"tailwind.config.ts"))||b(te(t,"tailwind.config.js")),{varCount:i,fonts:a}=ci(t),r=di(t);return{sourceDir:t,wasCloned:n,components:s,hasTailwind:o,cssVarCount:i,fonts:a,interactions:r}}async function Rn(){await ce("Source Project");let e=await Te({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"}}),t,n=!1;if(e.startsWith("http")||e.startsWith("git@")){n=!0;let h=Hs(e.replace(/\.git$/,""))||"react-source";if(t=te(process.cwd(),"workspace",h),b(t))J(`Using existing clone: ${I.dim(t)}`);else{let y=await ue();y.start("Cloning repository..."),$(`git clone --depth 1 "${e}" "${t}"`).success||(y.stop("Clone failed"),B(`Failed to clone ${e}. Check the URL and your access permissions.`),process.exit(1)),y.stop(`Cloned to ${I.dim(t)}`)}}else t=e,b(t)||(B(`Directory not found: ${t}`),process.exit(1)),J(`Using local source: ${I.dim(t)}`);let s=await ue();s.start("Analyzing project structure...");let o=li(t),i=b(te(t,"tailwind.config.ts"))||b(te(t,"tailwind.config.js")),{varCount:a,fonts:r}=ci(t),l=di(t);s.stop(`Found ${o.length} landing page components`),o.length===0&&(z("No components found. Make sure the React source has .tsx/.jsx files in src/components/"),process.exit(1));let c=o.map((h,y)=>` ${I.dim(`${y+1}.`)} ${I.bold(h.name)} ${I.muted(`\u2014 ${h.description}`)}`).join(`
1301
1301
  `),d=i?`Tailwind + custom CSS (${a} variables)`:`Custom CSS (${a} variables)`,u=r.length>0?r.join(", "):"System fonts",m=l.join(", ");return await Je(`${c}
1302
1302
 
1303
1303
  CSS: ${d}
1304
1304
  JS: ${m}
1305
- Font: ${u}`,`${o.length} components detected`),await se({message:"Does this look right?"})||(B("Please adjust your source directory and try again."),process.exit(0)),await de("Source analyzed!"),{sourceDir:t,wasCloned:n,components:o,hasTailwind:i,cssVarCount:a,fonts:r,interactions:l}}g();ut();Q();import{join as Xt}from"path";Z();g();import{mkdirSync as st,writeFileSync as Fn}from"fs";import{join as $e}from"path";function jn(e,t){st(e,{recursive:!0}),st($e(e,"templates"),{recursive:!0}),st($e(e,"modules"),{recursive:!0}),st($e(e,"css"),{recursive:!0}),st($e(e,"js"),{recursive:!0}),st($e(e,"images"),{recursive:!0}),st($e(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"}};Fn($e(e,"theme.json"),JSON.stringify(n,null,2)+`
1305
+ Font: ${u}`,`${o.length} components detected`),await se({message:"Does this look right?"})||(B("Please adjust your source directory and try again."),process.exit(0)),await de("Source analyzed!"),{sourceDir:t,wasCloned:n,components:o,hasTailwind:i,cssVarCount:a,fonts:r,interactions:l}}g();ut();Q();import{join as Xt}from"path";Z();g();import{mkdirSync as ot,writeFileSync as Fn}from"fs";import{join as $e}from"path";function jn(e,t){ot(e,{recursive:!0}),ot($e(e,"templates"),{recursive:!0}),ot($e(e,"modules"),{recursive:!0}),ot($e(e,"css"),{recursive:!0}),ot($e(e,"js"),{recursive:!0}),ot($e(e,"images"),{recursive:!0}),ot($e(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"}};Fn($e(e,"theme.json"),JSON.stringify(n,null,2)+`
1306
1306
  `),Fn($e(e,"fields.json"),`[]
1307
1307
  `);let s=`<!--
1308
1308
  templateType: page
@@ -1342,7 +1342,7 @@ ${I.bold("Option 4:")} Set an Anthropic API key
1342
1342
  {{ standard_footer_includes }}
1343
1343
  </body>
1344
1344
  </html>
1345
- `;st($e(e,"templates","layouts"),{recursive:!0}),Fn($e(e,"templates","layouts","base.html"),o)}Jn();async function Dn(){await ce("HubSpot Theme Setup");let e=await It({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=Xt(process.cwd(),"workspace");if(Ae(s),e==="fetch"){t=await Te({message:"What's your theme name in HubSpot?",placeholder:"My-Company-Theme",validate:u=>u.trim()?void 0:"Theme name is required"}),n=Xt(s,t);let l=await ue();l.start("Fetching theme from HubSpot...");let c=_(),d=he();if(c.hubspotUploadMode==="cli"||!d)$(`hs cms fetch "${t}" "${n}"`).success||(l.stop("Fetch failed"),B(`Could not fetch theme "${t}". Check the name in HubSpot Design Manager.`),process.exit(1));else try{await qt(d,t,n)}catch(u){l.stop("Fetch failed"),B(`Could not fetch theme "${t}": ${u instanceof Error?u.message:String(u)}`),process.exit(1)}l.stop(`Theme fetched: ${I.dim(n)}`)}else{t=await Te({message:"Name for your new theme:",placeholder:"my-theme",defaultValue:"my-theme"}),n=Xt(s,t);let l=await ue();l.start("Creating theme...");try{jn(n,t)}catch(c){l.stop("Creation failed"),B(`Could not create theme "${t}": ${c instanceof Error?c.message:String(c)}`),process.exit(1)}l.stop(`Theme created: ${I.dim(n)}`)}await ce("Checking theme compatibility");let o=Xt(n,"templates/layouts/base.html");b(o)||(B(`base.html not found at ${o}. Your theme may have a different structure.`),process.exit(1)),J("base.html found");let i=A(o),a=!1;if(i.includes("template_css"))J("template_css support");else{z("Missing template_css support in base.html");let l=i.indexOf("theme-overrides.css")!==-1?i.indexOf("{{",i.lastIndexOf(`
1345
+ `;ot($e(e,"templates","layouts"),{recursive:!0}),Fn($e(e,"templates","layouts","base.html"),o)}Jn();async function Dn(){await ce("HubSpot Theme Setup");let e=await It({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=Xt(process.cwd(),"workspace");if(Ae(s),e==="fetch"){t=await Te({message:"What's your theme name in HubSpot?",placeholder:"My-Company-Theme",validate:u=>u.trim()?void 0:"Theme name is required"}),n=Xt(s,t);let l=await ue();l.start("Fetching theme from HubSpot...");let c=_(),d=he();if(c.hubspotUploadMode==="cli"||!d)$(`hs cms fetch "${t}" "${n}"`).success||(l.stop("Fetch failed"),B(`Could not fetch theme "${t}". Check the name in HubSpot Design Manager.`),process.exit(1));else try{await qt(d,t,n)}catch(u){l.stop("Fetch failed"),B(`Could not fetch theme "${t}": ${u instanceof Error?u.message:String(u)}`),process.exit(1)}l.stop(`Theme fetched: ${I.dim(n)}`)}else{t=await Te({message:"Name for your new theme:",placeholder:"my-theme",defaultValue:"my-theme"}),n=Xt(s,t);let l=await ue();l.start("Creating theme...");try{jn(n,t)}catch(c){l.stop("Creation failed"),B(`Could not create theme "${t}": ${c instanceof Error?c.message:String(c)}`),process.exit(1)}l.stop(`Theme created: ${I.dim(n)}`)}await ce("Checking theme compatibility");let o=Xt(n,"templates/layouts/base.html");b(o)||(B(`base.html not found at ${o}. Your theme may have a different structure.`),process.exit(1)),J("base.html found");let i=A(o),a=!1;if(i.includes("template_css"))J("template_css support");else{z("Missing template_css support in base.html");let l=i.indexOf("theme-overrides.css")!==-1?i.indexOf("{{",i.lastIndexOf(`
1346
1346
  `,i.indexOf("theme-overrides.css"))):i.lastIndexOf("require_css");if(l>0){let c=i.lastIndexOf(`
1347
1347
  `,l);i=i.slice(0,c)+`
1348
1348
  {% if template_css %}
@@ -1361,11 +1361,11 @@ docs/
1361
1361
  *.md
1362
1362
  node_modules/
1363
1363
  .git
1364
- `),J("Created .hsignore");return await de("Theme ready!"),{themePath:n,themeName:t}}g();import{join as ke}from"path";import{readdirSync as Qt,rmSync as wi}from"fs";g();qe();Q();import{spawn as dc}from"child_process";import{join as V,basename as uc}from"path";import{readdirSync as De,statSync as vi,writeFileSync as mc}from"fs";var pc=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"]),Hn=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||oe();this.reported.clear(),this.moduleCount=0,this.expectedModules=0;let a=this.countSourceComponents(n),r=this.listModules(s),l=this.listDir(V(s,"css")),c=this.listDir(V(s,"js")),d=this.listDir(V(s,"templates")),u=this.buildFullPrompt(n,s,i);o("convert",`Starting Claude Code (${a} source components found)...`);let m="",f="",h=setInterval(()=>{this.reportProgress(s,r,l,c,d,o)},3e3);try{await new Promise((k,P)=>{let M={...process.env};delete M.CLAUDECODE;let G=["--print","--max-turns","50","--allowedTools","Read,Glob,Grep,Write,Edit,Bash"];this.model&&G.push("--model",this.model);let E=dc("claude",G,{cwd:s,stdio:["pipe","pipe","pipe"],env:M,shell:!0});E.stdout.on("data",R=>{m+=R.toString()}),E.stderr.on("data",R=>{f+=R.toString()}),E.on("error",R=>P(new Error(`Claude Code failed to start: ${R.message}`))),E.on("close",R=>{R!==0?P(new Error(`Claude Code exited with code ${R}.
1364
+ `),J("Created .hsignore");return await de("Theme ready!"),{themePath:n,themeName:t}}g();import{join as ke}from"path";import{readdirSync as Qt,rmSync as wi}from"fs";g();qe();Q();import{spawn as uc}from"child_process";import{join as V,basename as mc}from"path";import{readdirSync as De,statSync as vi,writeFileSync as pc}from"fs";var fc=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"]),Hn=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||oe();this.reported.clear(),this.moduleCount=0,this.expectedModules=0;let a=this.countSourceComponents(n),r=this.listModules(s),l=this.listDir(V(s,"css")),c=this.listDir(V(s,"js")),d=this.listDir(V(s,"templates")),u=this.buildFullPrompt(n,s,i);o("convert",`Starting Claude Code (${a} source components found)...`);let m="",f="",h=setInterval(()=>{this.reportProgress(s,r,l,c,d,o)},3e3);try{await new Promise((k,P)=>{let O={...process.env};delete O.CLAUDECODE;let G=["--print","--max-turns","50","--allowedTools","Read,Glob,Grep,Write,Edit,Bash"];this.model&&G.push("--model",this.model);let E=uc("claude",G,{cwd:s,stdio:["pipe","pipe","pipe"],env:O,shell:!0});E.stdout.on("data",R=>{m+=R.toString()}),E.stderr.on("data",R=>{f+=R.toString()}),E.on("error",R=>P(new Error(`Claude Code failed to start: ${R.message}`))),E.on("close",R=>{R!==0?P(new Error(`Claude Code exited with code ${R}.
1365
1365
  `+(f?`Stderr: ${f.slice(0,500)}
1366
1366
  `:"")+(m?`Output: ${m.slice(0,500)}`:"No output"))):k()}),E.stdin.on("error",()=>{}),E.stdin.write(u),E.stdin.end(),setTimeout(()=>{E.kill(),P(new Error("Claude Code timed out after 30 minutes"))},18e5)})}finally{clearInterval(h)}let y=V(s,"..","vibespot-conversion.log");try{let P=["=== vibeSpot Conversion Log ===",`Timestamp: ${new Date().toISOString()}`,`Source: ${n}`,`Theme: ${s}`,`Model: ${this.model||"default"}`,"","=== PROMPT SENT ===",u.slice(0,500)+`
1367
1367
  ... (truncated, full guide follows)`,"","=== CLAUDE CODE STDOUT ===",m||"(empty)","","=== CLAUDE CODE STDERR ===",f||"(empty)",""].join(`
1368
- `);mc(y,P,"utf-8"),o("status",`Log written to ${uc(y)}`)}catch{}o("scan","Scanning generated files...");let v=this.scanGeneratedFiles(s);if(v.modules.filter(k=>!r.has(k.moduleName+".module")).length===0){let k=m.slice(0,1500)||"(no output)",P=f.slice(0,500);throw new Error(`Claude Code did not create any new module files.
1368
+ `);pc(y,P,"utf-8"),o("status",`Log written to ${mc(y)}`)}catch{}o("scan","Scanning generated files...");let v=this.scanGeneratedFiles(s);if(v.modules.filter(k=>!r.has(k.moduleName+".module")).length===0){let k=m.slice(0,1500)||"(no output)",P=f.slice(0,500);throw new Error(`Claude Code did not create any new module files.
1369
1369
 
1370
1370
  This usually means the model described the conversion instead of using Write tool to create files.
1371
1371
 
@@ -1427,13 +1427,13 @@ HUBSPOT CMS RULES:
1427
1427
  ${Ee()}
1428
1428
 
1429
1429
  CONVERSION GUIDE:
1430
- ${s}`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=V(t,"css");if(b(s)){for(let r of De(s))if(r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=A(V(s,r));break}}let o=V(t,"js");if(b(o)){for(let r of De(o))if(r.endsWith(".js")&&r!=="main.js"){n.sharedJs=A(V(o,r));break}}let i=V(t,"templates");if(b(i)){for(let r of De(i))if(r.startsWith("lp-")&&r.endsWith(".html")){n.template=A(V(i,r));break}if(!n.template){for(let r of De(i))if(r.endsWith(".html")&&!pc.has(r)&&!r.startsWith("system")){let l=A(V(i,r));if(l.includes("dnd_area")){n.template=l;break}}}if(!n.template){for(let r of De(i))if(r.endsWith(".html")&&!r.startsWith("system")&&r!=="base.html"){let l=A(V(i,r));if(l.includes("dnd_area")){n.template=l;break}}}}let a=V(t,"modules");if(b(a))for(let r of De(a)){if(!r.endsWith(".module"))continue;let l=V(a,r);if(!vi(l).isDirectory())continue;let c={moduleName:r.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=V(l,"fields.json");b(d)&&(c.fieldsJson=A(d));let u=V(l,"meta.json");b(u)&&(c.metaJson=A(u));let m=V(l,"module.html");b(m)&&(c.moduleHtml=A(m));let f=V(l,"module.css");b(f)&&(c.moduleCss=A(f));let h=V(l,"module.js");b(h)&&(c.moduleJs=A(h)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}listModules(t){let n=V(t,"modules");return b(n)?new Set(De(n).filter(s=>s.endsWith(".module"))):new Set}listDir(t){return b(t)?new Set(De(t)):new Set}detectExpectedModules(t,n){let s=V(t,"templates");if(!b(s))return 0;for(let o of De(s))if(!n.has(o)&&!(!o.endsWith(".html")||o==="base.html"||o.startsWith("system")))try{let i=A(V(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=V(t,"src");return b(n)?this.countComponentsRecursive(n):0}countComponentsRecursive(t){let n=0;for(let s of De(t)){let o=V(t,s);try{vi(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}};g();qe();Q();import fc from"@anthropic-ai/sdk";import{join as q,basename as gc}from"path";import{readdirSync as xi}from"fs";var Ln=class{client;model="claude-sonnet-4-6";constructor(t){this.client=new fc({apiKey:t||process.env.ANTHROPIC_API_KEY})}async convert(t){let{sourceDir:n,themePath:s,conversionGuide:o,onProgress:i}=t,a=gi(o),r=gc(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,yi(c,d,l)),m=q(s,"css",`${l}-theme.css`);H(m,u),i("css-done",`Created css/${l}-theme.css`),i("js","Creating shared JavaScript...");let f=this.findAndReadHooks(n),h=this.findInteractiveComponents(n),y=await this.complete(a,bi(f,h,l)),v=q(s,"js",`${l}-animations.js`);H(v,y),i("js-done",`Created js/${l}-animations.js`),i("modules","Building modules...");let C=this.findComponents(n),k=[];for(let E=0;E<C.length;E++){let R=C[E],W=R.name.replace(/Section$/,"").replace(/([A-Z])/g," $1").trim();i("module",`Building ${W}.module (${E+1}/${C.length})...`);let L=A(R.path),U=await this.complete(a,hi(L,W,`See css/${l}-theme.css`));try{let F=JSON.parse(U),X={moduleName:W,fieldsJson:typeof F.fieldsJson=="string"?F.fieldsJson:JSON.stringify(F.fieldsJson,null,2),metaJson:typeof F.metaJson=="string"?F.metaJson:JSON.stringify(F.metaJson,null,2),moduleHtml:F.moduleHtml||"",moduleCss:F.moduleCss||"",moduleJs:F.moduleJs||void 0},le=q(s,"modules",`${W}.module`);Ae(le),H(q(le,"fields.json"),X.fieldsJson),H(q(le,"meta.json"),X.metaJson),H(q(le,"module.html"),X.moduleHtml),H(q(le,"module.css"),X.moduleCss),X.moduleJs&&H(q(le,"module.js"),X.moduleJs),k.push(X),i("module-done",`${W}.module (${this.countFiles(X)} files)`)}catch{i("module-error",`Failed to parse ${W} \u2014 skipping`)}}i("template","Creating page template...");let P=k.map(E=>E.moduleName),M=await this.complete(a,Si(P,r,l)),G=q(s,"templates",`lp-${l}.html`);return H(G,M),i("template-done",`Created templates/lp-${l}.html`),{sharedCss:u,sharedJs:y,template:M,modules:k}}async complete(t,n){return(await this.client.messages.create({model:this.model,max_tokens:8192,system:t,messages:[{role:"user",content:n}]})).content.find(i=>i.type==="text")?.text||""}findAndReadCSS(t){let n=[q(t,"src/index.css"),q(t,"src/globals.css"),q(t,"src/app/globals.css"),q(t,"app/globals.css")];for(let s of n)if(b(s))return A(s);return""}findAndReadTailwind(t){let n=[q(t,"tailwind.config.ts"),q(t,"tailwind.config.js"),q(t,"tailwind.config.mjs")];for(let s of n)if(b(s))return A(s);return""}findAndReadHooks(t){let n=q(t,"src/hooks");if(!b(n))return"";try{return xi(n).filter(s=>s.endsWith(".ts")||s.endsWith(".tsx")).map(s=>`// ${s}
1430
+ ${s}`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=V(t,"css");if(b(s)){for(let r of De(s))if(r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=A(V(s,r));break}}let o=V(t,"js");if(b(o)){for(let r of De(o))if(r.endsWith(".js")&&r!=="main.js"){n.sharedJs=A(V(o,r));break}}let i=V(t,"templates");if(b(i)){for(let r of De(i))if(r.startsWith("lp-")&&r.endsWith(".html")){n.template=A(V(i,r));break}if(!n.template){for(let r of De(i))if(r.endsWith(".html")&&!fc.has(r)&&!r.startsWith("system")){let l=A(V(i,r));if(l.includes("dnd_area")){n.template=l;break}}}if(!n.template){for(let r of De(i))if(r.endsWith(".html")&&!r.startsWith("system")&&r!=="base.html"){let l=A(V(i,r));if(l.includes("dnd_area")){n.template=l;break}}}}let a=V(t,"modules");if(b(a))for(let r of De(a)){if(!r.endsWith(".module"))continue;let l=V(a,r);if(!vi(l).isDirectory())continue;let c={moduleName:r.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=V(l,"fields.json");b(d)&&(c.fieldsJson=A(d));let u=V(l,"meta.json");b(u)&&(c.metaJson=A(u));let m=V(l,"module.html");b(m)&&(c.moduleHtml=A(m));let f=V(l,"module.css");b(f)&&(c.moduleCss=A(f));let h=V(l,"module.js");b(h)&&(c.moduleJs=A(h)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}listModules(t){let n=V(t,"modules");return b(n)?new Set(De(n).filter(s=>s.endsWith(".module"))):new Set}listDir(t){return b(t)?new Set(De(t)):new Set}detectExpectedModules(t,n){let s=V(t,"templates");if(!b(s))return 0;for(let o of De(s))if(!n.has(o)&&!(!o.endsWith(".html")||o==="base.html"||o.startsWith("system")))try{let i=A(V(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=V(t,"src");return b(n)?this.countComponentsRecursive(n):0}countComponentsRecursive(t){let n=0;for(let s of De(t)){let o=V(t,s);try{vi(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}};g();qe();Q();import gc from"@anthropic-ai/sdk";import{join as q,basename as hc}from"path";import{readdirSync as xi}from"fs";var Ln=class{client;model="claude-sonnet-4-6";constructor(t){this.client=new gc({apiKey:t||process.env.ANTHROPIC_API_KEY})}async convert(t){let{sourceDir:n,themePath:s,conversionGuide:o,onProgress:i}=t,a=gi(o),r=hc(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,yi(c,d,l)),m=q(s,"css",`${l}-theme.css`);H(m,u),i("css-done",`Created css/${l}-theme.css`),i("js","Creating shared JavaScript...");let f=this.findAndReadHooks(n),h=this.findInteractiveComponents(n),y=await this.complete(a,bi(f,h,l)),v=q(s,"js",`${l}-animations.js`);H(v,y),i("js-done",`Created js/${l}-animations.js`),i("modules","Building modules...");let C=this.findComponents(n),k=[];for(let E=0;E<C.length;E++){let R=C[E],W=R.name.replace(/Section$/,"").replace(/([A-Z])/g," $1").trim();i("module",`Building ${W}.module (${E+1}/${C.length})...`);let L=A(R.path),U=await this.complete(a,hi(L,W,`See css/${l}-theme.css`));try{let F=JSON.parse(U),X={moduleName:W,fieldsJson:typeof F.fieldsJson=="string"?F.fieldsJson:JSON.stringify(F.fieldsJson,null,2),metaJson:typeof F.metaJson=="string"?F.metaJson:JSON.stringify(F.metaJson,null,2),moduleHtml:F.moduleHtml||"",moduleCss:F.moduleCss||"",moduleJs:F.moduleJs||void 0},le=q(s,"modules",`${W}.module`);Ae(le),H(q(le,"fields.json"),X.fieldsJson),H(q(le,"meta.json"),X.metaJson),H(q(le,"module.html"),X.moduleHtml),H(q(le,"module.css"),X.moduleCss),X.moduleJs&&H(q(le,"module.js"),X.moduleJs),k.push(X),i("module-done",`${W}.module (${this.countFiles(X)} files)`)}catch{i("module-error",`Failed to parse ${W} \u2014 skipping`)}}i("template","Creating page template...");let P=k.map(E=>E.moduleName),O=await this.complete(a,Si(P,r,l)),G=q(s,"templates",`lp-${l}.html`);return H(G,O),i("template-done",`Created templates/lp-${l}.html`),{sharedCss:u,sharedJs:y,template:O,modules:k}}async complete(t,n){return(await this.client.messages.create({model:this.model,max_tokens:8192,system:t,messages:[{role:"user",content:n}]})).content.find(i=>i.type==="text")?.text||""}findAndReadCSS(t){let n=[q(t,"src/index.css"),q(t,"src/globals.css"),q(t,"src/app/globals.css"),q(t,"app/globals.css")];for(let s of n)if(b(s))return A(s);return""}findAndReadTailwind(t){let n=[q(t,"tailwind.config.ts"),q(t,"tailwind.config.js"),q(t,"tailwind.config.mjs")];for(let s of n)if(b(s))return A(s);return""}findAndReadHooks(t){let n=q(t,"src/hooks");if(!b(n))return"";try{return xi(n).filter(s=>s.endsWith(".ts")||s.endsWith(".tsx")).map(s=>`// ${s}
1431
1431
  ${A(q(n,s))}`).join(`
1432
1432
 
1433
1433
  `)}catch{return""}}findInteractiveComponents(t){let n=this.findComponents(t),s=[];for(let o of n){let i=A(o.path);/carousel|accordion|typing|parallax|embla|swiper|collapsible/i.test(i)&&s.push(`// ${o.name}
1434
1434
  ${i}`)}return s.join(`
1435
1435
 
1436
- `)}findComponents(t){let n=[q(t,"src/components/landing"),q(t,"src/components/sections"),q(t,"src/components")];for(let s of n)if(b(s))try{return xi(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:q(s,o)}))}catch{continue}return[]}countFiles(t){let n=3;return t.moduleCss&&n++,t.moduleJs&&n++,n}};g();qe();Q();import{spawn as hc}from"child_process";import{join as xe}from"path";import{readdirSync as Gn,statSync as yc}from"fs";var Un=class{async convert(t){let{sourceDir:n,themePath:s,onProgress:o}=t,i=t.conversionGuide||oe(),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=hc("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}.
1436
+ `)}findComponents(t){let n=[q(t,"src/components/landing"),q(t,"src/components/sections"),q(t,"src/components")];for(let s of n)if(b(s))try{return xi(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:q(s,o)}))}catch{continue}return[]}countFiles(t){let n=3;return t.moduleCss&&n++,t.moduleJs&&n++,n}};g();qe();Q();import{spawn as yc}from"child_process";import{join as xe}from"path";import{readdirSync as Gn,statSync as bc}from"fs";var Un=class{async convert(t){let{sourceDir:n,themePath:s,onProgress:o}=t,i=t.conversionGuide||oe(),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=yc("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}.
1437
1437
 
1438
1438
  INSTRUCTIONS:
1439
1439
  1. Analyze all .tsx/.jsx components in the React source
@@ -1448,7 +1448,7 @@ CONVERSION GUIDE:
1448
1448
  ${s}
1449
1449
 
1450
1450
  Do NOT run hs upload \u2014 I will handle that separately.
1451
- Create all files directly in the theme directory.`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=xe(t,"css");if(b(s)){for(let r of Gn(s))if((r.includes("theme")||r.includes("page"))&&r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=A(xe(s,r));break}}let o=xe(t,"js");if(b(o)){for(let r of Gn(o))if((r.includes("animation")||r.includes("page"))&&r.endsWith(".js")&&r!=="main.js"){n.sharedJs=A(xe(o,r));break}}let i=xe(t,"templates");if(b(i)){for(let r of Gn(i))if(r.endsWith(".html")&&!r.startsWith("system")&&r!=="base.html"){let l=A(xe(i,r));if(l.includes("dnd_area")){n.template=l;break}}}let a=xe(t,"modules");if(b(a))for(let r of Gn(a)){if(!r.endsWith(".module"))continue;let l=xe(a,r);if(!yc(l).isDirectory())continue;let c={moduleName:r.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=xe(l,"fields.json");b(d)&&(c.fieldsJson=A(d));let u=xe(l,"meta.json");b(u)&&(c.metaJson=A(u));let m=xe(l,"module.html");b(m)&&(c.moduleHtml=A(m));let f=xe(l,"module.css");b(f)&&(c.moduleCss=A(f));let h=xe(l,"module.js");b(h)&&(c.moduleJs=A(h)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}};g();qe();Q();import{spawn as bc}from"child_process";import{join as we}from"path";import{readdirSync as Bn,statSync as Sc}from"fs";var Wn=class{async convert(t){let{sourceDir:n,themePath:s,onProgress:o}=t,i=t.conversionGuide||oe(),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=bc("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}.
1451
+ Create all files directly in the theme directory.`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=xe(t,"css");if(b(s)){for(let r of Gn(s))if((r.includes("theme")||r.includes("page"))&&r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=A(xe(s,r));break}}let o=xe(t,"js");if(b(o)){for(let r of Gn(o))if((r.includes("animation")||r.includes("page"))&&r.endsWith(".js")&&r!=="main.js"){n.sharedJs=A(xe(o,r));break}}let i=xe(t,"templates");if(b(i)){for(let r of Gn(i))if(r.endsWith(".html")&&!r.startsWith("system")&&r!=="base.html"){let l=A(xe(i,r));if(l.includes("dnd_area")){n.template=l;break}}}let a=xe(t,"modules");if(b(a))for(let r of Gn(a)){if(!r.endsWith(".module"))continue;let l=xe(a,r);if(!bc(l).isDirectory())continue;let c={moduleName:r.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=xe(l,"fields.json");b(d)&&(c.fieldsJson=A(d));let u=xe(l,"meta.json");b(u)&&(c.metaJson=A(u));let m=xe(l,"module.html");b(m)&&(c.moduleHtml=A(m));let f=xe(l,"module.css");b(f)&&(c.moduleCss=A(f));let h=xe(l,"module.js");b(h)&&(c.moduleJs=A(h)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}};g();qe();Q();import{spawn as Sc}from"child_process";import{join as we}from"path";import{readdirSync as Bn,statSync as vc}from"fs";var Wn=class{async convert(t){let{sourceDir:n,themePath:s,onProgress:o}=t,i=t.conversionGuide||oe(),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=Sc("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}.
1452
1452
 
1453
1453
  INSTRUCTIONS:
1454
1454
  1. Analyze all .tsx/.jsx components in the React source
@@ -1463,15 +1463,15 @@ CONVERSION GUIDE:
1463
1463
  ${s}
1464
1464
 
1465
1465
  Do NOT run hs upload \u2014 I will handle that separately.
1466
- Create all files directly in the theme directory.`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=we(t,"css");if(b(s)){for(let r of Bn(s))if((r.includes("theme")||r.includes("page"))&&r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=A(we(s,r));break}}let o=we(t,"js");if(b(o)){for(let r of Bn(o))if((r.includes("animation")||r.includes("page"))&&r.endsWith(".js")&&r!=="main.js"){n.sharedJs=A(we(o,r));break}}let i=we(t,"templates");if(b(i)){for(let r of Bn(i))if(r.endsWith(".html")&&!r.startsWith("system")&&r!=="base.html"){let l=A(we(i,r));if(l.includes("dnd_area")){n.template=l;break}}}let a=we(t,"modules");if(b(a))for(let r of Bn(a)){if(!r.endsWith(".module"))continue;let l=we(a,r);if(!Sc(l).isDirectory())continue;let c={moduleName:r.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=we(l,"fields.json");b(d)&&(c.fieldsJson=A(d));let u=we(l,"meta.json");b(u)&&(c.metaJson=A(u));let m=we(l,"module.html");b(m)&&(c.moduleHtml=A(m));let f=we(l,"module.css");b(f)&&(c.moduleCss=A(f));let h=we(l,"module.js");b(h)&&(c.moduleJs=A(h)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}};qe();Q();function vc(e,t){switch(e){case"claude-code":return new Hn(t);case"gemini-cli":return new Un;case"codex-cli":return new Wn;case"api":return new Ln}}async function Vn(e){await ce("Converting React to HubSpot Modules"),await Je(`AI will now analyze your React code and create
1467
- HubSpot-native modules. This takes 2-5 minutes.`,"AI Conversion");let t=vc(e.aiEngine,e.model),n=oe(),s=await ue();s.start("Starting AI conversion...");let o=Date.now(),i=await t.convert({sourceDir:e.sourceDir,themePath:e.themePath,conversionGuide:n,onProgress:(h,y)=>{h==="created"?J(y):s.message(y)}}),a=((Date.now()-o)/1e3).toFixed(0);s.stop(`AI conversion complete (${a}s)`);let r=xc(e.themePath);for(let h of r)J(`Auto-fixed: ${h}`);let l=wc(e.themePath,i),c=[];for(let h of l){let y=h.passed?"\u2705":"\u274C",v=h.passed?"":h.critical?" (CRITICAL)":" (cosmetic)";c.push(`${y} ${h.label}${v}`)}let d=l.filter(h=>h.passed).length;c.push(`
1466
+ Create all files directly in the theme directory.`}scanGeneratedFiles(t){let n={sharedCss:"",sharedJs:"",template:"",modules:[]},s=we(t,"css");if(b(s)){for(let r of Bn(s))if((r.includes("theme")||r.includes("page"))&&r.endsWith(".css")&&r!=="theme-overrides.css"&&r!=="main.css"&&r!=="style.css"){n.sharedCss=A(we(s,r));break}}let o=we(t,"js");if(b(o)){for(let r of Bn(o))if((r.includes("animation")||r.includes("page"))&&r.endsWith(".js")&&r!=="main.js"){n.sharedJs=A(we(o,r));break}}let i=we(t,"templates");if(b(i)){for(let r of Bn(i))if(r.endsWith(".html")&&!r.startsWith("system")&&r!=="base.html"){let l=A(we(i,r));if(l.includes("dnd_area")){n.template=l;break}}}let a=we(t,"modules");if(b(a))for(let r of Bn(a)){if(!r.endsWith(".module"))continue;let l=we(a,r);if(!vc(l).isDirectory())continue;let c={moduleName:r.replace(".module",""),fieldsJson:"",metaJson:"",moduleHtml:"",moduleCss:""},d=we(l,"fields.json");b(d)&&(c.fieldsJson=A(d));let u=we(l,"meta.json");b(u)&&(c.metaJson=A(u));let m=we(l,"module.html");b(m)&&(c.moduleHtml=A(m));let f=we(l,"module.css");b(f)&&(c.moduleCss=A(f));let h=we(l,"module.js");b(h)&&(c.moduleJs=A(h)),c.fieldsJson&&c.moduleHtml&&n.modules.push(c)}return n}};qe();Q();function xc(e,t){switch(e){case"claude-code":return new Hn(t);case"gemini-cli":return new Un;case"codex-cli":return new Wn;case"api":return new Ln}}async function Vn(e){await ce("Converting React to HubSpot Modules"),await Je(`AI will now analyze your React code and create
1467
+ HubSpot-native modules. This takes 2-5 minutes.`,"AI Conversion");let t=xc(e.aiEngine,e.model),n=oe(),s=await ue();s.start("Starting AI conversion...");let o=Date.now(),i=await t.convert({sourceDir:e.sourceDir,themePath:e.themePath,conversionGuide:n,onProgress:(h,y)=>{h==="created"?J(y):s.message(y)}}),a=((Date.now()-o)/1e3).toFixed(0);s.stop(`AI conversion complete (${a}s)`);let r=wc(e.themePath);for(let h of r)J(`Auto-fixed: ${h}`);let l=Cc(e.themePath,i),c=[];for(let h of l){let y=h.passed?"\u2705":"\u274C",v=h.passed?"":h.critical?" (CRITICAL)":" (cosmetic)";c.push(`${y} ${h.label}${v}`)}let d=l.filter(h=>h.passed).length;c.push(`
1468
1468
  ${d}/${l.length} checks passed`),await Je(c.join(`
1469
1469
  `),"Conversion Checklist");let u=l.filter(h=>!h.passed&&h.critical),m=l.filter(h=>!h.passed&&!h.critical);if(u.length>0){if(B(`${u.length} critical issue(s) \u2014 upload will likely fail:
1470
1470
  `+u.map(y=>` - ${y.label}`).join(`
1471
1471
  `)),!await se({message:"Continue with upload anyway?",initialValue:!1}))throw new Error("Conversion aborted due to critical checklist failures.")}else m.length>0&&z(`${m.length} non-critical issue(s) \u2014 page will work but may look incomplete:
1472
1472
  `+m.map(h=>` - ${h.label}`).join(`
1473
- `));let f=ke(e.themePath,"..","vibespot-conversion.log");return b(f)&&(await se({message:"Keep conversion log file for debugging?",initialValue:!1})?J(`Log saved: ${f}`):wi(f)),await de("Files ready for upload!"),i}function xc(e){let t=[];Cc(e),Ac(e);let n=ke(e,"modules");if(b(n))for(let o of Qt(n)){if(!o.endsWith(".module"))continue;let i=ke(n,o,"fields.json");if(!b(i))continue;let a=o.replace(".module",""),r=A(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;Ci(d)&&(u=!0,t.push(`${a}: fixed choice field format`)),Ai(d)&&(u=!0,t.push(`${a}: fixed link field default value`)),u&&(r=JSON.stringify(d,null,2)+`
1474
- `,l=!0)}catch{t.push(`${a}: fields.json has invalid JSON \u2014 manual fix needed`)}l&&H(i,r);let c=ke(n,o,"module.html");if(b(c)){let d=A(c);d.includes("now()")&&(d=d.replace(/now\(\)/g,"local_dt"),H(c,d),t.push(`${a}: now() \u2192 local_dt`))}}let s=ke(e,"templates");if(b(s))for(let o of Qt(s)){if(!o.endsWith(".html"))continue;let i=ke(s,o),a=A(i);(a.includes("hubdb_table")||a.includes("hubdb_table_rows"))&&(wi(i),t.push(`Removed ${o} (HubDB requires CMS Hub Pro/Enterprise)`))}return t}function Ci(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)&&Ci(s.children)&&(t=!0)}return t}function Ai(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)&&Ai(s.children)&&(t=!0)}return t}function wc(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=ke(e,"templates"),d=!1;if(b(c))for(let u of Qt(c)){if(!u.endsWith(".html")||u==="base.html"||u.startsWith("system"))continue;let m=A(ke(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 Cc(e){let t=ke(e,"templates");if(b(t))for(let n of Qt(t)){if(!n.endsWith(".html")||n==="base.html"||n.startsWith("system"))continue;let s=ke(t,n),o=A(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+=`
1473
+ `));let f=ke(e.themePath,"..","vibespot-conversion.log");return b(f)&&(await se({message:"Keep conversion log file for debugging?",initialValue:!1})?J(`Log saved: ${f}`):wi(f)),await de("Files ready for upload!"),i}function wc(e){let t=[];Ac(e),kc(e);let n=ke(e,"modules");if(b(n))for(let o of Qt(n)){if(!o.endsWith(".module"))continue;let i=ke(n,o,"fields.json");if(!b(i))continue;let a=o.replace(".module",""),r=A(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;Ci(d)&&(u=!0,t.push(`${a}: fixed choice field format`)),Ai(d)&&(u=!0,t.push(`${a}: fixed link field default value`)),u&&(r=JSON.stringify(d,null,2)+`
1474
+ `,l=!0)}catch{t.push(`${a}: fields.json has invalid JSON \u2014 manual fix needed`)}l&&H(i,r);let c=ke(n,o,"module.html");if(b(c)){let d=A(c);d.includes("now()")&&(d=d.replace(/now\(\)/g,"local_dt"),H(c,d),t.push(`${a}: now() \u2192 local_dt`))}}let s=ke(e,"templates");if(b(s))for(let o of Qt(s)){if(!o.endsWith(".html"))continue;let i=ke(s,o),a=A(i);(a.includes("hubdb_table")||a.includes("hubdb_table_rows"))&&(wi(i),t.push(`Removed ${o} (HubDB requires CMS Hub Pro/Enterprise)`))}return t}function Ci(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)&&Ci(s.children)&&(t=!0)}return t}function Ai(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)&&Ai(s.children)&&(t=!0)}return t}function Cc(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=ke(e,"templates"),d=!1;if(b(c))for(let u of Qt(c)){if(!u.endsWith(".html")||u==="base.html"||u.startsWith("system"))continue;let m=A(ke(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 Ac(e){let t=ke(e,"templates");if(b(t))for(let n of Qt(t)){if(!n.endsWith(".html")||n==="base.html"||n.startsWith("system"))continue;let s=ke(t,n),o=A(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+=`
1475
1475
  templateType: page`),a||(c+=`
1476
1476
  isAvailableForNewContent: true`),/label\s*:/i.test(c)||(c+=`
1477
1477
  label: ${r}`),o=c+o.slice(l)}else o=`<!--
@@ -1479,13 +1479,13 @@ ${d}/${l.length} checks passed`),await Je(c.join(`
1479
1479
  isAvailableForNewContent: true
1480
1480
  label: ${r}
1481
1481
  -->
1482
- `+o;H(s,o),J(`Template "${n}" \u2014 annotations verified`)}}function Ac(e){let t=ke(e,"modules");if(b(t))for(let n of Qt(t)){if(!n.endsWith(".module"))continue;let s=ke(t,n,"meta.json");if(b(s))try{let o=JSON.parse(A(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&&H(s,JSON.stringify(o,null,2)+`
1483
- `)}catch{}}}g();ut();import{join as Ri,basename as Nc}from"path";g();Q();import{join as ie}from"path";import{readdirSync as Xe,rmSync as kc}from"fs";function Kn(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 Yn(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 zn(e){let t=[];return Ii(e)&&t.push("textarea \u2192 text"),Ti(e)&&t.push("name \u2192 item_name"),$i(e)&&t.push("now() \u2192 local_dt"),Ei(e)&&t.push("Removed HubDB templates"),_i(e)&&t.push("Fixed link field defaults"),Pi(e)&&t.push("Fixed rgba/invalid color values \u2192 hex"),Ic(e)&&t.push("Stripped CDN @import statements"),t}function ki(e,t){return t.message.includes("textarea")?Ii(e):t.message.includes("reserved field name")?Ti(e):t.message.includes("now()")?$i(e):t.message.includes("HubDB")?Ei(e):t.message.includes("invalid default value")||t.message.includes("deserialization")?_i(e):t.message.includes("invalid format")&&t.message.includes("color")?Pi(e):!1}function Ii(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"fields.json");if(!b(o))continue;let i=A(o);i.includes('"textarea"')&&(i=i.replace(/"textarea"/g,'"text"'),H(o,i),t=!0)}return t}function Ti(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"fields.json");if(!b(o))continue;let i=A(o);/"name":\s*"name"/g.test(i)&&(i=i.replace(/"name":\s*"name"/g,'"name": "item_name"'),H(o,i),t=!0)}return t}function $i(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"module.html");if(!b(o))continue;let i=A(o);i.includes("now()")&&(i=i.replace(/now\(\)/g,"local_dt"),H(o,i),t=!0)}return t}function Ei(e){let t=!1,n=ie(e,"templates");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".html"))continue;let o=ie(n,s),i=A(o);(i.includes("hubdb_table")||i.includes("hubdb_table_rows"))&&(kc(o),t=!0)}return t}function _i(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"fields.json");if(b(o))try{let i=JSON.parse(A(o));Mi(i)&&(H(o,JSON.stringify(i,null,2)+`
1484
- `),t=!0)}catch{}}return t}function Ic(e){let t=!1,n=ie(e,"css");if(b(n))for(let o of Xe(n)){if(!o.endsWith(".css"))continue;let i=ie(n,o),a=A(i),r=a.replace(/@import\s+url\(['"]?https?:\/\/[^)]+['"]?\)\s*;?/gi,"");r!==a&&(H(i,r),t=!0)}let s=ie(e,"modules");if(b(s))for(let o of Xe(s)){if(!o.endsWith(".module"))continue;let i=ie(s,o,"module.css");if(!b(i))continue;let a=A(i),r=a.replace(/@import\s+url\(['"]?https?:\/\/[^)]+['"]?\)\s*;?/gi,"");r!==a&&(H(i,r),t=!0)}if(b(s))for(let o of Xe(s)){if(!o.endsWith(".module"))continue;let i=ie(s,o,"module.html");if(!b(i))continue;let a=A(i),r=a.replace(/<link[^>]+href=['"]https?:\/\/[^'"]+['"][^>]*>/gi,"");r!==a&&(H(i,r),t=!0)}return t}function Pi(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"fields.json");if(b(o))try{let i=JSON.parse(A(o));Oi(i)&&(H(o,JSON.stringify(i,null,2)+`
1485
- `),t=!0)}catch{}}return t}function Oi(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"&&!Tc(i)){let a=$c(i);a&&(o.color=a.hex,a.opacity!==void 0&&(o.opacity=a.opacity),t=!0)}}Array.isArray(s.children)&&Oi(s.children)&&(t=!0)}return t}function Tc(e){return/^#[0-9a-fA-F]{6}$/.test(e)}function $c(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 Mi(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)&&Mi(s.children)&&(t=!0)}return t}Z();g();pt();pt();import{readdirSync as Ec}from"fs";import{join as _c,relative as Pc}from"path";var Oc=new Set([".git","node_modules",".vibespot",".DS_Store"]);function Ni(e){let t=[];for(let n of Ec(e,{withFileTypes:!0})){if(Oc.has(n.name)||n.name.startsWith(".")&&n.name!==".gitkeep")continue;let s=_c(e,n.name);n.isDirectory()?t.push(...Ni(s)):n.isFile()&&t.push(s)}return t}async function Mc(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 qn(e,t,n,s={}){let o=s.concurrency??5,i=Ni(t),a=i.length,r=0,l=0,c=[];return await Mc(i,o,async d=>{let u=Pc(t,d).replace(/\\/g,"/"),m=`${n}/${u}`;s.onFileStart?.(u);let f=await ii(e,m,d);if(f.success)r++,s.onFileComplete?.(u);else{l++;let h={file:u,status:f.error?.status||0,message:f.error?.message||"Unknown error",category:f.error?.category,detail:f.error?.detail};c.push(h),s.onFileError?.(u,h)}s.onProgress?.(r+l,a)}),{success:l===0,uploaded:r,failed:l,total:a,errors:c}}function Rc(e){return(e.match(/^Uploaded file /gm)||[]).length}async function $t(e){await ce("Uploading to HubSpot");let t=Nc(e)||e,n=_(),s=he(),o=n.hubspotUploadMode!=="cli"&&!!s,i=await ue(),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 qn(s,e,t,{onFileComplete:()=>{c++}});d=m.success,d?c=m.uploaded:l=Kn(m.errors)}else{let m=$(`hs cms upload "${e}" "${t}"`,{cwd:Ri(e,"..")}),f=[m.stdout,m.stderr].filter(Boolean).join(`
1486
- `);c=Rc(f),d=m.success,d||(l=Yn(f))}if(d)return i.stop(`All files uploaded! (${c} files)`),await de("Upload complete!"),!0;if(c>0?i.stop(`${c} files uploaded, but some errors occurred`):i.stop("Upload failed"),l.length===0){if(B("Upload failed with unknown error."),c>0&&(z(`Most files uploaded successfully. The theme may already be usable in HubSpot.
1482
+ `+o;H(s,o),J(`Template "${n}" \u2014 annotations verified`)}}function kc(e){let t=ke(e,"modules");if(b(t))for(let n of Qt(t)){if(!n.endsWith(".module"))continue;let s=ke(t,n,"meta.json");if(b(s))try{let o=JSON.parse(A(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&&H(s,JSON.stringify(o,null,2)+`
1483
+ `)}catch{}}}g();ut();import{join as Ri,basename as Rc}from"path";g();Q();import{join as ie}from"path";import{readdirSync as Xe,rmSync as Ic}from"fs";function Kn(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 Yn(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 zn(e){let t=[];return Ii(e)&&t.push("textarea \u2192 text"),Ti(e)&&t.push("name \u2192 item_name"),$i(e)&&t.push("now() \u2192 local_dt"),Ei(e)&&t.push("Removed HubDB templates"),_i(e)&&t.push("Fixed link field defaults"),Pi(e)&&t.push("Fixed rgba/invalid color values \u2192 hex"),Tc(e)&&t.push("Stripped CDN @import statements"),t}function ki(e,t){return t.message.includes("textarea")?Ii(e):t.message.includes("reserved field name")?Ti(e):t.message.includes("now()")?$i(e):t.message.includes("HubDB")?Ei(e):t.message.includes("invalid default value")||t.message.includes("deserialization")?_i(e):t.message.includes("invalid format")&&t.message.includes("color")?Pi(e):!1}function Ii(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"fields.json");if(!b(o))continue;let i=A(o);i.includes('"textarea"')&&(i=i.replace(/"textarea"/g,'"text"'),H(o,i),t=!0)}return t}function Ti(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"fields.json");if(!b(o))continue;let i=A(o);/"name":\s*"name"/g.test(i)&&(i=i.replace(/"name":\s*"name"/g,'"name": "item_name"'),H(o,i),t=!0)}return t}function $i(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"module.html");if(!b(o))continue;let i=A(o);i.includes("now()")&&(i=i.replace(/now\(\)/g,"local_dt"),H(o,i),t=!0)}return t}function Ei(e){let t=!1,n=ie(e,"templates");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".html"))continue;let o=ie(n,s),i=A(o);(i.includes("hubdb_table")||i.includes("hubdb_table_rows"))&&(Ic(o),t=!0)}return t}function _i(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"fields.json");if(b(o))try{let i=JSON.parse(A(o));Oi(i)&&(H(o,JSON.stringify(i,null,2)+`
1484
+ `),t=!0)}catch{}}return t}function Tc(e){let t=!1,n=ie(e,"css");if(b(n))for(let o of Xe(n)){if(!o.endsWith(".css"))continue;let i=ie(n,o),a=A(i),r=a.replace(/@import\s+url\(['"]?https?:\/\/[^)]+['"]?\)\s*;?/gi,"");r!==a&&(H(i,r),t=!0)}let s=ie(e,"modules");if(b(s))for(let o of Xe(s)){if(!o.endsWith(".module"))continue;let i=ie(s,o,"module.css");if(!b(i))continue;let a=A(i),r=a.replace(/@import\s+url\(['"]?https?:\/\/[^)]+['"]?\)\s*;?/gi,"");r!==a&&(H(i,r),t=!0)}if(b(s))for(let o of Xe(s)){if(!o.endsWith(".module"))continue;let i=ie(s,o,"module.html");if(!b(i))continue;let a=A(i),r=a.replace(/<link[^>]+href=['"]https?:\/\/[^'"]+['"][^>]*>/gi,"");r!==a&&(H(i,r),t=!0)}return t}function Pi(e){let t=!1,n=ie(e,"modules");if(!b(n))return!1;for(let s of Xe(n)){if(!s.endsWith(".module"))continue;let o=ie(n,s,"fields.json");if(b(o))try{let i=JSON.parse(A(o));Mi(i)&&(H(o,JSON.stringify(i,null,2)+`
1485
+ `),t=!0)}catch{}}return t}function Mi(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"&&!$c(i)){let a=Ec(i);a&&(o.color=a.hex,a.opacity!==void 0&&(o.opacity=a.opacity),t=!0)}}Array.isArray(s.children)&&Mi(s.children)&&(t=!0)}return t}function $c(e){return/^#[0-9a-fA-F]{6}$/.test(e)}function Ec(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 Oi(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)&&Oi(s.children)&&(t=!0)}return t}Z();g();pt();pt();import{readdirSync as _c}from"fs";import{join as Pc,relative as Mc}from"path";var Oc=new Set([".git","node_modules",".vibespot",".DS_Store"]);function Ni(e){let t=[];for(let n of _c(e,{withFileTypes:!0})){if(Oc.has(n.name)||n.name.startsWith(".")&&n.name!==".gitkeep")continue;let s=Pc(e,n.name);n.isDirectory()?t.push(...Ni(s)):n.isFile()&&t.push(s)}return t}async function Nc(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 qn(e,t,n,s={}){let o=s.concurrency??5,i=Ni(t),a=i.length,r=0,l=0,c=[];return await Nc(i,o,async d=>{let u=Mc(t,d).replace(/\\/g,"/"),m=`${n}/${u}`;s.onFileStart?.(u);let f=await ii(e,m,d);if(f.success)r++,s.onFileComplete?.(u);else{l++;let h={file:u,status:f.error?.status||0,message:f.error?.message||"Unknown error",category:f.error?.category,detail:f.error?.detail};c.push(h),s.onFileError?.(u,h)}s.onProgress?.(r+l,a)}),{success:l===0,uploaded:r,failed:l,total:a,errors:c}}function Fc(e){return(e.match(/^Uploaded file /gm)||[]).length}async function $t(e){await ce("Uploading to HubSpot");let t=Rc(e)||e,n=_(),s=he(),o=n.hubspotUploadMode!=="cli"&&!!s,i=await ue(),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 qn(s,e,t,{onFileComplete:()=>{c++}});d=m.success,d?c=m.uploaded:l=Kn(m.errors)}else{let m=$(`hs cms upload "${e}" "${t}"`,{cwd:Ri(e,"..")}),f=[m.stdout,m.stderr].filter(Boolean).join(`
1486
+ `);c=Fc(f),d=m.success,d||(l=Yn(f))}if(d)return i.stop(`All files uploaded! (${c} files)`),await de("Upload complete!"),!0;if(c>0?i.stop(`${c} files uploaded, but some errors occurred`):i.stop("Upload failed"),l.length===0){if(B("Upload failed with unknown error."),c>0&&(z(`Most files uploaded successfully. The theme may already be usable in HubSpot.
1487
1487
  You can check your HubSpot Design Manager to verify.`),await se({message:"Continue anyway (theme is likely uploaded)?",initialValue:!0})))return!0;if(r<a){if(!await se({message:"Try uploading again?"}))break;continue}break}let u=!1;for(let m of l)m.fixable?ki(e,m)?(J(`Auto-fixed: ${m.message}`),u=!0):z(`Could not auto-fix: ${m.message}`):B(m.message);if(!(u&&r<a)){if(c>0&&(z(`${c} files uploaded successfully despite errors.
1488
- The theme may work \u2014 check HubSpot Design Manager.`),await se({message:"Continue anyway?",initialValue:!0})))return!0;if(!u){if(i.start("Cleaning up stuck modules..."),o)try{await js(s,`${t}/modules`)}catch{}else $(`hs cms delete "${t}/modules"`,{cwd:Ri(e,"..")});i.stop("Cleaned up modules, retrying...")}}}return B("Upload failed after multiple attempts."),!1}g();import{execFileSync as Vs}from"child_process";import{rmSync as Fc}from"fs";import{basename as Fi}from"path";Q();async function ji(e){let{portalId:t,sourceDir:n,themePath:s,wasCloned:o}=e;await ce("You're all set!");let a=Wt(t)==="eu1"?"app-eu1.hubspot.com":"app.hubspot.com";if(await Je(`Your React page has been converted and uploaded to HubSpot.
1488
+ The theme may work \u2014 check HubSpot Design Manager.`),await se({message:"Continue anyway?",initialValue:!0})))return!0;if(!u){if(i.start("Cleaning up stuck modules..."),o)try{await js(s,`${t}/modules`)}catch{}else $(`hs cms delete "${t}/modules"`,{cwd:Ri(e,"..")});i.stop("Cleaned up modules, retrying...")}}}return B("Upload failed after multiple attempts."),!1}g();import{execFileSync as Vs}from"child_process";import{rmSync as jc}from"fs";import{basename as Fi}from"path";Q();async function ji(e){let{portalId:t,sourceDir:n,themePath:s,wasCloned:o}=e;await ce("You're all set!");let a=Wt(t)==="eu1"?"app-eu1.hubspot.com":"app.hubspot.com";if(await Je(`Your React page has been converted and uploaded to HubSpot.
1489
1489
  The theme and modules are now in your account, but you still
1490
1490
  need to ${I.bold("create a new landing page")} that uses them.
1491
1491
 
@@ -1497,14 +1497,14 @@ Next steps:
1497
1497
  ${I.bold("4.")} Your converted modules will appear \u2014 drag them onto the page
1498
1498
  ${I.bold("5.")} Click each section to edit text, images, and colors
1499
1499
  ${I.bold("6.")} Upload images via File Manager ${I.muted("(Settings \u2192 Files)")}
1500
- ${I.bold("7.")} Preview and publish!`,"What's next"),await se({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"?Vs("open",[c],{stdio:"ignore"}):d==="win32"?Vs("cmd",["/c","start","",c],{stdio:"ignore"}):Vs("xdg-open",[c],{stdio:"ignore"}),J("Opening HubSpot Landing Pages...")}catch{ee(`Open this URL in your browser: ${I.info(c)}`)}}let l=[];if(o&&b(n)&&l.push({path:n,label:`Cloned source (${Fi(n)})`}),b(s)&&l.push({path:s,label:`Theme directory (${Fi(s)})`}),l.length>0&&await se({message:"Clean up local working directories?"}))for(let d of l)try{Fc(d.path,{recursive:!0,force:!0}),J(`Removed ${d.label}`)}catch{z(`Could not remove ${d.label} \u2014 delete manually if needed.`)}await de(`Thanks for using hub${I.vibes("Vibes")}! ${I.vibes("~")}`)}Z();async function Ji(){Ne();let e=await Nn(),t=await Rn();K({lastSourcePath:t.sourceDir});let n=await Dn();K({lastThemePath:n.themePath}),await Vn({aiEngine:e.aiEngine,model:e.model,sourceDir:t.sourceDir,themePath:n.themePath}),await $t(n.themePath),await ji({portalId:e.portalId,sourceDir:t.sourceDir,themePath:n.themePath,wasCloned:t.wasCloned})}g();async function Di(){Ne(),await Nn()}g();Z();async function Hi(){Ne();let e=_();e.aiEngine||(B("AI engine not configured. Run `vibespot init` first or use the full wizard with `vibespot`."),process.exit(1));let t=await Rn(),n=await Dn();await Vn({aiEngine:e.aiEngine,sourceDir:t.sourceDir,themePath:n.themePath})}g();Z();async function Li(){Ne();let e=_();if(e.lastThemePath)if(await se({message:`Upload from ${e.lastThemePath}?`}))await $t(e.lastThemePath);else{let n=await Te({message:"Path to your HubSpot theme directory:",placeholder:"./my-theme"});await $t(n)}else{let t=await Te({message:"Path to your HubSpot theme directory:",placeholder:"./my-theme",validate:n=>n.trim()?void 0:"Path is required"});await $t(t)}}g();Z();async function Gi(){Ne(),await ce("Environment Diagnostics");let e=0,t=Gt();t.found?En(t.version)?J(`Node.js v${t.version}`):(z(`Node.js v${t.version} \u2014 too old (need 18+)`),ee(" Update at https://nodejs.org"),e++):(B("Node.js \u2014 not installed"),ee(" Install from https://nodejs.org"),e++);let n=Ut();n.found?J(`Git ${n.version}`):(B("Git \u2014 not installed"),ee(" Install from https://git-scm.com"),e++);let s=Fe();if(!s.found)z("HubSpot CLI \u2014 not installed (only needed for deployment)"),ee(" Install: npm install -g @hubspot/cli");else if(!ni(s.version))z(`HubSpot CLI v${s.version} \u2014 too old (need v8+)`),ee(" Update: npm install -g @hubspot/cli@latest"),e++;else{J(`HubSpot CLI v${s.version}`);let m=je();m.authenticated?J(`HubSpot portal${m.portalName?`: ${m.portalName}`:""} (ID: ${m.portalId})`):(z("HubSpot \u2014 not authenticated"),ee(" Run: hs init"))}let o=Bt();o.found?J(`Claude Code ${o.version} at ${o.path}`):ee(I.muted("Claude Code \u2014 not installed"));let i=Vt();i.found?J(`Gemini CLI ${i.version} at ${i.path}`):ee(I.muted("Gemini CLI \u2014 not installed"));let a=Kt();a.found?J(`OpenAI Codex ${a.version} at ${a.path}`):ee(I.muted("OpenAI Codex \u2014 not installed"));let r=_(),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?J("Anthropic API key configured"):ee(I.muted("Anthropic API key \u2014 not set")),c?J("OpenAI API key configured"):ee(I.muted("OpenAI API key \u2014 not set")),d?J("Google AI API key configured"):ee(I.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&&J(`AI engine: ${u[r.aiEngine]||r.aiEngine}`),r.lastThemePath&&ee(I.muted(`Last theme: ${r.lastThemePath}`)),!o.found&&!i.found&&!a.found&&!l&&!c&&!d&&(z("No AI engine available"),ee(" Fastest: Set an API key (ANTHROPIC_API_KEY, OPENAI_API_KEY, or GEMINI_API_KEY)"),ee(" Or install: Claude Code \u2014 https://claude.ai/code"),ee(" Gemini CLI \u2014 https://github.com/google-gemini/gemini-cli"),ee(" Codex CLI \u2014 https://github.com/openai/codex"),e++),console.log(),e===0?await de("Everything looks good!"):await de(I.warn(`${e} issue${e>1?"s":""} found \u2014 see above`))}g();import{join as ks}from"path";import{existsSync as qu}from"fs";import{execFileSync as Uo}from"child_process";import Is from"chalk";g();Se();Zt();as();fs();Z();import{createServer as Gu}from"http";import{readFileSync as Go,existsSync as yn}from"fs";import{join as dt,extname as El}from"path";import{createHash as Uu}from"crypto";import{WebSocketServer as Bu}from"ws";g();import{spawn as Fo}from"child_process";var ct=new Map;function va(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+=`
1500
+ ${I.bold("7.")} Preview and publish!`,"What's next"),await se({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"?Vs("open",[c],{stdio:"ignore"}):d==="win32"?Vs("cmd",["/c","start","",c],{stdio:"ignore"}):Vs("xdg-open",[c],{stdio:"ignore"}),J("Opening HubSpot Landing Pages...")}catch{ee(`Open this URL in your browser: ${I.info(c)}`)}}let l=[];if(o&&b(n)&&l.push({path:n,label:`Cloned source (${Fi(n)})`}),b(s)&&l.push({path:s,label:`Theme directory (${Fi(s)})`}),l.length>0&&await se({message:"Clean up local working directories?"}))for(let d of l)try{jc(d.path,{recursive:!0,force:!0}),J(`Removed ${d.label}`)}catch{z(`Could not remove ${d.label} \u2014 delete manually if needed.`)}await de(`Thanks for using hub${I.vibes("Vibes")}! ${I.vibes("~")}`)}Z();async function Ji(){Ne();let e=await Nn(),t=await Rn();K({lastSourcePath:t.sourceDir});let n=await Dn();K({lastThemePath:n.themePath}),await Vn({aiEngine:e.aiEngine,model:e.model,sourceDir:t.sourceDir,themePath:n.themePath}),await $t(n.themePath),await ji({portalId:e.portalId,sourceDir:t.sourceDir,themePath:n.themePath,wasCloned:t.wasCloned})}g();async function Di(){Ne(),await Nn()}g();Z();async function Hi(){Ne();let e=_();e.aiEngine||(B("AI engine not configured. Run `vibespot init` first or use the full wizard with `vibespot`."),process.exit(1));let t=await Rn(),n=await Dn();await Vn({aiEngine:e.aiEngine,sourceDir:t.sourceDir,themePath:n.themePath})}g();Z();async function Li(){Ne();let e=_();if(e.lastThemePath)if(await se({message:`Upload from ${e.lastThemePath}?`}))await $t(e.lastThemePath);else{let n=await Te({message:"Path to your HubSpot theme directory:",placeholder:"./my-theme"});await $t(n)}else{let t=await Te({message:"Path to your HubSpot theme directory:",placeholder:"./my-theme",validate:n=>n.trim()?void 0:"Path is required"});await $t(t)}}g();Z();async function Gi(){Ne(),await ce("Environment Diagnostics");let e=0,t=Gt();t.found?En(t.version)?J(`Node.js v${t.version}`):(z(`Node.js v${t.version} \u2014 too old (need 18+)`),ee(" Update at https://nodejs.org"),e++):(B("Node.js \u2014 not installed"),ee(" Install from https://nodejs.org"),e++);let n=Ut();n.found?J(`Git ${n.version}`):(B("Git \u2014 not installed"),ee(" Install from https://git-scm.com"),e++);let s=Fe();if(!s.found)z("HubSpot CLI \u2014 not installed (only needed for deployment)"),ee(" Install: npm install -g @hubspot/cli");else if(!ni(s.version))z(`HubSpot CLI v${s.version} \u2014 too old (need v8+)`),ee(" Update: npm install -g @hubspot/cli@latest"),e++;else{J(`HubSpot CLI v${s.version}`);let m=je();m.authenticated?J(`HubSpot portal${m.portalName?`: ${m.portalName}`:""} (ID: ${m.portalId})`):(z("HubSpot \u2014 not authenticated"),ee(" Run: hs init"))}let o=Bt();o.found?J(`Claude Code ${o.version} at ${o.path}`):ee(I.muted("Claude Code \u2014 not installed"));let i=Vt();i.found?J(`Gemini CLI ${i.version} at ${i.path}`):ee(I.muted("Gemini CLI \u2014 not installed"));let a=Kt();a.found?J(`OpenAI Codex ${a.version} at ${a.path}`):ee(I.muted("OpenAI Codex \u2014 not installed"));let r=_(),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?J("Anthropic API key configured"):ee(I.muted("Anthropic API key \u2014 not set")),c?J("OpenAI API key configured"):ee(I.muted("OpenAI API key \u2014 not set")),d?J("Google AI API key configured"):ee(I.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&&J(`AI engine: ${u[r.aiEngine]||r.aiEngine}`),r.lastThemePath&&ee(I.muted(`Last theme: ${r.lastThemePath}`)),!o.found&&!i.found&&!a.found&&!l&&!c&&!d&&(z("No AI engine available"),ee(" Fastest: Set an API key (ANTHROPIC_API_KEY, OPENAI_API_KEY, or GEMINI_API_KEY)"),ee(" Or install: Claude Code \u2014 https://claude.ai/code"),ee(" Gemini CLI \u2014 https://github.com/google-gemini/gemini-cli"),ee(" Codex CLI \u2014 https://github.com/openai/codex"),e++),console.log(),e===0?await de("Everything looks good!"):await de(I.warn(`${e} issue${e>1?"s":""} found \u2014 see above`))}g();import{join as ks}from"path";import{existsSync as Zu}from"fs";import{execFileSync as Uo}from"child_process";import Is from"chalk";g();Se();Zt();as();fs();Z();import{createServer as Vu}from"http";import{readFileSync as Go,existsSync as yn}from"fs";import{join as tt,extname as _l}from"path";import{createHash as Ku}from"crypto";import{WebSocketServer as Yu}from"ws";g();import{spawn as Fo}from"child_process";var dt=new Map;function xa(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+=`
1501
1501
  Process error: ${o.message}`,t.completedAt=Date.now()}),setTimeout(()=>{t.status==="running"&&(e.kill(),t.status="failed",t.output+=`
1502
- Process timed out`,t.completedAt=Date.now())},n||3e5)}function fn(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};ct.set(o,i);let a=Fo(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()),va(a,i,s?.timeout),o}function St(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};ct.set(s,o);let i=e.split(" "),a=Fo(i[0],i.slice(1),{cwd:n?.cwd,stdio:["ignore","pipe","pipe"],env:{...process.env,...n?.env},shell:!0});return va(a,o,n?.timeout),s}function gs(e){return ct.get(e)}function fu(){let e=Date.now()-18e5;for(let[t,n]of ct)n.completedAt&&n.completedAt<e&&ct.delete(t)}setInterval(fu,600*1e3);function hs(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};ct.set(s,o);let i=e.split(" "),a=Fo(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+=`
1502
+ Process timed out`,t.completedAt=Date.now())},n||3e5)}function fn(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};dt.set(o,i);let a=Fo(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()),xa(a,i,s?.timeout),o}function St(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};dt.set(s,o);let i=e.split(" "),a=Fo(i[0],i.slice(1),{cwd:n?.cwd,stdio:["ignore","pipe","pipe"],env:{...process.env,...n?.env},shell:!0});return xa(a,o,n?.timeout),s}function gs(e){return dt.get(e)}function bu(){let e=Date.now()-18e5;for(let[t,n]of dt)n.completedAt&&n.completedAt<e&&dt.delete(t)}setInterval(bu,600*1e3);function hs(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};dt.set(s,o);let i=e.split(" "),a=Fo(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+=`
1503
1503
  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+=`
1504
- Process timed out`,o.completedAt=Date.now(),o.listeners.clear())},l),s}function xa(e,t){let n=ct.get(e);if(!n||!("listeners"in n))return;let s=n;if(s.output)try{t(s.output)}catch{}s.listeners.add(t)}function wa(e,t){let n=ct.get(e);!n||!("listeners"in n)||n.listeners.delete(t)}et();Q();g();et();Z();import{existsSync as Rt,readdirSync as Ca,rmSync as gu}from"fs";import{join as Ft,basename as hu}from"path";import{homedir as yu}from"os";import{execFileSync as Aa}from"child_process";Jn();pt();Se();fs();Z();Q();var ka=process.platform==="win32"?{shell:!0}:{},Oe=Ft(yu(),"vibespot-themes"),ys=null,bu=5e3;function bs(){if(ys&&Date.now()-ys.ts<bu)return ys.data;let e=[];if(Rt(Oe))try{for(let t of Ca(Oe,{withFileTypes:!0}))if(t.isDirectory()){let n=Ft(Oe,t.name,"theme.json");if(Rt(n)){let s=0,o=Ft(Oe,t.name,"modules");if(Rt(o))try{s=Ca(o,{withFileTypes:!0}).filter(i=>i.isDirectory()).length}catch{}e.push({name:t.name,moduleCount:s})}}}catch{}return ys={data:e,ts:Date.now()},e}function Ia(e){let t=S(),n=_n(),s=!1;try{Aa("hs",["--version"],{encoding:"utf-8",stdio:"pipe",...ka}),s=!0}catch{}let o=Pt().sort((a,r)=>r.updatedAt-a.updatedAt).slice(0,10),i=bs();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 Ta(e,t){N(e,n=>{try{if(Nt()){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=Ft(Oe,o);Ae(Oe),Rt(i)&&gu(i,{recursive:!0,force:!0}),jn(i,o),sn(i,o),D(),p(t,200,{ok:!0,themeName:o,themePath:i})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function $a(e,t){N(e,n=>{try{if(Nt()){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=he(),a=_(),r=o.includes("/")||o.includes("@")?o.replace(/[@/]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""):o,l=Ft(Oe,r);Ae(Oe),a.hubspotUploadMode==="cli"||!i?(Aa("hs",["cms","fetch",o,l],{encoding:"utf-8",stdio:"pipe",...ka}),sn(l,r),an(l),D(),p(t,200,{ok:!0,themeName:r,themePath:l,moduleCount:S()?.modules.length||0})):qt(i,o,l).then(()=>{sn(l,r),an(l),D(),p(t,200,{ok:!0,themeName:r,themePath:l,moduleCount:S()?.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 Ea(e,t){N(e,n=>{try{if(Nt()){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(Rt(o)||(o=Ft(Oe,s)),!Rt(o)){p(t,400,{error:`Theme folder not found: ${s}`});return}let i=hu(o);sn(o,i),an(o),D(),p(t,200,{ok:!0,themeName:i,themePath:o,moduleCount:S()?.modules.length||0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function _a(e,t){N(e,n=>{try{if(Nt()){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=is(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 Pa(e,t){N(e,n=>{try{let{apiKey:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"API key is required"});return}K({anthropicApiKey:s}),p(t,200,{ok:!0})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Oa(e){let t=he();if(!t){p(e,200,{themes:[],error:"No HubSpot account connected"});return}(async()=>{let n=await ai(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 Mn(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=bs(),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)})})}g();et();Z();Se();import{existsSync as Su,readFileSync as vu,appendFileSync as xu}from"fs";import{join as Ma}from"path";import{homedir as Na}from"os";pt();Q();var gn={data:{},ts:0},wu=600*1e3,Ra={"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 Cu(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 Au(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 ku(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 Iu(){if(Date.now()-gn.ts<wu&&Object.keys(gn.data).length>0)return gn.data;let e=_(),t={...Ra},n=[],s=ge("anthropic-api",e);s&&n.push(Cu(s).then(a=>{a.length&&(t["anthropic-api"]=a,t["claude-oauth"]=a)}).catch(()=>{}));let o=ge("openai-api",e);o&&n.push(Au(o).then(a=>{a.length&&(t["openai-api"]=a)}).catch(()=>{}));let i=ge("gemini-api",e);return i&&n.push(ku(i).then(a=>{a.length&&(t["gemini-api"]=a,t["gemini-cli"]=a)}).catch(()=>{})),await Promise.all(n),gn.data=t,gn.ts=Date.now(),t}function Fa(e){let t=_n(),n=_(),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},o=Pt().length,i=bs().length,a=wt();Iu().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:Ra,sessionCount:o,localThemeCount:i})})}function ja(e,t){N(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}K(a),p(t,200,{ok:!0,engine:s})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Ja(e,t){N(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;default:p(t,400,{error:`Unknown provider: ${s}`});return}K(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;default:p(t,400,{error:`Unknown provider: ${s}`});return}K(i);let a=null;if(!_().aiEngine){let c={anthropic:"anthropic-api",openai:"openai-api",gemini:"gemini-api"}[s];c&&(K({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 Da(e,t){N(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=St(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 Ha(e,t){N(e,n=>{try{let s=JSON.parse(n||"{}"),o=_(),i=o.hubspotUploadMode||"api";if(s.personalAccessKey)if(i==="api"){On(s.personalAccessKey).then(a=>{Jt(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(!Fe().found){p(t,400,{error:"HubSpot CLI not installed",needsInstall:!0});return}let r=fn("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(!Fe().found){p(t,400,{error:"HubSpot CLI not installed",needsInstall:!0});return}let r=je();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 La(e,t){N(e,n=>{try{let s=JSON.parse(n||"{}");if(!Rs().found){p(t,400,{error:"GitHub CLI not installed",needsInstall:!0});return}let i=Fs();if(i.authenticated&&!s.force){p(t,200,{ok:!0,alreadyAuthenticated:!0,username:i.username});return}if(s.token){let r=fn("gh",["auth","login","--with-token"],"Authenticating with GitHub",{timeout:3e4,stdin:s.token});p(t,200,{ok:!0,jobId:r});return}let a=St("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 Ga(e,t){N(e,n=>{try{let{portalId:s,action:o}=JSON.parse(n);if((_().hubspotUploadMode||"api")==="api"){if(o==="remove"&&s){$s(s),p(t,200,{ok:!0});return}if(s){Es(s),p(t,200,{ok:!0});return}}else{if(!Fe().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=fn("hs",["accounts","remove",l],`Removing HubSpot account ${l}`,{timeout:15e3});p(t,200,{ok:!0,jobId:c});return}if(l){let c=fn("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 Ua(e){let t=St("gh auth logout --hostname github.com -y","Logging out of GitHub",{timeout:15e3});p(e,200,{ok:!0,jobId:t})}function Ba(e,t){N(e,n=>{try{let{cli:s,apiKey:o}=JSON.parse(n||"{}");switch(s){case"claude":{let i=St("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=St("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,K({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")?Ma(Na(),".zshrc"):Ma(Na(),".bashrc");try{(Su(l)?vu(l,"utf-8"):"").includes("OPENAI_API_KEY")||xu(l,`
1504
+ Process timed out`,o.completedAt=Date.now(),o.listeners.clear())},l),s}function wa(e,t){let n=dt.get(e);if(!n||!("listeners"in n))return;let s=n;if(s.output)try{t(s.output)}catch{}s.listeners.add(t)}function Ca(e,t){let n=dt.get(e);!n||!("listeners"in n)||n.listeners.delete(t)}et();Q();g();et();Z();import{existsSync as Rt,readdirSync as Aa,rmSync as Su}from"fs";import{join as Ft,basename as vu}from"path";import{homedir as xu}from"os";import{execFileSync as ka}from"child_process";Jn();pt();Se();fs();Z();Q();var Ia=process.platform==="win32"?{shell:!0}:{},Me=Ft(xu(),"vibespot-themes"),ys=null,wu=5e3;function bs(){if(ys&&Date.now()-ys.ts<wu)return ys.data;let e=[];if(Rt(Me))try{for(let t of Aa(Me,{withFileTypes:!0}))if(t.isDirectory()){let n=Ft(Me,t.name,"theme.json");if(Rt(n)){let s=0,o=Ft(Me,t.name,"modules");if(Rt(o))try{s=Aa(o,{withFileTypes:!0}).filter(i=>i.isDirectory()).length}catch{}e.push({name:t.name,moduleCount:s})}}}catch{}return ys={data:e,ts:Date.now()},e}function Ta(e){let t=S(),n=_n(),s=!1;try{ka("hs",["--version"],{encoding:"utf-8",stdio:"pipe",...Ia}),s=!0}catch{}let o=Pt().sort((a,r)=>r.updatedAt-a.updatedAt).slice(0,10),i=bs();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 $a(e,t){N(e,n=>{try{if(Nt()){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=Ft(Me,o);Ae(Me),Rt(i)&&Su(i,{recursive:!0,force:!0}),jn(i,o),sn(i,o),D(),p(t,200,{ok:!0,themeName:o,themePath:i})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Ea(e,t){N(e,n=>{try{if(Nt()){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=he(),a=_(),r=o.includes("/")||o.includes("@")?o.replace(/[@/]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""):o,l=Ft(Me,r);Ae(Me),a.hubspotUploadMode==="cli"||!i?(ka("hs",["cms","fetch",o,l],{encoding:"utf-8",stdio:"pipe",...Ia}),sn(l,r),an(l),D(),p(t,200,{ok:!0,themeName:r,themePath:l,moduleCount:S()?.modules.length||0})):qt(i,o,l).then(()=>{sn(l,r),an(l),D(),p(t,200,{ok:!0,themeName:r,themePath:l,moduleCount:S()?.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 _a(e,t){N(e,n=>{try{if(Nt()){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(Rt(o)||(o=Ft(Me,s)),!Rt(o)){p(t,400,{error:`Theme folder not found: ${s}`});return}let i=vu(o);sn(o,i),an(o),D(),p(t,200,{ok:!0,themeName:i,themePath:o,moduleCount:S()?.modules.length||0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function Pa(e,t){N(e,n=>{try{if(Nt()){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=is(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 Ma(e,t){N(e,n=>{try{let{apiKey:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"API key is required"});return}K({anthropicApiKey:s}),p(t,200,{ok:!0})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Oa(e){let t=he();if(!t){p(e,200,{themes:[],error:"No HubSpot account connected"});return}(async()=>{let n=await ai(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 On(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=bs(),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)})})}g();et();Z();Se();import{existsSync as Cu,readFileSync as Au,appendFileSync as ku}from"fs";import{join as Na}from"path";import{homedir as Ra}from"os";pt();Q();var gn={data:{},ts:0},Iu=600*1e3,Fa={"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 Tu(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 $u(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 Eu(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 _u(){if(Date.now()-gn.ts<Iu&&Object.keys(gn.data).length>0)return gn.data;let e=_(),t={...Fa},n=[],s=ge("anthropic-api",e);s&&n.push(Tu(s).then(a=>{a.length&&(t["anthropic-api"]=a,t["claude-oauth"]=a)}).catch(()=>{}));let o=ge("openai-api",e);o&&n.push($u(o).then(a=>{a.length&&(t["openai-api"]=a)}).catch(()=>{}));let i=ge("gemini-api",e);return i&&n.push(Eu(i).then(a=>{a.length&&(t["gemini-api"]=a,t["gemini-cli"]=a)}).catch(()=>{})),await Promise.all(n),gn.data=t,gn.ts=Date.now(),t}function ja(e){let t=_n(),n=_(),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},o=Pt().length,i=bs().length,a=wt();_u().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:Fa,sessionCount:o,localThemeCount:i})})}function Ja(e,t){N(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}K(a),p(t,200,{ok:!0,engine:s})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Da(e,t){N(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;default:p(t,400,{error:`Unknown provider: ${s}`});return}K(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;default:p(t,400,{error:`Unknown provider: ${s}`});return}K(i);let a=null;if(!_().aiEngine){let c={anthropic:"anthropic-api",openai:"openai-api",gemini:"gemini-api"}[s];c&&(K({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 Ha(e,t){N(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=St(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 La(e,t){N(e,n=>{try{let s=JSON.parse(n||"{}"),o=_(),i=o.hubspotUploadMode||"api";if(s.personalAccessKey)if(i==="api"){Mn(s.personalAccessKey).then(a=>{Jt(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(!Fe().found){p(t,400,{error:"HubSpot CLI not installed",needsInstall:!0});return}let r=fn("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(!Fe().found){p(t,400,{error:"HubSpot CLI not installed",needsInstall:!0});return}let r=je();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 Ga(e,t){N(e,n=>{try{let s=JSON.parse(n||"{}");if(!Rs().found){p(t,400,{error:"GitHub CLI not installed",needsInstall:!0});return}let i=Fs();if(i.authenticated&&!s.force){p(t,200,{ok:!0,alreadyAuthenticated:!0,username:i.username});return}if(s.token){let r=fn("gh",["auth","login","--with-token"],"Authenticating with GitHub",{timeout:3e4,stdin:s.token});p(t,200,{ok:!0,jobId:r});return}let a=St("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 Ua(e,t){N(e,n=>{try{let{portalId:s,action:o}=JSON.parse(n);if((_().hubspotUploadMode||"api")==="api"){if(o==="remove"&&s){$s(s),p(t,200,{ok:!0});return}if(s){Es(s),p(t,200,{ok:!0});return}}else{if(!Fe().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=fn("hs",["accounts","remove",l],`Removing HubSpot account ${l}`,{timeout:15e3});p(t,200,{ok:!0,jobId:c});return}if(l){let c=fn("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 Ba(e){let t=St("gh auth logout --hostname github.com -y","Logging out of GitHub",{timeout:15e3});p(e,200,{ok:!0,jobId:t})}function Wa(e,t){N(e,n=>{try{let{cli:s,apiKey:o}=JSON.parse(n||"{}");switch(s){case"claude":{let i=St("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=St("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,K({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")?Na(Ra(),".zshrc"):Na(Ra(),".bashrc");try{(Cu(l)?Au(l,"utf-8"):"").includes("OPENAI_API_KEY")||ku(l,`
1505
1505
  # Added by vibeSpot
1506
1506
  ${r}
1507
- `)}catch{}}}p(t,200,{ok:!0,message:"API key saved"})}else{let i=St("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 Wa(e,t){N(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}K({hubspotUploadMode:s}),p(t,200,{ok:!0,mode:s})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Va(e,t){N(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}_s(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 Ka(e,t){N(e,n=>{try{let s=JSON.parse(n),o=["agenticMode","agenticConcurrency"],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}K(i),p(t,200,{ok:!0,updated:Object.keys(i)})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Ya(e,t){let n=e.replace("/api/settings/job/","");if(!n){p(t,400,{error:"Job ID required"});return}let s=gs(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})}g();et();Z();Ke();function za(e,t){N(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}Ps(s.trim(),(o||"").trim());let i=_();(!i.aiEngine||i.aiEngine!=="claude-oauth")&&K({aiEngine:"claude-oauth"}),p(t,200,{ok:!0})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function qa(e,t){let n=Re(),s=Lt();p(t,200,{authenticated:n,expiresAt:s?.expiresAt||null})}function Xa(e,t){try{kn(),_().aiEngine==="claude-oauth"&&K({aiEngine:void 0}),p(t,200,{ok:!0})}catch(n){p(t,500,{error:n instanceof Error?n.message:String(n)})}}g();et();Se();import{existsSync as Tu,rmSync as $u}from"fs";import{join as Eu}from"path";function Qa(e,t,n){if(e==="GET"){let s=S(),o=Pt().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"){N(t,s=>{try{let{sessionId:o,deleteFiles:i}=JSON.parse(s);cr(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 Za(e,t){N(e,n=>{try{let{sessionId:s}=JSON.parse(n),o=is(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 el(e,t){N(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=Eu(Oe,s);if(!Tu(o)){p(t,404,{error:"Theme not found on disk"});return}$u(o,{recursive:!0,force:!0}),p(t,200,{ok:!0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function tl(e,t){N(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=dr(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)})}})}g();et();ve();Z();Se();Q();import{existsSync as As,readFileSync as ju,rmSync as Lo}from"fs";import{join as Be,basename as Ju}from"path";import{execFileSync as Du}from"child_process";var Hu=process.platform==="win32"?{shell:!0}:{};function ll(e){let t=S();if(!t){p(e,404,{error:"No active session"});return}let n=rt();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 cl(e){let t=S();if(!t){p(e,404,{error:"No active session"});return}let n=t.themePath;if(!As(n)){p(e,404,{error:"Theme directory not found"});return}let s=t.themeName||"theme",o=Be(n,".."),i=Ju(n);try{let a=`${s}.zip`,r=Be(o,a);As(r)&&Lo(r),Du("zip",["-r",a,i,"-x",`${i}/.git/*`,`${i}/.vibespot/*`,`${i}/node_modules/*`],{cwd:o,timeout:3e4,...Hu});let l=ju(r);Lo(r),e.writeHead(200,{"Content-Type":"application/zip","Content-Disposition":`attachment; filename="${a}"`,"Content-Length":l.length}),e.end(l)}catch(a){T.error("download-zip","Failed to create zip archive",a),p(e,500,{error:"Failed to create zip archive"})}}function dl(e,t,n){let s=S();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"){N(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=or(i,a);D(),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"){N(t,o=>{try{let{templateId:i,deleteModules:a}=JSON.parse(o);if(!i){p(n,400,{error:"templateId is required"});return}if(!ar(i,!!a)){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 ul(e,t){N(e,n=>{try{let{templateId:s}=JSON.parse(n);if(!s){p(t,400,{error:"templateId is required"});return}if(!qs(s)){p(t,404,{error:"Template not found"});return}D();let i=S();p(t,200,{ok:!0,modules:me().map(a=>a.moduleName),messageCount:i?.messages.length||0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function ml(e,t){N(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(!rr(s,o.trim())){p(t,404,{error:"Template not found"});return}D(),p(t,200,{ok:!0,newLabel:o.trim()})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function pl(e,t){N(e,n=>{try{let{templateId:s,label:o}=JSON.parse(n);if(!s){p(t,400,{error:"templateId is required"});return}let i=ir(s,o);if(!i){p(t,404,{error:"Template not found"});return}D(),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 fl(e){let t=rt();p(e,200,{modules:t.map(n=>({moduleName:n.module.moduleName,usedIn:n.usedIn,fieldsJson:n.module.fieldsJson}))})}function gl(e,t,n){let s=S();if(!s){p(n,404,{error:"No active session"});return}N(t,o=>{try{let{moduleName:i}=JSON.parse(o);if(!i){p(n,400,{error:"moduleName is required"});return}let r=rt().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()),D(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}})}function hl(e,t,n){let s=S();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"){N(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(),D(),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==="themeContext"?"theme-context.md":`${i}.md`;s.brandAssets[i]=a,s.updatedAt=Date.now();let l=Be(s.themePath,".vibespot");Ae(l),H(Be(l,r),a),D(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}if(e==="DELETE"){N(t,o=>{try{let{type:i}=JSON.parse(o);if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(n,400,{error:`Invalid type: ${i}`});return}s.brandAssets&&delete s.brandAssets[i],s.updatedAt=Date.now();let a=i==="themeContext"?"theme-context.md":`${i}.md`,r=Be(s.themePath,".vibespot",a);As(r)&&Lo(r),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 rl(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=Be(e.themePath,".vibespot");Ae(o),H(Be(o,s),n)}async function al(e,t,n){if(t==="styleguide"){let{extractDesignContext:m}=await Promise.resolve().then(()=>(Cs(),ws));return m(n||e.themePath)}let{resolveAgenticEngine:s}=await Promise.resolve().then(()=>(fs(),Sa)),{loadConfig:o}=await Promise.resolve().then(()=>(Z(),Qo)),i=o(),{engine:a,apiKey:r,model:l}=s(i),{buildPreviewHtml:c}=await Promise.resolve().then(()=>(as(),lo)),d=c();if(!d||d.length<50)return null;if(t==="brandvoice"){let{extractBrandvoice:m}=await Promise.resolve().then(()=>(il(),ol));return m(d,a,r,l)}let{extractThemeContext:u}=await Promise.resolve().then(()=>(Ho(),Do));return u(d,e.brandAssets?.themeContext,a,r,l)}function yl(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}N(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=>al(n,u,a))),d={};for(let u=0;u<l.length;u++){let m=c[u],f=m.status==="fulfilled"?m.value:null;f&&rl(n,l[u],f),d[l[u]]=f}D(),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 al(n,i,a);if(!r){p(t,200,{ok:!1,type:i,error:"No content to extract from"});return}rl(n,i,r),D(),p(t,200,{ok:!0,type:i,content:r})}catch(o){p(t,500,{error:o instanceof Error?o.message:String(o)})}})()})}function bl(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}N(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=he();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 f=m.replace(/[@/]/g,"_").replace(/_+/g,"_"),{homedir:h}=await import("os"),y=Be(h(),"vibespot-themes",".references",f);Ae(y);let{fetchTheme:v}=await Promise.resolve().then(()=>(Jn(),pi));await v(u,m,y),r=y}else if(o==="local"){if(!a){p(t,400,{error:"localPath is required for local import"});return}if(!As(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(()=>(Cs(),ws)),c=await l(r);n.brandAssets||(n.brandAssets={}),n.brandAssets.styleguide=c,n.updatedAt=Date.now();let d=Be(n.themePath,".vibespot");Ae(d),H(Be(d,"styleguide.md"),c),D(),p(t,200,{ok:!0,styleguide:c,source:r})}catch(o){p(t,500,{error:o instanceof Error?o.message:String(o)})}})()})}g();et();Se();import{join as Lu}from"path";Zt();function Sl(e,t){let n=S();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 vl(e,t,n){let s=S();if(!s){p(n,404,{error:"No active session"});return}if(e==="GET"){let o=me();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"){vo(t,n,o=>{o.deleteEntirely?Zi(o.moduleName):er(o.moduleName),D(),p(n,200,{ok:!0})});return}p(n,405,{error:"Method not allowed"})}function xl(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}N(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=Ce();c&&(o.shared==="css"?c.sharedCss=o.content:c.sharedJs=o.content),n.updatedAt=Date.now(),D(),at(),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(),D(),at(),p(t,200,{ok:!0})}catch(o){p(t,400,{error:String(o)})}})}function wl(e,t){vo(e,t,n=>{Array.isArray(n.order)?(Et(n.order),D(),p(t,200,{ok:!0})):p(t,400,{error:"order must be an array"})})}async function Cl(e){let t=S();if(!t){p(e,404,{error:"No active session"});return}try{at();let n=zn(t.themePath),s=hs(`hs cms upload "${t.themePath}" "${t.themeName}"`,"Uploading to HubSpot",{cwd:Lu(t.themePath,".."),timeout:18e4});p(e,200,{ok:!0,jobId:s,fixes:n})}catch(n){p(e,500,{error:String(n)})}}function Al(e,t){N(e,n=>{try{let{moduleName:s,fieldPath:o,value:i}=JSON.parse(n);tr(s,o,i),D(),p(t,200,{ok:!0})}catch(s){p(t,400,{error:String(s)})}})}function kl(e,t){N(e,n=>{try{let{url:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"url is required"});return}let o=ui(s),i=o.components.map(r=>`- ${r.name}: ${r.description}`).join(`
1507
+ `)}catch{}}}p(t,200,{ok:!0,message:"API key saved"})}else{let i=St("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 Va(e,t){N(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}K({hubspotUploadMode:s}),p(t,200,{ok:!0,mode:s})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Ka(e,t){N(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}_s(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 Ya(e,t){N(e,n=>{try{let s=JSON.parse(n),o=["agenticMode","agenticConcurrency"],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}K(i),p(t,200,{ok:!0,updated:Object.keys(i)})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function za(e,t){let n=e.replace("/api/settings/job/","");if(!n){p(t,400,{error:"Job ID required"});return}let s=gs(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})}g();et();Z();Ke();function qa(e,t){N(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}Ps(s.trim(),(o||"").trim());let i=_();(!i.aiEngine||i.aiEngine!=="claude-oauth")&&K({aiEngine:"claude-oauth"}),p(t,200,{ok:!0})}catch(s){p(t,400,{error:s instanceof Error?s.message:String(s)})}})}function Xa(e,t){let n=Re(),s=Lt();p(t,200,{authenticated:n,expiresAt:s?.expiresAt||null})}function Qa(e,t){try{kn(),_().aiEngine==="claude-oauth"&&K({aiEngine:void 0}),p(t,200,{ok:!0})}catch(n){p(t,500,{error:n instanceof Error?n.message:String(n)})}}g();et();Se();import{existsSync as Pu,rmSync as Mu}from"fs";import{join as Ou}from"path";function Za(e,t,n){if(e==="GET"){let s=S(),o=Pt().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"){N(t,s=>{try{let{sessionId:o,deleteFiles:i}=JSON.parse(s);cr(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 el(e,t){N(e,n=>{try{let{sessionId:s}=JSON.parse(n),o=is(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 tl(e,t){N(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=Ou(Me,s);if(!Pu(o)){p(t,404,{error:"Theme not found on disk"});return}Mu(o,{recursive:!0,force:!0}),p(t,200,{ok:!0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function nl(e,t){N(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=dr(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)})}})}g();et();ve();Z();Se();Q();import{existsSync as As,readFileSync as Lu,rmSync as Lo}from"fs";import{join as Be,basename as Gu}from"path";import{execFileSync as Uu}from"child_process";var Bu=process.platform==="win32"?{shell:!0}:{};function cl(e){let t=S();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 dl(e){let t=S();if(!t){p(e,404,{error:"No active session"});return}let n=t.themePath;if(!As(n)){p(e,404,{error:"Theme directory not found"});return}let s=t.themeName||"theme",o=Be(n,".."),i=Gu(n);try{let a=`${s}.zip`,r=Be(o,a);As(r)&&Lo(r),Uu("zip",["-r",a,i,"-x",`${i}/.git/*`,`${i}/.vibespot/*`,`${i}/node_modules/*`],{cwd:o,timeout:3e4,...Bu});let l=Lu(r);Lo(r),e.writeHead(200,{"Content-Type":"application/zip","Content-Disposition":`attachment; filename="${a}"`,"Content-Length":l.length}),e.end(l)}catch(a){T.error("download-zip","Failed to create zip archive",a),p(e,500,{error:"Failed to create zip archive"})}}function ul(e,t,n){let s=S();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"){N(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=or(i,a);D(),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"){N(t,o=>{try{let{templateId:i,deleteModules:a}=JSON.parse(o);if(!i){p(n,400,{error:"templateId is required"});return}if(!ar(i,!!a)){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 ml(e,t){N(e,n=>{try{let{templateId:s}=JSON.parse(n);if(!s){p(t,400,{error:"templateId is required"});return}if(!qs(s)){p(t,404,{error:"Template not found"});return}D();let i=S();p(t,200,{ok:!0,modules:me().map(a=>a.moduleName),messageCount:i?.messages.length||0})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function pl(e,t){N(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(!rr(s,o.trim())){p(t,404,{error:"Template not found"});return}D(),p(t,200,{ok:!0,newLabel:o.trim()})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}function fl(e,t){N(e,n=>{try{let{templateId:s,label:o}=JSON.parse(n);if(!s){p(t,400,{error:"templateId is required"});return}let i=ir(s,o);if(!i){p(t,404,{error:"Template not found"});return}D(),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 gl(e){let t=at();p(e,200,{modules:t.map(n=>({moduleName:n.module.moduleName,usedIn:n.usedIn,fieldsJson:n.module.fieldsJson}))})}function hl(e,t,n){let s=S();if(!s){p(n,404,{error:"No active session"});return}N(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()),D(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}})}function yl(e,t,n){let s=S();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"){N(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(),D(),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==="themeContext"?"theme-context.md":`${i}.md`;s.brandAssets[i]=a,s.updatedAt=Date.now();let l=Be(s.themePath,".vibespot");Ae(l),H(Be(l,r),a),D(),p(n,200,{ok:!0})}catch(i){p(n,500,{error:i instanceof Error?i.message:String(i)})}});return}if(e==="DELETE"){N(t,o=>{try{let{type:i}=JSON.parse(o);if(i!=="styleguide"&&i!=="brandvoice"&&i!=="themeContext"){p(n,400,{error:`Invalid type: ${i}`});return}s.brandAssets&&delete s.brandAssets[i],s.updatedAt=Date.now();let a=i==="themeContext"?"theme-context.md":`${i}.md`,r=Be(s.themePath,".vibespot",a);As(r)&&Lo(r),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 al(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=Be(e.themePath,".vibespot");Ae(o),H(Be(o,s),n)}async function ll(e,t,n){if(t==="styleguide"){let{extractDesignContext:m}=await Promise.resolve().then(()=>(Cs(),ws));return m(n||e.themePath)}let{resolveAgenticEngine:s}=await Promise.resolve().then(()=>(fs(),va)),{loadConfig:o}=await Promise.resolve().then(()=>(Z(),Qo)),i=o(),{engine:a,apiKey:r,model:l}=s(i),{buildPreviewHtml:c}=await Promise.resolve().then(()=>(as(),lo)),d=c();if(!d||d.length<50)return null;if(t==="brandvoice"){let{extractBrandvoice:m}=await Promise.resolve().then(()=>(rl(),il));return m(d,a,r,l)}let{extractThemeContext:u}=await Promise.resolve().then(()=>(Ho(),Do));return u(d,e.brandAssets?.themeContext,a,r,l)}function bl(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}N(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=>ll(n,u,a))),d={};for(let u=0;u<l.length;u++){let m=c[u],f=m.status==="fulfilled"?m.value:null;f&&al(n,l[u],f),d[l[u]]=f}D(),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 ll(n,i,a);if(!r){p(t,200,{ok:!1,type:i,error:"No content to extract from"});return}al(n,i,r),D(),p(t,200,{ok:!0,type:i,content:r})}catch(o){p(t,500,{error:o instanceof Error?o.message:String(o)})}})()})}function Sl(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}N(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=he();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 f=m.replace(/[@/]/g,"_").replace(/_+/g,"_"),{homedir:h}=await import("os"),y=Be(h(),"vibespot-themes",".references",f);Ae(y);let{fetchTheme:v}=await Promise.resolve().then(()=>(Jn(),pi));await v(u,m,y),r=y}else if(o==="local"){if(!a){p(t,400,{error:"localPath is required for local import"});return}if(!As(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(()=>(Cs(),ws)),c=await l(r);n.brandAssets||(n.brandAssets={}),n.brandAssets.styleguide=c,n.updatedAt=Date.now();let d=Be(n.themePath,".vibespot");Ae(d),H(Be(d,"styleguide.md"),c),D(),p(t,200,{ok:!0,styleguide:c,source:r})}catch(o){p(t,500,{error:o instanceof Error?o.message:String(o)})}})()})}g();et();Se();import{join as Wu}from"path";Zt();function vl(e,t){let n=S();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 xl(e,t,n){let s=S();if(!s){p(n,404,{error:"No active session"});return}if(e==="GET"){let o=me();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"){vo(t,n,o=>{o.deleteEntirely?Zi(o.moduleName):er(o.moduleName),D(),p(n,200,{ok:!0})});return}p(n,405,{error:"Method not allowed"})}function wl(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}N(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=Ce();c&&(o.shared==="css"?c.sharedCss=o.content:c.sharedJs=o.content),n.updatedAt=Date.now(),D(),lt(),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(),D(),lt(),p(t,200,{ok:!0})}catch(o){p(t,400,{error:String(o)})}})}function Cl(e,t){vo(e,t,n=>{Array.isArray(n.order)?(Et(n.order),D(),p(t,200,{ok:!0})):p(t,400,{error:"order must be an array"})})}async function Al(e){let t=S();if(!t){p(e,404,{error:"No active session"});return}try{lt();let n=zn(t.themePath),s=hs(`hs cms upload "${t.themePath}" "${t.themeName}"`,"Uploading to HubSpot",{cwd:Wu(t.themePath,".."),timeout:18e4});p(e,200,{ok:!0,jobId:s,fixes:n})}catch(n){p(e,500,{error:String(n)})}}function kl(e,t){N(e,n=>{try{let{moduleName:s,fieldPath:o,value:i}=JSON.parse(n);tr(s,o,i),D(),p(t,200,{ok:!0})}catch(s){p(t,400,{error:String(s)})}})}function Il(e,t){N(e,n=>{try{let{url:s}=JSON.parse(n);if(!s||typeof s!="string"){p(t,400,{error:"url is required"});return}let o=ui(s),i=o.components.map(r=>`- ${r.name}: ${r.description}`).join(`
1508
1508
  `),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.
1509
1509
 
1510
1510
  Source analysis found ${o.components.length} components:
@@ -1514,11 +1514,11 @@ Design system: ${o.hasTailwind?"Tailwind CSS":"Custom CSS"}, ${o.cssVarCount} CS
1514
1514
  Fonts: ${o.fonts.length>0?o.fonts.join(", "):"System fonts"}
1515
1515
  Interactions: ${o.interactions.join(", ")}
1516
1516
 
1517
- 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 Il(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}if(!_e()){p(t,200,{available:!1,commits:[]});return}let o=new URL(e.url||"/","http://localhost").searchParams.get("templateId"),i=o?Yi(n.themePath,o,50):Ki(n.themePath,50);p(t,200,{available:!0,commits:i,filtered:!!o})}function Tl(e,t){N(e,n=>{try{let s=S();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(it("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=qi(s.themePath,i,o,r);if(!l.success){p(t,500,{error:l.error||"Rollback failed"});return}fr()}else{let a=zi(s.themePath,o);if(!a.success){p(t,500,{error:a.error||"Rollback failed"});return}pr()}D(),p(t,200,{ok:!0,modules:me().map(a=>a.moduleName)})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}Co();var _l={".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 Pl(e){let{port:t,uiDir:n}=e,s=Gu((i,a)=>Wu(i,a,n)),o=new Bu({server:s});return o.on("connection",i=>Ku(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 Wu(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/")){Vu(o,s.pathname,e,t);return}if(s.pathname==="/preview"){let i=ro();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=ao(i);t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(a||"<!-- module not found -->");return}if(s.pathname.startsWith("/theme-assets/")){Yu(s.pathname.slice(14),t);return}zu(s.pathname,n,e,t)}function Vu(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":Sl(e,s);break;case"/api/modules":vl(e,n,s);break;case"/api/modules/reorder":wl(n,s);break;case"/api/modules/code":xl(n,s);break;case"/api/upload":Cl(s);break;case"/api/upload-files":e==="POST"?Lr(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/field":Al(n,s);break;case"/api/import":kl(n,s);break;case"/api/setup":Ia(s);break;case"/api/setup/create":Ta(n,s);break;case"/api/setup/fetch":$a(n,s);break;case"/api/setup/open":Ea(n,s);break;case"/api/setup/resume":_a(n,s);break;case"/api/setup/apikey":Pa(n,s);break;case"/api/setup/remote-themes":e==="GET"?Oa(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/status":e==="GET"?Fa(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/engine":e==="POST"?ja(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/apikey":e==="POST"?Ja(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/install":e==="POST"?Da(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-auth":e==="POST"?Ha(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/gh-auth":e==="POST"?La(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-switch":e==="POST"?Ga(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/gh-logout":e==="POST"?Ua(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/cli-auth":e==="POST"?Ba(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-mode":e==="POST"?Wa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/cli-toggle":e==="POST"?Va(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/save":e==="POST"?za(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/status":e==="GET"?qa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/logout":e==="POST"?Xa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings":e==="POST"?Ka(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/changelog":e==="GET"?p(s,200,{changelog:Ko()}):p(s,405,{error:"Method not allowed"});break;case"/api/themes":Qa(e,n,s);break;case"/api/themes/switch":e==="POST"?Za(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/delete-local":e==="POST"?el(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/rename":e==="POST"?tl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/history":e==="GET"?Il(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/rollback":e==="POST"?Tl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/dashboard":e==="GET"?ll(s):p(s,405,{error:"Method not allowed"});break;case"/api/templates":dl(e,n,s);break;case"/api/templates/activate":e==="POST"?ul(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/rename":e==="POST"?ml(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/clone":e==="POST"?pl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/module-library":e==="GET"?fl(s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets":hl(e,n,s);break;case"/api/brand-assets/extract":e==="POST"?yl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets/import-reference":e==="POST"?bl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/download-zip":e==="GET"?cl(s):p(s,405,{error:"Method not allowed"});break;default:t.startsWith("/api/settings/job/")&&e==="GET"?Ya(t,s):t.match(/^\/api\/templates\/[^/]+\/add-module$/)&&e==="POST"?gl(t,n,s):p(s,404,{error:"Not found"})}}function Ku(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;it("user",o),D();let i=Array.isArray(s.fileIds)?s.fileIds:void 0,a=Ro();a.needsPrompt&&e.send(JSON.stringify({type:"agentic_prompt"}));try{if(a.useAgentic){let l=[],c=[],d=await Mo(o,u=>{if(u.type==="module_progress"&&u.moduleFiles){let{moduleFiles:m,...f}=u;e.send(JSON.stringify(f))}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"?Le({sharedCss:u.sharedCss,sharedJs:u.sharedJs}):u.type==="blueprint_ready"?(Le({sharedCss:u.sharedCss,sharedJs:u.sharedJs}),Et(u.moduleOrder),e.send(JSON.stringify({type:"modules_updated",modules:me().map(m=>m.moduleName)}))):u.type==="module_progress"&&u.status==="complete"&&u.moduleFiles?(Le({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:me().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);No(d,{steps:l,modules:c,stats:d.stats})}else Po(l=>{e.send(JSON.stringify({type:"parse_warning",message:l}))}),await pn(o,l=>{e.send(JSON.stringify({type:"stream",content:l}))},l=>{e.send(JSON.stringify({type:"stream_status",content:l}))},i);let r=S();if(r){at();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/${r.themeName}-theme.css`),l.sharedJs&&d.push(`js/${r.themeName}-animations.js`),c=Vi(r.themePath,l.id,o,d)}else c=Ks(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:me().map(l=>l.moduleName)}));{let l=S();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"extract_brand_assets":{let o=S();if(!o){e.send(JSON.stringify({type:"error",message:"No active session"}));break}(async()=>{try{let i=_(),{engine:a,apiKey:r,model:l}=ps(i),{buildPreviewHtml:c}=await Promise.resolve().then(()=>(as(),lo)),d=c();if(!d||d.length<50)return;let{extractThemeContext:u}=await Promise.resolve().then(()=>(Ho(),Do)),m=await u(d,o.brandAssets?.themeContext,a,r,l),{mkdirSync:f,writeFileSync:h}=await import("fs");if(m){o.brandAssets||(o.brandAssets={}),o.brandAssets.themeContext=m,o.updatedAt=Date.now();let y=dt(o.themePath,".vibespot");yn(y)||f(y,{recursive:!0}),h(dt(y,"theme-context.md"),m),D(),e.send(JSON.stringify({type:"brand_asset_extracted",assetType:"themeContext"}))}if(!o.brandAssets?.styleguide)try{let{extractDesignContext:y}=await Promise.resolve().then(()=>(Cs(),ws)),v=await y(o.themePath);if(v){o.brandAssets||(o.brandAssets={}),o.brandAssets.styleguide=v,o.updatedAt=Date.now();let C=dt(o.themePath,".vibespot");yn(C)||f(C,{recursive:!0}),h(dt(C,"styleguide.md"),v),D(),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=S();if(!o){e.send(JSON.stringify({type:"error",message:"No active session"}));break}try{at();let i=zn(o.themePath);if(i.length>0&&e.send(JSON.stringify({type:"upload_status",phase:"autofix",fixes:i})),(_().hubspotUploadMode||"api")==="api"){let l=he();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 qn(l,o.themePath,o.themeName,{onFileStart:d=>{e.send(JSON.stringify({type:"upload_output",chunk:`Uploading ${d}
1517
+ 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 Tl(e,t){let n=S();if(!n){p(t,404,{error:"No active session"});return}if(!_e()){p(t,200,{available:!1,commits:[]});return}let o=new URL(e.url||"/","http://localhost").searchParams.get("templateId"),i=o?Yi(n.themePath,o,50):Ki(n.themePath,50);p(t,200,{available:!0,commits:i,filtered:!!o})}function $l(e,t){N(e,n=>{try{let s=S();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(rt("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=qi(s.themePath,i,o,r);if(!l.success){p(t,500,{error:l.error||"Rollback failed"});return}fr()}else{let a=zi(s.themePath,o);if(!a.success){p(t,500,{error:a.error||"Rollback failed"});return}pr()}D(),p(t,200,{ok:!0,modules:me().map(a=>a.moduleName)})}catch(s){p(t,500,{error:s instanceof Error?s.message:String(s)})}})}Co();var Pl={".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 Ml(e){let{port:t,uiDir:n}=e,s=Vu((i,a)=>zu(i,a,n)),o=new Yu({server:s});return o.on("connection",i=>Xu(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 zu(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/")){qu(o,s.pathname,e,t);return}if(s.pathname==="/preview"){let i=ro();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=ao(i);t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(a||"<!-- module not found -->");return}if(s.pathname.startsWith("/theme-assets/")){Qu(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";El(i,tt(n,"docs"),e,t);return}El(s.pathname,n,e,t)}function qu(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":vl(e,s);break;case"/api/modules":xl(e,n,s);break;case"/api/modules/reorder":Cl(n,s);break;case"/api/modules/code":wl(n,s);break;case"/api/upload":Al(s);break;case"/api/upload-files":e==="POST"?Lr(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/field":kl(n,s);break;case"/api/import":Il(n,s);break;case"/api/setup":Ta(s);break;case"/api/setup/create":$a(n,s);break;case"/api/setup/fetch":Ea(n,s);break;case"/api/setup/open":_a(n,s);break;case"/api/setup/resume":Pa(n,s);break;case"/api/setup/apikey":Ma(n,s);break;case"/api/setup/remote-themes":e==="GET"?Oa(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/status":e==="GET"?ja(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/engine":e==="POST"?Ja(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/apikey":e==="POST"?Da(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/install":e==="POST"?Ha(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-auth":e==="POST"?La(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/gh-auth":e==="POST"?Ga(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-switch":e==="POST"?Ua(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/gh-logout":e==="POST"?Ba(s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/cli-auth":e==="POST"?Wa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/hs-mode":e==="POST"?Va(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/cli-toggle":e==="POST"?Ka(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/save":e==="POST"?qa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/status":e==="GET"?Xa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings/claude-oauth/logout":e==="POST"?Qa(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/settings":e==="POST"?Ya(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/changelog":e==="GET"?p(s,200,{changelog:Ko()}):p(s,405,{error:"Method not allowed"});break;case"/api/themes":Za(e,n,s);break;case"/api/themes/switch":e==="POST"?el(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/delete-local":e==="POST"?tl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/themes/rename":e==="POST"?nl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/history":e==="GET"?Tl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/rollback":e==="POST"?$l(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/dashboard":e==="GET"?cl(s):p(s,405,{error:"Method not allowed"});break;case"/api/templates":ul(e,n,s);break;case"/api/templates/activate":e==="POST"?ml(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/rename":e==="POST"?pl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/templates/clone":e==="POST"?fl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/module-library":e==="GET"?gl(s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets":yl(e,n,s);break;case"/api/brand-assets/extract":e==="POST"?bl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/brand-assets/import-reference":e==="POST"?Sl(n,s):p(s,405,{error:"Method not allowed"});break;case"/api/download-zip":e==="GET"?dl(s):p(s,405,{error:"Method not allowed"});break;default:t.startsWith("/api/settings/job/")&&e==="GET"?za(t,s):t.match(/^\/api\/templates\/[^/]+\/add-module$/)&&e==="POST"?hl(t,n,s):p(s,404,{error:"Not found"})}}function Xu(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;rt("user",o),D();let i=Array.isArray(s.fileIds)?s.fileIds:void 0,a=Ro();a.needsPrompt&&e.send(JSON.stringify({type:"agentic_prompt"}));try{if(a.useAgentic){let l=[],c=[],d=await Oo(o,u=>{if(u.type==="module_progress"&&u.moduleFiles){let{moduleFiles:m,...f}=u;e.send(JSON.stringify(f))}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"?Le({sharedCss:u.sharedCss,sharedJs:u.sharedJs}):u.type==="blueprint_ready"?(Le({sharedCss:u.sharedCss,sharedJs:u.sharedJs}),Et(u.moduleOrder),e.send(JSON.stringify({type:"modules_updated",modules:me().map(m=>m.moduleName)}))):u.type==="module_progress"&&u.status==="complete"&&u.moduleFiles?(Le({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:me().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);No(d,{steps:l,modules:c,stats:d.stats})}else Po(l=>{e.send(JSON.stringify({type:"parse_warning",message:l}))}),await pn(o,l=>{e.send(JSON.stringify({type:"stream",content:l}))},l=>{e.send(JSON.stringify({type:"stream_status",content:l}))},i);let r=S();if(r){lt();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/${r.themeName}-theme.css`),l.sharedJs&&d.push(`js/${r.themeName}-animations.js`),c=Vi(r.themePath,l.id,o,d)}else c=Ks(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:me().map(l=>l.moduleName)}));{let l=S();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"extract_brand_assets":{let o=S();if(!o){e.send(JSON.stringify({type:"error",message:"No active session"}));break}(async()=>{try{let i=_(),{engine:a,apiKey:r,model:l}=ps(i),{buildPreviewHtml:c}=await Promise.resolve().then(()=>(as(),lo)),d=c();if(!d||d.length<50)return;let{extractThemeContext:u}=await Promise.resolve().then(()=>(Ho(),Do)),m=await u(d,o.brandAssets?.themeContext,a,r,l),{mkdirSync:f,writeFileSync:h}=await import("fs");if(m){o.brandAssets||(o.brandAssets={}),o.brandAssets.themeContext=m,o.updatedAt=Date.now();let y=tt(o.themePath,".vibespot");yn(y)||f(y,{recursive:!0}),h(tt(y,"theme-context.md"),m),D(),e.send(JSON.stringify({type:"brand_asset_extracted",assetType:"themeContext"}))}if(!o.brandAssets?.styleguide)try{let{extractDesignContext:y}=await Promise.resolve().then(()=>(Cs(),ws)),v=await y(o.themePath);if(v){o.brandAssets||(o.brandAssets={}),o.brandAssets.styleguide=v,o.updatedAt=Date.now();let C=tt(o.themePath,".vibespot");yn(C)||f(C,{recursive:!0}),h(tt(C,"styleguide.md"),v),D(),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=S();if(!o){e.send(JSON.stringify({type:"error",message:"No active session"}));break}try{lt();let i=zn(o.themePath);if(i.length>0&&e.send(JSON.stringify({type:"upload_status",phase:"autofix",fixes:i})),(_().hubspotUploadMode||"api")==="api"){let l=he();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 qn(l,o.themePath,o.themeName,{onFileStart:d=>{e.send(JSON.stringify({type:"upload_output",chunk:`Uploading ${d}
1518
1518
  `}))},onFileComplete:d=>{e.send(JSON.stringify({type:"upload_output",chunk:` \u2713 ${d}
1519
1519
  `}))},onFileError:(d,u)=>{e.send(JSON.stringify({type:"upload_output",chunk:` \u2717 ${d}: ${u.message}
1520
- `}))},onProgress:(d,u)=>{e.send(JSON.stringify({type:"upload_progress",completed:d,total:u}))}});if(c.success){let d=nt();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=Kn(c.errors);e.send(JSON.stringify({type:"upload_failed",output:c.errors.map(u=>`${u.file}: ${u.message}`).join(`
1521
- `),errors:d}))}}else{let l=hs(`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}))};xa(l,c);let d=setInterval(()=>{let u=gs(l);if(!(!u||u.status==="running"))if(clearInterval(d),wa(l,c),u.status==="completed"){let m=je(),f=m.portalId?Wt(m.portalId):"na1";e.send(JSON.stringify({type:"upload_complete",output:u.output,portalId:m.portalId||"",dataCenter:f,themeName:o.themeName}))}else{let m=Yn(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.
1520
+ `}))},onProgress:(d,u)=>{e.send(JSON.stringify({type:"upload_progress",completed:d,total:u}))}});if(c.success){let d=st();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=Kn(c.errors);e.send(JSON.stringify({type:"upload_failed",output:c.errors.map(u=>`${u.file}: ${u.message}`).join(`
1521
+ `),errors:d}))}}else{let l=hs(`hs cms upload "${o.themePath}" "${o.themeName}"`,"Uploading to HubSpot",{cwd:tt(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}))};wa(l,c);let d=setInterval(()=>{let u=gs(l);if(!(!u||u.status==="running"))if(clearInterval(d),Ca(l,c),u.status==="completed"){let m=je(),f=m.portalId?Wt(m.portalId):"na1";e.send(JSON.stringify({type:"upload_complete",output:u.output,portalId:m.portalId||"",dataCenter:f,themeName:o.themeName}))}else{let m=Yn(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.
1522
1522
 
1523
1523
  IMPORTANT: Be verbose in your response. For each error:
1524
1524
  1. State exactly which file has the problem and what the error is
@@ -1531,9 +1531,9 @@ CRITICAL: After fixing the reported errors, scan ALL other module files in the t
1531
1531
  After fixing all errors, summarize the changes you made.
1532
1532
 
1533
1533
  Upload log:
1534
- ${o}`;it("user",i),D(),e.send(JSON.stringify({type:"upload_fix_started"}));try{await pn(i,r=>{e.send(JSON.stringify({type:"stream",content:r})),e.send(JSON.stringify({type:"upload_fix_stream",content:r}))});let a=S();if(a){at();let r=Ks(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:me().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;default:e.send(JSON.stringify({type:"error",message:`Unknown type: ${s.type}`}))}});let t=S();if(t){let n=_(),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=Ce();e.send(JSON.stringify({type:"init",sessionId:t.id,themeName:t.themeName,modules:me().map(i=>i.moduleName),messageCount:t.messages.length,messages:t.messages,gitAvailable:_e(),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}))}))}else e.send(JSON.stringify({type:"needs_setup"}))}function Yu(e,t){let n=S();if(!n){t.writeHead(404,{"Content-Type":"text/plain"}),t.end("No session");return}let s=dt(n.themePath,"assets",e);if(!yn(s)){t.writeHead(404,{"Content-Type":"text/plain"}),t.end("Asset not found");return}let o=El(s),i=_l[o]||"application/octet-stream",a=Go(s);t.writeHead(200,{"Content-Type":i,"Cache-Control":"no-cache"}),t.end(a)}var $l=new Map;function zu(e,t,n,s){let i=dt(t,e==="/"?"/index.html":e);if(!yn(i)){let c=dt(t,"index.html");if(yn(c)){let d=Go(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=El(i),r=_l[a]||"application/octet-stream",l=a===".html";try{let c=$l.get(i);if(!c){let u=Go(i),m='"'+Uu("md5").update(u).digest("hex").slice(0,16)+'"';c={buffer:u,etag:m,contentType:r},$l.set(i,c)}if(n.headers["if-none-match"]===c.etag){s.writeHead(304),s.end();return}s.writeHead(200,{"Content-Type":c.contentType,"Cache-Control":l?"no-cache":"public, max-age=3600",ETag:c.etag}),s.end(c.buffer)}catch{s.writeHead(500,{"Content-Type":"text/plain"}),s.end("Internal Server Error")}}Se();var Xu=4200;async function Ol(){let e=Is.hex("#e8613a"),t=Is.dim;console.log(""),console.log(e(" v vibeSpot")),console.log(t(` Starting...
1535
- `));let n=Qu();n||(console.error(Is.red(" Could not find UI assets. Is the package installed correctly?")),process.exit(1));try{let{port:s,close:o}=await Pl({port:Xu,uiDir:n}),i=`http://localhost:${s}`;console.log(e(` v ${i}`)),console.log(t(` Press Ctrl+C to stop
1534
+ ${o}`;rt("user",i),D(),e.send(JSON.stringify({type:"upload_fix_started"}));try{await pn(i,r=>{e.send(JSON.stringify({type:"stream",content:r})),e.send(JSON.stringify({type:"upload_fix_stream",content:r}))});let a=S();if(a){lt();let r=Ks(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:me().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;default:e.send(JSON.stringify({type:"error",message:`Unknown type: ${s.type}`}))}});let t=S();if(t){let n=_(),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=Ce();e.send(JSON.stringify({type:"init",sessionId:t.id,themeName:t.themeName,modules:me().map(i=>i.moduleName),messageCount:t.messages.length,messages:t.messages,gitAvailable:_e(),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}))}))}else e.send(JSON.stringify({type:"needs_setup"}))}function Qu(e,t){let n=S();if(!n){t.writeHead(404,{"Content-Type":"text/plain"}),t.end("No session");return}let s=tt(n.themePath,"assets",e);if(!yn(s)){t.writeHead(404,{"Content-Type":"text/plain"}),t.end("Asset not found");return}let o=_l(s),i=Pl[o]||"application/octet-stream",a=Go(s);t.writeHead(200,{"Content-Type":i,"Cache-Control":"no-cache"}),t.end(a)}function El(e,t,n,s){let i=tt(t,e==="/"?"/index.html":e);if(!yn(i)){let c=tt(t,"index.html");if(yn(c)){let d=Go(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=_l(i),r=Pl[a]||"application/octet-stream",l=a===".html";try{let c=Go(i),d='"'+Ku("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")}}Se();var em=4200;async function Ol(){let e=Is.hex("#e8613a"),t=Is.dim;console.log(""),console.log(e(" v vibeSpot")),console.log(t(` Starting...
1535
+ `));let n=tm();n||(console.error(Is.red(" Could not find UI assets. Is the package installed correctly?")),process.exit(1));try{let{port:s,close:o}=await Ml({port:em,uiDir:n}),i=`http://localhost:${s}`;console.log(e(` v ${i}`)),console.log(t(` Press Ctrl+C to stop
1536
1536
  `));try{process.platform==="darwin"?Uo("open",[i],{stdio:"ignore"}):process.platform==="win32"?Uo("cmd",["/c","start","",i],{stdio:"ignore"}):Uo("xdg-open",[i],{stdio:"ignore"})}catch{}await new Promise(a=>{process.on("SIGINT",()=>{console.log(t(`
1537
1537
  Saving session...`)),D(),o(),console.log(t(` Goodbye!
1538
- `)),a(),setTimeout(()=>process.exit(0),500)})})}catch(s){console.error(Is.red(` Failed to start: ${s instanceof Error?s.message:String(s)}`)),process.exit(1)}}function Qu(){let e=[ks(import.meta.dirname,"../../ui"),ks(import.meta.dirname,"../ui"),ks(process.cwd(),"ui")];for(let t of e)if(qu(ks(t,"index.html")))return t;return null}Q();function Ml(){let e=new Zu;return e.name("vibespot").description("AI-powered HubSpot CMS landing page builder").version(wt()).action(Ol),e.command("wizard").description("Classic CLI wizard \u2014 step-by-step conversion flow").action(Ji),e.command("init").description("Check and install required tools").action(Di),e.command("convert").description("Convert a React project to HubSpot modules").action(Hi),e.command("upload").description("Upload theme to HubSpot").action(Li),e.command("doctor").description("Diagnose environment issues").action(Gi),e}var em=Ml();em.parseAsync(process.argv).catch(e=>{console.error(e),process.exit(1)});
1538
+ `)),a(),setTimeout(()=>process.exit(0),500)})})}catch(s){console.error(Is.red(` Failed to start: ${s instanceof Error?s.message:String(s)}`)),process.exit(1)}}function tm(){let e=[ks(import.meta.dirname,"../../ui"),ks(import.meta.dirname,"../ui"),ks(process.cwd(),"ui")];for(let t of e)if(Zu(ks(t,"index.html")))return t;return null}Q();function Nl(){let e=new nm;return e.name("vibespot").description("AI-powered HubSpot CMS landing page builder").version(wt()).action(Ol),e.command("wizard").description("Classic CLI wizard \u2014 step-by-step conversion flow").action(Ji),e.command("init").description("Check and install required tools").action(Di),e.command("convert").description("Convert a React project to HubSpot modules").action(Hi),e.command("upload").description("Upload theme to HubSpot").action(Li),e.command("doctor").description("Diagnose environment issues").action(Gi),e}var sm=Nl();sm.parseAsync(process.argv).catch(e=>{console.error(e),process.exit(1)});
1539
1539
  //# sourceMappingURL=index.js.map