bostrat-node 0.2.1 → 0.2.2

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/dist/cli.js +30 -30
  2. package/dist/index.js +98 -98
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- var re=Object.defineProperty;var ie=(e,t)=>()=>(e&&(t=e(e=0)),t);var ae=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0})};var ee={};ae(ee,{commandPlan:()=>q,flyDockerfile:()=>J,flyToml:()=>V,flyWizard:()=>Oe,parseFlyFlags:()=>Z,stageBuild:()=>Q});import S from"node:fs";import f from"node:path";import ye from"node:os";import he from"node:readline/promises";import{execFile as we}from"node:child_process";import{randomUUID as ge}from"node:crypto";import{fileURLToPath as Te}from"node:url";function V({app:e,region:t,nodeName:n=e,planeUrl:o=X}){return`# bostrat node on YOUR Fly org \u2014 written by \`bostrat-node fly\`.
1
+ var se=Object.defineProperty;var ie=(e,t)=>()=>(e&&(t=e(e=0)),t);var ae=(e,t)=>{for(var n in t)se(e,n,{get:t[n],enumerable:!0})};var ee={};ae(ee,{commandPlan:()=>q,flyDockerfile:()=>J,flyToml:()=>V,flyWizard:()=>Oe,parseFlyFlags:()=>Z,stageBuild:()=>Q});import S from"node:fs";import f from"node:path";import ye from"node:os";import he from"node:readline/promises";import{execFile as we}from"node:child_process";import{randomUUID as ge}from"node:crypto";import{fileURLToPath as Te}from"node:url";function V({app:e,region:t,nodeName:n=e,planeUrl:o=X}){return`# bostrat node on YOUR Fly org \u2014 written by \`bostrat-node fly\`.
2
2
  # Redeploy after edits: fly deploy <this dir> -c <this file> -a ${e} --ha=false
3
3
  # No [http_service] and none should be added: the node dials OUT to the plane;
4
4
  # nothing inbound, ever. The node token lives in \`fly secrets\`, not here.
@@ -54,29 +54,29 @@ RUN chmod +x /usr/local/bin/node-entrypoint.sh
54
54
  ENV NODE_ENV=production
55
55
  ENV HOME=/data/home
56
56
  CMD ["node-entrypoint.sh"]
57
- `}function q({app:e,org:t,region:n,sizeGb:o,token:r,owner:s,dir:i}){let a=[`BOSTRAT_PLANE_TOKEN=${r}`,...s?[`BOSTRAT_OWNER=${s}`]:[]];return[{argv:["apps","create",e,"-o",t],display:`fly apps create ${e} -o ${t}`,tolerate:/already|taken|exists/i},{argv:["volumes","create","node_data","-a",e,"-r",n,"-s",String(o),"-y"],display:`fly volumes create node_data -a ${e} -r ${n} -s ${o} -y`,tolerate:/already|exists/i},{argv:["secrets","import","-a",e,"--stage"],display:`fly secrets import -a ${e} --stage # BOSTRAT_PLANE_TOKEN=<redacted>${s?" BOSTRAT_OWNER=\u2026":""} via stdin`,stdin:a.join(`
57
+ `}function q({app:e,org:t,region:n,sizeGb:o,token:s,owner:r,dir:i}){let a=[`BOSTRAT_PLANE_TOKEN=${s}`,...r?[`BOSTRAT_OWNER=${r}`]:[]];return[{argv:["apps","create",e,"-o",t],display:`fly apps create ${e} -o ${t}`,tolerate:/already|taken|exists/i},{argv:["volumes","create","node_data","-a",e,"-r",n,"-s",String(o),"-y"],display:`fly volumes create node_data -a ${e} -r ${n} -s ${o} -y`,tolerate:/already|exists/i},{argv:["secrets","import","-a",e,"--stage"],display:`fly secrets import -a ${e} --stage # BOSTRAT_PLANE_TOKEN=<redacted>${r?" BOSTRAT_OWNER=\u2026":""} via stdin`,stdin:a.join(`
58
58
  `)+`
59
- `},{argv:["deploy",i,"-c",f.join(i,"fly.toml"),"-a",e,"--ha=false"],display:`fly deploy ${i} -c ${f.join(i,"fly.toml")} -a ${e} --ha=false`}]}function Z(e=[]){let t={},n={"--app":"app","--org":"org","--region":"region","--size-gb":"sizeGb","--name":"name","--plane-url":"planeUrl","--token":"token","--owner":"owner"};for(let o=0;o<e.length;o++){let r=e[o];if(r==="--yes"||r==="-y")t.yes=!0;else if(n[r])t[n[r]]=e[++o]??"";else if(r.startsWith("--")&&r.includes("=")){let[s,...i]=r.split("=");n[s]?t[n[s]]=i.join("="):s==="--yes"&&(t.yes=!0)}}return t.sizeGb!=null&&(t.sizeGb=Number(t.sizeGb)||10),t}function Q({app:e,agentDir:t=_e,dest:n,toml:o}){let r=n||f.join(ye.homedir(),".bostrat","fly",e);S.mkdirSync(r,{recursive:!0});let s=[],i=(l,{optional:p=!1}={})=>{let u=f.join(t,l);if(!S.existsSync(u)){if(p)return;throw new Error(`staging: ${u} missing \u2014 is this a complete bostrat-agent install?`)}S.cpSync(u,f.join(r,l),{recursive:!0}),s.push(l)};i("package.json"),i("package-lock.json",{optional:!0});let a=S.existsSync(f.join(t,"src"))?"src":"dist";return i(a),i("bin"),i("node-entrypoint.sh"),S.writeFileSync(f.join(r,".dockerignore"),`node_modules
60
- `),S.writeFileSync(f.join(r,"Dockerfile"),J({layout:a})),S.writeFileSync(f.join(r,"fly.toml"),o),s.push(".dockerignore","Dockerfile","fly.toml"),{dir:r,manifest:s}}async function Se({ask:e,output:t,exec:n,flag:o}){if(o)return o;try{let{stdout:r}=await B(["orgs","list","--json"],{exec:n}),s=JSON.parse(r),i=Array.isArray(s)?s.map(a=>a.Slug||a.slug).filter(Boolean):Object.keys(s);if(i.length===1)return t.write(`Org: ${i[0]} (your only org)
61
- `),i[0];if(i.length>1)return await e(`Fly org (${i.join(" / ")})`,i[0])}catch{}return await e("Fly org slug (see `fly orgs list`)","personal")}async function Oe({argv:e=[],input:t=process.stdin,output:n=process.stdout,exec:o,stageDest:r}={}){let s=Z(e),i=he.createInterface({input:t,output:n}),a=async(c,y)=>(await i.question(y?`${c} [${y}]: `:`${c}: `)).trim()||y||"",l=c=>(i.close(),c);n.write(`bostrat-node fly \u2014 a node on YOUR Fly org, on your bill.
59
+ `},{argv:["deploy",i,"-c",f.join(i,"fly.toml"),"-a",e,"--ha=false"],display:`fly deploy ${i} -c ${f.join(i,"fly.toml")} -a ${e} --ha=false`}]}function Z(e=[]){let t={},n={"--app":"app","--org":"org","--region":"region","--size-gb":"sizeGb","--name":"name","--plane-url":"planeUrl","--token":"token","--owner":"owner"};for(let o=0;o<e.length;o++){let s=e[o];if(s==="--yes"||s==="-y")t.yes=!0;else if(n[s])t[n[s]]=e[++o]??"";else if(s.startsWith("--")&&s.includes("=")){let[r,...i]=s.split("=");n[r]?t[n[r]]=i.join("="):r==="--yes"&&(t.yes=!0)}}return t.sizeGb!=null&&(t.sizeGb=Number(t.sizeGb)||10),t}function Q({app:e,agentDir:t=_e,dest:n,toml:o}){let s=n||f.join(ye.homedir(),".bostrat","fly",e);S.mkdirSync(s,{recursive:!0});let r=[],i=(l,{optional:p=!1}={})=>{let u=f.join(t,l);if(!S.existsSync(u)){if(p)return;throw new Error(`staging: ${u} missing \u2014 is this a complete bostrat-agent install?`)}S.cpSync(u,f.join(s,l),{recursive:!0}),r.push(l)};i("package.json"),i("package-lock.json",{optional:!0});let a=S.existsSync(f.join(t,"src"))?"src":"dist";return i(a),i("bin"),i("node-entrypoint.sh"),S.writeFileSync(f.join(s,".dockerignore"),`node_modules
60
+ `),S.writeFileSync(f.join(s,"Dockerfile"),J({layout:a})),S.writeFileSync(f.join(s,"fly.toml"),o),r.push(".dockerignore","Dockerfile","fly.toml"),{dir:s,manifest:r}}async function Se({ask:e,output:t,exec:n,flag:o}){if(o)return o;try{let{stdout:s}=await B(["orgs","list","--json"],{exec:n}),r=JSON.parse(s),i=Array.isArray(r)?r.map(a=>a.Slug||a.slug).filter(Boolean):Object.keys(r);if(i.length===1)return t.write(`Org: ${i[0]} (your only org)
61
+ `),i[0];if(i.length>1)return await e(`Fly org (${i.join(" / ")})`,i[0])}catch{}return await e("Fly org slug (see `fly orgs list`)","personal")}async function Oe({argv:e=[],input:t=process.stdin,output:n=process.stdout,exec:o,stageDest:s}={}){let r=Z(e),i=he.createInterface({input:t,output:n}),a=async(c,y)=>(await i.question(y?`${c} [${y}]: `:`${c}: `)).trim()||y||"",l=c=>(i.close(),c);n.write(`bostrat-node fly \u2014 a node on YOUR Fly org, on your bill.
62
62
  bostrat never sees your Fly account: this wizard only runs your own \`fly\` CLI.
63
63
 
64
64
  `);try{await B(["version"],{exec:o})}catch{return n.write("\u2717 `fly` (flyctl) is not installed or not on PATH.\n install: https://fly.io/docs/flyctl/install/ \u2014 then re-run `bostrat-node fly`\n"),l(1)}try{let{stdout:c}=await B(["auth","whoami"],{exec:o});n.write(`\u2713 signed in to Fly as ${c.trim()}
65
- `)}catch{return n.write("\u2717 not signed in to Fly. Run `fly auth login` (or `fly auth signup`) and re-run `bostrat-node fly`.\n"),l(1)}let p=await Se({ask:a,output:n,exec:o,flag:s.org}),u=s.app||await a("App name",`bostrat-node-${ge().slice(0,4)}`),k=s.region||await a("Region (see `fly platform regions`)","iad"),C=s.sizeGb||Number(await a("Volume size GB (logins + repos live here)","10"))||10,g=s.name||u,v=s.planeUrl||X,E=s.token||await a("Node token (minted in the bostrat setup chat \u2014 shown once)");if(!E)return n.write(`\u2717 a node token is required \u2014 mint one in the bostrat setup chat (Connect a node \u2192 Fly), then re-run with it.
66
- `),l(1);let j=s.owner??await a("Owner userId (shown next to the token; empty = infer from token)",""),{dir:T,manifest:N}=Q({app:u,dest:r,toml:V({app:u,region:k,nodeName:g,planeUrl:v})});n.write(`
65
+ `)}catch{return n.write("\u2717 not signed in to Fly. Run `fly auth login` (or `fly auth signup`) and re-run `bostrat-node fly`.\n"),l(1)}let p=await Se({ask:a,output:n,exec:o,flag:r.org}),u=r.app||await a("App name",`bostrat-node-${ge().slice(0,4)}`),k=r.region||await a("Region (see `fly platform regions`)","iad"),C=r.sizeGb||Number(await a("Volume size GB (logins + repos live here)","10"))||10,g=r.name||u,v=r.planeUrl||X,E=r.token||await a("Node token (minted in the bostrat setup chat \u2014 shown once)");if(!E)return n.write(`\u2717 a node token is required \u2014 mint one in the bostrat setup chat (Connect a node \u2192 Fly), then re-run with it.
66
+ `),l(1);let j=r.owner??await a("Owner userId (shown next to the token; empty = infer from token)",""),{dir:T,manifest:N}=Q({app:u,dest:s,toml:V({app:u,region:k,nodeName:g,planeUrl:v})});n.write(`
67
67
  staged build context \u2192 ${T} (${N.join(", ")})
68
68
 
69
69
  Plan (your flyctl, your org, your bill):
70
70
  `);let _=q({app:u,org:p,region:k,sizeGb:C,token:E,owner:j,dir:T});for(let c of _)n.write(` $ ${c.display}
71
- `);if(!s.yes&&(await a(`
71
+ `);if(!r.yes&&(await a(`
72
72
  Run it? (Y/n)`,"Y")).toLowerCase().startsWith("n"))return n.write(`aborted \u2014 nothing was created. Re-run any time; the staged context is kept.
73
73
  `),l(1);for(let c of _){n.write(`
74
74
  \u2192 ${c.display}
75
- `);try{let{stdout:y,stderr:P}=await B(c.argv,{stdin:c.stdin,exec:o}),K=`${y||""}${P||""}`.trim();K&&n.write(K.split(`
76
- `).map(se=>` ${se}`).join(`
75
+ `);try{let{stdout:y,stderr:$}=await B(c.argv,{stdin:c.stdin,exec:o}),K=`${y||""}${$||""}`.trim();K&&n.write(K.split(`
76
+ `).map(re=>` ${re}`).join(`
77
77
  `)+`
78
- `)}catch(y){let P=`${y?.stdout||""}${y?.stderr||""}${y?.message||""}`;if(c.tolerate&&c.tolerate.test(P)){n.write(` (already exists \u2014 continuing)
79
- `);continue}return n.write(`\u2717 failed: ${P.trim().split(`
78
+ `)}catch(y){let $=`${y?.stdout||""}${y?.stderr||""}${y?.message||""}`;if(c.tolerate&&c.tolerate.test($)){n.write(` (already exists \u2014 continuing)
79
+ `);continue}return n.write(`\u2717 failed: ${$.trim().split(`
80
80
  `).slice(-4).join(`
81
81
  `)}
82
82
  fix and re-run \`bostrat-node fly\` \u2014 every step is safe to repeat.
@@ -87,31 +87,31 @@ Run it? (Y/n)`,"Y")).toLowerCase().startsWith("n"))return n.write(`aborted \u201
87
87
  redeploy: fly deploy ${T} -c ${f.join(T,"fly.toml")} -a ${u} --ha=false
88
88
  Vendor logins (Claude/Codex) are NOT set up here \u2014 you type those later, inside
89
89
  boxes, and they land on this machine's volume, never on bostrat (box-auth-policy).
90
- `),l(0)}var _e,X,B,te=ie(()=>{_e=f.resolve(f.dirname(Te(import.meta.url)),".."),X="wss://plane.bostrat.ai/v1/node";B=(e,{stdin:t,exec:n}={})=>new Promise((o,r)=>{if(n)return n(e,{stdin:t}).then(o,r);let s=we("fly",e,{timeout:6e5,maxBuffer:16*1024*1024},(i,a,l)=>i?r(Object.assign(i,{stdout:a,stderr:l})):o({stdout:a,stderr:l}));t!=null&&s.stdin?.end(t)})});import m from"node:fs";import d from"node:path";import x from"node:os";import{createRequire as D}from"node:module";import{execFile as be,spawn as Ae}from"node:child_process";import{promisify as xe}from"node:util";import Re from"node:readline/promises";import{randomUUID as ve}from"node:crypto";import{fileURLToPath as Ee}from"node:url";import $ from"node:fs";import L from"node:path";import ce from"node:os";var le=process.env.BOSTRAT_STATE_DIR||L.join(process.env.HOME||ce.tmpdir(),".bostrat"),A=()=>L.join(le,"node.env");function U(e){let t=String(e||"").trim();if(!t)return"";let n=/^[a-z][a-z0-9+.-]*:\/\//i.test(t)?t:`wss://${t}`,o;try{o=new URL(n)}catch{return t}let r={"https:":"wss:","http:":"ws:","wss:":"wss:","ws:":"ws:"}[o.protocol];return r?(o.protocol=r,(o.pathname===""||o.pathname==="/")&&(o.pathname="/v1/node"),o.toString()):t}function I(e){let t;try{t=$.readFileSync(e,"utf8")}catch{return{}}let n={};for(let o of t.split(`
91
- `)){let r=o.trim();if(!r||r.startsWith("#"))continue;let s=/^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.exec(r);if(!s)continue;let i=s[2].trim();(i.startsWith('"')&&i.endsWith('"')||i.startsWith("'")&&i.endsWith("'"))&&(i=i.slice(1,-1)),n[s[1]]=i}return n}function H(e,t=process.env){let n=I(e);for(let[o,r]of Object.entries(n))o in t||(t[o]=r);return n}function W(e,t,{header:n=""}={}){let o=[];n&&o.push(...n.split(`
92
- `).map(r=>r?`# ${r}`:"#"));for(let[r,s]of Object.entries(t))s==null||s===""||o.push(`${r}=${s}`);$.mkdirSync(L.dirname(e),{recursive:!0}),$.writeFileSync(e,o.join(`
90
+ `),l(0)}var _e,X,B,te=ie(()=>{_e=f.resolve(f.dirname(Te(import.meta.url)),".."),X="wss://plane.bostrat.ai/v1/node";B=(e,{stdin:t,exec:n}={})=>new Promise((o,s)=>{if(n)return n(e,{stdin:t}).then(o,s);let r=we("fly",e,{timeout:6e5,maxBuffer:16*1024*1024},(i,a,l)=>i?s(Object.assign(i,{stdout:a,stderr:l})):o({stdout:a,stderr:l}));t!=null&&r.stdin?.end(t)})});import m from"node:fs";import d from"node:path";import x from"node:os";import{createRequire as D}from"node:module";import{execFile as be,spawn as Ae}from"node:child_process";import{promisify as xe}from"node:util";import Re from"node:readline/promises";import{randomUUID as ve}from"node:crypto";import{fileURLToPath as Ee}from"node:url";import P from"node:fs";import L from"node:path";import ce from"node:os";var le=process.env.BOSTRAT_STATE_DIR||L.join(process.env.HOME||ce.tmpdir(),".bostrat"),A=()=>L.join(le,"node.env");function U(e){let t=String(e||"").trim();if(!t)return"";let n=/^[a-z][a-z0-9+.-]*:\/\//i.test(t)?t:`wss://${t}`,o;try{o=new URL(n)}catch{return t}let s={"https:":"wss:","http:":"ws:","wss:":"wss:","ws:":"ws:"}[o.protocol];return s?(o.protocol=s,(o.pathname===""||o.pathname==="/")&&(o.pathname="/v1/node"),o.toString()):t}function I(e){let t;try{t=P.readFileSync(e,"utf8")}catch{return{}}let n={};for(let o of t.split(`
91
+ `)){let s=o.trim();if(!s||s.startsWith("#"))continue;let r=/^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.exec(s);if(!r)continue;let i=r[2].trim();(i.startsWith('"')&&i.endsWith('"')||i.startsWith("'")&&i.endsWith("'"))&&(i=i.slice(1,-1)),n[r[1]]=i}return n}function H(e,t=process.env){let n=I(e);for(let[o,s]of Object.entries(n))o in t||(t[o]=s);return n}function W(e,t,{header:n=""}={}){let o=[];n&&o.push(...n.split(`
92
+ `).map(s=>s?`# ${s}`:"#"));for(let[s,r]of Object.entries(t))r==null||r===""||o.push(`${s}=${r}`);P.mkdirSync(L.dirname(e),{recursive:!0}),P.writeFileSync(e,o.join(`
93
93
  `)+`
94
- `,{mode:384}),$.chmodSync(e,384)}function Y(e=process.platform){return e==="darwin"?{BOSTRAT_TMUX_BIN:"/opt/homebrew/bin/tmux",BOSTRAT_TMUX_SOCKET:`/tmp/tmux-${process.getuid?.()??501}/bostrat`,BOSTRAT_CHROMIUM_BIN:"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"}:{}}import{execFile as pe}from"node:child_process";import{promisify as fe}from"node:util";import ue from"node:os";import z from"node:path";var de=process.env.BOSTRAT_DEBUG_DIR||z.join(ue.homedir(),".bostrat","debug"),st=z.join(de,"handoff.jsonl"),rt=Number(process.env.BOSTRAT_HANDOFF_DEBUG_MAX)||500;var me=fe(pe);var Tt=process.env.BOSTRAT_TMUX_BIN||"/usr/bin/tmux",_t=process.env.BOSTRAT_TMUX_SOCKET||"/tmp/tmux-1000/default",St=process.env.BOSTRAT_DEFAULT_CWD||process.env.HOME||"/",Ot=process.env.BOSTRAT_AGENT_CMD||"claude --dangerously-skip-permissions";async function G(e,{loginShell:t=!1,failOpen:n=!1}={}){if(!e)return!1;let o=t?process.env.SHELL||"/bin/sh":"sh",r=t?"-lic":"-c";try{return await me(o,[r,'command -v "$1" >/dev/null 2>&1',"_",e],{timeout:5e3}),!0}catch(s){return s?.code===1?!1:n}}var bt=Number(process.env.BOSTRAT_PROMPT_CAPTURE_COLS)||100,At=Number(process.env.BOSTRAT_PROMPT_CAPTURE_ROWS)||40,xt=Number(process.env.BOSTRAT_PROMPT_CAPTURE_LINES)||80,Rt=Number(process.env.BOSTRAT_BOX_COLS)||120,vt=Number(process.env.BOSTRAT_BOX_ROWS)||40;var O=xe(be),M=d.dirname(Ee(import.meta.url)),b=d.resolve(M,".."),ke=d.join(M,"index.js"),Ne="wss://plane.bostrat.ai/v1/node",Pe=D(import.meta.url)("../package.json").version,w=(e,t)=>({name:e,level:"pass",detail:t}),R=(e,t,n)=>({name:e,level:"warn",detail:t,fix:n}),h=(e,t,n)=>({name:e,level:"fail",detail:t,fix:n});async function $e(){let[e,t]=process.versions.node.split(".").map(Number);return e>22||e===22&&t>=5?w("node runtime",`${process.version} at ${process.execPath}`):h("node runtime",`${process.version} < 22.5`,"install Node \u226522.5 via nvm and re-run under it")}function Ie(e){let t;try{t=m.statSync(e)}catch{return R("node.env",`${e} missing`,"run `bostrat-node init`")}let n=t.mode&511;return n&63?R("node.env",`${e} mode ${n.toString(8)} \u2014 group/world readable and it can hold a key`,`chmod 600 ${e}`):w("node.env",`${e} (0600)`)}async function Be(e){let t=e.BOSTRAT_TMUX_BIN||"/usr/bin/tmux";try{let{stdout:n}=await O(t,["-V"],{timeout:5e3});return w("tmux",`${t} (${n.trim()})`)}catch{return h("tmux",`${t} not runnable`,process.platform==="darwin"?"brew install tmux (then BOSTRAT_TMUX_BIN=/opt/homebrew/bin/tmux)":"install tmux")}}async function F(e,{required:t=!1}={}){if(await G(e,{loginShell:!0,failOpen:!1}))return w(e,"resolves on the login-shell PATH");let o="not on the login-shell PATH";return t?h(e,o,`install ${e} so \`$SHELL -lic 'command -v ${e}'\` finds it`):R(e,o)}async function Ce(){let e=await Promise.all(["claude","codex","cursor-agent"].map(t=>F(t)));return e.some(t=>t.level==="pass")||e.push(h("agent CLIs","no agent CLI found at all \u2014 a node with nothing to drive","install at least one of claude / codex / cursor-agent")),e}async function je(){try{let t=D(d.join(b,"src","node-cli.js"))("node-pty");return await new Promise((n,o)=>{let r=t.spawn("/bin/echo",["ok"],{cols:20,rows:5}),s=setTimeout(()=>o(new Error("spawn timeout")),5e3);r.onExit(()=>{clearTimeout(s),n()})}),w("node-pty","loads and spawns under this runtime")}catch(e){let t=`cd ${b} && npm rebuild node-pty # with THIS node first on PATH \u2014 never the system npm`;try{let n=D(d.join(b,"package.json")),o=d.join(d.dirname(n.resolve("node-pty/package.json")),"prebuilds",`${process.platform}-${process.arch}`,"spawn-helper");m.existsSync(o)&&!(m.statSync(o).mode&73)&&(t=`chmod +x ${o} # node-pty ships it non-executable`)}catch{}return h("node-pty",`load/spawn failed: ${e?.message||e}`,t)}}function Le(e){let t=e.BOSTRAT_CHROMIUM_BIN||"/usr/bin/chromium";return m.existsSync(t)?w("chromium (mocks)",t):R("chromium (mocks)",`${t} missing \u2014 mock rendering unavailable`,"install Chromium/Chrome and set BOSTRAT_CHROMIUM_BIN")}function Ue(e){let t=e.BOSTRAT_CLAUDE_USE_API_KEY==="1";return t&&!e.ANTHROPIC_API_KEY?h("claude lane","BOSTRAT_CLAUDE_USE_API_KEY=1 but ANTHROPIC_API_KEY is empty","add the key to node.env or set the flag to 0"):w("claude lane",t?"BYO API key (injected per new box)":"box-local login (subscription \u2014 you type `claude login` inside the box)")}async function De(e,{WebSocketImpl:t}={}){if(!e.BOSTRAT_PLANE_URL||!e.BOSTRAT_PLANE_TOKEN)return R("plane link","BOSTRAT_PLANE_URL/TOKEN unset \u2014 node runs pure M1 (local only)","run `bostrat-node init`");let n=t||(await import("ws")).default,o=Date.now(),r=U(e.BOSTRAT_PLANE_URL);return await new Promise(s=>{let i=new n(r,{headers:{authorization:`Bearer ${e.BOSTRAT_PLANE_TOKEN}`}}),a=p=>{clearTimeout(l);try{i.close()}catch{}s(p)},l=setTimeout(()=>a(h("plane link",`no hello_ok within 5s from ${r}`,"check the URL, the token, and the plane's IP gate")),5e3);i.on("open",()=>i.send(JSON.stringify({v:1,ch:"ctl",type:"hello",nodeId:`doctor-${ve().slice(0,8)}`}))),i.on("message",p=>{try{let u=JSON.parse(p);u.type==="hello_ok"?a(w("plane link",`hello_ok in ${Date.now()-o}ms (${r})`)):u.type==="error"&&a(h("plane link",`plane said: ${u.code} ${u.message||""}`,"check the token"))}catch{}}),i.on("error",p=>a(h("plane link",`${p?.message||p}`,"check the URL, the token, and the plane's IP gate")))})}function Fe(e){return e.BOSTRAT_STATE_REMOTE?w("state remote",`${e.BOSTRAT_STATE_REMOTE} (this node's own \u2014 never another node's repo)`):R("state remote","unset \u2014 state syncs to a local repo only, no off-box durability","create a per-node private repo and set BOSTRAT_STATE_REMOTE")}async function ne(e,t={}){let n=[];return n.push(await $e()),n.push(Ie(t.envFile||A())),n.push(await Be(e)),n.push(...await Ce()),n.push(await F("git",{required:!0})),n.push(await F("gh")),n.push(await je()),n.push(Le(e)),n.push(Ue(e)),n.push(await De(e,t)),n.push(Fe(e)),n}function oe(e,t=console.log){let n={pass:"\u2713",warn:"!",fail:"\u2717"};for(let s of e)t(`${n[s.level]} ${s.name}: ${s.detail}`),s.fix&&s.level!=="pass"&&t(` fix: ${s.fix}`);let o=e.filter(s=>s.level==="fail").length,r=e.filter(s=>s.level==="warn").length;return t(o?`
95
- FAIL \u2014 ${o} blocking, ${r} warnings`:`
96
- OK \u2014 0 blocking, ${r} warnings`),o===0}async function Me({envFile:e=A(),input:t=process.stdin,output:n=process.stdout}={}){let o=I(e),r=Re.createInterface({input:t,output:n}),s=async(_,c)=>(await r.question(c?`${_} [${c}]: `:`${_}: `)).trim()||c||"";n.write(`bostrat-node init \u2014 plane link + machine config. No vendor logins here:
94
+ `,{mode:384}),P.chmodSync(e,384)}function Y(e=process.platform){return e==="darwin"?{BOSTRAT_TMUX_BIN:"/opt/homebrew/bin/tmux",BOSTRAT_TMUX_SOCKET:`/tmp/tmux-${process.getuid?.()??501}/bostrat`,BOSTRAT_CHROMIUM_BIN:"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"}:{}}import{execFile as pe}from"node:child_process";import{promisify as fe}from"node:util";import ue from"node:os";import z from"node:path";var de=process.env.BOSTRAT_DEBUG_DIR||z.join(ue.homedir(),".bostrat","debug"),rt=z.join(de,"handoff.jsonl"),st=Number(process.env.BOSTRAT_HANDOFF_DEBUG_MAX)||500;var me=fe(pe);var Tt=process.env.BOSTRAT_TMUX_BIN||"/usr/bin/tmux",_t=process.env.BOSTRAT_TMUX_SOCKET||"/tmp/tmux-1000/default",St=process.env.BOSTRAT_DEFAULT_CWD||process.env.HOME||"/",Ot=process.env.BOSTRAT_AGENT_CMD||"claude --dangerously-skip-permissions";async function G(e,{loginShell:t=!1,failOpen:n=!1}={}){if(!e)return!1;let o=t?process.env.SHELL||"/bin/sh":"sh",s=t?"-lic":"-c";try{return await me(o,[s,'command -v "$1" >/dev/null 2>&1',"_",e],{timeout:5e3}),!0}catch(r){return r?.code===1?!1:n}}var bt=Number(process.env.BOSTRAT_PROMPT_CAPTURE_COLS)||100,At=Number(process.env.BOSTRAT_PROMPT_CAPTURE_ROWS)||40,xt=Number(process.env.BOSTRAT_PROMPT_CAPTURE_LINES)||80,Rt=Number(process.env.BOSTRAT_BOX_COLS)||120,vt=Number(process.env.BOSTRAT_BOX_ROWS)||40;var O=xe(be),M=d.dirname(Ee(import.meta.url)),b=d.resolve(M,".."),ke=d.join(M,"index.js"),Ne="wss://plane.bostrat.ai/v1/node",$e=D(import.meta.url)("../package.json").version,w=(e,t)=>({name:e,level:"pass",detail:t}),R=(e,t,n)=>({name:e,level:"warn",detail:t,fix:n}),h=(e,t,n)=>({name:e,level:"fail",detail:t,fix:n});async function Pe(){let[e,t]=process.versions.node.split(".").map(Number);return e>22||e===22&&t>=5?w("node runtime",`${process.version} at ${process.execPath}`):h("node runtime",`${process.version} < 22.5`,"install Node \u226522.5 via nvm and re-run under it")}function Ie(e){let t;try{t=m.statSync(e)}catch{return R("node.env",`${e} missing`,"run `bostrat-node init`")}let n=t.mode&511;return n&63?R("node.env",`${e} mode ${n.toString(8)} \u2014 group/world readable and it can hold a key`,`chmod 600 ${e}`):w("node.env",`${e} (0600)`)}async function Be(e){let t=e.BOSTRAT_TMUX_BIN||"/usr/bin/tmux";try{let{stdout:n}=await O(t,["-V"],{timeout:5e3});return w("tmux",`${t} (${n.trim()})`)}catch{return h("tmux",`${t} not runnable`,process.platform==="darwin"?"brew install tmux (then BOSTRAT_TMUX_BIN=/opt/homebrew/bin/tmux)":"install tmux")}}async function F(e,{required:t=!1}={}){if(await G(e,{loginShell:!0,failOpen:!1}))return w(e,"resolves on the login-shell PATH");let o="not on the login-shell PATH";return t?h(e,o,`install ${e} so \`$SHELL -lic 'command -v ${e}'\` finds it`):R(e,o)}async function Ce(){let e=await Promise.all(["claude","codex","cursor-agent"].map(t=>F(t)));return e.some(t=>t.level==="pass")||e.push(h("agent CLIs","no agent CLI found at all \u2014 a node with nothing to drive","install at least one of claude / codex / cursor-agent")),e}async function je(){try{let t=D(d.join(b,"src","node-cli.js"))("node-pty");return await new Promise((n,o)=>{let s=t.spawn("/bin/echo",["ok"],{cols:20,rows:5}),r=setTimeout(()=>o(new Error("spawn timeout")),5e3);s.onExit(()=>{clearTimeout(r),n()})}),w("node-pty","loads and spawns under this runtime")}catch(e){let t=`cd ${b} && npm rebuild node-pty # with THIS node first on PATH \u2014 never the system npm`;try{let n=D(d.join(b,"package.json")),o=d.join(d.dirname(n.resolve("node-pty/package.json")),"prebuilds",`${process.platform}-${process.arch}`,"spawn-helper");m.existsSync(o)&&!(m.statSync(o).mode&73)&&(t=`chmod +x ${o} # node-pty ships it non-executable`)}catch{}return h("node-pty",`load/spawn failed: ${e?.message||e}`,t)}}function Le(e){let t=e.BOSTRAT_CHROMIUM_BIN||"/usr/bin/chromium";return m.existsSync(t)?w("chromium (mocks)",t):R("chromium (mocks)",`${t} missing \u2014 mock rendering unavailable`,"install Chromium/Chrome and set BOSTRAT_CHROMIUM_BIN")}function Ue(e){let t=e.BOSTRAT_CLAUDE_USE_API_KEY==="1";return t&&!e.ANTHROPIC_API_KEY?h("claude lane","BOSTRAT_CLAUDE_USE_API_KEY=1 but ANTHROPIC_API_KEY is empty","add the key to node.env or set the flag to 0"):w("claude lane",t?"BYO API key (injected per new box)":"box-local login (subscription \u2014 you type `claude login` inside the box)")}async function De(e,{WebSocketImpl:t}={}){if(!e.BOSTRAT_PLANE_URL||!e.BOSTRAT_PLANE_TOKEN)return R("plane link","BOSTRAT_PLANE_URL/TOKEN unset \u2014 node runs pure M1 (local only)","run `bostrat-node init`");let n=t||(await import("ws")).default,o=Date.now(),s=U(e.BOSTRAT_PLANE_URL);return await new Promise(r=>{let i=new n(s,{headers:{authorization:`Bearer ${e.BOSTRAT_PLANE_TOKEN}`}}),a=p=>{clearTimeout(l);try{i.close()}catch{}r(p)},l=setTimeout(()=>a(h("plane link",`no hello_ok within 5s from ${s}`,"check the URL, the token, and the plane's IP gate")),5e3);i.on("open",()=>i.send(JSON.stringify({v:1,ch:"ctl",type:"hello",nodeId:`doctor-${ve().slice(0,8)}`}))),i.on("message",p=>{try{let u=JSON.parse(p);u.type==="hello_ok"?a(w("plane link",`hello_ok in ${Date.now()-o}ms (${s})`)):u.type==="error"&&a(h("plane link",`plane said: ${u.code} ${u.message||""}`,"check the token"))}catch{}}),i.on("error",p=>a(h("plane link",`${p?.message||p}`,"check the URL, the token, and the plane's IP gate")))})}function Fe(e){return e.BOSTRAT_STATE_REMOTE?w("state remote",`${e.BOSTRAT_STATE_REMOTE} (this node's own \u2014 never another node's repo)`):R("state remote","unset \u2014 state syncs to a local repo only, no off-box durability","create a per-node private repo and set BOSTRAT_STATE_REMOTE")}async function ne(e,t={}){let n=[];return n.push(await Pe()),n.push(Ie(t.envFile||A())),n.push(await Be(e)),n.push(...await Ce()),n.push(await F("git",{required:!0})),n.push(await F("gh")),n.push(await je()),n.push(Le(e)),n.push(Ue(e)),n.push(await De(e,t)),n.push(Fe(e)),n}function oe(e,t=console.log){let n={pass:"\u2713",warn:"!",fail:"\u2717"};for(let r of e)t(`${n[r.level]} ${r.name}: ${r.detail}`),r.fix&&r.level!=="pass"&&t(` fix: ${r.fix}`);let o=e.filter(r=>r.level==="fail").length,s=e.filter(r=>r.level==="warn").length;return t(o?`
95
+ FAIL \u2014 ${o} blocking, ${s} warnings`:`
96
+ OK \u2014 0 blocking, ${s} warnings`),o===0}async function Me({envFile:e=A(),input:t=process.stdin,output:n=process.stdout}={}){let o=I(e),s=Re.createInterface({input:t,output:n}),r=async(_,c)=>(await s.question(c?`${_} [${c}]: `:`${_}: `)).trim()||c||"";n.write(`bostrat-node init \u2014 plane link + machine config. No vendor logins here:
97
97
  you type those inside each box, later (box-auth-policy).
98
98
 
99
- `);let i=await s("Plane URL",o.BOSTRAT_PLANE_URL||Ne),a=U(i);a!==i.trim()&&n.write(` \u2192 using ${a}
100
- `);let l=await s("Node token (minted plane-side; stored 0600)",o.BOSTRAT_PLANE_TOKEN),p=await s("Owner userId (shown at mint; empty = infer from token)",o.BOSTRAT_OWNER||"");p&&!/^user_[A-Za-z0-9]+$/.test(p)&&n.write(` ! that doesn't look like a Clerk userId (user_\u2026) \u2014 leave it empty next time and the plane infers the owner from the token; saved as typed.
101
- `);let u=await s("Node name",o.BOSTRAT_NODE_NAME||x.hostname().split(".")[0]),k=await s("Repos root",o.BOSTRAT_REPOS_ROOT||d.join(x.homedir(),"Documents")),C=await s("State remote (per-node private repo; empty = local-only)",o.BOSTRAT_STATE_REMOTE||""),g=(await s("Route NEW claude boxes through a BYO API key? (y/N)",o.BOSTRAT_CLAUDE_USE_API_KEY==="1"?"y":"N")).toLowerCase().startsWith("y");g&&n.write(`
99
+ `);let i=await r("Plane URL",o.BOSTRAT_PLANE_URL||Ne),a=U(i);a!==i.trim()&&n.write(` \u2192 using ${a}
100
+ `);let l=await r("Node token (minted plane-side; stored 0600)",o.BOSTRAT_PLANE_TOKEN),p=await r("Owner userId (just press Enter \u2014 the plane infers it from your token)",o.BOSTRAT_OWNER||"");p&&!/^user_[A-Za-z0-9]+$/.test(p)&&n.write(` ! that doesn't look like a Clerk userId (user_\u2026) \u2014 leave it empty next time and the plane infers the owner from the token; saved as typed.
101
+ `);let u=await r("Node name",o.BOSTRAT_NODE_NAME||x.hostname().split(".")[0]),k=await r("Repos root",o.BOSTRAT_REPOS_ROOT||d.join(x.homedir(),"Documents")),C=await r("State remote (per-node private repo; empty = local-only)",o.BOSTRAT_STATE_REMOTE||""),g=(await r("Route NEW claude boxes through a BYO API key? (y/N)",o.BOSTRAT_CLAUDE_USE_API_KEY==="1"?"y":"N")).toLowerCase().startsWith("y");g&&n.write(`
102
102
  BYO API key (box-auth-policy rule 5): claude boxes on this node bill to YOUR key,
103
103
  injected per box, stored 0600 in node.env, never sent to the plane.
104
104
  \u2022 create/copy a key: https://console.anthropic.com/settings/keys
105
105
  \u2022 set a monthly spend limit while you're there \u2014 the key is live.
106
106
 
107
- `);let v=g?await s("ANTHROPIC_API_KEY (starts sk-ant-)",o.ANTHROPIC_API_KEY):"";g&&v&&!/^sk-ant-/.test(v)&&n.write(` ! that doesn't look like an Anthropic key (expected sk-ant-\u2026) \u2014 saved as-is; re-run init to correct.
108
- `),r.close();let E={...Y(),...o,BOSTRAT_PLANE_URL:a,BOSTRAT_PLANE_TOKEN:l,BOSTRAT_OWNER:p,BOSTRAT_NODE_NAME:u,BOSTRAT_REPOS_ROOT:k,BOSTRAT_STATE_REMOTE:C,BOSTRAT_CLAUDE_USE_API_KEY:g?"1":"0",ANTHROPIC_API_KEY:g?v:o.ANTHROPIC_API_KEY};W(e,E,{header:`bostrat node config \u2014 written by \`bostrat-node init\` ${new Date().toISOString()}
107
+ `);let v=g?await r("ANTHROPIC_API_KEY (starts sk-ant-)",o.ANTHROPIC_API_KEY):"";g&&v&&!/^sk-ant-/.test(v)&&n.write(` ! that doesn't look like an Anthropic key (expected sk-ant-\u2026) \u2014 saved as-is; re-run init to correct.
108
+ `),s.close();let E={...Y(),...o,BOSTRAT_PLANE_URL:a,BOSTRAT_PLANE_TOKEN:l,BOSTRAT_OWNER:p,BOSTRAT_NODE_NAME:u,BOSTRAT_REPOS_ROOT:k,BOSTRAT_STATE_REMOTE:C,BOSTRAT_CLAUDE_USE_API_KEY:g?"1":"0",ANTHROPIC_API_KEY:g?v:o.ANTHROPIC_API_KEY};W(e,E,{header:`bostrat node config \u2014 written by \`bostrat-node init\` ${new Date().toISOString()}
109
109
  0600: BOSTRAT_PLANE_TOKEN always lives here, ANTHROPIC_API_KEY may. Never commit.
110
110
  Bind host: unset = loopback-only while plane-linked; BOSTRAT_HOST=all restores bind-all (LAN).`}),n.write(`
111
111
  wrote ${e}
112
112
 
113
113
  `);let j={...E,...process.env},T=await ne(j,{envFile:e}),N=oe(T,_=>n.write(_+`
114
- `));return N&&n.write("\nnext: `bostrat-node run` (foreground) or `bostrat-node install-service`\n"),{ok:N,results:T}}function Ke({envFile:e=A()}={}){H(e);let t=process.env.BOSTRAT_NODE_BIN||process.execPath,n=Ae(t,[ke],{cwd:b,stdio:"inherit",env:process.env});for(let o of["SIGINT","SIGTERM"])process.on(o,()=>n.kill(o));return n.on("exit",(o,r)=>process.exit(r?1:o??1)),n}function He({agentDir:e=b,nodeBin:t=process.execPath,envFile:n=A(),home:o=x.homedir()}={}){let r=d.dirname(t),s=d.join(d.basename(M),"index.js");return`# bostrat node \u2014 written by \`bostrat-node install-service\`. Config lives in
114
+ `));return N&&n.write("\nnext: `bostrat-node run` (foreground) or `bostrat-node install-service`\n"),{ok:N,results:T}}function Ke({envFile:e=A()}={}){H(e);let t=process.env.BOSTRAT_NODE_BIN||process.execPath,n=Ae(t,[ke],{cwd:b,stdio:"inherit",env:process.env});for(let o of["SIGINT","SIGTERM"])process.on(o,()=>n.kill(o));return n.on("exit",(o,s)=>process.exit(s?1:o??1)),n}function He({agentDir:e=b,nodeBin:t=process.execPath,envFile:n=A(),home:o=x.homedir()}={}){let s=d.dirname(t),r=d.join(d.basename(M),"index.js");return`# bostrat node \u2014 written by \`bostrat-node install-service\`. Config lives in
115
115
  # ${n} (edit + \`systemctl --user restart bostrat-node\`), not here.
116
116
  [Unit]
117
117
  Description=bostrat node \u2014 box runtime dialing out to the coordination plane (plane-p1-package-node-scope-2026-07-14.md)
@@ -121,17 +121,17 @@ After=default.target
121
121
  Type=simple
122
122
  WorkingDirectory=${e}
123
123
  # Pinned runtime: node-pty is compiled against exactly this node (SEGV trap).
124
- ExecStart=${t} --disable-warning=ExperimentalWarning ${s}
124
+ ExecStart=${t} --disable-warning=ExperimentalWarning ${r}
125
125
  EnvironmentFile=${n}
126
126
  # systemd's user PATH omits ~/.local/bin (cursor-agent, bostrat-view) and the
127
127
  # nvm bin dir \u2014 both are load-bearing for box spawning.
128
- Environment=PATH=${o}/.local/bin:${r}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
128
+ Environment=PATH=${o}/.local/bin:${s}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
129
129
  Restart=on-failure
130
130
  RestartSec=2
131
131
 
132
132
  [Install]
133
133
  WantedBy=default.target
134
- `}function We({agentDir:e=b,nodeBin:t=process.execPath,home:n=x.homedir()}={}){let o=d.dirname(t),r=`${n}/Library/Logs/bostrat`;return`<?xml version="1.0" encoding="UTF-8"?>
134
+ `}function We({agentDir:e=b,nodeBin:t=process.execPath,home:n=x.homedir()}={}){let o=d.dirname(t),s=`${n}/Library/Logs/bostrat`;return`<?xml version="1.0" encoding="UTF-8"?>
135
135
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
136
136
  <plist version="1.0">
137
137
  <dict>
@@ -149,11 +149,11 @@ WantedBy=default.target
149
149
  </dict>
150
150
  <key>RunAtLoad</key><true/>
151
151
  <key>KeepAlive</key><true/>
152
- <key>StandardOutPath</key><string>${r}/node.out.log</string>
153
- <key>StandardErrorPath</key><string>${r}/node.err.log</string>
152
+ <key>StandardOutPath</key><string>${s}/node.out.log</string>
153
+ <key>StandardErrorPath</key><string>${s}/node.err.log</string>
154
154
  </dict>
155
155
  </plist>
156
- `}function Ye(e=process.platform,t=x.homedir()){return e==="darwin"?{kind:"launchd",file:d.join(t,"Library","LaunchAgents","com.bostrat.node.plist")}:{kind:"systemd",file:d.join(t,".config","systemd","user","bostrat-node.service")}}async function ze({uninstall:e=!1,start:t=!0,platform:n=process.platform,log:o=console.log,agentDir:r=b}={}){let{kind:s,file:i}=Ye(n);if(!e&&r.split(d.sep).includes("_npx"))return o("\u2717 running from the npx cache \u2014 a service must point at a durable install."),o(" fix: npm install -g bostrat-node && bostrat-node install-service"),1;if(e){s==="systemd"?(await O("systemctl",["--user","disable","--now","bostrat-node.service"]).catch(()=>{}),m.rmSync(i,{force:!0}),await O("systemctl",["--user","daemon-reload"])):(await O("launchctl",["unload","-w",i]).catch(()=>{}),m.rmSync(i,{force:!0})),o(`removed ${i}`);return}m.mkdirSync(d.dirname(i),{recursive:!0}),s==="systemd"?(m.writeFileSync(i,He()),await O("systemctl",["--user","daemon-reload"]),t&&await O("systemctl",["--user","enable","--now","bostrat-node.service"]),o(`installed ${i}${t?" (enabled + started)":""}`),o("logs: journalctl --user -u bostrat-node.service -f")):(m.mkdirSync(d.join(x.homedir(),"Library","Logs","bostrat"),{recursive:!0}),m.writeFileSync(i,We()),t&&await O("launchctl",["load","-w",i]),o(`installed ${i}${t?" (loaded)":""}`),o("logs: ~/Library/Logs/bostrat/node.{out,err}.log"))}async function Gt(e=process.argv.slice(2)){let t=e[0],n=A();if(t==="--version"||t==="-v"||t==="version")return console.log(Pe),0;if(t==="init")return(await Me({envFile:n})).ok?0:1;if(t==="doctor"){let o={...I(n),...process.env};return oe(await ne(o,{envFile:n}))?0:1}if(t==="run"||t==="start")return Ke({envFile:n}),null;if(t==="install-service")return await ze({uninstall:e.includes("--uninstall"),start:!e.includes("--no-start")})||0;if(t==="fly"){let{flyWizard:o}=await Promise.resolve().then(()=>(te(),ee));return await o({argv:e.slice(1)})}return console.log(`bostrat-node \u2014 install and run a bostrat node (plane P1)
156
+ `}function Ye(e=process.platform,t=x.homedir()){return e==="darwin"?{kind:"launchd",file:d.join(t,"Library","LaunchAgents","com.bostrat.node.plist")}:{kind:"systemd",file:d.join(t,".config","systemd","user","bostrat-node.service")}}async function ze({uninstall:e=!1,start:t=!0,platform:n=process.platform,log:o=console.log,agentDir:s=b}={}){let{kind:r,file:i}=Ye(n);if(!e&&s.split(d.sep).includes("_npx"))return o("\u2717 running from the npx cache \u2014 a service must point at a durable install."),o(" fix: npm install -g bostrat-node && bostrat-node install-service"),1;if(e){r==="systemd"?(await O("systemctl",["--user","disable","--now","bostrat-node.service"]).catch(()=>{}),m.rmSync(i,{force:!0}),await O("systemctl",["--user","daemon-reload"])):(await O("launchctl",["unload","-w",i]).catch(()=>{}),m.rmSync(i,{force:!0})),o(`removed ${i}`);return}m.mkdirSync(d.dirname(i),{recursive:!0}),r==="systemd"?(m.writeFileSync(i,He()),await O("systemctl",["--user","daemon-reload"]),t&&await O("systemctl",["--user","enable","--now","bostrat-node.service"]),o(`installed ${i}${t?" (enabled + started)":""}`),o("logs: journalctl --user -u bostrat-node.service -f")):(m.mkdirSync(d.join(x.homedir(),"Library","Logs","bostrat"),{recursive:!0}),m.writeFileSync(i,We()),t&&await O("launchctl",["load","-w",i]),o(`installed ${i}${t?" (loaded)":""}`),o("logs: ~/Library/Logs/bostrat/node.{out,err}.log"))}async function Gt(e=process.argv.slice(2)){let t=e[0],n=A();if(t==="--version"||t==="-v"||t==="version")return console.log($e),0;if(t==="init")return(await Me({envFile:n})).ok?0:1;if(t==="doctor"){let o={...I(n),...process.env};return oe(await ne(o,{envFile:n}))?0:1}if(t==="run"||t==="start")return Ke({envFile:n}),null;if(t==="install-service")return await ze({uninstall:e.includes("--uninstall"),start:!e.includes("--no-start")})||0;if(t==="fly"){let{flyWizard:o}=await Promise.resolve().then(()=>(te(),ee));return await o({argv:e.slice(1)})}return console.log(`bostrat-node \u2014 install and run a bostrat node (plane P1)
157
157
 
158
158
  usage: bostrat-node <init | doctor | run | install-service [--uninstall] [--no-start] | fly | --version>
159
159