@zibby/skills 0.1.16 → 0.1.17

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,7 +104,7 @@ 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 R(`/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 R(`/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 R(`/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 R(`/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 R(`/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 R(`/repos/${e}/${s}/pulls/${n}/comments?per_page=50`),o=await R(`/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 R(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 R(`/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 R(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 R("/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 R(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 R("/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 m=function(y){let _=y.replace(/^~(?=$|\/|\\)/,h);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:f}=await Le("github"),h=u(),k=n?m(n):o(h,"zibby-repos"),g=o(k,s);if(l(k,{recursive:!0}),c(g))return JSON.stringify({error:`Directory ${g} already exists. Remove it first or use a different destination.`,existingPath:g});try{let y=`https://x-access-token:${f}@github.com/${e}/${s}.git`;i(`git clone ${y} "${g}"`,{stdio:"pipe"});let _=p()==="win32",d;return _?d=i(`dir "${g}"`,{encoding:"utf-8",shell:"cmd.exe"}):d=i(`ls -la "${g}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:g,message:`Cloned ${e}/${s} to ${g}`,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(y){return JSON.stringify({error:`Clone failed: ${y.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 m=1,k=!0;for(;k&&l.length<c;){let d=`/installation/repositories?per_page=${a}&page=${m}`,j=(await R(d)).repositories||[];if(j.length===0)break;l=l.concat(j),k=j.length===a,m++}let g=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})),y=g.filter(d=>d.private).length,_=g.filter(d=>!d.private).length;return JSON.stringify({count:g.length,repos:g,privateCount:y,publicCount:_,message:`Found ${y} private and ${_} public repos`})}let u=await R(`/orgs/${e}`).then(()=>!0).catch(()=>!1),p=1,f=!0;for(;f&&l.length<c;){let m;u?m=`/orgs/${e}/repos?per_page=${a}&page=${p}&type=${s||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`:m=`/users/${e}/repos?per_page=${a}&page=${p}&type=${s||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`;let k=await R(m),g=Array.isArray(k)?k:[];if(g.length===0)break;l=l.concat(g),f=g.length===a,p++}let h=l.slice(0,c).map(m=>({name:m.name,fullName:m.full_name,private:m.private,description:m.description,language:m.language,defaultBranch:m.default_branch,updatedAt:m.updated_at,stars:m.stargazers_count,url:m.html_url}));return JSON.stringify({count:h.length,repos:h})}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 R(`/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 ds}from"@zibby/core/backend-client.js";async function q(r,t={}){let{token:e}=await ds("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 fe={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(y){return JSON.stringify({error:`Clone failed: ${y.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 m=1,k=!0;for(;k&&l.length<c;){let d=`/installation/repositories?per_page=${a}&page=${m}`,I=(await R(d)).repositories||[];if(I.length===0)break;l=l.concat(I),k=I.length===a,m++}let g=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})),y=g.filter(d=>d.private).length,_=g.filter(d=>!d.private).length;return JSON.stringify({count:g.length,repos:g,privateCount:y,publicCount:_,message:`Found ${y} private and ${_} public repos`})}let u=await R(`/orgs/${e}`).then(()=>!0).catch(()=>!1),p=1,f=!0;for(;f&&l.length<c;){let m;u?m=`/orgs/${e}/repos?per_page=${a}&page=${p}&type=${s||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`:m=`/users/${e}/repos?per_page=${a}&page=${p}&type=${s||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`;let k=await R(m),g=Array.isArray(k)?k:[];if(g.length===0)break;l=l.concat(g),f=g.length===a,p++}let h=l.slice(0,c).map(m=>({name:m.name,fullName:m.full_name,private:m.private,description:m.description,language:m.language,defaultBranch:m.default_branch,updatedAt:m.updated_at,stars:m.stargazers_count,url:m.html_url}));return JSON.stringify({count:h.length,repos:h})}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 R(`/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 ds}from"@zibby/core/backend-client.js";async function q(r,t={}){let{token:e}=await ds("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 fe={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
@@ -144,12 +144,12 @@ AFTER completing the test, you MUST call memory_save_insight at least once:
144
144
  1. Go to Settings \u2192 Integrations (https://studio.zibby.dev/integrations)
145
145
  2. Click "Connect Sentry" and authorize
146
146
  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 vs(){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: ${ye()}`),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(`
147
- `)}function Ns(){if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let r=bs(ws(),".zibby","config.json");return _s(r)&&JSON.parse(ks(r,"utf-8")).sessionToken||null}catch{return null}}function Os(){return(process.env.ZIBBY_API_URL||process.env.ZIBBY_PROD_API_URL||"https://api-prod.zibby.app").replace(/\/$/,"")}function ye(){return`${(process.env.ZIBBY_FRONTEND_URL||process.env.ZIBBY_PROD_FRONTEND_URL||"https://studio.zibby.dev").replace(/\/$/,"")}/integrations`}function $s(r){try{let t=process.platform;return Ss(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 Rs(){let r=Ns();if(!r)return{checked:!1,statuses:null,reason:"no-session-token"};try{let t=await fetch(`${Os()}/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 Ue(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 qe={id:"skill-installer",description:"Live skill installation for chat sessions",envKeys:[],catalog:B,promptFragment:vs,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 Rs();if(r==="list_available_skills"){let i=Object.entries(B).map(([o,a])=>{let c=s.includes(o),l=Ue(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"),h=(p(i)?.tools||[]).map(m=>m.name);return JSON.stringify({ok:!0,alreadyInstalled:!0,skillId:i,description:u?.description,availableTools:h,integrationUrl:u?.integrationProvider?ye():void 0,hint:`${i} is already active. Tools available: ${h.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=Ue(n.statuses,o.integrationProvider),p=ye();if(n.checked&&u.connected===!1){let f=$s(p);return JSON.stringify({ok:!1,error:`${o.integrationProvider} is not connected for this Zibby account yet`,needsIntegration:!0,integrationUrl:p,openedBrowser:f,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 js,readdirSync as Is,statSync as Ke,writeFileSync as As,mkdirSync as Ts}from"fs";import{join as Be,resolve as Cs,relative as Es}from"path";import{execSync as Fe}from"child_process";var Pe=256*1024,xs=64*1024,We={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 Ls(t,s);case"write_file":return Js(t,s);case"list_directory":return Ds(t,s);case"run_command":return Ms(t,s);case"open_url":return Us(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 te(r,t){return Cs(t,r)}function Ls(r,t){let e=te(r.path,t),s=Ke(e);return s.size>Pe?JSON.stringify({error:`File too large (${(s.size/1024).toFixed(0)}KB). Max: ${Pe/1024}KB`}):js(e,"utf-8")}function Js(r,t){let e=te(r.path,t),s=Be(e,"..");return Ts(s,{recursive:!0}),As(e,r.content,"utf-8"),JSON.stringify({ok:!0,path:Es(t,e)})}function Ds(r,t){let e=te(r.path||".",t);return Is(e).map(n=>{try{return Ke(Be(e,n)).isDirectory()?`${n}/`:n}catch{return n}}).join(`
147
+ `)}function Ns(){if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let r=bs(ws(),".zibby","config.json");return _s(r)&&JSON.parse(ks(r,"utf-8")).sessionToken||null}catch{return null}}function Os(){return(process.env.ZIBBY_API_URL||process.env.ZIBBY_PROD_API_URL||"https://api-prod.zibby.app").replace(/\/$/,"")}function ye(){return`${(process.env.ZIBBY_FRONTEND_URL||process.env.ZIBBY_PROD_FRONTEND_URL||"https://studio.zibby.dev").replace(/\/$/,"")}/integrations`}function $s(r){try{let t=process.platform;return Ss(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 Rs(){let r=Ns();if(!r)return{checked:!1,statuses:null,reason:"no-session-token"};try{let t=await fetch(`${Os()}/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 Ue(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 qe={id:"skill-installer",description:"Live skill installation for chat sessions",envKeys:[],catalog:B,promptFragment:vs,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 Rs();if(r==="list_available_skills"){let i=Object.entries(B).map(([o,a])=>{let c=s.includes(o),l=Ue(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"),h=(p(i)?.tools||[]).map(m=>m.name);return JSON.stringify({ok:!0,alreadyInstalled:!0,skillId:i,description:u?.description,availableTools:h,integrationUrl:u?.integrationProvider?ye():void 0,hint:`${i} is already active. Tools available: ${h.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=Ue(n.statuses,o.integrationProvider),p=ye();if(n.checked&&u.connected===!1){let f=$s(p);return JSON.stringify({ok:!1,error:`${o.integrationProvider} is not connected for this Zibby account yet`,needsIntegration:!0,integrationUrl:p,openedBrowser:f,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 Is,readdirSync as js,statSync as Ke,writeFileSync as As,mkdirSync as Ts}from"fs";import{join as Be,resolve as Cs,relative as Es}from"path";import{execSync as Fe}from"child_process";var Pe=256*1024,xs=64*1024,We={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 Ls(t,s);case"write_file":return Js(t,s);case"list_directory":return Ds(t,s);case"run_command":return Ms(t,s);case"open_url":return Us(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 te(r,t){return Cs(t,r)}function Ls(r,t){let e=te(r.path,t),s=Ke(e);return s.size>Pe?JSON.stringify({error:`File too large (${(s.size/1024).toFixed(0)}KB). Max: ${Pe/1024}KB`}):Is(e,"utf-8")}function Js(r,t){let e=te(r.path,t),s=Be(e,"..");return Ts(s,{recursive:!0}),As(e,r.content,"utf-8"),JSON.stringify({ok:!0,path:Es(t,e)})}function Ds(r,t){let e=te(r.path||".",t);return js(e).map(n=>{try{return Ke(Be(e,n)).isDirectory()?`${n}/`:n}catch{return n}}).join(`
148
148
  `)}function Ms(r,t){let e=r.cwd?te(r.cwd,t):t;return Fe(r.command,{cwd:e,encoding:"utf-8",timeout:3e4,maxBuffer:xs,stdio:["pipe","pipe","pipe"]})||"(no output)"}function Us(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 Fe(`${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{resolveIntegrationToken as Ge}from"@zibby/core/backend-client.js";async function ze(r,t={}){let{token:e,organizationSlug:s}=await Ge("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 He={id:"sentry",description:"Sentry error tracking \u2014 projects, issues, events",envKeys:[],promptFragment:`## Sentry (connected)
149
149
  You have access to the user's Sentry. Use these tools:
150
150
  - sentry_list_projects: List projects in the organization
151
151
  - sentry_list_issues: List errors/issues (supports query, project filter, sort)
152
- - sentry_get_issue: Get detailed info about a specific issue`,resolve(){return null},async handleToolCall(r,t){try{switch(r){case"sentry_list_projects":{let e=await ze("/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 ze(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 Ge("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})}},tools:[{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"]}}]};import{spawn as nt}from"child_process";import{writeFileSync as Ps,mkdirSync as Ye,existsSync as D,readdirSync as ie,readFileSync as ne,unlinkSync as Ks,createWriteStream as Bs,statSync as Fs}from"fs";import{resolve as F,join as L}from"path";import{resolveMaxParallelRuns as it}from"@zibby/core/utils/parallel-config.js";import{zibbyScratchSpecsDir as Ws}from"@zibby/core/constants/zibby-scratch.js";var _e="sessions",ke=".zibby/output",se=process.env.ZIBBY_RUNNER_NODE_PROGRESS==="1",zs=process.env.ZIBBY_RUNNER_STATUS_STREAM==="1",ot=process.env.ZIBBY_RUNNER_SPAWN_LOGS==="1",T=new Map,P=[],Gs=0,ge=0,Ze=3e3;function at(){return`run_${++Gs}_${Date.now().toString(36)}`}function Ve(r){let t=Math.floor(r/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function ct(r){return r.replace(/\x1b\[[0-9;]*[a-zA-Z]/g,"")}function I(r,t,e){if(!zs)return;let s=`
152
+ - sentry_get_issue: Get detailed info about a specific issue`,resolve(){return null},async handleToolCall(r,t){try{switch(r){case"sentry_list_projects":{let e=await ze("/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 ze(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 Ge("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})}},tools:[{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"]}}]};import{spawn as nt}from"child_process";import{writeFileSync as Ps,mkdirSync as Ye,existsSync as D,readdirSync as ie,readFileSync as ne,unlinkSync as Ks,createWriteStream as Bs,statSync as Fs}from"fs";import{resolve as F,join as L}from"path";import{resolveMaxParallelRuns as it}from"@zibby/core/utils/parallel-config.js";import{zibbyScratchSpecsDir as Ws}from"@zibby/core/constants/zibby-scratch.js";var _e="sessions",ke=".zibby/output",se=process.env.ZIBBY_RUNNER_NODE_PROGRESS==="1",zs=process.env.ZIBBY_RUNNER_STATUS_STREAM==="1",ot=process.env.ZIBBY_RUNNER_SPAWN_LOGS==="1",T=new Map,P=[],Gs=0,ge=0,Ze=3e3;function at(){return`run_${++Gs}_${Date.now().toString(36)}`}function Ve(r){let t=Math.floor(r/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function ct(r){return r.replace(/\x1b\[[0-9;]*[a-zA-Z]/g,"")}function j(r,t,e){if(!zs)return;let s=`
153
153
  ${t} [${r}] ${e}
154
154
  `;try{process.stderr.write(s)}catch{}}function we(){P.length=0;for(let[,r]of T)if(r.status==="queued"&&(r.status="cancelled"),r.status==="running"&&r._child)try{r._child.kill("SIGTERM")}catch{}}process.on("exit",we);process.on("SIGINT",()=>{we(),process.exit(0)});process.on("SIGTERM",()=>{we(),process.exit(0)});var lt={id:"runner",description:"Run zibby test workflows from chat (parallel supported)",envKeys:[],promptFragment:`## Test Runner
155
155
  You can run zibby test workflows directly from chat:
@@ -288,8 +288,8 @@ Each run generates:
288
288
  - events.json: All browser events
289
289
  - raw_stream_output.txt: Agent log
290
290
 
291
- 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 Hs(t,s);case"run_test":return await er(t,s,e);case"run_status":return tr(t);case"run_cancel":return sr(t);case"run_artifacts":return ir(t,s);case"run_diagnose":return or(t,s);case"list_specs":return ar(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 he(){let r=0;for(let[,t]of T)t.status==="running"&&r++;return r}function Qe(){for(;P.length>0;){let r=it(P[0]?.context?.options?.config);if(he()>=r)break;let{args:t,cwd:e,context:s}=P.shift();ut(t,e,s)}}async function Hs(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 f=e||"generate";return I(f,"\u{1F9EA}","Starting test spec generation (real agent with codebase access)..."),new Promise(h=>{ot&&console.error(`[zibby:spawn] skill=run_generate parentPid=${process.pid} \u2192 child zibby ${c.map(y=>/\s/.test(y)?JSON.stringify(y):y).join(" ")} cwd=${t}`);let m=nt("zibby",c,{cwd:t,env:{...process.env},stdio:["ignore","pipe","pipe"],detached:!1}),k="",g="";m.stdout.on("data",y=>{let _=y.toString();k+=_;for(let d of _.split(`
292
- `)){let b=ct(d).trim();b.startsWith("\u2705")?I(f,"\u2705",b.slice(2).trim()):b.startsWith("\u2713")&&I(f,"\u2714",b.slice(2).trim())}}),m.stderr.on("data",y=>{g+=y.toString()}),m.on("close",y=>{if(y!==0){I(f,"\u274C",`Generation failed (exit ${y})`),h(JSON.stringify({error:`zibby generate failed with exit code ${y}`,stderr:g.slice(-1e3)}));return}let _=F(t,a||"test-specs"),d=[];try{let b=e?e.toLowerCase().replace(/[^a-z0-9]+/g,"-"):"";d=ie(_).filter(j=>j.endsWith(".txt")&&(!b||j.startsWith(b))).map(j=>L(_,j))}catch{}I(f,"\u2705",`Generated ${d.length} test spec files`),h(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.`}))}),m.on("error",y=>{I(f,"\u274C",`Spawn error: ${y.message}`),h(JSON.stringify({error:y.message}))})})}var Xe=1e5,et=/^[A-Z][A-Z0-9]+-\d+$/,Ys=new Set(["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","rule","table","tableRow","tableCell","tableHeader","mediaSingle","panel"]);function Zs(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 re(r,t=0){if(!Array.isArray(r))return"";let e=[];for(let s of r){if(s.type==="text"){e.push(Zs(s.text||"",s.marks));continue}if(s.type==="hardBreak"){e.push(`
291
+ 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 Hs(t,s);case"run_test":return await er(t,s,e);case"run_status":return tr(t);case"run_cancel":return sr(t);case"run_artifacts":return ir(t,s);case"run_diagnose":return or(t,s);case"list_specs":return ar(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 he(){let r=0;for(let[,t]of T)t.status==="running"&&r++;return r}function Qe(){for(;P.length>0;){let r=it(P[0]?.context?.options?.config);if(he()>=r)break;let{args:t,cwd:e,context:s}=P.shift();ut(t,e,s)}}async function Hs(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 f=e||"generate";return j(f,"\u{1F9EA}","Starting test spec generation (real agent with codebase access)..."),new Promise(h=>{ot&&console.error(`[zibby:spawn] skill=run_generate parentPid=${process.pid} \u2192 child zibby ${c.map(y=>/\s/.test(y)?JSON.stringify(y):y).join(" ")} cwd=${t}`);let m=nt("zibby",c,{cwd:t,env:{...process.env},stdio:["ignore","pipe","pipe"],detached:!1}),k="",g="";m.stdout.on("data",y=>{let _=y.toString();k+=_;for(let d of _.split(`
292
+ `)){let b=ct(d).trim();b.startsWith("\u2705")?j(f,"\u2705",b.slice(2).trim()):b.startsWith("\u2713")&&j(f,"\u2714",b.slice(2).trim())}}),m.stderr.on("data",y=>{g+=y.toString()}),m.on("close",y=>{if(y!==0){j(f,"\u274C",`Generation failed (exit ${y})`),h(JSON.stringify({error:`zibby generate failed with exit code ${y}`,stderr:g.slice(-1e3)}));return}let _=F(t,a||"test-specs"),d=[];try{let b=e?e.toLowerCase().replace(/[^a-z0-9]+/g,"-"):"";d=ie(_).filter(I=>I.endsWith(".txt")&&(!b||I.startsWith(b))).map(I=>L(_,I))}catch{}j(f,"\u2705",`Generated ${d.length} test spec files`),h(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.`}))}),m.on("error",y=>{j(f,"\u274C",`Spawn error: ${y.message}`),h(JSON.stringify({error:y.message}))})})}var Xe=1e5,et=/^[A-Z][A-Z0-9]+-\d+$/,Ys=new Set(["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","rule","table","tableRow","tableCell","tableHeader","mediaSingle","panel"]);function Zs(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 re(r,t=0){if(!Array.isArray(r))return"";let e=[];for(let s of r){if(s.type==="text"){e.push(Zs(s.text||"",s.marks));continue}if(s.type==="hardBreak"){e.push(`
293
293
  `);continue}if(s.type==="rule"){e.push(`
294
294
  ---
295
295
  `);continue}let n=s.content?re(s.content,t+1):"";if(s.type==="listItem")e.push(n);else if(s.type==="bulletList"){let i=(s.content||[]).map(o=>`- ${re(o.content||[],t+1).trim()}`);e.push(`
@@ -313,9 +313,9 @@ ${n}
313
313
 
314
314
  `).trim();return u?(u.length>Xe&&(u=`${u.slice(0,Xe)}
315
315
 
316
- ...[truncated]`),{inlineSpec:`inline:${u}`,issueKey:r}):null}catch{return null}}function Xs(r,t){try{let e=JSON.parse(r);return JSON.stringify({...e,...t})}catch{return r}}async function er(r,t,e){let s={...r},n=String(s.spec??"").trim();if(!n)return JSON.stringify({error:"spec is required"});let i=null;if(et.test(n)&&!n.startsWith("inline:")){let u=await Qs(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 T.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(!D(u))return et.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=it(e?.options?.config);if(he()>=a){let u=at(),p=s.ticketKey||u,f={runId:u,spec:s.ticketKey?`${s.ticketKey}: ${s.spec}`:s.spec,ticketKey:s.ticketKey||null,status:"queued",startTime:Date.now(),exitCode:null,output:"",error:""};T.set(u,f),P.push({args:{...s,_queuedRunId:u},cwd:t,context:e}),I(p,"\u23F3",`Queued (${he()}/${a} running, ${P.length} queued)`);let h={runId:u,spec:f.spec,ticketKey:f.ticketKey,status:"queued",message:`Queued \u2014 will start when a slot opens (max ${a} concurrent).`};return i&&(h.resolvedFromJiraIssue=i,h.message+=` (spec built from Jira ${i})`),JSON.stringify(h)}let c=Date.now()-ge;c<Ze&&ge>0&&await new Promise(u=>setTimeout(u,Ze-c)),ge=Date.now();let l=ut(s,t,e);return i?Xs(l,{resolvedFromJiraIssue:i,message:`Spec was loaded from Jira issue ${i} (description + comments).`}):l}function ut(r,t,e){let{spec:s,ticketKey:n,agent:i,headless:o,workflow:a,_queuedRunId:c}=r,l=c||at(),u=s,p=!1;if(s.startsWith("inline:")){p=!0;let O=Ws(t);Ye(O,{recursive:!0}),u=L(O,`${l}.txt`),Ps(u,s.slice(7).trim(),"utf-8")}let f=F(t,".zibby","output","runs");Ye(f,{recursive:!0});let h=L(f,`${l}.log`),m=Bs(h,{flags:"a"}),g=i&&["assistant","cursor","claude","codex","gemini"].includes(i)?i:null,y=["test",u];g&&y.push("--agent",g),o&&y.push("--headless"),a&&y.push("--workflow",a),ot&&console.error(`[zibby:spawn] skill=run_test parentPid=${process.pid} \u2192 child zibby ${y.map(O=>/\s/.test(O)?JSON.stringify(O):O).join(" ")} cwd=${t}`);let _=nt("zibby",y,{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:h,isInline:p,pid:_.pid,status:"running",output:"",error:"",startTime:Date.now(),exitCode:null,currentNode:null,completedNodes:[]},b=n||l,j="";function Ae(O){let v=ct(O).trim();if(!v)return;if(v.startsWith("__WORKFLOW_GRAPH_LOG__")){try{let $=JSON.parse(v.slice(22));$.phase==="node_begin"?d.currentNode=$.node:$.phase==="node_end"&&($.node&&!d.completedNodes.includes($.node)&&d.completedNodes.push($.node),d.currentNode===$.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,ke,_e,d.sessionId)),v.startsWith("\u250C ")||v.startsWith("\u250C ")){let $=v.slice(2).trim();d.currentNode=$,se&&I(b,"\u25B6",`${$}`)}else if(v.startsWith("\u2514 ")||v.startsWith("\u2514 ")){let $=v.slice(2).trim();$.startsWith("done")?(d.currentNode&&!d.completedNodes.includes(d.currentNode)&&d.completedNodes.push(d.currentNode),se&&I(b,"\u2714",`${d.currentNode||"node"} done ${$.replace("done","").trim()}`),d.currentNode=null):$.startsWith("failed")&&(se&&I(b,"\u2718",`${d.currentNode||"node"} failed ${$.replace("failed","").trim()}`),d.currentNode=null)}else v.includes("Workflow completed")&&(d.currentNode=null,se&&I(b,"\u2714",`Workflow completed (${Ve(Date.now()-d.startTime)})`))}function zt(O){let v=O.toString();d.output+=v,m.write(v),d.output.length>5e4&&(d.output=d.output.slice(-3e4)),j+=v;let Y=j.split(`
317
- `);j=Y.pop();for(let $ of Y)Ae($)}return _.stdout.on("data",zt),_.stderr.on("data",O=>{let v=O.toString();d.error+=v,m.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(),j&&Ae(j),m.end();let v=Ve(Date.now()-d.startTime);if(O===0?I(b,"\u2705",`Passed (${v})`):I(b,"\u274C",`Failed (${v})`),d.isInline)try{Ks(d.specPath)}catch{}Qe()}),_.on("error",O=>{d.status="error",d.error+=`
318
- Spawn error: ${O.message}`,I(b,"\u274C",`Spawn error: ${O.message}`),m.end(),Qe()}),d._child=_,T.set(l,d),JSON.stringify({runId:l,spec:d.spec,ticketKey:d.ticketKey,status:"running",pid:_.pid,logFile:h})}function tt(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 tr(r){let{runId:t}=r;if(!t)return JSON.stringify({error:"runId is required"});if(t==="all"){let i=[...T.entries()].map(([u,p])=>{let f=tt(p),h={runId:u,spec:p.spec,ticketKey:p.ticketKey,status:p.status,elapsed:f.elapsed,exitCode:p.exitCode,sessionId:p.sessionId||null};return p.status==="running"?(h.currentNode=f.currentNode,h.completedNodes=f.completedNodes,h.progress=f.progress):h.outputTail=p.output.slice(-500),h}),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=T.get(t);if(!e)return JSON.stringify({error:`Run not found: ${t}`});let s=tt(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 st(r,t){if(t.status==="queued"){let e=P.findIndex(s=>s.args._queuedRunId===r);return e>=0&&P.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 sr(r){let{runId:t}=r;if(!t)return JSON.stringify({error:"runId is required"});if(t==="all"){let s=[];for(let[n,i]of T.entries())(i.status==="running"||i.status==="queued")&&s.push(st(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=T.get(t);return JSON.stringify(e?st(t,e):{error:`Run not found: ${t}`})}function rr(r,t){let e=T.get(r);if(e?.sessionPath&&D(e.sessionPath))return e.sessionPath;if(e?.sessionId){let s=F(t,ke,_e,e.sessionId);if(D(s))return s}return null}function pt(r,t=""){let e=[];if(!D(r))return e;for(let s of ie(r,{withFileTypes:!0})){let n=t?`${t}/${s.name}`:s.name;if(s.isDirectory())e.push(...pt(L(r,s.name),n));else{let i=Fs(L(r,s.name));e.push({path:n,size:i.size})}}return e}function rt(r){if(!D(r))return null;try{return JSON.parse(ne(r,"utf-8"))}catch{return null}}function dt(r,t=2e3){if(!r||!D(r))return"";try{return ne(r,"utf-8").slice(-Math.max(200,Number(t)||2e3))}catch{return""}}function nr({run:r,logTail:t,errorTail:e}){let n=`${t||""}
316
+ ...[truncated]`),{inlineSpec:`inline:${u}`,issueKey:r}):null}catch{return null}}function Xs(r,t){try{let e=JSON.parse(r);return JSON.stringify({...e,...t})}catch{return r}}async function er(r,t,e){let s={...r},n=String(s.spec??"").trim();if(!n)return JSON.stringify({error:"spec is required"});let i=null;if(et.test(n)&&!n.startsWith("inline:")){let u=await Qs(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 T.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(!D(u))return et.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=it(e?.options?.config);if(he()>=a){let u=at(),p=s.ticketKey||u,f={runId:u,spec:s.ticketKey?`${s.ticketKey}: ${s.spec}`:s.spec,ticketKey:s.ticketKey||null,status:"queued",startTime:Date.now(),exitCode:null,output:"",error:""};T.set(u,f),P.push({args:{...s,_queuedRunId:u},cwd:t,context:e}),j(p,"\u23F3",`Queued (${he()}/${a} running, ${P.length} queued)`);let h={runId:u,spec:f.spec,ticketKey:f.ticketKey,status:"queued",message:`Queued \u2014 will start when a slot opens (max ${a} concurrent).`};return i&&(h.resolvedFromJiraIssue=i,h.message+=` (spec built from Jira ${i})`),JSON.stringify(h)}let c=Date.now()-ge;c<Ze&&ge>0&&await new Promise(u=>setTimeout(u,Ze-c)),ge=Date.now();let l=ut(s,t,e);return i?Xs(l,{resolvedFromJiraIssue:i,message:`Spec was loaded from Jira issue ${i} (description + comments).`}):l}function ut(r,t,e){let{spec:s,ticketKey:n,agent:i,headless:o,workflow:a,_queuedRunId:c}=r,l=c||at(),u=s,p=!1;if(s.startsWith("inline:")){p=!0;let O=Ws(t);Ye(O,{recursive:!0}),u=L(O,`${l}.txt`),Ps(u,s.slice(7).trim(),"utf-8")}let f=F(t,".zibby","output","runs");Ye(f,{recursive:!0});let h=L(f,`${l}.log`),m=Bs(h,{flags:"a"}),g=i&&["assistant","cursor","claude","codex","gemini"].includes(i)?i:null,y=["test",u];g&&y.push("--agent",g),o&&y.push("--headless"),a&&y.push("--workflow",a),ot&&console.error(`[zibby:spawn] skill=run_test parentPid=${process.pid} \u2192 child zibby ${y.map(O=>/\s/.test(O)?JSON.stringify(O):O).join(" ")} cwd=${t}`);let _=nt("zibby",y,{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:h,isInline:p,pid:_.pid,status:"running",output:"",error:"",startTime:Date.now(),exitCode:null,currentNode:null,completedNodes:[]},b=n||l,I="";function Ae(O){let v=ct(O).trim();if(!v)return;if(v.startsWith("__WORKFLOW_GRAPH_LOG__")){try{let $=JSON.parse(v.slice(22));$.phase==="node_begin"?d.currentNode=$.node:$.phase==="node_end"&&($.node&&!d.completedNodes.includes($.node)&&d.completedNodes.push($.node),d.currentNode===$.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,ke,_e,d.sessionId)),v.startsWith("\u250C ")||v.startsWith("\u250C ")){let $=v.slice(2).trim();d.currentNode=$,se&&j(b,"\u25B6",`${$}`)}else if(v.startsWith("\u2514 ")||v.startsWith("\u2514 ")){let $=v.slice(2).trim();$.startsWith("done")?(d.currentNode&&!d.completedNodes.includes(d.currentNode)&&d.completedNodes.push(d.currentNode),se&&j(b,"\u2714",`${d.currentNode||"node"} done ${$.replace("done","").trim()}`),d.currentNode=null):$.startsWith("failed")&&(se&&j(b,"\u2718",`${d.currentNode||"node"} failed ${$.replace("failed","").trim()}`),d.currentNode=null)}else v.includes("Workflow completed")&&(d.currentNode=null,se&&j(b,"\u2714",`Workflow completed (${Ve(Date.now()-d.startTime)})`))}function zt(O){let v=O.toString();d.output+=v,m.write(v),d.output.length>5e4&&(d.output=d.output.slice(-3e4)),I+=v;let Y=I.split(`
317
+ `);I=Y.pop();for(let $ of Y)Ae($)}return _.stdout.on("data",zt),_.stderr.on("data",O=>{let v=O.toString();d.error+=v,m.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&&Ae(I),m.end();let v=Ve(Date.now()-d.startTime);if(O===0?j(b,"\u2705",`Passed (${v})`):j(b,"\u274C",`Failed (${v})`),d.isInline)try{Ks(d.specPath)}catch{}Qe()}),_.on("error",O=>{d.status="error",d.error+=`
318
+ Spawn error: ${O.message}`,j(b,"\u274C",`Spawn error: ${O.message}`),m.end(),Qe()}),d._child=_,T.set(l,d),JSON.stringify({runId:l,spec:d.spec,ticketKey:d.ticketKey,status:"running",pid:_.pid,logFile:h})}function tt(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 tr(r){let{runId:t}=r;if(!t)return JSON.stringify({error:"runId is required"});if(t==="all"){let i=[...T.entries()].map(([u,p])=>{let f=tt(p),h={runId:u,spec:p.spec,ticketKey:p.ticketKey,status:p.status,elapsed:f.elapsed,exitCode:p.exitCode,sessionId:p.sessionId||null};return p.status==="running"?(h.currentNode=f.currentNode,h.completedNodes=f.completedNodes,h.progress=f.progress):h.outputTail=p.output.slice(-500),h}),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=T.get(t);if(!e)return JSON.stringify({error:`Run not found: ${t}`});let s=tt(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 st(r,t){if(t.status==="queued"){let e=P.findIndex(s=>s.args._queuedRunId===r);return e>=0&&P.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 sr(r){let{runId:t}=r;if(!t)return JSON.stringify({error:"runId is required"});if(t==="all"){let s=[];for(let[n,i]of T.entries())(i.status==="running"||i.status==="queued")&&s.push(st(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=T.get(t);return JSON.stringify(e?st(t,e):{error:`Run not found: ${t}`})}function rr(r,t){let e=T.get(r);if(e?.sessionPath&&D(e.sessionPath))return e.sessionPath;if(e?.sessionId){let s=F(t,ke,_e,e.sessionId);if(D(s))return s}return null}function pt(r,t=""){let e=[];if(!D(r))return e;for(let s of ie(r,{withFileTypes:!0})){let n=t?`${t}/${s.name}`:s.name;if(s.isDirectory())e.push(...pt(L(r,s.name),n));else{let i=Fs(L(r,s.name));e.push({path:n,size:i.size})}}return e}function rt(r){if(!D(r))return null;try{return JSON.parse(ne(r,"utf-8"))}catch{return null}}function dt(r,t=2e3){if(!r||!D(r))return"";try{return ne(r,"utf-8").slice(-Math.max(200,Number(t)||2e3))}catch{return""}}function nr({run:r,logTail:t,errorTail:e}){let n=`${t||""}
319
319
  ${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 ir(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,ke,_e);if(!D(c))return JSON.stringify({matches:[],message:"No sessions found"});let l=[],u=i.toLowerCase();for(let p of ie(c,{withFileTypes:!0})){if(!p.isDirectory())continue;let f=L(c,p.name),h=[{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:m,label:k}of h){let g=L(f,m);if(D(g))try{let y=ne(g,"utf-8");if(y.toLowerCase().includes(u)){let _=y.toLowerCase().indexOf(u),d=Math.max(0,_-100),b=Math.min(y.length,_+i.length+100);l.push({sessionId:p.name,artifact:k,snippet:y.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=T.get(e),l=dt(c?.logPath,o);if(l)return JSON.stringify({runId:e,source:"run-log",totalLength:l.length,tail:l})}let a=rr(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=pt(a);return JSON.stringify({sessionId:a.split("/").pop(),files:c,total:c.length})}case"result":{let c=rt(L(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=rt(L(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=L(a,n,"raw_stream_output.txt");if(!D(c))return JSON.stringify({error:`No log found in ${n}`});let l=ne(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 or(r,t){let e=String(r?.runId||"all"),s=Number(r?.tail||2e3),n=e==="all"?[...T.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=T.get(c);if(!l)return{runId:c,error:`Run not found: ${c}`};let u=dt(l.logPath,s),p=String(l.error||"").slice(-Math.max(200,s));return{...nr({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 ar(r,t){let e=r?.directory||"test-specs",s=F(t,e);if(!D(s))return JSON.stringify({specs:[],directory:e,message:`Directory not found: ${e}`});try{let i=function(o,a){for(let c of ie(o,{withFileTypes:!0})){let l=a?`${a}/${c.name}`:c.name;c.isDirectory()?i(L(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 cr}from"child_process";import{existsSync as J,mkdirSync as lr,readdirSync as mt,statSync as ur,readFileSync as pr}from"fs";import{resolve as dr,join as A,basename as mr}from"path";var fr="/workspace/repos",yr=".zibby/repos";function be(r){return process.env.REPOS?fr:dr(r,yr)}function ft(){let r=process.env.REPOS;if(!r)return[];try{let t=JSON.parse(r);return Array.isArray(t)?t:[]}catch{return[]}}function Se(r){return String(r).replace(/\//g,"-")}function oe(r,t,e={}){return new Promise((s,n)=>{let i=cr(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 yt={id:"git",description:"Clone and manage git repositories for codebase analysis",envKeys:["GITHUB_TOKEN","GITLAB_TOKEN"],promptFragment:`## Git Repositories
320
320
  You can clone and explore git repositories locally for codebase analysis:
321
321
  - git_checkout: Clone a repo (or pull if already cloned). Supports GitHub and GitLab with auto-auth.
@@ -359,9 +359,9 @@ When a test ticket lacks context, use this workflow:
359
359
  key_facts TEXT,
360
360
  created_at VARCHAR(32) NOT NULL
361
361
  )`],ht=new Set;function C(r,t){return vt($t,t,{...Rt,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 _t(r){if(ht.has(r))return!0;if(!Nt(Z(r,".dolt"))){if(!Nr())return!1;kr(r,{recursive:!0}),C(r,["init","--name","Zibby Chat Memory","--email","chat@zibby.app"])}let t=`${vr.join(`;
362
- `)};`;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 ht.add(r),!0}function Nr(){try{return vt($t,["version"],{...Rt,timeout:5e3}),!0}catch{return!1}}function w(r){return r==null?"NULL":`'${String(r).replace(/'/g,"''")}'`}function $e(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 Re(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 jt(r){let t=new Map;for(let e of r||[]){let s=$e(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 ue(r,t){let e=String(r??"");return e.length<=t?e:t<=1?e.slice(0,t):`${e.slice(0,t-1)}\u2026`}function ce(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||Oe),error:r?.error||null};return e.backend==="mem0"?{...e,recentSessions:[],taskStats:[]}:e}function Or(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(`- ${ue(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}] ${ue(e.content,120)}`)}}return t.length===0?"":`## Memory Context
362
+ `)};`;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 ht.add(r),!0}function Nr(){try{return vt($t,["version"],{...Rt,timeout:5e3}),!0}catch{return!1}}function w(r){return r==null?"NULL":`'${String(r).replace(/'/g,"''")}'`}function $e(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 Re(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 It(r){let t=new Map;for(let e of r||[]){let s=$e(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 ue(r,t){let e=String(r??"");return e.length<=t?e:t<=1?e.slice(0,t):`${e.slice(0,t-1)}\u2026`}function ce(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||Oe),error:r?.error||null};return e.backend==="mem0"?{...e,recentSessions:[],taskStats:[]}:e}function Or(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(`- ${ue(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}] ${ue(e.content,120)}`)}}return t.length===0?"":`## Memory Context
363
363
  ${t.join(`
364
- `)}`}function Ne(r){return{backend:r.backend,recentSessions:r.recentSessions.slice(0,3).map(t=>({summary:ue(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:ue(String(t?.content||""),140),source:t?.source||null})),taskStats:r.taskStats,error:r.error||null}}async function kt(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(ae.has(r))return ae.get(r);try{let n=Z(r,".zibby.config.mjs");if(Nt(n)){let i=await import(le(n).href),o=String(i?.default?.memory?.backend||"").trim().toLowerCase();if(o==="mem0"||o==="dolt")return ae.set(r,o),o}}catch{}return ae.set(r,Oe),Oe}function It(r){let t=String(process.env.ZIBBY_MEMORY_USER_ID||"").trim();return t||`workspace:${wr(r||process.cwd())}`}function $r(){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 At(r){let t=r||process.cwd();if(ve.has(t))return ve.get(t);let e;try{let a=Ot(le(Z(t,"package.json")).href).resolve("mem0ai/oss");e=await import(le(a).href)}catch{try{let o=Sr.resolve("mem0ai/oss");e=await import(le(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=$r(),i=n?new s(n):new s;return ve.set(t,i),i}function wt(r,t="mid"){return(Array.isArray(r)?r:Array.isArray(r?.results)?r.results:[]).map(s=>({id:s?.id||pe(),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:Re(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 Tt={id:"chat-memory",description:"Persistent chat memory and task history (Dolt-backed)",envKeys:[],promptFragment:`## Chat Memory (persistent)
364
+ `)}`}function Ne(r){return{backend:r.backend,recentSessions:r.recentSessions.slice(0,3).map(t=>({summary:ue(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:ue(String(t?.content||""),140),source:t?.source||null})),taskStats:r.taskStats,error:r.error||null}}async function kt(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(ae.has(r))return ae.get(r);try{let n=Z(r,".zibby.config.mjs");if(Nt(n)){let i=await import(le(n).href),o=String(i?.default?.memory?.backend||"").trim().toLowerCase();if(o==="mem0"||o==="dolt")return ae.set(r,o),o}}catch{}return ae.set(r,Oe),Oe}function jt(r){let t=String(process.env.ZIBBY_MEMORY_USER_ID||"").trim();return t||`workspace:${wr(r||process.cwd())}`}function $r(){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 At(r){let t=r||process.cwd();if(ve.has(t))return ve.get(t);let e;try{let a=Ot(le(Z(t,"package.json")).href).resolve("mem0ai/oss");e=await import(le(a).href)}catch{try{let o=Sr.resolve("mem0ai/oss");e=await import(le(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=$r(),i=n?new s(n):new s;return ve.set(t,i),i}function wt(r,t="mid"){return(Array.isArray(r)?r:Array.isArray(r?.results)?r.results:[]).map(s=>({id:s?.id||pe(),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:Re(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 Tt={id:"chat-memory",description:"Persistent chat memory and task history (Dolt-backed)",envKeys:[],promptFragment:`## Chat Memory (persistent)
365
365
  You have persistent memory across sessions. Use it to avoid losing context:
366
366
  - **memory_store**: Save important facts, decisions, or context. Anything worth remembering.
367
367
  - **memory_recall**: Search your memory by keyword or category. Use this at the START of conversations to recall relevant context.
@@ -377,17 +377,17 @@ You have persistent memory across sessions. Use it to avoid losing context:
377
377
  - When the user's request is complete: call memory_end_session
378
378
 
379
379
  ### Categories for memory_store
380
- fact, decision, context, insight, credential, url, error, workaround`,resolve(){return null},async buildPromptContext(r,t={}){let e=r?.options?.workspace||process.cwd(),s=Z(e,gt),n=await kt(e,r);if(n==="dolt"&&!_t(s)){let i="Dolt not available. Install: brew install dolt (macOS) or see https://docs.dolthub.com/introduction/installation";return{backend:n,brief:ce({backend:n,error:i},n),promptContext:"",debugPreview:Ne(ce({backend:n,error:i},n)),error:i}}try{let i=n==="mem0"?await St(t,s,e):bt(t,s),o=JSON.parse(i||"{}"),a=ce({...o,backend:n},n);return{backend:n,brief:a,promptContext:Or(a),debugPreview:Ne(a),error:a.error||null}}catch(i){let o=String(i?.message||i),a=ce({backend:n,error:o},n);return{backend:n,brief:a,promptContext:"",debugPreview:Ne(a),error:o}}},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd(),n=Z(s,gt),i=await kt(s,e);if((i==="dolt"||["memory_end_session","task_log","task_history"].includes(r))&&!_t(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 Rr(t,n,s):Ct(t,n);case"memory_recall":return i==="mem0"?await Et(t,n,s):jr(t,n);case"memory_brief":return i==="mem0"?await St(t,n,s):bt(t,n);case"memory_end_session":return Ir(t,n);case"task_log":return Ar(t,n);case"task_history":return Tr(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 Ct(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=$e(e);if(!c)return JSON.stringify({error:"content is empty after normalization"});let l=Re(o,s),u=l==="long"?1:l==="mid"?.8:.5,p=String(a||"").trim().slice(0,160);if(p){let y=K(t,`SELECT id, tier, relevance
380
+ fact, decision, context, insight, credential, url, error, workaround`,resolve(){return null},async buildPromptContext(r,t={}){let e=r?.options?.workspace||process.cwd(),s=Z(e,gt),n=await kt(e,r);if(n==="dolt"&&!_t(s)){let i="Dolt not available. Install: brew install dolt (macOS) or see https://docs.dolthub.com/introduction/installation";return{backend:n,brief:ce({backend:n,error:i},n),promptContext:"",debugPreview:Ne(ce({backend:n,error:i},n)),error:i}}try{let i=n==="mem0"?await St(t,s,e):bt(t,s),o=JSON.parse(i||"{}"),a=ce({...o,backend:n},n);return{backend:n,brief:a,promptContext:Or(a),debugPreview:Ne(a),error:a.error||null}}catch(i){let o=String(i?.message||i),a=ce({backend:n,error:o},n);return{backend:n,brief:a,promptContext:"",debugPreview:Ne(a),error:o}}},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd(),n=Z(s,gt),i=await kt(s,e);if((i==="dolt"||["memory_end_session","task_log","task_history"].includes(r))&&!_t(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 Rr(t,n,s):Ct(t,n);case"memory_recall":return i==="mem0"?await Et(t,n,s):Ir(t,n);case"memory_brief":return i==="mem0"?await St(t,n,s):bt(t,n);case"memory_end_session":return jr(t,n);case"task_log":return Ar(t,n);case"task_history":return Tr(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 Ct(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=$e(e);if(!c)return JSON.stringify({error:"content is empty after normalization"});let l=Re(o,s),u=l==="long"?1:l==="mid"?.8:.5,p=String(a||"").trim().slice(0,160);if(p){let y=K(t,`SELECT id, tier, relevance
381
381
  FROM chat_memory
382
382
  WHERE memory_key = ${w(p)}
383
383
  ORDER BY created_at DESC
384
- LIMIT 1`)[0];if(y){let _=String(y.tier||"mid"),d=Number(y.relevance||0),b=G(l)>G(_)?l:_,j=Math.max(u,d);E(t,`UPDATE chat_memory
384
+ LIMIT 1`)[0];if(y){let _=String(y.tier||"mid"),d=Number(y.relevance||0),b=G(l)>G(_)?l:_,I=Math.max(u,d);E(t,`UPDATE chat_memory
385
385
  SET content = ${w(e)},
386
386
  category = ${w(s)},
387
387
  source = ${w(n)},
388
388
  ticket_key = ${w(i)},
389
389
  tier = ${w(b)},
390
- relevance = ${j},
390
+ relevance = ${I},
391
391
  created_at = ${w(W())}
392
392
  WHERE id = ${w(y.id)}`);try{C(t,["add","."]),C(t,["commit","-m",`memory upsert: ${s} \u2014 ${String(e).slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:y.id,category:s,tier:b,memoryKey:p,upserted:!0})}}let h=K(t,`SELECT id, content, tier, relevance
393
393
  FROM chat_memory
@@ -397,18 +397,18 @@ fact, decision, context, insight, credential, url, error, workaround`,resolve(){
397
397
  SET tier = ${w(_?l:g)},
398
398
  relevance = ${Math.max(u,y)}
399
399
  WHERE id = ${w(h.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:h.id,category:s,tier:_?l:g,deduped:!0,promoted:!0})}return JSON.stringify({ok:!0,id:h.id,category:s,tier:g,deduped:!0,promoted:!1})}let m=pe(),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)
400
- VALUES (${w(m)}, ${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:m,category:s,tier:l,memoryKey:p||null,stored:e.slice(0,100)})}async function Rr(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 At(e),u=It(e),p=Re(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 jr(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
400
+ VALUES (${w(m)}, ${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:m,category:s,tier:l,memoryKey:p||null,stored:e.slice(0,100)})}async function Rr(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 At(e),u=jt(e),p=Re(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 Ir(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
401
401
  FROM chat_memory ${a.length>0?`WHERE ${a.join(" AND ")}`:""}
402
402
  ORDER BY relevance DESC, created_at DESC
403
- LIMIT ${o}`,u=K(t,l);return JSON.stringify({total:u.length,memories:u})}async function Et(r,t,e){let{query:s,category:n,ticketKey:i,tier:o,limit:a=20}=r;try{let c=await At(e),l=It(e),u=[];if(s&&String(s).trim()){let p=await c.search(String(s),{userId:l,limit:a});u=wt(p)}else{let p=await c.getAll({userId:l,limit:Math.max(a,50)});u=wt(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 bt(r,t){let{ticketKey:e}=r;Er(t);let n=K(t,`SELECT session_id, summary, tickets, tasks_run, tasks_passed, tasks_failed, created_at
403
+ LIMIT ${o}`,u=K(t,l);return JSON.stringify({total:u.length,memories:u})}async function Et(r,t,e){let{query:s,category:n,ticketKey:i,tier:o,limit:a=20}=r;try{let c=await At(e),l=jt(e),u=[];if(s&&String(s).trim()){let p=await c.search(String(s),{userId:l,limit:a});u=wt(p)}else{let p=await c.getAll({userId:l,limit:Math.max(a,50)});u=wt(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 bt(r,t){let{ticketKey:e}=r;Er(t);let n=K(t,`SELECT session_id, summary, tickets, tasks_run, tasks_passed, tasks_failed, created_at
404
404
  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
405
405
  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
406
406
  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
407
- GROUP BY type, status ORDER BY cnt DESC LIMIT 10`),u=jt([...o,...a]);return JSON.stringify({recentSessions:n,topMemories:u,taskStats:l,ticketFilter:e||null})}async function St(r,t,e){let{ticketKey:s}=r,n=await Et({limit:80},t,e),i=JSON.parse(n||"{}"),o=Array.isArray(i.memories)?i.memories:[];s&&(o=o.filter(f=>f.ticket_key===s));let a=f=>{let h=Date.parse(String(f?.created_at||""))||0;return Number(f?.relevance||0)*1e12+h},c=(f,h)=>a(h)-a(f),l=o.filter(f=>f.tier==="long").sort(c).slice(0,10),u=o.filter(f=>f.tier==="mid").sort(c).slice(0,8),p=jt([...l,...u]);return JSON.stringify({recentSessions:[],topMemories:p,taskStats:[],ticketFilter:s||null,backend:"mem0"})}function Ir(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_${pe()}`;if(E(t,`INSERT INTO chat_sessions (session_id, summary, tickets, tasks_run, tasks_passed, tasks_failed, key_facts, created_at)
407
+ GROUP BY type, status ORDER BY cnt DESC LIMIT 10`),u=It([...o,...a]);return JSON.stringify({recentSessions:n,topMemories:u,taskStats:l,ticketFilter:e||null})}async function St(r,t,e){let{ticketKey:s}=r,n=await Et({limit:80},t,e),i=JSON.parse(n||"{}"),o=Array.isArray(i.memories)?i.memories:[];s&&(o=o.filter(f=>f.ticket_key===s));let a=f=>{let h=Date.parse(String(f?.created_at||""))||0;return Number(f?.relevance||0)*1e12+h},c=(f,h)=>a(h)-a(f),l=o.filter(f=>f.tier==="long").sort(c).slice(0,10),u=o.filter(f=>f.tier==="mid").sort(c).slice(0,8),p=It([...l,...u]);return JSON.stringify({recentSessions:[],topMemories:p,taskStats:[],ticketFilter:s||null,backend:"mem0"})}function jr(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_${pe()}`;if(E(t,`INSERT INTO chat_sessions (session_id, summary, tickets, tasks_run, tasks_passed, tasks_failed, key_facts, created_at)
408
408
  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))Ct({content:l,category:"fact",source:"session_summary",tier:"mid"},t);Cr(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 Ar(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=pe(),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)
409
409
  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 Tr(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
410
410
  FROM chat_tasks ${o.length>0?`WHERE ${o.join(" AND ")}`:""}
411
- ORDER BY created_at DESC LIMIT ${i}`,l=K(t,c);return JSON.stringify({total:l.length,tasks:l})}function Cr(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 Er(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 Q,readdirSync as je,mkdirSync as xr,writeFileSync as H,statSync as Jt}from"fs";import{join as S,resolve as Ie,relative as Dt,dirname as Mt}from"path";import{fileURLToPath as Lr}from"url";import{createRequire as Jr}from"module";var Dr=Jr(import.meta.url),Mr=`## Workflow Builder
411
+ ORDER BY created_at DESC LIMIT ${i}`,l=K(t,c);return JSON.stringify({total:l.length,tasks:l})}function Cr(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 Er(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 Q,readdirSync as Ie,mkdirSync as xr,writeFileSync as H,statSync as Jt}from"fs";import{join as S,resolve as je,relative as Dt,dirname as Mt}from"path";import{fileURLToPath as Lr}from"url";import{createRequire as Jr}from"module";var Dr=Jr(import.meta.url),Mr=`## Workflow Builder
412
412
 
413
413
  You can help users build custom AI workflows using the Zibby workflow framework.
414
414
 
@@ -518,7 +518,7 @@ Call with no arguments to see all available topics.
518
518
  - Workflow names must be kebab-case (e.g., ticket-triage, pr-review).
519
519
  - State flows through: each node's validated output is stored under its name in state (e.g., state.classify_ticket).
520
520
  - Downstream nodes reference upstream outputs in their prompt function (e.g., \\\`\\\${JSON.stringify(state.classify_ticket, null, 2)}\\\`).
521
- - Nodes can declare skills to get MCP tool access \u2014 the framework handles server lifecycle automatically.`,Ut=/^[a-z][a-z0-9-]{0,62}[a-z0-9]$/;function qt(r){return`${r.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}Workflow`}function V(r){return`${r.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())}Node`}function Ur(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 qr(r){let t=Ie(r,".zibby.config.mjs");if(!M(t))return{};try{return(await import(t)).default||{}}catch{return{}}}function Pr(){try{let r=Mt(Dr.resolve("@zibby/core/package.json")),t=S(r,"templates","browser-test-automation"),e=Q(S(t,"nodes","preflight.mjs"),"utf-8"),s=Q(S(t,"graph.mjs"),"utf-8");return{preflight:e,graph:s}}catch{return null}}var xt=Mt(Lr(import.meta.url));function Pt(){let r=Ie(xt,"..","..","..","docsite","docs");if(M(r))return r;let t=Ie(xt,"..","docs");return M(t)?t:null}function Lt(){let r=Pt();if(!r)return[];try{let t=(e,s="")=>{let n=[];for(let i of je(e)){let o=S(e,i);try{if(Jt(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 Kt(r){let t=Pt();if(!t)return null;let e=S(t,`${r}.md`);if(!M(e))return null;try{return Q(e,"utf-8")}catch{return null}}function Kr(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(`
521
+ - Nodes can declare skills to get MCP tool access \u2014 the framework handles server lifecycle automatically.`,Ut=/^[a-z][a-z0-9-]{0,62}[a-z0-9]$/;function qt(r){return`${r.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}Workflow`}function V(r){return`${r.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())}Node`}function Ur(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 qr(r){let t=je(r,".zibby.config.mjs");if(!M(t))return{};try{return(await import(t)).default||{}}catch{return{}}}function Pr(){try{let r=Mt(Dr.resolve("@zibby/core/package.json")),t=S(r,"templates","browser-test-automation"),e=Q(S(t,"nodes","preflight.mjs"),"utf-8"),s=Q(S(t,"graph.mjs"),"utf-8");return{preflight:e,graph:s}}catch{return null}}var xt=Mt(Lr(import.meta.url));function Pt(){let r=je(xt,"..","..","..","docsite","docs");if(M(r))return r;let t=je(xt,"..","docs");return M(t)?t:null}function Lt(){let r=Pt();if(!r)return[];try{let t=(e,s="")=>{let n=[];for(let i of Ie(e)){let o=S(e,i);try{if(Jt(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 Kt(r){let t=Pt();if(!t)return null;let e=S(t,`${r}.md`);if(!M(e))return null;try{return Q(e,"utf-8")}catch{return null}}function Kr(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(`
522
522
  `),e=r.edges.map(o=>o.condition?`- ${o.from} \u2192 ${o.to} (conditional: ${o.condition})`:`- ${o.from} \u2192 ${o.to}`).join(`
523
523
  `),s=Pr(),n=Kt("custom-workflows"),i="";return s&&(i+=`
524
524
  ## Real working examples from the Zibby framework
@@ -646,4 +646,4 @@ ${h}
646
646
  }
647
647
  `;H(S(o,"graph.mjs"),m,"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)}
648
648
  `,"utf-8");let g=["graph.mjs","workflow.json","nodes/index.mjs",...c.map(y=>`nodes/${y.replace(/_/g,"-")}.mjs`)];return{workflowDir:Dt(r,o),files:g,className:i,slug:n}}async function Wr(r){let{name:t,description:e,nodes:s,edges:n}=r;if(!t||!Ut.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||`${qt(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 zr(r,t){let{name:e,spec:s}=r,n=(e||s?.name||"").toLowerCase();if(!n||!Ut.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 Bt(s,t),a=Fr(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 Gr(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:[]},f=(await Bt(u,t)).nodes?.[c]?.code;if(!f)return JSON.stringify({error:"Failed to generate node code."});let h=S(l,"nodes"),m=`${c.replace(/_/g,"-")}.mjs`;H(S(h,m),f,"utf-8");let k=S(h,"index.mjs"),g=V(c),y=`export { ${g} } from './${c.replace(/_/g,"-")}.mjs';
649
- `,_=M(k)?Q(k,"utf-8"):"";return _.includes(g)||H(k,_+y,"utf-8"),JSON.stringify({ok:!0,file:`nodes/${m}`,exportName:g,message:`Node "${c}" added. Update graph.mjs to wire it into the graph.`})}async function Hr(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 Yr(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=je(t).filter(n=>{try{return Jt(S(t,n)).isDirectory()}catch{return!1}}).map(n=>{let i=S(t,n,"workflow.json"),o={};try{o=JSON.parse(Q(i,"utf-8"))}catch{}let a=S(t,n,"nodes"),c=0;try{c=je(a).filter(l=>l.endsWith(".mjs")&&l!=="index.mjs").length}catch{}return{name:n,description:o.description||"",nodeCount:c,path:Dt(r,S(t,n))}});return JSON.stringify({workflows:s})}var Ft={id:"workflow-builder",description:"Build, scaffold, and deploy custom AI workflows via conversation",envKeys:[],promptFragment:Mr,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 Wr(t);case"build_workflow":return await zr(t,s);case"add_node":return await Gr(t,s);case"deploy_workflow":return await Hr(t,s);case"list_workflows":return Yr(s);case"explore_framework_docs":{let n=(t.topic||"").trim();if(!n){let o=Lt();return JSON.stringify({available:o,hint:"Call again with a topic to read its content."})}let i=Kt(n);if(!i){let o=Lt();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 Zr}from"module";import{fileURLToPath as Vr}from"url";import{registerHandlers as Qr}from"@zibby/core/function-skill-registry.js";import{registerSkill as Xr}from"@zibby/agent-workflow";var en=Zr(import.meta.url);function tn(){try{return en.resolve("@zibby/core/function-bridge.js")}catch{return null}}var sn=import.meta.url;function rn(){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!==sn&&!n.startsWith("node:"))return n.startsWith("file://")?Vr(n):n}return null}finally{Error.prepareStackTrace=r}}function nn(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 on(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:nn(e.input)}];return Qr(r,s,n),{id:r,type:"function",serverName:r,allowedTools:[`mcp__${r}__*`],description:e.description||`Function skill: ${r}`,envKeys:[],tools:n,resolve(){let i=tn();return i?{command:"node",args:[i,t,r]}:null}}}function an(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 Wt(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=rn();if(!s)throw new Error(`Could not resolve caller file for skill "${r}".`);e=on(r,s,t)}else if(typeof t.resolve=="function")e=an(r,t);else throw new Error(`Skill "${r}" must have either a handler (function skill) or resolve (MCP skill).`);return Xr(e),e}var cn=Wt;import{registerSkill as Oi,getSkill as $i,hasSkill as Ri,getAllSkills as ji,listSkillIds as Ii}from"@zibby/agent-workflow";x(Te);x(xe);x(Je);x(fe);x(He);x(Me);x(lt);x(yt);x(qe);x(We);x(Tt);x(Ft);x({...fe,id:"slack_notify"});var bi={BROWSER:"browser",JIRA:"jira",GITHUB:"github",GIT:"git",SLACK:"slack",SENTRY:"sentry",MEMORY:"memory",RUNNER:"runner",SKILL_INSTALLER:"skill-installer",CORE_TOOLS:"core-tools",CHAT_MEMORY:"chat-memory",WORKFLOW_BUILDER:"workflow-builder"};export{bi as SKILLS,Te as browserSkill,Tt as chatMemorySkill,We as coreToolsSkill,cn as functionSkill,ji as getAllSkills,$i as getSkill,yt as gitSkill,Je as githubSkill,Ri as hasSkill,xe as jiraSkill,Ii as listSkillIds,Me as memorySkill,Oi as registerSkill,lt as runnerSkill,He as sentrySkill,Wt as skill,qe as skillInstallerSkill,fe as slackSkill,lt as testRunnerSkill,Ft as workflowBuilderSkill};
649
+ `,_=M(k)?Q(k,"utf-8"):"";return _.includes(g)||H(k,_+y,"utf-8"),JSON.stringify({ok:!0,file:`nodes/${m}`,exportName:g,message:`Node "${c}" added. Update graph.mjs to wire it into the graph.`})}async function Hr(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 Yr(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=Ie(t).filter(n=>{try{return Jt(S(t,n)).isDirectory()}catch{return!1}}).map(n=>{let i=S(t,n,"workflow.json"),o={};try{o=JSON.parse(Q(i,"utf-8"))}catch{}let a=S(t,n,"nodes"),c=0;try{c=Ie(a).filter(l=>l.endsWith(".mjs")&&l!=="index.mjs").length}catch{}return{name:n,description:o.description||"",nodeCount:c,path:Dt(r,S(t,n))}});return JSON.stringify({workflows:s})}var Ft={id:"workflow-builder",description:"Build, scaffold, and deploy custom AI workflows via conversation",envKeys:[],promptFragment:Mr,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 Wr(t);case"build_workflow":return await zr(t,s);case"add_node":return await Gr(t,s);case"deploy_workflow":return await Hr(t,s);case"list_workflows":return Yr(s);case"explore_framework_docs":{let n=(t.topic||"").trim();if(!n){let o=Lt();return JSON.stringify({available:o,hint:"Call again with a topic to read its content."})}let i=Kt(n);if(!i){let o=Lt();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 Zr}from"module";import{fileURLToPath as Vr}from"url";import{registerHandlers as Qr}from"@zibby/core/function-skill-registry.js";import{registerSkill as Xr}from"@zibby/agent-workflow";var en=Zr(import.meta.url);function tn(){try{return en.resolve("@zibby/core/function-bridge.js")}catch{return null}}var sn=import.meta.url;function rn(){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!==sn&&!n.startsWith("node:"))return n.startsWith("file://")?Vr(n):n}return null}finally{Error.prepareStackTrace=r}}function nn(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 on(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:nn(e.input)}];return Qr(r,s,n),{id:r,type:"function",serverName:r,allowedTools:[`mcp__${r}__*`],description:e.description||`Function skill: ${r}`,envKeys:[],tools:n,resolve(){let i=tn();return i?{command:"node",args:[i,t,r]}:null}}}function an(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 Wt(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=rn();if(!s)throw new Error(`Could not resolve caller file for skill "${r}".`);e=on(r,s,t)}else if(typeof t.resolve=="function")e=an(r,t);else throw new Error(`Skill "${r}" must have either a handler (function skill) or resolve (MCP skill).`);return Xr(e),e}var cn=Wt;import{registerSkill as Oi,getSkill as $i,hasSkill as Ri,getAllSkills as Ii,listSkillIds as ji}from"@zibby/agent-workflow";x(Te);x(xe);x(Je);x(fe);x(He);x(Me);x(lt);x(yt);x(qe);x(We);x(Tt);x(Ft);x({...fe,id:"slack_notify"});var bi={BROWSER:"browser",JIRA:"jira",GITHUB:"github",GIT:"git",SLACK:"slack",SENTRY:"sentry",MEMORY:"memory",RUNNER:"runner",SKILL_INSTALLER:"skill-installer",CORE_TOOLS:"core-tools",CHAT_MEMORY:"chat-memory",WORKFLOW_BUILDER:"workflow-builder",SESSION:"session"};export{bi as SKILLS,Te as browserSkill,Tt as chatMemorySkill,We as coreToolsSkill,cn as functionSkill,Ii as getAllSkills,$i as getSkill,yt as gitSkill,Je as githubSkill,Ri as hasSkill,xe as jiraSkill,ji as listSkillIds,Me as memorySkill,Oi as registerSkill,lt as runnerSkill,He as sentrySkill,Wt as skill,qe as skillInstallerSkill,fe as slackSkill,lt as testRunnerSkill,Ft as workflowBuilderSkill};
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/skills",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Built-in skill definitions for Zibby test automation framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,227 @@
1
+ ---
2
+ sidebar_position: 6
3
+ title: Sub-graphs (parent → child)
4
+ ---
5
+
6
+ # Sub-graphs
7
+
8
+ A **sub-graph node** runs another deployed workflow as a child of the current one. Use it when a step is large enough to deserve its own workflow definition — its own state schema, its own version, its own activity-tab history — but you want a parent to dispatch it as part of a larger flow.
9
+
10
+ The shape is one extra field on the existing node config:
11
+
12
+ ```js
13
+ g.addNode('audit', {
14
+ workflow: 'deep-audit', // ← name of another workflow in this project
15
+ });
16
+ ```
17
+
18
+ That's it. No new imports, no UUID, no separate class. The engine recognizes `workflow:` and turns this node into a sub-graph dispatcher.
19
+
20
+ ## When to use a sub-graph
21
+
22
+ | Scenario | Sub-graph? |
23
+ |---|---|
24
+ | Two parents need the same multi-node flow | ✅ Yes — define it once as a child, reference by name |
25
+ | One step needs different state schema than the rest | ✅ Yes — each workflow has its own schema |
26
+ | You want per-step activity-tab history + replay | ✅ Yes — each child run gets its own row |
27
+ | Step is a single LLM call | ❌ No — just add a regular node |
28
+ | Step has its own retry policy | Either works, but a sub-graph gives independent control |
29
+
30
+ ## Sync vs async
31
+
32
+ `async:` flips the dispatch mode:
33
+
34
+ ```js
35
+ g.addNode('audit', { workflow: 'deep-audit' }); // sync (default)
36
+ g.addNode('notify', { workflow: 'slack-notifier', async: true }); // fire-and-forget
37
+ ```
38
+
39
+ | Mode | Behavior | Returns to parent | Use for |
40
+ |---|---|---|---|
41
+ | **sync** (default) | Parent blocks, polls child until terminal status, merges result into parent state | the extracted value (see `output:` below) | Steps where downstream nodes depend on the child's result |
42
+ | **async** (`async: true`) | Parent dispatches the child and continues immediately. No polling. | a dispatch handle `{ jobId, status, workflow }` | Fan-out, notifications, side-effect work the parent shouldn't wait for |
43
+
44
+ Quota: every sub-graph run counts as a separate execution against the account's monthly cap (parent + 3 children = 4 executions).
45
+
46
+ ## Full option surface
47
+
48
+ ```js
49
+ g.addNode('audit', {
50
+ // ─── Required ─────────────────────────────────────────────────────
51
+ workflow: 'deep-audit', // resolved by name within this project
52
+
53
+ // ─── Mode (default sync) ──────────────────────────────────────────
54
+ async: false, // false = block + merge, true = fire-forget
55
+
56
+ // ─── State plumbing ───────────────────────────────────────────────
57
+ input: (state) => ({ // shape parent state → child input
58
+ ticketId: state.ticketId,
59
+ }), // OR a plain object OR omit (child gets {})
60
+
61
+ output: 'audit.score', // dot-path on child finalState
62
+ // OR (childState) => ({...}) function form
63
+ // OR omit → entire child finalState
64
+
65
+ // ─── Sync tunings (ignored when async: true) ──────────────────────
66
+ timeoutMs: 5 * 60 * 1000, // throw after this long (default 10min)
67
+ pollIntervalMs: 2000, // status-check frequency (default 2s)
68
+
69
+ // ─── Cross-cutting concerns ───────────────────────────────────────
70
+ retries: 3, // engine retries whole dispatch on transient failure
71
+ onComplete: (state, result) => result,
72
+
73
+ // ─── Advanced ─────────────────────────────────────────────────────
74
+ conversationId: 'inherit', // 'inherit' (default) | 'new' | (state) => string
75
+ });
76
+ ```
77
+
78
+ ## How state flows
79
+
80
+ Each workflow has its own state schema — they're independent. The parent must transform its state into the child's input shape, and (optionally) extract whatever it needs back out.
81
+
82
+ ### A complete example — `parent-orchestrator` calls `child-doubler`
83
+
84
+ ```js
85
+ // child-doubler — takes a number, returns it doubled.
86
+ class ChildDoublerAgent extends WorkflowAgent {
87
+ buildGraph() {
88
+ const g = new WorkflowGraph();
89
+ g.setStateSchema(z.object({
90
+ value: z.number(),
91
+ double: z.object({ doubled: z.number() }).optional(),
92
+ }));
93
+ g.addNode('double', {
94
+ _isCustomCode: true,
95
+ outputSchema: z.object({ doubled: z.number() }),
96
+ execute: async (ctx) => ({ doubled: ctx.state.getAll().value * 2 }),
97
+ });
98
+ g.setEntryPoint('double');
99
+ g.addEdge('double', 'END');
100
+ return g;
101
+ }
102
+ }
103
+
104
+ // parent-orchestrator — picks a number, calls child-doubler, reports.
105
+ class ParentOrchestratorAgent extends WorkflowAgent {
106
+ buildGraph() {
107
+ const g = new WorkflowGraph();
108
+ g.setStateSchema(z.object({
109
+ seed: z.number(),
110
+ pick_number: z.object({ value: z.number(), label: z.string() }).optional(),
111
+ call_doubler: z.number().optional(), // ← child's result lands here
112
+ report: z.object({ summary: z.string() }).optional(),
113
+ }));
114
+
115
+ g.addNode('pick_number', pickNumberNode);
116
+
117
+ g.addNode('call_doubler', {
118
+ workflow: 'child-doubler',
119
+ input: (state) => ({ value: state.pick_number.value }),
120
+ output: 'double.doubled', // dot-path through child's node name
121
+ });
122
+
123
+ g.addNode('report', reportNode); // reads state.call_doubler
124
+
125
+ g.setEntryPoint('pick_number');
126
+ g.addEdge('pick_number', 'call_doubler');
127
+ g.addEdge('call_doubler', 'report');
128
+ g.addEdge('report', 'END');
129
+ return g;
130
+ }
131
+ }
132
+ ```
133
+
134
+ Triggering the parent with `{ seed: 21 }`:
135
+
136
+ | Step | What happens | State after |
137
+ |---|---|---|
138
+ | 1 | `pick_number` runs | `{ seed: 21, pick_number: { value: 21, label: '…' } }` |
139
+ | 2 | `call_doubler.input(state)` fires | returns `{ value: 21 }` |
140
+ | 3 | Server validates `{ value: 21 }` against child's `stateSchema` | passes |
141
+ | 4 | Child runs in its own Fargate task. Final state: `{ value: 21, double: { doubled: 42 } }` | (parent waiting) |
142
+ | 5 | Engine extracts `output: 'double.doubled'` → `42` | `state.call_doubler = 42` |
143
+ | 6 | `report` runs, reads `state.call_doubler` | `state.report.summary = '…42…'` |
144
+
145
+ ### Why `output: 'double.doubled'` and not `'doubled'`?
146
+
147
+ Each node's output is stored at `state[nodeName]` in its own graph. So when the child's `double` node returns `{ doubled: 42 }`, that lands at `childState.double.doubled` — `doubled` is *nested under the node name*, not promoted to the top level.
148
+
149
+ If you want multiple fields, use the function form:
150
+
151
+ ```js
152
+ output: (childState) => ({
153
+ doubled: childState.double.doubled,
154
+ echoed: childState.value,
155
+ isDouble: childState.double.doubled === childState.value * 2,
156
+ }),
157
+ // → state.audit = { doubled: 42, echoed: 21, isDouble: true }
158
+ ```
159
+
160
+ Or omit `output:` and the entire `childState` lands at `state[nodeName]` — useful when you don't know yet which fields you'll need.
161
+
162
+ ## Schema validation at the boundary
163
+
164
+ The server runs the same input gate sub-graph triggers hit as user-initiated ones. If the parent's `input:` callback returns a value that doesn't satisfy the child's `stateSchema`, the trigger 400s **before** any Fargate spawn — no wasted compute. The parent's sub-graph node throws a typed error with the missing fields listed.
165
+
166
+ ## Errors
167
+
168
+ Sub-graph failures throw with a `code` field so you can branch:
169
+
170
+ | `err.code` | Meaning | Useful properties |
171
+ |---|---|---|
172
+ | `SUBGRAPH_INVALID_INPUT` | Parent's `input:` produced data that violates the child's stateSchema | `err.missing[]`, `err.validationErrors` |
173
+ | `SUBGRAPH_QUOTA_EXCEEDED` | Account is over its execution cap; child can't dispatch | `err.quotaInfo` |
174
+ | `SUBGRAPH_TRIGGER_FAILED` | Any other HTTP failure from the trigger endpoint | `err.status` |
175
+
176
+ Sync-mode terminal failures (child completed in `failed` / `canceled` / `timeout`):
177
+
178
+ ```js
179
+ err.subgraphJobId // child's executionId — look up in activity tab
180
+ err.subgraphStatus // 'failed' | 'canceled' | 'timeout'
181
+ ```
182
+
183
+ `retries:` on the sub-graph node re-runs the whole dispatch (trigger + poll) on transient failures, same semantics as a regular node retry.
184
+
185
+ ## What's deployed vs what you write
186
+
187
+ You only ever reference workflows by **name**. The cloud handles the UUID resolution.
188
+
189
+ | Stage | What you write | What the backend does |
190
+ |---|---|---|
191
+ | `zibby workflow deploy child-doubler` | nothing about UUIDs | mints UUID, stores `(projectId, workflowType='child-doubler', uuid='…')` |
192
+ | `subgraph('child-doubler')` in parent code | just the name | stored as a string in the parent's graph definition |
193
+ | `zibby workflow deploy parent-orchestrator` | nothing | looks up `'child-doubler'` → UUID, snapshots the dependency |
194
+ | Parent runs in Fargate → hits sub-graph node | nothing | POSTs to `/workflows/<uuid>/trigger` with `parentExecutionId` |
195
+
196
+ Names are unique per project (DDB primary key enforces this), so `subgraph('child-doubler')` resolves unambiguously within the parent's project.
197
+
198
+ ## Activity-tab tree-view
199
+
200
+ Each child execution row carries `parentExecutionId` pointing at the parent. The activity tab uses this to render parent runs as collapsible groups — expand to see the chain of children.
201
+
202
+ | Row | `parentExecutionId` | Type |
203
+ |---|---|---|
204
+ | Parent (orchestrator) | `null` | top-level (user-triggered) |
205
+ | Child (doubler) | `<parent's executionId>` | dispatched as sub-graph |
206
+
207
+ ## Local development
208
+
209
+ Sub-graph dispatch needs the `PROGRESS_API_URL` env var (the public API base). That's set automatically on Fargate runs. For local dev, you have two options:
210
+
211
+ 1. **Deploy both workflows to cloud, then trigger the parent.** The cloud path always works.
212
+ 2. **Mock the trigger + status endpoints locally.** See [`workflows/parent-orchestrator/mock-server.mjs`](https://github.com/ZibbyHQ/agent-workflow/tree/main/examples) in the agent-workflow repo for a 90-line example that simulates the dispatch + poll loop.
213
+
214
+ In-process sub-graph execution (running the child in the parent's Node process directly, no HTTP) is **not supported** — we picked consistency between local and cloud over the 10s spawn-time savings.
215
+
216
+ ## Cross-project sub-graphs
217
+
218
+ `workflow: 'name'` resolves within the parent's own project. To call another project's workflow, pass an explicit project ID:
219
+
220
+ ```js
221
+ g.addNode('audit', {
222
+ workflow: 'shared-audit',
223
+ project: 'b6219c3a-…', // explicit cross-project reference
224
+ });
225
+ ```
226
+
227
+ The caller must have access to the destination project (same account, or invited). Cross-**account** sub-graphs are not in v1.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/skills",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Built-in skill definitions for Zibby test automation framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",