@flowe-ai/cli 0.1.7 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/assets/menubar-icon.png +0 -0
- package/assets/notification-icon.png +0 -0
- package/audio/body_scan_60.ellie.cues.json +21 -21
- package/audio/body_scan_60.ellie.mp3 +0 -0
- package/audio/box_breath_45.ellie.cues.json +25 -25
- package/audio/box_breath_45.ellie.mp3 +0 -0
- package/audio/box_breath_60.ellie.cues.json +33 -33
- package/audio/box_breath_60.ellie.mp3 +0 -0
- package/audio/extended_box_90.ellie.cues.json +49 -49
- package/audio/extended_box_90.ellie.mp3 +0 -0
- package/audio/eye_rotation_30.ellie.cues.json +11 -11
- package/audio/eye_rotation_30.ellie.mp3 +0 -0
- package/audio/full_sensory_90.ellie.cues.json +17 -17
- package/audio/full_sensory_90.ellie.mp3 +0 -0
- package/audio/grounded_feet_45.ellie.cues.json +11 -11
- package/audio/grounded_feet_45.ellie.mp3 +0 -0
- package/audio/neck_rotation_45.ellie.cues.json +15 -15
- package/audio/neck_rotation_45.ellie.mp3 +0 -0
- package/audio/palming_60.ellie.cues.json +17 -17
- package/audio/palming_60.ellie.mp3 +0 -0
- package/audio/physiological_sigh_30.ellie.cues.json +13 -13
- package/audio/physiological_sigh_30.ellie.mp3 +0 -0
- package/audio/progressive_palming_90.ellie.cues.json +19 -19
- package/audio/progressive_palming_90.ellie.mp3 +0 -0
- package/audio/quick_palming_30.ellie.cues.json +11 -11
- package/audio/quick_palming_30.ellie.mp3 +0 -0
- package/bin/flowe.js +0 -0
- package/bin/menubar/flowe.1s.sh +96 -0
- package/dist/ambient-SIMIQWQM.js +1 -0
- package/dist/chunk-AX3TLBEV.js +2 -0
- package/dist/{chunk-CGFAXS4S.js → chunk-C6NO4B4N.js} +2 -2
- package/dist/cli.js +65 -21
- package/dist/install-skill-5UWJTC26.js +1 -0
- package/dist/mcp-server.js +1 -1
- package/package.json +7 -2
- package/skills/flowe/SKILL.md +149 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as p,c as R,i as _}from"./chunk-P2IV5O3T.js";import{readFileSync as V}from"fs";import{dirname as q,join as J}from"path";import{fileURLToPath as Q}from"url";var U=q(Q(import.meta.url));function E(){try{let e=V(J(U,"..","package.json"),"utf-8");return JSON.parse(e).version}catch{return"0.0.0"}}var pe=["logic_lock","deploy_anxiety","context_switch","sprint_prep","quick_reset","executive_reset","presentation_prep","shutdown"];import{readFileSync as k}from"fs";import{dirname as B,join as h}from"path";import{fileURLToPath as L}from"url";var v=B(L(import.meta.url));function Y(){return h(v,"..","protocols.json")}var l=null;function w(){if(l)return l;try{let e=k(Y(),"utf-8");return l=JSON.parse(e),l}catch{return l={protocols:{},audio_paths:{},cues_paths:{}},l}}function x(){return Object.values(w().protocols)}function P(e){return e.replace(/_\d+$/,"")}function he(){let e=new Set;for(let o of x())e.add(P(o.protocol_id));return[...e].sort()}function ve(e){return x().filter(o=>P(o.protocol_id)===e).map(o=>o.duration_seconds).sort((o,r)=>o-r)}function T(e,o){let r=x().filter(n=>n.duration_seconds===e&&(o===void 0||P(n.protocol_id)===o));return r.length===0?null:o!==void 0?r[0]:r[Math.floor(Math.random()*r.length)]}function j(e,o){let r=w(),n=`${e}.${o}`,t=r.audio_paths[n];return t?h(v,"..",t):null}var f=new Map;function $(e,o){let r=`${e}.${o}`,n=f.get(r);if(n!==void 0)return n;let i=w().cues_paths?.[r];if(!i)return f.set(r,null),null;try{let s=k(h(v,"..",i),"utf-8"),a=JSON.parse(s);return f.set(r,a),a}catch{return f.set(r,null),null}}import z from"sound-play";var c=null;function F(){return c!==null}function Ce(){return c?.donePromise??null}async function M(e){if(c)throw new Error("already playing \u2014 call stopAudio first");let o,r,n=new Promise((s,a)=>{o=s,r=a}),t=z.play(e),i=!1;return c={stop:()=>{i=!0,o(),c=null},donePromise:n},t.then(()=>{i||(o(),c=null)}).catch(s=>{c=null,r(s instanceof Error?s:new Error(String(s)))}),n}import{nanoid as ne}from"nanoid";import{readFileSync as H,writeFileSync as G,mkdirSync as K,existsSync as S,appendFileSync as W}from"fs";import{homedir as X}from"os";import{join as N}from"path";var C=N(X(),".cache","flowe"),d=N(C,"pending-events.jsonl"),Z=5e3;async function g(e,o,r){if(o.telemetry!=="off"){ee(),oe(e);try{await re(o,r)}catch{}}}function ee(){S(C)||K(C,{recursive:!0})}function oe(e){for(let o of e)W(d,JSON.stringify(o)+`
|
|
1
|
+
import{a as p,c as R,i as _}from"./chunk-P2IV5O3T.js";import{readFileSync as V}from"fs";import{dirname as q,join as J}from"path";import{fileURLToPath as Q}from"url";var U=q(Q(import.meta.url));function E(){try{let e=V(J(U,"..","package.json"),"utf-8");return JSON.parse(e).version}catch{return"0.0.0"}}var pe=["logic_lock","deploy_anxiety","context_switch","sprint_prep","quick_reset","executive_reset","presentation_prep","shutdown"];import{readFileSync as k}from"fs";import{dirname as B,join as h}from"path";import{fileURLToPath as L}from"url";var v=B(L(import.meta.url));function Y(){return h(v,"..","protocols.json")}var l=null;function w(){if(l)return l;try{let e=k(Y(),"utf-8");return l=JSON.parse(e),l}catch{return l={protocols:{},audio_paths:{},cues_paths:{}},l}}function x(){return Object.values(w().protocols)}function P(e){return e.replace(/_\d+$/,"")}function he(){let e=new Set;for(let o of x())e.add(P(o.protocol_id));return[...e].sort()}function ve(e){return x().filter(o=>P(o.protocol_id)===e).map(o=>o.duration_seconds).sort((o,r)=>o-r)}function T(e,o){let r=x().filter(n=>n.duration_seconds===e&&(o===void 0||P(n.protocol_id)===o));return r.length===0?null:o!==void 0?r[0]:r[Math.floor(Math.random()*r.length)]}function j(e,o){let r=w(),n=`${e}.${o}`,t=r.audio_paths[n];return t?h(v,"..",t):null}var f=new Map;function $(e,o){let r=`${e}.${o}`,n=f.get(r);if(n!==void 0)return n;let i=w().cues_paths?.[r];if(!i)return f.set(r,null),null;try{let s=k(h(v,"..",i),"utf-8"),a=JSON.parse(s);return f.set(r,a),a}catch{return f.set(r,null),null}}import z from"sound-play";var c=null;function F(){return c!==null}function Ce(){return c?.donePromise??null}async function M(e){if(c)throw new Error("already playing \u2014 call stopAudio first");let o,r,n=new Promise((s,a)=>{o=s,r=a}),t=z.play(e),i=!1;return c={stop:()=>{i=!0,o(),c=null},donePromise:n},t.then(()=>{i||(o(),c=null)}).catch(s=>{c=null,r(s instanceof Error?s:new Error(String(s)))}),n}function Se(){c&&c.stop()}import{nanoid as ne}from"nanoid";import{readFileSync as H,writeFileSync as G,mkdirSync as K,existsSync as S,appendFileSync as W}from"fs";import{homedir as X}from"os";import{join as N}from"path";var C=N(X(),".cache","flowe"),d=N(C,"pending-events.jsonl"),Z=5e3;async function g(e,o,r){if(o.telemetry!=="off"){ee(),oe(e);try{await re(o,r)}catch{}}}function ee(){S(C)||K(C,{recursive:!0})}function oe(e){for(let o of e)W(d,JSON.stringify(o)+`
|
|
2
2
|
`,"utf-8")}function te(){return S(d)?H(d,"utf-8").split(`
|
|
3
|
-
`).filter(o=>o.trim().length>0).map(o=>JSON.parse(o)):[]}function O(){S(d)&&G(d,"","utf-8")}async function re(e,o){let r=te();if(r.length===0)return;let n={version:E(),platform:`${process.platform}-${process.arch}`,node_version:process.version},t=new AbortController,i=setTimeout(()=>t.abort(),Z);try{let s={"Content-Type":"application/json"};o&&(s.Authorization=`Bearer ${o}`);let a=await fetch(`${e.backend_url}/api/v1/reset/log`,{method:"POST",headers:s,body:JSON.stringify({events:r,client:n,anonymous_id:e.anonymous_id}),signal:t.signal});(a.ok||a.status===401||a.status===400)&&O()}finally{clearTimeout(i)}}function se(e,o,r){if(e.length===0)return[];let t=o*1e3/e.length;return e.map((i,s)=>({label:i,mode:r,start_ms:Math.round(s*t),end_ms:Math.round((s+1)*t)}))}async function
|
|
3
|
+
`).filter(o=>o.trim().length>0).map(o=>JSON.parse(o)):[]}function O(){S(d)&&G(d,"","utf-8")}async function re(e,o){let r=te();if(r.length===0)return;let n={version:E(),platform:`${process.platform}-${process.arch}`,node_version:process.version},t=new AbortController,i=setTimeout(()=>t.abort(),Z);try{let s={"Content-Type":"application/json"};o&&(s.Authorization=`Bearer ${o}`);let a=await fetch(`${e.backend_url}/api/v1/reset/log`,{method:"POST",headers:s,body:JSON.stringify({events:r,client:n,anonymous_id:e.anonymous_id}),signal:t.signal});(a.ok||a.status===401||a.status===400)&&O()}finally{clearTimeout(i)}}function se(e,o,r){if(e.length===0)return[];let t=o*1e3/e.length;return e.map((i,s)=>({label:i,mode:r,start_ms:Math.round(s*t),end_ms:Math.round((s+1)*t)}))}async function Ve(e,o="user_requested",r){if(F())throw Object.assign(new Error("a reset is already running"),{code:"agent_busy"});let n=p(),t=T(e,r);if(!t){let A=r?`${r} at ${e}s`:`${e}s`;throw Object.assign(new Error(`no protocol available for ${A}`),{code:"protocol_unavailable"})}let i=j(t.protocol_id,n.voice);if(!i)throw Object.assign(new Error(`no audio available for ${t.protocol_id}:${n.voice}`),{code:"protocol_unavailable"});let s=`reset_${ne(8)}`,a=new Date,D=Math.floor(a.getTime()/1e3)+e;R();let y=await _();await g([{type:"reset_started",session_id:s,protocol_id:t.protocol_id,duration_seconds:e,voice:n.voice,trigger:o,client_timestamp:a.toISOString()}],n,y),M(i).then(()=>{g([{type:"reset_completed",session_id:s,protocol_id:t.protocol_id,duration_seconds:e,voice:n.voice,trigger:o,client_timestamp:new Date().toISOString()}],n,y).catch(()=>{})}).catch(()=>{g([{type:"reset_abandoned",session_id:s,protocol_id:t.protocol_id,duration_seconds:e,voice:n.voice,trigger:o,client_timestamp:new Date().toISOString()}],n,y).catch(()=>{})});let b=$(t.protocol_id,n.voice),I=b?b.cues:se(t.text_cues,e,t.category);return{session_id:s,protocol:t.protocol_id,protocol_display_name:t.display_name,duration_seconds:e,voice:n.voice,cues:I,rounds:t.rounds,status:"started",ends_at_unix:D,message_for_user:`${e}s ${t.display_name} started \xB7 ${n.voice}`}}import ie from"qrcode-terminal";async function Le(e="quick_reset",o={}){let r=p(),n=await _();if(!n)throw Object.assign(new Error("sign in with: flowe login"),{code:"auth_required"});let t;try{t=await fetch(`${r.backend_url}/api/v1/sessions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({protocolId:"nsdr",sessionType:e})})}catch{throw Object.assign(new Error("network unreachable \u2014 try: flowe reset"),{code:"network_error"})}if(!t.ok)throw t.status===401?Object.assign(new Error("session expired \u2014 run: flowe login"),{code:"auth_required"}):Object.assign(new Error(`server error ${t.status}`),{code:"network_error"});let i=await t.json(),s=`flowe://session/${i.session_id}`;return!o.suppressQr&&process.stdout.isTTY&&ie.generate(s,{small:!0}),{session_id:i.session_id,session_type:i.session_type,session_type_name:i.session_type_name,estimated_duration:i.estimated_duration,join_url:s,status:"waiting_for_join",message_for_user:`${i.session_type_name} (${i.estimated_duration}min) ready \xB7 ${s}`}}export{E as a,pe as b,x as c,he as d,ve as e,Ce as f,M as g,Se as h,Ve as i,Le as j};
|
package/dist/cli.js
CHANGED
|
@@ -1,32 +1,76 @@
|
|
|
1
|
-
import{a as
|
|
2
|
-
|
|
3
|
-
`;e.write(r)}
|
|
4
|
-
`;
|
|
5
|
-
`;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
`)
|
|
11
|
-
`;n
|
|
12
|
-
`)
|
|
13
|
-
`)
|
|
14
|
-
`)
|
|
15
|
-
`)}
|
|
1
|
+
import{a as Gt,b as Xe,c as Vt,d as Yt,e as tt,f as nt,g as Wt,h as Jt,i as zt,j as Xt}from"./chunk-C6NO4B4N.js";import{d as Zt,g as en,h as tn,i as nn,j as rn,k as _e,l as on,m as sn}from"./chunk-AX3TLBEV.js";import{b as rt}from"./chunk-RB3EXF6P.js";import{a as q,b as Ze,e as et,f as Ht,g as jt,h as qt,i as Z,k as Qt}from"./chunk-P2IV5O3T.js";import{cac as Qi}from"cac";import{existsSync as zi}from"fs";import{createWriteStream as Yr}from"fs";import{mkdtemp as Wr,rm as Jr}from"fs/promises";import{tmpdir as Qr}from"os";import{join as an}from"path";import{pipeline as zr}from"stream/promises";import{Readable as Xr}from"stream";async function un(e){let t=await Wr(an(Qr(),"flowe-stream-")),n=an(t,"audio.mp3"),r=async()=>{try{await Jr(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 p=o.headers.get("content-length");return p?parseInt(p,10):null})(),i=(()=>{let m=o.headers.get("cache-control")?.match(/max-age=(\d+)/);return m?parseInt(m[1],10):null})(),a=0,u=Xr.fromWeb(o.body),c=Yr(n);return u.on("data",p=>{a+=p.length,e.onProgress?.(a,s)}),await zr(u,c),{filePath:n,cleanup:r,bytes:a,cacheMaxAge:i}}catch(o){throw await r(),o}}function Zr(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=q(),n=await Z();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=Zr(t.backend_url,e.type,r,o),i;if(process.stdout.isTTY){let p=-1;i=(m,P)=>{if(!P){process.stdout.write(`\r fetching ${e.type}\u2026 ${m} bytes`);return}let A=Math.floor(m/P*100);A!==p&&(p=A,process.stdout.write(`\r fetching ${e.type}\u2026 ${A}%`))}}let a=await un({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 ws from"node-notifier";import{fileURLToPath as Ss}from"url";import{dirname as ys,join as ks}from"path";var ot="\x1B[0m",eo="\x1B[1m",to="\x1B[2m",st={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},charcoal:{r:45,g:45,b:45}};function it(){return process.env.NO_COLOR?!1:process.env.FORCE_COLOR?!0:!!process.stdout.isTTY}function at(e,t){return it()?`\x1B[38;2;${e.r};${e.g};${e.b}m${t}${ot}`:t}var d=e=>at(st.oak,e),N=e=>at(st.oakDeep,e),cn=e=>at(st.sage,e);var l=e=>it()?`${to}${e}${ot}`:e,k=e=>it()?`${eo}${e}${ot}`:e;var no=/\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 ut(e){return e.replace(no,"").length}function Y(e,t){let n=ut(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} ${Y(o,t)} ${B.v}`),r]}function M(e,t){let n=ut(e);if(n>=t)return e;let r=Math.floor((t-n)/2);return" ".repeat(r)+e}var ro=54;function dt(e,t=ro){return K(e,t)}function oo(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 ln(e,t=new Date){let n=oo(t),r=(e??"").trim(),o=r.length>0?r:"there";return`${n}, ${o}.`}function Oe(e,t){let n=t?d("\u25B8 "):" ",r=t?k(d(e.label)):e.label,o=e.detail?" "+l("\xB7 "+e.detail):"";return` ${n}${r}${o}`}function ft(e){let t=d("\u2713"),n=l(e.label.toUpperCase().padEnd(8)),r=d(e.value);return` ${t} ${n} ${r}`}function mt(e){return e.length===0?[]:[...e.map(ft),""]}var dn=" \u2191\u2193 to move \u23CE to select esc to cancel",so=" \u2191\u2193 to move \u23CE to select esc to back",pt=[30,45,60,90],$e=[{id:"ellie",description:"warm, even pace"},{id:"sage",description:"grounded, low"},{id:"ada",description:"clear, neutral"}];function io(e,t=[]){return dt(["",...mt(t),` ${N("\u25C6")} you're not signed in.`,""," sign in to track your progress, build a streak,"," and personalize your sessions.","",Oe({label:"SIGN IN"},e===0),Oe({label:"MAYBE LATER",detail:"anonymous"},e===1),"",l(dn),""])}function ao(e,t,n=[],r=pt){return dt(["",...mt(n),` ${t}`," What's the cadence for today?","",...r.map((o,s)=>Oe({label:`${o} seconds`},s===e)),"",l(dn),""])}function uo(e,t=[]){return dt(["",...mt(t)," Pick your guide.","",...$e.map((n,r)=>Oe({label:n.id,detail:n.description},r===e)),"",l(so),""])}var Te=e=>`\x1B[${e}A`,lt="\x1B[2K",co="\x1B[?25l",lo="\x1B[?25h";function fo(e,t,n){let r="";n>0&&(r+=Te(n));for(let o of t)r+=`\r${lt}${o}
|
|
2
|
+
`;if(n>t.length){let o=n-t.length;for(let s=0;s<o;s++)r+=`\r${lt}
|
|
3
|
+
`;r+=Te(o)}e.write(r)}function mo(e,t=pt){let n=t.indexOf(e);if(n>=0)return n;let r=t.indexOf(60);return r>=0?r:0}function po(e){let t=$e.findIndex(n=>n.id===e);return t>=0?t:0}async function ct(e,t,n,r,o,s){let i=n,a=()=>{let u=o(i);fo(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 fn(e){let t=e.io??bo();t.setRawMode?.(!0),t.out.write(co);let n={height:0};try{let r="already_authed",o=[];if(e.showAuthWedge){let i=await ct(t,n,0,2,a=>io(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:pt;for(;;){let i=await ct(t,n,mo(e.defaultDuration,s),s.length,u=>ao(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 ct(t,n,po(e.defaultVoice),$e.length,u=>uo(u,o),u=>$e[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(lo),e.clearOnExit&&n.height>0){let r=Te(n.height);for(let o=0;o<n.height;o++)r+=`\r${lt}
|
|
4
|
+
`;r+=Te(n.height),t.out.write(r)}await t.keys.return?.()}}function mn(){return!!process.stdout.isTTY&&!!process.stdin.isTTY&&!process.env.NO_COLOR&&!process.env.CI}function bo(){let e=process.stdin;return{out:process.stdout,setRawMode:n=>{e.isTTY&&e.setRawMode(n)},keys:go(e)}}function go(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 p=n.shift();p?p(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 xe(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 ho(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(ho(e,t)/1e3);return Math.max(0,n-r)}function pn(e,t,n){return{...e,status:t,blockIndex:t==="FOCUS_BLOCK"?e.blockIndex+1:e.blockIndex,enteredAtMs:n,pausedAtMs:null,pausedDurationMs:0}}function bn(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:pn(e,bn(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:pn(e,bn(e),t.nowMs)}}function Be(e,t){return e.status!==t.status||e.blockIndex!==t.blockIndex}var wo=100,So=8e3,gn=28;function yo(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 ko=24,Eo=11,hn=64,bt=["\xB7","\u2219","\u2022","\u25CF"],wn=1e3,Co=(()=>{let e=[],t=Math.PI*(3-Math.sqrt(5));for(let n=0;n<hn;n++){let r=n*t%(2*Math.PI),o=Math.sqrt((n+.5)/hn),s=n*.4123*2*Math.PI%(2*Math.PI);e.push({angle:r,radius:o,phaseOffset:s})}return e})();function vo(e,t){return e<=1?N(t):d(t)}function ht(e,t,n=ko,r=Eo,o=So){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)/wn),a=Math.min(1,Math.max(0,t)/wn),u=Math.min(i,a);if(u<=0)return new Array(r).fill("");let c=(n-1)/2,p=(r-1)/2,m=(n-2)/2,P=(r-2)/2,A=e/o*2*Math.PI;for(let g of Co){let w=.5+.5*Math.sin(A+g.phaseOffset),b=1-g.radius*.35,E=w*b*u;if(E<.12)continue;let h=Math.round(c+g.radius*m*Math.cos(g.angle)),C=Math.round(p+g.radius*P*Math.sin(g.angle));h<0||h>=n||C<0||C>=r||E>s[C][h]&&(s[C][h]=E)}let _=[],R=.88/bt.length;for(let g=0;g<r;g++){let w="";for(let b=0;b<n;b++){let E=s[g][b];if(E<.12){w+=" ";continue}let h=Math.min(bt.length-1,Math.floor((E-.12)/R));w+=vo(h,bt[h])}_.push(w)}return _}var wt=60,gt=50,Sn=gt+2;function Po(e){return`${Math.max(0,Math.floor(e))}s`}function Ro(e,t,n){return` ${N("\u2740")} ${k("SESSION_ACTIVE")} ${t}s \xB7 ${e} \xB7 ${l(n)}`}function Io(e){let t=` ${B.inTl}${B.h.repeat(Sn)}${B.inTr} `,n=` ${B.inBl}${B.h.repeat(Sn)}${B.inBr} `,r=e.map(o=>{let s=M(o,gt);return` ${B.v} ${Y(s,gt)} ${B.v} `});return[t,...r,n]}function Ao(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=yo(t,e);if(n<0)return"";let r=Ao(e[n].label),o=`[ ${k(d(r))} ]`;return M(o,wt)}function Oo(e,t,n){let r=Math.max(0,Math.min(.999,e/t));return Math.min(n,Math.floor(r*n)+1)}function $o(e,t,n,r){let o=`${l("TIME_REMAINING")} ${d(`-${Po(e/1e3)}`)}`;if(!r)return` ${o}`;let s=Oo(t,n,r),i=`${l("ROUND")} ${d(`${s} / ${r}`)}`,a=Math.floor(wt/2);return Y(` ${o}`,a)+i}function To(e,t){let n=Math.min(1,Math.max(0,e/t)),r=Math.round(n*gn),o=gn-r,s=`${d("\u2588".repeat(r))}${l("\u2591".repeat(o))}`,i=`${Math.round(n*100)}%`;return` ${l("PROGRESS_SEQUENCE")} [${s}] ${l(i)}`}var xo="\x1B[?25l",yn="\x1B[?25h",No=e=>`\x1B[${e}A`,Mo="\x1B[H",Bo="\x1B[2K",Fo="\r",Do="\x1B[?1049h",kn="\x1B[?1049l",Lo=25;function En(e,t,n){let r=Math.max(0,n-t),o=Io(ht(t,r)),s=["",Ro(e.displayName,e.duration,e.voice),"",...o,"",_o(e.cues,t),"",$o(r,t,n,e.rounds),"",To(t,n),""];return{lines:K(s,wt)}}function Cn(e,t,n){let r="";n||(r+=No(Lo));for(let o of t.lines)r+=`${Fo}${Bo}${o}
|
|
5
|
+
`;e.write(r)}async function vn(e){let t=e.out??process.stdout,n=e.now??Date.now,r=e.startedAt??n(),o=e.duration*1e3;t.write(Do+Mo+xo);let s=!0,i=!1,a=()=>{if(i)return;let p=n()-r,m=En(e,p,o);Cn(t,m,s),s=!1};a();let u=setInterval(a,wo),c=()=>{i=!0,clearInterval(u),t.write(yn+kn),process.exit(130)};process.once("SIGINT",c);try{await e.donePromise}finally{i=!0,clearInterval(u),process.removeListener("SIGINT",c);let p=En(e,o,o);Cn(t,p,!1),t.write(yn+kn)}}function Pn(){return!!process.stdout.isTTY&&!process.env.NO_COLOR&&!process.env.CI}var x=60,kt=30,Ko=28,Uo=8,Go=1e4,Et=25,Ho=Et+2;function ee(e){return e.length>=Et?e:[...e,...new Array(Et-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 jo(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`${d("\u2588".repeat(o))}${l("\u2591".repeat(s))}`}function qo(e,t){return t<=0?"0%":`${Math.round(e/t*100)}%`}function Vo(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 An(e,t){return` ${N("\u2740")} ${k(Vo(e.status))} ${l(t)}`}function te(e){return e.length===0?[]:[...e.map(ft),""]}function Yo(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 _n(e,t){let n=Yo(e,t);return M(`${d("\u25B8")} ${l(n)}`,x)}function Wo(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 Jo(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=Wo(e.preset),n=Jo(e,t),r=[];for(let o=0;o<t.length;o++)o<n?r.push(d("\u2713")):o===n?r.push(k(d("\u25B8"))):r.push(l("\xB7"));return r.join(" ")}function Qo(e,t){let n=e.paused&&e.state.pausedAtMs!==null?e.state.pausedAtMs-e.state.enteredAtMs:e.elapsedMs;return ht(n,t*1e3,Ko,Uo,Go).map(r=>M(e.paused?l(r):r,x))}function $n(e){let t=`[ ${k(d(e))} ]`;return M(t,x)}function Tn(e,t){let n=jo(e,t),r=qo(e,t);return` ${l("PROGRESS_SEQUENCE")} [${n}] ${l(r)}`}function xn(e){return e?` ${k(d("space"))} ${k("resume")} \xB7 ${l("s")} skip \xB7 ${k(d("q"))} ${k("quit")} \xB7 ${l("?")} help`:` ${l("space")} pause \xB7 ${l("s")} skip \xB7 ${l("q")} quit \xB7 ${l("?")} help`}function zo(e){let t=e.state.preset,n=["",` ${N("\u2740")} ${k("FOCUS_CYCLE")} ${l(e.presetName)}`,"",...te(e.breadcrumbs??[]),` ${l("blocks")} ${d(String(t.blocks))}`,` ${l("focus")} ${d(we(t.focusSec))} each`,` ${l("break")} ${d(we(t.breakSec))} each`,` ${l("long break")} ${d(we(t.longBreakSec))} after the last block`,"",M(`[ ${k(d("press enter to begin"))} ]`,x),"",` ${l("q")} quit`,""];return K(ee(n),x)}function St(e,t){let n=Ne(e.state),r=J(e.state,e.nowMs),o=n-r,s=e.paused?"PAUSED":t,i=["",An(e.state,e.presetName),"",...te(e.breadcrumbs??[]),_n(e.state,e.nowMs),"",...Qo(e,r),"",M(On(e.state),x),"",$n(`${s} . . .`),"",Tn(o,n),"",xn(e.paused),""];return K(ee(i),x)}function Xo(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=["",An(e.state,e.presetName),"",...te(e.breadcrumbs??[]),_n(e.state,e.nowMs),"","","",M(`${d(`next: ${o} in ${t}s`)}`,x),"","",M(On(e.state),x),"",$n("FETCHING SESSION . . ."),"",Tn(r,n),"",xn(e.paused),""];return K(ee(s),x)}function Zo(e){let t=e.state.preset,n=we(t.focusSec*t.blocks),r=["",` ${N("\u2740")} ${k("CYCLE_DONE")} ${l(e.presetName)}`,"",...te(e.breadcrumbs??[]),` ${l("focus blocks")} ${d(`${t.blocks}`)}`,` ${l("total deep work")} ${d(n)}`,` ${l("breaks taken")} ${d(`${t.blocks}`)}`,"",M(`[ ${k(d("nice work"))} ]`,x),"",` ${l("r")} repeat \xB7 ${l("x")} exit`,""];return K(ee(r),x)}function Fe(e){switch(e.state.status){case"PRE_FLIGHT":return zo(e);case"FOCUS_BLOCK":return St(e,"DEEP WORK");case"TRANSITION":return Xo(e);case"BREAK":return St(e,"BREATHE");case"LONG_BREAK":return St(e,"LONG_REST");case"CYCLE_DONE":return Zo(e)}}function De(e){return Ho}function Ct(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 es(e,t){let n=t?d("\u25B8 "):" ",r=t?k(d(e)):e,o=l(`\xB7 ${Ct(e)}`);return` ${n}${Y(r,10)} ${o}`}function Nn(e,t=[]){let n=["",` ${N("\u2740")} ${k("FOCUS_CYCLE")} ${l("pick a cadence")}`,"",...te(t),...ne.map((r,o)=>es(r,o===e)),"",` ${l("\u2191\u2193 to move \u23CE to select esc to cancel")}`,""];return K(ee(n),x)}var Mn=22,ts=22,yt=["\u2581","\u2582","\u2583","\u2584","\u2585","\u2584","\u2583","\u2582"];function ns(e){let t=e%yt.length,n="";for(let r=0;r<5;r++)n+=yt[(t+r)%yt.length];return n}function rs(e){let t=e?d("\u25B8"):" ",n=e?k(d("none")):"none",r=l("silence \u2014 your own thoughts");return` ${t} ${Y(n,Mn)} ${r}`}function os(e){return` ${l(e.toUpperCase())}`}function ss(e,t,n){let r=t?d("\u25B8"):" ",o=t?k(d(e.name)):e.name,s=l(Y(e.blurb,ts)),i=t?d(` ${ns(n)}`):"";return` ${r} ${Y(o,Mn)} ${s}${i}`}function Bn(e){let{entries:t,selectedIdx:n,tickFrame:r,breadcrumbs:o=[]}=e,s=[];s.push(` ${N("\u2740")} ${k("FOCUS_CYCLE")} ${l("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(rs(u)):a.kind==="category"?s.push(os(a.label)):s.push(ss(a.sound,u,r))}return s.push(""),s.push(` ${l("\u2191\u2193 to move \u23CE to select esc to cancel")}`),K(ee(s),x)}var Rn=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function In(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} kB`:`${(e/1024/1024).toFixed(1)} MB`}function is(e,t){let n=t<=0?0:Math.max(0,Math.min(1,e/t)),r=Math.round(n*kt),o=kt-r;return`${d("\u2588".repeat(r))}${l("\u2591".repeat(o))}`}function Fn(e){let{sound:t,status:n,downloaded:r,total:o,tickFrame:s,breadcrumbs:i=[]}=e,a=Rn[s%Rn.length],u=n==="ready"?k(d("READY . . .")):n==="failed"?k(d("OFFLINE \u2014 STARTING IN SILENCE")):n==="timeout"?k(d("TIMED OUT \u2014 STARTING IN SILENCE")):`${d(a)} ${k("PREPARING . . .")}`,c=o<=0?0:Math.round(r/o*100),p=t?`${k(d(t.name))} ${l(t.blurb)}`:`${k(d("silence"))} ${l("your own thoughts")}`,m=t?`${l(In(r))} ${l("/")} ${l(In(o))} ${l(`${c}%`)}`:"",P=["",` ${N("\u2740")} ${k("FOCUS_CYCLE")} ${l("preparing your ambience")}`,"",...te(i),M(`[ ${u} ]`,x),"",M(p,x),"",M(`[${is(r,o)}]`,x),"",M(m,x),"",` ${l("esc to cancel")}`,""];return K(ee(P),x)}import{existsSync as ie,mkdirSync as as,readFileSync as vt,renameSync as Ln,rmSync as Pt,writeFileSync as Rt}from"fs";import{homedir as us}from"os";import{join as ae}from"path";var cs="state.json",ls="daemon.pid",ds="control.txt",fs="daemon.log",ms=3e4,ps=["pause","resume","skip","quit"];function bs(){return process.env.FLOWE_HOME??ae(us(),".flowe")}function ue(){return ae(bs(),"sessions","active")}function Kn(){return ae(ue(),cs)}function It(){return ae(ue(),ls)}function Un(){return ae(ue(),ds)}function Gn(){return ae(ue(),fs)}function Se(){let e=ue();return ie(e)||as(e,{recursive:!0}),e}function Le(e){Se();let t=Kn(),n=`${t}.tmp`;Rt(n,JSON.stringify(e,null,2),"utf-8"),Ln(n,t)}function ye(e={}){let t=Kn();if(!ie(t))return null;try{let n=vt(t,"utf-8"),r=JSON.parse(n);if(r.version!==1)return null;let o=r;if(!gs(o)||ce()!==o.pid)return null;if(!ke(o.pid,e.kill))return Q(),null;let i=e.now??Date.now,a=e.staleAfterMs??ms;return i()-o.updatedAt>a?null:o}catch{return null}}function gs(e){return e.version===1&&typeof e.pid=="number"&&Number.isInteger(e.pid)&&e.pid>0&&typeof e.updatedAt=="number"&&Number.isFinite(e.updatedAt)}function Q(){let e=ue();ie(e)&&Pt(e,{recursive:!0,force:!0})}function Dn(e=process.pid){Se(),Rt(It(),String(e),"utf-8")}function ce(){let e=It();if(!ie(e))return null;try{let t=vt(e,"utf-8").trim();if(t.length===0)return null;let n=Number(t);return!Number.isInteger(n)||n<=0?null:n}catch{return null}}function hs(){let e=It();ie(e)&&Pt(e,{force:!0})}function ke(e,t=(n,r)=>{process.kill(n,r)}){if(!Number.isInteger(e)||e<=0)return!1;try{return t(e,0),!0}catch(n){return n.code==="EPERM"}}function Ke(e={}){let t=e.pidOverride??process.pid,n=ce();return n!==null&&n!==t&&ke(n,e.kill)?{kind:"busy",pid:n}:n!==null&&n!==t?(Q(),Dn(t),{kind:"swept",stalePid:n}):(Dn(t),{kind:"acquired"})}function Ue(){hs()}function Ge(e){let t=ce();if(t===null||!ke(t))throw t!==null&&Q(),new Error("no active focus session");Se();let n=Un(),r=`${n}.tmp`;Rt(r,`${e}
|
|
6
|
+
`,"utf-8"),Ln(r,n)}function He(){let e=Un();if(!ie(e))return null;let t;try{t=vt(e,"utf-8")}catch{return null}finally{Pt(e,{force:!0})}let n=t.trim().toLowerCase();return ps.includes(n)?n:null}var Ee="\x1B[?1049h",le="\x1B[?1049l",fe="\x1B[?25l",de="\x1B[?25h",Ce="\x1B[H",qe=e=>`\x1B[${e}A`,Ve="\x1B[2K",Es=100,Cs=3e4,qn=80,Hn=ks(ys(Ss(import.meta.url)),"..","assets/notification-icon.png");async function Vn(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()}},p=g=>{let w=Buffer.isBuffer(g)?g:Buffer.from(g);for(let b of W(w))i.push(b);c()},m=()=>{a=!0,c()};n.isTTY&&n.setRawMode(!0),n.resume(),n.on("data",p),n.once("end",m),t.write(Ee+Ce+fe);let P=!0,A=()=>{let g=Nn(s,o),w="";P||(w+=qe(g.length));for(let b of g)w+=`\r${Ve}${b}
|
|
7
|
+
`;t.write(w),P=!1},_=()=>{n.isTTY&&n.setRawMode(!1),n.off("data",p),n.off("end",m),n.pause(),t.write(de+le)},R=()=>{_(),process.removeListener("SIGINT",R),process.exit(0)};process.on("SIGINT",R);try{for(A();;){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,A();else if(g.name==="down"||g.name==="tab"||g.name==="char"&&g.char?.toLowerCase()==="j")s=(s+1)%ne.length,A();else{if(g.name==="return")return ne[s];if(g.name==="char"&&g.char?.toLowerCase()==="q")return null}}}}finally{process.removeListener("SIGINT",R),_()}}function vs(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 Yn(e){let t=e.out??process.stdout,n=e.stdin??process.stdin,r=e.breadcrumbs??[],o=on(e.manifest),s=sn(o),i=vs(o,e.defaultSoundId),a=0,u=[],c=!1,p=null,m=()=>{if(p){let h=p;p=null,h.resolve()}},P=h=>{let C=Buffer.isBuffer(h)?h:Buffer.from(h);for(let F of W(C))u.push(F);m()},A=()=>{c=!0,m()};n.isTTY&&n.setRawMode(!0),n.resume(),n.on("data",P),n.once("end",A),t.write(Ee+Ce+fe);let _=!0,R=()=>{let h=Bn({entries:o,selectedIdx:i,tickFrame:a,breadcrumbs:r}),C="";_||(C+=qe(h.length));for(let F of h)C+=`\r${Ve}${F}
|
|
8
|
+
`;t.write(C),_=!1},g=()=>{n.isTTY&&n.setRawMode(!1),n.off("data",P),n.off("end",A),n.pause(),t.write(de+le)},w=()=>{g(),process.removeListener("SIGINT",w),process.exit(0)};process.on("SIGINT",w);let b=(h,C)=>{let F=s.indexOf(h);if(F<0)return h;let D=(F+C+s.length)%s.length;return s[D]},E=setInterval(()=>{a++,R()},qn);try{for(R();;){if(u.length===0){if(c)return null;await new Promise(h=>{p={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),R();else if(h.name==="down"||h.name==="tab"||h.name==="char"&&h.char?.toLowerCase()==="j")i=b(i,1),R();else if(h.name==="return"){let C=o[i];if(C.kind==="none")return{sound:null};if(C.kind==="sound")return{sound:C.sound}}else if(h.name==="char"&&h.char?.toLowerCase()==="q")return null}}}finally{E&&(clearInterval(E),E=null),process.removeListener("SIGINT",w),g()}}async function Wn(e){let t=e.out??process.stdout,n=e.sound,r=e.timeoutMs??Cs,o=e.breadcrumbs??[];if(!n)return jn(t,{sound:null,status:"ready",downloaded:0,total:0,tickFrame:0,breadcrumbs:o},!0),await je(250),{filePath:null,outcome:"silent"};if(tn(n))return{filePath:Zt(n),outcome:"cached"};let s=0,i=n.bytes,a=0,u="fetching",c=!0,p=()=>{jn(t,{sound:n,status:u,downloaded:s,total:i,tickFrame:a,breadcrumbs:o},c),c=!1},m=setInterval(()=>{a++,p()},qn),P=new AbortController,A=setTimeout(()=>{P.abort(),_?.("timeout")},r),_=null,R=new Promise(E=>{_=E}),g=(E,h)=>{s=E,i=h||n.bytes},w=(e.download?e.download(n,g):rn(n,{signal:P.signal,onProgress:E=>g(E.downloaded,E.total)})).then(E=>({ok:!0,path:E})).catch(()=>({ok:!1}));t.write(Ee+Ce+fe),p();let b=await Promise.race([w,R]);return clearInterval(m),clearTimeout(A),_=null,b==="timeout"?(u="timeout",p(),await je(400),t.write(de+le),{filePath:null,outcome:"timeout"}):b.ok?(u="ready",s=i,p(),await je(300),t.write(de+le),{filePath:b.path,outcome:"ready"}):(u="failed",p(),await je(400),t.write(de+le),{filePath:null,outcome:"failed"})}function jn(e,t,n){let r=Fn(t),o="";n?o+=Ee+Ce+fe:o+=qe(r.length);for(let s of r)o+=`\r${Ve}${s}
|
|
9
|
+
`;e.write(o)}function je(e){return new Promise(t=>setTimeout(t,e))}function Ps(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,p=(e.ambientEnabled??!0)&&!!c,m=e.startAmbient??_e,P=e.breadcrumbs??[],A=e.autoStart??!0,_=e.stateEnabled??!0,R=e.ambientId??null,g=process.pid,w=!1;if(_){let f=Ke({pidOverride:g});if(f.kind==="busy")throw new Error(`focus session already running (pid ${f.pid})`);w=!0}let b=xe(o,r()),E=b.enteredAtMs,h=null,C=null,F=()=>{C?.stop(),C=null},D=De(o),I=!0,$="",G=(f,y=!1)=>{let v=f.join(`
|
|
10
|
+
`);if(!y&&!I&&v===$)return;let j="";I||(j+=qe(D));for(let Vr of f)j+=`\r${Ve}${Vr}
|
|
11
|
+
`;t.write(j),I=!1,$=v},S=(f=!1)=>{let y=r()-b.enteredAtMs,v=Fe({state:b,presetName:s,elapsedMs:y,nowMs:r(),paused:b.pausedAtMs!==null,breadcrumbs:P});G(v,f)},L=()=>{if(!(!_||!w))try{Le({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:R,startedAt:E,updatedAt:r()})}catch{}},H=f=>f<60?`${f}s`:`${Math.round(f/60)} min`,Ie=f=>{if(!u)return;let y="",v="";if(f.status==="FOCUS_BLOCK")y=`flowe \xB7 block ${f.blockIndex}/${f.preset.blocks}`,v=`${H(f.preset.focusSec)}. one thing. lock in.`;else if(f.status==="BREAK")y="flowe \xB7 break",v=`${H(f.preset.breakSec)}. stand up. breathe.`;else if(f.status==="LONG_BREAK")y="flowe \xB7 long break",v=`${H(f.preset.longBreakSec)}. walk. eyes off the screen.`;else if(f.status==="CYCLE_DONE")y="flowe \xB7 cycle done",v=`${f.preset.blocks} blocks banked. go ship.`;else return;try{ws.notify({title:y,message:v,icon:Hn,contentImage:Hn,sound:!0})}catch{}},Je=async f=>{if(Ie(f),f.status==="FOCUS_BLOCK"?p&&!C&&c&&(C=m(c)):F(),f.status==="BREAK"||f.status==="LONG_BREAK"){let y=f.status==="BREAK"?i:a,v=f.status==="BREAK"?5:15;try{h=await se({type:y,durationMin:v})}catch{h=null}}(f.status==="FOCUS_BLOCK"||f.status==="CYCLE_DONE")&&(h?.cancel(),h=null)},V=async f=>{let y=b,v=Me(y,f);v!==y&&(b=v,L(),Be(y,v)?await Je(v):qr(y,v))},qr=(f,y)=>{let v=f.pausedAtMs!==null,j=y.pausedAtMs!==null;if(v!==j&&y.status==="FOCUS_BLOCK"){if(j){F();return}p&&!C&&c&&(C=m(c))}},X=[],Ae=!1,oe=null,Qe=()=>{if(oe){let f=oe;oe=null,f.resolve()}},Bt=f=>{let y=Buffer.isBuffer(f)?f:Buffer.from(f);for(let v of W(y))X.push(v);Qe()},Ft=()=>{Ae=!0,Qe()},Dt=()=>{n.isTTY&&n.setRawMode(!0)};Dt(),n.resume(),n.on("data",Bt),n.once("end",Ft),t.write(Ee+Ce+fe);let Lt=f=>X.length>0||Ae?Promise.resolve():new Promise(y=>{let v={resolve:y};oe=v,setTimeout(()=>{oe===v&&(oe=null,y())},f)}),ze=()=>{h?.cancel(),h=null,F(),w&&(Ue(),Q(),w=!1),n.isTTY&&n.setRawMode(!1),n.off("data",Bt),n.off("end",Ft),n.pause(),process.removeListener("SIGCONT",Ut),t.write(de+le)},Kt=()=>{ze(),process.removeListener("SIGINT",Kt),process.exit(0)};process.on("SIGINT",Kt);let Ut=()=>{Dt(),t.write(fe),I=!0,$="",S(!0),Qe()};process.on("SIGCONT",Ut);try{if(A&&b.status==="PRE_FLIGHT"){let f=he(b,r());f!==b&&(b=f,E=b.enteredAtMs,L(),await Je(b))}for(S();b.status==="PRE_FLIGHT";){if(await Lt(6e4),Ae&&X.length===0){ze();return}for(;X.length>0;){let f=X.shift();if(f.name==="ctrl-c"||f.name==="escape"){await V({kind:"QUIT",nowMs:r()});break}if(f.name==="return"){let y=he(b,r());y!==b&&(b=y,E=b.enteredAtMs,L(),await Je(b));break}if(f.name==="char"&&(f.char??"").toLowerCase()==="q"){await V({kind:"QUIT",nowMs:r()});break}}}for(;b.status!=="CYCLE_DONE";){S(),L();let f=!1,y=_&&w?He():null;for(y&&(await V(Ps(y,r())),y==="quit"&&(f=!0));X.length>0&&!f;){let v=X.shift();if(v.name==="ctrl-c"||v.name==="escape"){await V({kind:"QUIT",nowMs:r()}),f=!0;break}if(v.name==="char"){let j=(v.char??"").toLowerCase();if(j===" ")await V(b.pausedAtMs!==null?{kind:"RESUME",nowMs:r()}:{kind:"PAUSE",nowMs:r()});else if(j==="s")await V({kind:"SKIP",nowMs:r()});else if(j==="q"||j==="x"){await V({kind:"QUIT",nowMs:r()}),f=!0;break}}}if(f){S();break}if(b.status==="CYCLE_DONE")break;if(Ae){await V({kind:"QUIT",nowMs:r()});continue}await Lt(Es),await V({kind:"TICK",nowMs:r()})}S()}finally{ze()}}import Rs from"node-notifier";import{fileURLToPath as Is}from"url";import{dirname as As,join as _s}from"path";var Os=100,$s="quick_reset",Ts="executive_reset",Qn=_s(As(Is(import.meta.url)),"..","assets/notification-icon.png");function xs(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 Ns(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 Ms(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 Bs=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??Os,s=e.breakType??$s,i=e.longBreakType??Ts,a=e.notifications??!0,u=e.startAmbient??_e,c=e.runBreak??se,p=e.consumeControl??He,m=e.pidOverride??process.pid,P=e.ambientId??null,A=e.ambientFilePath,_=Ke({pidOverride:m});if(_.kind==="busy")return{finalStatus:"PRE_FLIGHT",ticks:0,reason:"busy",busyPid:_.pid};let R=he(xe(t,r()),r()),g=R.enteredAtMs,w=null,b=null,E=()=>{b?.stop(),b=null},h=()=>{let S=Ns(R,{pid:m,preset:n,ambientId:P,startedAtMs:g,nowMs:r()});try{Le(S)}catch{}},C=async S=>{if(Ms(S,a),S.status==="FOCUS_BLOCK"?A&&!b&&(b=u(A)):E(),S.status==="BREAK"||S.status==="LONG_BREAK"){let L=S.status==="BREAK"?s:i,H=S.status==="BREAK"?5:15;try{w=await c({type:L,durationMin:H})}catch{w=null}}(S.status==="FOCUS_BLOCK"||S.status==="CYCLE_DONE")&&(w?.cancel(),w=null)},F=(S,L)=>{let H=S.pausedAtMs!==null,Ie=L.pausedAtMs!==null;if(H!==Ie&&L.status==="FOCUS_BLOCK"){if(Ie){E();return}A&&!b&&(b=u(A))}},D=async S=>{let L=R,H=Me(L,S);H!==L&&(R=H,Be(L,H)?await C(H):F(L,H))};await C(R),h();let I=0,$="cycle_done",G=e.maxTicks??Number.POSITIVE_INFINITY;try{for(;R.status!=="CYCLE_DONE"&&I<G;){let S=p();if(S!==null&&(await D(xs(S,r())),S==="quit")){$="quit";break}if(R.status==="CYCLE_DONE")break;await Bs(o),await D({kind:"TICK",nowMs:r()}),h(),I+=1}I>=G&&R.status!=="CYCLE_DONE"&&($="max_ticks")}finally{E(),w?.cancel(),w=null,h(),Ue(),R.status==="CYCLE_DONE"&&Q()}return{finalStatus:R.status,ticks:I,reason:$}}import{spawn as Fs}from"child_process";import{openSync as Ds,closeSync as Ls}from"fs";var Xn="FLOWE_FOCUS_DAEMON",At="FLOWE_FOCUS_PRESET",Zn="FLOWE_FOCUS_AMBIENT_FILE",er="FLOWE_FOCUS_AMBIENT_ID",tr="FLOWE_FOCUS_BREAK_TYPE",nr="FLOWE_FOCUS_LONG_BREAK_TYPE",ve=class extends Error{constructor(n){super(`a focus daemon is already running (pid ${n})`);this.existingPid=n;this.name="DaemonAlreadyRunningError"}existingPid};function Ks(e){let t={...process.env,[Xn]:"1",[At]:e.preset};return e.ambientFilePath&&(t[Zn]=e.ambientFilePath),e.ambientId&&(t[er]=e.ambientId),e.breakType&&(t[tr]=e.breakType),e.longBreakType&&(t[nr]=e.longBreakType),t}function rr(e){let t=ce();if(t!==null){if(ke(t))throw new ve(t);Q()}Se();let n=Gn(),r=Ds(n,"a"),o=e.spawnArgs?.cmd??process.execPath,s=e.spawnArgs?.args??[...process.execArgv,process.argv[1]??"","focus",e.preset],a=(e.spawnFn??Fs)(o,s,{detached:!0,stdio:["ignore",r,r],env:Ks(e)});if(Ls(r),a.unref(),a.pid===void 0)throw new Error("failed to spawn focus daemon (no pid returned)");let u=e.readyTimeoutMs??(e.spawnFn?0:1500);if(u>0&&!Us(a.pid,u))throw new Error("focus daemon did not become ready");return{pid:a.pid,logPath:n}}function Us(e,t){let n=Date.now()+t;for(;Date.now()<=n;){if(ce()===e)return!0;Gs(25)}return!1}function Gs(e){let t=new SharedArrayBuffer(4),n=new Int32Array(t);Atomics.wait(n,0,0,e)}function or(){let e=process.env[At];if(e!=="pomodoro"&&e!=="dev"&&e!=="ultradian"&&e!=="test2"&&e!=="test5")throw new Error(`invalid ${At}: ${e??"(unset)"} \u2014 daemon child cannot start`);return{preset:e,ambientFilePath:process.env[Zn]||void 0,ambientId:process.env[er]||void 0,breakType:process.env[tr]||void 0,longBreakType:process.env[nr]||void 0}}function sr(){return process.env[Xn]==="1"}function ir(e){return[`detached. pid ${e.pid}.`,`logs: ${e.logPath}`,"status: flowe focus status","pause: flowe focus pause resume: flowe focus resume","skip: flowe focus skip quit: flowe focus quit"].join(`
|
|
12
|
+
`)}var Hs="\x1B[?1049h",js="\x1B[?1049l",qs="\x1B[?25l",Vs="\x1B[?25h",Ys="\x1B[H",Ws=e=>`\x1B[${e}A`,Js="\x1B[2K",Qs=250;function zs(e,t){let n=U[e.preset],r=ur(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 ur(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 Xs(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 Zs=e=>new Promise(t=>setTimeout(t,e));function ei(){return["no active focus session.","","start one: flowe focus","or detached: flowe focus --detach"].join(`
|
|
13
|
+
`)}function cr(e){let t=ur(e.status,U[e.preset]);return[`flowe \xB7 ${e.preset} \xB7 ${e.status.toLowerCase()}`,`block ${e.blockIndex} / ${e.blocks}`,`remaining ${ar(e.remainingSec)}${t?` of ${ar(t)}`:""}`,`paused ${e.paused?"yes":"no"}`,`ambient ${e.ambient??"(none)"}`,`pid ${e.pid}`].join(`
|
|
14
|
+
`)}function ar(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 lr(e={}){let t=e.out??process.stdout,n=e.stdin??process.stdin,r=e.now??Date.now,o=e.pollMs??Qs,s=e.readState??ye,i=e.sendControl??Ge,a=e.maxPolls??Number.POSITIVE_INFINITY,u=s();if(u===null)return t.write(`${ei()}
|
|
15
|
+
`),{reason:"no_session"};let c=[],p=!1,m=null,P=()=>{if(m){let I=m;m=null,I.resolve()}},A=I=>{let $=Buffer.isBuffer(I)?I:Buffer.from(I);for(let G of W($))c.push(G);P()},_=()=>{p=!0,P()};n.isTTY&&n.setRawMode(!0),n.resume(),n.on("data",A),n.once("end",_),t.write(Hs+Ys+qs);let R=!0,g=u.preset,w=De(U[g]),b=I=>{let $="";R||($+=Ws(w));for(let G of I)$+=`\r${Js}${G}
|
|
16
|
+
`;t.write($),R=!1},E=I=>{let $=r(),G=zs(I,$),S=Fe({state:G,presetName:I.preset,elapsedMs:$-G.enteredAtMs,nowMs:$,paused:I.paused});b(S)},h=()=>{n.isTTY&&n.setRawMode(!1),n.off("data",A),n.off("end",_),n.pause(),t.write(Vs+js)},C=()=>{h(),process.removeListener("SIGINT",C),process.exit(0)};process.on("SIGINT",C);let F=0,D="cycle_done";try{let I=u;for(E(I);F<a;){let $=!1;for(;c.length>0;){let G=c.shift(),S=Xs(G,I?.paused??!1);if(S!==null){if(S==="detach"){D="detached",$=!0;break}try{i(S)}catch{}S==="quit"&&(D="quit")}}if($)break;if(p&&c.length===0){D="detached";break}if(await Zs(o),F+=1,I=s(),I===null){D=D==="quit"?"quit":"no_session";break}if(E(I),I.status==="CYCLE_DONE"){D=D==="quit"?"quit":"cycle_done";break}}}finally{process.removeListener("SIGINT",C),h()}return{reason:D}}import{readFileSync as ti}from"fs";import{dirname as ni,join as ri}from"path";import{fileURLToPath as oi}from"url";function fr(e,t){return e===null||e.status==="CYCLE_DONE"?ii(t):si(e,t)}function si(e,t){let n=dr(e.remainingSec),r=U[e.preset],o=fi(e.status,r),s=[];return s.push(ai(e,n)),s.push("---"),s.push(`flowe \xB7 ${e.preset} \xB7 ${li(e.status)}`),s.push(`block ${e.blockIndex} / ${e.blocks} | font=Menlo`),s.push(`remaining ${n}${o?` of ${dr(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(Ye("Resume","resume",t)):s.push(Ye("Pause","pause",t)),s.push(Ye("Skip block","skip",t)),s.push(Ye("Quit cycle","quit",t)),s.push("---"),s.push(`Open status in terminal | ${Re(t,["focus","status"])} terminal=true`),s.join(`
|
|
17
|
+
`)}function ii(e){return[ui(),"---","no active focus session | color=#8c8c8c size=11","---",`Start pomodoro | ${Re(e,["focus","pomodoro","--detach","--ambient","none"])} terminal=false refresh=true sfimage=play.circle.fill`,`Start dev | ${Re(e,["focus","dev","--detach","--ambient","none"])} terminal=false refresh=true sfimage=play.circle.fill`,`Start ultradian | ${Re(e,["focus","ultradian","--detach","--ambient","none"])} terminal=false refresh=true sfimage=play.circle.fill`].join(`
|
|
18
|
+
`)}function ai(e,t){let n=e.paused?`\u23F8 ${t}`:t;return mr(n,{dim:e.paused})}function ui(){return mr("flowe",{dim:!0})}function mr(e,t){let n=[],r=ci();return r&&n.push(`image=${r}`),t.dim&&n.push("color=#8c8c8c"),n.length?`${e} | ${n.join(" ")}`:e}var Pe=null;function ci(){if(Pe!==null)return Pe;try{let e=ni(oi(import.meta.url));Pe=ti(ri(e,"..","assets/menubar-icon.png")).toString("base64")}catch{Pe=""}return Pe}function li(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 Ye(e,t,n){let r=di(t),o=r?` sfimage=${r}`:"";return`${e} | ${Re(n,["focus",t])} terminal=false refresh=true${o}`}function di(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 Re(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 fi(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 dr(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 mi,existsSync as _t,mkdirSync as pi,readFileSync as bi,rmSync as gi,statSync as $u,writeFileSync as hi}from"fs";import{homedir as Ot}from"os";import{dirname as wi,join as me,resolve as Si}from"path";import{fileURLToPath as yi}from"url";import{execFileSync as pr,spawnSync as re}from"child_process";var $t="flowe.1s.sh";function ki(){return me(Ot(),"Library","Application Support","SwiftBar","Plugins")}function Tt(){try{let t=pr("/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 Ei=["Documents","Desktop","Downloads","Library/Mobile Documents"];function Ci(e,t=Ot()){if(!e.startsWith(`${t}/`))return!1;let n=e.slice(t.length+1);return Ei.some(r=>n===r||n.startsWith(`${r}/`))}function br(e){if(e?.override)return e.override;let t=(e?.readPref??Tt)(),n=e?.isRestricted??Ci;return t&&!n(t)?t:ki()}function gr(e){return re("/usr/bin/defaults",["write","com.ameba.SwiftBar","PluginDirectory",e],{stdio:"ignore"}).status===0}function hr(){re("/usr/bin/killall",["SwiftBar"],{stdio:"ignore"}),re("/usr/bin/open",["-a","SwiftBar"],{stdio:"ignore"})}function vi(){return me(wr(),"bin","menubar",$t)}function wr(){let e=yi(import.meta.url);return Si(wi(e),"..")}function Sr(){return me(wr(),"bin","flowe.js")}function yr(){try{let t=pr("/usr/bin/which",["flowe"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim();return t.length>0?t:null}catch{return null}}function Pi(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 kr(e){let t=br({override:e.pluginDir}),n=me(t,$t),r=e.templatePath??vi();if(!_t(r))throw new Error(`plugin template not found at ${r}`);let o=bi(r,"utf-8"),s=Pi(o,{floweBin:e.floweBin,nodeBin:e.nodeBin??process.execPath});return e.dryRun?{pluginPath:n,scriptContent:s,written:!1}:(pi(t,{recursive:!0}),hi(n,s,"utf-8"),mi(n,493),{pluginPath:n,scriptContent:s,written:!0})}function Er(e={}){let t=br({override:e.pluginDir}),n=me(t,$t),r=_t(n);return r&&gi(n),{pluginPath:n,existed:r}}function Cr(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(`
|
|
19
|
+
`)}function Ri(){return["/Applications/SwiftBar.app",me(Ot(),"Applications","SwiftBar.app")]}function Ii(){return Ri().some(e=>_t(e))}function Ai(){return re("/usr/bin/which",["brew"],{stdio:"ignore"}).status===0}function _i(){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 vr(e={}){let t=e.isInstalled??Ii,n=e.hasBrew??Ai,r=e.install??_i;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 Pr(){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(`
|
|
20
|
+
`)}function Rr(){re("/usr/bin/open",["-a","SwiftBar"],{stdio:"ignore"})}function Ir(){return re("/usr/bin/pgrep",["-x","SwiftBar"],{stdio:"ignore"}).status===0}function Ar(e){return e.existed?`removed \u2192 ${e.pluginPath}`:`nothing to remove (no plugin at ${e.pluginPath})`}function Oi(e){return new URL("/api/v1/cli/ambient/custom",e).toString()}function pe(e,t){return Object.assign(new Error(e),{code:t})}async function _r(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 Or(e){let t=e.prompt.trim();if(t.length<10)throw pe("prompt must be at least 10 characters","invalid_duration");let n=await Z();if(!n)throw pe("sign in with: flowe login","auth_required");let o=await(e.fetchFn??fetch)(Oi(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 pe("sign in with: flowe login","auth_required");if(o.status===403)throw pe(await _r(o),"agent_busy");if(!o.ok)throw pe(await _r(o),"network_error");let s=new Uint8Array(await o.arrayBuffer());if(s.byteLength===0)throw pe("ambient generation returned empty audio","network_error");let i=o.headers.get("X-Flowe-Ambient-Name");return{sound:en({name:e.name??i??"custom ambience",prompt:t,bytes:s})}}import{readFileSync as $i}from"fs";import{dirname as Ti,join as xi}from"path";import{fileURLToPath as Ni}from"url";var Mi=Ti(Ni(import.meta.url));function Bi(){try{let e=$i(xi(Mi,"..","package.json"),"utf-8");return JSON.parse(e).version}catch{return"0.0.0"}}var xt=[" \u2572\u2502\u2571 "," \u2500\u2500\u2740\u2500\u2500"," \u2571\u2502\u2572 "];function $r(){let e=Bi();return[d(xt[0]),`${d(xt[1])} ${N("flowe")} ${l(`v${e}`)}`,`${d(xt[2])} ${cn("neural reset for AI-paired engineers")}`].join(`
|
|
21
|
+
`)}var Tr=["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 xr(e){let t=Number.isFinite(e)?Math.max(0,Math.floor(e)):0;return Tr[t%Tr.length]}var Nr=60,Fi=28,Di=18;function be(e,t){return` ${l(e.padEnd(Di))} ${t}`}function Mr(e,t,n){return`${e} ${e===1?t:n}`}function Li(e){let t=` ${N("\u2740")} ${k("SUMMARY_REPORT")}`,n=be("PROTOCOL",d(e.protocolDisplayName)),r=be("DURATION",d(`${e.duration}s`)),o=be("GUIDE",d(e.voice)),s=e.rounds!=null?be("ROUNDS",d(String(e.rounds))):null,i=be("TODAY",d(Mr(e.sessionsToday,"session","sessions"))),a=e.streakDays!=null?be("STREAK",d(Mr(e.streakDays,"day","days"))):null,u=d("\u2588".repeat(Fi)),c=` ${l("INTEGRATION_SYNC")} [${u}] ${d("100%")}`,p=xr(e.totalSessions),m=M(l(`"${p}"`),Nr);return K(["",t,"",n,r,o,s,"",i,a,"",c,"",m,""].filter(A=>A!==null),Nr)}function Br(e,t=process.stdout){let n=Li(e);for(let r of n)t.write(r+`
|
|
22
|
+
`);return n.length}function Ki(){let e=N("\u25C6"),t=`[${d("r")}] repeat`,n=`[${d("n")}] new session`,r=`[${d("x")}] exit`;return` ${e} ${t} ${l("\xB7")} ${n} ${l("\xB7")} ${r}`}var Fr=2;async function Dr(e){e.setRawMode?.(!0),e.out.write(`
|
|
23
|
+
`+Ki()+`
|
|
24
|
+
`);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 Lr(){let e=process.stdin;return{out:process.stdout,setRawMode:n=>{e.isTTY&&e.setRawMode(n)},keys:Ui(e)}}function Ui(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 p=n.shift();p?p(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 Gi,mkdirSync as Hi,writeFileSync as ji}from"fs";import{homedir as qi,platform as Vi}from"os";import{join as We}from"path";var Kr="welcomed";function Nt(){let e=qi();return Vi()==="win32"?We(e,"AppData","Roaming","flowe"):We(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(`
|
|
25
|
+
`)}function Wi(e=Nt()){return Gi(We(e,Kr))}function Ji(e=Nt()){Hi(e,{recursive:!0}),ji(We(e,Kr),"","utf-8")}function Ur(e=process.stderr){try{let t=Nt();if(Wi(t))return;e.write(Yi()),Ji(t)}catch{}}var Gr=e=>`\x1B[${e}A`,Xi="\x1B[2K";function Zi(e,t){if(t<=0)return;let n=Gr(t);for(let r=0;r<t;r++)n+=`\r${Xi}
|
|
26
|
+
`;n+=Gr(t),e.write(n)}function ea(e){switch(e){case"auth_required":return 2;case"agent_busy":return 3;case"network_error":case"offline":return 4;default:return 1}}function z(e){let t=e,n=t?.message||String(e);process.stderr.write(`flowe: ${n}
|
|
27
|
+
`),process.exit(ea(t?.code))}function ta(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 Hr(e){if(Xe.includes(e))return e;throw Object.assign(new Error(`type must be one of: ${Xe.join(", ")}`),{code:"invalid_duration"})}function na(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 ra(e){let t=Yt();if(t.includes(e))return e;throw Object.assign(new Error(`unknown protocol "${e}" \u2014 available: ${t.join(", ")}`),{code:"invalid_duration"})}async function oa(e=2e3){let t=rt().catch(()=>null),n=new Promise(r=>setTimeout(()=>r(null),e));return Promise.race([t,n])}async function jr(e,t){let n=q(),r=await Z();r&&!n.user_first_name&&(await oa(),n=q());let o=ln(n.user_first_name),s=60;if(e)try{s=Mt(e)}catch{}let i=t?tt(t):void 0,a=await fn({defaultDuration:s,defaultVoice:n.voice,greeting:o,showAuthWedge:!r,availableDurations:i,signIn:async()=>{let{runLogin:u}=await import("./login-FRWDEJ6B.js");await u(),await rt()},clearOnExit:!0});return a?{duration:a.duration,voice:a.voice,family:t}:null}async function sa(e,t){if(t){let r=tt(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 ia(){if(sr()){let t=or(),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)}Ur();let e=Qi("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?ra(n.protocol):void 0,i=!n.quick&&mn()?await jr(t,o):await sa(t,o);if(!i)return;for(;;){i.voice&&Ze(i.voice);let a=await zt(i.duration,r,i.family),u=nt();if(Pn()&&u){await vn({duration:a.duration_seconds,voice:a.voice,displayName:a.protocol_display_name,cues:a.cues,rounds:a.rounds,donePromise:u}),et();let c=Br({protocolDisplayName:a.protocol_display_name,duration:a.duration_seconds,voice:a.voice,rounds:a.rounds,sessionsToday:Ht(),totalSessions:qt(),streakDays:jt()});if(n.quick)return;let p=await Dr(Lr());if(p==="exit")return;if(Zi(process.stdout,c+Fr),p==="repeat")continue;if(p==="new"){let m=await jr(void 0,i.family);if(!m)return;i=m;continue}return}process.stdout.write(`${a.message_for_user}
|
|
28
|
+
`);for(let c of a.cues)process.stdout.write(` \xB7 ${c.label}
|
|
29
|
+
`);u&&(await u,et());return}}catch(r){z(r)}}),e.command("nsdr [type]","Start an NSDR session (default: quick_reset; or pass a Core 8 type)").action(async t=>{try{let n=t?Hr(t):"quick_reset",r=await Xt(n);process.stdout.write(`${r.message_for_user}
|
|
30
|
+
`)}catch(n){z(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?Hr(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}
|
|
31
|
+
`);let u=await se({type:r,durationMin:o,voice:s,signal:i.signal});process.stdout.write(` playing\u2026 (Ctrl-C to stop)
|
|
32
|
+
`);try{await u.finished,process.stdout.write(` done.
|
|
33
|
+
`)}catch(c){throw u.cancel(),c}finally{process.off("SIGINT",a)}}catch(r){z(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 m=t;try{Ge(m),process.stdout.write(`sent: ${m}
|
|
34
|
+
`)}catch(P){process.stderr.write(`${P.message}
|
|
35
|
+
`),process.exit(1)}return}if(t==="status"){let m=ye();if(m===null){if(n.json){process.stdout.write(`${JSON.stringify({active:!1})}
|
|
36
|
+
`);return}process.stderr.write(`no active focus session
|
|
37
|
+
`),process.exit(1)}n.json?process.stdout.write(`${JSON.stringify(m)}
|
|
38
|
+
`):process.stdout.write(`${cr(m)}
|
|
39
|
+
`);return}if(t==="menubar"){let m=n.floweBin??"flowe",P=ye();process.stdout.write(`${fr(P,{floweBinary:m,nodeBinary:n.nodeBin})}
|
|
40
|
+
`);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 m=await lr();process.exit(m.reason==="no_session"?1:0)}let r=[],o;if(t===void 0){if(o=await Vn(),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 ${Ct(o)}`});let s=await nn().catch(()=>null),{loadCustomAmbientManifest:i,mergeAmbientManifests:a}=await import("./ambient-SIMIQWQM.js"),u=a(s,i()),c;if(n.ambient!==void 0)if(n.ambient==="none"||n.ambient==="")c={sound:null};else{let m=u?.sounds.find(P=>P.id===n.ambient);if(!m)throw Object.assign(new Error(`unknown ambient id: ${n.ambient}. Run \`flowe focus\` to pick interactively.`),{code:"invalid_duration"});c={sound:m}}else c=await Yn({manifest:u,breadcrumbs:r});if(c===null)return;r.push({label:"ambient",value:c.sound?.name??"silence"});let p=await Wn({sound:c.sound,breadcrumbs:r});if(n.detach)try{let m=rr({preset:o,ambientFilePath:p.filePath??void 0,ambientId:c.sound?.id});process.stdout.write(ir(m)+`
|
|
41
|
+
`);return}catch(m){throw m instanceof ve&&(process.stderr.write(`${m.message}
|
|
42
|
+
use \`flowe focus status\` or \`flowe focus quit\` first
|
|
43
|
+
`),process.exit(1)),m}await Jn({preset:o,ambientFilePath:p.filePath??void 0,ambientId:c.sound?.id??null,breadcrumbs:r})}catch(r){z(r)}}),e.command("status","Show config and queue state").action(()=>{let t=q();process.stdout.write($r()+`
|
|
16
44
|
|
|
17
45
|
`),process.stdout.write(`voice: ${t.voice}
|
|
18
46
|
`),process.stdout.write(`backend: ${t.backend_url}
|
|
19
47
|
`),process.stdout.write(`telemetry: ${t.telemetry}
|
|
20
48
|
`),process.stdout.write(`first_reset_at: ${t.first_reset_at??"(none yet)"}
|
|
21
|
-
`)}),e.command("voice [name]","Set preferred voice (sage, ada, or ellie)").action(t=>{if(!t){process.stdout.write(`current: ${
|
|
49
|
+
`)}),e.command("voice [name]","Set preferred voice (sage, ada, or ellie)").action(t=>{if(!t){process.stdout.write(`current: ${q().voice}
|
|
22
50
|
available: sage, ada, ellie
|
|
23
|
-
`);return}try{let n=
|
|
24
|
-
`)}catch(n){
|
|
51
|
+
`);return}try{let n=na(t);Ze(n),process.stdout.write(`voice set to ${n}
|
|
52
|
+
`)}catch(n){z(n)}}),e.command("protocols","List bundled reset protocols").action(()=>{let t=Vt();if(t.length===0){process.stdout.write(`(no protocols bundled yet)
|
|
25
53
|
`);return}for(let n of t)process.stdout.write(`${n.duration_seconds}s ${n.protocol_id.padEnd(24)} ${n.display_name}
|
|
26
|
-
`)}),e.command("login","Sign in with Clerk (device-grant flow)").action(async()=>{try{let{runLogin:t}=await import("./login-FRWDEJ6B.js");await t()}catch(t){
|
|
27
|
-
`)}),e.command("whoami","Show current auth status").action(async()=>{let t=await
|
|
54
|
+
`)}),e.command("login","Sign in with Clerk (device-grant flow)").action(async()=>{try{let{runLogin:t}=await import("./login-FRWDEJ6B.js");await t()}catch(t){z(t)}}),e.command("logout","Sign out and clear stored token").action(async()=>{await Qt(),process.stdout.write(`signed out
|
|
55
|
+
`)}),e.command("whoami","Show current auth status").action(async()=>{let t=await Z();process.stdout.write(t?`signed in
|
|
28
56
|
`:`not signed in \u2014 run: flowe login
|
|
29
57
|
`)}),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)+`
|
|
30
58
|
`),process.stdout.write(`
|
|
31
59
|
# add the above to ~/.config/claude/mcp.json (or your client's equivalent)
|
|
32
|
-
`)}),e.command("
|
|
60
|
+
`)}),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-SIMIQWQM.js"),a=i();if(!a||a.sounds.length===0){process.stdout.write(`no custom ambience saved yet
|
|
61
|
+
`);return}for(let u of a.sounds)process.stdout.write(`${u.id} ${u.name}
|
|
62
|
+
`);return}if(t!=="create")throw Object.assign(new Error("ambient command must be one of: create, list"),{code:"invalid_duration"});let o=ta(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...
|
|
63
|
+
`);let s=await Or({prompt:o,name:r.name});process.stdout.write(`saved custom ambience: ${s.sound.name} (${s.sound.id})
|
|
64
|
+
`),process.stdout.write(`start it with: flowe focus --ambient ${s.sound.id}
|
|
65
|
+
`)}catch(o){z(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}
|
|
66
|
+
use --force to overwrite, or --target <path> to install elsewhere.
|
|
67
|
+
`),process.exit(0)),process.stdout.write(`installed: ${s.target}
|
|
68
|
+
`),t.target||process.stdout.write(`default location: ${o()}
|
|
69
|
+
restart Claude Code (or open a new session) and Claude will fire flowe resets during long thinking pauses.
|
|
70
|
+
`)}),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=Sr(),r=t.floweBin??(zi(n)?n:yr());if(r||(process.stderr.write(`could not locate the flowe binary on PATH.
|
|
71
|
+
pass --flowe-bin <abs-path> to override (e.g. /opt/homebrew/bin/flowe).
|
|
72
|
+
`),process.exit(1)),!t.dryRun&&!t.skipSwiftbarCheck){let i=vr();i.action==="missing-brew"&&(process.stderr.write(`${Pr()}
|
|
73
|
+
`),process.exit(1)),i.action==="installed"&&process.stdout.write(`SwiftBar installed via brew.
|
|
74
|
+
`)}let o=Tt(),s=kr({floweBin:r,pluginDir:t.pluginDir,dryRun:t.dryRun});if(t.dryRun){process.stdout.write(s.scriptContent);return}if(process.stdout.write(`${Cr(s)}
|
|
75
|
+
`),t.launch!==!1&&!t.skipSwiftbarCheck){let i=s.pluginPath.replace(/\/[^/]+$/,"");o!==i&&gr(i),Ir()?hr():Rr()}}),e.command("uninstall-menubar","Remove the flowe SwiftBar plugin").option("--plugin-dir <path>","override SwiftBar plugin dir").action(t=>{let n=Er({pluginDir:t.pluginDir});process.stdout.write(`${Ar(n)}
|
|
76
|
+
`)}),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(Gt());try{e.parse(process.argv,{run:!1}),await e.runMatchedCommand()}catch(t){z(t)}}ia().catch(z);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readFileSync as f,mkdirSync as c,writeFileSync as d,existsSync as o}from"fs";import{homedir as g}from"os";import{dirname as s,join as a,resolve as m}from"path";import{fileURLToPath as S}from"url";var u="flowe",r="SKILL.md";function p(e=import.meta.url){let t=s(S(e));for(let n=0;n<4;n++){let i=a(t,"skills",u,r);if(o(i))return i;let l=m(t,"..");if(l===t)break;t=l}throw Object.assign(new Error(`bundled ${r} not found relative to ${e}`),{code:"install_failed"})}function k(e=g()){return a(e,".claude","skills",u,r)}function x(){return f(p(),"utf-8")}function E(e={}){let t=e.target??k();return o(t)&&!e.force?{written:!1,target:t,existing:!0}:(c(s(t),{recursive:!0}),d(t,x(),"utf-8"),{written:!0,target:t})}export{p as bundledSkillPath,k as defaultTarget,E as installSkill,x as readBundledSkill};
|
package/dist/mcp-server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as o,
|
|
1
|
+
import{b as o,i,j as a}from"./chunk-C6NO4B4N.js";import"./chunk-P2IV5O3T.js";import{Server as c}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as u}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as p,ListToolsRequestSchema as l}from"@modelcontextprotocol/sdk/types.js";var g=["Run a short neural reset (30, 45, 60, or 90 seconds) for the human operator.","Call this when you notice signs the human is fatigued, overwhelmed, or about to wait:","\xB7 after a long debugging loop or a frustrating error cascade","\xB7 before kicking off a task that will take >30s (long test run, long compile, long agent call)","\xB7 when the human expresses frustration, exhaustion, or decision fatigue","\xB7 when a task has spanned multiple hours with no apparent break","The tool returns immediately (non-blocking). Audio plays on the human's machine in the background.","Continue your work after calling this. Do not wait for the reset to finish."].join(`
|
|
2
2
|
`),d=["Start a guided NSDR (Non-Sleep Deep Rest) session for the human operator.","The human scans a QR / opens the returned link on their phone to join a voice session.","Defaults to quick_reset (classic yoga nidra) when no session_type is given.","Pass a session_type when the human asks for something specific:","\xB7 logic_lock when stuck debugging or problem-solving","\xB7 deploy_anxiety before high-stakes moments (deploy, incident)","\xB7 context_switch after a draining meeting","\xB7 sprint_prep before deep work / a coding sprint","\xB7 executive_reset after decision fatigue / many meetings","\xB7 presentation_prep before speaking / a big meeting","\xB7 shutdown at end of day / sleep prep","Call this when the human asks for a longer reset, is wrapping up a long work block,","or explicitly requests an NSDR / yoga nidra session.","Returns a join URL immediately. The session does not start until the human joins from mobile."].join(`
|
|
3
3
|
`),h=[{name:"flowe_reset",description:g,inputSchema:{type:"object",properties:{duration_seconds:{type:"number",enum:[30,45,60,90],description:"Length of the reset in seconds."},trigger:{type:"string",enum:["claude_thinking","long_compile","agent_call","user_requested"],description:"Why you are firing this reset. Used for analytics only."}},required:["duration_seconds"]}},{name:"flowe_nsdr",description:d,inputSchema:{type:"object",properties:{session_type:{type:"string",enum:[...o],description:"Which NSDR session type to run. Defaults to quick_reset."}},required:[]}}];function m(e){let n=e,t=n?.message||String(e);return{content:[{type:"text",text:`error[${n?.code??"unknown"}]: ${t}`}],isError:!0}}async function f(e,n={}){try{if(e==="flowe_reset"){let t=n.duration_seconds,r=n.trigger??"claude_thinking",s=await i(t,r);return{content:[{type:"text",text:JSON.stringify(s)}]}}if(e==="flowe_nsdr"){let t=n.session_type??"quick_reset",r=await a(t,{suppressQr:!0});return{content:[{type:"text",text:JSON.stringify(r)}]}}return{content:[{type:"text",text:`unknown tool: ${e}`}],isError:!0}}catch(t){return m(t)}}async function y(){let e=new c({name:"flowe",version:"0.1.0"},{capabilities:{tools:{}}});e.setRequestHandler(l,async()=>({tools:h})),e.setRequestHandler(p,async t=>{let{name:r,arguments:s}=t.params;return await f(r,s??{})});let n=new u;await e.connect(n)}var w=import.meta.url===`file://${process.argv[1]}`||process.argv[1]?.endsWith("mcp-server.js")||process.argv[1]?.endsWith("mcp-server.ts");w&&y().catch(e=>{process.stderr.write(`flowe-mcp: ${e instanceof Error?e.message:String(e)}
|
|
4
4
|
`),process.exit(1)});export{h as TOOL_DEFINITIONS,f as handleCallTool,y as runMcpServer};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowe-ai/cli",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Neural resets for engineers using AI coding assistants.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "flowe.ai",
|
|
@@ -33,7 +33,9 @@
|
|
|
33
33
|
"bin/",
|
|
34
34
|
"dist/",
|
|
35
35
|
"audio/",
|
|
36
|
+
"assets/",
|
|
36
37
|
"scripts/preinstall.js",
|
|
38
|
+
"skills/",
|
|
37
39
|
"protocols.json",
|
|
38
40
|
"README.md",
|
|
39
41
|
"LICENSE"
|
|
@@ -52,19 +54,22 @@
|
|
|
52
54
|
"test": "vitest run",
|
|
53
55
|
"test:watch": "vitest",
|
|
54
56
|
"type-check": "tsc --noEmit",
|
|
55
|
-
"generate-audio": "tsx scripts/generate-audio.ts"
|
|
57
|
+
"generate-audio": "tsx scripts/generate-audio.ts",
|
|
58
|
+
"generate-ambient": "tsx scripts/generate-elevenlabs-ambient.ts"
|
|
56
59
|
},
|
|
57
60
|
"dependencies": {
|
|
58
61
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
59
62
|
"cac": "^6.7.14",
|
|
60
63
|
"keytar": "^7.9.0",
|
|
61
64
|
"nanoid": "^5.1.6",
|
|
65
|
+
"node-notifier": "^10.0.1",
|
|
62
66
|
"qrcode-terminal": "^0.12.0",
|
|
63
67
|
"sound-play": "^1.1.0",
|
|
64
68
|
"zod": "^3.23.8"
|
|
65
69
|
},
|
|
66
70
|
"devDependencies": {
|
|
67
71
|
"@types/node": "^22.19.3",
|
|
72
|
+
"@types/node-notifier": "^8.0.5",
|
|
68
73
|
"@types/qrcode-terminal": "^0.12.2",
|
|
69
74
|
"tsup": "^8.3.5",
|
|
70
75
|
"tsx": "^4.19.2",
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: flowe
|
|
3
|
+
description: Run breath-led neural resets and offer focus cycles with flowe-cli. Auto-trigger short resets during long agent thinking pauses to protect the user's focus and working memory. At the start of a workday or substantial task, ask whether the user wants a Pomodoro/dev/ultradian focus session with ambience, then start it detached if they opt in.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# flowe
|
|
7
|
+
|
|
8
|
+
You have access to the `flowe` CLI for two kinds of attention support:
|
|
9
|
+
|
|
10
|
+
- `flowe reset`: short, breath-led neural resets with audio playback. Reset durations are 30s, 45s, 60s, or 90s.
|
|
11
|
+
- `flowe focus`: longer focus cycles with work blocks, breaks, optional ambience, pause/resume/skip/quit controls, and a detached background mode.
|
|
12
|
+
|
|
13
|
+
## Short resets: when to invoke
|
|
14
|
+
|
|
15
|
+
Proactively run `flowe reset` via the Bash tool when ALL of these hold:
|
|
16
|
+
|
|
17
|
+
- You anticipate a thinking, tool-call, build, or multi-file-edit pause **>30 seconds**
|
|
18
|
+
- You haven't already triggered a reset in the **last 5 minutes** in this session
|
|
19
|
+
- You're not in the middle of a destructive or time-sensitive operation (deploys, migrations, irreversible writes, anything where the user needs to watch output)
|
|
20
|
+
- The user hasn't said "no resets" or set `FLOWE_OPT_OUT=1`
|
|
21
|
+
|
|
22
|
+
Tell the user one short line **before** running. Example: `"Long compile incoming — running a 30s palming reset for you."` Don't ask permission. The user opted in by installing this skill.
|
|
23
|
+
|
|
24
|
+
## Short resets: picking the protocol family
|
|
25
|
+
|
|
26
|
+
`flowe` ships 11 protocol families. Pick the one that best matches what you've observed about the user's recent state. Pass it via `--protocol`:
|
|
27
|
+
|
|
28
|
+
| Recent signals from the user | `--protocol` | Why |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| Frustrated, stuck on errors, irritation rising in messages | `physiological_sigh` | Quickest parasympathetic switch; resets the stress response in seconds |
|
|
31
|
+
| Long debugging session, lots of stack-trace reading | `quick_palming` (30s) / `palming` (60s) / `progressive_palming` (90s) | Eye rest, darkness, lowers visual load |
|
|
32
|
+
| Stressed, anxious, terse messages, tight tone | `box_breath` (45s, 60s) / `extended_box` (90s) | Regulates breath cadence; calms nervous system |
|
|
33
|
+
| Cognitive overload, can't pick a path forward, thrashing | `body_scan` (60s) / `full_sensory` (90s, "5-4-3-2-1" grounding) | Reconnects with the body, defragments attention |
|
|
34
|
+
| Long sit, no movement, postural tightness implied | `neck_rotation` (45s) / `grounded_feet` (45s) | Gentle physical reset without leaving the chair |
|
|
35
|
+
| Reading a hard error stack, eyes scanning rapidly | `eye_rotation` (30s) | Resets eye muscles |
|
|
36
|
+
| End of a long focus block, winding down | `progressive_palming` (90s) | Longer, phased relaxation |
|
|
37
|
+
| **No specific signal observed** | omit `--protocol` entirely | flowe picks a random protocol that fits the duration |
|
|
38
|
+
|
|
39
|
+
When in doubt, omit `--protocol` and let flowe choose.
|
|
40
|
+
|
|
41
|
+
## Short resets: picking duration
|
|
42
|
+
|
|
43
|
+
| Predicted pause | Command shape |
|
|
44
|
+
|---|---|
|
|
45
|
+
| 30–45s | `flowe reset 30 --quick [--protocol X]` |
|
|
46
|
+
| 45–75s | `flowe reset 45 --quick [--protocol X]` |
|
|
47
|
+
| 75–120s | `flowe reset 60 --quick [--protocol X]` |
|
|
48
|
+
| 120s+ | `flowe reset 90 --quick [--protocol X]` |
|
|
49
|
+
|
|
50
|
+
`--quick` is **required**. Without it, `flowe` opens an interactive post-session menu and your session blocks waiting for keyboard input.
|
|
51
|
+
|
|
52
|
+
## Short reset examples
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Long compile, user has been frustrated → physiological sigh, 30s
|
|
56
|
+
flowe reset 30 --quick --protocol physiological_sigh
|
|
57
|
+
|
|
58
|
+
# Multi-file refactor incoming (~75s), user was deep-debugging earlier → palming
|
|
59
|
+
flowe reset 60 --quick --protocol palming
|
|
60
|
+
|
|
61
|
+
# Big test run (~2min), no specific signal → let flowe pick
|
|
62
|
+
flowe reset 90 --quick
|
|
63
|
+
|
|
64
|
+
# Quick tool-call wait (~35s), eyes scanning a stack trace → eye rotation
|
|
65
|
+
flowe reset 30 --quick --protocol eye_rotation
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Focus cycles: when to offer
|
|
69
|
+
|
|
70
|
+
Offer, do not auto-start, a focus cycle when any of these are true:
|
|
71
|
+
|
|
72
|
+
- The user is starting work for the day or says they are ready to begin.
|
|
73
|
+
- The user names a substantial task, coding session, review pass, or deep-work block.
|
|
74
|
+
- You are about to begin a multi-step implementation that will take sustained attention.
|
|
75
|
+
- The user has been context-switching and would benefit from a visible work/break cadence.
|
|
76
|
+
|
|
77
|
+
Ask once, briefly, with cadence and ambience choices:
|
|
78
|
+
|
|
79
|
+
`"Want me to start a flowe focus session while we work? Cadence: pomodoro 25/5, dev 50/10, ultradian 90/15. Ambience: 1 spring birds, 2 soft rain, 3 brown noise, 4 LA sunrise, 5 quiet cafe, 0 none."`
|
|
80
|
+
|
|
81
|
+
Only start a focus cycle after the user says yes. Do not ask again in the same conversation unless the prior cycle ended or the user brings it up.
|
|
82
|
+
|
|
83
|
+
## Focus cycles: picking the preset
|
|
84
|
+
|
|
85
|
+
| User/work signal | Preset | Command shape |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| Default deep-work session, unclear duration | `pomodoro` | `flowe focus pomodoro --detach --ambient <ambient-id>` |
|
|
88
|
+
| Long implementation/debugging stretch | `dev` | `flowe focus dev --detach --ambient <ambient-id>` |
|
|
89
|
+
| Long creative or architecture block | `ultradian` | `flowe focus ultradian --detach --ambient <ambient-id>` |
|
|
90
|
+
|
|
91
|
+
Use `--detach` so the focus cycle runs in the background and does not occupy the agent's shell. Always pass `--ambient` so the CLI never opens the interactive ambience picker in non-TTY agent runs.
|
|
92
|
+
|
|
93
|
+
## Focus cycles: picking ambience
|
|
94
|
+
|
|
95
|
+
Default to ambience unless the user picks `0` or says no ambience/silence. If the user says yes but does not choose a number, use option `1`.
|
|
96
|
+
|
|
97
|
+
| Choice | Ambient id | When to suggest |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| `1` | `nature_spring_birds` | Default; light, optimistic morning work |
|
|
100
|
+
| `2` | `rain_window_soft` | Calm, steady, low-distraction work |
|
|
101
|
+
| `3` | `tones_deep_brown_noise` | Deep focus, masking noise |
|
|
102
|
+
| `4` | `seaside_la_sunrise` | Open, cinematic, creative work |
|
|
103
|
+
| `5` | `interiors_quiet_cafe` | Social/ambient energy without music |
|
|
104
|
+
| `0` | `none` | No ambient sound |
|
|
105
|
+
|
|
106
|
+
Examples:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
flowe focus pomodoro --detach --ambient nature_spring_birds
|
|
110
|
+
flowe focus dev --detach --ambient rain_window_soft
|
|
111
|
+
flowe focus ultradian --detach --ambient tones_deep_brown_noise
|
|
112
|
+
flowe focus pomodoro --detach --ambient none
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Useful controls after a detached cycle starts:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
flowe focus status
|
|
119
|
+
flowe focus pause
|
|
120
|
+
flowe focus resume
|
|
121
|
+
flowe focus skip
|
|
122
|
+
flowe focus quit
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Tell the user one short line after starting, including ambience and controls: `"Started a Pomodoro focus cycle with spring birds in the background. You can pause/resume/quit from the menu bar or with flowe focus pause/resume/quit."`
|
|
126
|
+
|
|
127
|
+
## Setup
|
|
128
|
+
|
|
129
|
+
If `which flowe` returns nothing, install once:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
npm install -g @flowe-ai/cli
|
|
133
|
+
flowe voice ellie
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Voice options: `sage`, `ada`, `ellie`. Let the user pick if they ask. Default is `ellie`.
|
|
137
|
+
|
|
138
|
+
## Cooldowns and limits
|
|
139
|
+
|
|
140
|
+
- **Minimum 5 minutes between resets.** Resetting more often than that defeats the purpose; the user needs time to actually use the focus you just gave them back.
|
|
141
|
+
- **Focus cycles are opt-in.** Never auto-start `flowe focus`; ask first because it creates a long-running session.
|
|
142
|
+
- **Skip resets in Q&A / code review conversations.** No agent waits = no reason to fire.
|
|
143
|
+
- **Skip resets during the first 60 seconds of a new conversation.** The user is still ramping in; let them.
|
|
144
|
+
|
|
145
|
+
## Tuning
|
|
146
|
+
|
|
147
|
+
To disable auto-trigger entirely, set `FLOWE_OPT_OUT=1` in your shell environment.
|
|
148
|
+
|
|
149
|
+
To change cadence, durations, or behavior, edit this file directly at `~/.claude/skills/flowe/SKILL.md`. Your changes won't be overwritten unless you re-run `flowe install-skill --force`.
|