@flowe-ai/cli 0.3.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/dist/cli.js CHANGED
@@ -1,95 +1,96 @@
1
- import{a as Dt,b as Ve,c as We,d as Ut,e as jt,f as ze,g as Xe,h as qt,i as Ht,l as Yt,n as Ee,o as fe,p as ve,q as Re,r as _e,s as $e,t as Ie,u as Xt,v as Zt,w as en,x as tn,y as nn}from"./chunk-ZP43LZEQ.js";import{d as Vt,g as Wt,h as Jt,i as Ze,j as Ce,k as oe,l as Qt,m as zt}from"./chunk-3TLGYA6M.js";import{b as et}from"./chunk-3HG2U5YK.js";import{a as G,b as Je,e as Qe,f as Ft,g as Lt,h as Kt,i as W,k as Gt}from"./chunk-EC5WRPZP.js";import{cac as Ei}from"cac";import{existsSync as vi}from"fs";import Mr from"qrcode-terminal";async function rn(e="quick_reset",t={}){let n=G(),r=await W();if(!r)throw Object.assign(new Error("sign in with: flowe login"),{code:"auth_required"});let o;try{o=await fetch(`${n.backend_url}/api/v1/sessions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({protocolId:"nsdr",sessionType:e})})}catch{throw Object.assign(new Error("network unreachable \u2014 try: flowe reset"),{code:"network_error"})}if(!o.ok)throw o.status===401?Object.assign(new Error("session expired \u2014 run: flowe login"),{code:"auth_required"}):Object.assign(new Error(`server error ${o.status}`),{code:"network_error"});let s=await o.json(),i=`flowe://session/${s.session_id}`;return!t.suppressQr&&process.stdout.isTTY&&Mr.generate(i,{small:!0}),{session_id:s.session_id,session_type:s.session_type,session_type_name:s.session_type_name,estimated_duration:s.estimated_duration,join_url:i,status:"waiting_for_join",message_for_user:`${s.session_type_name} (${s.estimated_duration}min) ready \xB7 ${i}`}}import{createWriteStream as Nr}from"fs";import{mkdtemp as Br,rm as Dr}from"fs/promises";import{tmpdir as Fr}from"os";import{join as on}from"path";import{pipeline as Lr}from"stream/promises";import{Readable as Kr}from"stream";async function sn(e){let t=await Br(on(Fr(),"flowe-stream-")),n=on(t,"audio.mp3"),r=async()=>{try{await Dr(t,{recursive:!0,force:!0})}catch{}};try{let o=await fetch(e.url,{headers:e.headers,signal:e.signal});if(o.status===401)throw Object.assign(new Error("login required \u2014 run: flowe login"),{code:"auth_required"});if(o.status===404)throw Object.assign(new Error("session type not available on server"),{code:"protocol_unavailable"});if(!o.ok)throw Object.assign(new Error(`stream failed: ${o.status} ${o.statusText}`),{code:"network_error"});if(!o.body)throw Object.assign(new Error("empty response body"),{code:"network_error"});let s=(()=>{let m=o.headers.get("content-length");return m?parseInt(m,10):null})(),i=(()=>{let d=o.headers.get("cache-control")?.match(/max-age=(\d+)/);return d?parseInt(d[1],10):null})(),a=0,u=Kr.fromWeb(o.body),c=Nr(n);return u.on("data",m=>{a+=m.length,e.onProgress?.(a,s)}),await Lr(u,c),{filePath:n,cleanup:r,bytes:a,cacheMaxAge:i}}catch(o){throw await r(),o}}function Ur(e,t,n,r){let o=new URL(`/api/v1/nsdr/sessions/${t}/stream`,e);return o.searchParams.set("duration",String(n)),o.searchParams.set("voice",r),o.toString()}async function se(e){let t=G(),n=await W();if(!n)throw Object.assign(new Error("sign in with: flowe login"),{code:"auth_required"});let r=e.durationMin??5,o=e.voice??t.voice,s=Ur(t.backend_url,e.type,r,o),i;if(process.stdout.isTTY){let m=-1;i=(d,w)=>{if(!w){process.stdout.write(`\r fetching ${e.type}\u2026 ${d} bytes`);return}let E=Math.floor(d/w*100);E!==m&&(m=E,process.stdout.write(`\r fetching ${e.type}\u2026 ${E}%`))}}let a=await sn({url:s,headers:{Authorization:`Bearer ${n}`},signal:e.signal,onProgress:i});process.stdout.isTTY&&process.stdout.write("\r\x1B[2K");let c=qt(a.filePath).finally(()=>a.cleanup());return{started_at:new Date().toISOString(),type:e.type,voice:o,durationMin:r,finished:c,cancel:()=>Ht()}}import Jo from"node-notifier";import{fileURLToPath as Qo}from"url";import{dirname as zo,join as Xo}from"path";var tt="\x1B[0m",jr="\x1B[1m",qr="\x1B[2m",nt={oak:{r:212,g:165,b:116},oakDeep:{r:184,g:145,b:95},sage:{r:124,g:154,b:142},dusk:{r:139,g:123,b:164},duskLight:{r:185,g:163,b:204},duskDeep:{r:110,g:97,b:137},charcoal:{r:45,g:45,b:45}};function rt(){return process.env.NO_COLOR?!1:process.env.FORCE_COLOR?!0:!!process.stdout.isTTY}function ot(e,t){return rt()?`\x1B[38;2;${e.r};${e.g};${e.b}m${t}${tt}`:t}var f=e=>ot(nt.oak,e),M=e=>ot(nt.oakDeep,e),an=e=>ot(nt.sage,e);var l=e=>rt()?`${qr}${e}${tt}`:e,C=e=>rt()?`${jr}${e}${tt}`:e;var Hr=/\x1b\[[0-9;]*m/g,B={tl:"\u256D",tr:"\u256E",bl:"\u2570",br:"\u256F",h:"\u2500",v:"\u2502",inTl:"\u250C",inTr:"\u2510",inBl:"\u2514",inBr:"\u2518"};function st(e){return e.replace(Hr,"").length}function J(e,t){let n=st(e);return n>=t?e:e+" ".repeat(t-n)}function K(e,t){let n=B.tl+B.h.repeat(t+2)+B.tr,r=B.bl+B.h.repeat(t+2)+B.br;return[n,...e.map(o=>`${B.v} ${J(o,t)} ${B.v}`),r]}function N(e,t){let n=st(e);if(n>=t)return e;let r=Math.floor((t-n)/2);return" ".repeat(r)+e}var Gr=54;function ut(e,t=Gr){return K(e,t)}function Yr(e=new Date){let t=e.getHours();return t<5?"Late night":t<12?"Good morning":t<18?"Good afternoon":t<22?"Good evening":"Late night"}function un(e,t=new Date){let n=Yr(t),r=(e??"").trim(),o=r.length>0?r:"there";return`${n}, ${o}.`}function Pe(e,t){let n=t?f("\u25B8 "):" ",r=t?C(f(e.label)):e.label,o=e.detail?" "+l("\xB7 "+e.detail):"";return` ${n}${r}${o}`}function ct(e){let t=f("\u2713"),n=l(e.label.toUpperCase().padEnd(8)),r=f(e.value);return` ${t} ${n} ${r}`}function lt(e){return e.length===0?[]:[...e.map(ct),""]}var cn=" \u2191\u2193 to move \u23CE to select esc to cancel",Vr=" \u2191\u2193 to move \u23CE to select esc to back",dt=[30,45,60,90],Te=[{id:"ellie",description:"warm, even pace"},{id:"sage",description:"grounded, low"},{id:"ada",description:"clear, neutral"}];function Wr(e,t=[]){return ut(["",...lt(t),` ${M("\u25C6")} you're not signed in.`,""," sign in to track your progress, build a streak,"," and personalize your sessions.","",Pe({label:"SIGN IN"},e===0),Pe({label:"MAYBE LATER",detail:"anonymous"},e===1),"",l(cn),""])}function Jr(e,t,n=[],r=dt){return ut(["",...lt(n),` ${t}`," What's the cadence for today?","",...r.map((o,s)=>Pe({label:`${o} seconds`},s===e)),"",l(cn),""])}function Qr(e,t=[]){return ut(["",...lt(t)," Pick your guide.","",...Te.map((n,r)=>Pe({label:n.id,detail:n.description},r===e)),"",l(Vr),""])}var Ae=e=>`\x1B[${e}A`,at="\x1B[2K",zr="\x1B[?25l",Xr="\x1B[?25h";function Zr(e,t,n){let r="";n>0&&(r+=Ae(n));for(let o of t)r+=`\r${at}${o}
2
- `;if(n>t.length){let o=n-t.length;for(let s=0;s<o;s++)r+=`\r${at}
3
- `;r+=Ae(o)}e.write(r)}function eo(e,t=dt){let n=t.indexOf(e);if(n>=0)return n;let r=t.indexOf(60);return r>=0?r:0}function to(e){let t=Te.findIndex(n=>n.id===e);return t>=0?t:0}async function it(e,t,n,r,o,s){let i=n,a=()=>{let u=o(i);Zr(e.out,u,t.height),t.height=u.length};for(a();;){let u=await e.keys.next();if(u.done)return{cancel:!0};let c=u.value;if(c.name==="ctrl-c")return{cancel:!0};if(c.name==="escape")return{back:!0};if(c.name==="up"||c.name==="char"&&c.char==="k"){i=(i-1+r)%r,a();continue}if(c.name==="down"||c.name==="tab"||c.name==="char"&&c.char==="j"){i=(i+1)%r,a();continue}if(c.name==="return")return{result:s(i)}}}async function ln(e){let t=e.io??no();t.setRawMode?.(!0),t.out.write(zr);let n={height:0};try{let r="already_authed",o=[];if(e.showAuthWedge){let i=await it(t,n,0,2,a=>Wr(a,o),a=>a===0?"signin":"later");if("cancel"in i||"back"in i)return null;i.result==="signin"?(e.signIn&&await e.signIn(),r="signed_in",o.push({label:"auth",value:"signed in"})):(r="maybe_later",o.push({label:"auth",value:"continuing as guest"}))}let s=e.availableDurations?.length?e.availableDurations:dt;for(;;){let i=await it(t,n,eo(e.defaultDuration,s),s.length,u=>Jr(u,e.greeting,o,s),u=>s[u]);if("cancel"in i||"back"in i)return null;o.push({label:"cadence",value:`${i.result} seconds`});let a=await it(t,n,to(e.defaultVoice),Te.length,u=>Qr(u,o),u=>Te[u].id);if("cancel"in a)return null;if("back"in a){o.pop();continue}return{duration:i.result,voice:a.result,authChoice:r}}}finally{if(t.setRawMode?.(!1),t.out.write(Xr),e.clearOnExit&&n.height>0){let r=Ae(n.height);for(let o=0;o<n.height;o++)r+=`\r${at}
4
- `;r+=Ae(n.height),t.out.write(r)}await t.keys.return?.()}}function dn(){return!!process.stdout.isTTY&&!!process.stdin.isTTY&&!process.env.NO_COLOR&&!process.env.CI}function no(){let e=process.stdin;return{out:process.stdout,setRawMode:n=>{e.isTTY&&e.setRawMode(n)},keys:ro(e)}}function ro(e){e.resume();let t=[],n=[],r=!1,o=i=>{let a=Buffer.isBuffer(i)?i:Buffer.from(i),u=Q(a);for(let c of u){let m=n.shift();m?m(c):t.push(c)}},s=()=>{for(r=!0;n.length;)n.shift()(null)};return e.on("data",o),e.once("end",s),{async next(){return t.length?{value:t.shift(),done:!1}:r?{value:void 0,done:!0}:new Promise(i=>{n.push(a=>{i(a===null?{value:void 0,done:!0}:{value:a,done:!1})})})},async return(){return e.off("data",o),e.off("end",s),e.pause(),{value:void 0,done:!0}}}}function Q(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r===3){t.push({name:"ctrl-c"}),n+=1;continue}if(r===13||r===10){t.push({name:"return"}),n+=1;continue}if(r===9){t.push({name:"tab"}),n+=1;continue}if(r===27){if(e[n+1]===91){let o=e[n+2];o===65?t.push({name:"up"}):o===66?t.push({name:"down"}):t.push({name:"escape"}),n+=3;continue}t.push({name:"escape"}),n+=1;continue}if(r>=32&&r<127){t.push({name:"char",char:String.fromCharCode(r)}),n+=1;continue}n+=1}return t}var U={pomodoro:{focusSec:1500,breakSec:300,longBreakSec:900,blocks:4},dev:{focusSec:3e3,breakSec:600,longBreakSec:1800,blocks:3},ultradian:{focusSec:5400,breakSec:900,longBreakSec:1800,blocks:2},test2:{focusSec:20,breakSec:20,longBreakSec:50,blocks:2},test5:{focusSec:90,breakSec:30,longBreakSec:80,blocks:2}},me=5;function Oe(e,t){return{status:"PRE_FLIGHT",blockIndex:0,enteredAtMs:t,pausedAtMs:null,pausedDurationMs:0,preset:e}}function pe(e,t){return e.status!=="PRE_FLIGHT"?e:{...e,status:"FOCUS_BLOCK",blockIndex:1,enteredAtMs:t,pausedAtMs:null,pausedDurationMs:0}}function oo(e,t){let n=t-e.enteredAtMs;return e.pausedAtMs!==null?e.pausedAtMs-e.enteredAtMs-e.pausedDurationMs:n-e.pausedDurationMs}function xe(e){switch(e.status){case"FOCUS_BLOCK":return e.preset.focusSec;case"TRANSITION":return me;case"BREAK":return e.preset.breakSec;case"LONG_BREAK":return e.preset.longBreakSec;default:return 0}}function z(e,t){let n=xe(e),r=Math.floor(oo(e,t)/1e3);return Math.max(0,n-r)}function fn(e,t,n){return{...e,status:t,blockIndex:t==="FOCUS_BLOCK"?e.blockIndex+1:e.blockIndex,enteredAtMs:n,pausedAtMs:null,pausedDurationMs:0}}function mn(e){switch(e.status){case"FOCUS_BLOCK":return"TRANSITION";case"TRANSITION":return e.blockIndex>=e.preset.blocks?"LONG_BREAK":"BREAK";case"BREAK":return"FOCUS_BLOCK";case"LONG_BREAK":return"CYCLE_DONE";default:return e.status}}function Me(e,t){switch(t.kind){case"PAUSE":return e.pausedAtMs!==null||e.status==="PRE_FLIGHT"||e.status==="CYCLE_DONE"?e:{...e,pausedAtMs:t.nowMs};case"RESUME":{if(e.pausedAtMs===null)return e;let n=t.nowMs-e.pausedAtMs;return{...e,pausedAtMs:null,pausedDurationMs:e.pausedDurationMs+n}}case"SKIP":return e.status!=="FOCUS_BLOCK"&&e.status!=="BREAK"&&e.status!=="LONG_BREAK"&&e.status!=="TRANSITION"?e:fn(e,mn(e),t.nowMs);case"QUIT":return{...e,status:"CYCLE_DONE",enteredAtMs:t.nowMs,pausedAtMs:null};case"TICK":return e.pausedAtMs!==null||e.status==="PRE_FLIGHT"||e.status==="CYCLE_DONE"||z(e,t.nowMs)>0?e:fn(e,mn(e),t.nowMs)}}function Ne(e,t){return e.status!==t.status||e.blockIndex!==t.blockIndex}var so=100,io=8e3,pn=28;function ao(e,t){if(t.length===0||e<t[0].start_ms)return-1;let n=t.length-1;if(e>=t[n].end_ms)return n;for(let r=0;r<=n;r+=1)if(e<t[r].end_ms)return r;return n}var uo=24,co=11,bn=64,ft=["\xB7","\u2219","\u2022","\u25CF"],gn=1e3,lo=(()=>{let e=[],t=Math.PI*(3-Math.sqrt(5));for(let n=0;n<bn;n++){let r=n*t%(2*Math.PI),o=Math.sqrt((n+.5)/bn),s=n*.4123*2*Math.PI%(2*Math.PI);e.push({angle:r,radius:o,phaseOffset:s})}return e})();function fo(e,t){return e<=1?M(t):f(t)}function pt(e,t,n=uo,r=co,o=io){let s=[];for(let g=0;g<r;g++)s.push(new Array(n).fill(0));let i=Math.min(1,Math.max(0,e)/gn),a=Math.min(1,Math.max(0,t)/gn),u=Math.min(i,a);if(u<=0)return new Array(r).fill("");let c=(n-1)/2,m=(r-1)/2,d=(n-2)/2,w=(r-2)/2,E=e/o*2*Math.PI;for(let g of lo){let S=.5+.5*Math.sin(E+g.phaseOffset),b=1-g.radius*.35,v=S*b*u;if(v<.12)continue;let h=Math.round(c+g.radius*d*Math.cos(g.angle)),R=Math.round(m+g.radius*w*Math.sin(g.angle));h<0||h>=n||R<0||R>=r||v>s[R][h]&&(s[R][h]=v)}let P=[],$=.88/ft.length;for(let g=0;g<r;g++){let S="";for(let b=0;b<n;b++){let v=s[g][b];if(v<.12){S+=" ";continue}let h=Math.min(ft.length-1,Math.floor((v-.12)/$));S+=fo(h,ft[h])}P.push(S)}return P}var bt=60,mt=50,hn=mt+2;function mo(e){return`${Math.max(0,Math.floor(e))}s`}function po(e,t,n){return` ${M("\u2740")} ${C("SESSION_ACTIVE")} ${t}s \xB7 ${e} \xB7 ${l(n)}`}function bo(e){let t=` ${B.inTl}${B.h.repeat(hn)}${B.inTr} `,n=` ${B.inBl}${B.h.repeat(hn)}${B.inBr} `,r=e.map(o=>{let s=N(o,mt);return` ${B.v} ${J(s,mt)} ${B.v} `});return[t,...r,n]}function go(e){let t=e.toLowerCase().trim();return/\binhale\b/.test(t)?"INHALING . . .":/\bexhale\b/.test(t)?"EXHALING . . .":/\bhold\b/.test(t)?"HOLDING . . .":`${t.replace(/^\d+\s+/,"").trim().toUpperCase()} . . .`}function ho(e,t){let n=ao(t,e);if(n<0)return"";let r=go(e[n].label),o=`[ ${C(f(r))} ]`;return N(o,bt)}function wo(e,t,n){let r=Math.max(0,Math.min(.999,e/t));return Math.min(n,Math.floor(r*n)+1)}function So(e,t,n,r){let o=`${l("TIME_REMAINING")} ${f(`-${mo(e/1e3)}`)}`;if(!r)return` ${o}`;let s=wo(t,n,r),i=`${l("ROUND")} ${f(`${s} / ${r}`)}`,a=Math.floor(bt/2);return J(` ${o}`,a)+i}function yo(e,t){let n=Math.min(1,Math.max(0,e/t)),r=Math.round(n*pn),o=pn-r,s=`${f("\u2588".repeat(r))}${l("\u2591".repeat(o))}`,i=`${Math.round(n*100)}%`;return` ${l("PROGRESS_SEQUENCE")} [${s}] ${l(i)}`}var ko="\x1B[?25l",wn="\x1B[?25h",Co=e=>`\x1B[${e}A`,Eo="\x1B[H",vo="\x1B[2K",Ro="\r",_o="\x1B[?1049h",Sn="\x1B[?1049l",$o=25;function yn(e,t,n){let r=Math.max(0,n-t),o=bo(pt(t,r)),s=["",po(e.displayName,e.duration,e.voice),"",...o,"",ho(e.cues,t),"",So(r,t,n,e.rounds),"",yo(t,n),""];return{lines:K(s,bt)}}function kn(e,t,n){let r="";n||(r+=Co($o));for(let o of t.lines)r+=`${Ro}${vo}${o}
5
- `;e.write(r)}async function Cn(e){let t=e.out??process.stdout,n=e.now??Date.now,r=e.startedAt??n(),o=e.duration*1e3;t.write(_o+Eo+ko);let s=!0,i=!1,a=()=>{if(i)return;let m=n()-r,d=yn(e,m,o);kn(t,d,s),s=!1};a();let u=setInterval(a,so),c=()=>{i=!0,clearInterval(u),t.write(wn+Sn),process.exit(130)};process.once("SIGINT",c);try{await e.donePromise}finally{i=!0,clearInterval(u),process.removeListener("SIGINT",c);let m=yn(e,o,o);kn(t,m,!1),t.write(wn+Sn)}}function En(){return!!process.stdout.isTTY&&!process.env.NO_COLOR&&!process.env.CI}var x=60,wt=30,Io=28,Po=8,To=1e4,St=25,Ao=St+2;function Z(e){return e.length>=St?e:[...e,...new Array(St-e.length).fill("")]}function be(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/60),r=t%60;return`${n}:${r.toString().padStart(2,"0")}`}function Oo(e,t,n=wt){let r=t<=0?0:Math.max(0,Math.min(1,e/t)),o=Math.round(r*n),s=n-o;return`${f("\u2588".repeat(o))}${l("\u2591".repeat(s))}`}function xo(e,t){return t<=0?"0%":`${Math.round(e/t*100)}%`}function Mo(e){switch(e){case"PRE_FLIGHT":return"PRE_FLIGHT";case"FOCUS_BLOCK":return"FOCUS_BLOCK";case"TRANSITION":return"TRANSITION";case"BREAK":return"BREAK";case"LONG_BREAK":return"LONG_BREAK";case"CYCLE_DONE":return"CYCLE_DONE"}}function _n(e,t){return` ${M("\u2740")} ${C(Mo(e.status))} ${l(t)}`}function ee(e){return e.length===0?[]:[...e.map(ct),""]}function No(e,t){let n=be(z(e,t));return e.status==="FOCUS_BLOCK"?`block ${e.blockIndex} of ${e.preset.blocks} \xB7 ${n} \xB7 deep work`:e.status==="BREAK"?`break ${e.blockIndex} of ${e.preset.blocks} \xB7 ${n} \xB7 step away`:e.status==="LONG_BREAK"?`long break \xB7 ${n} \xB7 long rest`:e.status==="TRANSITION"?`transition \xB7 next: ${e.blockIndex>=e.preset.blocks?"long break":"break"}`:""}function $n(e,t){let n=No(e,t);return N(`${f("\u25B8")} ${l(n)}`,x)}function Bo(e){let t=[];for(let n=1;n<=e.blocks;n++)t.push({kind:"focus",blockIndex:n}),n<e.blocks&&t.push({kind:"break",blockIndex:n});return t.push({kind:"long_break",blockIndex:e.blocks}),t}function Do(e,t){for(let n=0;n<t.length;n++){let r=t[n];if(r.kind==="focus"&&r.blockIndex===e.blockIndex&&(e.status==="FOCUS_BLOCK"||e.status==="TRANSITION")||r.kind==="break"&&r.blockIndex===e.blockIndex&&e.status==="BREAK"||r.kind==="long_break"&&e.status==="LONG_BREAK")return n}return-1}function In(e){let t=Bo(e.preset),n=Do(e,t),r=[];for(let o=0;o<t.length;o++)o<n?r.push(f("\u2713")):o===n?r.push(C(f("\u25B8"))):r.push(l("\xB7"));return r.join(" ")}function Fo(e,t){let n=e.paused&&e.state.pausedAtMs!==null?e.state.pausedAtMs-e.state.enteredAtMs:e.elapsedMs;return pt(n,t*1e3,Io,Po,To).map(r=>N(e.paused?l(r):r,x))}function Pn(e){let t=`[ ${C(f(e))} ]`;return N(t,x)}function Tn(e,t){let n=Oo(e,t),r=xo(e,t);return` ${l("PROGRESS_SEQUENCE")} [${n}] ${l(r)}`}function An(e){return e?` ${C(f("space"))} ${C("resume")} \xB7 ${l("s")} skip \xB7 ${C(f("q"))} ${C("quit")} \xB7 ${l("?")} help`:` ${l("space")} pause \xB7 ${l("s")} skip \xB7 ${l("q")} quit \xB7 ${l("?")} help`}function Lo(e){let t=e.state.preset,n=["",` ${M("\u2740")} ${C("FOCUS_CYCLE")} ${l(e.presetName)}`,"",...ee(e.breadcrumbs??[]),` ${l("blocks")} ${f(String(t.blocks))}`,` ${l("focus")} ${f(be(t.focusSec))} each`,` ${l("break")} ${f(be(t.breakSec))} each`,` ${l("long break")} ${f(be(t.longBreakSec))} after the last block`,"",N(`[ ${C(f("press enter to begin"))} ]`,x),"",` ${l("q")} quit`,""];return K(Z(n),x)}function gt(e,t){let n=xe(e.state),r=z(e.state,e.nowMs),o=n-r,s=e.paused?"PAUSED":t,i=["",_n(e.state,e.presetName),"",...ee(e.breadcrumbs??[]),$n(e.state,e.nowMs),"",...Fo(e,r),"",N(In(e.state),x),"",Pn(`${s} . . .`),"",Tn(o,n),"",An(e.paused),""];return K(Z(i),x)}function Ko(e){let t=z(e.state,e.nowMs),n=xe(e.state),r=n-t,o=e.state.blockIndex>=e.state.preset.blocks?"LONG_BREAK":"BREAK",s=["",_n(e.state,e.presetName),"",...ee(e.breadcrumbs??[]),$n(e.state,e.nowMs),"","","",N(`${f(`next: ${o} in ${t}s`)}`,x),"","",N(In(e.state),x),"",Pn("FETCHING SESSION . . ."),"",Tn(r,n),"",An(e.paused),""];return K(Z(s),x)}function Uo(e){let t=e.state.preset,n=be(t.focusSec*t.blocks),r=["",` ${M("\u2740")} ${C("CYCLE_DONE")} ${l(e.presetName)}`,"",...ee(e.breadcrumbs??[]),` ${l("focus blocks")} ${f(`${t.blocks}`)}`,` ${l("total deep work")} ${f(n)}`,` ${l("breaks taken")} ${f(`${t.blocks}`)}`,"",N(`[ ${C(f("nice work"))} ]`,x),"",` ${l("r")} repeat \xB7 ${l("x")} exit`,""];return K(Z(r),x)}function Be(e){switch(e.state.status){case"PRE_FLIGHT":return Lo(e);case"FOCUS_BLOCK":return gt(e,"DEEP WORK");case"TRANSITION":return Ko(e);case"BREAK":return gt(e,"BREATHE");case"LONG_BREAK":return gt(e,"LONG_REST");case"CYCLE_DONE":return Uo(e)}}function De(e){return Ao}function yt(e){let t=U[e];if(t.focusSec<60||t.breakSec<60)return`${t.focusSec}s/${t.breakSec}s \xB7 ${t.blocks} blocks`;let n=Math.round(t.focusSec/60),r=Math.round(t.breakSec/60);return`${n}/${r} \xB7 ${t.blocks} blocks`}var te=["pomodoro","dev","ultradian","test2","test5"];function jo(e,t){let n=t?f("\u25B8 "):" ",r=t?C(f(e)):e,o=l(`\xB7 ${yt(e)}`);return` ${n}${J(r,10)} ${o}`}function On(e,t=[]){let n=["",` ${M("\u2740")} ${C("FOCUS_CYCLE")} ${l("pick a cadence")}`,"",...ee(t),...te.map((r,o)=>jo(r,o===e)),"",` ${l("\u2191\u2193 to move \u23CE to select esc to cancel")}`,""];return K(Z(n),x)}var xn=22,qo=22,ht=["\u2581","\u2582","\u2583","\u2584","\u2585","\u2584","\u2583","\u2582"];function Ho(e){let t=e%ht.length,n="";for(let r=0;r<5;r++)n+=ht[(t+r)%ht.length];return n}function Go(e){let t=e?f("\u25B8"):" ",n=e?C(f("none")):"none",r=l("silence \u2014 your own thoughts");return` ${t} ${J(n,xn)} ${r}`}function Yo(e){return` ${l(e.toUpperCase())}`}function Vo(e,t,n){let r=t?f("\u25B8"):" ",o=t?C(f(e.name)):e.name,s=l(J(e.blurb,qo)),i=t?f(` ${Ho(n)}`):"";return` ${r} ${J(o,xn)} ${s}${i}`}function Mn(e){let{entries:t,selectedIdx:n,tickFrame:r,breadcrumbs:o=[]}=e,s=[];s.push(` ${M("\u2740")} ${C("FOCUS_CYCLE")} ${l("pick an ambience")}`),s.push(""),s.push(...ee(o));for(let i=0;i<t.length;i++){let a=t[i],u=i===n;a.kind==="none"?s.push(Go(u)):a.kind==="category"?s.push(Yo(a.label)):s.push(Vo(a.sound,u,r))}return s.push(""),s.push(` ${l("\u2191\u2193 to move \u23CE to select esc to cancel")}`),K(Z(s),x)}var vn=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function Rn(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} kB`:`${(e/1024/1024).toFixed(1)} MB`}function Wo(e,t){let n=t<=0?0:Math.max(0,Math.min(1,e/t)),r=Math.round(n*wt),o=wt-r;return`${f("\u2588".repeat(r))}${l("\u2591".repeat(o))}`}function Nn(e){let{sound:t,status:n,downloaded:r,total:o,tickFrame:s,breadcrumbs:i=[]}=e,a=vn[s%vn.length],u=n==="ready"?C(f("READY . . .")):n==="failed"?C(f("OFFLINE \u2014 STARTING IN SILENCE")):n==="timeout"?C(f("TIMED OUT \u2014 STARTING IN SILENCE")):`${f(a)} ${C("PREPARING . . .")}`,c=o<=0?0:Math.round(r/o*100),m=t?`${C(f(t.name))} ${l(t.blurb)}`:`${C(f("silence"))} ${l("your own thoughts")}`,d=t?`${l(Rn(r))} ${l("/")} ${l(Rn(o))} ${l(`${c}%`)}`:"",w=["",` ${M("\u2740")} ${C("FOCUS_CYCLE")} ${l("preparing your ambience")}`,"",...ee(i),N(`[ ${u} ]`,x),"",N(m,x),"",N(`[${Wo(r,o)}]`,x),"",N(d,x),"",` ${l("esc to cancel")}`,""];return K(Z(w),x)}var ge="\x1B[?1049h",ie="\x1B[?1049l",ue="\x1B[?25l",ae="\x1B[?25h",he="\x1B[H",Le=e=>`\x1B[${e}A`,Ke="\x1B[2K",Zo=100,es=3e4,Fn=80,Bn=Xo(zo(Qo(import.meta.url)),"..","assets/notification-icon.png");async function Ln(e={}){let t=e.out??process.stdout,n=e.stdin??process.stdin,r=e.defaultPreset??"pomodoro",o=e.breadcrumbs??[],s=Math.max(0,te.indexOf(r)),i=[],a=!1,u=null,c=()=>{if(u){let g=u;u=null,g.resolve()}},m=g=>{let S=Buffer.isBuffer(g)?g:Buffer.from(g);for(let b of Q(S))i.push(b);c()},d=()=>{a=!0,c()};n.isTTY&&n.setRawMode(!0),n.resume(),n.on("data",m),n.once("end",d),t.write(ge+he+ue);let w=!0,E=()=>{let g=On(s,o),S="";w||(S+=Le(g.length));for(let b of g)S+=`\r${Ke}${b}
6
- `;t.write(S),w=!1},P=()=>{n.isTTY&&n.setRawMode(!1),n.off("data",m),n.off("end",d),n.pause(),t.write(ae+ie)},$=()=>{P(),process.removeListener("SIGINT",$),process.exit(0)};process.on("SIGINT",$);try{for(E();;){if(i.length===0){if(a)return null;await new Promise(g=>{u={resolve:g}})}for(;i.length>0;){let g=i.shift();if(g.name==="ctrl-c"||g.name==="escape")return null;if(g.name==="up"||g.name==="char"&&g.char?.toLowerCase()==="k")s=(s-1+te.length)%te.length,E();else if(g.name==="down"||g.name==="tab"||g.name==="char"&&g.char?.toLowerCase()==="j")s=(s+1)%te.length,E();else{if(g.name==="return")return te[s];if(g.name==="char"&&g.char?.toLowerCase()==="q")return null}}}}finally{process.removeListener("SIGINT",$),P()}}function ts(e,t){if(t)for(let n=0;n<e.length;n++){let r=e[n];if(r.kind==="sound"&&r.sound.id===t)return n}for(let n=0;n<e.length;n++)if(e[n].kind==="none")return n;return 0}async function Kn(e){let t=e.out??process.stdout,n=e.stdin??process.stdin,r=e.breadcrumbs??[],o=Qt(e.manifest),s=zt(o),i=ts(o,e.defaultSoundId),a=0,u=[],c=!1,m=null,d=()=>{if(m){let h=m;m=null,h.resolve()}},w=h=>{let R=Buffer.isBuffer(h)?h:Buffer.from(h);for(let D of Q(R))u.push(D);d()},E=()=>{c=!0,d()};n.isTTY&&n.setRawMode(!0),n.resume(),n.on("data",w),n.once("end",E),t.write(ge+he+ue);let P=!0,$=()=>{let h=Mn({entries:o,selectedIdx:i,tickFrame:a,breadcrumbs:r}),R="";P||(R+=Le(h.length));for(let D of h)R+=`\r${Ke}${D}
7
- `;t.write(R),P=!1},g=()=>{n.isTTY&&n.setRawMode(!1),n.off("data",w),n.off("end",E),n.pause(),t.write(ae+ie)},S=()=>{g(),process.removeListener("SIGINT",S),process.exit(0)};process.on("SIGINT",S);let b=(h,R)=>{let D=s.indexOf(h);if(D<0)return h;let F=(D+R+s.length)%s.length;return s[F]},v=setInterval(()=>{a++,$()},Fn);try{for($();;){if(u.length===0){if(c)return null;await new Promise(h=>{m={resolve:h}})}for(;u.length>0;){let h=u.shift();if(h.name==="ctrl-c"||h.name==="escape")return null;if(h.name==="up"||h.name==="char"&&h.char?.toLowerCase()==="k")i=b(i,-1),$();else if(h.name==="down"||h.name==="tab"||h.name==="char"&&h.char?.toLowerCase()==="j")i=b(i,1),$();else if(h.name==="return"){let R=o[i];if(R.kind==="none")return{sound:null};if(R.kind==="sound")return{sound:R.sound}}else if(h.name==="char"&&h.char?.toLowerCase()==="q")return null}}}finally{v&&(clearInterval(v),v=null),process.removeListener("SIGINT",S),g()}}async function Un(e){let t=e.out??process.stdout,n=e.sound,r=e.timeoutMs??es,o=e.breadcrumbs??[];if(!n)return Dn(t,{sound:null,status:"ready",downloaded:0,total:0,tickFrame:0,breadcrumbs:o},!0),await Fe(250),{filePath:null,outcome:"silent"};if(Jt(n))return{filePath:Vt(n),outcome:"cached"};let s=0,i=n.bytes,a=0,u="fetching",c=!0,m=()=>{Dn(t,{sound:n,status:u,downloaded:s,total:i,tickFrame:a,breadcrumbs:o},c),c=!1},d=setInterval(()=>{a++,m()},Fn),w=new AbortController,E=setTimeout(()=>{w.abort(),P?.("timeout")},r),P=null,$=new Promise(v=>{P=v}),g=(v,h)=>{s=v,i=h||n.bytes},S=(e.download?e.download(n,g):Ce(n,{signal:w.signal,onProgress:v=>g(v.downloaded,v.total)})).then(v=>({ok:!0,path:v})).catch(()=>({ok:!1}));t.write(ge+he+ue),m();let b=await Promise.race([S,$]);return clearInterval(d),clearTimeout(E),P=null,b==="timeout"?(u="timeout",m(),await Fe(400),t.write(ae+ie),{filePath:null,outcome:"timeout"}):b.ok?(u="ready",s=i,m(),await Fe(300),t.write(ae+ie),{filePath:b.path,outcome:"ready"}):(u="failed",m(),await Fe(400),t.write(ae+ie),{filePath:null,outcome:"failed"})}function Dn(e,t,n){let r=Nn(t),o="";n?o+=ge+he+ue:o+=Le(r.length);for(let s of r)o+=`\r${Ke}${s}
8
- `;e.write(o)}function Fe(e){return new Promise(t=>setTimeout(t,e))}function ns(e,t){switch(e){case"pause":return{kind:"PAUSE",nowMs:t};case"resume":return{kind:"RESUME",nowMs:t};case"skip":return{kind:"SKIP",nowMs:t};case"quit":return{kind:"QUIT",nowMs:t}}}async function jn(e){let t=e.out??process.stdout,n=e.stdin??process.stdin,r=e.now??Date.now,o=U[e.preset],s=e.preset,i=e.breakType??"quick_reset",a=e.longBreakType??"executive_reset",u=e.notifications??!0,c=e.ambientFilePath??void 0,m=(e.ambientEnabled??!0)&&!!c,d=e.startAmbient??oe,w=e.breadcrumbs??[],E=e.autoStart??!0,P=e.stateEnabled??!0,$=e.ambientId??null,g=process.pid,S=!1;if(P){let p=Re({pidOverride:g});if(p.kind==="busy")throw new Error(`focus session already running (pid ${p.pid})`);S=!0}let b=Oe(o,r()),v=b.enteredAtMs,h=null,R=null,D=()=>{R?.stop(),R=null},F=De(o),I=!0,A="",j=(p,k=!1)=>{let _=p.join(`
9
- `);if(!k&&!I&&_===A)return;let Y="";I||(Y+=Le(F));for(let xr of p)Y+=`\r${Ke}${xr}
10
- `;t.write(Y),I=!1,A=_},y=(p=!1)=>{let k=r()-b.enteredAtMs,_=Be({state:b,presetName:s,elapsedMs:k,nowMs:r(),paused:b.pausedAtMs!==null,breadcrumbs:w});j(_,p)},L=()=>{if(!(!P||!S))try{Ee({version:1,pid:g,status:b.status,preset:s,blockIndex:b.blockIndex,blocks:b.preset.blocks,remainingSec:z(b,r()),paused:b.pausedAtMs!==null,ambient:$,startedAt:v,updatedAt:r()})}catch{}},q=p=>p<60?`${p}s`:`${Math.round(p/60)} min`,ye=p=>{if(!u)return;let k="",_="";if(p.status==="FOCUS_BLOCK")k=`flowe \xB7 block ${p.blockIndex}/${p.preset.blocks}`,_=`${q(p.preset.focusSec)}. one thing. lock in.`;else if(p.status==="BREAK")k="flowe \xB7 break",_=`${q(p.preset.breakSec)}. stand up. breathe.`;else if(p.status==="LONG_BREAK")k="flowe \xB7 long break",_=`${q(p.preset.longBreakSec)}. walk. eyes off the screen.`;else if(p.status==="CYCLE_DONE")k="flowe \xB7 cycle done",_=`${p.preset.blocks} blocks banked. go ship.`;else return;try{Jo.notify({title:k,message:_,icon:Bn,contentImage:Bn,sound:!0})}catch{}},He=async p=>{if(ye(p),p.status==="FOCUS_BLOCK"?m&&!R&&c&&(R=d(c)):D(),p.status==="BREAK"||p.status==="LONG_BREAK"){let k=p.status==="BREAK"?i:a,_=p.status==="BREAK"?5:15;try{h=await se({type:k,durationMin:_})}catch{h=null}}(p.status==="FOCUS_BLOCK"||p.status==="CYCLE_DONE")&&(h?.cancel(),h=null)},V=async p=>{let k=b,_=Me(k,p);_!==k&&(b=_,L(),Ne(k,_)?await He(_):Or(k,_))},Or=(p,k)=>{let _=p.pausedAtMs!==null,Y=k.pausedAtMs!==null;if(_!==Y&&k.status==="FOCUS_BLOCK"){if(Y){D();return}m&&!R&&c&&(R=d(c))}},X=[],ke=!1,re=null,Ge=()=>{if(re){let p=re;re=null,p.resolve()}},At=p=>{let k=Buffer.isBuffer(p)?p:Buffer.from(p);for(let _ of Q(k))X.push(_);Ge()},Ot=()=>{ke=!0,Ge()},xt=()=>{n.isTTY&&n.setRawMode(!0)};xt(),n.resume(),n.on("data",At),n.once("end",Ot),t.write(ge+he+ue);let Mt=p=>X.length>0||ke?Promise.resolve():new Promise(k=>{let _={resolve:k};re=_,setTimeout(()=>{re===_&&(re=null,k())},p)}),Ye=()=>{h?.cancel(),h=null,D(),S&&(_e(),ve(),S=!1),n.isTTY&&n.setRawMode(!1),n.off("data",At),n.off("end",Ot),n.pause(),process.removeListener("SIGCONT",Bt),t.write(ae+ie)},Nt=()=>{Ye(),process.removeListener("SIGINT",Nt),process.exit(0)};process.on("SIGINT",Nt);let Bt=()=>{xt(),t.write(ue),I=!0,A="",y(!0),Ge()};process.on("SIGCONT",Bt);try{if(E&&b.status==="PRE_FLIGHT"){let p=pe(b,r());p!==b&&(b=p,v=b.enteredAtMs,L(),await He(b))}for(y();b.status==="PRE_FLIGHT";){if(await Mt(6e4),ke&&X.length===0){Ye();return}for(;X.length>0;){let p=X.shift();if(p.name==="ctrl-c"||p.name==="escape"){await V({kind:"QUIT",nowMs:r()});break}if(p.name==="return"){let k=pe(b,r());k!==b&&(b=k,v=b.enteredAtMs,L(),await He(b));break}if(p.name==="char"&&(p.char??"").toLowerCase()==="q"){await V({kind:"QUIT",nowMs:r()});break}}}for(;b.status!=="CYCLE_DONE";){y(),L();let p=!1,k=P&&S?Ie():null;for(k&&(await V(ns(k,r())),k==="quit"&&(p=!0));X.length>0&&!p;){let _=X.shift();if(_.name==="ctrl-c"||_.name==="escape"){await V({kind:"QUIT",nowMs:r()}),p=!0;break}if(_.name==="char"){let Y=(_.char??"").toLowerCase();if(Y===" ")await V(b.pausedAtMs!==null?{kind:"RESUME",nowMs:r()}:{kind:"PAUSE",nowMs:r()});else if(Y==="s")await V({kind:"SKIP",nowMs:r()});else if(Y==="q"||Y==="x"){await V({kind:"QUIT",nowMs:r()}),p=!0;break}}}if(p){y();break}if(b.status==="CYCLE_DONE")break;if(ke){await V({kind:"QUIT",nowMs:r()});continue}await Mt(Zo),await V({kind:"TICK",nowMs:r()})}y()}finally{Ye()}}import rs from"node-notifier";import{fileURLToPath as os}from"url";import{dirname as ss,join as is}from"path";var as=100,us="quick_reset",cs="executive_reset",qn=is(ss(os(import.meta.url)),"..","assets/notification-icon.png");function ls(e,t){switch(e){case"pause":return{kind:"PAUSE",nowMs:t};case"resume":return{kind:"RESUME",nowMs:t};case"skip":return{kind:"SKIP",nowMs:t};case"quit":return{kind:"QUIT",nowMs:t}}}function ds(e,t){return{version:1,pid:t.pid,status:e.status,preset:t.preset,blockIndex:e.blockIndex,blocks:e.preset.blocks,remainingSec:z(e,t.nowMs),paused:e.pausedAtMs!==null,ambient:t.ambientId,startedAt:t.startedAtMs,updatedAt:t.nowMs}}function fs(e,t){if(!t)return;let n="",r="";if(e.status==="FOCUS_BLOCK")n="flowe \xB7 deep work",r=`block ${e.blockIndex} of ${e.preset.blocks} started`;else if(e.status==="BREAK")n="flowe \xB7 break",r=`${Math.round(e.preset.breakSec/60)} min \xB7 breathe`;else if(e.status==="LONG_BREAK")n="flowe \xB7 long break",r=`${Math.round(e.preset.longBreakSec/60)} min \xB7 long rest`;else if(e.status==="CYCLE_DONE")n="flowe \xB7 cycle complete",r=`${e.preset.blocks} blocks \xB7 nice work`;else return;try{rs.notify({title:n,message:r,icon:qn,contentImage:qn,sound:!0})}catch{}}var ms=e=>new Promise(t=>setTimeout(t,e));async function Hn(e){let t=U[e.preset],n=e.preset,r=e.now??Date.now,o=e.tickMs??as,s=e.breakType??us,i=e.longBreakType??cs,a=e.notifications??!0,u=e.startAmbient??oe,c=e.runBreak??se,m=e.consumeControl??Ie,d=e.pidOverride??process.pid,w=e.ambientId??null,E=e.ambientFilePath,P=Re({pidOverride:d});if(P.kind==="busy")return{finalStatus:"PRE_FLIGHT",ticks:0,reason:"busy",busyPid:P.pid};let $=pe(Oe(t,r()),r()),g=$.enteredAtMs,S=null,b=null,v=()=>{b?.stop(),b=null},h=()=>{let y=ds($,{pid:d,preset:n,ambientId:w,startedAtMs:g,nowMs:r()});try{Ee(y)}catch{}},R=async y=>{if(fs(y,a),y.status==="FOCUS_BLOCK"?E&&!b&&(b=u(E)):v(),y.status==="BREAK"||y.status==="LONG_BREAK"){let L=y.status==="BREAK"?s:i,q=y.status==="BREAK"?5:15;try{S=await c({type:L,durationMin:q})}catch{S=null}}(y.status==="FOCUS_BLOCK"||y.status==="CYCLE_DONE")&&(S?.cancel(),S=null)},D=(y,L)=>{let q=y.pausedAtMs!==null,ye=L.pausedAtMs!==null;if(q!==ye&&L.status==="FOCUS_BLOCK"){if(ye){v();return}E&&!b&&(b=u(E))}},F=async y=>{let L=$,q=Me(L,y);q!==L&&($=q,Ne(L,q)?await R(q):D(L,q))};await R($),h();let I=0,A="cycle_done",j=e.maxTicks??Number.POSITIVE_INFINITY;try{for(;$.status!=="CYCLE_DONE"&&I<j;){let y=m();if(y!==null&&(await F(ls(y,r())),y==="quit")){A="quit";break}if($.status==="CYCLE_DONE")break;await ms(o),await F({kind:"TICK",nowMs:r()}),h(),I+=1}I>=j&&$.status!=="CYCLE_DONE"&&(A="max_ticks")}finally{v(),S?.cancel(),S=null,h(),_e(),$.status==="CYCLE_DONE"&&ve()}return{finalStatus:$.status,ticks:I,reason:A}}var ps="\x1B[?1049h",bs="\x1B[?1049l",gs="\x1B[?25l",hs="\x1B[?25h",ws="\x1B[H",Ss=e=>`\x1B[${e}A`,ys="\x1B[2K",ks=250;function Cs(e,t){let n=U[e.preset],r=Yn(e.status,n),s=Math.max(0,r-e.remainingSec)*1e3;return e.paused?{status:e.status,blockIndex:e.blockIndex,enteredAtMs:t-s,pausedAtMs:t,pausedDurationMs:0,preset:n}:{status:e.status,blockIndex:e.blockIndex,enteredAtMs:t-s,pausedAtMs:null,pausedDurationMs:0,preset:n}}function Yn(e,t){switch(e){case"FOCUS_BLOCK":return t.focusSec;case"TRANSITION":return me;case"BREAK":return t.breakSec;case"LONG_BREAK":return t.longBreakSec;default:return 0}}function Es(e,t){if(e.name==="ctrl-c")return"detach";if(e.name==="char"){let n=(e.char??"").toLowerCase();if(n===" ")return t?"resume":"pause";if(n==="s")return"skip";if(n==="q"||n==="x")return"quit";if(n==="d")return"detach"}return null}var vs=e=>new Promise(t=>setTimeout(t,e));function Rs(){return["no active focus session.","","start one: flowe focus","or detached: flowe focus --detach"].join(`
11
- `)}function Vn(e){let t=Yn(e.status,U[e.preset]);return[`flowe \xB7 ${e.preset} \xB7 ${e.status.toLowerCase()}`,`block ${e.blockIndex} / ${e.blocks}`,`remaining ${Gn(e.remainingSec)}${t?` of ${Gn(t)}`:""}`,`paused ${e.paused?"yes":"no"}`,`ambient ${e.ambient??"(none)"}`,`pid ${e.pid}`].join(`
12
- `)}function Gn(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/60),r=t%60;return`${n}:${r.toString().padStart(2,"0")}`}async function Wn(e={}){let t=e.out??process.stdout,n=e.stdin??process.stdin,r=e.now??Date.now,o=e.pollMs??ks,s=e.readState??fe,i=e.sendControl??$e,a=e.maxPolls??Number.POSITIVE_INFINITY,u=s();if(u===null)return t.write(`${Rs()}
13
- `),{reason:"no_session"};let c=[],m=!1,d=null,w=()=>{if(d){let I=d;d=null,I.resolve()}},E=I=>{let A=Buffer.isBuffer(I)?I:Buffer.from(I);for(let j of Q(A))c.push(j);w()},P=()=>{m=!0,w()};n.isTTY&&n.setRawMode(!0),n.resume(),n.on("data",E),n.once("end",P),t.write(ps+ws+gs);let $=!0,g=u.preset,S=De(U[g]),b=I=>{let A="";$||(A+=Ss(S));for(let j of I)A+=`\r${ys}${j}
14
- `;t.write(A),$=!1},v=I=>{let A=r(),j=Cs(I,A),y=Be({state:j,presetName:I.preset,elapsedMs:A-j.enteredAtMs,nowMs:A,paused:I.paused});b(y)},h=()=>{n.isTTY&&n.setRawMode(!1),n.off("data",E),n.off("end",P),n.pause(),t.write(hs+bs)},R=()=>{h(),process.removeListener("SIGINT",R),process.exit(0)};process.on("SIGINT",R);let D=0,F="cycle_done";try{let I=u;for(v(I);D<a;){let A=!1;for(;c.length>0;){let j=c.shift(),y=Es(j,I?.paused??!1);if(y!==null){if(y==="detach"){F="detached",A=!0;break}try{i(y)}catch{}y==="quit"&&(F="quit")}}if(A)break;if(m&&c.length===0){F="detached";break}if(await vs(o),D+=1,I=s(),I===null){F=F==="quit"?"quit":"no_session";break}if(v(I),I.status==="CYCLE_DONE"){F=F==="quit"?"quit":"cycle_done";break}}}finally{process.removeListener("SIGINT",R),h()}return{reason:F}}import{readFileSync as _s}from"fs";import{dirname as $s,join as Is}from"path";import{fileURLToPath as Ps}from"url";function Qn(e,t){return e===null||e.status==="CYCLE_DONE"?As(t):Ts(e,t)}function Ts(e,t){let n=Jn(e.remainingSec),r=U[e.preset],o=Ds(e.status,r),s=[];return s.push(Os(e,n)),s.push("---"),s.push(`flowe \xB7 ${e.preset} \xB7 ${Ns(e.status)}`),s.push(`block ${e.blockIndex} / ${e.blocks} | font=Menlo`),s.push(`remaining ${n}${o?` of ${Jn(o)}`:""} | font=Menlo`),s.push(`ambient ${e.ambient??"(none)"} | font=Menlo`),s.push(`paused ${e.paused?"yes":"no"} | font=Menlo`),s.push("---"),e.paused?s.push(Ue("Resume","resume",t)):s.push(Ue("Pause","pause",t)),s.push(Ue("Skip block","skip",t)),s.push(Ue("Quit cycle","quit",t)),s.push("---"),s.push(`Open status in terminal | ${Se(t,["focus","status"])} terminal=true`),s.join(`
15
- `)}function As(e){return[xs(),"---","no active focus session | color=#8c8c8c size=11","---",`Start pomodoro | ${Se(e,["focus","pomodoro","--detach","--ambient","none"])} terminal=false refresh=true sfimage=play.circle.fill`,`Start dev | ${Se(e,["focus","dev","--detach","--ambient","none"])} terminal=false refresh=true sfimage=play.circle.fill`,`Start ultradian | ${Se(e,["focus","ultradian","--detach","--ambient","none"])} terminal=false refresh=true sfimage=play.circle.fill`].join(`
16
- `)}function Os(e,t){let n=e.paused?`\u23F8 ${t}`:t;return zn(n,{dim:e.paused})}function xs(){return zn("flowe",{dim:!0})}function zn(e,t){let n=[],r=Ms();return r&&n.push(`image=${r}`),t.dim&&n.push("color=#8c8c8c"),n.length?`${e} | ${n.join(" ")}`:e}var we=null;function Ms(){if(we!==null)return we;try{let e=$s(Ps(import.meta.url));we=_s(Is(e,"..","assets/menubar-icon.png")).toString("base64")}catch{we=""}return we}function Ns(e){switch(e){case"FOCUS_BLOCK":return"focus";case"TRANSITION":return"transition";case"BREAK":return"break";case"LONG_BREAK":return"long break";case"CYCLE_DONE":return"done";case"PRE_FLIGHT":return"starting"}}function Ue(e,t,n){let r=Bs(t),o=r?` sfimage=${r}`:"";return`${e} | ${Se(n,["focus",t])} terminal=false refresh=true${o}`}function Bs(e){switch(e){case"pause":return"pause.fill";case"resume":return"play.fill";case"skip":return"forward.fill";case"quit":return"stop.fill";default:return""}}function Se(e,t){let n=e.floweBinary,r=e.nodeBinary;if(r){let s=[n,...t].map((i,a)=>`param${a+1}=${i}`).join(" ");return`bash=${r} ${s}`}let o=t.map((s,i)=>`param${i+1}=${s}`).join(" ");return`bash=${n} ${o}`}function Ds(e,t){switch(e){case"FOCUS_BLOCK":return t.focusSec;case"TRANSITION":return me;case"BREAK":return t.breakSec;case"LONG_BREAK":return t.longBreakSec;default:return 0}}function Jn(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/60),r=t%60;return`${n}:${r.toString().padStart(2,"0")}`}import{chmodSync as Fs,existsSync as kt,mkdirSync as Ls,readFileSync as Ks,rmSync as Us,statSync as Za,writeFileSync as js}from"fs";import{homedir as Ct}from"os";import{dirname as qs,join as ce,resolve as Hs}from"path";import{fileURLToPath as Gs}from"url";import{execFileSync as Xn,spawnSync as ne}from"child_process";var Et="flowe.1s.sh";function Ys(){return ce(Ct(),"Library","Application Support","SwiftBar","Plugins")}function vt(){try{let t=Xn("/usr/bin/defaults",["read","com.ameba.SwiftBar","PluginDirectory"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim();return t.length>0?t:null}catch{return null}}var Vs=["Documents","Desktop","Downloads","Library/Mobile Documents"];function Ws(e,t=Ct()){if(!e.startsWith(`${t}/`))return!1;let n=e.slice(t.length+1);return Vs.some(r=>n===r||n.startsWith(`${r}/`))}function Zn(e){if(e?.override)return e.override;let t=(e?.readPref??vt)(),n=e?.isRestricted??Ws;return t&&!n(t)?t:Ys()}function er(e){return ne("/usr/bin/defaults",["write","com.ameba.SwiftBar","PluginDirectory",e],{stdio:"ignore"}).status===0}function tr(){ne("/usr/bin/killall",["SwiftBar"],{stdio:"ignore"}),ne("/usr/bin/open",["-a","SwiftBar"],{stdio:"ignore"})}function Js(){return ce(nr(),"bin","menubar",Et)}function nr(){let e=Gs(import.meta.url);return Hs(qs(e),"..")}function rr(){return ce(nr(),"bin","flowe.js")}function or(){try{let t=Xn("/usr/bin/which",["flowe"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim();return t.length>0?t:null}catch{return null}}function Qs(e,t){let n=/^FLOWE_BIN="\$\{FLOWE_BIN:-\}"$/m;if(!n.test(e))throw new Error('plugin template is missing the FLOWE_BIN="${FLOWE_BIN:-}" placeholder');let r=/^NODE_BIN="\$\{NODE_BIN:-\}"$/m;if(!r.test(e))throw new Error('plugin template is missing the NODE_BIN="${NODE_BIN:-}" placeholder');let o=t.floweBin.replace(/"/g,'\\"'),s=(t.nodeBin??"").replace(/"/g,'\\"');return e.replace(n,`FLOWE_BIN="${o}"`).replace(r,`NODE_BIN="${s}"`)}function sr(e){let t=Zn({override:e.pluginDir}),n=ce(t,Et),r=e.templatePath??Js();if(!kt(r))throw new Error(`plugin template not found at ${r}`);let o=Ks(r,"utf-8"),s=Qs(o,{floweBin:e.floweBin,nodeBin:e.nodeBin??process.execPath});return e.dryRun?{pluginPath:n,scriptContent:s,written:!1}:(Ls(t,{recursive:!0}),js(n,s,"utf-8"),Fs(n,493),{pluginPath:n,scriptContent:s,written:!0})}function ir(e={}){let t=Zn({override:e.pluginDir}),n=ce(t,Et),r=kt(n);return r&&Us(n),{pluginPath:n,existed:r}}function ar(e){return[`installed \u2192 ${e.pluginPath}`,"","next steps:"," 1. open SwiftBar (brew install --cask swiftbar if not installed)"," 2. start a focus cycle: flowe focus pomodoro --detach"," 3. the menubar will refresh once a second with status + controls","","remove with: flowe uninstall-menubar"].join(`
17
- `)}function zs(){return["/Applications/SwiftBar.app",ce(Ct(),"Applications","SwiftBar.app")]}function Xs(){return zs().some(e=>kt(e))}function Zs(){return ne("/usr/bin/which",["brew"],{stdio:"ignore"}).status===0}function ei(){let e=ne("brew",["install","--cask","swiftbar"],{stdio:"inherit"});if(e.status!==0)throw new Error(`brew install --cask swiftbar failed (exit ${e.status??"null"})`)}function ur(e={}){let t=e.isInstalled??Xs,n=e.hasBrew??Zs,r=e.install??ei;if(t())return{action:"present"};if(!n())return{action:"missing-brew"};if(r(),!t())throw new Error("brew exited 0 but SwiftBar.app was not found in /Applications.");return{action:"installed"}}function cr(){return["SwiftBar is not installed, and brew is not available either.","","install Homebrew first: https://brew.sh","then re-run: flowe install-menubar","","or skip the dependency check and install just the plugin:"," flowe install-menubar --skip-swiftbar-check","","or download SwiftBar manually: https://github.com/swiftbar/SwiftBar/releases"].join(`
18
- `)}function lr(){ne("/usr/bin/open",["-a","SwiftBar"],{stdio:"ignore"})}function dr(){return ne("/usr/bin/pgrep",["-x","SwiftBar"],{stdio:"ignore"}).status===0}function fr(e){return e.existed?`removed \u2192 ${e.pluginPath}`:`nothing to remove (no plugin at ${e.pluginPath})`}var ti=["focus","deep_work","settle","sleep"],ni={focus:{label:"Focus",defaultScene:"rain_window_soft",defaultMinutes:null,modulation:"balanced",description:"balanced texture for ordinary attention"},deep_work:{label:"Deep Work",defaultScene:"nature_mountain_wind",defaultMinutes:90,modulation:"strong",description:"fewer shifts for sustained demanding work"},settle:{label:"Settle",defaultScene:"interiors_fireplace",defaultMinutes:10,modulation:"gentle",description:"slower texture for releasing activation"},sleep:{label:"Sleep",defaultScene:"tones_deep_brown_noise",defaultMinutes:30,modulation:"low",description:"dark sparse texture for easing toward sleep"}};function je(e){return ni[e]}function mr(e){let t=(e??"focus").trim().toLowerCase().replace(/[ -]+/g,"_");if(ti.includes(t))return t;throw new Error("intent must be one of: focus, deep-work, settle, sleep")}function pr(e){if(e===void 0)return;let t=e.trim().toLowerCase();if(t==="infinite"||t==="inf"||t==="\u221E")return null;let n=t.match(/^(\d+(?:\.\d+)?)(m|min|h|hr)?$/);if(!n)throw new Error("duration must look like 25m, 90m, 1h, or infinite");let r=Number(n[1]),o=n[2]?.startsWith("h")?r*60:r;if(!Number.isFinite(o)||o<=0||o>720)throw new Error("duration must be between 1 minute and 12 hours");return Math.round(o)}function br(e,t,n){if(n)return e.find(o=>o.id===n)??null;let r=je(t);return e.find(o=>o.id===r.defaultScene)??e[0]??null}function gr(e){switch(e){case"gentle":case"low":return .6;case"strong":return 1.2;case"balanced":return 1}}function Rt(e,t,n){let r=je(e),o=t===null?"infinite":`${t}m`;return[` FLOWESCAPE ${r.label}`,` ${r.description}`,` scene ${n}`,` neural ${r.modulation}`,` timer ${o}`," controls Ctrl-C to stop"].join(`
19
- `)}function ri(e){return new URL("/api/v1/cli/ambient/custom",e).toString()}function le(e,t){return Object.assign(new Error(e),{code:t})}async function hr(e){try{let t=await e.json();return typeof t.error=="string"?t.message??t.error:t.error?.message??t.message??`request failed: ${e.status}`}catch{return`request failed: ${e.status}`}}async function wr(e){let t=e.prompt.trim();if(t.length<10)throw le("prompt must be at least 10 characters","invalid_duration");let n=await W();if(!n)throw le("sign in with: flowe login","auth_required");let o=await(e.fetchFn??fetch)(ri(G().backend_url),{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify({prompt:t,name:e.name})});if(o.status===401)throw le("sign in with: flowe login","auth_required");if(o.status===403)throw le(await hr(o),"agent_busy");if(!o.ok)throw le(await hr(o),"network_error");let s=new Uint8Array(await o.arrayBuffer());if(s.byteLength===0)throw le("ambient generation returned empty audio","network_error");let i=o.headers.get("X-Flowe-Ambient-Name");return{sound:Wt({name:e.name??i??"custom ambience",prompt:t,bytes:s})}}import{readFileSync as oi}from"fs";import{dirname as si,join as ii}from"path";import{fileURLToPath as ai}from"url";var ui=si(ai(import.meta.url));function ci(){try{let e=oi(ii(ui,"..","package.json"),"utf-8");return JSON.parse(e).version}catch{return"0.0.0"}}var _t=[" \u2572\u2502\u2571 "," \u2500\u2500\u2740\u2500\u2500"," \u2571\u2502\u2572 "];function Sr(){let e=ci();return[f(_t[0]),`${f(_t[1])} ${M("flowe")} ${l(`v${e}`)}`,`${f(_t[2])} ${an("neural reset for AI-paired engineers")}`].join(`
20
- `)}var yr=["Most fatigue is unfinished arousal.","Calm is a learnable skill.","The exhale is where the parasympathetic switches on.","If you don't pause, your body picks the moment for you.","Rest is a posture you practice, not a place you go.","You can think yourself into anxiety. Breath is the way back.","Stillness is not a reward. It's a tool.","The shortest path to your next deep-work session is one slow exhale.","Recovery is a feature, not an absence of work.","Discomfort is data. So is calm.","Sixty seconds well spent beats six hours fighting yourself.","Your nervous system runs the show. Be a good operator.","The body is not the enemy of focus. It's the substrate.","There is no app version of slowing down.","You don't ship better code by gripping harder.","Breathe in for what is. Out for what was.","The vagus nerve doesn't care how busy your calendar is.","Forty-five seconds. Then back to the work.","The interval between thoughts is where insight lives.","The breath is the only autonomic system you can drive."];function kr(e){let t=Number.isFinite(e)?Math.max(0,Math.floor(e)):0;return yr[t%yr.length]}var Cr=60,li=28,di=18;function de(e,t){return` ${l(e.padEnd(di))} ${t}`}function Er(e,t,n){return`${e} ${e===1?t:n}`}function fi(e){let t=` ${M("\u2740")} ${C("SUMMARY_REPORT")}`,n=de("PROTOCOL",f(e.protocolDisplayName)),r=de("DURATION",f(`${e.duration}s`)),o=de("GUIDE",f(e.voice)),s=e.rounds!=null?de("ROUNDS",f(String(e.rounds))):null,i=de("TODAY",f(Er(e.sessionsToday,"session","sessions"))),a=e.streakDays!=null?de("STREAK",f(Er(e.streakDays,"day","days"))):null,u=f("\u2588".repeat(li)),c=` ${l("INTEGRATION_SYNC")} [${u}] ${f("100%")}`,m=kr(e.totalSessions),d=N(l(`"${m}"`),Cr);return K(["",t,"",n,r,o,s,"",i,a,"",c,"",d,""].filter(E=>E!==null),Cr)}function vr(e,t=process.stdout){let n=fi(e);for(let r of n)t.write(r+`
21
- `);return n.length}function mi(){let e=M("\u25C6"),t=`[${f("r")}] repeat`,n=`[${f("n")}] new session`,r=`[${f("x")}] exit`;return` ${e} ${t} ${l("\xB7")} ${n} ${l("\xB7")} ${r}`}var Rr=2;async function _r(e){e.setRawMode?.(!0),e.out.write(`
22
- `+mi()+`
23
- `);try{for(;;){let t=await e.keys.next();if(t.done)return"exit";let n=t.value;if(n.name==="ctrl-c"||n.name==="escape")return"exit";if(n.name==="char"){let r=(n.char??"").toLowerCase();if(r==="r")return"repeat";if(r==="n")return"new";if(r==="x"||r==="q")return"exit"}}}finally{e.setRawMode?.(!1),await e.keys.return?.()}}function $r(){let e=process.stdin;return{out:process.stdout,setRawMode:n=>{e.isTTY&&e.setRawMode(n)},keys:pi(e)}}function pi(e){e.resume();let t=[],n=[],r=!1,o=i=>{let a=Buffer.isBuffer(i)?i:Buffer.from(i),u=Q(a);for(let c of u){let m=n.shift();m?m(c):t.push(c)}},s=()=>{for(r=!0;n.length;)n.shift()(null)};return e.on("data",o),e.once("end",s),{async next(){return t.length?{value:t.shift(),done:!1}:r?{value:void 0,done:!0}:new Promise(i=>{n.push(a=>{i(a===null?{value:void 0,done:!0}:{value:a,done:!1})})})},async return(){return e.off("data",o),e.off("end",s),e.pause(),{value:void 0,done:!0}}}}import{existsSync as bi,mkdirSync as gi,writeFileSync as hi}from"fs";import{homedir as wi,platform as Si}from"os";import{join as qe}from"path";var Ir="welcomed";function $t(){let e=wi();return Si()==="win32"?qe(e,"AppData","Roaming","flowe"):qe(e,".config","flowe")}function yi(){return["","flowe-cli installed.","","Try it:"," flowe reset interactive picker (pick duration + protocol)"," flowe reset 60 quick 60-second reset, random protocol"," flowe protocols list all 12 protocols","","Docs: https://cli.flowe.ai/docs/",""].join(`
24
- `)}function ki(e=$t()){return bi(qe(e,Ir))}function Ci(e=$t()){gi(e,{recursive:!0}),hi(qe(e,Ir),"","utf-8")}function Pr(e=process.stderr){try{let t=$t();if(ki(t))return;e.write(yi()),Ci(t)}catch{}}var Tr=e=>`\x1B[${e}A`,Ri="\x1B[2K";function _i(e,t){if(t<=0)return;let n=Tr(t);for(let r=0;r<t;r++)n+=`\r${Ri}
25
- `;n+=Tr(t),e.write(n)}function $i(e){switch(e){case"auth_required":return 2;case"agent_busy":return 3;case"network_error":case"offline":return 4;default:return 1}}function H(e){let t=e,n=t?.message||String(e);process.stderr.write(`flowe: ${n}
26
- `),process.exit($i(t?.code))}function Ii(e){return Array.isArray(e)?e.join(" ").trim():(e??"").trim()}function Tt(e){let t=typeof e=="number"?e:parseInt(e,10);if(t===30||t===45||t===60||t===90)return t;throw Object.assign(new Error("duration must be 30, 45, 60, or 90"),{code:"invalid_duration"})}function It(e){if(Ve.includes(e))return e;throw Object.assign(new Error(`type must be one of: ${Ve.join(", ")}`),{code:"invalid_duration"})}function Pi(e){if(We.includes(e))return e;throw Object.assign(new Error(`type must be one of: ${We.join(", ")}`),{code:"invalid_duration"})}function Pt(e){if(e==="sage"||e==="ada"||e==="ellie")return e;throw Object.assign(new Error("voice must be sage, ada, or ellie"),{code:"invalid_duration"})}function Ti(e){let t=jt();if(t.includes(e))return e;throw Object.assign(new Error(`unknown protocol "${e}" \u2014 available: ${t.join(", ")}`),{code:"invalid_duration"})}async function Ai(e=2e3){let t=et().catch(()=>null),n=new Promise(r=>setTimeout(()=>r(null),e));return Promise.race([t,n])}async function Ar(e,t){let n=G(),r=await W();r&&!n.user_first_name&&(await Ai(),n=G());let o=un(n.user_first_name),s=60;if(e)try{s=Tt(e)}catch{}let i=t?ze(t):void 0,a=await ln({defaultDuration:s,defaultVoice:n.voice,greeting:o,showAuthWedge:!r,availableDurations:i,signIn:async()=>{let{runLogin:u}=await import("./login-Q4QMATEN.js");await u(),await et()},clearOnExit:!0});return a?{duration:a.duration,voice:a.voice,family:t}:null}async function Oi(e,t){if(t){let r=ze(t);if(e===void 0&&r.length===1)return{duration:r[0],family:t};if(e===void 0)throw Object.assign(new Error(`protocol "${t}" supports multiple durations (${r.join(", ")}s) \u2014 pass one as: flowe reset <duration> --protocol ${t}`),{code:"invalid_duration"});let o=Tt(e);if(!r.includes(o))throw Object.assign(new Error(`protocol "${t}" has no ${o}s variant \u2014 available: ${r.join(", ")}s`),{code:"invalid_duration"});return{duration:o,family:t}}return{duration:Tt(e??60)}}async function xi(){if(tn()){let t=en(),n=await Hn({preset:t.preset,ambientFilePath:t.ambientFilePath,ambientId:t.ambientId??null,breakType:t.breakType,longBreakType:t.longBreakType,notifications:process.env.FLOWE_FOCUS_NO_NOTIFICATIONS!=="1"});process.exit(n.reason==="busy"?1:0)}process.argv[2]!=="mcp"&&Pr();let e=Ei("flowe");e.command("reset [duration]","Run a micro-reset (30, 45, 60, or 90 seconds)").option("--trigger <trigger>","why this reset fired",{default:"user_requested"}).option("-q, --quick","skip the interactive picker and run with the given duration").option("--protocol <family>","restrict to a specific protocol family (e.g., physiological_sigh, box_breath)").action(async(t,n)=>{try{let r=n.trigger,o=n.protocol?Ti(n.protocol):void 0,i=!n.quick&&dn()?await Ar(t,o):await Oi(t,o);if(!i)return;for(;;){i.voice&&Je(i.voice);let a=await Yt(i.duration,r,i.family),u=Xe();if(En()&&u){await Cn({duration:a.duration_seconds,voice:a.voice,displayName:a.protocol_display_name,cues:a.cues,rounds:a.rounds,donePromise:u}),Qe();let c=vr({protocolDisplayName:a.protocol_display_name,duration:a.duration_seconds,voice:a.voice,rounds:a.rounds,sessionsToday:Ft(),totalSessions:Kt(),streakDays:Lt()});if(n.quick)return;let m=await _r($r());if(m==="exit")return;if(_i(process.stdout,c+Rr),m==="repeat")continue;if(m==="new"){let d=await Ar(void 0,i.family);if(!d)return;i=d;continue}return}process.stdout.write(`${a.message_for_user}
1
+ import{a as Dt,b as We,c as Je,d as Ut,e as jt,f as Xe,g as Ze,h as qt,i as Ht,l as Yt,n as _e,o as pe,p as Re,q as ve,r as Ie,s as $e,t as Oe,u as Xt,v as Zt,w as en,x as tn,y as nn}from"./chunk-GUTZZ5P5.js";import{d as Vt,g as Wt,h as Jt,i as et,j as Ee,k as se,l as Qt,m as zt}from"./chunk-3TLGYA6M.js";import{b as tt}from"./chunk-3HG2U5YK.js";import{a as q,b as Qe,e as ze,f as Lt,g as Ft,h as Kt,i as V,k as Gt}from"./chunk-EC5WRPZP.js";import{cac as Oi}from"cac";import{existsSync as Pi}from"fs";import Nr from"qrcode-terminal";async function rn(e="quick_reset",t={}){let n=q(),r=await V();if(!r)throw Object.assign(new Error("sign in with: flowe login"),{code:"auth_required"});let o;try{o=await fetch(`${n.backend_url}/api/v1/sessions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({protocolId:"nsdr",sessionType:e})})}catch{throw Object.assign(new Error("network unreachable \u2014 try: flowe reset"),{code:"network_error"})}if(!o.ok)throw o.status===401?Object.assign(new Error("session expired \u2014 run: flowe login"),{code:"auth_required"}):Object.assign(new Error(`server error ${o.status}`),{code:"network_error"});let s=await o.json(),i=`flowe://session/${s.session_id}`;return!t.suppressQr&&process.stdout.isTTY&&Nr.generate(i,{small:!0}),{session_id:s.session_id,session_type:s.session_type,session_type_name:s.session_type_name,estimated_duration:s.estimated_duration,join_url:i,status:"waiting_for_join",message_for_user:`${s.session_type_name} (${s.estimated_duration}min) ready \xB7 ${i}`}}import{createWriteStream as Br}from"fs";import{mkdtemp as Dr,rm as Lr}from"fs/promises";import{tmpdir as Fr}from"os";import{join as on}from"path";import{pipeline as Kr}from"stream/promises";import{Readable as Ur}from"stream";async function sn(e){let t=await Dr(on(Fr(),"flowe-stream-")),n=on(t,"audio.mp3"),r=async()=>{try{await Lr(t,{recursive:!0,force:!0})}catch{}};try{let o=await fetch(e.url,{headers:e.headers,signal:e.signal});if(o.status===401)throw Object.assign(new Error("login required \u2014 run: flowe login"),{code:"auth_required"});if(o.status===404)throw Object.assign(new Error("session type not available on server"),{code:"protocol_unavailable"});if(!o.ok)throw Object.assign(new Error(`stream failed: ${o.status} ${o.statusText}`),{code:"network_error"});if(!o.body)throw Object.assign(new Error("empty response body"),{code:"network_error"});let s=(()=>{let l=o.headers.get("content-length");return l?parseInt(l,10):null})(),i=(()=>{let d=o.headers.get("cache-control")?.match(/max-age=(\d+)/);return d?parseInt(d[1],10):null})(),a=0,u=Ur.fromWeb(o.body),c=Br(n);return u.on("data",l=>{a+=l.length,e.onProgress?.(a,s)}),await Kr(u,c),{filePath:n,cleanup:r,bytes:a,cacheMaxAge:i}}catch(o){throw await r(),o}}function jr(e,t,n,r){let o=new URL(`/api/v1/nsdr/sessions/${t}/stream`,e);return o.searchParams.set("duration",String(n)),o.searchParams.set("voice",r),o.toString()}async function ie(e){let t=q(),n=await V();if(!n)throw Object.assign(new Error("sign in with: flowe login"),{code:"auth_required"});let r=e.durationMin??5,o=e.voice??t.voice,s=jr(t.backend_url,e.type,r,o),i;if(process.stdout.isTTY){let l=-1;i=(d,w)=>{if(!w){process.stdout.write(`\r fetching ${e.type}\u2026 ${d} bytes`);return}let S=Math.floor(d/w*100);S!==l&&(l=S,process.stdout.write(`\r fetching ${e.type}\u2026 ${S}%`))}}let a=await sn({url:s,headers:{Authorization:`Bearer ${n}`},signal:e.signal,onProgress:i});process.stdout.isTTY&&process.stdout.write("\r\x1B[2K");let c=qt(a.filePath).finally(()=>a.cleanup());return{started_at:new Date().toISOString(),type:e.type,voice:o,durationMin:r,finished:c,cancel:()=>Ht()}}import ts from"node-notifier";import{fileURLToPath as ns}from"url";import{dirname as rs,join as os}from"path";var nt="\x1B[0m",qr="\x1B[1m",Hr="\x1B[2m",rt={oak:{r:212,g:165,b:116},oakDeep:{r:184,g:145,b:95},sage:{r:124,g:154,b:142},dusk:{r:139,g:123,b:164},duskLight:{r:185,g:163,b:204},duskDeep:{r:110,g:97,b:137},charcoal:{r:45,g:45,b:45}};function ot(){return process.env.NO_COLOR?!1:process.env.FORCE_COLOR?!0:!!process.stdout.isTTY}function st(e,t){return ot()?`\x1B[38;2;${e.r};${e.g};${e.b}m${t}${nt}`:t}var m=e=>st(rt.oak,e),N=e=>st(rt.oakDeep,e),an=e=>st(rt.sage,e);var f=e=>ot()?`${Hr}${e}${nt}`:e,R=e=>ot()?`${qr}${e}${nt}`:e;var Gr=/\x1b\[[0-9;]*m/g,Q={tl:"\u256D",tr:"\u256E",bl:"\u2570",br:"\u256F",h:"\u2500",v:"\u2502"};function it(e){return e.replace(Gr,"").length}function z(e,t){let n=it(e);return n>=t?e:e+" ".repeat(t-n)}function H(e,t){let n=Q.tl+Q.h.repeat(t+2)+Q.tr,r=Q.bl+Q.h.repeat(t+2)+Q.br;return[n,...e.map(o=>`${Q.v} ${z(o,t)} ${Q.v}`),r]}function F(e,t){let n=it(e);if(n>=t)return e;let r=Math.floor((t-n)/2);return" ".repeat(r)+e}var Yr=54;function ct(e,t=Yr){return H(e,t)}function Vr(e=new Date){let t=e.getHours();return t<5?"Late night":t<12?"Good morning":t<18?"Good afternoon":t<22?"Good evening":"Late night"}function un(e,t=new Date){let n=Vr(t),r=(e??"").trim(),o=r.length>0?r:"there";return`${n}, ${o}.`}function Pe(e,t){let n=t?m("\u25B8 "):" ",r=t?R(m(e.label)):e.label,o=e.detail?" "+f("\xB7 "+e.detail):"";return` ${n}${r}${o}`}function lt(e){let t=m("\u2713"),n=f(e.label.toUpperCase().padEnd(8)),r=m(e.value);return` ${t} ${n} ${r}`}function dt(e){return e.length===0?[]:[...e.map(lt),""]}var cn=" \u2191\u2193 to move \u23CE to select esc to cancel",Wr=" \u2191\u2193 to move \u23CE to select esc to back",ft=[30,45,60,90],Te=[{id:"ellie",description:"warm, even pace"},{id:"sage",description:"grounded, low"},{id:"ada",description:"clear, neutral"}];function Jr(e,t=[]){return ct(["",...dt(t),` ${N("\u25C6")} you're not signed in.`,""," sign in to track your progress, build a streak,"," and personalize your sessions.","",Pe({label:"SIGN IN"},e===0),Pe({label:"MAYBE LATER",detail:"anonymous"},e===1),"",f(cn),""])}function Qr(e,t,n=[],r=ft){return ct(["",...dt(n),` ${t}`," What's the cadence for today?","",...r.map((o,s)=>Pe({label:`${o} seconds`},s===e)),"",f(cn),""])}function zr(e,t=[]){return ct(["",...dt(t)," Pick your guide.","",...Te.map((n,r)=>Pe({label:n.id,detail:n.description},r===e)),"",f(Wr),""])}var xe=e=>`\x1B[${e}A`,ut="\x1B[2K",Xr="\x1B[?25l",Zr="\x1B[?25h";function eo(e,t,n){let r="";n>0&&(r+=xe(n));for(let o of t)r+=`\r${ut}${o}
2
+ `;if(n>t.length){let o=n-t.length;for(let s=0;s<o;s++)r+=`\r${ut}
3
+ `;r+=xe(o)}e.write(r)}function to(e,t=ft){let n=t.indexOf(e);if(n>=0)return n;let r=t.indexOf(60);return r>=0?r:0}function no(e){let t=Te.findIndex(n=>n.id===e);return t>=0?t:0}async function at(e,t,n,r,o,s){let i=n,a=()=>{let u=o(i);eo(e.out,u,t.height),t.height=u.length};for(a();;){let u=await e.keys.next();if(u.done)return{cancel:!0};let c=u.value;if(c.name==="ctrl-c")return{cancel:!0};if(c.name==="escape")return{back:!0};if(c.name==="up"||c.name==="char"&&c.char==="k"){i=(i-1+r)%r,a();continue}if(c.name==="down"||c.name==="tab"||c.name==="char"&&c.char==="j"){i=(i+1)%r,a();continue}if(c.name==="return")return{result:s(i)}}}async function ln(e){let t=e.io??ro();t.setRawMode?.(!0),t.out.write(Xr);let n={height:0};try{let r="already_authed",o=[];if(e.showAuthWedge){let i=await at(t,n,0,2,a=>Jr(a,o),a=>a===0?"signin":"later");if("cancel"in i||"back"in i)return null;i.result==="signin"?(e.signIn&&await e.signIn(),r="signed_in",o.push({label:"auth",value:"signed in"})):(r="maybe_later",o.push({label:"auth",value:"continuing as guest"}))}let s=e.availableDurations?.length?e.availableDurations:ft;for(;;){let i=await at(t,n,to(e.defaultDuration,s),s.length,u=>Qr(u,e.greeting,o,s),u=>s[u]);if("cancel"in i||"back"in i)return null;o.push({label:"cadence",value:`${i.result} seconds`});let a=await at(t,n,no(e.defaultVoice),Te.length,u=>zr(u,o),u=>Te[u].id);if("cancel"in a)return null;if("back"in a){o.pop();continue}return{duration:i.result,voice:a.result,authChoice:r}}}finally{if(t.setRawMode?.(!1),t.out.write(Zr),e.clearOnExit&&n.height>0){let r=xe(n.height);for(let o=0;o<n.height;o++)r+=`\r${ut}
4
+ `;r+=xe(n.height),t.out.write(r)}await t.keys.return?.()}}function dn(){return!!process.stdout.isTTY&&!!process.stdin.isTTY&&!process.env.NO_COLOR&&!process.env.CI}function ro(){let e=process.stdin;return{out:process.stdout,setRawMode:n=>{e.isTTY&&e.setRawMode(n)},keys:oo(e)}}function oo(e){e.resume();let t=[],n=[],r=!1,o=i=>{let a=Buffer.isBuffer(i)?i:Buffer.from(i),u=W(a);for(let c of u){let l=n.shift();l?l(c):t.push(c)}},s=()=>{for(r=!0;n.length;)n.shift()(null)};return e.on("data",o),e.once("end",s),{async next(){return t.length?{value:t.shift(),done:!1}:r?{value:void 0,done:!0}:new Promise(i=>{n.push(a=>{i(a===null?{value:void 0,done:!0}:{value:a,done:!1})})})},async return(){return e.off("data",o),e.off("end",s),e.pause(),{value:void 0,done:!0}}}}function W(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r===3){t.push({name:"ctrl-c"}),n+=1;continue}if(r===13||r===10){t.push({name:"return"}),n+=1;continue}if(r===9){t.push({name:"tab"}),n+=1;continue}if(r===27){if(e[n+1]===91){let o=e[n+2];o===65?t.push({name:"up"}):o===66?t.push({name:"down"}):t.push({name:"escape"}),n+=3;continue}t.push({name:"escape"}),n+=1;continue}if(r>=32&&r<127){t.push({name:"char",char:String.fromCharCode(r)}),n+=1;continue}n+=1}return t}var U={pomodoro:{focusSec:1500,breakSec:300,longBreakSec:900,blocks:4},dev:{focusSec:3e3,breakSec:600,longBreakSec:1800,blocks:3},ultradian:{focusSec:5400,breakSec:900,longBreakSec:1800,blocks:2},test2:{focusSec:20,breakSec:20,longBreakSec:50,blocks:2},test5:{focusSec:90,breakSec:30,longBreakSec:80,blocks:2}},be=5;function Ae(e,t){return{status:"PRE_FLIGHT",blockIndex:0,enteredAtMs:t,pausedAtMs:null,pausedDurationMs:0,preset:e}}function ge(e,t){return e.status!=="PRE_FLIGHT"?e:{...e,status:"FOCUS_BLOCK",blockIndex:1,enteredAtMs:t,pausedAtMs:null,pausedDurationMs:0}}function so(e,t){let n=t-e.enteredAtMs;return e.pausedAtMs!==null?e.pausedAtMs-e.enteredAtMs-e.pausedDurationMs:n-e.pausedDurationMs}function Me(e){switch(e.status){case"FOCUS_BLOCK":return e.preset.focusSec;case"TRANSITION":return be;case"BREAK":return e.preset.breakSec;case"LONG_BREAK":return e.preset.longBreakSec;default:return 0}}function J(e,t){let n=Me(e),r=Math.floor(so(e,t)/1e3);return Math.max(0,n-r)}function fn(e,t,n){return{...e,status:t,blockIndex:t==="FOCUS_BLOCK"?e.blockIndex+1:e.blockIndex,enteredAtMs:n,pausedAtMs:null,pausedDurationMs:0}}function mn(e){switch(e.status){case"FOCUS_BLOCK":return"TRANSITION";case"TRANSITION":return e.blockIndex>=e.preset.blocks?"LONG_BREAK":"BREAK";case"BREAK":return"FOCUS_BLOCK";case"LONG_BREAK":return"CYCLE_DONE";default:return e.status}}function Ne(e,t){switch(t.kind){case"PAUSE":return e.pausedAtMs!==null||e.status==="PRE_FLIGHT"||e.status==="CYCLE_DONE"?e:{...e,pausedAtMs:t.nowMs};case"RESUME":{if(e.pausedAtMs===null)return e;let n=t.nowMs-e.pausedAtMs;return{...e,pausedAtMs:null,pausedDurationMs:e.pausedDurationMs+n}}case"SKIP":return e.status!=="FOCUS_BLOCK"&&e.status!=="BREAK"&&e.status!=="LONG_BREAK"&&e.status!=="TRANSITION"?e:fn(e,mn(e),t.nowMs);case"QUIT":return{...e,status:"CYCLE_DONE",enteredAtMs:t.nowMs,pausedAtMs:null};case"TICK":return e.pausedAtMs!==null||e.status==="PRE_FLIGHT"||e.status==="CYCLE_DONE"||J(e,t.nowMs)>0?e:fn(e,mn(e),t.nowMs)}}function Be(e,t){return e.status!==t.status||e.blockIndex!==t.blockIndex}var io=(()=>{let e=[];for(let n=0;n<9;n+=1){let r=(-72+n*18)*Math.PI/180,o=Math.cos(r),s=Math.max(6,Math.round(30*o));for(let i=0;i<s;i+=1){let a=(i+n%2*.5)/s*2*Math.PI,u=e.length,c=Math.abs(Math.sin(u*12.9898+78.233)*43758.5453)%1;e.push({x:o*Math.cos(a),y:Math.sin(r),z:o*Math.sin(a),seed:c})}}return e})(),ao=[[/\bhead\b|forehead/,.84],[/\bjaw\b/,.66],[/shoulder/,.46],[/\bchest\b/,.26],[/stomach|belly/,.06],[/\bhips?\b|\bhands?\b/,-.16],[/\blegs?\b/,-.46],[/\bfeet\b|\bfoot\b|weight/,-.8]];function pn(e){let t=e.label.toLowerCase(),r={dir:0,band:0,double:!1,dim:e.mode==="palming"||/palm|cup over eyes|eye rest|eyes warm/.test(t)};if(e.phase==="inhale"||/\binhale\b/.test(t))return{...r,kind:"inhale",double:/double|top.?up/.test(t)};if(e.phase==="exhale"||/\bexhale\b/.test(t))return{...r,kind:"exhale"};if(e.phase==="hold_in"||e.phase==="hold_out"||/\bhold\b/.test(t))return{...r,kind:"hold"};if(/counter|anti.?clockwise|\bleft\b|\bback\b/.test(t)&&(e.mode==="rotation"||/clockwise|roll/.test(t)))return{...r,kind:"circle",dir:-1};if(/clockwise|\bright\b|forward/.test(t)&&(e.mode==="rotation"||/clockwise|roll/.test(t)))return{...r,kind:"circle",dir:1};if(/\bbreath(e|s)?\b/.test(t))return{...r,kind:"breath"};if(/whole body/.test(t))return{...r,kind:"band",band:Number.NaN};for(let[o,s]of ao)if(o.test(t))return{...r,kind:"band",band:s};return{...r,kind:"rest"}}var Z=e=>.5-.5*Math.cos(Math.PI*Math.max(0,Math.min(1,e)));function mt(e){return .3+.18*(.5-.5*Math.cos(2*Math.PI*e/9e3))}function bn(e,t,n,r){let o=Math.max(1,t.endMs-t.startMs),s=Math.max(0,Math.min(1,(n-t.startMs)/o));switch(e.kind){case"inhale":return e.double?s<.62?r+(.82-r)*Z(s/.62):.82+.18*Z((s-.62)/.38):r+(1-r)*Z(s);case"exhale":return r*(1-Z(s));case"hold":return r;case"breath":return s<.42?r+(.9-r)*Z(s/.42):.9-.75*Z((s-.42)/.58);default:{let i=Z((n-t.startMs)/1200);return r+(mt(n)-r)*i}}}function uo(e,t){if(t.length===0||e<t[0].startMs)return-1;for(let n=0;n<t.length;n+=1)if(e<t[n].endMs)return n;return t.length-1}function co(e,t=[]){let n=uo(e,t);if(n<0)return{fill:mt(e),light:null,turn:1,band:null,dim:!1};let r=mt(t[0].startMs);for(let l=0;l<n;l+=1)r=bn(pn(t[l]),t[l],t[l].endMs,r);let o=t[n],s=pn(o),i=bn(s,o,e,r),a=e<o.endMs,u=s.kind==="circle"&&a?s.dir*2*Math.PI*(e-o.startMs)/3200:null,c=s.kind==="band"&&a?s.band:null;return{fill:i,light:u,turn:s.dir||1,band:c,dim:s.dim&&a}}var lo=[[1,8],[2,16],[4,32],[64,128]];function fo(e){return e>=.8?3:e>=.5?2:e>=.2?1:0}var mo=4;function gn(e,t,n={}){let r=n.width??24,o=n.height??11,s=n.braille??!0,i=Array.from({length:o},()=>new Array(r).fill(0)),a=Array.from({length:o},()=>new Array(r).fill(-1)),u=(l,d,w)=>{let S=Math.floor(l/2),$=Math.floor(d/4);l<0||d<0||S>=r||$>=o||(i[$][S]|=lo[d%4][l%2],w>a[$][S]&&(a[$][S]=w))},c=Math.min(1,Math.max(0,e)/1e3,Math.max(0,t)/1e3);if(c>0){let l=co(e,n.cues??[]),d=r*2,w=o*4,S=(d-1)/2,$=(w-1)/2,C=Math.min(d,w)/2-1,g=C*(.55+(1-.55)*l.fill),k=2*Math.PI*e/26e3,[b,v]=[Math.sin(k),Math.cos(k)],[h,O]=[Math.sin(.42),Math.cos(.42)];io.forEach((P,E)=>{if(P.seed>=c)return;let T=P.x*v+P.z*b,L=-P.x*b+P.z*v,y=P.y*O-L*h,K=P.y*h+L*O;if(K<-.05&&E%mo!==0)return;let M=fo(K);l.band!==null&&(M=Number.isNaN(l.band)||Math.abs(P.y-l.band)<.17?Math.min(3,M+(Number.isNaN(l.band)?1:2)):Math.max(0,M-1)),l.dim&&(M=Math.max(0,M-1)),u(Math.round(S+T*g),Math.round($-y*g),M)});let D=l.light;if(D!==null&&c>=1){let P=Math.min(C+.5,g*1.16);[3,3,3,2,2,1,1,0].forEach((T,L)=>{let y=D-l.turn*L*.13;u(Math.round(S+Math.sin(y)*P),Math.round($-Math.cos(y)*P),T)})}}return i.map((l,d)=>{let w=[];return l.forEach((S,$)=>{let C=S===0?null:a[d][$],g=" ";if(S!==0)if(s)g=String.fromCharCode(10240+S);else{let b=0;for(let v=S;v;v>>=1)b+=v&1;g=b<=2?"\xB7":b<=4?"\u2022":"\u25CF"}let k=w[w.length-1];k&&k.tone===C?k.text+=g:w.push({text:g,tone:C})}),w})}function hn(e,t){return e.FLOWE_ORB==="dots"?!1:e.FLOWE_ORB==="braille"?!0:!(e.TERM==="linux"||t==="win32"&&!e.WT_SESSION&&!e.TERM_PROGRAM)}var go=100;var wn=28;function ho(e,t){if(t.length===0||e<t[0].start_ms)return-1;let n=t.length-1;if(e>=t[n].end_ms)return n;for(let r=0;r<=n;r+=1)if(e<t[r].end_ms)return r;return n}var wo={0:e=>f(N(e)),1:N,2:m,3:m};function So(e){return{label:e.label,startMs:e.start_ms,endMs:e.end_ms,mode:e.mode,phase:e.phase}}function pt(e,t,n=[],r=24,o=11){let s=hn(process.env,process.platform);return gn(e,t,{width:r,height:o,braille:s,cues:n.map(So)}).map(i=>i.map(a=>a.tone===null?a.text:wo[a.tone](a.text)).join(""))}var bt=60;function yo(e){return`${Math.max(0,Math.floor(e))}s`}function ko(e,t,n){return` ${N("\u2740")} ${R("SESSION_ACTIVE")} ${t}s \xB7 ${e} \xB7 ${f(n)}`}function Co(e){return["",...e.map(t=>F(t,bt)),""]}function Eo(e){let t=e.toLowerCase().trim();return/\binhale\b/.test(t)?"INHALING . . .":/\bexhale\b/.test(t)?"EXHALING . . .":/\bhold\b/.test(t)?"HOLDING . . .":`${t.replace(/^\d+\s+/,"").trim().toUpperCase()} . . .`}function _o(e,t){let n=ho(t,e);if(n<0)return"";let r=Eo(e[n].label),o=`[ ${R(m(r))} ]`;return F(o,bt)}function Ro(e,t,n){let r=Math.max(0,Math.min(.999,e/t));return Math.min(n,Math.floor(r*n)+1)}function vo(e,t,n,r){let o=`${f("TIME_REMAINING")} ${m(`-${yo(e/1e3)}`)}`;if(!r)return` ${o}`;let s=Ro(t,n,r),i=`${f("ROUND")} ${m(`${s} / ${r}`)}`,a=Math.floor(bt/2);return z(` ${o}`,a)+i}function Io(e,t){let n=Math.min(1,Math.max(0,e/t)),r=Math.round(n*wn),o=wn-r,s=`${m("\u2588".repeat(r))}${f("\u2591".repeat(o))}`,i=`${Math.round(n*100)}%`;return` ${f("PROGRESS_SEQUENCE")} [${s}] ${f(i)}`}var $o="\x1B[?25l",Sn="\x1B[?25h",Oo=e=>`\x1B[${e}A`,Po="\x1B[H",To="\x1B[2K",xo="\r",Ao="\x1B[?1049h",yn="\x1B[?1049l",Mo=25;function kn(e,t,n){let r=Math.max(0,n-t),o=Co(pt(t,r,e.cues));return{lines:["",...["",ko(e.displayName,e.duration,e.voice),"",...o,"",_o(e.cues,t),"",vo(r,t,n,e.rounds),"",Io(t,n),""].map(i=>` ${i}`),""]}}function Cn(e,t,n){let r="";n||(r+=Oo(Mo));for(let o of t.lines)r+=`${xo}${To}${o}
5
+ `;e.write(r)}async function En(e){let t=e.out??process.stdout,n=e.now??Date.now,r=e.startedAt??n(),o=e.duration*1e3;t.write(Ao+Po+$o);let s=!0,i=!1,a=()=>{if(i)return;let l=n()-r,d=kn(e,l,o);Cn(t,d,s),s=!1};a();let u=setInterval(a,go),c=()=>{i=!0,clearInterval(u),t.write(Sn+yn),process.exit(130)};process.once("SIGINT",c);try{await e.donePromise}finally{i=!0,clearInterval(u),process.removeListener("SIGINT",c);let l=kn(e,o,o);Cn(t,l,!1),t.write(Sn+yn)}}function _n(){return!!process.stdout.isTTY&&!process.env.NO_COLOR&&!process.env.CI}var B=60,wt=30,No=28,Bo=8,St=25,Do=St+2;function ee(e){return e.length>=St?e:[...e,...new Array(St-e.length).fill("")]}function he(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/60),r=t%60;return`${n}:${r.toString().padStart(2,"0")}`}function Lo(e,t,n=wt){let r=t<=0?0:Math.max(0,Math.min(1,e/t)),o=Math.round(r*n),s=n-o;return`${m("\u2588".repeat(o))}${f("\u2591".repeat(s))}`}function Fo(e,t){return t<=0?"0%":`${Math.round(e/t*100)}%`}function Ko(e){switch(e){case"PRE_FLIGHT":return"PRE_FLIGHT";case"FOCUS_BLOCK":return"FOCUS_BLOCK";case"TRANSITION":return"TRANSITION";case"BREAK":return"BREAK";case"LONG_BREAK":return"LONG_BREAK";case"CYCLE_DONE":return"CYCLE_DONE"}}function In(e,t){return` ${N("\u2740")} ${R(Ko(e.status))} ${f(t)}`}function te(e){return e.length===0?[]:[...e.map(lt),""]}function Uo(e,t){let n=he(J(e,t));return e.status==="FOCUS_BLOCK"?`block ${e.blockIndex} of ${e.preset.blocks} \xB7 ${n} \xB7 deep work`:e.status==="BREAK"?`break ${e.blockIndex} of ${e.preset.blocks} \xB7 ${n} \xB7 step away`:e.status==="LONG_BREAK"?`long break \xB7 ${n} \xB7 long rest`:e.status==="TRANSITION"?`transition \xB7 next: ${e.blockIndex>=e.preset.blocks?"long break":"break"}`:""}function $n(e,t){let n=Uo(e,t);return F(`${m("\u25B8")} ${f(n)}`,B)}function jo(e){let t=[];for(let n=1;n<=e.blocks;n++)t.push({kind:"focus",blockIndex:n}),n<e.blocks&&t.push({kind:"break",blockIndex:n});return t.push({kind:"long_break",blockIndex:e.blocks}),t}function qo(e,t){for(let n=0;n<t.length;n++){let r=t[n];if(r.kind==="focus"&&r.blockIndex===e.blockIndex&&(e.status==="FOCUS_BLOCK"||e.status==="TRANSITION")||r.kind==="break"&&r.blockIndex===e.blockIndex&&e.status==="BREAK"||r.kind==="long_break"&&e.status==="LONG_BREAK")return n}return-1}function On(e){let t=jo(e.preset),n=qo(e,t),r=[];for(let o=0;o<t.length;o++)o<n?r.push(m("\u2713")):o===n?r.push(R(m("\u25B8"))):r.push(f("\xB7"));return r.join(" ")}function Ho(e,t){let n=e.paused&&e.state.pausedAtMs!==null?e.state.pausedAtMs-e.state.enteredAtMs:e.elapsedMs;return pt(n,t*1e3,[],No,Bo).map(r=>F(e.paused?f(r):r,B))}function Pn(e){let t=`[ ${R(m(e))} ]`;return F(t,B)}function Tn(e,t){let n=Lo(e,t),r=Fo(e,t);return` ${f("PROGRESS_SEQUENCE")} [${n}] ${f(r)}`}function xn(e){return e?` ${R(m("space"))} ${R("resume")} \xB7 ${f("s")} skip \xB7 ${R(m("q"))} ${R("quit")} \xB7 ${f("?")} help`:` ${f("space")} pause \xB7 ${f("s")} skip \xB7 ${f("q")} quit \xB7 ${f("?")} help`}function Go(e){let t=e.state.preset,n=["",` ${N("\u2740")} ${R("FOCUS_CYCLE")} ${f(e.presetName)}`,"",...te(e.breadcrumbs??[]),` ${f("blocks")} ${m(String(t.blocks))}`,` ${f("focus")} ${m(he(t.focusSec))} each`,` ${f("break")} ${m(he(t.breakSec))} each`,` ${f("long break")} ${m(he(t.longBreakSec))} after the last block`,"",F(`[ ${R(m("press enter to begin"))} ]`,B),"",` ${f("q")} quit`,""];return H(ee(n),B)}function gt(e,t){let n=Me(e.state),r=J(e.state,e.nowMs),o=n-r,s=e.paused?"PAUSED":t,i=["",In(e.state,e.presetName),"",...te(e.breadcrumbs??[]),$n(e.state,e.nowMs),"",...Ho(e,r),"",F(On(e.state),B),"",Pn(`${s} . . .`),"",Tn(o,n),"",xn(e.paused),""];return H(ee(i),B)}function Yo(e){let t=J(e.state,e.nowMs),n=Me(e.state),r=n-t,o=e.state.blockIndex>=e.state.preset.blocks?"LONG_BREAK":"BREAK",s=["",In(e.state,e.presetName),"",...te(e.breadcrumbs??[]),$n(e.state,e.nowMs),"","","",F(`${m(`next: ${o} in ${t}s`)}`,B),"","",F(On(e.state),B),"",Pn("FETCHING SESSION . . ."),"",Tn(r,n),"",xn(e.paused),""];return H(ee(s),B)}function Vo(e){let t=e.state.preset,n=he(t.focusSec*t.blocks),r=["",` ${N("\u2740")} ${R("CYCLE_DONE")} ${f(e.presetName)}`,"",...te(e.breadcrumbs??[]),` ${f("focus blocks")} ${m(`${t.blocks}`)}`,` ${f("total deep work")} ${m(n)}`,` ${f("breaks taken")} ${m(`${t.blocks}`)}`,"",F(`[ ${R(m("nice work"))} ]`,B),"",` ${f("r")} repeat \xB7 ${f("x")} exit`,""];return H(ee(r),B)}function De(e){switch(e.state.status){case"PRE_FLIGHT":return Go(e);case"FOCUS_BLOCK":return gt(e,"DEEP WORK");case"TRANSITION":return Yo(e);case"BREAK":return gt(e,"BREATHE");case"LONG_BREAK":return gt(e,"LONG_REST");case"CYCLE_DONE":return Vo(e)}}function Le(e){return Do}function yt(e){let t=U[e];if(t.focusSec<60||t.breakSec<60)return`${t.focusSec}s/${t.breakSec}s \xB7 ${t.blocks} blocks`;let n=Math.round(t.focusSec/60),r=Math.round(t.breakSec/60);return`${n}/${r} \xB7 ${t.blocks} blocks`}var ne=["pomodoro","dev","ultradian","test2","test5"];function Wo(e,t){let n=t?m("\u25B8 "):" ",r=t?R(m(e)):e,o=f(`\xB7 ${yt(e)}`);return` ${n}${z(r,10)} ${o}`}function An(e,t=[]){let n=["",` ${N("\u2740")} ${R("FOCUS_CYCLE")} ${f("pick a cadence")}`,"",...te(t),...ne.map((r,o)=>Wo(r,o===e)),"",` ${f("\u2191\u2193 to move \u23CE to select esc to cancel")}`,""];return H(ee(n),B)}var Mn=22,Jo=22,ht=["\u2581","\u2582","\u2583","\u2584","\u2585","\u2584","\u2583","\u2582"];function Qo(e){let t=e%ht.length,n="";for(let r=0;r<5;r++)n+=ht[(t+r)%ht.length];return n}function zo(e){let t=e?m("\u25B8"):" ",n=e?R(m("none")):"none",r=f("silence \u2014 your own thoughts");return` ${t} ${z(n,Mn)} ${r}`}function Xo(e){return` ${f(e.toUpperCase())}`}function Zo(e,t,n){let r=t?m("\u25B8"):" ",o=t?R(m(e.name)):e.name,s=f(z(e.blurb,Jo)),i=t?m(` ${Qo(n)}`):"";return` ${r} ${z(o,Mn)} ${s}${i}`}function Nn(e){let{entries:t,selectedIdx:n,tickFrame:r,breadcrumbs:o=[]}=e,s=[];s.push(` ${N("\u2740")} ${R("FOCUS_CYCLE")} ${f("pick an ambience")}`),s.push(""),s.push(...te(o));for(let i=0;i<t.length;i++){let a=t[i],u=i===n;a.kind==="none"?s.push(zo(u)):a.kind==="category"?s.push(Xo(a.label)):s.push(Zo(a.sound,u,r))}return s.push(""),s.push(` ${f("\u2191\u2193 to move \u23CE to select esc to cancel")}`),H(ee(s),B)}var Rn=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function vn(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} kB`:`${(e/1024/1024).toFixed(1)} MB`}function es(e,t){let n=t<=0?0:Math.max(0,Math.min(1,e/t)),r=Math.round(n*wt),o=wt-r;return`${m("\u2588".repeat(r))}${f("\u2591".repeat(o))}`}function Bn(e){let{sound:t,status:n,downloaded:r,total:o,tickFrame:s,breadcrumbs:i=[]}=e,a=Rn[s%Rn.length],u=n==="ready"?R(m("READY . . .")):n==="failed"?R(m("OFFLINE \u2014 STARTING IN SILENCE")):n==="timeout"?R(m("TIMED OUT \u2014 STARTING IN SILENCE")):`${m(a)} ${R("PREPARING . . .")}`,c=o<=0?0:Math.round(r/o*100),l=t?`${R(m(t.name))} ${f(t.blurb)}`:`${R(m("silence"))} ${f("your own thoughts")}`,d=t?`${f(vn(r))} ${f("/")} ${f(vn(o))} ${f(`${c}%`)}`:"",w=["",` ${N("\u2740")} ${R("FOCUS_CYCLE")} ${f("preparing your ambience")}`,"",...te(i),F(`[ ${u} ]`,B),"",F(l,B),"",F(`[${es(r,o)}]`,B),"",F(d,B),"",` ${f("esc to cancel")}`,""];return H(ee(w),B)}var we="\x1B[?1049h",ae="\x1B[?1049l",ce="\x1B[?25l",ue="\x1B[?25h",Se="\x1B[H",Ke=e=>`\x1B[${e}A`,Ue="\x1B[2K",ss=100,is=3e4,Fn=80,Dn=os(rs(ns(import.meta.url)),"..","assets/notification-icon.png");async function Kn(e={}){let t=e.out??process.stdout,n=e.stdin??process.stdin,r=e.defaultPreset??"pomodoro",o=e.breadcrumbs??[],s=Math.max(0,ne.indexOf(r)),i=[],a=!1,u=null,c=()=>{if(u){let g=u;u=null,g.resolve()}},l=g=>{let k=Buffer.isBuffer(g)?g:Buffer.from(g);for(let b of W(k))i.push(b);c()},d=()=>{a=!0,c()};n.isTTY&&n.setRawMode(!0),n.resume(),n.on("data",l),n.once("end",d),t.write(we+Se+ce);let w=!0,S=()=>{let g=An(s,o),k="";w||(k+=Ke(g.length));for(let b of g)k+=`\r${Ue}${b}
6
+ `;t.write(k),w=!1},$=()=>{n.isTTY&&n.setRawMode(!1),n.off("data",l),n.off("end",d),n.pause(),t.write(ue+ae)},C=()=>{$(),process.removeListener("SIGINT",C),process.exit(0)};process.on("SIGINT",C);try{for(S();;){if(i.length===0){if(a)return null;await new Promise(g=>{u={resolve:g}})}for(;i.length>0;){let g=i.shift();if(g.name==="ctrl-c"||g.name==="escape")return null;if(g.name==="up"||g.name==="char"&&g.char?.toLowerCase()==="k")s=(s-1+ne.length)%ne.length,S();else if(g.name==="down"||g.name==="tab"||g.name==="char"&&g.char?.toLowerCase()==="j")s=(s+1)%ne.length,S();else{if(g.name==="return")return ne[s];if(g.name==="char"&&g.char?.toLowerCase()==="q")return null}}}}finally{process.removeListener("SIGINT",C),$()}}function as(e,t){if(t)for(let n=0;n<e.length;n++){let r=e[n];if(r.kind==="sound"&&r.sound.id===t)return n}for(let n=0;n<e.length;n++)if(e[n].kind==="none")return n;return 0}async function Un(e){let t=e.out??process.stdout,n=e.stdin??process.stdin,r=e.breadcrumbs??[],o=Qt(e.manifest),s=zt(o),i=as(o,e.defaultSoundId),a=0,u=[],c=!1,l=null,d=()=>{if(l){let h=l;l=null,h.resolve()}},w=h=>{let O=Buffer.isBuffer(h)?h:Buffer.from(h);for(let D of W(O))u.push(D);d()},S=()=>{c=!0,d()};n.isTTY&&n.setRawMode(!0),n.resume(),n.on("data",w),n.once("end",S),t.write(we+Se+ce);let $=!0,C=()=>{let h=Nn({entries:o,selectedIdx:i,tickFrame:a,breadcrumbs:r}),O="";$||(O+=Ke(h.length));for(let D of h)O+=`\r${Ue}${D}
7
+ `;t.write(O),$=!1},g=()=>{n.isTTY&&n.setRawMode(!1),n.off("data",w),n.off("end",S),n.pause(),t.write(ue+ae)},k=()=>{g(),process.removeListener("SIGINT",k),process.exit(0)};process.on("SIGINT",k);let b=(h,O)=>{let D=s.indexOf(h);if(D<0)return h;let P=(D+O+s.length)%s.length;return s[P]},v=setInterval(()=>{a++,C()},Fn);try{for(C();;){if(u.length===0){if(c)return null;await new Promise(h=>{l={resolve:h}})}for(;u.length>0;){let h=u.shift();if(h.name==="ctrl-c"||h.name==="escape")return null;if(h.name==="up"||h.name==="char"&&h.char?.toLowerCase()==="k")i=b(i,-1),C();else if(h.name==="down"||h.name==="tab"||h.name==="char"&&h.char?.toLowerCase()==="j")i=b(i,1),C();else if(h.name==="return"){let O=o[i];if(O.kind==="none")return{sound:null};if(O.kind==="sound")return{sound:O.sound}}else if(h.name==="char"&&h.char?.toLowerCase()==="q")return null}}}finally{v&&(clearInterval(v),v=null),process.removeListener("SIGINT",k),g()}}async function jn(e){let t=e.out??process.stdout,n=e.sound,r=e.timeoutMs??is,o=e.breadcrumbs??[];if(!n)return Ln(t,{sound:null,status:"ready",downloaded:0,total:0,tickFrame:0,breadcrumbs:o},!0),await Fe(250),{filePath:null,outcome:"silent"};if(Jt(n))return{filePath:Vt(n),outcome:"cached"};let s=0,i=n.bytes,a=0,u="fetching",c=!0,l=()=>{Ln(t,{sound:n,status:u,downloaded:s,total:i,tickFrame:a,breadcrumbs:o},c),c=!1},d=setInterval(()=>{a++,l()},Fn),w=new AbortController,S=setTimeout(()=>{w.abort(),$?.("timeout")},r),$=null,C=new Promise(v=>{$=v}),g=(v,h)=>{s=v,i=h||n.bytes},k=(e.download?e.download(n,g):Ee(n,{signal:w.signal,onProgress:v=>g(v.downloaded,v.total)})).then(v=>({ok:!0,path:v})).catch(()=>({ok:!1}));t.write(we+Se+ce),l();let b=await Promise.race([k,C]);return clearInterval(d),clearTimeout(S),$=null,b==="timeout"?(u="timeout",l(),await Fe(400),t.write(ue+ae),{filePath:null,outcome:"timeout"}):b.ok?(u="ready",s=i,l(),await Fe(300),t.write(ue+ae),{filePath:b.path,outcome:"ready"}):(u="failed",l(),await Fe(400),t.write(ue+ae),{filePath:null,outcome:"failed"})}function Ln(e,t,n){let r=Bn(t),o="";n?o+=we+Se+ce:o+=Ke(r.length);for(let s of r)o+=`\r${Ue}${s}
8
+ `;e.write(o)}function Fe(e){return new Promise(t=>setTimeout(t,e))}function us(e,t){switch(e){case"pause":return{kind:"PAUSE",nowMs:t};case"resume":return{kind:"RESUME",nowMs:t};case"skip":return{kind:"SKIP",nowMs:t};case"quit":return{kind:"QUIT",nowMs:t}}}async function qn(e){let t=e.out??process.stdout,n=e.stdin??process.stdin,r=e.now??Date.now,o=U[e.preset],s=e.preset,i=e.breakType??"quick_reset",a=e.longBreakType??"executive_reset",u=e.notifications??!0,c=e.ambientFilePath??void 0,l=(e.ambientEnabled??!0)&&!!c,d=e.startAmbient??se,w=e.breadcrumbs??[],S=e.autoStart??!0,$=e.stateEnabled??!0,C=e.ambientId??null,g=process.pid,k=!1;if($){let p=ve({pidOverride:g});if(p.kind==="busy")throw new Error(`focus session already running (pid ${p.pid})`);k=!0}let b=Ae(o,r()),v=b.enteredAtMs,h=null,O=null,D=()=>{O?.stop(),O=null},P=Le(o),E=!0,T="",L=(p,_=!1)=>{let I=p.join(`
9
+ `);if(!_&&!E&&I===T)return;let G="";E||(G+=Ke(P));for(let Mr of p)G+=`\r${Ue}${Mr}
10
+ `;t.write(G),E=!1,T=I},y=(p=!1)=>{let _=r()-b.enteredAtMs,I=De({state:b,presetName:s,elapsedMs:_,nowMs:r(),paused:b.pausedAtMs!==null,breadcrumbs:w});L(I,p)},K=()=>{if(!(!$||!k))try{_e({version:1,pid:g,status:b.status,preset:s,blockIndex:b.blockIndex,blocks:b.preset.blocks,remainingSec:J(b,r()),paused:b.pausedAtMs!==null,ambient:C,startedAt:v,updatedAt:r()})}catch{}},M=p=>p<60?`${p}s`:`${Math.round(p/60)} min`,me=p=>{if(!u)return;let _="",I="";if(p.status==="FOCUS_BLOCK")_=`flowe \xB7 block ${p.blockIndex}/${p.preset.blocks}`,I=`${M(p.preset.focusSec)}. one thing. lock in.`;else if(p.status==="BREAK")_="flowe \xB7 break",I=`${M(p.preset.breakSec)}. stand up. breathe.`;else if(p.status==="LONG_BREAK")_="flowe \xB7 long break",I=`${M(p.preset.longBreakSec)}. walk. eyes off the screen.`;else if(p.status==="CYCLE_DONE")_="flowe \xB7 cycle done",I=`${p.preset.blocks} blocks banked. go ship.`;else return;try{ts.notify({title:_,message:I,icon:Dn,contentImage:Dn,sound:!0})}catch{}},Ge=async p=>{if(me(p),p.status==="FOCUS_BLOCK"?l&&!O&&c&&(O=d(c)):D(),p.status==="BREAK"||p.status==="LONG_BREAK"){let _=p.status==="BREAK"?i:a,I=p.status==="BREAK"?5:15;try{h=await ie({type:_,durationMin:I})}catch{h=null}}(p.status==="FOCUS_BLOCK"||p.status==="CYCLE_DONE")&&(h?.cancel(),h=null)},Y=async p=>{let _=b,I=Ne(_,p);I!==_&&(b=I,K(),Be(_,I)?await Ge(I):Ar(_,I))},Ar=(p,_)=>{let I=p.pausedAtMs!==null,G=_.pausedAtMs!==null;if(I!==G&&_.status==="FOCUS_BLOCK"){if(G){D();return}l&&!O&&c&&(O=d(c))}},X=[],Ce=!1,oe=null,Ye=()=>{if(oe){let p=oe;oe=null,p.resolve()}},Tt=p=>{let _=Buffer.isBuffer(p)?p:Buffer.from(p);for(let I of W(_))X.push(I);Ye()},xt=()=>{Ce=!0,Ye()},At=()=>{n.isTTY&&n.setRawMode(!0)};At(),n.resume(),n.on("data",Tt),n.once("end",xt),t.write(we+Se+ce);let Mt=p=>X.length>0||Ce?Promise.resolve():new Promise(_=>{let I={resolve:_};oe=I,setTimeout(()=>{oe===I&&(oe=null,_())},p)}),Ve=()=>{h?.cancel(),h=null,D(),k&&(Ie(),Re(),k=!1),n.isTTY&&n.setRawMode(!1),n.off("data",Tt),n.off("end",xt),n.pause(),process.removeListener("SIGCONT",Bt),t.write(ue+ae)},Nt=()=>{Ve(),process.removeListener("SIGINT",Nt),process.exit(0)};process.on("SIGINT",Nt);let Bt=()=>{At(),t.write(ce),E=!0,T="",y(!0),Ye()};process.on("SIGCONT",Bt);try{if(S&&b.status==="PRE_FLIGHT"){let p=ge(b,r());p!==b&&(b=p,v=b.enteredAtMs,K(),await Ge(b))}for(y();b.status==="PRE_FLIGHT";){if(await Mt(6e4),Ce&&X.length===0){Ve();return}for(;X.length>0;){let p=X.shift();if(p.name==="ctrl-c"||p.name==="escape"){await Y({kind:"QUIT",nowMs:r()});break}if(p.name==="return"){let _=ge(b,r());_!==b&&(b=_,v=b.enteredAtMs,K(),await Ge(b));break}if(p.name==="char"&&(p.char??"").toLowerCase()==="q"){await Y({kind:"QUIT",nowMs:r()});break}}}for(;b.status!=="CYCLE_DONE";){y(),K();let p=!1,_=$&&k?Oe():null;for(_&&(await Y(us(_,r())),_==="quit"&&(p=!0));X.length>0&&!p;){let I=X.shift();if(I.name==="ctrl-c"||I.name==="escape"){await Y({kind:"QUIT",nowMs:r()}),p=!0;break}if(I.name==="char"){let G=(I.char??"").toLowerCase();if(G===" ")await Y(b.pausedAtMs!==null?{kind:"RESUME",nowMs:r()}:{kind:"PAUSE",nowMs:r()});else if(G==="s")await Y({kind:"SKIP",nowMs:r()});else if(G==="q"||G==="x"){await Y({kind:"QUIT",nowMs:r()}),p=!0;break}}}if(p){y();break}if(b.status==="CYCLE_DONE")break;if(Ce){await Y({kind:"QUIT",nowMs:r()});continue}await Mt(ss),await Y({kind:"TICK",nowMs:r()})}y()}finally{Ve()}}import cs from"node-notifier";import{fileURLToPath as ls}from"url";import{dirname as ds,join as fs}from"path";var ms=100,ps="quick_reset",bs="executive_reset",Hn=fs(ds(ls(import.meta.url)),"..","assets/notification-icon.png");function gs(e,t){switch(e){case"pause":return{kind:"PAUSE",nowMs:t};case"resume":return{kind:"RESUME",nowMs:t};case"skip":return{kind:"SKIP",nowMs:t};case"quit":return{kind:"QUIT",nowMs:t}}}function hs(e,t){return{version:1,pid:t.pid,status:e.status,preset:t.preset,blockIndex:e.blockIndex,blocks:e.preset.blocks,remainingSec:J(e,t.nowMs),paused:e.pausedAtMs!==null,ambient:t.ambientId,startedAt:t.startedAtMs,updatedAt:t.nowMs}}function ws(e,t){if(!t)return;let n="",r="";if(e.status==="FOCUS_BLOCK")n="flowe \xB7 deep work",r=`block ${e.blockIndex} of ${e.preset.blocks} started`;else if(e.status==="BREAK")n="flowe \xB7 break",r=`${Math.round(e.preset.breakSec/60)} min \xB7 breathe`;else if(e.status==="LONG_BREAK")n="flowe \xB7 long break",r=`${Math.round(e.preset.longBreakSec/60)} min \xB7 long rest`;else if(e.status==="CYCLE_DONE")n="flowe \xB7 cycle complete",r=`${e.preset.blocks} blocks \xB7 nice work`;else return;try{cs.notify({title:n,message:r,icon:Hn,contentImage:Hn,sound:!0})}catch{}}var Ss=e=>new Promise(t=>setTimeout(t,e));async function Gn(e){let t=U[e.preset],n=e.preset,r=e.now??Date.now,o=e.tickMs??ms,s=e.breakType??ps,i=e.longBreakType??bs,a=e.notifications??!0,u=e.startAmbient??se,c=e.runBreak??ie,l=e.consumeControl??Oe,d=e.pidOverride??process.pid,w=e.ambientId??null,S=e.ambientFilePath,$=ve({pidOverride:d});if($.kind==="busy")return{finalStatus:"PRE_FLIGHT",ticks:0,reason:"busy",busyPid:$.pid};let C=ge(Ae(t,r()),r()),g=C.enteredAtMs,k=null,b=null,v=()=>{b?.stop(),b=null},h=()=>{let y=hs(C,{pid:d,preset:n,ambientId:w,startedAtMs:g,nowMs:r()});try{_e(y)}catch{}},O=async y=>{if(ws(y,a),y.status==="FOCUS_BLOCK"?S&&!b&&(b=u(S)):v(),y.status==="BREAK"||y.status==="LONG_BREAK"){let K=y.status==="BREAK"?s:i,M=y.status==="BREAK"?5:15;try{k=await c({type:K,durationMin:M})}catch{k=null}}(y.status==="FOCUS_BLOCK"||y.status==="CYCLE_DONE")&&(k?.cancel(),k=null)},D=(y,K)=>{let M=y.pausedAtMs!==null,me=K.pausedAtMs!==null;if(M!==me&&K.status==="FOCUS_BLOCK"){if(me){v();return}S&&!b&&(b=u(S))}},P=async y=>{let K=C,M=Ne(K,y);M!==K&&(C=M,Be(K,M)?await O(M):D(K,M))};await O(C),h();let E=0,T="cycle_done",L=e.maxTicks??Number.POSITIVE_INFINITY;try{for(;C.status!=="CYCLE_DONE"&&E<L;){let y=l();if(y!==null&&(await P(gs(y,r())),y==="quit")){T="quit";break}if(C.status==="CYCLE_DONE")break;await Ss(o),await P({kind:"TICK",nowMs:r()}),h(),E+=1}E>=L&&C.status!=="CYCLE_DONE"&&(T="max_ticks")}finally{v(),k?.cancel(),k=null,h(),Ie(),C.status==="CYCLE_DONE"&&Re()}return{finalStatus:C.status,ticks:E,reason:T}}var ys="\x1B[?1049h",ks="\x1B[?1049l",Cs="\x1B[?25l",Es="\x1B[?25h",_s="\x1B[H",Rs=e=>`\x1B[${e}A`,vs="\x1B[2K",Is=250;function $s(e,t){let n=U[e.preset],r=Vn(e.status,n),s=Math.max(0,r-e.remainingSec)*1e3;return e.paused?{status:e.status,blockIndex:e.blockIndex,enteredAtMs:t-s,pausedAtMs:t,pausedDurationMs:0,preset:n}:{status:e.status,blockIndex:e.blockIndex,enteredAtMs:t-s,pausedAtMs:null,pausedDurationMs:0,preset:n}}function Vn(e,t){switch(e){case"FOCUS_BLOCK":return t.focusSec;case"TRANSITION":return be;case"BREAK":return t.breakSec;case"LONG_BREAK":return t.longBreakSec;default:return 0}}function Os(e,t){if(e.name==="ctrl-c")return"detach";if(e.name==="char"){let n=(e.char??"").toLowerCase();if(n===" ")return t?"resume":"pause";if(n==="s")return"skip";if(n==="q"||n==="x")return"quit";if(n==="d")return"detach"}return null}var Ps=e=>new Promise(t=>setTimeout(t,e));function Ts(){return["no active focus session.","","start one: flowe focus","or detached: flowe focus --detach"].join(`
11
+ `)}function Wn(e){let t=Vn(e.status,U[e.preset]);return[`flowe \xB7 ${e.preset} \xB7 ${e.status.toLowerCase()}`,`block ${e.blockIndex} / ${e.blocks}`,`remaining ${Yn(e.remainingSec)}${t?` of ${Yn(t)}`:""}`,`paused ${e.paused?"yes":"no"}`,`ambient ${e.ambient??"(none)"}`,`pid ${e.pid}`].join(`
12
+ `)}function Yn(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/60),r=t%60;return`${n}:${r.toString().padStart(2,"0")}`}async function Jn(e={}){let t=e.out??process.stdout,n=e.stdin??process.stdin,r=e.now??Date.now,o=e.pollMs??Is,s=e.readState??pe,i=e.sendControl??$e,a=e.maxPolls??Number.POSITIVE_INFINITY,u=s();if(u===null)return t.write(`${Ts()}
13
+ `),{reason:"no_session"};let c=[],l=!1,d=null,w=()=>{if(d){let E=d;d=null,E.resolve()}},S=E=>{let T=Buffer.isBuffer(E)?E:Buffer.from(E);for(let L of W(T))c.push(L);w()},$=()=>{l=!0,w()};n.isTTY&&n.setRawMode(!0),n.resume(),n.on("data",S),n.once("end",$),t.write(ys+_s+Cs);let C=!0,g=u.preset,k=Le(U[g]),b=E=>{let T="";C||(T+=Rs(k));for(let L of E)T+=`\r${vs}${L}
14
+ `;t.write(T),C=!1},v=E=>{let T=r(),L=$s(E,T),y=De({state:L,presetName:E.preset,elapsedMs:T-L.enteredAtMs,nowMs:T,paused:E.paused});b(y)},h=()=>{n.isTTY&&n.setRawMode(!1),n.off("data",S),n.off("end",$),n.pause(),t.write(Es+ks)},O=()=>{h(),process.removeListener("SIGINT",O),process.exit(0)};process.on("SIGINT",O);let D=0,P="cycle_done";try{let E=u;for(v(E);D<a;){let T=!1;for(;c.length>0;){let L=c.shift(),y=Os(L,E?.paused??!1);if(y!==null){if(y==="detach"){P="detached",T=!0;break}try{i(y)}catch{}y==="quit"&&(P="quit")}}if(T)break;if(l&&c.length===0){P="detached";break}if(await Ps(o),D+=1,E=s(),E===null){P=P==="quit"?"quit":"no_session";break}if(v(E),E.status==="CYCLE_DONE"){P=P==="quit"?"quit":"cycle_done";break}}}finally{process.removeListener("SIGINT",O),h()}return{reason:P}}import{readFileSync as xs}from"fs";import{dirname as As,join as Ms}from"path";import{fileURLToPath as Ns}from"url";function zn(e,t){return e===null||e.status==="CYCLE_DONE"?Ds(t):Bs(e,t)}function Bs(e,t){let n=Qn(e.remainingSec),r=U[e.preset],o=qs(e.status,r),s=[];return s.push(Ls(e,n)),s.push("---"),s.push(`flowe \xB7 ${e.preset} \xB7 ${Us(e.status)}`),s.push(`block ${e.blockIndex} / ${e.blocks} | font=Menlo`),s.push(`remaining ${n}${o?` of ${Qn(o)}`:""} | font=Menlo`),s.push(`ambient ${e.ambient??"(none)"} | font=Menlo`),s.push(`paused ${e.paused?"yes":"no"} | font=Menlo`),s.push("---"),e.paused?s.push(je("Resume","resume",t)):s.push(je("Pause","pause",t)),s.push(je("Skip block","skip",t)),s.push(je("Quit cycle","quit",t)),s.push("---"),s.push(`Open status in terminal | ${ke(t,["focus","status"])} terminal=true`),s.join(`
15
+ `)}function Ds(e){return[Fs(),"---","no active focus session | color=#8c8c8c size=11","---",`Start pomodoro | ${ke(e,["focus","pomodoro","--detach","--ambient","none"])} terminal=false refresh=true sfimage=play.circle.fill`,`Start dev | ${ke(e,["focus","dev","--detach","--ambient","none"])} terminal=false refresh=true sfimage=play.circle.fill`,`Start ultradian | ${ke(e,["focus","ultradian","--detach","--ambient","none"])} terminal=false refresh=true sfimage=play.circle.fill`].join(`
16
+ `)}function Ls(e,t){let n=e.paused?`\u23F8 ${t}`:t;return Xn(n,{dim:e.paused})}function Fs(){return Xn("flowe",{dim:!0})}function Xn(e,t){let n=[],r=Ks();return r&&n.push(`image=${r}`),t.dim&&n.push("color=#8c8c8c"),n.length?`${e} | ${n.join(" ")}`:e}var ye=null;function Ks(){if(ye!==null)return ye;try{let e=As(Ns(import.meta.url));ye=xs(Ms(e,"..","assets/menubar-icon.png")).toString("base64")}catch{ye=""}return ye}function Us(e){switch(e){case"FOCUS_BLOCK":return"focus";case"TRANSITION":return"transition";case"BREAK":return"break";case"LONG_BREAK":return"long break";case"CYCLE_DONE":return"done";case"PRE_FLIGHT":return"starting"}}function je(e,t,n){let r=js(t),o=r?` sfimage=${r}`:"";return`${e} | ${ke(n,["focus",t])} terminal=false refresh=true${o}`}function js(e){switch(e){case"pause":return"pause.fill";case"resume":return"play.fill";case"skip":return"forward.fill";case"quit":return"stop.fill";default:return""}}function ke(e,t){let n=e.floweBinary,r=e.nodeBinary;if(r){let s=[n,...t].map((i,a)=>`param${a+1}=${i}`).join(" ");return`bash=${r} ${s}`}let o=t.map((s,i)=>`param${i+1}=${s}`).join(" ");return`bash=${n} ${o}`}function qs(e,t){switch(e){case"FOCUS_BLOCK":return t.focusSec;case"TRANSITION":return be;case"BREAK":return t.breakSec;case"LONG_BREAK":return t.longBreakSec;default:return 0}}function Qn(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/60),r=t%60;return`${n}:${r.toString().padStart(2,"0")}`}import{chmodSync as Hs,existsSync as kt,mkdirSync as Gs,readFileSync as Ys,rmSync as Vs,statSync as uu,writeFileSync as Ws}from"fs";import{homedir as Ct}from"os";import{dirname as Js,join as le,resolve as Qs}from"path";import{fileURLToPath as zs}from"url";import{execFileSync as Zn,spawnSync as re}from"child_process";var Et="flowe.1s.sh";function Xs(){return le(Ct(),"Library","Application Support","SwiftBar","Plugins")}function _t(){try{let t=Zn("/usr/bin/defaults",["read","com.ameba.SwiftBar","PluginDirectory"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim();return t.length>0?t:null}catch{return null}}var Zs=["Documents","Desktop","Downloads","Library/Mobile Documents"];function ei(e,t=Ct()){if(!e.startsWith(`${t}/`))return!1;let n=e.slice(t.length+1);return Zs.some(r=>n===r||n.startsWith(`${r}/`))}function er(e){if(e?.override)return e.override;let t=(e?.readPref??_t)(),n=e?.isRestricted??ei;return t&&!n(t)?t:Xs()}function tr(e){return re("/usr/bin/defaults",["write","com.ameba.SwiftBar","PluginDirectory",e],{stdio:"ignore"}).status===0}function nr(){re("/usr/bin/killall",["SwiftBar"],{stdio:"ignore"}),re("/usr/bin/open",["-a","SwiftBar"],{stdio:"ignore"})}function ti(){return le(rr(),"bin","menubar",Et)}function rr(){let e=zs(import.meta.url);return Qs(Js(e),"..")}function or(){return le(rr(),"bin","flowe.js")}function sr(){try{let t=Zn("/usr/bin/which",["flowe"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim();return t.length>0?t:null}catch{return null}}function ni(e,t){let n=/^FLOWE_BIN="\$\{FLOWE_BIN:-\}"$/m;if(!n.test(e))throw new Error('plugin template is missing the FLOWE_BIN="${FLOWE_BIN:-}" placeholder');let r=/^NODE_BIN="\$\{NODE_BIN:-\}"$/m;if(!r.test(e))throw new Error('plugin template is missing the NODE_BIN="${NODE_BIN:-}" placeholder');let o=t.floweBin.replace(/"/g,'\\"'),s=(t.nodeBin??"").replace(/"/g,'\\"');return e.replace(n,`FLOWE_BIN="${o}"`).replace(r,`NODE_BIN="${s}"`)}function ir(e){let t=er({override:e.pluginDir}),n=le(t,Et),r=e.templatePath??ti();if(!kt(r))throw new Error(`plugin template not found at ${r}`);let o=Ys(r,"utf-8"),s=ni(o,{floweBin:e.floweBin,nodeBin:e.nodeBin??process.execPath});return e.dryRun?{pluginPath:n,scriptContent:s,written:!1}:(Gs(t,{recursive:!0}),Ws(n,s,"utf-8"),Hs(n,493),{pluginPath:n,scriptContent:s,written:!0})}function ar(e={}){let t=er({override:e.pluginDir}),n=le(t,Et),r=kt(n);return r&&Vs(n),{pluginPath:n,existed:r}}function ur(e){return[`installed \u2192 ${e.pluginPath}`,"","next steps:"," 1. open SwiftBar (brew install --cask swiftbar if not installed)"," 2. start a focus cycle: flowe focus pomodoro --detach"," 3. the menubar will refresh once a second with status + controls","","remove with: flowe uninstall-menubar"].join(`
17
+ `)}function ri(){return["/Applications/SwiftBar.app",le(Ct(),"Applications","SwiftBar.app")]}function oi(){return ri().some(e=>kt(e))}function si(){return re("/usr/bin/which",["brew"],{stdio:"ignore"}).status===0}function ii(){let e=re("brew",["install","--cask","swiftbar"],{stdio:"inherit"});if(e.status!==0)throw new Error(`brew install --cask swiftbar failed (exit ${e.status??"null"})`)}function cr(e={}){let t=e.isInstalled??oi,n=e.hasBrew??si,r=e.install??ii;if(t())return{action:"present"};if(!n())return{action:"missing-brew"};if(r(),!t())throw new Error("brew exited 0 but SwiftBar.app was not found in /Applications.");return{action:"installed"}}function lr(){return["SwiftBar is not installed, and brew is not available either.","","install Homebrew first: https://brew.sh","then re-run: flowe install-menubar","","or skip the dependency check and install just the plugin:"," flowe install-menubar --skip-swiftbar-check","","or download SwiftBar manually: https://github.com/swiftbar/SwiftBar/releases"].join(`
18
+ `)}function dr(){re("/usr/bin/open",["-a","SwiftBar"],{stdio:"ignore"})}function fr(){return re("/usr/bin/pgrep",["-x","SwiftBar"],{stdio:"ignore"}).status===0}function mr(e){return e.existed?`removed \u2192 ${e.pluginPath}`:`nothing to remove (no plugin at ${e.pluginPath})`}var ai=["focus","deep_work","settle","sleep"],ui={focus:{label:"Focus",defaultScene:"rain_window_soft",defaultMinutes:null,modulation:"balanced",description:"balanced texture for ordinary attention"},deep_work:{label:"Deep Work",defaultScene:"nature_mountain_wind",defaultMinutes:90,modulation:"strong",description:"fewer shifts for sustained demanding work"},settle:{label:"Settle",defaultScene:"interiors_fireplace",defaultMinutes:10,modulation:"gentle",description:"slower texture for releasing activation"},sleep:{label:"Sleep",defaultScene:"tones_deep_brown_noise",defaultMinutes:30,modulation:"low",description:"dark sparse texture for easing toward sleep"}};function qe(e){return ui[e]}function pr(e){let t=(e??"focus").trim().toLowerCase().replace(/[ -]+/g,"_");if(ai.includes(t))return t;throw new Error("intent must be one of: focus, deep-work, settle, sleep")}function br(e){if(e===void 0)return;let t=e.trim().toLowerCase();if(t==="infinite"||t==="inf"||t==="\u221E")return null;let n=t.match(/^(\d+(?:\.\d+)?)(m|min|h|hr)?$/);if(!n)throw new Error("duration must look like 25m, 90m, 1h, or infinite");let r=Number(n[1]),o=n[2]?.startsWith("h")?r*60:r;if(!Number.isFinite(o)||o<=0||o>720)throw new Error("duration must be between 1 minute and 12 hours");return Math.round(o)}function gr(e,t,n){if(n)return e.find(o=>o.id===n)??null;let r=qe(t);return e.find(o=>o.id===r.defaultScene)??e[0]??null}function hr(e){switch(e){case"gentle":case"low":return .6;case"strong":return 1.2;case"balanced":return 1}}function Rt(e,t,n){let r=qe(e),o=t===null?"infinite":`${t}m`;return[` FLOWESCAPE ${r.label}`,` ${r.description}`,` scene ${n}`,` neural ${r.modulation}`,` timer ${o}`," controls Ctrl-C to stop"].join(`
19
+ `)}function ci(e){return new URL("/api/v1/cli/ambient/custom",e).toString()}function de(e,t){return Object.assign(new Error(e),{code:t})}async function wr(e){try{let t=await e.json();return typeof t.error=="string"?t.message??t.error:t.error?.message??t.message??`request failed: ${e.status}`}catch{return`request failed: ${e.status}`}}async function Sr(e){let t=e.prompt.trim();if(t.length<10)throw de("prompt must be at least 10 characters","invalid_duration");let n=await V();if(!n)throw de("sign in with: flowe login","auth_required");let o=await(e.fetchFn??fetch)(ci(q().backend_url),{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify({prompt:t,name:e.name})});if(o.status===401)throw de("sign in with: flowe login","auth_required");if(o.status===403)throw de(await wr(o),"agent_busy");if(!o.ok)throw de(await wr(o),"network_error");let s=new Uint8Array(await o.arrayBuffer());if(s.byteLength===0)throw de("ambient generation returned empty audio","network_error");let i=o.headers.get("X-Flowe-Ambient-Name");return{sound:Wt({name:e.name??i??"custom ambience",prompt:t,bytes:s})}}import{readFileSync as li}from"fs";import{dirname as di,join as fi}from"path";import{fileURLToPath as mi}from"url";var pi=di(mi(import.meta.url));function bi(){try{let e=li(fi(pi,"..","package.json"),"utf-8");return JSON.parse(e).version}catch{return"0.0.0"}}var vt=[" \u2572\u2502\u2571 "," \u2500\u2500\u2740\u2500\u2500"," \u2571\u2502\u2572 "];function yr(){let e=bi();return[m(vt[0]),`${m(vt[1])} ${N("flowe")} ${f(`v${e}`)}`,`${m(vt[2])} ${an("neural reset for AI-paired engineers")}`].join(`
20
+ `)}var kr=["Most fatigue is unfinished arousal.","Calm is a learnable skill.","The exhale is where the parasympathetic switches on.","If you don't pause, your body picks the moment for you.","Rest is a posture you practice, not a place you go.","You can think yourself into anxiety. Breath is the way back.","Stillness is not a reward. It's a tool.","The shortest path to your next deep-work session is one slow exhale.","Recovery is a feature, not an absence of work.","Discomfort is data. So is calm.","Sixty seconds well spent beats six hours fighting yourself.","Your nervous system runs the show. Be a good operator.","The body is not the enemy of focus. It's the substrate.","There is no app version of slowing down.","You don't ship better code by gripping harder.","Breathe in for what is. Out for what was.","The vagus nerve doesn't care how busy your calendar is.","Forty-five seconds. Then back to the work.","The interval between thoughts is where insight lives.","The breath is the only autonomic system you can drive."];function Cr(e){let t=Number.isFinite(e)?Math.max(0,Math.floor(e)):0;return kr[t%kr.length]}var Er=60,gi=28,hi=18;function fe(e,t){return` ${f(e.padEnd(hi))} ${t}`}function _r(e,t,n){return`${e} ${e===1?t:n}`}function wi(e){let t=` ${N("\u2740")} ${R("SUMMARY_REPORT")}`,n=fe("PROTOCOL",m(e.protocolDisplayName)),r=fe("DURATION",m(`${e.duration}s`)),o=fe("GUIDE",m(e.voice)),s=e.rounds!=null?fe("ROUNDS",m(String(e.rounds))):null,i=fe("TODAY",m(_r(e.sessionsToday,"session","sessions"))),a=e.streakDays!=null?fe("STREAK",m(_r(e.streakDays,"day","days"))):null,u=m("\u2588".repeat(gi)),c=` ${f("INTEGRATION_SYNC")} [${u}] ${m("100%")}`,l=Cr(e.totalSessions),d=F(f(`"${l}"`),Er);return H(["",t,"",n,r,o,s,"",i,a,"",c,"",d,""].filter(S=>S!==null),Er)}function Rr(e,t=process.stdout){let n=wi(e);for(let r of n)t.write(r+`
21
+ `);return n.length}function Si(){let e=N("\u25C6"),t=`[${m("r")}] repeat`,n=`[${m("n")}] new session`,r=`[${m("x")}] exit`;return` ${e} ${t} ${f("\xB7")} ${n} ${f("\xB7")} ${r}`}var vr=2;async function Ir(e){e.setRawMode?.(!0),e.out.write(`
22
+ `+Si()+`
23
+ `);try{for(;;){let t=await e.keys.next();if(t.done)return"exit";let n=t.value;if(n.name==="ctrl-c"||n.name==="escape")return"exit";if(n.name==="char"){let r=(n.char??"").toLowerCase();if(r==="r")return"repeat";if(r==="n")return"new";if(r==="x"||r==="q")return"exit"}}}finally{e.setRawMode?.(!1),await e.keys.return?.()}}function $r(){let e=process.stdin;return{out:process.stdout,setRawMode:n=>{e.isTTY&&e.setRawMode(n)},keys:yi(e)}}function yi(e){e.resume();let t=[],n=[],r=!1,o=i=>{let a=Buffer.isBuffer(i)?i:Buffer.from(i),u=W(a);for(let c of u){let l=n.shift();l?l(c):t.push(c)}},s=()=>{for(r=!0;n.length;)n.shift()(null)};return e.on("data",o),e.once("end",s),{async next(){return t.length?{value:t.shift(),done:!1}:r?{value:void 0,done:!0}:new Promise(i=>{n.push(a=>{i(a===null?{value:void 0,done:!0}:{value:a,done:!1})})})},async return(){return e.off("data",o),e.off("end",s),e.pause(),{value:void 0,done:!0}}}}import{existsSync as ki,mkdirSync as Ci,writeFileSync as Ei}from"fs";import{homedir as _i,platform as Ri}from"os";import{join as He}from"path";var Or="welcomed";function It(){let e=_i();return Ri()==="win32"?He(e,"AppData","Roaming","flowe"):He(e,".config","flowe")}function vi(){return["","flowe-cli installed.","","Try it:"," flowe reset interactive picker (pick duration + protocol)"," flowe reset 60 quick 60-second reset, random protocol"," flowe protocols list all 12 protocols","","Docs: https://cli.flowe.ai/docs/",""].join(`
24
+ `)}function Ii(e=It()){return ki(He(e,Or))}function $i(e=It()){Ci(e,{recursive:!0}),Ei(He(e,Or),"","utf-8")}function Pr(e=process.stderr){try{let t=It();if(Ii(t))return;e.write(vi()),$i(t)}catch{}}var Tr=e=>`\x1B[${e}A`,Ti="\x1B[2K";function xi(e,t){if(t<=0)return;let n=Tr(t);for(let r=0;r<t;r++)n+=`\r${Ti}
25
+ `;n+=Tr(t),e.write(n)}function Ai(e){switch(e){case"auth_required":return 2;case"agent_busy":return 3;case"network_error":case"offline":return 4;default:return 1}}function j(e){let t=e,n=t?.message||String(e);process.stderr.write(`flowe: ${n}
26
+ `),process.exit(Ai(t?.code))}function Mi(e){return Array.isArray(e)?e.join(" ").trim():(e??"").trim()}function Pt(e){let t=typeof e=="number"?e:parseInt(e,10);if(t===30||t===45||t===60||t===90)return t;throw Object.assign(new Error("duration must be 30, 45, 60, or 90"),{code:"invalid_duration"})}function $t(e){if(We.includes(e))return e;throw Object.assign(new Error(`type must be one of: ${We.join(", ")}`),{code:"invalid_duration"})}function Ni(e){if(Je.includes(e))return e;throw Object.assign(new Error(`type must be one of: ${Je.join(", ")}`),{code:"invalid_duration"})}function Ot(e){if(e==="sage"||e==="ada"||e==="ellie")return e;throw Object.assign(new Error("voice must be sage, ada, or ellie"),{code:"invalid_duration"})}function Bi(e){let t=jt();if(t.includes(e))return e;throw Object.assign(new Error(`unknown protocol "${e}" \u2014 available: ${t.join(", ")}`),{code:"invalid_duration"})}async function Di(e=2e3){let t=tt().catch(()=>null),n=new Promise(r=>setTimeout(()=>r(null),e));return Promise.race([t,n])}async function xr(e,t){let n=q(),r=await V();r&&!n.user_first_name&&(await Di(),n=q());let o=un(n.user_first_name),s=60;if(e)try{s=Pt(e)}catch{}let i=t?Xe(t):void 0,a=await ln({defaultDuration:s,defaultVoice:n.voice,greeting:o,showAuthWedge:!r,availableDurations:i,signIn:async()=>{let{runLogin:u}=await import("./login-Q4QMATEN.js");await u(),await tt()},clearOnExit:!0});return a?{duration:a.duration,voice:a.voice,family:t}:null}async function Li(e,t){if(t){let r=Xe(t);if(e===void 0&&r.length===1)return{duration:r[0],family:t};if(e===void 0)throw Object.assign(new Error(`protocol "${t}" supports multiple durations (${r.join(", ")}s) \u2014 pass one as: flowe reset <duration> --protocol ${t}`),{code:"invalid_duration"});let o=Pt(e);if(!r.includes(o))throw Object.assign(new Error(`protocol "${t}" has no ${o}s variant \u2014 available: ${r.join(", ")}s`),{code:"invalid_duration"});return{duration:o,family:t}}return{duration:Pt(e??60)}}async function Fi(){if(tn()){let t=en(),n=await Gn({preset:t.preset,ambientFilePath:t.ambientFilePath,ambientId:t.ambientId??null,breakType:t.breakType,longBreakType:t.longBreakType,notifications:process.env.FLOWE_FOCUS_NO_NOTIFICATIONS!=="1"});process.exit(n.reason==="busy"?1:0)}process.argv[2]!=="mcp"&&Pr();let e=Oi("flowe");e.command("reset [duration]","Run a micro-reset (30, 45, 60, or 90 seconds)").option("--trigger <trigger>","why this reset fired",{default:"user_requested"}).option("-q, --quick","skip the interactive picker and run with the given duration").option("--protocol <family>","restrict to a specific protocol family (e.g., physiological_sigh, box_breath)").action(async(t,n)=>{try{let r=n.trigger,o=n.protocol?Bi(n.protocol):void 0,i=!n.quick&&dn()?await xr(t,o):await Li(t,o);if(!i)return;for(;;){i.voice&&Qe(i.voice);let a=await Yt(i.duration,r,i.family),u=Ze();if(_n()&&u){await En({duration:a.duration_seconds,voice:a.voice,displayName:a.protocol_display_name,cues:a.cues,rounds:a.rounds,donePromise:u}),ze();let c=Rr({protocolDisplayName:a.protocol_display_name,duration:a.duration_seconds,voice:a.voice,rounds:a.rounds,sessionsToday:Lt(),totalSessions:Kt(),streakDays:Ft()});if(n.quick)return;let l=await Ir($r());if(l==="exit")return;if(xi(process.stdout,c+vr),l==="repeat")continue;if(l==="new"){let d=await xr(void 0,i.family);if(!d)return;i=d;continue}return}process.stdout.write(`${a.message_for_user}
27
27
  `);for(let c of a.cues)process.stdout.write(` \xB7 ${c.label}
28
- `);u&&(await u,Qe());return}}catch(r){H(r)}}),e.command("quick [type]","Start a real authenticated Flowe Quick Reset (5\u201315 min live AI voice session)").option("--voice <name>","override guide voice (ellie, ada, sage)").option("--ambient <id>","ambient soundscape id (default: none)").option("--open","open the live session in your browser automatically").action(async(t,n)=>{try{let r=t?It(t):"quick_reset",o=n.voice?Pt(n.voice):void 0,{createAndStartLiveSession:s}=await import("./session-client-74I2RBYA.js"),i=await s({tier:"quick",sessionType:r,voice:o,ambient:n.ambient});if(process.stdout.isTTY&&(await import("qrcode-terminal")).default.generate(i.join_url,{small:!0}),process.stdout.write(`${i.message_for_user}
28
+ `);u&&(await u,ze());return}}catch(r){j(r)}}),e.command("quick [type]","Start a real authenticated Flowe Quick Reset (5\u201315 min live AI voice session)").option("--voice <name>","override guide voice (ellie, ada, sage)").option("--ambient <id>","ambient soundscape id (default: none)").option("--open","open the live session in your browser automatically").action(async(t,n)=>{try{let r=t?$t(t):"quick_reset",o=n.voice?Ot(n.voice):void 0,{createAndStartLiveSession:s}=await import("./session-client-2SS65HUQ.js"),i=await s({tier:"quick",sessionType:r,voice:o,ambient:n.ambient});if(process.stdout.isTTY&&(await import("qrcode-terminal")).default.generate(i.join_url,{small:!0}),process.stdout.write(`${i.message_for_user}
29
29
  `),process.stdout.write(` mobile/desktop: ${i.join_url}
30
- `),n.open){let{spawn:a}=await import("child_process"),u=process.platform==="darwin"?"open":process.platform==="win32"?"cmd":"xdg-open",c=process.platform==="win32"?["/c","start",'""',i.web_url]:[i.web_url];a(u,c,{detached:!0,stdio:"ignore"}).unref()}}catch(r){H(r)}}),e.command("deep [type]","Start a real authenticated Flowe Deep Reset (15\u201325 min interactive voice session)").option("--voice <name>","override guide voice (ellie, ada, sage)").option("--ambient <id>","ambient soundscape id (default: none)").option("--open","open the live session in your browser automatically").action(async(t,n)=>{try{let r=t?Pi(t):"ht_stress",o=n.voice?Pt(n.voice):void 0,{createAndStartLiveSession:s}=await import("./session-client-74I2RBYA.js"),i=await s({tier:"deep",sessionType:r,voice:o,ambient:n.ambient});if(process.stdout.isTTY&&(await import("qrcode-terminal")).default.generate(i.join_url,{small:!0}),process.stdout.write(`${i.message_for_user}
30
+ `),n.open){let{spawn:a}=await import("child_process"),u=process.platform==="darwin"?"open":process.platform==="win32"?"cmd":"xdg-open",c=process.platform==="win32"?["/c","start",'""',i.web_url]:[i.web_url];a(u,c,{detached:!0,stdio:"ignore"}).unref()}}catch(r){j(r)}}),e.command("deep [type]","Start a Flowe Deep Reset (30\u201350 min, two-way voice with Ada; Flowe Pro or a team plan)").option("--voice <name>","override guide voice (ellie, ada, sage)").option("--ambient <id>","ambient soundscape id (default: none)").option("--open","open the live session in your browser automatically").action(async(t,n)=>{try{let r=t?Ni(t):"ht_stress",o=n.voice?Ot(n.voice):void 0,{createAndStartLiveSession:s}=await import("./session-client-2SS65HUQ.js"),i=await s({tier:"deep",sessionType:r,voice:o,ambient:n.ambient});if(process.stdout.isTTY&&(await import("qrcode-terminal")).default.generate(i.join_url,{small:!0}),process.stdout.write(`${i.message_for_user}
31
31
  `),process.stdout.write(` mobile/desktop: ${i.join_url}
32
- `),n.open){let{spawn:a}=await import("child_process"),u=process.platform==="darwin"?"open":process.platform==="win32"?"cmd":"xdg-open",c=process.platform==="win32"?["/c","start",'""',i.web_url]:[i.web_url];a(u,c,{detached:!0,stdio:"ignore"}).unref()}}catch(r){H(r)}}),e.command("nsdr [type]","Start an NSDR Quick Reset session (default: quick_reset; or pass a Core 8 type)").action(async t=>{try{let n=t?It(t):"quick_reset",r=await rn(n);process.stdout.write(`${r.message_for_user}
33
- `)}catch(n){H(n)}}),e.command("break [type]","Stream and play a 5- or 15-minute NSDR reset (default: quick_reset)").option("--duration <minutes>","session length: 5 or 15",{default:"5"}).option("--voice <name>","override the configured voice (sage, ada, ellie)").action(async(t,n)=>{try{let r=t?It(t):"quick_reset",o=parseInt(n.duration,10);if(o!==5&&o!==15)throw Object.assign(new Error("--duration must be 5 or 15"),{code:"invalid_duration"});let s=n.voice?n.voice==="sage"||n.voice==="ada"||n.voice==="ellie"?n.voice:(()=>{throw Object.assign(new Error("--voice must be sage, ada, or ellie"),{code:"invalid_duration"})})():void 0,i=new AbortController,a=()=>i.abort();process.on("SIGINT",a),process.stdout.write(` ${r} \xB7 ${o}min \xB7 ${s??G().voice}
34
- `);let u=await se({type:r,durationMin:o,voice:s,signal:i.signal});process.stdout.write(` playing\u2026 (Ctrl-C to stop)
32
+ `),n.open){let{spawn:a}=await import("child_process"),u=process.platform==="darwin"?"open":process.platform==="win32"?"cmd":"xdg-open",c=process.platform==="win32"?["/c","start",'""',i.web_url]:[i.web_url];a(u,c,{detached:!0,stdio:"ignore"}).unref()}}catch(r){j(r)}}),e.command("nsdr [type]","Start an NSDR Quick Reset session (default: quick_reset; or pass a Core 8 type)").action(async t=>{try{let n=t?$t(t):"quick_reset",r=await rn(n);process.stdout.write(`${r.message_for_user}
33
+ `)}catch(n){j(n)}}),e.command("break [type]","Stream and play a 5- or 15-minute NSDR reset (default: quick_reset)").option("--duration <minutes>","session length: 5 or 15",{default:"5"}).option("--voice <name>","override the configured voice (sage, ada, ellie)").action(async(t,n)=>{try{let r=t?$t(t):"quick_reset",o=parseInt(n.duration,10);if(o!==5&&o!==15)throw Object.assign(new Error("--duration must be 5 or 15"),{code:"invalid_duration"});let s=n.voice?n.voice==="sage"||n.voice==="ada"||n.voice==="ellie"?n.voice:(()=>{throw Object.assign(new Error("--voice must be sage, ada, or ellie"),{code:"invalid_duration"})})():void 0,i=new AbortController,a=()=>i.abort();process.on("SIGINT",a),process.stdout.write(` ${r} \xB7 ${o}min \xB7 ${s??q().voice}
34
+ `);let u=await ie({type:r,durationMin:o,voice:s,signal:i.signal});process.stdout.write(` playing\u2026 (Ctrl-C to stop)
35
35
  `);try{await u.finished,process.stdout.write(` done.
36
- `)}catch(c){throw u.cancel(),c}finally{process.off("SIGINT",a)}}catch(r){H(r)}}),e.command("focus [preset]","Run a focus cycle (pomodoro | dev | ultradian | test2 | test5) or control a running daemon (pause | resume | skip | quit | status | attach | menubar)").option("--detach","run the cycle in the background and return to your shell").option("--attach","connect a TUI to a daemon already running in the background").option("--json","machine-readable JSON (pairs with `focus status`)").option("--ambient <id>",'preselect ambient sound (use "none" for silence) \u2014 skips the picker. Used by the SwiftBar Start actions so a click starts a session immediately, no Terminal needed.').option("--flowe-bin <path>","absolute path to the flowe binary (passed by the SwiftBar plugin)").option("--node-bin <path>","absolute path to the node binary (passed by the SwiftBar plugin)").action(async(t,n)=>{try{if(t==="pause"||t==="resume"||t==="skip"||t==="quit"){let d=t;try{$e(d),process.stdout.write(`sent: ${d}
36
+ `)}catch(c){throw u.cancel(),c}finally{process.off("SIGINT",a)}}catch(r){j(r)}}),e.command("focus [preset]","Run a focus cycle (pomodoro | dev | ultradian | test2 | test5) or control a running daemon (pause | resume | skip | quit | status | attach | menubar)").option("--detach","run the cycle in the background and return to your shell").option("--attach","connect a TUI to a daemon already running in the background").option("--json","machine-readable JSON (pairs with `focus status`)").option("--ambient <id>",'preselect ambient sound (use "none" for silence) \u2014 skips the picker. Used by the SwiftBar Start actions so a click starts a session immediately, no Terminal needed.').option("--flowe-bin <path>","absolute path to the flowe binary (passed by the SwiftBar plugin)").option("--node-bin <path>","absolute path to the node binary (passed by the SwiftBar plugin)").action(async(t,n)=>{try{if(t==="pause"||t==="resume"||t==="skip"||t==="quit"){let d=t;try{$e(d),process.stdout.write(`sent: ${d}
37
37
  `)}catch(w){process.stderr.write(`${w.message}
38
- `),process.exit(1)}return}if(t==="status"){let d=fe();if(d===null){if(n.json){process.stdout.write(`${JSON.stringify({active:!1})}
38
+ `),process.exit(1)}return}if(t==="status"){let d=pe();if(d===null){if(n.json){process.stdout.write(`${JSON.stringify({active:!1})}
39
39
  `);return}process.stderr.write(`no active focus session
40
40
  `),process.exit(1)}n.json?process.stdout.write(`${JSON.stringify(d)}
41
- `):process.stdout.write(`${Vn(d)}
42
- `);return}if(t==="menubar"){let d=n.floweBin??"flowe",w=fe();process.stdout.write(`${Qn(w,{floweBinary:d,nodeBinary:n.nodeBin})}
43
- `);return}if(t==="attach"||n.attach){if(n.detach)throw Object.assign(new Error("--attach and --detach cannot be used together"),{code:"invalid_duration"});if(t!==void 0&&t!=="attach")throw Object.assign(new Error("attach connects to an existing cycle; do not pass a preset"),{code:"invalid_duration"});let d=await Wn();process.exit(d.reason==="no_session"?1:0)}let r=[],o;if(t===void 0){if(o=await Ln(),o===null)return}else if(t==="pomodoro"||t==="dev"||t==="ultradian"||t==="test2"||t==="test5")o=t;else throw Object.assign(new Error(`preset must be one of: ${Object.keys(U).join(", ")}`),{code:"invalid_duration"});r.push({label:"preset",value:`${o} \xB7 ${yt(o)}`});let s=await Ze().catch(()=>null),{loadCustomAmbientManifest:i,mergeAmbientManifests:a}=await import("./ambient-RIFETQIW.js"),u=a(s,i()),c;if(n.ambient!==void 0)if(n.ambient==="none"||n.ambient==="")c={sound:null};else{let d=u?.sounds.find(w=>w.id===n.ambient);if(!d)throw Object.assign(new Error(`unknown ambient id: ${n.ambient}. Run \`flowe focus\` to pick interactively.`),{code:"invalid_duration"});c={sound:d}}else c=await Kn({manifest:u,breadcrumbs:r});if(c===null)return;r.push({label:"ambient",value:c.sound?.name??"silence"});let m=await Un({sound:c.sound,breadcrumbs:r});if(n.detach)try{let d=Zt({preset:o,ambientFilePath:m.filePath??void 0,ambientId:c.sound?.id});process.stdout.write(nn(d)+`
41
+ `):process.stdout.write(`${Wn(d)}
42
+ `);return}if(t==="menubar"){let d=n.floweBin??"flowe",w=pe();process.stdout.write(`${zn(w,{floweBinary:d,nodeBinary:n.nodeBin})}
43
+ `);return}if(t==="attach"||n.attach){if(n.detach)throw Object.assign(new Error("--attach and --detach cannot be used together"),{code:"invalid_duration"});if(t!==void 0&&t!=="attach")throw Object.assign(new Error("attach connects to an existing cycle; do not pass a preset"),{code:"invalid_duration"});let d=await Jn();process.exit(d.reason==="no_session"?1:0)}let r=[],o;if(t===void 0){if(o=await Kn(),o===null)return}else if(t==="pomodoro"||t==="dev"||t==="ultradian"||t==="test2"||t==="test5")o=t;else throw Object.assign(new Error(`preset must be one of: ${Object.keys(U).join(", ")}`),{code:"invalid_duration"});r.push({label:"preset",value:`${o} \xB7 ${yt(o)}`});let s=await et().catch(()=>null),{loadCustomAmbientManifest:i,mergeAmbientManifests:a}=await import("./ambient-RIFETQIW.js"),u=a(s,i()),c;if(n.ambient!==void 0)if(n.ambient==="none"||n.ambient==="")c={sound:null};else{let d=u?.sounds.find(w=>w.id===n.ambient);if(!d)throw Object.assign(new Error(`unknown ambient id: ${n.ambient}. Run \`flowe focus\` to pick interactively.`),{code:"invalid_duration"});c={sound:d}}else c=await Un({manifest:u,breadcrumbs:r});if(c===null)return;r.push({label:"ambient",value:c.sound?.name??"silence"});let l=await jn({sound:c.sound,breadcrumbs:r});if(n.detach)try{let d=Zt({preset:o,ambientFilePath:l.filePath??void 0,ambientId:c.sound?.id});process.stdout.write(nn(d)+`
44
44
  `);return}catch(d){throw d instanceof Xt&&(process.stderr.write(`${d.message}
45
45
  use \`flowe focus status\` or \`flowe focus quit\` first
46
- `),process.exit(1)),d}await jn({preset:o,ambientFilePath:m.filePath??void 0,ambientId:c.sound?.id??null,breadcrumbs:r})}catch(r){H(r)}}),e.command("sound [intent]","Play a Flowescape (focus | deep-work | settle | sleep)").option("--for <duration>","timer: 25m, 90m, 1h, or infinite").option("--scene <id>","choose a scene from the ambient manifest").option("--json","machine-readable selection").option("--dry-run","show the resolved room without downloading or playing audio").action(async(t,n)=>{try{let r=mr(t),o=je(r),s=pr(n.for),i=s===void 0?o.defaultMinutes:s;if(n.dryRun){let d={intent:r,label:o.label,scene:n.scene??o.defaultScene,minutes:i,modulation:o.modulation,playing:!1};process.stdout.write(n.json?`${JSON.stringify(d)}
46
+ `),process.exit(1)),d}await qn({preset:o,ambientFilePath:l.filePath??void 0,ambientId:c.sound?.id??null,breadcrumbs:r})}catch(r){j(r)}}),e.command("sound [intent]","Play a Flowescape (focus | deep-work | settle | sleep)").option("--for <duration>","timer: 25m, 90m, 1h, or infinite").option("--scene <id>","choose a scene from the ambient manifest").option("--json","machine-readable selection").option("--dry-run","show the resolved room without downloading or playing audio").action(async(t,n)=>{try{let r=pr(t),o=qe(r),s=br(n.for),i=s===void 0?o.defaultMinutes:s;if(n.dryRun){let d={intent:r,label:o.label,scene:n.scene??o.defaultScene,minutes:i,modulation:o.modulation,playing:!1};process.stdout.write(n.json?`${JSON.stringify(d)}
47
47
  `:`${Rt(r,i,d.scene)}
48
- `);return}let a=await Ze(),u=br(a.sounds,r,n.scene);if(!u)throw new Error("no soundscape scenes are currently available");if(n.scene&&u.id!==n.scene)throw new Error(`unknown scene: ${n.scene}`);let c=await Ce(u),m=oe(c,{volume:gr(o.modulation)});n.json?process.stdout.write(`${JSON.stringify({intent:r,scene:u.id,minutes:i,modulation:o.modulation,playing:!0})}
48
+ `);return}let a=await et(),u=gr(a.sounds,r,n.scene);if(!u)throw new Error("no soundscape scenes are currently available");if(n.scene&&u.id!==n.scene)throw new Error(`unknown scene: ${n.scene}`);let c=await Ee(u),l=se(c,{volume:hr(o.modulation)});n.json?process.stdout.write(`${JSON.stringify({intent:r,scene:u.id,minutes:i,modulation:o.modulation,playing:!0})}
49
49
  `):process.stdout.write(`${Rt(r,i,u.name)}
50
- `),await new Promise(d=>{let w,E=()=>{w&&clearTimeout(w),process.off("SIGINT",E),m.stop(),d()};process.on("SIGINT",E),i!==null&&(w=setTimeout(E,i*6e4))})}catch(r){H(r)}}),e.command("status","Show config and queue state").action(()=>{let t=G();process.stdout.write(Sr()+`
50
+ `),await new Promise(d=>{let w,S=()=>{w&&clearTimeout(w),process.off("SIGINT",S),l.stop(),d()};process.on("SIGINT",S),i!==null&&(w=setTimeout(S,i*6e4))})}catch(r){j(r)}}),e.command("status","Show config and queue state").action(()=>{let t=q();process.stdout.write(yr()+`
51
51
 
52
52
  `),process.stdout.write(`voice: ${t.voice}
53
53
  `),process.stdout.write(`backend: ${t.backend_url}
54
54
  `),process.stdout.write(`telemetry: ${t.telemetry}
55
55
  `),process.stdout.write(`first_reset_at: ${t.first_reset_at??"(none yet)"}
56
- `)}),e.command("voice [name]","Set preferred voice (sage, ada, or ellie)").action(t=>{if(!t){process.stdout.write(`current: ${G().voice}
56
+ `)}),e.command("voice [name]","Set preferred voice (sage, ada, or ellie)").action(t=>{if(!t){process.stdout.write(`current: ${q().voice}
57
57
  available: sage, ada, ellie
58
- `);return}try{let n=Pt(t);Je(n),process.stdout.write(`voice set to ${n}
59
- `)}catch(n){H(n)}}),e.command("protocols","List bundled reset protocols").action(()=>{let t=Ut();if(t.length===0){process.stdout.write(`(no protocols bundled yet)
58
+ `);return}try{let n=Ot(t);Qe(n),process.stdout.write(`voice set to ${n}
59
+ `)}catch(n){j(n)}}),e.command("protocols","List bundled reset protocols").action(()=>{let t=Ut();if(t.length===0){process.stdout.write(`(no protocols bundled yet)
60
60
  `);return}for(let n of t)process.stdout.write(`${n.duration_seconds}s ${n.protocol_id.padEnd(24)} ${n.display_name}
61
- `)}),e.command("login","Sign in with Clerk (device-grant flow)").action(async()=>{try{let{runLogin:t}=await import("./login-Q4QMATEN.js");await t()}catch(t){H(t)}}),e.command("logout","Sign out and clear stored token").action(async()=>{await Gt(),process.stdout.write(`signed out
62
- `)}),e.command("whoami","Show current auth status and Flowe plan").action(async()=>{if(!await W()){process.stdout.write(`not signed in \u2014 run: flowe login
63
- `);return}try{let{fetchAccountStatus:n}=await import("./session-client-74I2RBYA.js"),r=await n();if(!r.authenticated){process.stdout.write(`session expired \u2014 run: flowe login
64
- `);return}let o=r.first_name?`${r.first_name}${r.email?` (${r.email})`:""}`:r.email??"signed in",s=r.is_pro?"Flowe Pro":r.plan_type;if(process.stdout.write(`signed in \xB7 ${o} \xB7 ${s}
65
- `),r.quick_reset_quota&&r.quick_reset_quota.cap>0){let i=Math.max(0,r.quick_reset_quota.cap-r.quick_reset_quota.used);process.stdout.write(`quick resets: ${i} of ${r.quick_reset_quota.cap} free left this week
61
+ `)}),e.command("login","Sign in with Clerk (device-grant flow)").action(async()=>{try{let{runLogin:t}=await import("./login-Q4QMATEN.js");await t()}catch(t){j(t)}}),e.command("logout","Sign out and clear stored token").action(async()=>{await Gt(),process.stdout.write(`signed out
62
+ `)}),e.command("whoami","Show current auth status and Flowe plan").action(async()=>{if(!await V()){process.stdout.write(`not signed in \u2014 run: flowe login
63
+ `);return}try{let{fetchAccountStatus:n,teamLine:r}=await import("./session-client-2SS65HUQ.js"),o=await n();if(!o.authenticated){process.stdout.write(`session expired \u2014 run: flowe login
64
+ `);return}let s=o.first_name?`${o.first_name}${o.email?` (${o.email})`:""}`:o.email??"signed in",i=o.is_pro?"Flowe Pro":o.plan_type;process.stdout.write(`signed in \xB7 ${s} \xB7 ${i}
65
+ `);let a=r(o);if(a&&process.stdout.write(`${a}
66
+ `),o.quick_reset_quota&&o.quick_reset_quota.cap>0){let u=Math.max(0,o.quick_reset_quota.cap-o.quick_reset_quota.used);process.stdout.write(`quick resets: ${u} of ${o.quick_reset_quota.cap} free left this week
66
67
  `)}}catch{process.stdout.write(`signed in
67
68
  `)}}),e.command("setup [harness]","Configure Flowe MCP Apps for Claude Desktop, Claude Code, Antigravity, Codex, Cursor, or VS Code").option("--write","write the config directly to the harness config file").option("--dry-run","preview the merged config without writing").action(async(t,n)=>{try{let{HARNESS_IDS:r,resolveHarnessTargets:o,buildHarnessSnippet:s,applyHarnessConfig:i}=await import("./setup-harness-RR77VO5C.js"),a=o();if(!t){process.stdout.write(`Available harnesses for Flowe MCP:
68
69
 
69
- `);for(let c of r){let m=a[c],d=m.supportsMcpApps?"MCP Apps UI":"CLI / text";process.stdout.write(` ${c.padEnd(16)} ${m.label.padEnd(18)} [${d}] ${m.configPath}
70
+ `);for(let c of r){let l=a[c],d=l.supportsMcpApps?"MCP Apps UI":"CLI / text";process.stdout.write(` ${c.padEnd(16)} ${l.label.padEnd(18)} [${d}] ${l.configPath}
70
71
  `)}process.stdout.write("\nRun `flowe setup <harness>` to print config, or `flowe setup <harness> --write` to install.\n");return}if(!r.includes(t))throw Object.assign(new Error(`unknown harness "${t}" \u2014 available: ${r.join(", ")}`),{code:"invalid_duration"});let u=a[t];if(n.write||n.dryRun){let c=i(u,{dryRun:!!n.dryRun});n.dryRun?process.stdout.write(`# target: ${c.path}
71
72
  ${c.content}`):process.stdout.write(`configured ${u.label}: ${c.path}
72
73
  `);return}process.stdout.write(`# ${u.label} (${u.configPath})
73
74
  `),process.stdout.write(`${s(u)}
74
75
  `),process.stdout.write(`
75
76
  # run \`flowe setup ${u.id} --write\` to merge automatically
76
- `)}catch(r){H(r)}}),e.command("install-mcp","Print MCP config snippet for Claude Code / Cursor").action(()=>{let t={mcpServers:{flowe:{command:"flowe",args:["mcp"]}}};process.stdout.write(JSON.stringify(t,null,2)+`
77
+ `)}catch(r){j(r)}}),e.command("install-mcp","Print MCP config snippet for Claude Code / Cursor").action(()=>{let t={mcpServers:{flowe:{command:"flowe",args:["mcp"]}}};process.stdout.write(JSON.stringify(t,null,2)+`
77
78
  `),process.stdout.write(`
78
79
  # add the above to ~/.config/claude/mcp.json (or your client's equivalent)
79
80
  `)}),e.command("ambient [verb] [...prompt]","Create or list custom focus ambience").option("--name <name>","display name for a generated custom ambience").action(async(t,n,r)=>{try{if(t===void 0||t==="list"){let{loadCustomAmbientManifest:i}=await import("./ambient-RIFETQIW.js"),a=i();if(!a||a.sounds.length===0){process.stdout.write(`no custom ambience saved yet
80
81
  `);return}for(let u of a.sounds)process.stdout.write(`${u.id} ${u.name}
81
- `);return}if(t!=="create")throw Object.assign(new Error("ambient command must be one of: create, list"),{code:"invalid_duration"});let o=Ii(n);if(!o)throw Object.assign(new Error('usage: flowe ambient create "describe the ambience" --name "name"'),{code:"invalid_duration"});process.stdout.write(`generating custom ambience...
82
- `);let s=await wr({prompt:o,name:r.name});process.stdout.write(`saved custom ambience: ${s.sound.name} (${s.sound.id})
82
+ `);return}if(t!=="create")throw Object.assign(new Error("ambient command must be one of: create, list"),{code:"invalid_duration"});let o=Mi(n);if(!o)throw Object.assign(new Error('usage: flowe ambient create "describe the ambience" --name "name"'),{code:"invalid_duration"});process.stdout.write(`generating custom ambience...
83
+ `);let s=await Sr({prompt:o,name:r.name});process.stdout.write(`saved custom ambience: ${s.sound.name} (${s.sound.id})
83
84
  `),process.stdout.write(`start it with: flowe focus --ambient ${s.sound.id}
84
- `)}catch(o){H(o)}}),e.command("install-skill","Install the Claude Code skill so Claude proactively triggers resets during long thinking pauses").option("--print","print SKILL.md to stdout instead of writing a file").option("--force","overwrite an existing skill file").option("--target <path>","write to a custom path instead of ~/.claude/skills/flowe/SKILL.md").action(async t=>{let{installSkill:n,readBundledSkill:r,defaultTarget:o}=await import("./install-skill-5UWJTC26.js");if(t.print){process.stdout.write(r());return}let s=n({target:t.target,force:t.force});s.written||(process.stderr.write(`skill already installed at ${s.target}
85
+ `)}catch(o){j(o)}}),e.command("install-skill","Install the Claude Code skill so Claude proactively triggers resets during long thinking pauses").option("--print","print SKILL.md to stdout instead of writing a file").option("--force","overwrite an existing skill file").option("--target <path>","write to a custom path instead of ~/.claude/skills/flowe/SKILL.md").action(async t=>{let{installSkill:n,readBundledSkill:r,defaultTarget:o}=await import("./install-skill-5UWJTC26.js");if(t.print){process.stdout.write(r());return}let s=n({target:t.target,force:t.force});s.written||(process.stderr.write(`skill already installed at ${s.target}
85
86
  use --force to overwrite, or --target <path> to install elsewhere.
86
87
  `),process.exit(0)),process.stdout.write(`installed: ${s.target}
87
88
  `),t.target||process.stdout.write(`default location: ${o()}
88
89
  restart Claude Code (or open a new session) and Claude will fire flowe resets during long thinking pauses.
89
- `)}),e.command("install-menubar","Install the SwiftBar plugin so an active focus cycle shows in your menubar").option("--flowe-bin <path>","absolute path to flowe (default: this package's bin/flowe.js, then `which flowe`)").option("--plugin-dir <path>","override SwiftBar plugin dir (default: ~/Library/Application Support/SwiftBar/Plugins)").option("--dry-run","render the plugin script and print it instead of writing").option("--skip-swiftbar-check","install just the plugin file without checking for or installing SwiftBar.app").option("--no-launch","do not open SwiftBar after installing the plugin").action(t=>{let n=rr(),r=t.floweBin??(vi(n)?n:or());if(r||(process.stderr.write(`could not locate the flowe binary on PATH.
90
+ `)}),e.command("install-menubar","Install the SwiftBar plugin so an active focus cycle shows in your menubar").option("--flowe-bin <path>","absolute path to flowe (default: this package's bin/flowe.js, then `which flowe`)").option("--plugin-dir <path>","override SwiftBar plugin dir (default: ~/Library/Application Support/SwiftBar/Plugins)").option("--dry-run","render the plugin script and print it instead of writing").option("--skip-swiftbar-check","install just the plugin file without checking for or installing SwiftBar.app").option("--no-launch","do not open SwiftBar after installing the plugin").action(t=>{let n=or(),r=t.floweBin??(Pi(n)?n:sr());if(r||(process.stderr.write(`could not locate the flowe binary on PATH.
90
91
  pass --flowe-bin <abs-path> to override (e.g. /opt/homebrew/bin/flowe).
91
- `),process.exit(1)),!t.dryRun&&!t.skipSwiftbarCheck){let i=ur();i.action==="missing-brew"&&(process.stderr.write(`${cr()}
92
+ `),process.exit(1)),!t.dryRun&&!t.skipSwiftbarCheck){let i=cr();i.action==="missing-brew"&&(process.stderr.write(`${lr()}
92
93
  `),process.exit(1)),i.action==="installed"&&process.stdout.write(`SwiftBar installed via brew.
93
- `)}let o=vt(),s=sr({floweBin:r,pluginDir:t.pluginDir,dryRun:t.dryRun});if(t.dryRun){process.stdout.write(s.scriptContent);return}if(process.stdout.write(`${ar(s)}
94
- `),t.launch!==!1&&!t.skipSwiftbarCheck){let i=s.pluginPath.replace(/\/[^/]+$/,"");o!==i&&er(i),dr()?tr():lr()}}),e.command("uninstall-menubar","Remove the flowe SwiftBar plugin").option("--plugin-dir <path>","override SwiftBar plugin dir").action(t=>{let n=ir({pluginDir:t.pluginDir});process.stdout.write(`${fr(n)}
95
- `)}),e.command("mcp","Run the MCP stdio server (used by Claude Code / Cursor, not humans)").action(async()=>{let{runMcpServer:t}=await import("./mcp-server.js");await t()}),e.help(),e.version(Dt());try{e.parse(process.argv,{run:!1}),await e.runMatchedCommand()}catch(t){H(t)}}xi().catch(H);
94
+ `)}let o=_t(),s=ir({floweBin:r,pluginDir:t.pluginDir,dryRun:t.dryRun});if(t.dryRun){process.stdout.write(s.scriptContent);return}if(process.stdout.write(`${ur(s)}
95
+ `),t.launch!==!1&&!t.skipSwiftbarCheck){let i=s.pluginPath.replace(/\/[^/]+$/,"");o!==i&&tr(i),fr()?nr():dr()}}),e.command("uninstall-menubar","Remove the flowe SwiftBar plugin").option("--plugin-dir <path>","override SwiftBar plugin dir").action(t=>{let n=ar({pluginDir:t.pluginDir});process.stdout.write(`${mr(n)}
96
+ `)}),e.command("mcp","Run the MCP stdio server (used by Claude Code / Cursor, not humans)").action(async()=>{let{runMcpServer:t}=await import("./mcp-server.js");await t()}),e.help(),e.version(Dt());try{e.parse(process.argv,{run:!1}),await e.runMatchedCommand()}catch(t){j(t)}}Fi().catch(j);