@kizenapps/cli 1.18.1 → 1.18.2-ef078d6
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/README.md +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1150,7 +1150,7 @@ appbuilder admin init [--force]
|
|
|
1150
1150
|
|
|
1151
1151
|
`--env` picks the session, and defaults to the only environment you're signed in to. `kizen` runs as that environment's current account, unless `--business` (and `--user`), or `APPBUILDER_BUSINESS` (and `APPBUILDER_USER`), names another saved account; then `--env` defaults to the only environment where that name matches a saved account (see [Saved accounts](#saved-accounts)). The wrapper's own options (`--env`, `--business`, `--user`, `-h`/`--help`) come first and end at the first other argument or at `--`. Everything after that goes to `kizen` verbatim, so `appbuilder admin status --help` shows `kizen`'s help, and `appbuilder admin --help` shows this wrapper's. `init` is the wrapper's own subcommand only as the first argument; `appbuilder admin -- init` passes `init` to `kizen`.
|
|
1152
1152
|
|
|
1153
|
-
On first use, `appbuilder admin` installs `kizen` into a private virtual environment under `~/.kizenappbuilder/kizen/<version>-<sha>/` and reuses it afterwards without touching the network. `appbuilder admin init` does that ahead of time, and needs no session. It uses the newest of `python3.14`, `python3.13`, `python3.12` and `python3` that is 3.12 or newer, downloads the `kizen` release this CLI version pins (currently 0.
|
|
1153
|
+
On first use, `appbuilder admin` installs `kizen` into a private virtual environment under `~/.kizenappbuilder/kizen/<version>-<sha>/` and reuses it afterwards without touching the network. `appbuilder admin init` does that ahead of time, and needs no session. It uses the newest of `python3.14`, `python3.13`, `python3.12` and `python3` that is 3.12 or newer, downloads the `kizen` release this CLI version pins (currently 0.5.0) from its GitHub release, checks its sha256, and installs it and its dependencies from PyPI with `pip`. Progress goes to stderr; stdout is `kizen`'s. Each time it makes a new install, it removes installs for other `kizen` versions that have gone unused for 30 days.
|
|
1154
1154
|
|
|
1155
1155
|
If the install is damaged (for example, the Python it was built with was removed), the command says so and changes nothing. `appbuilder admin init --force` deletes the install and installs it again. Don't run it while `appbuilder admin` is running, since a running `kizen` uses that install.
|
|
1156
1156
|
|
package/dist/index.js
CHANGED
|
@@ -113,10 +113,10 @@ ${g}${m}, run \`${s.retry}\`.
|
|
|
113
113
|
`);return}let i=await t.store.signOut(r);t.writeStdout(i?`Signed out of ${r}. The session was removed from this machine.
|
|
114
114
|
`:`Not signed in to ${r}.
|
|
115
115
|
`)}),_u=Hs(async(e,t)=>{let n=Ws(e,t.processEnv),r=await Au(e.env,t.store,n),i=n===void 0?void 0:Er(r,await t.store.listAccounts(r),n);t.writeStdout(Ri(r,await t.identify(t.tokenProvider(r,i===void 0?void 0:{account:i}))))});function nb(e){let t;try{t=new URL(e).origin}catch{throw new Error("CLAUDE_CODE_MCP_SERVER_URL is not a valid URL, so auth-header won't send a token.")}let n=pe.find(r=>Ut(r)===t);if(n===void 0)throw new Error(`No Kizen environment matches the MCP server ${t}, so auth-header won't send it a token.`);return{environment:n,origin:t}}async function rb(e,t){let n=e===void 0?void 0:ku(e),r=t.processEnv.CLAUDE_CODE_MCP_SERVER_URL;if(r!==void 0&&r!==""){let i=nb(r);if(n!==void 0&&n!==i.environment)throw new Error(`--env ${n} doesn't match the MCP server ${i.origin} (${i.environment}), so auth-header won't send it a token.`);return i.environment}return n??Au(void 0,t.store)}function ib(e){let{business:t,user:n}=e;if(!(t===void 0&&n===void 0)){if(t===void 0||n===void 0)throw new Error("auth-header takes --business and --user together.");return{businessId:t,userId:n}}}var Eu=async(e,t)=>{let n;try{let r=ib(e),i=await rb(e.env,t),{requestTimeoutMs:o}=t.authHeaderTimeouts,s=await t.tokenProvider(i,{requestTimeoutMs:o,...r!==void 0&&{account:r}}).getAccessToken();n=`${JSON.stringify({Authorization:`Bearer ${s}`})}
|
|
116
|
-
`}catch(r){xu(t,r,{prefix:"appbuilder auth-header",oneLine:!0});return}t.writeStdout(n)};var $i="appbuilder admin",sb={env:["--env","<env>"],business:["--business","<id-or-name>"],user:["--user","<userId>"]},Iu=["-h","--help"],ab="--force";function cb(e){let t={},n=0,r=o=>({kind:"run",env:t.env,...t.business!==void 0&&{business:t.business},...t.user!==void 0&&{user:t.user},args:o});e:for(;n<e.length;){let o=e[n]??"";if(o==="--")return r(e.slice(n+1));if(Iu.includes(o))return{kind:"help"};for(let[s,[a,c]]of Object.entries(sb))if(o===a||o.startsWith(`${a}=`)){let l=o===a?e[n+1]:o.slice(a.length+1);if(l===void 0||l==="")return{kind:"error",message:`option '${a} ${c}' argument missing`};t[s]=l,n+=o===a?2:1;continue e}break}let i=e.slice(n);if(i[0]==="init"){let o=i.slice(1);return o.length===0?{kind:"init",force:!1}:o.length===1&&o[0]===ab?{kind:"init",force:!0}:o.length===1&&Iu.includes(o[0]??"")?{kind:"init-help"}:{kind:"error",message:`admin init takes only --force, but got: ${o.map(ge).join(" ")}`}}return r(i)}var lb=(e,t,n,r)=>[e,t,"auth-header","--env",n,"--business",r.businessId,"--user",r.userId].map(ge).join(" "),ub=["KIZEN_PROFILE","CLAUDE_CODE_MCP_SERVER_URL"];function db(e,t){let n={};for(let[r,i]of Object.entries(e))i!==void 0&&!ub.includes(r)&&(n[r]=i);return{...n,...t}}var Tu=["SIGTERM","SIGHUP"];function pb(e,t,n,r,i,o){return new Promise((s,a)=>{let c;try{c=r(e.python,[e.kizen,...t],{stdio:"inherit",env:n})}catch(g){a(g instanceof Error?g:new Error(String(g)));return}let d=[...(o?Tu:[...Tu,"SIGINT"]).map(g=>[g,()=>{c.kill(g)}]),...o?[["SIGINT",()=>{}]]:[]];for(let[g,m]of d)i.on(g,m);let u=!1,f=g=>{if(!u){u=!0;for(let[m,p]of d)i.off(m,p);g()}};c.on("error",g=>{f(()=>{a(g)})}),c.on("close",(g,m)=>{f(()=>{s(g??128+(m===null?0:ob.signals[m]))})})})}var Gn=(e,t)=>{e.writeStderr(`${$i}: ${t}
|
|
116
|
+
`}catch(r){xu(t,r,{prefix:"appbuilder auth-header",oneLine:!0});return}t.writeStdout(n)};var $i="appbuilder admin",sb={env:["--env","<env>"],business:["--business","<id-or-name>"],user:["--user","<userId>"]},Iu=["-h","--help"],ab="--force";function cb(e){let t={},n=0,r=o=>({kind:"run",env:t.env,...t.business!==void 0&&{business:t.business},...t.user!==void 0&&{user:t.user},args:o});e:for(;n<e.length;){let o=e[n]??"";if(o==="--")return r(e.slice(n+1));if(Iu.includes(o))return{kind:"help"};for(let[s,[a,c]]of Object.entries(sb))if(o===a||o.startsWith(`${a}=`)){let l=o===a?e[n+1]:o.slice(a.length+1);if(l===void 0||l==="")return{kind:"error",message:`option '${a} ${c}' argument missing`};t[s]=l,n+=o===a?2:1;continue e}break}let i=e.slice(n);if(i[0]==="init"){let o=i.slice(1);return o.length===0?{kind:"init",force:!1}:o.length===1&&o[0]===ab?{kind:"init",force:!0}:o.length===1&&Iu.includes(o[0]??"")?{kind:"init-help"}:{kind:"error",message:`admin init takes only --force, but got: ${o.map(ge).join(" ")}`}}return r(i)}var lb=(e,t,n,r)=>[e,t,"auth-header","--env",n,"--business",r.businessId,"--user",r.userId].map(ge).join(" "),ub=["KIZEN_PROFILE","CLAUDE_CODE_MCP_SERVER_URL","KICODE_API_KEY"];function db(e,t){let n={};for(let[r,i]of Object.entries(e))i!==void 0&&!ub.includes(r)&&(n[r]=i);return{...n,...t}}var Tu=["SIGTERM","SIGHUP"];function pb(e,t,n,r,i,o){return new Promise((s,a)=>{let c;try{c=r(e.python,[e.kizen,...t],{stdio:"inherit",env:n})}catch(g){a(g instanceof Error?g:new Error(String(g)));return}let d=[...(o?Tu:[...Tu,"SIGINT"]).map(g=>[g,()=>{c.kill(g)}]),...o?[["SIGINT",()=>{}]]:[]];for(let[g,m]of d)i.on(g,m);let u=!1,f=g=>{if(!u){u=!0;for(let[m,p]of d)i.off(m,p);g()}};c.on("error",g=>{f(()=>{a(g)})}),c.on("close",(g,m)=>{f(()=>{s(g??128+(m===null?0:ob.signals[m]))})})})}var Gn=(e,t)=>{e.writeStderr(`${$i}: ${t}
|
|
117
117
|
`),e.setExitCode(1)};async function mb(e,t=!1){let n;try{n=await e.ensureKizen(t?{force:t}:void 0)}catch(r){Gn(e,ke(r));return}e.writeStderr(`${$i}: kizen ${n.version} is ready in ${n.dir}.
|
|
118
118
|
`)}async function fb(e,t){let n=Ws(e,t.processEnv),r=await _r(e.env,n,t.store);if(!r.ok)return{ok:!1,message:r.message};let{environment:i}=r,o;if(n===void 0)o=await t.store.readSession(i);else{let s=Er(i,await t.store.listAccounts(i),n);o=await t.store.readAccount(i,s)}return o===null?{ok:!1,message:dt(i,`You're not signed in to ${i}.`).message}:t.scriptPath===void 0?{ok:!1,message:"can't tell which script is running, so kizen can't call back."}:{ok:!0,session:{KIZEN_AUTH_HELPER:lb(t.execPath,t.scriptPath,i,o),KIZEN_BASE_URL:Ut(i),KIZEN_BUSINESS_ID:o.businessId,KIZEN_USER_ID:o.userId}}}async function Nu(e,t){let n=cb(e);switch(n.kind){case"help":t.outputHelp();return;case"init-help":t.outputInitHelp();return;case"init":await mb(t,n.force);return;case"error":Gn(t,n.message);return;case"run":break}let r;try{r=await fb(n,t)}catch(s){Gn(t,ke(s));return}if(!r.ok){Gn(t,r.message);return}let i;try{i=await t.ensureKizen()}catch(s){Gn(t,ke(s));return}let o=db(t.processEnv,r.session);try{t.setExitCode(await pb(i,n.args,o,t.spawn,t.signals,t.interactive))}catch(s){Gn(t,`couldn't start kizen: ${ke(s)}`)}}import{spawn as yb}from"child_process";import{createHash as Bu,randomBytes as bb}from"crypto";import{createReadStream as wb,createWriteStream as vb}from"fs";import{access as Du,mkdir as Lu,readdir as kb,readFile as Ab,rename as xb,rm as Tr,stat as Di,utimes as Pb,writeFile as Cb}from"fs/promises";import{basename as Xs,join as qt}from"path";import{Readable as Sb,Transform as _b}from"stream";import{pipeline as Fu}from"stream/promises";import{spawn as gb}from"child_process";function Ru(e){return e.split(`
|
|
119
|
-
`).map(t=>t.trim().replace(/\s+#.*$/,"")).filter(t=>t.length>0&&!t.startsWith("#"))}function $u(e){let t=/^python-(\d+)[.-](\d+)$/.exec(e),n=t?.[1],r=t?.[2];return n!==void 0&&r!==void 0?`python${n}.${r}`:"python3"}function Gs([e,t],n){return e>n[0]||e===n[0]&&t>=n[1]}function Cn(e){return`${String(e[0])}.${String(e[1])}`}var hb=(e,t)=>e[0]>t[0]||e[0]===t[0]&&e[1]>t[1];function Oi(e){return new Promise(t=>{let n=gb(e,["-c","import sys; print('%d.%d' % sys.version_info[:2])"],{stdio:["ignore","pipe","ignore"]}),r="";n.stdout.on("data",i=>{r+=i.toString("utf-8")}),n.on("error",()=>{t(null)}),n.on("close",i=>{let o=/(\d+)\.(\d+)/.exec(r);if(i!==0||!o){t(null);return}t([Number(o[1]),Number(o[2])])})})}async function Js(e,t,n,r=Oi){let i=[],o;for(let s of e){let a=await r(s);if(!a){i.push(`${s}: not found`);continue}if(!Gs(a,t)){i.push(`${s}: ${Cn(a)} (too old)`);continue}if((o===void 0||hb(a,o.version))&&(o={bin:s,version:a}),n==="first")break}return{found:o,tried:i}}var Ir=[3,10];async function Ou(e,t=Oi){let n=$u(e),r=n==="python3"?["python3"]:[n,"python3"],{found:i,tried:o}=await Js(r,Ir,"first",t);if(i!==void 0)return i.bin;throw new Error(`No Python >= ${Cn(Ir)} found for runtime "${e}". The local runner needs Python ${Cn(Ir)}+ to install the bundled packages (e.g. psycopg 3.3), matching the remote code-runner (3.12 / 3.13). Tried ${o.join(", ")}. Install Python 3.12 or 3.13 and retry.`)}var Eb=e=>`https://github.com/kizen/kizen-admin-cli/releases/download/v${e}/kizen_builder-${e}-py3-none-any.whl`,Ib={version:"0.
|
|
119
|
+
`).map(t=>t.trim().replace(/\s+#.*$/,"")).filter(t=>t.length>0&&!t.startsWith("#"))}function $u(e){let t=/^python-(\d+)[.-](\d+)$/.exec(e),n=t?.[1],r=t?.[2];return n!==void 0&&r!==void 0?`python${n}.${r}`:"python3"}function Gs([e,t],n){return e>n[0]||e===n[0]&&t>=n[1]}function Cn(e){return`${String(e[0])}.${String(e[1])}`}var hb=(e,t)=>e[0]>t[0]||e[0]===t[0]&&e[1]>t[1];function Oi(e){return new Promise(t=>{let n=gb(e,["-c","import sys; print('%d.%d' % sys.version_info[:2])"],{stdio:["ignore","pipe","ignore"]}),r="";n.stdout.on("data",i=>{r+=i.toString("utf-8")}),n.on("error",()=>{t(null)}),n.on("close",i=>{let o=/(\d+)\.(\d+)/.exec(r);if(i!==0||!o){t(null);return}t([Number(o[1]),Number(o[2])])})})}async function Js(e,t,n,r=Oi){let i=[],o;for(let s of e){let a=await r(s);if(!a){i.push(`${s}: not found`);continue}if(!Gs(a,t)){i.push(`${s}: ${Cn(a)} (too old)`);continue}if((o===void 0||hb(a,o.version))&&(o={bin:s,version:a}),n==="first")break}return{found:o,tried:i}}var Ir=[3,10];async function Ou(e,t=Oi){let n=$u(e),r=n==="python3"?["python3"]:[n,"python3"],{found:i,tried:o}=await Js(r,Ir,"first",t);if(i!==void 0)return i.bin;throw new Error(`No Python >= ${Cn(Ir)} found for runtime "${e}". The local runner needs Python ${Cn(Ir)}+ to install the bundled packages (e.g. psycopg 3.3), matching the remote code-runner (3.12 / 3.13). Tried ${o.join(", ")}. Install Python 3.12 or 3.13 and retry.`)}var Eb=e=>`https://github.com/kizen/kizen-admin-cli/releases/download/v${e}/kizen_builder-${e}-py3-none-any.whl`,Ib={version:"0.5.0",wheelUrl:Eb("0.5.0"),sha256:"903f8824f3d624d23cf904e49bf03434ea849588ecf74ba7cdf190279bfff7c7"},Li="APPBUILDER_KIZEN_WHEEL",Tb=qt(nt,"kizen"),Nb=".appbuilder-ready.json",qs=[3,12],Rb=["python3.14","python3.13","python3.12","python3"],$b=720*60*6e4,Ob=60*6e4,Db=5*6e4,Lb=/^[0-9][\w.+!]*-[0-9a-f]{12}$/,Bb=/^kizen_builder-([^-]+)-.*\.whl$/;async function Fb(e){let{found:t,tried:n}=await Js(Rb,qs,"newest",e);if(t===void 0)throw new Error(`No Python ${Cn(qs)} or newer found to run kizen. Tried ${n.join(", ")}. Install Python ${Cn(qs)} or newer and retry.`);return t}var jb=20,Mb=e=>(t,n)=>new Promise((r,i)=>{let o=yb(t,n,{stdio:["ignore","pipe","pipe"]}),s="",a=c=>{s+=c.toString("utf-8")};o.stdout.on("data",a),o.stderr.on("data",a),o.on("error",c=>{i(new Error(`couldn't run ${t}: ${c.message}`))}),o.on("close",(c,l)=>{if(c===0){r();return}let d=s.trimEnd().split(`
|
|
120
120
|
`).slice(-jb).join(`
|
|
121
121
|
`);d!==""&&e(`${d}
|
|
122
122
|
`),i(new Error(`${Xs(t)} exited with ${c===null?String(l):`code ${String(c)}`}`))})});function ju(e,t,n=process.env){let r=n[Li];return{baseDir:Tb,pin:Ib,localWheel:r===""?void 0:r,fetch:(...i)=>fetch(...i),findPython:()=>Fb(),run:Mb(t),log:e,now:Date.now}}var zb=async e=>{let t=Bu("sha256");return await Fu(wb(e),t),t.digest("hex")},Bi=e=>qt(e,Nb),Nr=(e,t)=>qt(e,"bin",t);async function Zs(e,t){try{let n=JSON.parse(await Ab(Bi(e),"utf-8"));return!F(n)||n.sha256!==t?!1:(await Du(Nr(e,"python")),await Du(Nr(e,"kizen")),!0)}catch{return!1}}async function Ys(e,t){let n=new Date(t);await Pb(Bi(e),n,n).catch(()=>{})}async function Ub(e){if(e.localWheel!==void 0){let t=e.localWheel,n=Bb.exec(Xs(t))?.[1];if(n===void 0)throw new Error(`${Li} must name a kizen_builder wheel (kizen_builder-<version>-\u2026.whl), not ${t}.`);let r;try{r=await zb(t)}catch(i){throw new Error(`Couldn't read ${Li} ${t}: ${xe(i)}`)}return{version:n,sha256:r,localPath:t}}return{version:e.pin.version,sha256:e.pin.sha256,localPath:void 0}}async function Vb(e,t,n){let r=Bu("sha256");try{let i=await e.fetch(t,{signal:AbortSignal.timeout(Db)});if(!i.ok||i.body===null)throw new Error(`HTTP ${String(i.status)}`);await Fu(Sb.fromWeb(i.body),new _b({transform(o,s,a){r.update(o),a(null,o)}}),vb(n))}catch(i){throw new Error(`Couldn't download kizen from ${t}: ${xe(i)}`)}return r.digest("hex")}var Hb=e=>`.tmp-${e}-${String(process.pid)}-${bb(4).toString("hex")}`;async function Kb(e,t,n){let r;try{r=await kb(e)}catch{return}await Promise.all(r.map(async i=>{if(i===t)return;let o=qt(e,i);try{if(Lb.test(i)){let{mtimeMs:s}=await Di(Bi(o)).catch(()=>Di(o));n-s>$b&&await Tr(o,{recursive:!0,force:!0})}else if(i.startsWith(".tmp-")){let{mtimeMs:s}=await Di(o);n-s>Ob&&await Tr(o,{recursive:!0,force:!0})}}catch{}}))}var Wb=e=>Di(e).then(()=>!0,()=>!1),Mu=e=>new Error(`kizen's install at ${e} is damaged. Run \`appbuilder admin init --force\` to reinstall it.`);async function Gb(e,t,n){try{return await xb(e,t),!0}catch(r){if(!He(r,"ENOTEMPTY")&&!He(r,"EEXIST"))throw r}if(await Zs(t,n))return!1;throw Mu(t)}async function zu(e,t={}){let n=await Ub(e),r=`${n.version}-${n.sha256.slice(0,12)}`,i=qt(e.baseDir,r),o=u=>({version:n.version,dir:i,python:Nr(i,"python"),kizen:Nr(i,"kizen"),built:u});if(t.force===!0)e.log(`Removing ${i}.`),await Tr(i,{recursive:!0,force:!0});else{if(await Zs(i,n.sha256))return await Ys(i,e.now()),o(!1);if(await Wb(i)){if(await Zs(i,n.sha256))return await Ys(i,e.now()),o(!1);throw Mu(i)}}e.log(`Installing kizen ${n.version} into ${i} (first run only).`);let s=await e.findPython();e.log(`Using ${s.bin} (Python ${Cn(s.version)}).`),await Lu(e.baseDir,{recursive:!0,mode:448});let a=qt(e.baseDir,Hb(r)),c=qt(a,"venv"),l;try{await Lu(a);let u;if(n.localPath===void 0){u=qt(a,Xs(new URL(e.pin.wheelUrl).pathname)),e.log(`Downloading ${e.pin.wheelUrl}`);let f=await Vb(e,e.pin.wheelUrl,u);if(f!==n.sha256)throw await Tr(u,{force:!0}),new Error(`The kizen ${n.version} download doesn't match its pinned sha256 (expected ${n.sha256}, got ${f}), so nothing was installed.`)}else u=n.localPath,e.log(`Using the local wheel ${u} (${Li}).`);e.log("Creating a virtual environment.");try{await e.run(s.bin,["-m","venv",c])}catch(f){throw new Error(`Couldn't create a virtual environment: ${ke(f)}`)}e.log(`Installing kizen ${n.version} from the wheel and its dependencies from PyPI.`);try{await e.run(Nr(c,"python"),["-m","pip","install","--disable-pip-version-check",u])}catch(f){throw new Error(`Couldn't install kizen: ${ke(f)}`)}await Cb(Bi(c),`${JSON.stringify({version:n.version,sha256:n.sha256},null,2)}
|