klaudius 0.7.0 → 0.7.2

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 +26 -26
  2. package/package.json +2 -1
package/dist/bin.js CHANGED
@@ -1,59 +1,59 @@
1
1
  #!/usr/bin/env node
2
- import{a as x,b as ue,c as pe,d as T,f as me,g as fe}from"./chunk-SZ4KCTSL.js";import{a as ne,e as he}from"./chunk-47ODNABO.js";import{Command as us}from"commander";import{mkdir as je,readdir as Ut,readFile as De,stat as Dt,writeFile as Ke}from"fs/promises";import{resolve as Kt,isAbsolute as jt,join as Z}from"path";import*as g from"@clack/prompts";import m from"picocolors";import Ze from"react";import{render as et}from"ink";async function b(e={},s={}){if(!process.stdin.isTTY)throw new Error("Klaudius's interactive wizard requires a terminal (TTY). Run `npx klaudius init` directly from your terminal \u2014 not through a pipe, file redirect, or non-interactive shell context.");let{WizardApp:n}=await import("./WizardApp-B6HU5YMU.js"),t=null;x("runWizard:start",{onlySection:s.onlySection,hasDefaults:Object.keys(e).length>0}),pe(),await new Promise(a=>setImmediate(a)),await new Promise(a=>setTimeout(a,0)),x("runWizard:event loop drained, mounting Ink");let o=et(Ze.createElement(n,{defaults:e,onlySection:s.onlySection,banner:s.banner,onComplete:a=>{x("runWizard:onComplete called",{keys:Object.keys(a).length}),t=a}}),{stdout:process.stdout,stderr:process.stderr,stdin:process.stdin,exitOnCtrlC:!1});if(x("runWizard:render returned, awaiting exit"),await o.waitUntilExit(),x("runWizard:waitUntilExit resolved",{resultIsNull:t===null}),!t)throw new Error(`Wizard exited without completing. Diagnostic log: ${ue}
3
- Please share that file so we can trace what happened.`);return t}function B(e){let s=[],n=o=>{s.push(""),s.push("# "+"=".repeat(60)),s.push(`# ${o}`),s.push("# "+"=".repeat(60)),s.push("")},t=(o,a)=>{if(a==null||a===""){s.push(`# ${o}=`);return}let l=String(a);if(/[\s"'`$\\#&|<>;()*?\[\]{}!~]/.test(l)){let c=l.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`");s.push(`${o}="${c}"`)}else s.push(`${o}=${l}`)};return s.push("# Klaudius configuration"),s.push("# Generated by `npx klaudius init`. Edit freely."),s.push("# NEVER commit this file. .gitignore already excludes it."),n("Klaudius licence"),t("KLAUDIUS_LICENSE_KEY",e.licenseKey),n("Pricing"),t("PRICING",e.pricing),t("PRICING_TERMS",e.pricingTerms),t("PRICING_MONTHLY",e.pricingMonthly),n("Automated outreach features"),t("OUTREACH_ENABLED",e.outreachEnabled?"true":"false"),t("OPERATOR_NAME",e.name),t("SIGNATURE",e.signature),t("OUTREACH_CHANNELS",e.outreachChannels?.join(",")),t("OUTREACH_PRIORITY",e.outreachPriority),n("Email outreach"),t("EMAIL_ADDRESS",e.emailAddress),t("EMAIL_PASSWORD",e.emailPassword),t("EMAIL_FROM_NAME",e.emailFromName),t("EMAIL_SMTP_HOST",e.emailSmtpHost),t("EMAIL_SMTP_PORT",e.emailSmtpPort),t("EMAIL_IMAP_HOST",e.emailImapHost),t("EMAIL_IMAP_PORT",e.emailImapPort),t("EMAIL_SENT_FOLDER",e.emailSentFolder),t("EMAIL_INBOX_FOLDER",e.emailInboxFolder),n("SMS outreach"),t("SMS_PROVIDER",e.smsProvider),t("TEST_PHONE",e.testPhone),t("TWILIO_ACCOUNT_SID",e.twilioAccountSid),t("TWILIO_AUTH_TOKEN",e.twilioAuthToken),t("TWILIO_PHONE_NUMBER",e.twilioPhoneNumber),n("Supabase (pipeline state)"),t("SUPABASE_URL",e.supabaseUrl),t("SUPABASE_SERVICE_KEY",e.supabaseServiceKey),t("SUPABASE_PAT",e.supabasePat),t("SUPABASE_PROJECT_REF",e.supabaseProjectRef),n("Vercel (deployment)"),t("VERCEL_TOKEN",e.vercelToken),t("VERCEL_SCOPE",e.vercelScope??""),n("Search APIs"),t("GOOGLE_PLACES_API_KEY",e.googlePlacesApiKey),t("SERPAPI_KEY",e.serpapiKey),n("Telegram notifications (optional)"),t("TELEGRAM_BOT_TOKEN",e.telegramBotToken),t("TELEGRAM_CHAT_ID",e.telegramChatId),n("Rate limiting (sensible defaults)"),t("REQUESTS_PER_MINUTE",10),t("REQUEST_DELAY",2),s.join(`
2
+ import{a as x,b as me,c as fe,d as A,f as he,g as ge}from"./chunk-SZ4KCTSL.js";import{a as oe,e as ke}from"./chunk-47ODNABO.js";import{Command as ps}from"commander";import{mkdir as Be,readdir as Kt,readFile as je,stat as He,writeFile as Ve}from"fs/promises";import{resolve as jt,isAbsolute as Ht,join as B}from"path";import*as g from"@clack/prompts";import d from"picocolors";import tt from"react";import{render as st}from"ink";async function S(e={},s={}){if(!process.stdin.isTTY)throw new Error("Klaudius's interactive wizard requires a terminal (TTY). Run `npx klaudius init` directly from your terminal \u2014 not through a pipe, file redirect, or non-interactive shell context.");let{WizardApp:n}=await import("./WizardApp-B6HU5YMU.js"),t=null;x("runWizard:start",{onlySection:s.onlySection,hasDefaults:Object.keys(e).length>0}),fe(),await new Promise(a=>setImmediate(a)),await new Promise(a=>setTimeout(a,0)),x("runWizard:event loop drained, mounting Ink");let o=st(tt.createElement(n,{defaults:e,onlySection:s.onlySection,banner:s.banner,onComplete:a=>{x("runWizard:onComplete called",{keys:Object.keys(a).length}),t=a}}),{stdout:process.stdout,stderr:process.stderr,stdin:process.stdin,exitOnCtrlC:!1});if(x("runWizard:render returned, awaiting exit"),await o.waitUntilExit(),x("runWizard:waitUntilExit resolved",{resultIsNull:t===null}),!t)throw new Error(`Wizard exited without completing. Diagnostic log: ${me}
3
+ Please share that file so we can trace what happened.`);return t}function G(e){let s=[],n=o=>{s.push(""),s.push("# "+"=".repeat(60)),s.push(`# ${o}`),s.push("# "+"=".repeat(60)),s.push("")},t=(o,a)=>{if(a==null||a===""){s.push(`# ${o}=`);return}let l=String(a);if(/[\s"'`$\\#&|<>;()*?\[\]{}!~]/.test(l)){let c=l.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`");s.push(`${o}="${c}"`)}else s.push(`${o}=${l}`)};return s.push("# Klaudius configuration"),s.push("# Generated by `npx klaudius init`. Edit freely."),s.push("# NEVER commit this file. .gitignore already excludes it."),n("Klaudius licence"),t("KLAUDIUS_LICENSE_KEY",e.licenseKey),n("Pricing"),t("PRICING",e.pricing),t("PRICING_TERMS",e.pricingTerms),t("PRICING_MONTHLY",e.pricingMonthly),n("Automated outreach features"),t("OUTREACH_ENABLED",e.outreachEnabled?"true":"false"),t("OPERATOR_NAME",e.name),t("SIGNATURE",e.signature),t("OUTREACH_CHANNELS",e.outreachChannels?.join(",")),t("OUTREACH_PRIORITY",e.outreachPriority),n("Email outreach"),t("EMAIL_ADDRESS",e.emailAddress),t("EMAIL_PASSWORD",e.emailPassword),t("EMAIL_FROM_NAME",e.emailFromName),t("EMAIL_SMTP_HOST",e.emailSmtpHost),t("EMAIL_SMTP_PORT",e.emailSmtpPort),t("EMAIL_IMAP_HOST",e.emailImapHost),t("EMAIL_IMAP_PORT",e.emailImapPort),t("EMAIL_SENT_FOLDER",e.emailSentFolder),t("EMAIL_INBOX_FOLDER",e.emailInboxFolder),n("SMS outreach"),t("SMS_PROVIDER",e.smsProvider),t("TEST_PHONE",e.testPhone),t("TWILIO_ACCOUNT_SID",e.twilioAccountSid),t("TWILIO_AUTH_TOKEN",e.twilioAuthToken),t("TWILIO_PHONE_NUMBER",e.twilioPhoneNumber),n("Supabase (pipeline state)"),t("SUPABASE_URL",e.supabaseUrl),t("SUPABASE_SERVICE_KEY",e.supabaseServiceKey),t("SUPABASE_PAT",e.supabasePat),t("SUPABASE_PROJECT_REF",e.supabaseProjectRef),n("Vercel (deployment)"),t("VERCEL_TOKEN",e.vercelToken),t("VERCEL_SCOPE",e.vercelScope??""),n("Search APIs"),t("GOOGLE_PLACES_API_KEY",e.googlePlacesApiKey),t("SERPAPI_KEY",e.serpapiKey),n("Telegram notifications (optional)"),t("TELEGRAM_BOT_TOKEN",e.telegramBotToken),t("TELEGRAM_CHAT_ID",e.telegramChatId),n("Rate limiting (sensible defaults)"),t("REQUESTS_PER_MINUTE",10),t("REQUEST_DELAY",2),s.join(`
4
4
  `)+`
5
- `}function F(e){let s={mcpServers:{supabase:{command:"npx",args:["-y","@supabase/mcp-server-supabase@latest",`--project-ref=${e.supabaseProjectRef}`],env:{SUPABASE_ACCESS_TOKEN:e.supabasePat,NODE_OPTIONS:"--use-system-ca"}}}};return JSON.stringify(s,null,2)+`
6
- `}function tt(e,s){if(/[\s"'`$\\#&|<>;()*?\[\]{}!~]/.test(s)){let n=s.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`");return`${e}="${n}"`}return`${e}=${s}`}function ge(e,s,n){let t=n.filter(l=>!(l.key in s));if(t.length===0)return null;let o=e.endsWith(`
5
+ `}function Y(e){let s={mcpServers:{supabase:{command:"npx",args:["-y","@supabase/mcp-server-supabase@latest",`--project-ref=${e.supabaseProjectRef}`],env:{SUPABASE_ACCESS_TOKEN:e.supabasePat,NODE_OPTIONS:"--use-system-ca"}}}};return JSON.stringify(s,null,2)+`
6
+ `}function nt(e,s){if(/[\s"'`$\\#&|<>;()*?\[\]{}!~]/.test(s)){let n=s.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`");return`${e}="${n}"`}return`${e}=${s}`}function we(e,s,n){let t=n.filter(l=>!(l.key in s));if(t.length===0)return null;let o=e.endsWith(`
7
7
  `)?"":`
8
- `,a=["","# "+"=".repeat(60),"# Backfilled by `klaudius update` (new template env keys)","# "+"=".repeat(60)];for(let l of t)a.push(""),l.comment&&a.push(`# ${l.comment}`),a.push(tt(l.key,l.value));return e+o+a.join(`
8
+ `,a=["","# "+"=".repeat(60),"# Backfilled by `klaudius update` (new template env keys)","# "+"=".repeat(60)];for(let l of t)a.push(""),l.comment&&a.push(`# ${l.comment}`),a.push(nt(l.key,l.value));return e+o+a.join(`
9
9
  `)+`
10
- `}function st(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 v(e){let s={};for(let n of e.split(`
11
- `)){let t=n.trim();if(!t||t.startsWith("#"))continue;let o=t.indexOf("=");if(o===-1)continue;let a=t.slice(0,o).trim(),l=st(t.slice(o+1).trim());s[a]=l}return s}function ke(e){let s=a=>{let l=e[a];if(!l)return;let c=parseInt(l,10);return isNaN(c)?void 0:c},n=e.SMS_PROVIDER,t=e.OUTREACH_CHANNELS?.split(",").map(a=>a.trim()).filter(a=>a==="email"||a==="sms"),o=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:t&&t.length>0?t:void 0,outreachPriority:o==="email"||o==="sms"?o: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:n==="imessage"||n==="twilio"?n: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 ie(e){let s=P=>{let p=e[P];if(!p)return;let E=parseInt(p,10);return isNaN(E)?void 0:E},n=e.SUPABASE_URL,t=e.SUPABASE_SERVICE_KEY,o=e.SUPABASE_PAT,a=e.SUPABASE_PROJECT_REF,l=e.PRICING,c=e.PRICING_TERMS||"one-off, no monthly fees",h=e.VERCEL_TOKEN;if(!l||!n||!t||!o||!a||!h)return null;let r=e.SMS_PROVIDER,w=e.OUTREACH_CHANNELS?.split(",").map(P=>P.trim()).filter(P=>P==="email"||P==="sms"),k=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:w&&w.length>0?w:void 0,outreachPriority:k==="email"||k==="sms"?k: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:r==="imessage"||r==="twilio"?r:void 0,testPhone:e.TEST_PHONE,twilioAccountSid:e.TWILIO_ACCOUNT_SID,twilioAuthToken:e.TWILIO_AUTH_TOKEN,twilioPhoneNumber:e.TWILIO_PHONE_NUMBER,vercelToken:h,vercelScope:e.VERCEL_SCOPE||void 0,supabaseUrl:n,supabaseServiceKey:t,supabasePat:o,supabaseProjectRef:a,googlePlacesApiKey:e.GOOGLE_PLACES_API_KEY,serpapiKey:e.SERPAPI_KEY,telegramBotToken:e.TELEGRAM_BOT_TOKEN,telegramChatId:e.TELEGRAM_CHAT_ID}}import{mkdir as nt,rm as it}from"fs/promises";import{Readable as ot}from"stream";import*as we from"tar";var rt="https://klaudius.dev/api/template";function at(e){return ot.fromWeb(e)}async function G(e){let s=process.env.KLAUDIUS_TEMPLATE_URL??rt,n="0.7.0",t;try{t=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:n})})}catch(l){throw new Error(`Could not reach klaudius.dev to download the template: ${T(l)}`)}if(!t.ok){let l="";try{let c=await t.json();l=c.reason?` (${c.reason})`:""}catch{}throw new Error(`Template download failed: HTTP ${t.status}${l}`)}if(!t.body)throw new Error("Template download succeeded but response had no body");let o=t.headers.get("x-klaudius-tier");await nt(e.destDir,{recursive:!0});let a=0;try{await new Promise((l,c)=>{let h=we.extract({cwd:e.destDir,strict:!0,onReadEntry:()=>{a++}});h.on("finish",l),h.on("error",c),at(t.body).on("error",c).pipe(h)})}catch(l){throw await it(e.destDir,{recursive:!0,force:!0}).catch(()=>{}),new Error(`Failed to extract template archive: ${l.message}`)}return{filesExtracted:a,tier:o}}import{mkdir as lt,readFile as ct,writeFile as dt,access as ut}from"fs/promises";import{dirname as pt,join as ye}from"path";var mt=".klaudius",Ee=`${mt}/manifest.json`;async function Pe(e){let s=ye(e,Ee);try{await ut(s)}catch{return null}let n=await ct(s,"utf-8");return JSON.parse(n)}async function Y(e,s){let n=ye(e,Ee);await lt(pt(n),{recursive:!0}),await dt(n,JSON.stringify(s,null,2)+`
12
- `,"utf-8")}function Se(e,s){let n=new Date().toISOString();return{version:1,templateVersion:e,installedAt:n,updatedAt:n,files:s}}import{createHash as ft}from"crypto";import{hostname as be,userInfo as ht,platform as Ae,arch as Te}from"os";import O from"picocolors";var i={info:e=>console.log(O.cyan("\u2139"),e),success:e=>console.log(O.green("\u2713"),e),warn:e=>console.log(O.yellow("\u26A0"),e),error:e=>console.error(O.red("\u2717"),e),step:e=>console.log(O.dim("\u2192"),e),blank:()=>console.log(""),heading:e=>console.log(`
13
- `+O.bold(O.cyan(e))),detail:e=>console.log(O.dim(" "+e))};var gt="https://klaudius.dev",kt="/api/licenses/validate",wt="0.7.0";async function _e(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(),t=(process.env.KLAUDIUS_API_URL??gt).replace(/\/$/,"")+kt,o=H(),a;try{a=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({license_key:s,machine_id:o,hostname:be(),os:`${Ae()}-${Te()}`,cli_version:wt})})}catch(c){return{ok:!1,reason:`Could not reach the Klaudius license server (${T(c)}). Check your internet connection or try again later.`}}let l;try{l=await a.json()}catch{return{ok:!1,reason:`License server returned an unparseable response (HTTP ${a.status}).`}}return l.ok?{ok:!0,tier:l.tier??"core"}:{ok:!1,reason:l.reason??`License rejected (HTTP ${a.status}).`}}function H(){let e=[be(),ht().username,Ae(),Te()].join("|");return ft("sha256").update(e).digest("hex").slice(0,32)}import{readFile as yt}from"fs/promises";import{join as Et}from"path";async function $(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: ${T(s)}`}}}async function Ie(e){let s;try{s=await yt(Et(e.projectRoot,"scripts","schema.sql"),"utf-8")}catch(n){return{ok:!1,message:`Could not read scripts/schema.sql: ${n.message}`}}try{let n=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(n.ok)return{ok:!0};let t=await n.text();return t.includes("already exists")||t.includes('relation "clients" already exists')||t.includes("duplicate")?(i.detail("Schema appears already applied (tables exist). Skipping."),{ok:!0}):{ok:!1,message:`Supabase Management API rejected schema (HTTP ${n.status}): ${t.slice(0,300)}`}}catch(n){return{ok:!1,message:`Schema apply failed: ${n.message}`}}}async function W(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 n=await s.json();return{ok:!0,username:n.user?.username??n.user?.email}}catch(s){return{ok:!1,message:`Could not reach Vercel: ${T(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 n={};try{n=await s.json()}catch{}let t=n.error?.message??"",o=n.error?.status??"";return s.status===400&&(o==="PERMISSION_DENIED"||/Places API \(New\) has not been enabled|API_KEY_SERVICE_BLOCKED/i.test(t))?{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:t||`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}${t?`: ${t}`:""}.`}}catch(s){return{ok:!1,message:`Could not reach Google: ${T(s)}`}}}import Pt from"nodemailer";import{ImapFlow as St}from"imapflow";async function ve(e){let s=Pt.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(t){return{ok:!1,failedAt:"smtp",message:Re(t,"SMTP")}}finally{s.close()}let n=new St({host:e.emailImapHost,port:e.emailImapPort,secure:e.emailImapPort===993,auth:{user:e.emailAddress,pass:e.emailPassword},logger:!1});try{await n.connect(),await n.logout()}catch(t){try{await n.logout()}catch{}return{ok:!1,failedAt:"imap",message:Re(t,"IMAP")}}return{ok:!0}}function Re(e,s){let n=e instanceof Error?e.message:String(e),t=n.toLowerCase();return t.includes("invalid credentials")||t.includes("authentication failed")||t.includes("auth failed")||t.includes("login failed")?`${s} rejected the credentials. Most common causes:
10
+ `}function it(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 v(e){let s={};for(let n of e.split(`
11
+ `)){let t=n.trim();if(!t||t.startsWith("#"))continue;let o=t.indexOf("=");if(o===-1)continue;let a=t.slice(0,o).trim(),l=it(t.slice(o+1).trim());s[a]=l}return s}function ye(e){let s=a=>{let l=e[a];if(!l)return;let c=parseInt(l,10);return isNaN(c)?void 0:c},n=e.SMS_PROVIDER,t=e.OUTREACH_CHANNELS?.split(",").map(a=>a.trim()).filter(a=>a==="email"||a==="sms"),o=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:t&&t.length>0?t:void 0,outreachPriority:o==="email"||o==="sms"?o: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:n==="imessage"||n==="twilio"?n: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 re(e){let s=P=>{let m=e[P];if(!m)return;let E=parseInt(m,10);return isNaN(E)?void 0:E},n=e.SUPABASE_URL,t=e.SUPABASE_SERVICE_KEY,o=e.SUPABASE_PAT,a=e.SUPABASE_PROJECT_REF,l=e.PRICING,c=e.PRICING_TERMS||"one-off, no monthly fees",h=e.VERCEL_TOKEN;if(!l||!n||!t||!o||!a||!h)return null;let r=e.SMS_PROVIDER,w=e.OUTREACH_CHANNELS?.split(",").map(P=>P.trim()).filter(P=>P==="email"||P==="sms"),k=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:w&&w.length>0?w:void 0,outreachPriority:k==="email"||k==="sms"?k: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:r==="imessage"||r==="twilio"?r:void 0,testPhone:e.TEST_PHONE,twilioAccountSid:e.TWILIO_ACCOUNT_SID,twilioAuthToken:e.TWILIO_AUTH_TOKEN,twilioPhoneNumber:e.TWILIO_PHONE_NUMBER,vercelToken:h,vercelScope:e.VERCEL_SCOPE||void 0,supabaseUrl:n,supabaseServiceKey:t,supabasePat:o,supabaseProjectRef:a,googlePlacesApiKey:e.GOOGLE_PLACES_API_KEY,serpapiKey:e.SERPAPI_KEY,telegramBotToken:e.TELEGRAM_BOT_TOKEN,telegramChatId:e.TELEGRAM_CHAT_ID}}import{mkdir as ot,rm as rt}from"fs/promises";import{Readable as at}from"stream";import*as Ee from"tar";var lt="https://klaudius.dev/api/template";function ct(e){return at.fromWeb(e)}async function W(e){let s=process.env.KLAUDIUS_TEMPLATE_URL??lt,n="0.7.2",t;try{t=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:n})})}catch(l){throw new Error(`Could not reach klaudius.dev to download the template: ${A(l)}`)}if(!t.ok){let l="";try{let c=await t.json();l=c.reason?` (${c.reason})`:""}catch{}throw new Error(`Template download failed: HTTP ${t.status}${l}`)}if(!t.body)throw new Error("Template download succeeded but response had no body");let o=t.headers.get("x-klaudius-tier");await ot(e.destDir,{recursive:!0});let a=0;try{await new Promise((l,c)=>{let h=Ee.extract({cwd:e.destDir,strict:!0,onReadEntry:()=>{a++}});h.on("finish",l),h.on("error",c),ct(t.body).on("error",c).pipe(h)})}catch(l){throw await rt(e.destDir,{recursive:!0,force:!0}).catch(()=>{}),new Error(`Failed to extract template archive: ${l.message}`)}return{filesExtracted:a,tier:o}}import{mkdir as dt,readFile as ut,writeFile as pt,access as mt}from"fs/promises";import{dirname as ft,join as Pe}from"path";var ht=".klaudius",be=`${ht}/manifest.json`;async function Se(e){let s=Pe(e,be);try{await mt(s)}catch{return null}let n=await ut(s,"utf-8");return JSON.parse(n)}async function z(e,s){let n=Pe(e,be);await dt(ft(n),{recursive:!0}),await pt(n,JSON.stringify(s,null,2)+`
12
+ `,"utf-8")}function Te(e,s){let n=new Date().toISOString();return{version:1,templateVersion:e,installedAt:n,updatedAt:n,files:s}}import{createHash as gt}from"crypto";import{hostname as Ae,userInfo as kt,platform as _e,arch as Ie}from"os";import O from"picocolors";var i={info:e=>console.log(O.cyan("\u2139"),e),success:e=>console.log(O.green("\u2713"),e),warn:e=>console.log(O.yellow("\u26A0"),e),error:e=>console.error(O.red("\u2717"),e),step:e=>console.log(O.dim("\u2192"),e),blank:()=>console.log(""),heading:e=>console.log(`
13
+ `+O.bold(O.cyan(e))),detail:e=>console.log(O.dim(" "+e))};var wt="https://klaudius.dev",yt="/api/licenses/validate",Et="0.7.2";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(),t=(process.env.KLAUDIUS_API_URL??wt).replace(/\/$/,"")+yt,o=V(),a;try{a=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({license_key:s,machine_id:o,hostname:Ae(),os:`${_e()}-${Ie()}`,cli_version:Et})})}catch(c){return{ok:!1,reason:`Could not reach the Klaudius license server (${A(c)}). Check your internet connection or try again later.`}}let l;try{l=await a.json()}catch{return{ok:!1,reason:`License server returned an unparseable response (HTTP ${a.status}).`}}return l.ok?{ok:!0,tier:l.tier??"core"}:{ok:!1,reason:l.reason??`License rejected (HTTP ${a.status}).`}}function V(){let e=[Ae(),kt().username,_e(),Ie()].join("|");return gt("sha256").update(e).digest("hex").slice(0,32)}import{readFile as Pt}from"fs/promises";import{join as bt}from"path";async function M(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: ${A(s)}`}}}async function ve(e){let s;try{s=await Pt(bt(e.projectRoot,"scripts","schema.sql"),"utf-8")}catch(n){return{ok:!1,message:`Could not read scripts/schema.sql: ${n.message}`}}try{let n=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(n.ok)return{ok:!0};let t=await n.text();return t.includes("already exists")||t.includes('relation "clients" already exists')||t.includes("duplicate")?(i.detail("Schema appears already applied (tables exist). Skipping."),{ok:!0}):{ok:!1,message:`Supabase Management API rejected schema (HTTP ${n.status}): ${t.slice(0,300)}`}}catch(n){return{ok:!1,message:`Schema apply failed: ${n.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 n=await s.json();return{ok:!0,username:n.user?.username??n.user?.email}}catch(s){return{ok:!1,message:`Could not reach Vercel: ${A(s)}`}}}async function J(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 n={};try{n=await s.json()}catch{}let t=n.error?.message??"",o=n.error?.status??"";return s.status===400&&(o==="PERMISSION_DENIED"||/Places API \(New\) has not been enabled|API_KEY_SERVICE_BLOCKED/i.test(t))?{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:t||`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}${t?`: ${t}`:""}.`}}catch(s){return{ok:!1,message:`Could not reach Google: ${A(s)}`}}}import St from"nodemailer";import{ImapFlow as Tt}from"imapflow";async function Oe(e){let s=St.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(t){return{ok:!1,failedAt:"smtp",message:Ce(t,"SMTP")}}finally{s.close()}let n=new Tt({host:e.emailImapHost,port:e.emailImapPort,secure:e.emailImapPort===993,auth:{user:e.emailAddress,pass:e.emailPassword},logger:!1});try{await n.connect(),await n.logout()}catch(t){try{await n.logout()}catch{}return{ok:!1,failedAt:"imap",message:Ce(t,"IMAP")}}return{ok:!0}}function Ce(e,s){let n=e instanceof Error?e.message:String(e),t=n.toLowerCase();return t.includes("invalid credentials")||t.includes("authentication failed")||t.includes("auth failed")||t.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
- \u2022 2FA is required but no app-specific password was generated.`:t.includes("etimedout")||t.includes("timeout")?`${s} server didn't respond in time. Check the host/port, or your network.`:t.includes("enotfound")||t.includes("getaddrinfo")?`${s} host could not be resolved. Check the host setting.`:`${s} check failed: ${n}`}async function Ce(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`,n=Buffer.from(`${e.accountSid}:${e.authToken}`).toString("base64");try{let t=await fetch(s,{headers:{Authorization:`Basic ${n}`}});if(t.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(!t.ok)return{ok:!1,message:`Twilio API returned HTTP ${t.status}. Try again or check status.twilio.com.`};let o=await t.json();return o.status&&o.status!=="active"?{ok:!1,message:`Twilio account is in '${o.status}' state. Check the console for any holds before sending SMS.`}:{ok:!0,friendlyName:o.friendly_name}}catch(t){return{ok:!1,message:`Could not reach Twilio: ${T(t)}`}}}import{spawn as bt}from"child_process";async function Oe(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 n=`tell application "Messages" to send "Klaudius connected (setup ping; ignore)." to buddy "${e.testPhone.replace(/"/g,"")}"`,t=await At(n);if(t.code===0)return{ok:!0};let o=t.stderr.toLowerCase();return o.includes("can't get application")||o.includes("isn't running")||o.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."}:o.includes("(-1728)")||o.includes("not found")||o.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.`}:o.includes("(-1719)")||o.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: ${t.stderr.trim()||`exit code ${t.code}`}`}}function At(e){return new Promise(s=>{let n=bt("osascript",["-e",e],{stdio:["ignore","ignore","pipe"]}),t="";n.stderr.on("data",o=>{t+=o.toString()}),n.on("close",o=>s({code:o??1,stderr:t})),n.on("error",o=>s({code:1,stderr:o.message}))})}import{spawn as Ne}from"child_process";function Tt(){let e=process.env.NODE_OPTIONS?.trim(),s=e?`${e} --use-system-ca`:"--use-system-ca";return{...process.env,NODE_OPTIONS:s}}var M=2,xe=2e3,_t=[/ECONNRESET/,/ETIMEDOUT/,/ENOTFOUND/,/EAI_AGAIN/,/socket hang up/i,/Connection reset/i,/network timeout/i,/could not resolve host/i];function $e(e,s){let n=e+`
17
- `+s;return _t.some(t=>t.test(n))}function Me(e){return new Promise(s=>setTimeout(s,e))}function It(e,s,n){return new Promise(t=>{let o=Ne(e,s,{cwd:n.cwd,stdio:["ignore","pipe","pipe"],shell:!1,env:n.env??process.env}),a="",l="";o.stdout?.on("data",c=>{let h=c.toString();a+=h,process.stdout.write(h)}),o.stderr?.on("data",c=>{let h=c.toString();l+=h,process.stderr.write(h)}),o.on("close",c=>t({code:c??1,stdout:a,stderr:l})),o.on("error",c=>t({code:1,stdout:a,stderr:l+c.message}))})}async function oe(e,s,n){let t={code:0,stdout:"",stderr:""};for(let o=0;o<=M;o++){if(t=await It(e,s,{cwd:n.cwd,env:n.env}),t.code===0||!$e(t.stderr,t.stdout))return t;o<M&&(i.detail(`${n.label} failed with a transient network error \u2014 retrying (${o+2}/${M+1})\u2026`),await Me(xe))}return t}function Rt(e,s,n){return new Promise(t=>{let o=Ne(e,s,{cwd:n.cwd,stdio:["ignore","pipe","pipe"],shell:!1}),a="",l="";o.stdout?.on("data",c=>{a+=c.toString()}),o.stderr?.on("data",c=>{l+=c.toString()}),o.on("close",c=>t({code:c??1,stdout:a,stderr:l})),o.on("error",c=>t({code:1,stdout:a,stderr:l+c.message}))})}var vt=[{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 Ct(e){let s=`${e.stderr??""}
18
- ${e.stdout??""}`;return vt.find(t=>t.pattern.test(s))?.hint}async function Ot(e){let s=["supabase<2.26","python-dotenv","requests","httpx","Pillow"],n=["install","--quiet","--user"],t=async a=>{let l={code:0,stdout:"",stderr:""};for(let c=0;c<=M;c++){if(l=await Rt("pip3",a,{cwd:e}),l.code===0||!$e(l.stderr,l.stdout))return l;c<M&&(i.detail(`pip install hit a transient network error \u2014 retrying (${c+2}/${M+1})\u2026`),await Me(xe))}return l},o=await t([...n,"--break-system-packages",...s]);return o.code!==0&&/no such option:.*break-system-packages/i.test(o.stderr)&&(i.detail("Older pip detected; retrying without --break-system-packages"),o=await t([...n,...s])),o.code!==0&&(o.stderr.trim()&&process.stderr.write(o.stderr),o.stdout.trim()&&process.stdout.write(o.stdout)),o}async function Le(e){let s={npm:"skipped",pip:"skipped",playwright:"skipped",patchright:"skipped"},n=Tt(),t=(h,r)=>{let w=Ct(r);w&&((s.hints??={})[h]=w)};i.step("Running npm install (Next.js, Playwright JS, etc.)...");let o=await oe("npm",["install"],{cwd:e,label:"npm install",env:n});s.npm=o.code===0?"ok":"failed",o.code!==0&&t("npm",o),i.step("Installing Python packages (supabase, dotenv, requests, httpx, Pillow)...");let a=await Ot(e);s.pip=a.code===0?"ok":"failed",a.code!==0&&t("pip",a),i.step("Installing Playwright browser (chromium ~200MB; one-time)...");let l=await oe("npx",["playwright","install","chromium"],{cwd:e,label:"playwright install",env:n});s.playwright=l.code===0?"ok":"failed",l.code!==0&&t("playwright",l),i.step("Installing Patchright browser (chromium ~200MB; one-time)...");let c=await oe("npx",["patchright","install","chromium"],{cwd:e,label:"patchright install",env:n});return s.patchright=c.code===0?"ok":"failed",c.code!==0&&t("patchright",c),s}import{spawn as Nt}from"child_process";var q=3,re=10;async function J(){let e=await xt("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(),n=/Python\s+(\d+)\.(\d+)(?:\.(\d+))?/.exec(s);if(!n)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 t=parseInt(n[1],10),o=parseInt(n[2],10),a=n[3]?`${t}.${o}.${n[3]}`:`${t}.${o}`;return t<q||t===q&&o<re?{ok:!1,version:a,major:t,minor:o,message:`Your installed Python is ${a}. Klaudius needs Python ${q}.${re} or newer (the pipeline depends on packages that only ship wheels for ${q}.${re}+). 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:a,major:t,minor:o}}function xt(e,s){return new Promise(n=>{let t=Nt(e,s,{stdio:["ignore","pipe","pipe"],shell:!1}),o="",a="";t.stdout?.on("data",l=>{o+=l.toString()}),t.stderr?.on("data",l=>{a+=l.toString()}),t.on("close",l=>n({code:l??1,stdout:o,stderr:a})),t.on("error",()=>n({code:1,stdout:o,stderr:a}))})}function X(){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 n=parseInt(s[1],10),t=parseInt(s[2],10),o=parseInt(s[3],10),a=`${n}.${t}.${o}`;return n<22||n===22&&t<15?{ok:!1,version:a,major:n,minor:t,message:`Your installed Node.js is ${a}. 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:a,major:n,minor:t}}import{mkdir as $t,readFile as Mt,writeFile as Lt}from"fs/promises";import{join as Ue}from"path";async function Q(e,s){let n=Ue(e,".claude");await $t(n,{recursive:!0});let t=Ue(n,"settings.json"),o={};try{let h=await Mt(t,"utf-8"),r=JSON.parse(h);r&&typeof r=="object"&&!Array.isArray(r)&&(o=r)}catch{}let a=o.enabledMcpjsonServers,l=Array.isArray(a)?a.filter(h=>typeof h=="string"):[];l.includes(s)||l.push(s);let c={...o,enabledMcpjsonServers:l};await Lt(t,JSON.stringify(c,null,2)+`
19
- `,"utf-8")}var A=5;function L(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 He(e){let s=e.target??".",n=jt(s)?s:Kt(process.cwd(),s),t=await Ht(n);if(t.kind==="occupied"){let u=s===".";i.error("Klaudius needs an empty folder to scaffold into. This directory isn't empty."),i.detail(`Path: ${n}`),i.detail(`Contains: ${t.entries.slice(0,5).join(", ")}${t.entries.length>5?`, \u2026 (+${t.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(` ${m.cyan("npx klaudius init my-agency")}`),i.blank(),i.detail("2. Or cd into an empty folder first, then re-run:"),console.log(` ${m.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(` ${m.cyan(`npx klaudius init ${s}-2`)}`),i.detail("\u2026or delete the existing folder if it's safe to remove.")),process.exit(1)}let o=await Bt(e.license),a=g.spinner();a.start("Validating license");let l=await _e(o);l.ok||(a.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)),a.stop(`License valid (${l.tier??"core"} tier)`);let c=await J();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 h=X();h.ok||(i.error(h.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 r,w=!1;if(t.kind==="partial")if(await Vt(n)==="resume"){let f=await De(t.envPath,"utf-8"),d=ie(v(f));d?(i.success("Resuming with values from your existing .env"),i.detail("(Skipping the wizard \u2014 edit .env directly if you need to change anything.)"),r=d,w=!0):(i.warn("Existing .env was missing required fields \u2014 starting wizard fresh."),r=await b())}else{let f=await De(t.envPath,"utf-8"),d=ie(v(f));r=await b(d??{})}else r=await b();r.licenseKey=o,await C(n,r),w||(i.success("Saved .env"),i.success("Saved .mcp.json")),i.blank();for(let u=1;;u++){let f=g.spinner();f.start("Validating Supabase credentials");let d=await $({url:r.supabaseUrl,serviceKey:r.supabaseServiceKey});if(d.ok){f.stop("Supabase credentials accepted");break}f.stop(d.message??"Supabase check failed",2),u>=A&&L("Supabase",d.message??"Supabase check failed");let y=d.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(),r=await b(r,{onlySection:"supabase",banner:`Supabase rejected your credentials:
16
+ \u2022 2FA is required but no app-specific password was generated.`:t.includes("etimedout")||t.includes("timeout")?`${s} server didn't respond in time. Check the host/port, or your network.`:t.includes("enotfound")||t.includes("getaddrinfo")?`${s} host could not be resolved. Check the host setting.`:`${s} check failed: ${n}`}async function Ne(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`,n=Buffer.from(`${e.accountSid}:${e.authToken}`).toString("base64");try{let t=await fetch(s,{headers:{Authorization:`Basic ${n}`}});if(t.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(!t.ok)return{ok:!1,message:`Twilio API returned HTTP ${t.status}. Try again or check status.twilio.com.`};let o=await t.json();return o.status&&o.status!=="active"?{ok:!1,message:`Twilio account is in '${o.status}' state. Check the console for any holds before sending SMS.`}:{ok:!0,friendlyName:o.friendly_name}}catch(t){return{ok:!1,message:`Could not reach Twilio: ${A(t)}`}}}import{spawn as At}from"child_process";async function $e(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 n=`tell application "Messages" to send "Klaudius connected (setup ping; ignore)." to buddy "${e.testPhone.replace(/"/g,"")}"`,t=await _t(n);if(t.code===0)return{ok:!0};let o=t.stderr.toLowerCase();return o.includes("can't get application")||o.includes("isn't running")||o.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."}:o.includes("(-1728)")||o.includes("not found")||o.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.`}:o.includes("(-1719)")||o.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: ${t.stderr.trim()||`exit code ${t.code}`}`}}function _t(e){return new Promise(s=>{let n=At("osascript",["-e",e],{stdio:["ignore","ignore","pipe"]}),t="";n.stderr.on("data",o=>{t+=o.toString()}),n.on("close",o=>s({code:o??1,stderr:t})),n.on("error",o=>s({code:1,stderr:o.message}))})}import{spawn as xe}from"child_process";function It(){let e=process.env.NODE_OPTIONS?.trim(),s=e?`${e} --use-system-ca`:"--use-system-ca";return{...process.env,NODE_OPTIONS:s}}var L=2,Me=2e3,Rt=[/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 n=e+`
17
+ `+s;return Rt.some(t=>t.test(n))}function Ue(e){return new Promise(s=>setTimeout(s,e))}function vt(e,s,n){return new Promise(t=>{let o=xe(e,s,{cwd:n.cwd,stdio:["ignore","pipe","pipe"],shell:!1,env:n.env??process.env}),a="",l="";o.stdout?.on("data",c=>{let h=c.toString();a+=h,process.stdout.write(h)}),o.stderr?.on("data",c=>{let h=c.toString();l+=h,process.stderr.write(h)}),o.on("close",c=>t({code:c??1,stdout:a,stderr:l})),o.on("error",c=>t({code:1,stdout:a,stderr:l+c.message}))})}async function ae(e,s,n){let t={code:0,stdout:"",stderr:""};for(let o=0;o<=L;o++){if(t=await vt(e,s,{cwd:n.cwd,env:n.env}),t.code===0||!Le(t.stderr,t.stdout))return t;o<L&&(i.detail(`${n.label} failed with a transient network error \u2014 retrying (${o+2}/${L+1})\u2026`),await Ue(Me))}return t}function Ct(e,s,n){return new Promise(t=>{let o=xe(e,s,{cwd:n.cwd,stdio:["ignore","pipe","pipe"],shell:!1}),a="",l="";o.stdout?.on("data",c=>{a+=c.toString()}),o.stderr?.on("data",c=>{l+=c.toString()}),o.on("close",c=>t({code:c??1,stdout:a,stderr:l})),o.on("error",c=>t({code:1,stdout:a,stderr:l+c.message}))})}var Ot=[{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
+ ${e.stdout??""}`;return Ot.find(t=>t.pattern.test(s))?.hint}async function $t(e){let s=["supabase<2.26","python-dotenv","requests","httpx","Pillow","truststore"],n=["install","--quiet","--user"],t=async a=>{let l={code:0,stdout:"",stderr:""};for(let c=0;c<=L;c++){if(l=await Ct("pip3",a,{cwd:e}),l.code===0||!Le(l.stderr,l.stdout))return l;c<L&&(i.detail(`pip install hit a transient network error \u2014 retrying (${c+2}/${L+1})\u2026`),await Ue(Me))}return l},o=await t([...n,"--break-system-packages",...s]);return o.code!==0&&/no such option:.*break-system-packages/i.test(o.stderr)&&(i.detail("Older pip detected; retrying without --break-system-packages"),o=await t([...n,...s])),o.code!==0&&(o.stderr.trim()&&process.stderr.write(o.stderr),o.stdout.trim()&&process.stdout.write(o.stdout)),o}async function De(e){let s={npm:"skipped",pip:"skipped",playwright:"skipped",patchright:"skipped"},n=It(),t=(h,r)=>{let w=Nt(r);w&&((s.hints??={})[h]=w)};i.step("Running npm install (Next.js, Playwright JS, etc.)...");let o=await ae("npm",["install"],{cwd:e,label:"npm install",env:n});s.npm=o.code===0?"ok":"failed",o.code!==0&&t("npm",o),i.step("Installing Python packages (supabase, dotenv, requests, httpx, Pillow)...");let a=await $t(e);s.pip=a.code===0?"ok":"failed",a.code!==0&&t("pip",a),i.step("Installing Playwright browser (chromium ~200MB; one-time)...");let l=await ae("npx",["playwright","install","chromium"],{cwd:e,label:"playwright install",env:n});s.playwright=l.code===0?"ok":"failed",l.code!==0&&t("playwright",l),i.step("Installing Patchright browser (chromium ~200MB; one-time)...");let c=await ae("npx",["patchright","install","chromium"],{cwd:e,label:"patchright install",env:n});return s.patchright=c.code===0?"ok":"failed",c.code!==0&&t("patchright",c),s}import{spawn as xt}from"child_process";var X=3,le=10;async function Q(){let e=await Mt("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(),n=/Python\s+(\d+)\.(\d+)(?:\.(\d+))?/.exec(s);if(!n)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 t=parseInt(n[1],10),o=parseInt(n[2],10),a=n[3]?`${t}.${o}.${n[3]}`:`${t}.${o}`;return t<X||t===X&&o<le?{ok:!1,version:a,major:t,minor:o,message:`Your installed Python is ${a}. Klaudius needs Python ${X}.${le} or newer (the pipeline depends on packages that only ship wheels for ${X}.${le}+). 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:a,major:t,minor:o}}function Mt(e,s){return new Promise(n=>{let t=xt(e,s,{stdio:["ignore","pipe","pipe"],shell:!1}),o="",a="";t.stdout?.on("data",l=>{o+=l.toString()}),t.stderr?.on("data",l=>{a+=l.toString()}),t.on("close",l=>n({code:l??1,stdout:o,stderr:a})),t.on("error",()=>n({code:1,stdout:o,stderr:a}))})}function Z(){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 n=parseInt(s[1],10),t=parseInt(s[2],10),o=parseInt(s[3],10),a=`${n}.${t}.${o}`;return n<22||n===22&&t<15?{ok:!1,version:a,major:n,minor:t,message:`Your installed Node.js is ${a}. 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:a,major:n,minor:t}}import{mkdir as Lt,readFile as Ut,writeFile as Dt}from"fs/promises";import{join as Ke}from"path";async function ee(e,s){let n=Ke(e,".claude");await Lt(n,{recursive:!0});let t=Ke(n,"settings.json"),o={};try{let h=await Ut(t,"utf-8"),r=JSON.parse(h);r&&typeof r=="object"&&!Array.isArray(r)&&(o=r)}catch{}let a=o.enabledMcpjsonServers,l=Array.isArray(a)?a.filter(h=>typeof h=="string"):[];l.includes(s)||l.push(s);let c={...o,enabledMcpjsonServers:l};await Dt(t,JSON.stringify(c,null,2)+`
19
+ `,"utf-8")}var T=5;function U(e,s){i.blank(),i.error(`${e} validation failed ${T} 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??".",n=Ht(s)?s:jt(process.cwd(),s),t=await Vt(n);if(t.kind==="scaffolded"){i.blank(),i.warn(`Found an existing Klaudius project at ${d.bold(n)}.`),i.detail("(Your .env and project files are in place.)"),i.blank(),t.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(),n!==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(t.kind==="occupied"){let p=s===".";i.error("Klaudius needs an empty folder to scaffold into. This directory isn't empty."),i.detail(`Path: ${n}`),i.detail(`Contains: ${t.entries.slice(0,5).join(", ")}${t.entries.length>5?`, \u2026 (+${t.entries.length-5} more)`:""}`),i.blank(),p?(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 o=await Ft(e.license),a=g.spinner();a.start("Validating license");let l=await Re(o);l.ok||(a.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)),a.stop(`License valid (${l.tier??"core"} tier)`);let c=await Q();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 h=Z();h.ok||(i.error(h.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 r,w=!1;if(t.kind==="partial")if(await Bt(n)==="resume"){let f=await je(t.envPath,"utf-8"),u=re(v(f));u?(i.success("Resuming with values from your existing .env"),i.detail("(Skipping the wizard \u2014 edit .env directly if you need to change anything.)"),r=u,w=!0):(i.warn("Existing .env was missing required fields \u2014 starting wizard fresh."),r=await S())}else{let f=await je(t.envPath,"utf-8"),u=re(v(f));r=await S(u??{})}else r=await S();r.licenseKey=o,await C(n,r),w||(i.success("Saved .env"),i.success("Saved .mcp.json")),i.blank();for(let p=1;;p++){let f=g.spinner();f.start("Validating Supabase credentials");let u=await M({url:r.supabaseUrl,serviceKey:r.supabaseServiceKey});if(u.ok){f.stop("Supabase credentials accepted");break}f.stop(u.message??"Supabase check failed",2),p>=T&&U("Supabase",u.message??"Supabase check failed");let y=u.message??"Supabase check failed";i.blank(),i.warn(`Bouncing you back into the Supabase section so you can fix it in place. (attempt ${p+1} of ${T})`),i.detail("(Press Enter through any field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await S(r,{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
23
- field to keep what's already there.`}),await C(n,r)}i.blank();for(let u=1;;u++){let f=g.spinner();f.start("Validating Vercel token");let d=await W(r.vercelToken);if(d.ok){f.stop(d.username?`Vercel token accepted (signed in as ${d.username})`:"Vercel token accepted");break}f.stop(d.message??"Vercel check failed",2),u>=A&&L("Vercel",d.message??"Vercel check failed");let y=d.message??"Vercel check failed";i.blank(),i.warn(`Bouncing you back into the Vercel section so you can fix it in place. (attempt ${u+1} of ${A})`),i.detail("(Press Enter on the field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await b(r,{onlySection:"vercel",banner:`Vercel rejected the token:
23
+ field to keep what's already there.`}),await C(n,r)}i.blank();for(let p=1;;p++){let f=g.spinner();f.start("Validating Vercel token");let u=await q(r.vercelToken);if(u.ok){f.stop(u.username?`Vercel token accepted (signed in as ${u.username})`:"Vercel token accepted");break}f.stop(u.message??"Vercel check failed",2),p>=T&&U("Vercel",u.message??"Vercel check failed");let y=u.message??"Vercel check failed";i.blank(),i.warn(`Bouncing you back into the Vercel section so you can fix it in place. (attempt ${p+1} of ${T})`),i.detail("(Press Enter on the field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await S(r,{onlySection:"vercel",banner:`Vercel rejected the token:
24
24
  ${y}
25
25
 
26
26
  Generate a new token at https://vercel.com/account/tokens and
27
- paste it below. Press Enter to keep the current value.`}),await C(n,r)}i.blank();for(let u=1;;u++){let f=g.spinner();f.start("Validating Google Places API key");let d=await z(r.googlePlacesApiKey??"");if(d.ok){f.stop("Google Places API key accepted");break}f.stop(d.message??"Google Places check failed",2),u>=A&&L("Google Places",d.message??"Google Places check failed");let y=d.message??"Google Places check failed";i.blank(),i.warn(`Bouncing you back into the Google Places section so you can fix it in place. (attempt ${u+1} of ${A})`),i.detail("(Press Enter on the field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await b(r,{onlySection:"google-places",banner:`Google rejected the key:
27
+ paste it below. Press Enter to keep the current value.`}),await C(n,r)}i.blank();for(let p=1;;p++){let f=g.spinner();f.start("Validating Google Places API key");let u=await J(r.googlePlacesApiKey??"");if(u.ok){f.stop("Google Places API key accepted");break}f.stop(u.message??"Google Places check failed",2),p>=T&&U("Google Places",u.message??"Google Places check failed");let y=u.message??"Google Places check failed";i.blank(),i.warn(`Bouncing you back into the Google Places section so you can fix it in place. (attempt ${p+1} of ${T})`),i.detail("(Press Enter on the field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await S(r,{onlySection:"google-places",banner:`Google rejected the key:
28
28
  ${y}
29
29
 
30
30
  Generate (or fix) the key at https://console.cloud.google.com
31
- and paste it below. Press Enter to keep the current value.`}),await C(n,r)}if(r.outreachEnabled&&r.outreachChannels?.includes("email")&&r.emailAddress&&r.emailPassword&&r.emailSmtpHost&&r.emailSmtpPort&&r.emailImapHost&&r.emailImapPort){i.blank();for(let u=1;;u++){let f=g.spinner();f.start("Validating email credentials (SMTP + IMAP)");let d=await ve({emailAddress:r.emailAddress,emailPassword:r.emailPassword,emailSmtpHost:r.emailSmtpHost,emailSmtpPort:r.emailSmtpPort,emailImapHost:r.emailImapHost,emailImapPort:r.emailImapPort});if(d.ok){f.stop("Email credentials accepted (SMTP + IMAP)");break}f.stop(d.message??"Email check failed",2),u>=A&&L("Email",d.message??"Email check failed");let y=d.message??"Email check failed";i.blank(),i.warn(`Bouncing you back into the email section so you can fix it in place. (attempt ${u+1} of ${A})`),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await b(r,{onlySection:"email",banner:`${d.failedAt==="imap"?"IMAP":"SMTP"} check failed:
31
+ and paste it below. Press Enter to keep the current value.`}),await C(n,r)}if(r.outreachEnabled&&r.outreachChannels?.includes("email")&&r.emailAddress&&r.emailPassword&&r.emailSmtpHost&&r.emailSmtpPort&&r.emailImapHost&&r.emailImapPort){i.blank();for(let p=1;;p++){let f=g.spinner();f.start("Validating email credentials (SMTP + IMAP)");let u=await Oe({emailAddress:r.emailAddress,emailPassword:r.emailPassword,emailSmtpHost:r.emailSmtpHost,emailSmtpPort:r.emailSmtpPort,emailImapHost:r.emailImapHost,emailImapPort:r.emailImapPort});if(u.ok){f.stop("Email credentials accepted (SMTP + IMAP)");break}f.stop(u.message??"Email check failed",2),p>=T&&U("Email",u.message??"Email check failed");let y=u.message??"Email check failed";i.blank(),i.warn(`Bouncing you back into the email section so you can fix it in place. (attempt ${p+1} of ${T})`),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await S(r,{onlySection:"email",banner:`${u.failedAt==="imap"?"IMAP":"SMTP"} check failed:
32
32
  ${y}
33
33
 
34
34
  Re-enter the email address, app password, or host details below.
35
- Press Enter on any field to keep its current value.`}),await C(n,r)}}if(r.outreachEnabled&&r.outreachChannels?.includes("sms")&&r.smsProvider==="twilio"&&r.twilioAccountSid&&r.twilioAuthToken){i.blank();for(let u=1;;u++){let f=g.spinner();f.start("Validating Twilio credentials");let d=await Ce({accountSid:r.twilioAccountSid,authToken:r.twilioAuthToken});if(d.ok){f.stop(d.friendlyName?`Twilio credentials accepted (${d.friendlyName})`:"Twilio credentials accepted");break}f.stop(d.message??"Twilio check failed",2),u>=A&&L("Twilio",d.message??"Twilio check failed");let y=d.message??"Twilio check failed";i.blank(),i.warn(`Bouncing you back into the SMS section so you can fix it in place. (attempt ${u+1} of ${A})`),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await b(r,{onlySection:"sms",banner:`Twilio rejected the credentials:
35
+ Press Enter on any field to keep its current value.`}),await C(n,r)}}if(r.outreachEnabled&&r.outreachChannels?.includes("sms")&&r.smsProvider==="twilio"&&r.twilioAccountSid&&r.twilioAuthToken){i.blank();for(let p=1;;p++){let f=g.spinner();f.start("Validating Twilio credentials");let u=await Ne({accountSid:r.twilioAccountSid,authToken:r.twilioAuthToken});if(u.ok){f.stop(u.friendlyName?`Twilio credentials accepted (${u.friendlyName})`:"Twilio credentials accepted");break}f.stop(u.message??"Twilio check failed",2),p>=T&&U("Twilio",u.message??"Twilio check failed");let y=u.message??"Twilio check failed";i.blank(),i.warn(`Bouncing you back into the SMS section so you can fix it in place. (attempt ${p+1} of ${T})`),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await S(r,{onlySection:"sms",banner:`Twilio rejected the credentials:
36
36
  ${y}
37
37
 
38
38
  Re-enter the Account SID or Auth Token below.
39
- Press Enter on any field to keep its current value.`}),await C(n,r)}}if(r.outreachEnabled&&r.outreachChannels?.includes("sms")&&r.smsProvider==="imessage"&&r.testPhone){i.blank();for(let u=1;;u++){let f=g.spinner();f.start("Validating iMessage setup (sending a test ping)");let d=await Oe({testPhone:r.testPhone});if(d.ok){f.stop("iMessage dispatched (check your phone for the test ping)");break}f.stop(d.message??"iMessage check failed",2),u>=A&&L("iMessage",d.message??"iMessage check failed");let y=d.message??"iMessage check failed";i.blank(),i.warn(`Bouncing you back into the SMS section so you can fix it in place. (attempt ${u+1} of ${A})`),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await b(r,{onlySection:"sms",banner:`iMessage check failed:
39
+ Press Enter on any field to keep its current value.`}),await C(n,r)}}if(r.outreachEnabled&&r.outreachChannels?.includes("sms")&&r.smsProvider==="imessage"&&r.testPhone){i.blank();for(let p=1;;p++){let f=g.spinner();f.start("Validating iMessage setup (sending a test ping)");let u=await $e({testPhone:r.testPhone});if(u.ok){f.stop("iMessage dispatched (check your phone for the test ping)");break}f.stop(u.message??"iMessage check failed",2),p>=T&&U("iMessage",u.message??"iMessage check failed");let y=u.message??"iMessage check failed";i.blank(),i.warn(`Bouncing you back into the SMS section so you can fix it in place. (attempt ${p+1} of ${T})`),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await S(r,{onlySection:"sms",banner:`iMessage check failed:
40
40
  ${y}
41
41
 
42
42
  Either fix the underlying issue (sign in to Messages.app, configure
43
43
  Text Message Forwarding) and press Enter through, or change SMS
44
- provider to Twilio.`}),await C(n,r)}}if(r.telegramBotToken&&r.telegramChatId){i.blank();let u=0,f=!1;for(;!f;){u++;let d=g.spinner();d.start("Validating Telegram bot + chat (sending a test ping)");let y=await fe({botToken:r.telegramBotToken,chatId:r.telegramChatId});if(y.ok){d.stop(y.botHandle?`Telegram bot ${y.botHandle} accepted, test message delivered`:"Telegram credentials accepted, test message delivered"),f=!0;break}d.stop(y.message??"Telegram check failed",2);let Qe=y.message??"Telegram check failed";i.blank(),i.warn("Telegram is optional \u2014 you can skip it now and wire it up later by editing `.env`."),i.blank();let se=await g.select({message:"What would you like to do?",initialValue:u>=2?"skip":"retry",options:[{value:"retry",label:"Retry the check (good if it was a momentary network blip)"},{value:"edit",label:"Edit my bot token / chat ID and retry"},{value:"skip",label:"Skip Telegram for now (I'll add it later by editing .env)"}]});if(g.isCancel(se)&&(g.cancel("Setup cancelled. Your .env is saved \u2014 re-run `klaudius init` to resume."),process.exit(0)),se==="skip"){r.telegramBotToken=void 0,r.telegramChatId=void 0,await C(n,r),i.success("Skipped Telegram. Setup will continue."),i.detail("Wire it up later by pasting your bot token and chat ID into the TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID lines of `.env`."),f=!0;break}if(se==="edit"&&(i.blank(),r=await b(r,{onlySection:"telegram",banner:`Telegram check failed:
45
- ${Qe}
44
+ provider to Twilio.`}),await C(n,r)}}if(r.telegramBotToken&&r.telegramChatId){i.blank();let p=0,f=!1;for(;!f;){p++;let u=g.spinner();u.start("Validating Telegram bot + chat (sending a test ping)");let y=await ge({botToken:r.telegramBotToken,chatId:r.telegramChatId});if(y.ok){u.stop(y.botHandle?`Telegram bot ${y.botHandle} accepted, test message delivered`:"Telegram credentials accepted, test message delivered"),f=!0;break}u.stop(y.message??"Telegram check failed",2);let et=y.message??"Telegram check failed";i.blank(),i.warn("Telegram is optional \u2014 you can skip it now and wire it up later by editing `.env`."),i.blank();let ie=await g.select({message:"What would you like to do?",initialValue:p>=2?"skip":"retry",options:[{value:"retry",label:"Retry the check (good if it was a momentary network blip)"},{value:"edit",label:"Edit my bot token / chat ID and retry"},{value:"skip",label:"Skip Telegram for now (I'll add it later by editing .env)"}]});if(g.isCancel(ie)&&(g.cancel("Setup cancelled. Your .env is saved \u2014 re-run `klaudius init` to resume."),process.exit(0)),ie==="skip"){r.telegramBotToken=void 0,r.telegramChatId=void 0,await C(n,r),i.success("Skipped Telegram. Setup will continue."),i.detail("Wire it up later by pasting your bot token and chat ID into the TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID lines of `.env`."),f=!0;break}if(ie==="edit"&&(i.blank(),r=await S(r,{onlySection:"telegram",banner:`Telegram check failed:
45
+ ${et}
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 C(n,r),!r.telegramBotToken||!r.telegramChatId)){i.success("Skipped Telegram. Setup will continue."),f=!0;break}}}i.blank();let k=g.spinner();k.start("Downloading Klaudius template");let P;try{P=(await G({licenseKey:o,machineId:H(),hostname:process.platform==="win32"?process.env.COMPUTERNAME:void 0,os:`${process.platform}-${process.arch}`,destDir:n})).filesExtracted,k.stop(`Downloaded ${P} files into ${m.bold(n)}`)}catch(u){k.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 je(Z(n,"clients"),{recursive:!0});let p=await he(n);await Y(n,Se("0.1.0",p)),i.success("Wrote .klaudius/manifest.json");let E=!1,R="";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: ${r.supabaseUrl.replace("https://","https://supabase.com/dashboard/project/"+r.supabaseProjectRef+"/sql/new").replace(r.supabaseProjectRef+".supabase.co","")}`);else{i.blank();let u=g.spinner();u.start("Applying schema to Supabase");let f=await Ie({projectRoot:n,pat:r.supabasePat,projectRef:r.supabaseProjectRef});f.ok?u.stop("Schema applied (or already present)"):(u.stop(f.message??"Schema apply failed",2),E=!0,R=`https://supabase.com/dashboard/project/${r.supabaseProjectRef}/sql/new`)}let _=[],V={};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 Le(n);i.detail(`npm: ${u.npm}, pip: ${u.pip}, playwright: ${u.playwright}, patchright: ${u.patchright}`),u.npm==="failed"&&_.push("npm"),u.pip==="failed"&&_.push("pip"),u.playwright==="failed"&&_.push("playwright"),u.patchright==="failed"&&_.push("patchright"),V=u.hints??{}}i.blank();let de=[..._,...E?["schema"]:[]];if(de.length>0){g.outro(m.yellow(m.bold(`Setup paused \u2014 ${de.join(", ")} failed.`))),console.log(m.dim("Your credentials and project files are all saved.")),i.blank();for(let[d,y]of Object.entries(V))console.log(m.yellow(`Likely cause of ${d} failure:`)),console.log(m.dim(` ${y}`)),i.blank();console.log(m.dim("To finish, once you've addressed any causes above:")),i.blank(),n!==process.cwd()&&console.log(` ${m.cyan(`cd ${e.target}`)}`),_.length>0&&console.log(` ${m.cyan("bash setup.sh")} ${m.dim("# retry the failing installers")}`),E&&(console.log(m.dim(" Apply scripts/schema.sql in the Supabase SQL editor:")),console.log(` ${m.cyan(R)}`),console.log(m.dim(" Open scripts/schema.sql, copy the contents, paste into the editor, click Run."))),i.blank(),_.includes("pip")&&!V.pip&&(console.log(m.dim("If pip fails again with a build error, check `python3 --version` \u2014 Klaudius needs")),console.log(m.dim("Python 3.10+. Install a newer one from https://www.python.org/downloads/macos/")),console.log(m.dim("and open a fresh Terminal before retrying.")),i.blank());let f=["npm","playwright","patchright"].filter(d=>_.includes(d)&&!V[d]);if(f.length>0){let d=f.length===1?"keeps":"keep";console.log(m.dim(`If ${f.join(" / ")} ${d} failing with network errors (ECONNRESET,`)),console.log(m.dim("ETIMEDOUT, ENOTFOUND), they're transient \u2014 try a different network or your")),console.log(m.dim("phone's hotspot, then re-run `bash setup.sh`.")),i.blank()}console.log(m.dim("For a structured diagnostic of every check (Python / Node / installers / files)")),console.log(m.dim(`run ${m.cyan("klaudius doctor")} in this folder.`)),i.blank(),console.log(m.dim("Stuck? Email hello@klaudius.dev with the last ~20 lines of the install output.")),i.blank();return}g.outro(m.green(m.bold("Project ready."))),console.log(m.dim("Next steps:")),n!==process.cwd()&&console.log(` ${m.cyan(`cd ${e.target}`)}`),console.log(` ${m.cyan("claude")} ${m.dim("# open Claude Code in this project")}`),console.log(` ${m.dim("then ask Claude:")}`),console.log(` ${m.cyan(' "Run the pipeline."')}`),i.blank(),console.log(m.dim("Klaudius ships with sensible defaults for tone, follow-up cadence, pitch")),console.log(m.dim("and more \u2014 but you don't have to live with them. Customise by talking to")),console.log(m.dim("Claude inside this project. Examples you can ask:")),console.log(m.dim(' "Make the outreach more casual."')),console.log(m.dim(' "Change the follow-up cadence to weekly."')),console.log(m.dim(` "Don't pitch businesses with fewer than 5 reviews."`)),console.log(m.dim(' "Use a different opening hook for restaurants."')),console.log(m.dim("Claude knows where to make the change \u2014 no config files to edit by hand.")),i.blank()}async function C(e,s){await je(e,{recursive:!0}),await Ke(Z(e,".env"),B(s),"utf-8"),await Ke(Z(e,".mcp.json"),F(s),"utf-8"),await Q(e,"supabase")}async function Ht(e){try{(await Dt(e)).isDirectory()||(i.error(`Target exists but is not a directory: ${e}`),process.exit(1))}catch{return{kind:"fresh"}}let s=await Ut(e),n=s.filter(c=>!c.startsWith(".DS_Store"));if(n.length===0)return{kind:"fresh"};let t=new Set([".env",".mcp.json",".claude"]),o=n.every(c=>t.has(c)),a=n.includes(".env"),l=s.includes(".klaudius");return o&&a&&!l?{kind:"partial",envPath:Z(e,".env")}:{kind:"occupied",entries:n}}async function Vt(e){i.blank(),i.warn(`Found a partial setup at ${m.bold(e)}.`),i.detail(`A previous init wrote ${m.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 Bt(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:n=>n.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 Ft,writeFile as Ve,access as Gt}from"fs/promises";import{join as ae}from"path";import*as ee from"@clack/prompts";import Yt from"picocolors";async function Fe(e){let s=e.projectRoot??process.cwd(),n=ae(s,".env"),t=ae(s,".mcp.json"),o=await Be(ae(s,".klaudius","manifest.json")),a=await Be(n);!o&&!a&&(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=X();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 w=await Ft(n,"utf-8");c=v(w)}catch{i.warn("No .env found. Starting from an empty configuration.")}let h=ke(c);ee.intro("Reconfigure Klaudius"),i.detail("Press Enter on any prompt to keep its current value."),i.blank();let r=await b(h);if(r.supabaseUrl!==c.SUPABASE_URL||r.supabaseServiceKey!==c.SUPABASE_SERVICE_KEY){i.heading("Re-validating Supabase credentials");let w=await $({url:r.supabaseUrl,serviceKey:r.supabaseServiceKey});w.ok||(i.error(w.message??"Supabase check failed"),i.warn("Aborting. .env not modified."),process.exit(1)),i.success("Supabase credentials accepted")}await Ve(n,B(r),"utf-8"),i.success("Updated .env"),await Ve(t,F(r),"utf-8"),i.success("Updated .mcp.json"),await Q(s,"supabase"),i.blank(),ee.outro(Yt.green("Configuration updated."))}async function Be(e){try{return await Gt(e),!0}catch{return!1}}import{copyFile as Ge,mkdir as Ye,readdir as Wt,readFile as zt,rm as te,writeFile as We,access as qt}from"fs/promises";import{dirname as ze,join as I,relative as Jt}from"path";import{tmpdir as Xt}from"os";import*as D from"@clack/prompts";import le from"picocolors";var ce="0.7.0";async function qe(e){let s=e.projectRoot??process.cwd(),n=await Pe(s);n||(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 t,o=I(s,".env");try{let p=await zt(o,"utf-8"),E=v(p);t=E.KLAUDIUS_LICENSE_KEY??"",t||(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 R=ge(p,E,[{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)."}]);R!==null&&(await We(o,R,"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)}D.intro(`Update from ${n.templateVersion} \u2192 ${ce}`);let a=I(Xt(),`klaudius-update-${process.pid}-${Date.now()}`),l;try{i.heading("Downloading the latest Klaudius template");let p=await G({licenseKey:t,machineId:H(),hostname:process.env.HOSTNAME??process.env.COMPUTERNAME,os:`${process.platform}-${process.arch}`,destDir:a});i.success(`Fetched ${p.filesExtracted} canonical files`),l=a}catch(p){i.error(p.message),i.detail("Update aborted. Your project is unchanged."),await te(a,{recursive:!0,force:!0}).catch(()=>{}),process.exit(1)}let c=await Qt(l,s,n),h=c.filter(p=>p.state==="new"),r=c.filter(p=>p.state==="clean-update"),w=c.filter(p=>p.state==="user-only"),k=c.filter(p=>p.state==="conflict"),P=c.filter(p=>p.state==="no-change");if(i.blank(),i.heading("Change summary"),i.detail(`${U(P.length,"file")} unchanged`),i.detail(`${U(h.length,"new file")}`),i.detail(`${U(r.length,"file")} updated cleanly (no local edits)`),i.detail(`${U(w.length,"file")} you've edited (no upstream change \u2014 left alone)`),i.detail(`${U(k.length,"file")} with conflicts (you edited AND we have a new version)`),r.length===0&&h.length===0&&k.length===0){i.blank(),D.outro(le.green("Already up to date.")),await te(a,{recursive:!0,force:!0}).catch(()=>{});return}i.blank(),i.heading("Applying clean updates");for(let p of[...h,...r]){let E=I(l,p.path),R=I(s,p.path);await Ye(ze(R),{recursive:!0}),await Ge(E,R),n.files[p.path]=p.canonicalHash}if(i.success(`Wrote ${U(h.length+r.length,"file")}`),k.length>0){i.blank(),i.heading(`${k.length} conflict(s) need resolution`);let p=I(s,".klaudius","incoming");try{await te(p,{recursive:!0,force:!0})}catch{}for(let E of k){let R=I(l,E.path),_=I(p,E.path);await Ye(ze(_),{recursive:!0}),await Ge(R,_)}await We(I(s,".klaudius","conflicts.md"),Zt(k,n.templateVersion,ce),"utf-8"),i.detail("Staged canonical versions to .klaudius/incoming/"),i.detail("Wrote conflict report to .klaudius/conflicts.md")}n.updatedAt=new Date().toISOString(),k.length===0&&(n.templateVersion=ce),await Y(s,n),i.blank(),k.length===0?D.outro(le.green("Update complete.")):D.outro(le.yellow(`${k.length} conflict(s) staged. Open Claude Code in this project and ask:
49
- "Run /resolve-conflicts"`)),await te(a,{recursive:!0,force:!0}).catch(()=>{})}async function Qt(e,s,n){let t=await Je(e),o=[];for(let a of t){let l=await ne(I(e,a)),c=n.files[a],h=I(s,a),r;try{await qt(h),r=await ne(h)}catch{o.push({path:a,state:"new",canonicalHash:l,manifestHash:c});continue}l===c?r===c?o.push({path:a,state:"no-change",canonicalHash:l,localHash:r,manifestHash:c}):o.push({path:a,state:"user-only",canonicalHash:l,localHash:r,manifestHash:c}):r===c?o.push({path:a,state:"clean-update",canonicalHash:l,localHash:r,manifestHash:c}):o.push({path:a,state:"conflict",canonicalHash:l,localHash:r,manifestHash:c})}return o}function U(e,s){return`${e} ${s}${e===1?"":"s"}`}async function Je(e,s=e){let n=await Wt(e,{withFileTypes:!0}),t=[];for(let o of n){let a=I(e,o.name);o.isDirectory()?t.push(...await Je(a,s)):o.isFile()&&t.push(Jt(s,a))}return t}function Zt(e,s,n){let t=[];t.push("# Update Conflicts"),t.push(""),t.push(`Generated by \`npx klaudius update\` on ${new Date().toISOString()}.`),t.push(`Updating from canonical version **${s}** to **${n}**.`),t.push(""),t.push(`${e.length} file${e.length===1?"":"s"} ha${e.length===1?"s":"ve"} BOTH local edits AND upstream changes.`),t.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, or merge."),t.push(""),t.push("---"),t.push("");for(let o of e)t.push(`## ${o.path}`),t.push(""),t.push(`- Your version (with your local edits): \`${o.path}\``),t.push(`- New canonical version: \`.klaudius/incoming/${o.path}\``),t.push(`- Hash at last install/update: \`${(o.manifestHash??"(none)").slice(0,16)}\``),t.push(`- Your local hash now: \`${(o.localHash??"(missing)").slice(0,16)}\``),t.push(`- New canonical hash: \`${o.canonicalHash.slice(0,16)}\``),t.push(""),t.push("**Resolution options for the SKILL to walk through:**"),t.push(""),t.push("1. Keep mine \u2014 discard the new canonical changes"),t.push("2. Take canonical \u2014 overwrite my edits with the new version"),t.push("3. Merge \u2014 review both side-by-side and produce a combined version"),t.push(""),t.push("---"),t.push("");return t.join(`
50
- `)}import{access as es,readFile as ts,stat as ss}from"fs/promises";import{join as N}from"path";import S from"picocolors";import{spawn as ns}from"child_process";async function Xe(e){let s=e.projectRoot??process.cwd(),n=[];console.log(S.bold(`Klaudius doctor \u2014 checking your project\u2026
51
- `)),n.push(await is()),n.push(await os());let t=N(s,".env"),o=N(s,".klaudius","manifest.json"),a=N(s,".mcp.json"),l=N(s,"setup.sh"),c=await K(t),h=await K(o),r=await K(a),w=await K(l);if(n.push({name:".env present",status:c?"ok":"fail",detail:c?t:"missing",nextAction:c?void 0:"Run `klaudius init` in this folder."}),n.push({name:"Template scaffolded (.klaudius/manifest.json)",status:h?"ok":"fail",detail:h?o:"missing",nextAction:h?void 0:c?"Init didn't finish \u2014 run `klaudius init` and pick Resume.":"Run `klaudius init`."}),n.push({name:".mcp.json present",status:r?"ok":"warn",detail:r?a:"missing",nextAction:r?void 0:"Run `klaudius configure` to regenerate."}),n.push({name:"setup.sh present",status:w?"ok":"warn",detail:w?l:"missing \u2014 re-run init"}),n.push(await rs(s)),n.push(await as(s)),n.push(await ls()),!c)n.push({name:"Credential validations",status:"skip",detail:".env missing"});else if(e.offline)n.push({name:"Credential validations",status:"skip",detail:"--offline set"});else{let p=await ts(t,"utf-8"),E=v(p);await cs(E,n)}console.log();for(let p of n){let E=p.status==="ok"?S.green("\u2713"):p.status==="warn"?S.yellow("\u26A0"):p.status==="skip"?S.dim("\xB7"):S.red("\u2717");console.log(` ${E} ${p.name}${p.detail?S.dim(` \u2014 ${p.detail}`):""}`),p.nextAction&&console.log(` ${S.dim("\u2192")} ${S.cyan(p.nextAction)}`)}let k=n.filter(p=>p.status==="fail").length,P=n.filter(p=>p.status==="warn").length;console.log(),k===0&&P===0?console.log(S.green(S.bold("Everything checks out. You're good to go."))):k===0?console.log(S.yellow(S.bold(`${P} warning${P===1?"":"s"} \u2014 review above.`))):(console.log(S.red(S.bold(`${k} failed check${k===1?"":"s"} \u2014 see the \u2192 next actions above.`))),process.exitCode=1),console.log()}async function K(e){try{return await es(e),!0}catch{return!1}}async function is(){let e=await J();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 os(){let e=process.version,s=/^v(\d+)\.(\d+)\.(\d+)$/.exec(e);if(!s)return{name:"Node \u2265 22.15",status:"warn",detail:e};let n=parseInt(s[1],10),t=parseInt(s[2],10);return n<22||n===22&&t<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 rs(e){let s=N(e,"node_modules");if(!await K(s))return{name:"node_modules installed",status:"fail",detail:"missing",nextAction:"Run `bash setup.sh` (or `npm install`) in this folder."};try{if(!(await ss(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 as(e){let s=process.platform==="darwin"?N(process.env.HOME??"","Library","Caches","ms-playwright"):process.platform==="win32"?N(process.env.USERPROFILE??"","AppData","Local","ms-playwright"):N(process.env.HOME??"",".cache","ms-playwright");return await K(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 ls(){let e=["supabase","dotenv","requests","httpx","PIL"],s=`import sys
48
+ Press Enter on any field to keep its current value.`}),await C(n,r),!r.telegramBotToken||!r.telegramChatId)){i.success("Skipped Telegram. Setup will continue."),f=!0;break}}}i.blank();let k=g.spinner();k.start("Downloading Klaudius template");let P;try{P=(await W({licenseKey:o,machineId:V(),hostname:process.platform==="win32"?process.env.COMPUTERNAME:void 0,os:`${process.platform}-${process.arch}`,destDir:n})).filesExtracted,k.stop(`Downloaded ${P} files into ${d.bold(n)}`)}catch(p){k.stop(p.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(B(n,"clients"),{recursive:!0});let m=await ke(n);await z(n,Te("0.1.0",m)),i.success("Wrote .klaudius/manifest.json");let E=!1,R="";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: ${r.supabaseUrl.replace("https://","https://supabase.com/dashboard/project/"+r.supabaseProjectRef+"/sql/new").replace(r.supabaseProjectRef+".supabase.co","")}`);else{i.blank();let p=g.spinner();p.start("Applying schema to Supabase");let f=await ve({projectRoot:n,pat:r.supabasePat,projectRef:r.supabaseProjectRef});f.ok?p.stop("Schema applied (or already present)"):(p.stop(f.message??"Schema apply failed",2),E=!0,R=`https://supabase.com/dashboard/project/${r.supabaseProjectRef}/sql/new`)}let _=[],F={};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 p=await De(n);i.detail(`npm: ${p.npm}, pip: ${p.pip}, playwright: ${p.playwright}, patchright: ${p.patchright}`),p.npm==="failed"&&_.push("npm"),p.pip==="failed"&&_.push("pip"),p.playwright==="failed"&&_.push("playwright"),p.patchright==="failed"&&_.push("patchright"),F=p.hints??{}}i.blank();let pe=[..._,...E?["schema"]:[]];if(pe.length>0){g.outro(d.yellow(d.bold(`Setup paused \u2014 ${pe.join(", ")} failed.`))),console.log(d.dim("Your credentials and project files are all saved.")),i.blank();for(let[u,y]of Object.entries(F))console.log(d.yellow(`Likely cause of ${u} failure:`)),console.log(d.dim(` ${y}`)),i.blank();console.log(d.dim("To finish, once you've addressed any causes above:")),i.blank(),n!==process.cwd()&&console.log(` ${d.cyan(`cd ${e.target}`)}`),_.length>0&&console.log(` ${d.cyan("bash setup.sh")} ${d.dim("# retry the failing installers")}`),E&&(console.log(d.dim(" Apply scripts/schema.sql in the Supabase SQL editor:")),console.log(` ${d.cyan(R)}`),console.log(d.dim(" Open scripts/schema.sql, copy the contents, paste into the editor, click Run."))),i.blank(),_.includes("pip")&&!F.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 f=["npm","playwright","patchright"].filter(u=>_.includes(u)&&!F[u]);if(f.length>0){let u=f.length===1?"keeps":"keep";console.log(d.dim(`If ${f.join(" / ")} ${u} 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:")),n!==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 C(e,s){await Be(e,{recursive:!0}),await Ve(B(e,".env"),G(s),"utf-8"),await Ve(B(e,".mcp.json"),Y(s),"utf-8"),await ee(e,"supabase")}async function Vt(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 Kt(e),n=s.filter(c=>!c.startsWith(".DS_Store"));if(n.length===0)return{kind:"fresh"};let t=new Set([".env",".mcp.json",".claude"]),o=n.every(c=>t.has(c)),a=n.includes(".env"),l=s.includes(".klaudius");if(o&&a&&!l)return{kind:"partial",envPath:B(e,".env")};if(l&&a){let c=!0;try{c=!(await He(B(e,"node_modules"))).isDirectory()}catch{c=!0}return{kind:"scaffolded",nodeModulesMissing:c}}return{kind:"occupied",entries:n}}async function Bt(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 Ft(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:n=>n.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 Gt,writeFile as Ge,access as Yt}from"fs/promises";import{join as te}from"path";import*as se from"@clack/prompts";import $ from"picocolors";async function Ye(e){let s=e.projectRoot??process.cwd(),n=te(s,".env"),t=te(s,".mcp.json"),o=await ce(te(s,".klaudius","manifest.json")),a=await ce(n);!o&&!a&&(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=Z();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 w=await Gt(n,"utf-8");c=v(w)}catch{i.warn("No .env found. Starting from an empty configuration.")}let h=ye(c);se.intro("Reconfigure Klaudius"),i.detail("Press Enter on any prompt to keep its current value."),i.blank();let r=await S(h);if(r.supabaseUrl!==c.SUPABASE_URL||r.supabaseServiceKey!==c.SUPABASE_SERVICE_KEY){i.heading("Re-validating Supabase credentials");let w=await M({url:r.supabaseUrl,serviceKey:r.supabaseServiceKey});w.ok||(i.error(w.message??"Supabase check failed"),i.warn("Aborting. .env not modified."),process.exit(1)),i.success("Supabase credentials accepted")}await Ge(n,G(r),"utf-8"),i.success("Updated .env"),await Ge(t,Y(r),"utf-8"),i.success("Updated .mcp.json"),await ee(s,"supabase"),i.blank(),se.outro($.green("Configuration updated.")),await Wt(s,o)}async function Wt(e,s){let n=await ce(te(e,"node_modules"));i.blank(),s?n||(i.detail("Your project files are in place but dependencies aren't installed yet."),i.detail("To finish setup, run:"),i.blank(),console.log(` ${$.cyan("bash setup.sh")} ${$.dim("# (re-)installs npm + pip + browsers; idempotent")}`),i.blank(),i.detail("Then verify with:"),i.blank(),console.log(` ${$.cyan("npx klaudius doctor")} ${$.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(` ${$.cyan("npx klaudius init")} ${$.dim("# pick Resume when prompted")}`),i.blank())}async function ce(e){try{return await Yt(e),!0}catch{return!1}}import{copyFile as We,mkdir as ze,readdir as zt,readFile as qt,rm as ne,writeFile as qe,access as Jt}from"fs/promises";import{dirname as Je,join as I,relative as Xt}from"path";import{tmpdir as Qt}from"os";import*as K from"@clack/prompts";import de from"picocolors";var ue="0.7.2";async function Xe(e){let s=e.projectRoot??process.cwd(),n=await Se(s);n||(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 t,o=I(s,".env");try{let m=await qt(o,"utf-8"),E=v(m);t=E.KLAUDIUS_LICENSE_KEY??"",t||(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 R=we(m,E,[{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)."}]);R!==null&&(await qe(o,R,"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)}K.intro(`Update from ${n.templateVersion} \u2192 ${ue}`);let a=I(Qt(),`klaudius-update-${process.pid}-${Date.now()}`),l;try{i.heading("Downloading the latest Klaudius template");let m=await W({licenseKey:t,machineId:V(),hostname:process.env.HOSTNAME??process.env.COMPUTERNAME,os:`${process.platform}-${process.arch}`,destDir:a});i.success(`Fetched ${m.filesExtracted} canonical files`),l=a}catch(m){i.error(m.message),i.detail("Update aborted. Your project is unchanged."),await ne(a,{recursive:!0,force:!0}).catch(()=>{}),process.exit(1)}let c=await Zt(l,s,n),h=c.filter(m=>m.state==="new"),r=c.filter(m=>m.state==="clean-update"),w=c.filter(m=>m.state==="user-only"),k=c.filter(m=>m.state==="conflict"),P=c.filter(m=>m.state==="no-change");if(i.blank(),i.heading("Change summary"),i.detail(`${D(P.length,"file")} unchanged`),i.detail(`${D(h.length,"new file")}`),i.detail(`${D(r.length,"file")} updated cleanly (no local edits)`),i.detail(`${D(w.length,"file")} you've edited (no upstream change \u2014 left alone)`),i.detail(`${D(k.length,"file")} with conflicts (you edited AND we have a new version)`),r.length===0&&h.length===0&&k.length===0){i.blank(),K.outro(de.green("Already up to date.")),await ne(a,{recursive:!0,force:!0}).catch(()=>{});return}i.blank(),i.heading("Applying clean updates");for(let m of[...h,...r]){let E=I(l,m.path),R=I(s,m.path);await ze(Je(R),{recursive:!0}),await We(E,R),n.files[m.path]=m.canonicalHash}if(i.success(`Wrote ${D(h.length+r.length,"file")}`),k.length>0){i.blank(),i.heading(`${k.length} conflict(s) need resolution`);let m=I(s,".klaudius","incoming");try{await ne(m,{recursive:!0,force:!0})}catch{}for(let E of k){let R=I(l,E.path),_=I(m,E.path);await ze(Je(_),{recursive:!0}),await We(R,_)}await qe(I(s,".klaudius","conflicts.md"),es(k,n.templateVersion,ue),"utf-8"),i.detail("Staged canonical versions to .klaudius/incoming/"),i.detail("Wrote conflict report to .klaudius/conflicts.md")}n.updatedAt=new Date().toISOString(),k.length===0&&(n.templateVersion=ue),await z(s,n),i.blank(),k.length===0?K.outro(de.green("Update complete.")):K.outro(de.yellow(`${k.length} conflict(s) staged. Open Claude Code in this project and ask:
49
+ "Run /resolve-conflicts"`)),await ne(a,{recursive:!0,force:!0}).catch(()=>{})}async function Zt(e,s,n){let t=await Qe(e),o=[];for(let a of t){let l=await oe(I(e,a)),c=n.files[a],h=I(s,a),r;try{await Jt(h),r=await oe(h)}catch{o.push({path:a,state:"new",canonicalHash:l,manifestHash:c});continue}l===c?r===c?o.push({path:a,state:"no-change",canonicalHash:l,localHash:r,manifestHash:c}):o.push({path:a,state:"user-only",canonicalHash:l,localHash:r,manifestHash:c}):r===c?o.push({path:a,state:"clean-update",canonicalHash:l,localHash:r,manifestHash:c}):o.push({path:a,state:"conflict",canonicalHash:l,localHash:r,manifestHash:c})}return o}function D(e,s){return`${e} ${s}${e===1?"":"s"}`}async function Qe(e,s=e){let n=await zt(e,{withFileTypes:!0}),t=[];for(let o of n){let a=I(e,o.name);o.isDirectory()?t.push(...await Qe(a,s)):o.isFile()&&t.push(Xt(s,a))}return t}function es(e,s,n){let t=[];t.push("# Update Conflicts"),t.push(""),t.push(`Generated by \`npx klaudius update\` on ${new Date().toISOString()}.`),t.push(`Updating from canonical version **${s}** to **${n}**.`),t.push(""),t.push(`${e.length} file${e.length===1?"":"s"} ha${e.length===1?"s":"ve"} BOTH local edits AND upstream changes.`),t.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, or merge."),t.push(""),t.push("---"),t.push("");for(let o of e)t.push(`## ${o.path}`),t.push(""),t.push(`- Your version (with your local edits): \`${o.path}\``),t.push(`- New canonical version: \`.klaudius/incoming/${o.path}\``),t.push(`- Hash at last install/update: \`${(o.manifestHash??"(none)").slice(0,16)}\``),t.push(`- Your local hash now: \`${(o.localHash??"(missing)").slice(0,16)}\``),t.push(`- New canonical hash: \`${o.canonicalHash.slice(0,16)}\``),t.push(""),t.push("**Resolution options for the SKILL to walk through:**"),t.push(""),t.push("1. Keep mine \u2014 discard the new canonical changes"),t.push("2. Take canonical \u2014 overwrite my edits with the new version"),t.push("3. Merge \u2014 review both side-by-side and produce a combined version"),t.push(""),t.push("---"),t.push("");return t.join(`
50
+ `)}import{access as ts,readFile as ss,stat as ns}from"fs/promises";import{join as N}from"path";import b from"picocolors";import{spawn as is}from"child_process";async function Ze(e){let s=e.projectRoot??process.cwd(),n=[];console.log(b.bold(`Klaudius doctor \u2014 checking your project\u2026
51
+ `)),n.push(await os()),n.push(await rs());let t=N(s,".env"),o=N(s,".klaudius","manifest.json"),a=N(s,".mcp.json"),l=N(s,"setup.sh"),c=await j(t),h=await j(o),r=await j(a),w=await j(l);if(n.push({name:".env present",status:c?"ok":"fail",detail:c?t:"missing",nextAction:c?void 0:"Run `klaudius init` in this folder."}),n.push({name:"Template scaffolded (.klaudius/manifest.json)",status:h?"ok":"fail",detail:h?o:"missing",nextAction:h?void 0:c?"Init didn't finish \u2014 run `klaudius init` and pick Resume.":"Run `klaudius init`."}),n.push({name:".mcp.json present",status:r?"ok":"warn",detail:r?a:"missing",nextAction:r?void 0:"Run `klaudius configure` to regenerate."}),n.push({name:"setup.sh present",status:w?"ok":"warn",detail:w?l:"missing \u2014 re-run init"}),n.push(await as(s)),n.push(await ls(s)),n.push(await cs()),!c)n.push({name:"Credential validations",status:"skip",detail:".env missing"});else if(e.offline)n.push({name:"Credential validations",status:"skip",detail:"--offline set"});else{let m=await ss(t,"utf-8"),E=v(m);await ds(E,n)}console.log();for(let m of n){let E=m.status==="ok"?b.green("\u2713"):m.status==="warn"?b.yellow("\u26A0"):m.status==="skip"?b.dim("\xB7"):b.red("\u2717");console.log(` ${E} ${m.name}${m.detail?b.dim(` \u2014 ${m.detail}`):""}`),m.nextAction&&console.log(` ${b.dim("\u2192")} ${b.cyan(m.nextAction)}`)}let k=n.filter(m=>m.status==="fail").length,P=n.filter(m=>m.status==="warn").length;console.log(),k===0&&P===0?console.log(b.green(b.bold("Everything checks out. You're good to go."))):k===0?console.log(b.yellow(b.bold(`${P} warning${P===1?"":"s"} \u2014 review above.`))):(console.log(b.red(b.bold(`${k} failed check${k===1?"":"s"} \u2014 see the \u2192 next actions above.`))),process.exitCode=1),console.log()}async function j(e){try{return await ts(e),!0}catch{return!1}}async function os(){let e=await Q();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 rs(){let e=process.version,s=/^v(\d+)\.(\d+)\.(\d+)$/.exec(e);if(!s)return{name:"Node \u2265 22.15",status:"warn",detail:e};let n=parseInt(s[1],10),t=parseInt(s[2],10);return n<22||n===22&&t<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 as(e){let s=N(e,"node_modules");if(!await j(s))return{name:"node_modules installed",status:"fail",detail:"missing",nextAction:"Run `bash setup.sh` (or `npm install`) in this folder."};try{if(!(await ns(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 ls(e){let s=process.platform==="darwin"?N(process.env.HOME??"","Library","Caches","ms-playwright"):process.platform==="win32"?N(process.env.USERPROFILE??"","AppData","Local","ms-playwright"):N(process.env.HOME??"",".cache","ms-playwright");return await j(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 cs(){let e=["supabase","dotenv","requests","httpx","PIL"],s=`import sys
52
52
  try:
53
53
  ${e.map(t=>` import ${t}`).join(`
54
54
  `)}
55
55
  except Exception as e:
56
56
  print(str(e))
57
57
  sys.exit(1)
58
- `,n=await ds("python3",["-c",s]);return n.code===0?{name:"Python packages installed",status:"ok",detail:e.join(", ")}:{name:"Python packages installed",status:"fail",detail:(n.stdout||n.stderr).trim().split(`
59
- `).pop()??"import failed",nextAction:"Run `bash setup.sh` in this folder."}}async function cs(e,s){if(e.SUPABASE_URL&&e.SUPABASE_SERVICE_KEY){let n=await $({url:e.SUPABASE_URL,serviceKey:e.SUPABASE_SERVICE_KEY});s.push({name:"Supabase credentials",status:n.ok?"ok":"fail",detail:n.ok?"connected":n.message,nextAction:n.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 n=await W(e.VERCEL_TOKEN);s.push({name:"Vercel token",status:n.ok?"ok":"fail",detail:n.ok?n.username??"valid":n.message,nextAction:n.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 n=await z(e.GOOGLE_PLACES_API_KEY);s.push({name:"Google Places API key",status:n.ok?"ok":"fail",detail:n.ok?"accepted":n.message,nextAction:n.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 n=await me({botToken:e.TELEGRAM_BOT_TOKEN});s.push({name:"Telegram bot token",status:n.ok?"ok":"fail",detail:n.ok?`bot ${n.botHandle??"ok"} (chat_id not tested)`:n.message,nextAction:n.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 ds(e,s){return new Promise(n=>{let t=ns(e,s,{stdio:["ignore","pipe","pipe"],shell:!1}),o="",a="";t.stdout?.on("data",l=>{o+=l.toString()}),t.stderr?.on("data",l=>{a+=l.toString()}),t.on("close",l=>n({code:l??1,stdout:o,stderr:a})),t.on("error",()=>n({code:1,stdout:o,stderr:a}))})}var ps="0.7.0",j=new us;j.name("klaudius").description("Scaffold and maintain a Klaudius pipeline project").version(ps);j.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 He({target:e,license:s.license,skipInstall:!!s.skipInstall,skipSchema:!!s.skipSchema})}catch(n){console.error("init failed:",n.message),process.exit(1)}});j.command("configure").description("Re-run the setup wizard with current values pre-filled").action(async()=>{try{await Fe({})}catch(e){console.error("configure failed:",e.message),process.exit(1)}});j.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)}});j.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 Xe({offline:!!e.offline})}catch(s){console.error("doctor failed:",s.message),process.exit(1)}});j.parse(process.argv);
58
+ `,n=await us("python3",["-c",s]);return n.code===0?{name:"Python packages installed",status:"ok",detail:e.join(", ")}:{name:"Python packages installed",status:"fail",detail:(n.stdout||n.stderr).trim().split(`
59
+ `).pop()??"import failed",nextAction:"Run `bash setup.sh` in this folder."}}async function ds(e,s){if(e.SUPABASE_URL&&e.SUPABASE_SERVICE_KEY){let n=await M({url:e.SUPABASE_URL,serviceKey:e.SUPABASE_SERVICE_KEY});s.push({name:"Supabase credentials",status:n.ok?"ok":"fail",detail:n.ok?"connected":n.message,nextAction:n.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 n=await q(e.VERCEL_TOKEN);s.push({name:"Vercel token",status:n.ok?"ok":"fail",detail:n.ok?n.username??"valid":n.message,nextAction:n.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 n=await J(e.GOOGLE_PLACES_API_KEY);s.push({name:"Google Places API key",status:n.ok?"ok":"fail",detail:n.ok?"accepted":n.message,nextAction:n.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 n=await he({botToken:e.TELEGRAM_BOT_TOKEN});s.push({name:"Telegram bot token",status:n.ok?"ok":"fail",detail:n.ok?`bot ${n.botHandle??"ok"} (chat_id not tested)`:n.message,nextAction:n.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 us(e,s){return new Promise(n=>{let t=is(e,s,{stdio:["ignore","pipe","pipe"],shell:!1}),o="",a="";t.stdout?.on("data",l=>{o+=l.toString()}),t.stderr?.on("data",l=>{a+=l.toString()}),t.on("close",l=>n({code:l??1,stdout:o,stderr:a})),t.on("error",()=>n({code:1,stdout:o,stderr:a}))})}var ms="0.7.2",H=new ps;H.name("klaudius").description("Scaffold and maintain a Klaudius pipeline project").version(ms);H.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(n){console.error("init failed:",n.message),process.exit(1)}});H.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)}});H.command("update").description("Pull latest template; produce a conflicts report for any files you've modified").action(async()=>{try{await Xe({})}catch(e){console.error("update failed:",e.message),process.exit(1)}});H.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 Ze({offline:!!e.offline})}catch(s){console.error("doctor failed:",s.message),process.exit(1)}});H.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "klaudius",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
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": {
@@ -46,6 +46,7 @@
46
46
  "@types/node": "^20.14.0",
47
47
  "@types/nodemailer": "^8.0.0",
48
48
  "@types/react": "^19.2.14",
49
+ "node-pty": "^1.1.0",
49
50
  "tsup": "^8.2.0",
50
51
  "tsx": "^4.16.0",
51
52
  "typescript": "^5.5.0"