klaudius 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bin.js +5 -5
  2. package/package.json +1 -1
package/dist/bin.js CHANGED
@@ -8,15 +8,15 @@ Please share that file so we can trace what happened.`);return n}function z(e){l
8
8
  `,o=["","# "+"=".repeat(60),"# Backfilled by `klaudius update` (new template env keys)","# "+"=".repeat(60)];for(let l of n)o.push(""),l.comment&&o.push(`# ${l.comment}`),o.push(it(l.key,l.value));return e+r+o.join(`
9
9
  `)+`
10
10
  `}function ot(e){return e.length>=2&&e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1).replace(/\\\\/g,"\\").replace(/\\"/g,'"').replace(/\\\$/g,"$").replace(/\\`/g,"`"):e.length>=2&&e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1):e}function O(e){let s={};for(let t of e.split(`
11
- `)){let n=t.trim();if(!n||n.startsWith("#"))continue;let r=n.indexOf("=");if(r===-1)continue;let o=n.slice(0,r).trim(),l=ot(n.slice(r+1).trim());s[o]=l}return s}function ye(e){let s=o=>{let l=e[o];if(!l)return;let c=parseInt(l,10);return isNaN(c)?void 0:c},t=e.SMS_PROVIDER,n=e.OUTREACH_CHANNELS?.split(",").map(o=>o.trim()).filter(o=>o==="email"||o==="sms"),r=e.OUTREACH_PRIORITY;return{licenseKey:e.KLAUDIUS_LICENSE_KEY,pricing:e.PRICING,pricingTerms:e.PRICING_TERMS,pricingMonthly:e.PRICING_MONTHLY||void 0,outreachEnabled:e.OUTREACH_ENABLED?e.OUTREACH_ENABLED.toLowerCase()==="true":void 0,name:e.OPERATOR_NAME,signature:e.SIGNATURE,outreachChannels:n&&n.length>0?n:void 0,outreachPriority:r==="email"||r==="sms"?r:void 0,emailAddress:e.EMAIL_ADDRESS,emailFromName:e.EMAIL_FROM_NAME,emailSmtpHost:e.EMAIL_SMTP_HOST,emailSmtpPort:s("EMAIL_SMTP_PORT"),emailImapHost:e.EMAIL_IMAP_HOST,emailImapPort:s("EMAIL_IMAP_PORT"),emailSentFolder:e.EMAIL_SENT_FOLDER,emailInboxFolder:e.EMAIL_INBOX_FOLDER,smsProvider:t==="imessage"||t==="twilio"?t:void 0,testPhone:e.TEST_PHONE,twilioAccountSid:e.TWILIO_ACCOUNT_SID,twilioPhoneNumber:e.TWILIO_PHONE_NUMBER,twilioAuthToken:e.TWILIO_AUTH_TOKEN,supabaseUrl:e.SUPABASE_URL,supabaseProjectRef:e.SUPABASE_PROJECT_REF,supabaseServiceKey:e.SUPABASE_SERVICE_KEY,supabasePat:e.SUPABASE_PAT,vercelToken:e.VERCEL_TOKEN,vercelScope:e.VERCEL_SCOPE||void 0,googlePlacesApiKey:e.GOOGLE_PLACES_API_KEY,serpapiKey:e.SERPAPI_KEY,emailPassword:e.EMAIL_PASSWORD,telegramBotToken:e.TELEGRAM_BOT_TOKEN,telegramChatId:e.TELEGRAM_CHAT_ID}}function ae(e){let s=P=>{let w=e[P];if(!w)return;let _=parseInt(w,10);return isNaN(_)?void 0:_},t=e.SUPABASE_URL,n=e.SUPABASE_SERVICE_KEY,r=e.SUPABASE_PAT,o=e.SUPABASE_PROJECT_REF,l=e.PRICING,c=e.PRICING_TERMS||"one-off, no monthly fees",m=e.VERCEL_TOKEN;if(!l||!t||!n||!r||!o||!m)return null;let a=e.SMS_PROVIDER,k=e.OUTREACH_CHANNELS?.split(",").map(P=>P.trim()).filter(P=>P==="email"||P==="sms"),E=e.OUTREACH_PRIORITY;return{licenseKey:e.KLAUDIUS_LICENSE_KEY,pricing:l,pricingTerms:c,pricingMonthly:e.PRICING_MONTHLY||void 0,outreachEnabled:e.OUTREACH_ENABLED?.toLowerCase()==="true",name:e.OPERATOR_NAME,signature:e.SIGNATURE,outreachChannels:k&&k.length>0?k:void 0,outreachPriority:E==="email"||E==="sms"?E:void 0,emailAddress:e.EMAIL_ADDRESS,emailPassword:e.EMAIL_PASSWORD,emailFromName:e.EMAIL_FROM_NAME,emailSmtpHost:e.EMAIL_SMTP_HOST,emailSmtpPort:s("EMAIL_SMTP_PORT"),emailImapHost:e.EMAIL_IMAP_HOST,emailImapPort:s("EMAIL_IMAP_PORT"),emailSentFolder:e.EMAIL_SENT_FOLDER,emailInboxFolder:e.EMAIL_INBOX_FOLDER,smsProvider:a==="imessage"||a==="twilio"?a:void 0,testPhone:e.TEST_PHONE,twilioAccountSid:e.TWILIO_ACCOUNT_SID,twilioAuthToken:e.TWILIO_AUTH_TOKEN,twilioPhoneNumber:e.TWILIO_PHONE_NUMBER,vercelToken:m,vercelScope:e.VERCEL_SCOPE||void 0,supabaseUrl:t,supabaseServiceKey:n,supabasePat:r,supabaseProjectRef:o,googlePlacesApiKey:e.GOOGLE_PLACES_API_KEY,serpapiKey:e.SERPAPI_KEY,telegramBotToken:e.TELEGRAM_BOT_TOKEN,telegramChatId:e.TELEGRAM_CHAT_ID}}import{mkdir as rt,rm as at}from"fs/promises";import{Readable as lt}from"stream";import*as Ee from"tar";var ct="https://klaudius.dev/api/template";function dt(e){return lt.fromWeb(e)}async function J(e){let s=process.env.KLAUDIUS_TEMPLATE_URL??ct,t="0.8.0",n;try{n=await fetch(s,{method:"POST",headers:{Authorization:`Bearer ${e.licenseKey}`,"Content-Type":"application/json"},body:JSON.stringify({machine_id:e.machineId,hostname:e.hostname,os:e.os,cli_version:t})})}catch(l){throw new Error(`Could not reach klaudius.dev to download the template: ${R(l)}`)}if(!n.ok){let l="";try{let c=await n.json();l=c.reason?` (${c.reason})`:""}catch{}throw new Error(`Template download failed: HTTP ${n.status}${l}`)}if(!n.body)throw new Error("Template download succeeded but response had no body");let r=n.headers.get("x-klaudius-tier");await rt(e.destDir,{recursive:!0});let o=0;try{await new Promise((l,c)=>{let m=Ee.extract({cwd:e.destDir,strict:!0,onReadEntry:()=>{o++}});m.on("finish",l),m.on("error",c),dt(n.body).on("error",c).pipe(m)})}catch(l){throw await at(e.destDir,{recursive:!0,force:!0}).catch(()=>{}),new Error(`Failed to extract template archive: ${l.message}`)}return{filesExtracted:o,tier:r}}import{mkdir as ut,readFile as pt,writeFile as mt,access as ft}from"fs/promises";import{dirname as ht,join as Pe}from"path";var gt=".klaudius",be=`${gt}/manifest.json`;async function Se(e){let s=Pe(e,be);try{await ft(s)}catch{return null}let t=await pt(s,"utf-8");return JSON.parse(t)}async function X(e,s){let t=Pe(e,be);await ut(ht(t),{recursive:!0}),await mt(t,JSON.stringify(s,null,2)+`
11
+ `)){let n=t.trim();if(!n||n.startsWith("#"))continue;let r=n.indexOf("=");if(r===-1)continue;let o=n.slice(0,r).trim(),l=ot(n.slice(r+1).trim());s[o]=l}return s}function ye(e){let s=o=>{let l=e[o];if(!l)return;let c=parseInt(l,10);return isNaN(c)?void 0:c},t=e.SMS_PROVIDER,n=e.OUTREACH_CHANNELS?.split(",").map(o=>o.trim()).filter(o=>o==="email"||o==="sms"),r=e.OUTREACH_PRIORITY;return{licenseKey:e.KLAUDIUS_LICENSE_KEY,pricing:e.PRICING,pricingTerms:e.PRICING_TERMS,pricingMonthly:e.PRICING_MONTHLY||void 0,outreachEnabled:e.OUTREACH_ENABLED?e.OUTREACH_ENABLED.toLowerCase()==="true":void 0,name:e.OPERATOR_NAME,signature:e.SIGNATURE,outreachChannels:n&&n.length>0?n:void 0,outreachPriority:r==="email"||r==="sms"?r:void 0,emailAddress:e.EMAIL_ADDRESS,emailFromName:e.EMAIL_FROM_NAME,emailSmtpHost:e.EMAIL_SMTP_HOST,emailSmtpPort:s("EMAIL_SMTP_PORT"),emailImapHost:e.EMAIL_IMAP_HOST,emailImapPort:s("EMAIL_IMAP_PORT"),emailSentFolder:e.EMAIL_SENT_FOLDER,emailInboxFolder:e.EMAIL_INBOX_FOLDER,smsProvider:t==="imessage"||t==="twilio"?t:void 0,testPhone:e.TEST_PHONE,twilioAccountSid:e.TWILIO_ACCOUNT_SID,twilioPhoneNumber:e.TWILIO_PHONE_NUMBER,twilioAuthToken:e.TWILIO_AUTH_TOKEN,supabaseUrl:e.SUPABASE_URL,supabaseProjectRef:e.SUPABASE_PROJECT_REF,supabaseServiceKey:e.SUPABASE_SERVICE_KEY,supabasePat:e.SUPABASE_PAT,vercelToken:e.VERCEL_TOKEN,vercelScope:e.VERCEL_SCOPE||void 0,googlePlacesApiKey:e.GOOGLE_PLACES_API_KEY,serpapiKey:e.SERPAPI_KEY,emailPassword:e.EMAIL_PASSWORD,telegramBotToken:e.TELEGRAM_BOT_TOKEN,telegramChatId:e.TELEGRAM_CHAT_ID}}function ae(e){let s=P=>{let w=e[P];if(!w)return;let _=parseInt(w,10);return isNaN(_)?void 0:_},t=e.SUPABASE_URL,n=e.SUPABASE_SERVICE_KEY,r=e.SUPABASE_PAT,o=e.SUPABASE_PROJECT_REF,l=e.PRICING,c=e.PRICING_TERMS||"one-off, no monthly fees",m=e.VERCEL_TOKEN;if(!l||!t||!n||!r||!o||!m)return null;let a=e.SMS_PROVIDER,k=e.OUTREACH_CHANNELS?.split(",").map(P=>P.trim()).filter(P=>P==="email"||P==="sms"),E=e.OUTREACH_PRIORITY;return{licenseKey:e.KLAUDIUS_LICENSE_KEY,pricing:l,pricingTerms:c,pricingMonthly:e.PRICING_MONTHLY||void 0,outreachEnabled:e.OUTREACH_ENABLED?.toLowerCase()==="true",name:e.OPERATOR_NAME,signature:e.SIGNATURE,outreachChannels:k&&k.length>0?k:void 0,outreachPriority:E==="email"||E==="sms"?E:void 0,emailAddress:e.EMAIL_ADDRESS,emailPassword:e.EMAIL_PASSWORD,emailFromName:e.EMAIL_FROM_NAME,emailSmtpHost:e.EMAIL_SMTP_HOST,emailSmtpPort:s("EMAIL_SMTP_PORT"),emailImapHost:e.EMAIL_IMAP_HOST,emailImapPort:s("EMAIL_IMAP_PORT"),emailSentFolder:e.EMAIL_SENT_FOLDER,emailInboxFolder:e.EMAIL_INBOX_FOLDER,smsProvider:a==="imessage"||a==="twilio"?a:void 0,testPhone:e.TEST_PHONE,twilioAccountSid:e.TWILIO_ACCOUNT_SID,twilioAuthToken:e.TWILIO_AUTH_TOKEN,twilioPhoneNumber:e.TWILIO_PHONE_NUMBER,vercelToken:m,vercelScope:e.VERCEL_SCOPE||void 0,supabaseUrl:t,supabaseServiceKey:n,supabasePat:r,supabaseProjectRef:o,googlePlacesApiKey:e.GOOGLE_PLACES_API_KEY,serpapiKey:e.SERPAPI_KEY,telegramBotToken:e.TELEGRAM_BOT_TOKEN,telegramChatId:e.TELEGRAM_CHAT_ID}}import{mkdir as rt,rm as at}from"fs/promises";import{Readable as lt}from"stream";import*as Ee from"tar";var ct="https://klaudius.dev/api/template";function dt(e){return lt.fromWeb(e)}async function J(e){let s=process.env.KLAUDIUS_TEMPLATE_URL??ct,t="0.9.1",n;try{n=await fetch(s,{method:"POST",headers:{Authorization:`Bearer ${e.licenseKey}`,"Content-Type":"application/json"},body:JSON.stringify({machine_id:e.machineId,hostname:e.hostname,os:e.os,cli_version:t})})}catch(l){throw new Error(`Could not reach klaudius.dev to download the template: ${R(l)}`)}if(!n.ok){let l="";try{let c=await n.json();l=c.reason?` (${c.reason})`:""}catch{}throw new Error(`Template download failed: HTTP ${n.status}${l}`)}if(!n.body)throw new Error("Template download succeeded but response had no body");let r=n.headers.get("x-klaudius-tier");await rt(e.destDir,{recursive:!0});let o=0;try{await new Promise((l,c)=>{let m=Ee.extract({cwd:e.destDir,strict:!0,onReadEntry:()=>{o++}});m.on("finish",l),m.on("error",c),dt(n.body).on("error",c).pipe(m)})}catch(l){throw await at(e.destDir,{recursive:!0,force:!0}).catch(()=>{}),new Error(`Failed to extract template archive: ${l.message}`)}return{filesExtracted:o,tier:r}}import{mkdir as ut,readFile as pt,writeFile as mt,access as ft}from"fs/promises";import{dirname as ht,join as Pe}from"path";var gt=".klaudius",be=`${gt}/manifest.json`;async function Se(e){let s=Pe(e,be);try{await ft(s)}catch{return null}let t=await pt(s,"utf-8");return JSON.parse(t)}async function X(e,s){let t=Pe(e,be);await ut(ht(t),{recursive:!0}),await mt(t,JSON.stringify(s,null,2)+`
12
12
  `,"utf-8")}function _e(e,s){let t=new Date().toISOString();return{version:1,templateVersion:e,installedAt:t,updatedAt:t,files:s}}import{createHash as kt}from"crypto";import{hostname as Te,userInfo as wt,platform as Ae,arch as Ie}from"os";import x from"picocolors";var i={info:e=>console.log(x.cyan("\u2139"),e),success:e=>console.log(x.green("\u2713"),e),warn:e=>console.log(x.yellow("\u26A0"),e),error:e=>console.error(x.red("\u2717"),e),step:e=>console.log(x.dim("\u2192"),e),blank:()=>console.log(""),heading:e=>console.log(`
13
- `+x.bold(x.cyan(e))),detail:e=>console.log(x.dim(" "+e))};var yt="https://klaudius.dev",Et="/api/licenses/validate",Pt="0.8.0";async function Re(e){if(!e||e.trim().length===0)return{ok:!1,reason:"No license key provided. Pass one via --license <key> or paste it when prompted."};let s=e.trim(),n=(process.env.KLAUDIUS_API_URL??yt).replace(/\/$/,"")+Et,r=F(),o;try{o=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({license_key:s,machine_id:r,hostname:Te(),os:`${Ae()}-${Ie()}`,cli_version:Pt})})}catch(c){return{ok:!1,reason:`Could not reach the Klaudius license server (${R(c)}). Check your internet connection or try again later.`}}let l;try{l=await o.json()}catch{return{ok:!1,reason:`License server returned an unparseable response (HTTP ${o.status}).`}}return l.ok?{ok:!0,tier:l.tier??"core"}:{ok:!1,reason:l.reason??`License rejected (HTTP ${o.status}).`}}function F(){let e=[Te(),wt().username,Ae(),Ie()].join("|");return kt("sha256").update(e).digest("hex").slice(0,32)}import{readFile as bt}from"fs/promises";import{join as St}from"path";async function D(e){try{let s=await fetch(e.url+"/rest/v1/",{headers:{apikey:e.serviceKey,Authorization:`Bearer ${e.serviceKey}`}});return s.status===401||s.status===403?{ok:!1,message:`Supabase rejected auth (HTTP ${s.status}). Check SUPABASE_SERVICE_KEY.`}:{ok:!0}}catch(s){return{ok:!1,message:`Could not reach Supabase: ${R(s)}`}}}async function ve(e){let s;try{s=await bt(St(e.projectRoot,"scripts","schema.sql"),"utf-8")}catch(t){return{ok:!1,message:`Could not read scripts/schema.sql: ${t.message}`}}try{let t=await fetch(`https://api.supabase.com/v1/projects/${e.projectRef}/database/query`,{method:"POST",headers:{Authorization:`Bearer ${e.pat}`,"Content-Type":"application/json"},body:JSON.stringify({query:s})});if(t.ok)return{ok:!0};let n=await t.text();return n.includes("already exists")||n.includes('relation "clients" already exists')||n.includes("duplicate")?(i.detail("Schema appears already applied (tables exist). Skipping."),{ok:!0}):{ok:!1,message:`Supabase Management API rejected schema (HTTP ${t.status}): ${n.slice(0,300)}`}}catch(t){return{ok:!1,message:`Schema apply failed: ${t.message}`}}}async function Q(e){try{let s=await fetch("https://api.vercel.com/v2/user",{headers:{Authorization:`Bearer ${e}`}});if(s.status===401||s.status===403)return{ok:!1,message:`Vercel rejected the token (HTTP ${s.status}). The token is invalid, expired, or has been revoked.`};if(!s.ok)return{ok:!1,message:`Vercel API returned HTTP ${s.status}. Try again or check status.vercel.com.`};let t=await s.json();return{ok:!0,username:t.user?.username??t.user?.email}}catch(s){return{ok:!1,message:`Could not reach Vercel: ${R(s)}`}}}async function Z(e){try{let s=await fetch("https://places.googleapis.com/v1/places:searchText",{method:"POST",headers:{"Content-Type":"application/json","X-Goog-Api-Key":e,"X-Goog-FieldMask":"places.id"},body:JSON.stringify({textQuery:"x"})});if(s.ok)return{ok:!0};if(s.status===429)return{ok:!0};let t={};try{t=await s.json()}catch{}let n=t.error?.message??"",r=t.error?.status??"";return s.status===400&&(r==="PERMISSION_DENIED"||/Places API \(New\) has not been enabled|API_KEY_SERVICE_BLOCKED/i.test(n))?{ok:!1,message:"Key is valid, but Places API (New) is not enabled on its Cloud project. Open https://console.cloud.google.com/apis/library and enable 'Places API (New)' for the project this key belongs to, then try again."}:s.status===401||s.status===403?{ok:!1,message:n||`Google rejected the key (HTTP ${s.status}). Common causes: invalid key, billing not enabled on the Cloud project, or API key restrictions blocking this caller.`}:{ok:!1,message:`Google API returned HTTP ${s.status}${n?`: ${n}`:""}.`}}catch(s){return{ok:!1,message:`Could not reach Google: ${R(s)}`}}}import _t from"nodemailer";import{ImapFlow as Tt}from"imapflow";async function Oe(e){let s=_t.createTransport({host:e.emailSmtpHost,port:e.emailSmtpPort,secure:e.emailSmtpPort===465,auth:{user:e.emailAddress,pass:e.emailPassword},connectionTimeout:1e4,greetingTimeout:5e3,socketTimeout:1e4});try{await s.verify()}catch(n){return{ok:!1,failedAt:"smtp",message:Ce(n,"SMTP")}}finally{s.close()}let t=new Tt({host:e.emailImapHost,port:e.emailImapPort,secure:e.emailImapPort===993,auth:{user:e.emailAddress,pass:e.emailPassword},logger:!1});try{await t.connect(),await t.logout()}catch(n){try{await t.logout()}catch{}return{ok:!1,failedAt:"imap",message:Ce(n,"IMAP")}}return{ok:!0}}function Ce(e,s){let t=e instanceof Error?e.message:String(e),n=t.toLowerCase();return n.includes("invalid credentials")||n.includes("authentication failed")||n.includes("auth failed")||n.includes("login failed")?`${s} rejected the credentials. Most common causes:
13
+ `+x.bold(x.cyan(e))),detail:e=>console.log(x.dim(" "+e))};var yt="https://klaudius.dev",Et="/api/licenses/validate",Pt="0.9.1";async function Re(e){if(!e||e.trim().length===0)return{ok:!1,reason:"No license key provided. Pass one via --license <key> or paste it when prompted."};let s=e.trim(),n=(process.env.KLAUDIUS_API_URL??yt).replace(/\/$/,"")+Et,r=F(),o;try{o=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({license_key:s,machine_id:r,hostname:Te(),os:`${Ae()}-${Ie()}`,cli_version:Pt})})}catch(c){return{ok:!1,reason:`Could not reach the Klaudius license server (${R(c)}). Check your internet connection or try again later.`}}let l;try{l=await o.json()}catch{return{ok:!1,reason:`License server returned an unparseable response (HTTP ${o.status}).`}}return l.ok?{ok:!0,tier:l.tier??"core"}:{ok:!1,reason:l.reason??`License rejected (HTTP ${o.status}).`}}function F(){let e=[Te(),wt().username,Ae(),Ie()].join("|");return kt("sha256").update(e).digest("hex").slice(0,32)}import{readFile as bt}from"fs/promises";import{join as St}from"path";async function D(e){try{let s=await fetch(e.url+"/rest/v1/",{headers:{apikey:e.serviceKey,Authorization:`Bearer ${e.serviceKey}`}});return s.status===401||s.status===403?{ok:!1,message:`Supabase rejected auth (HTTP ${s.status}). Check SUPABASE_SERVICE_KEY.`}:{ok:!0}}catch(s){return{ok:!1,message:`Could not reach Supabase: ${R(s)}`}}}async function ve(e){let s;try{s=await bt(St(e.projectRoot,"scripts","schema.sql"),"utf-8")}catch(t){return{ok:!1,message:`Could not read scripts/schema.sql: ${t.message}`}}try{let t=await fetch(`https://api.supabase.com/v1/projects/${e.projectRef}/database/query`,{method:"POST",headers:{Authorization:`Bearer ${e.pat}`,"Content-Type":"application/json"},body:JSON.stringify({query:s})});if(t.ok)return{ok:!0};let n=await t.text();return n.includes("already exists")||n.includes('relation "clients" already exists')||n.includes("duplicate")?(i.detail("Schema appears already applied (tables exist). Skipping."),{ok:!0}):{ok:!1,message:`Supabase Management API rejected schema (HTTP ${t.status}): ${n.slice(0,300)}`}}catch(t){return{ok:!1,message:`Schema apply failed: ${t.message}`}}}async function Q(e){try{let s=await fetch("https://api.vercel.com/v2/user",{headers:{Authorization:`Bearer ${e}`}});if(s.status===401||s.status===403)return{ok:!1,message:`Vercel rejected the token (HTTP ${s.status}). The token is invalid, expired, or has been revoked.`};if(!s.ok)return{ok:!1,message:`Vercel API returned HTTP ${s.status}. Try again or check status.vercel.com.`};let t=await s.json();return{ok:!0,username:t.user?.username??t.user?.email}}catch(s){return{ok:!1,message:`Could not reach Vercel: ${R(s)}`}}}async function Z(e){try{let s=await fetch("https://places.googleapis.com/v1/places:searchText",{method:"POST",headers:{"Content-Type":"application/json","X-Goog-Api-Key":e,"X-Goog-FieldMask":"places.id"},body:JSON.stringify({textQuery:"x"})});if(s.ok)return{ok:!0};if(s.status===429)return{ok:!0};let t={};try{t=await s.json()}catch{}let n=t.error?.message??"",r=t.error?.status??"";return s.status===400&&(r==="PERMISSION_DENIED"||/Places API \(New\) has not been enabled|API_KEY_SERVICE_BLOCKED/i.test(n))?{ok:!1,message:"Key is valid, but Places API (New) is not enabled on its Cloud project. Open https://console.cloud.google.com/apis/library and enable 'Places API (New)' for the project this key belongs to, then try again."}:s.status===401||s.status===403?{ok:!1,message:n||`Google rejected the key (HTTP ${s.status}). Common causes: invalid key, billing not enabled on the Cloud project, or API key restrictions blocking this caller.`}:{ok:!1,message:`Google API returned HTTP ${s.status}${n?`: ${n}`:""}.`}}catch(s){return{ok:!1,message:`Could not reach Google: ${R(s)}`}}}import _t from"nodemailer";import{ImapFlow as Tt}from"imapflow";async function Oe(e){let s=_t.createTransport({host:e.emailSmtpHost,port:e.emailSmtpPort,secure:e.emailSmtpPort===465,auth:{user:e.emailAddress,pass:e.emailPassword},connectionTimeout:1e4,greetingTimeout:5e3,socketTimeout:1e4});try{await s.verify()}catch(n){return{ok:!1,failedAt:"smtp",message:Ce(n,"SMTP")}}finally{s.close()}let t=new Tt({host:e.emailImapHost,port:e.emailImapPort,secure:e.emailImapPort===993,auth:{user:e.emailAddress,pass:e.emailPassword},logger:!1});try{await t.connect(),await t.logout()}catch(n){try{await t.logout()}catch{}return{ok:!1,failedAt:"imap",message:Ce(n,"IMAP")}}return{ok:!0}}function Ce(e,s){let t=e instanceof Error?e.message:String(e),n=t.toLowerCase();return n.includes("invalid credentials")||n.includes("authentication failed")||n.includes("auth failed")||n.includes("login failed")?`${s} rejected the credentials. Most common causes:
14
14
  \u2022 The app password is wrong, expired, or for a different provider.
15
15
  \u2022 The email address doesn't match the account that issued the password.
16
16
  \u2022 2FA is required but no app-specific password was generated.`:n.includes("etimedout")||n.includes("timeout")?`${s} server didn't respond in time. Check the host/port, or your network.`:n.includes("enotfound")||n.includes("getaddrinfo")?`${s} host could not be resolved. Check the host setting.`:`${s} check failed: ${t}`}async function $e(e){if(!e.accountSid||!e.authToken)return{ok:!1,message:"Missing Twilio Account SID or Auth Token."};let s=`https://api.twilio.com/2010-04-01/Accounts/${encodeURIComponent(e.accountSid)}.json`,t=Buffer.from(`${e.accountSid}:${e.authToken}`).toString("base64");try{let n=await fetch(s,{headers:{Authorization:`Basic ${t}`}});if(n.status===401)return{ok:!1,message:"Twilio rejected the credentials (401). Check the Account SID and Auth Token from https://console.twilio.com/ \u2014 the Auth Token shown there is the value to paste."};if(!n.ok)return{ok:!1,message:`Twilio API returned HTTP ${n.status}. Try again or check status.twilio.com.`};let r=await n.json();return r.status&&r.status!=="active"?{ok:!1,message:`Twilio account is in '${r.status}' state. Check the console for any holds before sending SMS.`}:{ok:!0,friendlyName:r.friendly_name}}catch(n){return{ok:!1,message:`Could not reach Twilio: ${R(n)}`}}}import{spawn as At}from"child_process";async function Ne(e){if(process.platform!=="darwin")return{ok:!1,message:"iMessage send is only supported on macOS. To run init from a non-Mac, switch the SMS provider to Twilio in the wizard."};let t=`tell application "Messages" to send "Klaudius connected (setup ping; ignore)." to buddy "${e.testPhone.replace(/"/g,"")}"`,n=await It(t);if(n.code===0)return{ok:!0};let r=n.stderr.toLowerCase();return r.includes("can't get application")||r.includes("isn't running")||r.includes("can't make some data")?{ok:!1,message:"Messages.app didn't respond. Open Messages on your Mac and sign in with your Apple ID, then retry."}:r.includes("(-1728)")||r.includes("not found")||r.includes("buddy")?{ok:!1,message:`Couldn't reach ${e.testPhone}. Either the number format is wrong (use the international format with a leading +) or this Mac doesn't have a path to that number. If TEST_PHONE is a non-Apple phone (Android), you need an iPhone signed into the same Apple ID with Settings \u2192 Messages \u2192 Text Message Forwarding turned ON for this Mac.`}:r.includes("(-1719)")||r.includes("(-25006)")?{ok:!1,message:"Messages.app refused the send \u2014 usually means iMessage isn't configured on this Mac. Open Messages \u2192 Settings \u2192 iMessage and sign in with your Apple ID."}:{ok:!1,message:`osascript error: ${n.stderr.trim()||`exit code ${n.code}`}`}}function It(e){return new Promise(s=>{let t=At("osascript",["-e",e],{stdio:["ignore","ignore","pipe"]}),n="";t.stderr.on("data",r=>{n+=r.toString()}),t.on("close",r=>s({code:r??1,stderr:n})),t.on("error",r=>s({code:1,stderr:r.message}))})}import{spawn as xe}from"child_process";function Rt(){let e=process.env.NODE_OPTIONS?.trim(),s=e?`${e} --use-system-ca`:"--use-system-ca";return{...process.env,NODE_OPTIONS:s}}var K=2,Me=2e3,vt=[/ECONNRESET/,/ETIMEDOUT/,/ENOTFOUND/,/EAI_AGAIN/,/socket hang up/i,/Connection reset/i,/network timeout/i,/could not resolve host/i];function Le(e,s){let t=e+`
17
17
  `+s;return vt.some(n=>n.test(t))}function Ue(e){return new Promise(s=>setTimeout(s,e))}function Ct(e,s,t){return new Promise(n=>{let r=xe(e,s,{cwd:t.cwd,stdio:["ignore","pipe","pipe"],shell:!1,env:t.env??process.env}),o="",l="";r.stdout?.on("data",c=>{let m=c.toString();o+=m,process.stdout.write(m)}),r.stderr?.on("data",c=>{let m=c.toString();l+=m,process.stderr.write(m)}),r.on("close",c=>n({code:c??1,stdout:o,stderr:l})),r.on("error",c=>n({code:1,stdout:o,stderr:l+c.message}))})}async function le(e,s,t){let n={code:0,stdout:"",stderr:""};for(let r=0;r<=K;r++){if(n=await Ct(e,s,{cwd:t.cwd,env:t.env}),n.code===0||!Le(n.stderr,n.stdout))return n;r<K&&(i.detail(`${t.label} failed with a transient network error \u2014 retrying (${r+2}/${K+1})\u2026`),await Ue(Me))}return n}function Ot(e,s,t){return new Promise(n=>{let r=xe(e,s,{cwd:t.cwd,stdio:["ignore","pipe","pipe"],shell:!1}),o="",l="";r.stdout?.on("data",c=>{o+=c.toString()}),r.stderr?.on("data",c=>{l+=c.toString()}),r.on("close",c=>n({code:c??1,stdout:o,stderr:l})),r.on("error",c=>n({code:1,stdout:o,stderr:l+c.message}))})}var $t=[{pattern:/UNABLE_TO_VERIFY_LEAF_SIGNATURE|unable to verify the first certificate/i,hint:"TLS-handshake error \u2014 your machine appears to be intercepting HTTPS (antivirus, corporate proxy, or VPN re-signing traffic with its own root CA). We work around this with NODE_OPTIONS=--use-system-ca, which needs Node 22.15+. Run `node --version` to verify, upgrade if older, then re-run setup."},{pattern:/Microsoft Visual C\+\+ 14\.0 or greater is required/i,hint:"Python tried to compile a package from source and couldn't find the Microsoft C++ Build Tools. The latest Klaudius pins supabase<2.26 to skip the offending dependency entirely. Update with `npm install -g klaudius@latest` and re-run init \u2014 that should bypass the source build."}];function Nt(e){let s=`${e.stderr??""}
18
18
  ${e.stdout??""}`;return $t.find(n=>n.pattern.test(s))?.hint}async function xt(e){let s=["supabase<2.26","python-dotenv","requests","httpx","Pillow","truststore"],t=["install","--quiet","--user"],n=async o=>{let l={code:0,stdout:"",stderr:""};for(let c=0;c<=K;c++){if(l=await Ot("pip3",o,{cwd:e}),l.code===0||!Le(l.stderr,l.stdout))return l;c<K&&(i.detail(`pip install hit a transient network error \u2014 retrying (${c+2}/${K+1})\u2026`),await Ue(Me))}return l},r=await n([...t,"--break-system-packages",...s]);return r.code!==0&&/no such option:.*break-system-packages/i.test(r.stderr)&&(i.detail("Older pip detected; retrying without --break-system-packages"),r=await n([...t,...s])),r.code!==0&&(r.stderr.trim()&&process.stderr.write(r.stderr),r.stdout.trim()&&process.stdout.write(r.stdout)),r}async function De(e){let s={npm:"skipped",pip:"skipped",playwright:"skipped",patchright:"skipped"},t=Rt(),n=(m,a)=>{let k=Nt(a);k&&((s.hints??={})[m]=k)};i.step("Running npm install (Next.js, Playwright JS, etc.)...");let r=await le("npm",["install"],{cwd:e,label:"npm install",env:t});s.npm=r.code===0?"ok":"failed",r.code!==0&&n("npm",r),i.step("Installing Python packages (supabase, dotenv, requests, httpx, Pillow)...");let o=await xt(e);s.pip=o.code===0?"ok":"failed",o.code!==0&&n("pip",o),i.step("Installing Playwright browser (chromium ~200MB; one-time)...");let l=await le("npx",["playwright","install","chromium"],{cwd:e,label:"playwright install",env:t});s.playwright=l.code===0?"ok":"failed",l.code!==0&&n("playwright",l),i.step("Installing Patchright browser (chromium ~200MB; one-time)...");let c=await le("npx",["patchright","install","chromium"],{cwd:e,label:"patchright install",env:t});return s.patchright=c.code===0?"ok":"failed",c.code!==0&&n("patchright",c),s}import{spawn as Mt}from"child_process";var ee=3,ce=10;async function te(){let e=await Lt("python3",["--version"]);if(e.code!==0)return{ok:!1,message:"python3 is not installed (or not on PATH). Install Python 3.10 or newer from https://www.python.org/downloads/macos/ (macOS) or https://www.python.org/downloads/ (other)."};let s=(e.stdout+e.stderr).trim(),t=/Python\s+(\d+)\.(\d+)(?:\.(\d+))?/.exec(s);if(!t)return{ok:!1,message:`Could not parse the python3 version string ("${s}"). Install Python 3.10 or newer from https://www.python.org/downloads/.`};let n=parseInt(t[1],10),r=parseInt(t[2],10),o=t[3]?`${n}.${r}.${t[3]}`:`${n}.${r}`;return n<ee||n===ee&&r<ce?{ok:!1,version:o,major:n,minor:r,message:`Your installed Python is ${o}. Klaudius needs Python ${ee}.${ce} or newer (the pipeline depends on packages that only ship wheels for ${ee}.${ce}+). Install a newer Python from https://www.python.org/downloads/macos/ \u2014 it lives alongside your existing Python, nothing breaks. After installing, close every Terminal window, open a new one, then re-run klaudius.`}:{ok:!0,version:o,major:n,minor:r}}function Lt(e,s){return new Promise(t=>{let n=Mt(e,s,{stdio:["ignore","pipe","pipe"],shell:!1}),r="",o="";n.stdout?.on("data",l=>{r+=l.toString()}),n.stderr?.on("data",l=>{o+=l.toString()}),n.on("close",l=>t({code:l??1,stdout:r,stderr:o})),n.on("error",()=>t({code:1,stdout:r,stderr:o}))})}function se(){let e=process.version,s=/^v(\d+)\.(\d+)\.(\d+)/.exec(e);if(!s)return{ok:!1,message:`Could not parse the Node.js version string ("${e}"). Klaudius requires Node.js 22.15 or newer \u2014 install from https://nodejs.org/.`};let t=parseInt(s[1],10),n=parseInt(s[2],10),r=parseInt(s[3],10),o=`${t}.${n}.${r}`;return t<22||t===22&&n<15?{ok:!1,version:o,major:t,minor:n,message:`Your installed Node.js is ${o}. Klaudius requires Node.js 22.15 or newer (the dependency installer relies on the --use-system-ca flag, which was added in 22.15 to handle Windows machines where antivirus or corporate-proxy software MITMs HTTPS). Install a newer Node.js from https://nodejs.org/ \u2014 after installing, close every Terminal window, open a new one, then re-run klaudius.`}:{ok:!0,version:o,major:t,minor:n}}import{mkdir as Ut,readFile as Dt,writeFile as Kt}from"fs/promises";import{join as Ke}from"path";async function ne(e,s){let t=Ke(e,".claude");await Ut(t,{recursive:!0});let n=Ke(t,"settings.json"),r={};try{let m=await Dt(n,"utf-8"),a=JSON.parse(m);a&&typeof a=="object"&&!Array.isArray(a)&&(r=a)}catch{}let o=r.enabledMcpjsonServers,l=Array.isArray(o)?o.filter(m=>typeof m=="string"):[];l.includes(s)||l.push(s);let c={...r,enabledMcpjsonServers:l};await Kt(n,JSON.stringify(c,null,2)+`
19
- `,"utf-8")}var Bt="0.8.0",A=5;function j(e,s){i.blank(),i.error(`${e} validation failed ${A} times in a row. Pausing setup so you don't get stuck in a loop.`),i.detail(`Last error: ${s}`),i.blank(),i.detail("Your credentials are saved in `.env`. Two ways forward:"),i.detail(" \u2022 Open `.env` in any text editor, fix the value, re-run `klaudius init` and pick Resume."),i.detail(" \u2022 Or email hello@klaudius.dev with the error above and we'll dig in."),i.blank(),process.exit(1)}async function Fe(e){let s=e.target??".",t=Vt(s)?s:Ht(process.cwd(),s),n=await Ft(t);if(n.kind==="scaffolded"){i.blank(),i.warn(`Found an existing Klaudius project at ${d.bold(t)}.`),i.detail("(Your .env and project files are in place.)"),i.blank(),n.nodeModulesMissing?(i.detail("It looks like a previous setup didn't finish installing dependencies."),i.detail("To pick up where it left off, run:"),i.blank(),t!==process.cwd()&&console.log(` ${d.cyan(`cd ${s}`)}`),console.log(` ${d.cyan("bash setup.sh")} ${d.dim("# retries npm + pip + browsers; idempotent")}`),i.blank(),i.detail("Then verify with:"),i.blank(),console.log(` ${d.cyan("npx klaudius doctor")} ${d.dim("# checks Node / Python / installers / credentials")}`),i.blank()):(i.detail("Everything is scaffolded and dependencies look installed."),i.detail("Pick the action you wanted:"),i.blank(),console.log(` ${d.cyan("npx klaudius doctor")} ${d.dim("# verify Node / Python / installers / credentials")}`),console.log(` ${d.cyan("npx klaudius configure")} ${d.dim("# change a credential / API key")}`),console.log(` ${d.cyan("npx klaudius update")} ${d.dim("# pull the latest skills, scripts, lessons")}`),i.blank()),i.detail("If you wanted to start over from scratch, delete this folder and re-run `npx klaudius init`."),i.blank();return}if(n.kind==="occupied"){let u=s===".";i.error("Klaudius needs an empty folder to scaffold into. This directory isn't empty."),i.detail(`Path: ${t}`),i.detail(`Contains: ${n.entries.slice(0,5).join(", ")}${n.entries.length>5?`, \u2026 (+${n.entries.length-5} more)`:""}`),i.blank(),u?(i.detail("Two ways forward:"),i.blank(),i.detail("1. Pass a folder name and Klaudius creates it for you:"),console.log(` ${d.cyan("npx klaudius init my-agency")}`),i.blank(),i.detail("2. Or cd into an empty folder first, then re-run:"),console.log(` ${d.cyan("mkdir my-agency && cd my-agency && npx klaudius init")}`)):(i.detail(`The folder '${s}' already exists and isn't empty.`),i.detail("Either pick a different name:"),console.log(` ${d.cyan(`npx klaudius init ${s}-2`)}`),i.detail("\u2026or delete the existing folder if it's safe to remove.")),process.exit(1)}let r=await Yt(e.license),o=g.spinner();o.start("Validating license");let l=await Re(r);l.ok||(o.stop(`License invalid: ${l.reason??"unknown"}`,2),i.detail("If you believe this is in error, email hello@klaudius.dev with your purchase details."),process.exit(1)),o.stop(`License valid (${l.tier??"core"} tier)`);let c=await te();c.ok||(i.error(c.message??"Python version check failed."),i.blank(),i.detail("Once you've installed Python 3.10+, re-run `klaudius init` in this folder."),process.exit(1));let m=se();m.ok||(i.error(m.message??"Node.js version check failed."),i.blank(),i.detail("Once you've installed Node.js 22.15+, re-run `klaudius init` in this folder."),process.exit(1));let a,k=!1;if(n.kind==="partial")if(await Gt(t)==="resume"){let h=await je(n.envPath,"utf-8"),p=ae(O(h));p?(i.success("Resuming with values from your existing .env"),i.detail("(Skipping the wizard \u2014 edit .env directly if you need to change anything.)"),a=p,k=!0):(i.warn("Existing .env was missing required fields \u2014 starting wizard fresh."),a=await T())}else{let h=await je(n.envPath,"utf-8"),p=ae(O(h));a=await T(p??{})}else a=await T();a.licenseKey=r,await $(t,a),k||(i.success("Saved .env"),i.success("Saved .mcp.json")),i.blank();for(let u=1;;u++){let h=g.spinner();h.start("Validating Supabase credentials");let p=await D({url:a.supabaseUrl,serviceKey:a.supabaseServiceKey});if(p.ok){h.stop("Supabase credentials accepted");break}h.stop(p.message??"Supabase check failed",2),u>=A&&j("Supabase",p.message??"Supabase check failed");let y=p.message??"Supabase check failed";i.blank(),i.warn(`Bouncing you back into the Supabase section so you can fix it in place. (attempt ${u+1} of ${A})`),i.detail("(Press Enter through any field to keep its current value. Ctrl+C to exit.)"),i.blank(),a=await T(a,{onlySection:"supabase",banner:`Supabase rejected your credentials:
19
+ `,"utf-8")}var Bt="0.9.1",A=5;function j(e,s){i.blank(),i.error(`${e} validation failed ${A} times in a row. Pausing setup so you don't get stuck in a loop.`),i.detail(`Last error: ${s}`),i.blank(),i.detail("Your credentials are saved in `.env`. Two ways forward:"),i.detail(" \u2022 Open `.env` in any text editor, fix the value, re-run `klaudius init` and pick Resume."),i.detail(" \u2022 Or email hello@klaudius.dev with the error above and we'll dig in."),i.blank(),process.exit(1)}async function Fe(e){let s=e.target??".",t=Vt(s)?s:Ht(process.cwd(),s),n=await Ft(t);if(n.kind==="scaffolded"){i.blank(),i.warn(`Found an existing Klaudius project at ${d.bold(t)}.`),i.detail("(Your .env and project files are in place.)"),i.blank(),n.nodeModulesMissing?(i.detail("It looks like a previous setup didn't finish installing dependencies."),i.detail("To pick up where it left off, run:"),i.blank(),t!==process.cwd()&&console.log(` ${d.cyan(`cd ${s}`)}`),console.log(` ${d.cyan("bash setup.sh")} ${d.dim("# retries npm + pip + browsers; idempotent")}`),i.blank(),i.detail("Then verify with:"),i.blank(),console.log(` ${d.cyan("npx klaudius doctor")} ${d.dim("# checks Node / Python / installers / credentials")}`),i.blank()):(i.detail("Everything is scaffolded and dependencies look installed."),i.detail("Pick the action you wanted:"),i.blank(),console.log(` ${d.cyan("npx klaudius doctor")} ${d.dim("# verify Node / Python / installers / credentials")}`),console.log(` ${d.cyan("npx klaudius configure")} ${d.dim("# change a credential / API key")}`),console.log(` ${d.cyan("npx klaudius update")} ${d.dim("# pull the latest skills, scripts, lessons")}`),i.blank()),i.detail("If you wanted to start over from scratch, delete this folder and re-run `npx klaudius init`."),i.blank();return}if(n.kind==="occupied"){let u=s===".";i.error("Klaudius needs an empty folder to scaffold into. This directory isn't empty."),i.detail(`Path: ${t}`),i.detail(`Contains: ${n.entries.slice(0,5).join(", ")}${n.entries.length>5?`, \u2026 (+${n.entries.length-5} more)`:""}`),i.blank(),u?(i.detail("Two ways forward:"),i.blank(),i.detail("1. Pass a folder name and Klaudius creates it for you:"),console.log(` ${d.cyan("npx klaudius init my-agency")}`),i.blank(),i.detail("2. Or cd into an empty folder first, then re-run:"),console.log(` ${d.cyan("mkdir my-agency && cd my-agency && npx klaudius init")}`)):(i.detail(`The folder '${s}' already exists and isn't empty.`),i.detail("Either pick a different name:"),console.log(` ${d.cyan(`npx klaudius init ${s}-2`)}`),i.detail("\u2026or delete the existing folder if it's safe to remove.")),process.exit(1)}let r=await Yt(e.license),o=g.spinner();o.start("Validating license");let l=await Re(r);l.ok||(o.stop(`License invalid: ${l.reason??"unknown"}`,2),i.detail("If you believe this is in error, email hello@klaudius.dev with your purchase details."),process.exit(1)),o.stop(`License valid (${l.tier??"core"} tier)`);let c=await te();c.ok||(i.error(c.message??"Python version check failed."),i.blank(),i.detail("Once you've installed Python 3.10+, re-run `klaudius init` in this folder."),process.exit(1));let m=se();m.ok||(i.error(m.message??"Node.js version check failed."),i.blank(),i.detail("Once you've installed Node.js 22.15+, re-run `klaudius init` in this folder."),process.exit(1));let a,k=!1;if(n.kind==="partial")if(await Gt(t)==="resume"){let h=await je(n.envPath,"utf-8"),p=ae(O(h));p?(i.success("Resuming with values from your existing .env"),i.detail("(Skipping the wizard \u2014 edit .env directly if you need to change anything.)"),a=p,k=!0):(i.warn("Existing .env was missing required fields \u2014 starting wizard fresh."),a=await T())}else{let h=await je(n.envPath,"utf-8"),p=ae(O(h));a=await T(p??{})}else a=await T();a.licenseKey=r,await $(t,a),k||(i.success("Saved .env"),i.success("Saved .mcp.json")),i.blank();for(let u=1;;u++){let h=g.spinner();h.start("Validating Supabase credentials");let p=await D({url:a.supabaseUrl,serviceKey:a.supabaseServiceKey});if(p.ok){h.stop("Supabase credentials accepted");break}h.stop(p.message??"Supabase check failed",2),u>=A&&j("Supabase",p.message??"Supabase check failed");let y=p.message??"Supabase check failed";i.blank(),i.warn(`Bouncing you back into the Supabase section so you can fix it in place. (attempt ${u+1} of ${A})`),i.detail("(Press Enter through any field to keep its current value. Ctrl+C to exit.)"),i.blank(),a=await T(a,{onlySection:"supabase",banner:`Supabase rejected your credentials:
20
20
  ${y}
21
21
 
22
22
  Re-enter the URL, secret key, or PAT below. Press Enter on any
@@ -45,7 +45,7 @@ provider to Twilio.`}),await $(t,a)}}if(a.telegramBotToken&&a.telegramChatId){i.
45
45
  ${tt}
46
46
 
47
47
  Re-enter the bot token or chat_id below.
48
- Press Enter on any field to keep its current value.`}),await $(t,a),!a.telegramBotToken||!a.telegramChatId)){i.success("Skipped Telegram. Setup will continue."),h=!0;break}}}i.blank();let E=g.spinner();E.start("Downloading Klaudius template");let P;try{P=(await J({licenseKey:r,machineId:F(),hostname:process.platform==="win32"?process.env.COMPUTERNAME:void 0,os:`${process.platform}-${process.arch}`,destDir:t})).filesExtracted,E.stop(`Downloaded ${P} files into ${d.bold(t)}`)}catch(u){E.stop(u.message,2),i.detail("Your .env / .mcp.json are saved. Re-run init once the issue is resolved to retry the download."),process.exit(1)}await Be(G(t,"clients"),{recursive:!0});let w=await ke(t);await X(t,_e(Bt,w)),i.success("Wrote .klaudius/manifest.json");let _=!1,v="";if(e.skipSchema)i.warn("--skip-schema set; not applying scripts/schema.sql to your Supabase project."),i.detail(`Apply manually later via the SQL editor: ${a.supabaseUrl.replace("https://","https://supabase.com/dashboard/project/"+a.supabaseProjectRef+"/sql/new").replace(a.supabaseProjectRef+".supabase.co","")}`);else{i.blank();let u=g.spinner();u.start("Applying schema to Supabase");let h=await ve({projectRoot:t,pat:a.supabasePat,projectRef:a.supabaseProjectRef});h.ok?u.stop("Schema applied (or already present)"):(u.stop(h.message??"Schema apply failed",2),_=!0,v=`https://supabase.com/dashboard/project/${a.supabaseProjectRef}/sql/new`)}let f=[],b={};if(e.skipInstall)i.warn("--skip-install set; you'll need to run npm install + pip install + playwright/patchright install yourself.");else{i.blank(),i.heading("Installing dependencies");let u=await De(t);i.detail(`npm: ${u.npm}, pip: ${u.pip}, playwright: ${u.playwright}, patchright: ${u.patchright}`),u.npm==="failed"&&f.push("npm"),u.pip==="failed"&&f.push("pip"),u.playwright==="failed"&&f.push("playwright"),u.patchright==="failed"&&f.push("patchright"),b=u.hints??{}}i.blank();let C=[...f,..._?["schema"]:[]];if(C.length>0){g.outro(d.yellow(d.bold(`Setup paused \u2014 ${C.join(", ")} failed.`))),console.log(d.dim("Your credentials and project files are all saved.")),i.blank();for(let[p,y]of Object.entries(b))console.log(d.yellow(`Likely cause of ${p} failure:`)),console.log(d.dim(` ${y}`)),i.blank();console.log(d.dim("To finish, once you've addressed any causes above:")),i.blank(),t!==process.cwd()&&console.log(` ${d.cyan(`cd ${e.target}`)}`),f.length>0&&console.log(` ${d.cyan("bash setup.sh")} ${d.dim("# retry the failing installers")}`),_&&(console.log(d.dim(" Apply scripts/schema.sql in the Supabase SQL editor:")),console.log(` ${d.cyan(v)}`),console.log(d.dim(" Open scripts/schema.sql, copy the contents, paste into the editor, click Run."))),i.blank(),f.includes("pip")&&!b.pip&&(console.log(d.dim("If pip fails again with a build error, check `python3 --version` \u2014 Klaudius needs")),console.log(d.dim("Python 3.10+. Install a newer one from https://www.python.org/downloads/macos/")),console.log(d.dim("and open a fresh Terminal before retrying.")),i.blank());let h=["npm","playwright","patchright"].filter(p=>f.includes(p)&&!b[p]);if(h.length>0){let p=h.length===1?"keeps":"keep";console.log(d.dim(`If ${h.join(" / ")} ${p} failing with network errors (ECONNRESET,`)),console.log(d.dim("ETIMEDOUT, ENOTFOUND), they're transient \u2014 try a different network or your")),console.log(d.dim("phone's hotspot, then re-run `bash setup.sh`.")),i.blank()}console.log(d.dim("For a structured diagnostic of every check (Python / Node / installers / files)")),console.log(d.dim(`run ${d.cyan("klaudius doctor")} in this folder.`)),i.blank(),console.log(d.dim("Stuck? Email hello@klaudius.dev with the last ~20 lines of the install output.")),i.blank();return}g.outro(d.green(d.bold("Project ready."))),console.log(d.dim("Next steps:")),t!==process.cwd()&&console.log(` ${d.cyan(`cd ${e.target}`)}`),console.log(` ${d.cyan("claude")} ${d.dim("# open Claude Code in this project")}`),console.log(` ${d.dim("then ask Claude:")}`),console.log(` ${d.cyan(' "Run the pipeline."')}`),i.blank(),console.log(d.dim("Klaudius ships with sensible defaults for tone, follow-up cadence, pitch")),console.log(d.dim("and more \u2014 but you don't have to live with them. Customise by talking to")),console.log(d.dim("Claude inside this project. Examples you can ask:")),console.log(d.dim(' "Make the outreach more casual."')),console.log(d.dim(' "Change the follow-up cadence to weekly."')),console.log(d.dim(` "Don't pitch businesses with fewer than 5 reviews."`)),console.log(d.dim(' "Use a different opening hook for restaurants."')),console.log(d.dim("Claude knows where to make the change \u2014 no config files to edit by hand.")),i.blank()}async function $(e,s){await Be(e,{recursive:!0}),await Ve(G(e,".env"),z(s),"utf-8"),await Ve(G(e,".mcp.json"),q(s),"utf-8"),await ne(e,"supabase")}async function Ft(e){try{(await He(e)).isDirectory()||(i.error(`Target exists but is not a directory: ${e}`),process.exit(1))}catch{return{kind:"fresh"}}let s=await jt(e),t=s.filter(c=>!c.startsWith(".DS_Store"));if(t.length===0)return{kind:"fresh"};let n=new Set([".env",".mcp.json",".claude"]),r=t.every(c=>n.has(c)),o=t.includes(".env"),l=s.includes(".klaudius");if(r&&o&&!l)return{kind:"partial",envPath:G(e,".env")};if(l&&o){let c=!0;try{c=!(await He(G(e,"node_modules"))).isDirectory()}catch{c=!0}return{kind:"scaffolded",nodeModulesMissing:c}}return{kind:"occupied",entries:t}}async function Gt(e){i.blank(),i.warn(`Found a partial setup at ${d.bold(e)}.`),i.detail(`A previous init wrote ${d.bold(".env")} but didn't finish scaffolding.`),i.blank();let s=await g.select({message:"How would you like to proceed?",initialValue:"resume",options:[{value:"resume",label:"Resume \u2014 use my saved .env values, skip the wizard, retry validation"},{value:"redo",label:"Restart \u2014 walk through the wizard again (existing values pre-filled as defaults)"}]});return g.isCancel(s)&&(g.cancel("Setup cancelled. Existing .env left in place."),process.exit(0)),s}async function Yt(e){if(e&&e.trim().length>0)return e;g.intro("Klaudius");let s=await g.text({message:"Enter your Klaudius license key",placeholder:"KLAU-XXXX-XXXX-XXXX-XXXX",validate:t=>t.trim().length===0?"Required. Check your purchase confirmation email.":void 0});return g.isCancel(s)&&(g.cancel("Setup cancelled. No files written."),process.exit(0)),s}import{readFile as Wt,writeFile as Ge,access as zt}from"fs/promises";import{join as ie}from"path";import*as oe from"@clack/prompts";import L from"picocolors";async function Ye(e){let s=e.projectRoot??process.cwd(),t=ie(s,".env"),n=ie(s,".mcp.json"),r=await de(ie(s,".klaudius","manifest.json")),o=await de(t);!r&&!o&&(i.error("This doesn't look like a Klaudius project."),i.detail("Expected `.klaudius/manifest.json` or `.env` in this folder. Run `npx klaudius init` first."),process.exit(1));let l=se();l.ok||(i.error(l.message??"Node.js version check failed."),i.blank(),i.detail("Once you've installed Node.js 22.15+, re-run `klaudius configure` in this folder."),process.exit(1));let c={};try{let k=await Wt(t,"utf-8");c=O(k)}catch{i.warn("No .env found. Starting from an empty configuration.")}let m=ye(c);oe.intro("Reconfigure Klaudius"),i.detail("Press Enter on any prompt to keep its current value."),i.blank();let a=await T(m);if(a.supabaseUrl!==c.SUPABASE_URL||a.supabaseServiceKey!==c.SUPABASE_SERVICE_KEY){i.heading("Re-validating Supabase credentials");let k=await D({url:a.supabaseUrl,serviceKey:a.supabaseServiceKey});k.ok||(i.error(k.message??"Supabase check failed"),i.warn("Aborting. .env not modified."),process.exit(1)),i.success("Supabase credentials accepted")}await Ge(t,z(a),"utf-8"),i.success("Updated .env"),await Ge(n,q(a),"utf-8"),i.success("Updated .mcp.json"),await ne(s,"supabase"),i.blank(),oe.outro(L.green("Configuration updated.")),await qt(s,r)}async function qt(e,s){let t=await de(ie(e,"node_modules"));i.blank(),s?t||(i.detail("Your project files are in place but dependencies aren't installed yet."),i.detail("To finish setup, run:"),i.blank(),console.log(` ${L.cyan("bash setup.sh")} ${L.dim("# (re-)installs npm + pip + browsers; idempotent")}`),i.blank(),i.detail("Then verify with:"),i.blank(),console.log(` ${L.cyan("npx klaudius doctor")} ${L.dim("# checks Node / Python / installers / credentials")}`),i.blank()):(i.detail("Looks like a previous `klaudius init` saved your .env but didn't finish scaffolding."),i.detail("To finish setup, run:"),i.blank(),console.log(` ${L.cyan("npx klaudius init")} ${L.dim("# pick Resume when prompted")}`),i.blank())}async function de(e){try{return await zt(e),!0}catch{return!1}}import{copyFile as We,mkdir as ze,readdir as Jt,readFile as Xt,rm as Y,writeFile as qe,access as Je}from"fs/promises";import{dirname as Xe,join as I,relative as Qt}from"path";import{tmpdir as Zt}from"os";import*as H from"@clack/prompts";import ue from"picocolors";var pe="0.8.0";async function Qe(e){let s=e.projectRoot??process.cwd(),t=await Se(s);t||(i.error("This doesn't look like a Klaudius project."),i.detail("Expected `.klaudius/manifest.json`. Run `npx klaudius init` first."),process.exit(1));let n,r=I(s,".env");try{let f=await Xt(r,"utf-8"),b=O(f);n=b.KLAUDIUS_LICENSE_KEY??"",n||(i.error("Couldn't find KLAUDIUS_LICENSE_KEY in your .env file."),i.detail("This file is created by `npx klaudius init`. If your project predates"),i.detail("the licence-gated template (CLI version 0.1.x), re-run `npx klaudius init`"),i.detail("in a sibling directory, then copy KLAUDIUS_LICENSE_KEY from its .env."),process.exit(1));let C=we(f,b,[{key:"PRICING_TERMS",value:"one-off, no monthly fees",comment:"Phrasing slotted next to ${PRICING} in outreach copy. See template/CLAUDE.md."},{key:"VERCEL_SCOPE",value:"",comment:"Vercel team slug. Leave blank unless `vercel link` errors about scope (post-2024 multi-team Vercel accounts)."}]);C!==null&&(await qe(r,C,"utf-8"),i.detail("Backfilled new env keys"))}catch{i.error("Couldn't read .env from this directory."),i.detail("Are you running `klaudius update` from inside a Klaudius project?"),process.exit(1)}H.intro(`Update from ${t.templateVersion} \u2192 ${pe}`);let o=I(Zt(),`klaudius-update-${process.pid}-${Date.now()}`),l;try{i.heading("Downloading the latest Klaudius template");let f=await J({licenseKey:n,machineId:F(),hostname:process.env.HOSTNAME??process.env.COMPUTERNAME,os:`${process.platform}-${process.arch}`,destDir:o});i.success(`Fetched ${f.filesExtracted} canonical files`),l=o}catch(f){i.error(f.message),i.detail("Update aborted. Your project is unchanged."),await Y(o,{recursive:!0,force:!0}).catch(()=>{}),process.exit(1)}let c=await es(l,s,t),m=c.filter(f=>f.state==="new"),a=c.filter(f=>f.state==="clean-update"),k=c.filter(f=>f.state==="user-only"),E=c.filter(f=>f.state==="conflict"),P=c.filter(f=>f.state==="no-change"),w=c.filter(f=>f.state==="removed-clean"),_=c.filter(f=>f.state==="removed-modified"),v=[...E,..._];if(i.blank(),i.heading("Change summary"),i.detail(`${N(P.length,"file")} unchanged`),i.detail(`${N(m.length,"new file")}`),i.detail(`${N(a.length,"file")} updated cleanly (no local edits)`),i.detail(`${N(k.length,"file")} you've edited (no upstream change \u2014 left alone)`),i.detail(`${N(w.length,"file")} removed upstream (deleted cleanly)`),i.detail(`${N(E.length,"file")} with conflicts (you edited AND we have a new version)`),i.detail(`${N(_.length,"file")} removed upstream but edited locally (need your decision)`),m.length===0&&a.length===0&&w.length===0&&v.length===0){i.blank(),H.outro(ue.green("Already up to date.")),await Y(o,{recursive:!0,force:!0}).catch(()=>{});return}i.blank(),i.heading("Applying clean updates");for(let f of[...m,...a]){let b=I(l,f.path),C=I(s,f.path);await ze(Xe(C),{recursive:!0}),await We(b,C),t.files[f.path]=f.canonicalHash}m.length+a.length>0&&i.success(`Wrote ${N(m.length+a.length,"file")}`);for(let f of w){let b=I(s,f.path);await Y(b,{force:!0}),delete t.files[f.path]}if(w.length>0&&i.success(`Deleted ${N(w.length,"file")} removed upstream`),v.length>0){i.blank(),i.heading(`${v.length} conflict(s) need resolution`);let f=I(s,".klaudius","incoming");try{await Y(f,{recursive:!0,force:!0})}catch{}for(let b of E){let C=I(l,b.path),u=I(f,b.path);await ze(Xe(u),{recursive:!0}),await We(C,u)}await qe(I(s,".klaudius","conflicts.md"),ts(v,t.templateVersion,pe),"utf-8"),E.length>0&&i.detail("Staged canonical versions to .klaudius/incoming/"),i.detail("Wrote conflict report to .klaudius/conflicts.md")}t.updatedAt=new Date().toISOString(),v.length===0&&(t.templateVersion=pe),await X(s,t),i.blank(),v.length===0?H.outro(ue.green("Update complete.")):H.outro(ue.yellow(`${v.length} conflict(s) staged. Open Claude Code in this project and ask:
48
+ Press Enter on any field to keep its current value.`}),await $(t,a),!a.telegramBotToken||!a.telegramChatId)){i.success("Skipped Telegram. Setup will continue."),h=!0;break}}}i.blank();let E=g.spinner();E.start("Downloading Klaudius template");let P;try{P=(await J({licenseKey:r,machineId:F(),hostname:process.platform==="win32"?process.env.COMPUTERNAME:void 0,os:`${process.platform}-${process.arch}`,destDir:t})).filesExtracted,E.stop(`Downloaded ${P} files into ${d.bold(t)}`)}catch(u){E.stop(u.message,2),i.detail("Your .env / .mcp.json are saved. Re-run init once the issue is resolved to retry the download."),process.exit(1)}await Be(G(t,"clients"),{recursive:!0});let w=await ke(t);await X(t,_e(Bt,w)),i.success("Wrote .klaudius/manifest.json");let _=!1,v="";if(e.skipSchema)i.warn("--skip-schema set; not applying scripts/schema.sql to your Supabase project."),i.detail(`Apply manually later via the SQL editor: ${a.supabaseUrl.replace("https://","https://supabase.com/dashboard/project/"+a.supabaseProjectRef+"/sql/new").replace(a.supabaseProjectRef+".supabase.co","")}`);else{i.blank();let u=g.spinner();u.start("Applying schema to Supabase");let h=await ve({projectRoot:t,pat:a.supabasePat,projectRef:a.supabaseProjectRef});h.ok?u.stop("Schema applied (or already present)"):(u.stop(h.message??"Schema apply failed",2),_=!0,v=`https://supabase.com/dashboard/project/${a.supabaseProjectRef}/sql/new`)}let f=[],b={};if(e.skipInstall)i.warn("--skip-install set; you'll need to run npm install + pip install + playwright/patchright install yourself.");else{i.blank(),i.heading("Installing dependencies");let u=await De(t);i.detail(`npm: ${u.npm}, pip: ${u.pip}, playwright: ${u.playwright}, patchright: ${u.patchright}`),u.npm==="failed"&&f.push("npm"),u.pip==="failed"&&f.push("pip"),u.playwright==="failed"&&f.push("playwright"),u.patchright==="failed"&&f.push("patchright"),b=u.hints??{}}i.blank();let C=[...f,..._?["schema"]:[]];if(C.length>0){g.outro(d.yellow(d.bold(`Setup paused \u2014 ${C.join(", ")} failed.`))),console.log(d.dim("Your credentials and project files are all saved.")),i.blank();for(let[p,y]of Object.entries(b))console.log(d.yellow(`Likely cause of ${p} failure:`)),console.log(d.dim(` ${y}`)),i.blank();console.log(d.dim("To finish, once you've addressed any causes above:")),i.blank(),t!==process.cwd()&&console.log(` ${d.cyan(`cd ${e.target}`)}`),f.length>0&&console.log(` ${d.cyan("bash setup.sh")} ${d.dim("# retry the failing installers")}`),_&&(console.log(d.dim(" Apply scripts/schema.sql in the Supabase SQL editor:")),console.log(` ${d.cyan(v)}`),console.log(d.dim(" Open scripts/schema.sql, copy the contents, paste into the editor, click Run."))),i.blank(),f.includes("pip")&&!b.pip&&(console.log(d.dim("If pip fails again with a build error, check `python3 --version` \u2014 Klaudius needs")),console.log(d.dim("Python 3.10+. Install a newer one from https://www.python.org/downloads/macos/")),console.log(d.dim("and open a fresh Terminal before retrying.")),i.blank());let h=["npm","playwright","patchright"].filter(p=>f.includes(p)&&!b[p]);if(h.length>0){let p=h.length===1?"keeps":"keep";console.log(d.dim(`If ${h.join(" / ")} ${p} failing with network errors (ECONNRESET,`)),console.log(d.dim("ETIMEDOUT, ENOTFOUND), they're transient \u2014 try a different network or your")),console.log(d.dim("phone's hotspot, then re-run `bash setup.sh`.")),i.blank()}console.log(d.dim("For a structured diagnostic of every check (Python / Node / installers / files)")),console.log(d.dim(`run ${d.cyan("klaudius doctor")} in this folder.`)),i.blank(),console.log(d.dim("Stuck? Email hello@klaudius.dev with the last ~20 lines of the install output.")),i.blank();return}g.outro(d.green(d.bold("Project ready."))),console.log(d.dim("Next steps:")),t!==process.cwd()&&console.log(` ${d.cyan(`cd ${e.target}`)}`),console.log(` ${d.cyan("open DOCS.html")} ${d.dim("# read this first \u2014 operator basics + commands")}`),console.log(` ${d.cyan("open operator-guide.html")} ${d.dim("# deeper operational reference for day-to-day use")}`),console.log(` ${d.cyan("claude")} ${d.dim("# open Claude Code in this project")}`),console.log(` ${d.dim("then ask Claude:")}`),console.log(` ${d.cyan(' "Run the pipeline."')}`),i.blank(),console.log(d.dim("Klaudius ships with sensible defaults for tone, follow-up cadence, pitch")),console.log(d.dim("and more \u2014 but you don't have to live with them. Customise by talking to")),console.log(d.dim("Claude inside this project. Examples you can ask:")),console.log(d.dim(' "Make the outreach more casual."')),console.log(d.dim(' "Change the follow-up cadence to weekly."')),console.log(d.dim(` "Don't pitch businesses with fewer than 5 reviews."`)),console.log(d.dim(' "Use a different opening hook for restaurants."')),console.log(d.dim("Claude knows where to make the change \u2014 no config files to edit by hand.")),i.blank()}async function $(e,s){await Be(e,{recursive:!0}),await Ve(G(e,".env"),z(s),"utf-8"),await Ve(G(e,".mcp.json"),q(s),"utf-8"),await ne(e,"supabase")}async function Ft(e){try{(await He(e)).isDirectory()||(i.error(`Target exists but is not a directory: ${e}`),process.exit(1))}catch{return{kind:"fresh"}}let s=await jt(e),t=s.filter(c=>!c.startsWith(".DS_Store"));if(t.length===0)return{kind:"fresh"};let n=new Set([".env",".mcp.json",".claude"]),r=t.every(c=>n.has(c)),o=t.includes(".env"),l=s.includes(".klaudius");if(r&&o&&!l)return{kind:"partial",envPath:G(e,".env")};if(l&&o){let c=!0;try{c=!(await He(G(e,"node_modules"))).isDirectory()}catch{c=!0}return{kind:"scaffolded",nodeModulesMissing:c}}return{kind:"occupied",entries:t}}async function Gt(e){i.blank(),i.warn(`Found a partial setup at ${d.bold(e)}.`),i.detail(`A previous init wrote ${d.bold(".env")} but didn't finish scaffolding.`),i.blank();let s=await g.select({message:"How would you like to proceed?",initialValue:"resume",options:[{value:"resume",label:"Resume \u2014 use my saved .env values, skip the wizard, retry validation"},{value:"redo",label:"Restart \u2014 walk through the wizard again (existing values pre-filled as defaults)"}]});return g.isCancel(s)&&(g.cancel("Setup cancelled. Existing .env left in place."),process.exit(0)),s}async function Yt(e){if(e&&e.trim().length>0)return e;g.intro("Klaudius");let s=await g.text({message:"Enter your Klaudius license key",placeholder:"KLAU-XXXX-XXXX-XXXX-XXXX",validate:t=>t.trim().length===0?"Required. Check your purchase confirmation email.":void 0});return g.isCancel(s)&&(g.cancel("Setup cancelled. No files written."),process.exit(0)),s}import{readFile as Wt,writeFile as Ge,access as zt}from"fs/promises";import{join as ie}from"path";import*as oe from"@clack/prompts";import L from"picocolors";async function Ye(e){let s=e.projectRoot??process.cwd(),t=ie(s,".env"),n=ie(s,".mcp.json"),r=await de(ie(s,".klaudius","manifest.json")),o=await de(t);!r&&!o&&(i.error("This doesn't look like a Klaudius project."),i.detail("Expected `.klaudius/manifest.json` or `.env` in this folder. Run `npx klaudius init` first."),process.exit(1));let l=se();l.ok||(i.error(l.message??"Node.js version check failed."),i.blank(),i.detail("Once you've installed Node.js 22.15+, re-run `klaudius configure` in this folder."),process.exit(1));let c={};try{let k=await Wt(t,"utf-8");c=O(k)}catch{i.warn("No .env found. Starting from an empty configuration.")}let m=ye(c);oe.intro("Reconfigure Klaudius"),i.detail("Press Enter on any prompt to keep its current value."),i.blank();let a=await T(m);if(a.supabaseUrl!==c.SUPABASE_URL||a.supabaseServiceKey!==c.SUPABASE_SERVICE_KEY){i.heading("Re-validating Supabase credentials");let k=await D({url:a.supabaseUrl,serviceKey:a.supabaseServiceKey});k.ok||(i.error(k.message??"Supabase check failed"),i.warn("Aborting. .env not modified."),process.exit(1)),i.success("Supabase credentials accepted")}await Ge(t,z(a),"utf-8"),i.success("Updated .env"),await Ge(n,q(a),"utf-8"),i.success("Updated .mcp.json"),await ne(s,"supabase"),i.blank(),oe.outro(L.green("Configuration updated.")),await qt(s,r)}async function qt(e,s){let t=await de(ie(e,"node_modules"));i.blank(),s?t||(i.detail("Your project files are in place but dependencies aren't installed yet."),i.detail("To finish setup, run:"),i.blank(),console.log(` ${L.cyan("bash setup.sh")} ${L.dim("# (re-)installs npm + pip + browsers; idempotent")}`),i.blank(),i.detail("Then verify with:"),i.blank(),console.log(` ${L.cyan("npx klaudius doctor")} ${L.dim("# checks Node / Python / installers / credentials")}`),i.blank()):(i.detail("Looks like a previous `klaudius init` saved your .env but didn't finish scaffolding."),i.detail("To finish setup, run:"),i.blank(),console.log(` ${L.cyan("npx klaudius init")} ${L.dim("# pick Resume when prompted")}`),i.blank())}async function de(e){try{return await zt(e),!0}catch{return!1}}import{copyFile as We,mkdir as ze,readdir as Jt,readFile as Xt,rm as Y,writeFile as qe,access as Je}from"fs/promises";import{dirname as Xe,join as I,relative as Qt}from"path";import{tmpdir as Zt}from"os";import*as H from"@clack/prompts";import ue from"picocolors";var pe="0.9.1";async function Qe(e){let s=e.projectRoot??process.cwd(),t=await Se(s);t||(i.error("This doesn't look like a Klaudius project."),i.detail("Expected `.klaudius/manifest.json`. Run `npx klaudius init` first."),process.exit(1));let n,r=I(s,".env");try{let f=await Xt(r,"utf-8"),b=O(f);n=b.KLAUDIUS_LICENSE_KEY??"",n||(i.error("Couldn't find KLAUDIUS_LICENSE_KEY in your .env file."),i.detail("This file is created by `npx klaudius init`. If your project predates"),i.detail("the licence-gated template (CLI version 0.1.x), re-run `npx klaudius init`"),i.detail("in a sibling directory, then copy KLAUDIUS_LICENSE_KEY from its .env."),process.exit(1));let C=we(f,b,[{key:"PRICING_TERMS",value:"one-off, no monthly fees",comment:"Phrasing slotted next to ${PRICING} in outreach copy. See template/CLAUDE.md."},{key:"VERCEL_SCOPE",value:"",comment:"Vercel team slug. Leave blank unless `vercel link` errors about scope (post-2024 multi-team Vercel accounts)."}]);C!==null&&(await qe(r,C,"utf-8"),i.detail("Backfilled new env keys"))}catch{i.error("Couldn't read .env from this directory."),i.detail("Are you running `klaudius update` from inside a Klaudius project?"),process.exit(1)}H.intro(`Update from ${t.templateVersion} \u2192 ${pe}`);let o=I(Zt(),`klaudius-update-${process.pid}-${Date.now()}`),l;try{i.heading("Downloading the latest Klaudius template");let f=await J({licenseKey:n,machineId:F(),hostname:process.env.HOSTNAME??process.env.COMPUTERNAME,os:`${process.platform}-${process.arch}`,destDir:o});i.success(`Fetched ${f.filesExtracted} canonical files`),l=o}catch(f){i.error(f.message),i.detail("Update aborted. Your project is unchanged."),await Y(o,{recursive:!0,force:!0}).catch(()=>{}),process.exit(1)}let c=await es(l,s,t),m=c.filter(f=>f.state==="new"),a=c.filter(f=>f.state==="clean-update"),k=c.filter(f=>f.state==="user-only"),E=c.filter(f=>f.state==="conflict"),P=c.filter(f=>f.state==="no-change"),w=c.filter(f=>f.state==="removed-clean"),_=c.filter(f=>f.state==="removed-modified"),v=[...E,..._];if(i.blank(),i.heading("Change summary"),i.detail(`${N(P.length,"file")} unchanged`),i.detail(`${N(m.length,"new file")}`),i.detail(`${N(a.length,"file")} updated cleanly (no local edits)`),i.detail(`${N(k.length,"file")} you've edited (no upstream change \u2014 left alone)`),i.detail(`${N(w.length,"file")} removed upstream (deleted cleanly)`),i.detail(`${N(E.length,"file")} with conflicts (you edited AND we have a new version)`),i.detail(`${N(_.length,"file")} removed upstream but edited locally (need your decision)`),m.length===0&&a.length===0&&w.length===0&&v.length===0){i.blank(),H.outro(ue.green("Already up to date.")),await Y(o,{recursive:!0,force:!0}).catch(()=>{});return}i.blank(),i.heading("Applying clean updates");for(let f of[...m,...a]){let b=I(l,f.path),C=I(s,f.path);await ze(Xe(C),{recursive:!0}),await We(b,C),t.files[f.path]=f.canonicalHash}m.length+a.length>0&&i.success(`Wrote ${N(m.length+a.length,"file")}`);for(let f of w){let b=I(s,f.path);await Y(b,{force:!0}),delete t.files[f.path]}if(w.length>0&&i.success(`Deleted ${N(w.length,"file")} removed upstream`),v.length>0){i.blank(),i.heading(`${v.length} conflict(s) need resolution`);let f=I(s,".klaudius","incoming");try{await Y(f,{recursive:!0,force:!0})}catch{}for(let b of E){let C=I(l,b.path),u=I(f,b.path);await ze(Xe(u),{recursive:!0}),await We(C,u)}await qe(I(s,".klaudius","conflicts.md"),ts(v,t.templateVersion,pe),"utf-8"),E.length>0&&i.detail("Staged canonical versions to .klaudius/incoming/"),i.detail("Wrote conflict report to .klaudius/conflicts.md")}t.updatedAt=new Date().toISOString(),v.length===0&&(t.templateVersion=pe),await X(s,t),i.blank(),v.length===0?H.outro(ue.green("Update complete.")):H.outro(ue.yellow(`${v.length} conflict(s) staged. Open Claude Code in this project and ask:
49
49
  "Run /resolve-conflicts"`)),await Y(o,{recursive:!0,force:!0}).catch(()=>{})}async function es(e,s,t){let n=await Ze(e),r=new Set(n),o=[];for(let l of n){let c=await W(I(e,l)),m=t.files[l],a=I(s,l),k;try{await Je(a),k=await W(a)}catch{o.push({path:l,state:"new",canonicalHash:c,manifestHash:m});continue}c===m?k===m?o.push({path:l,state:"no-change",canonicalHash:c,localHash:k,manifestHash:m}):o.push({path:l,state:"user-only",canonicalHash:c,localHash:k,manifestHash:m}):k===m?o.push({path:l,state:"clean-update",canonicalHash:c,localHash:k,manifestHash:m}):o.push({path:l,state:"conflict",canonicalHash:c,localHash:k,manifestHash:m})}for(let l of Object.keys(t.files)){if(r.has(l))continue;let c=t.files[l],m=I(s,l),a;try{await Je(m),a=await W(m)}catch{delete t.files[l];continue}a===c?o.push({path:l,state:"removed-clean",localHash:a,manifestHash:c}):o.push({path:l,state:"removed-modified",localHash:a,manifestHash:c})}return o}function N(e,s){return`${e} ${s}${e===1?"":"s"}`}async function Ze(e,s=e){let t=await Jt(e,{withFileTypes:!0}),n=[];for(let r of t){let o=I(e,r.name);r.isDirectory()?n.push(...await Ze(o,s)):r.isFile()&&n.push(Qt(s,o))}return n}function ts(e,s,t){let n=e.filter(c=>c.state==="conflict").length,r=e.filter(c=>c.state==="removed-modified").length,o=[];o.push("# Update Conflicts"),o.push(""),o.push(`Generated by \`npx klaudius update\` on ${new Date().toISOString()}.`),o.push(`Updating from canonical version **${s}** to **${t}**.`),o.push("");let l=[];n>0&&l.push(`${n} file${n===1?"":"s"} ha${n===1?"s":"ve"} BOTH local edits AND upstream changes`),r>0&&l.push(`${r} file${r===1?"":"s"} ${r===1?"was":"were"} removed upstream but edited locally`),o.push(l.join(", and ")+"."),o.push("Open Claude Code in this project and run `/resolve-conflicts` \u2014 that skill walks through each conflict interactively, helping you decide what to keep, take, merge, or delete."),o.push(""),o.push("---"),o.push("");for(let c of e)o.push(`## ${c.path}`),o.push(""),c.state==="removed-modified"?(o.push("**Type:** Removed upstream"),o.push(""),o.push(`- Your local copy: \`${c.path}\``),o.push("- This file no longer exists in the canonical template."),o.push("- You've modified it locally since install."),o.push(`- Hash at last install/update: \`${(c.manifestHash??"(none)").slice(0,16)}\``),o.push(`- Your local hash now: \`${(c.localHash??"(missing)").slice(0,16)}\``),o.push(""),o.push("**Resolution options for the SKILL to walk through:**"),o.push(""),o.push("1. Keep mine \u2014 leave the file in place; stop tracking it in the manifest"),o.push("2. Delete \u2014 remove the file from disk and from the manifest")):(o.push("**Type:** Edit conflict"),o.push(""),o.push(`- Your version (with your local edits): \`${c.path}\``),o.push(`- New canonical version: \`.klaudius/incoming/${c.path}\``),o.push(`- Hash at last install/update: \`${(c.manifestHash??"(none)").slice(0,16)}\``),o.push(`- Your local hash now: \`${(c.localHash??"(missing)").slice(0,16)}\``),o.push(`- New canonical hash: \`${(c.canonicalHash??"(none)").slice(0,16)}\``),o.push(""),o.push("**Resolution options for the SKILL to walk through:**"),o.push(""),o.push("1. Keep mine \u2014 discard the new canonical changes"),o.push("2. Take canonical \u2014 overwrite my edits with the new version"),o.push("3. Merge \u2014 review both side-by-side and produce a combined version")),o.push(""),o.push("---"),o.push("");return o.join(`
50
50
  `)}import{access as ss,readFile as ns,stat as is}from"fs/promises";import{join as M}from"path";import S from"picocolors";import{spawn as os}from"child_process";async function et(e){let s=e.projectRoot??process.cwd(),t=[];console.log(S.bold(`Klaudius doctor \u2014 checking your project\u2026
51
51
  `)),t.push(await rs()),t.push(await as());let n=M(s,".env"),r=M(s,".klaudius","manifest.json"),o=M(s,".mcp.json"),l=M(s,"setup.sh"),c=await V(n),m=await V(r),a=await V(o),k=await V(l);if(t.push({name:".env present",status:c?"ok":"fail",detail:c?n:"missing",nextAction:c?void 0:"Run `klaudius init` in this folder."}),t.push({name:"Template scaffolded (.klaudius/manifest.json)",status:m?"ok":"fail",detail:m?r:"missing",nextAction:m?void 0:c?"Init didn't finish \u2014 run `klaudius init` and pick Resume.":"Run `klaudius init`."}),t.push({name:".mcp.json present",status:a?"ok":"warn",detail:a?o:"missing",nextAction:a?void 0:"Run `klaudius configure` to regenerate."}),t.push({name:"setup.sh present",status:k?"ok":"warn",detail:k?l:"missing \u2014 re-run init"}),t.push(await ls(s)),t.push(await cs(s)),t.push(await ds()),!c)t.push({name:"Credential validations",status:"skip",detail:".env missing"});else if(e.offline)t.push({name:"Credential validations",status:"skip",detail:"--offline set"});else{let w=await ns(n,"utf-8"),_=O(w);await us(_,t)}console.log();for(let w of t){let _=w.status==="ok"?S.green("\u2713"):w.status==="warn"?S.yellow("\u26A0"):w.status==="skip"?S.dim("\xB7"):S.red("\u2717");console.log(` ${_} ${w.name}${w.detail?S.dim(` \u2014 ${w.detail}`):""}`),w.nextAction&&console.log(` ${S.dim("\u2192")} ${S.cyan(w.nextAction)}`)}let E=t.filter(w=>w.status==="fail").length,P=t.filter(w=>w.status==="warn").length;console.log(),E===0&&P===0?console.log(S.green(S.bold("Everything checks out. You're good to go."))):E===0?console.log(S.yellow(S.bold(`${P} warning${P===1?"":"s"} \u2014 review above.`))):(console.log(S.red(S.bold(`${E} failed check${E===1?"":"s"} \u2014 see the \u2192 next actions above.`))),process.exitCode=1),console.log()}async function V(e){try{return await ss(e),!0}catch{return!1}}async function rs(){let e=await te();return e.ok?{name:"Python \u2265 3.10",status:"ok",detail:e.version}:{name:"Python \u2265 3.10",status:"fail",detail:e.version??"not found",nextAction:"Install Python 3.10+ from https://www.python.org/downloads/"}}async function as(){let e=process.version,s=/^v(\d+)\.(\d+)\.(\d+)$/.exec(e);if(!s)return{name:"Node \u2265 22.15",status:"warn",detail:e};let t=parseInt(s[1],10),n=parseInt(s[2],10);return t<22||t===22&&n<15?{name:"Node \u2265 22.15",status:"fail",detail:e,nextAction:"Upgrade Node.js to 22.15+ from https://nodejs.org/"}:{name:"Node \u2265 22.15",status:"ok",detail:e}}async function ls(e){let s=M(e,"node_modules");if(!await V(s))return{name:"node_modules installed",status:"fail",detail:"missing",nextAction:"Run `bash setup.sh` (or `npm install`) in this folder."};try{if(!(await is(s)).isDirectory())return{name:"node_modules installed",status:"warn",detail:"exists but isn't a directory"}}catch{}return{name:"node_modules installed",status:"ok"}}async function cs(e){let s=process.platform==="darwin"?M(process.env.HOME??"","Library","Caches","ms-playwright"):process.platform==="win32"?M(process.env.USERPROFILE??"","AppData","Local","ms-playwright"):M(process.env.HOME??"",".cache","ms-playwright");return await V(s)?{name:"Playwright browser installed",status:"ok",detail:s}:{name:"Playwright browser installed",status:"fail",detail:"no browser cache found",nextAction:"Run `npx playwright install chromium` in this folder."}}async function ds(){let e=["supabase","dotenv","requests","httpx","PIL"],s=`import sys
@@ -56,4 +56,4 @@ except Exception as e:
56
56
  print(str(e))
57
57
  sys.exit(1)
58
58
  `,t=await ps("python3",["-c",s]);return t.code===0?{name:"Python packages installed",status:"ok",detail:e.join(", ")}:{name:"Python packages installed",status:"fail",detail:(t.stdout||t.stderr).trim().split(`
59
- `).pop()??"import failed",nextAction:"Run `bash setup.sh` in this folder."}}async function us(e,s){if(e.SUPABASE_URL&&e.SUPABASE_SERVICE_KEY){let t=await D({url:e.SUPABASE_URL,serviceKey:e.SUPABASE_SERVICE_KEY});s.push({name:"Supabase credentials",status:t.ok?"ok":"fail",detail:t.ok?"connected":t.message,nextAction:t.ok?void 0:"Run `klaudius configure` to fix the URL or key."})}else s.push({name:"Supabase credentials",status:"fail",detail:"missing in .env"});if(e.VERCEL_TOKEN){let t=await Q(e.VERCEL_TOKEN);s.push({name:"Vercel token",status:t.ok?"ok":"fail",detail:t.ok?t.username??"valid":t.message,nextAction:t.ok?void 0:"Generate a new token at https://vercel.com/account/tokens, then `klaudius configure`."})}else s.push({name:"Vercel token",status:"fail",detail:"missing in .env"});if(e.GOOGLE_PLACES_API_KEY){let t=await Z(e.GOOGLE_PLACES_API_KEY);s.push({name:"Google Places API key",status:t.ok?"ok":"fail",detail:t.ok?"accepted":t.message,nextAction:t.ok?void 0:"Fix the key in https://console.cloud.google.com and `klaudius configure`."})}else s.push({name:"Google Places API key",status:"warn",detail:"not set (find skill will fail until you add one)"});if(e.TELEGRAM_BOT_TOKEN&&e.TELEGRAM_CHAT_ID){let t=await he({botToken:e.TELEGRAM_BOT_TOKEN});s.push({name:"Telegram bot token",status:t.ok?"ok":"fail",detail:t.ok?`bot ${t.botHandle??"ok"} (chat_id not tested)`:t.message,nextAction:t.ok?void 0:"Fix TELEGRAM_BOT_TOKEN in .env (or blank both Telegram lines to disable)."})}else e.TELEGRAM_BOT_TOKEN||e.TELEGRAM_CHAT_ID?s.push({name:"Telegram credentials",status:"warn",detail:"partial config (one of bot token / chat ID set, other missing)",nextAction:"Either set both, or blank both to disable Telegram notifications."}):s.push({name:"Telegram credentials",status:"skip",detail:"not configured (optional)"})}function ps(e,s){return new Promise(t=>{let n=os(e,s,{stdio:["ignore","pipe","pipe"],shell:!1}),r="",o="";n.stdout?.on("data",l=>{r+=l.toString()}),n.stderr?.on("data",l=>{o+=l.toString()}),n.on("close",l=>t({code:l??1,stdout:r,stderr:o})),n.on("error",()=>t({code:1,stdout:r,stderr:o}))})}var fs="0.8.0",B=new ms;B.name("klaudius").description("Scaffold and maintain a Klaudius pipeline project").version(fs);B.command("init").description("Scaffold a new Klaudius project").argument("[target]","Directory to create (defaults to current directory)",".").option("--license <key>","License key (received in your purchase confirmation email)").option("--skip-install","Skip npm/pip/playwright installation").option("--skip-schema","Skip applying schema.sql to your Supabase project").action(async(e,s)=>{try{await Fe({target:e,license:s.license,skipInstall:!!s.skipInstall,skipSchema:!!s.skipSchema})}catch(t){console.error("init failed:",t.message),process.exit(1)}});B.command("configure").description("Re-run the setup wizard with current values pre-filled").action(async()=>{try{await Ye({})}catch(e){console.error("configure failed:",e.message),process.exit(1)}});B.command("update").description("Pull latest template; produce a conflicts report for any files you've modified").action(async()=>{try{await Qe({})}catch(e){console.error("update failed:",e.message),process.exit(1)}});B.command("doctor").description("Diagnose a broken install \u2014 env versions, files, installed deps, credentials").option("--offline","Skip credential validations that require network calls").action(async e=>{try{await et({offline:!!e.offline})}catch(s){console.error("doctor failed:",s.message),process.exit(1)}});B.parse(process.argv);
59
+ `).pop()??"import failed",nextAction:"Run `bash setup.sh` in this folder."}}async function us(e,s){if(e.SUPABASE_URL&&e.SUPABASE_SERVICE_KEY){let t=await D({url:e.SUPABASE_URL,serviceKey:e.SUPABASE_SERVICE_KEY});s.push({name:"Supabase credentials",status:t.ok?"ok":"fail",detail:t.ok?"connected":t.message,nextAction:t.ok?void 0:"Run `klaudius configure` to fix the URL or key."})}else s.push({name:"Supabase credentials",status:"fail",detail:"missing in .env"});if(e.VERCEL_TOKEN){let t=await Q(e.VERCEL_TOKEN);s.push({name:"Vercel token",status:t.ok?"ok":"fail",detail:t.ok?t.username??"valid":t.message,nextAction:t.ok?void 0:"Generate a new token at https://vercel.com/account/tokens, then `klaudius configure`."})}else s.push({name:"Vercel token",status:"fail",detail:"missing in .env"});if(e.GOOGLE_PLACES_API_KEY){let t=await Z(e.GOOGLE_PLACES_API_KEY);s.push({name:"Google Places API key",status:t.ok?"ok":"fail",detail:t.ok?"accepted":t.message,nextAction:t.ok?void 0:"Fix the key in https://console.cloud.google.com and `klaudius configure`."})}else s.push({name:"Google Places API key",status:"warn",detail:"not set (find skill will fail until you add one)"});if(e.TELEGRAM_BOT_TOKEN&&e.TELEGRAM_CHAT_ID){let t=await he({botToken:e.TELEGRAM_BOT_TOKEN});s.push({name:"Telegram bot token",status:t.ok?"ok":"fail",detail:t.ok?`bot ${t.botHandle??"ok"} (chat_id not tested)`:t.message,nextAction:t.ok?void 0:"Fix TELEGRAM_BOT_TOKEN in .env (or blank both Telegram lines to disable)."})}else e.TELEGRAM_BOT_TOKEN||e.TELEGRAM_CHAT_ID?s.push({name:"Telegram credentials",status:"warn",detail:"partial config (one of bot token / chat ID set, other missing)",nextAction:"Either set both, or blank both to disable Telegram notifications."}):s.push({name:"Telegram credentials",status:"skip",detail:"not configured (optional)"})}function ps(e,s){return new Promise(t=>{let n=os(e,s,{stdio:["ignore","pipe","pipe"],shell:!1}),r="",o="";n.stdout?.on("data",l=>{r+=l.toString()}),n.stderr?.on("data",l=>{o+=l.toString()}),n.on("close",l=>t({code:l??1,stdout:r,stderr:o})),n.on("error",()=>t({code:1,stdout:r,stderr:o}))})}var fs="0.9.1",B=new ms;B.name("klaudius").description("Scaffold and maintain a Klaudius pipeline project").version(fs);B.command("init").description("Scaffold a new Klaudius project").argument("[target]","Directory to create (defaults to current directory)",".").option("--license <key>","License key (received in your purchase confirmation email)").option("--skip-install","Skip npm/pip/playwright installation").option("--skip-schema","Skip applying schema.sql to your Supabase project").action(async(e,s)=>{try{await Fe({target:e,license:s.license,skipInstall:!!s.skipInstall,skipSchema:!!s.skipSchema})}catch(t){console.error("init failed:",t.message),process.exit(1)}});B.command("configure").description("Re-run the setup wizard with current values pre-filled").action(async()=>{try{await Ye({})}catch(e){console.error("configure failed:",e.message),process.exit(1)}});B.command("update").description("Pull latest template; produce a conflicts report for any files you've modified").action(async()=>{try{await Qe({})}catch(e){console.error("update failed:",e.message),process.exit(1)}});B.command("doctor").description("Diagnose a broken install \u2014 env versions, files, installed deps, credentials").option("--offline","Skip credential validations that require network calls").action(async e=>{try{await et({offline:!!e.offline})}catch(s){console.error("doctor failed:",s.message),process.exit(1)}});B.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "klaudius",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "Scaffold and maintain a Klaudius project — an autonomous web agency pipeline that runs on Claude Code (find, build, deploy, outreach end-to-end).",
5
5
  "homepage": "https://klaudius.dev",
6
6
  "bugs": {