bostrat-node 0.2.17 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +33 -33
- package/dist/index.js +147 -147
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var me=Object.defineProperty;var he=(e,t)=>()=>(e&&(t=e(e=0)),t);var ye=(e,t)=>{for(var n in t)me(e,n,{get:t[n],enumerable:!0})};var ce={};ye(ce,{NODE_IMAGE:()=>K,commandPlan:()=>se,flyToml:()=>oe,flyWizard:()=>Xe,parseFlyFlags:()=>ie,stageConfig:()=>ae});import H from"node:fs";import x from"node:path";import Ue from"node:os";import He from"node:readline/promises";import{execFile as Ke}from"node:child_process";import{createRequire as ze}from"node:module";import{randomUUID as Ye}from"node:crypto";function oe({app:e,region:t,nodeName:n=e,planeUrl:r=re,image:s=K}){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.
|
|
@@ -9,7 +9,7 @@ primary_region = "${t}"
|
|
|
9
9
|
# The published node image (claude + cursor-agent + codex baked in, logged
|
|
10
10
|
# out), pinned to the bostrat-node version that wrote this file. Update with:
|
|
11
11
|
# npm i -g bostrat-node && bostrat-node fly (re-run is safe), or bump the tag.
|
|
12
|
-
image = "${
|
|
12
|
+
image = "${s}"
|
|
13
13
|
|
|
14
14
|
[env]
|
|
15
15
|
PORT = "3362"
|
|
@@ -34,26 +34,26 @@ primary_region = "${t}"
|
|
|
34
34
|
# Scale later with: fly scale memory 4096 -a ${e}
|
|
35
35
|
size = "shared-cpu-2x"
|
|
36
36
|
memory = "2gb"
|
|
37
|
-
`}function
|
|
37
|
+
`}function se({app:e,org:t,region:n,sizeGb:r,token:s,owner:o,dir:i}){let a=[`BOSTRAT_PLANE_TOKEN=${s}`,...o?[`BOSTRAT_OWNER=${o}`]:[]];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(r),"-y"],display:`fly volumes create node_data -a ${e} -r ${n} -s ${r} -y`,tolerate:/already|exists/i},{argv:["secrets","import","-a",e,"--stage"],display:`fly secrets import -a ${e} --stage # BOSTRAT_PLANE_TOKEN=<redacted>${o?" BOSTRAT_OWNER=\u2026":""} via stdin`,stdin:a.join(`
|
|
38
38
|
`)+`
|
|
39
|
-
`},{argv:["deploy",i,"-c",
|
|
40
|
-
`),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
|
|
39
|
+
`},{argv:["deploy",i,"-c",x.join(i,"fly.toml"),"-a",e,"--ha=false"],display:`fly deploy ${i} -c ${x.join(i,"fly.toml")} -a ${e} --ha=false`}]}function ie(e=[]){let t={},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<e.length;r++){let s=e[r];if(s==="--yes"||s==="-y")t.yes=!0;else if(n[s])t[n[s]]=e[++r]??"";else if(s.startsWith("--")&&s.includes("=")){let[o,...i]=s.split("=");n[o]?t[n[o]]=i.join("="):o==="--yes"&&(t.yes=!0)}}return t.sizeGb!=null&&(t.sizeGb=Number(t.sizeGb)||10),t}function ae({app:e,dest:t,toml:n}){let r=t||x.join(Ue.homedir(),".bostrat","fly",e);H.mkdirSync(r,{recursive:!0});for(let s of["Dockerfile",".dockerignore","package.json","package-lock.json","src","dist","bin","node-entrypoint.sh"])H.rmSync(x.join(r,s),{recursive:!0,force:!0});return H.writeFileSync(x.join(r,"fly.toml"),n),{dir:r,manifest:["fly.toml"]}}async function Ge({ask:e,output:t,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 t.write(`Org: ${i[0]} (your only org)
|
|
40
|
+
`),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 Xe({argv:e=[],input:t=process.stdin,output:n=process.stdout,exec:r,stageDest:s}={}){let o=ie(e),i=He.createInterface({input:t,output:n}),a=async(c,h)=>(await i.question(h?`${c} [${h}]: `:`${c}: `)).trim()||h||"",d=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
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
|
|
45
|
-
`),d(1);let B=
|
|
46
|
-
wrote ${
|
|
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 Ge({ask:a,output:n,exec:r,flag:o.org}),u=o.app||await a("App name",`bostrat-node-${Ye().slice(0,4)}`),k=o.region||await a("Region (see `fly platform regions`)","iad"),C=o.sizeGb||Number(await a("Volume size GB (logins + repos live here)","10"))||10,T=o.name||u,A=o.planeUrl||re,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||K,{dir:_}=ae({app:u,dest:s,toml:oe({app:u,region:k,nodeName:T,planeUrl:A,image:v})});n.write(`
|
|
46
|
+
wrote ${x.join(_,"fly.toml")} \u2014 deploys the prebuilt node image ${v}
|
|
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 S=
|
|
51
|
-
`);if(!
|
|
50
|
+
`);let S=se({app:u,org:f,region:k,sizeGb:C,token:R,owner:B,dir:_});for(let c of S)n.write(` $ ${c.display}
|
|
51
|
+
`);if(!o.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
53
|
`),d(1);for(let c of S){n.write(`
|
|
54
54
|
\u2192 ${c.display}
|
|
55
|
-
`);try{let{stdout:h,stderr:$}=await j(c.argv,{stdin:c.stdin,exec:r}),
|
|
56
|
-
`).map(
|
|
55
|
+
`);try{let{stdout:h,stderr:$}=await j(c.argv,{stdin:c.stdin,exec:r}),W=`${h||""}${$||""}`.trim();W&&n.write(W.split(`
|
|
56
|
+
`).map(pe=>` ${pe}`).join(`
|
|
57
57
|
`)+`
|
|
58
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(`
|
|
@@ -64,34 +64,34 @@ Run it? (Y/n)`,"Y")).toLowerCase().startsWith("n"))return n.write(`aborted \u201
|
|
|
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 ${_} -c ${
|
|
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
|
|
71
|
-
`)){let
|
|
72
|
-
`).map(
|
|
70
|
+
`),d(0)}var re,We,K,j,le=he(()=>{re="wss://plane.bostrat.ai/v1/node",We=ze(import.meta.url)("../package.json").version,K=`ghcr.io/globocodes/bostrat-node:${We}`;j=(e,{stdin:t,exec:n}={})=>new Promise((r,s)=>{if(n)return n(e,{stdin:t}).then(r,s);let o=Ke("fly",e,{timeout:6e5,maxBuffer:16*1024*1024},(i,a,d)=>i?s(Object.assign(i,{stdout:a,stderr:d})):r({stdout:a,stderr:d}));t!=null&&o.stdin?.end(t)})});import m from"node:fs";import l from"node:path";import E from"node:os";import{createRequire as z}from"node:module";import{execFile as Ve,spawn as Je}from"node:child_process";import{promisify as Ze}from"node:util";import qe from"node:readline/promises";import{randomUUID as Qe}from"node:crypto";import{fileURLToPath as et}from"node:url";import N from"node:fs";import L from"node:path";import we from"node:os";var ge=process.env.BOSTRAT_STATE_DIR||L.join(process.env.HOME||we.tmpdir(),".bostrat"),O=()=>L.join(ge,"node.env");function D(e){let t=String(e||"").trim();if(!t)return"";let n=/^[a-z][a-z0-9+.-]*:\/\//i.test(t)?t:`wss://${t}`,r;try{r=new URL(n)}catch{return t}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()):t}function P(e){let t;try{t=N.readFileSync(e,"utf8")}catch{return{}}let n={};for(let r of t.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 G(e,t=process.env){let n=P(e);for(let[r,s]of Object.entries(n))r in t||(t[r]=s);return n}function X(e,t,{header:n=""}={}){let r=[];n&&r.push(...n.split(`
|
|
72
|
+
`).map(s=>s?`# ${s}`:"#"));for(let[s,o]of Object.entries(t))o==null||o===""||r.push(`${s}=${o}`);N.mkdirSync(L.dirname(e),{recursive:!0}),N.writeFileSync(e,r.join(`
|
|
73
73
|
`)+`
|
|
74
|
-
`,{mode:384}),N.chmodSync(e,384)}function
|
|
75
|
-
FAIL \u2014 ${r} blocking, ${
|
|
76
|
-
OK \u2014 0 blocking, ${
|
|
74
|
+
`,{mode:384}),N.chmodSync(e,384)}function V(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 je}from"node:child_process";import{promisify as Ce}from"node:util";import Be from"node:fs";import ve from"node:os";import ke from"node:path";import{execFile as $e}from"node:child_process";import{promisify as Ne}from"node:util";import Z from"node:path";import be from"node:os";import{execFile as Oe}from"node:child_process";import{promisify as Ee}from"node:util";import F from"node:path";import{execFile as _e}from"node:child_process";import{promisify as Se}from"node:util";var Ct=Se(_e),J=process.env.HOME||"/home/globo",xe=F.join(process.env.BOSTRAT_STATE_DIR||F.join(J,".bostrat"),"repos"),Bt=[...(process.env.BOSTRAT_REPOS_ROOT||F.join(J,"Documents")).split(","),xe].map(e=>e.trim()).filter(Boolean),Lt=Number(process.env.BOSTRAT_REPOS_DEPTH)||3;var Yt=Ee(Oe),Ae=process.env.BOSTRAT_STATE_DIR||Z.join(process.env.HOME||be.tmpdir(),".bostrat"),Wt=Z.join(Ae,"repos");var Gt=5*6e4;var Xt=10*6e4;var sn=Ne($e),an=process.env.BOSTRAT_STATE_DIR||ke.join(process.env.HOME||ve.tmpdir(),".bostrat");var cn=25*1024;import Pe from"node:os";import q from"node:path";var Ie=process.env.BOSTRAT_DEBUG_DIR||q.join(Pe.homedir(),".bostrat","debug"),En=q.join(Ie,"handoff.jsonl"),An=Number(process.env.BOSTRAT_HANDOFF_DEBUG_MAX)||500;var Le=Ce(je);var Gn=process.env.BOSTRAT_TMUX_BIN||"/usr/bin/tmux";function te(e){return`/tmp/tmux-${e}/default`}function De({explicit:e,legacyExists:t,runtimeDir:n,uid:r}){if(e)return e;let s=te(r);return t?s:n?`${n}/bostrat/tmux-default`:s}var Q=typeof process.getuid=="function"?process.getuid():0,Xn=De({explicit:process.env.BOSTRAT_TMUX_SOCKET,legacyExists:(()=>{try{return Be.existsSync(te(Q))}catch{return!1}})(),runtimeDir:process.env.XDG_RUNTIME_DIR,uid:Q}),Vn=process.env.BOSTRAT_DEFAULT_CWD||process.env.HOME||"/",Jn=process.env.BOSTRAT_AGENT_CMD||"claude --dangerously-skip-permissions";async function U(e,{loginShell:t=!1,failOpen:n=!1}={}){let r=await Me(e,{loginShell:t});return r===ne?!0:r===M?!1:n}var ne="present",M="absent",ee="unknown",Fe=5e3;async function Me(e,{loginShell:t=!1,timeoutMs:n=Fe}={}){if(!e)return M;let r=t?process.env.SHELL||"/bin/sh":"sh",s=t?"-lic":"-c";try{return await Le(r,[s,'command -v "$1" >/dev/null 2>&1',"_",e],{timeout:n}),ne}catch(o){return o?.killed||o?.signal?ee:o?.code===1||o?.code===127?M:ee}}var I={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 Zn=Number(process.env.BOSTRAT_PROMPT_CAPTURE_COLS)||100,qn=Number(process.env.BOSTRAT_PROMPT_CAPTURE_ROWS)||40,Qn=Number(process.env.BOSTRAT_PROMPT_CAPTURE_LINES)||80,er=Number(process.env.BOSTRAT_BOX_COLS)||120,tr=Number(process.env.BOSTRAT_BOX_ROWS)||40;var w=Ze(Ve),Y=l.dirname(et(import.meta.url)),b=l.resolve(Y,".."),tt=l.join(Y,"index.js"),nt="wss://plane.bostrat.ai/v1/node",rt=z(import.meta.url)("../package.json").version,p=(e,t)=>({name:e,level:"pass",detail:t}),g=(e,t,n)=>({name:e,level:"warn",detail:t,fix:n}),y=(e,t,n)=>({name:e,level:"fail",detail:t,fix:n});async function ot(){let[e,t]=process.versions.node.split(".").map(Number);return e>22||e===22&&t>=5?p("node runtime",`${process.version} at ${process.execPath}`):y("node runtime",`${process.version} < 22.5`,"install Node \u226522.5 via nvm and re-run under it")}function st(e){let t;try{t=m.statSync(e)}catch{return g("node.env",`${e} missing`,"run `bostrat-node init`")}let n=t.mode&511;return n&63?g("node.env",`${e} mode ${n.toString(8)} \u2014 group/world readable and it can hold a key`,`chmod 600 ${e}`):p("node.env",`${e} (0600)`)}async function it(e){let t=e.BOSTRAT_TMUX_BIN||"/usr/bin/tmux";try{let{stdout:n}=await w(t,["-V"],{timeout:5e3});return p("tmux",`${t} (${n.trim()})`)}catch{return y("tmux",`${t} not runnable`,process.platform==="darwin"?"brew install tmux (then BOSTRAT_TMUX_BIN=/opt/homebrew/bin/tmux)":"install tmux")}}async function ue(e,{required:t=!1}={}){if(await U(e,{loginShell:!0,failOpen:!1}))return p(e,"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=I[e]?`${I[e]}${e==="cursor-agent"?" # installs to ~/.local/bin \u2014 ensure your login shell has it on PATH":""}`:`install ${e} so \`$SHELL -lic 'command -v ${e}'\` finds it`;return t?y(e,r,s):g(e,r,s)}async function at(){let e=process.env.SHELL||"/bin/sh";try{let{stdout:t}=await w(e,["-lic","gh --version"],{timeout:1e4}),n=String(t).match(/gh version [^\s]+/)?.[0]||"runs on the login-shell PATH";return p("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",I.gh)}}async function ct(){let e=await Promise.all(["claude","codex","cursor-agent"].map(t=>ue(t)));return e.some(t=>t.level==="pass")||e.push(y("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 lt(){let e=[...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(e.map(async([t,n,r])=>await U(t,{failOpen:!1})?p(t,"resolves on the service PATH"):g(t,`not on the service PATH \u2014 ${n}`,r)))}async function ut(){try{let t=z(l.join(b,"src","node-cli.js"))("node-pty");return await new Promise((n,r)=>{let s=t.spawn("/bin/echo",["ok"],{cols:20,rows:5}),o=setTimeout(()=>r(new Error("spawn timeout")),5e3);s.onExit(()=>{clearTimeout(o),n()})}),p("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=z(l.join(b,"package.json")),r=l.join(l.dirname(n.resolve("node-pty/package.json")),"prebuilds",`${process.platform}-${process.arch}`,"spawn-helper");m.existsSync(r)&&!(m.statSync(r).mode&73)&&(t=`chmod +x ${r} # node-pty ships it non-executable`)}catch{}return y("node-pty",`load/spawn failed: ${e?.message||e}`,t)}}function dt(e){let t=e.BOSTRAT_CHROMIUM_BIN||"/usr/bin/chromium";return m.existsSync(t)?p("chromium (mocks)",t):g("chromium (mocks)",`${t} missing \u2014 mock rendering unavailable`,"install Chromium/Chrome and set BOSTRAT_CHROMIUM_BIN")}function ft(e){let t=e.BOSTRAT_CLAUDE_USE_API_KEY==="1";return t&&!e.ANTHROPIC_API_KEY?y("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"):p("claude lane",t?"BYO API key (injected per new box)":"box-local login (subscription \u2014 you type `claude login` inside the box)")}async function pt(e,{WebSocketImpl:t}={}){if(!e.BOSTRAT_PLANE_URL||!e.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=t||(await import("ws")).default,r=Date.now(),s=D(e.BOSTRAT_PLANE_URL);return await new Promise(o=>{let i=new n(s,{headers:{authorization:`Bearer ${e.BOSTRAT_PLANE_TOKEN}`}}),a=f=>{clearTimeout(d);try{i.close()}catch{}o(f)},d=setTimeout(()=>a(y("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-${Qe().slice(0,8)}`}))),i.on("message",f=>{try{let u=JSON.parse(f);u.type==="hello_ok"?a(p("plane link",`hello_ok in ${Date.now()-r}ms (${s})`)):u.type==="error"&&a(y("plane link",`plane said: ${u.code} ${u.message||""}`,"check the token"))}catch{}}),i.on("error",f=>a(y("plane link",`${f?.message||f}`,"check the URL, the token, and the plane's IP gate")))})}function mt(e){return e.BOSTRAT_STATE_REMOTE?p("state remote",`${e.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 de(e,t={}){let n=[];return n.push(await ot()),n.push(st(t.envFile||O())),n.push(await it(e)),n.push(...await ct()),n.push(await ue("git",{required:!0})),n.push(await at()),n.push(...await lt()),n.push(await ut()),n.push(dt(e)),n.push(ft(e)),n.push(await pt(e,t)),n.push(mt(e)),n}function fe(e,t=console.log){let n={pass:"\u2713",warn:"!",fail:"\u2717"};for(let o of e)t(`${n[o.level]} ${o.name}: ${o.detail}`),o.fix&&o.level!=="pass"&&t(` fix: ${o.fix}`);let r=e.filter(o=>o.level==="fail").length,s=e.filter(o=>o.level==="warn").length;return t(r?`
|
|
75
|
+
FAIL \u2014 ${r} blocking, ${s} warnings`:`
|
|
76
|
+
OK \u2014 0 blocking, ${s} warnings`),r===0}async function ht({envFile:e=O(),input:t=process.stdin,output:n=process.stdout}={}){let r=P(e),s=qe.createInterface({input:t,output:n}),o=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
|
|
80
|
-
`);let d=await
|
|
81
|
-
`);let u=await
|
|
79
|
+
`);let i=await o("Plane URL",r.BOSTRAT_PLANE_URL||nt),a=D(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||E.hostname().split(".")[0]),k=await o("Repos root",r.BOSTRAT_REPOS_ROOT||l.join(E.homedir(),"Documents")),C=await o("State remote (per-node private repo; empty = local-only)",r.BOSTRAT_STATE_REMOTE||""),T=(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");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
|
|
88
|
-
`),
|
|
87
|
+
`);let A=T?await o("ANTHROPIC_API_KEY (starts sk-ant-)",r.ANTHROPIC_API_KEY):"";T&&A&&!/^sk-ant-/.test(A)&&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={...V(),...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:C,BOSTRAT_CLAUDE_USE_API_KEY:T?"1":"0",ANTHROPIC_API_KEY:T?A:r.ANTHROPIC_API_KEY};X(e,R,{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 ${e}
|
|
92
92
|
|
|
93
|
-
`);let B={...R,...process.env},v=await
|
|
94
|
-
`));return _&&n.write("\nnext: `bostrat-node run` (foreground) or `bostrat-node install-service`\n"),{ok:_,results:v}}function
|
|
93
|
+
`);let B={...R,...process.env},v=await de(B,{envFile:e}),_=fe(v,S=>n.write(S+`
|
|
94
|
+
`));return _&&n.write("\nnext: `bostrat-node run` (foreground) or `bostrat-node install-service`\n"),{ok:_,results:v}}function yt({envFile:e=O()}={}){G(e);let t=process.env.BOSTRAT_NODE_BIN||process.execPath,n=Je(t,[tt],{cwd:b,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 wt({agentDir:e=b,nodeBin:t=process.execPath,envFile:n=O(),home:r=E.homedir()}={}){let s=l.dirname(t),o=l.join(l.basename(Y),"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=${e}
|
|
103
103
|
# Pinned runtime: node-pty is compiled against exactly this node (SEGV trap).
|
|
104
|
-
ExecStart=${t} --disable-warning=ExperimentalWarning ${
|
|
104
|
+
ExecStart=${t} --disable-warning=ExperimentalWarning ${o}
|
|
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:${
|
|
108
|
+
Environment=PATH=${r}/.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
|
|
114
|
+
`}function gt({agentDir:e=b,nodeBin:t=process.execPath,home:n=E.homedir()}={}){let r=l.dirname(t),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>
|
|
@@ -129,11 +129,11 @@ WantedBy=default.target
|
|
|
129
129
|
</dict>
|
|
130
130
|
<key>RunAtLoad</key><true/>
|
|
131
131
|
<key>KeepAlive</key><true/>
|
|
132
|
-
<key>StandardOutPath</key><string>${
|
|
133
|
-
<key>StandardErrorPath</key><string>${
|
|
132
|
+
<key>StandardOutPath</key><string>${s}/node.out.log</string>
|
|
133
|
+
<key>StandardErrorPath</key><string>${s}/node.err.log</string>
|
|
134
134
|
</dict>
|
|
135
135
|
</plist>
|
|
136
|
-
`}function
|
|
136
|
+
`}function Tt(e=process.platform,t=E.homedir()){return e==="darwin"?{kind:"launchd",file:l.join(t,"Library","LaunchAgents","com.bostrat.node.plist")}:{kind:"systemd",file:l.join(t,".config","systemd","user","bostrat-node.service")}}async function _t({uninstall:e=!1,start:t=!0,platform:n=process.platform,log:r=console.log,agentDir:s=b}={}){let{kind:o,file:i}=Tt(n);if(!e&&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(e){o==="systemd"?(await w("systemctl",["--user","disable","--now","bostrat-node.service"]).catch(()=>{}),m.rmSync(i,{force:!0}),await w("systemctl",["--user","daemon-reload"])):(await w("launchctl",["unload","-w",i]).catch(()=>{}),m.rmSync(i,{force:!0})),r(`removed ${i}`);return}m.mkdirSync(l.dirname(i),{recursive:!0}),o==="systemd"?(m.writeFileSync(i,wt()),await w("systemctl",["--user","daemon-reload"]),t&&await w("systemctl",["--user","enable","--now","bostrat-node.service"]),r(`installed ${i}${t?" (enabled + started)":""}`),r("logs: journalctl --user -u bostrat-node.service -f")):(m.mkdirSync(l.join(E.homedir(),"Library","Logs","bostrat"),{recursive:!0}),m.writeFileSync(i,gt()),t&&await w("launchctl",["load","-w",i]),r(`installed ${i}${t?" (loaded)":""}`),r("logs: ~/Library/Logs/bostrat/node.{out,err}.log"))}async function Sr(e=process.argv.slice(2)){let t=e[0],n=O();if(t==="--version"||t==="-v"||t==="version")return console.log(rt),0;if(t==="init")return(await ht({envFile:n})).ok?0:1;if(t==="doctor"){let r={...P(n),...process.env};return fe(await de(r,{envFile:n}))?0:1}if(t==="run"||t==="start")return yt({envFile:n}),null;if(t==="install-service")return await _t({uninstall:e.includes("--uninstall"),start:!e.includes("--no-start")})||0;if(t==="fly"){let{flyWizard:r}=await Promise.resolve().then(()=>(le(),ce));return await r({argv:e.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)`),t?1:0}export{
|
|
144
|
+
fly provision this node on YOUR OWN Fly.io org (uses your flyctl)`),t?1:0}export{ht as init,_t as installService,gt as launchdPlist,Sr as main,fe as printDoctor,yt as runAgent,de as runDoctor,Tt as servicePaths,wt as systemdUnit};
|