bostrat-node 0.2.11 → 0.2.13

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 +35 -35
  2. package/dist/index.js +142 -142
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- var lt=Object.defineProperty;var ut=(t,e)=>()=>(t&&(e=t(t=0)),e);var dt=(t,e)=>{for(var n in e)lt(t,n,{get:e[n],enumerable:!0})};var ot={};dt(ot,{NODE_IMAGE:()=>U,commandPlan:()=>et,flyToml:()=>tt,flyWizard:()=>Dt,parseFlyFlags:()=>nt,stageConfig:()=>rt});import C from"node:fs";import _ from"node:path";import Nt from"node:os";import Pt from"node:readline/promises";import{execFile as jt}from"node:child_process";import{createRequire as It}from"node:module";import{randomUUID as Bt}from"node:crypto";function tt({app:t,region:e,nodeName:n=t,planeUrl:r=Q,image:s=U}){return`# bostrat node on YOUR Fly org \u2014 written by \`bostrat-node fly\`.
1
+ var lt=Object.defineProperty;var ut=(t,e)=>()=>(t&&(e=t(t=0)),e);var pt=(t,e)=>{for(var n in e)lt(t,n,{get:e[n],enumerable:!0})};var ot={};pt(ot,{NODE_IMAGE:()=>H,commandPlan:()=>tt,flyToml:()=>Q,flyWizard:()=>Lt,parseFlyFlags:()=>et,stageConfig:()=>nt});import U from"node:fs";import x from"node:path";import Nt from"node:os";import Pt from"node:readline/promises";import{execFile as jt}from"node:child_process";import{createRequire as It}from"node:module";import{randomUUID as Bt}from"node:crypto";function Q({app:t,region:e,nodeName:n=t,planeUrl:o=q,image:s=H}){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 ${t} --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.
@@ -16,7 +16,7 @@ primary_region = "${e}"
16
16
  # $HOME on the volume: your agent logins, repos, and node state survive
17
17
  # machine replacement (the "your login stays on your node" promise).
18
18
  HOME = "/data/home"
19
- BOSTRAT_PLANE_URL = "${r}"
19
+ BOSTRAT_PLANE_URL = "${o}"
20
20
  BOSTRAT_NODE_ID = "${t}"
21
21
  BOSTRAT_NODE_NAME = "${n}"
22
22
  BOSTRAT_REPOS_ROOT = "/data/home/repos"
@@ -34,64 +34,64 @@ primary_region = "${e}"
34
34
  # Scale later with: fly scale memory 4096 -a ${t}
35
35
  size = "shared-cpu-2x"
36
36
  memory = "2gb"
37
- `}function et({app:t,org:e,region:n,sizeGb:r,token:s,owner:o,dir:i}){let a=[`BOSTRAT_PLANE_TOKEN=${s}`,...o?[`BOSTRAT_OWNER=${o}`]:[]];return[{argv:["apps","create",t,"-o",e],display:`fly apps create ${t} -o ${e}`,tolerate:/already|taken|exists/i},{argv:["volumes","create","node_data","-a",t,"-r",n,"-s",String(r),"-y"],display:`fly volumes create node_data -a ${t} -r ${n} -s ${r} -y`,tolerate:/already|exists/i},{argv:["secrets","import","-a",t,"--stage"],display:`fly secrets import -a ${t} --stage # BOSTRAT_PLANE_TOKEN=<redacted>${o?" BOSTRAT_OWNER=\u2026":""} via stdin`,stdin:a.join(`
37
+ `}function tt({app:t,org:e,region:n,sizeGb:o,token:s,owner:r,dir:i}){let a=[`BOSTRAT_PLANE_TOKEN=${s}`,...r?[`BOSTRAT_OWNER=${r}`]:[]];return[{argv:["apps","create",t,"-o",e],display:`fly apps create ${t} -o ${e}`,tolerate:/already|taken|exists/i},{argv:["volumes","create","node_data","-a",t,"-r",n,"-s",String(o),"-y"],display:`fly volumes create node_data -a ${t} -r ${n} -s ${o} -y`,tolerate:/already|exists/i},{argv:["secrets","import","-a",t,"--stage"],display:`fly secrets import -a ${t} --stage # BOSTRAT_PLANE_TOKEN=<redacted>${r?" BOSTRAT_OWNER=\u2026":""} via stdin`,stdin:a.join(`
38
38
  `)+`
39
- `},{argv:["deploy",i,"-c",_.join(i,"fly.toml"),"-a",t,"--ha=false"],display:`fly deploy ${i} -c ${_.join(i,"fly.toml")} -a ${t} --ha=false`}]}function nt(t=[]){let e={},n={"--app":"app","--org":"org","--region":"region","--size-gb":"sizeGb","--name":"name","--plane-url":"planeUrl","--token":"token","--owner":"owner","--image":"image"};for(let r=0;r<t.length;r++){let s=t[r];if(s==="--yes"||s==="-y")e.yes=!0;else if(n[s])e[n[s]]=t[++r]??"";else if(s.startsWith("--")&&s.includes("=")){let[o,...i]=s.split("=");n[o]?e[n[o]]=i.join("="):o==="--yes"&&(e.yes=!0)}}return e.sizeGb!=null&&(e.sizeGb=Number(e.sizeGb)||10),e}function rt({app:t,dest:e,toml:n}){let r=e||_.join(Nt.homedir(),".bostrat","fly",t);C.mkdirSync(r,{recursive:!0});for(let s of["Dockerfile",".dockerignore","package.json","package-lock.json","src","dist","bin","node-entrypoint.sh"])C.rmSync(_.join(r,s),{recursive:!0,force:!0});return C.writeFileSync(_.join(r,"fly.toml"),n),{dir:r,manifest:["fly.toml"]}}async function Mt({ask:t,output:e,exec:n,flag:r}){if(r)return r;try{let{stdout:s}=await j(["orgs","list","--json"],{exec:n}),o=JSON.parse(s),i=Array.isArray(o)?o.map(a=>a.Slug||a.slug).filter(Boolean):Object.keys(o);if(i.length===1)return e.write(`Org: ${i[0]} (your only org)
40
- `),i[0];if(i.length>1)return await t(`Fly org (${i.join(" / ")})`,i[0])}catch{}return await t("Fly org slug (see `fly orgs list`)","personal")}async function Dt({argv:t=[],input:e=process.stdin,output:n=process.stdout,exec:r,stageDest:s}={}){let o=nt(t),i=Pt.createInterface({input:e,output:n}),a=async(c,m)=>(await i.question(m?`${c} [${m}]: `:`${c}: `)).trim()||m||"",d=c=>(i.close(),c);n.write(`bostrat-node fly \u2014 a node on YOUR Fly org, on your bill.
39
+ `},{argv:["deploy",i,"-c",x.join(i,"fly.toml"),"-a",t,"--ha=false"],display:`fly deploy ${i} -c ${x.join(i,"fly.toml")} -a ${t} --ha=false`}]}function et(t=[]){let e={},n={"--app":"app","--org":"org","--region":"region","--size-gb":"sizeGb","--name":"name","--plane-url":"planeUrl","--token":"token","--owner":"owner","--image":"image"};for(let o=0;o<t.length;o++){let s=t[o];if(s==="--yes"||s==="-y")e.yes=!0;else if(n[s])e[n[s]]=t[++o]??"";else if(s.startsWith("--")&&s.includes("=")){let[r,...i]=s.split("=");n[r]?e[n[r]]=i.join("="):r==="--yes"&&(e.yes=!0)}}return e.sizeGb!=null&&(e.sizeGb=Number(e.sizeGb)||10),e}function nt({app:t,dest:e,toml:n}){let o=e||x.join(Nt.homedir(),".bostrat","fly",t);U.mkdirSync(o,{recursive:!0});for(let s of["Dockerfile",".dockerignore","package.json","package-lock.json","src","dist","bin","node-entrypoint.sh"])U.rmSync(x.join(o,s),{recursive:!0,force:!0});return U.writeFileSync(x.join(o,"fly.toml"),n),{dir:o,manifest:["fly.toml"]}}async function Dt({ask:t,output:e,exec:n,flag:o}){if(o)return o;try{let{stdout:s}=await I(["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 e.write(`Org: ${i[0]} (your only org)
40
+ `),i[0];if(i.length>1)return await t(`Fly org (${i.join(" / ")})`,i[0])}catch{}return await t("Fly org slug (see `fly orgs list`)","personal")}async function Lt({argv:t=[],input:e=process.stdin,output:n=process.stdout,exec:o,stageDest:s}={}){let r=et(t),i=Pt.createInterface({input:e,output:n}),a=async(c,h)=>(await i.question(h?`${c} [${h}]: `:`${c}: `)).trim()||h||"",p=c=>(i.close(),c);n.write(`bostrat-node fly \u2014 a node on YOUR Fly org, on your bill.
41
41
  bostrat never sees your Fly account: this wizard only runs your own \`fly\` CLI.
42
42
 
43
- `);try{await j(["version"],{exec:r})}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"),d(1)}try{let{stdout:c}=await j(["auth","whoami"],{exec:r});n.write(`\u2713 signed in to Fly as ${c.trim()}
44
- `)}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"),d(1)}let f=await Mt({ask:a,output:n,exec:r,flag:o.org}),u=o.app||await a("App name",`bostrat-node-${Bt().slice(0,4)}`),k=o.region||await a("Region (see `fly platform regions`)","iad"),I=o.sizeGb||Number(await a("Volume size GB (logins + repos live here)","10"))||10,y=o.name||u,E=o.planeUrl||Q,R=o.token||await a("Node token (minted in the bostrat setup chat \u2014 shown once)");if(!R)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.
45
- `),d(1);let B=o.owner??await a("Owner userId (shown next to the token; empty = infer from token)",""),v=o.image||U,{dir:g}=rt({app:u,dest:s,toml:tt({app:u,region:k,nodeName:y,planeUrl:E,image:v})});n.write(`
46
- wrote ${_.join(g,"fly.toml")} \u2014 deploys the prebuilt node image ${v}
43
+ `);try{await I(["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"),p(1)}try{let{stdout:c}=await I(["auth","whoami"],{exec:o});n.write(`\u2713 signed in to Fly as ${c.trim()}
44
+ `)}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"),p(1)}let d=await Dt({ask:a,output:n,exec:o,flag:r.org}),u=r.app||await a("App name",`bostrat-node-${Bt().slice(0,4)}`),k=r.region||await a("Region (see `fly platform regions`)","iad"),B=r.sizeGb||Number(await a("Volume size GB (logins + repos live here)","10"))||10,T=r.name||u,E=r.planeUrl||q,v=r.token||await a("Node token (minted in the bostrat setup chat \u2014 shown once)");if(!v)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.
45
+ `),p(1);let F=r.owner??await a("Owner userId (shown next to the token; empty = infer from token)",""),R=r.image||H,{dir:_}=nt({app:u,dest:s,toml:Q({app:u,region:k,nodeName:T,planeUrl:E,image:R})});n.write(`
46
+ wrote ${x.join(_,"fly.toml")} \u2014 deploys the prebuilt node image ${R}
47
47
  (claude + cursor-agent + codex baked in, logged out; nothing builds on your machine)
48
48
 
49
49
  Plan (your flyctl, your org, your bill):
50
- `);let T=et({app:u,org:f,region:k,sizeGb:I,token:R,owner:B,dir:g});for(let c of T)n.write(` $ ${c.display}
51
- `);if(!o.yes&&(await a(`
50
+ `);let S=tt({app:u,org:d,region:k,sizeGb:B,token:v,owner:F,dir:_});for(let c of S)n.write(` $ ${c.display}
51
+ `);if(!r.yes&&(await a(`
52
52
  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.
53
- `),d(1);for(let c of T){n.write(`
53
+ `),p(1);for(let c of S){n.write(`
54
54
  \u2192 ${c.display}
55
- `);try{let{stdout:m,stderr:$}=await j(c.argv,{stdin:c.stdin,exec:r}),W=`${m||""}${$||""}`.trim();W&&n.write(W.split(`
55
+ `);try{let{stdout:h,stderr:$}=await I(c.argv,{stdin:c.stdin,exec:o}),W=`${h||""}${$||""}`.trim();W&&n.write(W.split(`
56
56
  `).map(ct=>` ${ct}`).join(`
57
57
  `)+`
58
- `)}catch(m){let $=`${m?.stdout||""}${m?.stderr||""}${m?.message||""}`;if(c.tolerate&&c.tolerate.test($)){n.write(` (already exists \u2014 continuing)
58
+ `)}catch(h){let $=`${h?.stdout||""}${h?.stderr||""}${h?.message||""}`;if(c.tolerate&&c.tolerate.test($)){n.write(` (already exists \u2014 continuing)
59
59
  `);continue}return n.write(`\u2717 failed: ${$.trim().split(`
60
60
  `).slice(-4).join(`
61
61
  `)}
62
62
  fix and re-run \`bostrat-node fly\` \u2014 every step is safe to repeat.
63
- `),d(1)}}return n.write(`
63
+ `),p(1)}}return n.write(`
64
64
  \u2713 deployed. The node dials out to the plane by itself \u2014 watch the bostrat setup
65
65
  chat: the node step advances on its own within a minute.
66
66
  logs: fly logs -a ${u}
67
- redeploy: fly deploy ${g} -c ${_.join(g,"fly.toml")} -a ${u} --ha=false
67
+ redeploy: fly deploy ${_} -c ${x.join(_,"fly.toml")} -a ${u} --ha=false
68
68
  Vendor logins (Claude/Codex) are NOT set up here \u2014 you type those later, inside
69
69
  boxes, and they land on this machine's volume, never on bostrat (box-auth-policy).
70
- `),d(0)}var Q,Ft,U,j,st=ut(()=>{Q="wss://plane.bostrat.ai/v1/node",Ft=It(import.meta.url)("../package.json").version,U=`ghcr.io/globocodes/bostrat-node:${Ft}`;j=(t,{stdin:e,exec:n}={})=>new Promise((r,s)=>{if(n)return n(t,{stdin:e}).then(r,s);let o=jt("fly",t,{timeout:6e5,maxBuffer:16*1024*1024},(i,a,d)=>i?s(Object.assign(i,{stdout:a,stderr:d})):r({stdout:a,stderr:d}));e!=null&&o.stdin?.end(e)})});import p from"node:fs";import l from"node:path";import b from"node:os";import{createRequire as H}from"node:module";import{execFile as Lt,spawn as Ct}from"node:child_process";import{promisify as Ut}from"node:util";import Ht from"node:readline/promises";import{randomUUID as Kt}from"node:crypto";import{fileURLToPath as zt}from"node:url";import N from"node:fs";import F from"node:path";import ft from"node:os";var pt=process.env.BOSTRAT_STATE_DIR||F.join(process.env.HOME||ft.tmpdir(),".bostrat"),O=()=>F.join(pt,"node.env");function M(t){let e=String(t||"").trim();if(!e)return"";let n=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:`wss://${e}`,r;try{r=new URL(n)}catch{return e}let s={"https:":"wss:","http:":"ws:","wss:":"wss:","ws:":"ws:"}[r.protocol];return s?(r.protocol=s,(r.pathname===""||r.pathname==="/")&&(r.pathname="/v1/node"),r.toString()):e}function P(t){let e;try{e=N.readFileSync(t,"utf8")}catch{return{}}let n={};for(let r of e.split(`
71
- `)){let s=r.trim();if(!s||s.startsWith("#"))continue;let o=/^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.exec(s);if(!o)continue;let i=o[2].trim();(i.startsWith('"')&&i.endsWith('"')||i.startsWith("'")&&i.endsWith("'"))&&(i=i.slice(1,-1)),n[o[1]]=i}return n}function Y(t,e=process.env){let n=P(t);for(let[r,s]of Object.entries(n))r in e||(e[r]=s);return n}function G(t,e,{header:n=""}={}){let r=[];n&&r.push(...n.split(`
72
- `).map(s=>s?`# ${s}`:"#"));for(let[s,o]of Object.entries(e))o==null||o===""||r.push(`${s}=${o}`);N.mkdirSync(F.dirname(t),{recursive:!0}),N.writeFileSync(t,r.join(`
70
+ `),p(0)}var q,Ft,H,I,rt=ut(()=>{q="wss://plane.bostrat.ai/v1/node",Ft=It(import.meta.url)("../package.json").version,H=`ghcr.io/globocodes/bostrat-node:${Ft}`;I=(t,{stdin:e,exec:n}={})=>new Promise((o,s)=>{if(n)return n(t,{stdin:e}).then(o,s);let r=jt("fly",t,{timeout:6e5,maxBuffer:16*1024*1024},(i,a,p)=>i?s(Object.assign(i,{stdout:a,stderr:p})):o({stdout:a,stderr:p}));e!=null&&r.stdin?.end(e)})});import m from"node:fs";import l from"node:path";import A from"node:os";import{createRequire as K}from"node:module";import{execFile as Mt,spawn as Ct}from"node:child_process";import{promisify as Ut}from"node:util";import Ht from"node:readline/promises";import{randomUUID as Kt}from"node:crypto";import{fileURLToPath as zt}from"node:url";import N from"node:fs";import D from"node:path";import dt from"node:os";var ft=process.env.BOSTRAT_STATE_DIR||D.join(process.env.HOME||dt.tmpdir(),".bostrat"),O=()=>D.join(ft,"node.env");function L(t){let e=String(t||"").trim();if(!e)return"";let n=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:`wss://${e}`,o;try{o=new URL(n)}catch{return e}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()):e}function P(t){let e;try{e=N.readFileSync(t,"utf8")}catch{return{}}let n={};for(let o of e.split(`
71
+ `)){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 Y(t,e=process.env){let n=P(t);for(let[o,s]of Object.entries(n))o in e||(e[o]=s);return n}function G(t,e,{header:n=""}={}){let o=[];n&&o.push(...n.split(`
72
+ `).map(s=>s?`# ${s}`:"#"));for(let[s,r]of Object.entries(e))r==null||r===""||o.push(`${s}=${r}`);N.mkdirSync(D.dirname(t),{recursive:!0}),N.writeFileSync(t,o.join(`
73
73
  `)+`
74
- `,{mode:384}),N.chmodSync(t,384)}function X(t=process.platform){return t==="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 vt}from"node:child_process";import{promisify as kt}from"node:util";import xt from"node:os";import Ot from"node:path";import{execFile as bt}from"node:child_process";import{promisify as At}from"node:util";import Z from"node:path";import gt from"node:os";import{execFile as Tt}from"node:child_process";import{promisify as _t}from"node:util";import D from"node:path";import{execFile as ht}from"node:child_process";import{promisify as wt}from"node:util";var Oe=wt(ht),V=process.env.HOME||"/home/globo",yt=D.join(process.env.BOSTRAT_STATE_DIR||D.join(V,".bostrat"),"repos"),be=[...(process.env.BOSTRAT_REPOS_ROOT||D.join(V,"Documents")).split(","),yt].map(t=>t.trim()).filter(Boolean),Ae=Number(process.env.BOSTRAT_REPOS_DEPTH)||3;var je=_t(Tt),St=process.env.BOSTRAT_STATE_DIR||Z.join(process.env.HOME||gt.tmpdir(),".bostrat"),Ie=Z.join(St,"repos");var Be=5*6e4;var Fe=10*6e4;var Xe=At(bt),Ve=process.env.BOSTRAT_STATE_DIR||Ot.join(process.env.HOME||xt.tmpdir(),".bostrat");var Ze=25*1024;import Et from"node:os";import J from"node:path";var Rt=process.env.BOSTRAT_DEBUG_DIR||J.join(Et.homedir(),".bostrat","debug"),en=J.join(Rt,"handoff.jsonl"),nn=Number(process.env.BOSTRAT_HANDOFF_DEBUG_MAX)||500;var $t=kt(vt);var Sn=process.env.BOSTRAT_TMUX_BIN||"/usr/bin/tmux",xn=process.env.BOSTRAT_TMUX_SOCKET||"/tmp/tmux-1000/default",On=process.env.BOSTRAT_DEFAULT_CWD||process.env.HOME||"/",bn=process.env.BOSTRAT_AGENT_CMD||"claude --dangerously-skip-permissions";async function q(t,{loginShell:e=!1,failOpen:n=!1}={}){if(!t)return!1;let r=e?process.env.SHELL||"/bin/sh":"sh",s=e?"-lic":"-c";try{return await $t(r,[s,'command -v "$1" >/dev/null 2>&1',"_",t],{timeout:5e3}),!0}catch(o){return o?.code===1?!1:n}}var L={claude:"npm install -g @anthropic-ai/claude-code",codex:"npm install -g @openai/codex","cursor-agent":"curl https://cursor.com/install -fsS | bash"};var An=Number(process.env.BOSTRAT_PROMPT_CAPTURE_COLS)||100,En=Number(process.env.BOSTRAT_PROMPT_CAPTURE_ROWS)||40,Rn=Number(process.env.BOSTRAT_PROMPT_CAPTURE_LINES)||80,vn=Number(process.env.BOSTRAT_BOX_COLS)||120,kn=Number(process.env.BOSTRAT_BOX_ROWS)||40;var S=Ut(Lt),z=l.dirname(zt(import.meta.url)),x=l.resolve(z,".."),Wt=l.join(z,"index.js"),Yt="wss://plane.bostrat.ai/v1/node",Gt=H(import.meta.url)("../package.json").version,w=(t,e)=>({name:t,level:"pass",detail:e}),A=(t,e,n)=>({name:t,level:"warn",detail:e,fix:n}),h=(t,e,n)=>({name:t,level:"fail",detail:e,fix:n});async function Xt(){let[t,e]=process.versions.node.split(".").map(Number);return t>22||t===22&&e>=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 Vt(t){let e;try{e=p.statSync(t)}catch{return A("node.env",`${t} missing`,"run `bostrat-node init`")}let n=e.mode&511;return n&63?A("node.env",`${t} mode ${n.toString(8)} \u2014 group/world readable and it can hold a key`,`chmod 600 ${t}`):w("node.env",`${t} (0600)`)}async function Zt(t){let e=t.BOSTRAT_TMUX_BIN||"/usr/bin/tmux";try{let{stdout:n}=await S(e,["-V"],{timeout:5e3});return w("tmux",`${e} (${n.trim()})`)}catch{return h("tmux",`${e} not runnable`,process.platform==="darwin"?"brew install tmux (then BOSTRAT_TMUX_BIN=/opt/homebrew/bin/tmux)":"install tmux")}}async function K(t,{required:e=!1}={}){if(await q(t,{loginShell:!0,failOpen:!1}))return w(t,"resolves on the login-shell PATH");let r="not on the login-shell PATH \u2014 boxes for this agent (and handoffs to it) will be refused",s=L[t]?`${L[t]}${t==="cursor-agent"?" # installs to ~/.local/bin \u2014 ensure your login shell has it on PATH":""}`:`install ${t} so \`$SHELL -lic 'command -v ${t}'\` finds it`;return e?h(t,r,s):A(t,r,s)}async function Jt(){let t=await Promise.all(["claude","codex","cursor-agent"].map(e=>K(e)));return t.some(e=>e.level==="pass")||t.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")),t}async function qt(){try{let e=H(l.join(x,"src","node-cli.js"))("node-pty");return await new Promise((n,r)=>{let s=e.spawn("/bin/echo",["ok"],{cols:20,rows:5}),o=setTimeout(()=>r(new Error("spawn timeout")),5e3);s.onExit(()=>{clearTimeout(o),n()})}),w("node-pty","loads and spawns under this runtime")}catch(t){let e=`cd ${x} && npm rebuild node-pty # with THIS node first on PATH \u2014 never the system npm`;try{let n=H(l.join(x,"package.json")),r=l.join(l.dirname(n.resolve("node-pty/package.json")),"prebuilds",`${process.platform}-${process.arch}`,"spawn-helper");p.existsSync(r)&&!(p.statSync(r).mode&73)&&(e=`chmod +x ${r} # node-pty ships it non-executable`)}catch{}return h("node-pty",`load/spawn failed: ${t?.message||t}`,e)}}function Qt(t){let e=t.BOSTRAT_CHROMIUM_BIN||"/usr/bin/chromium";return p.existsSync(e)?w("chromium (mocks)",e):A("chromium (mocks)",`${e} missing \u2014 mock rendering unavailable`,"install Chromium/Chrome and set BOSTRAT_CHROMIUM_BIN")}function te(t){let e=t.BOSTRAT_CLAUDE_USE_API_KEY==="1";return e&&!t.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",e?"BYO API key (injected per new box)":"box-local login (subscription \u2014 you type `claude login` inside the box)")}async function ee(t,{WebSocketImpl:e}={}){if(!t.BOSTRAT_PLANE_URL||!t.BOSTRAT_PLANE_TOKEN)return A("plane link","BOSTRAT_PLANE_URL/TOKEN unset \u2014 node runs pure M1 (local only)","run `bostrat-node init`");let n=e||(await import("ws")).default,r=Date.now(),s=M(t.BOSTRAT_PLANE_URL);return await new Promise(o=>{let i=new n(s,{headers:{authorization:`Bearer ${t.BOSTRAT_PLANE_TOKEN}`}}),a=f=>{clearTimeout(d);try{i.close()}catch{}o(f)},d=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-${Kt().slice(0,8)}`}))),i.on("message",f=>{try{let u=JSON.parse(f);u.type==="hello_ok"?a(w("plane link",`hello_ok in ${Date.now()-r}ms (${s})`)):u.type==="error"&&a(h("plane link",`plane said: ${u.code} ${u.message||""}`,"check the token"))}catch{}}),i.on("error",f=>a(h("plane link",`${f?.message||f}`,"check the URL, the token, and the plane's IP gate")))})}function ne(t){return t.BOSTRAT_STATE_REMOTE?w("state remote",`${t.BOSTRAT_STATE_REMOTE} (this node's own \u2014 never another node's repo)`):A("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 it(t,e={}){let n=[];return n.push(await Xt()),n.push(Vt(e.envFile||O())),n.push(await Zt(t)),n.push(...await Jt()),n.push(await K("git",{required:!0})),n.push(await K("gh")),n.push(await qt()),n.push(Qt(t)),n.push(te(t)),n.push(await ee(t,e)),n.push(ne(t)),n}function at(t,e=console.log){let n={pass:"\u2713",warn:"!",fail:"\u2717"};for(let o of t)e(`${n[o.level]} ${o.name}: ${o.detail}`),o.fix&&o.level!=="pass"&&e(` fix: ${o.fix}`);let r=t.filter(o=>o.level==="fail").length,s=t.filter(o=>o.level==="warn").length;return e(r?`
75
- FAIL \u2014 ${r} blocking, ${s} warnings`:`
76
- OK \u2014 0 blocking, ${s} warnings`),r===0}async function re({envFile:t=O(),input:e=process.stdin,output:n=process.stdout}={}){let r=P(t),s=Ht.createInterface({input:e,output:n}),o=async(T,c)=>(await s.question(c?`${T} [${c}]: `:`${T}: `)).trim()||c||"";n.write(`bostrat-node init \u2014 plane link + machine config. No vendor logins here:
74
+ `,{mode:384}),N.chmodSync(t,384)}function X(t=process.platform){return t==="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 Rt}from"node:child_process";import{promisify as kt}from"node:util";import xt from"node:os";import bt from"node:path";import{execFile as Ot}from"node:child_process";import{promisify as At}from"node:util";import Z from"node:path";import gt from"node:os";import{execFile as Tt}from"node:child_process";import{promisify as _t}from"node:util";import M from"node:path";import{execFile as ht}from"node:child_process";import{promisify as wt}from"node:util";var Ae=wt(ht),V=process.env.HOME||"/home/globo",yt=M.join(process.env.BOSTRAT_STATE_DIR||M.join(V,".bostrat"),"repos"),Ee=[...(process.env.BOSTRAT_REPOS_ROOT||M.join(V,"Documents")).split(","),yt].map(t=>t.trim()).filter(Boolean),ve=Number(process.env.BOSTRAT_REPOS_DEPTH)||3;var Be=_t(Tt),St=process.env.BOSTRAT_STATE_DIR||Z.join(process.env.HOME||gt.tmpdir(),".bostrat"),Fe=Z.join(St,"repos");var De=5*6e4;var Le=10*6e4;var Ze=At(Ot),Je=process.env.BOSTRAT_STATE_DIR||bt.join(process.env.HOME||xt.tmpdir(),".bostrat");var qe=25*1024;import Et from"node:os";import J from"node:path";var vt=process.env.BOSTRAT_DEBUG_DIR||J.join(Et.homedir(),".bostrat","debug"),on=J.join(vt,"handoff.jsonl"),rn=Number(process.env.BOSTRAT_HANDOFF_DEBUG_MAX)||500;var $t=kt(Rt);var bn=process.env.BOSTRAT_TMUX_BIN||"/usr/bin/tmux",On=process.env.BOSTRAT_TMUX_SOCKET||"/tmp/tmux-1000/default",An=process.env.BOSTRAT_DEFAULT_CWD||process.env.HOME||"/",En=process.env.BOSTRAT_AGENT_CMD||"claude --dangerously-skip-permissions";async function C(t,{loginShell:e=!1,failOpen:n=!1}={}){if(!t)return!1;let o=e?process.env.SHELL||"/bin/sh":"sh",s=e?"-lic":"-c";try{return await $t(o,[s,'command -v "$1" >/dev/null 2>&1',"_",t],{timeout:5e3}),!0}catch(r){return r?.code===1?!1:n}}var j={claude:"npm install -g @anthropic-ai/claude-code",codex:"npm install -g @openai/codex","cursor-agent":"curl https://cursor.com/install -fsS | bash",gh:"apt install gh (Debian: enable cli.github.com/packages) / brew install gh \u2014 see https://github.com/cli/cli#installation"};var vn=Number(process.env.BOSTRAT_PROMPT_CAPTURE_COLS)||100,Rn=Number(process.env.BOSTRAT_PROMPT_CAPTURE_ROWS)||40,kn=Number(process.env.BOSTRAT_PROMPT_CAPTURE_LINES)||80,$n=Number(process.env.BOSTRAT_BOX_COLS)||120,Nn=Number(process.env.BOSTRAT_BOX_ROWS)||40;var y=Ut(Mt),z=l.dirname(zt(import.meta.url)),b=l.resolve(z,".."),Wt=l.join(z,"index.js"),Yt="wss://plane.bostrat.ai/v1/node",Gt=K(import.meta.url)("../package.json").version,f=(t,e)=>({name:t,level:"pass",detail:e}),g=(t,e,n)=>({name:t,level:"warn",detail:e,fix:n}),w=(t,e,n)=>({name:t,level:"fail",detail:e,fix:n});async function Xt(){let[t,e]=process.versions.node.split(".").map(Number);return t>22||t===22&&e>=5?f("node runtime",`${process.version} at ${process.execPath}`):w("node runtime",`${process.version} < 22.5`,"install Node \u226522.5 via nvm and re-run under it")}function Vt(t){let e;try{e=m.statSync(t)}catch{return g("node.env",`${t} missing`,"run `bostrat-node init`")}let n=e.mode&511;return n&63?g("node.env",`${t} mode ${n.toString(8)} \u2014 group/world readable and it can hold a key`,`chmod 600 ${t}`):f("node.env",`${t} (0600)`)}async function Zt(t){let e=t.BOSTRAT_TMUX_BIN||"/usr/bin/tmux";try{let{stdout:n}=await y(e,["-V"],{timeout:5e3});return f("tmux",`${e} (${n.trim()})`)}catch{return w("tmux",`${e} not runnable`,process.platform==="darwin"?"brew install tmux (then BOSTRAT_TMUX_BIN=/opt/homebrew/bin/tmux)":"install tmux")}}async function st(t,{required:e=!1}={}){if(await C(t,{loginShell:!0,failOpen:!1}))return f(t,"resolves on the login-shell PATH");let o="not on the login-shell PATH \u2014 boxes for this agent (and handoffs to it) will be refused",s=j[t]?`${j[t]}${t==="cursor-agent"?" # installs to ~/.local/bin \u2014 ensure your login shell has it on PATH":""}`:`install ${t} so \`$SHELL -lic 'command -v ${t}'\` finds it`;return e?w(t,o,s):g(t,o,s)}async function Jt(){let t=process.env.SHELL||"/bin/sh";try{let{stdout:e}=await y(t,["-lic","gh --version"],{timeout:1e4}),n=String(e).match(/gh version [^\s]+/)?.[0]||"runs on the login-shell PATH";return f("gh (GitHub CLI)",n)}catch{return g("gh (GitHub CLI)","no real gh on the login-shell PATH (the bostrat gh shim alone doesn't count) \u2014 PR tab, ship offers, and Fix-CI are unavailable on this node",j.gh)}}async function qt(){let t=await Promise.all(["claude","codex","cursor-agent"].map(e=>st(e)));return t.some(e=>e.level==="pass")||t.push(w("agent CLIs","no agent CLI found at all \u2014 a node with nothing to drive","install at least one of claude / codex / cursor-agent")),t}async function Qt(){let t=[...process.platform==="linux"?[["fuser","stopped views can't free their ports (they leak, and the port can't be reused)","apt install psmisc"]]:[],["pgrep","agent-swap can't detect an idle pane shell \u2014 swaps may misfire","apt install procps"],["npm","codex auto-update and `npm run` views are unavailable","install Node.js with npm on the service PATH"]];return Promise.all(t.map(async([e,n,o])=>await C(e,{failOpen:!1})?f(e,"resolves on the service PATH"):g(e,`not on the service PATH \u2014 ${n}`,o)))}async function te(){try{let e=K(l.join(b,"src","node-cli.js"))("node-pty");return await new Promise((n,o)=>{let s=e.spawn("/bin/echo",["ok"],{cols:20,rows:5}),r=setTimeout(()=>o(new Error("spawn timeout")),5e3);s.onExit(()=>{clearTimeout(r),n()})}),f("node-pty","loads and spawns under this runtime")}catch(t){let e=`cd ${b} && npm rebuild node-pty # with THIS node first on PATH \u2014 never the system npm`;try{let n=K(l.join(b,"package.json")),o=l.join(l.dirname(n.resolve("node-pty/package.json")),"prebuilds",`${process.platform}-${process.arch}`,"spawn-helper");m.existsSync(o)&&!(m.statSync(o).mode&73)&&(e=`chmod +x ${o} # node-pty ships it non-executable`)}catch{}return w("node-pty",`load/spawn failed: ${t?.message||t}`,e)}}function ee(t){let e=t.BOSTRAT_CHROMIUM_BIN||"/usr/bin/chromium";return m.existsSync(e)?f("chromium (mocks)",e):g("chromium (mocks)",`${e} missing \u2014 mock rendering unavailable`,"install Chromium/Chrome and set BOSTRAT_CHROMIUM_BIN")}function ne(t){let e=t.BOSTRAT_CLAUDE_USE_API_KEY==="1";return e&&!t.ANTHROPIC_API_KEY?w("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"):f("claude lane",e?"BYO API key (injected per new box)":"box-local login (subscription \u2014 you type `claude login` inside the box)")}async function oe(t,{WebSocketImpl:e}={}){if(!t.BOSTRAT_PLANE_URL||!t.BOSTRAT_PLANE_TOKEN)return g("plane link","BOSTRAT_PLANE_URL/TOKEN unset \u2014 node runs pure M1 (local only)","run `bostrat-node init`");let n=e||(await import("ws")).default,o=Date.now(),s=L(t.BOSTRAT_PLANE_URL);return await new Promise(r=>{let i=new n(s,{headers:{authorization:`Bearer ${t.BOSTRAT_PLANE_TOKEN}`}}),a=d=>{clearTimeout(p);try{i.close()}catch{}r(d)},p=setTimeout(()=>a(w("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-${Kt().slice(0,8)}`}))),i.on("message",d=>{try{let u=JSON.parse(d);u.type==="hello_ok"?a(f("plane link",`hello_ok in ${Date.now()-o}ms (${s})`)):u.type==="error"&&a(w("plane link",`plane said: ${u.code} ${u.message||""}`,"check the token"))}catch{}}),i.on("error",d=>a(w("plane link",`${d?.message||d}`,"check the URL, the token, and the plane's IP gate")))})}function re(t){return t.BOSTRAT_STATE_REMOTE?f("state remote",`${t.BOSTRAT_STATE_REMOTE} (this node's own \u2014 never another node's repo)`):g("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 it(t,e={}){let n=[];return n.push(await Xt()),n.push(Vt(e.envFile||O())),n.push(await Zt(t)),n.push(...await qt()),n.push(await st("git",{required:!0})),n.push(await Jt()),n.push(...await Qt()),n.push(await te()),n.push(ee(t)),n.push(ne(t)),n.push(await oe(t,e)),n.push(re(t)),n}function at(t,e=console.log){let n={pass:"\u2713",warn:"!",fail:"\u2717"};for(let r of t)e(`${n[r.level]} ${r.name}: ${r.detail}`),r.fix&&r.level!=="pass"&&e(` fix: ${r.fix}`);let o=t.filter(r=>r.level==="fail").length,s=t.filter(r=>r.level==="warn").length;return e(o?`
75
+ FAIL \u2014 ${o} blocking, ${s} warnings`:`
76
+ OK \u2014 0 blocking, ${s} warnings`),o===0}async function se({envFile:t=O(),input:e=process.stdin,output:n=process.stdout}={}){let o=P(t),s=Ht.createInterface({input:e,output:n}),r=async(S,c)=>(await s.question(c?`${S} [${c}]: `:`${S}: `)).trim()||c||"";n.write(`bostrat-node init \u2014 plane link + machine config. No vendor logins here:
77
77
  you type those inside each box, later (box-auth-policy).
78
78
 
79
- `);let i=await o("Plane URL",r.BOSTRAT_PLANE_URL||Yt),a=M(i);a!==i.trim()&&n.write(` \u2192 using ${a}
80
- `);let d=await o("Node token (minted plane-side; stored 0600)",r.BOSTRAT_PLANE_TOKEN),f=await o("Owner userId (just press Enter \u2014 the plane infers it from your token)",r.BOSTRAT_OWNER||"");f&&!/^user_[A-Za-z0-9]+$/.test(f)&&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.
81
- `);let u=await o("Node name",r.BOSTRAT_NODE_NAME||b.hostname().split(".")[0]),k=await o("Repos root",r.BOSTRAT_REPOS_ROOT||l.join(b.homedir(),"Documents")),I=await o("State remote (per-node private repo; empty = local-only)",r.BOSTRAT_STATE_REMOTE||""),y=(await o("Route NEW claude boxes through a BYO API key? (y/N)",r.BOSTRAT_CLAUDE_USE_API_KEY==="1"?"y":"N")).toLowerCase().startsWith("y");y&&n.write(`
79
+ `);let i=await r("Plane URL",o.BOSTRAT_PLANE_URL||Yt),a=L(i);a!==i.trim()&&n.write(` \u2192 using ${a}
80
+ `);let p=await r("Node token (minted plane-side; stored 0600)",o.BOSTRAT_PLANE_TOKEN),d=await r("Owner userId (just press Enter \u2014 the plane infers it from your token)",o.BOSTRAT_OWNER||"");d&&!/^user_[A-Za-z0-9]+$/.test(d)&&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.
81
+ `);let u=await r("Node name",o.BOSTRAT_NODE_NAME||A.hostname().split(".")[0]),k=await r("Repos root",o.BOSTRAT_REPOS_ROOT||l.join(A.homedir(),"Documents")),B=await r("State remote (per-node private repo; empty = local-only)",o.BOSTRAT_STATE_REMOTE||""),T=(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");T&&n.write(`
82
82
  BYO API key (box-auth-policy rule 5): claude boxes on this node bill to YOUR key,
83
83
  injected per box, stored 0600 in node.env, never sent to the plane.
84
84
  \u2022 create/copy a key: https://console.anthropic.com/settings/keys
85
85
  \u2022 set a monthly spend limit while you're there \u2014 the key is live.
86
86
 
87
- `);let E=y?await o("ANTHROPIC_API_KEY (starts sk-ant-)",r.ANTHROPIC_API_KEY):"";y&&E&&!/^sk-ant-/.test(E)&&n.write(` ! that doesn't look like an Anthropic key (expected sk-ant-\u2026) \u2014 saved as-is; re-run init to correct.
88
- `),s.close();let R={...X(),...r,BOSTRAT_PLANE_URL:a,BOSTRAT_PLANE_TOKEN:d,BOSTRAT_OWNER:f,BOSTRAT_NODE_NAME:u,BOSTRAT_NODE_ID:r.BOSTRAT_NODE_ID||u,BOSTRAT_REPOS_ROOT:k,BOSTRAT_STATE_REMOTE:I,BOSTRAT_CLAUDE_USE_API_KEY:y?"1":"0",ANTHROPIC_API_KEY:y?E:r.ANTHROPIC_API_KEY};G(t,R,{header:`bostrat node config \u2014 written by \`bostrat-node init\` ${new Date().toISOString()}
87
+ `);let E=T?await r("ANTHROPIC_API_KEY (starts sk-ant-)",o.ANTHROPIC_API_KEY):"";T&&E&&!/^sk-ant-/.test(E)&&n.write(` ! that doesn't look like an Anthropic key (expected sk-ant-\u2026) \u2014 saved as-is; re-run init to correct.
88
+ `),s.close();let v={...X(),...o,BOSTRAT_PLANE_URL:a,BOSTRAT_PLANE_TOKEN:p,BOSTRAT_OWNER:d,BOSTRAT_NODE_NAME:u,BOSTRAT_NODE_ID:o.BOSTRAT_NODE_ID||u,BOSTRAT_REPOS_ROOT:k,BOSTRAT_STATE_REMOTE:B,BOSTRAT_CLAUDE_USE_API_KEY:T?"1":"0",ANTHROPIC_API_KEY:T?E:o.ANTHROPIC_API_KEY};G(t,v,{header:`bostrat node config \u2014 written by \`bostrat-node init\` ${new Date().toISOString()}
89
89
  0600: BOSTRAT_PLANE_TOKEN always lives here, ANTHROPIC_API_KEY may. Never commit.
90
90
  Bind host: unset = loopback-only while plane-linked; BOSTRAT_HOST=all restores bind-all (LAN).`}),n.write(`
91
91
  wrote ${t}
92
92
 
93
- `);let B={...R,...process.env},v=await it(B,{envFile:t}),g=at(v,T=>n.write(T+`
94
- `));return g&&n.write("\nnext: `bostrat-node run` (foreground) or `bostrat-node install-service`\n"),{ok:g,results:v}}function oe({envFile:t=O()}={}){Y(t);let e=process.env.BOSTRAT_NODE_BIN||process.execPath,n=Ct(e,[Wt],{cwd:x,stdio:"inherit",env:process.env});for(let r of["SIGINT","SIGTERM"])process.on(r,()=>n.kill(r));return n.on("exit",(r,s)=>process.exit(s?1:r??1)),n}function se({agentDir:t=x,nodeBin:e=process.execPath,envFile:n=O(),home:r=b.homedir()}={}){let s=l.dirname(e),o=l.join(l.basename(z),"index.js");return`# bostrat node \u2014 written by \`bostrat-node install-service\`. Config lives in
93
+ `);let F={...v,...process.env},R=await it(F,{envFile:t}),_=at(R,S=>n.write(S+`
94
+ `));return _&&n.write("\nnext: `bostrat-node run` (foreground) or `bostrat-node install-service`\n"),{ok:_,results:R}}function ie({envFile:t=O()}={}){Y(t);let e=process.env.BOSTRAT_NODE_BIN||process.execPath,n=Ct(e,[Wt],{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 ae({agentDir:t=b,nodeBin:e=process.execPath,envFile:n=O(),home:o=A.homedir()}={}){let s=l.dirname(e),r=l.join(l.basename(z),"index.js");return`# bostrat node \u2014 written by \`bostrat-node install-service\`. Config lives in
95
95
  # ${n} (edit + \`systemctl --user restart bostrat-node\`), not here.
96
96
  [Unit]
97
97
  Description=bostrat node \u2014 box runtime dialing out to the coordination plane (plane-p1-package-node-scope-2026-07-14.md)
@@ -101,17 +101,17 @@ After=default.target
101
101
  Type=simple
102
102
  WorkingDirectory=${t}
103
103
  # Pinned runtime: node-pty is compiled against exactly this node (SEGV trap).
104
- ExecStart=${e} --disable-warning=ExperimentalWarning ${o}
104
+ ExecStart=${e} --disable-warning=ExperimentalWarning ${r}
105
105
  EnvironmentFile=${n}
106
106
  # systemd's user PATH omits ~/.local/bin (cursor-agent, bostrat-view) and the
107
107
  # nvm bin dir \u2014 both are load-bearing for box spawning.
108
- Environment=PATH=${r}/.local/bin:${s}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
108
+ Environment=PATH=${o}/.local/bin:${s}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
109
109
  Restart=on-failure
110
110
  RestartSec=2
111
111
 
112
112
  [Install]
113
113
  WantedBy=default.target
114
- `}function ie({agentDir:t=x,nodeBin:e=process.execPath,home:n=b.homedir()}={}){let r=l.dirname(e),s=`${n}/Library/Logs/bostrat`;return`<?xml version="1.0" encoding="UTF-8"?>
114
+ `}function ce({agentDir:t=b,nodeBin:e=process.execPath,home:n=A.homedir()}={}){let o=l.dirname(e),s=`${n}/Library/Logs/bostrat`;return`<?xml version="1.0" encoding="UTF-8"?>
115
115
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
116
116
  <plist version="1.0">
117
117
  <dict>
@@ -125,7 +125,7 @@ WantedBy=default.target
125
125
  <key>WorkingDirectory</key><string>${t}</string>
126
126
  <key>EnvironmentVariables</key>
127
127
  <dict>
128
- <key>PATH</key><string>${n}/.local/bin:${r}:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin</string>
128
+ <key>PATH</key><string>${n}/.local/bin:${o}:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin</string>
129
129
  </dict>
130
130
  <key>RunAtLoad</key><true/>
131
131
  <key>KeepAlive</key><true/>
@@ -133,7 +133,7 @@ WantedBy=default.target
133
133
  <key>StandardErrorPath</key><string>${s}/node.err.log</string>
134
134
  </dict>
135
135
  </plist>
136
- `}function ae(t=process.platform,e=b.homedir()){return t==="darwin"?{kind:"launchd",file:l.join(e,"Library","LaunchAgents","com.bostrat.node.plist")}:{kind:"systemd",file:l.join(e,".config","systemd","user","bostrat-node.service")}}async function ce({uninstall:t=!1,start:e=!0,platform:n=process.platform,log:r=console.log,agentDir:s=x}={}){let{kind:o,file:i}=ae(n);if(!t&&s.split(l.sep).includes("_npx"))return r("\u2717 running from the npx cache \u2014 a service must point at a durable install."),r(" fix: npm install -g bostrat-node && bostrat-node install-service"),1;if(t){o==="systemd"?(await S("systemctl",["--user","disable","--now","bostrat-node.service"]).catch(()=>{}),p.rmSync(i,{force:!0}),await S("systemctl",["--user","daemon-reload"])):(await S("launchctl",["unload","-w",i]).catch(()=>{}),p.rmSync(i,{force:!0})),r(`removed ${i}`);return}p.mkdirSync(l.dirname(i),{recursive:!0}),o==="systemd"?(p.writeFileSync(i,se()),await S("systemctl",["--user","daemon-reload"]),e&&await S("systemctl",["--user","enable","--now","bostrat-node.service"]),r(`installed ${i}${e?" (enabled + started)":""}`),r("logs: journalctl --user -u bostrat-node.service -f")):(p.mkdirSync(l.join(b.homedir(),"Library","Logs","bostrat"),{recursive:!0}),p.writeFileSync(i,ie()),e&&await S("launchctl",["load","-w",i]),r(`installed ${i}${e?" (loaded)":""}`),r("logs: ~/Library/Logs/bostrat/node.{out,err}.log"))}async function Vn(t=process.argv.slice(2)){let e=t[0],n=O();if(e==="--version"||e==="-v"||e==="version")return console.log(Gt),0;if(e==="init")return(await re({envFile:n})).ok?0:1;if(e==="doctor"){let r={...P(n),...process.env};return at(await it(r,{envFile:n}))?0:1}if(e==="run"||e==="start")return oe({envFile:n}),null;if(e==="install-service")return await ce({uninstall:t.includes("--uninstall"),start:!t.includes("--no-start")})||0;if(e==="fly"){let{flyWizard:r}=await Promise.resolve().then(()=>(st(),ot));return await r({argv:t.slice(1)})}return console.log(`bostrat-node \u2014 install and run a bostrat node (plane P1)
136
+ `}function le(t=process.platform,e=A.homedir()){return t==="darwin"?{kind:"launchd",file:l.join(e,"Library","LaunchAgents","com.bostrat.node.plist")}:{kind:"systemd",file:l.join(e,".config","systemd","user","bostrat-node.service")}}async function ue({uninstall:t=!1,start:e=!0,platform:n=process.platform,log:o=console.log,agentDir:s=b}={}){let{kind:r,file:i}=le(n);if(!t&&s.split(l.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(t){r==="systemd"?(await y("systemctl",["--user","disable","--now","bostrat-node.service"]).catch(()=>{}),m.rmSync(i,{force:!0}),await y("systemctl",["--user","daemon-reload"])):(await y("launchctl",["unload","-w",i]).catch(()=>{}),m.rmSync(i,{force:!0})),o(`removed ${i}`);return}m.mkdirSync(l.dirname(i),{recursive:!0}),r==="systemd"?(m.writeFileSync(i,ae()),await y("systemctl",["--user","daemon-reload"]),e&&await y("systemctl",["--user","enable","--now","bostrat-node.service"]),o(`installed ${i}${e?" (enabled + started)":""}`),o("logs: journalctl --user -u bostrat-node.service -f")):(m.mkdirSync(l.join(A.homedir(),"Library","Logs","bostrat"),{recursive:!0}),m.writeFileSync(i,ce()),e&&await y("launchctl",["load","-w",i]),o(`installed ${i}${e?" (loaded)":""}`),o("logs: ~/Library/Logs/bostrat/node.{out,err}.log"))}async function Jn(t=process.argv.slice(2)){let e=t[0],n=O();if(e==="--version"||e==="-v"||e==="version")return console.log(Gt),0;if(e==="init")return(await se({envFile:n})).ok?0:1;if(e==="doctor"){let o={...P(n),...process.env};return at(await it(o,{envFile:n}))?0:1}if(e==="run"||e==="start")return ie({envFile:n}),null;if(e==="install-service")return await ue({uninstall:t.includes("--uninstall"),start:!t.includes("--no-start")})||0;if(e==="fly"){let{flyWizard:o}=await Promise.resolve().then(()=>(rt(),ot));return await o({argv:t.slice(1)})}return console.log(`bostrat-node \u2014 install and run a bostrat node (plane P1)
137
137
 
138
138
  usage: bostrat-node <init | doctor | run | install-service [--uninstall] [--no-start] | fly | --version>
139
139
 
@@ -141,4 +141,4 @@ usage: bostrat-node <init | doctor | run | install-service [--uninstall] [--no-s
141
141
  doctor check this machine (CLIs, tmux, node-pty, plane reachability)
142
142
  run start the node in the foreground (sources node.env)
143
143
  install-service run at boot/login: systemd --user (Linux) / launchd (macOS)
144
- fly provision this node on YOUR OWN Fly.io org (uses your flyctl)`),e?1:0}export{re as init,ce as installService,ie as launchdPlist,Vn as main,at as printDoctor,oe as runAgent,it as runDoctor,ae as servicePaths,se as systemdUnit};
144
+ fly provision this node on YOUR OWN Fly.io org (uses your flyctl)`),e?1:0}export{se as init,ue as installService,ce as launchdPlist,Jn as main,at as printDoctor,ie as runAgent,it as runDoctor,le as servicePaths,ae as systemdUnit};