@heygaia/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +111 -0
  2. package/dist/index.js +10 -0
  3. package/package.json +59 -0
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # @heygaia/cli
2
+
3
+ CLI tool for setting up and managing GAIA - your proactive personal AI assistant.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Quick install (recommended)
9
+ curl -fsSL https://heygaia.io/install.sh | sh
10
+
11
+ # Or via npm
12
+ npm install -g @heygaia/cli
13
+
14
+ # Or run without installing
15
+ npx @heygaia/cli init
16
+ ```
17
+
18
+ ## Commands
19
+
20
+ | Command | Description |
21
+ |---------|-------------|
22
+ | `gaia init` | Full setup from scratch - clones repo, installs tools, configures env, starts services |
23
+ | `gaia setup` | Configure an existing GAIA repository (env vars, dependencies) |
24
+ | `gaia start` | Start all GAIA services (auto-detects selfhost vs developer mode) |
25
+ | `gaia stop` | Stop all running GAIA services |
26
+ | `gaia status` | Check health of all services with latency |
27
+
28
+ ### `gaia init`
29
+
30
+ Interactive wizard for first-time setup:
31
+
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)
38
+
39
+ ### `gaia setup`
40
+
41
+ For existing repos that need configuration or reconfiguration. Run from within a cloned GAIA directory:
42
+
43
+ ```bash
44
+ cd /path/to/gaia && gaia setup
45
+ ```
46
+
47
+ ### `gaia start` / `gaia stop`
48
+
49
+ Start or stop services. Automatically detects selfhost vs developer mode from your `.env` configuration.
50
+
51
+ ### `gaia status`
52
+
53
+ Shows health and latency for: API (8000), Web (3000), PostgreSQL (5432), Redis (6379), MongoDB (27017), RabbitMQ (5672), ChromaDB (8080).
54
+
55
+ ## Setup Modes
56
+
57
+ - **Self-Host (Docker)**: Everything runs in Docker. Best for deployment.
58
+ - **Developer (Local)**: Databases in Docker, API + web run locally. Best for contributing.
59
+
60
+ ## Environment Variable Auto-Discovery
61
+
62
+ The CLI discovers env vars from the codebase at runtime:
63
+
64
+ - **API**: Extracted from `apps/api/app/config/settings.py` and `settings_validator.py` via Python AST
65
+ - **Web**: Parsed from `apps/web/.env`
66
+
67
+ No CLI updates needed when new variables are added.
68
+
69
+ ## Development
70
+
71
+ ```bash
72
+ # Dev mode (no build, uses current workspace)
73
+ GAIA_CLI_DEV=true bun packages/cli/src/index.ts <command>
74
+
75
+ # Build
76
+ cd packages/cli && bun run build
77
+
78
+ # Test built CLI
79
+ ./packages/cli/dist/index.js --help
80
+ ```
81
+
82
+ ### Install Script
83
+
84
+ Source of truth: `packages/cli/install.sh`. After modifying, sync to the web app:
85
+
86
+ ```bash
87
+ ./packages/cli/sync-install.sh
88
+ ```
89
+
90
+ This keeps `https://heygaia.io/install.sh` up to date.
91
+
92
+ ### Publishing
93
+
94
+ 1. Update version in `package.json`
95
+ 2. Build: `bun run build`
96
+ 3. Sync install script: `./sync-install.sh`
97
+ 4. Commit and tag: `git tag cli-v<version>`
98
+ 5. Push tag — GitHub Actions publishes to npm
99
+
100
+ ### Troubleshooting
101
+
102
+ | Issue | Fix |
103
+ |-------|-----|
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 |
108
+
109
+ ## License
110
+
111
+ MIT
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import{Command as Or}from"commander";import{render as Er}from"ink";import wr from"react";import{Box as me,Text as z}from"ink";import ir from"react";import{ProgressBar as Qe,Select as Ke,Spinner as Je}from"@inkjs/ui";import{Box as l,Text as s,useInput as J}from"ink";import se from"ink-text-input";import{useEffect as de,useState as L}from"react";import{Box as ie,Text as Xe}from"ink";var S="#00bbff";import{Box as Gt,Text as Ce}from"ink";import{jsx as He,jsxs as We}from"react/jsx-runtime";var Ue=({status:e,step:t})=>t.toLowerCase()==="welcome"?null:We(Gt,{width:"100%",borderStyle:"single",borderColor:"gray",paddingX:1,justifyContent:"space-between",children:[We(Ce,{color:S,children:[He(Ce,{bold:!0,children:"Status:"})," ",t]}),He(Ce,{color:"white",dimColor:!0,children:e})]});import{Box as Ot}from"ink";import qt from"ink-big-text";import $t from"ink-gradient";import{jsx as Ie}from"react/jsx-runtime";var ee=()=>Ie(Ot,{flexDirection:"column",marginTop:1,marginBottom:1,children:Ie($t,{colors:[S,"#b0eaff",S],children:Ie(qt,{text:"GAIA",font:"3d"})})});import{jsx as te,jsxs as ue}from"react/jsx-runtime";var jt=["Welcome","Prerequisites","Repository Setup","Install Tools","Environment Setup","Project Setup","Finished"],Ye=["Detect Repo","Prerequisites","Environment Setup","Project Setup","Finished"],Vt=({currentStep:e,steps:t})=>{let o=t.indexOf(e);return te(ie,{marginBottom:1,children:t.map((r,n)=>{let i=r===e,p=o>n;return ue(ie,{marginRight:2,children:[ue(Xe,{color:i?S:p?"green":"gray",children:[p?"\u2713 ":i?"\u25CF ":"\u25CB ",r]}),n<t.length-1&&te(Xe,{color:"gray",children:" \u203A "})]},r)})})},pe=({children:e,status:t,step:o,steps:r=jt})=>ue(ie,{flexDirection:"column",height:"100%",width:"100%",children:[ue(ie,{flexGrow:1,flexDirection:"column",children:[te(ee,{}),te(Vt,{currentStep:o,steps:r}),te(ie,{flexDirection:"column",flexGrow:1,children:e})]}),te(Ue,{status:t,step:o})]});import{Fragment as uo,jsx as a,jsxs as c}from"react/jsx-runtime";var Ee=({label:e,status:t})=>c(l,{children:[a(l,{marginRight:1,children:t==="pending"?a(Je,{type:"dots"}):t==="success"?a(s,{color:S,children:"\u2714"}):t==="error"?a(s,{color:"red",children:"\u2716"}):a(s,{color:"yellow",children:"\u26A0"})}),a(s,{children:e})]}),Ht=({onConfirm:e})=>(J((t,o)=>{o.return&&e()}),c(l,{flexDirection:"column",paddingX:2,borderStyle:"round",borderColor:S,children:[a(s,{bold:!0,children:"Welcome to the Interactive GAIA Setup"}),c(l,{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:S,children:"Press Enter to start..."})]})),Wt=({portResults:e,onAccept:t,onAbort:o})=>{J((n,i)=>{i.return?t():i.escape&&o()});let r=e.filter(n=>!n.available);return c(l,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:"yellow",children:[a(l,{marginBottom:1,children:a(s,{bold:!0,color:"yellow",children:"Port Conflicts Detected"})}),e.map(n=>c(l,{children:[c(s,{color:n.available?"green":n.alternative?"yellow":"red",children:[n.available?"\u2714":n.alternative?"\u26A0":"\u2716"," "]}),c(s,{children:[n.service," (:",n.port,")"]}),!n.available&&c(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)),c(l,{marginTop:1,flexDirection:"column",children:[r.some(n=>!n.alternative)&&a(l,{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(l,{marginTop:1,children:c(s,{children:[a(s,{color:"green",bold:!0,children:"Enter"})," to continue with alternatives ",a(s,{color:"yellow",bold:!0,children:"Escape"})," to abort"]})})]})]})},Ut=({defaultValue:e,onSubmit:t})=>{let[o,r]=L(e);return c(l,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:S,children:[a(s,{children:"Where should we clone the repository?"}),c(l,{children:[a(s,{color:S,children:"\u279C "}),a(se,{value:o,onChange:r,onSubmit:t})]}),c(s,{color:"gray",children:["(Press Enter for default: ",e,")"]})]})},Xt=({setupMode:e,repoPath:t,portOverrides:o,onConfirm:r})=>{J((m,f)=>{f.return&&r()});let n=e||"developer",i=t||"./gaia",p=o?.[3e3]??3e3,u=o?.[8e3]??8e3;return c(l,{flexDirection:"column",marginTop:2,borderStyle:"round",borderColor:S,padding:1,children:[a(s,{color:S,bold:!0,children:"You are all set!"}),c(l,{marginTop:1,flexDirection:"column",children:[a(s,{bold:!0,children:"To start GAIA, run:"}),c(l,{marginTop:1,padding:1,borderStyle:"single",borderColor:"gray",flexDirection:"column",children:[c(s,{color:"cyan",children:["$ cd ",i]}),a(s,{color:"cyan",children:"$ gaia start"})]}),a(l,{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)"})})]}),c(l,{marginTop:1,flexDirection:"column",children:[a(s,{bold:!0,children:"Access GAIA at:"}),c(l,{marginLeft:2,flexDirection:"column",children:[c(s,{children:["Web:"," ",c(s,{color:"cyan",bold:!0,children:["http://localhost:",p]})]}),c(s,{children:["API:"," ",c(s,{color:"cyan",bold:!0,children:["http://localhost:",u]})]})]})]}),a(we,{}),a(l,{marginTop:1,children:a(s,{dimColor:!0,children:"Press Enter to exit"})})]})},we=()=>c(l,{marginTop:1,flexDirection:"column",children:[a(s,{bold:!0,children:"Available commands:"}),c(l,{marginLeft:2,flexDirection:"column",children:[c(s,{children:[c(s,{color:S,bold:!0,children:["gaia start"," "]}),a(s,{color:"gray",children:" Start all services"})]}),c(s,{children:[c(s,{color:S,bold:!0,children:["gaia stop"," "]}),a(s,{color:"gray",children:" Stop all services"})]}),c(s,{children:[a(s,{color:S,bold:!0,children:"gaia status"}),a(s,{color:"gray",children:" Check service health"})]}),c(s,{children:[c(s,{color:S,bold:!0,children:["gaia setup"," "]}),a(s,{color:"gray",children:" Reconfigure environment"})]})]})]}),Yt=({phase:e,progress:t,isComplete:o,logs:r,title:n})=>c(l,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:S,children:[a(l,{marginBottom:1,children:a(s,{bold:!0,color:S,children:n||"Installing Dependencies"})}),c(l,{flexDirection:"column",gap:1,children:[a(l,{children:o?c(s,{color:"green",children:["\u2713 ",e]}):a(Je,{label:e||"Preparing..."})}),!o&&t>0&&a(l,{width:50,children:a(Qe,{value:t})}),!o&&r&&r.length>0&&a(l,{flexDirection:"column",marginTop:1,borderStyle:"single",borderColor:"gray",paddingX:1,paddingY:0,minHeight:6,children:r.map((i,p)=>a(s,{color:"gray",wrap:"truncate",children:i},p))})]})]});var Pe=({onSelect:e})=>c(l,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:S,children:[a(s,{bold:!0,children:"Setup Mode"}),a(l,{marginTop:1,children:a(s,{color:"gray",children:"How do you want to run GAIA?"})}),a(l,{marginTop:1,children:a(Ke,{options:[{label:"Self-Host (Docker)",value:"selfhost"},{label:"Developer Mode (Local)",value:"developer"}],onChange:o=>e(o)})}),c(l,{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)"})]})]}),De=({onSelect:e})=>c(l,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:S,children:[a(s,{bold:!0,children:"Environment Variables Setup"}),a(l,{marginTop:1,children:a(s,{color:"gray",children:"Choose how you want to configure environment variables:"})}),a(l,{marginTop:1,children:a(Ke,{options:[{label:"Manual Setup (Recommended)",value:"manual"},{label:"Infisical (Advanced)",value:"infisical"}],onChange:o=>e(o)})}),c(l,{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)"})]})]}),Re=({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,p]=L(null),u=[{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"}];J((f,g)=>{if(g.tab||g.downArrow)n(d=>d<u.length-1?d+1:d);else if(g.upArrow)n(d=>d>0?d-1:d);else if(g.return){if(r<u.length-1){n(y=>y+1);return}let d=u.filter(y=>!t[y.key].trim());if(d.length>0){p(`Required: ${d.map(h=>h.key).join(", ")}`);let y=u.findIndex(h=>!t[h.key].trim());y>=0&&n(y);return}e(t)}});let m=u[r];return c(l,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:S,children:[a(l,{marginBottom:1,children:a(s,{bold:!0,color:S,children:"Infisical Configuration"})}),a(l,{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."})}),c(l,{marginBottom:1,flexDirection:"column",children:[a(s,{color:"gray",children:"Configure your Infisical credentials."}),c(s,{color:"gray",dimColor:!0,children:["Visit"," ",a(s,{color:"cyan",underline:!0,children:"app.infisical.com"})," ","to get these values."]})]}),u.map((f,g)=>{let d=f.key.includes("SECRET")||f.key.includes("TOKEN");return c(l,{flexDirection:"column",marginBottom:1,children:[a(l,{children:c(s,{color:g===r?S:"white",children:[g===r?"\u25B8 ":" ",f.key,":"]})}),a(l,{marginLeft:2,children:a(s,{color:"gray",dimColor:!0,children:f.description})}),g===r?a(l,{marginLeft:2,children:a(se,{value:t[f.key],onChange:y=>{o(h=>({...h,[f.key]:y})),p(null)},placeholder:"Enter value...",mask:d?"*":void 0})}):a(l,{marginLeft:2,children:a(s,{color:t[f.key]?"green":"gray",children:t[f.key]?d?`\u2713 ${"*".repeat(8)}`:`\u2713 ${t[f.key]}`:"(not set)"})})]},f.key)}),i&&a(l,{marginTop:1,children:a(s,{color:"red",children:i})}),a(l,{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]=L(()=>{let y={};for(let h of e.variables)y[h.name]=h.defaultValue||"";return y}),[p,u]=L(0),[m,f]=L(null);de(()=>{let y={};for(let h of e.variables)y[h.name]=h.defaultValue||"";i(y),u(0),f(null)},[e.name]),J((y,h)=>{if(h.tab||h.downArrow)u(x=>x<e.variables.length-1?x+1:x);else if(h.upArrow)u(x=>x>0?x-1:x);else if(h.escape){let x=e.variables.filter(v=>v.required&&!n[v.name]?.trim());if(x.length>0){f(`Required fields cannot be skipped: ${x.map(v=>v.name).join(", ")}`);return}r(n)}});let g=()=>{if(p<e.variables.length-1)u(p+1);else{let y=e.variables.filter(h=>h.required&&!n[h.name]?.trim());if(y.length>0){f(`Required fields are missing: ${y.map(h=>h.name).join(", ")}`);return}f(null),r(n)}},d=e.variables.some(y=>y.required);return c(l,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:m?"red":S,children:[c(l,{justifyContent:"space-between",children:[c(s,{bold:!0,children:["Configure ",e.name]}),c(s,{color:"gray",children:["Group ",t+1," / ",o]})]}),c(l,{marginTop:1,flexDirection:"column",children:[c(l,{children:[c(s,{color:"cyan",bold:!0,children:["Purpose:"," "]}),a(s,{color:"white",children:e.description})]}),e.affectedFeatures&&c(l,{children:[c(s,{color:"cyan",bold:!0,children:["Affects:"," "]}),a(s,{color:"gray",children:e.affectedFeatures})]}),e.docsUrl&&c(l,{marginTop:1,children:[a(s,{color:"green",children:"\u{1F4D6} Docs: "}),a(s,{color:"blue",underline:!0,children:e.docsUrl})]})]}),a(l,{marginTop:1,flexDirection:"column",children:e.variables.map((y,h)=>{let x=h===p,v=!!y.defaultValue;return c(l,{flexDirection:"column",marginBottom:1,children:[c(l,{children:[c(s,{color:x?S:"gray",bold:x,children:[x?"\u279C ":" ",y.name]}),y.required&&c(s,{color:"red",bold:!0,children:[" ","*"]}),v&&!x&&c(s,{color:"gray",dimColor:!0,children:[" ","(default: ",y.defaultValue,")"]})]}),x&&a(l,{marginLeft:2,children:a(se,{value:n[y.name]||"",onChange:T=>{i(C=>({...C,[y.name]:T})),m&&f(null)},onSubmit:g,placeholder:v?`Default: ${y.defaultValue}`:y.required?"Enter a value (required)":"Press Enter to skip"})})]},y.name)})}),m&&a(l,{marginTop:1,children:c(s,{color:"red",bold:!0,children:["\u26A0 ",m]})}),a(l,{marginTop:1,flexDirection:"column",children:c(s,{color:"gray",dimColor:!0,children:["\u21B5 Enter to next field \u2022 Tab/\u2193 move down \u2022 \u2191 move up",!d&&" \u2022 ESC skip group"]})})]})},Ae=({alternatives:e,onSubmit:t})=>{let[o,r]=L(new Set),[n,i]=L({}),[p,u]=L(0),[m,f]=L(null);de(()=>{let T={};for(let C of e)for(let I of C.variables)T[I.name]=I.defaultValue||"";i(T)},[e]);let g=[];for(let T=0;T<e.length;T++)if(g.push({type:"provider",categoryIndex:T}),o.has(T)){let C=e[T];if(C)for(let I=0;I<C.variables.length;I++)g.push({type:"field",categoryIndex:T,fieldIndex:I})}g.push({type:"submit"});let d=g[p],y=d?.type==="field",h=d?.type==="submit";J((T,C)=>{let I=Math.min(p,g.length-1);if(I!==p){u(I);return}if(y)C.upArrow?u(E=>Math.max(0,E-1)):(C.downArrow||C.tab)&&u(E=>Math.min(g.length-1,E+1));else if(h)C.upArrow?u(E=>Math.max(0,E-1)):(C.return||T===" ")&&v();else if(C.upArrow)u(E=>Math.max(0,E-1));else if(C.downArrow||C.tab)u(E=>Math.min(g.length-1,E+1));else if((C.return||T===" ")&&d?.type==="provider"){let E=d.categoryIndex;r(V=>{let R=new Set(V);return R.has(E)?R.delete(E):R.add(E),R}),m&&f(null)}});let x=()=>{m&&f(null),u(T=>Math.min(g.length-1,T+1))},v=()=>{let T=[],C={};for(let I of o){let E=e[I];if(!E)continue;if(E.variables.some(R=>n[R.name]?.trim())){T.push(E.name);for(let R of E.variables){let le=n[R.name];le&&(C[R.name]=le)}}}if(T.length===0){o.size===0?f("Enable at least one provider (press Space or Enter)"):f("Enter a value for at least one field");return}t(T,C)};return c(l,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:m?"red":S,children:[c(l,{justifyContent:"space-between",children:[a(s,{bold:!0,children:"Configure AI Provider"}),a(s,{color:"yellow",children:"* At least one required"})]}),a(l,{marginTop:1,children:a(s,{color:"gray",children:"Enable and configure at least one AI provider below:"})}),a(l,{marginTop:1,flexDirection:"column",children:e.map((T,C)=>{let I=o.has(C),E=g.findIndex(R=>R.type==="provider"&&R.categoryIndex===C),V=p===E;return c(l,{flexDirection:"column",marginBottom:1,children:[c(l,{children:[a(s,{color:V?S:void 0,bold:V,children:V?"\u279C ":" "}),a(s,{color:I?"green":"gray",children:I?"[\u2714]":"[ ]"}),c(s,{color:I?S:"gray",bold:I,children:[" ",T.name]}),T.description&&c(s,{color:"gray",dimColor:!0,children:[" ","- ",T.description]})]}),V&&T.docsUrl&&c(l,{marginLeft:6,children:[a(s,{color:"yellow",children:"\u{1F4D6} "}),a(s,{color:"blue",underline:!0,children:T.docsUrl})]}),I&&a(l,{marginLeft:4,flexDirection:"column",marginTop:1,children:T.variables.map((R,le)=>{let Mt=g.findIndex(ae=>ae.type==="field"&&ae.categoryIndex===C&&ae.fieldIndex===le),Z=p===Mt,Ve=!!R.defaultValue,Te=n[R.name]||"";return c(l,{flexDirection:"column",marginBottom:1,children:[c(l,{children:[c(s,{color:Z?S:"gray",bold:Z,children:[Z?" \u279C ":" ",R.name]}),!Z&&Te&&a(s,{color:"green",children:" \u2713"}),!Z&&!Te&&Ve&&c(s,{color:"gray",dimColor:!0,children:[" ","(default: ",R.defaultValue,")"]})]}),Z&&a(l,{marginLeft:4,children:a(se,{value:Te,onChange:ae=>{i(Nt=>({...Nt,[R.name]:ae})),m&&f(null)},onSubmit:x,placeholder:Ve?`Default: ${R.defaultValue}`:"Enter value..."})})]},R.name)})})]},T.name)})}),m&&a(l,{marginTop:1,children:c(s,{color:"red",bold:!0,children:["\u26A0 ",m]})}),c(l,{marginTop:1,children:[a(s,{color:h?S:void 0,bold:h,children:h?"\u279C ":" "}),a(l,{borderStyle:"round",borderColor:h?S:"gray",paddingX:2,children:a(s,{color:h?S:"gray",bold:h,children:"Continue \u2192"})})]}),a(l,{marginTop:1,children:a(s,{color:"gray",dimColor:!0,children:"\u2191/\u2193 navigate \u2022 Space/Enter toggle/select \u2022 Tab skip field"})})]})},ke=({currentVar:e,currentIndex:t,totalCount:o,onSubmit:r,onSkip:n})=>{let[i,p]=L(e.defaultValue||""),[u,m]=L(null);de(()=>{p(e.defaultValue||""),m(null)},[e.name]),J((d,y)=>{if(y.escape){if(e.required&&!i.trim()){m("This field is required and cannot be skipped");return}n()}});let f=d=>{if(e.required&&!d.trim()){m("This field is required");return}m(null),r(d)},g=!!e.defaultValue;return c(l,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:u?"red":S,children:[c(l,{justifyContent:"space-between",children:[a(s,{bold:!0,children:"Configure Environment Variables"}),c(s,{color:"gray",children:[t+1," / ",o]})]}),c(l,{marginTop:1,flexDirection:"column",children:[c(l,{children:[a(s,{color:S,bold:!0,children:e.name}),e.required?c(s,{color:"red",bold:!0,children:[" ","* required"]}):c(s,{color:"gray",dimColor:!0,children:[" ","(optional)"]})]}),c(l,{marginTop:1,children:[c(s,{color:"cyan",bold:!0,children:["Category:"," "]}),a(s,{color:"white",children:e.category})]}),c(l,{children:[c(s,{color:"cyan",bold:!0,children:["Purpose:"," "]}),a(s,{color:"white",children:e.description})]}),e.affectedFeatures&&c(l,{children:[c(s,{color:"cyan",bold:!0,children:["Affects:"," "]}),a(s,{color:"gray",children:e.affectedFeatures})]}),e.docsUrl&&c(l,{marginTop:1,children:[a(s,{color:"green",children:"\u{1F4D6} Docs: "}),a(s,{color:"blue",underline:!0,children:e.docsUrl})]}),g&&c(l,{marginTop:1,children:[c(s,{color:"green",bold:!0,children:["Default:"," "]}),a(s,{color:"white",children:e.defaultValue})]})]}),c(l,{marginTop:1,children:[a(s,{color:S,children:"\u279C "}),a(se,{value:i,onChange:d=>{p(d),u&&m(null)},onSubmit:f,placeholder:g?"Press Enter to use default":e.required?"Enter a value (required)":"Press Enter to skip"})]}),u&&a(l,{marginTop:1,children:c(s,{color:"red",bold:!0,children:["\u26A0 ",u]})}),a(l,{marginTop:1,flexDirection:"column",children:e.required?a(s,{color:"yellow",dimColor:!0,children:"\u21B5 Enter to confirm (required field)"}):g?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]=L(e.currentState);return de(()=>{let r=()=>o({...e.currentState});return e.on("change",r),()=>{e.off("change",r)}},[e]),c(pe,{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&&c(l,{flexDirection:"column",borderStyle:"round",paddingX:1,borderColor:S,children:[a(s,{bold:!0,children:"System Checks"}),c(l,{flexDirection:"column",marginTop:1,children:[a(Ee,{label:"Git",status:t.data.checks.git}),a(Ee,{label:"Docker",status:t.data.checks.docker}),a(Ee,{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(Ut,{defaultValue:t.inputRequest.meta.default,onSubmit:r=>e.submitInput(r)}),t.step==="Repository Setup"&&c(l,{flexDirection:"column",borderStyle:"round",padding:1,borderColor:S,children:[a(s,{bold:!0,children:"Cloning Repository"}),c(l,{marginTop:1,flexDirection:"column",children:[a(Qe,{value:t.data.repoProgress||0}),t.data.repoPhase&&a(l,{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(De,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_infisical"&&a(Re,{onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_var"&&t.data.currentEnvVar&&a(ke,{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(Xt,{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(Yt,{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(l,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:c(s,{color:"red",children:["Error: ",t.error.message]})})]})};import{Spinner as Qt}from"@inkjs/ui";import{Box as G,Text as F,useInput as Kt}from"ink";import{useEffect as Jt,useState as zt}from"react";import{jsx as N,jsxs as A}from"react/jsx-runtime";var Ze=({store:e,command:t})=>{let[o,r]=zt(e.currentState);Jt(()=>{let i=()=>r({...e.currentState});return e.on("change",i),()=>{e.off("change",i)}},[e]),Kt((i,p)=>{(p.return||p.escape)&&(o.data.started||o.data.stopped||o.error)&&e.submitInput("exit")});let n=t==="start";return A(G,{flexDirection:"column",width:"100%",children:[N(ee,{}),(o.step==="Starting"||o.step==="Stopping")&&A(G,{flexDirection:"column",marginTop:1,paddingX:2,borderStyle:"round",borderColor:S,children:[N(Qt,{label:o.status||"Working..."}),o.data.repoPath&&N(G,{marginTop:1,children:A(F,{color:"gray",children:["Repository: ",o.data.repoPath]})}),o.data.setupMode&&N(G,{children:A(F,{color:"gray",children:["Mode: ",o.data.setupMode]})})]}),o.step==="Running"&&o.data.started&&A(G,{flexDirection:"column",marginTop:1,paddingX:2,paddingY:1,borderStyle:"round",borderColor:"green",children:[A(F,{color:"green",bold:!0,children:["\u2713"," GAIA is running!"]}),o.data.setupMode!=="developer"&&A(G,{marginTop:1,flexDirection:"column",children:[A(F,{children:["Web:"," ",A(F,{color:"cyan",bold:!0,children:["http://localhost:",o.data.webPort||3e3]})]}),A(F,{children:["API:"," ",A(F,{color:"cyan",bold:!0,children:["http://localhost:",o.data.apiPort||8e3]})]})]}),o.data.setupMode==="developer"&&A(G,{marginTop:1,flexDirection:"column",children:[N(F,{color:"gray",children:"Dev servers started in background."}),A(F,{color:"gray",children:["Logs: ",N(F,{color:S,children:"dev-start.log"})," in your repo root."]}),A(F,{color:"gray",children:["Run ",N(F,{color:S,children:"gaia stop"})," to shut down."]})]}),N(G,{marginTop:1,children:N(F,{dimColor:!0,children:"Press Enter to exit"})})]}),o.step==="Stopped"&&o.data.stopped&&A(G,{flexDirection:"column",marginTop:1,paddingX:2,paddingY:1,borderStyle:"round",borderColor:S,children:[A(F,{color:S,bold:!0,children:["\u2713"," All GAIA services stopped."]}),N(G,{marginTop:1,children:N(F,{dimColor:!0,children:"Press Enter to exit"})})]}),o.error&&A(G,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:[A(F,{color:"red",children:["Error: ",o.error.message]}),N(G,{marginTop:1,children:N(F,{dimColor:!0,children:"Press Enter to exit"})})]})]})};import{ProgressBar as Zt,Spinner as Fe}from"@inkjs/ui";import{Box as D,Text as w,useInput as et}from"ink";import{useEffect as er,useState as tr}from"react";import{jsx as b,jsxs as B}from"react/jsx-runtime";var tt=({store:e})=>{let[t,o]=tr(e.currentState);return er(()=>{let r=()=>o({...e.currentState});return e.on("change",r),()=>{e.off("change",r)}},[e]),B(pe,{status:t.status,step:t.step,steps:Ye,children:[t.step==="Detect Repo"&&B(D,{flexDirection:"column",paddingX:2,borderStyle:"round",borderColor:S,children:[b(w,{bold:!0,children:"Detecting GAIA Repository"}),b(D,{marginTop:1,children:b(Fe,{label:"Searching for repository..."})}),t.data.repoPath&&b(D,{marginTop:1,children:B(w,{color:"green",children:["Found: ",t.data.repoPath]})})]}),t.step==="Prerequisites"&&t.data.checks&&B(D,{flexDirection:"column",borderStyle:"round",paddingX:1,borderColor:S,children:[b(w,{bold:!0,children:"System Checks"}),B(D,{flexDirection:"column",marginTop:1,children:[b(_e,{label:"Git",status:t.data.checks.git}),b(_e,{label:"Docker",status:t.data.checks.docker}),b(_e,{label:"Mise",status:t.data.checks.mise})]})]}),t.inputRequest?.id==="port_conflicts"&&t.data.portConflicts&&b(rr,{portResults:t.data.portConflicts,onAccept:()=>e.submitInput("accept"),onAbort:()=>e.submitInput("abort")}),t.inputRequest?.id==="setup_mode"&&b(Pe,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_method"&&b(De,{onSelect:r=>e.submitInput(r)}),t.inputRequest?.id==="env_infisical"&&b(Re,{onSubmit:r=>e.submitInput(r)}),t.step==="Environment Setup"&&t.inputRequest?.id==="env_var"&&t.data.currentEnvVar&&b(ke,{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&&b(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&&b(Ae,{alternatives:t.data.alternativeGroups,onSubmit:(r,n)=>e.submitInput({selectedGroups:r,values:n})}),t.step==="Project Setup"&&B(D,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:S,children:[b(D,{marginBottom:1,children:b(w,{bold:!0,color:S,children:"Project Setup"})}),B(D,{flexDirection:"column",gap:1,children:[b(D,{children:t.data.dependencyComplete?B(w,{color:"green",children:["\u2713"," ",t.data.dependencyPhase]}):b(Fe,{label:t.data.dependencyPhase||"Preparing..."})}),!t.data.dependencyComplete&&t.data.dependencyProgress>0&&b(D,{width:50,children:b(Zt,{value:t.data.dependencyProgress})}),!t.data.dependencyComplete&&t.data.dependencyLogs?.length>0&&b(D,{flexDirection:"column",marginTop:1,borderStyle:"single",borderColor:"gray",paddingX:1,minHeight:6,children:t.data.dependencyLogs.map((r,n)=>b(w,{color:"gray",wrap:"truncate",children:r},n))})]})]}),t.step==="Finished"&&b(or,{setupMode:t.data.setupMode,repoPath:t.data.repoPath,onConfirm:()=>e.submitInput(!0)}),t.error&&b(D,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:B(w,{color:"red",children:["Error: ",t.error.message]})})]})},_e=({label:e,status:t})=>B(D,{children:[b(D,{marginRight:1,children:t==="pending"?b(Fe,{type:"dots"}):t==="success"?b(w,{color:S,children:"\u2714"}):t==="error"?b(w,{color:"red",children:"\u2716"}):b(w,{color:"yellow",children:"\u26A0"})}),b(w,{children:e})]}),rr=({portResults:e,onAccept:t,onAbort:o})=>(et((r,n)=>{n.return?t():n.escape&&o()}),B(D,{flexDirection:"column",marginTop:1,paddingX:1,borderStyle:"round",borderColor:"yellow",children:[b(w,{bold:!0,color:"yellow",children:"Port Conflicts Detected"}),e.map(r=>B(D,{children:[B(w,{color:r.available?"green":"red",children:[r.available?"\u2714":"\u2716"," "]}),B(w,{children:[r.service," (:",r.port,")"]}),!r.available&&B(w,{color:"gray",children:[" ","- in use",r.usedBy?` by ${r.usedBy}`:"",r.alternative?` (alt: :${r.alternative})`:""]})]},r.port)),b(D,{marginTop:1,children:B(w,{children:[b(w,{color:"green",bold:!0,children:"Enter"})," continue ",b(w,{color:"yellow",bold:!0,children:"Escape"})," abort"]})})]})),or=({setupMode:e,repoPath:t,onConfirm:o})=>(et((i,p)=>{p.return&&o()}),B(D,{flexDirection:"column",marginTop:2,borderStyle:"round",borderColor:S,padding:1,children:[b(w,{color:S,bold:!0,children:"Setup Complete!"}),B(D,{marginTop:1,flexDirection:"column",children:[b(w,{bold:!0,children:"To start GAIA, run:"}),B(D,{marginTop:1,padding:1,borderStyle:"single",borderColor:"gray",flexDirection:"column",children:[B(w,{color:"cyan",children:["$ cd ",t||"."]}),b(w,{color:"cyan",children:"$ gaia start"})]}),b(D,{marginTop:1,children:b(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)"})})]}),b(we,{}),b(D,{marginTop:1,children:b(w,{dimColor:!0,children:"Press Enter to exit"})})]}));import{Spinner as nr}from"@inkjs/ui";import{Box as k,Text as _,useInput as ar}from"ink";import{useEffect as rt,useState as ot}from"react";import{jsx as P,jsxs as M}from"react/jsx-runtime";var nt=({store:e})=>{let[t,o]=ot(e.currentState),[r,n]=ot(!1);return rt(()=>{let i=()=>o({...e.currentState});return e.on("change",i),()=>{e.off("change",i)}},[e]),rt(()=>{t.step==="Results"&&n(!1)},[t.step]),ar((i,p)=>{(p.return||p.escape)&&t.step==="Results"&&e.submitInput("exit"),i==="r"&&t.step==="Results"&&t.data.refreshable&&!r&&(n(!0),e.submitInput("refresh"))}),M(k,{flexDirection:"column",width:"100%",children:[P(ee,{}),t.step==="Checking"&&P(k,{marginTop:1,children:P(nr,{label:t.data.services?"Refreshing service health...":"Checking service health..."})}),t.step==="Results"&&t.data.services&&M(k,{flexDirection:"column",children:[M(k,{flexDirection:"column",borderStyle:"round",borderColor:S,paddingX:2,paddingY:1,children:[P(_,{bold:!0,color:S,children:"GAIA Service Status"}),M(k,{marginTop:1,flexDirection:"column",children:[M(k,{children:[P(k,{width:22,children:P(_,{bold:!0,children:"Service"})}),P(k,{width:10,children:P(_,{bold:!0,children:"Status"})}),P(k,{width:10,children:P(_,{bold:!0,children:"Latency"})})]}),P(_,{color:"gray",children:"\u2500".repeat(42)}),t.data.services.map(i=>M(k,{children:[P(k,{width:22,children:M(_,{children:[i.name," (:",i.port,")"]})}),P(k,{width:10,children:P(_,{color:i.status==="up"?"green":"red",bold:!0,children:i.status==="up"?"\u2713 UP":"\u2717 DOWN"})}),P(k,{width:10,children:P(_,{color:"gray",children:i.latency?`${i.latency}ms`:"--"})})]},i.name))]})]}),t.data.docker&&M(k,{flexDirection:"column",borderStyle:"round",borderColor:"gray",paddingX:2,paddingY:1,marginTop:1,children:[P(_,{bold:!0,children:"Docker Containers"}),M(_,{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(k,{marginTop:1,flexDirection:"column",children:t.data.docker.containers.map(i=>M(k,{children:[M(_,{color:i.status==="running"?"green":"red",children:[i.status==="running"?"\u2713":"\u2717"," "]}),P(_,{children:i.name}),i.health&&M(_,{color:"gray",children:[" (",i.health,")"]})]},i.name))})]}),P(k,{marginTop:1,children:M(_,{dimColor:!0,children:["Press Enter or Escape to exit \xB7 Press"," ",P(_,{color:S,children:"r"})," to refresh"]})})]}),t.error&&P(k,{borderStyle:"single",borderColor:"red",padding:1,marginTop:2,children:M(_,{color:"red",children:["Error: ",t.error.message]})})]})};import{jsx as O,jsxs as ce}from"react/jsx-runtime";var sr=["init","setup","status","start","stop"],Le=class extends ir.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}render(){return this.state.error?ce(me,{flexDirection:"column",padding:1,children:[O(z,{color:"red",bold:!0,children:"An unexpected error occurred:"}),O(z,{color:"red",children:this.state.error.message}),this.state.error.stack&&O(me,{marginTop:1,children:O(z,{color:"gray",dimColor:!0,children:this.state.error.stack})})]}):this.props.children}},cr=({store:e,command:t})=>{switch(t){case"init":return O(ze,{store:e});case"setup":return O(tt,{store:e});case"status":return O(nt,{store:e});case"start":case"stop":return O(Ze,{store:e,command:t});default:return ce(me,{flexDirection:"column",padding:1,children:[ce(z,{color:"red",children:["Unknown command: ",t]}),ce(me,{marginTop:1,flexDirection:"column",children:[O(z,{bold:!0,children:"Available commands:"}),sr.map(o=>ce(z,{children:[" ",O(z,{color:"cyan",children:o})]},o))]})]})}},$=({store:e,command:t})=>O(Le,{children:O(cr,{store:e,command:t})});import{EventEmitter as lr}from"events";var Me=class extends lr{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 Me;import*as ne from"fs";import*as ht from"path";import*as oe from"node:fs";import*as re from"node:path";import{execa as at}from"execa";var it={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/"}},st={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 Ne(e,t){return it[t][e]??st[t][e]}async function ct(e){let t=re.join(e,"apps/api/scripts/dump_config_schema.py"),o=re.join(e,"apps/api/app/config/settings_validator.py"),r=re.join(e,"apps/api/app/config/settings.py");if(!oe.existsSync(t))throw new Error("dump_config_schema.py not found in apps/api/scripts");try{try{let{stdout:n}=await at("python3",[t,o,r],{cwd:e});return JSON.parse(n)}catch{let{stdout:n}=await at("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 lt(e){let t=re.join(e,"apps","web",".env.local"),o=oe.existsSync(t)?t:re.join(e,"apps","web",".env");if(!oe.existsSync(o))return[];let r=oe.readFileSync(o,"utf-8"),n=[],i="General";for(let p of r.split(`
3
+ `)){let u=p.trim();if(u.startsWith("#")&&!u.startsWith("#=")){let d=u.replace(/^#+\s*/,"").trim();d&&!d.startsWith("These are")&&(i=d);continue}if(!u||u.startsWith("#"))continue;let m=u.indexOf("=");if(m===-1)continue;let f=u.substring(0,m).trim(),g=u.substring(m+1).trim();n.push({name:f,value:g,category:i})}return n}function ut(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 pt(e,t){for(let[o,r]of Object.entries(t)){let n=Number(o);for(let[i,p]of Object.entries(e)){let u=new RegExp(`:${n}(?=[/\\s]|$)`,"g");e[i]=p.replaceAll(u,`:${r}`)}}}function dt(e,t){return e.map(o=>({...o,variables:o.variables.map(r=>{let n=Ne(r.name,t);return{...r,defaultValue:n||r.defaultValue}})}))}function Ge(){return Object.keys(it.selfhost)}function mt(e){return{...st[e]}}import*as U from"fs";import*as Oe from"path";function ft(e){U.existsSync(e)&&U.copyFileSync(e,`${e}.bak`)}function gt(e,t){let o=Oe.join(e,".env");ft(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(u){for(let f of n)if(u===f||u.startsWith(`${f}_`))return f;let m=u.split("_");return m.length===1?"Core":m[0]||"Core"}let p=new Map;for(let[u,m]of Object.entries(t)){let f=i(u);p.has(f)||p.set(f,[]);let d=/[\s#"'\\]/.test(m)||m===""?`"${m.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:m;p.get(f).push(`${u}=${d}`)}for(let[u,m]of p.entries())r.push(`# ${u} Configuration`),r.push(...m),r.push("");U.writeFileSync(o,r.join(`
4
+ `),"utf-8")}function xt(e,t,o){let r=Oe.join(e,"apps","web",".env.local");ft(r);let n=lt(e),i=ut(t,o),p=["# GAIA Web App Environment Configuration","# Generated by GAIA CLI",`# Created: ${new Date().toISOString()}`,""],u=new Map;for(let m of n){u.has(m.category)||u.set(m.category,[]);let f=i[m.name]??m.value;u.get(m.category).push({name:m.name,value:f})}if(n.length===0){p.push("# Core URLs");for(let[m,f]of Object.entries(i))p.push(`${m}=${f}`);p.push("")}else for(let[m,f]of u.entries()){p.push(`# ${m}`);for(let{name:g,value:d}of f)p.push(`${g}=${d}`);p.push("")}U.writeFileSync(r,p.join(`
5
+ `),"utf-8")}var dr=e=>new Promise(t=>setTimeout(t,e));async function fe(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 p=Ge();for(let m of p){let f=Ne(m,r);f&&(i[m]=f)}let u=mt(r);for(let[m,f]of Object.entries(u))i[m]=f;if(n==="infisical")await mr(e,i),e.setStatus("Infisical credentials saved. Ensure your Infisical project contains all required variables.");else try{await fr(e,t,i,r)}catch(m){e.setError(m);return}o&&pt(i,o);try{await gr(e,t,i,r,o)}catch(m){e.setError(m);return}await dr(1e3)}async function mr(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 fr(e,t,o,r){e.setStatus("Parsing environment variables...");let n;try{n=await ct(t),n=dt(n,r)}catch(x){throw new Error(`Failed to parse settings: ${x.message}`)}let i=new Set,p=[],u=new Set;for(let x of n)if(x.alternativeGroup&&!u.has(x.name)){let v=n.find(T=>T.name===x.alternativeGroup);v&&(p.push([x,v]),i.add(x.name),i.add(v.name),u.add(x.name),u.add(v.name))}let m=n.filter(x=>x.variables.length===1&&!i.has(x.name)),f=n.filter(x=>x.variables.length>1&&!i.has(x.name));for(let x of p){e.updateData("alternativeGroups",x),e.setStatus("Choose an AI provider...");let v=await e.waitForInput("env_alternatives");for(let[T,C]of Object.entries(v.values))C&&(o[T]=C)}let g=Ge(),y=[...m.flatMap(x=>x.variables).filter(x=>!g.includes(x.name))].sort((x,v)=>x.required&&!v.required?-1:!x.required&&v.required?1:0);e.updateData("envVarTotal",y.length);for(let x=0;x<y.length;x++){let v=y[x];if(!v)continue;e.updateData("currentEnvVar",v),e.updateData("envVarIndex",x),e.setStatus(`Configuring ${v.name}...`);let T=await e.waitForInput("env_var",{varName:v.name});(T||v.required||v.defaultValue)&&(o[v.name]=T||v.defaultValue||"")}let h=[...f].filter(x=>!x.variables.every(v=>g.includes(v.name))).sort((x,v)=>{let T=x.variables.some(I=>I.required),C=v.variables.some(I=>I.required);return T&&!C?-1:!T&&C?1:0});e.updateData("envGroupTotal",h.length);for(let x=0;x<h.length;x++){let v=h[x];if(!v)continue;e.updateData("currentEnvGroup",v),e.updateData("envGroupIndex",x),e.setStatus(`Configuring ${v.name}...`);let T=await e.waitForInput("env_group",{groupName:v.name});for(let[C,I]of Object.entries(T)){let E=v.variables.find(V=>V.name===C);(I||E?.required||E?.defaultValue)&&(o[C]=I||E?.defaultValue||"")}}}async function gr(e,t,o,r,n){e.setStatus("Writing API environment file...");try{let i=ht.join(t,"apps","api");gt(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{xt(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 xr}from"execa";import ge from"fs";import hr from"simple-git";async function St(e,t,o){if(ge.existsSync(e)){let r=`${e}/.git`;if(!ge.existsSync(r))throw new Error(`Directory ${e} exists but is not a git repository`);await hr().cwd(e).pull(),o(100,"Already exists, pulled latest")}else try{let r=xr("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 p=i.match(/Receiving objects:\s+(\d+)%\s+\((\d+)\/(\d+)\)/);if(p?.[1]){let m=Math.min(100,parseInt(p[1],10)),f=p[2],g=p[3];o(10+Math.floor(m*.5),`Receiving objects: ${f}/${g}`)}let u=i.match(/Resolving deltas:\s+(\d+)%\s+\((\d+)\/(\d+)\)/);if(u?.[1]){let m=Math.min(100,parseInt(u[1],10)),f=u[2],g=u[3];o(60+Math.floor(m*.4),`Resolving deltas: ${f}/${g}`)}}),await r,o(100,"Clone complete")}catch(r){throw ge.existsSync(e)&&ge.rmSync(e,{recursive:!0,force:!0}),r}}import{execa as X}from"execa";var yr={8e3:"API Server",5432:"PostgreSQL",6379:"Redis",27017:"MongoDB",5672:"RabbitMQ",3e3:"Web Frontend",8080:"ChromaDB",8083:"Mongo Express"};async function xe(){try{return await X("git",["--version"]),"success"}catch{return"error"}}async function he(){try{return await X("docker",["info"]),"success"}catch{return"error"}}async function Se(){try{return await X("mise",["--version"]),"success"}catch{return"missing"}}async function ye(){if((await import("node:os")).platform()==="win32")try{return await X("powershell",["-Command","irm https://mise.jdx.dev/install.ps1 | iex"]),!0}catch{return!1}try{return await X("sh",["-c","curl https://mise.jdx.dev/install.sh | sh"]),!0}catch{return!1}}async function be(e){let t=await import("node:net"),o=[],r=n=>new Promise(i=>{let p=t.createServer();p.once("error",()=>i(!1)),p.once("listening",()=>{p.close(()=>i(!0))}),p.listen(n)});for(let n of e){let i=yr[n]||`Port ${n}`;if(await r(n))o.push({port:n,service:i,available:!0});else{let u=await br(n),m=await vr(n+1,n+100,r);o.push({port:n,service:i,available:!1,usedBy:u,alternative:m||void 0})}}return o}async function br(e){if((await import("node:os")).platform()==="win32"){try{let{stdout:r}=await X("netstat",["-ano","-p","TCP"]),n=r.trim().split(`
6
+ `);for(let i of n)if(i.includes(`:${e}`)&&i.includes("LISTENING")){let p=i.trim().split(/\s+/),u=p[p.length-1];if(u)try{let{stdout:m}=await X("tasklist",["/FI",`PID eq ${u}`,"/FO","CSV","/NH"]);return m.trim().split(",")[0]?.replace(/"/g,"")||`PID ${u}`}catch{return`PID ${u}`}}}catch{}return}try{let{stdout:r}=await X("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 vr(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 H from"path";var Tr=e=>new Promise(t=>setTimeout(t,e)),Cr="dev-start.log";async function bt(e,t,o){if(t==="selfhost"){o?.("Starting all services in Docker (selfhost mode)...");let r=H.join(e,"infra/docker");await q("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=H.join(e,Cr),i=W.openSync(n,"a"),p;try{p=r("mise",["dev"],{cwd:e,stdio:["ignore",i,i],detached:!0,shell:!0}),p.unref()}finally{W.closeSync(i)}if(await Tr(1500),p.pid!=null)try{process.kill(p.pid,0)}catch{throw new Error(`Development servers crashed on startup. Check logs at: ${n}`)}o?.(`Development servers started! Logs: ${n}`)}}async function vt(e,t,o){let r=H.join(e,"infra/docker"),n=await qe(e);t?.("Stopping Docker services...");try{await q("docker",n==="selfhost"?["compose","-f","docker-compose.prod.yml","down"]:["compose","down"],r)}catch{}t?.("Stopping local processes...");try{let i=o?.[8e3]??8e3,p=o?.[3e3]??3e3;if(process.platform==="win32")for(let u of[i,p])try{await q("powershell",["-Command",`Get-NetTCPConnection -LocalPort ${u} -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue }`],e)}catch{}else for(let u of[i,p])try{await q("sh",["-c",`lsof -ti :${u} -sTCP:LISTEN | xargs kill 2>/dev/null || true`],e)}catch{}}catch{}t?.("All services stopped.")}async function qe(e){let t=H.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 q(e,t,o,r,n){let{spawn:i}=await import("child_process");return new Promise((p,u)=>{let m=i(e,t,{cwd:o,stdio:["ignore","pipe","pipe"],shell:!0}),f="",g=0;m.stdout?.on("data",d=>{let y=d.toString();f+=y,n?.(y),g=Math.min(g+5,95),r?.(g)}),m.stderr?.on("data",d=>{let y=d.toString();f+=y,n?.(y),g=Math.min(g+5,95),r?.(g)}),m.on("close",d=>{d===0?(r?.(100),p()):u(new Error(`Command failed with code ${d}: ${f.slice(-500)}`))}),m.on("error",d=>{u(d)})})}function Y(e){let t=e||process.cwd();for(;t!==H.dirname(t);){if(W.existsSync(H.join(t,"apps/api/app/config/settings_validator.py")))return t;t=H.dirname(t)}return null}var Ir=process.env.GAIA_CLI_DEV==="true",Q=e=>new Promise(t=>setTimeout(t,e));async function Tt(e){e.setStep("Welcome"),e.setStatus("Waiting for user input..."),await e.waitForInput("welcome");let t=d=>{let y=e.currentState.data.dependencyLogs||[],h=d.split(`
8
+ `).filter(v=>v.trim()!==""),x=[...y,...h].slice(-20);e.updateData("dependencyLogs",x)};e.setStep("Prerequisites"),e.setStatus("Checking system requirements..."),e.updateData("checks",{git:"pending",docker:"pending",mise:"pending"}),await Q(800),e.setStatus("Checking Git...");let o=await xe();e.updateData("checks",{...e.currentState.data.checks,git:o}),e.setStatus("Checking Docker...");let r=await he();e.updateData("checks",{...e.currentState.data.checks,docker:r}),e.setStatus("Checking Mise...");let n=await Se();e.updateData("checks",{...e.currentState.data.checks,mise:n}),n==="missing"&&(e.setStatus("Installing Mise..."),n=await ye()?"success":"error",e.updateData("checks",{...e.currentState.data.checks,mise:n}));let i=[];if(o==="error"&&i.push("Git"),r==="error"&&i.push("Docker"),n==="error"&&i.push("Mise"),i.length>0){e.setError(new Error(`Prerequisites failed: ${i.join(", ")} ${i.length===1?"is":"are"} not installed or not working. Please install and try again.`));return}e.setStatus("Checking Ports...");let u=await be([8e3,5432,6379,27017,5672,3e3,8080,8083]),m={},f=u.filter(d=>!d.available);if(f.length>0){let d=f.filter(h=>!h.alternative);if(d.length>0){e.setError(new Error(`Cannot find free alternative ports for: ${d.map(h=>`${h.port} (${h.service})`).join(", ")}. Free these ports and try again.`));return}if(e.updateData("portConflicts",u),await e.waitForInput("port_conflicts")==="abort"){e.setError(new Error("Port conflicts not resolved. Please free the ports and try again."));return}for(let h of u)!h.available&&h.alternative&&(m[h.port]=h.alternative)}e.updateData("portOverrides",m),e.setStatus("Prerequisites check complete!"),await Q(1e3);let g="";if(Ir){if(g=Y()||"",!g){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 Q(500),e.setStatus("Repository ready!")}else{for(e.setStep("Repository Setup");;){if(g=await e.waitForInput("repo_path",{default:"./gaia"}),ne.existsSync(g)){if(!ne.statSync(g).isDirectory()){e.setError(new Error(`Path ${g} exists and is not a directory.`)),await Q(2e3),e.setError(null);continue}if(ne.readdirSync(g).length>0){e.setError(new Error(`Directory ${g} is not empty. Please choose another path.`)),await Q(2e3),e.setError(null);continue}}break}e.setStep("Repository Setup"),e.setStatus("Preparing repository..."),e.updateData("repoProgress",0),e.updateData("repoPhase","");try{await St(g,"https://github.com/theexperiencecompany/gaia.git",(d,y)=>{e.updateData("repoProgress",d),y?(e.updateData("repoPhase",y),e.setStatus(`${y}...`)):e.setStatus(`Cloning repository to ${g}... ${d}%`)}),e.setStatus("Repository ready!")}catch(d){e.setError(d);return}}await Q(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 q("mise",["trust"],g,void 0,t),e.updateData("dependencyProgress",50),e.updateData("dependencyPhase","Installing tools (node, python, uv, nx)..."),await q("mise",["install"],g,d=>{e.updateData("dependencyProgress",50+d*.5)},t),e.updateData("dependencyProgress",100),e.updateData("toolComplete",!0)}catch(d){e.setError(new Error(`Failed to install tools: ${d.message}`));return}if(await Q(1e3),await fe(e,g,m),!e.currentState.error){e.setStep("Project Setup"),e.updateData("dependencyPhase","Setting up project..."),e.updateData("dependencyProgress",0),e.updateData("dependencyComplete",!1),e.updateData("repoPath",g),e.updateData("dependencyLogs",[]);try{e.updateData("dependencyProgress",0),e.updateData("dependencyPhase","Running mise setup (all dependencies)..."),await q("mise",["setup"],g,d=>{e.updateData("dependencyProgress",d)},t),e.updateData("dependencyProgress",100),e.updateData("dependencyPhase","Setup complete!"),e.updateData("dependencyComplete",!0)}catch(d){e.setError(new Error(`Failed to setup project: ${d.message}`));return}await Q(1e3),e.setStep("Finished"),e.setStatus("Setup complete!")}}async function Ct(){let e=j(),{unmount:t}=Er(wr.createElement($,{store:e,command:"init"}));try{await Tt(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 Dr from"react";var ve=e=>new Promise(t=>setTimeout(t,e));async function It(e){e.setStep("Detect Repo"),e.setStatus("Looking for GAIA repository...");let t=Y();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 ve(1e3),e.setStep("Prerequisites"),e.setStatus("Checking system requirements..."),e.updateData("checks",{git:"pending",docker:"pending",mise:"pending"}),await ve(500);let o=await xe();e.updateData("checks",{...e.currentState.data.checks,git:o});let r=await he();e.updateData("checks",{...e.currentState.data.checks,docker:r});let n=await Se();e.updateData("checks",{...e.currentState.data.checks,mise:n}),n==="missing"&&(e.setStatus("Installing Mise..."),n=await ye()?"success":"error",e.updateData("checks",{...e.currentState.data.checks,mise:n}));let i=[];if(o==="error"&&i.push("Git"),r==="error"&&i.push("Docker"),n==="error"&&i.push("Mise"),i.length>0){e.setError(new Error(`Prerequisites failed: ${i.join(", ")} ${i.length===1?"is":"are"} not installed or not working. Please install and try again.`));return}e.setStatus("Checking Ports...");let u=await be([8e3,5432,6379,27017,5672,3e3,8080,8083]),m={},f=u.filter(d=>!d.available);if(f.length>0){let d=f.filter(h=>!h.alternative);if(d.length>0){e.setError(new Error(`Cannot find free alternative ports for: ${d.map(h=>`${h.port} (${h.service})`).join(", ")}. Free these ports and try again.`));return}if(e.updateData("portConflicts",u),await e.waitForInput("port_conflicts")==="abort"){e.setError(new Error("Port conflicts not resolved. Please free the ports and try again."));return}for(let h of u)!h.available&&h.alternative&&(m[h.port]=h.alternative)}if(e.updateData("portOverrides",m),e.setStatus("Prerequisites check complete!"),await ve(1e3),await fe(e,t,m),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 g=d=>{let y=e.currentState.data.dependencyLogs||[],h=d.split(`
9
+ `).filter(v=>v.trim()!==""),x=[...y,...h].slice(-20);e.updateData("dependencyLogs",x)};try{e.updateData("dependencyPhase","Trusting mise configuration..."),await q("mise",["trust"],t,void 0,g),e.updateData("dependencyProgress",20),e.updateData("dependencyPhase","Installing tools..."),await q("mise",["install"],t,d=>{e.updateData("dependencyProgress",20+d*.3)},g),e.updateData("dependencyPhase","Running mise setup..."),await q("mise",["setup"],t,d=>{e.updateData("dependencyProgress",50+d*.5)},g),e.updateData("dependencyProgress",100),e.updateData("dependencyPhase","Setup complete!"),e.updateData("dependencyComplete",!0)}catch(d){e.setError(new Error(`Failed to setup project: ${d.message}`));return}await ve(1e3),e.setStep("Finished"),e.setStatus("Setup complete!")}async function Et(){let e=j(),{unmount:t}=Pr(Dr.createElement($,{store:e,command:"setup"}));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 Rr}from"ink";import Br from"react";async function wt(e){e.setStep("Starting"),e.setStatus("Locating GAIA repository...");let t=Y();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 qe(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 bt(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}=Rr(Br.createElement($,{store:e,command:"start"}));await new Promise(o=>setTimeout(o,50));try{await wt(e)}catch(o){e.setError(o)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as Lr}from"ink";import Mr from"react";import{execa as je}from"execa";var $e=["gaia-backend","gaia-web","chromadb","postgres","redis","mongo","rabbitmq","arq_worker"];async function Dt(){try{let{stdout:e}=await je("docker",["inspect","--format","{{.Name}}|{{.State.Status}}|{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}",...$e]),t=new Map;for(let o of e.trim().split(`
10
+ `)){if(!o)continue;let[r,n,i]=o.split("|"),p=r?.replace(/^\//,"")??"";t.set(p,{name:p,status:n==="running"?"running":"stopped",health:i!=="none"?i:void 0})}return $e.map(o=>t.get(o)??{name:o,status:"not_found"})}catch{let e=$e.map(async t=>{try{let{stdout:o}=await je("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 Rt(){try{return await je("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"?kr(r.name,r.port,r.path):_r(r.name,r.port));return Promise.all(o)}async function kr(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 p=Date.now()-r;i.destroy(),n({name:e,port:t,status:"up",latency:p})}),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 Rt()?{running:!0,containers:await Dt()}:{running:!1,containers:[]}}async function Fr(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 kt(e){for(;await Fr(e),await e.waitForInput("exit_or_refresh")==="refresh";);}async function _t(){let e=j(),{unmount:t}=Lr(Mr.createElement($,{store:e,command:"status"}));await new Promise(o=>setTimeout(o,50));try{await kt(e)}catch(o){e.setError(o)}e.currentState.error&&await e.waitForInput("exit"),t(),process.exit(e.currentState.error?1:0)}import{render as Nr}from"ink";import Gr from"react";async function Ft(e){e.setStep("Stopping"),e.setStatus("Locating GAIA repository...");let t=Y();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 vt(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 Lt(){let e=j(),{unmount:t}=Nr(Gr.createElement($,{store:e,command:"stop"}));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)}var K=new Or;K.name("gaia").description("CLI tool for setting up and managing GAIA").version("0.1.0");K.command("init").description("Full setup from scratch (clone, configure, start)").action(async()=>{await Ct()});K.command("setup").description("Configure an existing GAIA repository").action(async()=>{await Et()});K.command("status").description("Check health of all GAIA services").action(async()=>{await _t()});K.command("start").description("Start GAIA services").action(async()=>{await Pt()});K.command("stop").description("Stop all GAIA services").action(async()=>{await Lt()});process.argv.slice(2).length||(K.outputHelp(),process.exit(0));K.parse();
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@heygaia/cli",
3
+ "version": "0.1.0",
4
+ "description": "CLI tool for setting up and managing GAIA",
5
+ "type": "module",
6
+ "bin": {
7
+ "gaia": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "README.md"
12
+ ],
13
+ "scripts": {
14
+ "dev": "tsx watch src/index.ts",
15
+ "build": "esbuild src/index.ts --bundle --platform=node --target=node18 --format=esm --packages=external --outfile=dist/index.js --minify && chmod +x dist/index.js",
16
+ "start": "NODE_ENV=production node dist/index.js",
17
+ "prepublishOnly": "pnpm run build"
18
+ },
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/heygaia/gaia.git",
25
+ "directory": "packages/cli"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "keywords": [
31
+ "gaia",
32
+ "cli",
33
+ "ai-assistant",
34
+ "setup"
35
+ ],
36
+ "license": "MIT",
37
+ "dependencies": {
38
+ "@inkjs/ui": "^2.0.0",
39
+ "commander": "^14.0.3",
40
+ "execa": "^9.6.1",
41
+ "ink": "^6.6.0",
42
+ "ink-big-text": "^2.0.0",
43
+ "ink-gradient": "^3.0.0",
44
+ "ink-image": "^2.0.0",
45
+ "ink-progress-bar": "^3.0.0",
46
+ "ink-text-input": "^6.0.0",
47
+ "react": "^19",
48
+ "react-dom": "^19",
49
+ "remove": "^0.1.5",
50
+ "simple-git": "^3.30.0"
51
+ },
52
+ "devDependencies": {
53
+ "@types/node": "^25.2.2",
54
+ "@types/react": "^19",
55
+ "@types/react-dom": "^19",
56
+ "esbuild": "latest",
57
+ "tsx": "latest"
58
+ }
59
+ }