@zibby/cli 0.4.14 → 0.4.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,42 +1,42 @@
1
- import e from"chalk";import{readFileSync as j,existsSync as O,writeSync as B}from"fs";import{homedir as F}from"os";import{join as z}from"path";var A="https://logs.workflows.zibby.app",J="https://logs-stream.zibby.app/",v=null;async function U(a){return v||(process.env.ZIBBY_SSE_ENDPOINT?(v=process.env.ZIBBY_SSE_ENDPOINT,v):(v=J,v))}function G(a){let t=z(F(),".zibby","config.json");O(t)||(console.log(e.red(`
1
+ import e from"chalk";import{readFileSync as j,existsSync as O,writeSync as B}from"fs";import{homedir as F}from"os";import{join as z}from"path";var A="https://logs.workflows.zibby.app",J="https://logs-stream.zibby.app/",v=null;async function U(i){return v||(process.env.ZIBBY_SSE_ENDPOINT?(v=process.env.ZIBBY_SSE_ENDPOINT,v):(v=J,v))}function G(i){let t=z(F(),".zibby","config.json");O(t)||(console.log(e.red(`
2
2
  Not authenticated`)),console.log(e.gray(` Run: zibby login
3
3
  `)),process.exit(1));let o;try{o=JSON.parse(j(t,"utf-8"))}catch{console.log(e.red(`
4
4
  Config file corrupt`)),console.log(e.gray(` Run: zibby login
5
5
  `)),process.exit(1)}let n=o.sessionToken;n||(console.log(e.red(`
6
6
  Not authenticated`)),console.log(e.gray(` Run: zibby login
7
- `)),process.exit(1));let u=a.project;return{token:n,projectId:u}}function C(a){let t=new Date(a);if(process.env.ZIBBY_LOGS_UTC==="1")return t.toISOString().replace("T"," ").replace("Z","");let o=(n,u=2)=>String(n).padStart(u,"0");return`${t.getFullYear()}-${o(t.getMonth()+1)}-${o(t.getDate())} ${o(t.getHours())}:${o(t.getMinutes())}:${o(t.getSeconds())}.${o(t.getMilliseconds(),3)}`}async function L(a,t){let o=await fetch(a,{headers:{Authorization:`Bearer ${t}`}});if(!o.ok){let n=await o.text();throw new Error(`API ${o.status}: ${n}`)}return o.json()}async function W(a,t,o,n){return a||(console.log(e.red(`
7
+ `)),process.exit(1));let u=i.project;return{token:n,projectId:u}}function C(i){let t=new Date(i);if(process.env.ZIBBY_LOGS_UTC==="1")return t.toISOString().replace("T"," ").replace("Z","");let o=(n,u=2)=>String(n).padStart(u,"0");return`${t.getFullYear()}-${o(t.getMonth()+1)}-${o(t.getDate())} ${o(t.getHours())}:${o(t.getMinutes())}:${o(t.getSeconds())}.${o(t.getMilliseconds(),3)}`}async function L(i,t){let o=await fetch(i,{headers:{Authorization:`Bearer ${t}`}});if(!o.ok){let n=await o.text();throw new Error(`API ${o.status}: ${n}`)}return o.json()}async function W(i,t,o,n){return i||(console.log(e.red(`
8
8
  Workflow UUID is required`)),console.log(e.gray(" Usage: zibby workflow logs <workflow-uuid>")),console.log(e.gray(` zibby workflow logs <workflow-uuid> -t
9
- `)),process.exit(1)),a}function D(a,t){let n=((a||"")+t).split(`
10
- `),u=n.pop()||"",i=[],f=null,s=null;for(let m=0;m<n.length;m++){let l=n[m];if(l.trim()){if(l.startsWith("id:")){f=l.slice(3).trim();continue}if(l.startsWith("event:")){let g=l.slice(6).trim();if(g==="log")continue;if(g==="status"){let c=n[m+1];if(c&&c.startsWith("data:"))try{let h=JSON.parse(c.slice(5).trim());h.status==="new_execution"?i.push({type:"newExecution",executionId:h.executionId,taskId:h.taskId}):h.status==="waiting"&&i.push({type:"waiting"})}catch{}continue}if(g==="complete"){i.push({type:"complete"});continue}if(g==="error"){let c=n[m+1];if(c&&c.startsWith("data:"))try{if(JSON.parse(c.slice(5).trim()).error==="No executions found for workflow"){s={type:"notFound"};break}}catch{}s={type:"failed"};break}continue}if(l.startsWith("data:")){let g=l.slice(5).trim();if(!g)continue;try{let c=JSON.parse(g);c.timestamp&&c.message&&i.push({type:"log",timestamp:c.timestamp,message:c.message,taskId:c.taskId})}catch{}}}}return{actions:i,remainder:u,lastEventId:f,returnSignal:s}}async function Y({token:a,executionId:t,sseEndpoint:o,stopped:n}){let u=null;try{let y=function(){let b=Array.from(I.entries()).slice(0,c);I.clear();for(let[w,p]of b)I.set(w,p);r=new Set(Array.from(I.values()).map(w=>w.taskId).filter(Boolean));for(let w of[...d.keys()])I.has(w)||d.delete(w)},x=function(S){for(let[b,w]of I)if(w.taskId===S)return b;return null},T=function(S){let b=I.get(S);!b||b.headerPrinted||(console.log(e.cyan(`
9
+ `)),process.exit(1)),i}function D(i,t){let n=((i||"")+t).split(`
10
+ `),u=n.pop()||"",a=[],f=null,s=null;for(let m=0;m<n.length;m++){let l=n[m];if(l.trim()){if(l.startsWith("id:")){f=l.slice(3).trim();continue}if(l.startsWith("event:")){let g=l.slice(6).trim();if(g==="log")continue;if(g==="status"){let c=n[m+1];if(c&&c.startsWith("data:"))try{let h=JSON.parse(c.slice(5).trim());h.status==="new_execution"?a.push({type:"newExecution",executionId:h.executionId,taskId:h.taskId}):h.status==="waiting"&&a.push({type:"waiting"})}catch{}continue}if(g==="complete"){a.push({type:"complete"});continue}if(g==="error"){let c=n[m+1];if(c&&c.startsWith("data:"))try{if(JSON.parse(c.slice(5).trim()).error==="No executions found for workflow"){s={type:"notFound"};break}}catch{}s={type:"failed"};break}continue}if(l.startsWith("data:")){let g=l.slice(5).trim();if(!g)continue;try{let c=JSON.parse(g);c.timestamp&&c.message&&a.push({type:"log",timestamp:c.timestamp,message:c.message,taskId:c.taskId})}catch{}}}}return{actions:a,remainder:u,lastEventId:f,returnSignal:s}}async function Y({token:i,executionId:t,sseEndpoint:o,stopped:n}){let u=null;try{let y=function(){let b=Array.from(I.entries()).slice(0,c);I.clear();for(let[w,p]of b)I.set(w,p);r=new Set(Array.from(I.values()).map(w=>w.taskId).filter(Boolean));for(let w of[...d.keys()])I.has(w)||d.delete(w)},x=function(S){for(let[b,w]of I)if(w.taskId===S)return b;return null},T=function(S){let b=I.get(S);!b||b.headerPrinted||(console.log(e.cyan(`
11
11
  \u250C\u2500 Execution: ${b.shortId} (task: ${b.taskSuffix})`)),console.log(e.cyan(` \u2514\u2500 Streaming logs...
12
- `)),b.headerPrinted=!0)},P=function(S){let b=e.gray(C(S.timestamp)),w=S.taskId?e.gray(`(${S.taskId.slice(-8)}) `):"";console.log(`${b} ${w}${S.message.replace(/\n$/,"")}`)},_=function(){if(!k)return;k=!1,$&&(clearTimeout($),$=null);let S=Array.from(I.entries()).reverse();for(let[b]of S){let w=d.get(b);if(!(!w||w.length===0)){T(b);for(let p of w)P(p)}}d.clear()},N=function(){k&&($&&clearTimeout($),$=setTimeout(_,h))},i=new URL(o);i.searchParams.set("jobId",t),u&&i.searchParams.set("lastEventId",u);let f=await fetch(i.toString(),{headers:{Authorization:`Bearer ${a}`,Accept:"text/event-stream"}});if(!f.ok)throw new Error(`SSE connection failed: ${f.status} ${f.statusText}`);let s=f.body.getReader(),m=new TextDecoder,l="",g=!1,c=Number(process.env.ZIBBY_LOGS_HISTORY_LIMIT)||10,h=Number(process.env.ZIBBY_LOGS_REPLAY_TIMEOUT_MS)||3e3,I=new Map,r=new Set,d=new Map,k=!0,$=null;for(N();!n.value;){let{done:S,value:b}=await s.read();if(S)break;let w=D(l,m.decode(b,{stream:!0}));l=w.remainder,w.lastEventId&&(u=w.lastEventId);for(let p of w.actions)switch(p.type){case"newExecution":{let E=`${p.executionId.slice(0,8)}...${p.executionId.slice(-4)}`,R=p.taskId?p.taskId.slice(-8):"pending";I.set(p.executionId,{shortId:E,taskSuffix:R,taskId:p.taskId||null,headerPrinted:!1}),d.has(p.executionId)||d.set(p.executionId,[]),y(),N();break}case"waiting":_(),console.log(e.gray(`
13
- Waiting for next execution...`));break;case"complete":_(),g=!0;break;case"log":{if(p.taskId&&r.size>0&&!r.has(p.taskId))break;if(k){let E=p.taskId?x(p.taskId):null;if(E){let R=d.get(E)||[];R.push(p),d.set(E,R),N()}else P(p)}else{if(p.taskId){let E=x(p.taskId);E&&T(E)}P(p)}break}}if(w.returnSignal)return w.returnSignal.type==="notFound"?{notFound:!0}:{failed:!0}}return _(),{completed:g}}catch(i){if(i.name==="AbortError")return{aborted:!0};throw i}}function H(a,{baseMs:t=500,capMs:o=3e4,rand:n=Math.random}={}){let u=Math.min(o,t*Math.pow(2,Math.max(0,a)));return Math.floor(n()*u)}async function Z({attemptStream:a,stopped:t,follow:o,logger:n,sleep:u=m=>new Promise(l=>setTimeout(l,m)),exit:i=m=>{throw new Error(`exit:${m}`)},backoff:f=H,notFoundPollMs:s=5e3}){let m=0,l=!1;for(;!t.value;){let g;try{g=await a(),m=0}catch(c){if(c.name==="AbortError"||t.value)return{reason:"aborted"};if(l||(n.error(` SSE Error: ${c.message}`),o&&n.gray(" Reconnecting..."),l=!0),!o)return i("error")??{reason:"error"};let h=f(m);m++,await u(h);continue}if(g.aborted||t.value)return{reason:"aborted"};if(g.notFound){if(o){l||(n.yellow(" No executions found yet. Waiting for workflow to be triggered..."),n.gray(" Press Ctrl+C to stop."),l=!0),await u(s);continue}return n.yellow(`
12
+ `)),b.headerPrinted=!0)},P=function(S){let b=e.gray(C(S.timestamp)),w=S.taskId?e.gray(`(${S.taskId.slice(-8)}) `):"";console.log(`${b} ${w}${S.message.replace(/\n$/,"")}`)},_=function(){if(!k)return;k=!1,$&&(clearTimeout($),$=null);let S=Array.from(I.entries()).reverse();for(let[b]of S){let w=d.get(b);if(!(!w||w.length===0)){T(b);for(let p of w)P(p)}}d.clear()},N=function(){k&&($&&clearTimeout($),$=setTimeout(_,h))},a=new URL(o);a.searchParams.set("jobId",t),u&&a.searchParams.set("lastEventId",u);let f=await fetch(a.toString(),{headers:{Authorization:`Bearer ${i}`,Accept:"text/event-stream"}});if(!f.ok)throw new Error(`SSE connection failed: ${f.status} ${f.statusText}`);let s=f.body.getReader(),m=new TextDecoder,l="",g=!1,c=Number(process.env.ZIBBY_LOGS_HISTORY_LIMIT)||10,h=Number(process.env.ZIBBY_LOGS_REPLAY_TIMEOUT_MS)||3e3,I=new Map,r=new Set,d=new Map,k=!0,$=null;for(N();!n.value;){let{done:S,value:b}=await s.read();if(S)break;let w=D(l,m.decode(b,{stream:!0}));l=w.remainder,w.lastEventId&&(u=w.lastEventId);for(let p of w.actions)switch(p.type){case"newExecution":{let E=`${p.executionId.slice(0,8)}...${p.executionId.slice(-4)}`,R=p.taskId?p.taskId.slice(-8):"pending";I.set(p.executionId,{shortId:E,taskSuffix:R,taskId:p.taskId||null,headerPrinted:!1}),d.has(p.executionId)||d.set(p.executionId,[]),y(),N();break}case"waiting":_(),console.log(e.gray(`
13
+ Waiting for next execution...`));break;case"complete":_(),g=!0;break;case"log":{if(p.taskId&&r.size>0&&!r.has(p.taskId))break;if(k){let E=p.taskId?x(p.taskId):null;if(E){let R=d.get(E)||[];R.push(p),d.set(E,R),N()}else P(p)}else{if(p.taskId){let E=x(p.taskId);E&&T(E)}P(p)}break}}if(w.returnSignal)return w.returnSignal.type==="notFound"?{notFound:!0}:{failed:!0}}return _(),{completed:g}}catch(a){if(a.name==="AbortError")return{aborted:!0};throw a}}function H(i,{baseMs:t=500,capMs:o=3e4,rand:n=Math.random}={}){let u=Math.min(o,t*Math.pow(2,Math.max(0,i)));return Math.floor(n()*u)}async function Z({attemptStream:i,stopped:t,follow:o,logger:n,sleep:u=m=>new Promise(l=>setTimeout(l,m)),exit:a=m=>{throw new Error(`exit:${m}`)},backoff:f=H,notFoundPollMs:s=5e3}){let m=0,l=!1;for(;!t.value;){let g;try{g=await i(),m=0}catch(c){if(c.name==="AbortError"||t.value)return{reason:"aborted"};if(l||(n.error(` SSE Error: ${c.message}`),o&&n.gray(" Reconnecting..."),l=!0),!o)return a("error")??{reason:"error"};let h=f(m);m++,await u(h);continue}if(g.aborted||t.value)return{reason:"aborted"};if(g.notFound){if(o){l||(n.yellow(" No executions found yet. Waiting for workflow to be triggered..."),n.gray(" Press Ctrl+C to stop."),l=!0),await u(s);continue}return n.yellow(`
14
14
  No executions found for this workflow. Trigger the workflow first.
15
- `),i("notFound")??{reason:"notFound"}}if(l&&(n.gray(` Reconnected.
15
+ `),a("notFound")??{reason:"notFound"}}if(l&&(n.gray(` Reconnected.
16
16
  `),l=!1),g.failed)return n.red(`
17
- Execution failed.`),o?{reason:"failed"}:i("failed")??{reason:"failed"};if(g.completed)return i("completed")??{reason:"completed"};if(!o)return{reason:"disconnected"}}return{reason:"stopped"}}async function V({token:a,jobId:t,follow:o,projectId:n}){console.log(e.gray(` Streaming logs for workflow ${e.cyan(t)}...`)),console.log(o?e.gray(` Press Ctrl+C to stop.
18
- `):"");let u=await U(a);if(!u)return console.log(e.yellow(` SSE endpoint not configured, using CloudWatch polling...
19
- `)),M({token:a,projectId:null,jobId:t,follow:o,limit:1e5});let i={value:!1},f=()=>{i.value=!0;try{B(2,`
17
+ Execution failed.`),o?{reason:"failed"}:a("failed")??{reason:"failed"};if(g.completed)return a("completed")??{reason:"completed"};if(!o)return{reason:"disconnected"}}return{reason:"stopped"}}async function V({token:i,jobId:t,follow:o,projectId:n}){console.log(e.gray(` Streaming logs for workflow ${e.cyan(t)}...`)),console.log(o?e.gray(` Press Ctrl+C to stop.
18
+ `):"");let u=await U(i);if(!u)return console.log(e.yellow(` SSE endpoint not configured, using CloudWatch polling...
19
+ `)),M({token:i,projectId:null,jobId:t,follow:o,limit:1e5});let a={value:!1},f=()=>{a.value=!0;try{B(2,`
20
20
  Stopped streaming.
21
- `)}catch{}process.exit(0)};process.prependListener("SIGINT",f),process.prependListener("SIGTERM",f),await Z({attemptStream:()=>Y({token:a,executionId:t,sseEndpoint:u,stopped:i}),stopped:i,follow:o,logger:{gray:s=>console.log(e.gray(s)),red:s=>console.log(e.red(s)),yellow:s=>console.log(e.yellow(s)),error:s=>console.error(e.red(s))},exit:s=>{s==="completed"&&process.exit(0),(s==="error"||s==="notFound"||s==="failed")&&process.exit(1)}})}async function M({token:a,projectId:t,jobId:o,follow:n,limit:u}){let i=t?`${A}/logs/${t}/${o}`:`${A}/job/${o}`,f=null,s=0,m=new Set,l=!1,g=0,c=5,h=()=>{l=!0,console.log(e.gray(`
21
+ `)}catch{}process.exit(0)};process.prependListener("SIGINT",f),process.prependListener("SIGTERM",f),await Z({attemptStream:()=>Y({token:i,executionId:t,sseEndpoint:u,stopped:a}),stopped:a,follow:o,logger:{gray:s=>console.log(e.gray(s)),red:s=>console.log(e.red(s)),yellow:s=>console.log(e.yellow(s)),error:s=>console.error(e.red(s))},exit:s=>{s==="completed"&&process.exit(0),(s==="error"||s==="notFound"||s==="failed")&&process.exit(1)}})}async function M({token:i,projectId:t,jobId:o,follow:n,limit:u}){let a=t?`${A}/logs/${t}/${o}`:`${A}/job/${o}`,f=null,s=0,m=new Set,l=!1,g=0,c=5,h=()=>{l=!0,console.log(e.gray(`
22
22
  Stopped tailing.
23
23
  `)),process.exit(0)};for(process.on("SIGINT",h),process.on("SIGTERM",h),console.log(e.gray(` Fetching logs for workflow ${e.cyan(o)}...`)),console.log(n?e.gray(` Press Ctrl+C to stop.
24
- `):"");!l;)try{let I=new URLSearchParams({limit:String(u)});f&&I.set("nextToken",f);let r=await L(`${i}?${I}`,a);g=0,r.message&&r.lines?.length===0&&s===0&&console.log(e.gray(` ${r.message}`)),r.status==="starting"&&r.lines?.length===0&&s===0&&console.log(e.gray(" Container starting..."));for(let y of r.lines||[]){let x=`${y.timestamp}:${y.message}`;if(m.has(x))continue;m.add(x);let T=e.gray(C(y.timestamp)),P=r.taskId?e.gray(`(${r.taskId.slice(-8)}) `):"";console.log(`${T} ${P}${y.message.replace(/\n$/,"")}`)}if(s=r.lines?.length>0?0:s+1,f=r.nextForwardToken||null,r.status==="completed"||r.status==="failed"){let y=r.status==="completed"?e.green:e.red;console.log(y(`
24
+ `):"");!l;)try{let I=new URLSearchParams({limit:String(u)});f&&I.set("nextToken",f);let r=await L(`${a}?${I}`,i);g=0,r.message&&r.lines?.length===0&&s===0&&console.log(e.gray(` ${r.message}`)),r.status==="starting"&&r.lines?.length===0&&s===0&&console.log(e.gray(" Container starting..."));for(let y of r.lines||[]){let x=`${y.timestamp}:${y.message}`;if(m.has(x))continue;m.add(x);let T=e.gray(C(y.timestamp)),P=r.taskId?e.gray(`(${r.taskId.slice(-8)}) `):"";console.log(`${T} ${P}${y.message.replace(/\n$/,"")}`)}if(s=r.lines?.length>0?0:s+1,f=r.nextForwardToken||null,r.status==="completed"||r.status==="failed"){let y=r.status==="completed"?e.green:e.red;console.log(y(`
25
25
  Job ${r.status}.`)),process.exit(r.status==="completed"?0:1)}if(!n){r.status&&console.log(e.gray(`
26
26
  Status: ${r.status}`));break}let $=r.lines?.length>0?500:s>5?5e3:2e3;await new Promise(y=>setTimeout(y,$))}catch(I){if(I.name==="AbortError")break;I.message.match(/API (400|401|403|404):/)&&(console.error(e.red(`
27
27
  ${I.message}
28
28
  `)),process.exit(1)),g++,console.error(e.red(` Error: ${I.message}`)),g>=c&&(console.error(e.red(`
29
29
  Too many consecutive errors (${c}). Stopping.
30
- `)),process.exit(1)),n||process.exit(1),await new Promise(d=>setTimeout(d,3e3))}}async function X({token:a,projectId:t,workflow:o,follow:n,limit:u}){let i=`${A}/all/${t}`,f=null,s=0,m=new Set,l=null,g=!1,c=0,h=5,I=()=>{g=!0,console.log(e.gray(`
30
+ `)),process.exit(1)),n||process.exit(1),await new Promise(d=>setTimeout(d,3e3))}}async function X({token:i,projectId:t,workflow:o,follow:n,limit:u}){let a=`${A}/all/${t}`,f=null,s=0,m=new Set,l=null,g=!1,c=0,h=5,I=()=>{g=!0,console.log(e.gray(`
31
31
  Stopped tailing.
32
32
  `)),process.exit(0)};for(process.on("SIGINT",I),process.on("SIGTERM",I),console.log(e.gray(`
33
33
  Tailing all runs for ${e.cyan(o)}...`)),console.log(n?e.gray(` Press Ctrl+C to stop.
34
- `):"");!g;)try{let r=new URLSearchParams({workflow:o,limit:String(u)});f&&r.set("nextToken",f);let d=await L(`${i}?${r}`,a);c=0,d.message&&d.lines?.length===0&&s===0&&console.log(e.gray(` ${d.message}`));for(let y of d.lines||[]){let x=`${y.timestamp}:${y.jobId}:${y.message}`;if(m.has(x))continue;m.add(x),y.jobId!==l&&(l!==null&&console.log(""),console.log(e.dim(` \u2500\u2500 ${y.jobId} \u2500\u2500`)),l=y.jobId);let T=e.gray(C(y.timestamp));console.log(`${T} ${y.message.replace(/\n$/,"")}`)}if(s=d.lines?.length>0?0:s+1,f=d.nextToken||null,!n){f&&console.log(e.gray(`
34
+ `):"");!g;)try{let r=new URLSearchParams({workflow:o,limit:String(u)});f&&r.set("nextToken",f);let d=await L(`${a}?${r}`,i);c=0,d.message&&d.lines?.length===0&&s===0&&console.log(e.gray(` ${d.message}`));for(let y of d.lines||[]){let x=`${y.timestamp}:${y.jobId}:${y.message}`;if(m.has(x))continue;m.add(x),y.jobId!==l&&(l!==null&&console.log(""),console.log(e.dim(` \u2500\u2500 ${y.jobId} \u2500\u2500`)),l=y.jobId);let T=e.gray(C(y.timestamp));console.log(`${T} ${y.message.replace(/\n$/,"")}`)}if(s=d.lines?.length>0?0:s+1,f=d.nextToken||null,!n){f&&console.log(e.gray(`
35
35
  ... more logs available. Run again or use --follow to stream.`)),d.jobCount&&console.log(e.gray(` ${d.jobCount} job(s) found.`));break}if(!d.hasRunning&&!f&&s>2){console.log(e.gray(`
36
36
  No running jobs. All caught up.`));break}let $=d.lines?.length>0?500:s>5?5e3:2e3;await new Promise(y=>setTimeout(y,$))}catch(r){if(r.name==="AbortError")break;r.message.match(/API (400|401|403|404):/)&&(console.error(e.red(`
37
37
  ${r.message}
38
38
  `)),process.exit(1)),c++,console.error(e.red(` Error: ${r.message}`)),c>=h&&(console.error(e.red(`
39
39
  Too many consecutive errors (${h}). Stopping.
40
- `)),process.exit(1)),n||process.exit(1),await new Promise(k=>setTimeout(k,3e3))}}async function oe(a,t){let{token:o,projectId:n}=G(t),u=t.follow===!0,i=t.lines?parseInt(t.lines,10):1e5;if(t.all){let s=t.workflow;return s||(console.log(e.red(`
40
+ `)),process.exit(1)),n||process.exit(1),await new Promise(k=>setTimeout(k,3e3))}}async function oe(i,t){let{token:o,projectId:n}=G(t),u=t.follow===!0,a=t.lines?parseInt(t.lines,10):1e5;if(t.all){let s=t.workflow;return s||(console.log(e.red(`
41
41
  --workflow is required with --all`)),console.log(e.gray(` Example: zibby workflow logs --workflow ticket-triage --all --project <id>
42
- `)),process.exit(1)),X({token:o,projectId:n,workflow:s,follow:u,limit:i})}let f=await W(a,t,o,n);return u?V({token:o,jobId:f,follow:u,projectId:n}):M({token:o,projectId:n,jobId:f,follow:!1,limit:i})}export{oe as logsCommand,D as parseSseChunk,Z as runReconnectLoop,H as sseBackoffMs};
42
+ `)),process.exit(1)),X({token:o,projectId:n,workflow:s,follow:u,limit:a})}let f=await W(i,t,o,n);return u?V({token:o,jobId:f,follow:u,projectId:n}):M({token:o,projectId:n,jobId:f,follow:!1,limit:a})}export{oe as logsCommand,D as parseSseChunk,Z as runReconnectLoop,H as sseBackoffMs};
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- var ce=Object.defineProperty;var le=(t,e)=>()=>(t&&(e=t(t=0)),e);var pe=(t,e)=>{for(var o in e)ce(t,o,{get:e[o],enumerable:!0})};var q={};pe(q,{uploadSessionArtifacts:()=>xe});import{readdirSync as Y,statSync as U,createReadStream as _e,existsSync as be}from"node:fs";import{join as M,relative as Oe,sep as Re,extname as Te}from"node:path";function ke(t){let e=Te(t).toLowerCase();return Ae[e]||"application/octet-stream"}function H(t){let e=[],o;try{o=Y(t)}catch{return e}for(let r of o){if(Pe.has(r)||r.startsWith("."))continue;let n=M(t,r),i;try{i=U(n)}catch{continue}i.isDirectory()?e.push(...H(n)):i.isFile()&&e.push(n)}return e}async function ve({apiUrl:t,apiKey:e,executionId:o,nodeName:r,filename:n,absolutePath:i,sizeBytes:s,contentType:f}){let p;try{let c=await fetch(`${t}/${o}/artifacts/upload-url`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify({nodeName:r,filename:n,contentType:f,sizeBytes:s})});if(!c.ok){let a=await c.text();return console.warn(`[artifacts] upload-url failed for ${r}/${n}: ${c.status} ${a.slice(0,200)}`),null}p=await c.json()}catch(c){return console.warn(`[artifacts] upload-url request errored for ${r}/${n}: ${c.message}`),null}try{let c=_e(i),a=await fetch(p.url,{method:"PUT",headers:{"Content-Type":f,"Content-Length":String(s)},body:c,duplex:"half"});if(!a.ok)return console.warn(`[artifacts] S3 PUT failed for ${r}/${n}: ${a.status}`),null}catch(c){return console.warn(`[artifacts] S3 PUT errored for ${r}/${n}: ${c.message}`),null}return{nodeName:r,filename:n,s3Key:p.s3Key,contentType:f,sizeBytes:s}}async function xe({sessionPath:t,executionId:e,apiUrl:o,apiKey:r}){let n={uploaded:[],skipped:[]};if(!t||!be(t))return n;if(!o||!r||!e)return console.warn("[artifacts] uploader missing required input \u2014 skipping"),n;let i;try{i=Y(t)}catch(a){return console.warn(`[artifacts] could not read session folder ${t}: ${a.message}`),n}let s=[];for(let a of i){let d=M(t,a),g;try{g=U(d)}catch{continue}if(!g.isDirectory()||a.startsWith(".")||a.startsWith("_"))continue;let T=H(d);for(let w of T){let b=Oe(d,w).split(Re).join("/"),m;try{m=U(w).size}catch{continue}if(m>Q){n.skipped.push({nodeName:a,filename:b,reason:`size ${m} > ${Q}`});continue}if(m===0){n.skipped.push({nodeName:a,filename:b,reason:"empty"});continue}s.push({apiUrl:o,apiKey:r,executionId:e,nodeName:a,filename:b,absolutePath:w,sizeBytes:m,contentType:ke(b)})}}if(s.length===0)return n;let f=4,p=s.slice(),c=Array.from({length:Math.min(f,p.length)},async()=>{for(;p.length;){let a=p.shift(),d=await ve(a);d?n.uploaded.push(d):n.skipped.push({nodeName:a.nodeName,filename:a.filename,reason:"upload failed"})}});if(await Promise.all(c),n.uploaded.length>0)try{let a=await fetch(`${o}/${e}/artifacts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({files:n.uploaded})});if(!a.ok){let d=await a.text();console.warn(`[artifacts] record failed: ${a.status} ${d.slice(0,200)}`)}}catch(a){console.warn(`[artifacts] record errored: ${a.message}`)}return n}var Q,Pe,Ae,X=le(()=>{Q=500*1024*1024,Pe=new Set([".DS_Store","Thumbs.db",".zibby-stop"]),Ae={".webm":"video/webm",".mp4":"video/mp4",".mov":"video/quicktime",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".txt":"text/plain",".md":"text/markdown",".csv":"text/csv",".log":"text/plain",".json":"application/json",".yaml":"application/yaml",".yml":"application/yaml",".pdf":"application/pdf",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip"}});import{mkdirSync as oe,writeFileSync as Ue,existsSync as E,readFileSync as V}from"fs";import{join as h,dirname as Ie,resolve as Z}from"path";import{pathToFileURL as C}from"url";import{execSync as Ce,spawn as ee}from"node:child_process";import{SQSClient as de,SendMessageCommand as fe}from"@aws-sdk/client-sqs";var v=null;function ue(){return v||(v=new de({region:process.env.AWS_REGION||"ap-southeast-2"})),v}async function K(t,{status:e,error:o}){let{EXECUTION_ID:r,SQS_AUTH_TOKEN:n,PROGRESS_API_URL:i,PROGRESS_QUEUE_URL:s,PROJECT_API_TOKEN:f}=t;if(!r)return;let p={executionId:r,...n&&{sqsAuthToken:n},status:e,...o&&{error:o},timestamp:new Date().toISOString()},c=i?"HTTP":s?"SQS":"NONE",a=JSON.stringify(p).length;console.log(`Sending final status: ${e} via ${c} (${(a/1024).toFixed(1)}KB)`);try{if(i)await ge(i,r,p,f);else if(s){let d=["completed","failed","insufficient_context","blocked"].includes(e)?"execution_completed":"progress_update";await he(s,r,p,d)}else{console.warn("No transport configured for final status \u2014 neither PROGRESS_API_URL nor PROGRESS_QUEUE_URL set");return}console.log(`Final status ${e} sent via ${c}`)}catch(d){console.error(`Failed to send final status (${e}) via ${c}:`),console.error(` Payload: ${(a/1024).toFixed(1)}KB`),console.error(` Error: ${d.message}`),d.name&&console.error(` Error type: ${d.name}`),d.code&&console.error(` Error code: ${d.code}`)}}async function ge(t,e,o,r){let n=`${t}/${e}/progress`,i={"Content-Type":"application/json"};r&&(i.Authorization=`Bearer ${r}`);let s=await fetch(n,{method:"POST",headers:i,body:JSON.stringify(o)});if(!s.ok){let f=await s.text();throw new Error(`HTTP ${s.status}: ${f}`)}}async function he(t,e,o,r="progress_update"){let n=JSON.stringify(o),i=(n.length/1024).toFixed(1);n.length>256*1024&&console.error(`\u274C SQS message too large: ${i}KB (limit 256KB) for ${e} [${r}]`),await ue().send(new fe({QueueUrl:t,MessageBody:n,MessageGroupId:e,MessageAttributes:{executionId:{DataType:"String",StringValue:e},messageType:{DataType:"String",StringValue:r}}}))}function W({workflowType:t,jobId:e,projectId:o,agentType:r,model:n,egressIp:i,egressKind:s}){let f="\u2500".repeat(60),p=`${r||"default"} (model: ${n||"auto"})`,c=["",f,` Workflow: ${t}`,` Job: ${e||"local"}`,` Project: ${o||"none"}`,` Agent: ${p}`];if(i||s){let a=i||"unknown",d=s||"static";c.push(` Egress: ${a} (${d})`)}return c.push(f),c.join(`
3
- `)}import{existsSync as we,writeFileSync as ye}from"fs";import{join as G}from"path";var x={width:1280,height:720},me="on",Se="tests",Ee="test-results/playwright";function $e(t={}){let e=t.viewport&&typeof t.viewport=="object"?{width:Number(t.viewport.width)||x.width,height:Number(t.viewport.height)||x.height}:x,o=typeof t.video=="string"?t.video:me,r=t.paths?.generated||Se,n=t.playwrightArtifacts!==!1,i=n?"on":"off",s=n?"only-on-failure":"off";return`// AUTO-GENERATED at workflow run start by @zibby/cli's
2
+ var ce=Object.defineProperty;var le=(t,e)=>()=>(t&&(e=t(t=0)),e);var pe=(t,e)=>{for(var o in e)ce(t,o,{get:e[o],enumerable:!0})};var q={};pe(q,{uploadSessionArtifacts:()=>Ie});import{readdirSync as H,statSync as I,createReadStream as $e,existsSync as be}from"node:fs";import{join as Y,relative as Oe,sep as Re,extname as Te}from"node:path";function ve(t){let e=Te(t).toLowerCase();return ke[e]||"application/octet-stream"}function M(t){let e=[],o;try{o=H(t)}catch{return e}for(let r of o){if(Pe.has(r)||r.startsWith(".")||Ae.has(r))continue;let n=Y(t,r),i;try{i=I(n)}catch{continue}i.isDirectory()?e.push(...M(n)):i.isFile()&&e.push(n)}return e}async function xe({apiUrl:t,apiKey:e,executionId:o,nodeName:r,filename:n,absolutePath:i,sizeBytes:s,contentType:f}){let d;try{let c=await fetch(`${t}/${o}/artifacts/upload-url`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify({nodeName:r,filename:n,contentType:f,sizeBytes:s})});if(!c.ok){let a=await c.text();return console.warn(`[artifacts] upload-url failed for ${r}/${n}: ${c.status} ${a.slice(0,200)}`),null}d=await c.json()}catch(c){return console.warn(`[artifacts] upload-url request errored for ${r}/${n}: ${c.message}`),null}try{let c=$e(i),a=d.requiredHeaders?{...d.requiredHeaders,"Content-Length":String(s)}:{"Content-Type":f,"Content-Length":String(s)},p=await fetch(d.url,{method:"PUT",headers:a,body:c,duplex:"half"});if(!p.ok)return console.warn(`[artifacts] S3 PUT failed for ${r}/${n}: ${p.status}`),null}catch(c){return console.warn(`[artifacts] S3 PUT errored for ${r}/${n}: ${c.message}`),null}return{nodeName:r,filename:n,s3Key:d.s3Key,contentType:f,sizeBytes:s}}async function Ie({sessionPath:t,executionId:e,apiUrl:o,apiKey:r}){let n={uploaded:[],skipped:[]};if(!t||!be(t))return n;if(!o||!r||!e)return console.warn("[artifacts] uploader missing required input \u2014 skipping"),n;let i;try{i=H(t)}catch(a){return console.warn(`[artifacts] could not read session folder ${t}: ${a.message}`),n}let s=[];for(let a of i){let p=Y(t,a),g;try{g=I(p)}catch{continue}if(!g.isDirectory()||a.startsWith(".")||a.startsWith("_"))continue;let T=M(p);for(let w of T){let b=Oe(p,w).split(Re).join("/"),m;try{m=I(w).size}catch{continue}if(m>Q){n.skipped.push({nodeName:a,filename:b,reason:`size ${m} > ${Q}`});continue}if(m===0){n.skipped.push({nodeName:a,filename:b,reason:"empty"});continue}s.push({apiUrl:o,apiKey:r,executionId:e,nodeName:a,filename:b,absolutePath:w,sizeBytes:m,contentType:ve(b)})}}if(s.length===0)return n;let f=4,d=s.slice(),c=Array.from({length:Math.min(f,d.length)},async()=>{for(;d.length;){let a=d.shift(),p=await xe(a);p?n.uploaded.push(p):n.skipped.push({nodeName:a.nodeName,filename:a.filename,reason:"upload failed"})}});if(await Promise.all(c),n.uploaded.length>0)try{let a=await fetch(`${o}/${e}/artifacts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({files:n.uploaded})});if(!a.ok){let p=await a.text();console.warn(`[artifacts] record failed: ${a.status} ${p.slice(0,200)}`)}}catch(a){console.warn(`[artifacts] record errored: ${a.message}`)}return n}var Q,Pe,Ae,ke,X=le(()=>{Q=500*1024*1024,Pe=new Set([".DS_Store","Thumbs.db",".zibby-stop"]),Ae=new Set(["node_modules",".git","dist",".zibby","__tests__","__mocks__",".cache",".next",".turbo"]),ke={".webm":"video/webm",".mp4":"video/mp4",".mov":"video/quicktime",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".txt":"text/plain",".md":"text/markdown",".csv":"text/csv",".log":"text/plain",".json":"application/json",".yaml":"application/yaml",".yml":"application/yaml",".pdf":"application/pdf",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip"}});import{mkdirSync as oe,writeFileSync as Ue,existsSync as _,readFileSync as V}from"fs";import{join as h,dirname as Ce,resolve as Z}from"path";import{pathToFileURL as C}from"url";import{execSync as De,spawn as ee}from"node:child_process";import{SQSClient as de,SendMessageCommand as fe}from"@aws-sdk/client-sqs";var v=null;function ue(){return v||(v=new de({region:process.env.AWS_REGION||"ap-southeast-2"})),v}async function K(t,{status:e,error:o}){let{EXECUTION_ID:r,SQS_AUTH_TOKEN:n,PROGRESS_API_URL:i,PROGRESS_QUEUE_URL:s,PROJECT_API_TOKEN:f}=t;if(!r)return;let d={executionId:r,...n&&{sqsAuthToken:n},status:e,...o&&{error:o},timestamp:new Date().toISOString()},c=i?"HTTP":s?"SQS":"NONE",a=JSON.stringify(d).length;console.log(`Sending final status: ${e} via ${c} (${(a/1024).toFixed(1)}KB)`);try{if(i)await ge(i,r,d,f);else if(s){let p=["completed","failed","insufficient_context","blocked"].includes(e)?"execution_completed":"progress_update";await he(s,r,d,p)}else{console.warn("No transport configured for final status \u2014 neither PROGRESS_API_URL nor PROGRESS_QUEUE_URL set");return}console.log(`Final status ${e} sent via ${c}`)}catch(p){console.error(`Failed to send final status (${e}) via ${c}:`),console.error(` Payload: ${(a/1024).toFixed(1)}KB`),console.error(` Error: ${p.message}`),p.name&&console.error(` Error type: ${p.name}`),p.code&&console.error(` Error code: ${p.code}`)}}async function ge(t,e,o,r){let n=`${t}/${e}/progress`,i={"Content-Type":"application/json"};r&&(i.Authorization=`Bearer ${r}`);let s=await fetch(n,{method:"POST",headers:i,body:JSON.stringify(o)});if(!s.ok){let f=await s.text();throw new Error(`HTTP ${s.status}: ${f}`)}}async function he(t,e,o,r="progress_update"){let n=JSON.stringify(o),i=(n.length/1024).toFixed(1);n.length>256*1024&&console.error(`\u274C SQS message too large: ${i}KB (limit 256KB) for ${e} [${r}]`),await ue().send(new fe({QueueUrl:t,MessageBody:n,MessageGroupId:e,MessageAttributes:{executionId:{DataType:"String",StringValue:e},messageType:{DataType:"String",StringValue:r}}}))}function W({workflowType:t,jobId:e,projectId:o,agentType:r,model:n,egressIp:i,egressKind:s}){let f="\u2500".repeat(60),d=`${r||"default"} (model: ${n||"auto"})`,c=["",f,` Workflow: ${t}`,` Job: ${e||"local"}`,` Project: ${o||"none"}`,` Agent: ${d}`];if(i||s){let a=i||"unknown",p=s||"static";c.push(` Egress: ${a} (${p})`)}return c.push(f),c.join(`
3
+ `)}import{existsSync as we,writeFileSync as ye}from"fs";import{join as G}from"path";var x={width:1280,height:720},me="on",Se="tests",_e="test-results/playwright";function Ee(t={}){let e=t.viewport&&typeof t.viewport=="object"?{width:Number(t.viewport.width)||x.width,height:Number(t.viewport.height)||x.height}:x,o=typeof t.video=="string"?t.video:me,r=t.paths?.generated||Se,n=t.playwrightArtifacts!==!1,i=n?"on":"off",s=n?"only-on-failure":"off";return`// AUTO-GENERATED at workflow run start by @zibby/cli's
4
4
  // playwright-config-materialize.js. Derived from the bundled
5
5
  // zibby.config.json (which @zibby/workflow-deploy serialized from your
6
6
  // project's .zibby.config.mjs). Do NOT edit by hand \u2014 re-run a workflow
@@ -11,7 +11,7 @@ import { defineConfig } from '@playwright/test';
11
11
 
12
12
  export default defineConfig({
13
13
  testDir: '${r.replace(/'/g,"\\'")}',
14
- outputDir: '${Ee}',
14
+ outputDir: '${_e}',
15
15
  timeout: 60000,
16
16
  retries: 0,
17
17
  workers: 1,
@@ -26,7 +26,7 @@ export default defineConfig({
26
26
 
27
27
  reporter: [['list']],
28
28
  });
29
- `}function J(t,e){if(!t)return{written:!1,path:null,reason:"no workspaceDir"};for(let n of["js","mjs","ts"]){let i=G(t,`playwright.config.${n}`);if(we(i))return{written:!1,path:i,reason:`existing playwright.config.${n} in workspace`}}let o=G(t,"playwright.config.js"),r=$e(e||{});try{return ye(o,r,"utf-8"),{written:!0,path:o,reason:"derived from zibby.config"}}catch(n){return{written:!1,path:null,reason:`write failed: ${n.message}`}}}import"@zibby/core";var A=process.env.WORKSPACE||"/workspace";async function De(t,e){oe(e,{recursive:!0});let o=Date.now();console.log("[setup] Fetching bundle...");let r=setInterval(()=>{let i=((Date.now()-o)/1e3).toFixed(1);console.log(`[setup] still fetching (${i}s elapsed)`)},3e3);try{await new Promise((i,s)=>{let f=ee("curl",["-fsSL",t],{stdio:["ignore","pipe","inherit"]}),p=ee("tar",["-xzf","-","-C",e],{stdio:["pipe","inherit","inherit"]});f.stdout.pipe(p.stdin);let c,a,d=()=>{if(c!==void 0&&a!==void 0){if(c!==0)return s(new Error(`curl exited ${c}`));if(a!==0)return s(new Error(`tar exited ${a}`));i()}};f.on("close",g=>{c=g,d()}),p.on("close",g=>{a=g,d()}),f.on("error",s),p.on("error",s)})}finally{clearInterval(r)}let n=((Date.now()-o)/1e3).toFixed(1);return console.log(`[setup] Bundle extracted (${n}s)`),e}async function te(){let t=process.env.WORKFLOW_SOURCES_URL;if(!t)throw new Error("WORKFLOW_SOURCES_URL env var is required");let e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch sources: ${e.status} ${e.statusText}`);let o=await e.json();if(!o.sources||typeof o.sources!="object")throw new Error('Invalid sources payload \u2014 missing "sources" map');return o}function Ne(t){let e=t?.agent;if(!e)return null;if(typeof e=="string")return e;if(typeof e=="object"){if(typeof e.provider=="string")return e.provider;for(let o of["claude","cursor","codex","gemini"])if(e[o])return o}return null}function Fe(t,e){let o=Z(e),r=0;for(let[n,i]of Object.entries(t)){let s=Z(e,n);if(!s.startsWith(`${o}/`)&&s!==o){console.error(` \u26D4 Skipping unsafe path: ${n}`);continue}oe(Ie(s),{recursive:!0}),Ue(s,i,"utf-8"),r++}return r}async function je(){let t=process.env.ZIBBY_EGRESS_PROXY_URL,e=process.env.ZIBBY_EGRESS_TOKEN;if(!(!t||!e))try{let o=await import("undici"),r=new o.ProxyAgent({uri:t,token:`Bearer ${e}`});o.setGlobalDispatcher(r)}catch(o){console.warn(`[setup] Failed to install egress proxy dispatcher: ${o.message}`)}}async function Le(){if(process.env.ZIBBY_EGRESS_IP)return{ip:process.env.ZIBBY_EGRESS_IP,kind:"static"};try{let t=new AbortController,e=setTimeout(()=>t.abort(),1500),o=await fetch("https://api.ipify.org?format=json",{signal:t.signal});return clearTimeout(e),o.ok?{ip:(await o.json())?.ip||null,kind:"dynamic"}:{ip:null,kind:"dynamic"}}catch{return{ip:null,kind:"dynamic"}}}async function Be(t,e){let o=h(t,"graph.mjs");if(!E(o))throw new Error(`graph.mjs not found at ${o}`);let r=await import(C(o).href),n=e?.entryClass,i=n&&r[n]||r.default||Object.values(r).find(s=>typeof s=="function"&&s.prototype?.buildGraph);if(!i)throw new Error("No WorkflowAgent class found in graph.mjs");return i}async function rt(){if(!process.env.NODE_PATH){process.env.NODE_PATH="/opt/zibby/packages";let l=await import("module");l.default._initPaths&&l.default._initPaths()}await je();let{WORKFLOW_JOB_ID:t,WORKFLOW_TYPE:e,PROJECT_ID:o,AGENT_TYPE:r,MODEL:n}=process.env;e||(console.error("Missing WORKFLOW_TYPE env var"),process.exit(1));let i=process.env.WORKFLOW_BUNDLE_URL,s,f={},p,c;if(i){p=e,s=h(A,".zibby","workflows",p);try{await De(i,s);try{let l=await te();f=l.input||{},c=l.version}catch{}}catch(l){console.warn(`[setup] Bundle extract failed (${l.message}); falling back to source install`),s=null}}if(!s){let l=await te(),{sources:u,input:S,workflowType:$,version:y}=l;f=S||{},p=$||e,c=y,console.log(`[setup] Workflow v${c||"?"} (${Object.keys(u).length} files)`),s=h(A,".zibby","workflows",p);let R=Fe(u,s);console.log(`[setup] Wrote ${R} files`),console.log("[setup] Installing dependencies...");try{Ce("npm install --silent --no-audit --no-fund",{cwd:s,stdio:"inherit"}),console.log("[setup] Dependencies installed")}catch(_){console.warn(`[setup] npm install failed: ${_.message}`)}}let a={},d=h(s,"workflow.json");E(d)&&(a=JSON.parse(V(d,"utf-8")));let g={},T=h(s,"zibby.config.json");if(E(T))try{g=JSON.parse(V(T,"utf-8")),console.log("[setup] Loaded user config from zibby.config.json")}catch(l){console.warn(`[setup] Failed to parse zibby.config.json: ${l.message} \u2014 falling back to defaults`)}let w=J(A,g);w.written?console.log(`[setup] Materialized playwright.config.js \u2192 ${w.path} (${w.reason})`):w.path&&console.log(`[setup] Using existing playwright config: ${w.path}`);let b=Ne(g)||r,m=await Le();console.log(W({workflowType:e,jobId:t,projectId:o,agentType:b,model:n,egressIp:m.ip,egressKind:m.kind}));let D=await Be(s,a);console.log(`[setup] Loaded ${D.name}`);let O=[],N=h(s,"node_modules","@zibby","agent-workflow"),F=h(s,"node_modules","@zibby","core","node_modules","@zibby","agent-workflow");E(N)&&O.push({kind:"hoisted",path:N}),E(F)&&O.push({kind:"nested",path:F});let k=process.env.ZIBBY_RUN_DIAG==="1";if(k){let{readdirSync:l}=await import("fs");console.log(` [diag] @zibby/agent-workflow copies in bundle: ${O.length}`);for(let u of O)console.log(` [diag] ${u.kind}: ${u.path}`);try{let u=h(s,"node_modules","@zibby");E(u)&&console.log(` [diag] node_modules/@zibby/ contents: [${l(u).join(", ")}]`)}catch{}}let j=h(s,"node_modules","@zibby","core","dist","index.js");if(E(j)&&O.length>0)try{let l=await import(C(j).href),u=[l.AssistantStrategy,l.CursorAgentStrategy,l.ClaudeAgentStrategy,l.CodexAgentStrategy,l.GeminiAgentStrategy].filter(Boolean);for(let S of O){let $=h(S.path,"dist","index.js");if(!E($))continue;let y=await import(C($).href),R=k?y.listStrategies():null;for(let _ of u)try{y.registerStrategy(new _)}catch(ae){console.warn(` register ${_.name} into ${S.kind} failed: ${ae.message}`)}k&&console.log(` [diag] ${S.kind} registry: before=[${R.join(",")||"empty"}] after=[${y.listStrategies().join(",")||"empty"}]`)}console.log("[setup] Registered 5 agent strategies (assistant, cursor, claude, codex, gemini)")}catch(l){console.warn(`[setup] Failed to bridge strategies: ${l.message}`)}else console.warn("[setup] No @zibby/core or @zibby/agent-workflow in bundle \u2014 agent strategies may be unavailable");let ne=Date.now(),L=new D({workflow:p||e}),se=L.buildGraph(),re={...f||{},cwd:A,runId:t||`run-${Date.now()}`,config:g,input:f||{}};console.log("");let P;try{P=await se.run(L,re)}catch(l){console.error(`
30
- Workflow execution failed: ${l.message}`),console.error(l.stack),await I("failed",l.message),process.exit(1)}let B=((Date.now()-ne)/1e3).toFixed(1),ie=P?.success!==!1,z=p||e;if(process.env.UPLOAD_ARTIFACTS!=="0"){let l=P?.state?.sessionPath,u=process.env.PROGRESS_API_URL||process.env.ZIBBY_API_BASE,S=process.env.PROJECT_API_TOKEN,$=process.env.WORKFLOW_JOB_ID;if(l&&u&&S&&$)try{let{uploadSessionArtifacts:y}=await Promise.resolve().then(()=>(X(),q)),{uploaded:R,skipped:_}=await y({sessionPath:l,executionId:$,apiUrl:u,apiKey:S});console.log(`[artifacts] uploaded ${R.length} file(s)${_.length?`, skipped ${_.length}`:""}`)}catch(y){console.warn(`[artifacts] uploader threw: ${y.message}`)}else console.log("[artifacts] skipping upload \u2014 sessionPath/apiUrl/apiKey/executionId missing")}ie?(console.log(`
31
- [done] ${z} completed in ${B}s`),await I("completed")):(console.error(`
32
- [done] ${z} failed after ${B}s`),await I("failed",P?.error||"Workflow execution failed"),process.exit(1))}async function I(t,e=null){let o={EXECUTION_ID:process.env.WORKFLOW_JOB_ID,PROGRESS_API_URL:process.env.PROGRESS_API_URL,PROGRESS_QUEUE_URL:process.env.PROGRESS_QUEUE_URL,PROJECT_API_TOKEN:process.env.PROJECT_API_TOKEN,SQS_AUTH_TOKEN:process.env.SQS_AUTH_TOKEN};if(o.EXECUTION_ID)try{await K(o,{status:t,...e&&{error:e}})}catch(r){console.error(`\u26A0\uFE0F Failed to report status: ${r.message}`)}}export{Ne as resolveAgentFromConfig,rt as runWorkflowCommand};
29
+ `}function J(t,e){if(!t)return{written:!1,path:null,reason:"no workspaceDir"};for(let n of["js","mjs","ts"]){let i=G(t,`playwright.config.${n}`);if(we(i))return{written:!1,path:i,reason:`existing playwright.config.${n} in workspace`}}let o=G(t,"playwright.config.js"),r=Ee(e||{});try{return ye(o,r,"utf-8"),{written:!0,path:o,reason:"derived from zibby.config"}}catch(n){return{written:!1,path:null,reason:`write failed: ${n.message}`}}}import"@zibby/core";var A=process.env.WORKSPACE||"/workspace";async function Ne(t,e){oe(e,{recursive:!0});let o=Date.now();console.log("[setup] Fetching bundle...");let r=setInterval(()=>{let i=((Date.now()-o)/1e3).toFixed(1);console.log(`[setup] still fetching (${i}s elapsed)`)},3e3);try{await new Promise((i,s)=>{let f=ee("curl",["-fsSL",t],{stdio:["ignore","pipe","inherit"]}),d=ee("tar",["-xzf","-","-C",e],{stdio:["pipe","inherit","inherit"]});f.stdout.pipe(d.stdin);let c,a,p=()=>{if(c!==void 0&&a!==void 0){if(c!==0)return s(new Error(`curl exited ${c}`));if(a!==0)return s(new Error(`tar exited ${a}`));i()}};f.on("close",g=>{c=g,p()}),d.on("close",g=>{a=g,p()}),f.on("error",s),d.on("error",s)})}finally{clearInterval(r)}let n=((Date.now()-o)/1e3).toFixed(1);return console.log(`[setup] Bundle extracted (${n}s)`),e}async function te(){let t=process.env.WORKFLOW_SOURCES_URL;if(!t)throw new Error("WORKFLOW_SOURCES_URL env var is required");let e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch sources: ${e.status} ${e.statusText}`);let o=await e.json();if(!o.sources||typeof o.sources!="object")throw new Error('Invalid sources payload \u2014 missing "sources" map');return o}function Fe(t){let e=t?.agent;if(!e)return null;if(typeof e=="string")return e;if(typeof e=="object"){if(typeof e.provider=="string")return e.provider;for(let o of["claude","cursor","codex","gemini"])if(e[o])return o}return null}function Le(t,e){let o=Z(e),r=0;for(let[n,i]of Object.entries(t)){let s=Z(e,n);if(!s.startsWith(`${o}/`)&&s!==o){console.error(` \u26D4 Skipping unsafe path: ${n}`);continue}oe(Ce(s),{recursive:!0}),Ue(s,i,"utf-8"),r++}return r}async function je(){let t=process.env.ZIBBY_EGRESS_PROXY_URL,e=process.env.ZIBBY_EGRESS_TOKEN;if(!(!t||!e))try{let o=await import("undici"),r=new o.ProxyAgent({uri:t,token:`Bearer ${e}`});o.setGlobalDispatcher(r)}catch(o){console.warn(`[setup] Failed to install egress proxy dispatcher: ${o.message}`)}}async function Be(){if(process.env.ZIBBY_EGRESS_IP)return{ip:process.env.ZIBBY_EGRESS_IP,kind:"static"};try{let t=new AbortController,e=setTimeout(()=>t.abort(),1500),o=await fetch("https://api.ipify.org?format=json",{signal:t.signal});return clearTimeout(e),o.ok?{ip:(await o.json())?.ip||null,kind:"dynamic"}:{ip:null,kind:"dynamic"}}catch{return{ip:null,kind:"dynamic"}}}async function ze(t,e){let o=h(t,"graph.mjs");if(!_(o))throw new Error(`graph.mjs not found at ${o}`);let r=await import(C(o).href),n=e?.entryClass,i=n&&r[n]||r.default||Object.values(r).find(s=>typeof s=="function"&&s.prototype?.buildGraph);if(!i)throw new Error("No WorkflowAgent class found in graph.mjs");return i}async function it(){if(!process.env.NODE_PATH){process.env.NODE_PATH="/opt/zibby/packages";let l=await import("module");l.default._initPaths&&l.default._initPaths()}await je();let{WORKFLOW_JOB_ID:t,WORKFLOW_TYPE:e,PROJECT_ID:o,AGENT_TYPE:r,MODEL:n}=process.env;e||(console.error("Missing WORKFLOW_TYPE env var"),process.exit(1));let i=process.env.WORKFLOW_BUNDLE_URL,s,f={},d,c;if(i){d=e,s=h(A,".zibby","workflows",d);try{await Ne(i,s);try{let l=await te();f=l.input||{},c=l.version}catch{}}catch(l){console.warn(`[setup] Bundle extract failed (${l.message}); falling back to source install`),s=null}}if(!s){let l=await te(),{sources:u,input:S,workflowType:E,version:y}=l;f=S||{},d=E||e,c=y,console.log(`[setup] Workflow v${c||"?"} (${Object.keys(u).length} files)`),s=h(A,".zibby","workflows",d);let R=Le(u,s);console.log(`[setup] Wrote ${R} files`),console.log("[setup] Installing dependencies...");try{De("npm install --silent --no-audit --no-fund",{cwd:s,stdio:"inherit"}),console.log("[setup] Dependencies installed")}catch($){console.warn(`[setup] npm install failed: ${$.message}`)}}let a={},p=h(s,"workflow.json");_(p)&&(a=JSON.parse(V(p,"utf-8")));let g={},T=h(s,"zibby.config.json");if(_(T))try{g=JSON.parse(V(T,"utf-8")),console.log("[setup] Loaded user config from zibby.config.json")}catch(l){console.warn(`[setup] Failed to parse zibby.config.json: ${l.message} \u2014 falling back to defaults`)}let w=J(A,g);w.written?console.log(`[setup] Materialized playwright.config.js \u2192 ${w.path} (${w.reason})`):w.path&&console.log(`[setup] Using existing playwright config: ${w.path}`);let b=Fe(g)||r,m=await Be();console.log(W({workflowType:e,jobId:t,projectId:o,agentType:b,model:n,egressIp:m.ip,egressKind:m.kind}));let D=await ze(s,a);console.log(`[setup] Loaded ${D.name}`);let O=[],N=h(s,"node_modules","@zibby","agent-workflow"),F=h(s,"node_modules","@zibby","core","node_modules","@zibby","agent-workflow");_(N)&&O.push({kind:"hoisted",path:N}),_(F)&&O.push({kind:"nested",path:F});let k=process.env.ZIBBY_RUN_DIAG==="1";if(k){let{readdirSync:l}=await import("fs");console.log(` [diag] @zibby/agent-workflow copies in bundle: ${O.length}`);for(let u of O)console.log(` [diag] ${u.kind}: ${u.path}`);try{let u=h(s,"node_modules","@zibby");_(u)&&console.log(` [diag] node_modules/@zibby/ contents: [${l(u).join(", ")}]`)}catch{}}let L=h(s,"node_modules","@zibby","core","dist","index.js");if(_(L)&&O.length>0)try{let l=await import(C(L).href),u=[l.AssistantStrategy,l.CursorAgentStrategy,l.ClaudeAgentStrategy,l.CodexAgentStrategy,l.GeminiAgentStrategy].filter(Boolean);for(let S of O){let E=h(S.path,"dist","index.js");if(!_(E))continue;let y=await import(C(E).href),R=k?y.listStrategies():null;for(let $ of u)try{y.registerStrategy(new $)}catch(ae){console.warn(` register ${$.name} into ${S.kind} failed: ${ae.message}`)}k&&console.log(` [diag] ${S.kind} registry: before=[${R.join(",")||"empty"}] after=[${y.listStrategies().join(",")||"empty"}]`)}console.log("[setup] Registered 5 agent strategies (assistant, cursor, claude, codex, gemini)")}catch(l){console.warn(`[setup] Failed to bridge strategies: ${l.message}`)}else console.warn("[setup] No @zibby/core or @zibby/agent-workflow in bundle \u2014 agent strategies may be unavailable");let ne=Date.now(),j=new D({workflow:d||e}),se=j.buildGraph(),re={...f||{},cwd:A,runId:t||`run-${Date.now()}`,config:g,input:f||{}};console.log("");let P;try{P=await se.run(j,re)}catch(l){console.error(`
30
+ Workflow execution failed: ${l.message}`),console.error(l.stack),await U("failed",l.message),process.exit(1)}let B=((Date.now()-ne)/1e3).toFixed(1),ie=P?.success!==!1,z=d||e;if(process.env.UPLOAD_ARTIFACTS!=="0"){let l=P?.state?.sessionPath,u=process.env.PROGRESS_API_URL||process.env.ZIBBY_API_BASE,S=process.env.PROJECT_API_TOKEN,E=process.env.WORKFLOW_JOB_ID;if(l&&u&&S&&E)try{let{uploadSessionArtifacts:y}=await Promise.resolve().then(()=>(X(),q)),{uploaded:R,skipped:$}=await y({sessionPath:l,executionId:E,apiUrl:u,apiKey:S});console.log(`[artifacts] uploaded ${R.length} file(s)${$.length?`, skipped ${$.length}`:""}`)}catch(y){console.warn(`[artifacts] uploader threw: ${y.message}`)}else console.log("[artifacts] skipping upload \u2014 sessionPath/apiUrl/apiKey/executionId missing")}ie?(console.log(`
31
+ [done] ${z} completed in ${B}s`),await U("completed")):(console.error(`
32
+ [done] ${z} failed after ${B}s`),await U("failed",P?.error||"Workflow execution failed"),process.exit(1))}async function U(t,e=null){let o={EXECUTION_ID:process.env.WORKFLOW_JOB_ID,PROGRESS_API_URL:process.env.PROGRESS_API_URL,PROGRESS_QUEUE_URL:process.env.PROGRESS_QUEUE_URL,PROJECT_API_TOKEN:process.env.PROJECT_API_TOKEN,SQS_AUTH_TOKEN:process.env.SQS_AUTH_TOKEN};if(o.EXECUTION_ID)try{await K(o,{status:t,...e&&{error:e}})}catch(r){console.error(`\u26A0\uFE0F Failed to report status: ${r.message}`)}}export{Fe as resolveAgentFromConfig,it as runWorkflowCommand};
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/cli",
3
- "version": "0.4.14",
3
+ "version": "0.4.16",
4
4
  "description": "Zibby CLI - Test automation generator and runner",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +1 @@
1
- import{readdirSync as $,statSync as m,createReadStream as T,existsSync as k}from"node:fs";import{join as w,relative as j,sep as x,extname as C}from"node:path";var g=500*1024*1024,v=new Set([".DS_Store","Thumbs.db",".zibby-stop"]),z={".webm":"video/webm",".mp4":"video/mp4",".mov":"video/quicktime",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".txt":"text/plain",".md":"text/markdown",".csv":"text/csv",".log":"text/plain",".json":"application/json",".yaml":"application/yaml",".yml":"application/yaml",".pdf":"application/pdf",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip"};function E(r){let n=C(r).toLowerCase();return z[n]||"application/octet-stream"}function S(r){let n=[],s;try{s=$(r)}catch{return n}for(let o of s){if(v.has(o)||o.startsWith("."))continue;let e=w(r,o),i;try{i=m(e)}catch{continue}i.isDirectory()?n.push(...S(e)):i.isFile()&&n.push(e)}return n}async function _({apiUrl:r,apiKey:n,executionId:s,nodeName:o,filename:e,absolutePath:i,sizeBytes:l,contentType:u}){let p;try{let a=await fetch(`${r}/${s}/artifacts/upload-url`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({nodeName:o,filename:e,contentType:u,sizeBytes:l})});if(!a.ok){let t=await a.text();return console.warn(`[artifacts] upload-url failed for ${o}/${e}: ${a.status} ${t.slice(0,200)}`),null}p=await a.json()}catch(a){return console.warn(`[artifacts] upload-url request errored for ${o}/${e}: ${a.message}`),null}try{let a=T(i),t=await fetch(p.url,{method:"PUT",headers:{"Content-Type":u,"Content-Length":String(l)},body:a,duplex:"half"});if(!t.ok)return console.warn(`[artifacts] S3 PUT failed for ${o}/${e}: ${t.status}`),null}catch(a){return console.warn(`[artifacts] S3 PUT errored for ${o}/${e}: ${a.message}`),null}return{nodeName:o,filename:e,s3Key:p.s3Key,contentType:u,sizeBytes:l}}async function F({sessionPath:r,executionId:n,apiUrl:s,apiKey:o}){let e={uploaded:[],skipped:[]};if(!r||!k(r))return e;if(!s||!o||!n)return console.warn("[artifacts] uploader missing required input \u2014 skipping"),e;let i;try{i=$(r)}catch(t){return console.warn(`[artifacts] could not read session folder ${r}: ${t.message}`),e}let l=[];for(let t of i){let c=w(r,t),y;try{y=m(c)}catch{continue}if(!y.isDirectory()||t.startsWith(".")||t.startsWith("_"))continue;let b=S(c);for(let h of b){let d=j(c,h).split(x).join("/"),f;try{f=m(h).size}catch{continue}if(f>g){e.skipped.push({nodeName:t,filename:d,reason:`size ${f} > ${g}`});continue}if(f===0){e.skipped.push({nodeName:t,filename:d,reason:"empty"});continue}l.push({apiUrl:s,apiKey:o,executionId:n,nodeName:t,filename:d,absolutePath:h,sizeBytes:f,contentType:E(d)})}}if(l.length===0)return e;let u=4,p=l.slice(),a=Array.from({length:Math.min(u,p.length)},async()=>{for(;p.length;){let t=p.shift(),c=await _(t);c?e.uploaded.push(c):e.skipped.push({nodeName:t.nodeName,filename:t.filename,reason:"upload failed"})}});if(await Promise.all(a),e.uploaded.length>0)try{let t=await fetch(`${s}/${n}/artifacts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify({files:e.uploaded})});if(!t.ok){let c=await t.text();console.warn(`[artifacts] record failed: ${t.status} ${c.slice(0,200)}`)}}catch(t){console.warn(`[artifacts] record errored: ${t.message}`)}return e}export{F as uploadSessionArtifacts};
1
+ import{readdirSync as $,statSync as m,createReadStream as b,existsSync as k}from"node:fs";import{join as w,relative as T,sep as x,extname as j}from"node:path";var y=500*1024*1024,C=new Set([".DS_Store","Thumbs.db",".zibby-stop"]),v=new Set(["node_modules",".git","dist",".zibby","__tests__","__mocks__",".cache",".next",".turbo"]),z={".webm":"video/webm",".mp4":"video/mp4",".mov":"video/quicktime",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".txt":"text/plain",".md":"text/markdown",".csv":"text/csv",".log":"text/plain",".json":"application/json",".yaml":"application/yaml",".yml":"application/yaml",".pdf":"application/pdf",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip"};function E(r){let n=j(r).toLowerCase();return z[n]||"application/octet-stream"}function S(r){let n=[],c;try{c=$(r)}catch{return n}for(let o of c){if(C.has(o)||o.startsWith(".")||v.has(o))continue;let t=w(r,o),l;try{l=m(t)}catch{continue}l.isDirectory()?n.push(...S(t)):l.isFile()&&n.push(t)}return n}async function O({apiUrl:r,apiKey:n,executionId:c,nodeName:o,filename:t,absolutePath:l,sizeBytes:p,contentType:u}){let i;try{let a=await fetch(`${r}/${c}/artifacts/upload-url`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({nodeName:o,filename:t,contentType:u,sizeBytes:p})});if(!a.ok){let e=await a.text();return console.warn(`[artifacts] upload-url failed for ${o}/${t}: ${a.status} ${e.slice(0,200)}`),null}i=await a.json()}catch(a){return console.warn(`[artifacts] upload-url request errored for ${o}/${t}: ${a.message}`),null}try{let a=b(l),e=i.requiredHeaders?{...i.requiredHeaders,"Content-Length":String(p)}:{"Content-Type":u,"Content-Length":String(p)},s=await fetch(i.url,{method:"PUT",headers:e,body:a,duplex:"half"});if(!s.ok)return console.warn(`[artifacts] S3 PUT failed for ${o}/${t}: ${s.status}`),null}catch(a){return console.warn(`[artifacts] S3 PUT errored for ${o}/${t}: ${a.message}`),null}return{nodeName:o,filename:t,s3Key:i.s3Key,contentType:u,sizeBytes:p}}async function F({sessionPath:r,executionId:n,apiUrl:c,apiKey:o}){let t={uploaded:[],skipped:[]};if(!r||!k(r))return t;if(!c||!o||!n)return console.warn("[artifacts] uploader missing required input \u2014 skipping"),t;let l;try{l=$(r)}catch(e){return console.warn(`[artifacts] could not read session folder ${r}: ${e.message}`),t}let p=[];for(let e of l){let s=w(r,e),g;try{g=m(s)}catch{continue}if(!g.isDirectory()||e.startsWith(".")||e.startsWith("_"))continue;let _=S(s);for(let h of _){let f=T(s,h).split(x).join("/"),d;try{d=m(h).size}catch{continue}if(d>y){t.skipped.push({nodeName:e,filename:f,reason:`size ${d} > ${y}`});continue}if(d===0){t.skipped.push({nodeName:e,filename:f,reason:"empty"});continue}p.push({apiUrl:c,apiKey:o,executionId:n,nodeName:e,filename:f,absolutePath:h,sizeBytes:d,contentType:E(f)})}}if(p.length===0)return t;let u=4,i=p.slice(),a=Array.from({length:Math.min(u,i.length)},async()=>{for(;i.length;){let e=i.shift(),s=await O(e);s?t.uploaded.push(s):t.skipped.push({nodeName:e.nodeName,filename:e.filename,reason:"upload failed"})}});if(await Promise.all(a),t.uploaded.length>0)try{let e=await fetch(`${c}/${n}/artifacts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify({files:t.uploaded})});if(!e.ok){let s=await e.text();console.warn(`[artifacts] record failed: ${e.status} ${s.slice(0,200)}`)}}catch(e){console.warn(`[artifacts] record errored: ${e.message}`)}return t}export{F as uploadSessionArtifacts};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/cli",
3
- "version": "0.4.14",
3
+ "version": "0.4.16",
4
4
  "description": "Zibby CLI - Test automation generator and runner",
5
5
  "type": "module",
6
6
  "bin": {