@zibby/cli 0.1.72 → 0.1.73

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,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import{mkdirSync as F,writeFileSync as L,existsSync as T}from"fs";import{join as w,dirname as W,resolve as h}from"path";import{pathToFileURL as K}from"url";import{SQSClient as C,SendMessageCommand as N}from"@aws-sdk/client-sqs";var S=null;function k(){return S||(S=new C({region:process.env.AWS_REGION||"ap-southeast-2"})),S}async function P(s,{status:e,error:o}){let{EXECUTION_ID:t,SQS_AUTH_TOKEN:r,PROGRESS_API_URL:i,PROGRESS_QUEUE_URL:n,PROJECT_API_TOKEN:d}=s;if(!t)return;let l={executionId:t,...r&&{sqsAuthToken:r},status:e,...o&&{error:o},timestamp:new Date().toISOString()},p=i?"HTTP":n?"SQS":"NONE",f=JSON.stringify(l).length;console.log(`Sending final status: ${e} via ${p} (${(f/1024).toFixed(1)}KB)`);try{if(i)await v(i,t,l,d);else if(n){let c=["completed","failed","insufficient_context","blocked"].includes(e)?"execution_completed":"progress_update";await x(n,t,l,c)}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 ${p}`)}catch(c){console.error(`Failed to send final status (${e}) via ${p}:`),console.error(` Payload: ${(f/1024).toFixed(1)}KB`),console.error(` Error: ${c.message}`),c.name&&console.error(` Error type: ${c.name}`),c.code&&console.error(` Error code: ${c.code}`)}}async function v(s,e,o,t){let r=`${s}/${e}/progress`,i={"Content-Type":"application/json"};t&&(i.Authorization=`Bearer ${t}`);let n=await fetch(r,{method:"POST",headers:i,body:JSON.stringify(o)});if(!n.ok){let d=await n.text();throw new Error(`HTTP ${n.status}: ${d}`)}}async function x(s,e,o,t="progress_update"){let r=JSON.stringify(o),i=(r.length/1024).toFixed(1);r.length>256*1024&&console.error(`\u274C SQS message too large: ${i}KB (limit 256KB) for ${e} [${t}]`),await k().send(new N({QueueUrl:s,MessageBody:r,MessageGroupId:e,MessageAttributes:{executionId:{DataType:"String",StringValue:e},messageType:{DataType:"String",StringValue:t}}}))}var y=process.env.WORKSPACE||"/workspace";async function D(){let s=process.env.WORKFLOW_SOURCES_URL;if(!s)throw new Error("WORKFLOW_SOURCES_URL env var is required");console.log("Fetching workflow sources via pre-signed URL...");let e=await fetch(s);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 b(s,e){let o=h(e),t=0;for(let[r,i]of Object.entries(s)){let n=h(e,r);if(!n.startsWith(`${o}/`)&&n!==o){console.error(` \u26D4 Skipping unsafe path: ${r}`);continue}F(W(n),{recursive:!0}),L(n,i,"utf-8"),t++}return t}async function G(s,e){let o=w(s,"graph.mjs");if(!T(o))throw new Error(`graph.mjs not found at ${o}`);let t=await import(K(o).href),r=e?.entryClass,i=r&&t[r]||t.default||Object.values(t).find(n=>typeof n=="function"&&n.prototype?.buildGraph);if(!i)throw new Error("No WorkflowAgent class found in graph.mjs");return i}async function z(){if(!process.env.NODE_PATH){process.env.NODE_PATH="/opt/zibby/packages";let a=await import("module");a.default._initPaths&&a.default._initPaths()}let{WORKFLOW_JOB_ID:s,WORKFLOW_TYPE:e,PROJECT_ID:o,AGENT_TYPE:t,MODEL:r}=process.env;e||(console.error("Missing WORKFLOW_TYPE env var"),process.exit(1)),console.log(`
3
- Zibby Custom Workflow Runner`),console.log(` Job: ${s||"local"}`),console.log(` Workflow: ${e}`),console.log(` Project: ${o||"none"}`),console.log(` Agent: ${t||"default"}`),console.log(` Model: ${r||"auto"}`),console.log("\u2500".repeat(60));let i=await D(),{sources:n,input:d,workflowType:l,version:p}=i;console.log(` Workflow v${p||"?"} \u2014 ${Object.keys(n).length} source files`);let f=w(y,".zibby","workflows",l||e),c=b(n,f);console.log(` Wrote ${c} files to ${f}`),console.log(" Installing dependencies...");let{execSync:U}=await import("child_process");try{U("npm install --silent --no-audit --no-fund",{cwd:f,stdio:"inherit"}),console.log(" Dependencies installed")}catch(a){console.warn(` npm install failed: ${a.message}`)}let O={},_=w(f,"workflow.json");if(T(_)){let{readFileSync:a}=await import("fs");O=JSON.parse(a(_,"utf-8"))}let m=await G(f,O);console.log(` Loaded ${m.name}`);let I=Date.now(),u=new m({workflow:l||e}),R=u.buildGraph(),A={input:d||{},cwd:y,runId:s||`run-${Date.now()}`};console.log(`
2
+ import{mkdirSync as F,writeFileSync as L,existsSync as T}from"fs";import{join as w,dirname as W,resolve as h}from"path";import{pathToFileURL as K}from"url";import{SQSClient as N,SendMessageCommand as C}from"@aws-sdk/client-sqs";var g=null;function v(){return g||(g=new N({region:process.env.AWS_REGION||"ap-southeast-2"})),g}async function P(s,{status:e,error:o}){let{EXECUTION_ID:t,SQS_AUTH_TOKEN:r,PROGRESS_API_URL:i,PROGRESS_QUEUE_URL:n,PROJECT_API_TOKEN:d}=s;if(!t)return;let l={executionId:t,...r&&{sqsAuthToken:r},status:e,...o&&{error:o},timestamp:new Date().toISOString()},p=i?"HTTP":n?"SQS":"NONE",f=JSON.stringify(l).length;console.log(`Sending final status: ${e} via ${p} (${(f/1024).toFixed(1)}KB)`);try{if(i)await k(i,t,l,d);else if(n){let c=["completed","failed","insufficient_context","blocked"].includes(e)?"execution_completed":"progress_update";await x(n,t,l,c)}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 ${p}`)}catch(c){console.error(`Failed to send final status (${e}) via ${p}:`),console.error(` Payload: ${(f/1024).toFixed(1)}KB`),console.error(` Error: ${c.message}`),c.name&&console.error(` Error type: ${c.name}`),c.code&&console.error(` Error code: ${c.code}`)}}async function k(s,e,o,t){let r=`${s}/${e}/progress`,i={"Content-Type":"application/json"};t&&(i.Authorization=`Bearer ${t}`);let n=await fetch(r,{method:"POST",headers:i,body:JSON.stringify(o)});if(!n.ok){let d=await n.text();throw new Error(`HTTP ${n.status}: ${d}`)}}async function x(s,e,o,t="progress_update"){let r=JSON.stringify(o),i=(r.length/1024).toFixed(1);r.length>256*1024&&console.error(`\u274C SQS message too large: ${i}KB (limit 256KB) for ${e} [${t}]`),await v().send(new C({QueueUrl:s,MessageBody:r,MessageGroupId:e,MessageAttributes:{executionId:{DataType:"String",StringValue:e},messageType:{DataType:"String",StringValue:t}}}))}var y=process.env.WORKSPACE||"/workspace";async function D(){let s=process.env.WORKFLOW_SOURCES_URL;if(!s)throw new Error("WORKFLOW_SOURCES_URL env var is required");console.log("Fetching workflow sources via pre-signed URL...");let e=await fetch(s);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 b(s,e){let o=h(e),t=0;for(let[r,i]of Object.entries(s)){let n=h(e,r);if(!n.startsWith(`${o}/`)&&n!==o){console.error(` \u26D4 Skipping unsafe path: ${r}`);continue}F(W(n),{recursive:!0}),L(n,i,"utf-8"),t++}return t}async function G(s,e){let o=w(s,"graph.mjs");if(!T(o))throw new Error(`graph.mjs not found at ${o}`);let t=await import(K(o).href),r=e?.entryClass,i=r&&t[r]||t.default||Object.values(t).find(n=>typeof n=="function"&&n.prototype?.buildGraph);if(!i)throw new Error("No WorkflowAgent class found in graph.mjs");return i}async function z(){if(!process.env.NODE_PATH){process.env.NODE_PATH="/opt/zibby/packages";let a=await import("module");a.default._initPaths&&a.default._initPaths()}let{WORKFLOW_JOB_ID:s,WORKFLOW_TYPE:e,PROJECT_ID:o,AGENT_TYPE:t,MODEL:r}=process.env;e||(console.error("Missing WORKFLOW_TYPE env var"),process.exit(1)),console.log(`
3
+ Zibby Custom Workflow Runner`),console.log(` Job: ${s||"local"}`),console.log(` Workflow: ${e}`),console.log(` Project: ${o||"none"}`),console.log(` Agent: ${t||"default"}`),console.log(` Model: ${r||"auto"}`),console.log("\u2500".repeat(60));let i=await D(),{sources:n,input:d,workflowType:l,version:p}=i;console.log(` Workflow v${p||"?"} \u2014 ${Object.keys(n).length} source files`);let f=w(y,".zibby","workflows",l||e),c=b(n,f);console.log(` Wrote ${c} files to ${f}`),console.log(" Installing dependencies...");let{execSync:U}=await import("child_process");try{U("npm install --silent --no-audit --no-fund",{cwd:f,stdio:"inherit"}),console.log(" Dependencies installed")}catch(a){console.warn(` npm install failed: ${a.message}`)}let _={},O=w(f,"workflow.json");if(T(O)){let{readFileSync:a}=await import("fs");_=JSON.parse(a(O,"utf-8"))}let m=await G(f,_);console.log(` Loaded ${m.name}`);let I=Date.now(),u=new m({workflow:l||e}),R=u.buildGraph(),A={input:d||{},cwd:y,runId:s||`run-${Date.now()}`};console.log(`
4
4
  Running graph (${R.nodes?.size||"?"} nodes)...
5
- `);let g;try{g=await R.run(u,A)}catch(a){console.error(`
6
- Workflow execution failed: ${a.message}`),console.error(a.stack),await E("failed",a.message),process.exit(1)}let $=((Date.now()-I)/1e3).toFixed(1);g?.success!==!1?(console.log(`
5
+ `);let S;try{S=await R.run(u,A)}catch(a){console.error(`
6
+ Workflow execution failed: ${a.message}`),console.error(a.stack),await E("failed",a.message),process.exit(1)}let $=((Date.now()-I)/1e3).toFixed(1);S?.success!==!1?(console.log(`
7
7
  Workflow "${l||e}" completed in ${$}s`),await E("completed")):(console.error(`
8
- Workflow "${l||e}" failed after ${$}s`),await E("failed",g?.error||"Workflow execution failed"),process.exit(1)),u.onComplete&&await u.onComplete(g)}async function E(s,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};if(o.EXECUTION_ID)try{await P(o,{status:s,...e&&{error:e}})}catch(t){console.error(`\u26A0\uFE0F Failed to report status: ${t.message}`)}}export{z as runWorkflowCommand};
8
+ Workflow "${l||e}" failed after ${$}s`),await E("failed",S?.error||"Workflow execution failed"),process.exit(1)),u.onComplete&&await u.onComplete(S)}async function E(s,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 P(o,{status:s,...e&&{error:e}})}catch(t){console.error(`\u26A0\uFE0F Failed to report status: ${t.message}`)}}export{z as runWorkflowCommand};
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/cli",
3
- "version": "0.1.72",
3
+ "version": "0.1.73",
4
4
  "description": "Zibby CLI - Test automation generator and runner",
5
5
  "type": "module",
6
6
  "bin": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/cli",
3
- "version": "0.1.72",
3
+ "version": "0.1.73",
4
4
  "description": "Zibby CLI - Test automation generator and runner",
5
5
  "type": "module",
6
6
  "bin": {