@zibby/cli 0.2.1 → 0.4.0

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 (44) hide show
  1. package/README.md +117 -16
  2. package/dist/bin/zibby.js +3 -3
  3. package/dist/commands/chat-agents.js +1 -1
  4. package/dist/commands/chat.js +62 -62
  5. package/dist/commands/credentials-api.js +1 -1
  6. package/dist/commands/credentials-file.js +1 -1
  7. package/dist/commands/creds.js +1 -1
  8. package/dist/commands/init.js +180 -82
  9. package/dist/commands/memory.js +48 -20
  10. package/dist/commands/run.js +52 -55
  11. package/dist/commands/template.js +9 -0
  12. package/dist/commands/uninstall.js +15 -14
  13. package/dist/commands/workflows/agent-helpers.js +7 -7
  14. package/dist/commands/workflows/generate.js +54 -32
  15. package/dist/commands/workflows/run-local.js +19 -19
  16. package/dist/commands/workflows/run.js +5 -5
  17. package/dist/commands/workflows/start.js +12 -12
  18. package/dist/package.json +2 -2
  19. package/dist/templates/zibby-workflow-claude/agents-md-block.md +65 -5
  20. package/dist/templates/zibby-workflow-claude/claude/agents/zibby-test-author.md +16 -1
  21. package/dist/templates/zibby-workflow-claude/claude/agents/zibby-workflow-builder.md +22 -2
  22. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-add-node.md +1 -1
  23. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-debug.md +1 -1
  24. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-delete.md +1 -1
  25. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-deploy.md +24 -14
  26. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-list.md +2 -2
  27. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-memory-cost.md +39 -0
  28. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-memory-pull.md +47 -0
  29. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-memory-remote-use-hosted.md +61 -0
  30. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-memory-stats.md +38 -0
  31. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-static-ip.md +8 -6
  32. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-tail.md +1 -1
  33. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-test-debug.md +2 -2
  34. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-test-generate.md +1 -1
  35. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-test-run.md +3 -2
  36. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-test-write.md +1 -1
  37. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-trigger.md +10 -6
  38. package/dist/templates/zibby-workflow-claude/cursor/rules/zibby-workflows.mdc +76 -13
  39. package/dist/templates/zibby-workflow-claude/manifest.json +5 -1
  40. package/dist/utils/agent-credentials.js +4 -3
  41. package/dist/utils/apply-memory-sync-config.js +1 -0
  42. package/dist/utils/credentials-loader.js +1 -1
  43. package/dist/utils/hosted-memory-sync.js +1 -0
  44. package/package.json +2 -2
@@ -1 +1 @@
1
- import e from"chalk";function h(o,n=""){return`${String(o).replace(/\/+$/,"")}/agents/credentials${n}`}function b(){let o=new Error("Session expired \u2014 run zibby login");return o.code="AUTH_EXPIRED",o}async function _({apiUrl:o,sessionToken:n}){if(!n)return{credentials:[],by_type:{oauth:[],api:[]},total:0};let r=await fetch(h(o),{headers:{Authorization:`Bearer ${n}`}});if(r.status===401)throw b();if(r.status===404)return{credentials:[],by_type:{oauth:[],api:[]},total:0};if(!r.ok){let i=new Error(`List credentials failed (${r.status})`);throw i.status=r.status,i}return r.json()}async function w({apiUrl:o,sessionToken:n,type:r,token:i,source:s="~/.zibby/credentials.env"}){if(!n)throw new Error("No session token \u2014 run zibby login first");let t=await fetch(h(o),{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify({type:r,token:i,source:s})});if(t.status===401)throw b();if(!t.ok){let c=`Add credential failed (${t.status})`;try{let a=await t.json();a?.error&&(c=`${c}: ${a.error}`)}catch{}let l=new Error(c);throw l.status=t.status,l}return t.json()}async function U({apiUrl:o,sessionToken:n,type:r,index:i}){if(!n)throw new Error("No session token \u2014 run zibby login first");let s=await fetch(h(o,`/${encodeURIComponent(r)}/${encodeURIComponent(i)}`),{method:"DELETE",headers:{Authorization:`Bearer ${n}`}});if(s.status===401)throw b();if(!s.ok){let t=new Error(`Delete credential failed (${s.status})`);throw t.status=s.status,t}return s.json()}async function v({apiUrl:o,sessionToken:n,credentials:r}){let i=0,s=0,t=[];for(let c of r)try{let l=await w({apiUrl:o,sessionToken:n,type:c.type,token:c.token,source:c.source_var||c.source||"local"});l.deduped?s+=1:l.added&&(i+=1)}catch(l){t.push({masked:c.token?`***${c.token.slice(-4)}`:"***",error:l.message})}return{added:i,deduped:s,errors:t}}import C from"node:fs/promises";import x from"node:path";import P from"node:os";var f=x.join(P.homedir(),".zibby","credentials.env"),E={CLAUDE_CODE_OAUTH_TOKEN:"oauth",CLAUDE_CODE_OAUTH_TOKEN_POOL:"oauth",ANTHROPIC_AUTH_TOKEN:"oauth",ANTHROPIC_API_KEY:"api",ANTHROPIC_API_KEY_POOL:"api"};function T(o){if(!o)return[];let n=[],r=new Set,i=String(o).split(/\r?\n/);for(let s of i){let t=s.trim();if(!t||t.startsWith("#"))continue;let c=t.indexOf("=");if(c<1)continue;let l=t.slice(0,c).trim(),a=t.slice(c+1).trim();if((a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),!a)continue;let d=E[l];if(!d)continue;let k=l.endsWith("_POOL")?a.split(",").map(u=>u.trim()).filter(Boolean):[a];for(let u of k)u.length<8||r.has(u)||(r.add(u),n.push({type:d,token:u,source_var:l}))}return n}async function N(o=f){let n;try{n=await C.readFile(o,"utf8")}catch(r){if(r.code==="ENOENT")return[];throw r}return T(n)}async function O({filepath:o,env:n=process.env}={}){let r=await N(o),i=new Set(r.map(t=>t.token)),s=[];for(let[t,c]of Object.entries(E)){let l=n[t];if(!l)continue;let a=t.endsWith("_POOL")?l.split(",").map(d=>d.trim()).filter(Boolean):[l];for(let d of a)d.length<8||i.has(d)||(i.add(d),s.push({type:c,token:d,source_var:t,source:"process.env"}))}return{file:r.map(t=>({...t,source:"file"})),env:s,all:[...r.map(t=>({...t,source:"file"})),...s]}}var p={local:{name:"Local Development",apiUrl:"http://localhost:3001",accountApiUrl:"http://localhost:3001",frontendUrl:"http://localhost:3000",description:"Local backend running on port 3001"},prod:{name:"Production",apiUrl:process.env.ZIBBY_PROD_API_URL||"https://api-prod.zibby.app",accountApiUrl:process.env.ZIBBY_PROD_ACCOUNT_API_URL||"https://account-api-prod.zibby.app",frontendUrl:process.env.ZIBBY_PROD_FRONTEND_URL||"https://studio.zibby.dev",description:"Production environment"}};function g(){let o;if(process.env.ZIBBY_API_URL)o=process.env.ZIBBY_API_URL;else{let n=process.env.ZIBBY_ENV||"prod";p[n]?o=p[n].apiUrl:o=p.prod.apiUrl}try{let n=new URL(o);return n.protocol!=="http:"&&n.protocol!=="https:"?(console.error(`\u26A0\uFE0F Invalid API URL protocol: ${n.protocol} (only http/https allowed)`),p.prod.apiUrl):o}catch{return console.error(`\u26A0\uFE0F Invalid API URL: ${o}`),p.prod.apiUrl}}import{existsSync as $,mkdirSync as G,readFileSync as L,writeFileSync as J}from"fs";import{homedir as A}from"os";import{join as y}from"path";function R(){return process.env.ZIBBY_CONFIG_DIR||y(A(),".zibby")}function B(){return y(R(),"config.json")}var z=y(A(),".zibby"),Q=y(z,"config.json");function D(){try{let o=B();if($(o)){let n=L(o,"utf-8");return JSON.parse(n)}}catch{}return{}}function I(){return D().sessionToken||null}function m(){let o=I();return o||(console.log(e.red("Not logged in. Run `zibby login` first.")),process.exit(1)),o}async function S(){let o=m(),n=g();console.log(""),console.log(e.cyan(" Stored credentials in your Zibby workspace")),console.log(e.gray(` Source file: ${f}`)),console.log("");let r;try{r=await _({apiUrl:n,sessionToken:o})}catch(s){console.log(e.red(` Failed: ${s.message}`)),process.exit(1)}let{by_type:i}=r;for(let s of["oauth","api"]){let t=i[s]||[];if(console.log(e.bold(` ${s} pool (${t.length} ${t.length===1?"token":"tokens"}):`)),t.length===0)console.log(e.gray(" (none)"));else for(let c of t){let l=c.uploaded_at?new Date(c.uploaded_at).toISOString().slice(0,10):"?",a=c.uploaded_by||"?";console.log(` [${c.index}] ${e.cyan(c.masked)} `+e.gray(`uploaded ${l} by ${a} source: ${c.source||"unknown"}`))}console.log("")}r.total===0&&(console.log(e.gray(" No credentials yet. Put any of these in ~/.zibby/credentials.env:")),console.log(e.gray(" CLAUDE_CODE_OAUTH_TOKEN=<your-token> # subscription billing")),console.log(e.gray(" CLAUDE_CODE_OAUTH_TOKEN_POOL=tok_a,tok_b,tok_c # multiple subs")),console.log(e.gray(" ANTHROPIC_API_KEY=<your-key> # API per-token billing")),console.log(e.gray(" Then run `zibby creds sync` to upload.")),console.log("")),console.log(e.gray(" Same file, same credentials, used by every zibby command:")),console.log(e.gray(" zibby test (test automation)")),console.log(e.gray(" zibby chat (interactive chat + cloud Claude Code sandbox)")),console.log(e.gray(" zibby workflow run (local execution)")),console.log(e.gray(" zibby workflow start (local dev server)")),console.log("")}async function F(){let o=m(),n=g();console.log(""),console.log(e.cyan(" Scanning your local credentials file...")),console.log(e.gray(` ${f}`));let r=await O(),i=r.all.length;if(i===0){console.log(""),console.log(e.yellow(" No credentials found.")),console.log(""),console.log(e.white(" Put one or more credentials in ~/.zibby/credentials.env:")),console.log(e.gray(" CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-... # subscription")),console.log(e.gray(" CLAUDE_CODE_OAUTH_TOKEN_POOL=tok1,tok2,tok3 # subscription pool")),console.log(e.gray(" ANTHROPIC_API_KEY=sk-ant-api03-... # API per-token")),console.log(""),console.log(e.gray(" Or export the same vars in your shell \u2014 Zibby reads both.")),console.log("");return}console.log(e.green(` \u2713 Found ${i} ${i===1?"credential":"credentials"}:`));for(let t of r.all)console.log(e.gray(` ${t.type} ***${t.token.slice(-4)} source: ${t.source_var} (${t.source})`));console.log(""),console.log(e.cyan(" Uploading to Zibby (KMS-encrypted)..."));let s=await v({apiUrl:n,sessionToken:o,credentials:r.all});if(console.log(""),console.log(e.green(` \u2713 ${s.added} new, ${s.deduped} already present`)),s.errors.length>0){console.log(e.red(` \u2717 ${s.errors.length} failed:`));for(let t of s.errors)console.log(e.red(` ${t.masked}: ${t.error}`))}console.log("")}async function Y(o,n){let r=m(),i=g();(!o||!n)&&(console.log(e.red("Usage: zibby creds remove <type> <index>")),console.log(e.gray(" e.g. zibby creds remove oauth 0")),process.exit(1)),console.log(""),console.log(e.cyan(` Removing ${o} credential at index ${n}...`));try{await U({apiUrl:i,sessionToken:r,type:o,index:n})}catch(s){console.log(e.red(` Failed: ${s.message}`)),process.exit(1)}console.log(e.green(" \u2713 Removed.")),console.log(""),console.log(e.gray(" Note: this only deletes Zibby's encrypted copy. To revoke")),console.log(e.gray(" the actual token, do that on the upstream provider where")),console.log(e.gray(" it was issued.")),console.log("")}async function co(o,...n){switch(o){case"list":return S();case"sync":return F();case"remove":return Y(n[0],n[1]);default:console.log(e.red(`Unknown subcommand: ${o}`)),console.log(e.gray(" zibby creds list")),console.log(e.gray(" zibby creds sync")),console.log(e.gray(" zibby creds remove <type> <index>")),process.exit(1)}}export{co as credsCmd,S as listCmd,Y as removeCmd,F as syncCmd};
1
+ import t from"chalk";function y(o,e=""){return`${String(o).replace(/\/+$/,"")}/agents/credentials${e}`}function h(){let o=new Error("Session expired \u2014 run zibby login");return o.code="AUTH_EXPIRED",o}async function m({apiUrl:o,sessionToken:e}){if(!e)return{credentials:[],by_type:{oauth:[],api:[]},total:0};let r=await fetch(y(o),{headers:{Authorization:`Bearer ${e}`}});if(r.status===401)throw h();if(r.status===404)return{credentials:[],by_type:{oauth:[],api:[]},total:0};if(!r.ok){let c=new Error(`List credentials failed (${r.status})`);throw c.status=r.status,c}return r.json()}async function O({apiUrl:o,sessionToken:e,type:r,token:c,source:s="~/.zibby/config.json"}){if(!e)throw new Error("No session token \u2014 run zibby login first");let n=await fetch(y(o),{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify({type:r,token:c,source:s})});if(n.status===401)throw h();if(!n.ok){let i=`Add credential failed (${n.status})`;try{let d=await n.json();d?.error&&(i=`${i}: ${d.error}`)}catch{}let l=new Error(i);throw l.status=n.status,l}return n.json()}async function _({apiUrl:o,sessionToken:e,type:r,index:c}){if(!e)throw new Error("No session token \u2014 run zibby login first");let s=await fetch(y(o,`/${encodeURIComponent(r)}/${encodeURIComponent(c)}`),{method:"DELETE",headers:{Authorization:`Bearer ${e}`}});if(s.status===401)throw h();if(!s.ok){let n=new Error(`Delete credential failed (${s.status})`);throw n.status=s.status,n}return s.json()}async function U({apiUrl:o,sessionToken:e,credentials:r}){let c=0,s=0,n=[];for(let i of r)try{let l=await O({apiUrl:o,sessionToken:e,type:i.type,token:i.token,source:i.source_var||i.source||"local"});l.deduped?s+=1:l.added&&(c+=1)}catch(l){n.push({masked:i.token?`***${i.token.slice(-4)}`:"***",error:l.message})}return{added:c,deduped:s,errors:n}}import $ from"node:fs/promises";import C from"node:path";import A from"node:os";var p=C.join(A.homedir(),".zibby","config.json"),v={CLAUDE_CODE_OAUTH_TOKEN:"oauth",CLAUDE_CODE_OAUTH_TOKEN_POOL:"oauth",ANTHROPIC_AUTH_TOKEN:"oauth",ANTHROPIC_API_KEY:"api",ANTHROPIC_API_KEY_POOL:"api"};function k(o){if(!o)return[];let e;try{e=JSON.parse(o)}catch{return[]}let r=e?.agentKeys;if(!r||typeof r!="object")return[];let c=[],s=new Set;for(let[n,i]of Object.entries(v)){let l=r[n];if(!l||typeof l!="string")continue;let d=n.endsWith("_POOL")?l.split(",").map(a=>a.trim()).filter(Boolean):[l.trim()];for(let a of d)a.length<8||s.has(a)||(s.add(a),c.push({type:i,token:a,source_var:n}))}return c}async function N(o=p){let e;try{e=await $.readFile(o,"utf8")}catch(r){if(r.code==="ENOENT")return[];throw r}return k(e)}async function w({filepath:o,env:e=process.env}={}){let r=await N(o),c=new Set(r.map(n=>n.token)),s=[];for(let[n,i]of Object.entries(v)){let l=e[n];if(!l)continue;let d=n.endsWith("_POOL")?l.split(",").map(a=>a.trim()).filter(Boolean):[l];for(let a of d)a.length<8||c.has(a)||(c.add(a),s.push({type:i,token:a,source_var:n,source:"process.env"}))}return{config:r.map(n=>({...n,source:"config.json"})),env:s,all:[...r.map(n=>({...n,source:"config.json"})),...s]}}var u={local:{name:"Local Development",apiUrl:"http://localhost:3001",accountApiUrl:"http://localhost:3001",frontendUrl:"http://localhost:3000",description:"Local backend running on port 3001"},prod:{name:"Production",apiUrl:process.env.ZIBBY_PROD_API_URL||"https://api-prod.zibby.app",accountApiUrl:process.env.ZIBBY_PROD_ACCOUNT_API_URL||"https://account-api-prod.zibby.app",frontendUrl:process.env.ZIBBY_PROD_FRONTEND_URL||"https://studio.zibby.dev",description:"Production environment"}};function f(){let o;if(process.env.ZIBBY_API_URL)o=process.env.ZIBBY_API_URL;else{let e=process.env.ZIBBY_ENV||"prod";u[e]?o=u[e].apiUrl:o=u.prod.apiUrl}try{let e=new URL(o);return e.protocol!=="http:"&&e.protocol!=="https:"?(console.error(`\u26A0\uFE0F Invalid API URL protocol: ${e.protocol} (only http/https allowed)`),u.prod.apiUrl):o}catch{return console.error(`\u26A0\uFE0F Invalid API URL: ${o}`),u.prod.apiUrl}}import{existsSync as E,mkdirSync as G,readFileSync as P,writeFileSync as J}from"fs";import{homedir as x}from"os";import{join as g}from"path";function R(){return process.env.ZIBBY_CONFIG_DIR||g(x(),".zibby")}function T(){return g(R(),"config.json")}var B=g(x(),".zibby"),X=g(B,"config.json");function z(){try{let o=T();if(E(o)){let e=P(o,"utf-8");return JSON.parse(e)}}catch{}return{}}function I(){return z().sessionToken||null}function b(){let o=I();return o||(console.log(t.red("Not logged in. Run `zibby login` first.")),process.exit(1)),o}async function L(){let o=b(),e=f();console.log(""),console.log(t.cyan(" Stored credentials in your Zibby workspace")),console.log(t.gray(` Source file: ${p}`)),console.log("");let r;try{r=await m({apiUrl:e,sessionToken:o})}catch(s){console.log(t.red(` Failed: ${s.message}`)),process.exit(1)}let{by_type:c}=r;for(let s of["oauth","api"]){let n=c[s]||[];if(console.log(t.bold(` ${s} pool (${n.length} ${n.length===1?"token":"tokens"}):`)),n.length===0)console.log(t.gray(" (none)"));else for(let i of n){let l=i.uploaded_at?new Date(i.uploaded_at).toISOString().slice(0,10):"?",d=i.uploaded_by||"?";console.log(` [${i.index}] ${t.cyan(i.masked)} `+t.gray(`uploaded ${l} by ${d} source: ${i.source||"unknown"}`))}console.log("")}r.total===0&&(console.log(t.gray(" No credentials yet. Run `zibby init` to set them up \u2014 Claude has")),console.log(t.gray(" both OAuth subscription and API key options. Then re-run sync.")),console.log("")),console.log(t.gray(" Same file, same credentials, used by every zibby command:")),console.log(t.gray(" zibby test (test automation)")),console.log(t.gray(" zibby chat (interactive chat + cloud Claude Code sandbox)")),console.log(t.gray(" zibby workflow run (local execution)")),console.log(t.gray(" zibby workflow start (local dev server)")),console.log("")}async function S(){let o=b(),e=f();console.log(""),console.log(t.cyan(" Scanning your local credentials...")),console.log(t.gray(` ${p}`));let r=await w(),c=r.all.length;if(c===0){console.log(""),console.log(t.yellow(" No credentials found in ~/.zibby/config.json.")),console.log(""),console.log(t.white(" Run `zibby init` first to choose API key or OAuth subscription.")),console.log(t.gray(" Or export tokens in your shell \u2014 Zibby reads process.env too.")),console.log("");return}console.log(t.green(` \u2713 Found ${c} ${c===1?"credential":"credentials"}:`));for(let n of r.all)console.log(t.gray(` ${n.type} ***${n.token.slice(-4)} source: ${n.source_var} (${n.source})`));console.log(""),console.log(t.cyan(" Uploading to Zibby (KMS-encrypted)..."));let s=await U({apiUrl:e,sessionToken:o,credentials:r.all});if(console.log(""),console.log(t.green(` \u2713 ${s.added} new, ${s.deduped} already present`)),s.errors.length>0){console.log(t.red(` \u2717 ${s.errors.length} failed:`));for(let n of s.errors)console.log(t.red(` ${n.masked}: ${n.error}`))}console.log("")}async function D(o,e){let r=b(),c=f();(!o||!e)&&(console.log(t.red("Usage: zibby creds remove <type> <index>")),console.log(t.gray(" e.g. zibby creds remove oauth 0")),process.exit(1)),console.log(""),console.log(t.cyan(` Removing ${o} credential at index ${e}...`));try{await _({apiUrl:c,sessionToken:r,type:o,index:e})}catch(s){console.log(t.red(` Failed: ${s.message}`)),process.exit(1)}console.log(t.green(" \u2713 Removed.")),console.log(""),console.log(t.gray(" Note: this only deletes Zibby's encrypted copy. To revoke")),console.log(t.gray(" the actual token, do that on the upstream provider where")),console.log(t.gray(" it was issued.")),console.log("")}async function ro(o,...e){switch(o){case"list":return L();case"sync":return S();case"remove":return D(e[0],e[1]);default:console.log(t.red(`Unknown subcommand: ${o}`)),console.log(t.gray(" zibby creds list")),console.log(t.gray(" zibby creds sync")),console.log(t.gray(" zibby creds remove <type> <index>")),process.exit(1)}}export{ro as credsCmd,L as listCmd,D as removeCmd,S as syncCmd};