@heygaia/cli 0.1.1 → 0.1.3

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.
Files changed (3) hide show
  1. package/README.md +120 -35
  2. package/dist/index.js +15 -13
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,25 +1,72 @@
1
1
  # @heygaia/cli
2
2
 
3
- CLI tool for setting up and managing GAIA - your proactive personal AI assistant.
3
+ CLI tool for setting up and managing [GAIA](https://heygaia.io) your proactive personal AI assistant.
4
+
5
+ The CLI provides an interactive terminal UI that guides you through cloning, configuring, and running a self-hosted GAIA instance.
6
+
7
+ ## Requirements
8
+
9
+ - **Node.js 18+** (for npm/npx) or **Bun** (alternative)
10
+ - **macOS or Linux** (Windows via WSL2)
11
+ - **Docker** installed and running
12
+ - **Git** installed
13
+
14
+ The CLI checks prerequisites at startup and tells you what's missing.
4
15
 
5
16
  ## Installation
6
17
 
18
+ ### curl (recommended)
19
+
20
+ Downloads and installs the CLI globally. Uses npm if available, falls back to bun.
21
+
7
22
  ```bash
8
- # Quick install (recommended)
9
23
  curl -fsSL https://heygaia.io/install.sh | sh
24
+ ```
10
25
 
11
- # Or via npm
26
+ ### npm
27
+
28
+ ```bash
12
29
  npm install -g @heygaia/cli
30
+ ```
31
+
32
+ ### npx (no install)
33
+
34
+ Run directly without a global install:
13
35
 
14
- # Or run without installing
36
+ ```bash
15
37
  npx @heygaia/cli init
16
38
  ```
17
39
 
40
+ ### Other package managers
41
+
42
+ ```bash
43
+ # pnpm
44
+ pnpm add -g @heygaia/cli
45
+
46
+ # bun
47
+ bun add -g @heygaia/cli
48
+ ```
49
+
50
+ ### Verify
51
+
52
+ ```bash
53
+ gaia --version
54
+ gaia --help
55
+ ```
56
+
57
+ ## What Happens When You Install
58
+
59
+ 1. The `@heygaia/cli` npm package is installed globally
60
+ 2. A `gaia` binary is added to your PATH (points to `dist/index.js`)
61
+ 3. No background processes, daemons, or services are started — the CLI only runs when you invoke it
62
+
63
+ The CLI itself is a single bundled JavaScript file (~300KB) with no native dependencies.
64
+
18
65
  ## Commands
19
66
 
20
67
  | Command | Description |
21
68
  |---------|-------------|
22
- | `gaia init` | Full setup from scratch - clones repo, installs tools, configures env, starts services |
69
+ | `gaia init` | Full setup from scratch clone repo, install tools, configure env, start services |
23
70
  | `gaia setup` | Configure an existing GAIA repository (env vars, dependencies) |
24
71
  | `gaia start` | Start all GAIA services (auto-detects selfhost vs developer mode) |
25
72
  | `gaia stop` | Stop all running GAIA services |
@@ -27,56 +74,93 @@ npx @heygaia/cli init
27
74
 
28
75
  ### `gaia init`
29
76
 
30
- Interactive wizard for first-time setup:
77
+ Interactive wizard for first-time setup. This is the main entry point for new users.
31
78
 
32
- 1. Prerequisites check (Git, Docker, Mise)
33
- 2. Repository cloning
34
- 3. Tool installation (Node.js, Python, uv, Nx)
35
- 4. Environment variable configuration
36
- 5. Project setup (`mise setup`)
37
- 6. Service startup (optional)
79
+ **What it does:**
80
+
81
+ 1. **Prerequisites check** Verifies Git, Docker, and [Mise](https://mise.jdx.dev) are installed. Auto-installs Mise if missing.
82
+ 2. **Port conflict detection** — Checks ports 3000, 5432, 6379, 8000, 8080, 27017, 5672. Suggests alternatives if any are in use.
83
+ 3. **Repository clone** Clones the GAIA repo to your chosen directory with progress tracking.
84
+ 4. **Tool installation** — Installs Node.js, Python, uv, and Nx via Mise.
85
+ 5. **Environment configuration** — Choose a setup mode and configure variables (see below).
86
+ 6. **Project setup** — Runs `mise setup` to install all dependencies, start Docker services, and seed the database.
87
+ 7. **Service startup** — Optionally starts all services immediately.
38
88
 
39
89
  ### `gaia setup`
40
90
 
41
- For existing repos that need configuration or reconfiguration. Run from within a cloned GAIA directory:
91
+ For existing repos that need configuration or reconfiguration. Skips cloning and tool installation, goes straight to environment setup.
42
92
 
43
93
  ```bash
44
- cd /path/to/gaia && gaia setup
94
+ cd /path/to/gaia
95
+ gaia setup
45
96
  ```
46
97
 
47
- ### `gaia start` / `gaia stop`
98
+ ### `gaia start`
99
+
100
+ Starts all services. Auto-detects the setup mode from your `.env` configuration:
48
101
 
49
- Start or stop services. Automatically detects selfhost vs developer mode from your `.env` configuration.
102
+ - **Self-host mode**: Runs `docker compose --profile all up -d`
103
+ - **Developer mode**: Runs `mise dev` for local API + web, Docker for databases
104
+
105
+ ### `gaia stop`
106
+
107
+ Stops all running services:
108
+ - Docker containers in the GAIA compose stack
109
+ - Local processes on ports 8000 (API) and 3000 (Web)
50
110
 
51
111
  ### `gaia status`
52
112
 
53
- Shows health and latency for: API (8000), Web (3000), PostgreSQL (5432), Redis (6379), MongoDB (27017), RabbitMQ (5672), ChromaDB (8080).
113
+ Shows a live health dashboard with latency for all services:
114
+
115
+ | Service | Port | Health Check |
116
+ |---------|------|--------------|
117
+ | API | 8000 | HTTP `GET /health` |
118
+ | Web | 3000 | HTTP `GET /` |
119
+ | PostgreSQL | 5432 | TCP connection |
120
+ | Redis | 6379 | TCP connection |
121
+ | MongoDB | 27017 | TCP connection |
122
+ | RabbitMQ | 5672 | TCP connection |
123
+ | ChromaDB | 8080 | TCP connection |
124
+
125
+ Press `r` to refresh.
54
126
 
55
127
  ## Setup Modes
56
128
 
57
- - **Self-Host (Docker)**: Everything runs in Docker. Best for deployment.
58
- - **Developer (Local)**: Databases in Docker, API + web run locally. Best for contributing.
129
+ During `gaia init` or `gaia setup`, you choose a mode:
130
+
131
+ - **Self-Host (Docker)** — Everything runs in Docker containers. Best for deployment and non-developers.
132
+ - **Developer (Local)** — Databases in Docker, API + web run locally with hot reload. Best for contributing.
59
133
 
60
- ## Environment Variable Auto-Discovery
134
+ ## Environment Variable Configuration
61
135
 
62
- The CLI discovers env vars from the codebase at runtime:
136
+ Two methods are available:
63
137
 
64
- - **API**: Extracted from `apps/api/app/config/settings.py` and `settings_validator.py` via Python AST
65
- - **Web**: Parsed from `apps/web/.env`
138
+ - **Manual** Interactive prompts for each variable with descriptions, documentation links, and defaults.
139
+ - **Infisical** Enter your Infisical credentials (token, project ID, machine identity) for centralized secret management.
66
140
 
67
- No CLI updates needed when new variables are added.
141
+ ### Auto-Discovery
142
+
143
+ The CLI discovers environment variables from the codebase at runtime:
144
+
145
+ - **API variables** — Extracted from `apps/api/app/config/settings.py` and `settings_validator.py` via Python AST parsing
146
+ - **Web variables** — Parsed from `apps/web/.env`
147
+
148
+ When a developer adds a new variable to either location, the CLI picks it up automatically — no CLI updates needed.
68
149
 
69
150
  ## Development
70
151
 
71
152
  ```bash
72
- # Dev mode (no build, uses current workspace)
73
- GAIA_CLI_DEV=true bun packages/cli/src/index.ts <command>
153
+ # Dev mode (watch, no build needed)
154
+ GAIA_CLI_DEV=true pnpm tsx packages/cli/src/index.ts <command>
74
155
 
75
156
  # Build
76
- cd packages/cli && bun run build
157
+ cd packages/cli && pnpm run build
77
158
 
78
- # Test built CLI
159
+ # Test the built CLI
79
160
  ./packages/cli/dist/index.js --help
161
+
162
+ # Run the test script
163
+ ./packages/cli/test-cli.sh
80
164
  ```
81
165
 
82
166
  ### Install Script
@@ -87,24 +171,25 @@ Source of truth: `packages/cli/install.sh`. After modifying, sync to the web app
87
171
  ./packages/cli/sync-install.sh
88
172
  ```
89
173
 
90
- This keeps `https://heygaia.io/install.sh` up to date.
174
+ This copies the script to `apps/web/public/install.sh`, which is served at `https://heygaia.io/install.sh`.
91
175
 
92
176
  ### Publishing
93
177
 
94
178
  1. Update version in `package.json`
95
- 2. Build: `bun run build`
179
+ 2. Build: `pnpm run build`
96
180
  3. Sync install script: `./sync-install.sh`
97
181
  4. Commit and tag: `git tag cli-v<version>`
98
182
  5. Push tag — GitHub Actions publishes to npm
99
183
 
100
- ### Troubleshooting
184
+ ## Troubleshooting
101
185
 
102
186
  | Issue | Fix |
103
187
  |-------|-----|
104
- | `command not found: gaia` | Ensure `~/.bun/bin` or `~/.npm-global/bin` is in PATH |
105
- | Raw mode not supported | CLI requires interactive terminal — don't run in background |
106
- | Port conflicts not detected | Ensure `lsof` is available (macOS/Linux) |
107
- | Env vars not discovered | Check `settings_validator.py` and `apps/web/.env` exist |
188
+ | `command not found: gaia` | Ensure the global bin directory is in PATH. For npm: `export PATH="$(npm config get prefix)/bin:$PATH"`. For bun: `export PATH="$HOME/.bun/bin:$PATH"` |
189
+ | Raw mode not supported | The CLI requires an interactive terminal — don't run in background or pipe |
190
+ | Port conflicts not detected | Ensure `lsof` is available (macOS/Linux). Windows requires WSL2 |
191
+ | Env vars not discovered | Check that `settings_validator.py` and `apps/web/.env` exist in the repo |
192
+ | Docker prerequisite fails | Ensure Docker Desktop/Engine is running, not just installed |
108
193
 
109
194
  ## License
110
195
 
package/dist/index.js CHANGED
@@ -1,14 +1,16 @@
1
1
  #!/usr/bin/env node
2
- import{Command as Or}from"commander";import{render as wr}from"ink";import Dr from"react";import{Box as fe,Text as Z}from"ink";import sr from"react";import{ProgressBar as Ke,Select as Je,Spinner as ze}from"@inkjs/ui";import{Box as p,Text as s,useInput as z}from"ink";import ce from"ink-text-input";import{useEffect as me,useState as M}from"react";import{Box as se,Text as Ye}from"ink";var h="#00bbff";import{Box as qt,Text as Ce}from"ink";import{jsx as He,jsxs as We}from"react/jsx-runtime";var Xe=({status:e,step:t})=>t.toLowerCase()==="welcome"?null:We(qt,{width:"100%",borderStyle:"single",borderColor:"gray",paddingX:1,justifyContent:"space-between",children:[We(Ce,{color:h,children:[He(Ce,{bold:!0,children:"Status:"})," ",t]}),He(Ce,{color:"white",dimColor:!0,children:e})]});import{Box as Ot}from"ink";import $t from"ink-big-text";import jt from"ink-gradient";import{jsx as Ee}from"react/jsx-runtime";var te=()=>Ee(Ot,{flexDirection:"column",marginTop:1,marginBottom:1,children:Ee(jt,{colors:[h,"#b0eaff",h],children:Ee($t,{text:"GAIA",font:"3d"})})});import{jsx as re,jsxs as pe}from"react/jsx-runtime";var Ut=["Welcome","Prerequisites","Repository Setup","Install Tools","Environment Setup","Project Setup","Finished"],Qe=["Detect Repo","Prerequisites","Environment Setup","Project Setup","Finished"],Vt=({currentStep:e,steps:t})=>{let o=t.indexOf(e);return re(se,{marginBottom:1,children:t.map((r,n)=>{let i=r===e,u=o>n;return pe(se,{marginRight:2,children:[pe(Ye,{color:i?h:u?"green":"gray",children:[u?"\u2713 ":i?"\u25CF ":"\u25CB ",r]}),n<t.length-1&&re(Ye,{color:"gray",children:" \u203A "})]},r)})})},de=({children:e,status:t,step:o,steps:r=Ut})=>pe(se,{flexDirection:"column",height:"100%",width:"100%",children:[pe(se,{flexGrow:1,flexDirection:"column",children:[re(te,{}),re(Vt,{currentStep:o,steps:r}),re(se,{flexDirection:"column",flexGrow:1,children:e})]}),re(Xe,{status:t,step:o})]});import{Fragment as po,jsx as a,jsxs as l}from"react/jsx-runtime";var we=({label:e,status:t})=>l(p,{children:[a(p,{marginRight:1,children:t==="pending"?a(ze,{type:"dots"}):t==="success"?a(s,{color:h,children:"\u2714"}):t==="error"?a(s,{color:"red",children:"\u2716"}):a(s,{color:"yellow",children:"\u26A0"})}),a(s,{children:e})]}),Ht=({onConfirm:e})=>(z((t,o)=>{o.return&&e()}),l(p,{flexDirection:"column",paddingX:2,borderStyle:"round",borderColor:h,children:[a(s,{bold:!0,children:"Welcome to the Interactive GAIA Setup"}),l(p,{flexDirection:"column",marginTop:1,marginBottom:1,children:[a(s,{children:"This wizard will guide you through the setup process:"}),a(s,{children:" 1. Check Prerequisites (Git, Docker, Mise)"}),a(s,{children:" 2. Clone Repository (from GitHub)"}),a(s,{children:" 3. Install Tools (node, python, uv via mise)"}),a(s,{children:" 4. Configure Env Vars (databases, API keys, etc.)"}),a(s,{children:" 5. Setup Project (install all dependencies)"})]}),a(s,{color:h,children:"Press Enter to start..."})]})),Wt=({portResults:e,onAccept:t,onAbort:o})=>{z((n,i)=>{i.return?t():i.escape&&o()});let r=e.filter(n=>!n.available);return l(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:"yellow",children:[a(p,{marginBottom:1,children:a(s,{bold:!0,color:"yellow",children:"Port Conflicts Detected"})}),e.map(n=>l(p,{children:[l(s,{color:n.available?"green":n.alternative?"yellow":"red",children:[n.available?"\u2714":n.alternative?"\u26A0":"\u2716"," "]}),l(s,{children:[n.service," (:",n.port,")"]}),!n.available&&l(s,{color:n.alternative?"gray":"red",children:[" ","- in use",n.usedBy?` by ${n.usedBy}`:"",n.alternative?` \u2192 will use :${n.alternative}`:" \u2014 NO ALTERNATIVE FOUND"]})]},n.port)),l(p,{marginTop:1,flexDirection:"column",children:[r.some(n=>!n.alternative)&&a(p,{borderStyle:"single",borderColor:"red",paddingX:1,marginBottom:1,children:a(s,{color:"red",children:"Some ports have no available alternative. Free them and retry."})}),!r.some(n=>!n.alternative)&&r.some(n=>n.alternative)&&a(s,{color:"gray",children:"Alternative ports will be used for conflicting services."}),a(p,{marginTop:1,children:l(s,{children:[a(s,{color:"green",bold:!0,children:"Enter"})," to continue with alternatives ",a(s,{color:"yellow",bold:!0,children:"Escape"})," to abort"]})})]})]})},Xt=({defaultValue:e,onSubmit:t})=>{let[o,r]=M(e);return l(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[a(s,{children:"Where should we clone the repository?"}),l(p,{children:[a(s,{color:h,children:"\u279C "}),a(ce,{value:o,onChange:r,onSubmit:t})]}),l(s,{color:"gray",children:["(Press Enter for default: ",e,")"]})]})},Yt=({setupMode:e,repoPath:t,portOverrides:o,onConfirm:r})=>{z((f,g)=>{g.return&&r()});let n=e||"developer",i=t||"./gaia",u=o?.[3e3]??3e3,m=o?.[8e3]??8e3;return l(p,{flexDirection:"column",marginTop:2,borderStyle:"round",borderColor:h,padding:1,children:[a(s,{color:h,bold:!0,children:"You are all set!"}),l(p,{marginTop:1,flexDirection:"column",children:[a(s,{bold:!0,children:"To start GAIA, run:"}),l(p,{marginTop:1,padding:1,borderStyle:"single",borderColor:"gray",flexDirection:"column",children:[l(s,{color:"cyan",children:["$ cd ",i]}),a(s,{color:"cyan",children:"$ gaia start"})]}),a(p,{marginTop:1,children:a(s,{color:"gray",dimColor:!0,children:n==="selfhost"?"Runs: docker compose --profile all up -d (background)":"Runs: mise dev (interactive \u2014 keep terminal open)"})})]}),l(p,{marginTop:1,flexDirection:"column",children:[a(s,{bold:!0,children:"Access GAIA at:"}),l(p,{marginLeft:2,flexDirection:"column",children:[l(s,{children:["Web:"," ",l(s,{color:"cyan",bold:!0,children:["http://localhost:",u]})]}),l(s,{children:["API:"," ",l(s,{color:"cyan",bold:!0,children:["http://localhost:",m]})]})]})]}),a(De,{}),a(p,{marginTop:1,children:a(s,{dimColor:!0,children:"Press Enter to exit"})})]})},De=()=>l(p,{marginTop:1,flexDirection:"column",children:[a(s,{bold:!0,children:"Available commands:"}),l(p,{marginLeft:2,flexDirection:"column",children:[l(s,{children:[l(s,{color:h,bold:!0,children:["gaia start"," "]}),a(s,{color:"gray",children:" Start all services"})]}),l(s,{children:[l(s,{color:h,bold:!0,children:["gaia stop"," "]}),a(s,{color:"gray",children:" Stop all services"})]}),l(s,{children:[a(s,{color:h,bold:!0,children:"gaia status"}),a(s,{color:"gray",children:" Check service health"})]}),l(s,{children:[l(s,{color:h,bold:!0,children:["gaia setup"," "]}),a(s,{color:"gray",children:" Reconfigure environment"})]})]})]}),Qt=({phase:e,progress:t,isComplete:o,logs:r,title:n})=>l(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[a(p,{marginBottom:1,children:a(s,{bold:!0,color:h,children:n||"Installing Dependencies"})}),l(p,{flexDirection:"column",gap:1,children:[a(p,{children:o?l(s,{color:"green",children:["\u2713 ",e]}):a(ze,{label:e||"Preparing..."})}),!o&&t>0&&a(p,{width:50,children:a(Ke,{value:t})}),!o&&r&&r.length>0&&a(p,{flexDirection:"column",marginTop:1,borderStyle:"single",borderColor:"gray",paddingX:1,paddingY:0,minHeight:6,children:r.map((i,u)=>a(s,{color:"gray",wrap:"truncate",children:i},u))})]})]});var Pe=({onSelect:e})=>l(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[a(s,{bold:!0,children:"Setup Mode"}),a(p,{marginTop:1,children:a(s,{color:"gray",children:"How do you want to run GAIA?"})}),a(p,{marginTop:1,children:a(Je,{options:[{label:"Self-Host (Docker)",value:"selfhost"},{label:"Developer Mode (Local)",value:"developer"}],onChange:o=>e(o)})}),l(p,{marginTop:1,flexDirection:"column",children:[a(s,{color:"gray",dimColor:!0,children:"Self-Host: Run everything in Docker containers (recommended for deployment)"}),a(s,{color:"gray",dimColor:!0,children:"Developer: Run backend locally with Docker services (recommended for contributing)"})]})]}),Re=({onSelect:e})=>l(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[a(s,{bold:!0,children:"Environment Variables Setup"}),a(p,{marginTop:1,children:a(s,{color:"gray",children:"Choose how you want to configure environment variables:"})}),a(p,{marginTop:1,children:a(Je,{options:[{label:"Manual Setup (Recommended)",value:"manual"},{label:"Infisical (Advanced)",value:"infisical"}],onChange:o=>e(o)})}),l(p,{marginTop:1,flexDirection:"column",children:[a(s,{color:"gray",dimColor:!0,children:"Manual Setup: Configure variables interactively (recommended for most users)"}),a(s,{color:"gray",dimColor:!0,children:"Infisical: All secrets managed in Infisical dashboard (requires pre-configuration)"})]})]}),ke=({onSubmit:e})=>{let[t,o]=M({INFISICAL_TOKEN:"",INFISICAL_PROJECT_ID:"",INFISICAL_MACHINE_IDENTITY_CLIENT_ID:"",INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET:""}),[r,n]=M(0),[i,u]=M(null),m=[{key:"INFISICAL_TOKEN",description:"Service token from project settings (st.xxx...)"},{key:"INFISICAL_PROJECT_ID",description:"Found in your Infisical project settings"},{key:"INFISICAL_MACHINE_IDENTITY_CLIENT_ID",description:"From Access Control \u2192 Machine Identities"},{key:"INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET",description:"Generated when creating the machine identity"}];z((g,y)=>{if(y.tab||y.downArrow)n(x=>x<m.length-1?x+1:x);else if(y.upArrow)n(x=>x>0?x-1:x);else if(y.return){if(r<m.length-1){n(c=>c+1);return}let x=m.filter(c=>!t[c.key].trim());if(x.length>0){u(`Required: ${x.map(S=>S.key).join(", ")}`);let c=m.findIndex(S=>!t[S.key].trim());c>=0&&n(c);return}e(t)}});let f=m[r];return l(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[a(p,{marginBottom:1,children:a(s,{bold:!0,color:h,children:"Infisical Configuration"})}),a(p,{marginBottom:1,borderStyle:"single",borderColor:"cyan",paddingX:1,children:a(s,{color:"cyan",children:"All environment variables (API keys, auth secrets, etc.) must be configured in your Infisical project. Only Infisical credentials will be stored locally."})}),l(p,{marginBottom:1,flexDirection:"column",children:[a(s,{color:"gray",children:"Configure your Infisical credentials."}),l(s,{color:"gray",dimColor:!0,children:["Visit"," ",a(s,{color:"cyan",underline:!0,children:"app.infisical.com"})," ","to get these values."]})]}),m.map((g,y)=>{let x=g.key.includes("SECRET")||g.key.includes("TOKEN");return l(p,{flexDirection:"column",marginBottom:1,children:[a(p,{children:l(s,{color:y===r?h:"white",children:[y===r?"\u25B8 ":" ",g.key,":"]})}),a(p,{marginLeft:2,children:a(s,{color:"gray",dimColor:!0,children:g.description})}),y===r?a(p,{marginLeft:2,children:a(ce,{value:t[g.key],onChange:c=>{o(S=>({...S,[g.key]:c})),u(null)},placeholder:"Enter value...",mask:x?"*":void 0})}):a(p,{marginLeft:2,children:a(s,{color:t[g.key]?"green":"gray",children:t[g.key]?x?`\u2713 ${"*".repeat(8)}`:`\u2713 ${t[g.key]}`:"(not set)"})})]},g.key)}),i&&a(p,{marginTop:1,children:a(s,{color:"red",children:i})}),a(p,{marginTop:1,children:a(s,{color:"gray",dimColor:!0,children:"\u2191\u2193/Tab to navigate \u2022 Enter to confirm"})})]})},Be=({category:e,currentIndex:t,totalGroups:o,onSubmit:r})=>{let[n,i]=M(()=>{let c={};for(let S of e.variables)c[S.name]=S.defaultValue||"";return c}),[u,m]=M(0),[f,g]=M(null);me(()=>{let c={};for(let S of e.variables)c[S.name]=S.defaultValue||"";i(c),m(0),g(null)},[e.name]),z((c,S)=>{if(S.tab||S.downArrow)m(d=>d<e.variables.length-1?d+1:d);else if(S.upArrow)m(d=>d>0?d-1:d);else if(S.escape){let d=e.variables.filter(T=>T.required&&!n[T.name]?.trim());if(d.length>0){g(`Required fields cannot be skipped: ${d.map(T=>T.name).join(", ")}`);return}r(n)}});let y=()=>{if(u<e.variables.length-1)m(u+1);else{let c=e.variables.filter(S=>S.required&&!n[S.name]?.trim());if(c.length>0){g(`Required fields are missing: ${c.map(S=>S.name).join(", ")}`);return}g(null),r(n)}},x=e.variables.some(c=>c.required);return l(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:f?"red":h,children:[l(p,{justifyContent:"space-between",children:[l(s,{bold:!0,children:["Configure ",e.name]}),l(s,{color:"gray",children:["Group ",t+1," / ",o]})]}),l(p,{marginTop:1,flexDirection:"column",children:[l(p,{children:[l(s,{color:"cyan",bold:!0,children:["Purpose:"," "]}),a(s,{color:"white",children:e.description})]}),e.affectedFeatures&&l(p,{children:[l(s,{color:"cyan",bold:!0,children:["Affects:"," "]}),a(s,{color:"gray",children:e.affectedFeatures})]}),e.docsUrl&&l(p,{marginTop:1,children:[a(s,{color:"green",children:"\u{1F4D6} Docs: "}),a(s,{color:"blue",underline:!0,children:e.docsUrl})]})]}),a(p,{marginTop:1,flexDirection:"column",children:e.variables.map((c,S)=>{let d=S===u,T=!!c.defaultValue;return l(p,{flexDirection:"column",marginBottom:1,children:[l(p,{children:[l(s,{color:d?h:"gray",bold:d,children:[d?"\u279C ":" ",c.name]}),c.required&&l(s,{color:"red",bold:!0,children:[" ","*"]}),T&&!d&&l(s,{color:"gray",dimColor:!0,children:[" ","(default: ",c.defaultValue,")"]})]}),d&&a(p,{marginLeft:2,children:a(ce,{value:n[c.name]||"",onChange:b=>{i(I=>({...I,[c.name]:b})),f&&g(null)},onSubmit:y,placeholder:T?`Default: ${c.defaultValue}`:c.required?"Enter a value (required)":"Press Enter to skip"})})]},c.name)})}),f&&a(p,{marginTop:1,children:l(s,{color:"red",bold:!0,children:["\u26A0 ",f]})}),a(p,{marginTop:1,flexDirection:"column",children:l(s,{color:"gray",dimColor:!0,children:["\u21B5 Enter to next field \u2022 Tab/\u2193 move down \u2022 \u2191 move up",!x&&" \u2022 ESC skip group"]})})]})},Ae=({alternatives:e,onSubmit:t})=>{let[o,r]=M(new Set),[n,i]=M({}),[u,m]=M(0),[f,g]=M(null);me(()=>{let b={};for(let I of e)for(let C of I.variables)b[C.name]=C.defaultValue||"";i(b)},[e]);let y=[];for(let b=0;b<e.length;b++)if(y.push({type:"provider",categoryIndex:b}),o.has(b)){let I=e[b];if(I)for(let C=0;C<I.variables.length;C++)y.push({type:"field",categoryIndex:b,fieldIndex:C})}y.push({type:"submit"});let x=y[u],c=x?.type==="field",S=x?.type==="submit";z((b,I)=>{let C=Math.min(u,y.length-1);if(C!==u){m(C);return}if(c)I.upArrow?m(E=>Math.max(0,E-1)):(I.downArrow||I.tab)&&m(E=>Math.min(y.length-1,E+1));else if(S)I.upArrow?m(E=>Math.max(0,E-1)):(I.return||b===" ")&&T();else if(I.upArrow)m(E=>Math.max(0,E-1));else if(I.downArrow||I.tab)m(E=>Math.min(y.length-1,E+1));else if((I.return||b===" ")&&x?.type==="provider"){let E=x.categoryIndex;r(V=>{let R=new Set(V);return R.has(E)?R.delete(E):R.add(E),R}),f&&g(null)}});let d=()=>{f&&g(null),m(b=>Math.min(y.length-1,b+1))},T=()=>{let b=[],I={};for(let C of o){let E=e[C];if(!E)continue;if(E.variables.some(R=>n[R.name]?.trim())){b.push(E.name);for(let R of E.variables){let ue=n[R.name];ue&&(I[R.name]=ue)}}}if(b.length===0){o.size===0?g("Enable at least one provider (press Space or Enter)"):g("Enter a value for at least one field");return}t(b,I)};return l(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:f?"red":h,children:[l(p,{justifyContent:"space-between",children:[a(s,{bold:!0,children:"Configure AI Provider"}),a(s,{color:"yellow",children:"* At least one required"})]}),a(p,{marginTop:1,children:a(s,{color:"gray",children:"Enable and configure at least one AI provider below:"})}),a(p,{marginTop:1,flexDirection:"column",children:e.map((b,I)=>{let C=o.has(I),E=y.findIndex(R=>R.type==="provider"&&R.categoryIndex===I),V=u===E;return l(p,{flexDirection:"column",marginBottom:1,children:[l(p,{children:[a(s,{color:V?h:void 0,bold:V,children:V?"\u279C ":" "}),a(s,{color:C?"green":"gray",children:C?"[\u2714]":"[ ]"}),l(s,{color:C?h:"gray",bold:C,children:[" ",b.name]}),b.description&&l(s,{color:"gray",dimColor:!0,children:[" ","- ",b.description]})]}),V&&b.docsUrl&&l(p,{marginLeft:6,children:[a(s,{color:"yellow",children:"\u{1F4D6} "}),a(s,{color:"blue",underline:!0,children:b.docsUrl})]}),C&&a(p,{marginLeft:4,flexDirection:"column",marginTop:1,children:b.variables.map((R,ue)=>{let Nt=y.findIndex(ie=>ie.type==="field"&&ie.categoryIndex===I&&ie.fieldIndex===ue),ee=u===Nt,Ve=!!R.defaultValue,Ie=n[R.name]||"";return l(p,{flexDirection:"column",marginBottom:1,children:[l(p,{children:[l(s,{color:ee?h:"gray",bold:ee,children:[ee?" \u279C ":" ",R.name]}),!ee&&Ie&&a(s,{color:"green",children:" \u2713"}),!ee&&!Ie&&Ve&&l(s,{color:"gray",dimColor:!0,children:[" ","(default: ",R.defaultValue,")"]})]}),ee&&a(p,{marginLeft:4,children:a(ce,{value:Ie,onChange:ie=>{i(Gt=>({...Gt,[R.name]:ie})),f&&g(null)},onSubmit:d,placeholder:Ve?`Default: ${R.defaultValue}`:"Enter value..."})})]},R.name)})})]},b.name)})}),f&&a(p,{marginTop:1,children:l(s,{color:"red",bold:!0,children:["\u26A0 ",f]})}),l(p,{marginTop:1,children:[a(s,{color:S?h:void 0,bold:S,children:S?"\u279C ":" "}),a(p,{borderStyle:"round",borderColor:S?h:"gray",paddingX:2,children:a(s,{color:S?h:"gray",bold:S,children:"Continue \u2192"})})]}),a(p,{marginTop:1,children:a(s,{color:"gray",dimColor:!0,children:"\u2191/\u2193 navigate \u2022 Space/Enter toggle/select \u2022 Tab skip field"})})]})},_e=({currentVar:e,currentIndex:t,totalCount:o,onSubmit:r,onSkip:n})=>{let[i,u]=M(e.defaultValue||""),[m,f]=M(null);me(()=>{u(e.defaultValue||""),f(null)},[e.name]),z((x,c)=>{if(c.escape){if(e.required&&!i.trim()){f("This field is required and cannot be skipped");return}n()}});let g=x=>{if(e.required&&!x.trim()){f("This field is required");return}f(null),r(x)},y=!!e.defaultValue;return l(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:m?"red":h,children:[l(p,{justifyContent:"space-between",children:[a(s,{bold:!0,children:"Configure Environment Variables"}),l(s,{color:"gray",children:[t+1," / ",o]})]}),l(p,{marginTop:1,flexDirection:"column",children:[l(p,{children:[a(s,{color:h,bold:!0,children:e.name}),e.required?l(s,{color:"red",bold:!0,children:[" ","* required"]}):l(s,{color:"gray",dimColor:!0,children:[" ","(optional)"]})]}),l(p,{marginTop:1,children:[l(s,{color:"cyan",bold:!0,children:["Category:"," "]}),a(s,{color:"white",children:e.category})]}),l(p,{children:[l(s,{color:"cyan",bold:!0,children:["Purpose:"," "]}),a(s,{color:"white",children:e.description})]}),e.affectedFeatures&&l(p,{children:[l(s,{color:"cyan",bold:!0,children:["Affects:"," "]}),a(s,{color:"gray",children:e.affectedFeatures})]}),e.docsUrl&&l(p,{marginTop:1,children:[a(s,{color:"green",children:"\u{1F4D6} Docs: "}),a(s,{color:"blue",underline:!0,children:e.docsUrl})]}),y&&l(p,{marginTop:1,children:[l(s,{color:"green",bold:!0,children:["Default:"," "]}),a(s,{color:"white",children:e.defaultValue})]})]}),l(p,{marginTop:1,children:[a(s,{color:h,children:"\u279C "}),a(ce,{value:i,onChange:x=>{u(x),m&&f(null)},onSubmit:g,placeholder:y?"Press Enter to use default":e.required?"Enter a value (required)":"Press Enter to skip"})]}),m&&a(p,{marginTop:1,children:l(s,{color:"red",bold:!0,children:["\u26A0 ",m]})}),a(p,{marginTop:1,flexDirection:"column",children:e.required?a(s,{color:"yellow",dimColor:!0,children:"\u21B5 Enter to confirm (required field)"}):y?a(s,{color:"green",dimColor:!0,children:"\u21B5 Enter to use default \u2022 ESC to skip"}):a(s,{color:"gray",dimColor:!0,children:"\u21B5 Enter to confirm \u2022 ESC to skip"})})]})},Ze=({store:e})=>{let[t,o]=M(e.currentState);return me(()=>{let r=()=>o({...e.currentState});return e.on("change",r),()=>{e.off("change",r)}},[e]),l(de,{status:t.status,step:t.step,children:[t.step==="Welcome"&&t.inputRequest?.id==="welcome"&&a(Ht,{onConfirm:()=>e.submitInput(!0)}),t.step==="Prerequisites"&&t.data.checks&&l(p,{flexDirection:"column",borderStyle:"round",paddingX:1,borderColor:h,children:[a(s,{bold:!0,children:"System Checks"}),l(p,{flexDirection:"column",marginTop:1,children:[a(we,{label:"Git",status:t.data.checks.git}),a(we,{label:"Docker",status:t.data.checks.docker}),a(we,{label:"Mise",status:t.data.checks.mise})]})]}),t.inputRequest?.id==="port_conflicts"&&t.data.portConflicts&&a(Wt,{portResults:t.data.portConflicts,onAccept:()=>e.submitInput("accept"),onAbort:()=>e.submitInput("abort")}),t.inputRequest?.id==="repo_path"&&a(Xt,{defaultValue:t.inputRequest.meta.default,onSubmit:r=>e.submitInput(r)}),t.step==="Repository Setup"&&l(p,{flexDirection:"column",borderStyle:"round",padding:1,borderColor:h,children:[a(s,{bold:!0,children:"Cloning Repository"}),l(p,{marginTop:1,flexDirection:"column",children:[a(Ke,{value:t.data.repoProgress||0}),t.data.repoPhase&&a(p,{marginTop:1,children:a(s,{color:"gray",children:t.data.repoPhase})})]})]}),t.inputRequest?.id==="setup_mode"&&a(Pe,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_method"&&a(Re,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_infisical"&&a(ke,{onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_var"&&t.data.currentEnvVar&&a(_e,{categories:t.data.envCategories||[],currentVar:t.data.currentEnvVar,currentIndex:t.data.envVarIndex||0,totalCount:t.data.envVarTotal||0,onSubmit:r=>e.submitInput(r),onSkip:()=>e.submitInput("")}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_group"&&t.data.currentEnvGroup&&a(Be,{category:t.data.currentEnvGroup,currentIndex:t.data.envGroupIndex||0,totalGroups:t.data.envGroupTotal||0,onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_alternatives"&&t.data.alternativeGroups&&a(Ae,{alternatives:t.data.alternativeGroups,onSubmit:(r,n)=>e.submitInput({selectedGroups:r,values:n})}),t.step==="Finished"&&a(Yt,{setupMode:t.data.setupMode,repoPath:t.data.repoPath,portOverrides:t.data.portOverrides,onConfirm:()=>e.submitInput(!0)}),(t.step==="Install Tools"||t.step==="Project Setup")&&a(Qt,{title:t.step==="Install Tools"?"Installing Tools":"Project Setup",phase:t.data.dependencyPhase||"",progress:t.data.dependencyProgress||0,isComplete:t.step==="Install Tools"?t.data.toolComplete||!1:t.data.dependencyComplete||!1,logs:t.data.dependencyLogs||[]}),t.error&&a(p,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:l(s,{color:"red",children:["Error: ",t.error.message]})})]})};import{Spinner as Kt}from"@inkjs/ui";import{Box as G,Text as L,useInput as Jt}from"ink";import{useEffect as zt,useState as Zt}from"react";import{jsx as N,jsxs as B}from"react/jsx-runtime";var et=({store:e,command:t})=>{let[o,r]=Zt(e.currentState);zt(()=>{let i=()=>r({...e.currentState});return e.on("change",i),()=>{e.off("change",i)}},[e]),Jt((i,u)=>{(u.return||u.escape)&&(o.data.started||o.data.stopped||o.error)&&e.submitInput("exit")});let n=t==="start";return B(G,{flexDirection:"column",width:"100%",children:[N(te,{}),(o.step==="Starting"||o.step==="Stopping")&&B(G,{flexDirection:"column",marginTop:1,paddingX:2,borderStyle:"round",borderColor:h,children:[N(Kt,{label:o.status||"Working..."}),o.data.repoPath&&N(G,{marginTop:1,children:B(L,{color:"gray",children:["Repository: ",o.data.repoPath]})}),o.data.setupMode&&N(G,{children:B(L,{color:"gray",children:["Mode: ",o.data.setupMode]})})]}),o.step==="Running"&&o.data.started&&B(G,{flexDirection:"column",marginTop:1,paddingX:2,paddingY:1,borderStyle:"round",borderColor:"green",children:[B(L,{color:"green",bold:!0,children:["\u2713"," GAIA is running!"]}),o.data.setupMode!=="developer"&&B(G,{marginTop:1,flexDirection:"column",children:[B(L,{children:["Web:"," ",B(L,{color:"cyan",bold:!0,children:["http://localhost:",o.data.webPort||3e3]})]}),B(L,{children:["API:"," ",B(L,{color:"cyan",bold:!0,children:["http://localhost:",o.data.apiPort||8e3]})]})]}),o.data.setupMode==="developer"&&B(G,{marginTop:1,flexDirection:"column",children:[N(L,{color:"gray",children:"Dev servers started in background."}),B(L,{color:"gray",children:["Logs: ",N(L,{color:h,children:"dev-start.log"})," in your repo root."]}),B(L,{color:"gray",children:["Run ",N(L,{color:h,children:"gaia stop"})," to shut down."]})]}),N(G,{marginTop:1,children:N(L,{dimColor:!0,children:"Press Enter to exit"})})]}),o.step==="Stopped"&&o.data.stopped&&B(G,{flexDirection:"column",marginTop:1,paddingX:2,paddingY:1,borderStyle:"round",borderColor:h,children:[B(L,{color:h,bold:!0,children:["\u2713"," All GAIA services stopped."]}),N(G,{marginTop:1,children:N(L,{dimColor:!0,children:"Press Enter to exit"})})]}),o.error&&B(G,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:[B(L,{color:"red",children:["Error: ",o.error.message]}),N(G,{marginTop:1,children:N(L,{dimColor:!0,children:"Press Enter to exit"})})]})]})};import{ProgressBar as er,Spinner as Me}from"@inkjs/ui";import{Box as P,Text as w,useInput as tt}from"ink";import{useEffect as tr,useState as rr}from"react";import{jsx as v,jsxs as k}from"react/jsx-runtime";var rt=({store:e})=>{let[t,o]=rr(e.currentState);return tr(()=>{let r=()=>o({...e.currentState});return e.on("change",r),()=>{e.off("change",r)}},[e]),k(de,{status:t.status,step:t.step,steps:Qe,children:[t.step==="Detect Repo"&&k(P,{flexDirection:"column",paddingX:2,borderStyle:"round",borderColor:h,children:[v(w,{bold:!0,children:"Detecting GAIA Repository"}),v(P,{marginTop:1,children:v(Me,{label:"Searching for repository..."})}),t.data.repoPath&&v(P,{marginTop:1,children:k(w,{color:"green",children:["Found: ",t.data.repoPath]})})]}),t.step==="Prerequisites"&&t.data.checks&&k(P,{flexDirection:"column",borderStyle:"round",paddingX:1,borderColor:h,children:[v(w,{bold:!0,children:"System Checks"}),k(P,{flexDirection:"column",marginTop:1,children:[v(Le,{label:"Git",status:t.data.checks.git}),v(Le,{label:"Docker",status:t.data.checks.docker}),v(Le,{label:"Mise",status:t.data.checks.mise})]})]}),t.inputRequest?.id==="port_conflicts"&&t.data.portConflicts&&v(or,{portResults:t.data.portConflicts,onAccept:()=>e.submitInput("accept"),onAbort:()=>e.submitInput("abort")}),t.inputRequest?.id==="setup_mode"&&v(Pe,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_method"&&v(Re,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_infisical"&&v(ke,{onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_var"&&t.data.currentEnvVar&&v(_e,{categories:t.data.envCategories||[],currentVar:t.data.currentEnvVar,currentIndex:t.data.envVarIndex||0,totalCount:t.data.envVarTotal||0,onSubmit:r=>e.submitInput(r),onSkip:()=>e.submitInput("")}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_group"&&t.data.currentEnvGroup&&v(Be,{category:t.data.currentEnvGroup,currentIndex:t.data.envGroupIndex||0,totalGroups:t.data.envGroupTotal||0,onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_alternatives"&&t.data.alternativeGroups&&v(Ae,{alternatives:t.data.alternativeGroups,onSubmit:(r,n)=>e.submitInput({selectedGroups:r,values:n})}),t.step==="Project Setup"&&k(P,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[v(P,{marginBottom:1,children:v(w,{bold:!0,color:h,children:"Project Setup"})}),k(P,{flexDirection:"column",gap:1,children:[v(P,{children:t.data.dependencyComplete?k(w,{color:"green",children:["\u2713"," ",t.data.dependencyPhase]}):v(Me,{label:t.data.dependencyPhase||"Preparing..."})}),!t.data.dependencyComplete&&t.data.dependencyProgress>0&&v(P,{width:50,children:v(er,{value:t.data.dependencyProgress})}),!t.data.dependencyComplete&&t.data.dependencyLogs?.length>0&&v(P,{flexDirection:"column",marginTop:1,borderStyle:"single",borderColor:"gray",paddingX:1,minHeight:6,children:t.data.dependencyLogs.map((r,n)=>v(w,{color:"gray",wrap:"truncate",children:r},n))})]})]}),t.step==="Finished"&&v(nr,{setupMode:t.data.setupMode,repoPath:t.data.repoPath,onConfirm:()=>e.submitInput(!0)}),t.error&&v(P,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:k(w,{color:"red",children:["Error: ",t.error.message]})})]})},Le=({label:e,status:t})=>k(P,{children:[v(P,{marginRight:1,children:t==="pending"?v(Me,{type:"dots"}):t==="success"?v(w,{color:h,children:"\u2714"}):t==="error"?v(w,{color:"red",children:"\u2716"}):v(w,{color:"yellow",children:"\u26A0"})}),v(w,{children:e})]}),or=({portResults:e,onAccept:t,onAbort:o})=>(tt((r,n)=>{n.return?t():n.escape&&o()}),k(P,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:"yellow",children:[v(w,{bold:!0,color:"yellow",children:"Port Conflicts Detected"}),e.map(r=>k(P,{children:[k(w,{color:r.available?"green":"red",children:[r.available?"\u2714":"\u2716"," "]}),k(w,{children:[r.service," (:",r.port,")"]}),!r.available&&k(w,{color:"gray",children:[" ","- in use",r.usedBy?` by ${r.usedBy}`:"",r.alternative?` (alt: :${r.alternative})`:""]})]},r.port)),v(P,{marginTop:1,children:k(w,{children:[v(w,{color:"green",bold:!0,children:"Enter"})," continue ",v(w,{color:"yellow",bold:!0,children:"Escape"})," abort"]})})]})),nr=({setupMode:e,repoPath:t,onConfirm:o})=>(tt((i,u)=>{u.return&&o()}),k(P,{flexDirection:"column",marginTop:2,borderStyle:"round",borderColor:h,padding:1,children:[v(w,{color:h,bold:!0,children:"Setup Complete!"}),k(P,{marginTop:1,flexDirection:"column",children:[v(w,{bold:!0,children:"To start GAIA, run:"}),k(P,{marginTop:1,padding:1,borderStyle:"single",borderColor:"gray",flexDirection:"column",children:[k(w,{color:"cyan",children:["$ cd ",t||"."]}),v(w,{color:"cyan",children:"$ gaia start"})]}),v(P,{marginTop:1,children:v(w,{color:"gray",dimColor:!0,children:(e||"developer")==="selfhost"?"Runs: docker compose --profile all up -d (background)":"Runs: mise dev (interactive \u2014 keep terminal open)"})})]}),v(De,{}),v(P,{marginTop:1,children:v(w,{dimColor:!0,children:"Press Enter to exit"})})]}));import{Spinner as ar}from"@inkjs/ui";import{Box as A,Text as _,useInput as ir}from"ink";import{useEffect as ot,useState as nt}from"react";import{jsx as D,jsxs as F}from"react/jsx-runtime";var at=({store:e})=>{let[t,o]=nt(e.currentState),[r,n]=nt(!1);return ot(()=>{let i=()=>o({...e.currentState});return e.on("change",i),()=>{e.off("change",i)}},[e]),ot(()=>{t.step==="Results"&&n(!1)},[t.step]),ir((i,u)=>{(u.return||u.escape)&&t.step==="Results"&&e.submitInput("exit"),i==="r"&&t.step==="Results"&&t.data.refreshable&&!r&&(n(!0),e.submitInput("refresh"))}),F(A,{flexDirection:"column",width:"100%",children:[D(te,{}),t.step==="Checking"&&D(A,{marginTop:1,children:D(ar,{label:t.data.services?"Refreshing service health...":"Checking service health..."})}),t.step==="Results"&&t.data.services&&F(A,{flexDirection:"column",children:[F(A,{flexDirection:"column",borderStyle:"round",borderColor:h,paddingX:2,paddingY:1,children:[D(_,{bold:!0,color:h,children:"GAIA Service Status"}),F(A,{marginTop:1,flexDirection:"column",children:[F(A,{children:[D(A,{width:22,children:D(_,{bold:!0,children:"Service"})}),D(A,{width:10,children:D(_,{bold:!0,children:"Status"})}),D(A,{width:10,children:D(_,{bold:!0,children:"Latency"})})]}),D(_,{color:"gray",children:"\u2500".repeat(42)}),t.data.services.map(i=>F(A,{children:[D(A,{width:22,children:F(_,{children:[i.name," (:",i.port,")"]})}),D(A,{width:10,children:D(_,{color:i.status==="up"?"green":"red",bold:!0,children:i.status==="up"?"\u2713 UP":"\u2717 DOWN"})}),D(A,{width:10,children:D(_,{color:"gray",children:i.latency?`${i.latency}ms`:"--"})})]},i.name))]})]}),t.data.docker&&F(A,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,marginTop:1,children:[D(_,{bold:!0,children:"Docker Containers"}),F(_,{color:"gray",children:["Docker:"," ",t.data.docker.running?D(_,{color:"green",children:"Running"}):D(_,{color:"red",children:"Not running"})]}),t.data.docker.containers?.length>0&&D(A,{marginTop:1,flexDirection:"column",children:t.data.docker.containers.map(i=>F(A,{children:[F(_,{color:i.status==="running"?"green":"red",children:[i.status==="running"?"\u2713":"\u2717"," "]}),D(_,{children:i.name}),i.health&&F(_,{color:"gray",children:[" (",i.health,")"]})]},i.name))})]}),D(A,{marginTop:1,children:F(_,{dimColor:!0,children:["Press Enter or Escape to exit \xB7 Press"," ",D(_,{color:h,children:"r"})," to refresh"]})})]}),t.error&&D(A,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:F(_,{color:"red",children:["Error: ",t.error.message]})})]})};import{jsx as q,jsxs as le}from"react/jsx-runtime";var cr=["init","setup","status","start","stop"],Fe=class extends sr.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}render(){return this.state.error?le(fe,{flexDirection:"column",padding:1,children:[q(Z,{color:"red",bold:!0,children:"An unexpected error occurred:"}),q(Z,{color:"red",children:this.state.error.message}),this.state.error.stack&&q(fe,{marginTop:1,children:q(Z,{color:"gray",dimColor:!0,children:this.state.error.stack})})]}):this.props.children}},lr=({store:e,command:t})=>{switch(t){case"init":return q(Ze,{store:e});case"setup":return q(rt,{store:e});case"status":return q(at,{store:e});case"start":case"stop":return q(et,{store:e,command:t});default:return le(fe,{flexDirection:"column",padding:1,children:[le(Z,{color:"red",children:["Unknown command: ",t]}),le(fe,{marginTop:1,flexDirection:"column",children:[q(Z,{bold:!0,children:"Available commands:"}),cr.map(o=>le(Z,{children:[" ",q(Z,{color:"cyan",children:o})]},o))]})]})}},$=({store:e,command:t})=>q(Fe,{children:q(lr,{store:e,command:t})});import{EventEmitter as ur}from"events";var Ne=class extends ur{state={step:"init",status:"",error:null,data:{},inputRequest:null};inputResolver=null;get currentState(){return this.state}setStep(t){this.state.step=t,this.emit("change",this.state)}setStatus(t){this.state.status=t,this.emit("change",this.state)}setError(t){this.state.error=t,t!==null&&this.inputResolver&&(this.inputResolver(null),this.inputResolver=null,this.state.inputRequest=null),this.emit("change",this.state)}updateData(t,o){this.state.data={...this.state.data,[t]:o},this.emit("change",this.state)}waitForInput(t,o){return this.state.inputRequest={id:t,meta:o},this.emit("change",this.state),new Promise(r=>{this.inputResolver=r})}submitInput(t){this.inputResolver&&(this.inputResolver(t),this.inputResolver=null,this.state.inputRequest=null,this.emit("change",this.state))}},j=()=>new Ne;import*as ae from"fs";import*as St from"path";import*as ne from"node:fs";import*as oe from"node:path";import{execa as it}from"execa";var st={selfhost:{MONGO_DB:"mongodb://mongo:27017/gaia",REDIS_URL:"redis://redis:6379",POSTGRES_URL:"postgresql://postgres:postgres@postgres:5432/langgraph",CHROMADB_HOST:"chromadb",CHROMADB_PORT:"8000",RABBITMQ_URL:"amqp://guest:guest@rabbitmq:5672/"},developer:{MONGO_DB:"mongodb://localhost:27017/gaia",REDIS_URL:"redis://localhost:6379",POSTGRES_URL:"postgresql://postgres:postgres@localhost:5432/postgres",CHROMADB_HOST:"localhost",CHROMADB_PORT:"8080",RABBITMQ_URL:"amqp://guest:guest@localhost:5672/"}},ct={selfhost:{HOST:"http://localhost:8000",FRONTEND_URL:"http://localhost:3000",GAIA_BACKEND_URL:"http://gaia-backend:80",SETUP_MODE:"selfhost"},developer:{HOST:"http://localhost:8000",FRONTEND_URL:"http://localhost:3000",GAIA_BACKEND_URL:"http://host.docker.internal:8000",SETUP_MODE:"developer"}};function Ge(e,t){return st[t][e]??ct[t][e]}async function lt(e){let t=oe.join(e,"apps/api/scripts/dump_config_schema.py"),o=oe.join(e,"apps/api/app/config/settings_validator.py"),r=oe.join(e,"apps/api/app/config/settings.py");if(!ne.existsSync(t))throw new Error("dump_config_schema.py not found in apps/api/scripts");try{try{let{stdout:n}=await it("python3",[t,o,r],{cwd:e});return JSON.parse(n)}catch{let{stdout:n}=await it("python",[t,o,r],{cwd:e});return JSON.parse(n)}}catch(n){throw new Error(`Failed to parse settings schema: ${n.message}. Ensure python is installed.`)}}function ut(e){let t=oe.join(e,"apps","web",".env.local"),o=ne.existsSync(t)?t:oe.join(e,"apps","web",".env");if(!ne.existsSync(o))return[];let r=ne.readFileSync(o,"utf-8"),n=[],i="General";for(let u of r.split(`
3
- `)){let m=u.trim();if(m.startsWith("#")&&!m.startsWith("#=")){let x=m.replace(/^#+\s*/,"").trim();x&&!x.startsWith("These are")&&(i=x);continue}if(!m||m.startsWith("#"))continue;let f=m.indexOf("=");if(f===-1)continue;let g=m.substring(0,f).trim(),y=m.substring(f+1).trim();n.push({name:g,value:y,category:i})}return n}function pt(e,t){let o=t?.[8e3]??8e3,r=t?.[3e3]??3e3,n={NEXT_PUBLIC_API_BASE_URL:`http://localhost:${o}/api/v1/`,NEXT_PUBLIC_WS_URL:`ws://localhost:${o}/api/v1/`};return r!==3e3&&(n.NEXT_PUBLIC_APP_URL=`http://localhost:${r}`),n}function dt(e,t){for(let[o,r]of Object.entries(t)){let n=Number(o);for(let[i,u]of Object.entries(e)){let m=new RegExp(`:${n}(?=[/\\s]|$)`,"g");e[i]=u.replaceAll(m,`:${r}`)}}}function mt(e,t){return e.map(o=>({...o,variables:o.variables.map(r=>{let n=Ge(r.name,t);return{...r,defaultValue:n||r.defaultValue}})}))}function qe(){return Object.keys(st.selfhost)}function ft(e){return{...ct[e]}}import*as Y from"fs";import*as Oe from"path";function gt(e){Y.existsSync(e)&&Y.copyFileSync(e,`${e}.bak`)}function xt(e,t){let o=Oe.join(e,".env");gt(o);let r=["# GAIA Environment Configuration","# Generated by GAIA CLI",`# Created: ${new Date().toISOString()}`,""],n=["MONGO","REDIS","POSTGRES","CHROMADB","RABBITMQ","WORKOS","GOOGLE","OPENAI","INFISICAL","LANGSMITH","DISCORD","SLACK","TELEGRAM","CLOUDINARY","COMPOSIO","FIRECRAWL","LIVEKIT","DEEPGRAM","ELEVENLABS","RESEND","SENTRY","POSTHOG","MEM0","E2B","DODO","NEXT_PUBLIC","GAIA"];function i(m){for(let g of n)if(m===g||m.startsWith(`${g}_`))return g;let f=m.split("_");return f.length===1?"Core":f[0]||"Core"}let u=new Map;for(let[m,f]of Object.entries(t)){let g=i(m);u.has(g)||u.set(g,[]);let x=/[\s#"'\\]/.test(f)||f===""?`"${f.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:f;u.get(g).push(`${m}=${x}`)}for(let[m,f]of u.entries())r.push(`# ${m} Configuration`),r.push(...f),r.push("");Y.writeFileSync(o,r.join(`
4
- `),"utf-8")}function ht(e,t,o){let r=Oe.join(e,"apps","web",".env.local");gt(r);let n=ut(e),i=pt(t,o),u=["# GAIA Web App Environment Configuration","# Generated by GAIA CLI",`# Created: ${new Date().toISOString()}`,""],m=new Map;for(let f of n){m.has(f.category)||m.set(f.category,[]);let g=i[f.name]??f.value;m.get(f.category).push({name:f.name,value:g})}if(n.length===0){u.push("# Core URLs");for(let[f,g]of Object.entries(i))u.push(`${f}=${g}`);u.push("")}else for(let[f,g]of m.entries()){u.push(`# ${f}`);for(let{name:y,value:x}of g)u.push(`${y}=${x}`);u.push("")}Y.writeFileSync(r,u.join(`
5
- `),"utf-8")}var mr=e=>new Promise(t=>setTimeout(t,e));async function ge(e,t,o){e.setStep("Environment Setup"),e.setStatus("Configuring environment...");let r=await e.waitForInput("setup_mode");e.updateData("setupMode",r),e.setStatus("Configuring environment variables...");let n=await e.waitForInput("env_method"),i={};i.ENV=r==="selfhost"?"production":"development";let u=qe();for(let f of u){let g=Ge(f,r);g&&(i[f]=g)}let m=ft(r);for(let[f,g]of Object.entries(m))i[f]=g;if(n==="infisical")await fr(e,i),e.setStatus("Infisical credentials saved. Ensure your Infisical project contains all required variables.");else try{await gr(e,t,i,r)}catch(f){e.setError(f);return}o&&dt(i,o);try{await xr(e,t,i,r,o)}catch(f){e.setError(f);return}await mr(1e3)}async function fr(e,t){e.setStatus("Configuring Infisical...");let o=await e.waitForInput("env_infisical");t.INFISICAL_PROJECT_ID=o.INFISICAL_PROJECT_ID,t.INFISICAL_MACHINE_IDENTITY_CLIENT_ID=o.INFISICAL_MACHINE_IDENTITY_CLIENT_ID,t.INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET=o.INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET}async function gr(e,t,o,r){e.setStatus("Parsing environment variables...");let n;try{n=await lt(t),n=mt(n,r)}catch(d){throw new Error(`Failed to parse settings: ${d.message}`)}let i=new Set,u=[],m=new Set;for(let d of n)if(d.alternativeGroup&&!m.has(d.name)){let T=n.find(b=>b.name===d.alternativeGroup);T&&(u.push([d,T]),i.add(d.name),i.add(T.name),m.add(d.name),m.add(T.name))}let f=n.filter(d=>d.variables.length===1&&!i.has(d.name)),g=n.filter(d=>d.variables.length>1&&!i.has(d.name));for(let d of u){e.updateData("alternativeGroups",d),e.setStatus("Choose an AI provider...");let T=await e.waitForInput("env_alternatives");for(let[b,I]of Object.entries(T.values))I&&(o[b]=I)}let y=qe(),c=[...f.flatMap(d=>d.variables).filter(d=>!y.includes(d.name))].sort((d,T)=>d.required&&!T.required?-1:!d.required&&T.required?1:0);e.updateData("envVarTotal",c.length);for(let d=0;d<c.length;d++){let T=c[d];if(!T)continue;e.updateData("currentEnvVar",T),e.updateData("envVarIndex",d),e.setStatus(`Configuring ${T.name}...`);let b=await e.waitForInput("env_var",{varName:T.name});(b||T.required||T.defaultValue)&&(o[T.name]=b||T.defaultValue||"")}let S=[...g].filter(d=>!d.variables.every(T=>y.includes(T.name))).sort((d,T)=>{let b=d.variables.some(C=>C.required),I=T.variables.some(C=>C.required);return b&&!I?-1:!b&&I?1:0});e.updateData("envGroupTotal",S.length);for(let d=0;d<S.length;d++){let T=S[d];if(!T)continue;e.updateData("currentEnvGroup",T),e.updateData("envGroupIndex",d),e.setStatus(`Configuring ${T.name}...`);let b=await e.waitForInput("env_group",{groupName:T.name});for(let[I,C]of Object.entries(b)){let E=T.variables.find(V=>V.name===I);(C||E?.required||E?.defaultValue)&&(o[I]=C||E?.defaultValue||"")}}}async function xr(e,t,o,r,n){e.setStatus("Writing API environment file...");try{let i=St.join(t,"apps","api");xt(i,o),e.setStatus("API environment variables configured!")}catch(i){throw new Error(`Failed to write API .env file: ${i.message}`)}e.setStatus("Writing web environment file...");try{ht(t,r,n),e.setStatus("Web environment variables configured!")}catch(i){throw new Error(`Failed to write web .env file: ${i.message}`)}}import{execa as hr}from"execa";import xe from"fs";import Sr from"simple-git";async function yt(e,t,o){if(xe.existsSync(e)){let r=`${e}/.git`;if(!xe.existsSync(r))throw new Error(`Directory ${e} exists but is not a git repository`);await Sr().cwd(e).pull(),o(100,"Already exists, pulled latest")}else try{let r=hr("git",["clone","--progress",t,e]);r.stderr?.on("data",n=>{let i=n.toString();i.includes("Counting objects")?o(5,"Counting objects"):i.includes("Compressing objects")&&o(10,"Compressing objects");let u=i.match(/Receiving objects:\s+(\d+)%\s+\((\d+)\/(\d+)\)/);if(u?.[1]){let f=Math.min(100,parseInt(u[1],10)),g=u[2],y=u[3];o(10+Math.floor(f*.5),`Receiving objects: ${g}/${y}`)}let m=i.match(/Resolving deltas:\s+(\d+)%\s+\((\d+)\/(\d+)\)/);if(m?.[1]){let f=Math.min(100,parseInt(m[1],10)),g=m[2],y=m[3];o(60+Math.floor(f*.4),`Resolving deltas: ${g}/${y}`)}}),await r,o(100,"Clone complete")}catch(r){throw xe.existsSync(e)&&xe.rmSync(e,{recursive:!0,force:!0}),r}}import{execa as H}from"execa";var U={git:"https://git-scm.com/downloads",docker:"https://docs.docker.com/get-docker/",mise:"https://mise.jdx.dev/getting-started.html"},br={8e3:"API Server",5432:"PostgreSQL",6379:"Redis",27017:"MongoDB",5672:"RabbitMQ",3e3:"Web Frontend",8080:"ChromaDB",8083:"Mongo Express"};async function he(){try{return await H("git",["--version"]),"success"}catch{return"error"}}async function Se(){let e=!1,t=!1,o;try{await H("docker",["--version"]),e=!0}catch{return{name:"Docker",installUrl:U.docker,installed:!1,working:!1,errorMessage:"Docker is not installed"}}try{await H("docker",["info"],{timeout:5e3}),t=!0}catch{o="Docker is installed but the daemon is not running. Please start Docker Desktop or the Docker daemon."}return{name:"Docker",installUrl:U.docker,installed:e,working:t,errorMessage:o}}async function ye(){try{return await H("mise",["--version"]),"success"}catch{return"missing"}}async function be(){if((await import("node:os")).platform()==="win32")try{return await H("powershell",["-Command","irm https://mise.jdx.dev/install.ps1 | iex"]),!0}catch{return!1}try{return await H("sh",["-c","curl https://mise.jdx.dev/install.sh | sh"]),!0}catch{return!1}}async function ve(e){let t=await import("node:net"),o=[],r=n=>new Promise(i=>{let u=t.createServer();u.once("error",()=>i(!1)),u.once("listening",()=>{u.close(()=>i(!0))}),u.listen(n)});for(let n of e){let i=br[n]||`Port ${n}`;if(await r(n))o.push({port:n,service:i,available:!0});else{let m=await vr(n),f=await Tr(n+1,n+100,r);o.push({port:n,service:i,available:!1,usedBy:m,alternative:f||void 0})}}return o}async function vr(e){if((await import("node:os")).platform()==="win32"){try{let{stdout:r}=await H("netstat",["-ano","-p","TCP"]),n=r.trim().split(`
6
- `);for(let i of n)if(i.includes(`:${e}`)&&i.includes("LISTENING")){let u=i.trim().split(/\s+/),m=u[u.length-1];if(m)try{let{stdout:f}=await H("tasklist",["/FI",`PID eq ${m}`,"/FO","CSV","/NH"]);return f.trim().split(",")[0]?.replace(/"/g,"")||`PID ${m}`}catch{return`PID ${m}`}}}catch{}return}try{let{stdout:r}=await H("lsof",["-i",`:${e}`,"-sTCP:LISTEN","-P","-n"]),n=r.trim().split(`
7
- `);if(n.length>1)return n[1]?.split(/\s+/)?.[0]||void 0}catch{}}async function Tr(e,t,o){for(let r=e;r<=t;r++)if(await o(r))return r;return null}import*as X from"fs";import*as W from"path";var Ir=e=>new Promise(t=>setTimeout(t,e)),Cr="dev-start.log";async function vt(e,t,o){if(t==="selfhost"){o?.("Starting all services in Docker (selfhost mode)...");let r=W.join(e,"infra/docker");await O("docker",["compose","-f","docker-compose.prod.yml","--profile","backend","--profile","web","up","-d","--build","--remove-orphans"],r),o?.("All services started in Docker!")}else{o?.("Starting development servers...");let{spawn:r}=await import("child_process"),n=W.join(e,Cr),i=X.openSync(n,"a"),u;try{u=r("mise",["dev"],{cwd:e,stdio:["ignore",i,i],detached:!0,shell:!0}),u.unref()}finally{X.closeSync(i)}if(await Ir(1500),u.pid!=null)try{process.kill(u.pid,0)}catch{throw new Error(`Development servers crashed on startup. Check logs at: ${n}`)}o?.(`Development servers started! Logs: ${n}`)}}async function Tt(e,t,o){let r=W.join(e,"infra/docker"),n=await $e(e);t?.("Stopping Docker services...");try{await O("docker",n==="selfhost"?["compose","-f","docker-compose.prod.yml","down"]:["compose","down"],r)}catch{}t?.("Stopping local processes...");try{let i=o?.[8e3]??8e3,u=o?.[3e3]??3e3;if(process.platform==="win32")for(let m of[i,u])try{await O("powershell",["-Command",`Get-NetTCPConnection -LocalPort ${m} -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue }`],e)}catch{}else for(let m of[i,u])try{await O("sh",["-c",`lsof -ti :${m} -sTCP:LISTEN | xargs kill 2>/dev/null || true`],e)}catch{}}catch{}t?.("All services stopped.")}async function $e(e){let t=W.join(e,"apps","api",".env");if(!X.existsSync(t))return null;let o=X.readFileSync(t,"utf-8"),r=o.match(/^SETUP_MODE=(.+)$/m);if(r?.[1]){let n=r[1].trim().replace(/^["']|["']$/g,"");if(n==="selfhost"||n==="developer")return n}return o.includes("mongodb://mongo:")?"selfhost":(o.includes("mongodb://localhost:"),"developer")}async function O(e,t,o,r,n){let{spawn:i}=await import("child_process");return new Promise((u,m)=>{let f=i(e,t,{cwd:o,stdio:["ignore","pipe","pipe"],shell:!0}),g="",y=0;f.stdout?.on("data",x=>{let c=x.toString();g+=c,n?.(c),y=Math.min(y+5,95),r?.(y)}),f.stderr?.on("data",x=>{let c=x.toString();g+=c,n?.(c),y=Math.min(y+5,95),r?.(y)}),f.on("close",x=>{x===0?(r?.(100),u()):m(new Error(`Command failed with code ${x}: ${g.slice(-500)}`))}),f.on("error",x=>{m(x)})})}function Q(e){let t=e||process.cwd();for(;t!==W.dirname(t);){if(X.existsSync(W.join(t,"apps/api/app/config/settings_validator.py")))return t;t=W.dirname(t)}return null}var Er=process.env.GAIA_CLI_DEV==="true",K=e=>new Promise(t=>setTimeout(t,e));async function It(e){e.setStep("Welcome"),e.setStatus("Waiting for user input..."),await e.waitForInput("welcome");let t=c=>{let S=e.currentState.data.dependencyLogs||[],d=c.split(`
8
- `).filter(b=>b.trim()!==""),T=[...S,...d].slice(-20);e.updateData("dependencyLogs",T)};e.setStep("Prerequisites"),e.setStatus("Checking system requirements..."),e.updateData("checks",{git:"pending",docker:"pending",mise:"pending"}),await K(800),e.setStatus("Checking Git...");let o=await he();e.updateData("checks",{...e.currentState.data.checks,git:o}),e.setStatus("Checking Docker...");let r=await Se(),n=r.working?"success":"error";e.updateData("checks",{...e.currentState.data.checks,docker:n}),r.working||e.updateData("dockerError",r.errorMessage),e.setStatus("Checking Mise...");let i=await ye();e.updateData("checks",{...e.currentState.data.checks,mise:i}),i==="missing"&&(e.setStatus("Installing Mise..."),i=await be()?"success":"error",e.updateData("checks",{...e.currentState.data.checks,mise:i}));let u=[];if(o==="error"&&u.push({name:"Git"}),n==="error"&&u.push({name:"Docker",message:r.errorMessage}),i==="error"&&u.push({name:"Mise"}),u.length>0){let c=[];c.push("Prerequisites failed:");for(let S of u)c.push(` \u2022 ${S.name}: ${S.message||"Not installed or not working"}`);c.push(`
9
- Installation guides:`),o==="error"&&c.push(` \u2022 Git: ${U.git}`),n==="error"&&(r.installed?c.push(" \u2022 Docker: Start Docker Desktop or run 'sudo systemctl start docker'"):c.push(` \u2022 Docker: ${U.docker}`)),i==="error"&&c.push(` \u2022 Mise: ${U.mise}`),e.setError(new Error(c.join(`
10
- `)));return}e.setStatus("Checking Ports...");let f=await ve([8e3,5432,6379,27017,5672,3e3,8080,8083]),g={},y=f.filter(c=>!c.available);if(y.length>0){let c=y.filter(d=>!d.alternative);if(c.length>0){e.setError(new Error(`Cannot find free alternative ports for: ${c.map(d=>`${d.port} (${d.service})`).join(", ")}. Free these ports and try again.`));return}if(e.updateData("portConflicts",f),await e.waitForInput("port_conflicts")==="abort"){e.setError(new Error("Port conflicts not resolved. Please free the ports and try again."));return}for(let d of f)!d.available&&d.alternative&&(g[d.port]=d.alternative)}e.updateData("portOverrides",g),e.setStatus("Prerequisites check complete!"),await K(1e3);let x="";if(Er){if(x=Q()||"",!x){e.setError(new Error("DEV_MODE: Could not find workspace root. Run from within the gaia repo."));return}e.setStep("Repository Setup"),e.setStatus("[DEV MODE] Using current workspace..."),await K(500),e.setStatus("Repository ready!")}else{for(e.setStep("Repository Setup");;){if(x=await e.waitForInput("repo_path",{default:"./gaia"}),ae.existsSync(x)){if(!ae.statSync(x).isDirectory()){e.setError(new Error(`Path ${x} exists and is not a directory.`)),await K(2e3),e.setError(null);continue}if(ae.readdirSync(x).length>0){e.setError(new Error(`Directory ${x} is not empty. Please choose another path.`)),await K(2e3),e.setError(null);continue}}break}e.setStep("Repository Setup"),e.setStatus("Preparing repository..."),e.updateData("repoProgress",0),e.updateData("repoPhase","");try{await yt(x,"https://github.com/theexperiencecompany/gaia.git",(c,S)=>{e.updateData("repoProgress",c),S?(e.updateData("repoPhase",S),e.setStatus(`${S}...`)):e.setStatus(`Cloning repository to ${x}... ${c}%`)}),e.setStatus("Repository ready!")}catch(c){e.setError(c);return}}await K(1e3),e.setStep("Install Tools"),e.setStatus("Installing toolchain..."),e.updateData("dependencyPhase","Initializing mise..."),e.updateData("dependencyProgress",0),e.updateData("dependencyLogs",[]);try{e.updateData("dependencyPhase","Trusting mise configuration..."),await O("mise",["trust"],x,void 0,t),e.updateData("dependencyProgress",50),e.updateData("dependencyPhase","Installing tools (node, python, uv, nx)..."),await O("mise",["install"],x,c=>{e.updateData("dependencyProgress",50+c*.5)},t),e.updateData("dependencyProgress",100),e.updateData("toolComplete",!0)}catch(c){e.setError(new Error(`Failed to install tools: ${c.message}`));return}if(await K(1e3),await ge(e,x,g),!e.currentState.error){e.setStep("Project Setup"),e.updateData("dependencyPhase","Setting up project..."),e.updateData("dependencyProgress",0),e.updateData("dependencyComplete",!1),e.updateData("repoPath",x),e.updateData("dependencyLogs",[]);try{e.updateData("dependencyProgress",0),e.updateData("dependencyPhase","Running mise setup (all dependencies)..."),await O("mise",["setup"],x,c=>{e.updateData("dependencyProgress",c)},t),e.updateData("dependencyProgress",100),e.updateData("dependencyPhase","Setup complete!"),e.updateData("dependencyComplete",!0)}catch(c){e.setError(new Error(`Failed to setup project: ${c.message}`));return}await K(1e3),e.setStep("Finished"),e.setStatus("Setup complete!")}}async function Ct(){let e=j(),{unmount:t}=wr(Dr.createElement($,{store:e,command:"init"}));try{await It(e)}catch(o){e.setError(o)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as Pr}from"ink";import Rr from"react";var Te=e=>new Promise(t=>setTimeout(t,e));async function Et(e){e.setStep("Detect Repo"),e.setStatus("Looking for GAIA repository...");let t=Q();if(!t){e.setError(new Error("Could not find GAIA repository. Run this command from within a cloned gaia repo, or use 'gaia init' to set up from scratch."));return}e.updateData("repoPath",t),e.setStatus(`Found repository at ${t}`),await Te(1e3),e.setStep("Prerequisites"),e.setStatus("Checking system requirements..."),e.updateData("checks",{git:"pending",docker:"pending",mise:"pending"}),await Te(500);let o=await he();e.updateData("checks",{...e.currentState.data.checks,git:o});let r=await Se(),n=r.working?"success":"error";e.updateData("checks",{...e.currentState.data.checks,docker:n}),r.working||e.updateData("dockerError",r.errorMessage);let i=await ye();e.updateData("checks",{...e.currentState.data.checks,mise:i}),i==="missing"&&(e.setStatus("Installing Mise..."),i=await be()?"success":"error",e.updateData("checks",{...e.currentState.data.checks,mise:i}));let u=[];if(o==="error"&&u.push({name:"Git"}),n==="error"&&u.push({name:"Docker",message:r.errorMessage}),i==="error"&&u.push({name:"Mise"}),u.length>0){let c=[];c.push("Prerequisites failed:");for(let S of u)c.push(` \u2022 ${S.name}: ${S.message||"Not installed or not working"}`);c.push(`
11
- Installation guides:`),o==="error"&&c.push(` \u2022 Git: ${U.git}`),n==="error"&&(r.installed?c.push(" \u2022 Docker: Start Docker Desktop or run 'sudo systemctl start docker'"):c.push(` \u2022 Docker: ${U.docker}`)),i==="error"&&c.push(` \u2022 Mise: ${U.mise}`),e.setError(new Error(c.join(`
12
- `)));return}e.setStatus("Checking Ports...");let f=await ve([8e3,5432,6379,27017,5672,3e3,8080,8083]),g={},y=f.filter(c=>!c.available);if(y.length>0){let c=y.filter(d=>!d.alternative);if(c.length>0){e.setError(new Error(`Cannot find free alternative ports for: ${c.map(d=>`${d.port} (${d.service})`).join(", ")}. Free these ports and try again.`));return}if(e.updateData("portConflicts",f),await e.waitForInput("port_conflicts")==="abort"){e.setError(new Error("Port conflicts not resolved. Please free the ports and try again."));return}for(let d of f)!d.available&&d.alternative&&(g[d.port]=d.alternative)}if(e.updateData("portOverrides",g),e.setStatus("Prerequisites check complete!"),await Te(1e3),await ge(e,t,g),e.currentState.error)return;e.setStep("Project Setup"),e.updateData("dependencyPhase","Setting up project..."),e.updateData("dependencyProgress",0),e.updateData("dependencyComplete",!1),e.updateData("dependencyLogs",[]);let x=c=>{let S=e.currentState.data.dependencyLogs||[],d=c.split(`
13
- `).filter(b=>b.trim()!==""),T=[...S,...d].slice(-20);e.updateData("dependencyLogs",T)};try{e.updateData("dependencyPhase","Trusting mise configuration..."),await O("mise",["trust"],t,void 0,x),e.updateData("dependencyProgress",20),e.updateData("dependencyPhase","Installing tools..."),await O("mise",["install"],t,c=>{e.updateData("dependencyProgress",20+c*.3)},x),e.updateData("dependencyPhase","Running mise setup..."),await O("mise",["setup"],t,c=>{e.updateData("dependencyProgress",50+c*.5)},x),e.updateData("dependencyProgress",100),e.updateData("dependencyPhase","Setup complete!"),e.updateData("dependencyComplete",!0)}catch(c){e.setError(new Error(`Failed to setup project: ${c.message}`));return}await Te(1e3),e.setStep("Finished"),e.setStatus("Setup complete!")}async function wt(){let e=j(),{unmount:t}=Pr(Rr.createElement($,{store:e,command:"setup"}));try{await Et(e)}catch(o){e.setError(o)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as kr}from"ink";import Br from"react";async function Dt(e){e.setStep("Starting"),e.setStatus("Locating GAIA repository...");let t=Q();if(!t){e.setError(new Error("Could not find GAIA repository. Run from within a cloned gaia repo."));return}e.updateData("repoPath",t);let o=await $e(t);if(!o){e.setError(new Error("No .env file found. Run 'gaia setup' first to configure the environment."));return}e.updateData("setupMode",o),e.setStatus(`Starting GAIA in ${o} mode...`);try{await vt(t,o,r=>{e.setStatus(r)}),e.setStep("Running"),e.setStatus("GAIA is running!"),e.updateData("started",!0)}catch(r){e.setError(new Error(`Failed to start services: ${r.message}`));return}await e.waitForInput("exit")}async function Pt(){let e=j(),{unmount:t}=kr(Br.createElement($,{store:e,command:"start"}));await new Promise(o=>setTimeout(o,50));try{await Dt(e)}catch(o){e.setError(o)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as Fr}from"ink";import Nr from"react";import{execa as Ue}from"execa";var je=["gaia-backend","gaia-web","chromadb","postgres","redis","mongo","rabbitmq","arq_worker"];async function Rt(){try{let{stdout:e}=await Ue("docker",["inspect","--format","{{.Name}}|{{.State.Status}}|{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}",...je]),t=new Map;for(let o of e.trim().split(`
14
- `)){if(!o)continue;let[r,n,i]=o.split("|"),u=r?.replace(/^\//,"")??"";t.set(u,{name:u,status:n==="running"?"running":"stopped",health:i!=="none"?i:void 0})}return je.map(o=>t.get(o)??{name:o,status:"not_found"})}catch{let e=je.map(async t=>{try{let{stdout:o}=await Ue("docker",["inspect","--format","{{.State.Status}}|{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}",t]),[r,n]=o.trim().split("|");return{name:t,status:r==="running"?"running":"stopped",health:n!=="none"?n:void 0}}catch{return{name:t,status:"not_found"}}});return Promise.all(e)}}async function kt(){try{return await Ue("docker",["info"]),!0}catch{return!1}}var Ar=[{name:"API",port:8e3,type:"http",path:"/health"},{name:"Web",port:3e3,type:"http",path:"/"},{name:"PostgreSQL",port:5432,type:"tcp"},{name:"Redis",port:6379,type:"tcp"},{name:"MongoDB",port:27017,type:"tcp"},{name:"RabbitMQ",port:5672,type:"tcp"},{name:"ChromaDB",port:8080,type:"tcp"}];async function Bt(e){let o=Ar.map(r=>({...r,port:e?.[r.port]??r.port})).map(r=>r.type==="http"?_r(r.name,r.port,r.path):Lr(r.name,r.port));return Promise.all(o)}async function _r(e,t,o){let r=Date.now();try{let n=await fetch(`http://localhost:${t}${o}`,{signal:AbortSignal.timeout(5e3)}),i=Date.now()-r;return{name:e,port:t,status:"up",latency:i,details:n.ok?`HTTP ${n.status}`:`HTTP ${n.status} (error)`}}catch{return{name:e,port:t,status:"down",details:"Connection failed"}}}async function Lr(e,t){let o=await import("node:net"),r=Date.now();return new Promise(n=>{let i=new o.Socket;i.setTimeout(3e3),i.on("connect",()=>{let u=Date.now()-r;i.destroy(),n({name:e,port:t,status:"up",latency:u})}),i.on("timeout",()=>{i.destroy(),n({name:e,port:t,status:"down"})}),i.on("error",()=>{i.destroy(),n({name:e,port:t,status:"down"})}),i.connect(t,"localhost")})}async function At(){return await kt()?{running:!0,containers:await Rt()}:{running:!1,containers:[]}}async function Mr(e){e.setStep("Checking"),e.setStatus("Checking service health..."),e.updateData("refreshable",!1);let[t,o]=await Promise.all([Bt(),At()]);e.updateData("services",t),e.updateData("docker",o);let r=t.filter(i=>i.status==="up").length,n=t.length;e.setStep("Results"),e.setStatus(`${r}/${n} services running`),e.updateData("refreshable",!0)}async function _t(e){for(;await Mr(e),await e.waitForInput("exit_or_refresh")==="refresh";);}async function Lt(){let e=j(),{unmount:t}=Fr(Nr.createElement($,{store:e,command:"status"}));await new Promise(o=>setTimeout(o,50));try{await _t(e)}catch(o){e.setError(o)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as Gr}from"ink";import qr from"react";async function Mt(e){e.setStep("Stopping"),e.setStatus("Locating GAIA repository...");let t=Q();if(!t){e.setError(new Error("Could not find GAIA repository. Run from within a cloned gaia repo."));return}e.updateData("repoPath",t);try{await Tt(t,o=>{e.setStatus(o)}),e.setStep("Stopped"),e.setStatus("All services stopped."),e.updateData("stopped",!0)}catch(o){e.setError(new Error(`Failed to stop services: ${o.message}`));return}await e.waitForInput("exit")}async function Ft(){let e=j(),{unmount:t}=Gr(qr.createElement($,{store:e,command:"stop"}));await new Promise(o=>setTimeout(o,50));try{await Mt(e)}catch(o){e.setError(o)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}var J=new Or;J.name("gaia").description("CLI tool for setting up and managing GAIA").version("0.1.0");J.command("init").description("Full setup from scratch (clone, configure, start)").action(async()=>{await Ct()});J.command("setup").description("Configure an existing GAIA repository").action(async()=>{await wt()});J.command("status").description("Check health of all GAIA services").action(async()=>{await Lt()});J.command("start").description("Start GAIA services").action(async()=>{await Pt()});J.command("stop").description("Stop all GAIA services").action(async()=>{await Ft()});process.argv.slice(2).length||(J.outputHelp(),process.exit(0));J.parse();
2
+ import{Command as Wr}from"commander";import{render as Ar}from"ink";import _r from"react";import{Box as xe,Text as Z}from"ink";import pr from"react";import{ProgressBar as ze,Select as Ze,Spinner as et}from"@inkjs/ui";import{Box as p,Text as s,useInput as z}from"ink";import le from"ink-text-input";import{useEffect as ge,useState as L}from"react";import{Box as ce,Text as Ke}from"ink";var h="#00bbff";import{Box as Ht,Text as we}from"ink";import{jsx as Xe,jsxs as Qe}from"react/jsx-runtime";var Ye=({status:e,step:t})=>t.toLowerCase()==="welcome"?null:Qe(Ht,{width:"100%",borderStyle:"single",borderColor:"gray",paddingX:1,justifyContent:"space-between",children:[Qe(we,{color:h,children:[Xe(we,{bold:!0,children:"Status:"})," ",t]}),Xe(we,{color:"white",dimColor:!0,children:e})]});import{Box as Vt}from"ink";import Ut from"ink-big-text";import Wt from"ink-gradient";import{jsx as Pe}from"react/jsx-runtime";var te=()=>Pe(Vt,{flexDirection:"column",marginTop:1,marginBottom:1,children:Pe(Wt,{colors:[h,"#b0eaff",h],children:Pe(Ut,{text:"GAIA",font:"3d"})})});import{jsx as re,jsxs as me}from"react/jsx-runtime";var Xt=["Welcome","Prerequisites","Repository Setup","Install Tools","Environment Setup","Project Setup","Finished"],Je=["Detect Repo","Prerequisites","Environment Setup","Project Setup","Finished"],Qt=({currentStep:e,steps:t})=>{let o=t.indexOf(e);return re(ce,{marginBottom:1,children:t.map((r,n)=>{let i=r===e,c=o>n;return me(ce,{marginRight:2,children:[me(Ke,{color:i?h:c?"green":"gray",children:[c?"\u2713 ":i?"\u25CF ":"\u25CB ",r]}),n<t.length-1&&re(Ke,{color:"gray",children:" \u203A "})]},r)})})},fe=({children:e,status:t,step:o,steps:r=Xt})=>me(ce,{flexDirection:"column",height:"100%",width:"100%",children:[me(ce,{flexGrow:1,flexDirection:"column",children:[re(te,{}),re(Qt,{currentStep:o,steps:r}),re(ce,{flexDirection:"column",flexGrow:1,children:e})]}),re(Ye,{status:t,step:o})]});import{Fragment as So,jsx as a,jsxs as u}from"react/jsx-runtime";var Re=({label:e,status:t})=>u(p,{children:[a(p,{marginRight:1,children:t==="pending"?a(et,{type:"dots"}):t==="success"?a(s,{color:h,children:"\u2714"}):t==="error"?a(s,{color:"red",children:"\u2716"}):a(s,{color:"yellow",children:"\u26A0"})}),a(s,{children:e})]}),Yt=({onConfirm:e})=>(z((t,o)=>{o.return&&e()}),u(p,{flexDirection:"column",paddingX:2,borderStyle:"round",borderColor:h,children:[a(s,{bold:!0,children:"Welcome to the Interactive GAIA Setup"}),u(p,{flexDirection:"column",marginTop:1,marginBottom:1,children:[a(s,{children:"This wizard will guide you through the setup process:"}),a(s,{children:" 1. Check Prerequisites (Git, Docker, Mise)"}),a(s,{children:" 2. Clone Repository (from GitHub)"}),a(s,{children:" 3. Install Tools (node, python, uv via mise)"}),a(s,{children:" 4. Configure Env Vars (databases, API keys, etc.)"}),a(s,{children:" 5. Setup Project (install all dependencies)"})]}),a(s,{color:h,children:"Press Enter to start..."})]})),Kt=({portResults:e,onAccept:t,onAbort:o})=>{z((n,i)=>{i.return?t():i.escape&&o()});let r=e.filter(n=>!n.available);return u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:"yellow",children:[a(p,{marginBottom:1,children:a(s,{bold:!0,color:"yellow",children:"Port Conflicts Detected"})}),e.map(n=>u(p,{children:[u(s,{color:n.available?"green":n.alternative?"yellow":"red",children:[n.available?"\u2714":n.alternative?"\u26A0":"\u2716"," "]}),u(s,{children:[n.service," (:",n.port,")"]}),!n.available&&u(s,{color:n.alternative?"gray":"red",children:[" ","- in use",n.usedBy?` by ${n.usedBy}`:"",n.alternative?` \u2192 will use :${n.alternative}`:" \u2014 NO ALTERNATIVE FOUND"]})]},n.port)),u(p,{marginTop:1,flexDirection:"column",children:[r.some(n=>!n.alternative)&&a(p,{borderStyle:"single",borderColor:"red",paddingX:1,marginBottom:1,children:a(s,{color:"red",children:"Some ports have no available alternative. Free them and retry."})}),!r.some(n=>!n.alternative)&&r.some(n=>n.alternative)&&a(s,{color:"gray",children:"Alternative ports will be used for conflicting services."}),a(p,{marginTop:1,children:u(s,{children:[a(s,{color:"green",bold:!0,children:"Enter"})," to continue with alternatives ",a(s,{color:"yellow",bold:!0,children:"Escape"})," to abort"]})})]})]})},Jt=({defaultValue:e,onSubmit:t})=>{let[o,r]=L(e);return u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[a(s,{children:"Where should we clone the repository?"}),u(p,{children:[a(s,{color:h,children:"\u279C "}),a(le,{value:o,onChange:r,onSubmit:t})]}),u(s,{color:"gray",children:["(Press Enter for default: ",e,")"]})]})},zt=({setupMode:e,repoPath:t,portOverrides:o,onConfirm:r})=>{z((m,g)=>{g.return&&r()});let n=e||"developer",i=t||"./gaia",c=o?.[3e3]??3e3,d=o?.[8e3]??8e3;return u(p,{flexDirection:"column",marginTop:2,borderStyle:"round",borderColor:h,padding:1,children:[a(s,{color:h,bold:!0,children:"You are all set!"}),u(p,{marginTop:1,flexDirection:"column",children:[a(s,{bold:!0,children:"To start GAIA, run:"}),u(p,{marginTop:1,padding:1,borderStyle:"single",borderColor:"gray",flexDirection:"column",children:[u(s,{color:"cyan",children:["$ cd ",i]}),a(s,{color:"cyan",children:"$ gaia start"})]}),a(p,{marginTop:1,children:a(s,{color:"gray",dimColor:!0,children:n==="selfhost"?"Runs: docker compose --profile all up -d (background)":"Runs: mise dev (interactive \u2014 keep terminal open)"})})]}),u(p,{marginTop:1,flexDirection:"column",children:[a(s,{bold:!0,children:"Access GAIA at:"}),u(p,{marginLeft:2,flexDirection:"column",children:[u(s,{children:["Web:"," ",u(s,{color:"cyan",bold:!0,children:["http://localhost:",c]})]}),u(s,{children:["API:"," ",u(s,{color:"cyan",bold:!0,children:["http://localhost:",d]})]})]})]}),a(De,{}),a(p,{marginTop:1,children:a(s,{dimColor:!0,children:"Press Enter to exit"})})]})},De=()=>u(p,{marginTop:1,flexDirection:"column",children:[a(s,{bold:!0,children:"Available commands:"}),u(p,{marginLeft:2,flexDirection:"column",children:[u(s,{children:[u(s,{color:h,bold:!0,children:["gaia start"," "]}),a(s,{color:"gray",children:" Start all services"})]}),u(s,{children:[u(s,{color:h,bold:!0,children:["gaia stop"," "]}),a(s,{color:"gray",children:" Stop all services"})]}),u(s,{children:[a(s,{color:h,bold:!0,children:"gaia status"}),a(s,{color:"gray",children:" Check service health"})]}),u(s,{children:[u(s,{color:h,bold:!0,children:["gaia setup"," "]}),a(s,{color:"gray",children:" Reconfigure environment"})]})]})]}),Zt=({phase:e,progress:t,isComplete:o,logs:r,title:n})=>u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[a(p,{marginBottom:1,children:a(s,{bold:!0,color:h,children:n||"Installing Dependencies"})}),u(p,{flexDirection:"column",gap:1,children:[a(p,{children:o?u(s,{color:"green",children:["\u2713 ",e]}):a(et,{label:e||"Preparing..."})}),!o&&t>0&&a(p,{width:50,children:a(ze,{value:t})}),!o&&r&&r.length>0&&a(p,{flexDirection:"column",marginTop:1,borderStyle:"single",borderColor:"gray",paddingX:1,paddingY:0,minHeight:6,children:r.map((i,c)=>a(s,{color:"gray",wrap:"truncate",children:i},c))})]})]});var ke=({onSelect:e})=>u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[a(s,{bold:!0,children:"Setup Mode"}),a(p,{marginTop:1,children:a(s,{color:"gray",children:"How do you want to run GAIA?"})}),a(p,{marginTop:1,children:a(Ze,{options:[{label:"Self-Host (Docker)",value:"selfhost"},{label:"Developer Mode (Local)",value:"developer"}],onChange:o=>e(o)})}),u(p,{marginTop:1,flexDirection:"column",children:[a(s,{color:"gray",dimColor:!0,children:"Self-Host: Run everything in Docker containers (recommended for deployment)"}),a(s,{color:"gray",dimColor:!0,children:"Developer: Run backend locally with Docker services (recommended for contributing)"})]})]}),Be=({onSelect:e})=>u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[a(s,{bold:!0,children:"Environment Variables Setup"}),a(p,{marginTop:1,children:a(s,{color:"gray",children:"Choose how you want to configure environment variables:"})}),a(p,{marginTop:1,children:a(Ze,{options:[{label:"Manual Setup (Recommended)",value:"manual"},{label:"Infisical (Advanced)",value:"infisical"}],onChange:o=>e(o)})}),u(p,{marginTop:1,flexDirection:"column",children:[a(s,{color:"gray",dimColor:!0,children:"Manual Setup: Configure variables interactively (recommended for most users)"}),a(s,{color:"gray",dimColor:!0,children:"Infisical: All secrets managed in Infisical dashboard (requires pre-configuration)"})]})]}),Ae=({onSubmit:e})=>{let[t,o]=L({INFISICAL_TOKEN:"",INFISICAL_PROJECT_ID:"",INFISICAL_MACHINE_IDENTITY_CLIENT_ID:"",INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET:""}),[r,n]=L(0),[i,c]=L(null),d=[{key:"INFISICAL_TOKEN",description:"Service token from project settings (st.xxx...)"},{key:"INFISICAL_PROJECT_ID",description:"Found in your Infisical project settings"},{key:"INFISICAL_MACHINE_IDENTITY_CLIENT_ID",description:"From Access Control \u2192 Machine Identities"},{key:"INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET",description:"Generated when creating the machine identity"}];z((g,v)=>{if(v.tab||v.downArrow)n(x=>x<d.length-1?x+1:x);else if(v.upArrow)n(x=>x>0?x-1:x);else if(v.return){if(r<d.length-1){n(l=>l+1);return}let x=d.filter(l=>!t[l.key].trim());if(x.length>0){c(`Required: ${x.map(S=>S.key).join(", ")}`);let l=d.findIndex(S=>!t[S.key].trim());l>=0&&n(l);return}e(t)}});let m=d[r];return u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[a(p,{marginBottom:1,children:a(s,{bold:!0,color:h,children:"Infisical Configuration"})}),a(p,{marginBottom:1,borderStyle:"single",borderColor:"cyan",paddingX:1,children:a(s,{color:"cyan",children:"All environment variables (API keys, auth secrets, etc.) must be configured in your Infisical project. Only Infisical credentials will be stored locally."})}),u(p,{marginBottom:1,flexDirection:"column",children:[a(s,{color:"gray",children:"Configure your Infisical credentials."}),u(s,{color:"gray",dimColor:!0,children:["Visit"," ",a(s,{color:"cyan",underline:!0,children:"app.infisical.com"})," ","to get these values."]})]}),d.map((g,v)=>{let x=g.key.includes("SECRET")||g.key.includes("TOKEN");return u(p,{flexDirection:"column",marginBottom:1,children:[a(p,{children:u(s,{color:v===r?h:"white",children:[v===r?"\u25B8 ":" ",g.key,":"]})}),a(p,{marginLeft:2,children:a(s,{color:"gray",dimColor:!0,children:g.description})}),v===r?a(p,{marginLeft:2,children:a(le,{value:t[g.key],onChange:l=>{o(S=>({...S,[g.key]:l})),c(null)},placeholder:"Enter value...",mask:x?"*":void 0})}):a(p,{marginLeft:2,children:a(s,{color:t[g.key]?"green":"gray",children:t[g.key]?x?`\u2713 ${"*".repeat(8)}`:`\u2713 ${t[g.key]}`:"(not set)"})})]},g.key)}),i&&a(p,{marginTop:1,children:a(s,{color:"red",children:i})}),a(p,{marginTop:1,children:a(s,{color:"gray",dimColor:!0,children:"\u2191\u2193/Tab to navigate \u2022 Enter to confirm"})})]})},_e=({category:e,currentIndex:t,totalGroups:o,onSubmit:r})=>{let[n,i]=L(()=>{let l={};for(let S of e.variables)l[S.name]=S.defaultValue||"";return l}),[c,d]=L(0),[m,g]=L(null);ge(()=>{let l={};for(let S of e.variables)l[S.name]=S.defaultValue||"";i(l),d(0),g(null)},[e.name]),z((l,S)=>{if(S.tab||S.downArrow)d(f=>f<e.variables.length-1?f+1:f);else if(S.upArrow)d(f=>f>0?f-1:f);else if(S.escape){let f=e.variables.filter(b=>b.required&&!n[b.name]?.trim());if(f.length>0){g(`Required fields cannot be skipped: ${f.map(b=>b.name).join(", ")}`);return}r(n)}});let v=()=>{if(c<e.variables.length-1)d(c+1);else{let l=e.variables.filter(S=>S.required&&!n[S.name]?.trim());if(l.length>0){g(`Required fields are missing: ${l.map(S=>S.name).join(", ")}`);return}g(null),r(n)}},x=e.variables.some(l=>l.required);return u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:m?"red":h,children:[u(p,{justifyContent:"space-between",children:[u(s,{bold:!0,children:["Configure ",e.name]}),u(s,{color:"gray",children:["Group ",t+1," / ",o]})]}),u(p,{marginTop:1,flexDirection:"column",children:[u(p,{children:[u(s,{color:"cyan",bold:!0,children:["Purpose:"," "]}),a(s,{color:"white",children:e.description})]}),e.affectedFeatures&&u(p,{children:[u(s,{color:"cyan",bold:!0,children:["Affects:"," "]}),a(s,{color:"gray",children:e.affectedFeatures})]}),e.docsUrl&&u(p,{marginTop:1,children:[a(s,{color:"green",children:"\u{1F4D6} Docs: "}),a(s,{color:"blue",underline:!0,children:e.docsUrl})]})]}),a(p,{marginTop:1,flexDirection:"column",children:e.variables.map((l,S)=>{let f=S===c,b=!!l.defaultValue;return u(p,{flexDirection:"column",marginBottom:1,children:[u(p,{children:[u(s,{color:f?h:"gray",bold:f,children:[f?"\u279C ":" ",l.name]}),l.required&&u(s,{color:"red",bold:!0,children:[" ","*"]}),b&&!f&&u(s,{color:"gray",dimColor:!0,children:[" ","(default: ",l.defaultValue,")"]})]}),f&&a(p,{marginLeft:2,children:a(le,{value:n[l.name]||"",onChange:y=>{i(C=>({...C,[l.name]:y})),m&&g(null)},onSubmit:v,placeholder:b?`Default: ${l.defaultValue}`:l.required?"Enter a value (required)":"Press Enter to skip"})})]},l.name)})}),m&&a(p,{marginTop:1,children:u(s,{color:"red",bold:!0,children:["\u26A0 ",m]})}),a(p,{marginTop:1,flexDirection:"column",children:u(s,{color:"gray",dimColor:!0,children:["\u21B5 Enter to next field \u2022 Tab/\u2193 move down \u2022 \u2191 move up",!x&&" \u2022 ESC skip group"]})})]})},Me=({alternatives:e,onSubmit:t})=>{let[o,r]=L(new Set),[n,i]=L({}),[c,d]=L(0),[m,g]=L(null);ge(()=>{let y={};for(let C of e)for(let I of C.variables)y[I.name]=I.defaultValue||"";i(y)},[e]);let v=[];for(let y=0;y<e.length;y++)if(v.push({type:"provider",categoryIndex:y}),o.has(y)){let C=e[y];if(C)for(let I=0;I<C.variables.length;I++)v.push({type:"field",categoryIndex:y,fieldIndex:I})}v.push({type:"submit"});let x=v[c],l=x?.type==="field",S=x?.type==="submit";z((y,C)=>{let I=Math.min(c,v.length-1);if(I!==c){d(I);return}if(l)C.upArrow?d(E=>Math.max(0,E-1)):(C.downArrow||C.tab)&&d(E=>Math.min(v.length-1,E+1));else if(S)C.upArrow?d(E=>Math.max(0,E-1)):(C.return||y===" ")&&b();else if(C.upArrow)d(E=>Math.max(0,E-1));else if(C.downArrow||C.tab)d(E=>Math.min(v.length-1,E+1));else if((C.return||y===" ")&&x?.type==="provider"){let E=x.categoryIndex;r(Q=>{let D=new Set(Q);return D.has(E)?D.delete(E):D.add(E),D}),m&&g(null)}});let f=()=>{m&&g(null),d(y=>Math.min(v.length-1,y+1))},b=()=>{let y=[],C={};for(let I of o){let E=e[I];if(!E)continue;if(E.variables.some(D=>n[D.name]?.trim())){y.push(E.name);for(let D of E.variables){let de=n[D.name];de&&(C[D.name]=de)}}}if(y.length===0){o.size===0?g("Enable at least one provider (press Space or Enter)"):g("Enter a value for at least one field");return}t(y,C)};return u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:m?"red":h,children:[u(p,{justifyContent:"space-between",children:[a(s,{bold:!0,children:"Configure AI Provider"}),a(s,{color:"yellow",children:"* At least one required"})]}),a(p,{marginTop:1,children:a(s,{color:"gray",children:"Enable and configure at least one AI provider below:"})}),a(p,{marginTop:1,flexDirection:"column",children:e.map((y,C)=>{let I=o.has(C),E=v.findIndex(D=>D.type==="provider"&&D.categoryIndex===C),Q=c===E;return u(p,{flexDirection:"column",marginBottom:1,children:[u(p,{children:[a(s,{color:Q?h:void 0,bold:Q,children:Q?"\u279C ":" "}),a(s,{color:I?"green":"gray",children:I?"[\u2714]":"[ ]"}),u(s,{color:I?h:"gray",bold:I,children:[" ",y.name]}),y.description&&u(s,{color:"gray",dimColor:!0,children:[" ","- ",y.description]})]}),Q&&y.docsUrl&&u(p,{marginLeft:6,children:[a(s,{color:"yellow",children:"\u{1F4D6} "}),a(s,{color:"blue",underline:!0,children:y.docsUrl})]}),I&&a(p,{marginLeft:4,flexDirection:"column",marginTop:1,children:y.variables.map((D,de)=>{let qt=v.findIndex(se=>se.type==="field"&&se.categoryIndex===C&&se.fieldIndex===de),ee=c===qt,We=!!D.defaultValue,Ee=n[D.name]||"";return u(p,{flexDirection:"column",marginBottom:1,children:[u(p,{children:[u(s,{color:ee?h:"gray",bold:ee,children:[ee?" \u279C ":" ",D.name]}),!ee&&Ee&&a(s,{color:"green",children:" \u2713"}),!ee&&!Ee&&We&&u(s,{color:"gray",dimColor:!0,children:[" ","(default: ",D.defaultValue,")"]})]}),ee&&a(p,{marginLeft:4,children:a(le,{value:Ee,onChange:se=>{i(jt=>({...jt,[D.name]:se})),m&&g(null)},onSubmit:f,placeholder:We?`Default: ${D.defaultValue}`:"Enter value..."})})]},D.name)})})]},y.name)})}),m&&a(p,{marginTop:1,children:u(s,{color:"red",bold:!0,children:["\u26A0 ",m]})}),u(p,{marginTop:1,children:[a(s,{color:S?h:void 0,bold:S,children:S?"\u279C ":" "}),a(p,{borderStyle:"round",borderColor:S?h:"gray",paddingX:2,children:a(s,{color:S?h:"gray",bold:S,children:"Continue \u2192"})})]}),a(p,{marginTop:1,children:a(s,{color:"gray",dimColor:!0,children:"\u2191/\u2193 navigate \u2022 Space/Enter toggle/select \u2022 Tab skip field"})})]})},Le=({currentVar:e,currentIndex:t,totalCount:o,onSubmit:r,onSkip:n})=>{let[i,c]=L(e.defaultValue||""),[d,m]=L(null);ge(()=>{c(e.defaultValue||""),m(null)},[e.name]),z((x,l)=>{if(l.escape){if(e.required&&!i.trim()){m("This field is required and cannot be skipped");return}n()}});let g=x=>{if(e.required&&!x.trim()){m("This field is required");return}m(null),r(x)},v=!!e.defaultValue;return u(p,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:d?"red":h,children:[u(p,{justifyContent:"space-between",children:[a(s,{bold:!0,children:"Configure Environment Variables"}),u(s,{color:"gray",children:[t+1," / ",o]})]}),u(p,{marginTop:1,flexDirection:"column",children:[u(p,{children:[a(s,{color:h,bold:!0,children:e.name}),e.required?u(s,{color:"red",bold:!0,children:[" ","* required"]}):u(s,{color:"gray",dimColor:!0,children:[" ","(optional)"]})]}),u(p,{marginTop:1,children:[u(s,{color:"cyan",bold:!0,children:["Category:"," "]}),a(s,{color:"white",children:e.category})]}),u(p,{children:[u(s,{color:"cyan",bold:!0,children:["Purpose:"," "]}),a(s,{color:"white",children:e.description})]}),e.affectedFeatures&&u(p,{children:[u(s,{color:"cyan",bold:!0,children:["Affects:"," "]}),a(s,{color:"gray",children:e.affectedFeatures})]}),e.docsUrl&&u(p,{marginTop:1,children:[a(s,{color:"green",children:"\u{1F4D6} Docs: "}),a(s,{color:"blue",underline:!0,children:e.docsUrl})]}),v&&u(p,{marginTop:1,children:[u(s,{color:"green",bold:!0,children:["Default:"," "]}),a(s,{color:"white",children:e.defaultValue})]})]}),u(p,{marginTop:1,children:[a(s,{color:h,children:"\u279C "}),a(le,{value:i,onChange:x=>{c(x),d&&m(null)},onSubmit:g,placeholder:v?"Press Enter to use default":e.required?"Enter a value (required)":"Press Enter to skip"})]}),d&&a(p,{marginTop:1,children:u(s,{color:"red",bold:!0,children:["\u26A0 ",d]})}),a(p,{marginTop:1,flexDirection:"column",children:e.required?a(s,{color:"yellow",dimColor:!0,children:"\u21B5 Enter to confirm (required field)"}):v?a(s,{color:"green",dimColor:!0,children:"\u21B5 Enter to use default \u2022 ESC to skip"}):a(s,{color:"gray",dimColor:!0,children:"\u21B5 Enter to confirm \u2022 ESC to skip"})})]})},tt=({store:e})=>{let[t,o]=L(e.currentState);return ge(()=>{let r=()=>o({...e.currentState});return e.on("change",r),()=>{e.off("change",r)}},[e]),u(fe,{status:t.status,step:t.step,children:[t.step==="Welcome"&&t.inputRequest?.id==="welcome"&&a(Yt,{onConfirm:()=>e.submitInput(!0)}),t.step==="Prerequisites"&&t.data.checks&&u(p,{flexDirection:"column",borderStyle:"round",paddingX:1,borderColor:h,children:[a(s,{bold:!0,children:"System Checks"}),u(p,{flexDirection:"column",marginTop:1,children:[a(Re,{label:"Git",status:t.data.checks.git}),a(Re,{label:"Docker",status:t.data.checks.docker}),a(Re,{label:"Mise",status:t.data.checks.mise})]})]}),t.inputRequest?.id==="port_conflicts"&&t.data.portConflicts&&a(Kt,{portResults:t.data.portConflicts,onAccept:()=>e.submitInput("accept"),onAbort:()=>e.submitInput("abort")}),t.inputRequest?.id==="repo_path"&&a(Jt,{defaultValue:t.inputRequest.meta.default,onSubmit:r=>e.submitInput(r)}),t.step==="Repository Setup"&&u(p,{flexDirection:"column",borderStyle:"round",padding:1,borderColor:h,children:[a(s,{bold:!0,children:"Cloning Repository"}),u(p,{marginTop:1,flexDirection:"column",children:[a(ze,{value:t.data.repoProgress||0}),t.data.repoPhase&&a(p,{marginTop:1,children:a(s,{color:"gray",children:t.data.repoPhase})})]})]}),t.inputRequest?.id==="setup_mode"&&a(ke,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_method"&&a(Be,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_infisical"&&a(Ae,{onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_var"&&t.data.currentEnvVar&&a(Le,{categories:t.data.envCategories||[],currentVar:t.data.currentEnvVar,currentIndex:t.data.envVarIndex||0,totalCount:t.data.envVarTotal||0,onSubmit:r=>e.submitInput(r),onSkip:()=>e.submitInput("")}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_group"&&t.data.currentEnvGroup&&a(_e,{category:t.data.currentEnvGroup,currentIndex:t.data.envGroupIndex||0,totalGroups:t.data.envGroupTotal||0,onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_alternatives"&&t.data.alternativeGroups&&a(Me,{alternatives:t.data.alternativeGroups,onSubmit:(r,n)=>e.submitInput({selectedGroups:r,values:n})}),t.step==="Finished"&&a(zt,{setupMode:t.data.setupMode,repoPath:t.data.repoPath,portOverrides:t.data.portOverrides,onConfirm:()=>e.submitInput(!0)}),(t.step==="Install Tools"||t.step==="Project Setup")&&a(Zt,{title:t.step==="Install Tools"?"Installing Tools":"Project Setup",phase:t.data.dependencyPhase||"",progress:t.data.dependencyProgress||0,isComplete:t.step==="Install Tools"?t.data.toolComplete||!1:t.data.dependencyComplete||!1,logs:t.data.dependencyLogs||[]}),t.error&&a(p,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:u(s,{color:"red",children:["Error: ",t.error.message]})})]})};import{Spinner as er}from"@inkjs/ui";import{Box as N,Text as M,useInput as tr}from"ink";import{useEffect as rr,useState as or}from"react";import{jsx as F,jsxs as B}from"react/jsx-runtime";var rt=({store:e,command:t})=>{let[o,r]=or(e.currentState);rr(()=>{let i=()=>r({...e.currentState});return e.on("change",i),()=>{e.off("change",i)}},[e]),tr((i,c)=>{(c.return||c.escape)&&(o.data.started||o.data.stopped||o.error)&&e.submitInput("exit")});let n=t==="start";return B(N,{flexDirection:"column",width:"100%",children:[F(te,{}),(o.step==="Starting"||o.step==="Stopping")&&B(N,{flexDirection:"column",marginTop:1,paddingX:2,borderStyle:"round",borderColor:h,children:[F(er,{label:o.status||"Working..."}),o.data.repoPath&&F(N,{marginTop:1,children:B(M,{color:"gray",children:["Repository: ",o.data.repoPath]})}),o.data.setupMode&&F(N,{children:B(M,{color:"gray",children:["Mode: ",o.data.setupMode]})})]}),o.step==="Running"&&o.data.started&&B(N,{flexDirection:"column",marginTop:1,paddingX:2,paddingY:1,borderStyle:"round",borderColor:"green",children:[B(M,{color:"green",bold:!0,children:["\u2713"," GAIA is running!"]}),o.data.setupMode!=="developer"&&B(N,{marginTop:1,flexDirection:"column",children:[B(M,{children:["Web:"," ",B(M,{color:"cyan",bold:!0,children:["http://localhost:",o.data.webPort||3e3]})]}),B(M,{children:["API:"," ",B(M,{color:"cyan",bold:!0,children:["http://localhost:",o.data.apiPort||8e3]})]})]}),o.data.setupMode==="developer"&&B(N,{marginTop:1,flexDirection:"column",children:[F(M,{color:"gray",children:"Dev servers started in background."}),B(M,{color:"gray",children:["Logs: ",F(M,{color:h,children:"dev-start.log"})," in your repo root."]}),B(M,{color:"gray",children:["Run ",F(M,{color:h,children:"gaia stop"})," to shut down."]})]}),F(N,{marginTop:1,children:F(M,{dimColor:!0,children:"Press Enter to exit"})})]}),o.step==="Stopped"&&o.data.stopped&&B(N,{flexDirection:"column",marginTop:1,paddingX:2,paddingY:1,borderStyle:"round",borderColor:h,children:[B(M,{color:h,bold:!0,children:["\u2713"," All GAIA services stopped."]}),F(N,{marginTop:1,children:F(M,{dimColor:!0,children:"Press Enter to exit"})})]}),o.error&&B(N,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:[B(M,{color:"red",children:["Error: ",o.error.message]}),F(N,{marginTop:1,children:F(M,{dimColor:!0,children:"Press Enter to exit"})})]})]})};import{ProgressBar as nr,Spinner as Fe}from"@inkjs/ui";import{Box as R,Text as w,useInput as ot}from"ink";import{useEffect as ir,useState as ar}from"react";import{jsx as T,jsxs as k}from"react/jsx-runtime";var nt=({store:e})=>{let[t,o]=ar(e.currentState);return ir(()=>{let r=()=>o({...e.currentState});return e.on("change",r),()=>{e.off("change",r)}},[e]),k(fe,{status:t.status,step:t.step,steps:Je,children:[t.step==="Detect Repo"&&k(R,{flexDirection:"column",paddingX:2,borderStyle:"round",borderColor:h,children:[T(w,{bold:!0,children:"Detecting GAIA Repository"}),T(R,{marginTop:1,children:T(Fe,{label:"Searching for repository..."})}),t.data.repoPath&&T(R,{marginTop:1,children:k(w,{color:"green",children:["Found: ",t.data.repoPath]})})]}),t.step==="Prerequisites"&&t.data.checks&&k(R,{flexDirection:"column",borderStyle:"round",paddingX:1,borderColor:h,children:[T(w,{bold:!0,children:"System Checks"}),k(R,{flexDirection:"column",marginTop:1,children:[T(Oe,{label:"Git",status:t.data.checks.git}),T(Oe,{label:"Docker",status:t.data.checks.docker}),T(Oe,{label:"Mise",status:t.data.checks.mise})]})]}),t.inputRequest?.id==="port_conflicts"&&t.data.portConflicts&&T(sr,{portResults:t.data.portConflicts,onAccept:()=>e.submitInput("accept"),onAbort:()=>e.submitInput("abort")}),t.inputRequest?.id==="setup_mode"&&T(ke,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_method"&&T(Be,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_infisical"&&T(Ae,{onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_var"&&t.data.currentEnvVar&&T(Le,{categories:t.data.envCategories||[],currentVar:t.data.currentEnvVar,currentIndex:t.data.envVarIndex||0,totalCount:t.data.envVarTotal||0,onSubmit:r=>e.submitInput(r),onSkip:()=>e.submitInput("")}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_group"&&t.data.currentEnvGroup&&T(_e,{category:t.data.currentEnvGroup,currentIndex:t.data.envGroupIndex||0,totalGroups:t.data.envGroupTotal||0,onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_alternatives"&&t.data.alternativeGroups&&T(Me,{alternatives:t.data.alternativeGroups,onSubmit:(r,n)=>e.submitInput({selectedGroups:r,values:n})}),t.step==="Project Setup"&&k(R,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:h,children:[T(R,{marginBottom:1,children:T(w,{bold:!0,color:h,children:"Project Setup"})}),k(R,{flexDirection:"column",gap:1,children:[T(R,{children:t.data.dependencyComplete?k(w,{color:"green",children:["\u2713"," ",t.data.dependencyPhase]}):T(Fe,{label:t.data.dependencyPhase||"Preparing..."})}),!t.data.dependencyComplete&&t.data.dependencyProgress>0&&T(R,{width:50,children:T(nr,{value:t.data.dependencyProgress})}),!t.data.dependencyComplete&&t.data.dependencyLogs?.length>0&&T(R,{flexDirection:"column",marginTop:1,borderStyle:"single",borderColor:"gray",paddingX:1,minHeight:6,children:t.data.dependencyLogs.map((r,n)=>T(w,{color:"gray",wrap:"truncate",children:r},n))})]})]}),t.step==="Finished"&&T(cr,{setupMode:t.data.setupMode,repoPath:t.data.repoPath,onConfirm:()=>e.submitInput(!0)}),t.error&&T(R,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:k(w,{color:"red",children:["Error: ",t.error.message]})})]})},Oe=({label:e,status:t})=>k(R,{children:[T(R,{marginRight:1,children:t==="pending"?T(Fe,{type:"dots"}):t==="success"?T(w,{color:h,children:"\u2714"}):t==="error"?T(w,{color:"red",children:"\u2716"}):T(w,{color:"yellow",children:"\u26A0"})}),T(w,{children:e})]}),sr=({portResults:e,onAccept:t,onAbort:o})=>(ot((r,n)=>{n.return?t():n.escape&&o()}),k(R,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:"yellow",children:[T(w,{bold:!0,color:"yellow",children:"Port Conflicts Detected"}),e.map(r=>k(R,{children:[k(w,{color:r.available?"green":"red",children:[r.available?"\u2714":"\u2716"," "]}),k(w,{children:[r.service," (:",r.port,")"]}),!r.available&&k(w,{color:"gray",children:[" ","- in use",r.usedBy?` by ${r.usedBy}`:"",r.alternative?` (alt: :${r.alternative})`:""]})]},r.port)),T(R,{marginTop:1,children:k(w,{children:[T(w,{color:"green",bold:!0,children:"Enter"})," continue ",T(w,{color:"yellow",bold:!0,children:"Escape"})," abort"]})})]})),cr=({setupMode:e,repoPath:t,onConfirm:o})=>(ot((i,c)=>{c.return&&o()}),k(R,{flexDirection:"column",marginTop:2,borderStyle:"round",borderColor:h,padding:1,children:[T(w,{color:h,bold:!0,children:"Setup Complete!"}),k(R,{marginTop:1,flexDirection:"column",children:[T(w,{bold:!0,children:"To start GAIA, run:"}),k(R,{marginTop:1,padding:1,borderStyle:"single",borderColor:"gray",flexDirection:"column",children:[k(w,{color:"cyan",children:["$ cd ",t||"."]}),T(w,{color:"cyan",children:"$ gaia start"})]}),T(R,{marginTop:1,children:T(w,{color:"gray",dimColor:!0,children:(e||"developer")==="selfhost"?"Runs: docker compose --profile all up -d (background)":"Runs: mise dev (interactive \u2014 keep terminal open)"})})]}),T(De,{}),T(R,{marginTop:1,children:T(w,{dimColor:!0,children:"Press Enter to exit"})})]}));import{Spinner as lr}from"@inkjs/ui";import{Box as A,Text as _,useInput as ur}from"ink";import{useEffect as it,useState as at}from"react";import{jsx as P,jsxs as O}from"react/jsx-runtime";var st=({store:e})=>{let[t,o]=at(e.currentState),[r,n]=at(!1);return it(()=>{let i=()=>o({...e.currentState});return e.on("change",i),()=>{e.off("change",i)}},[e]),it(()=>{t.step==="Results"&&n(!1)},[t.step]),ur((i,c)=>{(c.return||c.escape)&&t.step==="Results"&&e.submitInput("exit"),i==="r"&&t.step==="Results"&&t.data.refreshable&&!r&&(n(!0),e.submitInput("refresh"))}),O(A,{flexDirection:"column",width:"100%",children:[P(te,{}),t.step==="Checking"&&P(A,{marginTop:1,children:P(lr,{label:t.data.services?"Refreshing service health...":"Checking service health..."})}),t.step==="Results"&&t.data.services&&O(A,{flexDirection:"column",children:[O(A,{flexDirection:"column",borderStyle:"round",borderColor:h,paddingX:2,paddingY:1,children:[P(_,{bold:!0,color:h,children:"GAIA Service Status"}),O(A,{marginTop:1,flexDirection:"column",children:[O(A,{children:[P(A,{width:22,children:P(_,{bold:!0,children:"Service"})}),P(A,{width:10,children:P(_,{bold:!0,children:"Status"})}),P(A,{width:10,children:P(_,{bold:!0,children:"Latency"})})]}),P(_,{color:"gray",children:"\u2500".repeat(42)}),t.data.services.map(i=>O(A,{children:[P(A,{width:22,children:O(_,{children:[i.name," (:",i.port,")"]})}),P(A,{width:10,children:P(_,{color:i.status==="up"?"green":"red",bold:!0,children:i.status==="up"?"\u2713 UP":"\u2717 DOWN"})}),P(A,{width:10,children:P(_,{color:"gray",children:i.latency?`${i.latency}ms`:"--"})})]},i.name))]})]}),t.data.docker&&O(A,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,marginTop:1,children:[P(_,{bold:!0,children:"Docker Containers"}),O(_,{color:"gray",children:["Docker:"," ",t.data.docker.running?P(_,{color:"green",children:"Running"}):P(_,{color:"red",children:"Not running"})]}),t.data.docker.containers?.length>0&&P(A,{marginTop:1,flexDirection:"column",children:t.data.docker.containers.map(i=>O(A,{children:[O(_,{color:i.status==="running"?"green":"red",children:[i.status==="running"?"\u2713":"\u2717"," "]}),P(_,{children:i.name}),i.health&&O(_,{color:"gray",children:[" (",i.health,")"]})]},i.name))})]}),P(A,{marginTop:1,children:O(_,{dimColor:!0,children:["Press Enter or Escape to exit \xB7 Press"," ",P(_,{color:h,children:"r"})," to refresh"]})})]}),t.error&&P(A,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:O(_,{color:"red",children:["Error: ",t.error.message]})})]})};import{jsx as G,jsxs as ue}from"react/jsx-runtime";var dr=["init","setup","status","start","stop"],Ne=class extends pr.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}render(){return this.state.error?ue(xe,{flexDirection:"column",padding:1,children:[G(Z,{color:"red",bold:!0,children:"An unexpected error occurred:"}),G(Z,{color:"red",children:this.state.error.message}),this.state.error.stack&&G(xe,{marginTop:1,children:G(Z,{color:"gray",dimColor:!0,children:this.state.error.stack})})]}):this.props.children}},mr=({store:e,command:t})=>{switch(t){case"init":return G(tt,{store:e});case"setup":return G(nt,{store:e});case"status":return G(st,{store:e});case"start":case"stop":return G(rt,{store:e,command:t});default:return ue(xe,{flexDirection:"column",padding:1,children:[ue(Z,{color:"red",children:["Unknown command: ",t]}),ue(xe,{marginTop:1,flexDirection:"column",children:[G(Z,{bold:!0,children:"Available commands:"}),dr.map(o=>ue(Z,{children:[" ",G(Z,{color:"cyan",children:o})]},o))]})]})}},j=({store:e,command:t})=>G(Ne,{children:G(mr,{store:e,command:t})});import{EventEmitter as fr}from"events";var gr=150,Ge=class extends fr{state={step:"init",status:"",error:null,data:{},inputRequest:null};inputResolver=null;emitTimer=null;emitPending=!1;get currentState(){return this.state}scheduleEmit(){this.emitPending=!0,this.emitTimer||(this.emitTimer=setTimeout(()=>{this.emitTimer=null,this.emitPending&&(this.emitPending=!1,this.emit("change",this.state))},gr))}emitNow(){this.emitTimer&&(clearTimeout(this.emitTimer),this.emitTimer=null),this.emitPending=!1,this.emit("change",this.state)}setStep(t){this.state.step=t,this.emitNow()}setStatus(t){this.state.status=t,this.scheduleEmit()}setError(t){this.state.error=t,t!==null&&this.inputResolver&&(this.inputResolver(null),this.inputResolver=null,this.state.inputRequest=null),this.emitNow()}updateData(t,o){this.state.data={...this.state.data,[t]:o},this.scheduleEmit()}waitForInput(t,o){return this.state.inputRequest={id:t,meta:o},this.emitNow(),new Promise(r=>{this.inputResolver=r})}submitInput(t){this.inputResolver&&(this.inputResolver(t),this.inputResolver=null,this.state.inputRequest=null,this.emitNow())}},H=()=>new Ge;import*as ae from"fs";import*as Tt from"path";import*as ne from"node:fs";import*as oe from"node:path";import{execa as ct}from"execa";var lt={selfhost:{MONGO_DB:"mongodb://mongo:27017/gaia",REDIS_URL:"redis://redis:6379",POSTGRES_URL:"postgresql://postgres:postgres@postgres:5432/langgraph",CHROMADB_HOST:"chromadb",CHROMADB_PORT:"8000",RABBITMQ_URL:"amqp://guest:guest@rabbitmq:5672/"},developer:{MONGO_DB:"mongodb://localhost:27017/gaia",REDIS_URL:"redis://localhost:6379",POSTGRES_URL:"postgresql://postgres:postgres@localhost:5432/postgres",CHROMADB_HOST:"localhost",CHROMADB_PORT:"8080",RABBITMQ_URL:"amqp://guest:guest@localhost:5672/"}},ut={selfhost:{HOST:"http://localhost:8000",FRONTEND_URL:"http://localhost:3000",GAIA_BACKEND_URL:"http://gaia-backend:80",SETUP_MODE:"selfhost"},developer:{HOST:"http://localhost:8000",FRONTEND_URL:"http://localhost:3000",GAIA_BACKEND_URL:"http://host.docker.internal:8000",SETUP_MODE:"developer"}};function $e(e,t){return lt[t][e]??ut[t][e]}async function pt(e){let t=oe.join(e,"apps/api/scripts/dump_config_schema.py"),o=oe.join(e,"apps/api/app/config/settings_validator.py"),r=oe.join(e,"apps/api/app/config/settings.py");if(!ne.existsSync(t))throw new Error("dump_config_schema.py not found in apps/api/scripts");try{try{let{stdout:n}=await ct("python3",[t,o,r],{cwd:e});return JSON.parse(n)}catch{let{stdout:n}=await ct("python",[t,o,r],{cwd:e});return JSON.parse(n)}}catch(n){throw new Error(`Failed to parse settings schema: ${n.message}. Ensure python is installed.`)}}function dt(e){let t=oe.join(e,"apps","web",".env.local"),o=ne.existsSync(t)?t:oe.join(e,"apps","web",".env");if(!ne.existsSync(o))return[];let r=ne.readFileSync(o,"utf-8"),n=[],i="General";for(let c of r.split(`
3
+ `)){let d=c.trim();if(d.startsWith("#")&&!d.startsWith("#=")){let x=d.replace(/^#+\s*/,"").trim();x&&!x.startsWith("These are")&&(i=x);continue}if(!d||d.startsWith("#"))continue;let m=d.indexOf("=");if(m===-1)continue;let g=d.substring(0,m).trim(),v=d.substring(m+1).trim();n.push({name:g,value:v,category:i})}return n}function mt(e,t){let o=t?.[8e3]??8e3,r=t?.[3e3]??3e3,n={NEXT_PUBLIC_API_BASE_URL:`http://localhost:${o}/api/v1/`,NEXT_PUBLIC_WS_URL:`ws://localhost:${o}/api/v1/`};return r!==3e3&&(n.NEXT_PUBLIC_APP_URL=`http://localhost:${r}`),n}function ft(e,t){for(let[o,r]of Object.entries(t)){let n=Number(o);for(let[i,c]of Object.entries(e)){let d=new RegExp(`:${n}(?=[/\\s]|$)`,"g");e[i]=c.replaceAll(d,`:${r}`)}}}function gt(e,t){return e.map(o=>({...o,variables:o.variables.map(r=>{let n=$e(r.name,t);return{...r,defaultValue:n||r.defaultValue}})}))}function qe(){return Object.keys(lt.selfhost)}function xt(e){return{...ut[e]}}import*as q from"fs";import*as pe from"path";function je(e){q.existsSync(e)&&q.copyFileSync(e,`${e}.bak`)}function St(e,t){let o=pe.join(e,".env");je(o);let r=["# GAIA Environment Configuration","# Generated by GAIA CLI",`# Created: ${new Date().toISOString()}`,""],n=["MONGO","REDIS","POSTGRES","CHROMADB","RABBITMQ","WORKOS","GOOGLE","OPENAI","INFISICAL","LANGSMITH","DISCORD","SLACK","TELEGRAM","CLOUDINARY","COMPOSIO","FIRECRAWL","LIVEKIT","DEEPGRAM","ELEVENLABS","RESEND","SENTRY","POSTHOG","MEM0","E2B","DODO","NEXT_PUBLIC","GAIA"];function i(d){for(let g of n)if(d===g||d.startsWith(`${g}_`))return g;let m=d.split("_");return m.length===1?"Core":m[0]||"Core"}let c=new Map;for(let[d,m]of Object.entries(t)){let g=i(d);c.has(g)||c.set(g,[]);let x=/[\s#"'\\]/.test(m)||m===""?`"${m.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:m;c.get(g).push(`${d}=${x}`)}for(let[d,m]of c.entries())r.push(`# ${d} Configuration`),r.push(...m),r.push("");q.writeFileSync(o,r.join(`
4
+ `),"utf-8")}function vt(e,t,o){let r=pe.join(e,"apps","web",".env.local");je(r);let n=dt(e),i=mt(t,o),c=["# GAIA Web App Environment Configuration","# Generated by GAIA CLI",`# Created: ${new Date().toISOString()}`,""],d=new Map;for(let m of n){d.has(m.category)||d.set(m.category,[]);let g=i[m.name]??m.value;d.get(m.category).push({name:m.name,value:g})}if(n.length===0){c.push("# Core URLs");for(let[m,g]of Object.entries(i))c.push(`${m}=${g}`);c.push("")}else for(let[m,g]of d.entries()){c.push(`# ${m}`);for(let{name:v,value:x}of g)c.push(`${v}=${x}`);c.push("")}q.writeFileSync(r,c.join(`
5
+ `),"utf-8")}var hr={8e3:"API_HOST_PORT",5432:"POSTGRES_HOST_PORT",6379:"REDIS_HOST_PORT",27017:"MONGO_HOST_PORT",5672:"RABBITMQ_HOST_PORT",8080:"CHROMADB_HOST_PORT",8083:"MONGO_EXPRESS_HOST_PORT",3e3:"WEB_HOST_PORT"};function yt(e,t){let o=pe.join(e,"infra","docker",".env");je(o);let r=["# Docker Compose port overrides","# Generated by GAIA CLI to resolve port conflicts",`# Created: ${new Date().toISOString()}`,""];for(let[n,i]of Object.entries(t)){let c=Number(n),d=hr[c];d&&r.push(`${d}=${i}`)}r.push(""),q.writeFileSync(o,r.join(`
6
+ `),"utf-8")}var ht={API_HOST_PORT:8e3,POSTGRES_HOST_PORT:5432,REDIS_HOST_PORT:6379,MONGO_HOST_PORT:27017,RABBITMQ_HOST_PORT:5672,CHROMADB_HOST_PORT:8080,MONGO_EXPRESS_HOST_PORT:8083,WEB_HOST_PORT:3e3};function ie(e){let t=pe.join(e,"infra","docker",".env"),o={};if(!q.existsSync(t))return o;let r=q.readFileSync(t,"utf-8");for(let n of r.split(`
7
+ `)){let i=n.trim();if(i&&!i.startsWith("#")){let[c,...d]=i.split("=");if(c&&ht[c]){let m=Number(d.join("=").trim());!Number.isNaN(m)&&m>0&&(o[ht[c]]=m)}}}return o}var vr=e=>new Promise(t=>setTimeout(t,e));async function he(e,t,o){e.setStep("Environment Setup"),e.setStatus("Configuring environment...");let r=await e.waitForInput("setup_mode");e.updateData("setupMode",r),e.setStatus("Configuring environment variables...");let n=await e.waitForInput("env_method"),i={};i.ENV=r==="selfhost"?"production":"development";let c=qe();for(let m of c){let g=$e(m,r);g&&(i[m]=g)}let d=xt(r);for(let[m,g]of Object.entries(d))i[m]=g;if(n==="infisical")await yr(e,i),e.setStatus("Infisical credentials saved. Ensure your Infisical project contains all required variables.");else try{await Tr(e,t,i,r)}catch(m){e.setError(m);return}o&&ft(i,o);try{await br(e,t,i,r,o)}catch(m){e.setError(m);return}await vr(1e3)}async function yr(e,t){e.setStatus("Configuring Infisical...");let o=await e.waitForInput("env_infisical");t.INFISICAL_PROJECT_ID=o.INFISICAL_PROJECT_ID,t.INFISICAL_MACHINE_IDENTITY_CLIENT_ID=o.INFISICAL_MACHINE_IDENTITY_CLIENT_ID,t.INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET=o.INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET}async function Tr(e,t,o,r){e.setStatus("Parsing environment variables...");let n;try{n=await pt(t),n=gt(n,r)}catch(f){throw new Error(`Failed to parse settings: ${f.message}`)}let i=new Set,c=[],d=new Set;for(let f of n)if(f.alternativeGroup&&!d.has(f.name)){let b=n.find(y=>y.name===f.alternativeGroup);b&&(c.push([f,b]),i.add(f.name),i.add(b.name),d.add(f.name),d.add(b.name))}let m=n.filter(f=>f.variables.length===1&&!i.has(f.name)),g=n.filter(f=>f.variables.length>1&&!i.has(f.name));for(let f of c){e.updateData("alternativeGroups",f),e.setStatus("Choose an AI provider...");let b=await e.waitForInput("env_alternatives");for(let[y,C]of Object.entries(b.values))C&&(o[y]=C)}let v=qe(),l=[...m.flatMap(f=>f.variables).filter(f=>!v.includes(f.name))].sort((f,b)=>f.required&&!b.required?-1:!f.required&&b.required?1:0);e.updateData("envVarTotal",l.length);for(let f=0;f<l.length;f++){let b=l[f];if(!b)continue;e.updateData("currentEnvVar",b),e.updateData("envVarIndex",f),e.setStatus(`Configuring ${b.name}...`);let y=await e.waitForInput("env_var",{varName:b.name});(y||b.required||b.defaultValue)&&(o[b.name]=y||b.defaultValue||"")}let S=[...g].filter(f=>!f.variables.every(b=>v.includes(b.name))).sort((f,b)=>{let y=f.variables.some(I=>I.required),C=b.variables.some(I=>I.required);return y&&!C?-1:!y&&C?1:0});e.updateData("envGroupTotal",S.length);for(let f=0;f<S.length;f++){let b=S[f];if(!b)continue;e.updateData("currentEnvGroup",b),e.updateData("envGroupIndex",f),e.setStatus(`Configuring ${b.name}...`);let y=await e.waitForInput("env_group",{groupName:b.name});for(let[C,I]of Object.entries(y)){let E=b.variables.find(Q=>Q.name===C);(I||E?.required||E?.defaultValue)&&(o[C]=I||E?.defaultValue||"")}}}async function br(e,t,o,r,n){e.setStatus("Writing API environment file...");try{let i=Tt.join(t,"apps","api");St(i,o),e.setStatus("API environment variables configured!")}catch(i){throw new Error(`Failed to write API .env file: ${i.message}`)}e.setStatus("Writing web environment file...");try{vt(t,r,n),e.setStatus("Web environment variables configured!")}catch(i){throw new Error(`Failed to write web .env file: ${i.message}`)}if(n&&Object.keys(n).length>0){e.setStatus("Writing Docker Compose port overrides...");try{yt(t,n),e.setStatus("Docker Compose ports configured!")}catch(i){throw new Error(`Failed to write Docker Compose .env: ${i.message}`)}}}import{execa as Cr}from"execa";import Se from"fs";import Ir from"simple-git";async function bt(e,t,o){if(Se.existsSync(e)){let r=`${e}/.git`;if(!Se.existsSync(r))throw new Error(`Directory ${e} exists but is not a git repository`);await Ir().cwd(e).pull(),o(100,"Already exists, pulled latest")}else try{let r=Cr("git",["clone","--progress",t,e]);r.stderr?.on("data",n=>{let i=n.toString();i.includes("Counting objects")?o(5,"Counting objects"):i.includes("Compressing objects")&&o(10,"Compressing objects");let c=i.match(/Receiving objects:\s+(\d+)%\s+\((\d+)\/(\d+)\)/);if(c?.[1]){let m=Math.min(100,parseInt(c[1],10)),g=c[2],v=c[3];o(10+Math.floor(m*.5),`Receiving objects: ${g}/${v}`)}let d=i.match(/Resolving deltas:\s+(\d+)%\s+\((\d+)\/(\d+)\)/);if(d?.[1]){let m=Math.min(100,parseInt(d[1],10)),g=d[2],v=d[3];o(60+Math.floor(m*.4),`Resolving deltas: ${g}/${v}`)}}),await r,o(100,"Clone complete")}catch(r){throw Se.existsSync(e)&&Se.rmSync(e,{recursive:!0,force:!0}),r}}import{execa as Y}from"execa";var V={git:"https://git-scm.com/downloads",docker:"https://docs.docker.com/get-docker/",mise:"https://mise.jdx.dev/getting-started.html"},wr={8e3:"API Server",5432:"PostgreSQL",6379:"Redis",27017:"MongoDB",5672:"RabbitMQ",3e3:"Web Frontend",8080:"ChromaDB",8083:"Mongo Express"};async function ve(){try{return await Y("git",["--version"]),"success"}catch{return"error"}}async function ye(){let e=!1,t=!1,o;try{await Y("docker",["--version"]),e=!0}catch{return{name:"Docker",installUrl:V.docker,installed:!1,working:!1,errorMessage:"Docker is not installed"}}try{await Y("docker",["info"],{timeout:5e3}),t=!0}catch{o="Docker is installed but the daemon is not running. Please start Docker Desktop or the Docker daemon."}return{name:"Docker",installUrl:V.docker,installed:e,working:t,errorMessage:o}}async function Te(){try{return await Y("mise",["--version"]),"success"}catch{return"missing"}}async function be(){if((await import("node:os")).platform()==="win32")try{return await Y("powershell",["-Command","irm https://mise.jdx.dev/install.ps1 | iex"]),!0}catch{return!1}try{return await Y("sh",["-c","curl https://mise.jdx.dev/install.sh | sh"]),!0}catch{return!1}}async function Ce(e){let t=await import("node:net"),o=[],r=n=>new Promise(i=>{let c=t.createServer();c.once("error",()=>i(!1)),c.once("listening",()=>{c.close(()=>i(!0))}),c.listen(n)});for(let n of e){let i=wr[n]||`Port ${n}`;if(await r(n))o.push({port:n,service:i,available:!0});else{let d=await Pr(n),m=await Rr(n+1,n+100,r);o.push({port:n,service:i,available:!1,usedBy:d,alternative:m||void 0})}}return o}async function Pr(e){if((await import("node:os")).platform()==="win32"){try{let{stdout:r}=await Y("netstat",["-ano","-p","TCP"]),n=r.trim().split(`
8
+ `);for(let i of n)if(i.includes(`:${e}`)&&i.includes("LISTENING")){let c=i.trim().split(/\s+/),d=c[c.length-1];if(d)try{let{stdout:m}=await Y("tasklist",["/FI",`PID eq ${d}`,"/FO","CSV","/NH"]);return m.trim().split(",")[0]?.replace(/"/g,"")||`PID ${d}`}catch{return`PID ${d}`}}}catch{}return}try{let{stdout:r}=await Y("lsof",["-i",`:${e}`,"-sTCP:LISTEN","-P","-n"]),n=r.trim().split(`
9
+ `);if(n.length>1)return n[1]?.split(/\s+/)?.[0]||void 0}catch{}}async function Rr(e,t,o){for(let r=e;r<=t;r++)if(await o(r))return r;return null}import*as W from"fs";import*as U from"path";var Dr=e=>new Promise(t=>setTimeout(t,e)),kr="dev-start.log";function It(e){let t=U.join(e,".env");return W.existsSync(t)?["--env-file",".env"]:[]}async function Et(e,t,o){if(t==="selfhost"){o?.("Starting all services in Docker (selfhost mode)...");let r=U.join(e,"infra/docker"),n=It(r);await $("docker",["compose",...n,"-f","docker-compose.prod.yml","--profile","backend","--profile","web","up","-d","--build","--remove-orphans"],r),o?.("All services started in Docker!")}else{o?.("Starting development servers...");let{spawn:r}=await import("child_process"),n=U.join(e,kr),i=W.openSync(n,"a"),c;try{c=r("mise",["dev"],{cwd:e,stdio:["ignore",i,i],detached:!0,shell:!0}),c.unref()}finally{W.closeSync(i)}if(await Dr(1500),c.pid!=null)try{process.kill(c.pid,0)}catch{throw new Error(`Development servers crashed on startup. Check logs at: ${n}`)}o?.(`Development servers started! Logs: ${n}`)}}async function wt(e,t,o){let r=U.join(e,"infra/docker"),n=await He(e);t?.("Stopping Docker services...");try{let i=It(r),c=n==="selfhost"?["compose",...i,"-f","docker-compose.prod.yml","down"]:["compose",...i,"down"];await $("docker",c,r)}catch{}t?.("Stopping local processes...");try{let i=o?.[8e3]??8e3,c=o?.[3e3]??3e3;if(process.platform==="win32")for(let d of[i,c])try{await $("powershell",["-Command",`Get-NetTCPConnection -LocalPort ${d} -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue }`],e)}catch{}else for(let d of[i,c])try{await $("sh",["-c",`lsof -ti :${d} -sTCP:LISTEN | xargs kill 2>/dev/null || true`],e)}catch{}}catch{}t?.("All services stopped.")}async function He(e){let t=U.join(e,"apps","api",".env");if(!W.existsSync(t))return null;let o=W.readFileSync(t,"utf-8"),r=o.match(/^SETUP_MODE=(.+)$/m);if(r?.[1]){let n=r[1].trim().replace(/^["']|["']$/g,"");if(n==="selfhost"||n==="developer")return n}return o.includes("mongodb://mongo:")?"selfhost":(o.includes("mongodb://localhost:"),"developer")}async function $(e,t,o,r,n){let{spawn:i}=await import("child_process");return new Promise((c,d)=>{let m=i(e,t,{cwd:o,stdio:["ignore","pipe","pipe"],shell:!0}),g="",v=0;m.stdout?.on("data",x=>{let l=x.toString();g+=l,n?.(l),v=Math.min(v+5,95),r?.(v)}),m.stderr?.on("data",x=>{let l=x.toString();g+=l,n?.(l),v=Math.min(v+5,95),r?.(v)}),m.on("close",x=>{x===0?(r?.(100),c()):d(new Error(`Command failed with code ${x}: ${g.slice(-500)}`))}),m.on("error",x=>{d(x)})})}function X(e){let t=e||process.cwd();for(;t!==U.dirname(t);){if(W.existsSync(U.join(t,"apps/api/app/config/settings_validator.py")))return t;t=U.dirname(t)}return null}var Br=process.env.GAIA_CLI_DEV==="true",K=e=>new Promise(t=>setTimeout(t,e));async function Pt(e){e.setStep("Welcome"),e.setStatus("Waiting for user input..."),await e.waitForInput("welcome");let t=l=>{let S=e.currentState.data.dependencyLogs||[],f=l.split(`
10
+ `).filter(y=>y.trim()!==""),b=[...S,...f].slice(-20);e.updateData("dependencyLogs",b)};e.setStep("Prerequisites"),e.setStatus("Checking system requirements..."),e.updateData("checks",{git:"pending",docker:"pending",mise:"pending"}),await K(800),e.setStatus("Checking Git...");let o=await ve();e.updateData("checks",{...e.currentState.data.checks,git:o}),e.setStatus("Checking Docker...");let r=await ye(),n=r.working?"success":"error";e.updateData("checks",{...e.currentState.data.checks,docker:n}),r.working||e.updateData("dockerError",r.errorMessage),e.setStatus("Checking Mise...");let i=await Te();e.updateData("checks",{...e.currentState.data.checks,mise:i}),i==="missing"&&(e.setStatus("Installing Mise..."),i=await be()?"success":"error",e.updateData("checks",{...e.currentState.data.checks,mise:i}));let c=[];if(o==="error"&&c.push({name:"Git"}),n==="error"&&c.push({name:"Docker",message:r.errorMessage}),i==="error"&&c.push({name:"Mise"}),c.length>0){let l=[];l.push("Prerequisites failed:");for(let S of c)l.push(` \u2022 ${S.name}: ${S.message||"Not installed or not working"}`);l.push(`
11
+ Installation guides:`),o==="error"&&l.push(` \u2022 Git: ${V.git}`),n==="error"&&(r.installed?l.push(" \u2022 Docker: Start Docker Desktop or run 'sudo systemctl start docker'"):l.push(` \u2022 Docker: ${V.docker}`)),i==="error"&&l.push(` \u2022 Mise: ${V.mise}`),e.setError(new Error(l.join(`
12
+ `)));return}e.setStatus("Checking Ports...");let m=await Ce([8e3,5432,6379,27017,5672,3e3,8080,8083]),g={},v=m.filter(l=>!l.available);if(v.length>0){let l=v.filter(f=>!f.alternative);if(l.length>0){e.setError(new Error(`Cannot find free alternative ports for: ${l.map(f=>`${f.port} (${f.service})`).join(", ")}. Free these ports and try again.`));return}if(e.updateData("portConflicts",m),await e.waitForInput("port_conflicts")==="abort"){e.setError(new Error("Port conflicts not resolved. Please free the ports and try again."));return}for(let f of m)!f.available&&f.alternative&&(g[f.port]=f.alternative)}e.updateData("portOverrides",g),e.setStatus("Prerequisites check complete!"),await K(1e3);let x="";if(Br){if(x=X()||"",!x){e.setError(new Error("DEV_MODE: Could not find workspace root. Run from within the gaia repo."));return}e.setStep("Repository Setup"),e.setStatus("[DEV MODE] Using current workspace..."),await K(500),e.setStatus("Repository ready!")}else{for(e.setStep("Repository Setup");;){if(x=await e.waitForInput("repo_path",{default:"./gaia"}),ae.existsSync(x)){if(!ae.statSync(x).isDirectory()){e.setError(new Error(`Path ${x} exists and is not a directory.`)),await K(2e3),e.setError(null);continue}if(ae.readdirSync(x).length>0){e.setError(new Error(`Directory ${x} is not empty. Please choose another path.`)),await K(2e3),e.setError(null);continue}}break}e.setStep("Repository Setup"),e.setStatus("Preparing repository..."),e.updateData("repoProgress",0),e.updateData("repoPhase","");try{await bt(x,"https://github.com/theexperiencecompany/gaia.git",(l,S)=>{e.updateData("repoProgress",l),S?(e.updateData("repoPhase",S),e.setStatus(`${S}...`)):e.setStatus(`Cloning repository to ${x}... ${l}%`)}),e.setStatus("Repository ready!")}catch(l){e.setError(l);return}}await K(1e3),e.setStep("Install Tools"),e.setStatus("Installing toolchain..."),e.updateData("dependencyPhase","Initializing mise..."),e.updateData("dependencyProgress",0),e.updateData("dependencyLogs",[]);try{e.updateData("dependencyPhase","Trusting mise configuration..."),await $("mise",["trust"],x,void 0,t),e.updateData("dependencyProgress",50),e.updateData("dependencyPhase","Installing tools (node, python, uv, nx)..."),await $("mise",["install"],x,l=>{e.updateData("dependencyProgress",50+l*.5)},t),e.updateData("dependencyProgress",100),e.updateData("toolComplete",!0)}catch(l){e.setError(new Error(`Failed to install tools: ${l.message}`));return}if(await K(1e3),await he(e,x,g),!e.currentState.error){e.setStep("Project Setup"),e.updateData("dependencyPhase","Setting up project..."),e.updateData("dependencyProgress",0),e.updateData("dependencyComplete",!1),e.updateData("repoPath",x),e.updateData("dependencyLogs",[]);try{e.updateData("dependencyProgress",0),e.updateData("dependencyPhase","Running mise setup (all dependencies)..."),await $("mise",["setup"],x,l=>{e.updateData("dependencyProgress",l)},t),e.updateData("dependencyProgress",100),e.updateData("dependencyPhase","Setup complete!"),e.updateData("dependencyComplete",!0)}catch(l){e.setError(new Error(`Failed to setup project: ${l.message}`));return}await K(1e3),e.setStep("Finished"),e.setStatus("Setup complete!")}}async function Rt(){let e=H(),{unmount:t}=Ar(_r.createElement(j,{store:e,command:"init"}));try{await Pt(e)}catch(o){e.setError(o)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as Mr}from"ink";import Lr from"react";var Ie=e=>new Promise(t=>setTimeout(t,e));async function Dt(e){e.setStep("Detect Repo"),e.setStatus("Looking for GAIA repository...");let t=X();if(!t){e.setError(new Error("Could not find GAIA repository. Run this command from within a cloned gaia repo, or use 'gaia init' to set up from scratch."));return}e.updateData("repoPath",t),e.setStatus(`Found repository at ${t}`),await Ie(1e3),e.setStep("Prerequisites"),e.setStatus("Checking system requirements..."),e.updateData("checks",{git:"pending",docker:"pending",mise:"pending"}),await Ie(500);let o=await ve();e.updateData("checks",{...e.currentState.data.checks,git:o});let r=await ye(),n=r.working?"success":"error";e.updateData("checks",{...e.currentState.data.checks,docker:n}),r.working||e.updateData("dockerError",r.errorMessage);let i=await Te();e.updateData("checks",{...e.currentState.data.checks,mise:i}),i==="missing"&&(e.setStatus("Installing Mise..."),i=await be()?"success":"error",e.updateData("checks",{...e.currentState.data.checks,mise:i}));let c=[];if(o==="error"&&c.push({name:"Git"}),n==="error"&&c.push({name:"Docker",message:r.errorMessage}),i==="error"&&c.push({name:"Mise"}),c.length>0){let l=[];l.push("Prerequisites failed:");for(let S of c)l.push(` \u2022 ${S.name}: ${S.message||"Not installed or not working"}`);l.push(`
13
+ Installation guides:`),o==="error"&&l.push(` \u2022 Git: ${V.git}`),n==="error"&&(r.installed?l.push(" \u2022 Docker: Start Docker Desktop or run 'sudo systemctl start docker'"):l.push(` \u2022 Docker: ${V.docker}`)),i==="error"&&l.push(` \u2022 Mise: ${V.mise}`),e.setError(new Error(l.join(`
14
+ `)));return}e.setStatus("Checking Ports...");let m=await Ce([8e3,5432,6379,27017,5672,3e3,8080,8083]),g={},v=m.filter(l=>!l.available);if(v.length>0){let l=v.filter(f=>!f.alternative);if(l.length>0){e.setError(new Error(`Cannot find free alternative ports for: ${l.map(f=>`${f.port} (${f.service})`).join(", ")}. Free these ports and try again.`));return}if(e.updateData("portConflicts",m),await e.waitForInput("port_conflicts")==="abort"){e.setError(new Error("Port conflicts not resolved. Please free the ports and try again."));return}for(let f of m)!f.available&&f.alternative&&(g[f.port]=f.alternative)}if(e.updateData("portOverrides",g),e.setStatus("Prerequisites check complete!"),await Ie(1e3),await he(e,t,g),e.currentState.error)return;e.setStep("Project Setup"),e.updateData("dependencyPhase","Setting up project..."),e.updateData("dependencyProgress",0),e.updateData("dependencyComplete",!1),e.updateData("dependencyLogs",[]);let x=l=>{let S=e.currentState.data.dependencyLogs||[],f=l.split(`
15
+ `).filter(y=>y.trim()!==""),b=[...S,...f].slice(-20);e.updateData("dependencyLogs",b)};try{e.updateData("dependencyPhase","Trusting mise configuration..."),await $("mise",["trust"],t,void 0,x),e.updateData("dependencyProgress",20),e.updateData("dependencyPhase","Installing tools..."),await $("mise",["install"],t,l=>{e.updateData("dependencyProgress",20+l*.3)},x),e.updateData("dependencyPhase","Running mise setup..."),await $("mise",["setup"],t,l=>{e.updateData("dependencyProgress",50+l*.5)},x),e.updateData("dependencyProgress",100),e.updateData("dependencyPhase","Setup complete!"),e.updateData("dependencyComplete",!0)}catch(l){e.setError(new Error(`Failed to setup project: ${l.message}`));return}await Ie(1e3),e.setStep("Finished"),e.setStatus("Setup complete!")}async function kt(){let e=H(),{unmount:t}=Mr(Lr.createElement(j,{store:e,command:"setup"}));try{await Dt(e)}catch(o){e.setError(o)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as Or}from"ink";import Fr from"react";async function Bt(e){e.setStep("Starting"),e.setStatus("Locating GAIA repository...");let t=X();if(!t){e.setError(new Error("Could not find GAIA repository. Run from within a cloned gaia repo."));return}e.updateData("repoPath",t);let o=await He(t);if(!o){e.setError(new Error("No .env file found. Run 'gaia setup' first to configure the environment."));return}let r=ie(t),n=r[3e3]??3e3,i=r[8e3]??8e3;e.updateData("setupMode",o),e.updateData("webPort",n),e.updateData("apiPort",i),e.setStatus(`Starting GAIA in ${o} mode...`);try{await Et(t,o,c=>{e.setStatus(c)}),e.setStep("Running"),e.setStatus("GAIA is running!"),e.updateData("started",!0)}catch(c){e.setError(new Error(`Failed to start services: ${c.message}`));return}await e.waitForInput("exit")}async function At(){let e=H(),{unmount:t}=Or(Fr.createElement(j,{store:e,command:"start"}));await new Promise(o=>setTimeout(o,50));try{await Bt(e)}catch(o){e.setError(o)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as jr}from"ink";import Hr from"react";import{execa as Ue}from"execa";var Ve=["gaia-backend","gaia-web","chromadb","postgres","redis","mongo","rabbitmq","arq_worker"];async function _t(){try{let{stdout:e}=await Ue("docker",["inspect","--format","{{.Name}}|{{.State.Status}}|{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}",...Ve]),t=new Map;for(let o of e.trim().split(`
16
+ `)){if(!o)continue;let[r,n,i]=o.split("|"),c=r?.replace(/^\//,"")??"";t.set(c,{name:c,status:n==="running"?"running":"stopped",health:i!=="none"?i:void 0})}return Ve.map(o=>t.get(o)??{name:o,status:"not_found"})}catch{let e=Ve.map(async t=>{try{let{stdout:o}=await Ue("docker",["inspect","--format","{{.State.Status}}|{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}",t]),[r,n]=o.trim().split("|");return{name:t,status:r==="running"?"running":"stopped",health:n!=="none"?n:void 0}}catch{return{name:t,status:"not_found"}}});return Promise.all(e)}}async function Mt(){try{return await Ue("docker",["info"]),!0}catch{return!1}}var Nr=[{name:"API",port:8e3,type:"http",path:"/health"},{name:"Web",port:3e3,type:"http",path:"/"},{name:"PostgreSQL",port:5432,type:"tcp"},{name:"Redis",port:6379,type:"tcp"},{name:"MongoDB",port:27017,type:"tcp"},{name:"RabbitMQ",port:5672,type:"tcp"},{name:"ChromaDB",port:8080,type:"tcp"}];async function Lt(e){let o=Nr.map(r=>({...r,port:e?.[r.port]??r.port})).map(r=>r.type==="http"?Gr(r.name,r.port,r.path):$r(r.name,r.port));return Promise.all(o)}async function Gr(e,t,o){let r=Date.now();try{let n=await fetch(`http://localhost:${t}${o}`,{signal:AbortSignal.timeout(5e3)}),i=Date.now()-r;return{name:e,port:t,status:"up",latency:i,details:n.ok?`HTTP ${n.status}`:`HTTP ${n.status} (error)`}}catch{return{name:e,port:t,status:"down",details:"Connection failed"}}}async function $r(e,t){let o=await import("node:net"),r=Date.now();return new Promise(n=>{let i=new o.Socket;i.setTimeout(3e3),i.on("connect",()=>{let c=Date.now()-r;i.destroy(),n({name:e,port:t,status:"up",latency:c})}),i.on("timeout",()=>{i.destroy(),n({name:e,port:t,status:"down"})}),i.on("error",()=>{i.destroy(),n({name:e,port:t,status:"down"})}),i.connect(t,"localhost")})}async function Ot(){return await Mt()?{running:!0,containers:await _t()}:{running:!1,containers:[]}}async function qr(e){e.setStep("Checking"),e.setStatus("Checking service health..."),e.updateData("refreshable",!1);let t=X(),o=t?ie(t):void 0,[r,n]=await Promise.all([Lt(o),Ot()]);e.updateData("services",r),e.updateData("docker",n);let i=r.filter(d=>d.status==="up").length,c=r.length;e.setStep("Results"),e.setStatus(`${i}/${c} services running`),e.updateData("refreshable",!0)}async function Ft(e){for(;await qr(e),await e.waitForInput("exit_or_refresh")==="refresh";);}async function Nt(){let e=H(),{unmount:t}=jr(Hr.createElement(j,{store:e,command:"status"}));await new Promise(o=>setTimeout(o,50));try{await Ft(e)}catch(o){e.setError(o)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as Vr}from"ink";import Ur from"react";async function Gt(e){e.setStep("Stopping"),e.setStatus("Locating GAIA repository...");let t=X();if(!t){e.setError(new Error("Could not find GAIA repository. Run from within a cloned gaia repo."));return}e.updateData("repoPath",t);let o=ie(t);try{await wt(t,r=>{e.setStatus(r)},o),e.setStep("Stopped"),e.setStatus("All services stopped."),e.updateData("stopped",!0)}catch(r){e.setError(new Error(`Failed to stop services: ${r.message}`));return}await e.waitForInput("exit")}async function $t(){let e=H(),{unmount:t}=Vr(Ur.createElement(j,{store:e,command:"stop"}));await new Promise(o=>setTimeout(o,50));try{await Gt(e)}catch(o){e.setError(o)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}var J=new Wr;J.name("gaia").description("CLI tool for setting up and managing GAIA").version("0.1.0");J.command("init").description("Full setup from scratch (clone, configure, start)").action(async()=>{await Rt()});J.command("setup").description("Configure an existing GAIA repository").action(async()=>{await kt()});J.command("status").description("Check health of all GAIA services").action(async()=>{await Nt()});J.command("start").description("Start GAIA services").action(async()=>{await At()});J.command("stop").description("Stop all GAIA services").action(async()=>{await $t()});process.argv.slice(2).length||(J.outputHelp(),process.exit(0));J.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heygaia/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "CLI tool for setting up and managing GAIA",
5
5
  "type": "module",
6
6
  "bin": {