@zibby/core 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/core",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Core test automation engine with multi-agent and multi-MCP support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -69,9 +69,9 @@
69
69
  "@modelcontextprotocol/sdk": "^1.29.0",
70
70
  "@openai/codex-sdk": "^0.143.0",
71
71
  "@playwright/mcp": "^0.0.70",
72
- "@zibby/agent-workflow": "2.0.0",
73
- "@zibby/mcp-browser": "2.0.0",
74
- "@zibby/skill-ids": "2.0.0",
72
+ "@zibby/agent-workflow": "2.0.1",
73
+ "@zibby/mcp-browser": "2.0.1",
74
+ "@zibby/skill-ids": "2.0.1",
75
75
  "acorn": "^8.15.0",
76
76
  "acorn-walk": "^8.3.5",
77
77
  "axios": "^1.15.0",
@@ -1 +1 @@
1
- import{execSync as $}from"node:child_process";import{existsSync as w,mkdirSync as E}from"node:fs";import{join as S}from"node:path";function d(f,n,l,t,a="clone"){try{f(`git -C "${n}" remote set-url origin "${l}"`,{stdio:"pipe"})}catch(o){let r=String(o&&o.message||o);t&&(r=r.split(t).join("***")),console.error(`[${a}] WARNING: failed to strip token from .git/config: ${r}`)}}async function C(f={}){let{baseDir:n="/workspace/repos",repos:l=null,depth:t=1,branch:a=null}=f,o=process.env.REPOS;if(!o)throw new Error("REPOS environment variable not set. Are you running in a Zibby workflow container?");let r;try{r=JSON.parse(o)}catch(e){throw new Error(`Failed to parse REPOS env var: ${e.message}`,{cause:e})}if(!Array.isArray(r)||r.length===0)throw new Error("No repositories configured for this project");let g=l?r.filter(e=>l.includes(e.name)):r;if(g.length===0)throw new Error(`No matching repositories found. Available: ${r.map(e=>e.name).join(", ")}`);w(n)||E(n,{recursive:!0});let s={};return await Promise.all(g.map(async e=>{let p=e.provider||"github",i=p==="gitlab"?process.env.GITLAB_TOKEN:process.env.GITHUB_TOKEN;if(!i){console.error(`${p.toUpperCase()}_TOKEN not set, skipping ${e.name}`),s[e.name]=null;return}let y=e.name.replace(/\//g,"-"),m=S(n,y),c=e.cloneUrl||e.url;if(!c){console.error(`Repository "${e.name}" has no clone URL`),s[e.name]=null;return}let u;p==="gitlab"?u=c.replace(/^https:\/\//,`https://oauth2:${i}@`):u=c.replace(/^https:\/\//,`https://x-access-token:${i}@`);let h=["clone"];t>0&&h.push("--depth",t.toString()),a&&h.push("--branch",a),h.push(u,m);let R=`git ${h.join(" ")}`;console.log(`Cloning ${e.name} (${p}) to ${m}...`);try{$(R,{stdio:"pipe",env:{...process.env,GIT_TERMINAL_PROMPT:"0"}}),d($,m,c,i,`cloneRepo:${e.name}`),console.log(`Repository ${e.name} cloned successfully`),s[e.name]=m}catch(v){let b=v.message.replace(i,"***").replace(u,c);console.error(`Failed to clone ${e.name}: ${b}`),s[e.name]=null}})),s}export{C as cloneRepo};
1
+ import{execSync as v}from"node:child_process";import{existsSync as A,mkdirSync as N}from"node:fs";import{join as C}from"node:path";function y(t,e,r,o,s="clone"){try{t(`git -C "${e}" remote set-url origin "${r}"`,{stdio:"pipe"})}catch(c){let i=String(c&&c.message||c);o&&(i=i.split(o).join("***")),console.error(`[${s}] WARNING: failed to strip token from .git/config: ${i}`)}}import{existsSync as L,readFileSync as j}from"node:fs";import{homedir as P}from"node:os";import{join as K}from"node:path";var Z=Object.freeze(["github.com","gitlab.com"]);function u(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function E(t){if(typeof t!="string"||t===""||/[\\\x00-\x20\x7f]/.test(t))return"";let e;try{e=new URL(t)}catch{return""}return e.protocol!=="https:"?"":e.hostname.toLowerCase()}function x(t=process.env){let e=t&&(t.GITLAB_URL||t.GITLAB_INSTANCE_URL)||"";return u(e)}function m(t={}){if(t.gitlabHost){let e=String(t.gitlabHost).trim().toLowerCase();return e?e.includes("://")?u(e):e.replace(/:\d+$/,""):""}return x()}function O(t,e={}){if(t==="github.com")return"github";if(t==="gitlab.com")return"gitlab";let r=m(e);return r&&t===r?"gitlab":null}function b(t={},e={}){let r=t&&(t.cloneUrl||t.url)||"",o=u(r);if(!o)return null;let s=t.provider==="github"||t.provider==="gitlab"?t.provider:null,c=$(t,e),i=O(o,c?{gitlabHost:c}:{});return i?s&&s!==i?null:i:s==="gitlab"?"gitlab":null}function $(t,e={}){let r=m(e);return r||(t&&t.provider==="gitlab"?E(t.cloneUrl||t.url||""):"")}function T(t={},e="",r={}){let o=t&&(t.cloneUrl||t.url)||"";if(!o||!e||!b(t,r))return o;let s=$(t,r);return k(o,e,s?{gitlabHost:s}:{})}function k(t,e,r={}){if(!t||!e)return t;let o=E(t);if(!o)return t;if(o==="github.com")return t.replace(/^https:\/\/(?:[^@/]+@)?github\.com(?=[:/]|$)/i,`https://x-access-token:${e}@github.com`);if(o==="gitlab.com")return t.replace(/^https:\/\/(?:[^@/]+@)?gitlab\.com(?=[:/]|$)/i,`https://oauth2:${e}@gitlab.com`);let s=m(r);if(s&&o===s){let c=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`^https:\\/\\/(?:[^@/]+@)?${c}(?=[:/]|$)`,"i");return t.replace(i,`https://oauth2:${e}@${s}`)}return t}async function Q(t={}){let{baseDir:e="/workspace/repos",repos:r=null,depth:o=1,branch:s=null}=t,c=process.env.REPOS;if(!c)throw new Error("REPOS environment variable not set. Are you running in a Zibby workflow container?");let i;try{i=JSON.parse(c)}catch(n){throw new Error(`Failed to parse REPOS env var: ${n.message}`,{cause:n})}if(!Array.isArray(i)||i.length===0)throw new Error("No repositories configured for this project");let w=r?i.filter(n=>r.includes(n.name)):i;if(w.length===0)throw new Error(`No matching repositories found. Available: ${i.map(n=>n.name).join(", ")}`);A(e)||N(e,{recursive:!0});let l={};return await Promise.all(w.map(async n=>{let a=n.cloneUrl||n.url;if(!a){console.error(`Repository "${n.name}" has no clone URL`),l[n.name]=null;return}let f=b(n);if(!f){console.error(`Refusing to clone ${n.name}: '${u(a)||a}' is not a recognized VCS host (expected github.com, gitlab.com, or the self-hosted GitLab named by GITLAB_URL/GITLAB_INSTANCE_URL${n.provider?`; the repo declares provider='${n.provider}'`:""}). No token was sent.`),l[n.name]=null;return}let p=f==="gitlab"?process.env.GITLAB_TOKEN:process.env.GITHUB_TOKEN;if(!p){console.error(`${f.toUpperCase()}_TOKEN not set, skipping ${n.name}`),l[n.name]=null;return}let _=n.name.replace(/\//g,"-"),h=C(e,_),d=T({...n,cloneUrl:a},p);if(d===a){console.error(`Refusing to clone ${n.name}: could not safely attach credentials to '${a}' (an https:// URL on an exact trusted host is required). No token was sent.`),l[n.name]=null;return}let g=["clone"];o>0&&g.push("--depth",o.toString()),s&&g.push("--branch",s),g.push(d,h);let R=`git ${g.join(" ")}`;console.log(`Cloning ${n.name} (${f}) to ${h}...`);try{v(R,{stdio:"pipe",env:{...process.env,GIT_TERMINAL_PROMPT:"0"}}),y(v,h,a,p,`cloneRepo:${n.name}`),console.log(`Repository ${n.name} cloned successfully`),l[n.name]=h}catch(I){let S=I.message.replace(p,"***").replace(d,a);console.error(`Failed to clone ${n.name}: ${S}`),l[n.name]=null}})),l}export{Q as cloneRepo};
@@ -1,2 +1,2 @@
1
- import{execSync as f}from"node:child_process";import{existsSync as d,mkdirSync as $}from"node:fs";import{join as m,resolve as y}from"node:path";function h(t,n,o,r,i="clone"){try{t(`git -C "${n}" remote set-url origin "${o}"`,{stdio:"pipe"})}catch(e){let c=String(e&&e.message||e);r&&(c=c.split(r).join("***")),console.error(`[${i}] WARNING: failed to strip token from .git/config: ${c}`)}}var R="/workspace/repos",v=".zibby/repos";function g(){return process.env.REPOS?R:y(process.cwd(),v)}function E(t){return String(t).replace(/\//g,"-")}function w(){let t=process.env.REPOS;if(!t)return[];try{let n=JSON.parse(t);return Array.isArray(n)?n:[]}catch{return[]}}function p(t={}){let n=t.baseDir||g();return w().map((r,i)=>{let e=m(n,E(r.name));return{name:r.name,url:r.cloneUrl||r.url||null,branch:r.branch||null,provider:r.provider||"github",localPath:e,isCheckedOut:d(m(e,".git")),primary:i===0}})}function b(t,n={}){let o=p(n);return o.length===0?null:t?o.find(r=>r.name===t)||null:o[0]}function P(t,n={}){let o=b(t,n);return o?o.localPath:null}async function _(t,n={}){let{branch:o=null,depth:r=1,baseDir:i=g()}=n,e=b(t,{baseDir:i});if(!e){let s=p({baseDir:i}).map(l=>l.name).join(", ")||"(none)";throw new Error(`No repo "${t||"primary"}" configured for this workflow. Available: ${s}. Configure repos under project integrations, or set the REPOS env var.`)}if(e.isCheckedOut)return e.localPath;let c=e.provider==="gitlab"?process.env.GITLAB_TOKEN:process.env.GITHUB_TOKEN;if(!c)throw new Error(`${e.provider==="gitlab"?"GITLAB_TOKEN":"GITHUB_TOKEN"} not set \u2014 cannot clone ${e.name}. Connect the integration under project settings.`);if(!e.url)throw new Error(`Repo "${e.name}" has no clone URL configured.`);d(i)||$(i,{recursive:!0});let u=e.provider==="gitlab"?e.url.replace(/^https:\/\//,`https://oauth2:${c}@`):e.url.replace(/^https:\/\//,`https://x-access-token:${c}@`),a=["clone"];r>0&&a.push("--depth",String(r)),(o||e.branch)&&a.push("--branch",o||e.branch),a.push(u,e.localPath);try{f(`git ${a.join(" ")}`,{stdio:"pipe",env:{...process.env,GIT_TERMINAL_PROMPT:"0"}})}catch(s){let l=String(s.message||s).replace(c,"***").replace(u,e.url);throw new Error(`Failed to clone ${e.name}: ${l}`,{cause:s})}return h(f,e.localPath,e.url,c,`ensureRepo:${e.name}`),e.localPath}function x(t={}){let n=p(t);if(n.length===0)return null;let o=["## Available repositories",""];for(let r of n){let i=r.isCheckedOut?"already checked out at":"will be checked out to",e=r.primary?" (primary)":"";o.push(`- \`${r.name}\`${e} \u2014 ${i} \`${r.localPath}\``)}return o.push(""),o.push(`To materialize a repo: call the \`git_checkout\` skill with the repo name (e.g. \`git_checkout({ url: "${n[0].name}" })\`). In code, \`import { ensureRepo } from "@zibby/core"\` and \`await ensureRepo()\` returns the local path (clones on first call, no-op after).`),o.join(`
2
- `)}export{x as buildRepoContextHint,_ as ensureRepo,b as getRepo,p as listRepos,P as repoPath};
1
+ import{execSync as y}from"node:child_process";import{existsSync as _,mkdirSync as k}from"node:fs";import{join as T,resolve as A}from"node:path";function b(t,e,o,n,s="clone"){try{t(`git -C "${e}" remote set-url origin "${o}"`,{stdio:"pipe"})}catch(r){let i=String(r&&r.message||r);n&&(i=i.split(n).join("***")),console.error(`[${s}] WARNING: failed to strip token from .git/config: ${i}`)}}import{existsSync as U,readFileSync as P}from"node:fs";import{homedir as H}from"node:os";import{join as K}from"node:path";var Y=Object.freeze(["github.com","gitlab.com"]);function a(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function m(t){if(typeof t!="string"||t===""||/[\\\x00-\x20\x7f]/.test(t))return"";let e;try{e=new URL(t)}catch{return""}return e.protocol!=="https:"?"":e.hostname.toLowerCase()}function R(t=process.env){let e=t&&(t.GITLAB_URL||t.GITLAB_INSTANCE_URL)||"";return a(e)}function h(t={}){if(t.gitlabHost){let e=String(t.gitlabHost).trim().toLowerCase();return e?e.includes("://")?a(e):e.replace(/:\d+$/,""):""}return R()}function x(t,e={}){if(t==="github.com")return"github";if(t==="gitlab.com")return"gitlab";let o=h(e);return o&&t===o?"gitlab":null}function d(t={},e={}){let o=t&&(t.cloneUrl||t.url)||"",n=a(o);if(!n)return null;let s=t.provider==="github"||t.provider==="gitlab"?t.provider:null,r=w(t,e),i=x(n,r?{gitlabHost:r}:{});return i?s&&s!==i?null:i:s==="gitlab"?"gitlab":null}function w(t,e={}){let o=h(e);return o||(t&&t.provider==="gitlab"?m(t.cloneUrl||t.url||""):"")}function E(t={},e="",o={}){let n=t&&(t.cloneUrl||t.url)||"";if(!n||!e||!d(t,o))return n;let s=w(t,o);return S(n,e,s?{gitlabHost:s}:{})}function S(t,e,o={}){if(!t||!e)return t;let n=m(t);if(!n)return t;if(n==="github.com")return t.replace(/^https:\/\/(?:[^@/]+@)?github\.com(?=[:/]|$)/i,`https://x-access-token:${e}@github.com`);if(n==="gitlab.com")return t.replace(/^https:\/\/(?:[^@/]+@)?gitlab\.com(?=[:/]|$)/i,`https://oauth2:${e}@gitlab.com`);let s=h(o);if(s&&n===s){let r=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`^https:\\/\\/(?:[^@/]+@)?${r}(?=[:/]|$)`,"i");return t.replace(i,`https://oauth2:${e}@${s}`)}return t}var I="/workspace/repos",O=".zibby/repos";function $(){return process.env.REPOS?I:A(process.cwd(),O)}function C(t){return String(t).replace(/\//g,"-")}function N(){let t=process.env.REPOS;if(!t)return[];try{let e=JSON.parse(t);return Array.isArray(e)?e:[]}catch{return[]}}function g(t={}){let e=t.baseDir||$();return N().map((n,s)=>{let r=T(e,C(n.name));return{name:n.name,url:n.cloneUrl||n.url||null,branch:n.branch||null,provider:n.provider||"github",localPath:r,isCheckedOut:_(T(r,".git")),primary:s===0}})}function v(t,e={}){let o=g(e);return o.length===0?null:t?o.find(n=>n.name===t)||null:o[0]}function Q(t,e={}){let o=v(t,e);return o?o.localPath:null}async function X(t,e={}){let{branch:o=null,depth:n=1,baseDir:s=$()}=e,r=v(t,{baseDir:s});if(!r){let c=g({baseDir:s}).map(f=>f.name).join(", ")||"(none)";throw new Error(`No repo "${t||"primary"}" configured for this workflow. Available: ${c}. Configure repos under project integrations, or set the REPOS env var.`)}if(r.isCheckedOut)return r.localPath;if(!r.url)throw new Error(`Repo "${r.name}" has no clone URL configured.`);let i=d(r);if(!i)throw new Error(`Cannot clone ${r.name}: '${a(r.url)||r.url}' is not a recognized VCS host (expected github.com, gitlab.com, or the self-hosted GitLab named by GITLAB_URL/GITLAB_INSTANCE_URL${r.provider?`; the repo declares provider='${r.provider}'`:""}). No token was sent.`);let u=i==="gitlab"?process.env.GITLAB_TOKEN:process.env.GITHUB_TOKEN;if(!u)throw new Error(`${i==="gitlab"?"GITLAB_TOKEN":"GITHUB_TOKEN"} not set \u2014 cannot clone ${r.name}. Connect the integration under project settings.`);_(s)||k(s,{recursive:!0});let p=E(r,u);if(p===r.url)throw new Error(`Cannot clone ${r.name}: could not safely attach credentials to '${r.url}' (an https:// URL on an exact trusted host is required). No token was sent.`);let l=["clone"];n>0&&l.push("--depth",String(n)),(o||r.branch)&&l.push("--branch",o||r.branch),l.push(p,r.localPath);try{y(`git ${l.join(" ")}`,{stdio:"pipe",env:{...process.env,GIT_TERMINAL_PROMPT:"0"}})}catch(c){let f=String(c.message||c).replace(u,"***").replace(p,r.url);throw new Error(`Failed to clone ${r.name}: ${f}`,{cause:c})}return b(y,r.localPath,r.url,u,`ensureRepo:${r.name}`),r.localPath}function tt(t={}){let e=g(t);if(e.length===0)return null;let o=["## Available repositories",""];for(let n of e){let s=n.isCheckedOut?"already checked out at":"will be checked out to",r=n.primary?" (primary)":"";o.push(`- \`${n.name}\`${r} \u2014 ${s} \`${n.localPath}\``)}return o.push(""),o.push(`To materialize a repo: call the \`git_checkout\` skill with the repo name (e.g. \`git_checkout({ url: "${e[0].name}" })\`). In code, \`import { ensureRepo } from "@zibby/core"\` and \`await ensureRepo()\` returns the local path (clones on first call, no-op after).`),o.join(`
2
+ `)}export{tt as buildRepoContextHint,X as ensureRepo,v as getRepo,g as listRepos,Q as repoPath};
@@ -1 +1 @@
1
- import{existsSync as T,readFileSync as _}from"node:fs";import{homedir as y}from"node:os";import{join as I}from"node:path";var b=new Map,x={github:"GITHUB_TOKEN",gitlab:"GITLAB_TOKEN",sentry:"SENTRY_AUTH_TOKEN",slack:"SLACK_BOT_TOKEN"};function k(){let t=process.env.ZIBBY_SELF_HOST;return t!=null&&t!==""&&t!=="0"&&t.toLowerCase()!=="false"}function $(){if(process.env.PROJECT_API_TOKEN)return process.env.PROJECT_API_TOKEN;if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let t=I(y(),".zibby","config.json");return T(t)&&JSON.parse(_(t,"utf-8")).sessionToken||null}catch{return null}}function O(){return process.env.ZIBBY_ACCOUNT_API_URL?process.env.ZIBBY_ACCOUNT_API_URL.replace(/\/$/,""):(process.env.ZIBBY_ENV||"prod")==="local"?"http://localhost:3001":process.env.ZIBBY_PROD_ACCOUNT_API_URL||"https://api-prod.zibby.app"}async function w(t){if(k()){let i=x[t];if(i&&process.env[i])return{token:process.env[i]}}let e=Date.now(),n=b.get(t);if(n&&n.expiresAt>e)return n.data;let r=$();if(!r)throw new Error("Missing session credential: neither PROJECT_API_TOKEN nor ZIBBY_USER_TOKEN is set in this process env (and no ~/.zibby/config.json session). If this is an MCP skill child, the spawning skill must forward them \u2014 check the skill's envKeys / resolve() env (see @zibby/skills backend-session-env-contract). Interactive CLI: run `zibby login`.");let a=`${O()}/integrations/token/${t}`,s=await fetch(a,{method:"GET",headers:{Authorization:`Bearer ${r}`}});if(!s.ok){let i=await s.text().catch(()=>"");if(s.status===404){let u="";try{u=String(JSON.parse(i)?.error||"").trim()}catch{}throw new Error(u||`${t} is not connected. Connect it at https://studio.zibby.dev/integrations`)}throw s.status===401||s.status===403?new Error("Session expired. Run `zibby login` to re-authenticate."):new Error(`Failed to resolve ${t} token (${s.status}): ${i}`)}let o=await s.json();if(!o||typeof o!="object")throw new Error(`Invalid response from ${t} token endpoint: expected object, got ${typeof o}`);if(t==="jira"){if(!o.token||typeof o.token!="string")throw new Error(`Invalid jira token response: token is ${typeof o.token}, expected string`);if(!o.cloudId)throw new Error("Invalid jira token response: missing cloudId")}else if(t==="github"&&(!o.token||typeof o.token!="string"))throw new Error(`Invalid github token response: token is ${typeof o.token}, expected string`);let l=((o.expiresInSec||3e3)-120)*1e3;return b.set(t,{data:o,expiresAt:e+l}),o}var K=Object.freeze(["github.com","gitlab.com"]);function m(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function d(t){if(typeof t!="string"||t===""||/[\\\x00-\x20\x7f]/.test(t))return"";let e;try{e=new URL(t)}catch{return""}return e.protocol!=="https:"?"":e.hostname.toLowerCase()}function v(t=process.env){let e=t&&(t.GITLAB_URL||t.GITLAB_INSTANCE_URL)||"";return m(e)}function h(t={}){if(t.gitlabHost){let e=String(t.gitlabHost).trim().toLowerCase();return e?e.includes("://")?m(e):e.replace(/:\d+$/,""):""}return v()}function S(t,e={}){let n=d(t);if(!n)return!1;if(n==="github.com"||n==="gitlab.com")return!0;let r=h(e);return!!(r&&n===r)}function A(t,e={}){if(t==="github.com")return"github";if(t==="gitlab.com")return"gitlab";let n=h(e);return n&&t===n?"gitlab":null}function C(t,e,n={}){if(!t||!e)return t;let r=d(t);if(!r)return t;if(r==="github.com")return t.replace(/^https:\/\/(?:[^@/]+@)?github\.com(?=[:/]|$)/i,`https://x-access-token:${e}@github.com`);if(r==="gitlab.com")return t.replace(/^https:\/\/(?:[^@/]+@)?gitlab\.com(?=[:/]|$)/i,`https://oauth2:${e}@gitlab.com`);let a=h(n);if(a&&r===a){let s=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=new RegExp(`^https:\\/\\/(?:[^@/]+@)?${s}(?=[:/]|$)`,"i");return t.replace(o,`https://oauth2:${e}@${a}`)}return t}function B(t){return t&&String(t).replace(/^(https:\/\/)[^@/]+@/i,"$1")}function N(t,e){let n=t==null?"":String(t);return e&&(n=n.split(e).join("***")),n=n.replace(/(https?:\/\/)(?:x-access-token|oauth2):[^@\s/]+@/gi,"$1"),n=n.replace(/(https?:\/\/)[^@\s/:]+:[^@\s/]+@/gi,"$1"),n}async function P(t,e,n){try{await t("git",["remote","set-url","origin",B(n)],e)}catch(r){console.warn(`\u26A0\uFE0F could not scrub token from origin remote (continuing): ${r?.message||r}`)}}async function z({run:t,repoPath:e,repoUrl:n,branch:r,token:a,resolveToken:s=w,gitlabHost:o}={}){if(typeof t!="function")throw new Error("securePush: `run` (a spawn wrapper resolving {code,stdout,stderr}) is required");if(!r)throw new Error("securePush: `branch` is required");let l=h({gitlabHost:o}),i=d(n),u=S(n,{gitlabHost:l}),f=a||"";if(!f&&u&&typeof s=="function"){let p=A(i,{gitlabHost:l});if(p)try{f=(await s(p))?.token||""}catch{}}else!f&&!u&&console.warn(`\u26A0\uFE0F push target host '${i||"(unparseable)"}' is not a trusted VCS host \u2014 refusing to mint a token`);let g=f&&u,E=g?C(n,f,{gitlabHost:l}):"origin",c=await t("git",["push",E,r],e);if(!c||c.code!==0){let p=N(c&&c.stderr||"",f);throw new Error(`git push failed (exit ${c?c.code:"?"}): ${String(p).slice(-500)}`)}return{code:c.code,stdout:c.stdout,stderr:c.stderr,pushedAuthed:!!g,target:g?"<authed>":"origin"}}export{K as TRUSTED_VCS_HOSTS,C as authedUrl,m as hostnameOf,S as isTrustedVcsHost,A as providerForHost,N as redactGitSecrets,d as safeVcsHostname,P as scrubRemoteToTokenless,z as securePush,v as selfHostGitlabHost,B as tokenlessUrl};
1
+ import{existsSync as v,readFileSync as x}from"node:fs";import{homedir as I}from"node:os";import{join as k}from"node:path";var w=new Map,$={github:"GITHUB_TOKEN",gitlab:"GITLAB_TOKEN",sentry:"SENTRY_AUTH_TOKEN",slack:"SLACK_BOT_TOKEN"};function O(){let t=process.env.ZIBBY_SELF_HOST;return t!=null&&t!==""&&t!=="0"&&t.toLowerCase()!=="false"}function S(){if(process.env.PROJECT_API_TOKEN)return process.env.PROJECT_API_TOKEN;if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let t=k(I(),".zibby","config.json");return v(t)&&JSON.parse(x(t,"utf-8")).sessionToken||null}catch{return null}}function A(){return process.env.ZIBBY_ACCOUNT_API_URL?process.env.ZIBBY_ACCOUNT_API_URL.replace(/\/$/,""):(process.env.ZIBBY_ENV||"prod")==="local"?"http://localhost:3001":process.env.ZIBBY_PROD_ACCOUNT_API_URL||"https://api-prod.zibby.app"}async function m(t){if(O()){let c=$[t];if(c&&process.env[c])return{token:process.env[c]}}let e=Date.now(),n=w.get(t);if(n&&n.expiresAt>e)return n.data;let r=S();if(!r)throw new Error("Missing session credential: neither PROJECT_API_TOKEN nor ZIBBY_USER_TOKEN is set in this process env (and no ~/.zibby/config.json session). If this is an MCP skill child, the spawning skill must forward them \u2014 check the skill's envKeys / resolve() env (see @zibby/skills backend-session-env-contract). Interactive CLI: run `zibby login`.");let s=`${A()}/integrations/token/${t}`,i=await fetch(s,{method:"GET",headers:{Authorization:`Bearer ${r}`}});if(!i.ok){let c=await i.text().catch(()=>"");if(i.status===404){let u="";try{u=String(JSON.parse(c)?.error||"").trim()}catch{}throw new Error(u||`${t} is not connected. Connect it at https://studio.zibby.dev/integrations`)}throw i.status===401||i.status===403?new Error("Session expired. Run `zibby login` to re-authenticate."):new Error(`Failed to resolve ${t} token (${i.status}): ${c}`)}let o=await i.json();if(!o||typeof o!="object")throw new Error(`Invalid response from ${t} token endpoint: expected object, got ${typeof o}`);if(t==="jira"){if(!o.token||typeof o.token!="string")throw new Error(`Invalid jira token response: token is ${typeof o.token}, expected string`);if(!o.cloudId)throw new Error("Invalid jira token response: missing cloudId")}else if(t==="github"&&(!o.token||typeof o.token!="string"))throw new Error(`Invalid github token response: token is ${typeof o.token}, expected string`);let f=((o.expiresInSec||3e3)-120)*1e3;return w.set(t,{data:o,expiresAt:e+f}),o}var z=Object.freeze(["github.com","gitlab.com"]);function b(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function g(t){if(typeof t!="string"||t===""||/[\\\x00-\x20\x7f]/.test(t))return"";let e;try{e=new URL(t)}catch{return""}return e.protocol!=="https:"?"":e.hostname.toLowerCase()}function C(t=process.env){let e=t&&(t.GITLAB_URL||t.GITLAB_INSTANCE_URL)||"";return b(e)}function p(t={}){if(t.gitlabHost){let e=String(t.gitlabHost).trim().toLowerCase();return e?e.includes("://")?b(e):e.replace(/:\d+$/,""):""}return C()}function B(t,e={}){let n=g(t);if(!n)return!1;if(n==="github.com"||n==="gitlab.com")return!0;let r=p(e);return!!(r&&n===r)}function E(t,e={}){if(t==="github.com")return"github";if(t==="gitlab.com")return"gitlab";let n=p(e);return n&&t===n?"gitlab":null}function R(t={},e={}){let n=t&&(t.cloneUrl||t.url)||"",r=b(n);if(!r)return null;let s=t.provider==="github"||t.provider==="gitlab"?t.provider:null,i=T(t,e),o=E(r,i?{gitlabHost:i}:{});return o?s&&s!==o?null:o:s==="gitlab"?"gitlab":null}function T(t,e={}){let n=p(e);return n||(t&&t.provider==="gitlab"?g(t.cloneUrl||t.url||""):"")}function G(t={},e="",n={}){let r=t&&(t.cloneUrl||t.url)||"";if(!r||!e||!R(t,n))return r;let s=T(t,n);return _(r,e,s?{gitlabHost:s}:{})}function _(t,e,n={}){if(!t||!e)return t;let r=g(t);if(!r)return t;if(r==="github.com")return t.replace(/^https:\/\/(?:[^@/]+@)?github\.com(?=[:/]|$)/i,`https://x-access-token:${e}@github.com`);if(r==="gitlab.com")return t.replace(/^https:\/\/(?:[^@/]+@)?gitlab\.com(?=[:/]|$)/i,`https://oauth2:${e}@gitlab.com`);let s=p(n);if(s&&r===s){let i=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=new RegExp(`^https:\\/\\/(?:[^@/]+@)?${i}(?=[:/]|$)`,"i");return t.replace(o,`https://oauth2:${e}@${s}`)}return t}function N(t){return t&&String(t).replace(/^(https:\/\/)[^@/]+@/i,"$1")}function H(t,e){let n=t==null?"":String(t);return e&&(n=n.split(e).join("***")),n=n.replace(/(https?:\/\/)(?:x-access-token|oauth2):[^@\s/]+@/gi,"$1"),n=n.replace(/(https?:\/\/)[^@\s/:]+:[^@\s/]+@/gi,"$1"),n}async function F(t,e,n){try{await t("git",["remote","set-url","origin",N(n)],e)}catch(r){console.warn(`\u26A0\uFE0F could not scrub token from origin remote (continuing): ${r?.message||r}`)}}async function Y({run:t,repoPath:e,repoUrl:n,branch:r,token:s,resolveToken:i=m,gitlabHost:o}={}){if(typeof t!="function")throw new Error("securePush: `run` (a spawn wrapper resolving {code,stdout,stderr}) is required");if(!r)throw new Error("securePush: `branch` is required");let f=p({gitlabHost:o}),c=g(n),u=B(n,{gitlabHost:f}),l=s||"";if(!l&&u&&typeof i=="function"){let h=E(c,{gitlabHost:f});if(h)try{l=(await i(h))?.token||""}catch{}}else!l&&!u&&console.warn(`\u26A0\uFE0F push target host '${c||"(unparseable)"}' is not a trusted VCS host \u2014 refusing to mint a token`);let d=l&&u,y=d?_(n,l,{gitlabHost:f}):"origin",a=await t("git",["push",y,r],e);if(!a||a.code!==0){let h=H(a&&a.stderr||"",l);throw new Error(`git push failed (exit ${a?a.code:"?"}): ${String(h).slice(-500)}`)}return{code:a.code,stdout:a.stdout,stderr:a.stderr,pushedAuthed:!!d,target:d?"<authed>":"origin"}}export{z as TRUSTED_VCS_HOSTS,_ as authedUrl,G as authedUrlForRepo,b as hostnameOf,B as isTrustedVcsHost,E as providerForHost,R as providerForRepo,H as redactGitSecrets,g as safeVcsHostname,F as scrubRemoteToTokenless,Y as securePush,C as selfHostGitlabHost,N as tokenlessUrl};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/core",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Core test automation engine with multi-agent and multi-MCP support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -69,9 +69,9 @@
69
69
  "@modelcontextprotocol/sdk": "^1.29.0",
70
70
  "@openai/codex-sdk": "^0.143.0",
71
71
  "@playwright/mcp": "^0.0.70",
72
- "@zibby/agent-workflow": "2.0.0",
73
- "@zibby/mcp-browser": "2.0.0",
74
- "@zibby/skill-ids": "2.0.0",
72
+ "@zibby/agent-workflow": "2.0.1",
73
+ "@zibby/mcp-browser": "2.0.1",
74
+ "@zibby/skill-ids": "2.0.1",
75
75
  "acorn": "^8.15.0",
76
76
  "acorn-walk": "^8.3.5",
77
77
  "axios": "^1.15.0",