@flowe-ai/cli 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -7
- package/dist/chunk-3AO4PCEG.js +5 -0
- package/dist/chunk-B32B6OSK.js +1 -0
- package/dist/{chunk-M56P7SDZ.js → chunk-FXWU7EJA.js} +1 -1
- package/dist/{chunk-JTAA4OAX.js → chunk-LCVEDM2W.js} +1 -1
- package/dist/cli.js +68 -56
- package/dist/{login-IDFOVWCU.js → login-UO2GGRN2.js} +2 -2
- package/dist/mcp-server.js +9 -9
- package/dist/me-3CJ5RYRM.js +1 -0
- package/dist/{session-client-XHJ2MGA5.js → session-client-BR4JJT7O.js} +1 -1
- package/dist/ui/live-session.html +8 -8
- package/dist/ui/micro.html +6 -6
- package/package.json +4 -5
- package/protocols.json +857 -76
- package/skills/flowe/SKILL.md +15 -7
- package/audio/body_scan_60.ada.cues.json +0 -67
- package/audio/body_scan_60.ada.mp3 +0 -0
- package/audio/body_scan_60.ellie.cues.json +0 -67
- package/audio/body_scan_60.ellie.mp3 +0 -0
- package/audio/body_scan_60.sage.cues.json +0 -67
- package/audio/body_scan_60.sage.mp3 +0 -0
- package/audio/box_breath_45.ada.cues.json +0 -103
- package/audio/box_breath_45.ada.mp3 +0 -0
- package/audio/box_breath_45.ellie.cues.json +0 -103
- package/audio/box_breath_45.ellie.mp3 +0 -0
- package/audio/box_breath_45.sage.cues.json +0 -103
- package/audio/box_breath_45.sage.mp3 +0 -0
- package/audio/box_breath_60.ada.cues.json +0 -135
- package/audio/box_breath_60.ada.mp3 +0 -0
- package/audio/box_breath_60.ellie.cues.json +0 -135
- package/audio/box_breath_60.ellie.mp3 +0 -0
- package/audio/box_breath_60.sage.cues.json +0 -135
- package/audio/box_breath_60.sage.mp3 +0 -0
- package/audio/extended_box_90.ada.cues.json +0 -199
- package/audio/extended_box_90.ada.mp3 +0 -0
- package/audio/extended_box_90.ellie.cues.json +0 -199
- package/audio/extended_box_90.ellie.mp3 +0 -0
- package/audio/extended_box_90.sage.cues.json +0 -199
- package/audio/extended_box_90.sage.mp3 +0 -0
- package/audio/eye_rotation_30.ada.cues.json +0 -41
- package/audio/eye_rotation_30.ada.mp3 +0 -0
- package/audio/eye_rotation_30.ellie.cues.json +0 -41
- package/audio/eye_rotation_30.ellie.mp3 +0 -0
- package/audio/eye_rotation_30.sage.cues.json +0 -41
- package/audio/eye_rotation_30.sage.mp3 +0 -0
- package/audio/full_sensory_90.ada.cues.json +0 -60
- package/audio/full_sensory_90.ada.mp3 +0 -0
- package/audio/full_sensory_90.ellie.cues.json +0 -60
- package/audio/full_sensory_90.ellie.mp3 +0 -0
- package/audio/full_sensory_90.sage.cues.json +0 -60
- package/audio/full_sensory_90.sage.mp3 +0 -0
- package/audio/grounded_feet_45.ada.cues.json +0 -40
- package/audio/grounded_feet_45.ada.mp3 +0 -0
- package/audio/grounded_feet_45.ellie.cues.json +0 -40
- package/audio/grounded_feet_45.ellie.mp3 +0 -0
- package/audio/grounded_feet_45.sage.cues.json +0 -40
- package/audio/grounded_feet_45.sage.mp3 +0 -0
- package/audio/neck_rotation_45.ada.cues.json +0 -55
- package/audio/neck_rotation_45.ada.mp3 +0 -0
- package/audio/neck_rotation_45.ellie.cues.json +0 -55
- package/audio/neck_rotation_45.ellie.mp3 +0 -0
- package/audio/neck_rotation_45.sage.cues.json +0 -55
- package/audio/neck_rotation_45.sage.mp3 +0 -0
- package/audio/palming_60.ada.cues.json +0 -61
- package/audio/palming_60.ada.mp3 +0 -0
- package/audio/palming_60.ellie.cues.json +0 -61
- package/audio/palming_60.ellie.mp3 +0 -0
- package/audio/palming_60.sage.cues.json +0 -61
- package/audio/palming_60.sage.mp3 +0 -0
- package/audio/physiological_sigh_30.ada.cues.json +0 -55
- package/audio/physiological_sigh_30.ada.mp3 +0 -0
- package/audio/physiological_sigh_30.ellie.cues.json +0 -55
- package/audio/physiological_sigh_30.ellie.mp3 +0 -0
- package/audio/physiological_sigh_30.sage.cues.json +0 -55
- package/audio/physiological_sigh_30.sage.mp3 +0 -0
- package/audio/progressive_palming_90.ada.cues.json +0 -61
- package/audio/progressive_palming_90.ada.mp3 +0 -0
- package/audio/progressive_palming_90.ellie.cues.json +0 -61
- package/audio/progressive_palming_90.ellie.mp3 +0 -0
- package/audio/progressive_palming_90.sage.cues.json +0 -61
- package/audio/progressive_palming_90.sage.mp3 +0 -0
- package/audio/quick_palming_30.ada.cues.json +0 -40
- package/audio/quick_palming_30.ada.mp3 +0 -0
- package/audio/quick_palming_30.ellie.cues.json +0 -40
- package/audio/quick_palming_30.ellie.mp3 +0 -0
- package/audio/quick_palming_30.sage.cues.json +0 -40
- package/audio/quick_palming_30.sage.mp3 +0 -0
- package/dist/chunk-3KM7AYV7.js +0 -5
- package/dist/chunk-DX2IZG3L.js +0 -1
- package/dist/me-6WIWKE2Q.js +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,66 +1,78 @@
|
|
|
1
|
-
import{a as
|
|
2
|
-
`;if(n>t.length){let o=n-t.length;for(let s=0;s<o;s++)r+=`\r${
|
|
3
|
-
`;r+=
|
|
4
|
-
`;r+=
|
|
5
|
-
`;e.write(r)}async function
|
|
6
|
-
`;t.write(k),
|
|
7
|
-
`;t.write(O)
|
|
8
|
-
`;e.write(o)}function
|
|
9
|
-
`);if(!_
|
|
10
|
-
`;t.write(G),
|
|
11
|
-
`)}function
|
|
12
|
-
`)}function
|
|
13
|
-
`),{reason:"no_session"};let c=[],l=!1,d=null,
|
|
14
|
-
`;t.write(T),
|
|
15
|
-
`)}function
|
|
16
|
-
`)}function
|
|
17
|
-
`)}function
|
|
18
|
-
`)}function
|
|
19
|
-
`)}function
|
|
20
|
-
`)}var
|
|
21
|
-
`);return n.length}function
|
|
22
|
-
|
|
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
|
|
24
|
-
`)}function
|
|
25
|
-
`;n+=
|
|
26
|
-
`),process.exit(
|
|
27
|
-
|
|
28
|
-
`);
|
|
1
|
+
import{A as Zt,B as nt,D as en,E as an,F as un,G as cn,H as ln,I as dn,a as Ut,b as Je,c as Qe,d as Yt,e as Vt,f as Xe,g as Ze,h as Wt,i as Jt,j as _e,k as be,l as Re,m as ve,n as $e,o as Ie,p as Oe,u as et,v as tt,w as zt,x as Xt,y as se}from"./chunk-3AO4PCEG.js";import{d as tn,g as nn,h as rn,i as rt,j as Pe,k as ie,l as on,m as sn}from"./chunk-3TLGYA6M.js";import{b as ot}from"./chunk-FXWU7EJA.js";import{a as q,b as ze,c as jt,h as qt,i as Ht,j as Gt,k as V,m as Qt}from"./chunk-B32B6OSK.js";import{cac as Li}from"cac";import{existsSync as Di}from"fs";import qr from"qrcode-terminal";async function fn(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&&qr.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 Hr}from"fs";import{mkdtemp as Gr,rm as Yr}from"fs/promises";import{tmpdir as Vr}from"os";import{join as mn}from"path";import{pipeline as Wr}from"stream/promises";import{Readable as Jr}from"stream";async function pn(e){let t=await Gr(mn(Vr(),"flowe-stream-")),n=mn(t,"audio.mp3"),r=async()=>{try{await Yr(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=Jr.fromWeb(o.body),c=Hr(n);return u.on("data",l=>{a+=l.length,e.onProgress?.(a,s)}),await Wr(u,c),{filePath:n,cleanup:r,bytes:a,cacheMaxAge:i}}catch(o){throw await r(),o}}function Qr(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 ae(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=Qr(t.backend_url,e.type,r,o),i;if(process.stdout.isTTY){let l=-1;i=(d,f)=>{if(!f){process.stdout.write(`\r fetching ${e.type}\u2026 ${d} bytes`);return}let w=Math.floor(d/f*100);w!==l&&(l=w,process.stdout.write(`\r fetching ${e.type}\u2026 ${w}%`))}}let a=await pn({url:s,headers:{Authorization:`Bearer ${n}`},signal:e.signal,onProgress:i});process.stdout.isTTY&&process.stdout.write("\r\x1B[2K");let c=Wt(a.filePath).finally(()=>a.cleanup());return{started_at:new Date().toISOString(),type:e.type,voice:o,durationMin:r,finished:c,cancel:()=>Jt()}}import cs from"node-notifier";import{fileURLToPath as ls}from"url";import{dirname as ds,join as fs}from"path";var st="\x1B[0m",zr="\x1B[1m",Xr="\x1B[2m",it={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 at(){return process.env.NO_COLOR?!1:process.env.FORCE_COLOR?!0:!!process.stdout.isTTY}function ut(e,t){return at()?`\x1B[38;2;${e.r};${e.g};${e.b}m${t}${st}`:t}var p=e=>ut(it.oak,e),N=e=>ut(it.oakDeep,e),bn=e=>ut(it.sage,e);var m=e=>at()?`${Xr}${e}${st}`:e,v=e=>at()?`${zr}${e}${st}`:e;var Zr=/\x1b\[[0-9;]*m/g,Q={tl:"\u256D",tr:"\u256E",bl:"\u2570",br:"\u256F",h:"\u2500",v:"\u2502"};function ct(e){return e.replace(Zr,"").length}function z(e,t){let n=ct(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=ct(e);if(n>=t)return e;let r=Math.floor((t-n)/2);return" ".repeat(r)+e}var eo=54;function ft(e,t=eo){return H(e,t)}function to(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 gn(e,t=new Date){let n=to(t),r=(e??"").trim(),o=r.length>0?r:"there";return`${n}, ${o}.`}function Te(e,t){let n=t?p("\u25B8 "):" ",r=t?v(p(e.label)):e.label,o=e.detail?" "+m("\xB7 "+e.detail):"";return` ${n}${r}${o}`}function mt(e){let t=p("\u2713"),n=m(e.label.toUpperCase().padEnd(8)),r=p(e.value);return` ${t} ${n} ${r}`}function pt(e){return e.length===0?[]:[...e.map(mt),""]}var hn=" \u2191\u2193 to move \u23CE to select esc to cancel",no=" \u2191\u2193 to move \u23CE to select esc to back",bt=[30,45,60,90],xe=[{id:"ellie",description:"warm, even pace"},{id:"sage",description:"grounded, low"},{id:"ada",description:"clear, neutral"}];function ro(e,t=[]){return ft(["",...pt(t),` ${N("\u25C6")} you're not signed in.`,""," sign in to track your progress, build a streak,"," and personalize your sessions.","",Te({label:"SIGN IN"},e===0),Te({label:"MAYBE LATER",detail:"anonymous"},e===1),"",m(hn),""])}function oo(e,t,n=[],r=bt){return ft(["",...pt(n),` ${t}`," What's the cadence for today?","",...r.map((o,s)=>Te({label:`${o} seconds`},s===e)),"",m(hn),""])}function so(e,t=[]){return ft(["",...pt(t)," Pick your guide.","",...xe.map((n,r)=>Te({label:n.id,detail:n.description},r===e)),"",m(no),""])}var Ae=e=>`\x1B[${e}A`,dt="\x1B[2K",io="\x1B[?25l",ao="\x1B[?25h";function uo(e,t,n){let r="";n>0&&(r+=Ae(n));for(let o of t)r+=`\r${dt}${o}
|
|
2
|
+
`;if(n>t.length){let o=n-t.length;for(let s=0;s<o;s++)r+=`\r${dt}
|
|
3
|
+
`;r+=Ae(o)}e.write(r)}function co(e,t=bt){let n=t.indexOf(e);if(n>=0)return n;let r=t.indexOf(60);return r>=0?r:0}function lo(e){let t=xe.findIndex(n=>n.id===e);return t>=0?t:0}async function lt(e,t,n,r,o,s){let i=n,a=()=>{let u=o(i);uo(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 wn(e){let t=e.io??fo();t.setRawMode?.(!0),t.out.write(io);let n={height:0};try{let r="already_authed",o=[];if(e.showAuthWedge){let i=await lt(t,n,0,2,a=>ro(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:bt;for(;;){let i=await lt(t,n,co(e.defaultDuration,s),s.length,u=>oo(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 lt(t,n,lo(e.defaultVoice),xe.length,u=>so(u,o),u=>xe[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(ao),e.clearOnExit&&n.height>0){let r=Ae(n.height);for(let o=0;o<n.height;o++)r+=`\r${dt}
|
|
4
|
+
`;r+=Ae(n.height),t.out.write(r)}await t.keys.return?.()}}function Sn(){return!!process.stdout.isTTY&&!!process.stdin.isTTY&&!process.env.NO_COLOR&&!process.env.CI}function fo(){let e=process.stdin;return{out:process.stdout,setRawMode:n=>{e.isTTY&&e.setRawMode(n)},keys:mo(e)}}function mo(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}},ge=5;function Me(e,t){return{status:"PRE_FLIGHT",blockIndex:0,enteredAtMs:t,pausedAtMs:null,pausedDurationMs:0,preset:e}}function he(e,t){return e.status!=="PRE_FLIGHT"?e:{...e,status:"FOCUS_BLOCK",blockIndex:1,enteredAtMs:t,pausedAtMs:null,pausedDurationMs:0}}function po(e,t){let n=t-e.enteredAtMs;return e.pausedAtMs!==null?e.pausedAtMs-e.enteredAtMs-e.pausedDurationMs:n-e.pausedDurationMs}function Ne(e){switch(e.status){case"FOCUS_BLOCK":return e.preset.focusSec;case"TRANSITION":return ge;case"BREAK":return e.preset.breakSec;case"LONG_BREAK":return e.preset.longBreakSec;default:return 0}}function J(e,t){let n=Ne(e),r=Math.floor(po(e,t)/1e3);return Math.max(0,n-r)}function yn(e,t,n){return{...e,status:t,blockIndex:t==="FOCUS_BLOCK"?e.blockIndex+1:e.blockIndex,enteredAtMs:n,pausedAtMs:null,pausedDurationMs:0}}function kn(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 Be(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:yn(e,kn(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:yn(e,kn(e),t.nowMs)}}function Le(e,t){return e.status!==t.status||e.blockIndex!==t.blockIndex}var bo=(()=>{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})(),go=[[/\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 Cn(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 go)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 gt(e){return .3+.18*(.5-.5*Math.cos(2*Math.PI*e/9e3))}function En(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+(gt(n)-r)*i}}}function ho(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 wo(e,t=[]){let n=ho(e,t);if(n<0)return{fill:gt(e),light:null,turn:1,band:null,dim:!1};let r=gt(t[0].startMs);for(let l=0;l<n;l+=1)r=En(Cn(t[l]),t[l],t[l].endMs,r);let o=t[n],s=Cn(o),i=En(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 So=[[1,8],[2,16],[4,32],[64,128]];function yo(e){return e>=.8?3:e>=.5?2:e>=.2?1:0}var ko=4;function _n(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,f)=>{let w=Math.floor(l/2),y=Math.floor(d/4);l<0||d<0||w>=r||y>=o||(i[y][w]|=So[d%4][l%2],f>a[y][w]&&(a[y][w]=f))},c=Math.min(1,Math.max(0,e)/1e3,Math.max(0,t)/1e3);if(c>0){let l=wo(e,n.cues??[]),d=r*2,f=o*4,w=(d-1)/2,y=(f-1)/2,E=Math.min(d,f)/2-1,h=E*(.55+(1-.55)*l.fill),k=2*Math.PI*e/26e3,[g,$]=[Math.sin(k),Math.cos(k)],[S,O]=[Math.sin(.42),Math.cos(.42)];bo.forEach((P,_)=>{if(P.seed>=c)return;let T=P.x*$+P.z*g,D=-P.x*g+P.z*$,C=P.y*O-D*S,K=P.y*S+D*O;if(K<-.05&&_%ko!==0)return;let M=yo(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(w+T*h),Math.round(y-C*h),M)});let L=l.light;if(L!==null&&c>=1){let P=Math.min(E+.5,h*1.16);[3,3,3,2,2,1,1,0].forEach((T,D)=>{let C=L-l.turn*D*.13;u(Math.round(w+Math.sin(C)*P),Math.round(y-Math.cos(C)*P),T)})}}return i.map((l,d)=>{let f=[];return l.forEach((w,y)=>{let E=w===0?null:a[d][y],h=" ";if(w!==0)if(s)h=String.fromCharCode(10240+w);else{let g=0;for(let $=w;$;$>>=1)g+=$&1;h=g<=2?"\xB7":g<=4?"\u2022":"\u25CF"}let k=f[f.length-1];k&&k.tone===E?k.text+=h:f.push({text:h,tone:E})}),f})}function Rn(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 _o=100;var vn=28;function Ro(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 vo={0:e=>m(N(e)),1:N,2:p,3:p};function $o(e){return{label:e.label,startMs:e.start_ms,endMs:e.end_ms,mode:e.mode,phase:e.phase}}function ht(e,t,n=[],r=24,o=11){let s=Rn(process.env,process.platform);return _n(e,t,{width:r,height:o,braille:s,cues:n.map($o)}).map(i=>i.map(a=>a.tone===null?a.text:vo[a.tone](a.text)).join(""))}var wt=60;function Io(e){return`${Math.max(0,Math.floor(e))}s`}function Oo(e,t,n){return` ${N("\u2740")} ${v("SESSION_ACTIVE")} ${t}s \xB7 ${e} \xB7 ${m(n)}`}function Po(e){return["",...e.map(t=>F(t,wt)),""]}function To(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 xo(e,t){let n=Ro(t,e);if(n<0)return"";let r=To(e[n].label),o=`[ ${v(p(r))} ]`;return F(o,wt)}function Ao(e,t,n){let r=Math.max(0,Math.min(.999,e/t));return Math.min(n,Math.floor(r*n)+1)}function Mo(e,t,n,r){let o=`${m("TIME_REMAINING")} ${p(`-${Io(e/1e3)}`)}`;if(!r)return` ${o}`;let s=Ao(t,n,r),i=`${m("ROUND")} ${p(`${s} / ${r}`)}`,a=Math.floor(wt/2);return z(` ${o}`,a)+i}function No(e,t){let n=Math.min(1,Math.max(0,e/t)),r=Math.round(n*vn),o=vn-r,s=`${p("\u2588".repeat(r))}${m("\u2591".repeat(o))}`,i=`${Math.round(n*100)}%`;return` ${m("PROGRESS_SEQUENCE")} [${s}] ${m(i)}`}var Bo="\x1B[?25l",$n="\x1B[?25h",Lo=e=>`\x1B[${e}A`,Do="\x1B[H",Fo="\x1B[2K",Ko="\r",Uo="\x1B[?1049h",In="\x1B[?1049l",jo=25;function On(e,t,n){let r=Math.max(0,n-t),o=Po(ht(t,r,e.cues));return{lines:["",...["",Oo(e.displayName,e.duration,e.voice),"",...o,"",xo(e.cues,t),"",Mo(r,t,n,e.rounds),"",No(t,n),""].map(i=>` ${i}`),""]}}function Pn(e,t,n){let r="";n||(r+=Lo(jo));for(let o of t.lines)r+=`${Ko}${Fo}${o}
|
|
5
|
+
`;e.write(r)}async function Tn(e){let t=e.out??process.stdout,n=e.now??Date.now,r=e.startedAt??n(),o=e.duration*1e3;t.write(Uo+Do+Bo);let s=!0,i=!1,a=()=>{if(i)return;let l=n()-r,d=On(e,l,o);Pn(t,d,s),s=!1};a();let u=setInterval(a,_o),c=()=>{i=!0,clearInterval(u),t.write($n+In),process.exit(130)};process.once("SIGINT",c);try{await e.donePromise}finally{i=!0,clearInterval(u),process.removeListener("SIGINT",c);let l=On(e,o,o);Pn(t,l,!1),t.write($n+In)}}function xn(){return!!process.stdout.isTTY&&!process.env.NO_COLOR&&!process.env.CI}var B=60,kt=30,qo=28,Ho=8,Ct=25,Go=Ct+2;function ee(e){return e.length>=Ct?e:[...e,...new Array(Ct-e.length).fill("")]}function we(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 Yo(e,t,n=kt){let r=t<=0?0:Math.max(0,Math.min(1,e/t)),o=Math.round(r*n),s=n-o;return`${p("\u2588".repeat(o))}${m("\u2591".repeat(s))}`}function Vo(e,t){return t<=0?"0%":`${Math.round(e/t*100)}%`}function Wo(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 Nn(e,t){return` ${N("\u2740")} ${v(Wo(e.status))} ${m(t)}`}function te(e){return e.length===0?[]:[...e.map(mt),""]}function Jo(e,t){let n=we(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 Bn(e,t){let n=Jo(e,t);return F(`${p("\u25B8")} ${m(n)}`,B)}function Qo(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 zo(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 Ln(e){let t=Qo(e.preset),n=zo(e,t),r=[];for(let o=0;o<t.length;o++)o<n?r.push(p("\u2713")):o===n?r.push(v(p("\u25B8"))):r.push(m("\xB7"));return r.join(" ")}function Xo(e,t){let n=e.paused&&e.state.pausedAtMs!==null?e.state.pausedAtMs-e.state.enteredAtMs:e.elapsedMs;return ht(n,t*1e3,[],qo,Ho).map(r=>F(e.paused?m(r):r,B))}function Dn(e){let t=`[ ${v(p(e))} ]`;return F(t,B)}function Fn(e,t){let n=Yo(e,t),r=Vo(e,t);return` ${m("PROGRESS_SEQUENCE")} [${n}] ${m(r)}`}function Kn(e){return e?` ${v(p("space"))} ${v("resume")} \xB7 ${m("s")} skip \xB7 ${v(p("q"))} ${v("quit")} \xB7 ${m("?")} help`:` ${m("space")} pause \xB7 ${m("s")} skip \xB7 ${m("q")} quit \xB7 ${m("?")} help`}function Zo(e){let t=e.state.preset,n=["",` ${N("\u2740")} ${v("FOCUS_CYCLE")} ${m(e.presetName)}`,"",...te(e.breadcrumbs??[]),` ${m("blocks")} ${p(String(t.blocks))}`,` ${m("focus")} ${p(we(t.focusSec))} each`,` ${m("break")} ${p(we(t.breakSec))} each`,` ${m("long break")} ${p(we(t.longBreakSec))} after the last block`,"",F(`[ ${v(p("press enter to begin"))} ]`,B),"",` ${m("q")} quit`,""];return H(ee(n),B)}function St(e,t){let n=Ne(e.state),r=J(e.state,e.nowMs),o=n-r,s=e.paused?"PAUSED":t,i=["",Nn(e.state,e.presetName),"",...te(e.breadcrumbs??[]),Bn(e.state,e.nowMs),"",...Xo(e,r),"",F(Ln(e.state),B),"",Dn(`${s} . . .`),"",Fn(o,n),"",Kn(e.paused),""];return H(ee(i),B)}function es(e){let t=J(e.state,e.nowMs),n=Ne(e.state),r=n-t,o=e.state.blockIndex>=e.state.preset.blocks?"LONG_BREAK":"BREAK",s=["",Nn(e.state,e.presetName),"",...te(e.breadcrumbs??[]),Bn(e.state,e.nowMs),"","","",F(`${p(`next: ${o} in ${t}s`)}`,B),"","",F(Ln(e.state),B),"",Dn("FETCHING SESSION . . ."),"",Fn(r,n),"",Kn(e.paused),""];return H(ee(s),B)}function ts(e){let t=e.state.preset,n=we(t.focusSec*t.blocks),r=["",` ${N("\u2740")} ${v("CYCLE_DONE")} ${m(e.presetName)}`,"",...te(e.breadcrumbs??[]),` ${m("focus blocks")} ${p(`${t.blocks}`)}`,` ${m("total deep work")} ${p(n)}`,` ${m("breaks taken")} ${p(`${t.blocks}`)}`,"",F(`[ ${v(p("nice work"))} ]`,B),"",` ${m("r")} repeat \xB7 ${m("x")} exit`,""];return H(ee(r),B)}function De(e){switch(e.state.status){case"PRE_FLIGHT":return Zo(e);case"FOCUS_BLOCK":return St(e,"DEEP WORK");case"TRANSITION":return es(e);case"BREAK":return St(e,"BREATHE");case"LONG_BREAK":return St(e,"LONG_REST");case"CYCLE_DONE":return ts(e)}}function Fe(e){return Go}function Et(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 ns(e,t){let n=t?p("\u25B8 "):" ",r=t?v(p(e)):e,o=m(`\xB7 ${Et(e)}`);return` ${n}${z(r,10)} ${o}`}function Un(e,t=[]){let n=["",` ${N("\u2740")} ${v("FOCUS_CYCLE")} ${m("pick a cadence")}`,"",...te(t),...ne.map((r,o)=>ns(r,o===e)),"",` ${m("\u2191\u2193 to move \u23CE to select esc to cancel")}`,""];return H(ee(n),B)}var jn=22,rs=22,yt=["\u2581","\u2582","\u2583","\u2584","\u2585","\u2584","\u2583","\u2582"];function os(e){let t=e%yt.length,n="";for(let r=0;r<5;r++)n+=yt[(t+r)%yt.length];return n}function ss(e){let t=e?p("\u25B8"):" ",n=e?v(p("none")):"none",r=m("silence \u2014 your own thoughts");return` ${t} ${z(n,jn)} ${r}`}function is(e){return` ${m(e.toUpperCase())}`}function as(e,t,n){let r=t?p("\u25B8"):" ",o=t?v(p(e.name)):e.name,s=m(z(e.blurb,rs)),i=t?p(` ${os(n)}`):"";return` ${r} ${z(o,jn)} ${s}${i}`}function qn(e){let{entries:t,selectedIdx:n,tickFrame:r,breadcrumbs:o=[]}=e,s=[];s.push(` ${N("\u2740")} ${v("FOCUS_CYCLE")} ${m("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(ss(u)):a.kind==="category"?s.push(is(a.label)):s.push(as(a.sound,u,r))}return s.push(""),s.push(` ${m("\u2191\u2193 to move \u23CE to select esc to cancel")}`),H(ee(s),B)}var An=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function Mn(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} kB`:`${(e/1024/1024).toFixed(1)} MB`}function us(e,t){let n=t<=0?0:Math.max(0,Math.min(1,e/t)),r=Math.round(n*kt),o=kt-r;return`${p("\u2588".repeat(r))}${m("\u2591".repeat(o))}`}function Hn(e){let{sound:t,status:n,downloaded:r,total:o,tickFrame:s,breadcrumbs:i=[]}=e,a=An[s%An.length],u=n==="ready"?v(p("READY . . .")):n==="failed"?v(p("OFFLINE \u2014 STARTING IN SILENCE")):n==="timeout"?v(p("TIMED OUT \u2014 STARTING IN SILENCE")):`${p(a)} ${v("PREPARING . . .")}`,c=o<=0?0:Math.round(r/o*100),l=t?`${v(p(t.name))} ${m(t.blurb)}`:`${v(p("silence"))} ${m("your own thoughts")}`,d=t?`${m(Mn(r))} ${m("/")} ${m(Mn(o))} ${m(`${c}%`)}`:"",f=["",` ${N("\u2740")} ${v("FOCUS_CYCLE")} ${m("preparing your ambience")}`,"",...te(i),F(`[ ${u} ]`,B),"",F(l,B),"",F(`[${us(r,o)}]`,B),"",F(d,B),"",` ${m("esc to cancel")}`,""];return H(ee(f),B)}var Se="\x1B[?1049h",ue="\x1B[?1049l",le="\x1B[?25l",ce="\x1B[?25h",ye="\x1B[H",Ue=e=>`\x1B[${e}A`,je="\x1B[2K",ms=100,ps=3e4,Vn=80,Gn=fs(ds(ls(import.meta.url)),"..","assets/notification-icon.png");async function Wn(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 h=u;u=null,h.resolve()}},l=h=>{let k=Buffer.isBuffer(h)?h:Buffer.from(h);for(let g of W(k))i.push(g);c()},d=()=>{a=!0,c()};n.isTTY&&n.setRawMode(!0),n.resume(),n.on("data",l),n.once("end",d),t.write(Se+ye+le);let f=!0,w=()=>{let h=Un(s,o),k="";f||(k+=Ue(h.length));for(let g of h)k+=`\r${je}${g}
|
|
6
|
+
`;t.write(k),f=!1},y=()=>{n.isTTY&&n.setRawMode(!1),n.off("data",l),n.off("end",d),n.pause(),t.write(ce+ue)},E=()=>{y(),process.removeListener("SIGINT",E),process.exit(0)};process.on("SIGINT",E);try{for(w();;){if(i.length===0){if(a)return null;await new Promise(h=>{u={resolve:h}})}for(;i.length>0;){let h=i.shift();if(h.name==="ctrl-c"||h.name==="escape")return null;if(h.name==="up"||h.name==="char"&&h.char?.toLowerCase()==="k")s=(s-1+ne.length)%ne.length,w();else if(h.name==="down"||h.name==="tab"||h.name==="char"&&h.char?.toLowerCase()==="j")s=(s+1)%ne.length,w();else{if(h.name==="return")return ne[s];if(h.name==="char"&&h.char?.toLowerCase()==="q")return null}}}}finally{process.removeListener("SIGINT",E),y()}}function bs(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 Jn(e){let t=e.out??process.stdout,n=e.stdin??process.stdin,r=e.breadcrumbs??[],o=on(e.manifest),s=sn(o),i=bs(o,e.defaultSoundId),a=0,u=[],c=!1,l=null,d=()=>{if(l){let S=l;l=null,S.resolve()}},f=S=>{let O=Buffer.isBuffer(S)?S:Buffer.from(S);for(let L of W(O))u.push(L);d()},w=()=>{c=!0,d()};n.isTTY&&n.setRawMode(!0),n.resume(),n.on("data",f),n.once("end",w),t.write(Se+ye+le);let y=!0,E=()=>{let S=qn({entries:o,selectedIdx:i,tickFrame:a,breadcrumbs:r}),O="";y||(O+=Ue(S.length));for(let L of S)O+=`\r${je}${L}
|
|
7
|
+
`;t.write(O),y=!1},h=()=>{n.isTTY&&n.setRawMode(!1),n.off("data",f),n.off("end",w),n.pause(),t.write(ce+ue)},k=()=>{h(),process.removeListener("SIGINT",k),process.exit(0)};process.on("SIGINT",k);let g=(S,O)=>{let L=s.indexOf(S);if(L<0)return S;let P=(L+O+s.length)%s.length;return s[P]},$=setInterval(()=>{a++,E()},Vn);try{for(E();;){if(u.length===0){if(c)return null;await new Promise(S=>{l={resolve:S}})}for(;u.length>0;){let S=u.shift();if(S.name==="ctrl-c"||S.name==="escape")return null;if(S.name==="up"||S.name==="char"&&S.char?.toLowerCase()==="k")i=g(i,-1),E();else if(S.name==="down"||S.name==="tab"||S.name==="char"&&S.char?.toLowerCase()==="j")i=g(i,1),E();else if(S.name==="return"){let O=o[i];if(O.kind==="none")return{sound:null};if(O.kind==="sound")return{sound:O.sound}}else if(S.name==="char"&&S.char?.toLowerCase()==="q")return null}}}finally{$&&(clearInterval($),$=null),process.removeListener("SIGINT",k),h()}}async function Qn(e){let t=e.out??process.stdout,n=e.sound,r=e.timeoutMs??ps,o=e.breadcrumbs??[];if(!n)return Yn(t,{sound:null,status:"ready",downloaded:0,total:0,tickFrame:0,breadcrumbs:o},!0),await Ke(250),{filePath:null,outcome:"silent"};if(rn(n))return{filePath:tn(n),outcome:"cached"};let s=0,i=n.bytes,a=0,u="fetching",c=!0,l=()=>{Yn(t,{sound:n,status:u,downloaded:s,total:i,tickFrame:a,breadcrumbs:o},c),c=!1},d=setInterval(()=>{a++,l()},Vn),f=new AbortController,w=setTimeout(()=>{f.abort(),y?.("timeout")},r),y=null,E=new Promise($=>{y=$}),h=($,S)=>{s=$,i=S||n.bytes},k=(e.download?e.download(n,h):Pe(n,{signal:f.signal,onProgress:$=>h($.downloaded,$.total)})).then($=>({ok:!0,path:$})).catch(()=>({ok:!1}));t.write(Se+ye+le),l();let g=await Promise.race([k,E]);return clearInterval(d),clearTimeout(w),y=null,g==="timeout"?(u="timeout",l(),await Ke(400),t.write(ce+ue),{filePath:null,outcome:"timeout"}):g.ok?(u="ready",s=i,l(),await Ke(300),t.write(ce+ue),{filePath:g.path,outcome:"ready"}):(u="failed",l(),await Ke(400),t.write(ce+ue),{filePath:null,outcome:"failed"})}function Yn(e,t,n){let r=Hn(t),o="";n?o+=Se+ye+le:o+=Ue(r.length);for(let s of r)o+=`\r${je}${s}
|
|
8
|
+
`;e.write(o)}function Ke(e){return new Promise(t=>setTimeout(t,e))}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}}}async function zn(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??ie,f=e.breadcrumbs??[],w=e.autoStart??!0,y=e.stateEnabled??!0,E=e.ambientId??null,h=process.pid,k=!1;if(y){let b=ve({pidOverride:h});if(b.kind==="busy")throw new Error(`focus session already running (pid ${b.pid})`);k=!0}let g=Me(o,r()),$=g.enteredAtMs,S=null,O=null,L=()=>{O?.stop(),O=null},P=Fe(o),_=!0,T="",D=(b,R=!1)=>{let I=b.join(`
|
|
9
|
+
`);if(!R&&!_&&I===T)return;let G="";_||(G+=Ue(P));for(let jr of b)G+=`\r${je}${jr}
|
|
10
|
+
`;t.write(G),_=!1,T=I},C=(b=!1)=>{let R=r()-g.enteredAtMs,I=De({state:g,presetName:s,elapsedMs:R,nowMs:r(),paused:g.pausedAtMs!==null,breadcrumbs:f});D(I,b)},K=()=>{if(!(!y||!k))try{_e({version:1,pid:h,status:g.status,preset:s,blockIndex:g.blockIndex,blocks:g.preset.blocks,remainingSec:J(g,r()),paused:g.pausedAtMs!==null,ambient:E,startedAt:$,updatedAt:r()})}catch{}},M=b=>b<60?`${b}s`:`${Math.round(b/60)} min`,pe=b=>{if(!u)return;let R="",I="";if(b.status==="FOCUS_BLOCK")R=`flowe \xB7 block ${b.blockIndex}/${b.preset.blocks}`,I=`${M(b.preset.focusSec)}. one thing. lock in.`;else if(b.status==="BREAK")R="flowe \xB7 break",I=`${M(b.preset.breakSec)}. stand up. breathe.`;else if(b.status==="LONG_BREAK")R="flowe \xB7 long break",I=`${M(b.preset.longBreakSec)}. walk. eyes off the screen.`;else if(b.status==="CYCLE_DONE")R="flowe \xB7 cycle done",I=`${b.preset.blocks} blocks banked. go ship.`;else return;try{cs.notify({title:R,message:I,icon:Gn,contentImage:Gn,sound:!0})}catch{}},Ye=async b=>{if(pe(b),b.status==="FOCUS_BLOCK"?l&&!O&&c&&(O=d(c)):L(),b.status==="BREAK"||b.status==="LONG_BREAK"){let R=b.status==="BREAK"?i:a,I=b.status==="BREAK"?5:15;try{S=await ae({type:R,durationMin:I})}catch{S=null}}(b.status==="FOCUS_BLOCK"||b.status==="CYCLE_DONE")&&(S?.cancel(),S=null)},Y=async b=>{let R=g,I=Be(R,b);I!==R&&(g=I,K(),Le(R,I)?await Ye(I):Ur(R,I))},Ur=(b,R)=>{let I=b.pausedAtMs!==null,G=R.pausedAtMs!==null;if(I!==G&&R.status==="FOCUS_BLOCK"){if(G){L();return}l&&!O&&c&&(O=d(c))}},X=[],Ee=!1,oe=null,Ve=()=>{if(oe){let b=oe;oe=null,b.resolve()}},Nt=b=>{let R=Buffer.isBuffer(b)?b:Buffer.from(b);for(let I of W(R))X.push(I);Ve()},Bt=()=>{Ee=!0,Ve()},Lt=()=>{n.isTTY&&n.setRawMode(!0)};Lt(),n.resume(),n.on("data",Nt),n.once("end",Bt),t.write(Se+ye+le);let Dt=b=>X.length>0||Ee?Promise.resolve():new Promise(R=>{let I={resolve:R};oe=I,setTimeout(()=>{oe===I&&(oe=null,R())},b)}),We=()=>{S?.cancel(),S=null,L(),k&&($e(),Re(),k=!1),n.isTTY&&n.setRawMode(!1),n.off("data",Nt),n.off("end",Bt),n.pause(),process.removeListener("SIGCONT",Kt),t.write(ce+ue)},Ft=()=>{We(),process.removeListener("SIGINT",Ft),process.exit(0)};process.on("SIGINT",Ft);let Kt=()=>{Lt(),t.write(le),_=!0,T="",C(!0),Ve()};process.on("SIGCONT",Kt);try{if(w&&g.status==="PRE_FLIGHT"){let b=he(g,r());b!==g&&(g=b,$=g.enteredAtMs,K(),await Ye(g))}for(C();g.status==="PRE_FLIGHT";){if(await Dt(6e4),Ee&&X.length===0){We();return}for(;X.length>0;){let b=X.shift();if(b.name==="ctrl-c"||b.name==="escape"){await Y({kind:"QUIT",nowMs:r()});break}if(b.name==="return"){let R=he(g,r());R!==g&&(g=R,$=g.enteredAtMs,K(),await Ye(g));break}if(b.name==="char"&&(b.char??"").toLowerCase()==="q"){await Y({kind:"QUIT",nowMs:r()});break}}}for(;g.status!=="CYCLE_DONE";){C(),K();let b=!1,R=y&&k?Oe():null;for(R&&(await Y(gs(R,r())),R==="quit"&&(b=!0));X.length>0&&!b;){let I=X.shift();if(I.name==="ctrl-c"||I.name==="escape"){await Y({kind:"QUIT",nowMs:r()}),b=!0;break}if(I.name==="char"){let G=(I.char??"").toLowerCase();if(G===" ")await Y(g.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()}),b=!0;break}}}if(b){C();break}if(g.status==="CYCLE_DONE")break;if(Ee){await Y({kind:"QUIT",nowMs:r()});continue}await Dt(ms),await Y({kind:"TICK",nowMs:r()})}C()}finally{We()}}import hs from"node-notifier";import{fileURLToPath as ws}from"url";import{dirname as Ss,join as ys}from"path";var ks=100,Cs="quick_reset",Es="executive_reset",Xn=ys(Ss(ws(import.meta.url)),"..","assets/notification-icon.png");function _s(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 Rs(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 vs(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{hs.notify({title:n,message:r,icon:Xn,contentImage:Xn,sound:!0})}catch{}}var $s=e=>new Promise(t=>setTimeout(t,e));async function Zn(e){let t=U[e.preset],n=e.preset,r=e.now??Date.now,o=e.tickMs??ks,s=e.breakType??Cs,i=e.longBreakType??Es,a=e.notifications??!0,u=e.startAmbient??ie,c=e.runBreak??ae,l=e.consumeControl??Oe,d=e.pidOverride??process.pid,f=e.ambientId??null,w=e.ambientFilePath,y=ve({pidOverride:d});if(y.kind==="busy")return{finalStatus:"PRE_FLIGHT",ticks:0,reason:"busy",busyPid:y.pid};let E=he(Me(t,r()),r()),h=E.enteredAtMs,k=null,g=null,$=()=>{g?.stop(),g=null},S=()=>{let C=Rs(E,{pid:d,preset:n,ambientId:f,startedAtMs:h,nowMs:r()});try{_e(C)}catch{}},O=async C=>{if(vs(C,a),C.status==="FOCUS_BLOCK"?w&&!g&&(g=u(w)):$(),C.status==="BREAK"||C.status==="LONG_BREAK"){let K=C.status==="BREAK"?s:i,M=C.status==="BREAK"?5:15;try{k=await c({type:K,durationMin:M})}catch{k=null}}(C.status==="FOCUS_BLOCK"||C.status==="CYCLE_DONE")&&(k?.cancel(),k=null)},L=(C,K)=>{let M=C.pausedAtMs!==null,pe=K.pausedAtMs!==null;if(M!==pe&&K.status==="FOCUS_BLOCK"){if(pe){$();return}w&&!g&&(g=u(w))}},P=async C=>{let K=E,M=Be(K,C);M!==K&&(E=M,Le(K,M)?await O(M):L(K,M))};await O(E),S();let _=0,T="cycle_done",D=e.maxTicks??Number.POSITIVE_INFINITY;try{for(;E.status!=="CYCLE_DONE"&&_<D;){let C=l();if(C!==null&&(await P(_s(C,r())),C==="quit")){T="quit";break}if(E.status==="CYCLE_DONE")break;await $s(o),await P({kind:"TICK",nowMs:r()}),S(),_+=1}_>=D&&E.status!=="CYCLE_DONE"&&(T="max_ticks")}finally{$(),k?.cancel(),k=null,S(),$e(),E.status==="CYCLE_DONE"&&Re()}return{finalStatus:E.status,ticks:_,reason:T}}var Is="\x1B[?1049h",Os="\x1B[?1049l",Ps="\x1B[?25l",Ts="\x1B[?25h",xs="\x1B[H",As=e=>`\x1B[${e}A`,Ms="\x1B[2K",Ns=250;function Bs(e,t){let n=U[e.preset],r=tr(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 tr(e,t){switch(e){case"FOCUS_BLOCK":return t.focusSec;case"TRANSITION":return ge;case"BREAK":return t.breakSec;case"LONG_BREAK":return t.longBreakSec;default:return 0}}function Ls(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 Ds=e=>new Promise(t=>setTimeout(t,e));function Fs(){return["no active focus session.","","start one: flowe focus","or detached: flowe focus --detach"].join(`
|
|
11
|
+
`)}function nr(e){let t=tr(e.status,U[e.preset]);return[`flowe \xB7 ${e.preset} \xB7 ${e.status.toLowerCase()}`,`block ${e.blockIndex} / ${e.blocks}`,`remaining ${er(e.remainingSec)}${t?` of ${er(t)}`:""}`,`paused ${e.paused?"yes":"no"}`,`ambient ${e.ambient??"(none)"}`,`pid ${e.pid}`].join(`
|
|
12
|
+
`)}function er(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 rr(e={}){let t=e.out??process.stdout,n=e.stdin??process.stdin,r=e.now??Date.now,o=e.pollMs??Ns,s=e.readState??be,i=e.sendControl??Ie,a=e.maxPolls??Number.POSITIVE_INFINITY,u=s();if(u===null)return t.write(`${Fs()}
|
|
13
|
+
`),{reason:"no_session"};let c=[],l=!1,d=null,f=()=>{if(d){let _=d;d=null,_.resolve()}},w=_=>{let T=Buffer.isBuffer(_)?_:Buffer.from(_);for(let D of W(T))c.push(D);f()},y=()=>{l=!0,f()};n.isTTY&&n.setRawMode(!0),n.resume(),n.on("data",w),n.once("end",y),t.write(Is+xs+Ps);let E=!0,h=u.preset,k=Fe(U[h]),g=_=>{let T="";E||(T+=As(k));for(let D of _)T+=`\r${Ms}${D}
|
|
14
|
+
`;t.write(T),E=!1},$=_=>{let T=r(),D=Bs(_,T),C=De({state:D,presetName:_.preset,elapsedMs:T-D.enteredAtMs,nowMs:T,paused:_.paused});g(C)},S=()=>{n.isTTY&&n.setRawMode(!1),n.off("data",w),n.off("end",y),n.pause(),t.write(Ts+Os)},O=()=>{S(),process.removeListener("SIGINT",O),process.exit(0)};process.on("SIGINT",O);let L=0,P="cycle_done";try{let _=u;for($(_);L<a;){let T=!1;for(;c.length>0;){let D=c.shift(),C=Ls(D,_?.paused??!1);if(C!==null){if(C==="detach"){P="detached",T=!0;break}try{i(C)}catch{}C==="quit"&&(P="quit")}}if(T)break;if(l&&c.length===0){P="detached";break}if(await Ds(o),L+=1,_=s(),_===null){P=P==="quit"?"quit":"no_session";break}if($(_),_.status==="CYCLE_DONE"){P=P==="quit"?"quit":"cycle_done";break}}}finally{process.removeListener("SIGINT",O),S()}return{reason:P}}import{readFileSync as Ks}from"fs";import{dirname as Us,join as js}from"path";import{fileURLToPath as qs}from"url";function sr(e,t){return e===null||e.status==="CYCLE_DONE"?Gs(t):Hs(e,t)}function Hs(e,t){let n=or(e.remainingSec),r=U[e.preset],o=zs(e.status,r),s=[];return s.push(Ys(e,n)),s.push("---"),s.push(`flowe \xB7 ${e.preset} \xB7 ${Js(e.status)}`),s.push(`block ${e.blockIndex} / ${e.blocks} | font=Menlo`),s.push(`remaining ${n}${o?` of ${or(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(qe("Resume","resume",t)):s.push(qe("Pause","pause",t)),s.push(qe("Skip block","skip",t)),s.push(qe("Quit cycle","quit",t)),s.push("---"),s.push(`Open status in terminal | ${Ce(t,["focus","status"])} terminal=true`),s.join(`
|
|
15
|
+
`)}function Gs(e){return[Vs(),"---","no active focus session | color=#8c8c8c size=11","---",`Start pomodoro | ${Ce(e,["focus","pomodoro","--detach","--ambient","none"])} terminal=false refresh=true sfimage=play.circle.fill`,`Start dev | ${Ce(e,["focus","dev","--detach","--ambient","none"])} terminal=false refresh=true sfimage=play.circle.fill`,`Start ultradian | ${Ce(e,["focus","ultradian","--detach","--ambient","none"])} terminal=false refresh=true sfimage=play.circle.fill`].join(`
|
|
16
|
+
`)}function Ys(e,t){let n=e.paused?`\u23F8 ${t}`:t;return ir(n,{dim:e.paused})}function Vs(){return ir("flowe",{dim:!0})}function ir(e,t){let n=[],r=Ws();return r&&n.push(`image=${r}`),t.dim&&n.push("color=#8c8c8c"),n.length?`${e} | ${n.join(" ")}`:e}var ke=null;function Ws(){if(ke!==null)return ke;try{let e=Us(qs(import.meta.url));ke=Ks(js(e,"..","assets/menubar-icon.png")).toString("base64")}catch{ke=""}return ke}function Js(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 qe(e,t,n){let r=Qs(t),o=r?` sfimage=${r}`:"";return`${e} | ${Ce(n,["focus",t])} terminal=false refresh=true${o}`}function Qs(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 Ce(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 zs(e,t){switch(e){case"FOCUS_BLOCK":return t.focusSec;case"TRANSITION":return ge;case"BREAK":return t.breakSec;case"LONG_BREAK":return t.longBreakSec;default:return 0}}function or(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 Xs,existsSync as _t,mkdirSync as Zs,readFileSync as ei,rmSync as ti,statSync as yu,writeFileSync as ni}from"fs";import{homedir as Rt}from"os";import{dirname as ri,join as de,resolve as oi}from"path";import{fileURLToPath as si}from"url";import{execFileSync as ar,spawnSync as re}from"child_process";var vt="flowe.1s.sh";function ii(){return de(Rt(),"Library","Application Support","SwiftBar","Plugins")}function $t(){try{let t=ar("/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 ai=["Documents","Desktop","Downloads","Library/Mobile Documents"];function ui(e,t=Rt()){if(!e.startsWith(`${t}/`))return!1;let n=e.slice(t.length+1);return ai.some(r=>n===r||n.startsWith(`${r}/`))}function ur(e){if(e?.override)return e.override;let t=(e?.readPref??$t)(),n=e?.isRestricted??ui;return t&&!n(t)?t:ii()}function cr(e){return re("/usr/bin/defaults",["write","com.ameba.SwiftBar","PluginDirectory",e],{stdio:"ignore"}).status===0}function lr(){re("/usr/bin/killall",["SwiftBar"],{stdio:"ignore"}),re("/usr/bin/open",["-a","SwiftBar"],{stdio:"ignore"})}function ci(){return de(dr(),"bin","menubar",vt)}function dr(){let e=si(import.meta.url);return oi(ri(e),"..")}function fr(){return de(dr(),"bin","flowe.js")}function mr(){try{let t=ar("/usr/bin/which",["flowe"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim();return t.length>0?t:null}catch{return null}}function li(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 pr(e){let t=ur({override:e.pluginDir}),n=de(t,vt),r=e.templatePath??ci();if(!_t(r))throw new Error(`plugin template not found at ${r}`);let o=ei(r,"utf-8"),s=li(o,{floweBin:e.floweBin,nodeBin:e.nodeBin??process.execPath});return e.dryRun?{pluginPath:n,scriptContent:s,written:!1}:(Zs(t,{recursive:!0}),ni(n,s,"utf-8"),Xs(n,493),{pluginPath:n,scriptContent:s,written:!0})}function br(e={}){let t=ur({override:e.pluginDir}),n=de(t,vt),r=_t(n);return r&&ti(n),{pluginPath:n,existed:r}}function gr(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 di(){return["/Applications/SwiftBar.app",de(Rt(),"Applications","SwiftBar.app")]}function fi(){return di().some(e=>_t(e))}function mi(){return re("/usr/bin/which",["brew"],{stdio:"ignore"}).status===0}function pi(){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 hr(e={}){let t=e.isInstalled??fi,n=e.hasBrew??mi,r=e.install??pi;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 wr(){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 Sr(){re("/usr/bin/open",["-a","SwiftBar"],{stdio:"ignore"})}function yr(){return re("/usr/bin/pgrep",["-x","SwiftBar"],{stdio:"ignore"}).status===0}function kr(e){return e.existed?`removed \u2192 ${e.pluginPath}`:`nothing to remove (no plugin at ${e.pluginPath})`}var bi=["focus","deep_work","settle","sleep"],gi={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 He(e){return gi[e]}function Cr(e){let t=(e??"focus").trim().toLowerCase().replace(/[ -]+/g,"_");if(bi.includes(t))return t;throw new Error("intent must be one of: focus, deep-work, settle, sleep")}function Er(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 _r(e,t,n){if(n)return e.find(o=>o.id===n)??null;let r=He(t);return e.find(o=>o.id===r.defaultScene)??e[0]??null}function Rr(e){switch(e){case"gentle":case"low":return .6;case"strong":return 1.2;case"balanced":return 1}}function It(e,t,n){let r=He(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 hi(e){return new URL("/api/v1/cli/ambient/custom",e).toString()}function fe(e,t){return Object.assign(new Error(e),{code:t})}async function vr(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 $r(e){let t=e.prompt.trim();if(t.length<10)throw fe("prompt must be at least 10 characters","invalid_duration");let n=await V();if(!n)throw fe("sign in with: flowe login","auth_required");let o=await(e.fetchFn??fetch)(hi(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 fe("sign in with: flowe login","auth_required");if(o.status===403)throw fe(await vr(o),"agent_busy");if(!o.ok)throw fe(await vr(o),"network_error");let s=new Uint8Array(await o.arrayBuffer());if(s.byteLength===0)throw fe("ambient generation returned empty audio","network_error");let i=o.headers.get("X-Flowe-Ambient-Name");return{sound:nn({name:e.name??i??"custom ambience",prompt:t,bytes:s})}}import{readFileSync as wi}from"fs";import{dirname as Si,join as yi}from"path";import{fileURLToPath as ki}from"url";var Ci=Si(ki(import.meta.url));function Ei(){try{let e=wi(yi(Ci,"..","package.json"),"utf-8");return JSON.parse(e).version}catch{return"0.0.0"}}var Ot=[" \u2572\u2502\u2571 "," \u2500\u2500\u2740\u2500\u2500"," \u2571\u2502\u2572 "];function Ir(){let e=Ei();return[p(Ot[0]),`${p(Ot[1])} ${N("flowe")} ${m(`v${e}`)}`,`${p(Ot[2])} ${bn("neural reset for AI-paired engineers")}`].join(`
|
|
20
|
+
`)}var Or=["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 Pr(e){let t=Number.isFinite(e)?Math.max(0,Math.floor(e)):0;return Or[t%Or.length]}var Tr=60,_i=28,Ri=18;function me(e,t){return` ${m(e.padEnd(Ri))} ${t}`}function xr(e,t,n){return`${e} ${e===1?t:n}`}function vi(e){let t=` ${N("\u2740")} ${v("SUMMARY_REPORT")}`,n=me("PROTOCOL",p(e.protocolDisplayName)),r=me("DURATION",p(`${e.duration}s`)),o=me("GUIDE",p(e.voice)),s=e.rounds!=null?me("ROUNDS",p(String(e.rounds))):null,i=me("TODAY",p(xr(e.sessionsToday,"session","sessions"))),a=e.streakDays!=null?me("STREAK",p(xr(e.streakDays,"day","days"))):null,u=p("\u2588".repeat(_i)),c=` ${m("INTEGRATION_SYNC")} [${u}] ${p("100%")}`,l=Pr(e.totalSessions),d=F(m(`"${l}"`),Tr);return H(["",t,"",n,r,o,s,"",i,a,"",c,"",d,""].filter(w=>w!==null),Tr)}function Ar(e,t=process.stdout){let n=vi(e);for(let r of n)t.write(r+`
|
|
21
|
+
`);return n.length}function $i(){let e=N("\u25C6"),t=`[${p("r")}] repeat`,n=`[${p("n")}] new session`,r=`[${p("x")}] exit`;return` ${e} ${t} ${m("\xB7")} ${n} ${m("\xB7")} ${r}`}var Mr=2;async function Nr(e){e.setRawMode?.(!0),e.out.write(`
|
|
22
|
+
`+$i()+`
|
|
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 Br(){let e=process.stdin;return{out:process.stdout,setRawMode:n=>{e.isTTY&&e.setRawMode(n)},keys:Ii(e)}}function Ii(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 Oi,mkdirSync as Pi,writeFileSync as Ti}from"fs";import{homedir as xi,platform as Ai}from"os";import{join as Ge}from"path";var Lr="welcomed";function Pt(){let e=xi();return Ai()==="win32"?Ge(e,"AppData","Roaming","flowe"):Ge(e,".config","flowe")}function Mi(){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 Ni(e=Pt()){return Oi(Ge(e,Lr))}function Bi(e=Pt()){Pi(e,{recursive:!0}),Ti(Ge(e,Lr),"","utf-8")}function Dr(e=process.stderr){try{let t=Pt();if(Ni(t))return;Bi(t),e.write(Mi())}catch{}}var Fr=e=>`\x1B[${e}A`,At="\x1B[2K";function Fi(e,t){if(t<=0)return;let n=Fr(t);for(let r=0;r<t;r++)n+=`\r${At}
|
|
25
|
+
`;n+=Fr(t),e.write(n)}function Ki(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(Ki(t?.code))}function Ui(e){return Array.isArray(e)?e.join(" ").trim():(e??"").trim()}function Mt(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 Tt(e){if(Je.includes(e))return e;throw Object.assign(new Error(`type must be one of: ${Je.join(", ")}`),{code:"invalid_duration"})}function ji(e){if(Qe.includes(e))return e;throw Object.assign(new Error(`type must be one of: ${Qe.join(", ")}`),{code:"invalid_duration"})}function xt(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 qi(e){let t=Vt();if(t.includes(e))return e;throw Object.assign(new Error(`unknown protocol "${e}" \u2014 available: ${t.join(", ")}`),{code:"invalid_duration"})}function Hi(e){if(e!==void 0){if(zt(e))return e;throw Object.assign(new Error(`--situation must be one of: ${et.join(", ")}`),{code:"invalid_duration"})}}function Gi(e){if(e!==void 0){if(Xt(e))return e;throw Object.assign(new Error(`--feeling must be one of: ${tt.join(", ")}`),{code:"invalid_duration"})}}var Yi="https://www.flowe.ai/pricing?utm_source=flowe-cli&utm_medium=terminal";function Vi(e){let t=e.account==="guest"?"Run: flowe login":`Flowe Pro: ${Yi}`;return`${e.message}
|
|
27
|
+
${t}
|
|
28
|
+
`}function Wi(e){return new Promise(t=>setTimeout(t,e*1e3))}async function Ji(e=2e3){let t=ot().catch(()=>null),n=new Promise(r=>setTimeout(()=>r(null),e));return Promise.race([t,n])}async function Kr(e,t){let n=q(),r=await V();r&&!n.user_first_name&&(await Ji(),n=q());let o=gn(n.user_first_name),s=60;if(e)try{s=Mt(e)}catch{}let i=t?Xe(t):void 0,a=await wn({defaultDuration:s,defaultVoice:n.voice,greeting:o,showAuthWedge:!r,availableDurations:i,signIn:async()=>{let{runLogin:u}=await import("./login-UO2GGRN2.js");await u(),await ot()},clearOnExit:!0});return a?{duration:a.duration,voice:a.voice,family:t}:null}async function Qi(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=Mt(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:Mt(e??60)}}async function zi(){if(ln()){let t=cn(),n=await Zn({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"&&Dr();let e=Li("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)").option("--moment <line>","one plain line about your moment; the reset is shaped around it").option("--situation <label>",`what you are in the middle of (${et.join(", ")})`).option("--feeling <label>",`how you feel (${tt.join(", ")})`).action(async(t,n)=>{try{let r=n.trigger,o=n.protocol?qi(n.protocol):void 0,s=Hi(n.situation),i=Gi(n.feeling),a=typeof n.moment=="string"?n.moment:void 0,c=!n.quick&&Sn()?await Kr(t,o):await Qi(t,o);if(!c)return;for(;;){c.voice&&ze(c.voice);let l=xn(),d=se();l&&d&&process.stdout.write(" shaping your reset\u2026\r");let f;try{f=await en(c.duration,r,c.family,{moment:a,situation:s,feeling:i,surface:"terminal"})}catch(y){if(!(y instanceof Zt))throw y;l&&d&&process.stdout.write(`\r${At}`),process.stdout.write(Vi(y));return}l&&d&&process.stdout.write(`\r${At}`);let w=Ze()??(f.audio_mode==="silent"?Wi(f.duration_seconds):null);if(l&&w){await Tn({duration:f.duration_seconds,voice:f.voice,displayName:f.shaped?f.protocol_display_name:`${f.protocol_display_name} \xB7 no voice`,cues:f.cues,rounds:f.rounds,donePromise:w}),nt(f.session_id);let y=Ar({protocolDisplayName:f.protocol_display_name,duration:f.duration_seconds,voice:f.voice,rounds:f.rounds,sessionsToday:qt(),totalSessions:Gt(),streakDays:Ht()}),E=f.back_to_it?2:0;if(f.back_to_it&&process.stdout.write(`
|
|
29
|
+
back to it: ${f.back_to_it}
|
|
30
|
+
`),n.quick)return;let h=await Nr(Br());if(h==="exit")return;if(Fi(process.stdout,y+E+Mr),h==="repeat")continue;if(h==="new"){let k=await Kr(void 0,c.family);if(!k)return;c=k;continue}return}if(process.stdout.write(`${f.message_for_user}
|
|
31
|
+
`),f.shaped)for(let y of f.captions??[])process.stdout.write(` \xB7 ${y.text}
|
|
32
|
+
`);else for(let y of f.cues)process.stdout.write(` \xB7 ${y.label}
|
|
33
|
+
`);w&&(await w,nt(f.session_id)),f.back_to_it&&process.stdout.write(`back to it: ${f.back_to_it}
|
|
34
|
+
`);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?Tt(t):"quick_reset",o=n.voice?xt(n.voice):void 0,{createAndStartLiveSession:s}=await import("./session-client-BR4JJT7O.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
35
|
`),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){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?
|
|
36
|
+
`),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?ji(t):"ht_stress",o=n.voice?xt(n.voice):void 0,{createAndStartLiveSession:s}=await import("./session-client-BR4JJT7O.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
37
|
`),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){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
|
|
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
|
|
34
|
-
`);let u=await
|
|
38
|
+
`),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?Tt(t):"quick_reset",r=await fn(n);process.stdout.write(`${r.message_for_user}
|
|
39
|
+
`)}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?Tt(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}
|
|
40
|
+
`);let u=await ae({type:r,durationMin:o,voice:s,signal:i.signal});process.stdout.write(` playing\u2026 (Ctrl-C to stop)
|
|
35
41
|
`);try{await u.finished,process.stdout.write(` done.
|
|
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{
|
|
37
|
-
`)}catch(
|
|
38
|
-
`),process.exit(1)}return}if(t==="status"){let d=
|
|
42
|
+
`)}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{Ie(d),process.stdout.write(`sent: ${d}
|
|
43
|
+
`)}catch(f){process.stderr.write(`${f.message}
|
|
44
|
+
`),process.exit(1)}return}if(t==="status"){let d=be();if(d===null){if(n.json){process.stdout.write(`${JSON.stringify({active:!1})}
|
|
39
45
|
`);return}process.stderr.write(`no active focus session
|
|
40
46
|
`),process.exit(1)}n.json?process.stdout.write(`${JSON.stringify(d)}
|
|
41
|
-
`):process.stdout.write(`${
|
|
42
|
-
`);return}if(t==="menubar"){let d=n.floweBin??"flowe",
|
|
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
|
|
44
|
-
`);return}catch(d){throw d instanceof
|
|
47
|
+
`):process.stdout.write(`${nr(d)}
|
|
48
|
+
`);return}if(t==="menubar"){let d=n.floweBin??"flowe",f=be();process.stdout.write(`${sr(f,{floweBinary:d,nodeBinary:n.nodeBin})}
|
|
49
|
+
`);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 rr();process.exit(d.reason==="no_session"?1:0)}let r=[],o;if(t===void 0){if(o=await Wn(),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 ${Et(o)}`});let s=await rt().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(f=>f.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 Jn({manifest:u,breadcrumbs:r});if(c===null)return;r.push({label:"ambient",value:c.sound?.name??"silence"});let l=await Qn({sound:c.sound,breadcrumbs:r});if(n.detach)try{let d=un({preset:o,ambientFilePath:l.filePath??void 0,ambientId:c.sound?.id});process.stdout.write(dn(d)+`
|
|
50
|
+
`);return}catch(d){throw d instanceof an&&(process.stderr.write(`${d.message}
|
|
45
51
|
use \`flowe focus status\` or \`flowe focus quit\` first
|
|
46
|
-
`),process.exit(1)),d}await
|
|
47
|
-
`:`${
|
|
48
|
-
`);return}let a=await
|
|
49
|
-
`):process.stdout.write(`${
|
|
50
|
-
`),await new Promise(d=>{let w
|
|
52
|
+
`),process.exit(1)),d}await zn({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=Cr(t),o=He(r),s=Er(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)}
|
|
53
|
+
`:`${It(r,i,d.scene)}
|
|
54
|
+
`);return}let a=await rt(),u=_r(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 Pe(u),l=ie(c,{volume:Rr(o.modulation)});n.json?process.stdout.write(`${JSON.stringify({intent:r,scene:u.id,minutes:i,modulation:o.modulation,playing:!0})}
|
|
55
|
+
`):process.stdout.write(`${It(r,i,u.name)}
|
|
56
|
+
`),await new Promise(d=>{let f,w=()=>{f&&clearTimeout(f),process.off("SIGINT",w),l.stop(),d()};process.on("SIGINT",w),i!==null&&(f=setTimeout(w,i*6e4))})}catch(r){j(r)}}),e.command("status","Show config and queue state").action(()=>{let t=q();process.stdout.write(Ir()+`
|
|
51
57
|
|
|
52
58
|
`),process.stdout.write(`voice: ${t.voice}
|
|
53
59
|
`),process.stdout.write(`backend: ${t.backend_url}
|
|
54
60
|
`),process.stdout.write(`telemetry: ${t.telemetry}
|
|
61
|
+
`),process.stdout.write(`shaping: ${se(t)?"on":"off"}
|
|
55
62
|
`),process.stdout.write(`first_reset_at: ${t.first_reset_at??"(none yet)"}
|
|
56
|
-
`)}),e.command("
|
|
63
|
+
`)}),e.command("config [key] [value]","Show or change settings (shaping on|off)").action((t,n)=>{try{if(t===void 0){let r=q();process.stdout.write(`shaping: ${se(r)?"on":"off"}${r.shaping!==!1&&!se(r)?" (FLOWE_OPT_OUT is set)":""}
|
|
64
|
+
`),process.stdout.write(`voice: ${r.voice}
|
|
65
|
+
`);return}if(t!=="shaping")throw Object.assign(new Error(`unknown setting "${t}" \u2014 available: shaping`),{code:"invalid_duration"});if(n===void 0){process.stdout.write(`shaping: ${se()?"on":"off"}
|
|
66
|
+
`);return}if(n!=="on"&&n!=="off")throw Object.assign(new Error("usage: flowe config shaping on|off"),{code:"invalid_duration"});jt(n==="on"),process.stdout.write(n==="on"?`shaping on: resets are shaped to your moment (5 a week without Flowe Pro)
|
|
67
|
+
`:`shaping off: resets run as a silent guide, and nothing is sent
|
|
68
|
+
`)}catch(r){j(r)}}),e.command("voice [name]","Set preferred voice (sage, ada, or ellie)").action(t=>{if(!t){process.stdout.write(`current: ${q().voice}
|
|
57
69
|
available: sage, ada, ellie
|
|
58
|
-
`);return}try{let n=
|
|
59
|
-
`)}catch(n){j(n)}}),e.command("protocols","List bundled reset protocols").action(()=>{let t=
|
|
70
|
+
`);return}try{let n=xt(t);ze(n),process.stdout.write(`voice set to ${n}
|
|
71
|
+
`)}catch(n){j(n)}}),e.command("protocols","List bundled reset protocols").action(()=>{let t=Yt();if(t.length===0){process.stdout.write(`(no protocols bundled yet)
|
|
60
72
|
`);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-
|
|
73
|
+
`)}),e.command("login","Sign in with Clerk (device-grant flow)").action(async()=>{try{let{runLogin:t}=await import("./login-UO2GGRN2.js");await t()}catch(t){j(t)}}),e.command("logout","Sign out and clear stored token").action(async()=>{await Qt(),process.stdout.write(`signed out
|
|
62
74
|
`)}),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-
|
|
75
|
+
`);return}try{let{fetchAccountStatus:n,teamLine:r}=await import("./session-client-BR4JJT7O.js"),o=await n();if(!o.authenticated){process.stdout.write(`session expired \u2014 run: flowe login
|
|
64
76
|
`);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
77
|
`);let a=r(o);if(a&&process.stdout.write(`${a}
|
|
66
78
|
`),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
|
|
@@ -79,18 +91,18 @@ ${c.content}`):process.stdout.write(`configured ${u.label}: ${c.path}
|
|
|
79
91
|
# add the above to ~/.config/claude/mcp.json (or your client's equivalent)
|
|
80
92
|
`)}),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
|
|
81
93
|
`);return}for(let u of a.sounds)process.stdout.write(`${u.id} ${u.name}
|
|
82
|
-
`);return}if(t!=="create")throw Object.assign(new Error("ambient command must be one of: create, list"),{code:"invalid_duration"});let o=
|
|
83
|
-
`);let s=await
|
|
94
|
+
`);return}if(t!=="create")throw Object.assign(new Error("ambient command must be one of: create, list"),{code:"invalid_duration"});let o=Ui(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...
|
|
95
|
+
`);let s=await $r({prompt:o,name:r.name});process.stdout.write(`saved custom ambience: ${s.sound.name} (${s.sound.id})
|
|
84
96
|
`),process.stdout.write(`start it with: flowe focus --ambient ${s.sound.id}
|
|
85
97
|
`)}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}
|
|
86
98
|
use --force to overwrite, or --target <path> to install elsewhere.
|
|
87
99
|
`),process.exit(0)),process.stdout.write(`installed: ${s.target}
|
|
88
100
|
`),t.target||process.stdout.write(`default location: ${o()}
|
|
89
101
|
restart Claude Code (or open a new session) and Claude will fire flowe resets during long thinking pauses.
|
|
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=
|
|
102
|
+
`)}),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=fr(),r=t.floweBin??(Di(n)?n:mr());if(r||(process.stderr.write(`could not locate the flowe binary on PATH.
|
|
91
103
|
pass --flowe-bin <abs-path> to override (e.g. /opt/homebrew/bin/flowe).
|
|
92
|
-
`),process.exit(1)),!t.dryRun&&!t.skipSwiftbarCheck){let i=
|
|
104
|
+
`),process.exit(1)),!t.dryRun&&!t.skipSwiftbarCheck){let i=hr();i.action==="missing-brew"&&(process.stderr.write(`${wr()}
|
|
93
105
|
`),process.exit(1)),i.action==="installed"&&process.stdout.write(`SwiftBar installed via brew.
|
|
94
|
-
`)}let o
|
|
95
|
-
`),t.launch!==!1&&!t.skipSwiftbarCheck){let i=s.pluginPath.replace(/\/[^/]+$/,"");o!==i&&
|
|
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(
|
|
106
|
+
`)}let o=$t(),s=pr({floweBin:r,pluginDir:t.pluginDir,dryRun:t.dryRun});if(t.dryRun){process.stdout.write(s.scriptContent);return}if(process.stdout.write(`${gr(s)}
|
|
107
|
+
`),t.launch!==!1&&!t.skipSwiftbarCheck){let i=s.pluginPath.replace(/\/[^/]+$/,"");o!==i&&cr(i),yr()?lr():Sr()}}),e.command("uninstall-menubar","Remove the flowe SwiftBar plugin").option("--plugin-dir <path>","override SwiftBar plugin dir").action(t=>{let n=br({pluginDir:t.pluginDir});process.stdout.write(`${kr(n)}
|
|
108
|
+
`)}),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(Ut());try{e.parse(process.argv,{run:!1}),await e.runMatchedCommand()}catch(t){j(t)}}zi().catch(j);
|