@zibby/cli 0.2.0 → 0.3.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 (34) hide show
  1. package/README.md +2 -2
  2. package/dist/auth/cli-login.js +7 -7
  3. package/dist/auth/ensure-auth.js +6 -6
  4. package/dist/bin/zibby.js +3 -3
  5. package/dist/commands/chat-agents.js +1 -0
  6. package/dist/commands/chat-sandbox-attach.js +5 -0
  7. package/dist/commands/chat.js +79 -69
  8. package/dist/commands/credentials-api.js +1 -0
  9. package/dist/commands/credentials-file.js +1 -0
  10. package/dist/commands/creds.js +1 -0
  11. package/dist/commands/init.js +83 -75
  12. package/dist/commands/list-projects.js +5 -5
  13. package/dist/commands/memory.js +28 -18
  14. package/dist/commands/project.js +3 -3
  15. package/dist/commands/run.js +52 -55
  16. package/dist/commands/studio.js +1 -1
  17. package/dist/commands/template.js +9 -0
  18. package/dist/commands/upload.js +4 -4
  19. package/dist/commands/workflow.js +23 -23
  20. package/dist/commands/workflows/dedicated-egress.js +6 -6
  21. package/dist/commands/workflows/delete.js +4 -4
  22. package/dist/commands/workflows/deploy.js +19 -19
  23. package/dist/commands/workflows/env.js +7 -7
  24. package/dist/commands/workflows/generate.js +13 -13
  25. package/dist/commands/workflows/list.js +6 -6
  26. package/dist/commands/workflows/run-local.js +15 -15
  27. package/dist/commands/workflows/start.js +16 -16
  28. package/dist/commands/workflows/trigger.js +7 -7
  29. package/dist/config/environments.js +1 -1
  30. package/dist/package.json +4 -4
  31. package/dist/templates/zibby-workflow-claude/claude/commands/zibby-static-ip.md +1 -1
  32. package/dist/utils/agent-credentials.js +4 -3
  33. package/dist/utils/credentials-loader.js +1 -0
  34. package/package.json +4 -4
@@ -1,77 +1,85 @@
1
- var me=Object.defineProperty;var ge=(t,e)=>()=>(t&&(e=t(t=0)),e);var fe=(t,e)=>{for(var a in e)me(t,a,{get:e[a],enumerable:!0})};var le={};fe(le,{setupCiCommand:()=>$e,setupPlaywrightMcpCommand:()=>ae,testWithVideoCommand:()=>Ke});import{spawn as H,execSync as F}from"child_process";import{join as K,dirname as W,resolve as te}from"path";import{readFileSync as ne,writeFileSync as oe,existsSync as T,mkdirSync as se}from"fs";import{homedir as ie}from"os";import{createRequire as ve}from"module";import x from"chalk";function xe(){try{return W(G.resolve("@zibby/core/package.json"))}catch{return null}}function re(t){try{return F(`command -v ${t}`,{stdio:"pipe"}),!0}catch{return!1}}function Pe(){try{let t=G.resolve("@zibby/mcp-browser/bin/mcp-browser-zibby.js");if(T(t))return t}catch{}try{let t=G.resolve("@playwright/mcp/package.json"),e=W(t),a=JSON.parse(ne(t,"utf-8")),l=typeof a.bin=="string"?a.bin:a.bin?.["playwright-mcp"];if(l){let m=K(e,l);if(T(m))return m}let n=K(e,"cli.js");if(T(n))return n}catch{}return null}function Q(t,e,a={}){return new Promise((l,n)=>{let m=H(t,e,{stdio:"inherit",...a});m.on("close",y=>l(y??1)),m.on("error",n)})}async function Ce(t){return re("playwright")?await Q("playwright",["install","ffmpeg"],{cwd:t})===0:await Q("npx",["--yes","playwright","install","ffmpeg"],{cwd:t})===0}function Ae({headed:t=!1,viewport:e=null}){let a=process.execPath,l=W(a),n=Pe(),m=Number(e?.width)||1280,y=Number(e?.height)||720,r=`${m}x${y}`,w=[];w.push(`--viewport-size=${r}`,"--output-dir=test-results"),t||w.push("--headless");let g;n?g={command:a,args:[n,...w],env:{PATH:`${l}:/usr/bin:/bin:/usr/sbin:/sbin`}}:g={command:"npx",args:["-y","@playwright/mcp",...w],env:{PATH:`${l}:/usr/bin:/bin:/usr/sbin:/sbin`}},g.description="Zibby MCP Browser - Playwright MCP with Zibby defaults";let C=K(ie(),".cursor"),f=K(C,"mcp.json");T(C)||se(C,{recursive:!0});let v={mcpServers:{}};if(T(f))try{v=JSON.parse(ne(f,"utf-8")),(!v.mcpServers||typeof v.mcpServers!="object")&&(v.mcpServers={})}catch{v={mcpServers:{}}}v.mcpServers["playwright-official"]=g,oe(f,`${JSON.stringify(v,null,2)}
2
- `,"utf-8")}async function Ie(){let t=xe();if(!t)return;let e=K(t,"scripts","patch-cursor-mcp.js");if(T(e))try{await new Promise((a,l)=>{let n=H(process.execPath,[e],{cwd:process.cwd(),stdio:"ignore"});n.on("close",m=>a(m??0)),n.on("error",l)})}catch{}}function Ee(t){return te(t).replace(/^\/+/,"").replace(/\//g,"-")}function ke(t){let e=String(t||""),a=e.split(`
3
- `).find(m=>/playwright-official/i.test(m)&&/APPROVAL|🔑/i.test(m));if(a){let m=a.match(/=>\s*(\S+)/);if(m)return m[1]}let l=e.match(/playwright-official[^=]*=>\s*(\S+)/);if(l)return l[1];let n=e.match(/playwright-official-[a-f0-9]+/i);return n?n[0]:null}function Se(t,e){let a=Ee(t),l=K(ie(),".cursor","projects",a);se(l,{recursive:!0});let n=K(l,"mcp-approvals.json");return oe(n,`${JSON.stringify([e],null,2)}
4
- `,"utf-8"),n}function ee(t){try{return F("cursor-agent mcp list",{cwd:t,encoding:"utf-8",stdio:["ignore","pipe","pipe"],env:process.env,maxBuffer:2*1024*1024})}catch(e){let a=e.stdout!=null?String(e.stdout):"",l=e.stderr!=null?String(e.stderr):"";return a+l}}function _e(t){try{return F("cursor-agent mcp enable playwright-official",{cwd:t,encoding:"utf-8",stdio:["ignore","pipe","pipe"],env:process.env,maxBuffer:1024*1024}),!0}catch{return!1}}async function ae(t={}){let e=!!t.headed,a=t.viewport||{width:1280,height:720};if(!process.execPath)throw new Error("Node.js runtime not found");let l=await Ce(process.cwd());console.log(l?x.gray(" \u2713 ffmpeg installed for Playwright video"):x.yellow(" \u26A0 Could not install ffmpeg (video may be unavailable)")),Ae({headed:e,viewport:a}),await Ie();let n=te(process.cwd());if(re("cursor-agent")){ee(n);let m=_e(n);m&&console.log(x.gray(" \u2713 cursor-agent: mcp enable playwright-official"));let y=ee(n),r=ke(y);if(r)try{let w=Se(n,r);console.log(x.gray(` \u2713 MCP auto-approval key saved (${w})`))}catch(w){console.log(x.yellow(` \u26A0 Could not write mcp-approvals.json: ${w.message}`))}else m||(console.log(x.yellow(" \u26A0 Could not auto-approve MCP (mcp enable failed and no approval key in cursor-agent output)")),console.log(x.gray(" Try: cursor-agent mcp enable playwright-official")))}else console.log(x.yellow(" \u26A0 cursor-agent not found; install it to use Cursor MCP tools"))}async function $e(t){try{console.log(x.cyan(`
1
+ var Ae=Object.defineProperty;var J=(t,e)=>()=>(t&&(e=t(t=0)),e);var X=(t,e)=>{for(var s in e)Ae(t,s,{get:e[s],enumerable:!0})};var ie={};X(ie,{templateAddCommand:()=>_e,templateListCommand:()=>Ee,writeTemplateFiles:()=>se});import{mkdir as ne,writeFile as B,readFile as Y}from"fs/promises";import{existsSync as F,readdirSync as Ie}from"fs";import{join as E}from"path";import v from"chalk";async function se(t,e,s={}){let a=s.enableMemory!==!1,{TemplateFactory:o}=await import("@zibby/core/templates"),{graphPath:d,nodesPath:y,readmePath:i,resultHandlerPath:h,template:f}=o.getTemplateFiles(e),w=E(t,".zibby");F(w)||await ne(w,{recursive:!0});let m=[];await B(E(w,"graph.mjs"),await Y(d,"utf-8")),m.push("graph.mjs"),h&&(await B(E(w,"result-handler.mjs"),await Y(h,"utf-8")),m.push("result-handler.mjs")),await B(E(w,"README.md"),await Y(i,"utf-8")),m.push("README.md");let A=E(w,"nodes");await ne(A,{recursive:!0});for(let b of Ie(y)){let r=await Y(E(y,b),"utf-8");!a&&b==="execute-live.mjs"&&(r=r.replace("skills: [SKILLS.BROWSER, SKILLS.MEMORY],","skills: [SKILLS.BROWSER],")),await B(E(A,b),r),m.push(`nodes/${b}`)}let k=E(f.path,"chat.mjs");return F(k)&&(await B(E(w,"chat.mjs"),await Y(k,"utf-8")),m.push("chat.mjs")),{template:f,copied:m}}async function Ee(){let{TemplateFactory:t}=await import("@zibby/core/templates"),e=t.listTemplates();console.log(""),console.log(v.bold.cyan(" Available templates")),console.log("");for(let s of e){let a=s.default?v.gray(" (default)"):"";if(console.log(` ${v.cyan(s.name)}${a}`),console.log(` ${v.white(s.displayName)}`),s.description&&console.log(` ${v.gray(s.description)}`),s.features&&s.features.length)for(let o of s.features)console.log(v.gray(` \u2022 ${o}`));console.log("")}console.log(v.gray(" Use: zibby template add <name> (or pass -t <name> to zibby init)")),console.log("")}async function _e(t,e={}){t||(console.log(v.red(`
2
+ Missing template name.
3
+ `)),console.log(v.gray(" Usage: zibby template add <name>")),console.log(v.gray(` See available templates: zibby template list
4
+ `)),process.exit(1));let s=e.cwd||process.cwd(),a=E(s,".zibby");F(a)||(console.log(v.yellow(`
5
+ No .zibby/ directory in ${s}.
6
+ `)),console.log(v.gray(" Run `zibby init` first to bootstrap the project.\n")),process.exit(1));let o;try{o=await se(s,t,{enableMemory:e.enableMemory!==!1})}catch(d){console.log(v.red(`
7
+ ${d.message}
8
+ `)),console.log(v.gray(` See available templates: zibby template list
9
+ `)),process.exit(1)}console.log(""),console.log(v.green(` \u2713 Added template ${v.bold(o.template.name)}`)),console.log(v.gray(` ${o.copied.length} files written to ${a}/`));for(let d of o.copied)console.log(v.gray(` \u2022 ${d}`));console.log(""),console.log(v.gray(" Re-running `zibby template add <name>` overwrites existing files \u2014")),console.log(v.gray(" use this to refresh after `npm update @zibby/core`.")),console.log("")}var re=J(()=>{});var fe={};X(fe,{setupCiCommand:()=>je,setupPlaywrightMcpCommand:()=>ye,testWithVideoCommand:()=>Ne});import{spawn as U,execSync as W}from"child_process";import{join as $,dirname as q,resolve as ce}from"path";import{readFileSync as pe,writeFileSync as de,existsSync as K,mkdirSync as ue}from"fs";import{homedir as ge}from"os";import{createRequire as Se}from"module";import P from"chalk";function $e(){try{return q(V.resolve("@zibby/core/package.json"))}catch{return null}}function me(t){try{return W(`command -v ${t}`,{stdio:"pipe"}),!0}catch{return!1}}function Oe(){try{let t=V.resolve("@zibby/mcp-browser/bin/mcp-browser-zibby.js");if(K(t))return t}catch{}try{let t=V.resolve("@playwright/mcp/package.json"),e=q(t),s=JSON.parse(pe(t,"utf-8")),a=typeof s.bin=="string"?s.bin:s.bin?.["playwright-mcp"];if(a){let d=$(e,a);if(K(d))return d}let o=$(e,"cli.js");if(K(o))return o}catch{}return null}function ae(t,e,s={}){return new Promise((a,o)=>{let d=U(t,e,{stdio:"inherit",...s});d.on("close",y=>a(y??1)),d.on("error",o)})}async function Ke(t){return me("playwright")?await ae("playwright",["install","ffmpeg"],{cwd:t})===0:await ae("npx",["--yes","playwright","install","ffmpeg"],{cwd:t})===0}function Te({headed:t=!1,viewport:e=null}){let s=process.execPath,a=q(s),o=Oe(),d=Number(e?.width)||1280,y=Number(e?.height)||720,i=`${d}x${y}`,h=[];h.push(`--viewport-size=${i}`,"--output-dir=test-results"),t||h.push("--headless");let f;o?f={command:s,args:[o,...h],env:{PATH:`${a}:/usr/bin:/bin:/usr/sbin:/sbin`}}:f={command:"npx",args:["-y","@playwright/mcp",...h],env:{PATH:`${a}:/usr/bin:/bin:/usr/sbin:/sbin`}},f.description="Zibby MCP Browser - Playwright MCP with Zibby defaults";let w=$(ge(),".cursor"),m=$(w,"mcp.json");K(w)||ue(w,{recursive:!0});let A={mcpServers:{}};if(K(m))try{A=JSON.parse(pe(m,"utf-8")),(!A.mcpServers||typeof A.mcpServers!="object")&&(A.mcpServers={})}catch{A={mcpServers:{}}}A.mcpServers["playwright-official"]=f,de(m,`${JSON.stringify(A,null,2)}
10
+ `,"utf-8")}async function Me(){let t=$e();if(!t)return;let e=$(t,"scripts","patch-cursor-mcp.js");if(K(e))try{await new Promise((s,a)=>{let o=U(process.execPath,[e],{cwd:process.cwd(),stdio:"ignore"});o.on("close",d=>s(d??0)),o.on("error",a)})}catch{}}function ze(t){return ce(t).replace(/^\/+/,"").replace(/\//g,"-")}function Re(t){let e=String(t||""),s=e.split(`
11
+ `).find(d=>/playwright-official/i.test(d)&&/APPROVAL|🔑/i.test(d));if(s){let d=s.match(/=>\s*(\S+)/);if(d)return d[1]}let a=e.match(/playwright-official[^=]*=>\s*(\S+)/);if(a)return a[1];let o=e.match(/playwright-official-[a-f0-9]+/i);return o?o[0]:null}function Be(t,e){let s=ze(t),a=$(ge(),".cursor","projects",s);ue(a,{recursive:!0});let o=$(a,"mcp-approvals.json");return de(o,`${JSON.stringify([e],null,2)}
12
+ `,"utf-8"),o}function le(t){try{return W("cursor-agent mcp list",{cwd:t,encoding:"utf-8",stdio:["ignore","pipe","pipe"],env:process.env,maxBuffer:2*1024*1024})}catch(e){let s=e.stdout!=null?String(e.stdout):"",a=e.stderr!=null?String(e.stderr):"";return s+a}}function Ye(t){try{return W("cursor-agent mcp enable playwright-official",{cwd:t,encoding:"utf-8",stdio:["ignore","pipe","pipe"],env:process.env,maxBuffer:1024*1024}),!0}catch{return!1}}async function ye(t={}){let e=!!t.headed,s=t.viewport||{width:1280,height:720};if(!process.execPath)throw new Error("Node.js runtime not found");let a=await Ke(process.cwd());console.log(a?P.gray(" \u2713 ffmpeg installed for Playwright video"):P.yellow(" \u26A0 Could not install ffmpeg (video may be unavailable)")),Te({headed:e,viewport:s}),await Me();let o=ce(process.cwd());if(me("cursor-agent")){le(o);let d=Ye(o);d&&console.log(P.gray(" \u2713 cursor-agent: mcp enable playwright-official"));let y=le(o),i=Re(y);if(i)try{let h=Be(o,i);console.log(P.gray(` \u2713 MCP auto-approval key saved (${h})`))}catch(h){console.log(P.yellow(` \u26A0 Could not write mcp-approvals.json: ${h.message}`))}else d||(console.log(P.yellow(" \u26A0 Could not auto-approve MCP (mcp enable failed and no approval key in cursor-agent output)")),console.log(P.gray(" Try: cursor-agent mcp enable playwright-official")))}else console.log(P.yellow(" \u26A0 cursor-agent not found; install it to use Cursor MCP tools"))}async function je(t){try{console.log(P.cyan(`
5
13
  \u{1F680} Running CI setup...
6
- `)),await ae({headed:!1,cloudSync:!0,viewport:{width:1280,height:720}}),console.log(x.green(`
14
+ `)),await ye({headed:!1,cloudSync:!0,viewport:{width:1280,height:720}}),console.log(P.green(`
7
15
  \u2705 CI/CD setup complete!
8
- `))}catch(e){console.log(x.red(`
16
+ `))}catch(e){console.log(P.red(`
9
17
  \u274C Error: ${e.message}
10
- `)),process.exit(1)}}async function Ke(t,e){try{let a=["playwright","test",t||"tests/","--project=chromium"];e.headed&&a.push("--headed"),console.log(x.cyan(`
18
+ `)),process.exit(1)}}async function Ne(t,e){try{let s=["playwright","test",t||"tests/","--project=chromium"];e.headed&&s.push("--headed"),console.log(P.cyan(`
11
19
  \u{1F3A5} Running tests with video recording...
12
- `)),console.log(x.gray("\u2501".repeat(50)));let l=H("npx",a,{cwd:process.cwd(),stdio:"inherit"});l.on("close",n=>{n===0?console.log(x.green(`
20
+ `)),console.log(P.gray("\u2501".repeat(50)));let a=U("npx",s,{cwd:process.cwd(),stdio:"inherit"});a.on("close",o=>{o===0?console.log(P.green(`
13
21
  \u2705 Tests complete!
14
- `)):(console.log(x.red(`
15
- \u274C Tests failed with code ${n}
16
- `)),process.exit(n))}),l.on("error",n=>{console.log(x.red(`
17
- \u274C Error: ${n.message}
18
- `)),process.exit(1)})}catch(a){console.log(x.red(`
19
- \u274C Error: ${a.message}
20
- `)),process.exit(1)}}var G,ce=ge(()=>{G=ve(import.meta.url)});import{mkdir as M,writeFile as h,readFile as A}from"fs/promises";import{existsSync as P,readdirSync as Me}from"fs";import{join as p,resolve as pe,dirname as Be}from"path";import{homedir as k}from"os";import D from"inquirer";import o from"chalk";import I from"ora";import{spawn as R,execSync as L}from"child_process";import{fileURLToPath as ze}from"url";import{createRequire as de}from"module";import{existsSync as ye,readFileSync as he,writeFileSync as be,mkdirSync as we}from"fs";import{join as q}from"path";import{homedir as U}from"os";var O={cursor:{envVar:"CURSOR_API_KEY",label:"Cursor API Key",url:"https://cursor.com/settings"},claude:{envVar:"ANTHROPIC_API_KEY",label:"Anthropic API Key",url:"https://console.anthropic.com/settings/keys"},codex:{envVar:"OPENAI_API_KEY",label:"OpenAI API Key",url:"https://platform.openai.com/api-keys"},gemini:{envVar:"GEMINI_API_KEY",label:"Gemini API Key",url:"https://aistudio.google.com/app/apikey"}};function J(){return q(U(),".zibby","config.json")}function V(){try{let t=J();return ye(t)?JSON.parse(he(t,"utf-8")):{}}catch{return{}}}function X(t,e){let a=q(U(),".zibby");we(a,{recursive:!0});let l=J(),n=V(),m=e?O[e]:null;m&&((!n.agentKeys||typeof n.agentKeys!="object")&&(n.agentKeys={}),n.agentKeys[m.envVar]=String(t).trim()),delete n.agentApiKey,be(l,`${JSON.stringify(n,null,2)}
21
- `,"utf-8")}var Te=ze(import.meta.url),Re=Be(Te),ue=de(import.meta.url);async function Ye(){try{let t=process.platform==="win32",e=L("npm config get prefix",{encoding:"utf-8"}).trim(),a=t?e:`${e}/bin`,l=a.replace(/^~/,k()),n=t?";":":";if(process.env.PATH.split(n).some(f=>{let v=f.replace(/^~/,k());return v===l||v===a}))return;if(process.env.CI||process.env.ZIBBY_CI||!process.stdin.isTTY){console.log(o.yellow("\u26A0\uFE0F npm global bin not in PATH")),console.log(o.gray(` Location: ${l}`)),console.log(o.gray(` Add it manually: export PATH="${l}:$PATH"
22
- `));return}console.log(o.yellow("\u26A0\uFE0F npm global bin not in PATH")),console.log(o.gray(` Location: ${l}`)),console.log();let{shouldAddPath:r}=await D.prompt([{type:"confirm",name:"shouldAddPath",message:"Add npm global bin to your shell PATH automatically?",default:!0}]);if(!r){t?(console.log(o.gray(`
23
- \u{1F4A1} To add manually on Windows:`)),console.log(o.gray(' 1. Search "Environment Variables" in Start menu')),console.log(o.gray(' 2. Edit "Path" in User variables')),console.log(o.gray(` 3. Add: ${l}
24
- `))):(console.log(o.gray(`
25
- \u{1F4A1} To add manually, run:`)),console.log(o.gray(` echo 'export PATH="${l}:$PATH"' >> ~/.zshrc`)),console.log(o.gray(` source ~/.zshrc
26
- `)));return}if(t){console.log(o.yellow("\u26A0\uFE0F Cannot auto-add PATH on Windows")),console.log(o.gray(" Please add manually:")),console.log(o.gray(' 1. Search "Environment Variables" in Start menu')),console.log(o.gray(' 2. Edit "Path" in User variables')),console.log(o.gray(` 3. Add: ${l}
27
- `));return}let w=process.env.SHELL||"",g="";if(w.includes("zsh"))g=p(k(),".zshrc");else if(w.includes("bash"))g=P(p(k(),".bashrc"))?p(k(),".bashrc"):p(k(),".bash_profile");else{console.log(o.yellow(`\u26A0\uFE0F Unknown shell: ${w}`)),console.log(o.gray(" Please add manually:")),console.log(o.gray(` export PATH="${l}:$PATH"`));return}if(P(g)){let f=await A(g,"utf-8");if(f.includes(l)||f.includes("npm")&&f.includes("global")&&f.includes("bin")){console.log(o.yellow(`\u26A0\uFE0F PATH entry found in ${g} but not active`)),console.log(o.gray(` Run: source ${g}
28
- `));return}}let C=`
22
+ `)):(console.log(P.red(`
23
+ \u274C Tests failed with code ${o}
24
+ `)),process.exit(o))}),a.on("error",o=>{console.log(P.red(`
25
+ \u274C Error: ${o.message}
26
+ `)),process.exit(1)})}catch(s){console.log(P.red(`
27
+ \u274C Error: ${s.message}
28
+ `)),process.exit(1)}}var V,he=J(()=>{V=Se(import.meta.url)});import{mkdir as T,writeFile as x,readFile as z}from"fs/promises";import{existsSync as C,readdirSync as Le,readFileSync as De}from"fs";import{join as g,resolve as be,dirname as Ze}from"path";import{homedir as S}from"os";import O from"inquirer";import n from"chalk";import _ from"ora";import{spawn as M,execSync as j}from"child_process";import{fileURLToPath as He}from"url";import{createRequire as we}from"module";import{existsSync as Pe,readFileSync as Ce,writeFileSync as xe,mkdirSync as ke}from"fs";import{join as Q}from"path";import{homedir as ee}from"os";var L={cursor:{envVar:"CURSOR_API_KEY",label:"Cursor API Key",url:"https://cursor.com/settings"},claude:{envVar:"ANTHROPIC_API_KEY",label:"Anthropic API Key",url:"https://console.anthropic.com/settings/keys"},codex:{envVar:"OPENAI_API_KEY",label:"OpenAI API Key",url:"https://platform.openai.com/api-keys"},gemini:{envVar:"GEMINI_API_KEY",label:"Gemini API Key",url:"https://aistudio.google.com/app/apikey"}};function te(){return Q(ee(),".zibby","config.json")}function D(){try{let t=te();return Pe(t)?JSON.parse(Ce(t,"utf-8")):{}}catch{return{}}}function oe(t,e){let s=e?L[e]:null;s&&G(s.envVar,t)}function G(t,e){if(!t||typeof t!="string"||!e||typeof e!="string")return;let s=Q(ee(),".zibby");ke(s,{recursive:!0});let a=te(),o=D();(!o.agentKeys||typeof o.agentKeys!="object")&&(o.agentKeys={}),o.agentKeys[t]=String(e).trim(),delete o.agentApiKey,xe(a,`${JSON.stringify(o,null,2)}
29
+ `,"utf-8")}function Ge(){if(process.platform==="darwin")try{let t=j('security find-generic-password -s "Claude Code-credentials" -w',{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim();if(t){let e=JSON.parse(t);if(e?.claudeAiOauth?.accessToken)return e.claudeAiOauth}}catch{}try{let t=g(S(),".claude",".credentials.json");return C(t)&&JSON.parse(De(t,"utf-8"))?.claudeAiOauth||null}catch{return null}}async function Fe(){let t=Ge(),e=t?.accessToken||null,s=t?.subscriptionType?t.subscriptionType.charAt(0).toUpperCase()+t.subscriptionType.slice(1):null,a=process.platform==="darwin"?"macOS Keychain":"~/.claude/.credentials.json",o=process.env.ANTHROPIC_API_KEY||D().agentKeys?.ANTHROPIC_API_KEY;console.log(""),console.log(n.cyan(" Claude has two billing modes \u2014 choose which you have:")),console.log("");let d=e?s?`Subscription (OAuth) \u2014 Claude ${s} plan detected (${a}, ***${e.slice(-4)})`:`Subscription (OAuth) \u2014 auto-detected (${a}, ***${e.slice(-4)})`:"Subscription (OAuth) \u2014 Claude Pro / Max plan billing",{kind:y}=await O.prompt([{type:"select",name:"kind",message:"Which Claude credential do you want to use?",choices:[{name:d,value:"oauth"},{name:o?`API key \u2014 found one (***${o.slice(-4)}), pay-per-token billing`:"API key \u2014 pay-per-token billing via console.anthropic.com",value:"api"}],default:e?"oauth":o?"api":"oauth"}]);if(y==="skip")return{kind:"skip"};if(y==="oauth"){if(e)return{kind:"oauth",token:e,subscriptionType:t?.subscriptionType};console.log(""),console.log(n.gray(" How to get an OAuth subscription token:")),console.log(n.gray(" 1. Install claude: npm install -g @anthropic-ai/claude-code")),console.log(n.gray(" 2. Run: claude")),console.log(n.gray(" \u2192 log in via browser \u2192 quit when shell appears")),console.log(n.gray(" 3. Read your token:")),process.platform==="darwin"?(console.log(n.gray(' (macOS) security find-generic-password -s "Claude Code-credentials" -w')),console.log(n.gray(" | jq -r .claudeAiOauth.accessToken"))):console.log(n.gray(" cat ~/.claude/.credentials.json | jq -r .claudeAiOauth.accessToken")),console.log("");let{token:h}=await O.prompt([{type:"password",name:"token",message:"Paste OAuth token (or press Enter to skip):",mask:"*"}]);return h&&h.trim()?{kind:"oauth",token:h.trim()}:{kind:"skip"}}if(o)return{kind:"api",token:o};let{token:i}=await O.prompt([{type:"password",name:"token",message:"Paste Anthropic API key (from https://console.anthropic.com/settings/keys, or press Enter to skip):",mask:"*"}]);return i&&i.trim()?{kind:"api",token:i.trim()}:{kind:"skip"}}var Ve=He(import.meta.url),Ue=Ze(Ve),ve=we(import.meta.url);async function We(){try{let t=process.platform==="win32",e=j("npm config get prefix",{encoding:"utf-8"}).trim(),s=t?e:`${e}/bin`,a=s.replace(/^~/,S()),o=t?";":":";if(process.env.PATH.split(o).some(m=>{let A=m.replace(/^~/,S());return A===a||A===s}))return;if(process.env.CI||process.env.ZIBBY_CI||!process.stdin.isTTY){console.log(n.yellow("npm global bin not in PATH")),console.log(n.gray(` Location: ${a}`)),console.log(n.gray(` Add it manually: export PATH="${a}:$PATH"
30
+ `));return}console.log(n.yellow("npm global bin not in PATH")),console.log(n.gray(` Location: ${a}`)),console.log();let{shouldAddPath:i}=await O.prompt([{type:"confirm",name:"shouldAddPath",message:"Add npm global bin to your shell PATH automatically?",default:!0}]);if(!i){t?(console.log(n.gray(`
31
+ To add manually on Windows:`)),console.log(n.gray(' 1. Search "Environment Variables" in Start menu')),console.log(n.gray(' 2. Edit "Path" in User variables')),console.log(n.gray(` 3. Add: ${a}
32
+ `))):(console.log(n.gray(`
33
+ To add manually, run:`)),console.log(n.gray(` echo 'export PATH="${a}:$PATH"' >> ~/.zshrc`)),console.log(n.gray(` source ~/.zshrc
34
+ `)));return}if(t){console.log(n.yellow("Cannot auto-add PATH on Windows")),console.log(n.gray(" Please add manually:")),console.log(n.gray(' 1. Search "Environment Variables" in Start menu')),console.log(n.gray(' 2. Edit "Path" in User variables')),console.log(n.gray(` 3. Add: ${a}
35
+ `));return}let h=process.env.SHELL||"",f="";if(h.includes("zsh"))f=g(S(),".zshrc");else if(h.includes("bash"))f=C(g(S(),".bashrc"))?g(S(),".bashrc"):g(S(),".bash_profile");else{console.log(n.yellow(`Unknown shell: ${h}`)),console.log(n.gray(" Please add manually:")),console.log(n.gray(` export PATH="${a}:$PATH"`));return}if(C(f)){let m=await z(f,"utf-8");if(m.includes(a)||m.includes("npm")&&m.includes("global")&&m.includes("bin")){console.log(n.yellow(`PATH entry found in ${f} but not active`)),console.log(n.gray(` Run: source ${f}
36
+ `));return}}let w=`
29
37
  # npm global bin (added by zibby)
30
- export PATH="${l}:$PATH"
31
- `;await h(g,(P(g)?await A(g,"utf-8"):"")+C),console.log(o.green(`\u2705 Added to ${g}`)),console.log(o.yellow(`
32
- \u{1F4A1} Run this to activate in current session:`)),console.log(o.gray(` source ${g}
33
- `))}catch{}}async function ft(t,e){console.log(o.bold.cyan(`
34
- \u{1F3AD} Welcome to Zibby Test Automation!
35
- `));let a=!e.skipMemory,l=["dolt","mem0"].includes(String(e.memoryBackend||"").toLowerCase())?String(e.memoryBackend).toLowerCase():"dolt";await Ye();let n=t?pe(process.cwd(),t):process.cwd(),m=t||"zibby-tests",y=!!t;y&&P(n)&&(console.log(o.red(`
36
- \u274C Directory "${t}" already exists!
37
- `)),process.exit(1)),!y&&P(p(n,".zibby.config.mjs"))&&!e.force&&(console.log(o.yellow(`
38
- \u26A0\uFE0F Zibby is already initialized in this directory!
39
- `)),console.log(o.white("Config file found: .zibby.config.mjs")),console.log(o.gray(`Use --force or -f to reinitialize
40
- `)),process.exit(0)),e.force&&!y&&console.log(o.cyan(`
38
+ export PATH="${a}:$PATH"
39
+ `;await x(f,(C(f)?await z(f,"utf-8"):"")+w),console.log(n.green(`Added to ${f}`)),console.log(n.yellow(`
40
+ Run this to activate in current session:`)),console.log(n.gray(` source ${f}
41
+ `))}catch{}}async function Kt(t,e){console.log(`
42
+ Zibby Test Automation
43
+ `);let s=!e.skipMemory,a=["dolt","mem0"].includes(String(e.memoryBackend||"").toLowerCase())?String(e.memoryBackend).toLowerCase():"dolt";await We();let o=t?be(process.cwd(),t):process.cwd(),d=t||"zibby-tests",y=!!t;y&&C(o)&&(console.log(n.red(`
44
+ Directory "${t}" already exists!
45
+ `)),process.exit(1)),!y&&C(g(o,".zibby.config.mjs"))&&!e.force&&(console.log(n.yellow(`
46
+ Zibby is already initialized in this directory!
47
+ `)),console.log(n.white("Config file found: .zibby.config.mjs")),console.log(n.gray(`Use --force or -f to reinitialize
48
+ `)),process.exit(0)),e.force&&!y&&console.log(n.cyan(`
41
49
  Reinitializing Zibby configuration...
42
- `));let r;if(e.agent&&(e.headed||e.headless))console.log(o.cyan(`Setting up with provided options...
43
- `)),r={agent:e.agent,browserMode:e.headless?"headless":"headed",apiKey:e.apiKey||null,cloudSync:!!(e.cloudSync||e.apiKey)};else{if(e.agent)r={agent:e.agent};else{let{agent:S}=await D.prompt([{type:"select",name:"agent",message:"Which AI agent do you prefer?",choices:[{name:"Cursor",value:"cursor"},{name:"Claude (Anthropic)",value:"claude"},{name:"Codex (OpenAI)",value:"codex"},{name:"Gemini (Google)",value:"gemini"}],default:"cursor"}]);r={agent:S}}let f=O[r.agent];if(f&&!e.agentKey&&!(process.env.CI||process.env.ZIBBY_CI||!process.stdin.isTTY)){let S=V(),B=process.env[f.envVar]||S.agentKeys?.[f.envVar],E=B?`***${B.slice(-4)}`:null,s=E?`${f.label} found (${E}). Press Enter to keep, or paste a new key:`:`Enter ${f.label} (from ${f.url}, or press Enter to skip):`,{agentKey:c}=await D.prompt([{type:"password",name:"agentKey",message:s,mask:"*"}]);c&&c.trim()&&(r.agentKey=c.trim())}let v=[];if(!e.headed&&!e.headless&&v.push({type:"select",name:"browserMode",message:"Browser mode during live AI execution?",choices:[{name:"Headed - Visible browser (recommended for development)",value:"headed"},{name:"Headless - Hidden browser (for CI/CD)",value:"headless"}],default:"headed"}),e.apiKey||v.push({type:"input",name:"apiKey",message:"Enable cloud sync? Enter project ZIBBY_API_KEY (or press Enter to skip):"}),v.length>0){let S=await D.prompt(v);Object.assign(r,S)}r.browserMode=e.headless?"headless":e.headed?"headed":r.browserMode,r.apiKey=e.apiKey||r.apiKey,r.cloudSync=!!(e.cloudSync||e.apiKey||r.apiKey&&r.apiKey.trim())}e.agentKey&&(r.agentKey=e.agentKey);let g=O[r.agent];r.agentKey&&(X(r.agentKey,r.agent),console.log(o.gray(" \u2713 Agent API key saved to ~/.zibby/config.json"))),r.mcp="playwright",r.setupMcp=r.agent==="cursor";let C=I("Setting up Zibby...").start();try{if(y&&await M(n,{recursive:!0}),await M(p(n,"test-specs/examples"),{recursive:!0}),await M(p(n,"tests"),{recursive:!0}),await M(p(n,".zibby/output"),{recursive:!0}),await M(p(n,".zibby/commands"),{recursive:!0}),a&&l==="dolt")try{let{initMemory:s,DoltDB:c}=await import("@zibby/memory");if(c.isAvailable()){let{created:i}=s(n);i&&(C.text="Initialized test memory database (Dolt)...")}else C.text="Dolt not found \u2014 skipping memory database (brew install dolt)"}catch{}C.text="Scaffolding workflow graph...";let{TemplateFactory:f}=await import("@zibby/core/templates"),v=e.template||"browser-test-automation";try{let{graphPath:s,nodesPath:c,readmePath:i,resultHandlerPath:u,template:d}=f.getTemplateFiles(v),b=p(n,".zibby"),z=await A(s,"utf-8");if(await h(p(b,"graph.mjs"),z),u){let $=await A(u,"utf-8");await h(p(b,"result-handler.mjs"),$)}let Y=await A(i,"utf-8");await h(p(b,"README.md"),Y),await M(p(b,"nodes"),{recursive:!0});let{readdirSync:_}=await import("fs"),j=_(c);for(let $ of j){let Z=await A(p(c,$),"utf-8");!a&&$==="execute-live.mjs"&&(Z=Z.replace("skills: [SKILLS.BROWSER, SKILLS.MEMORY],","skills: [SKILLS.BROWSER],")),await h(p(b,"nodes",$),Z)}let N=p(d.path,"chat.mjs");if(P(N)){let $=await A(N,"utf-8");await h(p(b,"chat.mjs"),$)}}catch(s){throw C.fail(`Failed to scaffold template: ${s.message}`),s}C.text="Generating configuration files...";let S=je(r,e,{memoryBackend:l});if(await h(p(n,".zibby.config.mjs"),S),await h(p(n,".env.example"),Oe(r,l)),r.apiKey&&r.apiKey.trim()){let s=p(n,".env"),c=r.apiKey.trim();if(P(s)){let i=await A(s,"utf8");/^ZIBBY_API_KEY=/m.test(i)?i=i.replace(/^ZIBBY_API_KEY=.*/m,`ZIBBY_API_KEY=${c}`):/^#\s*ZIBBY_API_KEY=/m.test(i)?i=i.replace(/^#\s*ZIBBY_API_KEY=.*/m,`ZIBBY_API_KEY=${c}`):i=`${i.trimEnd()}
50
+ `));let i;if(e.agent&&(e.headed||e.headless))console.log(n.cyan(`Setting up with provided options...
51
+ `)),i={agent:e.agent,browserMode:e.headless?"headless":"headed",apiKey:e.apiKey||null,cloudSync:!!(e.cloudSync||e.apiKey)};else{if(e.agent)i={agent:e.agent};else{let{agent:b}=await O.prompt([{type:"select",name:"agent",message:"Which AI agent do you prefer?",choices:[{name:"Cursor",value:"cursor"},{name:"Claude (Anthropic)",value:"claude"},{name:"Codex (OpenAI)",value:"codex"},{name:"Gemini (Google)",value:"gemini"}],default:"cursor"}]);i={agent:b}}let m=L[i.agent],A=!(process.env.CI||process.env.ZIBBY_CI||!process.stdin.isTTY);if(i.agent==="claude"&&!e.agentKey&&A){let b=await Fe();b?.kind==="oauth"&&b.token?i.claudeOauthToken=b.token:b?.kind==="api"&&b.token&&(i.agentKey=b.token)}else if(m&&!e.agentKey&&A){let b=D(),r=process.env[m.envVar]||b.agentKeys?.[m.envVar],c=r?`***${r.slice(-4)}`:null,l=c?`${m.label} found (${c}). Press Enter to keep, or paste a new key:`:`Enter ${m.label} (from ${m.url}, or press Enter to skip):`,{agentKey:u}=await O.prompt([{type:"password",name:"agentKey",message:l,mask:"*"}]);u&&u.trim()&&(i.agentKey=u.trim())}let k=[];if(!e.headed&&!e.headless&&k.push({type:"select",name:"browserMode",message:"Browser mode during live AI execution?",choices:[{name:"Headed - Visible browser (recommended for development)",value:"headed"},{name:"Headless - Hidden browser (for CI/CD)",value:"headless"}],default:"headed"}),e.apiKey||k.push({type:"input",name:"apiKey",message:"Enable cloud sync? Enter project ZIBBY_API_KEY (or press Enter to skip):"}),k.length>0){let b=await O.prompt(k);Object.assign(i,b)}i.browserMode=e.headless?"headless":e.headed?"headed":i.browserMode,i.apiKey=e.apiKey||i.apiKey,i.cloudSync=!!(e.cloudSync||e.apiKey||i.apiKey&&i.apiKey.trim())}e.agentKey&&(i.agentKey=e.agentKey),e.agentOauthToken&&i.agent==="claude"&&(i.claudeOauthToken=e.agentOauthToken);let f=L[i.agent];i.claudeOauthToken&&(G("CLAUDE_CODE_OAUTH_TOKEN",i.claudeOauthToken),console.log(n.gray(" Claude OAuth subscription token saved to ~/.zibby/config.json")),console.log(n.gray(" Used by: zibby test / chat / workflow run / workflow start"))),i.agentKey&&(oe(i.agentKey,i.agent),console.log(n.gray(" Agent API key saved to ~/.zibby/config.json"))),i.mcp="playwright",i.setupMcp=i.agent==="cursor";let w=_("Setting up Zibby...").start();try{if(y&&await T(o,{recursive:!0}),await T(g(o,"test-specs/examples"),{recursive:!0}),await T(g(o,"tests"),{recursive:!0}),await T(g(o,".zibby/output"),{recursive:!0}),await T(g(o,".zibby/commands"),{recursive:!0}),s&&a==="dolt")try{let{initMemory:r,DoltDB:c}=await import("@zibby/ui-memory");if(c.isAvailable()){let{created:l}=r(o);l&&(w.text="Initialized test memory database (Dolt)...")}else w.text="Dolt not found \u2014 skipping memory database (brew install dolt)"}catch{}w.text="Scaffolding workflow graph...";let m=e.template||"browser-test-automation";try{let{writeTemplateFiles:r}=await Promise.resolve().then(()=>(re(),ie));await r(o,m,{enableMemory:s})}catch(r){throw w.fail(`Failed to scaffold template: ${r.message}`),r}w.text="Generating configuration files...";let A=qe(i,e,{memoryBackend:a});if(await x(g(o,".zibby.config.mjs"),A),await x(g(o,".env.example"),Je(i,a)),i.apiKey&&i.apiKey.trim()){let r=g(o,".env"),c=i.apiKey.trim();if(C(r)){let l=await z(r,"utf8");/^ZIBBY_API_KEY=/m.test(l)?l=l.replace(/^ZIBBY_API_KEY=.*/m,`ZIBBY_API_KEY=${c}`):/^#\s*ZIBBY_API_KEY=/m.test(l)?l=l.replace(/^#\s*ZIBBY_API_KEY=.*/m,`ZIBBY_API_KEY=${c}`):l=`${l.trimEnd()}
44
52
 
45
53
  # Zibby Cloud Sync
46
54
  ZIBBY_API_KEY=${c}
47
- `,await h(s,i)}else await h(s,De(r,c,l))}if(r.agentKey&&g){let s=p(n,".env"),c=r.agentKey;if(P(s)){let i=await A(s,"utf8"),u=new RegExp(`^${g.envVar}=.*`,"m"),d=new RegExp(`^#\\s*${g.envVar}=.*`,"m");u.test(i)?i=i.replace(u,`${g.envVar}=${c}`):d.test(i)?i=i.replace(d,`${g.envVar}=${c}`):i=`${i.trimEnd()}
55
+ `,await x(r,l)}else await x(r,Xe(i,c,a))}if(i.agentKey&&f){let r=g(o,".env"),c=i.agentKey;if(C(r)){let l=await z(r,"utf8"),u=new RegExp(`^${f.envVar}=.*`,"m"),p=new RegExp(`^#\\s*${f.envVar}=.*`,"m");u.test(l)?l=l.replace(u,`${f.envVar}=${c}`):p.test(l)?l=l.replace(p,`${f.envVar}=${c}`):l=`${l.trimEnd()}
48
56
 
49
57
  # AI Agent Key
50
- ${g.envVar}=${c}
51
- `,await h(s,i)}}if(y){let s=Le(m,r,{memoryBackend:l});await h(p(n,"package.json"),s)}if(!P(p(n,".gitignore"))){let s=Ne();await h(p(n,".gitignore"),s)}if(!P(p(n,"playwright.config.js"))){let s=Ze("on");await h(p(n,"playwright.config.js"),s)}if(!P(p(n,"test-specs/examples/example-domain.txt"))){let s=Ve();await h(p(n,"test-specs/examples/example-domain.txt"),s)}let B=pe(Re,"../../../../examples/.zibby/commands");if(P(B)){let s=Me(B).filter(c=>c.toLowerCase().endsWith(".md"));for(let c of s){let i=p(n,".zibby/commands",c);if(e.force||!P(i)){let u=await A(p(B,c),"utf-8");await h(i,u)}}}if(!P(p(n,".zibby/commands/example.md"))){let s=Ge();await h(p(n,".zibby/commands/example.md"),s)}if(y){let s=He(m,r);await h(p(n,"README.md"),s)}if(C.succeed(y?"Project created!":"Zibby initialized!"),y&&!e.skipInstall){let s=I("Installing dependencies...").start();await new Promise((c,i)=>{R("npm",["install"],{cwd:n,stdio:"pipe"}).on("close",d=>{d===0?(s.succeed("Dependencies installed!"),c()):(s.fail("Failed to install dependencies"),i(new Error("npm install failed")))})})}else if(!y){let s=["@zibby/cli","@zibby/core"],c=[];for(let i of s)try{de(p(n,"package.json")).resolve(`${i}/package.json`)}catch{c.push(i)}if(c.length>0){let i=ue("../../package.json"),u=c.map(d=>d==="@zibby/cli"?`${d}@latest`:d==="@zibby/core"?`${d}@${i.dependencies?.["@zibby/core"]||"latest"}`:d);if(e.skipInstall)console.log(o.yellow(`
52
- Missing required Zibby dependencies in this project:`)),console.log(o.white(` ${c.join(", ")}`)),console.log(o.gray("Install them manually to avoid runtime errors:")),console.log(o.white(` npm install --save-dev ${u.join(" ")}
53
- `));else{let d=I(`Installing ${u.join(", ")}...`).start();await new Promise(z=>{R("npm",["install","--save-dev",...u],{cwd:n,stdio:"pipe"}).on("close",_=>z(_??1))})===0?d.succeed("Installed missing Zibby dependencies"):(d.warn("Could not auto-install Zibby dependencies"),console.log(o.gray("Run this manually:")),console.log(o.white(` npm install --save-dev ${u.join(" ")}
54
- `)))}}}if(!y&&a&&l==="mem0"&&(console.log(o.yellow(`
55
- Using mem0 backend requires mem0ai in your project dependencies.`)),console.log(o.gray("Run this manually in your project when ready:")),console.log(o.white(` npm install mem0ai
56
- `))),!e.skipInstall){let s=I("Installing Playwright browsers...").start();await new Promise(c=>{let i=R("npx",["playwright","install","chromium"],{cwd:n,stdio:"pipe"}),u="";i.stdout.on("data",d=>{u+=d.toString()}),i.stderr.on("data",d=>{u+=d.toString()}),i.on("close",d=>{d===0?(u.includes("already installed")||u.includes("up to date")?s.succeed("Playwright browsers already installed"):s.succeed("Playwright browsers installed!"),c()):(s.warn("Could not verify Playwright browsers"),console.log(o.yellow(`
57
- \u26A0\uFE0F If tests fail, run: npx playwright install
58
- `)),c())})})}if(r.agent==="cursor"&&!e.skipInstall){let s=I("Checking cursor-agent CLI...").start();try{L("cursor-agent --version",{encoding:"utf-8",timeout:5e3,stdio:"pipe"}),s.succeed("cursor-agent CLI already installed")}catch{s.text="Installing cursor-agent CLI...";try{await new Promise((c,i)=>{R("bash",["-c","curl https://cursor.com/install -fsS | bash"],{stdio:"pipe"}).on("close",d=>{if(d===0){let b=p(k(),".local","bin");process.env.PATH.includes(b)||(process.env.PATH=`${b}:${process.env.PATH}`),s.succeed("cursor-agent CLI installed!"),c()}else i(new Error("cursor-agent install failed"))})})}catch{s.fail("Could not install cursor-agent CLI"),console.log(o.yellow(` Install manually: curl https://cursor.com/install -fsS | bash
59
- `))}}}if(r.agent==="codex"&&!e.skipInstall){let s=I("Checking Codex CLI...").start();try{L("codex --version",{encoding:"utf-8",timeout:5e3,stdio:"pipe"}),s.succeed("Codex CLI already installed")}catch{s.text="Installing Codex CLI...";try{await new Promise((c,i)=>{R("npm",["install","-g","@openai/codex"],{stdio:"pipe"}).on("close",d=>{d===0?(s.succeed("Codex CLI installed!"),c()):i(new Error("npm install -g @openai/codex failed"))})})}catch{s.fail("Could not install Codex CLI"),console.log(o.yellow(` Install manually: npm install -g @openai/codex
60
- `))}}}if(r.agent==="gemini"&&!e.skipInstall){let s=I("Checking Gemini CLI...").start();try{L("gemini --version",{encoding:"utf-8",timeout:5e3,stdio:"pipe"}),s.succeed("Gemini CLI already installed")}catch{s.text="Installing Gemini CLI...";try{await new Promise((i,u)=>{R("npm",["install","-g","@google/gemini-cli"],{stdio:"pipe"}).on("close",b=>{b===0?(s.succeed("Gemini CLI installed!"),i()):u(new Error("npm install -g @google/gemini-cli failed"))})})}catch{s.fail("Could not install Gemini CLI"),console.log(o.yellow(` Install manually: npm install -g @google/gemini-cli
61
- `))}}let c=I("Configuring Gemini MCP servers...").start();try{let i=p(k(),".gemini"),u=p(i,"settings.json");P(i)||await M(i,{recursive:!0});let d={mcpServers:{}};if(P(u))try{let j=await A(u,"utf-8");d=JSON.parse(j),d.mcpServers||(d.mcpServers={})}catch{}let b;try{let{createRequire:j}=await import("module");b=j(import.meta.url).resolve("@zibby/mcp-browser/bin/mcp-browser-zibby.js")}catch{b="@playwright/mcp"}let z=r.browserMode!=="headless",Y=b==="@playwright/mcp"?["-y","@playwright/mcp","--isolated","--viewport-size=1280x720","--output-dir","test-results"]:[b,"--isolated","--viewport-size=1280x720","--output-dir=test-results"];z||Y.push("--headless"),d.mcpServers["playwright-official"]={command:b==="@playwright/mcp"?"npx":"node",args:Y},await h(u,`${JSON.stringify(d,null,2)}
62
- `,"utf-8");let _="Gemini MCP configured";z?_+=" (headed mode - visible browser)":_+=" (headless mode - hidden browser)",c.succeed(_)}catch(i){c.fail("MCP setup failed"),console.log(o.yellow(" You may need to configure ~/.gemini/settings.json manually")),console.log(o.gray(` Error: ${i.message}
63
- `))}}if(r.agent==="cursor"&&r.setupMcp){let s=I("Setting up Playwright MCP...").start();try{let{setupPlaywrightMcpCommand:c}=await Promise.resolve().then(()=>(ce(),le)),i=r.cloudSync||!1,u=r.browserMode!=="headless";await c({headed:u,cloudSync:i,viewport:{width:1280,height:720}});let d="Playwright MCP configured";u?d+=" (headed mode - visible browser)":d+=" (headless mode - hidden browser)",i&&(d+=" + Zibby MCP (cloud sync)"),s.succeed(d),i&&!(r.apiKey&&r.apiKey.trim())&&console.log(o.gray(`
58
+ ${f.envVar}=${c}
59
+ `,await x(r,l)}}if(y){let r=Qe(d,i,{memoryBackend:a});await x(g(o,"package.json"),r)}if(!C(g(o,".gitignore"))){let r=et();await x(g(o,".gitignore"),r)}if(!C(g(o,"playwright.config.js"))){let r=tt("on");await x(g(o,"playwright.config.js"),r)}if(!C(g(o,"test-specs/examples/example-domain.txt"))){let r=ot();await x(g(o,"test-specs/examples/example-domain.txt"),r)}let k=be(Ue,"../../../../examples/.zibby/commands");if(C(k)){let r=Le(k).filter(c=>c.toLowerCase().endsWith(".md"));for(let c of r){let l=g(o,".zibby/commands",c);if(e.force||!C(l)){let u=await z(g(k,c),"utf-8");await x(l,u)}}}if(!C(g(o,".zibby/commands/example.md"))){let r=nt();await x(g(o,".zibby/commands/example.md"),r)}if(y){let r=st(d,i);await x(g(o,"README.md"),r)}if(w.succeed(y?"Project created!":"Zibby initialized!"),y&&!e.skipInstall){let r=_("Installing dependencies...").start();await new Promise((c,l)=>{M("npm",["install"],{cwd:o,stdio:"pipe"}).on("close",p=>{p===0?(r.succeed("Dependencies installed!"),c()):(r.fail("Failed to install dependencies"),l(new Error("npm install failed")))})})}else if(!y){let r=["@zibby/cli","@zibby/core"],c=[];for(let l of r)try{we(g(o,"package.json")).resolve(`${l}/package.json`)}catch{c.push(l)}if(c.length>0){let l=ve("../../package.json"),u=c.map(p=>p==="@zibby/cli"?`${p}@latest`:p==="@zibby/core"?`${p}@${l.dependencies?.["@zibby/core"]||"latest"}`:p);if(e.skipInstall)console.log(n.yellow(`
60
+ Missing required Zibby dependencies in this project:`)),console.log(n.white(` ${c.join(", ")}`)),console.log(n.gray("Install them manually to avoid runtime errors:")),console.log(n.white(` npm install --save-dev ${u.join(" ")}
61
+ `));else{let p=_(`Installing ${u.join(", ")}...`).start();await new Promise(N=>{M("npm",["install","--save-dev",...u],{cwd:o,stdio:"pipe"}).on("close",R=>N(R??1))})===0?p.succeed("Installed missing Zibby dependencies"):(p.warn("Could not auto-install Zibby dependencies"),console.log(n.gray("Run this manually:")),console.log(n.white(` npm install --save-dev ${u.join(" ")}
62
+ `)))}}}if(!y&&s&&a==="mem0"&&(console.log(n.yellow(`
63
+ Using mem0 backend requires mem0ai in your project dependencies.`)),console.log(n.gray("Run this manually in your project when ready:")),console.log(n.white(` npm install mem0ai
64
+ `))),!e.skipInstall){let r=_("Installing Playwright browsers...").start();await new Promise(c=>{let l=M("npx",["playwright","install","chromium"],{cwd:o,stdio:"pipe"}),u="";l.stdout.on("data",p=>{u+=p.toString()}),l.stderr.on("data",p=>{u+=p.toString()}),l.on("close",p=>{p===0?(u.includes("already installed")||u.includes("up to date")?r.succeed("Playwright browsers already installed"):r.succeed("Playwright browsers installed!"),c()):(r.warn("Could not verify Playwright browsers"),console.log(n.yellow(`
65
+ If tests fail, run: npx playwright install
66
+ `)),c())})})}if(i.agent==="cursor"&&!e.skipInstall){let r=_("Checking cursor-agent CLI...").start();try{j("cursor-agent --version",{encoding:"utf-8",timeout:5e3,stdio:"pipe"}),r.succeed("cursor-agent CLI already installed")}catch{r.text="Installing cursor-agent CLI...";try{await new Promise((c,l)=>{M("bash",["-c","curl https://cursor.com/install -fsS | bash"],{stdio:"pipe"}).on("close",p=>{if(p===0){let I=g(S(),".local","bin");process.env.PATH.includes(I)||(process.env.PATH=`${I}:${process.env.PATH}`),r.succeed("cursor-agent CLI installed!"),c()}else l(new Error("cursor-agent install failed"))})})}catch{r.fail("Could not install cursor-agent CLI"),console.log(n.yellow(` Install manually: curl https://cursor.com/install -fsS | bash
67
+ `))}}}if(i.agent==="codex"&&!e.skipInstall){let r=_("Checking Codex CLI...").start();try{j("codex --version",{encoding:"utf-8",timeout:5e3,stdio:"pipe"}),r.succeed("Codex CLI already installed")}catch{r.text="Installing Codex CLI...";try{await new Promise((c,l)=>{M("npm",["install","-g","@openai/codex"],{stdio:"pipe"}).on("close",p=>{p===0?(r.succeed("Codex CLI installed!"),c()):l(new Error("npm install -g @openai/codex failed"))})})}catch{r.fail("Could not install Codex CLI"),console.log(n.yellow(` Install manually: npm install -g @openai/codex
68
+ `))}}}if(i.agent==="gemini"&&!e.skipInstall){let r=_("Checking Gemini CLI...").start();try{j("gemini --version",{encoding:"utf-8",timeout:5e3,stdio:"pipe"}),r.succeed("Gemini CLI already installed")}catch{r.text="Installing Gemini CLI...";try{await new Promise((l,u)=>{M("npm",["install","-g","@google/gemini-cli"],{stdio:"pipe"}).on("close",I=>{I===0?(r.succeed("Gemini CLI installed!"),l()):u(new Error("npm install -g @google/gemini-cli failed"))})})}catch{r.fail("Could not install Gemini CLI"),console.log(n.yellow(` Install manually: npm install -g @google/gemini-cli
69
+ `))}}let c=_("Configuring Gemini MCP servers...").start();try{let l=g(S(),".gemini"),u=g(l,"settings.json");C(l)||await T(l,{recursive:!0});let p={mcpServers:{}};if(C(u))try{let H=await z(u,"utf-8");p=JSON.parse(H),p.mcpServers||(p.mcpServers={})}catch{}let I;try{let{createRequire:H}=await import("module");I=H(import.meta.url).resolve("@zibby/mcp-browser/bin/mcp-browser-zibby.js")}catch{I="@playwright/mcp"}let N=i.browserMode!=="headless",Z=I==="@playwright/mcp"?["-y","@playwright/mcp","--isolated","--viewport-size=1280x720","--output-dir","test-results"]:[I,"--isolated","--viewport-size=1280x720","--output-dir=test-results"];N||Z.push("--headless"),p.mcpServers["playwright-official"]={command:I==="@playwright/mcp"?"npx":"node",args:Z},await x(u,`${JSON.stringify(p,null,2)}
70
+ `,"utf-8");let R="Gemini MCP configured";N?R+=" (headed mode - visible browser)":R+=" (headless mode - hidden browser)",c.succeed(R)}catch(l){c.fail("MCP setup failed"),console.log(n.yellow(" You may need to configure ~/.gemini/settings.json manually")),console.log(n.gray(` Error: ${l.message}
71
+ `))}}if(i.agent==="cursor"&&i.setupMcp){let r=_("Setting up Playwright MCP...").start();try{let{setupPlaywrightMcpCommand:c}=await Promise.resolve().then(()=>(he(),fe)),l=i.cloudSync||!1,u=i.browserMode!=="headless";await c({headed:u,cloudSync:l,viewport:{width:1280,height:720}});let p="Playwright MCP configured";u?p+=" (headed mode - visible browser)":p+=" (headless mode - hidden browser)",l&&(p+=" + Zibby MCP (cloud sync)"),r.succeed(p),l&&!(i.apiKey&&i.apiKey.trim())&&console.log(n.gray(`
64
72
  Copy .env.example to .env and set ZIBBY_API_KEY to enable uploads
65
- `))}catch(c){s.fail("MCP setup script failed"),console.log(o.yellow(" Check if MCP is already configured:")),console.log(o.gray(' \u2022 Open Cursor settings \u2192 Check "playwright-official" MCP')),console.log(o.gray(" \u2022 Run: cursor-agent mcp list")),console.log(o.gray(` \u2022 Or run manually: zibby setup-playwright
66
- `)),console.log(o.gray(` Error: ${c.message}
67
- `))}}console.log(o.bold.green(`
68
- \u{1F389} All set!
69
- `)),console.log(o.cyan("Start the Zibby Chat Agent:")),y&&console.log(o.white(` cd ${t}`)),console.log(o.white(` zibby
70
- `)),console.log(o.cyan("Or run a test directly:")),console.log(o.white(` zibby run test-specs/examples/example-domain.txt
71
- `)),console.log(o.cyan("Next steps:"));let E=1;console.log(o.white(` ${E++}. cp .env.example .env ${o.gray("# then add your API keys")}`)),a&&console.log(o.white(` ${E++}. Set ${o.bold("ZIBBY_MEMORY_BACKEND")} in .env ${o.gray(`# currently: ${l}`)}`)),console.log(o.white(` ${E++}. Type ${o.bold("zibby")} to chat with the AI testing assistant`)),console.log(o.white(` ${E++}. Write test specs in test-specs/`)),console.log(o.white(` ${E++}. Run: npx zibby run <spec-file>
72
- `))}catch(f){C.fail("Failed to create project"),console.error(o.red(`
73
- \u274C Error: ${f.message}
74
- `)),process.exit(1)}}function je(t,e={},a={}){let l=["dolt","mem0"].includes(String(a.memoryBackend||"").toLowerCase())?String(a.memoryBackend).toLowerCase():"dolt",n={claude:`
73
+ `))}catch(c){r.fail("MCP setup script failed"),console.log(n.yellow(" Check if MCP is already configured:")),console.log(n.gray(' \u2022 Open Cursor settings \u2192 Check "playwright-official" MCP')),console.log(n.gray(" \u2022 Run: cursor-agent mcp list")),console.log(n.gray(` \u2022 Or run manually: zibby setup-playwright
74
+ `)),console.log(n.gray(` Error: ${c.message}
75
+ `))}}console.log(n.bold.green(`
76
+ All set!
77
+ `)),console.log(n.cyan("Start the Zibby Chat Agent:")),y&&console.log(n.white(` cd ${t}`)),console.log(n.white(` zibby
78
+ `)),console.log(n.cyan("Or run a test directly:")),console.log(n.white(` zibby run test-specs/examples/example-domain.txt
79
+ `)),console.log(n.cyan("Next steps:"));let b=1;console.log(n.white(` ${b++}. cp .env.example .env ${n.gray("# then add your API keys")}`)),s&&console.log(n.white(` ${b++}. Set ${n.bold("ZIBBY_MEMORY_BACKEND")} in .env ${n.gray(`# currently: ${a}`)}`)),console.log(n.white(` ${b++}. Type ${n.bold("zibby")} to chat with the AI testing assistant`)),console.log(n.white(` ${b++}. Write test specs in test-specs/`)),console.log(n.white(` ${b++}. Run: npx zibby run <spec-file>
80
+ `))}catch(m){w.fail("Failed to create project"),console.error(n.red(`
81
+ Error: ${m.message}
82
+ `)),process.exit(1)}}function qe(t,e={},s={}){let a=["dolt","mem0"].includes(String(s.memoryBackend||"").toLowerCase())?String(s.memoryBackend).toLowerCase():"dolt",o={claude:`
75
83
  claude: {
76
84
  model: 'auto', // Options: 'auto', 'sonnet-4.6', 'opus-4.6', 'sonnet-4.5', 'opus-4.5'
77
85
  maxTokens: 4096,
@@ -84,12 +92,12 @@ Using mem0 backend requires mem0ai in your project dependencies.`)),console.log(
84
92
  },`,gemini:`
85
93
  gemini: {
86
94
  model: 'gemini-2.5-pro', // Options: 'auto', 'gemini-2.5-pro', 'gemini-2.5-flash'
87
- },`},m=t.agent,y=Object.entries(n).filter(([r])=>r!==m).map(([,r])=>r.split(`
88
- `).map(w=>w.trim()?` // ${w.trimStart()}`:w).join(`
95
+ },`},d=t.agent,y=Object.entries(o).filter(([i])=>i!==d).map(([,i])=>i.split(`
96
+ `).map(h=>h.trim()?` // ${h.trimStart()}`:h).join(`
89
97
  `)).join(`
90
98
  `);return`export default {
91
99
  // AI agent settings
92
- agent: {${n[m]}
100
+ agent: {${o[d]}
93
101
  ${y}
94
102
  strictMode: false,
95
103
  },
@@ -103,7 +111,7 @@ ${y}
103
111
 
104
112
  // Chat memory backend adapter (dolt | mem0)
105
113
  memory: {
106
- backend: '${l}',
114
+ backend: '${a}',
107
115
  },
108
116
 
109
117
  // Advanced: Override models per node (optional)
@@ -154,14 +162,14 @@ ${y}
154
162
  // Cloud sync - auto-upload test results & videos (requires ZIBBY_API_KEY in .env)
155
163
  cloudSync: ${t.cloudSync||!1}
156
164
  };
157
- `}function Oe(t,e="dolt"){return`# Zibby Test Automation - Environment Variables
165
+ `}function Je(t,e="dolt"){return`# Zibby Test Automation - Environment Variables
158
166
 
159
167
  # AI Provider Keys
160
168
  ${{claude:"ANTHROPIC_API_KEY=sk-ant-your_key_here",cursor:`# Cursor Agent uses cursor-agent CLI \u2014 no API key needed
161
169
  # Install: curl https://cursor.com/install -fsS | bash`,codex:"OPENAI_API_KEY=sk-your_key_here",gemini:"GEMINI_API_KEY=your_key_here"}[t.agent]||""}
162
170
 
163
171
  # Zibby Cloud Sync (for uploading test results & videos)
164
- # Get your API key from: https://zibby.app/settings/tokens
172
+ # Get your API key from: https://zibby.dev/settings/tokens
165
173
  # ZIBBY_API_KEY=zby_your_api_key_here
166
174
 
167
175
  # Test Memory (Dolt DB) - Auto-compaction settings
@@ -171,7 +179,7 @@ ${{claude:"ANTHROPIC_API_KEY=sk-ant-your_key_here",cursor:`# Cursor Agent uses c
171
179
 
172
180
  # Chat memory backend
173
181
  ZIBBY_MEMORY_BACKEND=${e}
174
- `}function De(t,e,a="dolt"){return`# Zibby Test Automation - Environment Variables
182
+ `}function Xe(t,e,s="dolt"){return`# Zibby Test Automation - Environment Variables
175
183
 
176
184
  # AI Provider Keys
177
185
  ${{claude:"ANTHROPIC_API_KEY=sk-ant-your_key_here",cursor:"# Cursor Agent uses cursor-agent CLI \u2014 no API key needed",codex:"OPENAI_API_KEY=sk-your_key_here",gemini:"GEMINI_API_KEY=your_key_here"}[t.agent]||""}
@@ -185,8 +193,8 @@ ZIBBY_API_KEY=${e}
185
193
  # ZIBBY_MEMORY_COMPACT_EVERY=1500 # Auto-compact every N runs (0 to disable)
186
194
 
187
195
  # Chat memory backend
188
- ZIBBY_MEMORY_BACKEND=${a}
189
- `}function Le(t,e,a={}){let n={"@zibby/cli":"latest","@zibby/core":ue("../../package.json").dependencies?.["@zibby/core"]||"latest"};return a.memoryBackend==="mem0"&&(n.mem0ai="^2.4.6"),JSON.stringify({name:t,version:"1.0.0",type:"module",private:!0,scripts:{"test:spec":"zibby run",test:"playwright test","test:headed":"playwright test --headed"},dependencies:n,devDependencies:{"@playwright/test":"^1.49.0",dotenv:"^17.2.3"}},null,2)}function Ne(){return`# Dependencies
196
+ ZIBBY_MEMORY_BACKEND=${s}
197
+ `}function Qe(t,e,s={}){let o={"@zibby/cli":"latest","@zibby/core":ve("../../package.json").dependencies?.["@zibby/core"]||"latest"};return s.memoryBackend==="mem0"&&(o.mem0ai="^2.4.6"),JSON.stringify({name:t,version:"1.0.0",type:"module",private:!0,scripts:{"test:spec":"zibby run",test:"playwright test","test:headed":"playwright test --headed"},dependencies:o,devDependencies:{"@playwright/test":"^1.49.0",dotenv:"^17.2.3"}},null,2)}function et(){return`# Dependencies
190
198
  node_modules/
191
199
 
192
200
  # Test artifacts
@@ -214,7 +222,7 @@ Thumbs.db
214
222
  # Zibby memory (Dolt DB synced separately via dolt remote, not git)
215
223
  .zibby/memory/
216
224
  .zibby/memory-context.md
217
- `}function Ze(t="off",e=null){return`import { defineConfig} from '@playwright/test';
225
+ `}function tt(t="off",e=null){return`import { defineConfig} from '@playwright/test';
218
226
 
219
227
  export default defineConfig({
220
228
  testDir: './tests',
@@ -236,7 +244,7 @@ ${e?` outputDir: '${e}',
236
244
  ['list']
237
245
  ],
238
246
  });
239
- `}function Ve(){return`Test Specification: Example Domain Navigation
247
+ `}function ot(){return`Test Specification: Example Domain Navigation
240
248
  ==============================================
241
249
 
242
250
  Application: Example Domain
@@ -273,7 +281,7 @@ Notes:
273
281
  - Uses a stable, public domain (example.com) maintained by IANA
274
282
  - No authentication required
275
283
  - Suitable for CI/CD smoke testing
276
- `}function Ge(){return`# Example command template
284
+ `}function nt(){return`# Example command template
277
285
 
278
286
  Use this command when the user asks for a concise testing task breakdown.
279
287
 
@@ -284,7 +292,7 @@ Required output format:
284
292
  4. Expected result
285
293
 
286
294
  Keep the response actionable and short.
287
- `}function He(t,e){return`# ${t}
295
+ `}function st(t,e){return`# ${t}
288
296
 
289
297
  AI-powered test automation with Zibby.
290
298
 
@@ -373,4 +381,4 @@ ${t}/
373
381
 
374
382
  - Documentation: https://docs.zibby.dev
375
383
  - Examples: https://github.com/zibby/examples
376
- `}export{je as generateConfig,ft as initCommand};
384
+ `}export{qe as generateConfig,Kt as initCommand};
@@ -1,11 +1,11 @@
1
- import s from"chalk";import C from"ora";var r={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.app",description:"Production environment"}};function u(){let o;if(process.env.ZIBBY_API_URL)o=process.env.ZIBBY_API_URL;else{let n=process.env.ZIBBY_ENV||"prod";r[n]?o=r[n].apiUrl:o=r.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)`),r.prod.apiUrl):o}catch{return console.error(`\u26A0\uFE0F Invalid API URL: ${o}`),r.prod.apiUrl}}import{existsSync as g,mkdirSync as A,readFileSync as E,writeFileSync as $}from"fs";import{homedir as U}from"os";import{join as i}from"path";function m(){return process.env.ZIBBY_CONFIG_DIR||i(U(),".zibby")}function I(){return i(m(),"config.json")}var L=i(U(),".zibby"),F=i(L,"config.json");function T(){let o=m();g(o)||A(o,{recursive:!0})}function d(){try{let o=I();if(g(o)){let n=E(o,"utf-8");return JSON.parse(n)}}catch{}return{}}function k(o){T(),$(I(),JSON.stringify(o,null,2))}function h(){return d().sessionToken||null}function y(){return d().user||null}function _(o){let n=d();n.projects=o,k(n)}async function G(){let o=C("Fetching projects...").start();try{let n=h(),c=y();n||(o.fail("Not logged in"),console.log(s.yellow(`
1
+ import s from"chalk";import C from"ora";var r={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 u(){let o;if(process.env.ZIBBY_API_URL)o=process.env.ZIBBY_API_URL;else{let n=process.env.ZIBBY_ENV||"prod";r[n]?o=r[n].apiUrl:o=r.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)`),r.prod.apiUrl):o}catch{return console.error(`\u26A0\uFE0F Invalid API URL: ${o}`),r.prod.apiUrl}}import{existsSync as g,mkdirSync as A,readFileSync as E,writeFileSync as $}from"fs";import{homedir as U}from"os";import{join as i}from"path";function m(){return process.env.ZIBBY_CONFIG_DIR||i(U(),".zibby")}function I(){return i(m(),"config.json")}var L=i(U(),".zibby"),Z=i(L,"config.json");function T(){let o=m();g(o)||A(o,{recursive:!0})}function f(){try{let o=I();if(g(o)){let n=E(o,"utf-8");return JSON.parse(n)}}catch{}return{}}function k(o){T(),$(I(),JSON.stringify(o,null,2))}function h(){return f().sessionToken||null}function v(){return f().user||null}function y(o){let n=f();n.projects=o,k(n)}async function G(){let o=C("Fetching projects...").start();try{let n=h(),c=v();n||(o.fail("Not logged in"),console.log(s.yellow(`
2
2
  Please log in first:`)),console.log(s.gray(` zibby login
3
3
  `)),process.exit(1)),c&&(console.log(s.gray(`Logged in as: ${c.email}`)),c.account_id&&console.log(s.gray(`Account ID: ${c.account_id}
4
- `)));let v=u(),p=await fetch(`${v}/projects`,{headers:{Authorization:`Bearer ${n}`}});if(!p.ok){let e=await p.json().catch(()=>({}));throw new Error(e.error||"Failed to fetch projects")}let t=(await p.json()).projects||[],j=t.map(e=>({name:e.name,projectId:e.projectId,apiToken:e.apiToken}));if(_(j),o.stop(),t.length===0){console.log(`
5
- No projects found`),console.log(`Create a project at: https://zibby.app/projects
6
- `);return}let x=e=>e&&e.length>8?`${e.substring(0,8)}\u2022\u2022\u2022\u2022`:e||"-",l=Math.max(4,...t.map(e=>e.name.length)),a=36,f=14,B=` ${"Name".padEnd(l)} ${"Project ID".padEnd(a)} ${"API Token".padEnd(f)}`,P=` ${"\u2500".repeat(l)} ${"\u2500".repeat(a)} ${"\u2500".repeat(f)}`;console.log(`
4
+ `)));let _=u(),l=await fetch(`${_}/projects`,{headers:{Authorization:`Bearer ${n}`}});if(!l.ok){let e=await l.json().catch(()=>({}));throw new Error(e.error||"Failed to fetch projects")}let t=(await l.json()).projects||[],b=t.map(e=>({name:e.name,projectId:e.projectId,apiToken:e.apiToken}));if(y(b),o.stop(),t.length===0){console.log(`
5
+ No projects found`),console.log(`Create a project at: https://zibby.dev/projects
6
+ `);return}let j=e=>e&&e.length>8?`${e.substring(0,8)}\u2022\u2022\u2022\u2022`:e||"-",p=Math.max(4,...t.map(e=>e.name.length)),a=36,d=14,x=` ${"Name".padEnd(p)} ${"Project ID".padEnd(a)} ${"API Token".padEnd(d)}`,B=` ${"\u2500".repeat(p)} ${"\u2500".repeat(a)} ${"\u2500".repeat(d)}`;console.log(`
7
7
  Your Projects (${t.length})
8
- `),console.log(B),console.log(P);for(let e of t){let N=e.name.padEnd(l),b=e.projectId.padEnd(a),R=x(e.apiToken).padEnd(f);console.log(` ${N} ${b} ${R}`)}console.log(""),console.log("\u{1F4A1} Use the Project ID with --project flag:"),console.log(` zibby run test-specs/login.txt --project <project-id> --sync
8
+ `),console.log(x),console.log(B);for(let e of t){let P=e.name.padEnd(p),N=e.projectId.padEnd(a),R=j(e.apiToken).padEnd(d);console.log(` ${P} ${N} ${R}`)}console.log(""),console.log("\u{1F4A1} Use the Project ID with --project flag:"),console.log(` zibby run test-specs/login.txt --project <project-id> --sync
9
9
  `)}catch(n){o.fail("Failed to fetch projects"),console.error(s.red(`
10
10
  \u274C Error: ${n.message}
11
11
  `)),process.exit(1)}}export{G as listProjectsCommand};
@@ -1,39 +1,49 @@
1
1
  import o from"chalk";var y=`
2
- Install @zibby/memory and Dolt to enable test memory:
2
+ Install @zibby/ui-memory and Dolt to enable test memory:
3
3
 
4
- npm install @zibby/memory # add the package
4
+ npm install @zibby/ui-memory # add the package
5
5
  brew install dolt # macOS
6
6
  # or: curl -L https://github.com/dolthub/dolt/releases/latest/download/install.sh | bash
7
- `;async function d(){try{return await import("@zibby/memory")}catch{return console.log(o.yellow(`
8
- @zibby/memory is not installed.
9
- `)),console.log(o.white(y)),null}}async function h(){let s=await d();if(!s)return;let l=process.cwd(),e=s.getStats(l);if(!e.available){console.log(o.red(`
7
+ `;async function d(){try{return await import("@zibby/ui-memory")}catch{return console.log(o.yellow(`
8
+ @zibby/ui-memory is not installed.
9
+ `)),console.log(o.white(y)),null}}async function p(){let t=await d();if(!t)return;let c=process.cwd(),n=t.getStats(c);if(!n.available){console.log(o.red(`
10
10
  Dolt is not installed.
11
11
  `)),console.log(o.white(" Install Dolt to enable test memory:")),console.log(o.gray(" brew install dolt # macOS")),console.log(o.gray(` curl -L https://github.com/dolthub/dolt/releases/latest/download/install.sh | bash # Linux
12
- `));return}if(!e.initialized){console.log(o.yellow(`
12
+ `));return}if(!n.initialized){console.log(o.yellow(`
13
13
  Memory database not initialized.
14
14
  `)),console.log(o.white(" Run `zibby init` or `zibby memory init` to set it up.\n"));return}console.log(o.bold.cyan(`
15
15
  Zibby Test Memory
16
- `)),console.log(o.gray(` Dolt: ${e.doltVersion}`));let a=o.gray(` ${"\u2500".repeat(40)}`);console.log(a);let n=e.counts;if(console.log(o.white(` Test runs: ${o.cyan(n.runs)} (${o.green(`${n.passed} passed`)}, ${n.failed>0?o.red(`${n.failed} failed`):o.gray(`${n.failed} failed`)})`)),console.log(o.white(` Selectors: ${o.cyan(n.selectors)} tracked`)),console.log(o.white(` Pages: ${o.cyan(n.pages)} discovered`)),console.log(o.white(` Transitions: ${o.cyan(n.transitions)} mapped`)),console.log(o.white(` Insights: ${o.cyan(n.insights||0)} saved`)),e.recentRuns.length>0){console.log(`
17
- ${a}`),console.log(o.white(" Recent runs:"));for(let t of e.recentRuns){let c=t.passed?o.green("\u2713"):o.red("\u2717"),r=t.duration_ms?o.gray(`${(t.duration_ms/1e3).toFixed(1)}s`):"";console.log(` ${c} ${o.white(t.spec_path)} ${r}`)}}if(e.topSelectors.length>0){console.log(`
18
- ${a}`),console.log(o.white(" Top selectors:"));for(let t of e.topSelectors){let c=t.success_count+t.failure_count,r=Math.round(t.success_count/c*100);console.log(` ${o.cyan(t.stable_id||"?")} \u2192 ${t.element_desc} (${r}%, ${c} uses)`)}}if(e.log){console.log(`
19
- ${a}`),console.log(o.white(" Recent commits:"));let t=e.log.split(`
20
- `).filter(c=>c.startsWith("commit")||c.trim().startsWith("run ")).slice(0,10);for(let c of t)console.log(o.gray(` ${c.trim()}`))}console.log("")}async function f(s){let l=await d();if(!l)return;let e=process.cwd();if(!s.force){console.log(o.yellow(`
16
+ `)),console.log(o.gray(` Dolt: ${n.doltVersion}`));let a=o.gray(` ${"\u2500".repeat(40)}`);console.log(a);let s=n.counts;if(console.log(o.white(` Test runs: ${o.cyan(s.runs)} (${o.green(`${s.passed} passed`)}, ${s.failed>0?o.red(`${s.failed} failed`):o.gray(`${s.failed} failed`)})`)),console.log(o.white(` Selectors: ${o.cyan(s.selectors)} tracked`)),console.log(o.white(` Pages: ${o.cyan(s.pages)} discovered`)),console.log(o.white(` Transitions: ${o.cyan(s.transitions)} mapped`)),console.log(o.white(` Insights: ${o.cyan(s.insights||0)} saved`)),n.recentRuns.length>0){console.log(`
17
+ ${a}`),console.log(o.white(" Recent runs:"));for(let e of n.recentRuns){let l=e.passed?o.green("\u2713"):o.red("\u2717"),g=e.duration_ms?o.gray(`${(e.duration_ms/1e3).toFixed(1)}s`):"";console.log(` ${l} ${o.white(e.spec_path)} ${g}`)}}if(n.topSelectors.length>0){console.log(`
18
+ ${a}`),console.log(o.white(" Top selectors:"));for(let e of n.topSelectors){let l=e.success_count+e.failure_count,g=Math.round(e.success_count/l*100);console.log(` ${o.cyan(e.stable_id||"?")} \u2192 ${e.element_desc} (${g}%, ${l} uses)`)}}if(n.log){console.log(`
19
+ ${a}`),console.log(o.white(" Recent commits:"));let e=n.log.split(`
20
+ `).filter(l=>l.startsWith("commit")||l.trim().startsWith("run ")).slice(0,10);for(let l of e)console.log(o.gray(` ${l.trim()}`))}console.log("")}async function f(t){let c=await d();if(!c)return;let n=process.cwd();if(!t.force){console.log(o.yellow(`
21
21
  This will permanently delete the memory database.
22
22
  `)),console.log(o.white(` Run with --force to confirm: zibby memory reset --force
23
- `));return}let a=l.resetMemory(e);console.log(a?o.green(`
23
+ `));return}let a=c.resetMemory(n);console.log(a?o.green(`
24
24
  Memory database reset.
25
25
  `):o.gray(`
26
26
  No memory database found.
27
- `))}async function b(s){let l=await d();if(!l)return;let e=process.cwd(),a=l.getStats(e);if(!a.initialized){console.log(o.yellow(`
27
+ `))}async function b(t){let c=await d();if(!c)return;let n=process.cwd(),a=c.getStats(n);if(!a.initialized){console.log(o.yellow(`
28
28
  Memory database not initialized.
29
- `));return}let n=s.maxRuns||50,t=s.maxAge||90;console.log(o.white(`
30
- Compacting memory (keep last ${n} runs/spec, prune data older than ${t}d)...`));let c=a.counts;if(l.compactMemory(e,{maxRuns:n,maxAgeDays:t}).pruned){let m=l.getStats(e).counts,i=g=>c[g]-m[g];console.log(o.green(" Done.")),i("runs")>0&&console.log(o.gray(` Pruned ${i("runs")} old runs`)),i("selectors")>0&&console.log(o.gray(` Pruned ${i("selectors")} stale selectors`)),i("insights")>0&&console.log(o.gray(` Pruned ${i("insights")} old insights`)),i("transitions")>0&&console.log(o.gray(` Pruned ${i("transitions")} stale transitions`)),console.log(o.gray(` Dolt GC completed
29
+ `));return}let s=t.maxRuns||50,e=t.maxAge||90;console.log(o.white(`
30
+ Compacting memory (keep last ${s} runs/spec, prune data older than ${e}d)...`));let l=a.counts;if(c.compactMemory(n,{maxRuns:s,maxAgeDays:e}).pruned){let u=c.getStats(n).counts,r=m=>l[m]-u[m];console.log(o.green(" Done.")),r("runs")>0&&console.log(o.gray(` Pruned ${r("runs")} old runs`)),r("selectors")>0&&console.log(o.gray(` Pruned ${r("selectors")} stale selectors`)),r("insights")>0&&console.log(o.gray(` Pruned ${r("insights")} old insights`)),r("transitions")>0&&console.log(o.gray(` Pruned ${r("transitions")} stale transitions`)),console.log(o.gray(` Dolt GC completed
31
31
  `))}else console.log(o.gray(` Nothing to compact.
32
- `))}async function p(){let s=await d();if(!s)return;let l=process.cwd();if(!s.DoltDB.isAvailable()){console.log(o.red(`
32
+ `))}async function $(){let t=await d();if(!t)return;let c=process.cwd(),n=t.getCostStats(c);if(!n){console.log(o.yellow(`
33
+ Memory database not initialized.
34
+ `)),console.log(o.white(" Run `zibby memory init` first.\n"));return}if(n.available===!1){console.log(o.yellow(`
35
+ No usage data yet${n.reason?` (${n.reason})`:""}.
36
+ `)),console.log(o.gray(" Run `zibby test <spec>` once to populate. Token counts come from")),console.log(o.gray(` the LLM SDK and are written to .zibby/output/sessions/<id>/execute_live/usage.json.
37
+ `));return}console.log(o.bold.cyan(`
38
+ Zibby \u2014 LLM Cost Report
39
+ `));let a=o.gray(` ${"\u2500".repeat(60)}`),s=n.totals;if(console.log(a),console.log(o.white(` Runs with usage data: ${o.cyan(s.runs)}`)),console.log(o.white(` Total input tokens: ${o.cyan(i(s.input))}`)),console.log(o.white(` Total output tokens: ${o.cyan(i(s.output))}`)),console.log(o.white(` Total cache reads: ${o.cyan(i(s.cache_read))} ${o.gray("(billed at ~10% of normal input rate)")}`)),console.log(o.white(` Total cache creation: ${o.cyan(i(s.cache_creation))} ${o.gray("(billed at ~125% of normal input rate)")}`)),n.by_domain.length>0){console.log(`
40
+ ${a}`),console.log(o.white(" By domain:"));for(let e of n.by_domain.slice(0,10)){let l=e.runs>0?Math.round((e.input+e.output)/e.runs):0;console.log(` ${o.cyan(e.domain.padEnd(30))} ${o.gray(`${e.runs} runs \xB7 ~${i(l)}/run avg`)}`)}}if(n.by_spec.length>0){console.log(`
41
+ ${a}`),console.log(o.white(" By spec:"));for(let e of n.by_spec.slice(0,10)){let l=e.runs>0?Math.round((e.input+e.output)/e.runs):0;console.log(` ${o.cyan(String(e.spec_path).padEnd(40))} ${o.gray(`${e.runs} runs \xB7 ~${i(l)}/run avg`)}`)}}if(n.recent.length>0){console.log(`
42
+ ${a}`),console.log(o.white(" Last 10 runs:"));for(let e of n.recent.slice(0,10)){let l=e.passed?o.green("\u2713"):o.red("\u2717"),g=(e.input_tokens||0)+(e.output_tokens||0),u=(e.cache_read_tokens||0)>0?o.gray(` \xB7 cache read ${i(e.cache_read_tokens)}`):"";console.log(` ${l} ${o.gray(e.run_at.slice(0,16))} ${o.cyan(i(g).padStart(8))} ${o.white(e.spec_path||"")}${u}`)}}console.log("")}function i(t){return t==null?"\u2014":t<1e3?String(t):t<1e6?`${(t/1e3).toFixed(1)}K`:`${(t/1e6).toFixed(2)}M`}async function w(){let t=await d();if(!t)return;let c=process.cwd();if(!t.DoltDB.isAvailable()){console.log(o.red(`
33
43
  Dolt is not installed.
34
44
  `)),console.log(o.white(" Install Dolt:")),console.log(o.gray(" brew install dolt # macOS")),console.log(o.gray(` curl -L https://github.com/dolthub/dolt/releases/latest/download/install.sh | bash # Linux
35
- `));return}let{created:e,available:a}=s.initMemory(l);e?console.log(o.green(`
45
+ `));return}let{created:n,available:a}=t.initMemory(c);n?console.log(o.green(`
36
46
  Memory database initialized at .zibby/memory/
37
47
  `)):a&&console.log(o.gray(`
38
48
  Memory database already initialized.
39
- `))}export{b as memoryCompactCommand,p as memoryInitCommand,f as memoryResetCommand,h as memoryStatsCommand};
49
+ `))}export{b as memoryCompactCommand,$ as memoryCostCommand,w as memoryInitCommand,f as memoryResetCommand,p as memoryStatsCommand};
@@ -1,6 +1,6 @@
1
- import a from"dotenv";var s={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.app",description:"Production environment"}};function c(){let r;if(process.env.ZIBBY_API_URL)r=process.env.ZIBBY_API_URL;else{let e=process.env.ZIBBY_ENV||"prod";s[e]?r=s[e].apiUrl:r=s.prod.apiUrl}try{let e=new URL(r);return e.protocol!=="http:"&&e.protocol!=="https:"?(console.error(`\u26A0\uFE0F Invalid API URL protocol: ${e.protocol} (only http/https allowed)`),s.prod.apiUrl):r}catch{return console.error(`\u26A0\uFE0F Invalid API URL: ${r}`),s.prod.apiUrl}}a.config();function d(r){let e=r.apiKey||process.env.ZIBBY_API_KEY;return e||(console.log(`
1
+ import a from"dotenv";var s={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 c(){let r;if(process.env.ZIBBY_API_URL)r=process.env.ZIBBY_API_URL;else{let e=process.env.ZIBBY_ENV||"prod";s[e]?r=s[e].apiUrl:r=s.prod.apiUrl}try{let e=new URL(r);return e.protocol!=="http:"&&e.protocol!=="https:"?(console.error(`\u26A0\uFE0F Invalid API URL protocol: ${e.protocol} (only http/https allowed)`),s.prod.apiUrl):r}catch{return console.error(`\u26A0\uFE0F Invalid API URL: ${r}`),s.prod.apiUrl}}a.config();function d(r){let e=r.apiKey||process.env.ZIBBY_API_KEY;return e||(console.log(`
2
2
  Error: API key is required`),console.log(` Set ZIBBY_API_KEY environment variable or use --api-key flag
3
- `),process.exit(1)),{apiKey:e}}async function _(r={}){let{apiKey:e}=d(r),p=c();try{let t=await fetch(`${p}/projects`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`}});if(!t.ok){let n=await t.json().catch(()=>({}));console.log(`
3
+ `),process.exit(1)),{apiKey:e}}async function v(r={}){let{apiKey:e}=d(r),p=c();try{let t=await fetch(`${p}/projects`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`}});if(!t.ok){let n=await t.json().catch(()=>({}));console.log(`
4
4
  Error: ${n.message||t.statusText}
5
5
  `),process.exit(1)}let o=await t.json();if(Array.isArray(o)||(o.projects&&Array.isArray(o.projects)?o=o.projects:o.data&&Array.isArray(o.data)?o=o.data:(console.log(`
6
6
  Error: Unexpected response format
@@ -12,4 +12,4 @@ import a from"dotenv";var s={local:{name:"Local Development",apiUrl:"http://loca
12
12
  Total: ${o.length} project${o.length===1?"":"s"}
13
13
  `)}catch(t){console.log(`
14
14
  Error: ${t.message}
15
- `),process.exit(1)}}export{_ as projectListCommand};
15
+ `),process.exit(1)}}export{v as projectListCommand};