klaudius 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,7 +36,7 @@ npx klaudius update # Pull latest template; conflicts staged for resolu
36
36
 
37
37
  ## Prerequisites
38
38
 
39
- - Node 20+
39
+ - Node 22+ (and Python 3.10+)
40
40
  - A Claude Code subscription (Pro or Max plan)
41
41
  - A Supabase project (free tier is fine to start)
42
42
  - A Vercel team (Hobby tier is fine to start)
@@ -0,0 +1,191 @@
1
+ import{a as m,d as J}from"./chunk-GI7NTKNT.js";import{useEffect as Ge,useMemo as Le,useRef as Y,useState as A}from"react";import{Box as P,Text as v,useApp as ze,useInput as je}from"ink";var Q={gmail:{label:"Gmail",smtpHost:"smtp.gmail.com",smtpPort:587,imapHost:"imap.gmail.com",imapPort:993,sentFolder:"[Gmail]/Sent Mail",inboxFolder:"INBOX",appPasswordHelp:`Generate at https://myaccount.google.com/apppasswords
2
+ (2-step verification must be enabled on your Google account first;
3
+ Google won't accept your normal account password from third-party apps).`},outlook:{label:"Outlook / Office 365",smtpHost:"smtp-mail.outlook.com",smtpPort:587,imapHost:"outlook.office365.com",imapPort:993,sentFolder:"Sent Items",inboxFolder:"INBOX",appPasswordHelp:`Generate at https://account.microsoft.com/security \u2192 Advanced security options \u2192 App passwords
4
+ (2-step verification must be enabled first).`},ionos:{label:"IONOS",smtpHost:"smtp.ionos.co.uk",smtpPort:587,imapHost:"imap.ionos.co.uk",imapPort:993,sentFolder:"Sent Items",inboxFolder:"INBOX",appPasswordHelp:`Use your normal IONOS mailbox password.
5
+ (IONOS doesn't require app passwords for IMAP/SMTP unless you've enabled 2FA.)`},fastmail:{label:"Fastmail",smtpHost:"smtp.fastmail.com",smtpPort:587,imapHost:"imap.fastmail.com",imapPort:993,sentFolder:"Sent",inboxFolder:"INBOX",appPasswordHelp:`Generate at https://app.fastmail.com/settings/security/integrations
6
+ (Fastmail requires app passwords for IMAP/SMTP regardless of 2FA setting.)`},zoho:{label:"Zoho Mail",smtpHost:"smtp.zoho.com",smtpPort:587,imapHost:"imap.zoho.com",imapPort:993,sentFolder:"Sent",inboxFolder:"INBOX",appPasswordHelp:`Generate at https://accounts.zoho.com/u/h#security/app_passwords
7
+ (Zoho requires app passwords for IMAP/SMTP \u2014 your normal account password won't work.)`}},ee=`Use the app-specific password your provider issues for SMTP/IMAP
8
+ (check their security settings \u2014 most providers require a generated password
9
+ rather than your normal account password).`;var B=class extends Error{constructor(){super("user pressed back"),this.name="BackSignal"}},H=class extends Error{constructor(){super("user cancelled"),this.name="CancelSignal"}},be="Include the country code with a + (e.g. +12025550123 for US, +447123456789 for UK)",te=e=>/^\+\d{8,15}$/.test(e)?void 0:be,we=e=>/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(e)?void 0:"Enter a valid email",I=e=>t=>t.trim().length===0?`${e} is required`:void 0,Se={id:"pricing",title:"Pricing",isApplicable:()=>!0,execute:async(e,{prompt:t})=>({pricing:await t({type:"text",message:"What price will you charge clients per finished site?",placeholder:"e.g. $999, \xA3799, \u20AC899",initialValue:e.pricing??"$999",validate:I("Price"),note:{title:"Pricing",body:`Use the currency that matches the region of clients you'll be reaching
10
+ out to (e.g. $ for US clients, \xA3 for the UK, \u20AC for the EU). Klaudius
11
+ uses this exact string verbatim throughout outreach.`}})})},Pe={id:"outreach-enabled",title:"Automated outreach",isApplicable:()=>!0,execute:async(e,{prompt:t})=>({outreachEnabled:await t({type:"confirm",message:"Use Klaudius's automated outreach features?",initialValue:e.outreachEnabled??!0,note:{title:"Automated outreach features",body:`After finding candidates and building websites for them, Klaudius can
12
+ run outreach to them automatically (email and/or SMS).
13
+ If you'd rather handle outreach manually, you can skip this here.`}})})},xe={id:"operator-name",title:"Your name",isApplicable:e=>e.outreachEnabled===!0,execute:async(e,{prompt:t})=>{let s=await t({type:"text",message:"Your name as it should appear publicly in outreach",placeholder:"e.g. Mike Smith \u2014 or your business name if you'd rather",initialValue:e.name??e.emailFromName??"",validate:I("Name")}),a=s.trim().split(/\s+/)[0];return{name:s,signature:e.signature??`Thanks, ${a}`}}},ve={id:"channels",title:"Outreach channels",isApplicable:e=>e.outreachEnabled===!0,execute:async(e,{prompt:t})=>{let s=e.outreachChannels&&e.outreachChannels.length>1?"both":e.outreachChannels?.[0]??"email",a=await t({type:"select",message:"Which channels can Klaudius use for outreach?",initialValue:s,options:[{value:"email",label:"Email only"},{value:"sms",label:"SMS only"},{value:"both",label:"Both (recommended for maximum reach)"}],note:{title:"Outreach channels",body:`Different businesses have different contact methods publicly available \u2014
14
+ some list only an email, others only a phone number. Klaudius uses whichever
15
+ channel is available for each candidate (it doesn't message the same candidate
16
+ on both). Picking 'both' just means Klaudius can reach more of the
17
+ businesses it finds.`}}),n=a==="both"?["email","sms"]:[a],o;return n.length>1&&(o=await t({type:"select",message:"When a candidate has both email and a phone number, which channel should Klaudius try first?",initialValue:e.outreachPriority??"email",options:[{value:"email",label:"Prefer email (better for B2B / professional services)"},{value:"sms",label:"Prefer SMS (better response rates for trades / local services)"}]})),{outreachChannels:n,outreachPriority:o}}},Ie={id:"email",title:"Email setup",isApplicable:e=>e.outreachChannels?.includes("email")===!0,execute:async(e,{prompt:t,info:s})=>{s({title:"Email setup",body:`Klaudius needs an email account to send outreach FROM. This is the
18
+ address candidates will see as the sender. Use a domain you control
19
+ (your own, your business's) \u2014 not your personal address.`});let a=await t({type:"select",message:"Who hosts the email account you'll send outreach from?",initialValue:e.emailProvider??"gmail",options:[{value:"gmail",label:"Gmail"},{value:"fastmail",label:"Fastmail"},{value:"outlook",label:"Outlook / Office 365"},{value:"zoho",label:"Zoho Mail"},{value:"ionos",label:"IONOS"},{value:"custom",label:"Custom / other (enter SMTP/IMAP details manually)"}]}),n=a!=="custom"?Q[a]:void 0,o=await t({type:"text",message:"Email address to send outreach from",placeholder:"you@yourbusiness.com",initialValue:e.emailAddress??"",validate:we}),i=n?.appPasswordHelp??ee,u=await t({type:"password",message:"Paste the app password",initialValue:e.emailPassword??"",validate:I("App password"),note:{title:"App password",body:`An app password is a separate, single-purpose password that your
20
+ email provider issues for third-party apps like Klaudius. It is NOT
21
+ your normal account login password.
22
+
23
+ `+i+`
24
+
25
+ Once generated, it's stored locally in this project's .env file.
26
+ It is never sent to Klaudius's servers \u2014 only to your email
27
+ provider when sending outreach.`}}),r,c,f,y,k,E;if(a==="custom"){r=await t({type:"text",message:"SMTP host (the server Klaudius connects to for sending)",placeholder:"e.g. smtp.yourprovider.com",initialValue:e.emailSmtpHost??"",validate:I("SMTP host")});let F=await t({type:"text",message:"SMTP port (usually 587 for STARTTLS or 465 for SSL)",initialValue:String(e.emailSmtpPort??587),validate:T=>/^\d+$/.test(T)?void 0:"Must be a number"});c=parseInt(F,10),f=await t({type:"text",message:"IMAP host (the server Klaudius connects to for reading replies)",placeholder:"e.g. imap.yourprovider.com",initialValue:e.emailImapHost??"",validate:I("IMAP host")});let O=await t({type:"text",message:"IMAP port (usually 993 for SSL)",initialValue:String(e.emailImapPort??993),validate:T=>/^\d+$/.test(T)?void 0:"Must be a number"});y=parseInt(O,10),k=await t({type:"text",message:"Sent folder name (so SMTP-sent messages also appear in your email client's Sent folder)",placeholder:'e.g. "Sent", "Sent Items"',initialValue:e.emailSentFolder??"Sent"}),E=await t({type:"text",message:"Inbox folder name (almost always INBOX)",initialValue:e.emailInboxFolder??"INBOX"})}else r=n.smtpHost,c=n.smtpPort,f=n.imapHost,y=n.imapPort,k=n.sentFolder,E=n.inboxFolder;return{emailProvider:a,emailAddress:o,emailPassword:u,emailFromName:e.name,emailSmtpHost:r,emailSmtpPort:c,emailImapHost:f,emailImapPort:y,emailSentFolder:k,emailInboxFolder:E}}},Ae={id:"sms",title:"SMS setup",isApplicable:e=>e.outreachChannels?.includes("sms")===!0,execute:async(e,{prompt:t,info:s})=>{s({title:"SMS setup",body:`Klaudius can send SMS one of two ways:
28
+
29
+ \u2022 macOS iMessage \u2014 free, uses Messages.app on your Mac.
30
+ Reaches other Apple users as iMessage for free. To reach
31
+ non-Apple phones (e.g. Android), you need a one-time setup:
32
+ 1. Sign in to Messages.app on this Mac with your Apple ID.
33
+ 2. On your iPhone, sign in to the SAME Apple ID.
34
+ 3. On your iPhone: Settings \u2192 Messages \u2192 Text Message
35
+ Forwarding \u2192 toggle this Mac ON. (You'll be asked to
36
+ enter a 6-digit code that appears on the Mac.)
37
+ Once that's done, the iPhone doesn't need to be nearby.
38
+ Apple keeps the relay working as long as both devices stay
39
+ signed into the same Apple ID and have data/Wi-Fi.
40
+
41
+ \u2022 Twilio \u2014 cross-platform, ~$0.01 per SMS. Sender is a phone
42
+ number you buy from Twilio. Works on any OS, reaches any
43
+ phone, no iPhone required. Recommended for consistent delivery.`});let a=await t({type:"select",message:"Which SMS provider?",initialValue:e.smsProvider??(process.platform==="darwin"?"imessage":"twilio"),options:[{value:"imessage",label:"macOS iMessage (free, Mac only)"},{value:"twilio",label:"Twilio (cross-platform, paid per-message \u2014 recommended)"}]}),n=await t({type:"text",message:"Your mobile number (used as a safe target for test sends so Klaudius doesn't accidentally message real candidates while you're testing)",placeholder:"+12025550123",initialValue:e.testPhone??"",validate:te}),o={smsProvider:a,testPhone:n};return a==="twilio"&&(o.twilioAccountSid=await t({type:"text",message:"Twilio Account SID (starts with AC...)",initialValue:e.twilioAccountSid??"",validate:i=>/^AC[a-zA-Z0-9]+$/.test(i)?void 0:"Should start with 'AC'"}),o.twilioAuthToken=await t({type:"password",message:"Twilio Auth Token",initialValue:e.twilioAuthToken??"",validate:I("Twilio Auth Token")}),o.twilioPhoneNumber=await t({type:"text",message:"Twilio phone number (the number outreach will be sent FROM)",placeholder:"+15551234567",initialValue:e.twilioPhoneNumber??"",validate:te})),o}},ke={id:"vercel",title:"Vercel deployment",isApplicable:()=>!0,execute:async(e,{prompt:t})=>({vercelToken:await t({type:"password",message:"Paste your Vercel API token",initialValue:e.vercelToken??"",validate:a=>a.trim().length===0?"Required \u2014 without this Klaudius can't deploy generated sites":void 0,note:{title:"Vercel deployment",body:`Klaudius deploys every generated client site to Vercel. We use a
44
+ Vercel API token to do this without an interactive login.
45
+
46
+ How to get one (one-time, ~30 seconds):
47
+ 1. Open https://vercel.com/account/tokens
48
+ 2. Click 'Create Token'
49
+ 3. Name it 'Klaudius', set scope to your personal account, set
50
+ expiration to 'No expiration' (recommended) or your preferred
51
+ duration
52
+ 4. Click Create, then copy the token shown
53
+
54
+ Don't have a Vercel account yet? Sign up free at vercel.com.
55
+ The Hobby (free) plan caps you at 200 projects and 100 deployments
56
+ per day. If you grow past 200 active client sites you can either
57
+ upgrade to Pro ($20/month, unlimited projects + 6,000 deploys/day),
58
+ or simply switch to a new Vercel account each time you hit the
59
+ 200-project ceiling.
60
+
61
+ STUCK? Open Claude (or any LLM) in another tab/app and paste:
62
+
63
+ "I need to create a personal Vercel API token for the
64
+ Klaudius CLI tool. Walk me through generating one at
65
+ vercel.com/account/tokens, including which scope and
66
+ expiration to choose."`}})})},Te={id:"supabase",title:"Supabase",isApplicable:()=>!0,execute:async(e,{prompt:t,info:s})=>{s({title:"Supabase setup",body:`Supabase is your CRM. It's where Klaudius records every business it
67
+ finds, where each one sits in your funnel (gathered \u2192 built \u2192 deployed
68
+ \u2192 outreach sent \u2192 responded), and the follow-up state for every lead.
69
+ You can browse it at any time from the Supabase dashboard, or ask
70
+ Claude \u2014 your Klaudius project ships with the Supabase MCP wired in,
71
+ so Claude can read the CRM live (e.g. 'who replied this week?',
72
+ 'who haven't I followed up with?').
73
+
74
+ The free tier (500 MB database, 5 GB bandwidth/month) is plenty:
75
+ Klaudius's records are tiny text rows (a few KB per client at most),
76
+ and the only reads/writes are the pipeline's own bookkeeping \u2014
77
+ no public traffic to your CRM. Even with thousands of leads tracked
78
+ you'll use a sliver of the limit.
79
+
80
+ If you don't have a project yet: open https://supabase.com/dashboard
81
+ and create one. The flow is:
82
+ 1. Sign up (or sign in) with GitHub / Google / email
83
+ 2. 'Create a new organization' page \u2014 name and type don't matter
84
+ for Klaudius, pick anything you like
85
+ 3. Plan page \u2014 pick Free
86
+ 4. 'Create a new project' page \u2014 set a database password (any
87
+ strong password \u2014 Klaudius doesn't use it directly, but you'll
88
+ want it later if you ever connect to the database manually).
89
+ Region defaults to the nearest one to you, leave it. Accept
90
+ defaults for any other security settings on the page.
91
+ 5. Click 'Create new project'.
92
+
93
+ STUCK on any of the prompts below? Open Claude (or ChatGPT, or any LLM)
94
+ in another tab/app and paste this prompt verbatim:
95
+
96
+ "I'm setting up a Supabase project to use with the Klaudius CLI.
97
+ The wizard is asking for: (1) project URL, (2) the secret/service-
98
+ role key, (3) a personal access token. Walk me through where to
99
+ find each one in the current Supabase dashboard UI, including the
100
+ exact menu paths and any caveats for newer vs. legacy projects."`});let n=(await t({type:"text",message:"Paste your Supabase API URL",placeholder:"https://YOUR_REF.supabase.co",initialValue:e.supabaseUrl??"",validate:r=>/^https:\/\/[a-z0-9]+\.supabase\.co(\/rest\/v1\/?)?$/i.test(r.trim())?void 0:"Should look like https://xxxx.supabase.co (with or without /rest/v1/)",note:{title:"API URL",body:`In your Supabase dashboard, open your project, then go to:
101
+ Settings \u2192 Data API \u2192 'API URL'
102
+
103
+ It looks like https://xxxx.supabase.co. Click to copy and paste
104
+ below.`}})).trim().replace(/\/rest\/v1\/?$/i,"").replace(/\/$/,""),o=n.match(/^https:\/\/([a-z0-9]+)\.supabase\.co/i)?.[1]??"",i=await t({type:"password",message:"Paste the Supabase secret key (sb_secret_\u2026)",initialValue:e.supabaseServiceKey??"",validate:r=>r.length<20?"Looks too short":void 0,note:{title:"Secret key",body:o?`Open this exact page:
105
+ https://supabase.com/dashboard/project/${o}/settings/api-keys
106
+
107
+ Under 'Secret keys', find the row whose value starts with
108
+ 'sb_secret_'. Click to copy the full value.
109
+
110
+ NEVER use the 'anon' / 'public' / 'sb_publishable_' key (those
111
+ are client-side keys with no write permissions).`:`Open Settings \u2192 API Keys in your Supabase project. Copy the
112
+ secret key (starts with 'sb_secret_').`}}),u=await t({type:"password",message:"Paste the Supabase personal access token",initialValue:e.supabasePat??"",validate:r=>r.startsWith("sbp_")?void 0:"Should start with 'sbp_'",note:{title:"Personal access token",body:`This is a separate credential from the secret key above \u2014 it's an
113
+ ACCOUNT-wide token (not project-scoped) used by the Supabase MCP and
114
+ by Klaudius's schema migration.
115
+
116
+ Open this exact page:
117
+ https://supabase.com/dashboard/account/tokens
118
+
119
+ Click 'Generate new token', name it 'Klaudius', and set the
120
+ expiration to 'Never' (recommended \u2014 saves you having to rotate
121
+ it later). Copy the value (starts with 'sbp_') and paste it
122
+ below.`}});return{supabaseUrl:n,supabaseServiceKey:i,supabasePat:u,supabaseProjectRef:o}}},Ce={id:"google-places",title:"Google Places API",isApplicable:()=>!0,execute:async(e,{prompt:t})=>({googlePlacesApiKey:await t({type:"password",message:"Paste your Google Places API key",placeholder:"AIzaSy\u2026",initialValue:e.googlePlacesApiKey??"",validate:a=>a.trim().length===0?"Required \u2014 without this Klaudius can't find candidates":void 0,note:{title:"Google Places API key",body:`Klaudius's /find skill queries Google's Places API to discover businesses
123
+ without websites in your target region. Without a key, the pipeline has
124
+ no source of leads \u2014 so this is required.
125
+
126
+ Cost: Google gives every new account $300 in trial credit to spend over
127
+ 90 days. That's far more than you'll need at solo-operator volume \u2014
128
+ Klaudius's Places API calls are fractions of a cent each. If you do
129
+ exhaust it, sign up again with a different Google account to get
130
+ another $300 trial.
131
+
132
+ How to get a key (~5 min):
133
+ 1. Open https://console.cloud.google.com and sign in (or create a
134
+ Google account if you don't have one yet).
135
+ 2. On the welcome page, click 'Try for free' (or 'Start free' in the
136
+ top banner) and complete the signup. Google asks for a card to
137
+ verify identity, but won't charge it \u2014 the trial caps at the
138
+ $300 credit unless you manually upgrade to a paid account.
139
+ 3. Once the trial is active, Google auto-creates a project called
140
+ 'My First Project'. Make sure it's selected in the project picker
141
+ at the top of the console (it should be by default).
142
+ 4. APIs & Services \u2192 Library \u2192 search 'Places API' \u2192 click
143
+ 'Places API (New)' (NOT the legacy 'Places API') \u2192 Enable.
144
+ 5. Google's 'Get Started on Google Maps Platform' page opens and
145
+ auto-generates an API key for you (starts with 'AIzaSy\u2026').
146
+ Click the copy icon next to it and paste below.
147
+
148
+ Optional but recommended once you've pasted the key: lock it down via
149
+ APIs & Services \u2192 Credentials \u2192 click your key \u2192 under 'API
150
+ restrictions' restrict it to 'Places API (New)'. Klaudius works either
151
+ way.
152
+
153
+ STUCK? Open Claude (or any LLM) in another tab/app and paste this prompt:
154
+
155
+ "I need a Google Places API (New) key for a CLI tool called
156
+ Klaudius. Walk me through claiming the $300 Google Cloud free trial
157
+ and getting the API key Google auto-generates after enabling
158
+ Places API (New), including any signup gotchas."`}})})},Ee={id:"telegram",title:"Telegram (optional)",isApplicable:()=>!0,execute:async(e,{prompt:t})=>{if(!await t({type:"confirm",message:"Set up Telegram notifications? (sends a ping when outreach lands)",initialValue:!!e.telegramBotToken,note:{title:"Telegram notifications (optional)",body:`Klaudius can ping a Telegram chat when outreach is sent or when a
159
+ candidate replies. This is OPTIONAL \u2014 skip it if you'd rather check
160
+ the Supabase dashboard manually.
161
+
162
+ If you say yes, you'll need a Telegram bot token (created via
163
+ @BotFather, ~30 seconds) and your chat ID (your own user ID, for
164
+ personal pings). The next two prompts walk you through both.`}}))return{};let a=await t({type:"password",message:"Paste your Telegram bot token",initialValue:e.telegramBotToken??"",validate:I("Bot token"),note:{title:"Bot token",body:`Telegram lets you create personal bots in ~30 seconds. Klaudius
165
+ uses a bot to send you private notifications.
166
+
167
+ How to create one:
168
+ 1. Open Telegram (mobile, desktop, or web).
169
+ 2. Search for the user '@BotFather' and open the chat.
170
+ 3. Send /newbot.
171
+ 4. BotFather asks for a display name \u2014 pick anything (e.g.
172
+ 'Klaudius Notifier').
173
+ 5. BotFather asks for a username \u2014 must end in 'bot' (e.g.
174
+ 'KlaudiusNotifierBot'). Each username has to be globally
175
+ unique, so add a personal suffix if it's taken.
176
+ 6. BotFather replies with a token like
177
+ '1234567890:AAEhBP_yourtokenhere\u2026'. Copy it and paste below.`}}),n=null,o=0,i=null;for(;n===null;){o++;let u=o>1;await t({type:"text",message:u?"Send another message to the bot, then press Enter to retry":"Send a message to your bot, then press Enter to detect chat ID",initialValue:"",placeholder:"(press Enter when you've sent the message)",validate:()=>{},note:{title:u?"Detect chat ID \u2014 retry":"Detect chat ID",body:u?`${i}
178
+
179
+ Make sure you sent a regular text message (e.g. 'hi'), not
180
+ just a /start tap \u2014 /start alone doesn't always register.
181
+ Then press Enter to retry.`:`Klaudius will auto-detect your chat ID by asking Telegram for
182
+ any messages your bot has received. To make that work:
183
+
184
+ 1. In the Telegram app, search for the bot you just created
185
+ (the username ending in 'bot') and open the chat.
186
+ 2. Send it a regular text message \u2014 type 'hi' and tap send.
187
+ If the chat starts with a 'Start' button, tap that first,
188
+ THEN send 'hi'. /start alone doesn't always show up.
189
+ 3. Press Enter below \u2014 Klaudius will detect the chat ID for
190
+ you.`}});let r=await J({botToken:a});if(r.ok&&r.chatId)n=r.chatId;else if(r.reason==="no_messages")i="No messages from you to your bot have been picked up yet.";else throw new Error(`Telegram chat ID auto-detect failed: ${r.message??"unknown error"}`)}return{telegramBotToken:a,telegramChatId:n}}},C=[Se,Pe,xe,ve,Ie,Ae,ke,Te,Ce,Ee];import{Box as ae,Text as Oe}from"ink";import{jsx as oe,jsxs as Re}from"react/jsx-runtime";var Me={pending:"\u25CB",current:"\u25C9",done:"\u2713",skipped:"\xB7"},Be={pending:void 0,current:"cyan",done:"green",skipped:void 0};function ne({items:e}){return oe(ae,{flexDirection:"column",width:28,flexShrink:0,children:e.map(t=>{let s=t.status==="skipped"||t.status==="pending";return oe(ae,{children:Re(Oe,{color:Be[t.status],bold:t.status==="current",dimColor:s&&t.status!=="current",children:[Me[t.status]," ",t.title]})},t.id)})})}import{useEffect as Ne,useState as se}from"react";import{Box as z,Text as _,useInput as Ve}from"ink";import Ke from"ink-text-input";import{jsx as R,jsxs as j}from"react/jsx-runtime";function ie({spec:e,masked:t,onSubmit:s,onBack:a}){let[n,o]=se(typeof e.initialValue=="string"?e.initialValue:""),[i,u]=se(null);Ne(()=>(m("TextPromptUI:mount",{masked:t,message:e.message.slice(0,60),initial:typeof e.initialValue=="string"?e.initialValue.slice(0,30):null}),()=>{m("TextPromptUI:unmount")}),[t,e.message,e.initialValue]),Ve((c,f)=>{m("TextPromptUI:useInput fired",{input:c,ctrl:f.ctrl,escape:f.escape,return:f.return}),f.escape&&a()});let r=c=>{m("TextPromptUI:handleSubmit",{raw:c.slice(0,30)});let f=c;if(e.validate){let y=e.validate(f);if(y){m("TextPromptUI:validate failed",{err:y}),u(y);return}}u(null),s(f)};return j(z,{flexDirection:"column",children:[j(_,{children:[R(_,{color:"cyan",children:"?"})," ",e.message]}),j(z,{children:[R(_,{color:"green",children:"\u203A "}),R(Ke,{value:n,onChange:o,onSubmit:r,placeholder:e.placeholder,mask:t?"\u2022":void 0})]}),i&&R(z,{marginTop:0,children:R(_,{color:"red",children:i})})]})}import{useState as Fe}from"react";import{Box as re,Text as W,useInput as Ue}from"ink";import{jsx as le,jsxs as $}from"react/jsx-runtime";function ce({spec:e,onSubmit:t,onBack:s}){let a=e.options??[],n=typeof e.initialValue=="string"?Math.max(0,a.findIndex(u=>u.value===e.initialValue)):0,[o,i]=Fe(n===-1?0:n);return Ue((u,r)=>{if(r.escape)s();else if(r.upArrow)i(c=>(c-1+a.length)%a.length);else if(r.downArrow)i(c=>(c+1)%a.length);else if(r.return){let c=a[o];c&&t(c.value)}}),$(re,{flexDirection:"column",children:[$(W,{children:[le(W,{color:"cyan",children:"?"})," ",e.message]}),le(re,{flexDirection:"column",marginTop:0,children:a.map((u,r)=>{let c=r===o;return $(W,{color:c?"cyan":void 0,bold:c,children:[c?"\u25CF ":"\u25CB ",u.label]},u.value)})})]})}import{useState as He}from"react";import{Box as ue,Text as N,useInput as _e}from"ink";import{jsx as pe,jsxs as V}from"react/jsx-runtime";function de({spec:e,onSubmit:t,onBack:s}){let[a,n]=He(typeof e.initialValue=="boolean"?e.initialValue:!0);return _e((o,i)=>{i.escape?s():i.leftArrow||i.rightArrow?n(u=>!u):o==="y"||o==="Y"?n(!0):o==="n"||o==="N"?n(!1):i.return&&t(a)}),V(ue,{flexDirection:"column",children:[V(N,{children:[pe(N,{color:"cyan",children:"?"})," ",e.message]}),V(ue,{marginTop:0,children:[V(N,{color:a?"cyan":void 0,bold:a,children:[a?"\u25CF ":"\u25CB ","Yes"]}),pe(N,{children:" "}),V(N,{color:a?void 0:"cyan",bold:!a,children:[a?"\u25CB ":"\u25CF ","No"]})]})]})}import{Box as me,Text as he}from"ink";import{jsx as q,jsxs as De}from"react/jsx-runtime";function X({title:e,body:t}){let s=t.split(`
191
+ `);return De(me,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:1,children:[q(he,{color:"cyan",bold:!0,children:e}),q(me,{flexDirection:"column",marginTop:0,children:s.map((a,n)=>q(he,{dimColor:!1,children:a.length===0?" ":a},n))})]})}import{jsx as p,jsxs as K}from"react/jsx-runtime";function Ot({defaults:e,onComplete:t,onlySection:s,banner:a}){let{exit:n}=ze(),o=Y({...e}),i=Y(new Map),[,u]=A(0),r=()=>u(d=>d+1),[c,f]=A(null),[y,k]=A(null),[E,F]=A([]),[O,T]=A(null),[Z,ge]=A(!1),[D,fe]=A({current:0,total:0}),U=()=>{let d=i.current;for(let h of C){let L=h.isApplicable(o.current),l=d.get(h.id);L?s&&h.id!==s?l!=="current"&&d.set(h.id,"done"):(l==="skipped"||!l)&&d.set(h.id,"pending"):d.set(h.id,"skipped")}};i.current.size===0&&U();let G=Y(!1);Ge(()=>{if(m("WizardApp:useEffect fired",{startedAlready:G.current}),G.current){m("WizardApp:useEffect returning early (startedRef true)");return}G.current=!0,m("WizardApp:orchestrator starting");let d=0,h=l=>{let w=++d;return m("orchestrator:promptFn called",{id:w,type:l.type,message:l.message.slice(0,60)}),T(null),new Promise((S,g)=>{k({id:w,spec:l,resolve:x=>{m("orchestrator:prompt resolved",{id:w,type:l.type,value:typeof x=="string"?x.slice(0,30):x}),S(x)},reject:x=>{m("orchestrator:prompt rejected",{id:w,reason:x.message}),g(x)}})})},L=l=>{F(w=>[...w,l])};return(async()=>{try{let l=s?C.filter(g=>g.id===s):C,w=()=>l.filter(g=>g.isApplicable(o.current)).length,S=0;for(;S<l.length;){let g=l[S];if(!g.isApplicable(o.current)){i.current.set(g.id,"skipped"),S++,U(),r();continue}F([]);for(let b of C)b.id===g.id?i.current.set(b.id,"current"):i.current.get(b.id)==="current"&&i.current.set(b.id,"pending");f(g.id);let x=l.slice(0,S+1).filter(b=>b.isApplicable(o.current)).length;fe({current:x,total:w()}),r();try{let b=await g.execute(o.current,{prompt:h,info:L});o.current={...o.current,...b},i.current.set(g.id,"done"),U(),S++}catch(b){if(b instanceof B){i.current.set(g.id,"pending");let M=S-1;for(;M>=0&&!l[M].isApplicable(o.current);)M--;M<0||(S=M,i.current.set(l[S].id,"pending")),U(),r();continue}throw b}}m("orchestrator:all sections done, calling onComplete + exit"),ge(!0),k(null),f(null),r(),await new Promise(g=>setTimeout(g,200)),t(o.current),n()}catch(l){m("orchestrator:caught error",{name:l?.name,message:l?.message}),l instanceof H&&(n(),process.exit(0));let w=l instanceof Error?l.message:String(l);T(`Setup error: ${w}`),r()}})(),()=>{m("WizardApp:useEffect cleanup ran (component unmounting)")}},[n,t]),je((d,h)=>{m("WizardApp:useInput fired",{input:d,ctrl:h.ctrl,escape:h.escape,return:h.return}),h.ctrl&&d==="c"&&(m("WizardApp:Ctrl+C \u2192 exiting"),n(),process.exit(0))});let ye=Le(()=>C.map(d=>({id:d.id,title:d.title,status:i.current.get(d.id)??"pending"})),[c,Z,O]);return K(P,{flexDirection:"column",paddingY:1,children:[K(P,{marginBottom:1,children:[p(v,{bold:!0,color:"cyan",children:"Klaudius setup"}),p(v,{dimColor:!0,children:" \xB7 "}),p(v,{dimColor:!0,children:D.total>0?`Step ${D.current} of ${D.total}`:"Loading\u2026"})]}),K(P,{children:[p(ne,{items:ye}),K(P,{flexDirection:"column",flexGrow:1,marginLeft:2,children:[a&&K(P,{marginBottom:1,borderStyle:"round",borderColor:"red",paddingX:1,flexDirection:"column",children:[p(v,{color:"red",bold:!0,children:"\u26A0 Heads up"}),p(v,{children:a})]}),E.map((d,h)=>p(P,{marginBottom:1,children:p(X,{title:d.title,body:d.body})},h)),y?.spec.note&&p(P,{marginBottom:1,children:p(X,{title:y.spec.note.title,body:y.spec.note.body})}),y&&We(y),O&&p(P,{marginTop:1,children:p(v,{color:"red",children:O})}),Z&&p(P,{marginTop:1,children:p(v,{color:"green",bold:!0,children:"\u2713 Setup complete. Continuing\u2026"})})]})]}),p(P,{marginTop:1,children:p(v,{dimColor:!0,children:"\u21B5 confirm esc back to previous section ctrl-c cancel"})})]})}function We(e){let t=a=>e.resolve(a),s=()=>e.reject(new B);switch(e.spec.type){case"text":case"password":return p(ie,{spec:e.spec,masked:e.spec.type==="password",onSubmit:t,onBack:s},e.id);case"select":return p(ce,{spec:e.spec,onSubmit:t,onBack:s},e.id);case"confirm":return p(de,{spec:e.spec,onSubmit:t,onBack:s},e.id)}}export{Ot as WizardApp};
package/dist/bin.js CHANGED
@@ -1,43 +1,43 @@
1
1
  #!/usr/bin/env node
2
- import{a as A,b as B,c as V}from"./chunk-OUNGUMWF.js";import{a as $,e as G}from"./chunk-47ODNABO.js";import{Command as dt}from"commander";import{mkdir as We,readdir as Ye,readFile as de,stat as ze,writeFile as pe}from"fs/promises";import{resolve as Xe,isAbsolute as qe,join as D}from"path";import*as d from"@clack/prompts";import h from"picocolors";import Se from"react";import{render as Pe}from"ink";async function w(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-T4VJERQN.js"),t=null;A("runWizard:start",{onlySection:s.onlySection,hasDefaults:Object.keys(e).length>0}),V(),await new Promise(l=>setImmediate(l)),await new Promise(l=>setTimeout(l,0)),A("runWizard:event loop drained, mounting Ink");let r=Pe(Se.createElement(n,{defaults:e,onlySection:s.onlySection,banner:s.banner,onComplete:l=>{A("runWizard:onComplete called",{keys:Object.keys(l).length}),t=l}}),{stdout:process.stdout,stderr:process.stderr,stdin:process.stdin,exitOnCtrlC:!1});if(A("runWizard:render returned, awaiting exit"),await r.waitUntilExit(),A("runWizard:waitUntilExit resolved",{resultIsNull:t===null}),!t)throw new Error(`Wizard exited without completing. Diagnostic log: ${B}
3
- Please share that file so we can trace what happened.`);return t}function R(e){let s=[],n=r=>{s.push(""),s.push("# "+"=".repeat(60)),s.push(`# ${r}`),s.push("# "+"=".repeat(60)),s.push("")},t=(r,l)=>{l==null||l===""?s.push(`# ${r}=`):s.push(`${r}=${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),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_TEAM_SCOPE",e.vercelTeamScope),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 A,b as B,c as F,e as V}from"./chunk-GI7NTKNT.js";import{a as N,e as G}from"./chunk-47ODNABO.js";import{Command as ht}from"commander";import{mkdir as fe,readdir as qe,readFile as me,stat as Je,writeFile as he}from"fs/promises";import{resolve as Qe,isAbsolute as Ze,join as x}from"path";import*as p from"@clack/prompts";import m from"picocolors";import _e from"react";import{render as Te}from"ink";async function w(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-PTMPD2IP.js"),t=null;A("runWizard:start",{onlySection:s.onlySection,hasDefaults:Object.keys(e).length>0}),F(),await new Promise(l=>setImmediate(l)),await new Promise(l=>setTimeout(l,0)),A("runWizard:event loop drained, mounting Ink");let a=Te(_e.createElement(n,{defaults:e,onlySection:s.onlySection,banner:s.banner,onComplete:l=>{A("runWizard:onComplete called",{keys:Object.keys(l).length}),t=l}}),{stdout:process.stdout,stderr:process.stderr,stdin:process.stdin,exitOnCtrlC:!1});if(A("runWizard:render returned, awaiting exit"),await a.waitUntilExit(),A("runWizard:waitUntilExit resolved",{resultIsNull:t===null}),!t)throw new Error(`Wizard exited without completing. Diagnostic log: ${B}
3
+ Please share that file so we can trace what happened.`);return t}function R(e){let s=[],n=a=>{s.push(""),s.push("# "+"=".repeat(60)),s.push(`# ${a}`),s.push("# "+"=".repeat(60)),s.push("")},t=(a,l)=>{if(l==null||l===""){s.push(`# ${a}=`);return}let c=String(l);if(/[\s"'`$\\#&|<>;()*?\[\]{}!~]/.test(c)){let r=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`");s.push(`${a}="${r}"`)}else s.push(`${a}=${c}`)};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),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),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 C(e){let s={mcpServers:{"shadcn-ui":{command:"npx",args:["-y","@jpisnice/shadcn-ui-mcp-server"]},"page-design-guide":{command:"npx",args:["-y","page-design-guide-mcp"]},supabase:{type:"http",url:`https://mcp.supabase.com/mcp?project_ref=${e.supabaseProjectRef}`,headers:{Authorization:`Bearer ${e.supabasePat}`}}}};return JSON.stringify(s,null,2)+`
6
- `}function P(e){let s={};for(let n of e.split(`
7
- `)){let t=n.trim();if(!t||t.startsWith("#"))continue;let r=t.indexOf("=");if(r===-1)continue;let l=t.slice(0,r).trim(),u=t.slice(r+1).trim();s[l]=u}return s}function W(e){let s=l=>{let u=e[l];if(!u)return;let a=parseInt(u,10);return isNaN(a)?void 0:a},n=e.SMS_PROVIDER,t=e.OUTREACH_CHANNELS?.split(",").map(l=>l.trim()).filter(l=>l==="email"||l==="sms"),r=e.OUTREACH_PRIORITY;return{pricing:e.PRICING,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:r==="email"||r==="sms"?r:void 0,emailAddress:e.EMAIL_ADDRESS,emailFromName:e.EMAIL_FROM_NAME,emailSmtpHost:e.EMAIL_SMTP_HOST,emailSmtpPort:s("EMAIL_SMTP_PORT"),emailImapHost:e.EMAIL_IMAP_HOST,emailImapPort:s("EMAIL_IMAP_PORT"),emailSentFolder:e.EMAIL_SENT_FOLDER,emailInboxFolder:e.EMAIL_INBOX_FOLDER,smsProvider:n==="imessage"||n==="twilio"?n:void 0,testPhone:e.TEST_PHONE,twilioAccountSid:e.TWILIO_ACCOUNT_SID,twilioPhoneNumber:e.TWILIO_PHONE_NUMBER,vercelTeamScope:e.VERCEL_TEAM_SCOPE,supabaseUrl:e.SUPABASE_URL,supabaseProjectRef:e.SUPABASE_PROJECT_REF,googlePlacesApiKey:e.GOOGLE_PLACES_API_KEY,serpapiKey:e.SERPAPI_KEY,telegramChatId:e.TELEGRAM_CHAT_ID}}function N(e){let s=k=>{let o=e[k];if(!o)return;let c=parseInt(o,10);return isNaN(c)?void 0:c},n=e.SUPABASE_URL,t=e.SUPABASE_SERVICE_KEY,r=e.SUPABASE_PAT,l=e.SUPABASE_PROJECT_REF,u=e.PRICING,a=e.VERCEL_TOKEN;if(!u||!n||!t||!r||!l||!a)return null;let m=e.SMS_PROVIDER,f=e.OUTREACH_CHANNELS?.split(",").map(k=>k.trim()).filter(k=>k==="email"||k==="sms"),g=e.OUTREACH_PRIORITY;return{licenseKey:e.KLAUDIUS_LICENSE_KEY,pricing:u,outreachEnabled:e.OUTREACH_ENABLED?.toLowerCase()==="true",name:e.OPERATOR_NAME,signature:e.SIGNATURE,outreachChannels:f&&f.length>0?f:void 0,outreachPriority:g==="email"||g==="sms"?g: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:m==="imessage"||m==="twilio"?m:void 0,testPhone:e.TEST_PHONE,twilioAccountSid:e.TWILIO_ACCOUNT_SID,twilioAuthToken:e.TWILIO_AUTH_TOKEN,twilioPhoneNumber:e.TWILIO_PHONE_NUMBER,vercelToken:a,vercelTeamScope:e.VERCEL_TEAM_SCOPE,supabaseUrl:n,supabaseServiceKey:t,supabasePat:r,supabaseProjectRef:l,googlePlacesApiKey:e.GOOGLE_PLACES_API_KEY,serpapiKey:e.SERPAPI_KEY,telegramBotToken:e.TELEGRAM_BOT_TOKEN,telegramChatId:e.TELEGRAM_CHAT_ID}}import{mkdir as Ae,rm as be}from"fs/promises";import{Readable as Te}from"stream";import*as Y from"tar";var _e="https://klaudius.dev/api/template";function Ie(e){return Te.fromWeb(e)}async function v(e){let s=process.env.KLAUDIUS_TEMPLATE_URL??_e,n="0.2.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(u){throw new Error(`Could not reach klaudius.dev to download the template: ${u.message}`)}if(!t.ok){let u="";try{let a=await t.json();u=a.reason?` (${a.reason})`:""}catch{}throw new Error(`Template download failed: HTTP ${t.status}${u}`)}if(!t.body)throw new Error("Template download succeeded but response had no body");let r=t.headers.get("x-klaudius-tier");await Ae(e.destDir,{recursive:!0});let l=0;try{await new Promise((u,a)=>{let m=Y.extract({cwd:e.destDir,strict:!0,onReadEntry:()=>{l++}});m.on("finish",u),m.on("error",a),Ie(t.body).on("error",a).pipe(m)})}catch(u){throw await be(e.destDir,{recursive:!0,force:!0}).catch(()=>{}),new Error(`Failed to extract template archive: ${u.message}`)}return{filesExtracted:l,tier:r}}import{mkdir as Re,readFile as Ce,writeFile as ve,access as Oe}from"fs/promises";import{dirname as Le,join as z}from"path";var Me=".klaudius",X=`${Me}/manifest.json`;async function q(e){let s=z(e,X);try{await Oe(s)}catch{return null}let n=await Ce(s,"utf-8");return JSON.parse(n)}async function O(e,s){let n=z(e,X);await Re(Le(n),{recursive:!0}),await ve(n,JSON.stringify(s,null,2)+`
8
- `,"utf-8")}function J(e,s){let n=new Date().toISOString();return{version:1,templateVersion:e,installedAt:n,updatedAt:n,files:s}}import{createHash as xe}from"crypto";import{hostname as Q,userInfo as $e,platform as Z,arch as ee}from"os";import E from"picocolors";var i={info:e=>console.log(E.cyan("\u2139"),e),success:e=>console.log(E.green("\u2713"),e),warn:e=>console.log(E.yellow("\u26A0"),e),error:e=>console.error(E.red("\u2717"),e),step:e=>console.log(E.dim("\u2192"),e),blank:()=>console.log(""),heading:e=>console.log(`
9
- `+E.bold(E.cyan(e))),detail:e=>console.log(E.dim(" "+e))};var Ne="https://klaudius.dev",Ue="/api/licenses/validate",De="0.2.0";async function te(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??Ne).replace(/\/$/,"")+Ue,r=_(),l;try{l=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({license_key:s,machine_id:r,hostname:Q(),os:`${Z()}-${ee()}`,cli_version:De})})}catch(a){return{ok:!1,reason:`Could not reach the Klaudius license server (${a instanceof Error?a.message:"unknown"}). Check your internet connection or try again later.`}}let u;try{u=await l.json()}catch{return{ok:!1,reason:`License server returned an unparseable response (HTTP ${l.status}).`}}return u.ok?{ok:!0,tier:u.tier??"core"}:{ok:!1,reason:u.reason??`License rejected (HTTP ${l.status}).`}}function _(){let e=[Q(),$e().username,Z(),ee()].join("|");return xe("sha256").update(e).digest("hex").slice(0,32)}import{readFile as Ke}from"fs/promises";import{join as He}from"path";async function L(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: ${s.message}`}}}async function se(e){let s;try{s=await Ke(He(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 ne(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: ${s.message}`}}}async function ie(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??"",r=n.error?.status??"";return s.status===400&&(r==="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: ${s.message}`}}}import je from"nodemailer";import{ImapFlow as Fe}from"imapflow";async function re(e){let s=je.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:ae(t,"SMTP")}}finally{s.close()}let n=new Fe({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:ae(t,"IMAP")}}return{ok:!0}}function ae(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:
5
+ `}function C(e){let s={mcpServers:{supabase:{command:"npx",args:["-y","@supabase/mcp-server-supabase@latest",`--project-ref=${e.supabaseProjectRef}`],env:{SUPABASE_ACCESS_TOKEN:e.supabasePat}}}};return JSON.stringify(s,null,2)+`
6
+ `}function be(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 P(e){let s={};for(let n of e.split(`
7
+ `)){let t=n.trim();if(!t||t.startsWith("#"))continue;let a=t.indexOf("=");if(a===-1)continue;let l=t.slice(0,a).trim(),c=be(t.slice(a+1).trim());s[l]=c}return s}function W(e){let s=l=>{let c=e[l];if(!c)return;let r=parseInt(c,10);return isNaN(r)?void 0:r},n=e.SMS_PROVIDER,t=e.OUTREACH_CHANNELS?.split(",").map(l=>l.trim()).filter(l=>l==="email"||l==="sms"),a=e.OUTREACH_PRIORITY;return{licenseKey:e.KLAUDIUS_LICENSE_KEY,pricing:e.PRICING,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:a==="email"||a==="sms"?a: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,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 U(e){let s=k=>{let o=e[k];if(!o)return;let u=parseInt(o,10);return isNaN(u)?void 0:u},n=e.SUPABASE_URL,t=e.SUPABASE_SERVICE_KEY,a=e.SUPABASE_PAT,l=e.SUPABASE_PROJECT_REF,c=e.PRICING,r=e.VERCEL_TOKEN;if(!c||!n||!t||!a||!l||!r)return null;let h=e.SMS_PROVIDER,f=e.OUTREACH_CHANNELS?.split(",").map(k=>k.trim()).filter(k=>k==="email"||k==="sms"),g=e.OUTREACH_PRIORITY;return{licenseKey:e.KLAUDIUS_LICENSE_KEY,pricing:c,outreachEnabled:e.OUTREACH_ENABLED?.toLowerCase()==="true",name:e.OPERATOR_NAME,signature:e.SIGNATURE,outreachChannels:f&&f.length>0?f:void 0,outreachPriority:g==="email"||g==="sms"?g: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:h==="imessage"||h==="twilio"?h:void 0,testPhone:e.TEST_PHONE,twilioAccountSid:e.TWILIO_ACCOUNT_SID,twilioAuthToken:e.TWILIO_AUTH_TOKEN,twilioPhoneNumber:e.TWILIO_PHONE_NUMBER,vercelToken:r,supabaseUrl:n,supabaseServiceKey:t,supabasePat:a,supabaseProjectRef:l,googlePlacesApiKey:e.GOOGLE_PLACES_API_KEY,serpapiKey:e.SERPAPI_KEY,telegramBotToken:e.TELEGRAM_BOT_TOKEN,telegramChatId:e.TELEGRAM_CHAT_ID}}import{mkdir as Ie,rm as Re}from"fs/promises";import{Readable as Ce}from"stream";import*as Y from"tar";var ve="https://klaudius.dev/api/template";function Oe(e){return Ce.fromWeb(e)}async function v(e){let s=process.env.KLAUDIUS_TEMPLATE_URL??ve,n="0.3.1",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(c){throw new Error(`Could not reach klaudius.dev to download the template: ${c.message}`)}if(!t.ok){let c="";try{let r=await t.json();c=r.reason?` (${r.reason})`:""}catch{}throw new Error(`Template download failed: HTTP ${t.status}${c}`)}if(!t.body)throw new Error("Template download succeeded but response had no body");let a=t.headers.get("x-klaudius-tier");await Ie(e.destDir,{recursive:!0});let l=0;try{await new Promise((c,r)=>{let h=Y.extract({cwd:e.destDir,strict:!0,onReadEntry:()=>{l++}});h.on("finish",c),h.on("error",r),Oe(t.body).on("error",r).pipe(h)})}catch(c){throw await Re(e.destDir,{recursive:!0,force:!0}).catch(()=>{}),new Error(`Failed to extract template archive: ${c.message}`)}return{filesExtracted:l,tier:a}}import{mkdir as Le,readFile as xe,writeFile as Me,access as $e}from"fs/promises";import{dirname as Ne,join as z}from"path";var Ue=".klaudius",X=`${Ue}/manifest.json`;async function q(e){let s=z(e,X);try{await $e(s)}catch{return null}let n=await xe(s,"utf-8");return JSON.parse(n)}async function O(e,s){let n=z(e,X);await Le(Ne(n),{recursive:!0}),await Me(n,JSON.stringify(s,null,2)+`
8
+ `,"utf-8")}function J(e,s){let n=new Date().toISOString();return{version:1,templateVersion:e,installedAt:n,updatedAt:n,files:s}}import{createHash as Ke}from"crypto";import{hostname as Q,userInfo as De,platform as Z,arch as ee}from"os";import E from"picocolors";var i={info:e=>console.log(E.cyan("\u2139"),e),success:e=>console.log(E.green("\u2713"),e),warn:e=>console.log(E.yellow("\u26A0"),e),error:e=>console.error(E.red("\u2717"),e),step:e=>console.log(E.dim("\u2192"),e),blank:()=>console.log(""),heading:e=>console.log(`
9
+ `+E.bold(E.cyan(e))),detail:e=>console.log(E.dim(" "+e))};var He="https://klaudius.dev",je="/api/licenses/validate",Be="0.3.1";async function te(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??He).replace(/\/$/,"")+je,a=b(),l;try{l=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({license_key:s,machine_id:a,hostname:Q(),os:`${Z()}-${ee()}`,cli_version:Be})})}catch(r){return{ok:!1,reason:`Could not reach the Klaudius license server (${r instanceof Error?r.message:"unknown"}). Check your internet connection or try again later.`}}let c;try{c=await l.json()}catch{return{ok:!1,reason:`License server returned an unparseable response (HTTP ${l.status}).`}}return c.ok?{ok:!0,tier:c.tier??"core"}:{ok:!1,reason:c.reason??`License rejected (HTTP ${l.status}).`}}function b(){let e=[Q(),De().username,Z(),ee()].join("|");return Ke("sha256").update(e).digest("hex").slice(0,32)}import{readFile as Fe}from"fs/promises";import{join as Ve}from"path";async function L(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: ${s.message}`}}}async function se(e){let s;try{s=await Fe(Ve(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 ie(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: ${s.message}`}}}async function ne(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??"",a=n.error?.status??"";return s.status===400&&(a==="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: ${s.message}`}}}import Ge from"nodemailer";import{ImapFlow as We}from"imapflow";async function ae(e){let s=Ge.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 We({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
10
  \u2022 The app password is wrong, expired, or for a different provider.
11
11
  \u2022 The email address doesn't match the account that issued the password.
12
- \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 oe(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 r=await t.json();return r.status&&r.status!=="active"?{ok:!1,message:`Twilio account is in '${r.status}' state. Check the console for any holds before sending SMS.`}:{ok:!0,friendlyName:r.friendly_name}}catch(t){return{ok:!1,message:`Could not reach Twilio: ${t.message}`}}}async function le(e){let s;try{let n=await fetch(`https://api.telegram.org/bot${encodeURIComponent(e.botToken)}/getMe`),t=await n.json();if(!t.ok)return{ok:!1,failedAt:"token",message:`Telegram rejected the bot token: ${t.description??`HTTP ${n.status}`}. Generate a new token by messaging @BotFather \u2192 /mytoken or /newbot.`};s=t.result?.username?`@${t.result.username}`:t.result?.first_name}catch(n){return{ok:!1,failedAt:"token",message:`Could not reach Telegram: ${n.message}`}}try{let n=await fetch(`https://api.telegram.org/bot${encodeURIComponent(e.botToken)}/sendMessage`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chat_id:e.chatId,text:"\u2713 Klaudius connected. You'll get a notification here whenever outreach lands or a candidate replies. (You can ignore this setup message.)",disable_notification:!0})}),t=await n.json();if(!t.ok){let r=t.description??`HTTP ${n.status}`,l="";return/chat not found/i.test(r)?l=" The chat_id is wrong, or the bot hasn't been added to that chat yet. If it's a group, you must add the bot to the group first; then send /start to it.":(/bot was blocked/i.test(r)||/forbidden/i.test(r))&&(l=" The bot has been blocked by the chat, or never received a /start. Open Telegram, find your bot, and send /start to wake it up."),{ok:!1,failedAt:"chat",botHandle:s,message:`Telegram delivered the bot token check but couldn't send to chat_id ${e.chatId}: ${r}.${l}`}}}catch(n){return{ok:!1,failedAt:"chat",botHandle:s,message:`Could not reach Telegram for chat_id check: ${n.message}`}}return{ok:!0,botHandle:s}}import{spawn as Be}from"child_process";async function ce(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 Ve(n);if(t.code===0)return{ok:!0};let r=t.stderr.toLowerCase();return r.includes("can't get application")||r.includes("isn't running")||r.includes("can't make some data")?{ok:!1,message:"Messages.app didn't respond. Open Messages on your Mac and sign in with your Apple ID, then retry."}:r.includes("(-1728)")||r.includes("not found")||r.includes("buddy")?{ok:!1,message:`Couldn't reach ${e.testPhone}. Either the number format is wrong (use the international format with a leading +) or this Mac doesn't have a path to that number. If TEST_PHONE is a non-Apple phone (Android), you need an iPhone signed into the same Apple ID with Settings \u2192 Messages \u2192 Text Message Forwarding turned ON for this Mac.`}:r.includes("(-1719)")||r.includes("(-25006)")?{ok:!1,message:"Messages.app refused the send \u2014 usually means iMessage isn't configured on this Mac. Open Messages \u2192 Settings \u2192 iMessage and sign in with your Apple ID."}:{ok:!1,message:`osascript error: ${t.stderr.trim()||`exit code ${t.code}`}`}}function Ve(e){return new Promise(s=>{let n=Be("osascript",["-e",e],{stdio:["ignore","ignore","pipe"]}),t="";n.stderr.on("data",r=>{t+=r.toString()}),n.on("close",r=>s({code:r??1,stderr:t})),n.on("error",r=>s({code:1,stderr:r.message}))})}import{spawn as Ge}from"child_process";function U(e,s,n){return new Promise(t=>{let r=Ge(e,s,{cwd:n.cwd,stdio:n.inherit!==!1?"inherit":"pipe",shell:!1});r.on("close",l=>t(l??1)),r.on("error",()=>t(1))})}async function ue(e){let s={npm:"skipped",pip:"skipped",playwright:"skipped"};i.step("Running npm install (Next.js, Playwright JS, etc.)...");let n=await U("npm",["install"],{cwd:e});s.npm=n===0?"ok":"failed",i.step("Installing Python packages (supabase, dotenv, requests, httpx, Pillow)...");let t=await U("pip3",["install","--quiet","--user","--break-system-packages","supabase","python-dotenv","requests","httpx","Pillow"],{cwd:e});s.pip=t===0?"ok":"failed",i.step("Installing Playwright browser (chromium ~200MB; one-time)...");let r=await U("npx",["playwright","install","chromium"],{cwd:e});return s.playwright=r===0?"ok":"failed",s}async function me(e){let s=e.target??".",n=qe(s)?s:Xe(process.cwd(),s),t=await Je(n);t.kind==="occupied"&&(i.error(`Target directory is not empty: ${n}`),i.detail(`Contains: ${t.entries.slice(0,5).join(", ")}${t.entries.length>5?", ...":""}`),i.detail("Either choose a fresh directory, or delete the existing one and retry."),process.exit(1));let r=await Ze(e.license),l=d.spinner();l.start("Validating license");let u=await te(r);u.ok||(l.stop(`License invalid: ${u.reason??"unknown"}`,2),i.detail("If you believe this is in error, email hello@klaudius.dev with your purchase details."),process.exit(1)),l.stop(`License valid (${u.tier??"core"} tier)`);let a,m=!1;if(t.kind==="partial")if(await Qe(n)==="resume"){let c=await de(t.envPath,"utf-8"),p=N(P(c));p?(i.success("Resuming with values from your existing .env"),i.detail("(Skipping the wizard \u2014 edit .env directly if you need to change anything.)"),a=p,m=!0):(i.warn("Existing .env was missing required fields \u2014 starting wizard fresh."),a=await w())}else{let c=await de(t.envPath,"utf-8"),p=N(P(c));a=await w(p??{})}else a=await w();for(a.licenseKey=r,await S(n,a),m||(i.success("Saved .env"),i.success("Saved .mcp.json")),i.blank();;){let o=d.spinner();o.start("Validating Supabase credentials");let c=await L({url:a.supabaseUrl,serviceKey:a.supabaseServiceKey});if(c.ok){o.stop("Supabase credentials accepted");break}o.stop(c.message??"Supabase check failed",2);let p=c.message??"Supabase check failed";i.blank(),i.warn("Bouncing you back into the Supabase section so you can fix it in place."),i.detail("(Press Enter through any field to keep its current value. Ctrl+C to exit.)"),i.blank(),a=await w(a,{onlySection:"supabase",banner:`Supabase rejected your credentials:
13
- ${p}
12
+ \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 oe(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 a=await t.json();return a.status&&a.status!=="active"?{ok:!1,message:`Twilio account is in '${a.status}' state. Check the console for any holds before sending SMS.`}:{ok:!0,friendlyName:a.friendly_name}}catch(t){return{ok:!1,message:`Could not reach Twilio: ${t.message}`}}}import{spawn as Ye}from"child_process";async function le(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 ze(n);if(t.code===0)return{ok:!0};let a=t.stderr.toLowerCase();return a.includes("can't get application")||a.includes("isn't running")||a.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."}:a.includes("(-1728)")||a.includes("not found")||a.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.`}:a.includes("(-1719)")||a.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 ze(e){return new Promise(s=>{let n=Ye("osascript",["-e",e],{stdio:["ignore","ignore","pipe"]}),t="";n.stderr.on("data",a=>{t+=a.toString()}),n.on("close",a=>s({code:a??1,stderr:t})),n.on("error",a=>s({code:1,stderr:a.message}))})}import{spawn as pe}from"child_process";function ce(e,s,n){return new Promise(t=>{let a=pe(e,s,{cwd:n.cwd,stdio:n.inherit!==!1?"inherit":"pipe",shell:!1});a.on("close",l=>t(l??1)),a.on("error",()=>t(1))})}function ue(e,s,n){return new Promise(t=>{let a=pe(e,s,{cwd:n.cwd,stdio:["ignore","pipe","pipe"],shell:!1}),l="",c="";a.stdout?.on("data",r=>{l+=r.toString()}),a.stderr?.on("data",r=>{c+=r.toString()}),a.on("close",r=>t({code:r??1,stdout:l,stderr:c})),a.on("error",r=>t({code:1,stdout:l,stderr:c+r.message}))})}async function Xe(e){let s=["supabase","python-dotenv","requests","httpx","Pillow"],n=["install","--quiet","--user"],t=await ue("pip3",[...n,"--break-system-packages",...s],{cwd:e});return t.code!==0&&/no such option:.*break-system-packages/i.test(t.stderr)&&(i.detail("Older pip detected; retrying without --break-system-packages"),t=await ue("pip3",[...n,...s],{cwd:e})),t.code!==0?(t.stderr.trim()&&process.stderr.write(t.stderr),t.stdout.trim()&&process.stdout.write(t.stdout),"failed"):"ok"}async function de(e){let s={npm:"skipped",pip:"skipped",playwright:"skipped"};i.step("Running npm install (Next.js, Playwright JS, etc.)...");let n=await ce("npm",["install"],{cwd:e});s.npm=n===0?"ok":"failed",i.step("Installing Python packages (supabase, dotenv, requests, httpx, Pillow)..."),s.pip=await Xe(e),i.step("Installing Playwright browser (chromium ~200MB; one-time)...");let t=await ce("npx",["playwright","install","chromium"],{cwd:e});return s.playwright=t===0?"ok":"failed",s}async function ge(e){let s=e.target??".",n=Ze(s)?s:Qe(process.cwd(),s),t=await et(n);if(t.kind==="occupied"){let o=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(),o?(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 a=await st(e.license),l=p.spinner();l.start("Validating license");let c=await te(a);c.ok||(l.stop(`License invalid: ${c.reason??"unknown"}`,2),i.detail("If you believe this is in error, email hello@klaudius.dev with your purchase details."),process.exit(1)),l.stop(`License valid (${c.tier??"core"} tier)`);let r,h=!1;if(t.kind==="partial")if(await tt(n)==="resume"){let u=await me(t.envPath,"utf-8"),d=U(P(u));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,h=!0):(i.warn("Existing .env was missing required fields \u2014 starting wizard fresh."),r=await w())}else{let u=await me(t.envPath,"utf-8"),d=U(P(u));r=await w(d??{})}else r=await w();for(r.licenseKey=a,await S(n,r),h||(i.success("Saved .env"),i.success("Saved .mcp.json")),i.blank();;){let o=p.spinner();o.start("Validating Supabase credentials");let u=await L({url:r.supabaseUrl,serviceKey:r.supabaseServiceKey});if(u.ok){o.stop("Supabase credentials accepted");break}o.stop(u.message??"Supabase check failed",2);let d=u.message??"Supabase check failed";i.blank(),i.warn("Bouncing you back into the Supabase section so you can fix it in place."),i.detail("(Press Enter through any field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await w(r,{onlySection:"supabase",banner:`Supabase rejected your credentials:
13
+ ${d}
14
14
 
15
15
  Re-enter the URL, secret key, or PAT below. Press Enter on any
16
- field to keep what's already there.`}),await S(n,a)}for(i.blank();;){let o=d.spinner();o.start("Validating Vercel token");let c=await ne(a.vercelToken);if(c.ok){o.stop(c.username?`Vercel token accepted (signed in as ${c.username})`:"Vercel token accepted");break}o.stop(c.message??"Vercel check failed",2);let p=c.message??"Vercel check failed";i.blank(),i.warn("Bouncing you back into the Vercel section so you can fix it in place."),i.detail("(Press Enter on the field to keep its current value. Ctrl+C to exit.)"),i.blank(),a=await w(a,{onlySection:"vercel",banner:`Vercel rejected the token:
17
- ${p}
16
+ field to keep what's already there.`}),await S(n,r)}for(i.blank();;){let o=p.spinner();o.start("Validating Vercel token");let u=await ie(r.vercelToken);if(u.ok){o.stop(u.username?`Vercel token accepted (signed in as ${u.username})`:"Vercel token accepted");break}o.stop(u.message??"Vercel check failed",2);let d=u.message??"Vercel check failed";i.blank(),i.warn("Bouncing you back into the Vercel section so you can fix it in place."),i.detail("(Press Enter on the field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await w(r,{onlySection:"vercel",banner:`Vercel rejected the token:
17
+ ${d}
18
18
 
19
19
  Generate a new token at https://vercel.com/account/tokens and
20
- paste it below. Press Enter to keep the current value.`}),await S(n,a)}for(i.blank();;){let o=d.spinner();o.start("Validating Google Places API key");let c=await ie(a.googlePlacesApiKey??"");if(c.ok){o.stop("Google Places API key accepted");break}o.stop(c.message??"Google Places check failed",2);let p=c.message??"Google Places check failed";i.blank(),i.warn("Bouncing you back into the Google Places section so you can fix it in place."),i.detail("(Press Enter on the field to keep its current value. Ctrl+C to exit.)"),i.blank(),a=await w(a,{onlySection:"google-places",banner:`Google rejected the key:
21
- ${p}
20
+ paste it below. Press Enter to keep the current value.`}),await S(n,r)}for(i.blank();;){let o=p.spinner();o.start("Validating Google Places API key");let u=await ne(r.googlePlacesApiKey??"");if(u.ok){o.stop("Google Places API key accepted");break}o.stop(u.message??"Google Places check failed",2);let d=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."),i.detail("(Press Enter on the field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await w(r,{onlySection:"google-places",banner:`Google rejected the key:
21
+ ${d}
22
22
 
23
23
  Generate (or fix) the key at https://console.cloud.google.com
24
- and paste it below. Press Enter to keep the current value.`}),await S(n,a)}if(a.outreachEnabled&&a.outreachChannels?.includes("email")&&a.emailAddress&&a.emailPassword&&a.emailSmtpHost&&a.emailSmtpPort&&a.emailImapHost&&a.emailImapPort)for(i.blank();;){let o=d.spinner();o.start("Validating email credentials (SMTP + IMAP)");let c=await re({emailAddress:a.emailAddress,emailPassword:a.emailPassword,emailSmtpHost:a.emailSmtpHost,emailSmtpPort:a.emailSmtpPort,emailImapHost:a.emailImapHost,emailImapPort:a.emailImapPort});if(c.ok){o.stop("Email credentials accepted (SMTP + IMAP)");break}o.stop(c.message??"Email check failed",2);let p=c.message??"Email check failed";i.blank(),i.warn("Bouncing you back into the email section so you can fix it in place."),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),a=await w(a,{onlySection:"email",banner:`${c.failedAt==="imap"?"IMAP":"SMTP"} check failed:
25
- ${p}
24
+ and paste it below. Press Enter to keep the current value.`}),await S(n,r)}if(r.outreachEnabled&&r.outreachChannels?.includes("email")&&r.emailAddress&&r.emailPassword&&r.emailSmtpHost&&r.emailSmtpPort&&r.emailImapHost&&r.emailImapPort)for(i.blank();;){let o=p.spinner();o.start("Validating email credentials (SMTP + IMAP)");let u=await ae({emailAddress:r.emailAddress,emailPassword:r.emailPassword,emailSmtpHost:r.emailSmtpHost,emailSmtpPort:r.emailSmtpPort,emailImapHost:r.emailImapHost,emailImapPort:r.emailImapPort});if(u.ok){o.stop("Email credentials accepted (SMTP + IMAP)");break}o.stop(u.message??"Email check failed",2);let d=u.message??"Email check failed";i.blank(),i.warn("Bouncing you back into the email section so you can fix it in place."),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await w(r,{onlySection:"email",banner:`${u.failedAt==="imap"?"IMAP":"SMTP"} check failed:
25
+ ${d}
26
26
 
27
27
  Re-enter the email address, app password, or host details below.
28
- Press Enter on any field to keep its current value.`}),await S(n,a)}if(a.outreachEnabled&&a.outreachChannels?.includes("sms")&&a.smsProvider==="twilio"&&a.twilioAccountSid&&a.twilioAuthToken)for(i.blank();;){let o=d.spinner();o.start("Validating Twilio credentials");let c=await oe({accountSid:a.twilioAccountSid,authToken:a.twilioAuthToken});if(c.ok){o.stop(c.friendlyName?`Twilio credentials accepted (${c.friendlyName})`:"Twilio credentials accepted");break}o.stop(c.message??"Twilio check failed",2);let p=c.message??"Twilio check failed";i.blank(),i.warn("Bouncing you back into the SMS section so you can fix it in place."),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),a=await w(a,{onlySection:"sms",banner:`Twilio rejected the credentials:
29
- ${p}
28
+ Press Enter on any field to keep its current value.`}),await S(n,r)}if(r.outreachEnabled&&r.outreachChannels?.includes("sms")&&r.smsProvider==="twilio"&&r.twilioAccountSid&&r.twilioAuthToken)for(i.blank();;){let o=p.spinner();o.start("Validating Twilio credentials");let u=await oe({accountSid:r.twilioAccountSid,authToken:r.twilioAuthToken});if(u.ok){o.stop(u.friendlyName?`Twilio credentials accepted (${u.friendlyName})`:"Twilio credentials accepted");break}o.stop(u.message??"Twilio check failed",2);let d=u.message??"Twilio check failed";i.blank(),i.warn("Bouncing you back into the SMS section so you can fix it in place."),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await w(r,{onlySection:"sms",banner:`Twilio rejected the credentials:
29
+ ${d}
30
30
 
31
31
  Re-enter the Account SID or Auth Token below.
32
- Press Enter on any field to keep its current value.`}),await S(n,a)}if(a.outreachEnabled&&a.outreachChannels?.includes("sms")&&a.smsProvider==="imessage"&&a.testPhone)for(i.blank();;){let o=d.spinner();o.start("Validating iMessage setup (sending a test ping)");let c=await ce({testPhone:a.testPhone});if(c.ok){o.stop("iMessage dispatched (check your phone for the test ping)");break}o.stop(c.message??"iMessage check failed",2);let p=c.message??"iMessage check failed";i.blank(),i.warn("Bouncing you back into the SMS section so you can fix it in place."),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),a=await w(a,{onlySection:"sms",banner:`iMessage check failed:
33
- ${p}
32
+ Press Enter on any field to keep its current value.`}),await S(n,r)}if(r.outreachEnabled&&r.outreachChannels?.includes("sms")&&r.smsProvider==="imessage"&&r.testPhone)for(i.blank();;){let o=p.spinner();o.start("Validating iMessage setup (sending a test ping)");let u=await le({testPhone:r.testPhone});if(u.ok){o.stop("iMessage dispatched (check your phone for the test ping)");break}o.stop(u.message??"iMessage check failed",2);let d=u.message??"iMessage check failed";i.blank(),i.warn("Bouncing you back into the SMS section so you can fix it in place."),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await w(r,{onlySection:"sms",banner:`iMessage check failed:
33
+ ${d}
34
34
 
35
35
  Either fix the underlying issue (sign in to Messages.app, configure
36
36
  Text Message Forwarding) and press Enter through, or change SMS
37
- provider to Twilio.`}),await S(n,a)}if(a.telegramBotToken&&a.telegramChatId)for(i.blank();;){let o=d.spinner();o.start("Validating Telegram bot + chat (sending a test ping)");let c=await le({botToken:a.telegramBotToken,chatId:a.telegramChatId});if(c.ok){o.stop(c.botHandle?`Telegram bot ${c.botHandle} accepted, test message delivered`:"Telegram credentials accepted, test message delivered");break}o.stop(c.message??"Telegram check failed",2);let p=c.message??"Telegram check failed";i.blank(),i.warn("Bouncing you back into the Telegram section so you can fix it in place."),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),a=await w(a,{onlySection:"telegram",banner:`Telegram check failed:
38
- ${p}
37
+ provider to Twilio.`}),await S(n,r)}if(r.telegramBotToken&&r.telegramChatId)for(i.blank();;){let o=p.spinner();o.start("Validating Telegram bot + chat (sending a test ping)");let u=await V({botToken:r.telegramBotToken,chatId:r.telegramChatId});if(u.ok){o.stop(u.botHandle?`Telegram bot ${u.botHandle} accepted, test message delivered`:"Telegram credentials accepted, test message delivered");break}o.stop(u.message??"Telegram check failed",2);let d=u.message??"Telegram check failed";i.blank(),i.warn("Bouncing you back into the Telegram section so you can fix it in place."),i.detail("(Press Enter on any field to keep its current value. Ctrl+C to exit.)"),i.blank(),r=await w(r,{onlySection:"telegram",banner:`Telegram check failed:
38
+ ${d}
39
39
 
40
40
  Re-enter the bot token or chat_id below.
41
- Press Enter on any field to keep its current value.`}),await S(n,a)}i.blank();let f=d.spinner();f.start("Downloading Klaudius template");let g;try{g=(await v({licenseKey:r,machineId:_(),hostname:process.platform==="win32"?process.env.COMPUTERNAME:void 0,os:`${process.platform}-${process.arch}`,destDir:n})).filesExtracted,f.stop(`Downloaded ${g} files into ${h.bold(n)}`)}catch(o){f.stop(o.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)}let k=await G(n);if(await O(n,J("0.1.0",k)),i.success("Wrote .klaudius/manifest.json"),e.skipSchema)i.warn("--skip-schema set; not applying scripts/schema.sql to your Supabase project."),i.detail(`Apply manually later via the SQL editor: ${a.supabaseUrl.replace("https://","https://supabase.com/dashboard/project/"+a.supabaseProjectRef+"/sql/new").replace(a.supabaseProjectRef+".supabase.co","")}`);else{i.blank();let o=d.spinner();o.start("Applying schema to Supabase");let c=await se({projectRoot:n,pat:a.supabasePat,projectRef:a.supabaseProjectRef});c.ok?o.stop("Schema applied (or already present)"):(o.stop(c.message??"Schema apply failed",2),i.warn("Apply scripts/schema.sql manually in your Supabase SQL editor before running the pipeline."))}if(e.skipInstall)i.warn("--skip-install set; you'll need to run npm install + pip install + playwright install yourself.");else{i.blank(),i.heading("Installing dependencies");let o=await ue(n);i.detail(`npm: ${o.npm}, pip: ${o.pip}, playwright: ${o.playwright}`),(o.npm==="failed"||o.pip==="failed"||o.playwright==="failed")&&i.warn("Some installers failed. You can re-run them manually with `bash setup.sh`.")}i.blank(),d.outro(h.green(h.bold("Project ready."))),console.log(h.dim("Next steps:")),n!==process.cwd()&&console.log(` ${h.cyan(`cd ${e.target}`)}`),console.log(` ${h.cyan("claude")} ${h.dim("# open Claude Code in this project")}`),console.log(` ${h.dim("then ask Claude:")}`),console.log(` ${h.cyan(' "Run the pipeline."')}`),i.blank(),console.log(h.dim("Klaudius ships with sensible defaults for tone, follow-up cadence, pitch")),console.log(h.dim("and more \u2014 but you don't have to live with them. Customise by talking to")),console.log(h.dim("Claude inside this project. Examples you can ask:")),console.log(h.dim(' "Make the outreach more casual."')),console.log(h.dim(' "Change the follow-up cadence to weekly."')),console.log(h.dim(` "Don't pitch businesses with fewer than 5 reviews."`)),console.log(h.dim(' "Use a different opening hook for restaurants."')),console.log(h.dim("Claude knows where to make the change \u2014 no config files to edit by hand.")),i.blank()}async function S(e,s){await We(e,{recursive:!0}),await pe(D(e,".env"),R(s),"utf-8"),await pe(D(e,".mcp.json"),C(s),"utf-8")}async function Je(e){try{(await ze(e)).isDirectory()||(i.error(`Target exists but is not a directory: ${e}`),process.exit(1))}catch{return{kind:"fresh"}}let s=await Ye(e),n=s.filter(a=>!a.startsWith(".DS_Store"));if(n.length===0)return{kind:"fresh"};let t=new Set([".env",".mcp.json"]),r=n.every(a=>t.has(a)),l=n.includes(".env"),u=s.includes(".klaudius");return r&&l&&!u?{kind:"partial",envPath:D(e,".env")}:{kind:"occupied",entries:n}}async function Qe(e){i.blank(),i.warn(`Found a partial setup at ${h.bold(e)}.`),i.detail(`A previous init wrote ${h.bold(".env")} but didn't finish scaffolding.`),i.blank();let s=await d.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 d.isCancel(s)&&(d.cancel("Setup cancelled. Existing .env left in place."),process.exit(0)),s}async function Ze(e){if(e&&e.trim().length>0)return e;d.intro("Klaudius");let s=await d.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 d.isCancel(s)&&(d.cancel("Setup cancelled. No files written."),process.exit(0)),s}import{readFile as et,writeFile as he,access as tt}from"fs/promises";import{join as K}from"path";import*as M from"@clack/prompts";import st from"picocolors";async function fe(e){let s=e.projectRoot??process.cwd(),n=K(s,".env"),t=K(s,".mcp.json");try{await tt(K(s,".klaudius","manifest.json"))}catch{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 r={};try{let a=await et(n,"utf-8");r=P(a)}catch{i.warn("No .env found. Starting from an empty configuration.")}let l=W(r);M.intro("Reconfigure Klaudius"),i.detail("Press Enter on any prompt to keep its current value."),i.blank();let u=await w(l);if(u.supabaseUrl!==r.SUPABASE_URL||u.supabaseServiceKey!==r.SUPABASE_SERVICE_KEY){i.heading("Re-validating Supabase credentials");let a=await L({url:u.supabaseUrl,serviceKey:u.supabaseServiceKey});a.ok||(i.error(a.message??"Supabase check failed"),i.warn("Aborting. .env not modified."),process.exit(1)),i.success("Supabase credentials accepted")}await he(n,R(u),"utf-8"),i.success("Updated .env"),(u.supabaseProjectRef!==r.SUPABASE_PROJECT_REF||u.supabasePat!==r.SUPABASE_PAT)&&(await he(t,C(u),"utf-8"),i.success("Updated .mcp.json")),i.blank(),M.outro(st.green("Configuration updated."))}import{copyFile as ge,mkdir as we,readdir as nt,readFile as it,rm as x,writeFile as at,access as rt}from"fs/promises";import{dirname as ye,join as y,relative as ot}from"path";import{tmpdir as lt}from"os";import*as T from"@clack/prompts";import H from"picocolors";var j="0.2.0";async function ke(e){let s=e.projectRoot??process.cwd(),n=await q(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;try{let o=await it(y(s,".env"),"utf-8");t=P(o).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))}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)}T.intro(`Update from ${n.templateVersion} \u2192 ${j}`);let r=y(lt(),`klaudius-update-${process.pid}-${Date.now()}`),l;try{i.heading("Downloading the latest Klaudius template");let o=await v({licenseKey:t,machineId:_(),hostname:process.env.HOSTNAME??process.env.COMPUTERNAME,os:`${process.platform}-${process.arch}`,destDir:r});i.success(`Fetched ${o.filesExtracted} canonical files`),l=r}catch(o){i.error(o.message),i.detail("Update aborted. Your project is unchanged."),await x(r,{recursive:!0,force:!0}).catch(()=>{}),process.exit(1)}let u=await ct(l,s,n),a=u.filter(o=>o.state==="new"),m=u.filter(o=>o.state==="clean-update"),f=u.filter(o=>o.state==="user-only"),g=u.filter(o=>o.state==="conflict"),k=u.filter(o=>o.state==="no-change");if(i.blank(),i.heading("Change summary"),i.detail(`${b(k.length,"file")} unchanged`),i.detail(`${b(a.length,"new file")}`),i.detail(`${b(m.length,"file")} updated cleanly (no local edits)`),i.detail(`${b(f.length,"file")} you've edited (no upstream change \u2014 left alone)`),i.detail(`${b(g.length,"file")} with conflicts (you edited AND we have a new version)`),m.length===0&&a.length===0&&g.length===0){i.blank(),T.outro(H.green("Already up to date.")),await x(r,{recursive:!0,force:!0}).catch(()=>{});return}i.blank(),i.heading("Applying clean updates");for(let o of[...a,...m]){let c=y(l,o.path),p=y(s,o.path);await we(ye(p),{recursive:!0}),await ge(c,p),n.files[o.path]=o.canonicalHash}if(i.success(`Wrote ${b(a.length+m.length,"file")}`),g.length>0){i.blank(),i.heading(`${g.length} conflict(s) need resolution`);let o=y(s,".klaudius","incoming");try{await x(o,{recursive:!0,force:!0})}catch{}for(let c of g){let p=y(l,c.path),F=y(o,c.path);await we(ye(F),{recursive:!0}),await ge(p,F)}await at(y(s,".klaudius","conflicts.md"),ut(g,n.templateVersion,j),"utf-8"),i.detail("Staged canonical versions to .klaudius/incoming/"),i.detail("Wrote conflict report to .klaudius/conflicts.md")}n.updatedAt=new Date().toISOString(),g.length===0&&(n.templateVersion=j),await O(s,n),i.blank(),g.length===0?T.outro(H.green("Update complete.")):T.outro(H.yellow(`${g.length} conflict(s) staged. Open Claude Code in this project and ask:
42
- "Run /resolve-conflicts"`)),await x(r,{recursive:!0,force:!0}).catch(()=>{})}async function ct(e,s,n){let t=await Ee(e),r=[];for(let l of t){let u=await $(y(e,l)),a=n.files[l],m=y(s,l),f;try{await rt(m),f=await $(m)}catch{r.push({path:l,state:"new",canonicalHash:u,manifestHash:a});continue}u===a?f===a?r.push({path:l,state:"no-change",canonicalHash:u,localHash:f,manifestHash:a}):r.push({path:l,state:"user-only",canonicalHash:u,localHash:f,manifestHash:a}):f===a?r.push({path:l,state:"clean-update",canonicalHash:u,localHash:f,manifestHash:a}):r.push({path:l,state:"conflict",canonicalHash:u,localHash:f,manifestHash:a})}return r}function b(e,s){return`${e} ${s}${e===1?"":"s"}`}async function Ee(e,s=e){let n=await nt(e,{withFileTypes:!0}),t=[];for(let r of n){let l=y(e,r.name);r.isDirectory()?t.push(...await Ee(l,s)):r.isFile()&&t.push(ot(s,l))}return t}function ut(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 r of e)t.push(`## ${r.path}`),t.push(""),t.push(`- Your version (with your local edits): \`${r.path}\``),t.push(`- New canonical version: \`.klaudius/incoming/${r.path}\``),t.push(`- Hash at last install/update: \`${(r.manifestHash??"(none)").slice(0,16)}\``),t.push(`- Your local hash now: \`${(r.localHash??"(missing)").slice(0,16)}\``),t.push(`- New canonical hash: \`${r.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(`
43
- `)}var pt="0.2.0",I=new dt;I.name("klaudius").description("Scaffold and maintain a Klaudius pipeline project").version(pt);I.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 me({target:e,license:s.license,skipInstall:!!s.skipInstall,skipSchema:!!s.skipSchema})}catch(n){console.error("init failed:",n.message),process.exit(1)}});I.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)}});I.command("update").description("Pull latest template; produce a conflicts report for any files you've modified").action(async()=>{try{await ke({})}catch(e){console.error("update failed:",e.message),process.exit(1)}});I.parse(process.argv);
41
+ Press Enter on any field to keep its current value.`}),await S(n,r)}i.blank();let f=p.spinner();f.start("Downloading Klaudius template");let g;try{g=(await v({licenseKey:a,machineId:b(),hostname:process.platform==="win32"?process.env.COMPUTERNAME:void 0,os:`${process.platform}-${process.arch}`,destDir:n})).filesExtracted,f.stop(`Downloaded ${g} files into ${m.bold(n)}`)}catch(o){f.stop(o.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 fe(x(n,"clients"),{recursive:!0});let k=await G(n);if(await O(n,J("0.1.0",k)),i.success("Wrote .klaudius/manifest.json"),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 o=p.spinner();o.start("Applying schema to Supabase");let u=await se({projectRoot:n,pat:r.supabasePat,projectRef:r.supabaseProjectRef});u.ok?o.stop("Schema applied (or already present)"):(o.stop(u.message??"Schema apply failed",2),i.warn("Apply scripts/schema.sql manually in your Supabase SQL editor before running the pipeline."))}if(e.skipInstall)i.warn("--skip-install set; you'll need to run npm install + pip install + playwright install yourself.");else{i.blank(),i.heading("Installing dependencies");let o=await de(n);i.detail(`npm: ${o.npm}, pip: ${o.pip}, playwright: ${o.playwright}`),(o.npm==="failed"||o.pip==="failed"||o.playwright==="failed")&&i.warn("Some installers failed. You can re-run them manually with `bash setup.sh`.")}i.blank(),p.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 S(e,s){await fe(e,{recursive:!0}),await he(x(e,".env"),R(s),"utf-8"),await he(x(e,".mcp.json"),C(s),"utf-8")}async function et(e){try{(await Je(e)).isDirectory()||(i.error(`Target exists but is not a directory: ${e}`),process.exit(1))}catch{return{kind:"fresh"}}let s=await qe(e),n=s.filter(r=>!r.startsWith(".DS_Store"));if(n.length===0)return{kind:"fresh"};let t=new Set([".env",".mcp.json"]),a=n.every(r=>t.has(r)),l=n.includes(".env"),c=s.includes(".klaudius");return a&&l&&!c?{kind:"partial",envPath:x(e,".env")}:{kind:"occupied",entries:n}}async function tt(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 p.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 p.isCancel(s)&&(p.cancel("Setup cancelled. Existing .env left in place."),process.exit(0)),s}async function st(e){if(e&&e.trim().length>0)return e;p.intro("Klaudius");let s=await p.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 p.isCancel(s)&&(p.cancel("Setup cancelled. No files written."),process.exit(0)),s}import{readFile as it,writeFile as we,access as nt}from"fs/promises";import{join as K}from"path";import*as M from"@clack/prompts";import rt from"picocolors";async function ye(e){let s=e.projectRoot??process.cwd(),n=K(s,".env"),t=K(s,".mcp.json");try{await nt(K(s,".klaudius","manifest.json"))}catch{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 a={};try{let r=await it(n,"utf-8");a=P(r)}catch{i.warn("No .env found. Starting from an empty configuration.")}let l=W(a);M.intro("Reconfigure Klaudius"),i.detail("Press Enter on any prompt to keep its current value."),i.blank();let c=await w(l);if(c.supabaseUrl!==a.SUPABASE_URL||c.supabaseServiceKey!==a.SUPABASE_SERVICE_KEY){i.heading("Re-validating Supabase credentials");let r=await L({url:c.supabaseUrl,serviceKey:c.supabaseServiceKey});r.ok||(i.error(r.message??"Supabase check failed"),i.warn("Aborting. .env not modified."),process.exit(1)),i.success("Supabase credentials accepted")}await we(n,R(c),"utf-8"),i.success("Updated .env"),await we(t,C(c),"utf-8"),i.success("Updated .mcp.json"),i.blank(),M.outro(rt.green("Configuration updated."))}import{copyFile as ke,mkdir as Ee,readdir as at,readFile as ot,rm as $,writeFile as lt,access as ct}from"fs/promises";import{dirname as Se,join as y,relative as ut}from"path";import{tmpdir as pt}from"os";import*as T from"@clack/prompts";import D from"picocolors";var H="0.3.1";async function Pe(e){let s=e.projectRoot??process.cwd(),n=await q(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;try{let o=await ot(y(s,".env"),"utf-8");t=P(o).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))}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)}T.intro(`Update from ${n.templateVersion} \u2192 ${H}`);let a=y(pt(),`klaudius-update-${process.pid}-${Date.now()}`),l;try{i.heading("Downloading the latest Klaudius template");let o=await v({licenseKey:t,machineId:b(),hostname:process.env.HOSTNAME??process.env.COMPUTERNAME,os:`${process.platform}-${process.arch}`,destDir:a});i.success(`Fetched ${o.filesExtracted} canonical files`),l=a}catch(o){i.error(o.message),i.detail("Update aborted. Your project is unchanged."),await $(a,{recursive:!0,force:!0}).catch(()=>{}),process.exit(1)}let c=await dt(l,s,n),r=c.filter(o=>o.state==="new"),h=c.filter(o=>o.state==="clean-update"),f=c.filter(o=>o.state==="user-only"),g=c.filter(o=>o.state==="conflict"),k=c.filter(o=>o.state==="no-change");if(i.blank(),i.heading("Change summary"),i.detail(`${_(k.length,"file")} unchanged`),i.detail(`${_(r.length,"new file")}`),i.detail(`${_(h.length,"file")} updated cleanly (no local edits)`),i.detail(`${_(f.length,"file")} you've edited (no upstream change \u2014 left alone)`),i.detail(`${_(g.length,"file")} with conflicts (you edited AND we have a new version)`),h.length===0&&r.length===0&&g.length===0){i.blank(),T.outro(D.green("Already up to date.")),await $(a,{recursive:!0,force:!0}).catch(()=>{});return}i.blank(),i.heading("Applying clean updates");for(let o of[...r,...h]){let u=y(l,o.path),d=y(s,o.path);await Ee(Se(d),{recursive:!0}),await ke(u,d),n.files[o.path]=o.canonicalHash}if(i.success(`Wrote ${_(r.length+h.length,"file")}`),g.length>0){i.blank(),i.heading(`${g.length} conflict(s) need resolution`);let o=y(s,".klaudius","incoming");try{await $(o,{recursive:!0,force:!0})}catch{}for(let u of g){let d=y(l,u.path),j=y(o,u.path);await Ee(Se(j),{recursive:!0}),await ke(d,j)}await lt(y(s,".klaudius","conflicts.md"),mt(g,n.templateVersion,H),"utf-8"),i.detail("Staged canonical versions to .klaudius/incoming/"),i.detail("Wrote conflict report to .klaudius/conflicts.md")}n.updatedAt=new Date().toISOString(),g.length===0&&(n.templateVersion=H),await O(s,n),i.blank(),g.length===0?T.outro(D.green("Update complete.")):T.outro(D.yellow(`${g.length} conflict(s) staged. Open Claude Code in this project and ask:
42
+ "Run /resolve-conflicts"`)),await $(a,{recursive:!0,force:!0}).catch(()=>{})}async function dt(e,s,n){let t=await Ae(e),a=[];for(let l of t){let c=await N(y(e,l)),r=n.files[l],h=y(s,l),f;try{await ct(h),f=await N(h)}catch{a.push({path:l,state:"new",canonicalHash:c,manifestHash:r});continue}c===r?f===r?a.push({path:l,state:"no-change",canonicalHash:c,localHash:f,manifestHash:r}):a.push({path:l,state:"user-only",canonicalHash:c,localHash:f,manifestHash:r}):f===r?a.push({path:l,state:"clean-update",canonicalHash:c,localHash:f,manifestHash:r}):a.push({path:l,state:"conflict",canonicalHash:c,localHash:f,manifestHash:r})}return a}function _(e,s){return`${e} ${s}${e===1?"":"s"}`}async function Ae(e,s=e){let n=await at(e,{withFileTypes:!0}),t=[];for(let a of n){let l=y(e,a.name);a.isDirectory()?t.push(...await Ae(l,s)):a.isFile()&&t.push(ut(s,l))}return t}function mt(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 a of e)t.push(`## ${a.path}`),t.push(""),t.push(`- Your version (with your local edits): \`${a.path}\``),t.push(`- New canonical version: \`.klaudius/incoming/${a.path}\``),t.push(`- Hash at last install/update: \`${(a.manifestHash??"(none)").slice(0,16)}\``),t.push(`- Your local hash now: \`${(a.localHash??"(missing)").slice(0,16)}\``),t.push(`- New canonical hash: \`${a.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(`
43
+ `)}var ft="0.3.1",I=new ht;I.name("klaudius").description("Scaffold and maintain a Klaudius pipeline project").version(ft);I.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 ge({target:e,license:s.license,skipInstall:!!s.skipInstall,skipSchema:!!s.skipSchema})}catch(n){console.error("init failed:",n.message),process.exit(1)}});I.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)}});I.command("update").description("Pull latest template; produce a conflicts report for any files you've modified").action(async()=>{try{await Pe({})}catch(e){console.error("update failed:",e.message),process.exit(1)}});I.parse(process.argv);
@@ -0,0 +1,6 @@
1
+ import{appendFileSync as c}from"fs";import{tmpdir as g}from"os";import{join as u}from"path";var r=u(g(),"klaudius-wizard-debug.log"),h=process.env.KLAUDIUS_WIZARD_DEBUG==="1",d=!1;function m(o,t){if(h)try{d||(d=!0,c(r,`
2
+ === klaudius wizard debug session \u2014 ${new Date().toISOString()} ===
3
+ node ${process.version}, platform ${process.platform}, tty=${process.stdin.isTTY}
4
+ `));let e=`${Date.now()} `,s=t===void 0?"":" "+JSON.stringify(t,null,0).slice(0,400);c(r,e+o+s+`
5
+ `)}catch{}}var b=r,l=!1;function T(){if(l)return;l=!0;let o=process.exit.bind(process);process.exit=(t=>{let e=new Error("process.exit called").stack??"(no stack)";return m("process.exit called",{code:t,stack:e.split(`
6
+ `).slice(0,8).join(" | ")}),o(t)})}async function w(o){let t;try{let a=await fetch(`https://api.telegram.org/bot${encodeURIComponent(o.botToken)}/getUpdates`);if(t=await a.json(),!t.ok){let i=t.description??`HTTP ${a.status}`;return/webhook/i.test(i)?{ok:!1,reason:"webhook_set",message:"This bot has a webhook set, so getUpdates is unavailable. Auto-detect can't run; you'll need to paste the chat ID manually."}:{ok:!1,reason:"bad_token",message:`Telegram rejected the bot token: ${i}. Double-check the token from @BotFather.`}}}catch(a){return{ok:!1,reason:"network",message:`Could not reach Telegram: ${a.message}`}}let e=t.result??[];if(e.length===0)return{ok:!1,reason:"no_messages",message:"No messages yet. Send your bot a regular text message in Telegram, then retry."};let s=e[e.length-1],n=s.message?.chat?.id??s.edited_message?.chat?.id??s.channel_post?.chat?.id;return n===void 0?{ok:!1,reason:"no_messages",message:"Got an update from Telegram but couldn't find a chat ID in it. Send another text message and retry."}:{ok:!0,chatId:String(n)}}async function _(o){let t;try{let e=await fetch(`https://api.telegram.org/bot${encodeURIComponent(o.botToken)}/getMe`),s=await e.json();if(!s.ok)return{ok:!1,failedAt:"token",message:`Telegram rejected the bot token: ${s.description??`HTTP ${e.status}`}. Generate a new token by messaging @BotFather \u2192 /mytoken or /newbot.`};t=s.result?.username?`@${s.result.username}`:s.result?.first_name}catch(e){return{ok:!1,failedAt:"token",message:`Could not reach Telegram: ${e.message}`}}try{let e=await fetch(`https://api.telegram.org/bot${encodeURIComponent(o.botToken)}/sendMessage`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chat_id:o.chatId,text:"\u2713 Klaudius connected. You'll get a notification here whenever outreach lands or a candidate replies. (You can ignore this setup message.)",disable_notification:!0})}),s=await e.json();if(!s.ok){let n=s.description??`HTTP ${e.status}`,a="";return/chat not found/i.test(n)?a=" The chat_id is wrong, or the bot hasn't been added to that chat yet. If it's a group, you must add the bot to the group first; then send /start to it.":(/bot was blocked/i.test(n)||/forbidden/i.test(n))&&(a=" The bot has been blocked by the chat, or never received a /start. Open Telegram, find your bot, and send /start to wake it up."),{ok:!1,failedAt:"chat",botHandle:t,message:`Telegram delivered the bot token check but couldn't send to chat_id ${o.chatId}: ${n}.${a}`}}}catch(e){return{ok:!1,failedAt:"chat",botHandle:t,message:`Could not reach Telegram for chat_id check: ${e.message}`}}return{ok:!0,botHandle:t}}export{m as a,b,T as c,w as d,_ as e};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "klaudius",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Scaffold and maintain a Klaudius project — an autonomous web agency pipeline that runs on Claude Code (find, build, deploy, outreach end-to-end).",
5
5
  "homepage": "https://klaudius.dev",
6
6
  "bugs": {
@@ -29,7 +29,7 @@
29
29
  "prepublishOnly": "npm run build"
30
30
  },
31
31
  "engines": {
32
- "node": ">=20"
32
+ "node": ">=22"
33
33
  },
34
34
  "dependencies": {
35
35
  "@clack/prompts": "^0.7.0",
@@ -1,158 +0,0 @@
1
- import{a as d}from"./chunk-OUNGUMWF.js";import{useEffect as Le,useMemo as je,useRef as X,useState as A}from"react";import{Box as S,Text as x,useApp as ze,useInput as De}from"ink";var J={gmail:{label:"Gmail",smtpHost:"smtp.gmail.com",smtpPort:587,imapHost:"imap.gmail.com",imapPort:993,sentFolder:"[Gmail]/Sent Mail",inboxFolder:"INBOX",appPasswordHelp:`Generate at https://myaccount.google.com/apppasswords
2
- (2-step verification must be enabled on your Google account first;
3
- Google won't accept your normal account password from third-party apps).`},outlook:{label:"Outlook / Office 365",smtpHost:"smtp-mail.outlook.com",smtpPort:587,imapHost:"outlook.office365.com",imapPort:993,sentFolder:"Sent Items",inboxFolder:"INBOX",appPasswordHelp:`Generate at https://account.microsoft.com/security \u2192 Advanced security options \u2192 App passwords
4
- (2-step verification must be enabled first).`},ionos:{label:"IONOS",smtpHost:"smtp.ionos.co.uk",smtpPort:587,imapHost:"imap.ionos.co.uk",imapPort:993,sentFolder:"Sent Items",inboxFolder:"INBOX",appPasswordHelp:`Use your normal IONOS mailbox password.
5
- (IONOS doesn't require app passwords for IMAP/SMTP unless you've enabled 2FA.)`},fastmail:{label:"Fastmail",smtpHost:"smtp.fastmail.com",smtpPort:587,imapHost:"imap.fastmail.com",imapPort:993,sentFolder:"Sent",inboxFolder:"INBOX",appPasswordHelp:`Generate at https://app.fastmail.com/settings/security/integrations
6
- (Fastmail requires app passwords for IMAP/SMTP regardless of 2FA setting.)`},zoho:{label:"Zoho Mail",smtpHost:"smtp.zoho.com",smtpPort:587,imapHost:"imap.zoho.com",imapPort:993,sentFolder:"Sent",inboxFolder:"INBOX",appPasswordHelp:`Generate at https://accounts.zoho.com/u/h#security/app_passwords
7
- (Zoho requires app passwords for IMAP/SMTP \u2014 your normal account password won't work.)`}},Q=`Use the app-specific password your provider issues for SMTP/IMAP
8
- (check their security settings \u2014 most providers require a generated password
9
- rather than your normal account password).`;var R=class extends Error{constructor(){super("user pressed back"),this.name="BackSignal"}},H=class extends Error{constructor(){super("user cancelled"),this.name="CancelSignal"}},ye="Include the country code with a + (e.g. +12025550123 for US, +447123456789 for UK)",ee=e=>/^\+\d{8,15}$/.test(e)?void 0:ye,be=e=>/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(e)?void 0:"Enter a valid email",I=e=>t=>t.trim().length===0?`${e} is required`:void 0,Pe={id:"pricing",title:"Pricing",isApplicable:()=>!0,execute:async(e,{prompt:t})=>({pricing:await t({type:"text",message:"What price will you charge clients per finished site?",placeholder:"e.g. $999, \xA3799, \u20AC899",initialValue:e.pricing??"$999",validate:I("Price"),note:{title:"Pricing",body:`Use the currency that matches the region of clients you'll be reaching
10
- out to (e.g. $ for US clients, \xA3 for the UK, \u20AC for the EU). Klaudius
11
- uses this exact string verbatim throughout outreach.`}})})},we={id:"outreach-enabled",title:"Automated outreach",isApplicable:()=>!0,execute:async(e,{prompt:t})=>({outreachEnabled:await t({type:"confirm",message:"Use Klaudius's automated outreach features?",initialValue:e.outreachEnabled??!0,note:{title:"Automated outreach features",body:`After finding candidates and building websites for them, Klaudius can
12
- run outreach to them automatically (email and/or SMS).
13
- If you'd rather handle outreach manually, you can skip this here.`}})})},Se={id:"operator-name",title:"Your name",isApplicable:e=>e.outreachEnabled===!0,execute:async(e,{prompt:t})=>{let n=await t({type:"text",message:"Your name as it should appear publicly in outreach",placeholder:"e.g. Mike Smith \u2014 or your business name if you'd rather",initialValue:e.name??e.emailFromName??"",validate:I("Name")}),o=n.trim().split(/\s+/)[0];return{name:n,signature:e.signature??`Thanks, ${o}`}}},ve={id:"channels",title:"Outreach channels",isApplicable:e=>e.outreachEnabled===!0,execute:async(e,{prompt:t})=>{let n=e.outreachChannels&&e.outreachChannels.length>1?"both":e.outreachChannels?.[0]??"email",o=await t({type:"select",message:"Which channels can Klaudius use for outreach?",initialValue:n,options:[{value:"email",label:"Email only"},{value:"sms",label:"SMS only"},{value:"both",label:"Both (recommended for maximum reach)"}],note:{title:"Outreach channels",body:`Different businesses have different contact methods publicly available \u2014
14
- some list only an email, others only a phone number. Klaudius uses whichever
15
- channel is available for each candidate (it doesn't message the same candidate
16
- on both). Picking 'both' just means Klaudius can reach more of the
17
- businesses it finds.`}}),s=o==="both"?["email","sms"]:[o],a;return s.length>1&&(a=await t({type:"select",message:"When a candidate has both email and a phone number, which channel should Klaudius try first?",initialValue:e.outreachPriority??"email",options:[{value:"email",label:"Prefer email (better for B2B / professional services)"},{value:"sms",label:"Prefer SMS (better response rates for trades / local services)"}]})),{outreachChannels:s,outreachPriority:a}}},xe={id:"email",title:"Email setup",isApplicable:e=>e.outreachChannels?.includes("email")===!0,execute:async(e,{prompt:t,info:n})=>{n({title:"Email setup",body:`Klaudius needs an email account to send outreach FROM. This is the
18
- address candidates will see as the sender. Use a domain you control
19
- (your own, your business's) \u2014 not your personal address.`});let o=await t({type:"select",message:"Who hosts the email account you'll send outreach from?",initialValue:e.emailProvider??"gmail",options:[{value:"gmail",label:"Gmail"},{value:"fastmail",label:"Fastmail"},{value:"outlook",label:"Outlook / Office 365"},{value:"zoho",label:"Zoho Mail"},{value:"ionos",label:"IONOS"},{value:"custom",label:"Custom / other (enter SMTP/IMAP details manually)"}]}),s=o!=="custom"?J[o]:void 0,a=await t({type:"text",message:"Email address to send outreach from",placeholder:"you@yourbusiness.com",initialValue:e.emailAddress??"",validate:be}),i=s?.appPasswordHelp??Q,m=await t({type:"password",message:"Paste the app password",initialValue:e.emailPassword??"",validate:I("App password"),note:{title:"App password",body:`An app password is a separate, single-purpose password that your
20
- email provider issues for third-party apps like Klaudius. It is NOT
21
- your normal account login password.
22
-
23
- `+i+`
24
-
25
- Once generated, it's stored locally in this project's .env file.
26
- It is never sent to Klaudius's servers \u2014 only to your email
27
- provider when sending outreach.`}}),r,c,f,y,T,E;if(o==="custom"){r=await t({type:"text",message:"SMTP host (the server Klaudius connects to for sending)",placeholder:"e.g. smtp.yourprovider.com",initialValue:e.emailSmtpHost??"",validate:I("SMTP host")});let _=await t({type:"text",message:"SMTP port (usually 587 for STARTTLS or 465 for SSL)",initialValue:String(e.emailSmtpPort??587),validate:k=>/^\d+$/.test(k)?void 0:"Must be a number"});c=parseInt(_,10),f=await t({type:"text",message:"IMAP host (the server Klaudius connects to for reading replies)",placeholder:"e.g. imap.yourprovider.com",initialValue:e.emailImapHost??"",validate:I("IMAP host")});let O=await t({type:"text",message:"IMAP port (usually 993 for SSL)",initialValue:String(e.emailImapPort??993),validate:k=>/^\d+$/.test(k)?void 0:"Must be a number"});y=parseInt(O,10),T=await t({type:"text",message:"Sent folder name (so SMTP-sent messages also appear in your email client's Sent folder)",placeholder:'e.g. "Sent", "Sent Items"',initialValue:e.emailSentFolder??"Sent"}),E=await t({type:"text",message:"Inbox folder name (almost always INBOX)",initialValue:e.emailInboxFolder??"INBOX"})}else r=s.smtpHost,c=s.smtpPort,f=s.imapHost,y=s.imapPort,T=s.sentFolder,E=s.inboxFolder;return{emailProvider:o,emailAddress:a,emailPassword:m,emailFromName:e.name,emailSmtpHost:r,emailSmtpPort:c,emailImapHost:f,emailImapPort:y,emailSentFolder:T,emailInboxFolder:E}}},Ie={id:"sms",title:"SMS setup",isApplicable:e=>e.outreachChannels?.includes("sms")===!0,execute:async(e,{prompt:t,info:n})=>{n({title:"SMS setup",body:`Klaudius can send SMS one of two ways:
28
-
29
- \u2022 macOS iMessage \u2014 free, uses Messages.app on your Mac.
30
- Reaches other Apple users as iMessage for free. To reach
31
- non-Apple phones (e.g. Android), you need a one-time setup:
32
- 1. Sign in to Messages.app on this Mac with your Apple ID.
33
- 2. On your iPhone, sign in to the SAME Apple ID.
34
- 3. On your iPhone: Settings \u2192 Messages \u2192 Text Message
35
- Forwarding \u2192 toggle this Mac ON. (You'll be asked to
36
- enter a 6-digit code that appears on the Mac.)
37
- Once that's done, the iPhone doesn't need to be nearby.
38
- Apple keeps the relay working as long as both devices stay
39
- signed into the same Apple ID and have data/Wi-Fi.
40
-
41
- \u2022 Twilio \u2014 cross-platform, ~$0.01 per SMS. Sender is a phone
42
- number you buy from Twilio. Works on any OS, reaches any
43
- phone, no iPhone required. Recommended for consistent delivery.`});let o=await t({type:"select",message:"Which SMS provider?",initialValue:e.smsProvider??"imessage",options:[{value:"imessage",label:"macOS iMessage (free, Mac only)"},{value:"twilio",label:"Twilio (cross-platform, paid per-message \u2014 recommended)"}]}),s=await t({type:"text",message:"Your mobile number (used as a safe target for test sends so Klaudius doesn't accidentally message real candidates while you're testing)",placeholder:"+12025550123",initialValue:e.testPhone??"",validate:ee}),a={smsProvider:o,testPhone:s};return o==="twilio"&&(a.twilioAccountSid=await t({type:"text",message:"Twilio Account SID (starts with AC...)",initialValue:e.twilioAccountSid??"",validate:i=>/^AC[a-zA-Z0-9]+$/.test(i)?void 0:"Should start with 'AC'"}),a.twilioAuthToken=await t({type:"password",message:"Twilio Auth Token",initialValue:e.twilioAuthToken??"",validate:I("Twilio Auth Token")}),a.twilioPhoneNumber=await t({type:"text",message:"Twilio phone number (the number outreach will be sent FROM)",placeholder:"+15551234567",initialValue:e.twilioPhoneNumber??"",validate:ee})),a}},Ae={id:"vercel",title:"Vercel deployment",isApplicable:()=>!0,execute:async(e,{prompt:t})=>({vercelToken:await t({type:"password",message:"Paste your Vercel API token",initialValue:e.vercelToken??"",validate:o=>o.trim().length===0?"Required \u2014 without this Klaudius can't deploy generated sites":void 0,note:{title:"Vercel deployment",body:`Klaudius deploys every generated client site to Vercel. We use a
44
- Vercel API token to do this without an interactive login.
45
-
46
- How to get one (one-time, ~30 seconds):
47
- 1. Open https://vercel.com/account/tokens
48
- 2. Click 'Create Token'
49
- 3. Name it 'Klaudius', set scope to your personal account, set
50
- expiration to 'No expiration' (recommended) or your preferred
51
- duration
52
- 4. Click Create, then copy the token shown
53
-
54
- Don't have a Vercel account yet? Sign up free at vercel.com.
55
- The Hobby (free) plan caps you at 200 projects and 100 deployments
56
- per day. If you grow past 200 active client sites you can either
57
- upgrade to Pro ($20/month, unlimited projects + 6,000 deploys/day),
58
- or simply switch to a new Vercel account each time you hit the
59
- 200-project ceiling.
60
-
61
- (Team accounts: this wizard assumes a personal Vercel account.
62
- If you deploy under a team, generate a team-scoped token instead
63
- and set VERCEL_TEAM_SCOPE in .env after init \u2014 see .env.example.)
64
-
65
- STUCK? Open Claude (or any LLM) in another tab/app and paste:
66
-
67
- "I need to create a personal Vercel API token for the
68
- Klaudius CLI tool. Walk me through generating one at
69
- vercel.com/account/tokens, including which scope and
70
- expiration to choose."`}})})},Te={id:"supabase",title:"Supabase",isApplicable:()=>!0,execute:async(e,{prompt:t,info:n})=>{n({title:"Supabase setup",body:`Supabase is your CRM. It's where Klaudius records every business it
71
- finds, where each one sits in your funnel (gathered \u2192 built \u2192 deployed
72
- \u2192 outreach sent \u2192 responded \u2192 won / lost), the follow-up schedule, and
73
- the full outreach reply history. You can browse it at any time from
74
- the Supabase dashboard, or query it conversationally by asking Claude
75
- (e.g. 'who replied this week?', 'who haven't I followed up with?').
76
-
77
- The free tier (500 MB database, 5 GB bandwidth/month) is plenty:
78
- Klaudius's records are tiny text rows (a few KB per client at most),
79
- and the only reads/writes are the pipeline's own bookkeeping \u2014
80
- no public traffic to your CRM. Even with thousands of leads tracked
81
- you'll use a sliver of the limit.
82
-
83
- If you don't have a project yet: open https://supabase.com/dashboard
84
- and create one. The flow is:
85
- 1. Sign up (or sign in) with GitHub / Google / email
86
- 2. 'Create a new organization' page \u2014 name and type don't matter
87
- for Klaudius, pick anything you like
88
- 3. Plan page \u2014 pick Free
89
- 4. 'Create a new project' page \u2014 set a database password (any
90
- strong password \u2014 Klaudius doesn't use it directly, but you'll
91
- want it later if you ever connect to the database manually).
92
- Region defaults to the nearest one to you, leave it. Accept
93
- defaults for any other security settings on the page.
94
- 5. Click 'Create new project' and wait ~2 minutes for it to
95
- provision. Then come back here.
96
-
97
- STUCK on any of the prompts below? Open Claude (or ChatGPT, or any LLM)
98
- in another tab/app and paste this prompt verbatim:
99
-
100
- "I'm setting up a Supabase project to use with the Klaudius CLI.
101
- The wizard is asking for: (1) project URL, (2) the secret/service-
102
- role key, (3) a personal access token. Walk me through where to
103
- find each one in the current Supabase dashboard UI, including the
104
- exact menu paths and any caveats for newer vs. legacy projects."`});let s=(await t({type:"text",message:"Supabase API URL (Dashboard \u2192 your project \u2192 Settings \u2192 API \u2192 API URL)",placeholder:"https://YOUR_REF.supabase.co",initialValue:e.supabaseUrl??"",validate:r=>/^https:\/\/[a-z0-9]+\.supabase\.co(\/rest\/v1\/?)?$/i.test(r.trim())?void 0:"Should look like https://xxxx.supabase.co (with or without /rest/v1/)"})).trim().replace(/\/rest\/v1\/?$/i,"").replace(/\/$/,""),a=s.match(/^https:\/\/([a-z0-9]+)\.supabase\.co/i)?.[1]??"",i=await t({type:"password",message:"Paste the Supabase secret key (sb_secret_\u2026 or service_role / eyJ\u2026)",validate:r=>r.length<20?"Looks too short":void 0,note:{title:"Secret key",body:a?`Open this exact page (\u2318-click to follow):
105
- https://supabase.com/dashboard/project/${a}/settings/api-keys
106
-
107
- Newer projects: look under 'Secret keys' for a row whose value starts
108
- with 'sb_secret_'. Click reveal, then copy the full value.
109
-
110
- Older / legacy projects: scroll to the 'Legacy keys' section and copy
111
- the row labelled 'service_role' / 'service role key' (its value starts
112
- with 'eyJ').
113
-
114
- Either format works \u2014 Klaudius accepts both. NEVER use the 'anon' /
115
- 'public' / 'sb_publishable_' key (those are client-side keys with no
116
- write permissions).`:`Open Settings \u2192 API Keys in your Supabase project. Copy the secret
117
- key (sb_secret_\u2026 for new projects, or 'service_role' / eyJ\u2026 for legacy).`}}),m=await t({type:"password",message:"Paste the Supabase personal access token",validate:r=>r.startsWith("sbp_")?void 0:"Should start with 'sbp_'",note:{title:"Personal access token",body:`This is a separate credential from the secret key above \u2014 it's an
118
- ACCOUNT-wide token (not project-scoped) used by the Supabase MCP and
119
- by Klaudius's schema migration.
120
-
121
- Open this exact page (\u2318-click to follow):
122
- https://supabase.com/dashboard/account/tokens
123
-
124
- Click 'Generate new token', name it 'Klaudius', and set the
125
- expiration to 'Never' (recommended \u2014 saves you having to rotate
126
- it later). Copy the value (starts with 'sbp_') and paste it
127
- below.`}});return{supabaseUrl:s,supabaseServiceKey:i,supabasePat:m,supabaseProjectRef:a}}},ke={id:"google-places",title:"Google Places API",isApplicable:()=>!0,execute:async(e,{prompt:t})=>({googlePlacesApiKey:await t({type:"text",message:"Paste your Google Places API key",placeholder:"AIzaSy\u2026",initialValue:e.googlePlacesApiKey??"",validate:o=>o.trim().length===0?"Required \u2014 without this Klaudius can't find candidates":void 0,note:{title:"Google Places API key",body:`Klaudius's /find skill queries Google's Places API to discover businesses
128
- without websites in your target region. Without a key, the pipeline has
129
- no source of leads \u2014 so this is required.
130
-
131
- Pricing: Google gives every account a free monthly quota per Places API
132
- tier (thousands of searches/month) \u2014 plenty of headroom at solo-operator
133
- volume. You only get charged if you go over, and Google won't surprise-
134
- bill you: the API simply stops responding at the quota by default unless
135
- you explicitly opt in to overage.
136
-
137
- How to get a key (~5 min):
138
- 1. Open https://console.cloud.google.com
139
- 2. Create a project (or pick an existing one) from the project picker
140
- in the top bar.
141
- 3. Enable billing on the project. Google requires a card on file to
142
- activate the Places API, but it's only used if you exceed the free
143
- quota \u2014 by default the API just throttles you, it doesn't auto-bill.
144
- 4. APIs & Services \u2192 Library \u2192 search 'Places API (New)' \u2192 Enable.
145
- Note: 'Places API (New)' specifically \u2014 not the legacy 'Places API'.
146
- 5. APIs & Services \u2192 Credentials \u2192 '+ CREATE CREDENTIALS' \u2192 API key.
147
- 6. Copy the generated key. (Optional but recommended: click the key,
148
- restrict it to 'Places API (New)' under API restrictions.)
149
-
150
- STUCK? Open Claude (or any LLM) in another tab/app and paste this prompt:
151
-
152
- "I need a Google Places API (New) key for a CLI tool called
153
- Klaudius. Walk me through the Google Cloud Console steps to enable
154
- Places API (New) on a free project and generate a restricted API
155
- key, including any billing setup gotchas."`}})})},Ce={id:"telegram",title:"Telegram (optional)",isApplicable:()=>!0,execute:async(e,{prompt:t})=>{if(!await t({type:"confirm",message:"Set up Telegram notifications? (sends a ping when outreach lands)",initialValue:!!e.telegramBotToken,note:{title:"Telegram notifications (optional)",body:`Klaudius can ping a Telegram chat when outreach is sent or when a
156
- candidate replies. This is OPTIONAL \u2014 skip it if you'd rather check
157
- the Supabase dashboard manually.`}}))return{};let o=await t({type:"password",message:"Telegram bot token (talk to @BotFather to create one)",initialValue:e.telegramBotToken??"",validate:I("Bot token")}),s=await t({type:"text",message:"Telegram chat ID",placeholder:"e.g. 8716063463",initialValue:e.telegramChatId??"",validate:a=>/^-?\d+$/.test(a)?void 0:"Numeric chat ID"});return{telegramBotToken:o,telegramChatId:s}}},C=[Pe,we,Se,ve,xe,Ie,Ae,Te,ke,Ce];import{Box as te,Text as Ee}from"ink";import{jsx as oe,jsxs as Re}from"react/jsx-runtime";var Oe={pending:"\u25CB",current:"\u25C9",done:"\u2713",skipped:"\xB7"},Me={pending:void 0,current:"cyan",done:"green",skipped:void 0};function ae({items:e}){return oe(te,{flexDirection:"column",width:28,flexShrink:0,children:e.map(t=>{let n=t.status==="skipped"||t.status==="pending";return oe(te,{children:Re(Ee,{color:Me[t.status],bold:t.status==="current",dimColor:n&&t.status!=="current",children:[Oe[t.status]," ",t.title]})},t.id)})})}import{useEffect as Ne,useState as ne}from"react";import{Box as D,Text as F,useInput as Be}from"ink";import Ve from"ink-text-input";import{jsx as N,jsxs as G}from"react/jsx-runtime";function se({spec:e,masked:t,onSubmit:n,onBack:o}){let[s,a]=ne(typeof e.initialValue=="string"?e.initialValue:""),[i,m]=ne(null);Ne(()=>(d("TextPromptUI:mount",{masked:t,message:e.message.slice(0,60),initial:typeof e.initialValue=="string"?e.initialValue.slice(0,30):null}),()=>{d("TextPromptUI:unmount")}),[t,e.message,e.initialValue]),Be((c,f)=>{d("TextPromptUI:useInput fired",{input:c,ctrl:f.ctrl,escape:f.escape,return:f.return}),f.escape&&o()});let r=c=>{d("TextPromptUI:handleSubmit",{raw:c.slice(0,30)});let f=c;if(e.validate){let y=e.validate(f);if(y){d("TextPromptUI:validate failed",{err:y}),m(y);return}}m(null),n(f)};return G(D,{flexDirection:"column",children:[G(F,{children:[N(F,{color:"cyan",children:"?"})," ",e.message]}),G(D,{children:[N(F,{color:"green",children:"\u203A "}),N(Ve,{value:s,onChange:a,onSubmit:r,placeholder:e.placeholder,mask:t?"\u2022":void 0})]}),i&&N(D,{marginTop:0,children:N(F,{color:"red",children:i})})]})}import{useState as Ke}from"react";import{Box as ie,Text as W,useInput as _e}from"ink";import{jsx as re,jsxs as $}from"react/jsx-runtime";function le({spec:e,onSubmit:t,onBack:n}){let o=e.options??[],s=typeof e.initialValue=="string"?Math.max(0,o.findIndex(m=>m.value===e.initialValue)):0,[a,i]=Ke(s===-1?0:s);return _e((m,r)=>{if(r.escape)n();else if(r.upArrow)i(c=>(c-1+o.length)%o.length);else if(r.downArrow)i(c=>(c+1)%o.length);else if(r.return){let c=o[a];c&&t(c.value)}}),$(ie,{flexDirection:"column",children:[$(W,{children:[re(W,{color:"cyan",children:"?"})," ",e.message]}),re(ie,{flexDirection:"column",marginTop:0,children:o.map((m,r)=>{let c=r===a;return $(W,{color:c?"cyan":void 0,bold:c,children:[c?"\u25CF ":"\u25CB ",m.label]},m.value)})})]})}import{useState as Ue}from"react";import{Box as ce,Text as B,useInput as He}from"ink";import{jsx as ue,jsxs as V}from"react/jsx-runtime";function pe({spec:e,onSubmit:t,onBack:n}){let[o,s]=Ue(typeof e.initialValue=="boolean"?e.initialValue:!0);return He((a,i)=>{i.escape?n():i.leftArrow||i.rightArrow?s(m=>!m):a==="y"||a==="Y"?s(!0):a==="n"||a==="N"?s(!1):i.return&&t(o)}),V(ce,{flexDirection:"column",children:[V(B,{children:[ue(B,{color:"cyan",children:"?"})," ",e.message]}),V(ce,{marginTop:0,children:[V(B,{color:o?"cyan":void 0,bold:o,children:[o?"\u25CF ":"\u25CB ","Yes"]}),ue(B,{children:" "}),V(B,{color:o?void 0:"cyan",bold:!o,children:[o?"\u25CB ":"\u25CF ","No"]})]})]})}import{Box as de,Text as me}from"ink";import{jsx as q,jsxs as Fe}from"react/jsx-runtime";function Y({title:e,body:t}){let n=t.split(`
158
- `);return Fe(de,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:1,children:[q(me,{color:"cyan",bold:!0,children:e}),q(de,{flexDirection:"column",marginTop:0,children:n.map((o,s)=>q(me,{dimColor:!1,children:o.length===0?" ":o},s))})]})}import{jsx as u,jsxs as K}from"react/jsx-runtime";function Ct({defaults:e,onComplete:t,onlySection:n,banner:o}){let{exit:s}=ze(),a=X({...e}),i=X(new Map),[,m]=A(0),r=()=>m(p=>p+1),[c,f]=A(null),[y,T]=A(null),[E,_]=A([]),[O,k]=A(null),[Z,he]=A(!1),[L,ge]=A({current:0,total:0}),U=()=>{let p=i.current;for(let h of C){let z=h.isApplicable(a.current),l=p.get(h.id);z?n&&h.id!==n?l!=="current"&&p.set(h.id,"done"):(l==="skipped"||!l)&&p.set(h.id,"pending"):p.set(h.id,"skipped")}};i.current.size===0&&U();let j=X(!1);Le(()=>{if(d("WizardApp:useEffect fired",{startedAlready:j.current}),j.current){d("WizardApp:useEffect returning early (startedRef true)");return}j.current=!0,d("WizardApp:orchestrator starting");let p=0,h=l=>{let P=++p;return d("orchestrator:promptFn called",{id:P,type:l.type,message:l.message.slice(0,60)}),k(null),new Promise((w,g)=>{T({id:P,spec:l,resolve:v=>{d("orchestrator:prompt resolved",{id:P,type:l.type,value:typeof v=="string"?v.slice(0,30):v}),w(v)},reject:v=>{d("orchestrator:prompt rejected",{id:P,reason:v.message}),g(v)}})})},z=l=>{_(P=>[...P,l])};return(async()=>{try{let l=n?C.filter(g=>g.id===n):C,P=()=>l.filter(g=>g.isApplicable(a.current)).length,w=0;for(;w<l.length;){let g=l[w];if(!g.isApplicable(a.current)){i.current.set(g.id,"skipped"),w++,U(),r();continue}_([]);for(let b of C)b.id===g.id?i.current.set(b.id,"current"):i.current.get(b.id)==="current"&&i.current.set(b.id,"pending");f(g.id);let v=l.slice(0,w+1).filter(b=>b.isApplicable(a.current)).length;ge({current:v,total:P()}),r();try{let b=await g.execute(a.current,{prompt:h,info:z});a.current={...a.current,...b},i.current.set(g.id,"done"),U(),w++}catch(b){if(b instanceof R){i.current.set(g.id,"pending");let M=w-1;for(;M>=0&&!l[M].isApplicable(a.current);)M--;M<0||(w=M,i.current.set(l[w].id,"pending")),U(),r();continue}throw b}}d("orchestrator:all sections done, calling onComplete + exit"),he(!0),T(null),f(null),r(),await new Promise(g=>setTimeout(g,200)),t(a.current),s()}catch(l){d("orchestrator:caught error",{name:l?.name,message:l?.message}),l instanceof H&&(s(),process.exit(0));let P=l instanceof Error?l.message:String(l);k(`Setup error: ${P}`),r()}})(),()=>{d("WizardApp:useEffect cleanup ran (component unmounting)")}},[s,t]),De((p,h)=>{d("WizardApp:useInput fired",{input:p,ctrl:h.ctrl,escape:h.escape,return:h.return}),h.ctrl&&p==="c"&&(d("WizardApp:Ctrl+C \u2192 exiting"),s(),process.exit(0))});let fe=je(()=>C.map(p=>({id:p.id,title:p.title,status:i.current.get(p.id)??"pending"})),[c,Z,O]);return K(S,{flexDirection:"column",paddingY:1,children:[K(S,{marginBottom:1,children:[u(x,{bold:!0,color:"cyan",children:"Klaudius setup"}),u(x,{dimColor:!0,children:" \xB7 "}),u(x,{dimColor:!0,children:L.total>0?`Step ${L.current} of ${L.total}`:"Loading\u2026"})]}),K(S,{children:[u(ae,{items:fe}),K(S,{flexDirection:"column",flexGrow:1,marginLeft:2,children:[o&&K(S,{marginBottom:1,borderStyle:"round",borderColor:"red",paddingX:1,flexDirection:"column",children:[u(x,{color:"red",bold:!0,children:"\u26A0 Heads up"}),u(x,{children:o})]}),E.map((p,h)=>u(S,{marginBottom:1,children:u(Y,{title:p.title,body:p.body})},h)),y?.spec.note&&u(S,{marginBottom:1,children:u(Y,{title:y.spec.note.title,body:y.spec.note.body})}),y&&Ge(y),O&&u(S,{marginTop:1,children:u(x,{color:"red",children:O})}),Z&&u(S,{marginTop:1,children:u(x,{color:"green",bold:!0,children:"\u2713 Setup complete. Continuing\u2026"})})]})]}),u(S,{marginTop:1,children:u(x,{dimColor:!0,children:"\u21B5 confirm esc back to previous section ctrl-c cancel"})})]})}function Ge(e){let t=o=>e.resolve(o),n=()=>e.reject(new R);switch(e.spec.type){case"text":case"password":return u(se,{spec:e.spec,masked:e.spec.type==="password",onSubmit:t,onBack:n},e.id);case"select":return u(le,{spec:e.spec,onSubmit:t,onBack:n},e.id);case"confirm":return u(pe,{spec:e.spec,onSubmit:t,onBack:n},e.id)}}export{Ct as WizardApp};
@@ -1,6 +0,0 @@
1
- import{appendFileSync as o}from"fs";import{tmpdir as p}from"os";import{join as a}from"path";var r=a(p(),"klaudius-wizard-debug.log"),l=process.env.KLAUDIUS_WIZARD_DEBUG==="1",n=!1;function d(t,e){if(l)try{n||(n=!0,o(r,`
2
- === klaudius wizard debug session \u2014 ${new Date().toISOString()} ===
3
- node ${process.version}, platform ${process.platform}, tty=${process.stdin.isTTY}
4
- `));let s=`${Date.now()} `,c=e===void 0?"":" "+JSON.stringify(e,null,0).slice(0,400);o(r,s+t+c+`
5
- `)}catch{}}var x=r,i=!1;function g(){if(i)return;i=!0;let t=process.exit.bind(process);process.exit=(e=>{let s=new Error("process.exit called").stack??"(no stack)";return d("process.exit called",{code:e,stack:s.split(`
6
- `).slice(0,8).join(" | ")}),t(e)})}export{d as a,x as b,g as c};