@zibby/skills 0.1.22 → 0.1.24

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/index.js CHANGED
@@ -104,17 +104,17 @@ When user says "check out repo-name" or "clone repo-name":
104
104
  When user just wants to "look at" or "read" files (not clone):
105
105
  - Use github_get_file to read individual files via API`,resolve(){let r={};for(let t of this.envKeys)process.env[t]&&(r[t]=process.env[t]);return{command:"npx",args:["-y","@modelcontextprotocol/server-github@latest"],env:r}},async handleToolCall(r,t){try{switch(r){case"github_search_issues":{let e=t.query;if(!e)return JSON.stringify({error:"query is required"});let s=await $(`/search/issues?q=${encodeURIComponent(e)}&per_page=${t.limit||20}`),n=(s.items||[]).map(i=>({number:i.number,title:i.title,state:i.state,repo:i.repository_url?.split("/").slice(-2).join("/"),url:i.html_url,user:i.user?.login,isPR:!!i.pull_request,labels:(i.labels||[]).map(o=>o.name),createdAt:i.created_at}));return JSON.stringify({total:s.total_count,items:n})}case"github_search_code":{let e=t.query;if(!e)return JSON.stringify({error:"query is required"});let s=t.repo?`+repo:${t.repo}`:"",n=t.language?`+language:${t.language}`:"",i=await $(`/search/code?q=${encodeURIComponent(e)}${s}${n}&per_page=${t.limit||15}`),o=(i.items||[]).map(a=>({name:a.name,path:a.path,repo:a.repository?.full_name,url:a.html_url,score:a.score}));return JSON.stringify({total:i.total_count,items:o})}case"github_get_pr":{let{owner:e,repo:s,number:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await $(`/repos/${e}/${s}/pulls/${n}`);return JSON.stringify({number:i.number,title:i.title,state:i.state,merged:i.merged,body:i.body?.slice(0,5e3),user:i.user?.login,branch:i.head?.ref,base:i.base?.ref,changedFiles:i.changed_files,additions:i.additions,deletions:i.deletions,createdAt:i.created_at,mergedAt:i.merged_at,url:i.html_url,labels:(i.labels||[]).map(o=>o.name)})}case"github_get_pr_diff":{let{owner:e,repo:s,number:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await $(`/repos/${e}/${s}/pulls/${n}`,{accept:"application/vnd.github.v3.diff",raw:!0}),o=i.length>15e3;return JSON.stringify({number:n,diff:o?i.slice(0,15e3):i,truncated:o,totalLength:i.length})}case"github_list_pr_files":{let{owner:e,repo:s,number:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await $(`/repos/${e}/${s}/pulls/${n}/files?per_page=100`);return JSON.stringify({total:i.length,files:i.map(o=>({filename:o.filename,status:o.status,additions:o.additions,deletions:o.deletions,patch:o.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:e,repo:s,number:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await $(`/repos/${e}/${s}/pulls/${n}/comments?per_page=50`),o=await $(`/repos/${e}/${s}/issues/${n}/comments?per_page=50`),a=[...i.map(c=>({type:"review",user:c.user?.login,body:c.body?.slice(0,1e3),path:c.path,line:c.line,createdAt:c.created_at})),...o.map(c=>({type:"issue",user:c.user?.login,body:c.body?.slice(0,1e3),createdAt:c.created_at}))].sort((c,l)=>new Date(c.createdAt)-new Date(l.createdAt));return JSON.stringify({total:a.length,comments:a})}case"github_list_commits":{let{owner:e,repo:s,branch:n,path:i,limit:o}=t;if(!e||!s)return JSON.stringify({error:"owner and repo are required"});let a=`/repos/${e}/${s}/commits?per_page=${o||20}`;n&&(a+=`&sha=${encodeURIComponent(n)}`),i&&(a+=`&path=${encodeURIComponent(i)}`);let c=await $(a);return JSON.stringify({total:c.length,commits:c.map(l=>({sha:l.sha?.slice(0,8),fullSha:l.sha,message:l.commit?.message?.slice(0,300),author:l.commit?.author?.name,date:l.commit?.author?.date,url:l.html_url}))})}case"github_get_commit":{let{owner:e,repo:s,sha:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and sha are required"});let i=await $(`/repos/${e}/${s}/commits/${n}`);return JSON.stringify({sha:i.sha?.slice(0,8),message:i.commit?.message,author:i.commit?.author?.name,date:i.commit?.author?.date,stats:i.stats,files:(i.files||[]).map(o=>({filename:o.filename,status:o.status,additions:o.additions,deletions:o.deletions,patch:o.patch?.slice(0,3e3)}))})}case"github_get_file":{let{owner:e,repo:s,path:n,ref:i}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and path are required"});let o=`/repos/${e}/${s}/contents/${encodeURIComponent(n)}`;i&&(o+=`?ref=${encodeURIComponent(i)}`);let a=await $(o);if(a.type!=="file")return Array.isArray(a)?JSON.stringify({type:"directory",path:n,entries:a.map(u=>({name:u.name,type:u.type,size:u.size,path:u.path}))}):JSON.stringify({error:`Not a file: ${a.type}`});let c=Buffer.from(a.content||"","base64").toString("utf-8"),l=c.length>2e4;return JSON.stringify({path:a.path,size:a.size,sha:a.sha?.slice(0,8),content:l?c.slice(0,2e4):c,truncated:l})}case"github_get_user":try{let e=await $("/installation/repositories?per_page=1");if(e.repositories&&e.repositories.length>0){let s=e.repositories[0],n=s.owner.login,i=s.owner.type,o=i==="Organization"?`/orgs/${n}`:`/users/${n}`,a=await $(o);return JSON.stringify({login:a.login,name:a.name||a.login,avatar:a.avatar_url,bio:a.bio||a.description,type:i,isOrg:i==="Organization",publicRepos:a.public_repos,message:"Showing GitHub App installation owner (GitHub Apps cannot access /user endpoint)"})}return JSON.stringify({error:"No repositories accessible to this GitHub App installation"})}catch(e){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${e.message})`})}case"github_list_orgs":try{let s=(await $("/installation/repositories?per_page=100")).repositories||[],n=new Map;for(let o of s)o.owner.type==="Organization"&&(n.has(o.owner.login)||n.set(o.owner.login,{login:o.owner.login,description:null,url:o.owner.url}));let i=Array.from(n.values());return JSON.stringify({count:i.length,orgs:i,message:"Extracted from accessible repositories (GitHub Apps cannot access /user/orgs directly)"})}catch(e){return JSON.stringify({error:`GitHub App cannot list orgs via /user/orgs. Error: ${e.message}`})}case"github_clone":{let f=function(g){let _=g.replace(/^~(?=$|\/|\\)/,m);return a(_)},{owner:e,repo:s,destination:n}=t;if(!e||!s)return JSON.stringify({error:"owner and repo are required"});let{execSync:i}=await import("child_process"),{join:o,resolve:a}=await import("path"),{existsSync:c,mkdirSync:l}=await import("fs"),{homedir:u,platform:p}=await import("os"),{token:y}=await Me("github"),m=u(),k=n?f(n):o(m,"zibby-repos"),h=o(k,s);if(l(k,{recursive:!0}),c(h))return JSON.stringify({error:`Directory ${h} already exists. Remove it first or use a different destination.`,existingPath:h});try{let g=`https://x-access-token:${y}@github.com/${e}/${s}.git`;i(`git clone ${g} "${h}"`,{stdio:"pipe"});let _=p()==="win32",d;return _?d=i(`dir "${h}"`,{encoding:"utf-8",shell:"cmd.exe"}):d=i(`ls -la "${h}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:h,message:`Cloned ${e}/${s} to ${h}`,contents:d.split(`
106
106
  `).slice(0,30).join(`
107
- `),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(g){return JSON.stringify({error:`Clone failed: ${g.message}`})}}case"github_search_repos":{let{query:e,limit:s}=t;if(!e)return JSON.stringify({error:"query is required"});let n=await this.handleToolCall("github_list_repos",{limit:200},{}),i=JSON.parse(n);if(i.error)return JSON.stringify(i);let o=e.toLowerCase(),a=i.repos.filter(c=>c.name.toLowerCase().includes(o)||c.fullName.toLowerCase().includes(o)||c.description&&c.description.toLowerCase().includes(o));return JSON.stringify({query:e,count:a.length,repos:a.slice(0,s||20)})}case"github_list_repos":{let{owner:e,type:s,sort:n,direction:i,limit:o}=t,a=100,c=o||200,l=[];if(!e){let f=1,k=!0;for(;k&&l.length<c;){let d=`/installation/repositories?per_page=${a}&page=${f}`,I=(await $(d)).repositories||[];if(I.length===0)break;l=l.concat(I),k=I.length===a,f++}let h=l.slice(0,c).map(d=>({name:d.name,fullName:d.full_name,private:d.private,description:d.description,language:d.language,defaultBranch:d.default_branch,updatedAt:d.updated_at,stars:d.stargazers_count,url:d.html_url})),g=h.filter(d=>d.private).length,_=h.filter(d=>!d.private).length;return JSON.stringify({count:h.length,repos:h,privateCount:g,publicCount:_,message:`Found ${g} private and ${_} public repos`})}let u=await $(`/orgs/${e}`).then(()=>!0).catch(()=>!1),p=1,y=!0;for(;y&&l.length<c;){let f;u?f=`/orgs/${e}/repos?per_page=${a}&page=${p}&type=${s||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`:f=`/users/${e}/repos?per_page=${a}&page=${p}&type=${s||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`;let k=await $(f),h=Array.isArray(k)?k:[];if(h.length===0)break;l=l.concat(h),y=h.length===a,p++}let m=l.slice(0,c).map(f=>({name:f.name,fullName:f.full_name,private:f.private,description:f.description,language:f.language,defaultBranch:f.default_branch,updatedAt:f.updated_at,stars:f.stargazers_count,url:f.html_url}));return JSON.stringify({count:m.length,repos:m})}case"github_create_issue":{let{owner:e,repo:s,title:n,body:i}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and title are required"});let o=await $(`/repos/${e}/${s}/issues`,{method:"POST",body:{title:n,body:i||""}});return JSON.stringify({number:o.number,url:o.html_url,title:o.title})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"github_get_user",description:"Get the authenticated GitHub user profile and their organizations",input_schema:{type:"object",properties:{}}},{name:"github_list_orgs",description:"List GitHub organizations the authenticated user belongs to",input_schema:{type:"object",properties:{}}},{name:"github_list_repos",description:"List repositories for a user or org. If no owner given, lists the authenticated user's repos.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Org or user login. Omit to list your own repos."},type:{type:"string",enum:["all","public","private","forks","sources","member"],description:"Filter by type (default: all)"},sort:{type:"string",enum:["created","updated","pushed","full_name"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max repos to return (default: 30)"}}}},{name:"github_clone",description:'Clone a GitHub repository to the local filesystem. Use when user says "check out" or "clone" a repo.',input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner (user or org name)"},repo:{type:"string",description:"Repository name"},destination:{type:"string",description:"Destination directory. Accepts absolute paths, ~-prefixed paths, or relative names. Defaults to ~/zibby-repos/<repo>."}},required:["owner","repo"]}},{name:"github_search_repos",description:"Search accessible repositories by name or description. Use this when the user asks to find a specific repo.",input_schema:{type:"object",properties:{query:{type:"string",description:'Search term to match against repo name or description (e.g., "electron", "my-app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_issues",description:"Search GitHub issues and pull requests",input_schema:{type:"object",properties:{query:{type:"string",description:'GitHub search query (e.g. "SCRUM-123", "login bug repo:org/app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_code",description:"Search code across GitHub repositories by keyword",input_schema:{type:"object",properties:{query:{type:"string",description:'Code search query (e.g. "handleLogin", "class AuthService")'},repo:{type:"string",description:'Scope to a specific repo (e.g. "org/app"). Optional.'},language:{type:"string",description:'Filter by language (e.g. "javascript", "python"). Optional.'},limit:{type:"number",description:"Max results (default: 15)"}},required:["query"]}},{name:"github_get_pr",description:"Get details of a pull request \u2014 title, description, branch, stats",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_get_pr_diff",description:"Get the unified diff of a pull request \u2014 the actual code changes",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_files",description:"List files changed in a PR with per-file patches",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_comments",description:"Get all review and issue comments on a PR",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_commits",description:"List recent commits on a branch, optionally filtered by file path",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},branch:{type:"string",description:"Branch name (default: repo default branch)"},path:{type:"string",description:"Filter commits touching this file path"},limit:{type:"number",description:"Max commits (default: 20)"}},required:["owner","repo"]}},{name:"github_get_commit",description:"Get details of a specific commit \u2014 message, stats, file diffs",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},sha:{type:"string",description:"Commit SHA (full or short)"}},required:["owner","repo","sha"]}},{name:"github_get_file",description:"Read a file (or list a directory) from a GitHub repo. Works on any branch/ref.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},path:{type:"string",description:'File or directory path (e.g. "src/auth/login.ts")'},ref:{type:"string",description:"Branch, tag, or commit SHA (default: repo default branch)"}},required:["owner","repo","path"]}},{name:"github_create_issue",description:"Create a GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},title:{type:"string",description:"Issue title"},body:{type:"string",description:"Issue body (markdown)"}},required:["owner","repo","title"]}}]};import{resolveIntegrationToken as ys}from"@zibby/core/backend-client.js";async function q(r,t={}){let{token:e}=await ys("slack"),s=["conversations.list","users.list","users.profile.get","conversations.history","conversations.replies"].includes(r),n=`https://slack.com/api/${r}`,i={Authorization:`Bearer ${e}`},o;if(s){let l=new URLSearchParams(t).toString();l&&(n+=`?${l}`)}else i["Content-Type"]="application/json; charset=utf-8",o=JSON.stringify(t);let c=await(await fetch(n,{method:s?"GET":"POST",headers:i,body:o})).json();if(!c.ok)throw new Error(`Slack API error: ${c.error}`);return c}var he={id:"slack",serverName:"slack",allowedTools:["mcp__slack__*"],envKeys:["SLACK_BOT_TOKEN","SLACK_TEAM_ID"],description:"Slack MCP Server",promptFragment:`## Slack (connected)
107
+ `),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(g){return JSON.stringify({error:`Clone failed: ${g.message}`})}}case"github_search_repos":{let{query:e,limit:s}=t;if(!e)return JSON.stringify({error:"query is required"});let n=await this.handleToolCall("github_list_repos",{limit:200},{}),i=JSON.parse(n);if(i.error)return JSON.stringify(i);let o=e.toLowerCase(),a=i.repos.filter(c=>c.name.toLowerCase().includes(o)||c.fullName.toLowerCase().includes(o)||c.description&&c.description.toLowerCase().includes(o));return JSON.stringify({query:e,count:a.length,repos:a.slice(0,s||20)})}case"github_list_repos":{let{owner:e,type:s,sort:n,direction:i,limit:o}=t,a=100,c=o||200,l=[];if(!e){let f=1,k=!0;for(;k&&l.length<c;){let d=`/installation/repositories?per_page=${a}&page=${f}`,I=(await $(d)).repositories||[];if(I.length===0)break;l=l.concat(I),k=I.length===a,f++}let h=l.slice(0,c).map(d=>({name:d.name,fullName:d.full_name,private:d.private,description:d.description,language:d.language,defaultBranch:d.default_branch,updatedAt:d.updated_at,stars:d.stargazers_count,url:d.html_url})),g=h.filter(d=>d.private).length,_=h.filter(d=>!d.private).length;return JSON.stringify({count:h.length,repos:h,privateCount:g,publicCount:_,message:`Found ${g} private and ${_} public repos`})}let u=await $(`/orgs/${e}`).then(()=>!0).catch(()=>!1),p=1,y=!0;for(;y&&l.length<c;){let f;u?f=`/orgs/${e}/repos?per_page=${a}&page=${p}&type=${s||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`:f=`/users/${e}/repos?per_page=${a}&page=${p}&type=${s||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`;let k=await $(f),h=Array.isArray(k)?k:[];if(h.length===0)break;l=l.concat(h),y=h.length===a,p++}let m=l.slice(0,c).map(f=>({name:f.name,fullName:f.full_name,private:f.private,description:f.description,language:f.language,defaultBranch:f.default_branch,updatedAt:f.updated_at,stars:f.stargazers_count,url:f.html_url}));return JSON.stringify({count:m.length,repos:m})}case"github_create_issue":{let{owner:e,repo:s,title:n,body:i}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and title are required"});let o=await $(`/repos/${e}/${s}/issues`,{method:"POST",body:{title:n,body:i||""}});return JSON.stringify({number:o.number,url:o.html_url,title:o.title})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"github_get_user",description:"Get the authenticated GitHub user profile and their organizations",input_schema:{type:"object",properties:{}}},{name:"github_list_orgs",description:"List GitHub organizations the authenticated user belongs to",input_schema:{type:"object",properties:{}}},{name:"github_list_repos",description:"List repositories for a user or org. If no owner given, lists the authenticated user's repos.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Org or user login. Omit to list your own repos."},type:{type:"string",enum:["all","public","private","forks","sources","member"],description:"Filter by type (default: all)"},sort:{type:"string",enum:["created","updated","pushed","full_name"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max repos to return (default: 30)"}}}},{name:"github_clone",description:'Clone a GitHub repository to the local filesystem. Use when user says "check out" or "clone" a repo.',input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner (user or org name)"},repo:{type:"string",description:"Repository name"},destination:{type:"string",description:"Destination directory. Accepts absolute paths, ~-prefixed paths, or relative names. Defaults to ~/zibby-repos/<repo>."}},required:["owner","repo"]}},{name:"github_search_repos",description:"Search accessible repositories by name or description. Use this when the user asks to find a specific repo.",input_schema:{type:"object",properties:{query:{type:"string",description:'Search term to match against repo name or description (e.g., "electron", "my-app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_issues",description:"Search GitHub issues and pull requests",input_schema:{type:"object",properties:{query:{type:"string",description:'GitHub search query (e.g. "SCRUM-123", "login bug repo:org/app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_code",description:"Search code across GitHub repositories by keyword",input_schema:{type:"object",properties:{query:{type:"string",description:'Code search query (e.g. "handleLogin", "class AuthService")'},repo:{type:"string",description:'Scope to a specific repo (e.g. "org/app"). Optional.'},language:{type:"string",description:'Filter by language (e.g. "javascript", "python"). Optional.'},limit:{type:"number",description:"Max results (default: 15)"}},required:["query"]}},{name:"github_get_pr",description:"Get details of a pull request \u2014 title, description, branch, stats",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_get_pr_diff",description:"Get the unified diff of a pull request \u2014 the actual code changes",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_files",description:"List files changed in a PR with per-file patches",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_comments",description:"Get all review and issue comments on a PR",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_commits",description:"List recent commits on a branch, optionally filtered by file path",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},branch:{type:"string",description:"Branch name (default: repo default branch)"},path:{type:"string",description:"Filter commits touching this file path"},limit:{type:"number",description:"Max commits (default: 20)"}},required:["owner","repo"]}},{name:"github_get_commit",description:"Get details of a specific commit \u2014 message, stats, file diffs",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},sha:{type:"string",description:"Commit SHA (full or short)"}},required:["owner","repo","sha"]}},{name:"github_get_file",description:"Read a file (or list a directory) from a GitHub repo. Works on any branch/ref.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},path:{type:"string",description:'File or directory path (e.g. "src/auth/login.ts")'},ref:{type:"string",description:"Branch, tag, or commit SHA (default: repo default branch)"}},required:["owner","repo","path"]}},{name:"github_create_issue",description:"Create a GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},title:{type:"string",description:"Issue title"},body:{type:"string",description:"Issue body (markdown)"}},required:["owner","repo","title"]}}]};import{resolveIntegrationToken as ys}from"@zibby/core/backend-client.js";async function U(r,t={}){let{token:e}=await ys("slack"),s=["conversations.list","users.list","users.profile.get","conversations.history","conversations.replies"].includes(r),n=`https://slack.com/api/${r}`,i={Authorization:`Bearer ${e}`},o;if(s){let l=new URLSearchParams(t).toString();l&&(n+=`?${l}`)}else i["Content-Type"]="application/json; charset=utf-8",o=JSON.stringify(t);let c=await(await fetch(n,{method:s?"GET":"POST",headers:i,body:o})).json();if(!c.ok)throw new Error(`Slack API error: ${c.error}`);return c}var he={id:"slack",serverName:"slack",allowedTools:["mcp__slack__*"],envKeys:["SLACK_BOT_TOKEN","SLACK_TEAM_ID"],description:"Slack MCP Server",promptFragment:`## Slack (connected)
108
108
  You have access to the user's Slack workspace. Use these tools:
109
109
  - slack_list_channels, slack_post_message, slack_reply_to_thread
110
110
  - slack_add_reaction, slack_get_channel_history, slack_get_thread_replies
111
- - slack_get_users, slack_get_user_profile`,resolve(){let r={};for(let t of this.envKeys)process.env[t]&&(r[t]=process.env[t]);return{command:"npx",args:["-y","@modelcontextprotocol/server-slack@latest"],env:r}},async handleToolCall(r,t){try{switch(r){case"slack_list_channels":{let e=await q("conversations.list",{types:"public_channel",limit:100});return JSON.stringify({channels:(e.channels||[]).map(s=>({id:s.id,name:s.name,topic:s.topic?.value}))})}case"slack_post_message":{if(!t.channel||!t.text)return JSON.stringify({error:"channel and text are required"});let e=await q("chat.postMessage",{channel:t.channel,text:t.text});return JSON.stringify({ok:!0,ts:e.ts,channel:e.channel})}case"slack_reply_to_thread":{if(!t.channel||!t.thread_ts||!t.text)return JSON.stringify({error:"channel, thread_ts, and text are required"});let e=await q("chat.postMessage",{channel:t.channel,thread_ts:t.thread_ts,text:t.text});return JSON.stringify({ok:!0,ts:e.ts})}case"slack_add_reaction":return!t.channel||!t.timestamp||!t.reaction?JSON.stringify({error:"channel, timestamp, and reaction are required"}):(await q("reactions.add",{channel:t.channel,timestamp:t.timestamp,name:t.reaction}),JSON.stringify({ok:!0}));case"slack_get_channel_history":{if(!t.channel)return JSON.stringify({error:"channel is required"});let e=await q("conversations.history",{channel:t.channel,limit:t.limit||20});return JSON.stringify({messages:(e.messages||[]).map(s=>({user:s.user,text:s.text,ts:s.ts}))})}case"slack_get_thread_replies":{if(!t.channel||!t.thread_ts)return JSON.stringify({error:"channel and thread_ts are required"});let e=await q("conversations.replies",{channel:t.channel,ts:t.thread_ts});return JSON.stringify({messages:(e.messages||[]).map(s=>({user:s.user,text:s.text,ts:s.ts}))})}case"slack_get_users":{let e=await q("users.list",{limit:100});return JSON.stringify({users:(e.members||[]).filter(s=>!s.is_bot&&!s.deleted).map(s=>({id:s.id,name:s.real_name||s.name}))})}case"slack_get_user_profile":{if(!t.user_id)return JSON.stringify({error:"user_id is required"});let e=await q("users.profile.get",{user:t.user_id});return JSON.stringify({profile:e.profile})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"slack_list_channels",description:"List public channels in the workspace",input_schema:{type:"object",properties:{}}},{name:"slack_post_message",description:"Post a message to a Slack channel or DM",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID or name"},text:{type:"string",description:"Message text"}},required:["channel","text"]}},{name:"slack_reply_to_thread",description:"Reply to a specific message thread",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},thread_ts:{type:"string",description:"Thread timestamp"},text:{type:"string",description:"Reply text"}},required:["channel","thread_ts","text"]}},{name:"slack_add_reaction",description:"Add an emoji reaction to a message",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},timestamp:{type:"string",description:"Message timestamp"},reaction:{type:"string",description:"Emoji name without colons"}},required:["channel","timestamp","reaction"]}},{name:"slack_get_channel_history",description:"Get recent messages from a channel",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},limit:{type:"number",description:"Number of messages"}},required:["channel"]}},{name:"slack_get_thread_replies",description:"Get all replies in a message thread",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},thread_ts:{type:"string",description:"Thread timestamp"}},required:["channel","thread_ts"]}},{name:"slack_get_users",description:"List workspace users with basic profiles",input_schema:{type:"object",properties:{}}},{name:"slack_get_user_profile",description:"Get detailed profile for a specific user",input_schema:{type:"object",properties:{user_id:{type:"string",description:"Slack user ID"}},required:["user_id"]}}]};import{createRequire as gs}from"module";import{resolveIntegrationToken as hs}from"@zibby/core/backend-client.js";var _s=gs(import.meta.url);function ks(){if(process.env.MCP_LARK_PATH)return process.env.MCP_LARK_PATH;try{return _s.resolve("@zibby/skills/bin/mcp-lark.mjs")}catch{return null}}var ws=6e3*1e3,Z=null;async function bs(){let{appId:r,appSecret:t,host:e}=await hs("lark");if(Z&&Z.appId===r&&Z.expiresAt>Date.now())return{token:Z.token,host:e};let n=await(await fetch(`${e}/open-apis/auth/v3/tenant_access_token/internal`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({app_id:r,app_secret:t})})).json();if(n.code!==0)throw new Error(`Lark tenant_access_token failed: ${n.msg||n.code}`);return Z={token:n.tenant_access_token,expiresAt:Date.now()+ws,appId:r},{token:n.tenant_access_token,host:e}}async function se(r,t,e={}){let{token:s,host:n}=await bs(),i=`${n}${t}`,o={method:r,headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json; charset=utf-8"}};r!=="GET"&&(o.body=JSON.stringify(e));let c=await(await fetch(i,o)).json();if(c.code!==0)throw new Error(`Lark API ${t} error: ${c.msg||c.code}`);return c.data||{}}function qe(r){return JSON.stringify({text:r})}function Ss(r){return!r||typeof r!="string"||r.startsWith("oc_")?"chat_id":r.startsWith("ou_")?"open_id":r.startsWith("on_")?"union_id":r.startsWith("cli_")?"app_id":r.includes("@")?"email":"chat_id"}var Ue={id:"lark",serverName:"lark",allowedTools:["mcp__lark__*"],description:"Lark / Feishu messaging \u2014 send messages and reply in threads.",envKeys:[],promptFragment:`## Lark (connected)
111
+ - slack_get_users, slack_get_user_profile`,resolve(){let r={};for(let t of this.envKeys)process.env[t]&&(r[t]=process.env[t]);return{command:"npx",args:["-y","@modelcontextprotocol/server-slack@latest"],env:r}},async handleToolCall(r,t){try{switch(r){case"slack_list_channels":{let e=await U("conversations.list",{types:"public_channel",limit:100});return JSON.stringify({channels:(e.channels||[]).map(s=>({id:s.id,name:s.name,topic:s.topic?.value}))})}case"slack_post_message":{if(!t.channel||!t.text)return JSON.stringify({error:"channel and text are required"});let e=await U("chat.postMessage",{channel:t.channel,text:t.text});return JSON.stringify({ok:!0,ts:e.ts,channel:e.channel})}case"slack_reply_to_thread":{if(!t.channel||!t.thread_ts||!t.text)return JSON.stringify({error:"channel, thread_ts, and text are required"});let e=await U("chat.postMessage",{channel:t.channel,thread_ts:t.thread_ts,text:t.text});return JSON.stringify({ok:!0,ts:e.ts})}case"slack_add_reaction":return!t.channel||!t.timestamp||!t.reaction?JSON.stringify({error:"channel, timestamp, and reaction are required"}):(await U("reactions.add",{channel:t.channel,timestamp:t.timestamp,name:t.reaction}),JSON.stringify({ok:!0}));case"slack_get_channel_history":{if(!t.channel)return JSON.stringify({error:"channel is required"});let e=await U("conversations.history",{channel:t.channel,limit:t.limit||20});return JSON.stringify({messages:(e.messages||[]).map(s=>({user:s.user,text:s.text,ts:s.ts}))})}case"slack_get_thread_replies":{if(!t.channel||!t.thread_ts)return JSON.stringify({error:"channel and thread_ts are required"});let e=await U("conversations.replies",{channel:t.channel,ts:t.thread_ts});return JSON.stringify({messages:(e.messages||[]).map(s=>({user:s.user,text:s.text,ts:s.ts}))})}case"slack_get_users":{let e=await U("users.list",{limit:100});return JSON.stringify({users:(e.members||[]).filter(s=>!s.is_bot&&!s.deleted).map(s=>({id:s.id,name:s.real_name||s.name}))})}case"slack_get_user_profile":{if(!t.user_id)return JSON.stringify({error:"user_id is required"});let e=await U("users.profile.get",{user:t.user_id});return JSON.stringify({profile:e.profile})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"slack_list_channels",description:"List public channels in the workspace",input_schema:{type:"object",properties:{}}},{name:"slack_post_message",description:"Post a message to a Slack channel or DM",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID or name"},text:{type:"string",description:"Message text"}},required:["channel","text"]}},{name:"slack_reply_to_thread",description:"Reply to a specific message thread",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},thread_ts:{type:"string",description:"Thread timestamp"},text:{type:"string",description:"Reply text"}},required:["channel","thread_ts","text"]}},{name:"slack_add_reaction",description:"Add an emoji reaction to a message",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},timestamp:{type:"string",description:"Message timestamp"},reaction:{type:"string",description:"Emoji name without colons"}},required:["channel","timestamp","reaction"]}},{name:"slack_get_channel_history",description:"Get recent messages from a channel",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},limit:{type:"number",description:"Number of messages"}},required:["channel"]}},{name:"slack_get_thread_replies",description:"Get all replies in a message thread",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},thread_ts:{type:"string",description:"Thread timestamp"}},required:["channel","thread_ts"]}},{name:"slack_get_users",description:"List workspace users with basic profiles",input_schema:{type:"object",properties:{}}},{name:"slack_get_user_profile",description:"Get detailed profile for a specific user",input_schema:{type:"object",properties:{user_id:{type:"string",description:"Slack user ID"}},required:["user_id"]}}]};import{existsSync as gs}from"fs";import{fileURLToPath as hs}from"url";import{dirname as _s,resolve as ks}from"path";import{resolveIntegrationToken as ws}from"@zibby/core/backend-client.js";function bs(){if(process.env.MCP_LARK_PATH)return process.env.MCP_LARK_PATH;let r=_s(hs(import.meta.url)),t=ks(r,"..","bin","mcp-lark.mjs");return gs(t)?t:null}var Ss=6e3*1e3,Z=null;async function vs(){let{appId:r,appSecret:t,host:e}=await ws("lark");if(Z&&Z.appId===r&&Z.expiresAt>Date.now())return{token:Z.token,host:e};let n=await(await fetch(`${e}/open-apis/auth/v3/tenant_access_token/internal`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({app_id:r,app_secret:t})})).json();if(n.code!==0)throw new Error(`Lark tenant_access_token failed: ${n.msg||n.code}`);return Z={token:n.tenant_access_token,expiresAt:Date.now()+Ss,appId:r},{token:n.tenant_access_token,host:e}}async function se(r,t,e={}){let{token:s,host:n}=await vs(),i=`${n}${t}`,o={method:r,headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json; charset=utf-8"}};r!=="GET"&&(o.body=JSON.stringify(e));let c=await(await fetch(i,o)).json();if(c.code!==0)throw new Error(`Lark API ${t} error: ${c.msg||c.code}`);return c.data||{}}function Ue(r){return JSON.stringify({text:r})}function Ns(r){return!r||typeof r!="string"||r.startsWith("oc_")?"chat_id":r.startsWith("ou_")?"open_id":r.startsWith("on_")?"union_id":r.startsWith("cli_")?"app_id":r.includes("@")?"email":"chat_id"}var qe={id:"lark",serverName:"lark",allowedTools:["mcp__lark__*"],description:"Lark / Feishu messaging \u2014 send messages and reply in threads.",envKeys:[],promptFragment:`## Lark (connected)
112
112
  You can send messages and replies on Lark. Use:
113
113
  - lark_send_message: post a message to a chat, user, or DM
114
114
  - lark_reply: reply to an existing message (threaded)
115
115
  - lark_list_chats: list chats the bot is a member of
116
116
  - lark_get_chat_history: fetch recent messages in a chat
117
- When responding to an incoming event, prefer lark_reply with the source message_id so the response threads cleanly.`,resolve(){let r=ks();if(!r)return null;let t={};for(let e of["PROJECT_API_TOKEN","PROGRESS_API_URL","EXECUTION_ID","PROJECT_ID","STAGE"])process.env[e]&&(t[e]=process.env[e]);return{command:"node",args:[r],env:t}},tools:[{name:"lark_send_message",description:"Send a text message to a Lark chat, user, or DM. receive_id can be a chat_id (oc_*), open_id (ou_*), union_id (on_*), or email.",input_schema:{type:"object",properties:{receive_id:{type:"string",description:"Target id: chat_id (oc_*), open_id (ou_*), union_id (on_*), or email"},text:{type:"string",description:"Message text"}},required:["receive_id","text"]}},{name:"lark_reply",description:"Reply to an existing Lark message (creates a thread). Use the message_id from the inbound event.",input_schema:{type:"object",properties:{message_id:{type:"string",description:"Lark message id (om_*) to reply to"},text:{type:"string",description:"Reply text"}},required:["message_id","text"]}},{name:"lark_list_chats",description:"List chats (groups + DMs) the bot is a member of.",input_schema:{type:"object",properties:{page_size:{type:"number",description:"Max results (default 50)"}}}},{name:"lark_get_chat_history",description:"Fetch recent messages in a chat.",input_schema:{type:"object",properties:{chat_id:{type:"string",description:"Chat id (oc_*)"},page_size:{type:"number",description:"Max messages (default 20)"}},required:["chat_id"]}}],async handleToolCall(r,t){try{switch(r){case"lark_send_message":{if(!t.receive_id||!t.text)return JSON.stringify({error:"receive_id and text are required"});let e=Ss(t.receive_id),s=await se("POST",`/open-apis/im/v1/messages?receive_id_type=${e}`,{receive_id:t.receive_id,msg_type:"text",content:qe(t.text)});return JSON.stringify({ok:!0,message_id:s.message_id})}case"lark_reply":{if(!t.message_id||!t.text)return JSON.stringify({error:"message_id and text are required"});let e=await se("POST",`/open-apis/im/v1/messages/${encodeURIComponent(t.message_id)}/reply`,{msg_type:"text",content:qe(t.text)});return JSON.stringify({ok:!0,message_id:e.message_id})}case"lark_list_chats":{let e=t.page_size||50,n=((await se("GET",`/open-apis/im/v1/chats?page_size=${e}`)).items||[]).map(i=>({chat_id:i.chat_id,name:i.name,description:i.description,owner_id:i.owner_id,chat_mode:i.chat_mode}));return JSON.stringify({chats:n})}case"lark_get_chat_history":{if(!t.chat_id)return JSON.stringify({error:"chat_id is required"});let e=t.page_size||20,n=((await se("GET",`/open-apis/im/v1/messages?container_id_type=chat&container_id=${encodeURIComponent(t.chat_id)}&page_size=${e}&sort_type=ByCreateTimeDesc`)).items||[]).map(i=>({message_id:i.message_id,sender_id:i.sender?.id,sender_type:i.sender?.sender_type,msg_type:i.msg_type,content:i.body?.content,create_time:i.create_time}));return JSON.stringify({messages:n})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}}};import{createRequire as vs}from"module";import{execFileSync as Ns}from"child_process";import{join as Ke}from"path";import{existsSync as Os}from"fs";var Rs=vs(import.meta.url);function $s(){if(process.env.MCP_MEMORY_PATH)return process.env.MCP_MEMORY_PATH;try{return Rs.resolve("@zibby/ui-memory/mcp-server")}catch{return null}}var Be={id:"memory",serverName:"memory",allowedTools:["mcp__memory__*"],envKeys:[],description:"Zibby Memory MCP Server (test history, selectors, page model)",async middleware(){try{let{createMemoryMiddleware:r}=await import("@zibby/ui-memory");return r()}catch{return null}},promptFragment:`BEFORE executing browser actions:
117
+ When responding to an incoming event, prefer lark_reply with the source message_id so the response threads cleanly.`,resolve(){let r=bs();if(!r)return null;let t={};for(let e of["PROJECT_API_TOKEN","PROGRESS_API_URL","EXECUTION_ID","PROJECT_ID","STAGE"])process.env[e]&&(t[e]=process.env[e]);return{type:"stdio",command:"node",args:[r],env:t,alwaysLoad:!0}},tools:[{name:"lark_send_message",description:"Send a text message to a Lark chat, user, or DM. receive_id can be a chat_id (oc_*), open_id (ou_*), union_id (on_*), or email.",input_schema:{type:"object",properties:{receive_id:{type:"string",description:"Target id: chat_id (oc_*), open_id (ou_*), union_id (on_*), or email"},text:{type:"string",description:"Message text"}},required:["receive_id","text"]}},{name:"lark_reply",description:"Reply to an existing Lark message (creates a thread). Use the message_id from the inbound event.",input_schema:{type:"object",properties:{message_id:{type:"string",description:"Lark message id (om_*) to reply to"},text:{type:"string",description:"Reply text"}},required:["message_id","text"]}},{name:"lark_list_chats",description:"List chats (groups + DMs) the bot is a member of.",input_schema:{type:"object",properties:{page_size:{type:"number",description:"Max results (default 50)"}}}},{name:"lark_get_chat_history",description:"Fetch recent messages in a chat.",input_schema:{type:"object",properties:{chat_id:{type:"string",description:"Chat id (oc_*)"},page_size:{type:"number",description:"Max messages (default 20)"}},required:["chat_id"]}}],async handleToolCall(r,t){try{switch(r){case"lark_send_message":{if(!t.receive_id||!t.text)return JSON.stringify({error:"receive_id and text are required"});let e=Ns(t.receive_id),s=await se("POST",`/open-apis/im/v1/messages?receive_id_type=${e}`,{receive_id:t.receive_id,msg_type:"text",content:Ue(t.text)});return JSON.stringify({ok:!0,message_id:s.message_id})}case"lark_reply":{if(!t.message_id||!t.text)return JSON.stringify({error:"message_id and text are required"});let e=await se("POST",`/open-apis/im/v1/messages/${encodeURIComponent(t.message_id)}/reply`,{msg_type:"text",content:Ue(t.text)});return JSON.stringify({ok:!0,message_id:e.message_id})}case"lark_list_chats":{let e=t.page_size||50,n=((await se("GET",`/open-apis/im/v1/chats?page_size=${e}`)).items||[]).map(i=>({chat_id:i.chat_id,name:i.name,description:i.description,owner_id:i.owner_id,chat_mode:i.chat_mode}));return JSON.stringify({chats:n})}case"lark_get_chat_history":{if(!t.chat_id)return JSON.stringify({error:"chat_id is required"});let e=t.page_size||20,n=((await se("GET",`/open-apis/im/v1/messages?container_id_type=chat&container_id=${encodeURIComponent(t.chat_id)}&page_size=${e}&sort_type=ByCreateTimeDesc`)).items||[]).map(i=>({message_id:i.message_id,sender_id:i.sender?.id,sender_type:i.sender?.sender_type,msg_type:i.msg_type,content:i.body?.content,create_time:i.create_time}));return JSON.stringify({messages:n})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}}};import{createRequire as Os}from"module";import{execFileSync as Rs}from"child_process";import{join as Ke}from"path";import{existsSync as $s}from"fs";var Is=Os(import.meta.url);function js(){if(process.env.MCP_MEMORY_PATH)return process.env.MCP_MEMORY_PATH;try{return Is.resolve("@zibby/ui-memory/mcp-server")}catch{return null}}var Be={id:"memory",serverName:"memory",allowedTools:["mcp__memory__*"],envKeys:[],description:"Zibby Memory MCP Server (test history, selectors, page model)",async middleware(){try{let{createMemoryMiddleware:r}=await import("@zibby/ui-memory");return r()}catch{return null}},promptFragment:`BEFORE executing browser actions:
118
118
  - Review any test memory/history above. Prefer selectors proven to work.
119
119
  - If a previous run failed, avoid the same approach.
120
120
  - After setup/login completes, navigate directly to the target page instead of clicking through menus.
@@ -126,18 +126,18 @@ DURING execution \u2014 when a selector fails and you switch to a fallback:
126
126
  AFTER completing the test, you MUST call memory_save_insight at least once:
127
127
  - Save any useful finding: reliable selectors, timing quirks, navigation patterns, workarounds.
128
128
  - Category: selector_tip | timing | navigation | workaround | flaky | general
129
- - Be specific \u2014 future runs will read your insights.`,resolve(){let r=$s();if(!r)throw new Error(`\u274C Memory MCP server not found
129
+ - Be specific \u2014 future runs will read your insights.`,resolve(){let r=js();if(!r)throw new Error(`\u274C Memory MCP server not found
130
130
 
131
131
  Install @zibby/ui-memory:
132
- npm install @zibby/ui-memory`);let t=Ke(process.cwd(),".zibby","memory");if(!Os(Ke(t,".dolt")))throw new Error(`\u274C Memory database not initialized
132
+ npm install @zibby/ui-memory`);let t=Ke(process.cwd(),".zibby","memory");if(!$s(Ke(t,".dolt")))throw new Error(`\u274C Memory database not initialized
133
133
 
134
134
  Run:
135
- zibby init --mem`);try{let e=Ns("dolt",["sql","-q","SELECT COUNT(*) AS cnt FROM test_runs","-r","json"],{cwd:t,encoding:"utf-8",timeout:5e3}),s=JSON.parse(e.trim()).rows||[];if(!s[0]||s[0].cnt===0)return console.log("[memory] Database empty \u2014 memory tools activate after first completed run"),null}catch(e){throw new Error(`\u274C Dolt not found or memory database error
135
+ zibby init --mem`);try{let e=Rs("dolt",["sql","-q","SELECT COUNT(*) AS cnt FROM test_runs","-r","json"],{cwd:t,encoding:"utf-8",timeout:5e3}),s=JSON.parse(e.trim()).rows||[];if(!s[0]||s[0].cnt===0)return console.log("[memory] Database empty \u2014 memory tools activate after first completed run"),null}catch(e){throw new Error(`\u274C Dolt not found or memory database error
136
136
 
137
137
  Install Dolt:
138
138
  https://docs.dolthub.com/introduction/installation
139
139
 
140
- Error: ${e.message}`,{cause:e})}return{command:"node",args:[r,"--db-path",t],description:this.description}},tools:[{name:"memory_get_test_history",description:"Query recent test runs with pass/fail results and timing",input_schema:{type:"object",properties:{specPath:{type:"string",description:"Filter by spec path (substring match)"},limit:{type:"number",description:"Max results (default 10)"}}}},{name:"memory_get_selectors",description:"Query known selectors for a page with stability metrics",input_schema:{type:"object",properties:{pageUrl:{type:"string",description:"Filter by page URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_get_page_model",description:"Query page structure \u2014 elements, roles, selectors",input_schema:{type:"object",properties:{url:{type:"string",description:"Filter by page URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_get_navigation",description:"Query known page-to-page transitions",input_schema:{type:"object",properties:{fromUrl:{type:"string",description:"Filter by source URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_save_insight",description:"Save a useful observation for future runs (selector tips, timing, workarounds)",input_schema:{type:"object",properties:{category:{type:"string",enum:["selector_tip","timing","navigation","workaround","flaky","general"],description:"Type of insight"},content:{type:"string",description:"The insight text \u2014 be specific and actionable"},specPath:{type:"string",description:"Related spec path"},sessionId:{type:"string",description:"Current session ID"}},required:["category","content"]}}]};import{existsSync as Is,readFileSync as js}from"fs";import{homedir as Ts}from"os";import{join as As}from"path";import{spawn as Cs}from"child_process";var B={jira:{description:"Jira issue search, details, comments, transitions",integrationProvider:"jira",envKeys:[],setupInstructions:`To connect Jira:
140
+ Error: ${e.message}`,{cause:e})}return{command:"node",args:[r,"--db-path",t],description:this.description}},tools:[{name:"memory_get_test_history",description:"Query recent test runs with pass/fail results and timing",input_schema:{type:"object",properties:{specPath:{type:"string",description:"Filter by spec path (substring match)"},limit:{type:"number",description:"Max results (default 10)"}}}},{name:"memory_get_selectors",description:"Query known selectors for a page with stability metrics",input_schema:{type:"object",properties:{pageUrl:{type:"string",description:"Filter by page URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_get_page_model",description:"Query page structure \u2014 elements, roles, selectors",input_schema:{type:"object",properties:{url:{type:"string",description:"Filter by page URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_get_navigation",description:"Query known page-to-page transitions",input_schema:{type:"object",properties:{fromUrl:{type:"string",description:"Filter by source URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_save_insight",description:"Save a useful observation for future runs (selector tips, timing, workarounds)",input_schema:{type:"object",properties:{category:{type:"string",enum:["selector_tip","timing","navigation","workaround","flaky","general"],description:"Type of insight"},content:{type:"string",description:"The insight text \u2014 be specific and actionable"},specPath:{type:"string",description:"Related spec path"},sessionId:{type:"string",description:"Current session ID"}},required:["category","content"]}}]};import{existsSync as Ts,readFileSync as As}from"fs";import{homedir as Cs}from"os";import{join as Es}from"path";import{spawn as xs}from"child_process";var B={jira:{description:"Jira issue search, details, comments, transitions",integrationProvider:"jira",envKeys:[],setupInstructions:`To connect Jira:
141
141
  1. Go to Settings \u2192 Integrations (https://studio.zibby.dev/integrations)
142
142
  2. Click "Connect Jira" and authorize via Atlassian OAuth
143
143
  3. After OAuth completes, ask me to install Jira again`},github:{description:"GitHub issues, PRs, repository management",integrationProvider:"github",envKeys:[],setupInstructions:`To connect GitHub:
@@ -149,15 +149,15 @@ AFTER completing the test, you MUST call memory_save_insight at least once:
149
149
  3. After OAuth completes, ask me to install Slack again`},sentry:{description:"Sentry error tracking \u2014 projects, issues, events",integrationProvider:"sentry",envKeys:[],setupInstructions:`To connect Sentry:
150
150
  1. Go to Settings \u2192 Integrations (https://studio.zibby.dev/integrations)
151
151
  2. Click "Connect Sentry" and authorize
152
- 3. After OAuth completes, ask me to install Sentry again`},runner:{description:"Run zibby test workflows from chat (parallel supported)",envKeys:[],setupInstructions:"Ready to use. Runs zibby test workflows as background processes \u2014 each with its own browser and session."},browser:{description:"Playwright browser automation (navigate, click, fill, screenshot)",envKeys:[],setupInstructions:"Ready to use. Starts a Playwright browser for web automation."},memory:{description:"Test memory database (Dolt) \u2014 history, selectors, insights",envKeys:[],setupInstructions:"Ready to use. Requires Dolt (https://docs.dolthub.com/introduction/installation) and a memory DB via `zibby init --mem`."},"chat-memory":{description:"Persistent chat memory \u2014 remembers facts, decisions, and task history across sessions (Dolt-backed)",envKeys:[],setupInstructions:'Ready to use. Requires Dolt installed. Tables auto-create on first use. Install with: "add chat memory" or "install chat-memory".'},git:{description:"Clone and explore git repositories locally for codebase analysis",envKeys:[],setupInstructions:"Ready to use. Clone repos with git_checkout, explore with git_explore. Auto-authenticates with GitHub/GitLab tokens."}};function Es(){let r=["## Available Skills"];for(let[t,e]of Object.entries(B)){let s=e.integrationProvider?`integration: ${e.integrationProvider}`:"ready";r.push(`- ${t}: ${e.description} [${s}]`)}return r.push(""),r.push("Use the install_skill / uninstall_skill / list_available_skills tools to manage skills."),r.push(`Zibby third party Integration settings page: ${_e()}`),r.push(""),r.push("## Tool-First Policy (mandatory)"),r.push("CRITICAL RULES \u2014 follow these strictly:"),r.push("1. When user asks to do something and a matching skill is available but not installed, IMMEDIATELY call install_skill. Never ask for credentials or confirmation first."),r.push(`2. If install_skill succeeds, the skill's tools are now available. Use them RIGHT AWAY in the same turn \u2014 don't just say "it's connected", actually call the tools.`),r.push("3. If install_skill reports needsIntegration, tell the user to connect via the integration URL and try again after."),r.push("4. When the relevant skill is already installed, use its tools directly \u2014 don't ask for IDs or keys. Each skill's own instructions explain the workflow."),r.push("5. If a task needs multiple skills (e.g. data from one + execution from another), install all of them, then follow each skill's workflow instructions."),r.join(`
153
- `)}function xs(){if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let r=As(Ts(),".zibby","config.json");return Is(r)&&JSON.parse(js(r,"utf-8")).sessionToken||null}catch{return null}}function Ls(){return(process.env.ZIBBY_API_URL||process.env.ZIBBY_PROD_API_URL||"https://api-prod.zibby.app").replace(/\/$/,"")}function _e(){return`${(process.env.ZIBBY_FRONTEND_URL||process.env.ZIBBY_PROD_FRONTEND_URL||"https://studio.zibby.dev").replace(/\/$/,"")}/integrations`}function Js(r){try{let t=process.platform;return Cs(t==="darwin"?"open":t==="win32"?"cmd":"xdg-open",t==="win32"?["/c","start","",r]:[r],{detached:!0,stdio:"ignore"}).unref(),!0}catch{return!1}}async function Ds(){let r=xs();if(!r)return{checked:!1,statuses:null,reason:"no-session-token"};try{let t=await fetch(`${Ls()}/integrations/status`,{method:"GET",headers:{Authorization:`Bearer ${r}`}});return t.ok?{checked:!0,statuses:await t.json()||{},reason:null}:{checked:!1,statuses:null,reason:`status-${t.status}`}}catch{return{checked:!1,statuses:null,reason:"network-error"}}}function Fe(r,t){if(!t||!r)return{connected:null};let e=r[t];return!e||typeof e.connected!="boolean"?{connected:null,details:e||null}:{connected:e.connected,details:e}}var We={id:"skill-installer",description:"Live skill installation for chat sessions",envKeys:[],catalog:B,promptFragment:Es,tools:[{name:"install_skill",description:"Install a skill into the current chat session so its tools become available",input_schema:{type:"object",properties:{skillId:{type:"string",description:'Skill identifier to install (e.g. "jira", "github", "browser", "memory")'}},required:["skillId"]}},{name:"uninstall_skill",description:"Remove a skill from the current chat session",input_schema:{type:"object",properties:{skillId:{type:"string",description:"Skill identifier to remove"}},required:["skillId"]}},{name:"list_available_skills",description:"List all skills that can be installed, with their env-var readiness status",input_schema:{type:"object",properties:{}}}],async handleToolCall(r,t,e){let{activeSkills:s}=e,n=await Ds();if(r==="list_available_skills"){let i=Object.entries(B).map(([o,a])=>{let c=s.includes(o),l=Fe(n.statuses,a.integrationProvider);return{id:o,description:a.description,installed:c,integrationProvider:a.integrationProvider||void 0,integrationConnected:l.connected,setupInstructions:l.connected===!1?a.setupInstructions:void 0}});return JSON.stringify({skills:i})}if(r==="install_skill"){let{skillId:i}=t;if(!i)return JSON.stringify({ok:!1,error:"skillId is required"});if(s.includes(i)){let u=B[i],{getSkill:p}=await import("@zibby/agent-workflow"),m=(p(i)?.tools||[]).map(f=>f.name);return JSON.stringify({ok:!0,alreadyInstalled:!0,skillId:i,description:u?.description,availableTools:m,integrationUrl:u?.integrationProvider?_e():void 0,hint:`${i} is already active. Tools available: ${m.join(", ")}. Use them directly.`})}if(!B[i])return JSON.stringify({ok:!1,error:`Unknown skill "${i}". Available: ${Object.keys(B).join(", ")}`});let o=B[i];if(o.integrationProvider){let u=Fe(n.statuses,o.integrationProvider),p=_e();if(n.checked&&u.connected===!1){let y=Js(p);return JSON.stringify({ok:!1,error:`${o.integrationProvider} is not connected for this Zibby account yet`,needsIntegration:!0,integrationUrl:p,openedBrowser:y,setupInstructions:`Please connect ${o.integrationProvider} first at ${p}. After you finish OAuth, ask me to install ${i} again.`})}}s.push(i);let{getSkill:a}=await import("@zibby/agent-workflow"),l=(a(i)?.tools||[]).map(u=>u.name);return JSON.stringify({ok:!0,installed:i,description:o.description,availableTools:l,hint:`${i} is now active. You now have these tools: ${l.join(", ")}. Use them immediately to help the user \u2014 don't just confirm installation.`})}if(r==="uninstall_skill"){let{skillId:i}=t;if(!i)return JSON.stringify({ok:!1,error:"skillId is required"});if(i==="skill-installer")return JSON.stringify({ok:!1,error:"Cannot uninstall the skill installer"});let o=s.indexOf(i);return o===-1?JSON.stringify({ok:!1,error:`${i} is not installed`}):(s.splice(o,1),JSON.stringify({ok:!0,uninstalled:i}))}return JSON.stringify({error:`Unknown tool: ${r}`})},resolve(){return null}};import{readFileSync as Ms,readdirSync as Ps,statSync as Ge,writeFileSync as qs,mkdirSync as Us}from"fs";import{join as He,resolve as Ks,relative as Bs}from"path";import{execSync as Ye}from"child_process";var ze=256*1024,Fs=64*1024,Ze={id:"core-tools",description:"File read/write, directory listing, shell commands, open URLs, wait for async operations",envKeys:[],tools:[{name:"read_file",description:"Read the contents of a file. Returns the text content.",input_schema:{type:"object",properties:{path:{type:"string",description:"File path (relative to cwd or absolute)"}},required:["path"]}},{name:"write_file",description:"Write content to a file. Creates parent directories if needed.",input_schema:{type:"object",properties:{path:{type:"string",description:"File path (relative to cwd or absolute)"},content:{type:"string",description:"Content to write"}},required:["path","content"]}},{name:"list_directory",description:"List files and directories in a path. Returns names with type indicators (/ for dirs).",input_schema:{type:"object",properties:{path:{type:"string",description:"Directory path (relative to cwd or absolute). Defaults to cwd."}}}},{name:"run_command",description:"Run a shell command and return its output. Use for grep, git, npm, etc.",input_schema:{type:"object",properties:{command:{type:"string",description:"Shell command to execute"},cwd:{type:"string",description:"Working directory (optional, defaults to project root)"}},required:["command"]}},{name:"open_url",description:"Open a URL in the user's default browser. Use for OAuth flows, documentation, integration setup pages.",input_schema:{type:"object",properties:{url:{type:"string",description:"URL to open"}},required:["url"]}},{name:"wait",description:"Wait for N seconds. Use this for async operations (tests, builds, deploys) \u2014 wait, then check status again.",input_schema:{type:"object",properties:{seconds:{type:"number",description:"Seconds to wait (default: 5, max: 300)"},reason:{type:"string",description:"Why waiting (for logging/clarity)"}}}}],async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"read_file":return Ws(t,s);case"write_file":return zs(t,s);case"list_directory":return Gs(t,s);case"run_command":return Hs(t,s);case"open_url":return Ys(t);case"wait":return await Zs(t,e?.options?.signal);default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.message})}},resolve(){return null}};function re(r,t){return Ks(t,r)}function Ws(r,t){let e=re(r.path,t),s=Ge(e);return s.size>ze?JSON.stringify({error:`File too large (${(s.size/1024).toFixed(0)}KB). Max: ${ze/1024}KB`}):Ms(e,"utf-8")}function zs(r,t){let e=re(r.path,t),s=He(e,"..");return Us(s,{recursive:!0}),qs(e,r.content,"utf-8"),JSON.stringify({ok:!0,path:Bs(t,e)})}function Gs(r,t){let e=re(r.path||".",t);return Ps(e).map(n=>{try{return Ge(He(e,n)).isDirectory()?`${n}/`:n}catch{return n}}).join(`
154
- `)}function Hs(r,t){let e=r.cwd?re(r.cwd,t):t;return Ye(r.command,{cwd:e,encoding:"utf-8",timeout:3e4,maxBuffer:Fs,stdio:["pipe","pipe","pipe"]})||"(no output)"}function Ys(r){let{url:t}=r;if(!t||!t.startsWith("http://")&&!t.startsWith("https://"))return JSON.stringify({error:"Invalid URL \u2014 must start with http:// or https://"});let e=process.platform,s=e==="darwin"?"open":e==="win32"?"start":"xdg-open";try{return Ye(`${s} "${t}"`,{stdio:"ignore",timeout:5e3}),JSON.stringify({ok:!0,opened:t})}catch{return JSON.stringify({ok:!1,error:`Could not open browser. Please visit: ${t}`})}}async function Zs(r,t){let e=Math.min(Math.max(r.seconds||5,1),300),s=r.reason||"async operation",n=500,i=Date.now()+e*1e3;for(;Date.now()<i;){if(t?.aborted)return JSON.stringify({ok:!0,waited:Math.round((e*1e3-(i-Date.now()))/1e3),reason:s,interrupted:!0});await new Promise(o=>setTimeout(o,Math.min(n,i-Date.now())))}return JSON.stringify({ok:!0,waited:e,reason:s})}import{createRequire as Vs}from"module";import{resolveIntegrationToken as Qe}from"@zibby/core/backend-client.js";var Qs=Vs(import.meta.url);function Xs(){if(process.env.MCP_SENTRY_PATH)return process.env.MCP_SENTRY_PATH;try{return Qs.resolve("@zibby/skills/bin/mcp-sentry.mjs")}catch{return null}}async function Ve(r,t={}){let{token:e,organizationSlug:s}=await Qe("sentry"),n=`https://sentry.io/api/0/organizations/${s}${r}`,i=await fetch(n,{method:t.method||"GET",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!i.ok){let o=await i.text().catch(()=>"");throw new Error(`Sentry API ${i.status}: ${o.slice(0,300)}`)}return i.json()}var ne={id:"sentry",serverName:"sentry",allowedTools:["mcp__sentry__*"],description:"Sentry error tracking \u2014 projects, issues, events",envKeys:[],tools:[],promptFragment:`## Sentry (connected)
152
+ 3. After OAuth completes, ask me to install Sentry again`},runner:{description:"Run zibby test workflows from chat (parallel supported)",envKeys:[],setupInstructions:"Ready to use. Runs zibby test workflows as background processes \u2014 each with its own browser and session."},browser:{description:"Playwright browser automation (navigate, click, fill, screenshot)",envKeys:[],setupInstructions:"Ready to use. Starts a Playwright browser for web automation."},memory:{description:"Test memory database (Dolt) \u2014 history, selectors, insights",envKeys:[],setupInstructions:"Ready to use. Requires Dolt (https://docs.dolthub.com/introduction/installation) and a memory DB via `zibby init --mem`."},"chat-memory":{description:"Persistent chat memory \u2014 remembers facts, decisions, and task history across sessions (Dolt-backed)",envKeys:[],setupInstructions:'Ready to use. Requires Dolt installed. Tables auto-create on first use. Install with: "add chat memory" or "install chat-memory".'},git:{description:"Clone and explore git repositories locally for codebase analysis",envKeys:[],setupInstructions:"Ready to use. Clone repos with git_checkout, explore with git_explore. Auto-authenticates with GitHub/GitLab tokens."}};function Ls(){let r=["## Available Skills"];for(let[t,e]of Object.entries(B)){let s=e.integrationProvider?`integration: ${e.integrationProvider}`:"ready";r.push(`- ${t}: ${e.description} [${s}]`)}return r.push(""),r.push("Use the install_skill / uninstall_skill / list_available_skills tools to manage skills."),r.push(`Zibby third party Integration settings page: ${_e()}`),r.push(""),r.push("## Tool-First Policy (mandatory)"),r.push("CRITICAL RULES \u2014 follow these strictly:"),r.push("1. When user asks to do something and a matching skill is available but not installed, IMMEDIATELY call install_skill. Never ask for credentials or confirmation first."),r.push(`2. If install_skill succeeds, the skill's tools are now available. Use them RIGHT AWAY in the same turn \u2014 don't just say "it's connected", actually call the tools.`),r.push("3. If install_skill reports needsIntegration, tell the user to connect via the integration URL and try again after."),r.push("4. When the relevant skill is already installed, use its tools directly \u2014 don't ask for IDs or keys. Each skill's own instructions explain the workflow."),r.push("5. If a task needs multiple skills (e.g. data from one + execution from another), install all of them, then follow each skill's workflow instructions."),r.join(`
153
+ `)}function Js(){if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let r=Es(Cs(),".zibby","config.json");return Ts(r)&&JSON.parse(As(r,"utf-8")).sessionToken||null}catch{return null}}function Ds(){return(process.env.ZIBBY_API_URL||process.env.ZIBBY_PROD_API_URL||"https://api-prod.zibby.app").replace(/\/$/,"")}function _e(){return`${(process.env.ZIBBY_FRONTEND_URL||process.env.ZIBBY_PROD_FRONTEND_URL||"https://studio.zibby.dev").replace(/\/$/,"")}/integrations`}function Ms(r){try{let t=process.platform;return xs(t==="darwin"?"open":t==="win32"?"cmd":"xdg-open",t==="win32"?["/c","start","",r]:[r],{detached:!0,stdio:"ignore"}).unref(),!0}catch{return!1}}async function Ps(){let r=Js();if(!r)return{checked:!1,statuses:null,reason:"no-session-token"};try{let t=await fetch(`${Ds()}/integrations/status`,{method:"GET",headers:{Authorization:`Bearer ${r}`}});return t.ok?{checked:!0,statuses:await t.json()||{},reason:null}:{checked:!1,statuses:null,reason:`status-${t.status}`}}catch{return{checked:!1,statuses:null,reason:"network-error"}}}function Fe(r,t){if(!t||!r)return{connected:null};let e=r[t];return!e||typeof e.connected!="boolean"?{connected:null,details:e||null}:{connected:e.connected,details:e}}var We={id:"skill-installer",description:"Live skill installation for chat sessions",envKeys:[],catalog:B,promptFragment:Ls,tools:[{name:"install_skill",description:"Install a skill into the current chat session so its tools become available",input_schema:{type:"object",properties:{skillId:{type:"string",description:'Skill identifier to install (e.g. "jira", "github", "browser", "memory")'}},required:["skillId"]}},{name:"uninstall_skill",description:"Remove a skill from the current chat session",input_schema:{type:"object",properties:{skillId:{type:"string",description:"Skill identifier to remove"}},required:["skillId"]}},{name:"list_available_skills",description:"List all skills that can be installed, with their env-var readiness status",input_schema:{type:"object",properties:{}}}],async handleToolCall(r,t,e){let{activeSkills:s}=e,n=await Ps();if(r==="list_available_skills"){let i=Object.entries(B).map(([o,a])=>{let c=s.includes(o),l=Fe(n.statuses,a.integrationProvider);return{id:o,description:a.description,installed:c,integrationProvider:a.integrationProvider||void 0,integrationConnected:l.connected,setupInstructions:l.connected===!1?a.setupInstructions:void 0}});return JSON.stringify({skills:i})}if(r==="install_skill"){let{skillId:i}=t;if(!i)return JSON.stringify({ok:!1,error:"skillId is required"});if(s.includes(i)){let u=B[i],{getSkill:p}=await import("@zibby/agent-workflow"),m=(p(i)?.tools||[]).map(f=>f.name);return JSON.stringify({ok:!0,alreadyInstalled:!0,skillId:i,description:u?.description,availableTools:m,integrationUrl:u?.integrationProvider?_e():void 0,hint:`${i} is already active. Tools available: ${m.join(", ")}. Use them directly.`})}if(!B[i])return JSON.stringify({ok:!1,error:`Unknown skill "${i}". Available: ${Object.keys(B).join(", ")}`});let o=B[i];if(o.integrationProvider){let u=Fe(n.statuses,o.integrationProvider),p=_e();if(n.checked&&u.connected===!1){let y=Ms(p);return JSON.stringify({ok:!1,error:`${o.integrationProvider} is not connected for this Zibby account yet`,needsIntegration:!0,integrationUrl:p,openedBrowser:y,setupInstructions:`Please connect ${o.integrationProvider} first at ${p}. After you finish OAuth, ask me to install ${i} again.`})}}s.push(i);let{getSkill:a}=await import("@zibby/agent-workflow"),l=(a(i)?.tools||[]).map(u=>u.name);return JSON.stringify({ok:!0,installed:i,description:o.description,availableTools:l,hint:`${i} is now active. You now have these tools: ${l.join(", ")}. Use them immediately to help the user \u2014 don't just confirm installation.`})}if(r==="uninstall_skill"){let{skillId:i}=t;if(!i)return JSON.stringify({ok:!1,error:"skillId is required"});if(i==="skill-installer")return JSON.stringify({ok:!1,error:"Cannot uninstall the skill installer"});let o=s.indexOf(i);return o===-1?JSON.stringify({ok:!1,error:`${i} is not installed`}):(s.splice(o,1),JSON.stringify({ok:!0,uninstalled:i}))}return JSON.stringify({error:`Unknown tool: ${r}`})},resolve(){return null}};import{readFileSync as Us,readdirSync as qs,statSync as Ge,writeFileSync as Ks,mkdirSync as Bs}from"fs";import{join as He,resolve as Fs,relative as Ws}from"path";import{execSync as Ye}from"child_process";var ze=256*1024,zs=64*1024,Ze={id:"core-tools",description:"File read/write, directory listing, shell commands, open URLs, wait for async operations",envKeys:[],tools:[{name:"read_file",description:"Read the contents of a file. Returns the text content.",input_schema:{type:"object",properties:{path:{type:"string",description:"File path (relative to cwd or absolute)"}},required:["path"]}},{name:"write_file",description:"Write content to a file. Creates parent directories if needed.",input_schema:{type:"object",properties:{path:{type:"string",description:"File path (relative to cwd or absolute)"},content:{type:"string",description:"Content to write"}},required:["path","content"]}},{name:"list_directory",description:"List files and directories in a path. Returns names with type indicators (/ for dirs).",input_schema:{type:"object",properties:{path:{type:"string",description:"Directory path (relative to cwd or absolute). Defaults to cwd."}}}},{name:"run_command",description:"Run a shell command and return its output. Use for grep, git, npm, etc.",input_schema:{type:"object",properties:{command:{type:"string",description:"Shell command to execute"},cwd:{type:"string",description:"Working directory (optional, defaults to project root)"}},required:["command"]}},{name:"open_url",description:"Open a URL in the user's default browser. Use for OAuth flows, documentation, integration setup pages.",input_schema:{type:"object",properties:{url:{type:"string",description:"URL to open"}},required:["url"]}},{name:"wait",description:"Wait for N seconds. Use this for async operations (tests, builds, deploys) \u2014 wait, then check status again.",input_schema:{type:"object",properties:{seconds:{type:"number",description:"Seconds to wait (default: 5, max: 300)"},reason:{type:"string",description:"Why waiting (for logging/clarity)"}}}}],async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"read_file":return Gs(t,s);case"write_file":return Hs(t,s);case"list_directory":return Ys(t,s);case"run_command":return Zs(t,s);case"open_url":return Vs(t);case"wait":return await Qs(t,e?.options?.signal);default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.message})}},resolve(){return null}};function re(r,t){return Fs(t,r)}function Gs(r,t){let e=re(r.path,t),s=Ge(e);return s.size>ze?JSON.stringify({error:`File too large (${(s.size/1024).toFixed(0)}KB). Max: ${ze/1024}KB`}):Us(e,"utf-8")}function Hs(r,t){let e=re(r.path,t),s=He(e,"..");return Bs(s,{recursive:!0}),Ks(e,r.content,"utf-8"),JSON.stringify({ok:!0,path:Ws(t,e)})}function Ys(r,t){let e=re(r.path||".",t);return qs(e).map(n=>{try{return Ge(He(e,n)).isDirectory()?`${n}/`:n}catch{return n}}).join(`
154
+ `)}function Zs(r,t){let e=r.cwd?re(r.cwd,t):t;return Ye(r.command,{cwd:e,encoding:"utf-8",timeout:3e4,maxBuffer:zs,stdio:["pipe","pipe","pipe"]})||"(no output)"}function Vs(r){let{url:t}=r;if(!t||!t.startsWith("http://")&&!t.startsWith("https://"))return JSON.stringify({error:"Invalid URL \u2014 must start with http:// or https://"});let e=process.platform,s=e==="darwin"?"open":e==="win32"?"start":"xdg-open";try{return Ye(`${s} "${t}"`,{stdio:"ignore",timeout:5e3}),JSON.stringify({ok:!0,opened:t})}catch{return JSON.stringify({ok:!1,error:`Could not open browser. Please visit: ${t}`})}}async function Qs(r,t){let e=Math.min(Math.max(r.seconds||5,1),300),s=r.reason||"async operation",n=500,i=Date.now()+e*1e3;for(;Date.now()<i;){if(t?.aborted)return JSON.stringify({ok:!0,waited:Math.round((e*1e3-(i-Date.now()))/1e3),reason:s,interrupted:!0});await new Promise(o=>setTimeout(o,Math.min(n,i-Date.now())))}return JSON.stringify({ok:!0,waited:e,reason:s})}import{existsSync as Xs}from"fs";import{fileURLToPath as er}from"url";import{dirname as tr,resolve as sr}from"path";import{resolveIntegrationToken as Qe}from"@zibby/core/backend-client.js";function rr(){if(process.env.MCP_SENTRY_PATH)return process.env.MCP_SENTRY_PATH;let r=tr(er(import.meta.url)),t=sr(r,"..","bin","mcp-sentry.mjs");return Xs(t)?t:null}async function Ve(r,t={}){let{token:e,organizationSlug:s}=await Qe("sentry"),n=`https://sentry.io/api/0/organizations/${s}${r}`,i=await fetch(n,{method:t.method||"GET",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!i.ok){let o=await i.text().catch(()=>"");throw new Error(`Sentry API ${i.status}: ${o.slice(0,300)}`)}return i.json()}var ne={id:"sentry",serverName:"sentry",allowedTools:["mcp__sentry__*"],description:"Sentry error tracking \u2014 projects, issues, events",envKeys:[],tools:[],promptFragment:`## Sentry (connected)
155
155
  You have access to the user's Sentry. Use these tools:
156
156
  - sentry_list_projects: List projects in the organization
157
157
  - sentry_list_issues: List errors/issues (supports Sentry search query, project filter, sort)
158
- - sentry_get_issue: Get detailed info about a specific issue (requires issueId)`,resolve(){let r=Xs();if(!r)return null;let t={};for(let e of["PROJECT_API_TOKEN","PROGRESS_API_URL","EXECUTION_ID","PROJECT_ID","STAGE"])process.env[e]&&(t[e]=process.env[e]);return{command:"node",args:[r],env:t}},async handleToolCall(r,t={}){try{switch(r){case"sentry_list_projects":{let e=await Ve("/projects/?per_page=50");return JSON.stringify({projects:e.map(s=>({slug:s.slug,name:s.name,platform:s.platform}))})}case"sentry_list_issues":{let e=t.project||"",s=t.query||"is:unresolved",n=t.sort||"date",i=`/issues/?query=${encodeURIComponent(s)}&sort=${n}&per_page=${t.limit||25}`;e&&(i+=`&project=${encodeURIComponent(e)}`);let o=await Ve(i);return JSON.stringify({issues:o.map(a=>({id:a.id,title:a.title,culprit:a.culprit,count:a.count,firstSeen:a.firstSeen,lastSeen:a.lastSeen,level:a.level,status:a.status}))})}case"sentry_get_issue":{let{issueId:e}=t;if(!e)return JSON.stringify({error:"issueId is required"});let{token:s}=await Qe("sentry"),n=await fetch(`https://sentry.io/api/0/issues/${e}/`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Sentry API ${n.status}`);let i=await n.json();return JSON.stringify({id:i.id,title:i.title,culprit:i.culprit,metadata:i.metadata,count:i.count,userCount:i.userCount,firstSeen:i.firstSeen,lastSeen:i.lastSeen,level:i.level,status:i.status,project:{slug:i.project?.slug,name:i.project?.name}})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},toolsForAssistant:[{name:"sentry_list_projects",description:"List Sentry projects",input_schema:{type:"object",properties:{}}},{name:"sentry_list_issues",description:"List Sentry issues (errors)",input_schema:{type:"object",properties:{project:{type:"string",description:"Project slug (optional)"},query:{type:"string",description:"Sentry search query (default: is:unresolved)"},sort:{type:"string",description:"Sort order: date, new, priority, freq, user (default: date)"},limit:{type:"number",description:"Max issues to return (default 25)"}}}},{name:"sentry_get_issue",description:"Get details of a specific Sentry issue",input_schema:{type:"object",properties:{issueId:{type:"string",description:"Sentry issue ID"}},required:["issueId"]}}]};ne.tools=ne.toolsForAssistant;import{spawn as ct}from"child_process";import{writeFileSync as er,mkdirSync as Xe,existsSync as L,readdirSync as ce,readFileSync as ae,unlinkSync as tr,createWriteStream as sr,statSync as rr}from"fs";import{resolve as F,join as x}from"path";import{resolveMaxParallelRuns as lt}from"@zibby/core/utils/parallel-config.js";import{zibbyScratchSpecsDir as nr}from"@zibby/core/constants/zibby-scratch.js";var be="sessions",Se=".zibby/output",ie=process.env.ZIBBY_RUNNER_NODE_PROGRESS==="1",ir=process.env.ZIBBY_RUNNER_STATUS_STREAM==="1",ut=process.env.ZIBBY_RUNNER_SPAWN_LOGS==="1",A=new Map,U=[],or=0,ke=0,et=3e3;function pt(){return`run_${++or}_${Date.now().toString(36)}`}function tt(r){let t=Math.floor(r/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function dt(r){return r.replace(/\x1b\[[0-9;]*[a-zA-Z]/g,"")}function j(r,t,e){if(!ir)return;let s=`
158
+ - sentry_get_issue: Get detailed info about a specific issue (requires issueId)`,resolve(){let r=rr();if(!r)return null;let t={};for(let e of["PROJECT_API_TOKEN","PROGRESS_API_URL","EXECUTION_ID","PROJECT_ID","STAGE"])process.env[e]&&(t[e]=process.env[e]);return{type:"stdio",command:"node",args:[r],env:t,alwaysLoad:!0}},async handleToolCall(r,t={}){try{switch(r){case"sentry_list_projects":{let e=await Ve("/projects/?per_page=50");return JSON.stringify({projects:e.map(s=>({slug:s.slug,name:s.name,platform:s.platform}))})}case"sentry_list_issues":{let e=t.project||"",s=t.query||"is:unresolved",n=t.sort||"date",i=`/issues/?query=${encodeURIComponent(s)}&sort=${n}&per_page=${t.limit||25}`;e&&(i+=`&project=${encodeURIComponent(e)}`);let o=await Ve(i);return JSON.stringify({issues:o.map(a=>({id:a.id,title:a.title,culprit:a.culprit,count:a.count,firstSeen:a.firstSeen,lastSeen:a.lastSeen,level:a.level,status:a.status}))})}case"sentry_get_issue":{let{issueId:e}=t;if(!e)return JSON.stringify({error:"issueId is required"});let{token:s}=await Qe("sentry"),n=await fetch(`https://sentry.io/api/0/issues/${e}/`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Sentry API ${n.status}`);let i=await n.json();return JSON.stringify({id:i.id,title:i.title,culprit:i.culprit,metadata:i.metadata,count:i.count,userCount:i.userCount,firstSeen:i.firstSeen,lastSeen:i.lastSeen,level:i.level,status:i.status,project:{slug:i.project?.slug,name:i.project?.name}})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},toolsForAssistant:[{name:"sentry_list_projects",description:"List Sentry projects",input_schema:{type:"object",properties:{}}},{name:"sentry_list_issues",description:"List Sentry issues (errors)",input_schema:{type:"object",properties:{project:{type:"string",description:"Project slug (optional)"},query:{type:"string",description:"Sentry search query (default: is:unresolved)"},sort:{type:"string",description:"Sort order: date, new, priority, freq, user (default: date)"},limit:{type:"number",description:"Max issues to return (default 25)"}}}},{name:"sentry_get_issue",description:"Get details of a specific Sentry issue",input_schema:{type:"object",properties:{issueId:{type:"string",description:"Sentry issue ID"}},required:["issueId"]}}]};ne.tools=ne.toolsForAssistant;import{spawn as ct}from"child_process";import{writeFileSync as nr,mkdirSync as Xe,existsSync as L,readdirSync as ce,readFileSync as ae,unlinkSync as ir,createWriteStream as or,statSync as ar}from"fs";import{resolve as F,join as x}from"path";import{resolveMaxParallelRuns as lt}from"@zibby/core/utils/parallel-config.js";import{zibbyScratchSpecsDir as cr}from"@zibby/core/constants/zibby-scratch.js";var be="sessions",Se=".zibby/output",ie=process.env.ZIBBY_RUNNER_NODE_PROGRESS==="1",lr=process.env.ZIBBY_RUNNER_STATUS_STREAM==="1",ut=process.env.ZIBBY_RUNNER_SPAWN_LOGS==="1",A=new Map,q=[],ur=0,ke=0,et=3e3;function pt(){return`run_${++ur}_${Date.now().toString(36)}`}function tt(r){let t=Math.floor(r/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function dt(r){return r.replace(/\x1b\[[0-9;]*[a-zA-Z]/g,"")}function j(r,t,e){if(!lr)return;let s=`
159
159
  ${t} [${r}] ${e}
160
- `;try{process.stderr.write(s)}catch{}}function ve(){U.length=0;for(let[,r]of A)if(r.status==="queued"&&(r.status="cancelled"),r.status==="running"&&r._child)try{r._child.kill("SIGTERM")}catch{}}process.on("exit",ve);process.on("SIGINT",()=>{ve(),process.exit(0)});process.on("SIGTERM",()=>{ve(),process.exit(0)});var mt={id:"runner",description:"Run zibby test workflows from chat (parallel supported)",envKeys:[],promptFragment:`## Test Runner
160
+ `;try{process.stderr.write(s)}catch{}}function ve(){q.length=0;for(let[,r]of A)if(r.status==="queued"&&(r.status="cancelled"),r.status==="running"&&r._child)try{r._child.kill("SIGTERM")}catch{}}process.on("exit",ve);process.on("SIGINT",()=>{ve(),process.exit(0)});process.on("SIGTERM",()=>{ve(),process.exit(0)});var mt={id:"runner",description:"Run zibby test workflows from chat (parallel supported)",envKeys:[],promptFragment:`## Test Runner
161
161
  You can run zibby test workflows directly from chat:
162
162
 
163
163
  **CRITICAL: When user asks to test a ticket:**
@@ -294,8 +294,8 @@ Each run generates:
294
294
  - events.json: All browser events
295
295
  - raw_stream_output.txt: Agent log
296
296
 
297
- Use run_artifacts({ runId, type }) and run_diagnose({ runId }) to inspect and explain failures.`,resolve(){return null},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"run_generate":return await ar(t,s);case"run_test":return await mr(t,s,e);case"run_status":return fr(t);case"run_cancel":return yr(t);case"run_artifacts":return _r(t,s);case"run_diagnose":return kr(t,s);case"list_specs":return wr(t,s);default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.message})}},tools:[{name:"run_generate",description:"Generate specs from codebase. CRITICAL: DO NOT USE if ticket has test steps in comments. Only use when: (1) NO steps in ticket AND (2) local codebase exists (not external URLs). For tickets with steps, use run_test with inline format.",input_schema:{type:"object",properties:{ticket:{type:"string",description:"Jira ticket key (e.g. SCRUM-123). Auto-fetches ticket details."},description:{type:"string",description:"Ticket description text (use if no Jira key available)"},input:{type:"string",description:"Path to a file containing ticket/requirements text"},repo:{type:"string",description:"Path to the codebase (default: current directory)"},agent:{type:"string",description:"Optional agent override (cursor, gemini, claude, codex, assistant). Omit to use configured agent."},output:{type:"string",description:"Output directory for spec files (default: test-specs)"}}}},{name:"run_test",description:"Start a test (async, returns runId). spec = file path, or inline:+steps, or a Jira-shaped issue key (e.g. PROJ-123): when Jira is connected, the runner loads that issue's description+comments into an inline spec. After starting, tell the user and let them ask for progress via run_status.",input_schema:{type:"object",properties:{spec:{type:"string",description:"Workspace file path; or inline:+steps; or Jira issue key (KEY-123) to auto-fetch from Jira when the jira skill is active."},ticketKey:{type:"string",description:"Optional label (e.g. SCRUM-123). If spec is an issue key, this defaults to that key."},agent:{type:"string",description:"Optional agent override (cursor, gemini, claude, codex, assistant). Omit to use configured agent."},headless:{type:"boolean",description:"Run browser headless (default false)"},workflow:{type:"string",description:"Workflow override (e.g. quick-smoke)"}},required:["spec"]}},{name:"run_status",description:'Instant progress check \u2014 returns immediately. Use this whenever user asks about test progress. ALWAYS use runId="all".',input_schema:{type:"object",properties:{runId:{type:"string",description:'Use "all" to see all runs in this session (recommended). Or a specific run ID if known.'}},required:["runId"]}},{name:"run_cancel",description:'Cancel/kill a running test. ONLY use when the USER explicitly asks to cancel or stop a run. NEVER auto-cancel \u2014 tests take 1-5 minutes and "running" is normal. Use runId="all" to cancel all active runs.',input_schema:{type:"object",properties:{runId:{type:"string",description:'Run ID to cancel, or "all" to cancel all active runs'}},required:["runId"]}},{name:"run_artifacts",description:"Read artifacts from a test run session. Can list files, read results/events/logs, or search across all sessions.",input_schema:{type:"object",properties:{runId:{type:"string",description:"Run ID from run_test. Omit to search across all sessions."},type:{type:"string",enum:["list","result","events","log","search"],description:'What to retrieve: "list" = all files in session, "result" = result.json, "events" = events.json, "log" = raw output tail, "search" = search text across sessions'},node:{type:"string",description:'Node name to read from (e.g. "execute_live", "generate_script"). Default: "execute_live"'},query:{type:"string",description:'Search text (only for type="search"). Searches across all session logs/events.'},tail:{type:"number",description:"Number of characters from end of log to return (default: 3000)"}},required:["type"]}},{name:"run_diagnose",description:"Diagnose one or all runs, especially failed ones. Uses run logs + known error patterns and returns likely root cause with suggested next action.",input_schema:{type:"object",properties:{runId:{type:"string",description:'Run ID from run_test, or "all" (default) to diagnose all known runs'},tail:{type:"number",description:"Characters of run log tail to inspect (default: 2000)"}}}},{name:"list_specs",description:"List available test spec files in the project",input_schema:{type:"object",properties:{directory:{type:"string",description:'Directory to scan (default: "test-specs")'}}}}]};function we(){let r=0;for(let[,t]of A)t.status==="running"&&r++;return r}function st(){for(;U.length>0;){let r=lt(U[0]?.context?.options?.config);if(we()>=r)break;let{args:t,cwd:e,context:s}=U.shift();ft(t,e,s)}}async function ar(r,t){let{ticket:e,description:s,input:n,repo:i,agent:o,output:a}=r,c=["generate"];e&&c.push("--ticket",e),s&&c.push("--description",s),n&&c.push("--input",n),i&&c.push("--repo",i),a&&c.push("--output",a);let l=["assistant","cursor","claude","codex","gemini"],u=o||process.env.AGENT_TYPE,p=u&&l.includes(u)?u:null;p&&c.push("--agent",p);let y=e||"generate";return j(y,"\u{1F9EA}","Starting test spec generation (real agent with codebase access)..."),new Promise(m=>{ut&&console.error(`[zibby:spawn] skill=run_generate parentPid=${process.pid} \u2192 child zibby ${c.map(g=>/\s/.test(g)?JSON.stringify(g):g).join(" ")} cwd=${t}`);let f=ct("zibby",c,{cwd:t,env:{...process.env},stdio:["ignore","pipe","pipe"],detached:!1}),k="",h="";f.stdout.on("data",g=>{let _=g.toString();k+=_;for(let d of _.split(`
298
- `)){let b=dt(d).trim();b.startsWith("\u2705")?j(y,"\u2705",b.slice(2).trim()):b.startsWith("\u2713")&&j(y,"\u2714",b.slice(2).trim())}}),f.stderr.on("data",g=>{h+=g.toString()}),f.on("close",g=>{if(g!==0){j(y,"\u274C",`Generation failed (exit ${g})`),m(JSON.stringify({error:`zibby generate failed with exit code ${g}`,stderr:h.slice(-1e3)}));return}let _=F(t,a||"test-specs"),d=[];try{let b=e?e.toLowerCase().replace(/[^a-z0-9]+/g,"-"):"";d=ce(_).filter(I=>I.endsWith(".txt")&&(!b||I.startsWith(b))).map(I=>x(_,I))}catch{}j(y,"\u2705",`Generated ${d.length} test spec files`),m(JSON.stringify({success:!0,ticketKey:e||null,specFiles:d.map(b=>b.replace(`${t}/`,"")),total:d.length,message:`Generated ${d.length} specs. Now call run_test for each file.`}))}),f.on("error",g=>{j(y,"\u274C",`Spawn error: ${g.message}`),m(JSON.stringify({error:g.message}))})})}var rt=1e5,nt=/^[A-Z][A-Z0-9]+-\d+$/,cr=new Set(["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","rule","table","tableRow","tableCell","tableHeader","mediaSingle","panel"]);function lr(r,t){if(!t||!t.length)return r;let e=r;for(let s of t)s.type==="strong"?e=`**${e}**`:s.type==="em"?e=`_${e}_`:s.type==="code"?e=`\`${e}\``:s.type==="strike"?e=`~~${e}~~`:s.type==="link"&&s.attrs?.href&&(e=`[${e}](${s.attrs.href})`);return e}function oe(r,t=0){if(!Array.isArray(r))return"";let e=[];for(let s of r){if(s.type==="text"){e.push(lr(s.text||"",s.marks));continue}if(s.type==="hardBreak"){e.push(`
297
+ Use run_artifacts({ runId, type }) and run_diagnose({ runId }) to inspect and explain failures.`,resolve(){return null},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"run_generate":return await pr(t,s);case"run_test":return await hr(t,s,e);case"run_status":return _r(t);case"run_cancel":return kr(t);case"run_artifacts":return Sr(t,s);case"run_diagnose":return vr(t,s);case"list_specs":return Nr(t,s);default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.message})}},tools:[{name:"run_generate",description:"Generate specs from codebase. CRITICAL: DO NOT USE if ticket has test steps in comments. Only use when: (1) NO steps in ticket AND (2) local codebase exists (not external URLs). For tickets with steps, use run_test with inline format.",input_schema:{type:"object",properties:{ticket:{type:"string",description:"Jira ticket key (e.g. SCRUM-123). Auto-fetches ticket details."},description:{type:"string",description:"Ticket description text (use if no Jira key available)"},input:{type:"string",description:"Path to a file containing ticket/requirements text"},repo:{type:"string",description:"Path to the codebase (default: current directory)"},agent:{type:"string",description:"Optional agent override (cursor, gemini, claude, codex, assistant). Omit to use configured agent."},output:{type:"string",description:"Output directory for spec files (default: test-specs)"}}}},{name:"run_test",description:"Start a test (async, returns runId). spec = file path, or inline:+steps, or a Jira-shaped issue key (e.g. PROJ-123): when Jira is connected, the runner loads that issue's description+comments into an inline spec. After starting, tell the user and let them ask for progress via run_status.",input_schema:{type:"object",properties:{spec:{type:"string",description:"Workspace file path; or inline:+steps; or Jira issue key (KEY-123) to auto-fetch from Jira when the jira skill is active."},ticketKey:{type:"string",description:"Optional label (e.g. SCRUM-123). If spec is an issue key, this defaults to that key."},agent:{type:"string",description:"Optional agent override (cursor, gemini, claude, codex, assistant). Omit to use configured agent."},headless:{type:"boolean",description:"Run browser headless (default false)"},workflow:{type:"string",description:"Workflow override (e.g. quick-smoke)"}},required:["spec"]}},{name:"run_status",description:'Instant progress check \u2014 returns immediately. Use this whenever user asks about test progress. ALWAYS use runId="all".',input_schema:{type:"object",properties:{runId:{type:"string",description:'Use "all" to see all runs in this session (recommended). Or a specific run ID if known.'}},required:["runId"]}},{name:"run_cancel",description:'Cancel/kill a running test. ONLY use when the USER explicitly asks to cancel or stop a run. NEVER auto-cancel \u2014 tests take 1-5 minutes and "running" is normal. Use runId="all" to cancel all active runs.',input_schema:{type:"object",properties:{runId:{type:"string",description:'Run ID to cancel, or "all" to cancel all active runs'}},required:["runId"]}},{name:"run_artifacts",description:"Read artifacts from a test run session. Can list files, read results/events/logs, or search across all sessions.",input_schema:{type:"object",properties:{runId:{type:"string",description:"Run ID from run_test. Omit to search across all sessions."},type:{type:"string",enum:["list","result","events","log","search"],description:'What to retrieve: "list" = all files in session, "result" = result.json, "events" = events.json, "log" = raw output tail, "search" = search text across sessions'},node:{type:"string",description:'Node name to read from (e.g. "execute_live", "generate_script"). Default: "execute_live"'},query:{type:"string",description:'Search text (only for type="search"). Searches across all session logs/events.'},tail:{type:"number",description:"Number of characters from end of log to return (default: 3000)"}},required:["type"]}},{name:"run_diagnose",description:"Diagnose one or all runs, especially failed ones. Uses run logs + known error patterns and returns likely root cause with suggested next action.",input_schema:{type:"object",properties:{runId:{type:"string",description:'Run ID from run_test, or "all" (default) to diagnose all known runs'},tail:{type:"number",description:"Characters of run log tail to inspect (default: 2000)"}}}},{name:"list_specs",description:"List available test spec files in the project",input_schema:{type:"object",properties:{directory:{type:"string",description:'Directory to scan (default: "test-specs")'}}}}]};function we(){let r=0;for(let[,t]of A)t.status==="running"&&r++;return r}function st(){for(;q.length>0;){let r=lt(q[0]?.context?.options?.config);if(we()>=r)break;let{args:t,cwd:e,context:s}=q.shift();ft(t,e,s)}}async function pr(r,t){let{ticket:e,description:s,input:n,repo:i,agent:o,output:a}=r,c=["generate"];e&&c.push("--ticket",e),s&&c.push("--description",s),n&&c.push("--input",n),i&&c.push("--repo",i),a&&c.push("--output",a);let l=["assistant","cursor","claude","codex","gemini"],u=o||process.env.AGENT_TYPE,p=u&&l.includes(u)?u:null;p&&c.push("--agent",p);let y=e||"generate";return j(y,"\u{1F9EA}","Starting test spec generation (real agent with codebase access)..."),new Promise(m=>{ut&&console.error(`[zibby:spawn] skill=run_generate parentPid=${process.pid} \u2192 child zibby ${c.map(g=>/\s/.test(g)?JSON.stringify(g):g).join(" ")} cwd=${t}`);let f=ct("zibby",c,{cwd:t,env:{...process.env},stdio:["ignore","pipe","pipe"],detached:!1}),k="",h="";f.stdout.on("data",g=>{let _=g.toString();k+=_;for(let d of _.split(`
298
+ `)){let b=dt(d).trim();b.startsWith("\u2705")?j(y,"\u2705",b.slice(2).trim()):b.startsWith("\u2713")&&j(y,"\u2714",b.slice(2).trim())}}),f.stderr.on("data",g=>{h+=g.toString()}),f.on("close",g=>{if(g!==0){j(y,"\u274C",`Generation failed (exit ${g})`),m(JSON.stringify({error:`zibby generate failed with exit code ${g}`,stderr:h.slice(-1e3)}));return}let _=F(t,a||"test-specs"),d=[];try{let b=e?e.toLowerCase().replace(/[^a-z0-9]+/g,"-"):"";d=ce(_).filter(I=>I.endsWith(".txt")&&(!b||I.startsWith(b))).map(I=>x(_,I))}catch{}j(y,"\u2705",`Generated ${d.length} test spec files`),m(JSON.stringify({success:!0,ticketKey:e||null,specFiles:d.map(b=>b.replace(`${t}/`,"")),total:d.length,message:`Generated ${d.length} specs. Now call run_test for each file.`}))}),f.on("error",g=>{j(y,"\u274C",`Spawn error: ${g.message}`),m(JSON.stringify({error:g.message}))})})}var rt=1e5,nt=/^[A-Z][A-Z0-9]+-\d+$/,dr=new Set(["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","rule","table","tableRow","tableCell","tableHeader","mediaSingle","panel"]);function mr(r,t){if(!t||!t.length)return r;let e=r;for(let s of t)s.type==="strong"?e=`**${e}**`:s.type==="em"?e=`_${e}_`:s.type==="code"?e=`\`${e}\``:s.type==="strike"?e=`~~${e}~~`:s.type==="link"&&s.attrs?.href&&(e=`[${e}](${s.attrs.href})`);return e}function oe(r,t=0){if(!Array.isArray(r))return"";let e=[];for(let s of r){if(s.type==="text"){e.push(mr(s.text||"",s.marks));continue}if(s.type==="hardBreak"){e.push(`
299
299
  `);continue}if(s.type==="rule"){e.push(`
300
300
  ---
301
301
  `);continue}let n=s.content?oe(s.content,t+1):"";if(s.type==="listItem")e.push(n);else if(s.type==="bulletList"){let i=(s.content||[]).map(o=>`- ${oe(o.content||[],t+1).trim()}`);e.push(`
@@ -308,21 +308,21 @@ ${i.join(`
308
308
 
309
309
  ${"#".repeat(i)} ${n.trim()}
310
310
 
311
- `)}else cr.has(s.type)?e.push(`
311
+ `)}else dr.has(s.type)?e.push(`
312
312
 
313
313
  ${n}
314
314
  `):e.push(n)}return e.join("").replace(/\n{3,}/g,`
315
315
 
316
- `)}function ur(r){return r==null||r===""?"":typeof r=="string"?r.trim():typeof r=="object"&&Array.isArray(r.content)?oe(r.content).trim():""}async function pr(r){let{getSkill:t}=await import("@zibby/agent-workflow"),e=t("jira");if(!e||typeof e.handleToolCall!="function")return null;try{let s=await e.handleToolCall("jira_get_issue",{issueKey:r}),n=JSON.parse(s);if(n?.error)return null;let i=await e.handleToolCall("jira_get_comments",{issueKey:r,maxResults:50}),o=JSON.parse(i);if(o?.error)return null;let a=ur(n.description),c=[];a&&c.push(a);let l=Array.isArray(o.comments)?o.comments:[];if(l.length>0){let p=l.map(y=>String(y.body||"").trim()).filter(Boolean).join(`
316
+ `)}function fr(r){return r==null||r===""?"":typeof r=="string"?r.trim():typeof r=="object"&&Array.isArray(r.content)?oe(r.content).trim():""}async function yr(r){let{getSkill:t}=await import("@zibby/agent-workflow"),e=t("jira");if(!e||typeof e.handleToolCall!="function")return null;try{let s=await e.handleToolCall("jira_get_issue",{issueKey:r}),n=JSON.parse(s);if(n?.error)return null;let i=await e.handleToolCall("jira_get_comments",{issueKey:r,maxResults:50}),o=JSON.parse(i);if(o?.error)return null;let a=fr(n.description),c=[];a&&c.push(a);let l=Array.isArray(o.comments)?o.comments:[];if(l.length>0){let p=l.map(y=>String(y.body||"").trim()).filter(Boolean).join(`
317
317
 
318
318
  `);p&&c.push(p)}let u=c.join(`
319
319
 
320
320
  `).trim();return u?(u.length>rt&&(u=`${u.slice(0,rt)}
321
321
 
322
- ...[truncated]`),{inlineSpec:`inline:${u}`,issueKey:r}):null}catch{return null}}function dr(r,t){try{let e=JSON.parse(r);return JSON.stringify({...e,...t})}catch{return r}}async function mr(r,t,e){let s={...r},n=String(s.spec??"").trim();if(!n)return JSON.stringify({error:"spec is required"});let i=null;if(nt.test(n)&&!n.startsWith("inline:")){let u=await pr(n);u&&(n=u.inlineSpec,s.spec=n,String(s.ticketKey||"").trim()||(s.ticketKey=u.issueKey),i=u.issueKey)}let o=String(s.ticketKey||"").trim();if(o){for(let[u,p]of A.entries())if(p?.ticketKey===o&&!(p?.status!=="running"&&p?.status!=="queued"))return JSON.stringify({runId:u,ticketKey:o,status:p.status,reused:!0,message:`A run for ${o} is already ${p.status}. Reusing existing run instead of starting a duplicate.`})}if(!n.startsWith("inline:")){let u=F(t,n);if(!L(u))return nt.test(n)?JSON.stringify({error:`Invalid run_test spec: "${n}" is an issue id, not a spec.`,reason:"Jira auto-load was attempted but did not return usable text, or Jira is not configured.",doNext:["Confirm the jira skill is active and authenticated.",'Or call tracker tools yourself, then run_test with spec: "inline:" + steps.'],validExample:{spec:"inline:1. Open https://example.com \u2026 2. Verify \u2026",ticketKey:n},invalidExample:{spec:n,ticketKey:n}}):JSON.stringify({error:`Test spec not found: ${n}`,hint:'If this should be issue steps, load the issue with your tracker tools first, then run_test with spec: "inline:" + steps. Otherwise use a real file path.'})}let a=lt(e?.options?.config);if(we()>=a){let u=pt(),p=s.ticketKey||u,y={runId:u,spec:s.ticketKey?`${s.ticketKey}: ${s.spec}`:s.spec,ticketKey:s.ticketKey||null,status:"queued",startTime:Date.now(),exitCode:null,output:"",error:""};A.set(u,y),U.push({args:{...s,_queuedRunId:u},cwd:t,context:e}),j(p,"\u23F3",`Queued (${we()}/${a} running, ${U.length} queued)`);let m={runId:u,spec:y.spec,ticketKey:y.ticketKey,status:"queued",message:`Queued \u2014 will start when a slot opens (max ${a} concurrent).`};return i&&(m.resolvedFromJiraIssue=i,m.message+=` (spec built from Jira ${i})`),JSON.stringify(m)}let c=Date.now()-ke;c<et&&ke>0&&await new Promise(u=>setTimeout(u,et-c)),ke=Date.now();let l=ft(s,t,e);return i?dr(l,{resolvedFromJiraIssue:i,message:`Spec was loaded from Jira issue ${i} (description + comments).`}):l}function ft(r,t,e){let{spec:s,ticketKey:n,agent:i,headless:o,workflow:a,_queuedRunId:c}=r,l=c||pt(),u=s,p=!1;if(s.startsWith("inline:")){p=!0;let O=nr(t);Xe(O,{recursive:!0}),u=x(O,`${l}.txt`),er(u,s.slice(7).trim(),"utf-8")}let y=F(t,".zibby","output","runs");Xe(y,{recursive:!0});let m=x(y,`${l}.log`),f=sr(m,{flags:"a"}),h=i&&["assistant","cursor","claude","codex","gemini"].includes(i)?i:null,g=["test",u];h&&g.push("--agent",h),o&&g.push("--headless"),a&&g.push("--workflow",a),ut&&console.error(`[zibby:spawn] skill=run_test parentPid=${process.pid} \u2192 child zibby ${g.map(O=>/\s/.test(O)?JSON.stringify(O):O).join(" ")} cwd=${t}`);let _=ct("zibby",g,{cwd:t,env:{...process.env,ZIBBY_WORKFLOW_GRAPH_LOG_MARKERS:"1"},stdio:["ignore","pipe","pipe"],detached:!1}),d={runId:l,spec:n?`${n}: ${s}`:s,ticketKey:n||null,specPath:u,logPath:m,isInline:p,pid:_.pid,status:"running",output:"",error:"",startTime:Date.now(),exitCode:null,currentNode:null,completedNodes:[]},b=n||l,I="";function Ee(O){let v=dt(O).trim();if(!v)return;if(v.startsWith("__WORKFLOW_GRAPH_LOG__")){try{let R=JSON.parse(v.slice(22));R.phase==="node_begin"?d.currentNode=R.node:R.phase==="node_end"&&(R.node&&!d.completedNodes.includes(R.node)&&d.completedNodes.push(R.node),d.currentNode===R.node&&(d.currentNode=null))}catch{}return}let Y=v.match(/Session\s+(\S+)/);if(Y&&!d.sessionId&&(d.sessionId=Y[1],d.sessionPath=F(t,Se,be,d.sessionId)),v.startsWith("\u250C ")||v.startsWith("\u250C ")){let R=v.slice(2).trim();d.currentNode=R,ie&&j(b,"\u25B6",`${R}`)}else if(v.startsWith("\u2514 ")||v.startsWith("\u2514 ")){let R=v.slice(2).trim();R.startsWith("done")?(d.currentNode&&!d.completedNodes.includes(d.currentNode)&&d.completedNodes.push(d.currentNode),ie&&j(b,"\u2714",`${d.currentNode||"node"} done ${R.replace("done","").trim()}`),d.currentNode=null):R.startsWith("failed")&&(ie&&j(b,"\u2718",`${d.currentNode||"node"} failed ${R.replace("failed","").trim()}`),d.currentNode=null)}else v.includes("Workflow completed")&&(d.currentNode=null,ie&&j(b,"\u2714",`Workflow completed (${tt(Date.now()-d.startTime)})`))}function Yt(O){let v=O.toString();d.output+=v,f.write(v),d.output.length>5e4&&(d.output=d.output.slice(-3e4)),I+=v;let Y=I.split(`
323
- `);I=Y.pop();for(let R of Y)Ee(R)}return _.stdout.on("data",Yt),_.stderr.on("data",O=>{let v=O.toString();d.error+=v,f.write(v),d.error.length>2e4&&(d.error=d.error.slice(-1e4))}),_.on("close",O=>{d.status=O===0?"passed":"failed",d.exitCode=O,d.endTime=Date.now(),I&&Ee(I),f.end();let v=tt(Date.now()-d.startTime);if(O===0?j(b,"\u2705",`Passed (${v})`):j(b,"\u274C",`Failed (${v})`),d.isInline)try{tr(d.specPath)}catch{}st()}),_.on("error",O=>{d.status="error",d.error+=`
324
- Spawn error: ${O.message}`,j(b,"\u274C",`Spawn error: ${O.message}`),f.end(),st()}),d._child=_,A.set(l,d),JSON.stringify({runId:l,spec:d.spec,ticketKey:d.ticketKey,status:"running",pid:_.pid,logFile:m})}function it(r){let t=Math.round(((r.endTime||Date.now())-r.startTime)/1e3),e=r.completedNodes||[],s=r.currentNode||null;if(r.status!=="running")return{elapsed:t,stage:r.status,completedNodes:e,currentNode:null};let n;return s?(n=`Actively executing node "${s}"`,e.length&&(n+=` (completed: ${e.join(", ")})`)):e.length?n=`Between nodes (completed: ${e.join(", ")})`:n="Starting up (initializing workflow)",n+=`. Elapsed: ${t}s. This is normal progress \u2014 do not cancel.`,{elapsed:t,stage:"running",currentNode:s,completedNodes:e,progress:n}}function fr(r){let{runId:t}=r;if(!t)return JSON.stringify({error:"runId is required"});if(t==="all"){let i=[...A.entries()].map(([u,p])=>{let y=it(p),m={runId:u,spec:p.spec,ticketKey:p.ticketKey,status:p.status,elapsed:y.elapsed,exitCode:p.exitCode,sessionId:p.sessionId||null};return p.status==="running"?(m.currentNode=y.currentNode,m.completedNodes=y.completedNodes,m.progress=y.progress):m.outputTail=p.output.slice(-500),m}),o=i.filter(u=>u.status==="running").length,a=i.filter(u=>u.status==="passed").length,c=i.filter(u=>u.status==="failed").length,l={total:i.length,running:o,passed:a,failed:c,runs:i};return o>0&&(l._hint="All running tests are progressing normally through their workflow nodes. Do NOT cancel, diagnose, or interpret as stuck. Just tell the user they are still running."),JSON.stringify(l)}let e=A.get(t);if(!e)return JSON.stringify({error:`Run not found: ${t}`});let s=it(e),n={runId:t,spec:e.spec,ticketKey:e.ticketKey,status:e.status,elapsed:s.elapsed,exitCode:e.exitCode,sessionId:e.sessionId||null};return e.status==="running"?(n.currentNode=s.currentNode,n.completedNodes=s.completedNodes,n.progress=s.progress):(n.outputTail=e.output.slice(-1e3),n.errorTail=e.error.slice(-500)),e.status==="running"&&(n._hint="This run is actively progressing. Do NOT cancel, diagnose, or assume stuck. Just tell the user it is still running."),JSON.stringify(n)}function ot(r,t){if(t.status==="queued"){let e=U.findIndex(s=>s.args._queuedRunId===r);return e>=0&&U.splice(e,1),t.status="cancelled",t.endTime=Date.now(),{ok:!0,runId:r,status:"cancelled"}}if(t.status!=="running")return{ok:!1,runId:r,error:`Run is not active (status: ${t.status})`};try{return t._child.kill("SIGTERM"),t.status="cancelled",t.endTime=Date.now(),{ok:!0,runId:r,status:"cancelled"}}catch(e){return{ok:!1,runId:r,error:`Failed to cancel: ${e.message}`}}}function yr(r){let{runId:t}=r;if(!t)return JSON.stringify({error:"runId is required"});if(t==="all"){let s=[];for(let[n,i]of A.entries())(i.status==="running"||i.status==="queued")&&s.push(ot(n,i));return s.length===0?JSON.stringify({ok:!0,message:"No active runs to cancel"}):JSON.stringify({ok:!0,cancelled:s.length,results:s})}let e=A.get(t);return JSON.stringify(e?ot(t,e):{error:`Run not found: ${t}`})}function gr(r,t){let e=A.get(r);if(e?.sessionPath&&L(e.sessionPath))return e.sessionPath;if(e?.sessionId){let s=F(t,Se,be,e.sessionId);if(L(s))return s}return null}function yt(r,t=""){let e=[];if(!L(r))return e;for(let s of ce(r,{withFileTypes:!0})){let n=t?`${t}/${s.name}`:s.name;if(s.isDirectory())e.push(...yt(x(r,s.name),n));else{let i=rr(x(r,s.name));e.push({path:n,size:i.size})}}return e}function at(r){if(!L(r))return null;try{return JSON.parse(ae(r,"utf-8"))}catch{return null}}function gt(r,t=2e3){if(!r||!L(r))return"";try{return ae(r,"utf-8").slice(-Math.max(200,Number(t)||2e3))}catch{return""}}function hr({run:r,logTail:t,errorTail:e}){let n=`${t||""}
325
- ${e||""}`.toLowerCase(),i={runId:r?.runId||null,status:r?.status||null,exitCode:r?.exitCode??null,likelyCause:"Unknown failure",confidence:"low",nextStep:'Call run_artifacts({ runId, type: "log" }) with larger tail and inspect full logs.'};return r?.status==="running"||r?.status==="queued"?{...i,likelyCause:"Run is still active; no terminal failure to diagnose yet.",confidence:"high",nextStep:'Call run_status({ runId: "all" }) to check progress.'}:n.includes("test spec not found")?{...i,likelyCause:"Invalid spec input: run_test received a non-existent spec path.",confidence:"high",nextStep:"Use spec as inline:... or a real file path from list_specs. For ticket keys, fetch steps first via Jira then build inline spec."}:n.includes("unknown command")&&n.includes("'run'")?{...i,likelyCause:"CLI command mismatch (`zibby run` unsupported in current CLI).",confidence:"high",nextStep:"Use `zibby test ...` spawn path (runner should already do this)."}:n.includes("missing openai_api_key")||n.includes("didn't provide an api key")||n.includes("401")?{...i,likelyCause:"Provider authentication/config issue (API key/proxy auth missing or rejected).",confidence:"medium",nextStep:"Verify proxy/token env and auth mode, then retry once configuration is valid."}:n.includes("spawn error")||n.includes("enoent")?{...i,likelyCause:"Failed to spawn CLI process (binary/path/environment issue).",confidence:"medium",nextStep:"Confirm `zibby` is installed and available in PATH for the chat process."}:n.includes("security command failed")||n.includes("security process exited with code: 45")||n.includes("password not found for account")?{...i,likelyCause:"Cursor agent keychain/auth failed during preflight (often transient, more common under parallel starts).",confidence:"high",nextStep:'Retry failed ticket sequentially (not parallel), or run with a different agent via run_test({ ..., agent: "codex" }).'}:i}function _r(r,t){let{runId:e,type:s,node:n="execute_live",query:i,tail:o=3e3}=r;if(s==="search"){if(!i)return JSON.stringify({error:'query is required for type="search"'});let c=F(t,Se,be);if(!L(c))return JSON.stringify({matches:[],message:"No sessions found"});let l=[],u=i.toLowerCase();for(let p of ce(c,{withFileTypes:!0})){if(!p.isDirectory())continue;let y=x(c,p.name),m=[{file:"execute_live/result.json",label:"result"},{file:"execute_live/events.json",label:"events"},{file:"execute_live/raw_stream_output.txt",label:"log"},{file:"generate_script/raw_stream_output.txt",label:"script_log"},{file:"title.txt",label:"title"}];for(let{file:f,label:k}of m){let h=x(y,f);if(L(h))try{let g=ae(h,"utf-8");if(g.toLowerCase().includes(u)){let _=g.toLowerCase().indexOf(u),d=Math.max(0,_-100),b=Math.min(g.length,_+i.length+100);l.push({sessionId:p.name,artifact:k,snippet:g.slice(d,b)})}}catch{}}if(l.length>=20)break}return JSON.stringify({query:i,matches:l,total:l.length})}if(!e)return JSON.stringify({error:"runId is required for this type"});if(s==="log"){let c=A.get(e),l=gt(c?.logPath,o);if(l)return JSON.stringify({runId:e,source:"run-log",totalLength:l.length,tail:l})}let a=gr(e,t);if(!a)return JSON.stringify({error:`No session found for run ${e}. The run may still be starting.`});switch(s){case"list":{let c=yt(a);return JSON.stringify({sessionId:a.split("/").pop(),files:c,total:c.length})}case"result":{let c=at(x(a,n,"result.json"));return JSON.stringify(c?{sessionId:a.split("/").pop(),node:n,result:c}:{error:`No result.json found in ${n}`})}case"events":{let c=at(x(a,n,"events.json"));if(!c)return JSON.stringify({error:`No events.json found in ${n}`});let l=Array.isArray(c)?c:c.events||[];return JSON.stringify({sessionId:a.split("/").pop(),node:n,totalEvents:l.length,events:l.slice(-50)})}case"log":{let c=x(a,n,"raw_stream_output.txt");if(!L(c))return JSON.stringify({error:`No log found in ${n}`});let l=ae(c,"utf-8");return JSON.stringify({sessionId:a.split("/").pop(),node:n,totalLength:l.length,tail:l.slice(-o)})}default:return JSON.stringify({error:`Unknown artifact type: ${s}. Use: list, result, events, log, search`})}}function kr(r,t){let e=String(r?.runId||"all"),s=Number(r?.tail||2e3),n=e==="all"?[...A.keys()]:[e];if(n.length===0)return JSON.stringify({error:"No runs available to diagnose. Call run_test first."});let i=n.map(c=>{let l=A.get(c);if(!l)return{runId:c,error:`Run not found: ${c}`};let u=gt(l.logPath,s),p=String(l.error||"").slice(-Math.max(200,s));return{...hr({run:l,logTail:u,errorTail:p}),ticketKey:l.ticketKey||null,spec:l.spec,logTail:u,errorTail:p}}),o=i.filter(c=>c.status==="failed"||c.status==="error"),a=i.filter(c=>c.status==="running"||c.status==="queued");return JSON.stringify({total:i.length,failed:o.length,active:a.length,diagnoses:i})}function wr(r,t){let e=r?.directory||"test-specs",s=F(t,e);if(!L(s))return JSON.stringify({specs:[],directory:e,message:`Directory not found: ${e}`});try{let i=function(o,a){for(let c of ce(o,{withFileTypes:!0})){let l=a?`${a}/${c.name}`:c.name;c.isDirectory()?i(x(o,c.name),l):(c.name.endsWith(".txt")||c.name.endsWith(".md"))&&n.push(l)}},n=[];return i(s,""),JSON.stringify({specs:n.map(o=>`${e}/${o}`),total:n.length,directory:e})}catch(n){return JSON.stringify({error:n.message})}}import{spawn as br}from"child_process";import{existsSync as J,mkdirSync as Sr,readdirSync as ht,statSync as vr,readFileSync as Nr}from"fs";import{resolve as Ne,join as D,basename as Or}from"path";var Oe=".zibby/repos";function le(r,t,e={}){return new Promise((s,n)=>{let i=br(r,{cwd:t,shell:!0,env:{...process.env,GIT_TERMINAL_PROMPT:"0",...e}}),o="",a="";i.stdout.on("data",c=>{o+=c.toString()}),i.stderr.on("data",c=>{a+=c.toString()}),i.on("close",c=>{c!==0?n(new Error(`Exit ${c}: ${a.trim()||o.trim()}`)):s(o.trim())}),i.on("error",c=>n(c))})}var _t={id:"git",description:"Clone and manage git repositories for codebase analysis",envKeys:["GITHUB_TOKEN","GITLAB_TOKEN"],promptFragment:`## Git Repositories
322
+ ...[truncated]`),{inlineSpec:`inline:${u}`,issueKey:r}):null}catch{return null}}function gr(r,t){try{let e=JSON.parse(r);return JSON.stringify({...e,...t})}catch{return r}}async function hr(r,t,e){let s={...r},n=String(s.spec??"").trim();if(!n)return JSON.stringify({error:"spec is required"});let i=null;if(nt.test(n)&&!n.startsWith("inline:")){let u=await yr(n);u&&(n=u.inlineSpec,s.spec=n,String(s.ticketKey||"").trim()||(s.ticketKey=u.issueKey),i=u.issueKey)}let o=String(s.ticketKey||"").trim();if(o){for(let[u,p]of A.entries())if(p?.ticketKey===o&&!(p?.status!=="running"&&p?.status!=="queued"))return JSON.stringify({runId:u,ticketKey:o,status:p.status,reused:!0,message:`A run for ${o} is already ${p.status}. Reusing existing run instead of starting a duplicate.`})}if(!n.startsWith("inline:")){let u=F(t,n);if(!L(u))return nt.test(n)?JSON.stringify({error:`Invalid run_test spec: "${n}" is an issue id, not a spec.`,reason:"Jira auto-load was attempted but did not return usable text, or Jira is not configured.",doNext:["Confirm the jira skill is active and authenticated.",'Or call tracker tools yourself, then run_test with spec: "inline:" + steps.'],validExample:{spec:"inline:1. Open https://example.com \u2026 2. Verify \u2026",ticketKey:n},invalidExample:{spec:n,ticketKey:n}}):JSON.stringify({error:`Test spec not found: ${n}`,hint:'If this should be issue steps, load the issue with your tracker tools first, then run_test with spec: "inline:" + steps. Otherwise use a real file path.'})}let a=lt(e?.options?.config);if(we()>=a){let u=pt(),p=s.ticketKey||u,y={runId:u,spec:s.ticketKey?`${s.ticketKey}: ${s.spec}`:s.spec,ticketKey:s.ticketKey||null,status:"queued",startTime:Date.now(),exitCode:null,output:"",error:""};A.set(u,y),q.push({args:{...s,_queuedRunId:u},cwd:t,context:e}),j(p,"\u23F3",`Queued (${we()}/${a} running, ${q.length} queued)`);let m={runId:u,spec:y.spec,ticketKey:y.ticketKey,status:"queued",message:`Queued \u2014 will start when a slot opens (max ${a} concurrent).`};return i&&(m.resolvedFromJiraIssue=i,m.message+=` (spec built from Jira ${i})`),JSON.stringify(m)}let c=Date.now()-ke;c<et&&ke>0&&await new Promise(u=>setTimeout(u,et-c)),ke=Date.now();let l=ft(s,t,e);return i?gr(l,{resolvedFromJiraIssue:i,message:`Spec was loaded from Jira issue ${i} (description + comments).`}):l}function ft(r,t,e){let{spec:s,ticketKey:n,agent:i,headless:o,workflow:a,_queuedRunId:c}=r,l=c||pt(),u=s,p=!1;if(s.startsWith("inline:")){p=!0;let O=cr(t);Xe(O,{recursive:!0}),u=x(O,`${l}.txt`),nr(u,s.slice(7).trim(),"utf-8")}let y=F(t,".zibby","output","runs");Xe(y,{recursive:!0});let m=x(y,`${l}.log`),f=or(m,{flags:"a"}),h=i&&["assistant","cursor","claude","codex","gemini"].includes(i)?i:null,g=["test",u];h&&g.push("--agent",h),o&&g.push("--headless"),a&&g.push("--workflow",a),ut&&console.error(`[zibby:spawn] skill=run_test parentPid=${process.pid} \u2192 child zibby ${g.map(O=>/\s/.test(O)?JSON.stringify(O):O).join(" ")} cwd=${t}`);let _=ct("zibby",g,{cwd:t,env:{...process.env,ZIBBY_WORKFLOW_GRAPH_LOG_MARKERS:"1"},stdio:["ignore","pipe","pipe"],detached:!1}),d={runId:l,spec:n?`${n}: ${s}`:s,ticketKey:n||null,specPath:u,logPath:m,isInline:p,pid:_.pid,status:"running",output:"",error:"",startTime:Date.now(),exitCode:null,currentNode:null,completedNodes:[]},b=n||l,I="";function Ee(O){let v=dt(O).trim();if(!v)return;if(v.startsWith("__WORKFLOW_GRAPH_LOG__")){try{let R=JSON.parse(v.slice(22));R.phase==="node_begin"?d.currentNode=R.node:R.phase==="node_end"&&(R.node&&!d.completedNodes.includes(R.node)&&d.completedNodes.push(R.node),d.currentNode===R.node&&(d.currentNode=null))}catch{}return}let Y=v.match(/Session\s+(\S+)/);if(Y&&!d.sessionId&&(d.sessionId=Y[1],d.sessionPath=F(t,Se,be,d.sessionId)),v.startsWith("\u250C ")||v.startsWith("\u250C ")){let R=v.slice(2).trim();d.currentNode=R,ie&&j(b,"\u25B6",`${R}`)}else if(v.startsWith("\u2514 ")||v.startsWith("\u2514 ")){let R=v.slice(2).trim();R.startsWith("done")?(d.currentNode&&!d.completedNodes.includes(d.currentNode)&&d.completedNodes.push(d.currentNode),ie&&j(b,"\u2714",`${d.currentNode||"node"} done ${R.replace("done","").trim()}`),d.currentNode=null):R.startsWith("failed")&&(ie&&j(b,"\u2718",`${d.currentNode||"node"} failed ${R.replace("failed","").trim()}`),d.currentNode=null)}else v.includes("Workflow completed")&&(d.currentNode=null,ie&&j(b,"\u2714",`Workflow completed (${tt(Date.now()-d.startTime)})`))}function Yt(O){let v=O.toString();d.output+=v,f.write(v),d.output.length>5e4&&(d.output=d.output.slice(-3e4)),I+=v;let Y=I.split(`
323
+ `);I=Y.pop();for(let R of Y)Ee(R)}return _.stdout.on("data",Yt),_.stderr.on("data",O=>{let v=O.toString();d.error+=v,f.write(v),d.error.length>2e4&&(d.error=d.error.slice(-1e4))}),_.on("close",O=>{d.status=O===0?"passed":"failed",d.exitCode=O,d.endTime=Date.now(),I&&Ee(I),f.end();let v=tt(Date.now()-d.startTime);if(O===0?j(b,"\u2705",`Passed (${v})`):j(b,"\u274C",`Failed (${v})`),d.isInline)try{ir(d.specPath)}catch{}st()}),_.on("error",O=>{d.status="error",d.error+=`
324
+ Spawn error: ${O.message}`,j(b,"\u274C",`Spawn error: ${O.message}`),f.end(),st()}),d._child=_,A.set(l,d),JSON.stringify({runId:l,spec:d.spec,ticketKey:d.ticketKey,status:"running",pid:_.pid,logFile:m})}function it(r){let t=Math.round(((r.endTime||Date.now())-r.startTime)/1e3),e=r.completedNodes||[],s=r.currentNode||null;if(r.status!=="running")return{elapsed:t,stage:r.status,completedNodes:e,currentNode:null};let n;return s?(n=`Actively executing node "${s}"`,e.length&&(n+=` (completed: ${e.join(", ")})`)):e.length?n=`Between nodes (completed: ${e.join(", ")})`:n="Starting up (initializing workflow)",n+=`. Elapsed: ${t}s. This is normal progress \u2014 do not cancel.`,{elapsed:t,stage:"running",currentNode:s,completedNodes:e,progress:n}}function _r(r){let{runId:t}=r;if(!t)return JSON.stringify({error:"runId is required"});if(t==="all"){let i=[...A.entries()].map(([u,p])=>{let y=it(p),m={runId:u,spec:p.spec,ticketKey:p.ticketKey,status:p.status,elapsed:y.elapsed,exitCode:p.exitCode,sessionId:p.sessionId||null};return p.status==="running"?(m.currentNode=y.currentNode,m.completedNodes=y.completedNodes,m.progress=y.progress):m.outputTail=p.output.slice(-500),m}),o=i.filter(u=>u.status==="running").length,a=i.filter(u=>u.status==="passed").length,c=i.filter(u=>u.status==="failed").length,l={total:i.length,running:o,passed:a,failed:c,runs:i};return o>0&&(l._hint="All running tests are progressing normally through their workflow nodes. Do NOT cancel, diagnose, or interpret as stuck. Just tell the user they are still running."),JSON.stringify(l)}let e=A.get(t);if(!e)return JSON.stringify({error:`Run not found: ${t}`});let s=it(e),n={runId:t,spec:e.spec,ticketKey:e.ticketKey,status:e.status,elapsed:s.elapsed,exitCode:e.exitCode,sessionId:e.sessionId||null};return e.status==="running"?(n.currentNode=s.currentNode,n.completedNodes=s.completedNodes,n.progress=s.progress):(n.outputTail=e.output.slice(-1e3),n.errorTail=e.error.slice(-500)),e.status==="running"&&(n._hint="This run is actively progressing. Do NOT cancel, diagnose, or assume stuck. Just tell the user it is still running."),JSON.stringify(n)}function ot(r,t){if(t.status==="queued"){let e=q.findIndex(s=>s.args._queuedRunId===r);return e>=0&&q.splice(e,1),t.status="cancelled",t.endTime=Date.now(),{ok:!0,runId:r,status:"cancelled"}}if(t.status!=="running")return{ok:!1,runId:r,error:`Run is not active (status: ${t.status})`};try{return t._child.kill("SIGTERM"),t.status="cancelled",t.endTime=Date.now(),{ok:!0,runId:r,status:"cancelled"}}catch(e){return{ok:!1,runId:r,error:`Failed to cancel: ${e.message}`}}}function kr(r){let{runId:t}=r;if(!t)return JSON.stringify({error:"runId is required"});if(t==="all"){let s=[];for(let[n,i]of A.entries())(i.status==="running"||i.status==="queued")&&s.push(ot(n,i));return s.length===0?JSON.stringify({ok:!0,message:"No active runs to cancel"}):JSON.stringify({ok:!0,cancelled:s.length,results:s})}let e=A.get(t);return JSON.stringify(e?ot(t,e):{error:`Run not found: ${t}`})}function wr(r,t){let e=A.get(r);if(e?.sessionPath&&L(e.sessionPath))return e.sessionPath;if(e?.sessionId){let s=F(t,Se,be,e.sessionId);if(L(s))return s}return null}function yt(r,t=""){let e=[];if(!L(r))return e;for(let s of ce(r,{withFileTypes:!0})){let n=t?`${t}/${s.name}`:s.name;if(s.isDirectory())e.push(...yt(x(r,s.name),n));else{let i=ar(x(r,s.name));e.push({path:n,size:i.size})}}return e}function at(r){if(!L(r))return null;try{return JSON.parse(ae(r,"utf-8"))}catch{return null}}function gt(r,t=2e3){if(!r||!L(r))return"";try{return ae(r,"utf-8").slice(-Math.max(200,Number(t)||2e3))}catch{return""}}function br({run:r,logTail:t,errorTail:e}){let n=`${t||""}
325
+ ${e||""}`.toLowerCase(),i={runId:r?.runId||null,status:r?.status||null,exitCode:r?.exitCode??null,likelyCause:"Unknown failure",confidence:"low",nextStep:'Call run_artifacts({ runId, type: "log" }) with larger tail and inspect full logs.'};return r?.status==="running"||r?.status==="queued"?{...i,likelyCause:"Run is still active; no terminal failure to diagnose yet.",confidence:"high",nextStep:'Call run_status({ runId: "all" }) to check progress.'}:n.includes("test spec not found")?{...i,likelyCause:"Invalid spec input: run_test received a non-existent spec path.",confidence:"high",nextStep:"Use spec as inline:... or a real file path from list_specs. For ticket keys, fetch steps first via Jira then build inline spec."}:n.includes("unknown command")&&n.includes("'run'")?{...i,likelyCause:"CLI command mismatch (`zibby run` unsupported in current CLI).",confidence:"high",nextStep:"Use `zibby test ...` spawn path (runner should already do this)."}:n.includes("missing openai_api_key")||n.includes("didn't provide an api key")||n.includes("401")?{...i,likelyCause:"Provider authentication/config issue (API key/proxy auth missing or rejected).",confidence:"medium",nextStep:"Verify proxy/token env and auth mode, then retry once configuration is valid."}:n.includes("spawn error")||n.includes("enoent")?{...i,likelyCause:"Failed to spawn CLI process (binary/path/environment issue).",confidence:"medium",nextStep:"Confirm `zibby` is installed and available in PATH for the chat process."}:n.includes("security command failed")||n.includes("security process exited with code: 45")||n.includes("password not found for account")?{...i,likelyCause:"Cursor agent keychain/auth failed during preflight (often transient, more common under parallel starts).",confidence:"high",nextStep:'Retry failed ticket sequentially (not parallel), or run with a different agent via run_test({ ..., agent: "codex" }).'}:i}function Sr(r,t){let{runId:e,type:s,node:n="execute_live",query:i,tail:o=3e3}=r;if(s==="search"){if(!i)return JSON.stringify({error:'query is required for type="search"'});let c=F(t,Se,be);if(!L(c))return JSON.stringify({matches:[],message:"No sessions found"});let l=[],u=i.toLowerCase();for(let p of ce(c,{withFileTypes:!0})){if(!p.isDirectory())continue;let y=x(c,p.name),m=[{file:"execute_live/result.json",label:"result"},{file:"execute_live/events.json",label:"events"},{file:"execute_live/raw_stream_output.txt",label:"log"},{file:"generate_script/raw_stream_output.txt",label:"script_log"},{file:"title.txt",label:"title"}];for(let{file:f,label:k}of m){let h=x(y,f);if(L(h))try{let g=ae(h,"utf-8");if(g.toLowerCase().includes(u)){let _=g.toLowerCase().indexOf(u),d=Math.max(0,_-100),b=Math.min(g.length,_+i.length+100);l.push({sessionId:p.name,artifact:k,snippet:g.slice(d,b)})}}catch{}}if(l.length>=20)break}return JSON.stringify({query:i,matches:l,total:l.length})}if(!e)return JSON.stringify({error:"runId is required for this type"});if(s==="log"){let c=A.get(e),l=gt(c?.logPath,o);if(l)return JSON.stringify({runId:e,source:"run-log",totalLength:l.length,tail:l})}let a=wr(e,t);if(!a)return JSON.stringify({error:`No session found for run ${e}. The run may still be starting.`});switch(s){case"list":{let c=yt(a);return JSON.stringify({sessionId:a.split("/").pop(),files:c,total:c.length})}case"result":{let c=at(x(a,n,"result.json"));return JSON.stringify(c?{sessionId:a.split("/").pop(),node:n,result:c}:{error:`No result.json found in ${n}`})}case"events":{let c=at(x(a,n,"events.json"));if(!c)return JSON.stringify({error:`No events.json found in ${n}`});let l=Array.isArray(c)?c:c.events||[];return JSON.stringify({sessionId:a.split("/").pop(),node:n,totalEvents:l.length,events:l.slice(-50)})}case"log":{let c=x(a,n,"raw_stream_output.txt");if(!L(c))return JSON.stringify({error:`No log found in ${n}`});let l=ae(c,"utf-8");return JSON.stringify({sessionId:a.split("/").pop(),node:n,totalLength:l.length,tail:l.slice(-o)})}default:return JSON.stringify({error:`Unknown artifact type: ${s}. Use: list, result, events, log, search`})}}function vr(r,t){let e=String(r?.runId||"all"),s=Number(r?.tail||2e3),n=e==="all"?[...A.keys()]:[e];if(n.length===0)return JSON.stringify({error:"No runs available to diagnose. Call run_test first."});let i=n.map(c=>{let l=A.get(c);if(!l)return{runId:c,error:`Run not found: ${c}`};let u=gt(l.logPath,s),p=String(l.error||"").slice(-Math.max(200,s));return{...br({run:l,logTail:u,errorTail:p}),ticketKey:l.ticketKey||null,spec:l.spec,logTail:u,errorTail:p}}),o=i.filter(c=>c.status==="failed"||c.status==="error"),a=i.filter(c=>c.status==="running"||c.status==="queued");return JSON.stringify({total:i.length,failed:o.length,active:a.length,diagnoses:i})}function Nr(r,t){let e=r?.directory||"test-specs",s=F(t,e);if(!L(s))return JSON.stringify({specs:[],directory:e,message:`Directory not found: ${e}`});try{let i=function(o,a){for(let c of ce(o,{withFileTypes:!0})){let l=a?`${a}/${c.name}`:c.name;c.isDirectory()?i(x(o,c.name),l):(c.name.endsWith(".txt")||c.name.endsWith(".md"))&&n.push(l)}},n=[];return i(s,""),JSON.stringify({specs:n.map(o=>`${e}/${o}`),total:n.length,directory:e})}catch(n){return JSON.stringify({error:n.message})}}import{spawn as Or}from"child_process";import{existsSync as J,mkdirSync as Rr,readdirSync as ht,statSync as $r,readFileSync as Ir}from"fs";import{resolve as Ne,join as D,basename as jr}from"path";var Oe=".zibby/repos";function le(r,t,e={}){return new Promise((s,n)=>{let i=Or(r,{cwd:t,shell:!0,env:{...process.env,GIT_TERMINAL_PROMPT:"0",...e}}),o="",a="";i.stdout.on("data",c=>{o+=c.toString()}),i.stderr.on("data",c=>{a+=c.toString()}),i.on("close",c=>{c!==0?n(new Error(`Exit ${c}: ${a.trim()||o.trim()}`)):s(o.trim())}),i.on("error",c=>n(c))})}var _t={id:"git",description:"Clone and manage git repositories for codebase analysis",envKeys:["GITHUB_TOKEN","GITLAB_TOKEN"],promptFragment:`## Git Repositories
326
326
  You can clone and explore git repositories locally for codebase analysis:
327
327
  - git_checkout: Clone a repo (or pull if already cloned). Supports GitHub and GitLab with auto-auth.
328
328
  - git_list_repos: List locally cloned repos
@@ -333,7 +333,7 @@ When a test ticket lacks context, use this workflow:
333
333
  2. Use git_explore to understand the project structure
334
334
  3. Use shell commands (grep, cat) to read specific files for deeper understanding
335
335
  4. Use GitHub/GitLab skills to read related PRs and commits
336
- 5. Build well-informed test specs and save them to files before running tests`,resolve(){return null},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"git_checkout":return await Rr(t,s);case"git_list_repos":return $r(t,s);case"git_explore":return Ir(t,s);default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.message})}},tools:[{name:"git_checkout",description:"Clone a git repository locally (or pull latest if already cloned). Auto-authenticates with GitHub/GitLab tokens if available.",input_schema:{type:"object",properties:{url:{type:"string",description:'Repository URL (e.g. "https://github.com/org/repo" or "org/repo" shorthand for GitHub)'},branch:{type:"string",description:"Branch to checkout (default: repo default branch)"},shallow:{type:"boolean",description:"Shallow clone with depth 1 (default: true, faster)"},name:{type:"string",description:"Local directory name override (default: repo name from URL)"}},required:["url"]}},{name:"git_list_repos",description:"List locally cloned repositories",input_schema:{type:"object",properties:{}}},{name:"git_explore",description:"Quick structural overview of a cloned repo: key files, package.json info, directory tree (top 2 levels), detected framework/language",input_schema:{type:"object",properties:{repo:{type:"string",description:"Repo name (as listed by git_list_repos)"},depth:{type:"number",description:"Directory tree depth (default: 2)"}},required:["repo"]}}]};async function Rr(r,t){let{url:e,branch:s,shallow:n=!0,name:i}=r;!e.includes("://")&&!e.startsWith("git@")&&(e=`https://github.com/${e}`);let o=i||Or(e.replace(/\.git$/,"")),a=Ne(t,Oe);Sr(a,{recursive:!0});let c=D(a,o),l=e,u=process.env.GITHUB_TOKEN,p=process.env.GITLAB_TOKEN,y=process.env.GITLAB_URL;if(e.includes("github.com")&&u)l=e.replace("https://github.com",`https://x-access-token:${u}@github.com`);else if(p&&y)try{let k=new URL(y).host;e.includes(k)&&(l=e.replace(`https://${k}`,`https://oauth2:${p}@${k}`))}catch{}if(J(D(c,".git"))){let k=s?`git -C "${c}" fetch origin ${s} && git -C "${c}" checkout ${s} && git -C "${c}" pull origin ${s}`:`git -C "${c}" pull`;await le(k,t);let h=await le(`git -C "${c}" log -1 --format="%h %s"`,t);return JSON.stringify({action:"updated",repo:o,path:c,branch:s||"default",head:h})}let m=["git","clone"];n&&m.push("--depth","1"),s&&m.push("--branch",s),m.push(`"${l}"`,`"${c}"`),await le(m.join(" "),t);let f=await le(`git -C "${c}" log -1 --format="%h %s"`,t);return JSON.stringify({action:"cloned",repo:o,path:c,branch:s||"default",shallow:n,head:f})}function $r(r,t){let e=Ne(t,Oe);if(!J(e))return JSON.stringify({repos:[],message:"No repos cloned yet"});let s=[];for(let n of ht(e,{withFileTypes:!0})){if(!n.isDirectory())continue;let i=D(e,n.name);if(!J(D(i,".git")))continue;let o=vr(i);s.push({name:n.name,path:i,lastModified:o.mtime.toISOString()})}return JSON.stringify({repos:s,total:s.length,directory:e})}function Ir(r,t){let{repo:e,depth:s=2}=r,n=Ne(t,Oe,e);if(!J(n))return JSON.stringify({error:`Repo not found: ${e}. Run git_checkout first.`});let i={repo:e,path:n},o=D(n,"package.json");if(J(o))try{let m=JSON.parse(Nr(o,"utf-8"));i.packageJson={name:m.name,version:m.version,scripts:m.scripts?Object.keys(m.scripts):[],dependencies:m.dependencies?Object.keys(m.dependencies).slice(0,30):[],devDependencies:m.devDependencies?Object.keys(m.devDependencies).slice(0,20):[]},m.dependencies?.react?i.framework="React":m.dependencies?.next?i.framework="Next.js":m.dependencies?.vue?i.framework="Vue":m.dependencies?.angular?i.framework="Angular":m.dependencies?.express?i.framework="Express":m.dependencies?.fastify&&(i.framework="Fastify")}catch{}let a=D(n,"pyproject.toml");J(a)&&(i.language="Python");let c=D(n,"go.mod");J(c)&&(i.language="Go");let l=D(n,"Cargo.toml");J(l)&&(i.language="Rust"),J(o)&&(i.language=i.language||"JavaScript/TypeScript");let u=[];function p(m,f,k){if(k>s)return;let h;try{h=ht(m,{withFileTypes:!0})}catch{return}let g=h.filter(_=>!_.name.startsWith(".")&&_.name!=="node_modules"&&_.name!=="__pycache__"&&_.name!=="dist"&&_.name!=="build"&&_.name!==".git").sort((_,d)=>_.isDirectory()!==d.isDirectory()?_.isDirectory()?-1:1:_.name.localeCompare(d.name));for(let _ of g){let d=_.isDirectory();u.push(`${f}${d?"\u{1F4C1}":"\u{1F4C4}"} ${_.name}`),d&&k<s&&p(D(m,_.name),`${f} `,k+1)}}p(n,"",1),i.tree=u.slice(0,80),u.length>80&&(i.treeTruncated=!0);let y=["README.md","README.rst","src/App.tsx","src/App.jsx","src/App.js","src/routes.tsx","src/routes.js","app/routes.tsx","app/routes.js","src/index.tsx","src/index.ts","src/main.tsx","src/main.ts","pages/_app.tsx","pages/_app.js","app/layout.tsx","docker-compose.yml","Dockerfile",".env.example"];return i.keyFilesFound=y.filter(m=>J(D(n,m))),JSON.stringify(i)}import{execFileSync as Rt}from"child_process";import{existsSync as $t,mkdirSync as jr}from"fs";import{join as V,basename as Tr}from"path";import{randomBytes as Ar}from"crypto";import{pathToFileURL as de}from"url";import{createRequire as It}from"module";var kt=".zibby/memory",jt="dolt",Tt={encoding:"utf-8",stdio:["pipe","pipe","pipe"],timeout:15e3},Ie="dolt",Re=new Map,ue=new Map,Cr=It(import.meta.url),fe=()=>Ar(8).toString("hex"),W=()=>new Date().toISOString(),Er=[`CREATE TABLE IF NOT EXISTS chat_memory (
336
+ 5. Build well-informed test specs and save them to files before running tests`,resolve(){return null},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"git_checkout":return await Tr(t,s);case"git_list_repos":return Ar(t,s);case"git_explore":return Cr(t,s);default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.message})}},tools:[{name:"git_checkout",description:"Clone a git repository locally (or pull latest if already cloned). Auto-authenticates with GitHub/GitLab tokens if available.",input_schema:{type:"object",properties:{url:{type:"string",description:'Repository URL (e.g. "https://github.com/org/repo" or "org/repo" shorthand for GitHub)'},branch:{type:"string",description:"Branch to checkout (default: repo default branch)"},shallow:{type:"boolean",description:"Shallow clone with depth 1 (default: true, faster)"},name:{type:"string",description:"Local directory name override (default: repo name from URL)"}},required:["url"]}},{name:"git_list_repos",description:"List locally cloned repositories",input_schema:{type:"object",properties:{}}},{name:"git_explore",description:"Quick structural overview of a cloned repo: key files, package.json info, directory tree (top 2 levels), detected framework/language",input_schema:{type:"object",properties:{repo:{type:"string",description:"Repo name (as listed by git_list_repos)"},depth:{type:"number",description:"Directory tree depth (default: 2)"}},required:["repo"]}}]};async function Tr(r,t){let{url:e,branch:s,shallow:n=!0,name:i}=r;!e.includes("://")&&!e.startsWith("git@")&&(e=`https://github.com/${e}`);let o=i||jr(e.replace(/\.git$/,"")),a=Ne(t,Oe);Rr(a,{recursive:!0});let c=D(a,o),l=e,u=process.env.GITHUB_TOKEN,p=process.env.GITLAB_TOKEN,y=process.env.GITLAB_URL;if(e.includes("github.com")&&u)l=e.replace("https://github.com",`https://x-access-token:${u}@github.com`);else if(p&&y)try{let k=new URL(y).host;e.includes(k)&&(l=e.replace(`https://${k}`,`https://oauth2:${p}@${k}`))}catch{}if(J(D(c,".git"))){let k=s?`git -C "${c}" fetch origin ${s} && git -C "${c}" checkout ${s} && git -C "${c}" pull origin ${s}`:`git -C "${c}" pull`;await le(k,t);let h=await le(`git -C "${c}" log -1 --format="%h %s"`,t);return JSON.stringify({action:"updated",repo:o,path:c,branch:s||"default",head:h})}let m=["git","clone"];n&&m.push("--depth","1"),s&&m.push("--branch",s),m.push(`"${l}"`,`"${c}"`),await le(m.join(" "),t);let f=await le(`git -C "${c}" log -1 --format="%h %s"`,t);return JSON.stringify({action:"cloned",repo:o,path:c,branch:s||"default",shallow:n,head:f})}function Ar(r,t){let e=Ne(t,Oe);if(!J(e))return JSON.stringify({repos:[],message:"No repos cloned yet"});let s=[];for(let n of ht(e,{withFileTypes:!0})){if(!n.isDirectory())continue;let i=D(e,n.name);if(!J(D(i,".git")))continue;let o=$r(i);s.push({name:n.name,path:i,lastModified:o.mtime.toISOString()})}return JSON.stringify({repos:s,total:s.length,directory:e})}function Cr(r,t){let{repo:e,depth:s=2}=r,n=Ne(t,Oe,e);if(!J(n))return JSON.stringify({error:`Repo not found: ${e}. Run git_checkout first.`});let i={repo:e,path:n},o=D(n,"package.json");if(J(o))try{let m=JSON.parse(Ir(o,"utf-8"));i.packageJson={name:m.name,version:m.version,scripts:m.scripts?Object.keys(m.scripts):[],dependencies:m.dependencies?Object.keys(m.dependencies).slice(0,30):[],devDependencies:m.devDependencies?Object.keys(m.devDependencies).slice(0,20):[]},m.dependencies?.react?i.framework="React":m.dependencies?.next?i.framework="Next.js":m.dependencies?.vue?i.framework="Vue":m.dependencies?.angular?i.framework="Angular":m.dependencies?.express?i.framework="Express":m.dependencies?.fastify&&(i.framework="Fastify")}catch{}let a=D(n,"pyproject.toml");J(a)&&(i.language="Python");let c=D(n,"go.mod");J(c)&&(i.language="Go");let l=D(n,"Cargo.toml");J(l)&&(i.language="Rust"),J(o)&&(i.language=i.language||"JavaScript/TypeScript");let u=[];function p(m,f,k){if(k>s)return;let h;try{h=ht(m,{withFileTypes:!0})}catch{return}let g=h.filter(_=>!_.name.startsWith(".")&&_.name!=="node_modules"&&_.name!=="__pycache__"&&_.name!=="dist"&&_.name!=="build"&&_.name!==".git").sort((_,d)=>_.isDirectory()!==d.isDirectory()?_.isDirectory()?-1:1:_.name.localeCompare(d.name));for(let _ of g){let d=_.isDirectory();u.push(`${f}${d?"\u{1F4C1}":"\u{1F4C4}"} ${_.name}`),d&&k<s&&p(D(m,_.name),`${f} `,k+1)}}p(n,"",1),i.tree=u.slice(0,80),u.length>80&&(i.treeTruncated=!0);let y=["README.md","README.rst","src/App.tsx","src/App.jsx","src/App.js","src/routes.tsx","src/routes.js","app/routes.tsx","app/routes.js","src/index.tsx","src/index.ts","src/main.tsx","src/main.ts","pages/_app.tsx","pages/_app.js","app/layout.tsx","docker-compose.yml","Dockerfile",".env.example"];return i.keyFilesFound=y.filter(m=>J(D(n,m))),JSON.stringify(i)}import{execFileSync as Rt}from"child_process";import{existsSync as $t,mkdirSync as Er}from"fs";import{join as V,basename as xr}from"path";import{randomBytes as Lr}from"crypto";import{pathToFileURL as de}from"url";import{createRequire as It}from"module";var kt=".zibby/memory",jt="dolt",Tt={encoding:"utf-8",stdio:["pipe","pipe","pipe"],timeout:15e3},Ie="dolt",Re=new Map,ue=new Map,Jr=It(import.meta.url),fe=()=>Lr(8).toString("hex"),W=()=>new Date().toISOString(),Dr=[`CREATE TABLE IF NOT EXISTS chat_memory (
337
337
  id VARCHAR(64) PRIMARY KEY,
338
338
  memory_key VARCHAR(160),
339
339
  category VARCHAR(32) NOT NULL,
@@ -364,10 +364,10 @@ When a test ticket lacks context, use this workflow:
364
364
  tasks_failed INT DEFAULT 0,
365
365
  key_facts TEXT,
366
366
  created_at VARCHAR(32) NOT NULL
367
- )`],wt=new Set;function C(r,t){return Rt(jt,t,{...Tt,cwd:r})}function K(r,t){try{let e=C(r,["sql","-q",t,"-r","json"]);return JSON.parse(e.trim()).rows||[]}catch{return[]}}function E(r,t){C(r,["sql","-q",t])}function bt(r){if(wt.has(r))return!0;if(!$t(V(r,".dolt"))){if(!xr())return!1;jr(r,{recursive:!0}),C(r,["init","--name","Zibby Chat Memory","--email","chat@zibby.app"])}let t=`${Er.join(`;
368
- `)};`;E(r,t);try{E(r,"ALTER TABLE chat_memory ADD COLUMN tier VARCHAR(16) DEFAULT 'mid'")}catch{}try{E(r,"ALTER TABLE chat_memory ADD COLUMN memory_key VARCHAR(160)")}catch{}return wt.add(r),!0}function xr(){try{return Rt(jt,["version"],{...Tt,timeout:5e3}),!0}catch{return!1}}function w(r){return r==null?"NULL":`'${String(r).replace(/'/g,"''")}'`}function je(r){return String(r||"").toLowerCase().replace(/[“”]/g,'"').replace(/[‘’]/g,"'").replace(/[\s_-]+/g," ").replace(/[^\w\s"']/g,"").replace(/\s+/g," ").trim()}function G(r){return r==="long"?3:r==="mid"?2:r==="short"?1:0}function Te(r,t){let e=["short","mid","long"].includes(r)?r:"mid";return new Set(["fact","decision","preference","credential","url","workaround"]).has(String(t||"").toLowerCase())&&e==="short"?"mid":e}function At(r){let t=new Map;for(let e of r||[]){let s=je(e.content),n=e.memory_key?`key:${e.memory_key}`:s?`norm:${s}`:"";if(!n)continue;let i=t.get(n);if(!i){t.set(n,e);continue}let o=G(i.tier),a=G(e.tier);if(a>o){t.set(n,e);continue}a===o&&Number(e.relevance||0)>Number(i.relevance||0)&&t.set(n,e)}return[...t.values()]}function me(r,t){let e=String(r??"");return e.length<=t?e:t<=1?e.slice(0,t):`${e.slice(0,t-1)}\u2026`}function pe(r,t){let e={recentSessions:Array.isArray(r?.recentSessions)?r.recentSessions:[],topMemories:Array.isArray(r?.topMemories)?r.topMemories:[],taskStats:Array.isArray(r?.taskStats)?r.taskStats:[],ticketFilter:r?.ticketFilter||null,backend:t||String(r?.backend||Ie),error:r?.error||null};return e.backend==="mem0"?{...e,recentSessions:[],taskStats:[]}:e}function Lr(r){let t=[];if(r.recentSessions?.length>0){t.push("Recent sessions:");for(let e of r.recentSessions.slice(0,3))e?.summary?.trim()&&t.push(`- ${me(e.summary,150)}${e.tickets?` [${e.tickets}]`:""}`)}if(r.topMemories?.length>0){t.push("Known facts:");for(let e of r.topMemories.slice(0,10)){let s=e.tier==="long"?"\u2605":"\xB7";t.push(`${s} [${e.category}] ${me(e.content,120)}`)}}return t.length===0?"":`## Memory Context
367
+ )`],wt=new Set;function C(r,t){return Rt(jt,t,{...Tt,cwd:r})}function K(r,t){try{let e=C(r,["sql","-q",t,"-r","json"]);return JSON.parse(e.trim()).rows||[]}catch{return[]}}function E(r,t){C(r,["sql","-q",t])}function bt(r){if(wt.has(r))return!0;if(!$t(V(r,".dolt"))){if(!Mr())return!1;Er(r,{recursive:!0}),C(r,["init","--name","Zibby Chat Memory","--email","chat@zibby.app"])}let t=`${Dr.join(`;
368
+ `)};`;E(r,t);try{E(r,"ALTER TABLE chat_memory ADD COLUMN tier VARCHAR(16) DEFAULT 'mid'")}catch{}try{E(r,"ALTER TABLE chat_memory ADD COLUMN memory_key VARCHAR(160)")}catch{}return wt.add(r),!0}function Mr(){try{return Rt(jt,["version"],{...Tt,timeout:5e3}),!0}catch{return!1}}function w(r){return r==null?"NULL":`'${String(r).replace(/'/g,"''")}'`}function je(r){return String(r||"").toLowerCase().replace(/[“”]/g,'"').replace(/[‘’]/g,"'").replace(/[\s_-]+/g," ").replace(/[^\w\s"']/g,"").replace(/\s+/g," ").trim()}function G(r){return r==="long"?3:r==="mid"?2:r==="short"?1:0}function Te(r,t){let e=["short","mid","long"].includes(r)?r:"mid";return new Set(["fact","decision","preference","credential","url","workaround"]).has(String(t||"").toLowerCase())&&e==="short"?"mid":e}function At(r){let t=new Map;for(let e of r||[]){let s=je(e.content),n=e.memory_key?`key:${e.memory_key}`:s?`norm:${s}`:"";if(!n)continue;let i=t.get(n);if(!i){t.set(n,e);continue}let o=G(i.tier),a=G(e.tier);if(a>o){t.set(n,e);continue}a===o&&Number(e.relevance||0)>Number(i.relevance||0)&&t.set(n,e)}return[...t.values()]}function me(r,t){let e=String(r??"");return e.length<=t?e:t<=1?e.slice(0,t):`${e.slice(0,t-1)}\u2026`}function pe(r,t){let e={recentSessions:Array.isArray(r?.recentSessions)?r.recentSessions:[],topMemories:Array.isArray(r?.topMemories)?r.topMemories:[],taskStats:Array.isArray(r?.taskStats)?r.taskStats:[],ticketFilter:r?.ticketFilter||null,backend:t||String(r?.backend||Ie),error:r?.error||null};return e.backend==="mem0"?{...e,recentSessions:[],taskStats:[]}:e}function Pr(r){let t=[];if(r.recentSessions?.length>0){t.push("Recent sessions:");for(let e of r.recentSessions.slice(0,3))e?.summary?.trim()&&t.push(`- ${me(e.summary,150)}${e.tickets?` [${e.tickets}]`:""}`)}if(r.topMemories?.length>0){t.push("Known facts:");for(let e of r.topMemories.slice(0,10)){let s=e.tier==="long"?"\u2605":"\xB7";t.push(`${s} [${e.category}] ${me(e.content,120)}`)}}return t.length===0?"":`## Memory Context
369
369
  ${t.join(`
370
- `)}`}function $e(r){return{backend:r.backend,recentSessions:r.recentSessions.slice(0,3).map(t=>({summary:me(String(t?.summary||""),160),tickets:t?.tickets||null,created_at:t?.created_at||null})),topMemories:r.topMemories.slice(0,8).map(t=>({category:t?.category||null,tier:t?.tier||null,content:me(String(t?.content||""),140),source:t?.source||null})),taskStats:r.taskStats,error:r.error||null}}async function St(r,t){let e=String(process.env.ZIBBY_MEMORY_BACKEND||"").trim().toLowerCase();if(e==="mem0"||e==="dolt")return e;let s=String(t?.options?.memoryBackend||t?.options?.config?.memory?.backend||"").trim().toLowerCase();if(s==="mem0"||s==="dolt")return s;if(ue.has(r))return ue.get(r);try{let n=V(r,".zibby.config.mjs");if($t(n)){let i=await import(de(n).href),o=String(i?.default?.memory?.backend||"").trim().toLowerCase();if(o==="mem0"||o==="dolt")return ue.set(r,o),o}}catch{}return ue.set(r,Ie),Ie}function Ct(r){let t=String(process.env.ZIBBY_MEMORY_USER_ID||"").trim();return t||`workspace:${Tr(r||process.cwd())}`}function Jr(){let r=String(process.env.ZIBBY_MEM0_OPENAI_BASE_URL||"").trim();if(!r)return null;let t=String(process.env.ZIBBY_MEM0_API_KEY||process.env.ZIBBY_USER_TOKEN||process.env.OPENAI_API_KEY||"").trim(),e=String(process.env.ZIBBY_MEM0_LLM_MODEL||"gpt-4.1-mini").trim(),s=String(process.env.ZIBBY_MEM0_EMBEDDER_MODEL||"text-embedding-3-small").trim(),n=Number(process.env.ZIBBY_MEM0_EMBEDDING_DIMS||1536);return{llm:{provider:"openai",config:{model:e,baseURL:r,...t?{apiKey:t}:{}}},embedder:{provider:"openai",config:{model:s,embeddingDims:n,baseURL:r,...t?{apiKey:t}:{}}},vectorStore:{provider:"memory",config:{dimension:n}}}}async function Et(r){let t=r||process.cwd();if(Re.has(t))return Re.get(t);let e;try{let a=It(de(V(t,"package.json")).href).resolve("mem0ai/oss");e=await import(de(a).href)}catch{try{let o=Cr.resolve("mem0ai/oss");e=await import(de(o).href)}catch(o){throw new Error(`Cannot find package 'mem0ai' for workspace "${t}". Install in that project: npm install mem0ai. (${o.message})`,{cause:o})}}let s=e?.Memory;if(!s)throw new Error("mem0ai/oss does not export Memory");let n=Jr(),i=n?new s(n):new s;return Re.set(t,i),i}function vt(r,t="mid"){return(Array.isArray(r)?r:Array.isArray(r?.results)?r.results:[]).map(s=>({id:s?.id||fe(),memory_key:s?.metadata?.memoryKey||s?.metadata?.memory_key||null,category:s?.metadata?.category||"fact",content:s?.memory||s?.content||"",source:s?.metadata?.source||"mem0",ticket_key:s?.metadata?.ticketKey||s?.metadata?.ticket_key||null,tier:Te(s?.metadata?.tier||t,s?.metadata?.category||"fact"),relevance:Number(s?.score??s?.metadata?.relevance??.8),created_at:s?.created_at||s?.metadata?.created_at||W()})).filter(s=>String(s.content||"").trim().length>0)}var xt={id:"chat-memory",description:"Persistent chat memory and task history (Dolt-backed)",envKeys:[],promptFragment:`## Chat Memory (persistent)
370
+ `)}`}function $e(r){return{backend:r.backend,recentSessions:r.recentSessions.slice(0,3).map(t=>({summary:me(String(t?.summary||""),160),tickets:t?.tickets||null,created_at:t?.created_at||null})),topMemories:r.topMemories.slice(0,8).map(t=>({category:t?.category||null,tier:t?.tier||null,content:me(String(t?.content||""),140),source:t?.source||null})),taskStats:r.taskStats,error:r.error||null}}async function St(r,t){let e=String(process.env.ZIBBY_MEMORY_BACKEND||"").trim().toLowerCase();if(e==="mem0"||e==="dolt")return e;let s=String(t?.options?.memoryBackend||t?.options?.config?.memory?.backend||"").trim().toLowerCase();if(s==="mem0"||s==="dolt")return s;if(ue.has(r))return ue.get(r);try{let n=V(r,".zibby.config.mjs");if($t(n)){let i=await import(de(n).href),o=String(i?.default?.memory?.backend||"").trim().toLowerCase();if(o==="mem0"||o==="dolt")return ue.set(r,o),o}}catch{}return ue.set(r,Ie),Ie}function Ct(r){let t=String(process.env.ZIBBY_MEMORY_USER_ID||"").trim();return t||`workspace:${xr(r||process.cwd())}`}function Ur(){let r=String(process.env.ZIBBY_MEM0_OPENAI_BASE_URL||"").trim();if(!r)return null;let t=String(process.env.ZIBBY_MEM0_API_KEY||process.env.ZIBBY_USER_TOKEN||process.env.OPENAI_API_KEY||"").trim(),e=String(process.env.ZIBBY_MEM0_LLM_MODEL||"gpt-4.1-mini").trim(),s=String(process.env.ZIBBY_MEM0_EMBEDDER_MODEL||"text-embedding-3-small").trim(),n=Number(process.env.ZIBBY_MEM0_EMBEDDING_DIMS||1536);return{llm:{provider:"openai",config:{model:e,baseURL:r,...t?{apiKey:t}:{}}},embedder:{provider:"openai",config:{model:s,embeddingDims:n,baseURL:r,...t?{apiKey:t}:{}}},vectorStore:{provider:"memory",config:{dimension:n}}}}async function Et(r){let t=r||process.cwd();if(Re.has(t))return Re.get(t);let e;try{let a=It(de(V(t,"package.json")).href).resolve("mem0ai/oss");e=await import(de(a).href)}catch{try{let o=Jr.resolve("mem0ai/oss");e=await import(de(o).href)}catch(o){throw new Error(`Cannot find package 'mem0ai' for workspace "${t}". Install in that project: npm install mem0ai. (${o.message})`,{cause:o})}}let s=e?.Memory;if(!s)throw new Error("mem0ai/oss does not export Memory");let n=Ur(),i=n?new s(n):new s;return Re.set(t,i),i}function vt(r,t="mid"){return(Array.isArray(r)?r:Array.isArray(r?.results)?r.results:[]).map(s=>({id:s?.id||fe(),memory_key:s?.metadata?.memoryKey||s?.metadata?.memory_key||null,category:s?.metadata?.category||"fact",content:s?.memory||s?.content||"",source:s?.metadata?.source||"mem0",ticket_key:s?.metadata?.ticketKey||s?.metadata?.ticket_key||null,tier:Te(s?.metadata?.tier||t,s?.metadata?.category||"fact"),relevance:Number(s?.score??s?.metadata?.relevance??.8),created_at:s?.created_at||s?.metadata?.created_at||W()})).filter(s=>String(s.content||"").trim().length>0)}var xt={id:"chat-memory",description:"Persistent chat memory and task history (Dolt-backed)",envKeys:[],promptFragment:`## Chat Memory (persistent)
371
371
  You have persistent memory across sessions. Use it to avoid losing context:
372
372
  - **memory_store**: Save important facts, decisions, or context. Anything worth remembering.
373
373
  - **memory_recall**: Search your memory by keyword or category. Use this at the START of conversations to recall relevant context.
@@ -383,7 +383,7 @@ You have persistent memory across sessions. Use it to avoid losing context:
383
383
  - When the user's request is complete: call memory_end_session
384
384
 
385
385
  ### Categories for memory_store
386
- fact, decision, context, insight, credential, url, error, workaround`,resolve(){return null},async buildPromptContext(r,t={}){let e=r?.options?.workspace||process.cwd(),s=V(e,kt),n=await St(e,r);if(n==="dolt"&&!bt(s)){let i="Dolt not available. Install: brew install dolt (macOS) or see https://docs.dolthub.com/introduction/installation";return{backend:n,brief:pe({backend:n,error:i},n),promptContext:"",debugPreview:$e(pe({backend:n,error:i},n)),error:i}}try{let i=n==="mem0"?await Ot(t,s,e):Nt(t,s),o=JSON.parse(i||"{}"),a=pe({...o,backend:n},n);return{backend:n,brief:a,promptContext:Lr(a),debugPreview:$e(a),error:a.error||null}}catch(i){let o=String(i?.message||i),a=pe({backend:n,error:o},n);return{backend:n,brief:a,promptContext:"",debugPreview:$e(a),error:o}}},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd(),n=V(s,kt),i=await St(s,e);if((i==="dolt"||["memory_end_session","task_log","task_history"].includes(r))&&!bt(n))return JSON.stringify({error:"Dolt not available. Install: brew install dolt (macOS) or see https://docs.dolthub.com/introduction/installation"});try{switch(r){case"memory_store":return i==="mem0"?await Dr(t,n,s):Lt(t,n);case"memory_recall":return i==="mem0"?await Jt(t,n,s):Mr(t,n);case"memory_brief":return i==="mem0"?await Ot(t,n,s):Nt(t,n);case"memory_end_session":return Pr(t,n);case"task_log":return qr(t,n);case"task_history":return Ur(t,n);default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(a){if(i==="mem0")throw new Error(`mem0 throw: ${a.message}`,{cause:a});return JSON.stringify({error:a.message})}},tools:[{name:"memory_store",description:"Save a fact, decision, or context to persistent memory. Survives across sessions.",input_schema:{type:"object",properties:{memoryKey:{type:"string",description:"Stable semantic identity key (e.g. user.jira.default_board)"},content:{type:"string",description:"The information to remember"},category:{type:"string",enum:["fact","decision","context","insight","preference","credential","url","error","workaround"],description:"Category of memory"},tier:{type:"string",enum:["short","mid","long"],description:"Memory tier: short (session/24h), mid (days/weeks), long (permanent)"},source:{type:"string",description:'Where this info came from (e.g. "jira", "github", "user", "test_run")'},ticketKey:{type:"string",description:"Related ticket key (optional)"}},required:["content","category"]}},{name:"memory_recall",description:"Search persistent memory by keyword, category, ticket, or tier. Returns matching facts and context.",input_schema:{type:"object",properties:{query:{type:"string",description:"Search text (matches content)"},category:{type:"string",description:"Filter by category"},ticketKey:{type:"string",description:"Filter by ticket key"},tier:{type:"string",enum:["short","mid","long"],description:"Filter by memory tier"},limit:{type:"number",description:"Max results (default: 20)"}}}},{name:"memory_brief",description:"Get a compact briefing: recent session summaries + top relevant facts. Call at the start of a conversation.",input_schema:{type:"object",properties:{ticketKey:{type:"string",description:"Focus briefing on a specific ticket (optional)"}}}},{name:"memory_end_session",description:"End the current session and save a summary for future recall. Call when a task is complete.",input_schema:{type:"object",properties:{summary:{type:"string",description:"What happened in this session (1-3 sentences)"},tickets:{type:"string",description:"Comma-separated ticket keys covered"},tasksRun:{type:"number",description:"Number of tasks/tests run"},tasksPassed:{type:"number",description:"Number passed"},tasksFailed:{type:"number",description:"Number failed"},keyFacts:{type:"string",description:"Key facts worth remembering from this session (semicolon-separated)"}},required:["summary"]}},{name:"task_log",description:"Record a completed task (test run, analysis, generation) to persistent history.",input_schema:{type:"object",properties:{title:{type:"string",description:"Task description"},type:{type:"string",enum:["test_run","generate","analysis","research","other"],description:"Task type"},status:{type:"string",enum:["passed","failed","cancelled","error"],description:"Outcome"},ticketKey:{type:"string",description:"Related ticket key"},specPath:{type:"string",description:"Spec file path (if test run)"},resultSummary:{type:"string",description:"Brief result description"}},required:["title","type","status"]}},{name:"task_history",description:"Query past tasks by ticket, status, or type. See what was done before.",input_schema:{type:"object",properties:{ticketKey:{type:"string",description:"Filter by ticket key"},type:{type:"string",description:"Filter by task type"},status:{type:"string",description:"Filter by status"},limit:{type:"number",description:"Max results (default: 20)"}}}}]};function Lt(r,t){let{content:e,category:s,source:n,ticketKey:i,tier:o,memoryKey:a}=r;if(!e||!s)return JSON.stringify({error:"content and category are required"});let c=je(e);if(!c)return JSON.stringify({error:"content is empty after normalization"});let l=Te(o,s),u=l==="long"?1:l==="mid"?.8:.5,p=String(a||"").trim().slice(0,160);if(p){let g=K(t,`SELECT id, tier, relevance
386
+ fact, decision, context, insight, credential, url, error, workaround`,resolve(){return null},async buildPromptContext(r,t={}){let e=r?.options?.workspace||process.cwd(),s=V(e,kt),n=await St(e,r);if(n==="dolt"&&!bt(s)){let i="Dolt not available. Install: brew install dolt (macOS) or see https://docs.dolthub.com/introduction/installation";return{backend:n,brief:pe({backend:n,error:i},n),promptContext:"",debugPreview:$e(pe({backend:n,error:i},n)),error:i}}try{let i=n==="mem0"?await Ot(t,s,e):Nt(t,s),o=JSON.parse(i||"{}"),a=pe({...o,backend:n},n);return{backend:n,brief:a,promptContext:Pr(a),debugPreview:$e(a),error:a.error||null}}catch(i){let o=String(i?.message||i),a=pe({backend:n,error:o},n);return{backend:n,brief:a,promptContext:"",debugPreview:$e(a),error:o}}},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd(),n=V(s,kt),i=await St(s,e);if((i==="dolt"||["memory_end_session","task_log","task_history"].includes(r))&&!bt(n))return JSON.stringify({error:"Dolt not available. Install: brew install dolt (macOS) or see https://docs.dolthub.com/introduction/installation"});try{switch(r){case"memory_store":return i==="mem0"?await qr(t,n,s):Lt(t,n);case"memory_recall":return i==="mem0"?await Jt(t,n,s):Kr(t,n);case"memory_brief":return i==="mem0"?await Ot(t,n,s):Nt(t,n);case"memory_end_session":return Br(t,n);case"task_log":return Fr(t,n);case"task_history":return Wr(t,n);default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(a){if(i==="mem0")throw new Error(`mem0 throw: ${a.message}`,{cause:a});return JSON.stringify({error:a.message})}},tools:[{name:"memory_store",description:"Save a fact, decision, or context to persistent memory. Survives across sessions.",input_schema:{type:"object",properties:{memoryKey:{type:"string",description:"Stable semantic identity key (e.g. user.jira.default_board)"},content:{type:"string",description:"The information to remember"},category:{type:"string",enum:["fact","decision","context","insight","preference","credential","url","error","workaround"],description:"Category of memory"},tier:{type:"string",enum:["short","mid","long"],description:"Memory tier: short (session/24h), mid (days/weeks), long (permanent)"},source:{type:"string",description:'Where this info came from (e.g. "jira", "github", "user", "test_run")'},ticketKey:{type:"string",description:"Related ticket key (optional)"}},required:["content","category"]}},{name:"memory_recall",description:"Search persistent memory by keyword, category, ticket, or tier. Returns matching facts and context.",input_schema:{type:"object",properties:{query:{type:"string",description:"Search text (matches content)"},category:{type:"string",description:"Filter by category"},ticketKey:{type:"string",description:"Filter by ticket key"},tier:{type:"string",enum:["short","mid","long"],description:"Filter by memory tier"},limit:{type:"number",description:"Max results (default: 20)"}}}},{name:"memory_brief",description:"Get a compact briefing: recent session summaries + top relevant facts. Call at the start of a conversation.",input_schema:{type:"object",properties:{ticketKey:{type:"string",description:"Focus briefing on a specific ticket (optional)"}}}},{name:"memory_end_session",description:"End the current session and save a summary for future recall. Call when a task is complete.",input_schema:{type:"object",properties:{summary:{type:"string",description:"What happened in this session (1-3 sentences)"},tickets:{type:"string",description:"Comma-separated ticket keys covered"},tasksRun:{type:"number",description:"Number of tasks/tests run"},tasksPassed:{type:"number",description:"Number passed"},tasksFailed:{type:"number",description:"Number failed"},keyFacts:{type:"string",description:"Key facts worth remembering from this session (semicolon-separated)"}},required:["summary"]}},{name:"task_log",description:"Record a completed task (test run, analysis, generation) to persistent history.",input_schema:{type:"object",properties:{title:{type:"string",description:"Task description"},type:{type:"string",enum:["test_run","generate","analysis","research","other"],description:"Task type"},status:{type:"string",enum:["passed","failed","cancelled","error"],description:"Outcome"},ticketKey:{type:"string",description:"Related ticket key"},specPath:{type:"string",description:"Spec file path (if test run)"},resultSummary:{type:"string",description:"Brief result description"}},required:["title","type","status"]}},{name:"task_history",description:"Query past tasks by ticket, status, or type. See what was done before.",input_schema:{type:"object",properties:{ticketKey:{type:"string",description:"Filter by ticket key"},type:{type:"string",description:"Filter by task type"},status:{type:"string",description:"Filter by status"},limit:{type:"number",description:"Max results (default: 20)"}}}}]};function Lt(r,t){let{content:e,category:s,source:n,ticketKey:i,tier:o,memoryKey:a}=r;if(!e||!s)return JSON.stringify({error:"content and category are required"});let c=je(e);if(!c)return JSON.stringify({error:"content is empty after normalization"});let l=Te(o,s),u=l==="long"?1:l==="mid"?.8:.5,p=String(a||"").trim().slice(0,160);if(p){let g=K(t,`SELECT id, tier, relevance
387
387
  FROM chat_memory
388
388
  WHERE memory_key = ${w(p)}
389
389
  ORDER BY created_at DESC
@@ -403,18 +403,18 @@ fact, decision, context, insight, credential, url, error, workaround`,resolve(){
403
403
  SET tier = ${w(_?l:h)},
404
404
  relevance = ${Math.max(u,g)}
405
405
  WHERE id = ${w(m.id)}`);try{C(t,["add","."]),C(t,["commit","-m",`memory promote: ${s} \u2014 ${String(e).slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:m.id,category:s,tier:_?l:h,deduped:!0,promoted:!0})}return JSON.stringify({ok:!0,id:m.id,category:s,tier:h,deduped:!0,promoted:!1})}let f=fe(),k=process.env.ZIBBY_CHAT_SESSION_ID||null;E(t,`INSERT INTO chat_memory (id, memory_key, category, content, source, ticket_key, session_id, tier, relevance, created_at)
406
- VALUES (${w(f)}, ${w(p||null)}, ${w(s)}, ${w(e)}, ${w(n)}, ${w(i)}, ${w(k)}, ${w(l)}, ${u}, ${w(W())})`);try{C(t,["add","."]),C(t,["commit","-m",`memory: ${s} \u2014 ${e.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:f,category:s,tier:l,memoryKey:p||null,stored:e.slice(0,100)})}async function Dr(r,t,e){let{content:s,category:n,source:i,ticketKey:o,tier:a,memoryKey:c}=r;if(!s||!n)return JSON.stringify({error:"content and category are required"});try{let l=await Et(e),u=Ct(e),p=Te(a,n);return await l.add([{role:"user",content:String(s)}],{userId:u,metadata:{memoryKey:c||null,category:n,tier:p,source:i||"zibby-chat",ticketKey:o||null,created_at:W()}}),JSON.stringify({ok:!0,backend:"mem0",userId:u,category:n,tier:p,memoryKey:c||null,stored:String(s).slice(0,100)})}catch(l){throw new Error(`mem0 store failed: ${l.message}. If mem0 is not installed, run: npm install mem0ai`,{cause:l})}}function Mr(r,t){let{query:e,category:s,ticketKey:n,tier:i,limit:o=20}=r,a=[];e&&a.push(`content LIKE ${w(`%${e}%`)}`),s&&a.push(`category = ${w(s)}`),n&&a.push(`ticket_key = ${w(n)}`),i&&a.push(`tier = ${w(i)}`);let l=`SELECT id, memory_key, category, content, source, ticket_key, tier, relevance, created_at
406
+ VALUES (${w(f)}, ${w(p||null)}, ${w(s)}, ${w(e)}, ${w(n)}, ${w(i)}, ${w(k)}, ${w(l)}, ${u}, ${w(W())})`);try{C(t,["add","."]),C(t,["commit","-m",`memory: ${s} \u2014 ${e.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:f,category:s,tier:l,memoryKey:p||null,stored:e.slice(0,100)})}async function qr(r,t,e){let{content:s,category:n,source:i,ticketKey:o,tier:a,memoryKey:c}=r;if(!s||!n)return JSON.stringify({error:"content and category are required"});try{let l=await Et(e),u=Ct(e),p=Te(a,n);return await l.add([{role:"user",content:String(s)}],{userId:u,metadata:{memoryKey:c||null,category:n,tier:p,source:i||"zibby-chat",ticketKey:o||null,created_at:W()}}),JSON.stringify({ok:!0,backend:"mem0",userId:u,category:n,tier:p,memoryKey:c||null,stored:String(s).slice(0,100)})}catch(l){throw new Error(`mem0 store failed: ${l.message}. If mem0 is not installed, run: npm install mem0ai`,{cause:l})}}function Kr(r,t){let{query:e,category:s,ticketKey:n,tier:i,limit:o=20}=r,a=[];e&&a.push(`content LIKE ${w(`%${e}%`)}`),s&&a.push(`category = ${w(s)}`),n&&a.push(`ticket_key = ${w(n)}`),i&&a.push(`tier = ${w(i)}`);let l=`SELECT id, memory_key, category, content, source, ticket_key, tier, relevance, created_at
407
407
  FROM chat_memory ${a.length>0?`WHERE ${a.join(" AND ")}`:""}
408
408
  ORDER BY relevance DESC, created_at DESC
409
- LIMIT ${o}`,u=K(t,l);return JSON.stringify({total:u.length,memories:u})}async function Jt(r,t,e){let{query:s,category:n,ticketKey:i,tier:o,limit:a=20}=r;try{let c=await Et(e),l=Ct(e),u=[];if(s&&String(s).trim()){let p=await c.search(String(s),{userId:l,limit:a});u=vt(p)}else{let p=await c.getAll({userId:l,limit:Math.max(a,50)});u=vt(p)}return n&&(u=u.filter(p=>p.category===n)),i&&(u=u.filter(p=>p.ticket_key===i)),o&&(u=u.filter(p=>p.tier===o)),u=u.slice(0,a),JSON.stringify({total:u.length,memories:u,backend:"mem0"})}catch(c){throw new Error(`mem0 recall failed: ${c.message}. If mem0 is not installed, run: npm install mem0ai`,{cause:c})}}function Nt(r,t){let{ticketKey:e}=r;Br(t);let n=K(t,`SELECT session_id, summary, tickets, tasks_run, tasks_passed, tasks_failed, created_at
409
+ LIMIT ${o}`,u=K(t,l);return JSON.stringify({total:u.length,memories:u})}async function Jt(r,t,e){let{query:s,category:n,ticketKey:i,tier:o,limit:a=20}=r;try{let c=await Et(e),l=Ct(e),u=[];if(s&&String(s).trim()){let p=await c.search(String(s),{userId:l,limit:a});u=vt(p)}else{let p=await c.getAll({userId:l,limit:Math.max(a,50)});u=vt(p)}return n&&(u=u.filter(p=>p.category===n)),i&&(u=u.filter(p=>p.ticket_key===i)),o&&(u=u.filter(p=>p.tier===o)),u=u.slice(0,a),JSON.stringify({total:u.length,memories:u,backend:"mem0"})}catch(c){throw new Error(`mem0 recall failed: ${c.message}. If mem0 is not installed, run: npm install mem0ai`,{cause:c})}}function Nt(r,t){let{ticketKey:e}=r;Gr(t);let n=K(t,`SELECT session_id, summary, tickets, tasks_run, tasks_passed, tasks_failed, created_at
410
410
  FROM chat_sessions ORDER BY created_at DESC LIMIT 5`),i=e?`AND ticket_key = ${w(e)}`:"",o=K(t,`SELECT memory_key, category, content, source, tier, relevance, created_at FROM chat_memory
411
411
  WHERE tier = 'long' ${i} ORDER BY relevance DESC, created_at DESC LIMIT 10`),a=K(t,`SELECT memory_key, category, content, source, tier, relevance, created_at FROM chat_memory
412
412
  WHERE tier = 'mid' ${i} ORDER BY relevance DESC, created_at DESC LIMIT 8`),l=K(t,`SELECT type, status, COUNT(*) as cnt FROM chat_tasks
413
- GROUP BY type, status ORDER BY cnt DESC LIMIT 10`),u=At([...o,...a]);return JSON.stringify({recentSessions:n,topMemories:u,taskStats:l,ticketFilter:e||null})}async function Ot(r,t,e){let{ticketKey:s}=r,n=await Jt({limit:80},t,e),i=JSON.parse(n||"{}"),o=Array.isArray(i.memories)?i.memories:[];s&&(o=o.filter(y=>y.ticket_key===s));let a=y=>{let m=Date.parse(String(y?.created_at||""))||0;return Number(y?.relevance||0)*1e12+m},c=(y,m)=>a(m)-a(y),l=o.filter(y=>y.tier==="long").sort(c).slice(0,10),u=o.filter(y=>y.tier==="mid").sort(c).slice(0,8),p=At([...l,...u]);return JSON.stringify({recentSessions:[],topMemories:p,taskStats:[],ticketFilter:s||null,backend:"mem0"})}function Pr(r,t){let{summary:e,tickets:s,tasksRun:n=0,tasksPassed:i=0,tasksFailed:o=0,keyFacts:a}=r;if(!e)return JSON.stringify({error:"summary is required"});let c=process.env.ZIBBY_CHAT_SESSION_ID||`session_${fe()}`;if(E(t,`INSERT INTO chat_sessions (session_id, summary, tickets, tasks_run, tasks_passed, tasks_failed, key_facts, created_at)
414
- VALUES (${w(c)}, ${w(e)}, ${w(s)}, ${n}, ${i}, ${o}, ${w(a)}, ${w(W())})`),a)for(let l of a.split(";").map(u=>u.trim()).filter(Boolean))Lt({content:l,category:"fact",source:"session_summary",tier:"mid"},t);Kr(t);try{C(t,["add","."]),C(t,["commit","-m",`session end: ${e.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,sessionId:c,summary:e.slice(0,200)})}function qr(r,t){let{title:e,type:s,status:n,ticketKey:i,specPath:o,resultSummary:a}=r;if(!e||!s||!n)return JSON.stringify({error:"title, type, and status are required"});let c=fe(),l=process.env.ZIBBY_CHAT_SESSION_ID||null;E(t,`INSERT INTO chat_tasks (id, ticket_key, type, title, status, spec_path, session_id, result_summary, created_at, finished_at)
415
- VALUES (${w(c)}, ${w(i)}, ${w(s)}, ${w(e)}, ${w(n)}, ${w(o)}, ${w(l)}, ${w(a)}, ${w(W())}, ${w(W())})`);try{C(t,["add","."]),C(t,["commit","-m",`task: ${n} \u2014 ${e.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:c,title:e,type:s,status:n})}function Ur(r,t){let{ticketKey:e,type:s,status:n,limit:i=20}=r,o=[];e&&o.push(`ticket_key = ${w(e)}`),s&&o.push(`type = ${w(s)}`),n&&o.push(`status = ${w(n)}`);let c=`SELECT id, ticket_key, type, title, status, spec_path, result_summary, created_at, finished_at
413
+ GROUP BY type, status ORDER BY cnt DESC LIMIT 10`),u=At([...o,...a]);return JSON.stringify({recentSessions:n,topMemories:u,taskStats:l,ticketFilter:e||null})}async function Ot(r,t,e){let{ticketKey:s}=r,n=await Jt({limit:80},t,e),i=JSON.parse(n||"{}"),o=Array.isArray(i.memories)?i.memories:[];s&&(o=o.filter(y=>y.ticket_key===s));let a=y=>{let m=Date.parse(String(y?.created_at||""))||0;return Number(y?.relevance||0)*1e12+m},c=(y,m)=>a(m)-a(y),l=o.filter(y=>y.tier==="long").sort(c).slice(0,10),u=o.filter(y=>y.tier==="mid").sort(c).slice(0,8),p=At([...l,...u]);return JSON.stringify({recentSessions:[],topMemories:p,taskStats:[],ticketFilter:s||null,backend:"mem0"})}function Br(r,t){let{summary:e,tickets:s,tasksRun:n=0,tasksPassed:i=0,tasksFailed:o=0,keyFacts:a}=r;if(!e)return JSON.stringify({error:"summary is required"});let c=process.env.ZIBBY_CHAT_SESSION_ID||`session_${fe()}`;if(E(t,`INSERT INTO chat_sessions (session_id, summary, tickets, tasks_run, tasks_passed, tasks_failed, key_facts, created_at)
414
+ VALUES (${w(c)}, ${w(e)}, ${w(s)}, ${n}, ${i}, ${o}, ${w(a)}, ${w(W())})`),a)for(let l of a.split(";").map(u=>u.trim()).filter(Boolean))Lt({content:l,category:"fact",source:"session_summary",tier:"mid"},t);zr(t);try{C(t,["add","."]),C(t,["commit","-m",`session end: ${e.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,sessionId:c,summary:e.slice(0,200)})}function Fr(r,t){let{title:e,type:s,status:n,ticketKey:i,specPath:o,resultSummary:a}=r;if(!e||!s||!n)return JSON.stringify({error:"title, type, and status are required"});let c=fe(),l=process.env.ZIBBY_CHAT_SESSION_ID||null;E(t,`INSERT INTO chat_tasks (id, ticket_key, type, title, status, spec_path, session_id, result_summary, created_at, finished_at)
415
+ VALUES (${w(c)}, ${w(i)}, ${w(s)}, ${w(e)}, ${w(n)}, ${w(o)}, ${w(l)}, ${w(a)}, ${w(W())}, ${w(W())})`);try{C(t,["add","."]),C(t,["commit","-m",`task: ${n} \u2014 ${e.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:c,title:e,type:s,status:n})}function Wr(r,t){let{ticketKey:e,type:s,status:n,limit:i=20}=r,o=[];e&&o.push(`ticket_key = ${w(e)}`),s&&o.push(`type = ${w(s)}`),n&&o.push(`status = ${w(n)}`);let c=`SELECT id, ticket_key, type, title, status, spec_path, result_summary, created_at, finished_at
416
416
  FROM chat_tasks ${o.length>0?`WHERE ${o.join(" AND ")}`:""}
417
- ORDER BY created_at DESC LIMIT ${i}`,l=K(t,c);return JSON.stringify({total:l.length,tasks:l})}function Kr(r){try{E(r,"UPDATE chat_memory SET relevance = relevance * 0.98 WHERE tier = 'long' AND relevance > 0.5"),E(r,"UPDATE chat_memory SET relevance = relevance * 0.90 WHERE tier = 'mid' AND relevance > 0.1"),E(r,"UPDATE chat_memory SET relevance = relevance * 0.70 WHERE tier = 'short' AND relevance > 0.05"),E(r,"DELETE FROM chat_memory WHERE relevance < 0.05")}catch{}}function Br(r){try{let t=new Date(Date.now()-864e5).toISOString();E(r,`DELETE FROM chat_memory WHERE tier = 'short' AND created_at < ${w(t)}`)}catch{}}import{existsSync as M,readFileSync as X,readdirSync as Ae,mkdirSync as Fr,writeFileSync as H,statSync as Pt}from"fs";import{join as S,resolve as Ce,relative as qt,dirname as Ut}from"path";import{fileURLToPath as Wr}from"url";import{createRequire as zr}from"module";var Gr=zr(import.meta.url),Hr=`## Workflow Builder
417
+ ORDER BY created_at DESC LIMIT ${i}`,l=K(t,c);return JSON.stringify({total:l.length,tasks:l})}function zr(r){try{E(r,"UPDATE chat_memory SET relevance = relevance * 0.98 WHERE tier = 'long' AND relevance > 0.5"),E(r,"UPDATE chat_memory SET relevance = relevance * 0.90 WHERE tier = 'mid' AND relevance > 0.1"),E(r,"UPDATE chat_memory SET relevance = relevance * 0.70 WHERE tier = 'short' AND relevance > 0.05"),E(r,"DELETE FROM chat_memory WHERE relevance < 0.05")}catch{}}function Gr(r){try{let t=new Date(Date.now()-864e5).toISOString();E(r,`DELETE FROM chat_memory WHERE tier = 'short' AND created_at < ${w(t)}`)}catch{}}import{existsSync as M,readFileSync as X,readdirSync as Ae,mkdirSync as Hr,writeFileSync as H,statSync as Pt}from"fs";import{join as S,resolve as Ce,relative as Ut,dirname as qt}from"path";import{fileURLToPath as Yr}from"url";import{createRequire as Zr}from"module";var Vr=Zr(import.meta.url),Qr=`## Workflow Builder
418
418
 
419
419
  You can help users build custom AI workflows using the Zibby workflow framework.
420
420
 
@@ -524,9 +524,9 @@ Call with no arguments to see all available topics.
524
524
  - Workflow names must be kebab-case (e.g., ticket-triage, pr-review).
525
525
  - State flows through: each node's validated output is stored under its name in state (e.g., state.classify_ticket).
526
526
  - Downstream nodes reference upstream outputs in their prompt function (e.g., \\\`\\\${JSON.stringify(state.classify_ticket, null, 2)}\\\`).
527
- - Nodes can declare skills to get MCP tool access \u2014 the framework handles server lifecycle automatically.`,Kt=/^[a-z][a-z0-9-]{0,62}[a-z0-9]$/;function Bt(r){return`${r.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}Workflow`}function Q(r){return`${r.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())}Node`}function Yr(r){let t=r?.agent;return t?t.provider?t.provider:t.gemini?"gemini":t.codex?"codex":t.claude?"claude":t.cursor?"cursor":process.env.AGENT_TYPE||"cursor":process.env.AGENT_TYPE||"cursor"}async function Zr(r){let t=Ce(r,".zibby.config.mjs");if(!M(t))return{};try{return(await import(t)).default||{}}catch{return{}}}function Vr(){try{let r=Ut(Gr.resolve("@zibby/core/package.json")),t=S(r,"templates","browser-test-automation"),e=X(S(t,"nodes","preflight.mjs"),"utf-8"),s=X(S(t,"graph.mjs"),"utf-8");return{preflight:e,graph:s}}catch{return null}}var Dt=Ut(Wr(import.meta.url));function Ft(){let r=Ce(Dt,"..","..","..","docsite","docs");if(M(r))return r;let t=Ce(Dt,"..","docs");return M(t)?t:null}function Mt(){let r=Ft();if(!r)return[];try{let t=(e,s="")=>{let n=[];for(let i of Ae(e)){let o=S(e,i);try{if(Pt(o).isDirectory())n=n.concat(t(o,`${s}${i}/`));else if(i.endsWith(".md")){let a=`${s}${i.replace(/\.md$/,"")}`;n.push(a)}}catch{}}return n};return t(r)}catch{return[]}}function Wt(r){let t=Ft();if(!t)return null;let e=S(t,`${r}.md`);if(!M(e))return null;try{return X(e,"utf-8")}catch{return null}}function Qr(r){let t=r.nodes.map(o=>{let a=o.inputFields?.length?`Input fields: ${o.inputFields.join(", ")}`:"Input: receives full state",c=o.outputFields?.length?`Output fields: ${o.outputFields.join(", ")}`:"Output: determined by task",l=o.skills?.length?`Skills: ${o.skills.join(", ")}`:"";return`- ${o.name}: ${o.description}. ${a}. ${c}.${l?` ${l}`:""}`}).join(`
527
+ - Nodes can declare skills to get MCP tool access \u2014 the framework handles server lifecycle automatically.`,Kt=/^[a-z][a-z0-9-]{0,62}[a-z0-9]$/;function Bt(r){return`${r.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}Workflow`}function Q(r){return`${r.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())}Node`}function Xr(r){let t=r?.agent;return t?t.provider?t.provider:t.gemini?"gemini":t.codex?"codex":t.claude?"claude":t.cursor?"cursor":process.env.AGENT_TYPE||"cursor":process.env.AGENT_TYPE||"cursor"}async function en(r){let t=Ce(r,".zibby.config.mjs");if(!M(t))return{};try{return(await import(t)).default||{}}catch{return{}}}function tn(){try{let r=qt(Vr.resolve("@zibby/core/package.json")),t=S(r,"templates","browser-test-automation"),e=X(S(t,"nodes","preflight.mjs"),"utf-8"),s=X(S(t,"graph.mjs"),"utf-8");return{preflight:e,graph:s}}catch{return null}}var Dt=qt(Yr(import.meta.url));function Ft(){let r=Ce(Dt,"..","..","..","docsite","docs");if(M(r))return r;let t=Ce(Dt,"..","docs");return M(t)?t:null}function Mt(){let r=Ft();if(!r)return[];try{let t=(e,s="")=>{let n=[];for(let i of Ae(e)){let o=S(e,i);try{if(Pt(o).isDirectory())n=n.concat(t(o,`${s}${i}/`));else if(i.endsWith(".md")){let a=`${s}${i.replace(/\.md$/,"")}`;n.push(a)}}catch{}}return n};return t(r)}catch{return[]}}function Wt(r){let t=Ft();if(!t)return null;let e=S(t,`${r}.md`);if(!M(e))return null;try{return X(e,"utf-8")}catch{return null}}function sn(r){let t=r.nodes.map(o=>{let a=o.inputFields?.length?`Input fields: ${o.inputFields.join(", ")}`:"Input: receives full state",c=o.outputFields?.length?`Output fields: ${o.outputFields.join(", ")}`:"Output: determined by task",l=o.skills?.length?`Skills: ${o.skills.join(", ")}`:"";return`- ${o.name}: ${o.description}. ${a}. ${c}.${l?` ${l}`:""}`}).join(`
528
528
  `),e=r.edges.map(o=>o.condition?`- ${o.from} \u2192 ${o.to} (conditional: ${o.condition})`:`- ${o.from} \u2192 ${o.to}`).join(`
529
- `),s=Vr(),n=Wt("custom-workflows"),i="";return s&&(i+=`
529
+ `),s=tn(),n=Wt("custom-workflows"),i="";return s&&(i+=`
530
530
  ## Real working examples from the Zibby framework
531
531
 
532
532
  ### Example node (preflight.mjs) \u2014 a prompt-only node with Zod schema and onComplete hook:
@@ -603,7 +603,7 @@ Return a JSON object with this exact structure:
603
603
  }
604
604
  }
605
605
 
606
- IMPORTANT: Return ONLY valid JSON. No markdown fences, no explanation outside the JSON.`}async function zt(r,t){let e=await Zr(t),s=Yr(e);try{let{invokeAgent:n}=await import("@zibby/core"),i=Qr(r),o=await n(i,{state:{agentType:s,config:e,cwd:t,workspace:t}},{model:e?.agent?.[s]?.model||"auto",workspace:t,config:e,timeout:12e4}),c=(typeof o=="string"?o:o?.raw||JSON.stringify(o?.structured||o)).match(/\{[\s\S]*\}/);if(!c)throw new Error("Agent did not return valid JSON");return JSON.parse(c[0])}catch(n){return console.warn(`Agent code generation failed (${n.message}), using templates`),Xr(r)}}function Xr(r){let t={};for(let e of r.nodes){let s=Q(e.name),n=`${e.name.split("_").map(c=>c.charAt(0).toUpperCase()+c.slice(1)).join("")}OutputSchema`,i=e.outputFields?.length?e.outputFields.map(c=>` ${c}: z.string().describe('${c}'),`).join(`
606
+ IMPORTANT: Return ONLY valid JSON. No markdown fences, no explanation outside the JSON.`}async function zt(r,t){let e=await en(t),s=Xr(e);try{let{invokeAgent:n}=await import("@zibby/core"),i=sn(r),o=await n(i,{state:{agentType:s,config:e,cwd:t,workspace:t}},{model:e?.agent?.[s]?.model||"auto",workspace:t,config:e,timeout:12e4}),c=(typeof o=="string"?o:o?.raw||JSON.stringify(o?.structured||o)).match(/\{[\s\S]*\}/);if(!c)throw new Error("Agent did not return valid JSON");return JSON.parse(c[0])}catch(n){return console.warn(`Agent code generation failed (${n.message}), using templates`),rn(r)}}function rn(r){let t={};for(let e of r.nodes){let s=Q(e.name),n=`${e.name.split("_").map(c=>c.charAt(0).toUpperCase()+c.slice(1)).join("")}OutputSchema`,i=e.outputFields?.length?e.outputFields.map(c=>` ${c}: z.string().describe('${c}'),`).join(`
607
607
  `):` summary: z.string().describe('Summary of the result'),
608
608
  status: z.enum(['ok', 'warn', 'error']).describe('Overall status'),`,o=r.edges.filter(c=>c.to===e.name&&c.from!=="START").map(c=>`Previous step (${c.from}): \${JSON.stringify(state.${c.from} || {}, null, 2)}`).join(`
609
609
  `),a=o?`${e.description}
@@ -625,7 +625,7 @@ export const ${s} = {
625
625
  prompt: (state) => \`${a}\`,
626
626
  outputSchema: ${n},
627
627
  };
628
- `}}return{nodes:t}}function en(r,t,e,s){let n=t.toLowerCase(),i=Bt(n),o=S(r,".zibby","workflows",n),a=S(o,"nodes");Fr(a,{recursive:!0});let c=e.nodes.map(g=>g.name);for(let g of e.nodes){let _=s.nodes?.[g.name]?.code;_&&H(S(a,`${g.name.replace(/_/g,"-")}.mjs`),_,"utf-8")}let l=c.map(g=>{let _=Q(g),d=g.replace(/_/g,"-");return`export { ${_} } from './${d}.mjs';`});H(S(a,"index.mjs"),`${l.join(`
628
+ `}}return{nodes:t}}function nn(r,t,e,s){let n=t.toLowerCase(),i=Bt(n),o=S(r,".zibby","workflows",n),a=S(o,"nodes");Hr(a,{recursive:!0});let c=e.nodes.map(g=>g.name);for(let g of e.nodes){let _=s.nodes?.[g.name]?.code;_&&H(S(a,`${g.name.replace(/_/g,"-")}.mjs`),_,"utf-8")}let l=c.map(g=>{let _=Q(g),d=g.replace(/_/g,"-");return`export { ${_} } from './${d}.mjs';`});H(S(a,"index.mjs"),`${l.join(`
629
629
  `)}
630
630
  `,"utf-8");let u=c[0],p=c.map(g=>Q(g)).join(", "),y=c.map(g=>` graph.addNode('${g}', ${Q(g)});`).join(`
631
631
  `),m=e.edges.map(g=>g.condition?` graph.addConditionalEdges('${g.from}', (state) => {
@@ -651,5 +651,5 @@ ${m}
651
651
  }
652
652
  }
653
653
  `;H(S(o,"graph.mjs"),f,"utf-8");let k={name:n,description:e.description||`${i} workflow`,entryClass:i,triggers:{api:!0}};H(S(o,"workflow.json"),`${JSON.stringify(k,null,2)}
654
- `,"utf-8");let h=["graph.mjs","workflow.json","nodes/index.mjs",...c.map(g=>`nodes/${g.replace(/_/g,"-")}.mjs`)];return{workflowDir:qt(r,o),files:h,className:i,slug:n}}async function tn(r){let{name:t,description:e,nodes:s,edges:n}=r;if(!t||!Kt.test(t.toLowerCase()))return JSON.stringify({error:`Invalid workflow name "${t}". Must be kebab-case, 2-64 chars, lowercase letters/numbers/hyphens.`});if(!s||s.length===0)return JSON.stringify({error:"At least one node is required."});let i={name:t.toLowerCase(),description:e||`${Bt(t.toLowerCase())} workflow`,nodes:s.map(o=>({name:o.name.replace(/-/g,"_"),description:o.description||`Process ${o.name}`,inputFields:o.inputFields||[],outputFields:o.outputFields||[]})),edges:n||[]};if(i.edges.length===0&&i.nodes.length>0){for(let o=0;o<i.nodes.length-1;o++)i.edges.push({from:i.nodes[o].name,to:i.nodes[o+1].name});i.edges.push({from:i.nodes[i.nodes.length-1].name,to:"END"})}return JSON.stringify({ok:!0,spec:i,message:`Workflow "${i.name}" designed with ${i.nodes.length} node(s). Call build_workflow to generate the code.`,preview:{nodes:i.nodes.map(o=>o.name),flow:i.edges.map(o=>o.condition?`${o.from} \u2192(if ${o.condition})\u2192 ${o.to}`:`${o.from} \u2192 ${o.to}`)}})}async function sn(r,t){let{name:e,spec:s}=r,n=(e||s?.name||"").toLowerCase();if(!n||!Kt.test(n))return JSON.stringify({error:`Invalid workflow name "${n}".`});if(!s||!s.nodes||s.nodes.length===0)return JSON.stringify({error:"spec with nodes is required. Call design_workflow first."});let i=S(t,".zibby","workflows",n);if(M(i))return JSON.stringify({error:`Workflow "${n}" already exists at .zibby/workflows/${n}/. Delete it first or choose a different name.`});let o=await zt(s,t),a=en(t,n,s,o);return JSON.stringify({ok:!0,...a,message:`Workflow "${n}" created at ${a.workflowDir}/`,nextSteps:[`Test locally: zibby start ${n}`,`Deploy to cloud: zibby deploy ${n} --project <project-id>`,`Tail logs: zibby logs --workflow ${n} --project <project-id>`]})}async function rn(r,t){let{workflowName:e,nodeName:s,description:n,inputFields:i,outputFields:o}=r,a=(e||"").toLowerCase(),c=(s||"").replace(/-/g,"_"),l=S(t,".zibby","workflows",a);if(!M(l))return JSON.stringify({error:`Workflow "${a}" not found. Create it first with build_workflow.`});let u={name:a,description:"",nodes:[{name:c,description:n||`Process ${c}`,inputFields:i||[],outputFields:o||[]}],edges:[]},y=(await zt(u,t)).nodes?.[c]?.code;if(!y)return JSON.stringify({error:"Failed to generate node code."});let m=S(l,"nodes"),f=`${c.replace(/_/g,"-")}.mjs`;H(S(m,f),y,"utf-8");let k=S(m,"index.mjs"),h=Q(c),g=`export { ${h} } from './${c.replace(/_/g,"-")}.mjs';
655
- `,_=M(k)?X(k,"utf-8"):"";return _.includes(h)||H(k,_+g,"utf-8"),JSON.stringify({ok:!0,file:`nodes/${f}`,exportName:h,message:`Node "${c}" added. Update graph.mjs to wire it into the graph.`})}async function nn(r,t){let{name:e,projectId:s}=r,n=(e||"").toLowerCase();if(!n)return JSON.stringify({error:"Workflow name is required."});if(!s)return JSON.stringify({error:"projectId is required."});let i=S(t,".zibby","workflows",n);if(!M(i))return JSON.stringify({error:`Workflow "${n}" not found at .zibby/workflows/${n}/`});try{let{execSync:o}=await import("child_process"),a=o(`node "${S(t,"packages/cli/bin/zibby.js")}" deploy ${n} --project ${s}`,{cwd:t,encoding:"utf-8",timeout:3e4,stdio:["pipe","pipe","pipe"]});return JSON.stringify({ok:!0,output:a.trim()})}catch{try{let{execSync:a}=await import("child_process"),c=a(`npx zibby deploy ${n} --project ${s}`,{cwd:t,encoding:"utf-8",timeout:3e4,stdio:["pipe","pipe","pipe"]});return JSON.stringify({ok:!0,output:c.trim()})}catch(a){return JSON.stringify({error:`Deploy failed: ${a.message}`})}}}function on(r){let t=S(r,".zibby","workflows");if(!M(t))return JSON.stringify({workflows:[],message:"No workflows found. Use build_workflow to create one."});let s=Ae(t).filter(n=>{try{return Pt(S(t,n)).isDirectory()}catch{return!1}}).map(n=>{let i=S(t,n,"workflow.json"),o={};try{o=JSON.parse(X(i,"utf-8"))}catch{}let a=S(t,n,"nodes"),c=0;try{c=Ae(a).filter(l=>l.endsWith(".mjs")&&l!=="index.mjs").length}catch{}return{name:n,description:o.description||"",nodeCount:c,path:qt(r,S(t,n))}});return JSON.stringify({workflows:s})}var Gt={id:"workflow-builder",description:"Build, scaffold, and deploy custom AI workflows via conversation",envKeys:[],promptFragment:Hr,tools:[{name:"design_workflow",description:"Design a workflow spec (nodes, edges, descriptions) for the user to review before building. Call this after understanding requirements.",input_schema:{type:"object",properties:{name:{type:"string",description:"Workflow name in kebab-case (e.g., ticket-triage)"},description:{type:"string",description:"What the workflow does"},nodes:{type:"array",items:{type:"object",properties:{name:{type:"string",description:"Node name in snake_case (e.g., classify_ticket)"},description:{type:"string",description:"What this node does \u2014 be specific about input/output"},inputFields:{type:"array",items:{type:"string"},description:"Key fields this node reads from state"},outputFields:{type:"array",items:{type:"string"},description:"Key fields this node produces"}},required:["name","description"]},description:"Workflow nodes (processing steps)"},edges:{type:"array",items:{type:"object",properties:{from:{type:"string",description:"Source node name"},to:{type:"string",description:'Target node name (or "END")'},condition:{type:"string",description:"JS expression for conditional routing (optional)"}},required:["from","to"]},description:"Edges connecting nodes. If omitted, nodes are wired linearly."}},required:["name","description","nodes"]}},{name:"build_workflow",description:"Generate real workflow code on disk from a design spec. Uses the configured AI agent for high-quality code generation.",input_schema:{type:"object",properties:{name:{type:"string",description:"Workflow name (from design_workflow)"},spec:{type:"object",description:"The full spec object returned by design_workflow",properties:{name:{type:"string"},description:{type:"string"},nodes:{type:"array",items:{type:"object"}},edges:{type:"array",items:{type:"object"}}}}},required:["name","spec"]}},{name:"add_node",description:"Add a new node to an existing workflow. Generates the node file and updates the barrel export.",input_schema:{type:"object",properties:{workflowName:{type:"string",description:"Existing workflow name (kebab-case)"},nodeName:{type:"string",description:"New node name (snake_case)"},description:{type:"string",description:"What this node does"},inputFields:{type:"array",items:{type:"string"},description:"Fields read from state"},outputFields:{type:"array",items:{type:"string"},description:"Fields produced"}},required:["workflowName","nodeName","description"]}},{name:"deploy_workflow",description:"Deploy a workflow to Zibby Cloud. Returns the trigger URL.",input_schema:{type:"object",properties:{name:{type:"string",description:"Workflow name to deploy"},projectId:{type:"string",description:"Target project ID"}},required:["name","projectId"]}},{name:"list_workflows",description:"List all local workflows in .zibby/workflows/.",input_schema:{type:"object",properties:{}}},{name:"explore_framework_docs",description:"Read Zibby framework documentation on demand. Call this before building complex workflows or when you need details on advanced patterns (middleware, conditional routing, skills, deployment, CLI commands).",input_schema:{type:"object",properties:{topic:{type:"string",description:'Doc topic to read (e.g., "workflow", "custom-workflows", "cli-reference", "packages/core", "packages/skills", "integrations/jira"). Call with no topic to list all available docs.'}}}}],async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"design_workflow":return await tn(t);case"build_workflow":return await sn(t,s);case"add_node":return await rn(t,s);case"deploy_workflow":return await nn(t,s);case"list_workflows":return on(s);case"explore_framework_docs":{let n=(t.topic||"").trim();if(!n){let o=Mt();return JSON.stringify({available:o,hint:"Call again with a topic to read its content."})}let i=Wt(n);if(!i){let o=Mt();return JSON.stringify({error:`Doc "${n}" not found.`,available:o})}return JSON.stringify({topic:n,content:i})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.message})}},resolve(){return null}};import{createRequire as an}from"module";import{fileURLToPath as cn}from"url";import{registerHandlers as ln}from"@zibby/core/function-skill-registry.js";import{registerSkill as un}from"@zibby/agent-workflow";var pn=an(import.meta.url);function dn(){try{return pn.resolve("@zibby/core/function-bridge.js")}catch{return null}}var mn=import.meta.url;function fn(){let r=Error.prepareStackTrace;try{Error.prepareStackTrace=(s,n)=>n;let e=new Error().stack;for(let s=2;s<e.length;s++){let n=e[s].getFileName();if(n&&n!==mn&&!n.startsWith("node:"))return n.startsWith("file://")?cn(n):n}return null}finally{Error.prepareStackTrace=r}}function yn(r){if(!r||typeof r!="object")return{type:"object",properties:{},required:[]};let t={},e=[];for(let[s,n]of Object.entries(r))if(typeof n=="string")t[s]={type:n},e.push(s);else{let{required:i,...o}=n;t[s]=o,i!==!1&&e.push(s)}return{type:"object",properties:t,required:e}}function gn(r,t,e){if(typeof e.handler!="function")throw new Error(`Skill "${r}" must have a handler function`);let s={[r]:e.handler},n=[{name:r,description:e.description||"",input_schema:yn(e.input)}];return ln(r,s,n),{id:r,type:"function",serverName:r,allowedTools:[`mcp__${r}__*`],description:e.description||`Function skill: ${r}`,envKeys:[],tools:n,resolve(){let i=dn();return i?{command:"node",args:[i,t,r]}:null}}}function hn(r,t){return{id:r,type:"mcp",serverName:t.serverName||r,allowedTools:t.allowedTools||[`mcp__${t.serverName||r}__*`],description:t.description||`MCP skill: ${r}`,envKeys:t.envKeys||[],tools:t.tools||[],resolve:t.resolve,...t.cursorKey&&{cursorKey:t.cursorKey},...t.sessionEnvKey&&{sessionEnvKey:t.sessionEnvKey}}}function Ht(r,t){let e;if("handler"in t){if(typeof t.handler!="function")throw new Error(`Skill "${r}" must have a handler function`);let s=fn();if(!s)throw new Error(`Could not resolve caller file for skill "${r}".`);e=gn(r,s,t)}else if(typeof t.resolve=="function")e=hn(r,t);else throw new Error(`Skill "${r}" must have either a handler (function skill) or resolve (MCP skill).`);return un(e),e}var _n=Ht;import{registerSkill as qi,getSkill as Ui,hasSkill as Ki,getAllSkills as Bi,listSkillIds as Fi}from"@zibby/agent-workflow";T(xe);T(De);T(Pe);T(he);T(Ue);T(ne);T(Be);T(mt);T(_t);T(We);T(Ze);T(xt);T(Gt);T({...he,id:"slack_notify"});var Ji={BROWSER:"browser",JIRA:"jira",GITHUB:"github",GIT:"git",SLACK:"slack",LARK:"lark",SENTRY:"sentry",MEMORY:"memory",RUNNER:"runner",SKILL_INSTALLER:"skill-installer",CORE_TOOLS:"core-tools",CHAT_MEMORY:"chat-memory",WORKFLOW_BUILDER:"workflow-builder"};export{Ji as SKILLS,xe as browserSkill,xt as chatMemorySkill,Ze as coreToolsSkill,_n as functionSkill,Bi as getAllSkills,Ui as getSkill,_t as gitSkill,Pe as githubSkill,Ki as hasSkill,De as jiraSkill,Ue as larkSkill,Fi as listSkillIds,Be as memorySkill,qi as registerSkill,mt as runnerSkill,ne as sentrySkill,Ht as skill,We as skillInstallerSkill,he as slackSkill,mt as testRunnerSkill,Gt as workflowBuilderSkill};
654
+ `,"utf-8");let h=["graph.mjs","workflow.json","nodes/index.mjs",...c.map(g=>`nodes/${g.replace(/_/g,"-")}.mjs`)];return{workflowDir:Ut(r,o),files:h,className:i,slug:n}}async function on(r){let{name:t,description:e,nodes:s,edges:n}=r;if(!t||!Kt.test(t.toLowerCase()))return JSON.stringify({error:`Invalid workflow name "${t}". Must be kebab-case, 2-64 chars, lowercase letters/numbers/hyphens.`});if(!s||s.length===0)return JSON.stringify({error:"At least one node is required."});let i={name:t.toLowerCase(),description:e||`${Bt(t.toLowerCase())} workflow`,nodes:s.map(o=>({name:o.name.replace(/-/g,"_"),description:o.description||`Process ${o.name}`,inputFields:o.inputFields||[],outputFields:o.outputFields||[]})),edges:n||[]};if(i.edges.length===0&&i.nodes.length>0){for(let o=0;o<i.nodes.length-1;o++)i.edges.push({from:i.nodes[o].name,to:i.nodes[o+1].name});i.edges.push({from:i.nodes[i.nodes.length-1].name,to:"END"})}return JSON.stringify({ok:!0,spec:i,message:`Workflow "${i.name}" designed with ${i.nodes.length} node(s). Call build_workflow to generate the code.`,preview:{nodes:i.nodes.map(o=>o.name),flow:i.edges.map(o=>o.condition?`${o.from} \u2192(if ${o.condition})\u2192 ${o.to}`:`${o.from} \u2192 ${o.to}`)}})}async function an(r,t){let{name:e,spec:s}=r,n=(e||s?.name||"").toLowerCase();if(!n||!Kt.test(n))return JSON.stringify({error:`Invalid workflow name "${n}".`});if(!s||!s.nodes||s.nodes.length===0)return JSON.stringify({error:"spec with nodes is required. Call design_workflow first."});let i=S(t,".zibby","workflows",n);if(M(i))return JSON.stringify({error:`Workflow "${n}" already exists at .zibby/workflows/${n}/. Delete it first or choose a different name.`});let o=await zt(s,t),a=nn(t,n,s,o);return JSON.stringify({ok:!0,...a,message:`Workflow "${n}" created at ${a.workflowDir}/`,nextSteps:[`Test locally: zibby start ${n}`,`Deploy to cloud: zibby deploy ${n} --project <project-id>`,`Tail logs: zibby logs --workflow ${n} --project <project-id>`]})}async function cn(r,t){let{workflowName:e,nodeName:s,description:n,inputFields:i,outputFields:o}=r,a=(e||"").toLowerCase(),c=(s||"").replace(/-/g,"_"),l=S(t,".zibby","workflows",a);if(!M(l))return JSON.stringify({error:`Workflow "${a}" not found. Create it first with build_workflow.`});let u={name:a,description:"",nodes:[{name:c,description:n||`Process ${c}`,inputFields:i||[],outputFields:o||[]}],edges:[]},y=(await zt(u,t)).nodes?.[c]?.code;if(!y)return JSON.stringify({error:"Failed to generate node code."});let m=S(l,"nodes"),f=`${c.replace(/_/g,"-")}.mjs`;H(S(m,f),y,"utf-8");let k=S(m,"index.mjs"),h=Q(c),g=`export { ${h} } from './${c.replace(/_/g,"-")}.mjs';
655
+ `,_=M(k)?X(k,"utf-8"):"";return _.includes(h)||H(k,_+g,"utf-8"),JSON.stringify({ok:!0,file:`nodes/${f}`,exportName:h,message:`Node "${c}" added. Update graph.mjs to wire it into the graph.`})}async function ln(r,t){let{name:e,projectId:s}=r,n=(e||"").toLowerCase();if(!n)return JSON.stringify({error:"Workflow name is required."});if(!s)return JSON.stringify({error:"projectId is required."});let i=S(t,".zibby","workflows",n);if(!M(i))return JSON.stringify({error:`Workflow "${n}" not found at .zibby/workflows/${n}/`});try{let{execSync:o}=await import("child_process"),a=o(`node "${S(t,"packages/cli/bin/zibby.js")}" deploy ${n} --project ${s}`,{cwd:t,encoding:"utf-8",timeout:3e4,stdio:["pipe","pipe","pipe"]});return JSON.stringify({ok:!0,output:a.trim()})}catch{try{let{execSync:a}=await import("child_process"),c=a(`npx zibby deploy ${n} --project ${s}`,{cwd:t,encoding:"utf-8",timeout:3e4,stdio:["pipe","pipe","pipe"]});return JSON.stringify({ok:!0,output:c.trim()})}catch(a){return JSON.stringify({error:`Deploy failed: ${a.message}`})}}}function un(r){let t=S(r,".zibby","workflows");if(!M(t))return JSON.stringify({workflows:[],message:"No workflows found. Use build_workflow to create one."});let s=Ae(t).filter(n=>{try{return Pt(S(t,n)).isDirectory()}catch{return!1}}).map(n=>{let i=S(t,n,"workflow.json"),o={};try{o=JSON.parse(X(i,"utf-8"))}catch{}let a=S(t,n,"nodes"),c=0;try{c=Ae(a).filter(l=>l.endsWith(".mjs")&&l!=="index.mjs").length}catch{}return{name:n,description:o.description||"",nodeCount:c,path:Ut(r,S(t,n))}});return JSON.stringify({workflows:s})}var Gt={id:"workflow-builder",description:"Build, scaffold, and deploy custom AI workflows via conversation",envKeys:[],promptFragment:Qr,tools:[{name:"design_workflow",description:"Design a workflow spec (nodes, edges, descriptions) for the user to review before building. Call this after understanding requirements.",input_schema:{type:"object",properties:{name:{type:"string",description:"Workflow name in kebab-case (e.g., ticket-triage)"},description:{type:"string",description:"What the workflow does"},nodes:{type:"array",items:{type:"object",properties:{name:{type:"string",description:"Node name in snake_case (e.g., classify_ticket)"},description:{type:"string",description:"What this node does \u2014 be specific about input/output"},inputFields:{type:"array",items:{type:"string"},description:"Key fields this node reads from state"},outputFields:{type:"array",items:{type:"string"},description:"Key fields this node produces"}},required:["name","description"]},description:"Workflow nodes (processing steps)"},edges:{type:"array",items:{type:"object",properties:{from:{type:"string",description:"Source node name"},to:{type:"string",description:'Target node name (or "END")'},condition:{type:"string",description:"JS expression for conditional routing (optional)"}},required:["from","to"]},description:"Edges connecting nodes. If omitted, nodes are wired linearly."}},required:["name","description","nodes"]}},{name:"build_workflow",description:"Generate real workflow code on disk from a design spec. Uses the configured AI agent for high-quality code generation.",input_schema:{type:"object",properties:{name:{type:"string",description:"Workflow name (from design_workflow)"},spec:{type:"object",description:"The full spec object returned by design_workflow",properties:{name:{type:"string"},description:{type:"string"},nodes:{type:"array",items:{type:"object"}},edges:{type:"array",items:{type:"object"}}}}},required:["name","spec"]}},{name:"add_node",description:"Add a new node to an existing workflow. Generates the node file and updates the barrel export.",input_schema:{type:"object",properties:{workflowName:{type:"string",description:"Existing workflow name (kebab-case)"},nodeName:{type:"string",description:"New node name (snake_case)"},description:{type:"string",description:"What this node does"},inputFields:{type:"array",items:{type:"string"},description:"Fields read from state"},outputFields:{type:"array",items:{type:"string"},description:"Fields produced"}},required:["workflowName","nodeName","description"]}},{name:"deploy_workflow",description:"Deploy a workflow to Zibby Cloud. Returns the trigger URL.",input_schema:{type:"object",properties:{name:{type:"string",description:"Workflow name to deploy"},projectId:{type:"string",description:"Target project ID"}},required:["name","projectId"]}},{name:"list_workflows",description:"List all local workflows in .zibby/workflows/.",input_schema:{type:"object",properties:{}}},{name:"explore_framework_docs",description:"Read Zibby framework documentation on demand. Call this before building complex workflows or when you need details on advanced patterns (middleware, conditional routing, skills, deployment, CLI commands).",input_schema:{type:"object",properties:{topic:{type:"string",description:'Doc topic to read (e.g., "workflow", "custom-workflows", "cli-reference", "packages/core", "packages/skills", "integrations/jira"). Call with no topic to list all available docs.'}}}}],async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"design_workflow":return await on(t);case"build_workflow":return await an(t,s);case"add_node":return await cn(t,s);case"deploy_workflow":return await ln(t,s);case"list_workflows":return un(s);case"explore_framework_docs":{let n=(t.topic||"").trim();if(!n){let o=Mt();return JSON.stringify({available:o,hint:"Call again with a topic to read its content."})}let i=Wt(n);if(!i){let o=Mt();return JSON.stringify({error:`Doc "${n}" not found.`,available:o})}return JSON.stringify({topic:n,content:i})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.message})}},resolve(){return null}};import{createRequire as pn}from"module";import{fileURLToPath as dn}from"url";import{registerHandlers as mn}from"@zibby/core/function-skill-registry.js";import{registerSkill as fn}from"@zibby/agent-workflow";var yn=pn(import.meta.url);function gn(){try{return yn.resolve("@zibby/core/function-bridge.js")}catch{return null}}var hn=import.meta.url;function _n(){let r=Error.prepareStackTrace;try{Error.prepareStackTrace=(s,n)=>n;let e=new Error().stack;for(let s=2;s<e.length;s++){let n=e[s].getFileName();if(n&&n!==hn&&!n.startsWith("node:"))return n.startsWith("file://")?dn(n):n}return null}finally{Error.prepareStackTrace=r}}function kn(r){if(!r||typeof r!="object")return{type:"object",properties:{},required:[]};let t={},e=[];for(let[s,n]of Object.entries(r))if(typeof n=="string")t[s]={type:n},e.push(s);else{let{required:i,...o}=n;t[s]=o,i!==!1&&e.push(s)}return{type:"object",properties:t,required:e}}function wn(r,t,e){if(typeof e.handler!="function")throw new Error(`Skill "${r}" must have a handler function`);let s={[r]:e.handler},n=[{name:r,description:e.description||"",input_schema:kn(e.input)}];return mn(r,s,n),{id:r,type:"function",serverName:r,allowedTools:[`mcp__${r}__*`],description:e.description||`Function skill: ${r}`,envKeys:[],tools:n,resolve(){let i=gn();return i?{command:"node",args:[i,t,r]}:null}}}function bn(r,t){return{id:r,type:"mcp",serverName:t.serverName||r,allowedTools:t.allowedTools||[`mcp__${t.serverName||r}__*`],description:t.description||`MCP skill: ${r}`,envKeys:t.envKeys||[],tools:t.tools||[],resolve:t.resolve,...t.cursorKey&&{cursorKey:t.cursorKey},...t.sessionEnvKey&&{sessionEnvKey:t.sessionEnvKey}}}function Ht(r,t){let e;if("handler"in t){if(typeof t.handler!="function")throw new Error(`Skill "${r}" must have a handler function`);let s=_n();if(!s)throw new Error(`Could not resolve caller file for skill "${r}".`);e=wn(r,s,t)}else if(typeof t.resolve=="function")e=bn(r,t);else throw new Error(`Skill "${r}" must have either a handler (function skill) or resolve (MCP skill).`);return fn(e),e}var Sn=Ht;import{registerSkill as Hi,getSkill as Yi,hasSkill as Zi,getAllSkills as Vi,listSkillIds as Qi}from"@zibby/agent-workflow";T(xe);T(De);T(Pe);T(he);T(qe);T(ne);T(Be);T(mt);T(_t);T(We);T(Ze);T(xt);T(Gt);T({...he,id:"slack_notify"});var Fi={BROWSER:"browser",JIRA:"jira",GITHUB:"github",GIT:"git",SLACK:"slack",LARK:"lark",SENTRY:"sentry",MEMORY:"memory",RUNNER:"runner",SKILL_INSTALLER:"skill-installer",CORE_TOOLS:"core-tools",CHAT_MEMORY:"chat-memory",WORKFLOW_BUILDER:"workflow-builder"};export{Fi as SKILLS,xe as browserSkill,xt as chatMemorySkill,Ze as coreToolsSkill,Sn as functionSkill,Vi as getAllSkills,Yi as getSkill,_t as gitSkill,Pe as githubSkill,Zi as hasSkill,De as jiraSkill,qe as larkSkill,Qi as listSkillIds,Be as memorySkill,Hi as registerSkill,mt as runnerSkill,ne as sentrySkill,Ht as skill,We as skillInstallerSkill,he as slackSkill,mt as testRunnerSkill,Gt as workflowBuilderSkill};
package/dist/lark.js CHANGED
@@ -1,7 +1,7 @@
1
- import{createRequire as p}from"module";import{resolveIntegrationToken as m}from"@zibby/core/backend-client.js";var l=p(import.meta.url);function u(){if(process.env.MCP_LARK_PATH)return process.env.MCP_LARK_PATH;try{return l.resolve("@zibby/skills/bin/mcp-lark.mjs")}catch{return null}}var h=6e3*1e3,a=null;async function g(){let{appId:e,appSecret:t,host:r}=await m("lark");if(a&&a.appId===e&&a.expiresAt>Date.now())return{token:a.token,host:r};let n=await(await fetch(`${r}/open-apis/auth/v3/tenant_access_token/internal`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({app_id:e,app_secret:t})})).json();if(n.code!==0)throw new Error(`Lark tenant_access_token failed: ${n.msg||n.code}`);return a={token:n.tenant_access_token,expiresAt:Date.now()+h,appId:e},{token:n.tenant_access_token,host:r}}async function c(e,t,r={}){let{token:i,host:n}=await g(),s=`${n}${t}`,_={method:e,headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json; charset=utf-8"}};e!=="GET"&&(_.body=JSON.stringify(r));let o=await(await fetch(s,_)).json();if(o.code!==0)throw new Error(`Lark API ${t} error: ${o.msg||o.code}`);return o.data||{}}function d(e){return JSON.stringify({text:e})}function y(e){return!e||typeof e!="string"||e.startsWith("oc_")?"chat_id":e.startsWith("ou_")?"open_id":e.startsWith("on_")?"union_id":e.startsWith("cli_")?"app_id":e.includes("@")?"email":"chat_id"}var T={id:"lark",serverName:"lark",allowedTools:["mcp__lark__*"],description:"Lark / Feishu messaging \u2014 send messages and reply in threads.",envKeys:[],promptFragment:`## Lark (connected)
1
+ import{existsSync as p}from"fs";import{fileURLToPath as m}from"url";import{dirname as l,resolve as h}from"path";import{resolveIntegrationToken as u}from"@zibby/core/backend-client.js";function g(){if(process.env.MCP_LARK_PATH)return process.env.MCP_LARK_PATH;let e=l(m(import.meta.url)),t=h(e,"..","bin","mcp-lark.mjs");return p(t)?t:null}var y=6e3*1e3,a=null;async function f(){let{appId:e,appSecret:t,host:s}=await u("lark");if(a&&a.appId===e&&a.expiresAt>Date.now())return{token:a.token,host:s};let n=await(await fetch(`${s}/open-apis/auth/v3/tenant_access_token/internal`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({app_id:e,app_secret:t})})).json();if(n.code!==0)throw new Error(`Lark tenant_access_token failed: ${n.msg||n.code}`);return a={token:n.tenant_access_token,expiresAt:Date.now()+y,appId:e},{token:n.tenant_access_token,host:s}}async function c(e,t,s={}){let{token:i,host:n}=await f(),r=`${n}${t}`,_={method:e,headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json; charset=utf-8"}};e!=="GET"&&(_.body=JSON.stringify(s));let o=await(await fetch(r,_)).json();if(o.code!==0)throw new Error(`Lark API ${t} error: ${o.msg||o.code}`);return o.data||{}}function d(e){return JSON.stringify({text:e})}function k(e){return!e||typeof e!="string"||e.startsWith("oc_")?"chat_id":e.startsWith("ou_")?"open_id":e.startsWith("on_")?"union_id":e.startsWith("cli_")?"app_id":e.includes("@")?"email":"chat_id"}var O={id:"lark",serverName:"lark",allowedTools:["mcp__lark__*"],description:"Lark / Feishu messaging \u2014 send messages and reply in threads.",envKeys:[],promptFragment:`## Lark (connected)
2
2
  You can send messages and replies on Lark. Use:
3
3
  - lark_send_message: post a message to a chat, user, or DM
4
4
  - lark_reply: reply to an existing message (threaded)
5
5
  - lark_list_chats: list chats the bot is a member of
6
6
  - lark_get_chat_history: fetch recent messages in a chat
7
- When responding to an incoming event, prefer lark_reply with the source message_id so the response threads cleanly.`,resolve(){let e=u();if(!e)return null;let t={};for(let r of["PROJECT_API_TOKEN","PROGRESS_API_URL","EXECUTION_ID","PROJECT_ID","STAGE"])process.env[r]&&(t[r]=process.env[r]);return{command:"node",args:[e],env:t}},tools:[{name:"lark_send_message",description:"Send a text message to a Lark chat, user, or DM. receive_id can be a chat_id (oc_*), open_id (ou_*), union_id (on_*), or email.",input_schema:{type:"object",properties:{receive_id:{type:"string",description:"Target id: chat_id (oc_*), open_id (ou_*), union_id (on_*), or email"},text:{type:"string",description:"Message text"}},required:["receive_id","text"]}},{name:"lark_reply",description:"Reply to an existing Lark message (creates a thread). Use the message_id from the inbound event.",input_schema:{type:"object",properties:{message_id:{type:"string",description:"Lark message id (om_*) to reply to"},text:{type:"string",description:"Reply text"}},required:["message_id","text"]}},{name:"lark_list_chats",description:"List chats (groups + DMs) the bot is a member of.",input_schema:{type:"object",properties:{page_size:{type:"number",description:"Max results (default 50)"}}}},{name:"lark_get_chat_history",description:"Fetch recent messages in a chat.",input_schema:{type:"object",properties:{chat_id:{type:"string",description:"Chat id (oc_*)"},page_size:{type:"number",description:"Max messages (default 20)"}},required:["chat_id"]}}],async handleToolCall(e,t){try{switch(e){case"lark_send_message":{if(!t.receive_id||!t.text)return JSON.stringify({error:"receive_id and text are required"});let r=y(t.receive_id),i=await c("POST",`/open-apis/im/v1/messages?receive_id_type=${r}`,{receive_id:t.receive_id,msg_type:"text",content:d(t.text)});return JSON.stringify({ok:!0,message_id:i.message_id})}case"lark_reply":{if(!t.message_id||!t.text)return JSON.stringify({error:"message_id and text are required"});let r=await c("POST",`/open-apis/im/v1/messages/${encodeURIComponent(t.message_id)}/reply`,{msg_type:"text",content:d(t.text)});return JSON.stringify({ok:!0,message_id:r.message_id})}case"lark_list_chats":{let r=t.page_size||50,n=((await c("GET",`/open-apis/im/v1/chats?page_size=${r}`)).items||[]).map(s=>({chat_id:s.chat_id,name:s.name,description:s.description,owner_id:s.owner_id,chat_mode:s.chat_mode}));return JSON.stringify({chats:n})}case"lark_get_chat_history":{if(!t.chat_id)return JSON.stringify({error:"chat_id is required"});let r=t.page_size||20,n=((await c("GET",`/open-apis/im/v1/messages?container_id_type=chat&container_id=${encodeURIComponent(t.chat_id)}&page_size=${r}&sort_type=ByCreateTimeDesc`)).items||[]).map(s=>({message_id:s.message_id,sender_id:s.sender?.id,sender_type:s.sender?.sender_type,msg_type:s.msg_type,content:s.body?.content,create_time:s.create_time}));return JSON.stringify({messages:n})}default:return JSON.stringify({error:`Unknown tool: ${e}`})}}catch(r){return JSON.stringify({error:r.message})}}};function x(){a=null}export{x as _resetLarkTokenCache,T as larkSkill};
7
+ When responding to an incoming event, prefer lark_reply with the source message_id so the response threads cleanly.`,resolve(){let e=g();if(!e)return null;let t={};for(let s of["PROJECT_API_TOKEN","PROGRESS_API_URL","EXECUTION_ID","PROJECT_ID","STAGE"])process.env[s]&&(t[s]=process.env[s]);return{type:"stdio",command:"node",args:[e],env:t,alwaysLoad:!0}},tools:[{name:"lark_send_message",description:"Send a text message to a Lark chat, user, or DM. receive_id can be a chat_id (oc_*), open_id (ou_*), union_id (on_*), or email.",input_schema:{type:"object",properties:{receive_id:{type:"string",description:"Target id: chat_id (oc_*), open_id (ou_*), union_id (on_*), or email"},text:{type:"string",description:"Message text"}},required:["receive_id","text"]}},{name:"lark_reply",description:"Reply to an existing Lark message (creates a thread). Use the message_id from the inbound event.",input_schema:{type:"object",properties:{message_id:{type:"string",description:"Lark message id (om_*) to reply to"},text:{type:"string",description:"Reply text"}},required:["message_id","text"]}},{name:"lark_list_chats",description:"List chats (groups + DMs) the bot is a member of.",input_schema:{type:"object",properties:{page_size:{type:"number",description:"Max results (default 50)"}}}},{name:"lark_get_chat_history",description:"Fetch recent messages in a chat.",input_schema:{type:"object",properties:{chat_id:{type:"string",description:"Chat id (oc_*)"},page_size:{type:"number",description:"Max messages (default 20)"}},required:["chat_id"]}}],async handleToolCall(e,t){try{switch(e){case"lark_send_message":{if(!t.receive_id||!t.text)return JSON.stringify({error:"receive_id and text are required"});let s=k(t.receive_id),i=await c("POST",`/open-apis/im/v1/messages?receive_id_type=${s}`,{receive_id:t.receive_id,msg_type:"text",content:d(t.text)});return JSON.stringify({ok:!0,message_id:i.message_id})}case"lark_reply":{if(!t.message_id||!t.text)return JSON.stringify({error:"message_id and text are required"});let s=await c("POST",`/open-apis/im/v1/messages/${encodeURIComponent(t.message_id)}/reply`,{msg_type:"text",content:d(t.text)});return JSON.stringify({ok:!0,message_id:s.message_id})}case"lark_list_chats":{let s=t.page_size||50,n=((await c("GET",`/open-apis/im/v1/chats?page_size=${s}`)).items||[]).map(r=>({chat_id:r.chat_id,name:r.name,description:r.description,owner_id:r.owner_id,chat_mode:r.chat_mode}));return JSON.stringify({chats:n})}case"lark_get_chat_history":{if(!t.chat_id)return JSON.stringify({error:"chat_id is required"});let s=t.page_size||20,n=((await c("GET",`/open-apis/im/v1/messages?container_id_type=chat&container_id=${encodeURIComponent(t.chat_id)}&page_size=${s}&sort_type=ByCreateTimeDesc`)).items||[]).map(r=>({message_id:r.message_id,sender_id:r.sender?.id,sender_type:r.sender?.sender_type,msg_type:r.msg_type,content:r.body?.content,create_time:r.create_time}));return JSON.stringify({messages:n})}default:return JSON.stringify({error:`Unknown tool: ${e}`})}}catch(s){return JSON.stringify({error:s.message})}}};function b(){a=null}export{b as _resetLarkTokenCache,O as larkSkill};
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/skills",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "description": "Built-in skill definitions for Zibby test automation framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/dist/sentry.js CHANGED
@@ -1,5 +1,5 @@
1
- import{createRequire as l}from"module";import{resolveIntegrationToken as p}from"@zibby/core/backend-client.js";var y=l(import.meta.url);function d(){if(process.env.MCP_SENTRY_PATH)return process.env.MCP_SENTRY_PATH;try{return y.resolve("@zibby/skills/bin/mcp-sentry.mjs")}catch{return null}}async function c(o,s={}){let{token:t,organizationSlug:r}=await p("sentry"),i=`https://sentry.io/api/0/organizations/${r}${o}`,e=await fetch(i,{method:s.method||"GET",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!e.ok){let a=await e.text().catch(()=>"");throw new Error(`Sentry API ${e.status}: ${a.slice(0,300)}`)}return e.json()}var u={id:"sentry",serverName:"sentry",allowedTools:["mcp__sentry__*"],description:"Sentry error tracking \u2014 projects, issues, events",envKeys:[],tools:[],promptFragment:`## Sentry (connected)
1
+ import{existsSync as l}from"fs";import{fileURLToPath as y}from"url";import{dirname as d,resolve as m}from"path";import{resolveIntegrationToken as p}from"@zibby/core/backend-client.js";function f(){if(process.env.MCP_SENTRY_PATH)return process.env.MCP_SENTRY_PATH;let r=d(y(import.meta.url)),s=m(r,"..","bin","mcp-sentry.mjs");return l(s)?s:null}async function c(r,s={}){let{token:t,organizationSlug:n}=await p("sentry"),i=`https://sentry.io/api/0/organizations/${n}${r}`,e=await fetch(i,{method:s.method||"GET",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!e.ok){let a=await e.text().catch(()=>"");throw new Error(`Sentry API ${e.status}: ${a.slice(0,300)}`)}return e.json()}var u={id:"sentry",serverName:"sentry",allowedTools:["mcp__sentry__*"],description:"Sentry error tracking \u2014 projects, issues, events",envKeys:[],tools:[],promptFragment:`## Sentry (connected)
2
2
  You have access to the user's Sentry. Use these tools:
3
3
  - sentry_list_projects: List projects in the organization
4
4
  - sentry_list_issues: List errors/issues (supports Sentry search query, project filter, sort)
5
- - sentry_get_issue: Get detailed info about a specific issue (requires issueId)`,resolve(){let o=d();if(!o)return null;let s={};for(let t of["PROJECT_API_TOKEN","PROGRESS_API_URL","EXECUTION_ID","PROJECT_ID","STAGE"])process.env[t]&&(s[t]=process.env[t]);return{command:"node",args:[o],env:s}},async handleToolCall(o,s={}){try{switch(o){case"sentry_list_projects":{let t=await c("/projects/?per_page=50");return JSON.stringify({projects:t.map(r=>({slug:r.slug,name:r.name,platform:r.platform}))})}case"sentry_list_issues":{let t=s.project||"",r=s.query||"is:unresolved",i=s.sort||"date",e=`/issues/?query=${encodeURIComponent(r)}&sort=${i}&per_page=${s.limit||25}`;t&&(e+=`&project=${encodeURIComponent(t)}`);let a=await c(e);return JSON.stringify({issues:a.map(n=>({id:n.id,title:n.title,culprit:n.culprit,count:n.count,firstSeen:n.firstSeen,lastSeen:n.lastSeen,level:n.level,status:n.status}))})}case"sentry_get_issue":{let{issueId:t}=s;if(!t)return JSON.stringify({error:"issueId is required"});let{token:r}=await p("sentry"),i=await fetch(`https://sentry.io/api/0/issues/${t}/`,{headers:{Authorization:`Bearer ${r}`}});if(!i.ok)throw new Error(`Sentry API ${i.status}`);let e=await i.json();return JSON.stringify({id:e.id,title:e.title,culprit:e.culprit,metadata:e.metadata,count:e.count,userCount:e.userCount,firstSeen:e.firstSeen,lastSeen:e.lastSeen,level:e.level,status:e.status,project:{slug:e.project?.slug,name:e.project?.name}})}default:return JSON.stringify({error:`Unknown tool: ${o}`})}}catch(t){return JSON.stringify({error:t.message})}},toolsForAssistant:[{name:"sentry_list_projects",description:"List Sentry projects",input_schema:{type:"object",properties:{}}},{name:"sentry_list_issues",description:"List Sentry issues (errors)",input_schema:{type:"object",properties:{project:{type:"string",description:"Project slug (optional)"},query:{type:"string",description:"Sentry search query (default: is:unresolved)"},sort:{type:"string",description:"Sort order: date, new, priority, freq, user (default: date)"},limit:{type:"number",description:"Max issues to return (default 25)"}}}},{name:"sentry_get_issue",description:"Get details of a specific Sentry issue",input_schema:{type:"object",properties:{issueId:{type:"string",description:"Sentry issue ID"}},required:["issueId"]}}]};u.tools=u.toolsForAssistant;export{u as sentrySkill};
5
+ - sentry_get_issue: Get detailed info about a specific issue (requires issueId)`,resolve(){let r=f();if(!r)return null;let s={};for(let t of["PROJECT_API_TOKEN","PROGRESS_API_URL","EXECUTION_ID","PROJECT_ID","STAGE"])process.env[t]&&(s[t]=process.env[t]);return{type:"stdio",command:"node",args:[r],env:s,alwaysLoad:!0}},async handleToolCall(r,s={}){try{switch(r){case"sentry_list_projects":{let t=await c("/projects/?per_page=50");return JSON.stringify({projects:t.map(n=>({slug:n.slug,name:n.name,platform:n.platform}))})}case"sentry_list_issues":{let t=s.project||"",n=s.query||"is:unresolved",i=s.sort||"date",e=`/issues/?query=${encodeURIComponent(n)}&sort=${i}&per_page=${s.limit||25}`;t&&(e+=`&project=${encodeURIComponent(t)}`);let a=await c(e);return JSON.stringify({issues:a.map(o=>({id:o.id,title:o.title,culprit:o.culprit,count:o.count,firstSeen:o.firstSeen,lastSeen:o.lastSeen,level:o.level,status:o.status}))})}case"sentry_get_issue":{let{issueId:t}=s;if(!t)return JSON.stringify({error:"issueId is required"});let{token:n}=await p("sentry"),i=await fetch(`https://sentry.io/api/0/issues/${t}/`,{headers:{Authorization:`Bearer ${n}`}});if(!i.ok)throw new Error(`Sentry API ${i.status}`);let e=await i.json();return JSON.stringify({id:e.id,title:e.title,culprit:e.culprit,metadata:e.metadata,count:e.count,userCount:e.userCount,firstSeen:e.firstSeen,lastSeen:e.lastSeen,level:e.level,status:e.status,project:{slug:e.project?.slug,name:e.project?.name}})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(t){return JSON.stringify({error:t.message})}},toolsForAssistant:[{name:"sentry_list_projects",description:"List Sentry projects",input_schema:{type:"object",properties:{}}},{name:"sentry_list_issues",description:"List Sentry issues (errors)",input_schema:{type:"object",properties:{project:{type:"string",description:"Project slug (optional)"},query:{type:"string",description:"Sentry search query (default: is:unresolved)"},sort:{type:"string",description:"Sort order: date, new, priority, freq, user (default: date)"},limit:{type:"number",description:"Max issues to return (default 25)"}}}},{name:"sentry_get_issue",description:"Get details of a specific Sentry issue",input_schema:{type:"object",properties:{issueId:{type:"string",description:"Sentry issue ID"}},required:["issueId"]}}]};u.tools=u.toolsForAssistant;export{u as sentrySkill};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/skills",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "description": "Built-in skill definitions for Zibby test automation framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",