@flowe-ai/cli 0.2.1 → 0.3.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 +42 -97
- package/dist/{ambient-SIMIQWQM.js → ambient-RIFETQIW.js} +1 -1
- package/dist/{chunk-RB3EXF6P.js → chunk-3HG2U5YK.js} +1 -1
- package/dist/chunk-3TLGYA6M.js +3 -0
- package/dist/chunk-EC5WRPZP.js +1 -0
- package/dist/chunk-QVIYCUHZ.js +1 -0
- package/dist/chunk-ZP43LZEQ.js +5 -0
- package/dist/cli.js +73 -54
- package/dist/{login-FRWDEJ6B.js → login-Q4QMATEN.js} +2 -2
- package/dist/mcp-server.js +9 -4
- package/dist/me-SZLS6RWX.js +1 -0
- package/dist/session-client-74I2RBYA.js +1 -0
- package/dist/setup-harness-RR77VO5C.js +9 -0
- package/dist/ui/live-session.html +49 -0
- package/dist/ui/micro.html +9 -0
- package/package.json +18 -8
- package/scripts/preinstall.js +1 -1
- package/skills/flowe/SKILL.md +48 -111
- package/dist/chunk-AX3TLBEV.js +0 -2
- package/dist/chunk-C6NO4B4N.js +0 -3
- package/dist/chunk-P2IV5O3T.js +0 -1
- package/dist/me-LA6RUW2D.js +0 -1
package/README.md
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
# flowe
|
|
1
|
+
# @flowe-ai/cli
|
|
2
2
|
|
|
3
|
-
> Neural resets
|
|
3
|
+
> Neural resets, live AI-guided Quick & Deep Resets, and interactive MCP Apps inside your AI coding workspace.
|
|
4
4
|
|
|
5
|
-
Built by certified hypnotherapists
|
|
5
|
+
Built by engineers and certified clinical hypnotherapists. `flowe` delivers instant 30–90s offline micro-resets in your terminal, live authenticated Quick & Deep Resets with Ada, Ellie, and Sage, and interactive **MCP App cards (SEP-1865)** inside Claude Desktop, Antigravity, Cursor, VS Code, Codex, and Claude Code.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Docs and voice samples: [cli.flowe.ai](https://cli.flowe.ai)
|
|
7
|
+
Docs, live demo, and voice samples: **[cli.flowe.ai](https://cli.flowe.ai)**
|
|
10
8
|
|
|
11
9
|
## Install
|
|
12
10
|
|
|
@@ -14,118 +12,65 @@ Docs and voice samples: [cli.flowe.ai](https://cli.flowe.ai)
|
|
|
14
12
|
npm install -g @flowe-ai/cli
|
|
15
13
|
```
|
|
16
14
|
|
|
17
|
-
Requires Node.js ≥ 20
|
|
18
|
-
|
|
19
|
-
## Quickstart
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
flowe reset # interactive picker — choose duration + protocol
|
|
23
|
-
flowe reset 60 # 60-second reset, random protocol
|
|
24
|
-
flowe reset 60 --protocol box_breath # deterministic — box-breathing only
|
|
25
|
-
flowe reset --quick # skip the picker, use defaults
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Press `q` or `Ctrl+C` to abandon a session. The TUI returns you to a clean prompt.
|
|
29
|
-
|
|
30
|
-
## What flowe does
|
|
15
|
+
Requires **Node.js ≥ 20** on **macOS, Linux, or Windows**.
|
|
31
16
|
|
|
32
|
-
|
|
17
|
+
## Connect your AI harness (MCP Apps)
|
|
33
18
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
| Family | Durations | What it is |
|
|
37
|
-
|---|---|---|
|
|
38
|
-
| `box_breath` | 45s, 60s | Box breathing — inhale, hold, exhale, hold |
|
|
39
|
-
| `extended_box` | 90s | Box breathing with longer rounds |
|
|
40
|
-
| `physiological_sigh` | 30s | Double inhale through the nose, long exhale |
|
|
41
|
-
| `quick_palming` | 30s | Short palming — cover the eyes |
|
|
42
|
-
| `palming` | 60s | Standard palming reset |
|
|
43
|
-
| `progressive_palming` | 90s | Longer palming with phased relaxation |
|
|
44
|
-
| `body_scan` | 60s | Brief somatic check-in |
|
|
45
|
-
| `eye_rotation` | 30s | Eye movement reset |
|
|
46
|
-
| `neck_rotation` | 45s | Neck mobility break |
|
|
47
|
-
| `grounded_feet` | 45s | Pressure-into-ground grounding |
|
|
48
|
-
| `full_sensory` | 90s | 5-4-3-2-1 sensory grounding |
|
|
49
|
-
|
|
50
|
-
Run `flowe protocols` to see the full list.
|
|
51
|
-
|
|
52
|
-
## Voices
|
|
19
|
+
Merge Flowe's stdio MCP server cleanly into your AI host in one command:
|
|
53
20
|
|
|
54
21
|
```bash
|
|
55
|
-
flowe
|
|
56
|
-
flowe
|
|
22
|
+
flowe setup claude-desktop --write
|
|
23
|
+
flowe setup antigravity --write
|
|
24
|
+
flowe setup cursor --write
|
|
25
|
+
flowe setup vscode --write
|
|
26
|
+
flowe setup claude-code --write
|
|
27
|
+
flowe setup codex --write
|
|
57
28
|
```
|
|
58
29
|
|
|
59
|
-
|
|
30
|
+
Supporting MCP Apps hosts mount Flowe's self-contained **Dusk + Peek** UI cards (`ui://flowe/micro.html`, `ui://flowe/live-session.html`) inline inside the chat. Terminal-only hosts automatically receive concise structured text.
|
|
31
|
+
|
|
32
|
+
## Three Reset Tiers
|
|
60
33
|
|
|
61
|
-
|
|
34
|
+
| Tier | Duration | Auth | Command |
|
|
35
|
+
|---|---|---|---|
|
|
36
|
+
| **Micro-Resets** | 30–90s | Offline · Free | `flowe reset 60 --protocol box_breath` |
|
|
37
|
+
| **Quick Resets** | 5–15 min | Flowe Account | `flowe quick logic_lock --ambient rain_window_soft` |
|
|
38
|
+
| **Deep Resets** | 15–25 min | Flowe Account | `flowe deep ht_burnout --open` |
|
|
62
39
|
|
|
63
|
-
|
|
40
|
+
### Offline Micro-Resets
|
|
64
41
|
|
|
65
42
|
```bash
|
|
66
|
-
flowe
|
|
43
|
+
flowe reset # interactive picker
|
|
44
|
+
flowe reset 30 --protocol physiological_sigh
|
|
45
|
+
flowe reset 60 --protocol box_breath
|
|
46
|
+
flowe reset --quick # skip picker, use defaults
|
|
67
47
|
```
|
|
68
48
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
Don't want to use the CLI to install? Download `SKILL.md` directly:
|
|
72
|
-
|
|
73
|
-
- [github.com/flowe-ai/flowe-cli/blob/main/SKILL.md](https://github.com/flowe-ai/flowe-cli/blob/main/SKILL.md)
|
|
74
|
-
|
|
75
|
-
Drop it into `~/.claude/skills/flowe/SKILL.md` (or your project's `.claude/skills/flowe/SKILL.md`). The skill content is the same.
|
|
76
|
-
|
|
77
|
-
To opt out of auto-trigger entirely, set `FLOWE_OPT_OUT=1` in your shell or delete the file.
|
|
78
|
-
|
|
79
|
-
## Login (optional)
|
|
49
|
+
### Live Quick & Deep Resets (Flowe Account)
|
|
80
50
|
|
|
81
51
|
```bash
|
|
82
|
-
flowe login
|
|
52
|
+
flowe login # OAuth device grant (stored in OS Keychain)
|
|
53
|
+
flowe whoami # check account, plan & Quick Reset quota
|
|
54
|
+
flowe quick logic_lock --ambient rain_window_soft
|
|
55
|
+
flowe deep ht_burnout --open # opens desktop or prints phone handoff QR
|
|
83
56
|
```
|
|
84
57
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
## Status
|
|
58
|
+
### Focus Cycles & Voices
|
|
88
59
|
|
|
89
60
|
```bash
|
|
90
|
-
flowe
|
|
91
|
-
flowe
|
|
61
|
+
flowe focus pomodoro --ambient rain_window_soft
|
|
62
|
+
flowe focus dev --ambient forest_morning
|
|
63
|
+
flowe focus ultradian --ambient brown_noise
|
|
64
|
+
flowe voice ada | ellie | sage
|
|
92
65
|
```
|
|
93
66
|
|
|
94
|
-
##
|
|
95
|
-
|
|
96
|
-
Config lives at `~/.config/flowe/config.json`. Voice preference, telemetry mode, and the anonymous ID. Login tokens go in the OS keychain via `keytar`, never on disk.
|
|
97
|
-
|
|
98
|
-
## Privacy
|
|
99
|
-
|
|
100
|
-
- Anonymous mode (default): events sent with a generated stable ID, no email or device fingerprint.
|
|
101
|
-
- Logged-in mode: events tied to your flowe account.
|
|
102
|
-
- `FLOWE_OPT_OUT=1` in your shell: events skipped entirely.
|
|
103
|
-
|
|
104
|
-
## Troubleshooting
|
|
67
|
+
## Privacy & Opt-Out
|
|
105
68
|
|
|
106
|
-
**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
**Session won't start, "agent_busy".** A previous reset is still running. Wait for it to finish or run `flowe status` to see what's open.
|
|
111
|
-
|
|
112
|
-
**Login redirects but never completes.** The device-grant flow waits up to 5 minutes. If the browser closes early, run `flowe login` again.
|
|
113
|
-
|
|
114
|
-
## Exit codes
|
|
115
|
-
|
|
116
|
-
| Code | Meaning |
|
|
117
|
-
|---|---|
|
|
118
|
-
| `0` | Success |
|
|
119
|
-
| `1` | User error (bad flag, unknown protocol family) |
|
|
120
|
-
| `2` | Network error (telemetry, login, macro session) |
|
|
121
|
-
| `3` | Auth required or expired |
|
|
122
|
-
| `4` | Audio device unavailable |
|
|
69
|
+
- **Offline by default:** All 12 micro-reset protocols work with zero account and store only a local ID in `~/.config/flowe/config.json`.
|
|
70
|
+
- **Keychain tokens:** `flowe login` and inline MCP `flowe_auth` store credentials in your OS Keychain (falling back to `0600` local storage only if unavailable).
|
|
71
|
+
- **Zero code leaves your machine:** Never reads files, prompts, or repository paths.
|
|
72
|
+
- **Full opt-out:** Set `FLOWE_OPT_OUT=1` to disable telemetry and proactive MCP suggestions completely.
|
|
123
73
|
|
|
124
74
|
## License
|
|
125
75
|
|
|
126
|
-
MIT
|
|
127
|
-
|
|
128
|
-
## Links
|
|
129
|
-
|
|
130
|
-
Docs: [cli.flowe.ai](https://cli.flowe.ai)
|
|
131
|
-
Issues + feature requests: [github.com/flowe-ai/flowe-cli/issues](https://github.com/flowe-ai/flowe-cli/issues)
|
|
76
|
+
MIT © [Flowe AI](https://www.flowe.ai)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j,k,l,m}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l,m}from"./chunk-3TLGYA6M.js";export{a as DEFAULT_MANIFEST_URL,c as applyAmbientAssetBaseUrl,l as buildAmbientEntries,d as cachePathFor,b as defaultManifestUrl,j as downloadAmbient,i as fetchAmbientManifest,h as isCached,e as loadCustomAmbientManifest,f as mergeAmbientManifests,g as saveCustomAmbientSound,m as selectableIndices,k as startAmbientFile};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as i,d as n,i as o}from"./chunk-
|
|
1
|
+
import{a as i,d as n,i as o}from"./chunk-EC5WRPZP.js";async function l(t={}){let e=i(),r=t.authToken!==void 0?t.authToken:await o();if(!r)return null;let a=t.fetch??globalThis.fetch;try{let s=await a(`${e.backend_url}/api/v1/me`,{method:"GET",headers:{Authorization:`Bearer ${r}`}});return s.ok?await s.json():null}catch{return null}}async function m(t={}){let e=await l(t);return e?typeof e.first_name=="string"&&e.first_name.trim().length>0?(n(e.first_name),e.first_name):(n(null),null):null}export{l as a,m as b};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{spawn as M}from"child_process";import{createHash as A}from"crypto";import{EventEmitter as _}from"events";import{createWriteStream as C,existsSync as y,mkdirSync as k,readFileSync as P,statSync as L,unlinkSync as E,writeFileSync as v}from"fs";import{homedir as I,platform as O}from"os";import{dirname as R,join as m}from"path";import{Readable as F}from"stream";import{pipeline as N}from"stream/promises";var U="https://www.flowe.ai/cli/ambient/manifest.json",D=5e3,B=3e4,$=29e3,W=900;function j(){return process.env.FLOWE_AMBIENT_MANIFEST_URL||U}function J(){return process.env.FLOWE_AMBIENT_ASSET_BASE_URL||null}function H(t){try{return new URL(t).pathname.split("/").filter(Boolean).pop()||t}catch{return t.split("/").filter(Boolean).pop()||t}}function G(t,e=J()){if(!e)return t;let n=e.replace(/\/+$/,"");return{...t,sounds:t.sounds.map(o=>({...o,url:`${n}/${encodeURIComponent(H(o.url))}`}))}}function w(){let t=I(),e=O()==="win32"?m(t,"AppData","Roaming","flowe"):m(t,".config","flowe");return m(e,"cache","ambient")}function x(){return m(w(),"custom-manifest.json")}function S(t){return m(w(),`${t.sha256}.mp3`)}function q(){let t=x();if(!y(t))return null;try{let e=JSON.parse(P(t,"utf-8"));return e.version!==1||!Array.isArray(e.categories)||!Array.isArray(e.sounds)?null:e}catch{return null}}function st(t,e){if(!t&&!e)return null;if(!t)return e;if(!e||e.sounds.length===0)return t;let n=new Set(t.categories.map(r=>r.id)),o=[...t.categories];for(let r of e.categories)n.has(r.id)||(n.add(r.id),o.push(r));let i=new Set(t.sounds.map(r=>r.id)),s=[...t.sounds];for(let r of e.sounds)i.has(r.id)||(i.add(r.id),s.push(r));return{version:1,generated_at:t.generated_at,categories:o,sounds:s}}function at(t){let e=Buffer.from(t.bytes),n=A("sha256").update(e).digest("hex"),o=`custom_${n.slice(0,12)}`,i=(t.name.trim()||"custom ambience").slice(0,48),s={id:o,category:"custom",name:i,blurb:"generated ambience",url:`flowe-local://ambient/custom/${o}.mp3`,sha256:n,bytes:e.byteLength};k(w(),{recursive:!0}),v(S(s),e);let r=q(),c=[s,...r?.sounds.filter(u=>u.id!==o)??[]],d={version:1,generated_at:(t.now??(()=>new Date))().toISOString(),categories:[{id:"custom",label:"custom"}],sounds:c};return v(x(),JSON.stringify(d,null,2)+`
|
|
2
|
+
`,"utf-8"),s}function z(t){let e=S(t);if(!y(e))return!1;try{let n=P(e);return A("sha256").update(n).digest("hex")===t.sha256}catch{return!1}}async function lt(t){let e=t?.url??j(),n=t?.timeoutMs??D,o=new AbortController,i=setTimeout(()=>o.abort(),n);t?.signal&&(t.signal.aborted?o.abort():t.signal.addEventListener("abort",()=>o.abort()));try{let s=await fetch(e,{signal:o.signal});if(!s.ok)throw new Error(`manifest fetch failed: ${s.status}`);let r=await s.json();if(!r.sounds||!r.categories)throw new Error("manifest shape invalid");return G(r)}finally{clearTimeout(i)}}async function ct(t,e){let n=S(t);if(z(t))return e?.onProgress?.({downloaded:t.bytes,total:t.bytes}),n;k(R(n),{recursive:!0});let o=e?.timeoutMs??B,i=new AbortController,s=setTimeout(()=>i.abort(),o);e?.signal&&(e.signal.aborted?i.abort():e.signal.addEventListener("abort",()=>i.abort()));let r=`${n}.part`;try{let c=await fetch(t.url,{signal:i.signal});if(!c.ok||!c.body)throw new Error(`download failed: ${c.status}`);let d=t.bytes,u=0,f=A("sha256"),b=c.body.getReader(),g=new F({read(){b.read().then(({value:a,done:h})=>{if(h){this.push(null);return}u+=a.byteLength,f.update(a),e?.onProgress?.({downloaded:u,total:d}),this.push(Buffer.from(a))}).catch(a=>this.destroy(a))}});if(await N(g,C(r)),f.digest("hex")!==t.sha256){try{E(r)}catch{}throw new Error("sha256 mismatch")}let{renameSync:l}=await import("fs");return l(r,n),n}catch(c){try{y(r)&&E(r)}catch{}throw c}finally{clearTimeout(s)}}var T=!1;function V(){let t=new _;return t.killed=!1,t.kill=()=>(t.killed||(t.killed=!0,t.emit("exit",null,"SIGTERM")),!0),t}function K(t,e=1){let n=Number.isFinite(e)&&e>0?e:1;return process.platform==="darwin"?M("afplay",["-v",String(n),t],{stdio:"ignore"}):process.platform==="win32"?(T||(T=!0,process.stderr.write(`ambience isn't supported on Windows yet \u2014 the session runs without background sound
|
|
3
|
+
`)),V()):M("mpg123",["-q","-f",String(Math.round(32768*n)),t],{stdio:"ignore"})}function ut(t,e={}){if(!t||!y(t))return{stop:()=>{}};try{if(L(t).size<=0)return{stop:()=>{}}}catch{return{stop:()=>{}}}let n=!1,o=null,i=null,s=new Set,r=new Set,c=e.loopRestartMs??$,d=e.overlapMs??W,u=e.volume??1,f=e.spawnPlayer??K,b=()=>{i&&(clearTimeout(i),i=null);for(let l of s)clearTimeout(l);s.clear()},g=l=>{if(l&&!l.killed)try{l.kill("SIGTERM")}catch{}},p=()=>{if(n)return;let l=o,a;try{a=f(t,u)}catch{n=!0;return}if(o=a,r.add(a),l&&l!==a){let h=setTimeout(()=>{s.delete(h),g(l)},d);s.add(h)}i=setTimeout(()=>{i=null,p()},c),a.on("exit",()=>{r.delete(a),!n&&o===a&&(i&&(clearTimeout(i),i=null),p())}),a.on("error",()=>{n=!0,b()})};return p(),{stop:()=>{n=!0,b(),o=null;for(let l of r)g(l);r.clear()}}}function dt(t){let e=[{kind:"none"}];if(!t)return e;for(let n of t.categories){let o=t.sounds.filter(i=>i.category===n.id);if(o.length!==0){e.push({kind:"category",categoryId:n.id,label:n.label});for(let i of o)e.push({kind:"sound",sound:i})}}return e}function mt(t){let e=[];for(let n=0;n<t.length;n++)t[n].kind!=="category"&&e.push(n);return e}export{U as a,j as b,G as c,S as d,q as e,st as f,at as g,z as h,lt as i,ct as j,ut as k,dt as l,mt as m};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readFileSync as x,writeFileSync as A,mkdirSync as E,existsSync as h}from"fs";import{homedir as T,platform as P}from"os";import{join as d}from"path";import{nanoid as D}from"nanoid";var v="https://www.flowe.ai",O=90,b=["sage","ada","ellie"];function V(t){return typeof t=="string"&&b.includes(t)?t:"ellie"}function S(){let t=T();return P()==="win32"?d(t,"AppData","Roaming","flowe"):d(t,".config","flowe")}function k(){return d(S(),"config.json")}function w(){return{version:2,voice:"ellie",anonymous_id:`anon_${D(12)}`,telemetry:"on",backend_url:process.env.FLOWE_BACKEND_URL||v,session_dates:[]}}function N(t){let e=typeof t.version=="number"?t.version:1,n=t.voice,r=V(n),o={version:2,voice:r,anonymous_id:t.anonymous_id??`anon_${D(12)}`,telemetry:t.telemetry??"on",backend_url:t.backend_url??v,session_dates:Array.isArray(t.session_dates)?t.session_dates:[]};return typeof t.first_reset_at=="string"&&(o.first_reset_at=t.first_reset_at),typeof t.user_first_name=="string"&&(o.user_first_name=t.user_first_name),(e<2||n!==r)&&s(o),o}function i(){let t=k();if(!h(t)){let e=w();return s(e),e}try{let e=x(t,"utf-8"),n=JSON.parse(e),r=N(n);return process.env.FLOWE_BACKEND_URL&&(r.backend_url=process.env.FLOWE_BACKEND_URL),r}catch{let e=w();return s(e),e}}function s(t){let e=S();h(e)||E(e,{recursive:!0}),A(k(),JSON.stringify(t,null,2),"utf-8")}function Q(t){let e=i();e.voice=t,s(e)}function X(){let t=i();t.first_reset_at||(t.first_reset_at=new Date().toISOString(),s(t))}function Z(t){let e=i();t&&t.trim().length>0?e.user_first_name=t.trim():delete e.user_first_name,s(e)}function u(t=new Date){let e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`}function R(t,e){let n=new Date(e);n.setDate(n.getDate()-O);let r=u(n);return t.filter(o=>o>=r)}function tt(t=new Date){let e=i(),n=u(t),r=R([...e.session_dates,n],t);e.session_dates=r,s(e)}function et(t=new Date){let e=i(),n=u(t);return e.session_dates.filter(r=>r===n).length}function nt(t=new Date){let e=i(),n=new Set(e.session_dates),r=new Date(t);r.setHours(0,0,0,0);let o=new Date(r);n.has(u(o))||o.setDate(o.getDate()-1);let _=0;for(;n.has(u(o));)_+=1,o.setDate(o.getDate()-1);return _}function rt(){return i().session_dates.length}import{execFileSync as g}from"child_process";import{existsSync as m,mkdirSync as K,readFileSync as L,rmSync as U,writeFileSync as I}from"fs";import{homedir as $,platform as l}from"os";import{join as f}from"path";var c="flowe-cli",a="clerk-token";function p(){let t=$(),e=l()==="win32"?f(t,"AppData","Roaming","flowe"):f(t,".config","flowe");return f(e,".token")}function j(){if(l()!=="darwin")return null;try{let t=g("security",["find-generic-password","-s",c,"-a",a,"-w"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim();return t.length>0?t:null}catch{return null}}function B(t){if(l()!=="darwin")return!1;try{return g("security",["add-generic-password","-U","-s",c,"-a",a,"-w",t],{stdio:"ignore"}),!0}catch{return!1}}function M(){if(l()!=="darwin")return!1;try{return g("security",["delete-generic-password","-s",c,"-a",a],{stdio:"ignore"}),!0}catch{return!1}}function W(){try{let t=p();if(!m(t))return null;let e=L(t,"utf-8").trim();return e.length>0?e:null}catch{return null}}function H(t){let e=p(),n=f(e,"..");m(n)||K(n,{recursive:!0}),I(e,t,{encoding:"utf-8",mode:384})}function J(){try{let t=p();m(t)&&U(t,{force:!0})}catch{}}async function y(){try{let e=(await import("keytar")).default;return e&&typeof e.getPassword=="function"?e:null}catch{return null}}async function ft(){let t=process.env.FLOWE_AUTH_TOKEN?.trim();if(t)return t;let e=await y();if(e)try{let n=await e.getPassword(c,a);return n||null}catch{return null}return j()??W()}async function lt(t){let e=await y();if(e)try{await e.setPassword(c,a,t);return}catch{}B(t)||H(t)}async function dt(){let t=await y();if(t)try{await t.deletePassword(c,a)}catch{}M(),J()}export{i as a,Q as b,X as c,Z as d,tt as e,et as f,nt as g,rt as h,ft as i,lt as j,dt as k};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as y,d as b,e as q,i as f,j as D}from"./chunk-EC5WRPZP.js";var B=[{id:"quick_reset",name:"Reset",description:"Quick mental refresh between tasks.",duration_minutes:10,technique:"Yoga Nidra",category:"calm"},{id:"sprint_prep",name:"Lock In",description:"Before deep work or a focus sprint.",duration_minutes:10,technique:"Dopamine priming",category:"focus"},{id:"context_switch",name:"Clear",description:"After meetings, before code.",duration_minutes:8,technique:"Body scan",category:"focus"},{id:"shutdown",name:"Wind Down",description:"End of day, sleep transition.",duration_minutes:15,technique:"Breathing",category:"sleep"},{id:"logic_lock",name:"Unstuck",description:"When a problem keeps circling.",duration_minutes:10,technique:"Open focus",category:"focus"},{id:"deploy_anxiety",name:"Calm Down",description:"Heart racing, high stakes.",duration_minutes:5,technique:"Cyclic sighing",category:"calm"},{id:"executive_reset",name:"Defog",description:"Brain fog, decision fatigue.",duration_minutes:12,technique:"Quiet focus",category:"calm"},{id:"presentation_prep",name:"Steady",description:"Before a presentation or meeting.",duration_minutes:8,technique:"Grounding",category:"focus"}],I=[{id:"ht_stress",name:"Stress",hook:"For the days everything feels too much.",duration_minutes:20},{id:"ht_anxiety",name:"Anxiety",hook:"For the racing 2 a.m. loop you cannot shake.",duration_minutes:20},{id:"ht_people_pleasing",name:"People pleasing",hook:"When saying no still feels impossible.",duration_minutes:20},{id:"ht_relationships",name:"Relationships",hook:"When the same fight keeps showing up.",duration_minutes:20},{id:"ht_confidence",name:"Confidence",hook:"When imposter syndrome will not quiet down.",duration_minutes:20},{id:"ht_fears",name:"Fears and phobias",hook:"For the freeze before the big moment.",duration_minutes:20},{id:"ht_anger",name:"Anger",hook:"When the reaction is bigger than the trigger.",duration_minutes:20},{id:"ht_procrastination",name:"Procrastination",hook:"For the task you cannot seem to start.",duration_minutes:20},{id:"ht_burnout",name:"Burnout",hook:"When nothing feels like it refills you.",duration_minutes:22}];function l(e,t){return Object.assign(new Error(t),{code:e})}function m(e){return(e?.backendUrl??y().backend_url).replace(/\/+$/,"")}async function L(e={}){let t=e.fetch??globalThis.fetch,r=m(e),o;try{o=await t(`${r}/api/v1/cli/auth/start`,{method:"POST",headers:{"Content-Type":"application/json"}})}catch{throw l("network_error",`could not reach ${r}`)}if(!o.ok)throw l("network_error",`failed to start sign-in (${o.status})`);let n=await o.json();return{device_code:n.device_code,user_code:n.user_code,verification_uri:n.verification_uri,verification_uri_complete:n.verification_uri_complete,interval:n.interval,expires_at:n.expires_at}}async function Q(e,t={}){let r=t.fetch??globalThis.fetch,o=t.setAuthToken??D,n=m(t),s;try{s=await r(`${n}/api/v1/cli/auth/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:e})})}catch{throw l("network_error",`could not reach ${n}`)}if(s.status===410)return{status:"expired"};if(!s.ok)throw l("network_error",`sign-in poll failed (${s.status})`);let i=await s.json();if(i.status==="authorized"&&i.token){await o(i.token);let a=await E({...t,getAuthToken:async()=>i.token}).catch(()=>({authenticated:!0,user_id:i.user_id,is_pro:!1,plan_type:"free"}));return a.first_name&&b(a.first_name),{status:"authorized",user_id:i.user_id,account:a}}return{status:"authorization_pending"}}async function E(e={}){let t=e.fetch??globalThis.fetch,r=e.getAuthToken??f,o=m(e),n=await r();if(!n)return{authenticated:!1,is_pro:!1,plan_type:"guest",quick_reset_quota:null};let s={Authorization:`Bearer ${n}`},[i,a,p]=await Promise.all([t(`${o}/api/v1/me`,{headers:s}).catch(()=>null),t(`${o}/api/v1/user/plan-status`,{headers:s}).catch(()=>null),t(`${o}/api/v1/quota/quick-reset`,{headers:s}).catch(()=>null)]);if(i?.status===401)return{authenticated:!1,is_pro:!1,plan_type:"guest",quick_reset_quota:null};let d=i?.ok?await i.json():null,u=a?.ok?await a.json():null,c=p?.ok?await p.json():null;d?.first_name&&b(d.first_name);let g=u?!u.is_quota_limited:c?.cap===-1;return{authenticated:!0,user_id:d?.user_id,first_name:d?.first_name??y().user_first_name??null,email:d?.email??null,is_pro:g,plan_type:u?.plan_type??(g?"pro":"free"),quick_reset_quota:c}}async function z(e,t={}){let r=t.fetch??globalThis.fetch,o=t.getAuthToken??f,n=m(t),s=y(),i=await o();if(!i)throw l("auth_required","Sign in with Flowe to run live Quick and Deep Resets.");let a=e.tier==="deep"?"hypnotherapy":"nsdr",p=e.voice??s.voice,d=e.ambient??"none",u;try{u=await r(`${n}/api/v1/sessions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({protocolId:a,sessionType:e.sessionType})})}catch{throw l("network_error","Network unreachable \u2014 try a local 30\u201390s micro-reset.")}if(!u.ok){let _=await u.json().catch(()=>({})),h=_?.error?.code,v=_?.error?.message??_?.message??`server error ${u.status}`;throw u.status===401?l("auth_required","Session expired \u2014 sign in to Flowe again."):u.status===403?l(h==="QUOTA_EXCEEDED"?"quota_exceeded":"subscription_required",v):l("network_error",v)}let c=await u.json(),g=`flowe://session/${c.session_id}`,T=`${n}/session/${c.session_id}`,S,k,w,A,C=[],R="waiting_for_join";if(e.startRoom!==!1)try{let _=await r(`${n}/api/v1/sessions/${encodeURIComponent(c.session_id)}/start`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({voiceId:p,ambient:d})});if(_.ok){let h=await _.json();S=h.room_name,k=h.livekit_url,w=h.livekit_token,A=h.current_phase,C=Array.isArray(h.phases)?h.phases:[],k&&w&&(R="live")}}catch{}let $=e.tier==="deep"?"Deep Reset":"Quick Reset";return{session_id:c.session_id,tier:e.tier,protocol_id:c.protocol_id??a,session_type:c.session_type??e.sessionType,session_type_name:c.session_type_name,estimated_duration:c.estimated_duration,voice:p,ambient:d,room_name:S,livekit_url:k,livekit_token:w,current_phase:A,phases:C,join_url:g,web_url:T,status:R,requires_microphone:e.tier==="deep",message_for_user:`${$}: ${c.session_type_name} (${c.estimated_duration} min) ready \xB7 ${T}`}}async function N(e,t={},r={}){let o=r.fetch??globalThis.fetch,n=r.getAuthToken??f,s=m(r),i=await n();if(!i)throw l("auth_required","Sign in with Flowe first.");let a={};if(typeof t.durationMinutes=="number"&&(a.durationMinutes=t.durationMinutes),typeof t.rating=="number"&&(a.userFeedback={rating:t.rating,comments:t.comments}),(await o(`${s}/api/v1/sessions/${encodeURIComponent(e)}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify(a)})).ok){try{q()}catch{}return{completed:!0}}return{completed:!1}}async function U(e,t={}){let r=t.fetch??globalThis.fetch,o=t.getAuthToken??f,n=m(t),s=await o();if(!s)return{cancelled:!1};try{return{cancelled:(await r(`${n}/api/v1/sessions/${encodeURIComponent(e)}`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}})).ok}}catch{return{cancelled:!1}}}export{B as a,I as b,L as c,Q as d,E as e,z as f,N as g,U as h};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{a as W,c as Q,e as Y,i as G}from"./chunk-EC5WRPZP.js";import{readFileSync as ge}from"fs";import{dirname as ye,join as he}from"path";import{fileURLToPath as be}from"url";var xe=ye(be(import.meta.url));function H(){try{let e=ge(he(xe,"..","package.json"),"utf-8");return JSON.parse(e).version}catch{return"0.0.0"}}var at=["logic_lock","deploy_anxiety","context_switch","sprint_prep","quick_reset","executive_reset","presentation_prep","shutdown"],ct=["ht_stress","ht_anxiety","ht_people_pleasing","ht_relationships","ht_confidence","ht_fears","ht_anger","ht_procrastination","ht_burnout"];import{readFileSync as K}from"fs";import{dirname as Se,join as N}from"path";import{fileURLToPath as ve}from"url";var k=Se(ve(import.meta.url));function Ee(){return N(k,"..","protocols.json")}var g=null;function A(){if(g)return g;try{let e=K(Ee(),"utf-8");return g=JSON.parse(e),g}catch{return g={protocols:{},audio_paths:{},cues_paths:{}},g}}function D(){return Object.values(A().protocols)}function M(e){return e.replace(/_\d+$/,"")}function mt(){let e=new Set;for(let t of D())e.add(M(t.protocol_id));return[...e].sort()}function _t(e){return D().filter(t=>M(t.protocol_id)===e).map(t=>t.duration_seconds).sort((t,r)=>t-r)}function z(e,t){let r=D().filter(n=>n.duration_seconds===e&&(t===void 0||M(n.protocol_id)===t));return r.length===0?null:t!==void 0?r[0]:r[Math.floor(Math.random()*r.length)]}function X(e,t){let r=A(),n=`${e}.${t}`,o=r.audio_paths[n];return o?N(k,"..",o):null}var C=new Map;function Z(e,t){let r=`${e}.${t}`,n=C.get(r);if(n!==void 0)return n;let a=A().cues_paths?.[r];if(!a)return C.set(r,null),null;try{let s=K(N(k,"..",a),"utf-8"),i=JSON.parse(s);return C.set(r,i),i}catch{return C.set(r,null),null}}import{spawn as R}from"child_process";import{platform as Pe}from"os";var d=null;function ee(e){return typeof e!="number"||!Number.isFinite(e)||e<=0?1:Math.min(2,Math.max(.05,e))}function we(e,t=1){let r=ee(t),n=Pe();if(n==="darwin"){let a=r===1?[e]:["-v",String(r),e];return R("afplay",a,{stdio:"ignore"})}if(n==="win32"){let s=["Add-Type -AssemblyName presentationCore;","$p = New-Object System.Windows.Media.MediaPlayer;",`$p.Open([Uri]'${e.replace(/'/g,"''")}');`,`$p.Volume = ${Math.min(1,r)};`,"$p.Play();","Start-Sleep -Milliseconds 300;","while ($p.Position -lt $p.NaturalDuration.TimeSpan -and $p.NaturalDuration.HasTimeSpan) { Start-Sleep -Milliseconds 200 };","$p.Close();"].join(" ");return R("powershell",["-NoProfile","-NonInteractive","-Command",s],{stdio:"ignore"})}let o=Math.round(32768*r);return R("mpg123",["-q","-f",String(o),e],{stdio:"ignore"})}function I(){return d!==null}function xt(){return d?.donePromise??null}function te(e,t={}){if(d)return Promise.reject(new Error("already playing \u2014 call stopAudio first"));let r=ee(t.volume),n=t.spawnPlayer??we,o;try{o=n(e,r)}catch(c){return Promise.reject(c instanceof Error?c:new Error(String(c)))}let a=!1,s=!1,i,u,p=new Promise((c,l)=>{i=c,u=l}),m=()=>{d?.child===o&&(d=null)},_=()=>{a||(a=!0,m(),i())},T=c=>{a||(a=!0,m(),u(c))};return d={child:o,stop:()=>{if(s=!0,m(),!o.killed)try{o.kill("SIGTERM")}catch{}_()},donePromise:p},o.once("error",c=>{if(s){_();return}let l=Object.assign(new Error(`audio playback failed: ${c.message}`),{code:"audio_device"});T(l)}),o.once("exit",(c,l)=>{if(s||l==="SIGTERM"||l==="SIGINT"||c===0||c===null){_();return}let O=Object.assign(new Error(`audio player exited with code ${c}`),{code:"audio_device"});T(O)}),p}function re(){d&&d.stop()}import{nanoid as $e}from"nanoid";import{readFileSync as Te,writeFileSync as Ce,mkdirSync as Fe,existsSync as L,appendFileSync as Oe}from"fs";import{homedir as Ne}from"os";import{join as oe}from"path";var $=oe(Ne(),".cache","flowe"),v=oe($,"pending-events.jsonl"),ke=5e3;function Ae(){let e=process.env.FLOWE_OPT_OUT?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}async function F(e,t,r){if(!(t.telemetry==="off"||Ae())){De(),Me(e);try{await Ie(t,r)}catch{}}}function De(){L($)||Fe($,{recursive:!0})}function Me(e){for(let t of e)Oe(v,JSON.stringify(t)+`
|
|
2
|
+
`,"utf-8")}function Re(){return L(v)?Te(v,"utf-8").split(`
|
|
3
|
+
`).filter(t=>t.trim().length>0).map(t=>JSON.parse(t)):[]}function ne(){L(v)&&Ce(v,"","utf-8")}async function Ie(e,t){let r=Re();if(r.length===0)return;let n={version:H(),platform:`${process.platform}-${process.arch}`,node_version:process.version},o=new AbortController,a=setTimeout(()=>o.abort(),ke);try{let s={"Content-Type":"application/json"};t&&(s.Authorization=`Bearer ${t}`);let i=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:o.signal});(i.ok||i.status===401||i.status===400)&&ne()}finally{clearTimeout(a)}}function Le(e,t,r){if(e.length===0)return[];let o=t*1e3/e.length;return e.map((a,s)=>({label:a,mode:r,start_ms:Math.round(s*o),end_ms:Math.round((s+1)*o)}))}function Rt(){return I()?(re(),!0):!1}async function It(e,t="user_requested",r,n={}){let o=process.env.FLOWE_SILENT_AUDIO==="1"?"silent":n.audioMode??"local";if(o==="local"&&I())throw Object.assign(new Error("a reset is already running"),{code:"agent_busy"});let a=W(),s=n.voice??a.voice,i=z(e,r);if(!i){let _e=r?`${r} at ${e}s`:`${e}s`;throw Object.assign(new Error(`no protocol available for ${_e}`),{code:"protocol_unavailable"})}let u=X(i.protocol_id,s);if(o==="local"&&!u)throw Object.assign(new Error(`no audio available for ${i.protocol_id}:${s}`),{code:"protocol_unavailable"});let p=`reset_${$e(8)}`,m=new Date,_=Math.floor(m.getTime()/1e3),T=_+e;Q();let c=await G();await F([{type:"reset_started",session_id:p,protocol_id:i.protocol_id,duration_seconds:e,voice:s,trigger:t,client_timestamp:m.toISOString()}],a,c),o==="local"&&u&&te(u).then(()=>{if(n.recordOnComplete)try{Y()}catch{}F([{type:"reset_completed",session_id:p,protocol_id:i.protocol_id,duration_seconds:e,voice:s,trigger:t,client_timestamp:new Date().toISOString()}],a,c).catch(()=>{})}).catch(()=>{F([{type:"reset_abandoned",session_id:p,protocol_id:i.protocol_id,duration_seconds:e,voice:s,trigger:t,client_timestamp:new Date().toISOString()}],a,c).catch(()=>{})});let l=Z(i.protocol_id,s),O=l?l.cues:Le(i.text_cues,e,i.category);return{session_id:p,protocol:i.protocol_id,protocol_display_name:i.display_name,duration_seconds:e,voice:s,category:i.category,audio_mode:o,cues:O,rounds:i.rounds,status:"started",started_at_unix:_,ends_at_unix:T,message_for_user:`${e}s ${i.display_name} started \xB7 ${s}`}}import{existsSync as y,mkdirSync as Ve,readFileSync as V,renameSync as se,rmSync as j,writeFileSync as q}from"fs";import{homedir as je}from"os";import{join as h}from"path";var qe="state.json",Be="daemon.pid",Ue="control.txt",Je="daemon.log",We=3e4,Qe=["pause","resume","skip","quit"];function Ye(){return process.env.FLOWE_HOME??h(je(),".flowe")}function b(){return h(Ye(),"sessions","active")}function ae(){return h(b(),qe)}function B(){return h(b(),Be)}function ce(){return h(b(),Ue)}function ue(){return h(b(),Je)}function E(){let e=b();return y(e)||Ve(e,{recursive:!0}),e}function Bt(e){E();let t=ae(),r=`${t}.tmp`;q(r,JSON.stringify(e,null,2),"utf-8"),se(r,t)}function Ut(e={}){let t=ae();if(!y(t))return null;try{let r=V(t,"utf-8"),n=JSON.parse(r);if(n.version!==1)return null;let o=n;if(!Ge(o)||x()!==o.pid)return null;if(!w(o.pid,e.kill))return P(),null;let s=e.now??Date.now,i=e.staleAfterMs??We;return s()-o.updatedAt>i?null:o}catch{return null}}function Ge(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 P(){let e=b();y(e)&&j(e,{recursive:!0,force:!0})}function ie(e=process.pid){E(),q(B(),String(e),"utf-8")}function x(){let e=B();if(!y(e))return null;try{let t=V(e,"utf-8").trim();if(t.length===0)return null;let r=Number(t);return!Number.isInteger(r)||r<=0?null:r}catch{return null}}function He(){let e=B();y(e)&&j(e,{force:!0})}function w(e,t=(r,n)=>{process.kill(r,n)}){if(!Number.isInteger(e)||e<=0)return!1;try{return t(e,0),!0}catch(r){return r.code==="EPERM"}}function Jt(e={}){let t=e.pidOverride??process.pid,r=x();return r!==null&&r!==t&&w(r,e.kill)?{kind:"busy",pid:r}:r!==null&&r!==t?(P(),ie(t),{kind:"swept",stalePid:r}):(ie(t),{kind:"acquired"})}function Wt(){He()}function Qt(e){let t=x();if(t===null||!w(t))throw t!==null&&P(),new Error("no active focus session");E();let r=ce(),n=`${r}.tmp`;q(n,`${e}
|
|
4
|
+
`,"utf-8"),se(n,r)}function Yt(){let e=ce();if(!y(e))return null;let t;try{t=V(e,"utf-8")}catch{return null}finally{j(e,{force:!0})}let r=t.trim().toLowerCase();return Qe.includes(r)?r:null}import{spawn as Ke}from"child_process";import{openSync as ze,closeSync as Xe}from"fs";var le="FLOWE_FOCUS_DAEMON",U="FLOWE_FOCUS_PRESET",de="FLOWE_FOCUS_AMBIENT_FILE",pe="FLOWE_FOCUS_AMBIENT_ID",fe="FLOWE_FOCUS_BREAK_TYPE",me="FLOWE_FOCUS_LONG_BREAK_TYPE",J=class extends Error{constructor(r){super(`a focus daemon is already running (pid ${r})`);this.existingPid=r;this.name="DaemonAlreadyRunningError"}existingPid};function Ze(e){let t={...process.env,[le]:"1",[U]:e.preset};return e.ambientFilePath&&(t[de]=e.ambientFilePath),e.ambientId&&(t[pe]=e.ambientId),e.breakType&&(t[fe]=e.breakType),e.longBreakType&&(t[me]=e.longBreakType),t}function Zt(e){let t=x();if(t!==null){if(w(t))throw new J(t);P()}E();let r=ue(),n=ze(r,"a"),o=e.spawnArgs?.cmd??process.execPath,a=e.spawnArgs?.args??[...process.execArgv,process.argv[1]??"","focus",e.preset],i=(e.spawnFn??Ke)(o,a,{detached:!0,stdio:["ignore",n,n],env:Ze(e)});if(Xe(n),i.unref(),i.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&&!et(i.pid,u))throw new Error("focus daemon did not become ready");return{pid:i.pid,logPath:r}}function et(e,t){let r=Date.now()+t;for(;Date.now()<=r;){if(x()===e)return!0;tt(25)}return!1}function tt(e){let t=new SharedArrayBuffer(4),r=new Int32Array(t);Atomics.wait(r,0,0,e)}function er(){let e=process.env[U];if(e!=="pomodoro"&&e!=="dev"&&e!=="ultradian"&&e!=="test2"&&e!=="test5")throw new Error(`invalid ${U}: ${e??"(unset)"} \u2014 daemon child cannot start`);return{preset:e,ambientFilePath:process.env[de]||void 0,ambientId:process.env[pe]||void 0,breakType:process.env[fe]||void 0,longBreakType:process.env[me]||void 0}}function tr(){return process.env[le]==="1"}function rr(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(`
|
|
5
|
+
`)}export{H as a,at as b,ct as c,D as d,mt as e,_t as f,xt as g,te as h,re as i,Ae as j,Rt as k,It as l,Ye as m,Bt as n,Ut as o,P as p,Jt as q,Wt as r,Qt as s,Yt as t,J as u,Zt as v,er as w,tr as x,rr as y};
|