@zenku/cli-node 0.1.25 → 0.1.26
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/package.json +1 -1
- package/zenku-bundle.cjs +1 -1
package/package.json
CHANGED
package/zenku-bundle.cjs
CHANGED
|
@@ -237,4 +237,4 @@ ${r.result.output}
|
|
|
237
237
|
Contents:
|
|
238
238
|
`);for(let o of i)process.stdout.write(` ${o}
|
|
239
239
|
`)}})}),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(...fa).action(async(t,n)=>{let i=la(n.target),{item:r,zipBytes:o,version:a}=await C("Fetching kit catalog...",async()=>{let c=await Tn(),l=ua(c,t);l||y('"%s" not found in agent-kit (run `zenku agent-kit list` to see available items)',t);let d=await ca(l.name,l.type);return{item:l,zipBytes:d,version:c.version}}),s=da(n.global),u=i.map(c=>pa(s,r.name,r.type,c));if(!n.force){let c=u.filter(l=>(0,H.existsSync)(l));c.length>0&&y('"%s" is already installed at %s (use --force to overwrite)',t,c.join(", "))}for(let c of u)r.type==="skill"?((0,H.existsSync)(c)&&(0,H.rmSync)(c,{recursive:!0}),yD(o,c)):bD(o,c);_({json:()=>({installed:r.name,type:r.type,version:a,targets:i,paths:u}),human:()=>{for(let c of u)S("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(...fa).action(async(t,n)=>{try{let i=la(n.target),r=da(n.global),o=[];for(let a of i){let s=pa(r,t,"skill",a),u=pa(r,t,"agent",a),c=(0,H.existsSync)((0,le.join)(s,"SKILL.md")),l=(0,H.existsSync)(u);c&&((0,H.rmSync)(s,{recursive:!0}),o.push({target:a,type:"skill"})),l&&((0,H.rmSync)(u),o.push({target:a,type:"agent"}))}o.length===0&&y('"%s" is not installed (run `zenku agent-kit installed` to see installed items)',t),_({json:()=>({uninstalled:t,type:o[0].type,targets:[...new Set(o.map(a=>a.target))]}),human:()=>S("Uninstalled %s",t)})}catch(i){y("%s",L(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(...fa).action(async t=>{try{let n=la(t.target),i=da(t.global),r=DD(i,n);if(t.skills&&(r=r.filter(o=>o.type==="skill")),t.agents&&(r=r.filter(o=>o.type==="agent")),r.length===0){_({json:()=>({items:[]}),human:()=>U("No skills or agents installed.")});return}_({json:()=>({items:r}),human:()=>{Y(["NAME","TYPE","TARGETS"],r.map(o=>[o.name,o.type,o.targets.join(", ")]))}})}catch(n){y("%s",L(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(...fa).action(async(t,n)=>{!t&&!n.all&&y("provide <name> or use --all"),t&&n.all&&y("use either <name> or --all, not both");let i=la(n.target),r=da(n.global),o=await C("Checking for updates...",()=>Tn()),a;if(n.all){a=new Map;let u=DD(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){U("No kit items installed to update.");return}let s=[];for(let[u,c]of a){let l=ua(o,u);if(!l){s.push({name:u,action:"not-found"});continue}let d=await C(`Updating ${u}...`,()=>ca(l.name,l.type));for(let p of c){let m=pa(r,u,l.type,p);l.type==="skill"?((0,H.existsSync)(m)&&(0,H.rmSync)(m,{recursive:!0}),yD(d,m)):bD(d,m)}s.push({name:u,action:"updated",targets:c})}_({json:()=>({version:o.version,results:s}),human:()=>{for(let u of s)u.action==="updated"?S("%s: updated to v%s",u.name,o.version):U("%s: not found in agent-kit (may have been removed)",u.name)}})}),e}function _D(e){e.addCommand(Ux())}var Ce=require("node:fs"),He=require("node:path"),jn=require("node:os");function of(e){return e||(process.env.CLAUDE_CONFIG_DIR?process.env.CLAUDE_CONFIG_DIR:(0,He.join)((0,jn.homedir)(),".claude"))}function xD(e){return e||(process.env.ZENKU_MACHINE_ID?process.env.ZENKU_MACHINE_ID:(0,jn.hostname)())}function af(e){let t=[],n;try{n=(0,Ce.readdirSync)(e,{withFileTypes:!0})}catch{return t}for(let i of n){let r=(0,He.join)(e,i.name);i.isDirectory()?t.push(...af(r)):i.isFile()&&i.name.endsWith(".jsonl")&&t.push(r)}return t}function ft(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Nx(e,t){let n=(0,Ce.statSync)(e);return Date.now()-n.mtimeMs>=t*86400*1e3}function wD(e,t,n){let i=(0,He.relative)(t,e);return`${n}/${i}`}function Rx(e){return e.replace(/'/g,"\\'")}async function kD(e,t,n,i,r,o,a){let u=(0,Ce.statSync)(t).size,c=null;try{let p=await e.collection("session_files").getFirstListItem(`key='${Rx(n)}'`);c={id:p.id,size:p.size}}catch{}if(c&&c.size===u)return{status:"skipped",key:n,size:u};if(a)return c?U("[DRY-RUN] Would update: %s (%s -> %s)",n,ft(c.size),ft(u)):U("[DRY-RUN] Would upload: %s (%s)",n,ft(u)),{status:c?"updated":"uploaded",key:n,size:u};let l=(0,Ce.readFileSync)(t),d=new File([l],(0,He.basename)(t),{type:"application/x-ndjson"});try{return c?(await e.collection("session_files").update(c.id,{size:u,file:d}),S("Updated: %s (%s -> %s)",n,ft(c.size),ft(u)),{status:"updated",key:n,size:u}):(await e.collection("session_files").create({key:n,machine_id:i,size:u,tenant_id:r,account_id:o,file:d}),S("Uploaded: %s (%s)",n,ft(u)),{status:"uploaded",key:n,size:u})}catch(p){let m=p instanceof Error?p.message:String(p);return{status:"failed",key:n,size:u,error:m}}}function Bx(){let e=new T("sessions").description("Upload and manage Claude Code session transcripts");return e.command("sync").description("Scan local Claude Code sessions and upload new/changed files").option("--machine-id <id>","machine identifier for R2 key namespacing").option("--claude-dir <path>","Claude config directory").option("--dry-run","show what would be uploaded without uploading").option("--cleanup-days <days>","delete local files older than N days after successful upload").action(async t=>{let n=of(t.claudeDir),i=xD(t.machineId),r=t.dryRun??!1,o=t.cleanupDays?Number(t.cleanupDays):0;o&&(Number.isNaN(o)||o<1)&&y("--cleanup-days requires a positive integer");let a=(0,He.join)(n,"projects"),s=af(a);if(s.length===0){U("No session files found in %s",a);return}let{client:u,profile:c}=await z("library"),l=qe(c),d=We(c);o>0&&U("Cleanup mode: syncing files older than %s days",o),U("Scanning %s sessions in %s",s.length,a);let p=0,m=0,b=0,x=0,E=0,N=0;for(let J of s){if(o>0&&!Nx(J,o)){N++;continue}let F=wD(J,a,i),q=await kD(u,J,F,i,l,d,r);switch(q.status){case"uploaded":p++;break;case"updated":m++;break;case"skipped":b++;break;case"failed":U("Failed: %s \u2014 %s",F,q.error),x++;continue}if(o>0)if(r)U("[DRY-RUN] Would delete local: %s",J);else try{(0,Ce.unlinkSync)(J),E++}catch{U("Failed to delete local: %s",J)}}U(""),o>0?U("Summary: %s total, %s too new (<%sd), %s uploaded, %s updated, %s unchanged, %s deleted locally, %s failed",s.length,N,o,p,m,b,E,x):U("Summary: %s total, %s uploaded, %s updated, %s unchanged, %s failed",s.length,p,m,b,x)}),e.command("list").description("List Claude Code session files").option("--remote","list uploaded session files from PocketBase").option("--claude-dir <path>","Claude config directory").action(async t=>{if(t.remote){let{client:n}=await z("library"),i=await C("Fetching session files...",()=>n.collection("session_files").getList(1,200,{sort:"-created"}));_({json:()=>i.items,human:()=>{let r=i.items.map(o=>[o.id,o.key,o.machine_id,ft(o.size),o.created]);Y(["ID","KEY","MACHINE","SIZE","CREATED"],r)}})}else{let n=of(t.claudeDir),i=(0,He.join)(n,"projects"),r=af(i);_({json:()=>r.map(o=>{let a=(0,Ce.statSync)(o);return{path:o,size:a.size,modified:a.mtime}}),human:()=>{let o=r.map(a=>{let s=(0,Ce.statSync)(a);return[(0,He.relative)(i,a),ft(s.size),s.mtime.toISOString().slice(0,19)]});Y(["PATH","SIZE","MODIFIED"],o),U(`
|
|
240
|
-
%s files, %s total`,r.length,ft(r.reduce((a,s)=>a+(0,Ce.statSync)(s).size,0)))}})}}),e.command("upload").description("Upload a single session file").option("--hook","hook mode: read session path from stdin JSON").option("--machine-id <id>","machine identifier for R2 key namespacing").option("--claude-dir <path>","Claude config directory").argument("[file]","path to .jsonl file (when not using --hook)").action(async(t,n)=>{let i=of(n.claudeDir),r=xD(n.machineId),o=(0,He.join)(i,"projects"),a;if(n.hook){let m;try{m=(0,Ce.readFileSync)(0,"utf-8")}catch{y("failed to read from stdin")}let b;try{b=JSON.parse(m)}catch{y("invalid JSON on stdin")}let x=b.transcript_path;x||y("no transcript_path in hook input"),a=x.replace(/^~/,(0,jn.homedir)())}else t?a=t:y("provide a file path or use --hook to read from stdin");try{(0,Ce.statSync)(a)}catch{y("file not found: %s",a)}let s=wD(a,o,r),{client:u,profile:c}=await z("library"),l=qe(c),d=We(c),p=await kD(u,a,s,r,l,d,!1);p.status==="failed"&&y("upload failed: %s",p.error),_({json:()=>p,human:()=>{p.status==="skipped"&&U("Skipped (unchanged): %s",s)}})}),e}function CD(e){e.addCommand(Bx())}var ma=require("node:child_process"),pe=require("node:fs"),SD=require("node:os"),St=require("node:path");function ID(){return!0}var ED="https://registry.npmjs.org",Zx=15e3,FD="@zenku";function Lx(){let{platform:e,arch:t}=process,n=["darwin-arm64","darwin-x64","linux-arm64","linux-x64"],i=`${e}-${t}`;return n.includes(i)||y("Unsupported platform: %s",i),`cli-${i}`}async function Mx(e){let t=`${ED}/${FD}/${e}/latest`,n=new AbortController,i=setTimeout(()=>n.abort(),Zx);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 Vx(e,t){let n=`${e}-${t}.tgz`,i=`${ED}/${FD}/${e}/-/${n}`,r=(0,pe.mkdtempSync)((0,St.join)((0,SD.tmpdir)(),"zenku-upgrade-"));try{(0,ma.execSync)(`curl -fsSL "${i}" -o "${(0,St.join)(r,n)}"`,{stdio:"pipe"}),(0,ma.execSync)(`tar xzf "${(0,St.join)(r,n)}" -C "${r}"`,{stdio:"pipe"});let o=(0,St.join)(r,"package","zenku"),a=process.execPath,s=(0,St.dirname)(a),u=(0,St.join)(s,`.zenku-upgrade-${process.pid}`),c=!1;try{(0,pe.accessSync)(s,pe.constants.W_OK)}catch{c=!0}if(c)(0,ma.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 OD(e){e.addCommand(new T("upgrade").description("Upgrade zenku to the latest version").action(async()=>{if(ID()){_({json:()=>({mode:"bundle",message:"Self-upgrade not available in bundle mode. Use: npm update -g @zenku/cli-node"}),human:()=>{U("Self-upgrade is not available in bundle mode."),U("Update via npm: npm update -g @zenku/cli-node")}});return}let t=sf(),n=Lx(),i=await C("Checking for updates...",()=>Mx(n));if(t===i){_({json:()=>({previous:t,latest:i,upgraded:!1}),human:()=>U("Already up to date (v%s).",t)});return}U("v%s \u2192 v%s",t,i),await C(`Downloading v${i}...`,async()=>{Vx(n,i)}),_({json:()=>({previous:t,latest:i,upgraded:!0}),human:()=>U("Upgraded zenku to v%s.",i)})}))}var qx={};function sf(){return"0.1.
|
|
240
|
+
%s files, %s total`,r.length,ft(r.reduce((a,s)=>a+(0,Ce.statSync)(s).size,0)))}})}}),e.command("upload").description("Upload a single session file").option("--hook","hook mode: read session path from stdin JSON").option("--machine-id <id>","machine identifier for R2 key namespacing").option("--claude-dir <path>","Claude config directory").argument("[file]","path to .jsonl file (when not using --hook)").action(async(t,n)=>{let i=of(n.claudeDir),r=xD(n.machineId),o=(0,He.join)(i,"projects"),a;if(n.hook){let m;try{m=(0,Ce.readFileSync)(0,"utf-8")}catch{y("failed to read from stdin")}let b;try{b=JSON.parse(m)}catch{y("invalid JSON on stdin")}let x=b.transcript_path;x||y("no transcript_path in hook input"),a=x.replace(/^~/,(0,jn.homedir)())}else t?a=t:y("provide a file path or use --hook to read from stdin");try{(0,Ce.statSync)(a)}catch{y("file not found: %s",a)}let s=wD(a,o,r),{client:u,profile:c}=await z("library"),l=qe(c),d=We(c),p=await kD(u,a,s,r,l,d,!1);p.status==="failed"&&y("upload failed: %s",p.error),_({json:()=>p,human:()=>{p.status==="skipped"&&U("Skipped (unchanged): %s",s)}})}),e}function CD(e){e.addCommand(Bx())}var ma=require("node:child_process"),pe=require("node:fs"),SD=require("node:os"),St=require("node:path");function ID(){return!0}var ED="https://registry.npmjs.org",Zx=15e3,FD="@zenku";function Lx(){let{platform:e,arch:t}=process,n=["darwin-arm64","darwin-x64","linux-arm64","linux-x64"],i=`${e}-${t}`;return n.includes(i)||y("Unsupported platform: %s",i),`cli-${i}`}async function Mx(e){let t=`${ED}/${FD}/${e}/latest`,n=new AbortController,i=setTimeout(()=>n.abort(),Zx);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 Vx(e,t){let n=`${e}-${t}.tgz`,i=`${ED}/${FD}/${e}/-/${n}`,r=(0,pe.mkdtempSync)((0,St.join)((0,SD.tmpdir)(),"zenku-upgrade-"));try{(0,ma.execSync)(`curl -fsSL "${i}" -o "${(0,St.join)(r,n)}"`,{stdio:"pipe"}),(0,ma.execSync)(`tar xzf "${(0,St.join)(r,n)}" -C "${r}"`,{stdio:"pipe"});let o=(0,St.join)(r,"package","zenku"),a=process.execPath,s=(0,St.dirname)(a),u=(0,St.join)(s,`.zenku-upgrade-${process.pid}`),c=!1;try{(0,pe.accessSync)(s,pe.constants.W_OK)}catch{c=!0}if(c)(0,ma.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 OD(e){e.addCommand(new T("upgrade").description("Upgrade zenku to the latest version").action(async()=>{if(ID()){_({json:()=>({mode:"bundle",message:"Self-upgrade not available in bundle mode. Use: npm update -g @zenku/cli-node"}),human:()=>{U("Self-upgrade is not available in bundle mode."),U("Update via npm: npm update -g @zenku/cli-node")}});return}let t=sf(),n=Lx(),i=await C("Checking for updates...",()=>Mx(n));if(t===i){_({json:()=>({previous:t,latest:i,upgraded:!1}),human:()=>U("Already up to date (v%s).",t)});return}U("v%s \u2192 v%s",t,i),await C(`Downloading v${i}...`,async()=>{Vx(n,i)}),_({json:()=>({previous:t,latest:i,upgraded:!0}),human:()=>U("Upgraded zenku to v%s.",i)})}))}var qx={};function sf(){return"0.1.26"}function AD(){let e=new T;return e.name("zenku").description("Zenku CLI \u2014 manage PocketBase services from the terminal.").version(sf()).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();Zv(n.profile??""),Iv(n.tenant??""),Sv(n.account??""),wv(!!n.json),n.interactive&&n.nonInteractive&&y("--interactive and --non-interactive cannot be used together"),n.interactive?Zd("interactive"):n.nonInteractive&&Zd("non-interactive")}),e.commandsGroup("Core Commands:"),eD(e),nD(e),oD(e),_D(e),e.commandsGroup("Platform Commands:"),Yv(e),Xv(e),e.commandsGroup("Auth & Config:"),qv(e),Wv(e),Gv(e),Kv(e),e.commandsGroup("Other:"),CD(e),OD(e),e.addHelpCommand(new T("help").argument("[command]")),e}var Wx=AD();Wx.parse();
|