@zenku/cli-node 0.1.15 → 0.1.16

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 (2) hide show
  1. package/package.json +1 -1
  2. package/zenku-bundle.cjs +4 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenku/cli-node",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "Zenku CLI (Node.js) — runs under node, no native binary.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "bin": {
package/zenku-bundle.cjs CHANGED
@@ -140,7 +140,7 @@ ${t}`,S$=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),E$=Objec
140
140
  `),process.stdout.write(`Type: ${o.type}
141
141
  `),process.stdout.write(`Slug: ${o.slug}
142
142
  `),process.stdout.write(`Created: ${o.created}
143
- `)}})}),e.command("create").description("Create an account").requiredOption("--name <name>","account name").option("--type <type>","account type (personal/team)","team").action(async i=>{let{profile:r,client:o}=await T("vault"),a=p_(i.name),s=await k("Creating account...",()=>o.collection("accounts").create({name:i.name,type:i.type,slug:a,owner:r.userId}));x({json:()=>s,human:()=>E("Account created: %s (%s)",s.name,s.id)})});let t=new A("members").description("Manage account members");t.command("list").description("List members of an account").argument("<account-id>","account ID").action(async i=>{let{client:r}=await T("vault"),o=await k("Fetching members...",()=>r.collection("account_members").getList(1,200,{filter:`account='${i}'`,expand:"role,user",sort:"-created"}));x({json:()=>o.items,human:()=>{let a=o.items.map(s=>{let u="",c="",l=s.expand;return l&&(l.user&&(u=nt(l.user.email)),l.role&&(c=nt(l.role.name))),[s.id,u,c,s.created]});X(["ID","USER","ROLE","CREATED"],a)}})}),t.command("add").description("Add a member to an account").argument("<account-id>","account ID").requiredOption("--user <id>","user ID to add").requiredOption("--role <slug>","role slug").action(async(i,r)=>{let{client:o}=await T("vault"),a=await k("Resolving role...",()=>$v(o,r.role)),s=await k("Adding member...",()=>o.collection("account_members").create({account:i,user:r.user,role:a}));x({json:()=>s,human:()=>E("Member added: %s",s.id)})}),t.command("remove").description("Remove a member from an account").argument("<account-id>","account ID").argument("<member-id>","member ID").action(async(i,r)=>{let{client:o}=await T("vault");await k("Removing member...",()=>o.collection("account_members").delete(r)),x({json:()=>({deleted:!0}),human:()=>E("Member removed")})}),e.addCommand(t);let n=new A("invitations").description("Manage account invitations");return n.command("list").description("List invitations for an account").argument("<account-id>","account ID").action(async i=>{let{client:r}=await T("vault"),o=await k("Fetching invitations...",()=>r.collection("account_invitations").getList(1,200,{filter:`account='${i}'`,expand:"role",sort:"-created"}));x({json:()=>o.items,human:()=>{let a=o.items.map(s=>{let u="",c=s.expand;return c?.role&&(u=nt(c.role.name)),[s.id,s.email,u,s.accepted_at?"accepted":"pending",s.created]});X(["ID","EMAIL","ROLE","STATUS","CREATED"],a)}})}),n.command("create").description("Create an invitation").argument("<account-id>","account ID").requiredOption("--email <email>","email to invite").requiredOption("--role <slug>","role slug").action(async(i,r)=>{let{client:o}=await T("vault"),a=await k("Resolving role...",()=>$v(o,r.role)),s=await k("Creating invitation...",()=>o.collection("account_invitations").create({account:i,email:r.email,role:a}));x({json:()=>s,human:()=>E("Invitation sent to %s",r.email)})}),e.addCommand(n),e}function _v(e){e.addCommand(f_())}function m_(){let e=new A("roles").description("Manage RBAC roles");return e.command("list").description("List all roles").action(async()=>{let{client:t}=await T("vault"),n=await k("Fetching roles...",()=>t.collection("roles").getList(1,200,{sort:"name"}));x({json:()=>n.items,human:()=>{let i=n.items.map(r=>[r.id,r.name,r.slug,r.is_system?"yes":""]);X(["ID","NAME","SLUG","SYSTEM"],i)}})}),e}function xv(e){e.addCommand(m_())}function h_(){let e=new A("vault").description("Vault memory commands (bots, nodes, sessions, messages, summaries)"),t=new A("bots").description("Manage vault bots");t.command("list").description("List bots").action(async()=>{let{client:a}=await T("vault"),s=await k("Fetching bots...",()=>a.collection("bots").getList(1,200,{sort:"-created"}));x({json:()=>s.items,human:()=>{let u=s.items.map(c=>[c.id,c.name,c.slug,c.created]);X(["ID","NAME","SLUG","CREATED"],u)}})}),t.command("get").description("Get bot details").argument("<id>","bot ID").action(async a=>{let{client:s}=await T("vault"),u=await k("Fetching bot...",()=>s.collection("bots").getOne(a));x({json:()=>u,human:()=>{process.stdout.write(`ID: ${u.id}
143
+ `)}})}),e.command("create").description("Create an account").requiredOption("--name <name>","account name").option("--type <type>","account type (personal/team)","team").action(async i=>{let{profile:r,client:o}=await T("vault"),a=p_(i.name),s=await k("Creating account...",()=>o.collection("accounts").create({name:i.name,type:i.type,slug:a,owner:r.userId}));x({json:()=>s,human:()=>E("Account created: %s (%s)",s.name,s.id)})});let t=new A("members").description("Manage account members");t.command("list").description("List members of an account").argument("<account-id>","account ID").action(async i=>{let{client:r}=await T("vault"),o=await k("Fetching members...",()=>r.collection("account_members").getList(1,200,{filter:`account='${i}'`,expand:"role,user",sort:"-created"}));x({json:()=>o.items,human:()=>{let a=o.items.map(s=>{let u="",c="",l=s.expand;return l&&(l.user&&(u=nt(l.user.email)),l.role&&(c=nt(l.role.name))),[s.id,u,c,s.created]});X(["ID","USER","ROLE","CREATED"],a)}})}),t.command("add").description("Add a member to an account").argument("<account-id>","account ID").requiredOption("--user <id>","user ID to add").requiredOption("--role <slug>","role slug").action(async(i,r)=>{let{client:o}=await T("vault"),a=await k("Resolving role...",()=>$v(o,r.role)),s=await k("Adding member...",()=>o.collection("account_members").create({account:i,user:r.user,role:a}));x({json:()=>s,human:()=>E("Member added: %s",s.id)})}),t.command("remove").description("Remove a member from an account").argument("<account-id>","account ID").argument("<member-id>","member ID").action(async(i,r)=>{let{client:o}=await T("vault");await k("Removing member...",()=>o.collection("account_members").delete(r)),x({json:()=>({deleted:!0}),human:()=>E("Member removed")})}),e.addCommand(t);let n=new A("invitations").description("Manage account invitations");return n.command("list").description("List invitations for an account").argument("<account-id>","account ID").action(async i=>{let{client:r}=await T("vault"),o=await k("Fetching invitations...",()=>r.collection("account_invitations").getList(1,200,{filter:`account='${i}'`,expand:"role",sort:"-created"}));x({json:()=>o.items,human:()=>{let a=o.items.map(s=>{let u="",c=s.expand;return c?.role&&(u=nt(c.role.name)),[s.id,s.email,u,s.accepted_at?"accepted":"pending",s.created]});X(["ID","EMAIL","ROLE","STATUS","CREATED"],a)}})}),n.command("create").description("Create an invitation").argument("<account-id>","account ID").requiredOption("--email <email>","email to invite").requiredOption("--role <slug>","role slug").action(async(i,r)=>{let{client:o}=await T("vault"),a=await k("Resolving role...",()=>$v(o,r.role)),s=await k("Creating invitation...",()=>o.collection("account_invitations").create({account:i,email:r.email,role:a}));x({json:()=>s,human:()=>E("Invitation sent to %s",r.email)})}),e.addCommand(n),e}function _v(e){e.addCommand(f_())}function m_(){let e=new A("roles").description("Manage RBAC roles");return e.command("list").description("List all roles").action(async()=>{let{client:t}=await T("vault"),n=await k("Fetching roles...",()=>t.collection("roles").getList(1,200,{sort:"name"}));x({json:()=>n.items,human:()=>{let i=n.items.map(r=>[r.id,r.name,r.slug,r.is_system?"yes":""]);X(["ID","NAME","SLUG","SYSTEM"],i)}})}),e}function xv(e){e.addCommand(m_())}function h_(){let e=new A("vault").description("Vault memory commands (agents, nodes, sessions, messages, summaries)"),t=new A("agents").description("Manage vault agents");t.command("list").description("List agents").action(async()=>{let{client:a}=await T("vault"),s=await k("Fetching agents...",()=>a.collection("agents").getList(1,200,{sort:"-created"}));x({json:()=>s.items,human:()=>{let u=s.items.map(c=>[c.id,c.name,c.slug,c.created]);X(["ID","NAME","SLUG","CREATED"],u)}})}),t.command("get").description("Get agent details").argument("<id>","agent ID").action(async a=>{let{client:s}=await T("vault"),u=await k("Fetching agent...",()=>s.collection("agents").getOne(a));x({json:()=>u,human:()=>{process.stdout.write(`ID: ${u.id}
144
144
  `),process.stdout.write(`Name: ${u.name}
145
145
  `),process.stdout.write(`Slug: ${u.slug}
146
146
  `),process.stdout.write(`Created: ${u.created}
@@ -153,9 +153,9 @@ ${t}`,S$=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),E$=Objec
153
153
  `);let c=u.content;c&&process.stdout.write(`
154
154
  ${c}
155
155
  `)}})}),n.command("tree").description("Get node tree").option("--depth <n>","tree depth (1-10)","3").option("--node <id>","root node ID").action(async a=>{let s=await $e("vault"),u=Number(a.depth),l={depth:Number.isNaN(u)?3:u};a.node&&(l.nodeId=a.node);let d=await k("Fetching tree...",()=>s.query("nodes.getTree",l));x({json:()=>d,human:()=>{process.stdout.write(JSON.stringify(d,null,2)+`
156
- `)}})}),n.command("create").description("Create a knowledge node").requiredOption("--title <title>","node title").option("--type <type>","node type (folder/document)","document").requiredOption("--slug <slug>","node slug").option("--parent <id>","parent node ID").option("--content <content>","node content (use @file or - for stdin)").action(async a=>{let s=await $e("vault"),u={title:a.title,slug:a.slug,type:a.type};a.parent&&(u.parent=a.parent),a.content&&(u.content=Dt(a.content));let c=await k("Creating node...",()=>s.mutate("nodes.create",u));x({json:()=>c,human:()=>{let l=c;E("Node created: %s (%s)",l.title,l.id)}})}),n.command("update").description("Update a knowledge node").argument("<id>","node ID").option("--title <title>","new title").option("--content <content>","new content (use @file or - for stdin)").action(async(a,s)=>{let u=await $e("vault"),c={id:a};s.title&&(c.title=s.title),s.content&&(c.content=Dt(s.content));let l=await k("Updating node...",()=>u.mutate("nodes.update",c));x({json:()=>l,human:()=>E("Node updated")})}),n.command("delete").description("Delete a knowledge node").argument("<id>","node ID").action(async a=>{let s=await $e("vault");await k("Deleting node...",()=>s.mutate("nodes.delete",{id:a})),x({json:()=>({deleted:!0}),human:()=>E("Node deleted")})});let i=new A("sessions").description("Manage vault sessions");i.command("list").description("List sessions").option("--status <status>","filter by status").action(async a=>{let{client:s}=await T("vault"),u=a.status?`status='${a.status}'`:"",c=await k("Fetching sessions...",()=>s.collection("sessions").getList(1,200,{sort:"-created",filter:u}));x({json:()=>c.items,human:()=>{let l=c.items.map(d=>[d.id,d.session_key,d.bot,d.status,d.created]);X(["ID","SESSION KEY","BOT","STATUS","CREATED"],l)}})}),i.command("get").description("Get session details").argument("<id>","session ID").action(async a=>{let{client:s}=await T("vault"),u=await k("Fetching session...",()=>s.collection("sessions").getOne(a));x({json:()=>u,human:()=>{process.stdout.write(`ID: ${u.id}
156
+ `)}})}),n.command("create").description("Create a knowledge node").requiredOption("--title <title>","node title").option("--type <type>","node type (folder/document)","document").requiredOption("--slug <slug>","node slug").option("--parent <id>","parent node ID").option("--content <content>","node content (use @file or - for stdin)").action(async a=>{let s=await $e("vault"),u={title:a.title,slug:a.slug,type:a.type};a.parent&&(u.parent=a.parent),a.content&&(u.content=Dt(a.content));let c=await k("Creating node...",()=>s.mutate("nodes.create",u));x({json:()=>c,human:()=>{let l=c;E("Node created: %s (%s)",l.title,l.id)}})}),n.command("update").description("Update a knowledge node").argument("<id>","node ID").option("--title <title>","new title").option("--content <content>","new content (use @file or - for stdin)").action(async(a,s)=>{let u=await $e("vault"),c={id:a};s.title&&(c.title=s.title),s.content&&(c.content=Dt(s.content));let l=await k("Updating node...",()=>u.mutate("nodes.update",c));x({json:()=>l,human:()=>E("Node updated")})}),n.command("delete").description("Delete a knowledge node").argument("<id>","node ID").action(async a=>{let s=await $e("vault");await k("Deleting node...",()=>s.mutate("nodes.delete",{id:a})),x({json:()=>({deleted:!0}),human:()=>E("Node deleted")})});let i=new A("sessions").description("Manage vault sessions");i.command("list").description("List sessions").option("--status <status>","filter by status").action(async a=>{let{client:s}=await T("vault"),u=a.status?`status='${a.status}'`:"",c=await k("Fetching sessions...",()=>s.collection("sessions").getList(1,200,{sort:"-created",filter:u}));x({json:()=>c.items,human:()=>{let l=c.items.map(d=>[d.id,d.session_key,d.agent,d.status,d.created]);X(["ID","SESSION KEY","AGENT","STATUS","CREATED"],l)}})}),i.command("get").description("Get session details").argument("<id>","session ID").action(async a=>{let{client:s}=await T("vault"),u=await k("Fetching session...",()=>s.collection("sessions").getOne(a));x({json:()=>u,human:()=>{process.stdout.write(`ID: ${u.id}
157
157
  `),process.stdout.write(`Session Key: ${u.session_key}
158
- `),process.stdout.write(`Bot: ${u.bot}
158
+ `),process.stdout.write(`Agent: ${u.agent}
159
159
  `),process.stdout.write(`Status: ${u.status}
160
160
  `),process.stdout.write(`Channel: ${u.channel}
161
161
  `),process.stdout.write(`Created: ${u.created}
@@ -193,4 +193,4 @@ Contents:
193
193
  `)}})}),e.command("install").description("Install a skill, agent, or persona into the current project").argument("<name>","skill, agent, or persona name").option("--force","overwrite existing installation").option("--global","install to home directory (~/) instead of project root").option(...Yo).action(async(t,n)=>{let i=Jo(n.target),{item:r,zipBytes:o,version:a}=await k("Fetching kit catalog...",async()=>{let c=await In(),l=Go(c,t);l||_('"%s" not found in agent-kit (run `zenku agent-kit list` to see available items)',t);let d=await Wo(l.name,l.type);return{item:l,zipBytes:d,version:c.version}}),s=Ko(n.global),u=i.map(c=>Ho(s,r.name,r.type,c));if(!n.force){let c=u.filter(l=>(0,G.existsSync)(l));c.length>0&&_('"%s" is already installed at %s (use --force to overwrite)',t,c.join(", "))}for(let c of u)r.type==="skill"?((0,G.existsSync)(c)&&(0,G.rmSync)(c,{recursive:!0}),Zv(o,c)):Lv(o,c);x({json:()=>({installed:r.name,type:r.type,version:a,targets:i,paths:u}),human:()=>{for(let c of u)E("Installed %s (%s) -> %s",r.name,r.type,c)}})}),e.command("uninstall").description("Remove an installed skill, agent, or persona").argument("<name>","skill, agent, or persona name").option("--global","uninstall from home directory (~/) instead of project root").option(...Yo).action(async(t,n)=>{try{let i=Jo(n.target),r=Ko(n.global),o=[];for(let a of i){let s=Ho(r,t,"skill",a),u=Ho(r,t,"agent",a),c=(0,G.existsSync)((0,ue.join)(s,"SKILL.md")),l=(0,G.existsSync)(u);c&&((0,G.rmSync)(s,{recursive:!0}),o.push({target:a,type:"skill"})),l&&((0,G.rmSync)(u),o.push({target:a,type:"agent"}))}o.length===0&&_('"%s" is not installed (run `zenku agent-kit installed` to see installed items)',t),x({json:()=>({uninstalled:t,type:o[0].type,targets:[...new Set(o.map(a=>a.target))]}),human:()=>E("Uninstalled %s",t)})}catch(i){_("%s",Y(i))}}),e.command("installed").description("List installed skills and agents").option("--skills","show skills only").option("--agents","show agents only").option("--global","list installed items in home directory (~/) instead of project root").option(...Yo).action(async t=>{try{let n=Jo(t.target),i=Ko(t.global),r=Rv(i,n);if(t.skills&&(r=r.filter(o=>o.type==="skill")),t.agents&&(r=r.filter(o=>o.type==="agent")),r.length===0){x({json:()=>({items:[]}),human:()=>V("No skills or agents installed.")});return}x({json:()=>({items:r}),human:()=>{X(["NAME","TYPE","TARGETS"],r.map(o=>[o.name,o.type,o.targets.join(", ")]))}})}catch(n){_("%s",Y(n))}}),e.command("update").description("Update installed items to the latest kit version").argument("[name]","skill, agent, or persona name (omit with --all)").option("--all","update all installed items").option("--global","update items in home directory (~/) instead of project root").option(...Yo).action(async(t,n)=>{!t&&!n.all&&_("provide <name> or use --all"),t&&n.all&&_("use either <name> or --all, not both");let i=Jo(n.target),r=Ko(n.global),o=await k("Checking for updates...",()=>In()),a;if(n.all){a=new Map;let u=Rv(r,i),c=new Set(o.items.map(l=>l.name));for(let l of u)c.has(l.name)&&a.set(l.name,l.targets)}else a=new Map([[t,i]]);if(a.size===0){V("No kit items installed to update.");return}let s=[];for(let[u,c]of a){let l=Go(o,u);if(!l){s.push({name:u,action:"not-found"});continue}let d=await k(`Updating ${u}...`,()=>Wo(l.name,l.type));for(let p of c){let m=Ho(r,u,l.type,p);l.type==="skill"?((0,G.existsSync)(m)&&(0,G.rmSync)(m,{recursive:!0}),Zv(d,m)):Lv(d,m)}s.push({name:u,action:"updated",targets:c})}x({json:()=>({version:o.version,results:s}),human:()=>{for(let u of s)u.action==="updated"?E("%s: updated to v%s",u.name,o.version):V("%s: not found in agent-kit (may have been removed)",u.name)}})}),e}function Vv(e){e.addCommand(G_())}function qv(e){let t=new A("context").description("Manage tenant and account context");t.command("show").description("Display current tenant and account context").action(()=>{let n=re(de()),i;try{({profile:i}=oe(n))}catch(a){_("%s",Y(a))}let r=Ot(i),o=Pt(i);x({json:()=>({tenantId:r||null,accountId:o||null,profile:n}),human:()=>{process.stdout.write(`Profile: ${n}
194
194
  `),process.stdout.write(`Tenant ID: ${r||"(not set)"}
195
195
  `),process.stdout.write(`Account ID: ${o||"(not set)"}
196
- `)}})}),t.command("set").description("Set tenant and/or account in profile").option("--tenant-id <id>","tenant ID to store").option("--account-id <id>","account ID to store").action(n=>{!n.tenantId&&!n.accountId&&_("specify --tenant-id <id> and/or --account-id <id>");let i=re(de()),r,o;try{({cfg:r,profile:o}=oe(i))}catch(a){_("%s",Y(a))}n.tenantId&&(o.tenantId=n.tenantId),n.accountId&&(o.accountId=n.accountId),le(r,i,o),x({json:()=>({tenantId:o.tenantId||null,accountId:o.accountId||null}),human:()=>{n.tenantId&&E("Tenant ID set to %s",n.tenantId),n.accountId&&E("Account ID set to %s",n.accountId)}})}),t.command("clear").description("Remove tenant and/or account from profile").option("--tenant-id","clear tenant ID").option("--account-id","clear account ID").action(n=>{let i=!n.tenantId&&!n.accountId,r=re(de()),o,a;try{({cfg:o,profile:a}=oe(r))}catch(s){_("%s",Y(s))}(i||n.tenantId)&&(a.tenantId=""),(i||n.accountId)&&(a.accountId=""),le(o,r,a),x({json:()=>({tenantId:a.tenantId||null,accountId:a.accountId||null}),human:()=>{i?E("Tenant and account context cleared."):n.tenantId?E("Tenant ID cleared."):E("Account ID cleared.")}})}),t.command("use").description("Interactively pick an account from your memberships").action(async()=>{let{cfg:n,profile:i,client:r}=await T("auth"),o=await Ro(r.baseURL,r.authStore.token,i.userId);if(!o){V("No account selected.");return}let a=re(de());i.accountId=o,le(n,a,i),x({json:()=>({accountId:o}),human:()=>E("Account set to %s",o)})}),e.addCommand(t)}var Xo=require("node:child_process"),pe=require("node:fs"),Wv=require("node:os"),yt=require("node:path");function Gv(){return!0}var Jv="https://registry.npmjs.org",W_=15e3,Kv="@zenku";function J_(){let{platform:e,arch:t}=process,n=["darwin-arm64","darwin-x64","linux-arm64","linux-x64"],i=`${e}-${t}`;return n.includes(i)||_("Unsupported platform: %s",i),`cli-${i}`}async function K_(e){let t=`${Jv}/${Kv}/${e}/latest`,n=new AbortController,i=setTimeout(()=>n.abort(),W_);try{let r=await fetch(t,{signal:n.signal});if(!r.ok)throw new Error(`HTTP ${r.status}`);return(await r.json()).version}catch(r){throw r instanceof DOMException&&r.name==="AbortError"?new Error("request timed out"):r}finally{clearTimeout(i)}}function H_(e,t){let n=`${e}-${t}.tgz`,i=`${Jv}/${Kv}/${e}/-/${n}`,r=(0,pe.mkdtempSync)((0,yt.join)((0,Wv.tmpdir)(),"zenku-upgrade-"));try{(0,Xo.execSync)(`curl -fsSL "${i}" -o "${(0,yt.join)(r,n)}"`,{stdio:"pipe"}),(0,Xo.execSync)(`tar xzf "${(0,yt.join)(r,n)}" -C "${r}"`,{stdio:"pipe"});let o=(0,yt.join)(r,"package","zenku"),a=process.execPath,s=(0,yt.dirname)(a),u=(0,yt.join)(s,`.zenku-upgrade-${process.pid}`),c=!1;try{(0,pe.accessSync)(s,pe.constants.W_OK)}catch{c=!0}if(c)(0,Xo.execSync)(`sudo install -m 755 "${o}" "${a}"`,{stdio:"inherit"});else{(0,pe.copyFileSync)(o,u),(0,pe.chmodSync)(u,493);try{(0,pe.renameSync)(u,a)}catch{try{(0,pe.unlinkSync)(u)}catch{}throw new Error(`failed to replace binary at ${a}`)}}}finally{(0,pe.rmSync)(r,{recursive:!0,force:!0})}}function Hv(e){e.addCommand(new A("upgrade").description("Upgrade zenku to the latest version").action(async()=>{if(Gv()){x({json:()=>({mode:"bundle",message:"Self-upgrade not available in bundle mode. Use: npm update -g @zenku/cli-node"}),human:()=>{V("Self-upgrade is not available in bundle mode."),V("Update via npm: npm update -g @zenku/cli-node")}});return}let t=Ap(),n=J_(),i=await k("Checking for updates...",()=>K_(n));if(t===i){x({json:()=>({previous:t,latest:i,upgraded:!1}),human:()=>V("Already up to date (v%s).",t)});return}V("v%s \u2192 v%s",t,i),await k(`Downloading v${i}...`,async()=>{H_(n,i)}),x({json:()=>({previous:t,latest:i,upgraded:!0}),human:()=>V("Upgraded zenku to v%s.",i)})}))}var Y_={};function Ap(){return"0.1.15"}function Qv(){let e=new A;return e.name("zenku").description("Zenku CLI \u2014 manage PocketBase services from the terminal.").version(Ap()).option("--profile <name>","config profile to use").option("--tenant <id>","override tenant ID for this command").option("--account <id>","override account ID for this command").option("--json","output as JSON").option("--interactive","force interactive mode").option("--non-interactive","force non-interactive mode").hook("preAction",t=>{let n=t.optsWithGlobals();dv(n.profile??""),ev(n.tenant??""),tv(n.account??""),Yg(!!n.json),n.interactive&&n.nonInteractive&&_("--interactive and --non-interactive cannot be used together"),n.interactive?Cd("interactive"):n.nonInteractive&&Cd("non-interactive")}),hv(e),gv(e),vv(e),yv(e),bv(e),_v(e),xv(e),wv(e),Iv(e),Vv(e),qv(e),Hv(e),e}var X_=Qv();X_.parse();
196
+ `)}})}),t.command("set").description("Set tenant and/or account in profile").option("--tenant-id <id>","tenant ID to store").option("--account-id <id>","account ID to store").action(n=>{!n.tenantId&&!n.accountId&&_("specify --tenant-id <id> and/or --account-id <id>");let i=re(de()),r,o;try{({cfg:r,profile:o}=oe(i))}catch(a){_("%s",Y(a))}n.tenantId&&(o.tenantId=n.tenantId),n.accountId&&(o.accountId=n.accountId),le(r,i,o),x({json:()=>({tenantId:o.tenantId||null,accountId:o.accountId||null}),human:()=>{n.tenantId&&E("Tenant ID set to %s",n.tenantId),n.accountId&&E("Account ID set to %s",n.accountId)}})}),t.command("clear").description("Remove tenant and/or account from profile").option("--tenant-id","clear tenant ID").option("--account-id","clear account ID").action(n=>{let i=!n.tenantId&&!n.accountId,r=re(de()),o,a;try{({cfg:o,profile:a}=oe(r))}catch(s){_("%s",Y(s))}(i||n.tenantId)&&(a.tenantId=""),(i||n.accountId)&&(a.accountId=""),le(o,r,a),x({json:()=>({tenantId:a.tenantId||null,accountId:a.accountId||null}),human:()=>{i?E("Tenant and account context cleared."):n.tenantId?E("Tenant ID cleared."):E("Account ID cleared.")}})}),t.command("use").description("Interactively pick an account from your memberships").action(async()=>{let{cfg:n,profile:i,client:r}=await T("auth"),o=await Ro(r.baseURL,r.authStore.token,i.userId);if(!o){V("No account selected.");return}let a=re(de());i.accountId=o,le(n,a,i),x({json:()=>({accountId:o}),human:()=>E("Account set to %s",o)})}),e.addCommand(t)}var Xo=require("node:child_process"),pe=require("node:fs"),Wv=require("node:os"),yt=require("node:path");function Gv(){return!0}var Jv="https://registry.npmjs.org",W_=15e3,Kv="@zenku";function J_(){let{platform:e,arch:t}=process,n=["darwin-arm64","darwin-x64","linux-arm64","linux-x64"],i=`${e}-${t}`;return n.includes(i)||_("Unsupported platform: %s",i),`cli-${i}`}async function K_(e){let t=`${Jv}/${Kv}/${e}/latest`,n=new AbortController,i=setTimeout(()=>n.abort(),W_);try{let r=await fetch(t,{signal:n.signal});if(!r.ok)throw new Error(`HTTP ${r.status}`);return(await r.json()).version}catch(r){throw r instanceof DOMException&&r.name==="AbortError"?new Error("request timed out"):r}finally{clearTimeout(i)}}function H_(e,t){let n=`${e}-${t}.tgz`,i=`${Jv}/${Kv}/${e}/-/${n}`,r=(0,pe.mkdtempSync)((0,yt.join)((0,Wv.tmpdir)(),"zenku-upgrade-"));try{(0,Xo.execSync)(`curl -fsSL "${i}" -o "${(0,yt.join)(r,n)}"`,{stdio:"pipe"}),(0,Xo.execSync)(`tar xzf "${(0,yt.join)(r,n)}" -C "${r}"`,{stdio:"pipe"});let o=(0,yt.join)(r,"package","zenku"),a=process.execPath,s=(0,yt.dirname)(a),u=(0,yt.join)(s,`.zenku-upgrade-${process.pid}`),c=!1;try{(0,pe.accessSync)(s,pe.constants.W_OK)}catch{c=!0}if(c)(0,Xo.execSync)(`sudo install -m 755 "${o}" "${a}"`,{stdio:"inherit"});else{(0,pe.copyFileSync)(o,u),(0,pe.chmodSync)(u,493);try{(0,pe.renameSync)(u,a)}catch{try{(0,pe.unlinkSync)(u)}catch{}throw new Error(`failed to replace binary at ${a}`)}}}finally{(0,pe.rmSync)(r,{recursive:!0,force:!0})}}function Hv(e){e.addCommand(new A("upgrade").description("Upgrade zenku to the latest version").action(async()=>{if(Gv()){x({json:()=>({mode:"bundle",message:"Self-upgrade not available in bundle mode. Use: npm update -g @zenku/cli-node"}),human:()=>{V("Self-upgrade is not available in bundle mode."),V("Update via npm: npm update -g @zenku/cli-node")}});return}let t=Ap(),n=J_(),i=await k("Checking for updates...",()=>K_(n));if(t===i){x({json:()=>({previous:t,latest:i,upgraded:!1}),human:()=>V("Already up to date (v%s).",t)});return}V("v%s \u2192 v%s",t,i),await k(`Downloading v${i}...`,async()=>{H_(n,i)}),x({json:()=>({previous:t,latest:i,upgraded:!0}),human:()=>V("Upgraded zenku to v%s.",i)})}))}var Y_={};function Ap(){return"0.1.16"}function Qv(){let e=new A;return e.name("zenku").description("Zenku CLI \u2014 manage PocketBase services from the terminal.").version(Ap()).option("--profile <name>","config profile to use").option("--tenant <id>","override tenant ID for this command").option("--account <id>","override account ID for this command").option("--json","output as JSON").option("--interactive","force interactive mode").option("--non-interactive","force non-interactive mode").hook("preAction",t=>{let n=t.optsWithGlobals();dv(n.profile??""),ev(n.tenant??""),tv(n.account??""),Yg(!!n.json),n.interactive&&n.nonInteractive&&_("--interactive and --non-interactive cannot be used together"),n.interactive?Cd("interactive"):n.nonInteractive&&Cd("non-interactive")}),hv(e),gv(e),vv(e),yv(e),bv(e),_v(e),xv(e),wv(e),Iv(e),Vv(e),qv(e),Hv(e),e}var X_=Qv();X_.parse();