@zibby/cli 0.6.0 → 0.7.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.
- package/dist/bin/zibby.js +3 -3
- package/dist/commands/app-auth.js +17 -0
- package/dist/commands/app.js +1 -1
- package/dist/commands/init.js +125 -117
- package/dist/commands/mcp.js +3 -3
- package/dist/commands/workflows/generate.js +143 -135
- package/dist/commands/workflows/webhook.js +28 -0
- package/dist/package.json +2 -1
- package/package.json +2 -1
package/dist/commands/mcp.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import p from"node:fs";import l from"node:path";import $ from"node:os";import n from"chalk";import{existsSync as x,mkdirSync as
|
|
1
|
+
import p from"node:fs";import l from"node:path";import $ from"node:os";import n from"chalk";import{existsSync as x,mkdirSync as j,readFileSync as A,writeFileSync as O}from"fs";import{homedir as h}from"os";import{join as f}from"path";function P(){return process.env.ZIBBY_CONFIG_DIR||f(h(),".zibby")}function B(){return f(P(),"config.json")}var k=f(h(),".zibby"),F=f(k,"config.json");function N(){try{let o=B();if(x(o)){let e=A(o,"utf-8");return JSON.parse(e)}}catch{}return{}}function _(){return N().sessionToken||null}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://api-prod.zibby.app",frontendUrl:process.env.ZIBBY_PROD_FRONTEND_URL||"https://studio.zibby.dev",description:"Production environment"}};function v(){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}}var I=v,m=["claude-code","claude-desktop","cursor","codex","gemini"],C={claude:"claude-code","claude-desktop-app":"claude-desktop"},g={"claude-code":"Claude Code","claude-desktop":"Claude Desktop",cursor:"Cursor",codex:"Codex CLI",gemini:"Gemini CLI"};function w(o){let e=$.homedir();switch(o){case"claude-code":return l.join(e,".claude","settings.json");case"cursor":return l.join(e,".cursor","mcp.json");case"codex":return l.join(e,".codex","config.toml");case"gemini":return l.join(e,".gemini","settings.json");case"claude-desktop":return process.platform==="darwin"?l.join(e,"Library","Application Support","Claude","claude_desktop_config.json"):process.platform==="win32"?l.join(process.env.APPDATA||e,"Claude","claude_desktop_config.json"):l.join(e,".config","Claude","claude_desktop_config.json");default:return null}}async function T(o,e){let s=I(),r=await fetch(`${s}/api/user/tokens`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify({name:e})});if(!r.ok){let t=await r.text().catch(()=>"");throw new Error(`Could not mint PAT (HTTP ${r.status}): ${t.slice(0,200)}`)}let c=await r.json();if(!c?.token)throw new Error("PAT response missing token field");return c.token}function z(o){try{let e=p.readFileSync(o,"utf8");return e.trim()?JSON.parse(e):{}}catch(e){if(e.code==="ENOENT")return{};throw new Error(`Could not parse existing config ${o}: ${e.message}`)}}function U(o,e){p.mkdirSync(l.dirname(o),{recursive:!0});let s=`${o}.zibby-mcp-${Date.now()}.tmp`;p.writeFileSync(s,e,{mode:384}),p.renameSync(s,o)}function S({existing:o,apiUrl:e,pat:s,agent:r}){let c={...o};c.mcpServers={...o.mcpServers||{}};let t=r==="gemini"?"httpUrl":"url";return c.mcpServers.zibby={[t]:`${e}/mcp`,headers:{Authorization:`Bearer ${s}`}},c}function E({existing:o,apiUrl:e,patEnvName:s}){let r=["","[mcp_servers.zibby]",`url = "${e}/mcp"`,`bearer_token_env_var = "${s}"`,""].join(`
|
|
2
2
|
`);if(!o.trim())return r.trimStart();let c=/(^|\n)\[mcp_servers\.zibby\][\s\S]*?(?=\n\[[^\]]+\]|\n*$)/;return c.test(o)?o.replace(c,`
|
|
3
3
|
${r.trim()}
|
|
4
4
|
`):o.replace(/\s*$/,"")+`
|
|
5
|
-
`+r}async function R({agent:o,sessionToken:e,explicitPat:s,apiUrl:r,force:c}){let t=
|
|
6
|
-
`),console.log(n.green(" \u2713 wrote")+n.gray(" "+l.basename(t)))}return{installed:!0,configFile:t}}async function
|
|
5
|
+
`+r}async function R({agent:o,sessionToken:e,explicitPat:s,apiUrl:r,force:c}){let t=w(o);if(!t)return console.log(n.yellow(` skip ${g[o]} \u2014 not supported on this platform`)),{skipped:!0};let d=`MCP \u2013 ${g[o]}`;console.log(n.gray(` \u2192 ${g[o]}`)),console.log(n.gray(` config: ${t}`));let i;if(s?(i=s,console.log(n.gray(` using supplied PAT: ${i.slice(0,18)}...`))):(i=await T(e,d),console.log(n.gray(` minted PAT: ${i.slice(0,18)}...`))),o==="codex"){let a=p.existsSync(t)?p.readFileSync(t,"utf8"):"",b=E({existing:a,apiUrl:r,patEnvName:"ZIBBY_PAT"});if(!c&&a===b)return console.log(n.gray(" no change needed")),{unchanged:!0};U(t,b),console.log(n.green(" \u2713 wrote")+n.gray(" "+l.basename(t))),console.log(n.yellow(" add to your shell rc:")),console.log(n.cyan(` export ZIBBY_PAT=${i}`))}else{let a=z(t),y=S({existing:a,apiUrl:r,pat:i,agent:o});U(t,JSON.stringify(y,null,2)+`
|
|
6
|
+
`),console.log(n.green(" \u2713 wrote")+n.gray(" "+l.basename(t)))}return{installed:!0,configFile:t}}async function q(o={}){let e=o.token||process.env.ZIBBY_PAT||null,s=e?null:_();!e&&!s&&(console.error(n.red("No Zibby auth available.")),console.error(""),console.error(n.gray("Pick one:")),console.error(" zibby login # interactive OAuth, stores session"),console.error(" zibby mcp install --token zby_pat_\u2026 --all # one-shot, no login"),console.error(" ZIBBY_PAT=zby_pat_\u2026 zibby mcp install --all # CI / scripted"),process.exit(1)),e&&!/^zby_pat_/.test(e)&&(console.error(n.red("--token / ZIBBY_PAT must be a Personal Access Token (starts with zby_pat_).")),process.exit(1));let r;if(o.all)r=[...m];else if(o.agent){let i=C[o.agent]||o.agent;m.includes(i)||(console.error(n.red(`Unknown agent: ${o.agent}`)),console.error(n.gray(`Known: ${m.join(", ")}`)),process.exit(1)),r=[i]}else console.error(n.red("Pass --agent <name> or --all.")),console.error(""),console.error(n.gray("Examples:")),console.error(" zibby mcp install --agent claude-code"),console.error(" zibby mcp install --agent cursor"),console.error(" zibby mcp install --agent codex"),console.error(" zibby mcp install --agent gemini"),console.error(" zibby mcp install --all"),process.exit(1);let c=I();console.log(n.bold(`Installing Zibby Remote MCP into ${r.length} agent${r.length===1?"":"s"}\u2026`)),console.log(n.gray(`API: ${c}/mcp`)),console.log("");let t=[],d=0;for(let i of r){try{(await R({agent:i,sessionToken:s,explicitPat:e,apiUrl:c,force:o.force})).installed&&t.push(i)}catch(a){console.error(n.red(` \u2717 ${g[i]} failed: ${a.message}`)),d++}console.log("")}t.length&&(console.log(n.bold.green(`\u2713 Installed for ${t.length} agent${t.length===1?"":"s"}.`)),console.log(""),console.log(n.bold("Next step:")+" restart the agent so it picks up the new MCP server."),console.log(""),console.log(n.gray("Revoke / list your MCP tokens anytime at https://zibby.dev/settings/tokens"))),d&&process.exit(1)}export{q as mcpInstallCommand};
|