@zibby/skills 0.1.37 → 0.1.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/skills",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
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,90 @@
1
+ export namespace reviewMemorySkill {
2
+ let id: string;
3
+ let serverName: string;
4
+ let allowedTools: string[];
5
+ let description: string;
6
+ let promptFragment: string;
7
+ function resolve(): {
8
+ command: any;
9
+ args: any[];
10
+ env: {};
11
+ description: string;
12
+ type?: undefined;
13
+ alwaysLoad?: undefined;
14
+ } | {
15
+ type: string;
16
+ command: string;
17
+ args: any[];
18
+ env: {};
19
+ description: string;
20
+ alwaysLoad: boolean;
21
+ };
22
+ function handleToolCall(name: any, args: any): Promise<string>;
23
+ let tools: ({
24
+ name: string;
25
+ description: string;
26
+ input_schema: {
27
+ type: string;
28
+ properties: {
29
+ scope: {
30
+ type: string;
31
+ description: string;
32
+ };
33
+ query: {
34
+ type: string;
35
+ description: string;
36
+ };
37
+ scopePrefix?: undefined;
38
+ content?: undefined;
39
+ metadata?: undefined;
40
+ headSha?: undefined;
41
+ };
42
+ required: string[];
43
+ };
44
+ } | {
45
+ name: string;
46
+ description: string;
47
+ input_schema: {
48
+ type: string;
49
+ properties: {
50
+ scopePrefix: {
51
+ type: string;
52
+ description: string;
53
+ };
54
+ scope?: undefined;
55
+ query?: undefined;
56
+ content?: undefined;
57
+ metadata?: undefined;
58
+ headSha?: undefined;
59
+ };
60
+ required: string[];
61
+ };
62
+ } | {
63
+ name: string;
64
+ description: string;
65
+ input_schema: {
66
+ type: string;
67
+ properties: {
68
+ scope: {
69
+ type: string;
70
+ description: string;
71
+ };
72
+ content: {
73
+ type: string;
74
+ description: string;
75
+ };
76
+ metadata: {
77
+ type: string;
78
+ description: string;
79
+ };
80
+ headSha: {
81
+ type: string;
82
+ description: string;
83
+ };
84
+ query?: undefined;
85
+ scopePrefix?: undefined;
86
+ };
87
+ required: string[];
88
+ };
89
+ })[];
90
+ }
@@ -0,0 +1,18 @@
1
+ import{existsSync as s,readFileSync as c}from"node:fs";import{homedir as p}from"node:os";import{join as l,dirname as d,resolve as m}from"node:path";import{fileURLToPath as u}from"node:url";function f(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let o=d(u(import.meta.url)),e=m(o,"..","bin","mcp-skill.mjs");return s(e)?e:null}function w(){if(process.env.PROJECT_API_TOKEN)return process.env.PROJECT_API_TOKEN;if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let o=l(p(),".zibby","config.json");return s(o)&&JSON.parse(c(o,"utf-8")).sessionToken||null}catch{return null}}function y(){return process.env.ZIBBY_ACCOUNT_API_URL?process.env.ZIBBY_ACCOUNT_API_URL.replace(/\/$/,""):(process.env.ZIBBY_ENV||"prod")==="local"?"http://localhost:3001":process.env.ZIBBY_PROD_ACCOUNT_API_URL||"https://api-prod.zibby.app"}async function n(o,e){let r=w();if(!r)throw new Error("No backend credential (PROJECT_API_TOKEN). Review memory is only available inside a Zibby run.");let t=`${y()}/memory/review`,i=await fetch(t,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify({op:o,...e})});if(!i.ok){let a=await i.text().catch(()=>"");throw new Error(`Review memory ${o} failed (${i.status}): ${a.slice(0,300)}`)}return i.json()}var g={id:"review-memory",serverName:"review_memory",allowedTools:["mcp__review_memory__*"],description:"Review memory \u2014 persist & recall per-PR (configurable-scope) review notes across stateless runs",promptFragment:`## Review Memory (per-PR, configurable scope)
2
+ Persist what you pulled, found, and reasoned during a review so a FOLLOW-UP
3
+ run (a fresh stateless task replying on the same PR) can recall it. Storage is
4
+ keyed by a \`scope\` STRING you choose \u2014 nothing is hardcoded to per-PR:
5
+ - per-PR: scope = "review:owner/repo#<prNumber>" (the usual choice)
6
+ - per-repo: scope = "repo:owner/repo"
7
+ - per-org: scope = "org:owner"
8
+ Same tools, different scope string \u2014 pick the granularity you need.
9
+
10
+ Tools:
11
+ - review_memory_recall: At the START of a review, recall any prior note for
12
+ this PR's scope (e.g. "review:owner/repo#42"). If found, build on it instead
13
+ of re-deriving everything.
14
+ - review_memory_recall_prefix: List notes whose scope starts with a prefix
15
+ (e.g. "review:owner/repo#") \u2014 e.g. to see prior reviews across a repo.
16
+ - review_memory_store: At the END (or when you learn something durable), store
17
+ a concise note under the PR's scope. Pass headSha so a later run knows which
18
+ commit the note describes. Overwrites the prior note for that exact scope.`,resolve(){let o=f();if(!o)return{command:null,args:[],env:{},description:this.description};let e={};for(let r of["PROJECT_API_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV","ZIBBY_PROD_ACCOUNT_API_URL","ZIBBY_USER_TOKEN"])process.env[r]&&(e[r]=process.env[r]);return{type:"stdio",command:"node",args:[o,"../dist/reviewMemory.js","reviewMemorySkill"],env:e,description:this.description,alwaysLoad:!0}},async handleToolCall(o,e){try{switch(o){case"review_memory_recall":{let r=typeof e?.scope=="string"?e.scope.trim():"";if(!r)return JSON.stringify({error:"scope is required"});let t=await n("recall",{scope:r});return JSON.stringify(t)}case"review_memory_recall_prefix":{let r=typeof e?.scopePrefix=="string"?e.scopePrefix.trim():"";if(!r)return JSON.stringify({error:"scopePrefix is required"});let t=await n("recall-prefix",{scopePrefix:r});return JSON.stringify(t)}case"review_memory_store":{let r=typeof e?.scope=="string"?e.scope.trim():"";if(!r)return JSON.stringify({error:"scope is required"});if(typeof e?.content!="string"||e.content.length===0)return JSON.stringify({error:"content is required (non-empty string)"});let t={scope:r,content:e.content};e.metadata!=null&&(t.metadata=e.metadata),e.headSha!=null&&(t.headSha=String(e.headSha));let i=await n("store",t);return JSON.stringify(i)}default:return JSON.stringify({error:`Unknown tool: ${o}`})}}catch(r){return JSON.stringify({error:r.message})}},tools:[{name:"review_memory_recall",description:'Recall the prior review note for a scope (exact match). Use at the start of a review to build on what an earlier run pulled/found/reasoned. scope is the storage key \u2014 e.g. "review:owner/repo#42" for per-PR.',input_schema:{type:"object",properties:{scope:{type:"string",description:'Storage key. Per-PR: "review:owner/repo#<prNumber>". Per-repo: "repo:owner/repo". Per-org: "org:owner". Or any custom string.'},query:{type:"string",description:"Optional free-text hint (reserved for future semantic recall; v1 ignores it \u2014 recall is exact-scope)."}},required:["scope"]}},{name:"review_memory_recall_prefix",description:'List review notes whose scope STARTS WITH a prefix (e.g. "review:owner/repo#" to see all prior PR reviews in a repo). Capped at 25 most-relevant.',input_schema:{type:"object",properties:{scopePrefix:{type:"string",description:'Scope prefix to match, e.g. "review:owner/repo#" or "repo:owner/".'}},required:["scopePrefix"]}},{name:"review_memory_store",description:"Store (overwrite) the review note for a scope so a follow-up run can recall it. Write a concise summary of what you pulled, found, and reasoned. Pass headSha so a later run knows which commit the note describes.",input_schema:{type:"object",properties:{scope:{type:"string",description:'Storage key. Per-PR: "review:owner/repo#<prNumber>". Or per-repo/per-org/custom. Same key you recall by.'},content:{type:"string",description:"The note: what was pulled, what was found, the reasoning. Free-form markdown/text."},metadata:{type:"object",description:"Optional structured metadata (e.g. {filesReviewed, verdict, severity})."},headSha:{type:"string",description:"Optional PR head commit SHA this note describes \u2014 lets a later run detect new commits."}},required:["scope","content"]}}]};export{g as reviewMemorySkill};
@@ -1,4 +1,4 @@
1
- import{existsSync as J}from"fs";import{fileURLToPath as I}from"url";import{dirname as H,resolve as L}from"path";import{resolveIntegrationToken as C}from"@zibby/core/backend-client.js";var v=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",PLANE:"plane",LINEAR:"linear"}),B=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"}});function j(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let a=H(I(import.meta.url)),o=L(a,"..","bin","mcp-skill.mjs");return J(o)?o:null}async function d(a,o={}){let{token:t}=await C("github"),r=a.startsWith("https://")?a:`https://api.github.com${a}`,i={Authorization:`Bearer ${t}`,Accept:o.accept||"application/vnd.github.v3+json","User-Agent":"Zibby-App",...o.body?{"Content-Type":"application/json"}:{}},e=await fetch(r,{method:o.method||"GET",headers:i,body:o.body?JSON.stringify(o.body):void 0});if(!e.ok){let n=await e.text().catch(()=>"");throw new Error(`GitHub API ${e.status}: ${n.slice(0,300)}`)}return o.raw?e.text():e.json()}var _={id:"github",serverName:"github",allowedTools:["mcp__github__*"],requiresIntegration:v.GITHUB,envKeys:["GITHUB_TOKEN"],description:"GitHub \u2014 issues, PRs, commits, code search, file reading",promptFragment:`## GitHub (connected)
1
+ import{existsSync as J}from"fs";import{fileURLToPath as I}from"url";import{dirname as H,resolve as L}from"path";import{resolveIntegrationToken as C}from"@zibby/core/backend-client.js";var v=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",PLANE:"plane",LINEAR:"linear"}),B=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"}});function j(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let a=H(I(import.meta.url)),o=L(a,"..","bin","mcp-skill.mjs");return J(o)?o:null}async function d(a,o={}){let{token:t}=await C("github"),r=a.startsWith("https://")?a:`https://api.github.com${a}`,i={Authorization:`Bearer ${t}`,Accept:o.accept||"application/vnd.github.v3+json","User-Agent":"Zibby-App",...o.body?{"Content-Type":"application/json"}:{}},e=await fetch(r,{method:o.method||"GET",headers:i,body:o.body?JSON.stringify(o.body):void 0});if(!e.ok){let s=await e.text().catch(()=>"");throw new Error(`GitHub API ${e.status}: ${s.slice(0,300)}`)}return o.raw?e.text():e.json()}var _={id:"github",serverName:"github",allowedTools:["mcp__github__*"],requiresIntegration:v.GITHUB,envKeys:["GITHUB_TOKEN"],description:"GitHub \u2014 issues, PRs, commits, code search, file reading",promptFragment:`## GitHub (connected)
2
2
  You have access to the user's GitHub repositories. Available tools:
3
3
 
4
4
  ### Discovery
@@ -36,6 +36,6 @@ When user says "check out repo-name" or "clone repo-name":
36
36
  3. STOP. Do not offer to inspect files or ask what to do next.
37
37
 
38
38
  When user just wants to "look at" or "read" files (not clone):
39
- - Use github_get_file to read individual files via API`,resolve(){let a=j();if(!a)return{command:null,args:[],env:{},description:this.description};let o={};for(let t of this.envKeys)process.env[t]&&(o[t]=process.env[t]);return{type:"stdio",command:"node",args:[a,"../dist/github.js","githubSkill"],env:o,description:this.description,alwaysLoad:!0}},async handleToolCall(a,o){try{switch(a){case"github_search_issues":{let t=o.query;if(!t)return JSON.stringify({error:"query is required"});let r=await d(`/search/issues?q=${encodeURIComponent(t)}&per_page=${o.limit||20}`),i=(r.items||[]).map(e=>({number:e.number,title:e.title,state:e.state,repo:e.repository_url?.split("/").slice(-2).join("/"),url:e.html_url,user:e.user?.login,isPR:!!e.pull_request,labels:(e.labels||[]).map(n=>n.name),createdAt:e.created_at}));return JSON.stringify({total:r.total_count,items:i})}case"github_search_code":{let t=o.query;if(!t)return JSON.stringify({error:"query is required"});let r=o.repo?`+repo:${o.repo}`:"",i=o.language?`+language:${o.language}`:"",e=await d(`/search/code?q=${encodeURIComponent(t)}${r}${i}&per_page=${o.limit||15}`),n=(e.items||[]).map(s=>({name:s.name,path:s.path,repo:s.repository?.full_name,url:s.html_url,score:s.score}));return JSON.stringify({total:e.total_count,items:n})}case"github_get_pr":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}`);return JSON.stringify({number:e.number,title:e.title,state:e.state,merged:e.merged,body:e.body?.slice(0,5e3),user:e.user?.login,branch:e.head?.ref,base:e.base?.ref,changedFiles:e.changed_files,additions:e.additions,deletions:e.deletions,createdAt:e.created_at,mergedAt:e.merged_at,url:e.html_url,labels:(e.labels||[]).map(n=>n.name)})}case"github_get_pr_diff":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}`,{accept:"application/vnd.github.v3.diff",raw:!0}),n=e.length>15e3;return JSON.stringify({number:i,diff:n?e.slice(0,15e3):e,truncated:n,totalLength:e.length})}case"github_list_pr_files":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}/files?per_page=100`);return JSON.stringify({total:e.length,files:e.map(n=>({filename:n.filename,status:n.status,additions:n.additions,deletions:n.deletions,patch:n.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}/comments?per_page=50`),n=await d(`/repos/${t}/${r}/issues/${i}/comments?per_page=50`),s=[...e.map(p=>({type:"review",user:p.user?.login,body:p.body?.slice(0,1e3),path:p.path,line:p.line,createdAt:p.created_at})),...n.map(p=>({type:"issue",user:p.user?.login,body:p.body?.slice(0,1e3),createdAt:p.created_at}))].sort((p,u)=>new Date(p.createdAt)-new Date(u.createdAt));return JSON.stringify({total:s.length,comments:s})}case"github_create_review":{let{owner:t,repo:r,number:i,body:e,event:n,comments:s}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let p=(n||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(p))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${n})`});let u=Array.isArray(s)?s.filter(g=>g&&g.path&&g.body&&(g.line!=null||g.position!=null)).map(g=>{let f={path:g.path,body:String(g.body)};return g.line!=null?(f.line=Number(g.line),f.side=g.side==="LEFT"?"LEFT":"RIGHT"):f.position=Number(g.position),f}):[];if(p!=="APPROVE"&&!e&&u.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let m={event:p};e&&(m.body=String(e)),u.length>0&&(m.comments=u);let c=await d(`/repos/${t}/${r}/pulls/${i}/reviews`,{method:"POST",body:m});return JSON.stringify({ok:!0,id:c.id,state:c.state,event:p,commentsPosted:u.length,url:c.html_url})}case"github_list_commits":{let{owner:t,repo:r,branch:i,path:e,limit:n}=o;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let s=`/repos/${t}/${r}/commits?per_page=${n||20}`;i&&(s+=`&sha=${encodeURIComponent(i)}`),e&&(s+=`&path=${encodeURIComponent(e)}`);let p=await d(s);return JSON.stringify({total:p.length,commits:p.map(u=>({sha:u.sha?.slice(0,8),fullSha:u.sha,message:u.commit?.message?.slice(0,300),author:u.commit?.author?.name,date:u.commit?.author?.date,url:u.html_url}))})}case"github_get_commit":{let{owner:t,repo:r,sha:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and sha are required"});let e=await d(`/repos/${t}/${r}/commits/${i}`);return JSON.stringify({sha:e.sha?.slice(0,8),message:e.commit?.message,author:e.commit?.author?.name,date:e.commit?.author?.date,stats:e.stats,files:(e.files||[]).map(n=>({filename:n.filename,status:n.status,additions:n.additions,deletions:n.deletions,patch:n.patch?.slice(0,3e3)}))})}case"github_get_file":{let{owner:t,repo:r,path:i,ref:e}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and path are required"});let n=`/repos/${t}/${r}/contents/${encodeURIComponent(i)}`;e&&(n+=`?ref=${encodeURIComponent(e)}`);let s=await d(n);if(s.type!=="file")return Array.isArray(s)?JSON.stringify({type:"directory",path:i,entries:s.map(m=>({name:m.name,type:m.type,size:m.size,path:m.path}))}):JSON.stringify({error:`Not a file: ${s.type}`});let p=Buffer.from(s.content||"","base64").toString("utf-8"),u=p.length>2e4;return JSON.stringify({path:s.path,size:s.size,sha:s.sha?.slice(0,8),content:u?p.slice(0,2e4):p,truncated:u})}case"github_get_user":try{let t=await d("/installation/repositories?per_page=1");if(t.repositories&&t.repositories.length>0){let r=t.repositories[0],i=r.owner.login,e=r.owner.type,n=e==="Organization"?`/orgs/${i}`:`/users/${i}`,s=await d(n);return JSON.stringify({login:s.login,name:s.name||s.login,avatar:s.avatar_url,bio:s.bio||s.description,type:e,isOrg:e==="Organization",publicRepos:s.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(t){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${t.message})`})}case"github_list_orgs":try{let r=(await d("/installation/repositories?per_page=100")).repositories||[],i=new Map;for(let n of r)n.owner.type==="Organization"&&(i.has(n.owner.login)||i.set(n.owner.login,{login:n.owner.login,description:null,url:n.owner.url}));let e=Array.from(i.values());return JSON.stringify({count:e.length,orgs:e,message:"Extracted from accessible repositories (GitHub Apps cannot access /user/orgs directly)"})}catch(t){return JSON.stringify({error:`GitHub App cannot list orgs via /user/orgs. Error: ${t.message}`})}case"github_clone":{let l=function(w){let R=w.replace(/^~(?=$|\/|\\)/,f);return s(R)},{owner:t,repo:r,destination:i}=o;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let{execSync:e}=await import("child_process"),{join:n,resolve:s}=await import("path"),{existsSync:p,mkdirSync:u}=await import("fs"),{homedir:m,platform:c}=await import("os"),{token:g}=await C("github"),f=m(),y=i?l(i):n(f,"zibby-repos"),h=n(y,r);if(u(y,{recursive:!0}),p(h))return JSON.stringify({error:`Directory ${h} already exists. Remove it first or use a different destination.`,existingPath:h});try{let w=`https://x-access-token:${g}@github.com/${t}/${r}.git`;e(`git clone ${w} "${h}"`,{stdio:"pipe"});let R=c()==="win32",b;return R?b=e(`dir "${h}"`,{encoding:"utf-8",shell:"cmd.exe"}):b=e(`ls -la "${h}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:h,message:`Cloned ${t}/${r} to ${h}`,contents:b.split(`
39
+ - Use github_get_file to read individual files via API`,resolve(){let a=j();if(!a)return{command:null,args:[],env:{},description:this.description};let o={};for(let t of this.envKeys)process.env[t]&&(o[t]=process.env[t]);return{type:"stdio",command:"node",args:[a,"../dist/github.js","githubSkill"],env:o,description:this.description,alwaysLoad:!0}},async handleToolCall(a,o){try{switch(a){case"github_search_issues":{let t=o.query;if(!t)return JSON.stringify({error:"query is required"});let r=await d(`/search/issues?q=${encodeURIComponent(t)}&per_page=${o.limit||20}`),i=(r.items||[]).map(e=>({number:e.number,title:e.title,state:e.state,repo:e.repository_url?.split("/").slice(-2).join("/"),url:e.html_url,user:e.user?.login,isPR:!!e.pull_request,labels:(e.labels||[]).map(s=>s.name),createdAt:e.created_at}));return JSON.stringify({total:r.total_count,items:i})}case"github_search_code":{let t=o.query;if(!t)return JSON.stringify({error:"query is required"});let r=o.repo?`+repo:${o.repo}`:"",i=o.language?`+language:${o.language}`:"",e=await d(`/search/code?q=${encodeURIComponent(t)}${r}${i}&per_page=${o.limit||15}`),s=(e.items||[]).map(n=>({name:n.name,path:n.path,repo:n.repository?.full_name,url:n.html_url,score:n.score}));return JSON.stringify({total:e.total_count,items:s})}case"github_get_pr":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}`);return JSON.stringify({number:e.number,title:e.title,state:e.state,merged:e.merged,body:e.body?.slice(0,5e3),user:e.user?.login,branch:e.head?.ref,headSha:e.head?.sha,base:e.base?.ref,changedFiles:e.changed_files,additions:e.additions,deletions:e.deletions,createdAt:e.created_at,mergedAt:e.merged_at,url:e.html_url,labels:(e.labels||[]).map(s=>s.name)})}case"github_get_pr_diff":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}`,{accept:"application/vnd.github.v3.diff",raw:!0}),s=e.length>15e3;return JSON.stringify({number:i,diff:s?e.slice(0,15e3):e,truncated:s,totalLength:e.length})}case"github_list_pr_files":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}/files?per_page=100`);return JSON.stringify({total:e.length,files:e.map(s=>({filename:s.filename,status:s.status,additions:s.additions,deletions:s.deletions,patch:s.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}/comments?per_page=50`),s=await d(`/repos/${t}/${r}/issues/${i}/comments?per_page=50`),n=[...e.map(p=>({type:"review",user:p.user?.login,body:p.body?.slice(0,1e3),path:p.path,line:p.line,createdAt:p.created_at})),...s.map(p=>({type:"issue",user:p.user?.login,body:p.body?.slice(0,1e3),createdAt:p.created_at}))].sort((p,u)=>new Date(p.createdAt)-new Date(u.createdAt));return JSON.stringify({total:n.length,comments:n})}case"github_create_review":{let{owner:t,repo:r,number:i,body:e,event:s,comments:n}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let p=(s||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(p))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${s})`});let u=Array.isArray(n)?n.filter(g=>g&&g.path&&g.body&&(g.line!=null||g.position!=null)).map(g=>{let f={path:g.path,body:String(g.body)};return g.line!=null?(f.line=Number(g.line),f.side=g.side==="LEFT"?"LEFT":"RIGHT"):f.position=Number(g.position),f}):[];if(p!=="APPROVE"&&!e&&u.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let m={event:p};e&&(m.body=String(e)),u.length>0&&(m.comments=u);let c=await d(`/repos/${t}/${r}/pulls/${i}/reviews`,{method:"POST",body:m});return JSON.stringify({ok:!0,id:c.id,state:c.state,event:p,commentsPosted:u.length,url:c.html_url})}case"github_list_commits":{let{owner:t,repo:r,branch:i,path:e,limit:s}=o;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let n=`/repos/${t}/${r}/commits?per_page=${s||20}`;i&&(n+=`&sha=${encodeURIComponent(i)}`),e&&(n+=`&path=${encodeURIComponent(e)}`);let p=await d(n);return JSON.stringify({total:p.length,commits:p.map(u=>({sha:u.sha?.slice(0,8),fullSha:u.sha,message:u.commit?.message?.slice(0,300),author:u.commit?.author?.name,date:u.commit?.author?.date,url:u.html_url}))})}case"github_get_commit":{let{owner:t,repo:r,sha:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and sha are required"});let e=await d(`/repos/${t}/${r}/commits/${i}`);return JSON.stringify({sha:e.sha?.slice(0,8),message:e.commit?.message,author:e.commit?.author?.name,date:e.commit?.author?.date,stats:e.stats,files:(e.files||[]).map(s=>({filename:s.filename,status:s.status,additions:s.additions,deletions:s.deletions,patch:s.patch?.slice(0,3e3)}))})}case"github_get_file":{let{owner:t,repo:r,path:i,ref:e}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and path are required"});let s=`/repos/${t}/${r}/contents/${encodeURIComponent(i)}`;e&&(s+=`?ref=${encodeURIComponent(e)}`);let n=await d(s);if(n.type!=="file")return Array.isArray(n)?JSON.stringify({type:"directory",path:i,entries:n.map(m=>({name:m.name,type:m.type,size:m.size,path:m.path}))}):JSON.stringify({error:`Not a file: ${n.type}`});let p=Buffer.from(n.content||"","base64").toString("utf-8"),u=p.length>2e4;return JSON.stringify({path:n.path,size:n.size,sha:n.sha?.slice(0,8),content:u?p.slice(0,2e4):p,truncated:u})}case"github_get_user":try{let t=await d("/installation/repositories?per_page=1");if(t.repositories&&t.repositories.length>0){let r=t.repositories[0],i=r.owner.login,e=r.owner.type,s=e==="Organization"?`/orgs/${i}`:`/users/${i}`,n=await d(s);return JSON.stringify({login:n.login,name:n.name||n.login,avatar:n.avatar_url,bio:n.bio||n.description,type:e,isOrg:e==="Organization",publicRepos:n.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(t){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${t.message})`})}case"github_list_orgs":try{let r=(await d("/installation/repositories?per_page=100")).repositories||[],i=new Map;for(let s of r)s.owner.type==="Organization"&&(i.has(s.owner.login)||i.set(s.owner.login,{login:s.owner.login,description:null,url:s.owner.url}));let e=Array.from(i.values());return JSON.stringify({count:e.length,orgs:e,message:"Extracted from accessible repositories (GitHub Apps cannot access /user/orgs directly)"})}catch(t){return JSON.stringify({error:`GitHub App cannot list orgs via /user/orgs. Error: ${t.message}`})}case"github_clone":{let l=function(w){let R=w.replace(/^~(?=$|\/|\\)/,f);return n(R)},{owner:t,repo:r,destination:i}=o;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let{execSync:e}=await import("child_process"),{join:s,resolve:n}=await import("path"),{existsSync:p,mkdirSync:u}=await import("fs"),{homedir:m,platform:c}=await import("os"),{token:g}=await C("github"),f=m(),y=i?l(i):s(f,"zibby-repos"),h=s(y,r);if(u(y,{recursive:!0}),p(h))return JSON.stringify({error:`Directory ${h} already exists. Remove it first or use a different destination.`,existingPath:h});try{let w=`https://x-access-token:${g}@github.com/${t}/${r}.git`;e(`git clone ${w} "${h}"`,{stdio:"pipe"});let R=c()==="win32",b;return R?b=e(`dir "${h}"`,{encoding:"utf-8",shell:"cmd.exe"}):b=e(`ls -la "${h}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:h,message:`Cloned ${t}/${r} to ${h}`,contents:b.split(`
40
40
  `).slice(0,30).join(`
41
- `),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(w){return JSON.stringify({error:`Clone failed: ${w.message}`})}}case"github_search_repos":{let{query:t,limit:r}=o;if(!t)return JSON.stringify({error:"query is required"});let i=await this.handleToolCall("github_list_repos",{limit:200},{}),e=JSON.parse(i);if(e.error)return JSON.stringify(e);let n=t.toLowerCase(),s=e.repos.filter(p=>p.name.toLowerCase().includes(n)||p.fullName.toLowerCase().includes(n)||p.description&&p.description.toLowerCase().includes(n));return JSON.stringify({query:t,count:s.length,repos:s.slice(0,r||20)})}case"github_list_repos":{let{owner:t,type:r,sort:i,direction:e,limit:n}=o,s=100,p=n||200,u=[];if(!t){let l=1,y=!0;for(;y&&u.length<p;){let b=`/installation/repositories?per_page=${s}&page=${l}`,N=(await d(b)).repositories||[];if(N.length===0)break;u=u.concat(N),y=N.length===s,l++}let h=u.slice(0,p).map(b=>({name:b.name,fullName:b.full_name,private:b.private,description:b.description,language:b.language,defaultBranch:b.default_branch,updatedAt:b.updated_at,stars:b.stargazers_count,url:b.html_url})),w=h.filter(b=>b.private).length,R=h.filter(b=>!b.private).length;return JSON.stringify({count:h.length,repos:h,privateCount:w,publicCount:R,message:`Found ${w} private and ${R} public repos`})}let m=await d(`/orgs/${t}`).then(()=>!0).catch(()=>!1),c=1,g=!0;for(;g&&u.length<p;){let l;m?l=`/orgs/${t}/repos?per_page=${s}&page=${c}&type=${r||"all"}&sort=${i||"updated"}&direction=${e||"desc"}`:l=`/users/${t}/repos?per_page=${s}&page=${c}&type=${r||"all"}&sort=${i||"updated"}&direction=${e||"desc"}`;let y=await d(l),h=Array.isArray(y)?y:[];if(h.length===0)break;u=u.concat(h),g=h.length===s,c++}let f=u.slice(0,p).map(l=>({name:l.name,fullName:l.full_name,private:l.private,description:l.description,language:l.language,defaultBranch:l.default_branch,updatedAt:l.updated_at,stars:l.stargazers_count,url:l.html_url}));return JSON.stringify({count:f.length,repos:f})}case"github_create_issue":{let{owner:t,repo:r,title:i,body:e}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and title are required"});let n=await d(`/repos/${t}/${r}/issues`,{method:"POST",body:{title:i,body:e||""}});return JSON.stringify({number:n.number,url:n.html_url,title:n.title})}case"github_list_issues":{let{owner:t,repo:r,state:i,labels:e,since:n,assignee:s,sort:p,direction:u,limit:m}=o||{};if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let c=new URLSearchParams;c.set("state",i||"open"),c.set("per_page",String(m||30)),c.set("sort",p||"updated"),c.set("direction",u||"desc"),e&&c.set("labels",Array.isArray(e)?e.join(","):e),n&&c.set("since",n),s&&c.set("assignee",s);let g=await d(`/repos/${t}/${r}/issues?${c.toString()}`),f=(Array.isArray(g)?g:[]).filter(l=>!l.pull_request).map(l=>({number:l.number,title:l.title,state:l.state,labels:(l.labels||[]).map(y=>typeof y=="string"?y:y.name),assignee:l.assignee?.login||null,assignees:(l.assignees||[]).map(y=>y.login),user:l.user?.login,comments:l.comments,url:l.html_url,createdAt:l.created_at,updatedAt:l.updated_at}));return JSON.stringify({count:f.length,issues:f})}case"github_get_issue":{let{owner:t,repo:r,number:i}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/issues/${i}`);return e.pull_request?JSON.stringify({error:`#${i} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:e.number,title:e.title,body:e.body||"",state:e.state,stateReason:e.state_reason||null,labels:(e.labels||[]).map(n=>typeof n=="string"?n:n.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(n=>n.login),user:e.user?.login,milestone:e.milestone?.title||null,comments:e.comments,url:e.html_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"github_get_issue_comments":{let{owner:t,repo:r,number:i,limit:e}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let n=await d(`/repos/${t}/${r}/issues/${i}/comments?per_page=${e||100}`),s=(Array.isArray(n)?n:[]).map(p=>({id:p.id,user:p.user?.login,body:p.body||"",createdAt:p.created_at,updatedAt:p.updated_at,url:p.html_url}));return JSON.stringify({count:s.length,comments:s})}case"github_add_issue_comment":{let{owner:t,repo:r,number:i,body:e}=o||{};if(!t||!r||!i||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let n=await d(`/repos/${t}/${r}/issues/${i}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:n.id,url:n.html_url})}case"github_close_issue":{let{owner:t,repo:r,number:i,stateReason:e}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let n={state:"closed"};e&&(n.state_reason=e);let s=await d(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:n});return JSON.stringify({ok:!0,number:s.number,state:s.state,stateReason:s.state_reason||null,url:s.html_url})}case"github_reopen_issue":{let{owner:t,repo:r,number:i}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:e.number,state:e.state,url:e.html_url})}case"github_label_issue":{let{owner:t,repo:r,number:i,labels:e,mode:n}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let s=Array.isArray(e)?e:e?[e]:[];if(!s.length)return JSON.stringify({error:"labels (string or array) is required"});let p=n||"add";if(p==="set"){let m=await d(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:{labels:s}});return JSON.stringify({ok:!0,number:m.number,labels:(m.labels||[]).map(c=>typeof c=="string"?c:c.name)})}if(p==="remove"){for(let c of s)await d(`/repos/${t}/${r}/issues/${i}/labels/${encodeURIComponent(c)}`,{method:"DELETE"});let m=await d(`/repos/${t}/${r}/issues/${i}`);return JSON.stringify({ok:!0,number:m.number,labels:(m.labels||[]).map(c=>typeof c=="string"?c:c.name)})}let u=await d(`/repos/${t}/${r}/issues/${i}/labels`,{method:"POST",body:{labels:s}});return JSON.stringify({ok:!0,number:i,labels:(Array.isArray(u)?u:[]).map(m=>typeof m=="string"?m:m.name)})}default:return JSON.stringify({error:`Unknown tool: ${a}`})}}catch(t){return JSON.stringify({error:t.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_create_review",description:"Post a review on a pull request: a summary body plus optional inline comments anchored to file/line, with an event (COMMENT, APPROVE, or REQUEST_CHANGES). Use this to deliver a code review back to the PR.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},body:{type:"string",description:"The review summary (markdown). Shown as the top-level review comment."},event:{type:"string",enum:["COMMENT","APPROVE","REQUEST_CHANGES"],description:"Review verdict. Default COMMENT (no approval state). Use REQUEST_CHANGES for blocking issues."},comments:{type:"array",description:"Optional inline comments, each anchored to a changed line.",items:{type:"object",properties:{path:{type:"string",description:"File path as it appears in the diff"},line:{type:"number",description:"Line number in the file's NEW version (the right side of the diff)"},side:{type:"string",enum:["LEFT","RIGHT"],description:"RIGHT (new) or LEFT (old). Default RIGHT."},body:{type:"string",description:"The inline comment text (markdown)"}},required:["path","line","body"]}}},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"]}},{name:"github_list_issues",description:"List issues in a repo (excludes pull requests). Filter by state, labels, and an updated-since cursor for polling.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},state:{type:"string",enum:["open","closed","all"],description:"Filter by state (default: open)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},since:{type:"string",description:"ISO-8601 timestamp; only issues updated at/after this (polling cursor)"},assignee:{type:"string",description:'Filter by assignee login, "none", or "*"'},sort:{type:"string",enum:["created","updated","comments"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30, max 100 per page)"}},required:["owner","repo"]}},{name:"github_get_issue",description:"Get a single GitHub issue with full detail (title, body, state, labels, assignee, url)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_get_issue_comments",description:"Get the comment thread on a GitHub issue (chronological)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},limit:{type:"number",description:"Max comments (default: 100)"}},required:["owner","repo","number"]}},{name:"github_add_issue_comment",description:"Add a comment to a GitHub issue. Also the way to record a PR link on an issue (post a markdown link).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},body:{type:"string",description:"Comment body (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_close_issue",description:"Close a GitHub issue. Optionally set the close reason (completed or not_planned).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},stateReason:{type:"string",enum:["completed","not_planned"],description:"Why the issue was closed (optional)"}},required:["owner","repo","number"]}},{name:"github_reopen_issue",description:"Reopen a closed GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_label_issue",description:"Add, set (replace all), or remove labels on a GitHub issue. Labels back state-like transitions on GitHub.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},labels:{type:"array",items:{type:"string"},description:"Label name(s)"},mode:{type:"string",enum:["add","set","remove"],description:"add appends, set replaces all, remove deletes (default: add)"}},required:["owner","repo","number","labels"]}}]};var G=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i,q=/\b(in[\s-]?progress|wip|doing|started|in[\s-]?review|review)\b/i,U=/\b(done|closed|complete|completed|resolved|fixed|merged|shipped)\b/i,M=/\b(todo|to[\s-]?do|open|backlog|reopen|new)\b/i,E="in progress",P="blocked";function k(a,o=[]){if(a==="closed")return"done";if(a!=="open")return"unknown";let t=(o||[]).map(String);return t.some(r=>G.test(r))?"blocked":t.some(r=>q.test(r))?"in_progress":"todo"}function $(a={}){let o=a.owner||process.env.GITHUB_OWNER,t=a.repo||process.env.GITHUB_REPO;if(!o||!t)throw new Error("GitHub scope missing: provide {owner, repo} via ctx or env GITHUB_OWNER / GITHUB_REPO.");return{owner:o,repo:t}}function S(a){let o=JSON.parse(a);if(o&&o.error)throw new Error(o.error);return o}function A(a,o={}){let t=a.labels||[],r=a.number,i=o.owner&&o.repo?`${o.owner}/${o.repo}#${r}`:`#${r}`;return{id:String(r),key:i,title:a.title||"",body:a.body||"",state:a.state||null,stateCategory:k(a.state,t),assignee:a.assignee||a.assignees&&a.assignees[0]||null,url:a.url||null,_raw:a}}var x={id:"github",toStateCategory:k,toNeutral:A,IN_PROGRESS_LABEL:E,BLOCKED_LABEL:P,async listCandidates(a={}){let o=a.ctx||{},{owner:t,repo:r}=$(o);return(S(await _.handleToolCall("github_list_issues",{owner:t,repo:r,state:a.state||"open",labels:a.labels,since:a.updatedAfter,limit:a.limit})).issues||[]).map(e=>A(e,{owner:t,repo:r}))},async getTicket(a,o={}){let{owner:t,repo:r}=$(o),i=O(a);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);let e=JSON.parse(await _.handleToolCall("github_get_issue",{owner:t,repo:r,number:i}));return e.error?null:A(e,{owner:t,repo:r})},async getComments(a,o={}){let{owner:t,repo:r}=$(o),i=O(a);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);return(S(await _.handleToolCall("github_get_issue_comments",{owner:t,repo:r,number:i})).comments||[]).map(n=>({id:String(n.id),author:n.user||"Unknown",body:n.body||"",createdAt:n.createdAt||null,updatedAt:n.updatedAt||null,_raw:n})).sort((n,s)=>String(s.createdAt).localeCompare(String(n.createdAt)))},async addComment(a,o,t={}){let{owner:r,repo:i}=$(t),e=O(a);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);if(!o)throw new Error("body is required");let n=S(await _.handleToolCall("github_add_issue_comment",{owner:r,repo:i,number:e,body:o}));return{ok:!!n.ok,id:n.id?String(n.id):null}},async transition(a,o,t={}){let{owner:r,repo:i}=$(t),e=O(a);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);let n=String(o||"");if(U.test(n)){let s=S(await _.handleToolCall("github_close_issue",{owner:r,repo:i,number:e,stateReason:"completed"}));return{ok:!!s.ok,stateAfter:s.state||"closed",stateCategoryAfter:"done",_raw:s}}if(G.test(n)){await T(r,i,e);let s=S(await _.handleToolCall("github_label_issue",{owner:r,repo:i,number:e,labels:[P],mode:"add"}));return{ok:!!s.ok,stateAfter:"open",stateCategoryAfter:"blocked",via:"label",_raw:s}}if(q.test(n)){await T(r,i,e);let s=S(await _.handleToolCall("github_label_issue",{owner:r,repo:i,number:e,labels:[E],mode:"add"}));return{ok:!!s.ok,stateAfter:"open",stateCategoryAfter:"in_progress",via:"label",_raw:s}}if(M.test(n)){let s=S(await _.handleToolCall("github_reopen_issue",{owner:r,repo:i,number:e}));return{ok:!!s.ok,stateAfter:s.state||"open",stateCategoryAfter:"todo",_raw:s}}return{ok:!1,error:`GitHub issues have no "${o}" state. Representable targets: open/todo, in progress, blocked, done/closed.`}},async linkPullRequest(a,o,t,r={}){let{owner:i,repo:e}=$(r),n=O(a);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);if(!o)throw new Error("prUrl is required");let s=`${t?`${t}: `:"Linked PR: "}${o}`;return{ok:!!S(await _.handleToolCall("github_add_issue_comment",{owner:i,repo:e,number:n,body:s})).ok,via:"comment"}}};async function T(a,o,t){await _.handleToolCall("github_reopen_issue",{owner:a,repo:o,number:t})}function O(a){if(a==null)return null;if(typeof a=="number")return a;let o=/(\d+)\s*$/.exec(String(a));return o?Number(o[1]):null}var X=x;export{X as default,x as githubAdapter};
41
+ `),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(w){return JSON.stringify({error:`Clone failed: ${w.message}`})}}case"github_search_repos":{let{query:t,limit:r}=o;if(!t)return JSON.stringify({error:"query is required"});let i=await this.handleToolCall("github_list_repos",{limit:200},{}),e=JSON.parse(i);if(e.error)return JSON.stringify(e);let s=t.toLowerCase(),n=e.repos.filter(p=>p.name.toLowerCase().includes(s)||p.fullName.toLowerCase().includes(s)||p.description&&p.description.toLowerCase().includes(s));return JSON.stringify({query:t,count:n.length,repos:n.slice(0,r||20)})}case"github_list_repos":{let{owner:t,type:r,sort:i,direction:e,limit:s}=o,n=100,p=s||200,u=[];if(!t){let l=1,y=!0;for(;y&&u.length<p;){let b=`/installation/repositories?per_page=${n}&page=${l}`,N=(await d(b)).repositories||[];if(N.length===0)break;u=u.concat(N),y=N.length===n,l++}let h=u.slice(0,p).map(b=>({name:b.name,fullName:b.full_name,private:b.private,description:b.description,language:b.language,defaultBranch:b.default_branch,updatedAt:b.updated_at,stars:b.stargazers_count,url:b.html_url})),w=h.filter(b=>b.private).length,R=h.filter(b=>!b.private).length;return JSON.stringify({count:h.length,repos:h,privateCount:w,publicCount:R,message:`Found ${w} private and ${R} public repos`})}let m=await d(`/orgs/${t}`).then(()=>!0).catch(()=>!1),c=1,g=!0;for(;g&&u.length<p;){let l;m?l=`/orgs/${t}/repos?per_page=${n}&page=${c}&type=${r||"all"}&sort=${i||"updated"}&direction=${e||"desc"}`:l=`/users/${t}/repos?per_page=${n}&page=${c}&type=${r||"all"}&sort=${i||"updated"}&direction=${e||"desc"}`;let y=await d(l),h=Array.isArray(y)?y:[];if(h.length===0)break;u=u.concat(h),g=h.length===n,c++}let f=u.slice(0,p).map(l=>({name:l.name,fullName:l.full_name,private:l.private,description:l.description,language:l.language,defaultBranch:l.default_branch,updatedAt:l.updated_at,stars:l.stargazers_count,url:l.html_url}));return JSON.stringify({count:f.length,repos:f})}case"github_create_issue":{let{owner:t,repo:r,title:i,body:e}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and title are required"});let s=await d(`/repos/${t}/${r}/issues`,{method:"POST",body:{title:i,body:e||""}});return JSON.stringify({number:s.number,url:s.html_url,title:s.title})}case"github_list_issues":{let{owner:t,repo:r,state:i,labels:e,since:s,assignee:n,sort:p,direction:u,limit:m}=o||{};if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let c=new URLSearchParams;c.set("state",i||"open"),c.set("per_page",String(m||30)),c.set("sort",p||"updated"),c.set("direction",u||"desc"),e&&c.set("labels",Array.isArray(e)?e.join(","):e),s&&c.set("since",s),n&&c.set("assignee",n);let g=await d(`/repos/${t}/${r}/issues?${c.toString()}`),f=(Array.isArray(g)?g:[]).filter(l=>!l.pull_request).map(l=>({number:l.number,title:l.title,state:l.state,labels:(l.labels||[]).map(y=>typeof y=="string"?y:y.name),assignee:l.assignee?.login||null,assignees:(l.assignees||[]).map(y=>y.login),user:l.user?.login,comments:l.comments,url:l.html_url,createdAt:l.created_at,updatedAt:l.updated_at}));return JSON.stringify({count:f.length,issues:f})}case"github_get_issue":{let{owner:t,repo:r,number:i}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/issues/${i}`);return e.pull_request?JSON.stringify({error:`#${i} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:e.number,title:e.title,body:e.body||"",state:e.state,stateReason:e.state_reason||null,labels:(e.labels||[]).map(s=>typeof s=="string"?s:s.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(s=>s.login),user:e.user?.login,milestone:e.milestone?.title||null,comments:e.comments,url:e.html_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"github_get_issue_comments":{let{owner:t,repo:r,number:i,limit:e}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let s=await d(`/repos/${t}/${r}/issues/${i}/comments?per_page=${e||100}`),n=(Array.isArray(s)?s:[]).map(p=>({id:p.id,user:p.user?.login,body:p.body||"",createdAt:p.created_at,updatedAt:p.updated_at,url:p.html_url}));return JSON.stringify({count:n.length,comments:n})}case"github_add_issue_comment":{let{owner:t,repo:r,number:i,body:e}=o||{};if(!t||!r||!i||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let s=await d(`/repos/${t}/${r}/issues/${i}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:s.id,url:s.html_url})}case"github_close_issue":{let{owner:t,repo:r,number:i,stateReason:e}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let s={state:"closed"};e&&(s.state_reason=e);let n=await d(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:s});return JSON.stringify({ok:!0,number:n.number,state:n.state,stateReason:n.state_reason||null,url:n.html_url})}case"github_reopen_issue":{let{owner:t,repo:r,number:i}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:e.number,state:e.state,url:e.html_url})}case"github_label_issue":{let{owner:t,repo:r,number:i,labels:e,mode:s}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let n=Array.isArray(e)?e:e?[e]:[];if(!n.length)return JSON.stringify({error:"labels (string or array) is required"});let p=s||"add";if(p==="set"){let m=await d(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:{labels:n}});return JSON.stringify({ok:!0,number:m.number,labels:(m.labels||[]).map(c=>typeof c=="string"?c:c.name)})}if(p==="remove"){for(let c of n)await d(`/repos/${t}/${r}/issues/${i}/labels/${encodeURIComponent(c)}`,{method:"DELETE"});let m=await d(`/repos/${t}/${r}/issues/${i}`);return JSON.stringify({ok:!0,number:m.number,labels:(m.labels||[]).map(c=>typeof c=="string"?c:c.name)})}let u=await d(`/repos/${t}/${r}/issues/${i}/labels`,{method:"POST",body:{labels:n}});return JSON.stringify({ok:!0,number:i,labels:(Array.isArray(u)?u:[]).map(m=>typeof m=="string"?m:m.name)})}default:return JSON.stringify({error:`Unknown tool: ${a}`})}}catch(t){return JSON.stringify({error:t.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_create_review",description:"Post a review on a pull request: a summary body plus optional inline comments anchored to file/line, with an event (COMMENT, APPROVE, or REQUEST_CHANGES). Use this to deliver a code review back to the PR.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},body:{type:"string",description:"The review summary (markdown). Shown as the top-level review comment."},event:{type:"string",enum:["COMMENT","APPROVE","REQUEST_CHANGES"],description:"Review verdict. Default COMMENT (no approval state). Use REQUEST_CHANGES for blocking issues."},comments:{type:"array",description:"Optional inline comments, each anchored to a changed line.",items:{type:"object",properties:{path:{type:"string",description:"File path as it appears in the diff"},line:{type:"number",description:"Line number in the file's NEW version (the right side of the diff)"},side:{type:"string",enum:["LEFT","RIGHT"],description:"RIGHT (new) or LEFT (old). Default RIGHT."},body:{type:"string",description:"The inline comment text (markdown)"}},required:["path","line","body"]}}},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"]}},{name:"github_list_issues",description:"List issues in a repo (excludes pull requests). Filter by state, labels, and an updated-since cursor for polling.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},state:{type:"string",enum:["open","closed","all"],description:"Filter by state (default: open)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},since:{type:"string",description:"ISO-8601 timestamp; only issues updated at/after this (polling cursor)"},assignee:{type:"string",description:'Filter by assignee login, "none", or "*"'},sort:{type:"string",enum:["created","updated","comments"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30, max 100 per page)"}},required:["owner","repo"]}},{name:"github_get_issue",description:"Get a single GitHub issue with full detail (title, body, state, labels, assignee, url)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_get_issue_comments",description:"Get the comment thread on a GitHub issue (chronological)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},limit:{type:"number",description:"Max comments (default: 100)"}},required:["owner","repo","number"]}},{name:"github_add_issue_comment",description:"Add a comment to a GitHub issue. Also the way to record a PR link on an issue (post a markdown link).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},body:{type:"string",description:"Comment body (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_close_issue",description:"Close a GitHub issue. Optionally set the close reason (completed or not_planned).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},stateReason:{type:"string",enum:["completed","not_planned"],description:"Why the issue was closed (optional)"}},required:["owner","repo","number"]}},{name:"github_reopen_issue",description:"Reopen a closed GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_label_issue",description:"Add, set (replace all), or remove labels on a GitHub issue. Labels back state-like transitions on GitHub.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},labels:{type:"array",items:{type:"string"},description:"Label name(s)"},mode:{type:"string",enum:["add","set","remove"],description:"add appends, set replaces all, remove deletes (default: add)"}},required:["owner","repo","number","labels"]}}]};var G=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i,q=/\b(in[\s-]?progress|wip|doing|started|in[\s-]?review|review)\b/i,U=/\b(done|closed|complete|completed|resolved|fixed|merged|shipped)\b/i,M=/\b(todo|to[\s-]?do|open|backlog|reopen|new)\b/i,E="in progress",P="blocked";function k(a,o=[]){if(a==="closed")return"done";if(a!=="open")return"unknown";let t=(o||[]).map(String);return t.some(r=>G.test(r))?"blocked":t.some(r=>q.test(r))?"in_progress":"todo"}function $(a={}){let o=a.owner||process.env.GITHUB_OWNER,t=a.repo||process.env.GITHUB_REPO;if(!o||!t)throw new Error("GitHub scope missing: provide {owner, repo} via ctx or env GITHUB_OWNER / GITHUB_REPO.");return{owner:o,repo:t}}function S(a){let o=JSON.parse(a);if(o&&o.error)throw new Error(o.error);return o}function A(a,o={}){let t=a.labels||[],r=a.number,i=o.owner&&o.repo?`${o.owner}/${o.repo}#${r}`:`#${r}`;return{id:String(r),key:i,title:a.title||"",body:a.body||"",state:a.state||null,stateCategory:k(a.state,t),assignee:a.assignee||a.assignees&&a.assignees[0]||null,url:a.url||null,_raw:a}}var x={id:"github",toStateCategory:k,toNeutral:A,IN_PROGRESS_LABEL:E,BLOCKED_LABEL:P,async listCandidates(a={}){let o=a.ctx||{},{owner:t,repo:r}=$(o);return(S(await _.handleToolCall("github_list_issues",{owner:t,repo:r,state:a.state||"open",labels:a.labels,since:a.updatedAfter,limit:a.limit})).issues||[]).map(e=>A(e,{owner:t,repo:r}))},async getTicket(a,o={}){let{owner:t,repo:r}=$(o),i=O(a);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);let e=JSON.parse(await _.handleToolCall("github_get_issue",{owner:t,repo:r,number:i}));return e.error?null:A(e,{owner:t,repo:r})},async getComments(a,o={}){let{owner:t,repo:r}=$(o),i=O(a);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);return(S(await _.handleToolCall("github_get_issue_comments",{owner:t,repo:r,number:i})).comments||[]).map(s=>({id:String(s.id),author:s.user||"Unknown",body:s.body||"",createdAt:s.createdAt||null,updatedAt:s.updatedAt||null,_raw:s})).sort((s,n)=>String(n.createdAt).localeCompare(String(s.createdAt)))},async addComment(a,o,t={}){let{owner:r,repo:i}=$(t),e=O(a);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);if(!o)throw new Error("body is required");let s=S(await _.handleToolCall("github_add_issue_comment",{owner:r,repo:i,number:e,body:o}));return{ok:!!s.ok,id:s.id?String(s.id):null}},async transition(a,o,t={}){let{owner:r,repo:i}=$(t),e=O(a);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);let s=String(o||"");if(U.test(s)){let n=S(await _.handleToolCall("github_close_issue",{owner:r,repo:i,number:e,stateReason:"completed"}));return{ok:!!n.ok,stateAfter:n.state||"closed",stateCategoryAfter:"done",_raw:n}}if(G.test(s)){await T(r,i,e);let n=S(await _.handleToolCall("github_label_issue",{owner:r,repo:i,number:e,labels:[P],mode:"add"}));return{ok:!!n.ok,stateAfter:"open",stateCategoryAfter:"blocked",via:"label",_raw:n}}if(q.test(s)){await T(r,i,e);let n=S(await _.handleToolCall("github_label_issue",{owner:r,repo:i,number:e,labels:[E],mode:"add"}));return{ok:!!n.ok,stateAfter:"open",stateCategoryAfter:"in_progress",via:"label",_raw:n}}if(M.test(s)){let n=S(await _.handleToolCall("github_reopen_issue",{owner:r,repo:i,number:e}));return{ok:!!n.ok,stateAfter:n.state||"open",stateCategoryAfter:"todo",_raw:n}}return{ok:!1,error:`GitHub issues have no "${o}" state. Representable targets: open/todo, in progress, blocked, done/closed.`}},async linkPullRequest(a,o,t,r={}){let{owner:i,repo:e}=$(r),s=O(a);if(s==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);if(!o)throw new Error("prUrl is required");let n=`${t?`${t}: `:"Linked PR: "}${o}`;return{ok:!!S(await _.handleToolCall("github_add_issue_comment",{owner:i,repo:e,number:s,body:n})).ok,via:"comment"}}};async function T(a,o,t){await _.handleToolCall("github_reopen_issue",{owner:a,repo:o,number:t})}function O(a){if(a==null)return null;if(typeof a=="number")return a;let o=/(\d+)\s*$/.exec(String(a));return o?Number(o[1]):null}var X=x;export{X as default,x as githubAdapter};
@@ -219,6 +219,6 @@ When user says "check out repo-name" or "clone repo-name":
219
219
  3. STOP. Do not offer to inspect files or ask what to do next.
220
220
 
221
221
  When user just wants to "look at" or "read" files (not clone):
222
- - Use github_get_file to read individual files via API`,resolve(){let r=Be();if(!r)return{command:null,args:[],env:{},description:this.description};let s={};for(let e of this.envKeys)process.env[e]&&(s[e]=process.env[e]);return{type:"stdio",command:"node",args:[r,"../dist/github.js","githubSkill"],env:s,description:this.description,alwaysLoad:!0}},async handleToolCall(r,s){try{switch(r){case"github_search_issues":{let e=s.query;if(!e)return JSON.stringify({error:"query is required"});let t=await h(`/search/issues?q=${encodeURIComponent(e)}&per_page=${s.limit||20}`),n=(t.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:t.total_count,items:n})}case"github_search_code":{let e=s.query;if(!e)return JSON.stringify({error:"query is required"});let t=s.repo?`+repo:${s.repo}`:"",n=s.language?`+language:${s.language}`:"",i=await h(`/search/code?q=${encodeURIComponent(e)}${t}${n}&per_page=${s.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:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/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:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/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:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/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:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/pulls/${n}/comments?per_page=50`),o=await h(`/repos/${e}/${t}/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,d)=>new Date(c.createdAt)-new Date(d.createdAt));return JSON.stringify({total:a.length,comments:a})}case"github_create_review":{let{owner:e,repo:t,number:n,body:i,event:o,comments:a}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let c=(o||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(c))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${o})`});let d=Array.isArray(a)?a.filter(m=>m&&m.path&&m.body&&(m.line!=null||m.position!=null)).map(m=>{let g={path:m.path,body:String(m.body)};return m.line!=null?(g.line=Number(m.line),g.side=m.side==="LEFT"?"LEFT":"RIGHT"):g.position=Number(m.position),g}):[];if(c!=="APPROVE"&&!i&&d.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let u={event:c};i&&(u.body=String(i)),d.length>0&&(u.comments=d);let p=await h(`/repos/${e}/${t}/pulls/${n}/reviews`,{method:"POST",body:u});return JSON.stringify({ok:!0,id:p.id,state:p.state,event:c,commentsPosted:d.length,url:p.html_url})}case"github_list_commits":{let{owner:e,repo:t,branch:n,path:i,limit:o}=s;if(!e||!t)return JSON.stringify({error:"owner and repo are required"});let a=`/repos/${e}/${t}/commits?per_page=${o||20}`;n&&(a+=`&sha=${encodeURIComponent(n)}`),i&&(a+=`&path=${encodeURIComponent(i)}`);let c=await h(a);return JSON.stringify({total:c.length,commits:c.map(d=>({sha:d.sha?.slice(0,8),fullSha:d.sha,message:d.commit?.message?.slice(0,300),author:d.commit?.author?.name,date:d.commit?.author?.date,url:d.html_url}))})}case"github_get_commit":{let{owner:e,repo:t,sha:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and sha are required"});let i=await h(`/repos/${e}/${t}/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:t,path:n,ref:i}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and path are required"});let o=`/repos/${e}/${t}/contents/${encodeURIComponent(n)}`;i&&(o+=`?ref=${encodeURIComponent(i)}`);let a=await h(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"),d=c.length>2e4;return JSON.stringify({path:a.path,size:a.size,sha:a.sha?.slice(0,8),content:d?c.slice(0,2e4):c,truncated:d})}case"github_get_user":try{let e=await h("/installation/repositories?per_page=1");if(e.repositories&&e.repositories.length>0){let t=e.repositories[0],n=t.owner.login,i=t.owner.type,o=i==="Organization"?`/orgs/${n}`:`/users/${n}`,a=await h(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 t=(await h("/installation/repositories?per_page=100")).repositories||[],n=new Map;for(let o of t)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 l=function(S){let w=S.replace(/^~(?=$|\/|\\)/,g);return a(w)},{owner:e,repo:t,destination:n}=s;if(!e||!t)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:d}=await import("fs"),{homedir:u,platform:p}=await import("os"),{token:m}=await ne("github"),g=u(),y=n?l(n):o(g,"zibby-repos"),f=o(y,t);if(d(y,{recursive:!0}),c(f))return JSON.stringify({error:`Directory ${f} already exists. Remove it first or use a different destination.`,existingPath:f});try{let S=`https://x-access-token:${m}@github.com/${e}/${t}.git`;i(`git clone ${S} "${f}"`,{stdio:"pipe"});let w=p()==="win32",b;return w?b=i(`dir "${f}"`,{encoding:"utf-8",shell:"cmd.exe"}):b=i(`ls -la "${f}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:f,message:`Cloned ${e}/${t} to ${f}`,contents:b.split(`
222
+ - Use github_get_file to read individual files via API`,resolve(){let r=Be();if(!r)return{command:null,args:[],env:{},description:this.description};let s={};for(let e of this.envKeys)process.env[e]&&(s[e]=process.env[e]);return{type:"stdio",command:"node",args:[r,"../dist/github.js","githubSkill"],env:s,description:this.description,alwaysLoad:!0}},async handleToolCall(r,s){try{switch(r){case"github_search_issues":{let e=s.query;if(!e)return JSON.stringify({error:"query is required"});let t=await h(`/search/issues?q=${encodeURIComponent(e)}&per_page=${s.limit||20}`),n=(t.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:t.total_count,items:n})}case"github_search_code":{let e=s.query;if(!e)return JSON.stringify({error:"query is required"});let t=s.repo?`+repo:${s.repo}`:"",n=s.language?`+language:${s.language}`:"",i=await h(`/search/code?q=${encodeURIComponent(e)}${t}${n}&per_page=${s.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:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/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,headSha:i.head?.sha,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:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/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:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/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:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/pulls/${n}/comments?per_page=50`),o=await h(`/repos/${e}/${t}/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,d)=>new Date(c.createdAt)-new Date(d.createdAt));return JSON.stringify({total:a.length,comments:a})}case"github_create_review":{let{owner:e,repo:t,number:n,body:i,event:o,comments:a}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let c=(o||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(c))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${o})`});let d=Array.isArray(a)?a.filter(m=>m&&m.path&&m.body&&(m.line!=null||m.position!=null)).map(m=>{let g={path:m.path,body:String(m.body)};return m.line!=null?(g.line=Number(m.line),g.side=m.side==="LEFT"?"LEFT":"RIGHT"):g.position=Number(m.position),g}):[];if(c!=="APPROVE"&&!i&&d.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let u={event:c};i&&(u.body=String(i)),d.length>0&&(u.comments=d);let p=await h(`/repos/${e}/${t}/pulls/${n}/reviews`,{method:"POST",body:u});return JSON.stringify({ok:!0,id:p.id,state:p.state,event:c,commentsPosted:d.length,url:p.html_url})}case"github_list_commits":{let{owner:e,repo:t,branch:n,path:i,limit:o}=s;if(!e||!t)return JSON.stringify({error:"owner and repo are required"});let a=`/repos/${e}/${t}/commits?per_page=${o||20}`;n&&(a+=`&sha=${encodeURIComponent(n)}`),i&&(a+=`&path=${encodeURIComponent(i)}`);let c=await h(a);return JSON.stringify({total:c.length,commits:c.map(d=>({sha:d.sha?.slice(0,8),fullSha:d.sha,message:d.commit?.message?.slice(0,300),author:d.commit?.author?.name,date:d.commit?.author?.date,url:d.html_url}))})}case"github_get_commit":{let{owner:e,repo:t,sha:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and sha are required"});let i=await h(`/repos/${e}/${t}/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:t,path:n,ref:i}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and path are required"});let o=`/repos/${e}/${t}/contents/${encodeURIComponent(n)}`;i&&(o+=`?ref=${encodeURIComponent(i)}`);let a=await h(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"),d=c.length>2e4;return JSON.stringify({path:a.path,size:a.size,sha:a.sha?.slice(0,8),content:d?c.slice(0,2e4):c,truncated:d})}case"github_get_user":try{let e=await h("/installation/repositories?per_page=1");if(e.repositories&&e.repositories.length>0){let t=e.repositories[0],n=t.owner.login,i=t.owner.type,o=i==="Organization"?`/orgs/${n}`:`/users/${n}`,a=await h(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 t=(await h("/installation/repositories?per_page=100")).repositories||[],n=new Map;for(let o of t)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 l=function(S){let w=S.replace(/^~(?=$|\/|\\)/,g);return a(w)},{owner:e,repo:t,destination:n}=s;if(!e||!t)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:d}=await import("fs"),{homedir:u,platform:p}=await import("os"),{token:m}=await ne("github"),g=u(),y=n?l(n):o(g,"zibby-repos"),f=o(y,t);if(d(y,{recursive:!0}),c(f))return JSON.stringify({error:`Directory ${f} already exists. Remove it first or use a different destination.`,existingPath:f});try{let S=`https://x-access-token:${m}@github.com/${e}/${t}.git`;i(`git clone ${S} "${f}"`,{stdio:"pipe"});let w=p()==="win32",b;return w?b=i(`dir "${f}"`,{encoding:"utf-8",shell:"cmd.exe"}):b=i(`ls -la "${f}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:f,message:`Cloned ${e}/${t} to ${f}`,contents:b.split(`
223
223
  `).slice(0,30).join(`
224
224
  `),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(S){return JSON.stringify({error:`Clone failed: ${S.message}`})}}case"github_search_repos":{let{query:e,limit:t}=s;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,t||20)})}case"github_list_repos":{let{owner:e,type:t,sort:n,direction:i,limit:o}=s,a=100,c=o||200,d=[];if(!e){let l=1,y=!0;for(;y&&d.length<c;){let b=`/installation/repositories?per_page=${a}&page=${l}`,U=(await h(b)).repositories||[];if(U.length===0)break;d=d.concat(U),y=U.length===a,l++}let f=d.slice(0,c).map(b=>({name:b.name,fullName:b.full_name,private:b.private,description:b.description,language:b.language,defaultBranch:b.default_branch,updatedAt:b.updated_at,stars:b.stargazers_count,url:b.html_url})),S=f.filter(b=>b.private).length,w=f.filter(b=>!b.private).length;return JSON.stringify({count:f.length,repos:f,privateCount:S,publicCount:w,message:`Found ${S} private and ${w} public repos`})}let u=await h(`/orgs/${e}`).then(()=>!0).catch(()=>!1),p=1,m=!0;for(;m&&d.length<c;){let l;u?l=`/orgs/${e}/repos?per_page=${a}&page=${p}&type=${t||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`:l=`/users/${e}/repos?per_page=${a}&page=${p}&type=${t||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`;let y=await h(l),f=Array.isArray(y)?y:[];if(f.length===0)break;d=d.concat(f),m=f.length===a,p++}let g=d.slice(0,c).map(l=>({name:l.name,fullName:l.full_name,private:l.private,description:l.description,language:l.language,defaultBranch:l.default_branch,updatedAt:l.updated_at,stars:l.stargazers_count,url:l.html_url}));return JSON.stringify({count:g.length,repos:g})}case"github_create_issue":{let{owner:e,repo:t,title:n,body:i}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and title are required"});let o=await h(`/repos/${e}/${t}/issues`,{method:"POST",body:{title:n,body:i||""}});return JSON.stringify({number:o.number,url:o.html_url,title:o.title})}case"github_list_issues":{let{owner:e,repo:t,state:n,labels:i,since:o,assignee:a,sort:c,direction:d,limit:u}=s||{};if(!e||!t)return JSON.stringify({error:"owner and repo are required"});let p=new URLSearchParams;p.set("state",n||"open"),p.set("per_page",String(u||30)),p.set("sort",c||"updated"),p.set("direction",d||"desc"),i&&p.set("labels",Array.isArray(i)?i.join(","):i),o&&p.set("since",o),a&&p.set("assignee",a);let m=await h(`/repos/${e}/${t}/issues?${p.toString()}`),g=(Array.isArray(m)?m:[]).filter(l=>!l.pull_request).map(l=>({number:l.number,title:l.title,state:l.state,labels:(l.labels||[]).map(y=>typeof y=="string"?y:y.name),assignee:l.assignee?.login||null,assignees:(l.assignees||[]).map(y=>y.login),user:l.user?.login,comments:l.comments,url:l.html_url,createdAt:l.created_at,updatedAt:l.updated_at}));return JSON.stringify({count:g.length,issues:g})}case"github_get_issue":{let{owner:e,repo:t,number:n}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/issues/${n}`);return i.pull_request?JSON.stringify({error:`#${n} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:i.number,title:i.title,body:i.body||"",state:i.state,stateReason:i.state_reason||null,labels:(i.labels||[]).map(o=>typeof o=="string"?o:o.name),assignee:i.assignee?.login||null,assignees:(i.assignees||[]).map(o=>o.login),user:i.user?.login,milestone:i.milestone?.title||null,comments:i.comments,url:i.html_url,createdAt:i.created_at,updatedAt:i.updated_at,closedAt:i.closed_at})}case"github_get_issue_comments":{let{owner:e,repo:t,number:n,limit:i}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o=await h(`/repos/${e}/${t}/issues/${n}/comments?per_page=${i||100}`),a=(Array.isArray(o)?o:[]).map(c=>({id:c.id,user:c.user?.login,body:c.body||"",createdAt:c.created_at,updatedAt:c.updated_at,url:c.html_url}));return JSON.stringify({count:a.length,comments:a})}case"github_add_issue_comment":{let{owner:e,repo:t,number:n,body:i}=s||{};if(!e||!t||!n||!i)return JSON.stringify({error:"owner, repo, number, and body are required"});let o=await h(`/repos/${e}/${t}/issues/${n}/comments`,{method:"POST",body:{body:i}});return JSON.stringify({ok:!0,id:o.id,url:o.html_url})}case"github_close_issue":{let{owner:e,repo:t,number:n,stateReason:i}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o={state:"closed"};i&&(o.state_reason=i);let a=await h(`/repos/${e}/${t}/issues/${n}`,{method:"PATCH",body:o});return JSON.stringify({ok:!0,number:a.number,state:a.state,stateReason:a.state_reason||null,url:a.html_url})}case"github_reopen_issue":{let{owner:e,repo:t,number:n}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/issues/${n}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:i.number,state:i.state,url:i.html_url})}case"github_label_issue":{let{owner:e,repo:t,number:n,labels:i,mode:o}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let a=Array.isArray(i)?i:i?[i]:[];if(!a.length)return JSON.stringify({error:"labels (string or array) is required"});let c=o||"add";if(c==="set"){let u=await h(`/repos/${e}/${t}/issues/${n}`,{method:"PATCH",body:{labels:a}});return JSON.stringify({ok:!0,number:u.number,labels:(u.labels||[]).map(p=>typeof p=="string"?p:p.name)})}if(c==="remove"){for(let p of a)await h(`/repos/${e}/${t}/issues/${n}/labels/${encodeURIComponent(p)}`,{method:"DELETE"});let u=await h(`/repos/${e}/${t}/issues/${n}`);return JSON.stringify({ok:!0,number:u.number,labels:(u.labels||[]).map(p=>typeof p=="string"?p:p.name)})}let d=await h(`/repos/${e}/${t}/issues/${n}/labels`,{method:"POST",body:{labels:a}});return JSON.stringify({ok:!0,number:n,labels:(Array.isArray(d)?d:[]).map(u=>typeof u=="string"?u:u.name)})}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_create_review",description:"Post a review on a pull request: a summary body plus optional inline comments anchored to file/line, with an event (COMMENT, APPROVE, or REQUEST_CHANGES). Use this to deliver a code review back to the PR.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},body:{type:"string",description:"The review summary (markdown). Shown as the top-level review comment."},event:{type:"string",enum:["COMMENT","APPROVE","REQUEST_CHANGES"],description:"Review verdict. Default COMMENT (no approval state). Use REQUEST_CHANGES for blocking issues."},comments:{type:"array",description:"Optional inline comments, each anchored to a changed line.",items:{type:"object",properties:{path:{type:"string",description:"File path as it appears in the diff"},line:{type:"number",description:"Line number in the file's NEW version (the right side of the diff)"},side:{type:"string",enum:["LEFT","RIGHT"],description:"RIGHT (new) or LEFT (old). Default RIGHT."},body:{type:"string",description:"The inline comment text (markdown)"}},required:["path","line","body"]}}},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"]}},{name:"github_list_issues",description:"List issues in a repo (excludes pull requests). Filter by state, labels, and an updated-since cursor for polling.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},state:{type:"string",enum:["open","closed","all"],description:"Filter by state (default: open)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},since:{type:"string",description:"ISO-8601 timestamp; only issues updated at/after this (polling cursor)"},assignee:{type:"string",description:'Filter by assignee login, "none", or "*"'},sort:{type:"string",enum:["created","updated","comments"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30, max 100 per page)"}},required:["owner","repo"]}},{name:"github_get_issue",description:"Get a single GitHub issue with full detail (title, body, state, labels, assignee, url)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_get_issue_comments",description:"Get the comment thread on a GitHub issue (chronological)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},limit:{type:"number",description:"Max comments (default: 100)"}},required:["owner","repo","number"]}},{name:"github_add_issue_comment",description:"Add a comment to a GitHub issue. Also the way to record a PR link on an issue (post a markdown link).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},body:{type:"string",description:"Comment body (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_close_issue",description:"Close a GitHub issue. Optionally set the close reason (completed or not_planned).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},stateReason:{type:"string",enum:["completed","not_planned"],description:"Why the issue was closed (optional)"}},required:["owner","repo","number"]}},{name:"github_reopen_issue",description:"Reopen a closed GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_label_issue",description:"Add, set (replace all), or remove labels on a GitHub issue. Labels back state-like transitions on GitHub.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},labels:{type:"array",items:{type:"string"},description:"Label name(s)"},mode:{type:"string",enum:["add","set","remove"],description:"add appends, set replaces all, remove deletes (default: add)"}},required:["owner","repo","number","labels"]}}]};var ue=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i,le=/\b(in[\s-]?progress|wip|doing|started|in[\s-]?review|review)\b/i,Fe=/\b(done|closed|complete|completed|resolved|fixed|merged|shipped)\b/i,ze=/\b(todo|to[\s-]?do|open|backlog|reopen|new)\b/i,oe="in progress",ae="blocked";function de(r,s=[]){if(r==="closed")return"done";if(r!=="open")return"unknown";let e=(s||[]).map(String);return e.some(t=>ue.test(t))?"blocked":e.some(t=>le.test(t))?"in_progress":"todo"}function C(r={}){let s=r.owner||process.env.GITHUB_OWNER,e=r.repo||process.env.GITHUB_REPO;if(!s||!e)throw new Error("GitHub scope missing: provide {owner, repo} via ctx or env GITHUB_OWNER / GITHUB_REPO.");return{owner:s,repo:e}}function j(r){let s=JSON.parse(r);if(s&&s.error)throw new Error(s.error);return s}function Q(r,s={}){let e=r.labels||[],t=r.number,n=s.owner&&s.repo?`${s.owner}/${s.repo}#${t}`:`#${t}`;return{id:String(t),key:n,title:r.title||"",body:r.body||"",state:r.state||null,stateCategory:de(r.state,e),assignee:r.assignee||r.assignees&&r.assignees[0]||null,url:r.url||null,_raw:r}}var V={id:"github",toStateCategory:de,toNeutral:Q,IN_PROGRESS_LABEL:oe,BLOCKED_LABEL:ae,async listCandidates(r={}){let s=r.ctx||{},{owner:e,repo:t}=C(s);return(j(await k.handleToolCall("github_list_issues",{owner:e,repo:t,state:r.state||"open",labels:r.labels,since:r.updatedAfter,limit:r.limit})).issues||[]).map(i=>Q(i,{owner:e,repo:t}))},async getTicket(r,s={}){let{owner:e,repo:t}=C(s),n=q(r);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);let i=JSON.parse(await k.handleToolCall("github_get_issue",{owner:e,repo:t,number:n}));return i.error?null:Q(i,{owner:e,repo:t})},async getComments(r,s={}){let{owner:e,repo:t}=C(s),n=q(r);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);return(j(await k.handleToolCall("github_get_issue_comments",{owner:e,repo:t,number:n})).comments||[]).map(o=>({id:String(o.id),author:o.user||"Unknown",body:o.body||"",createdAt:o.createdAt||null,updatedAt:o.updatedAt||null,_raw:o})).sort((o,a)=>String(a.createdAt).localeCompare(String(o.createdAt)))},async addComment(r,s,e={}){let{owner:t,repo:n}=C(e),i=q(r);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);if(!s)throw new Error("body is required");let o=j(await k.handleToolCall("github_add_issue_comment",{owner:t,repo:n,number:i,body:s}));return{ok:!!o.ok,id:o.id?String(o.id):null}},async transition(r,s,e={}){let{owner:t,repo:n}=C(e),i=q(r);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);let o=String(s||"");if(Fe.test(o)){let a=j(await k.handleToolCall("github_close_issue",{owner:t,repo:n,number:i,stateReason:"completed"}));return{ok:!!a.ok,stateAfter:a.state||"closed",stateCategoryAfter:"done",_raw:a}}if(ue.test(o)){await ce(t,n,i);let a=j(await k.handleToolCall("github_label_issue",{owner:t,repo:n,number:i,labels:[ae],mode:"add"}));return{ok:!!a.ok,stateAfter:"open",stateCategoryAfter:"blocked",via:"label",_raw:a}}if(le.test(o)){await ce(t,n,i);let a=j(await k.handleToolCall("github_label_issue",{owner:t,repo:n,number:i,labels:[oe],mode:"add"}));return{ok:!!a.ok,stateAfter:"open",stateCategoryAfter:"in_progress",via:"label",_raw:a}}if(ze.test(o)){let a=j(await k.handleToolCall("github_reopen_issue",{owner:t,repo:n,number:i}));return{ok:!!a.ok,stateAfter:a.state||"open",stateCategoryAfter:"todo",_raw:a}}return{ok:!1,error:`GitHub issues have no "${s}" state. Representable targets: open/todo, in progress, blocked, done/closed.`}},async linkPullRequest(r,s,e,t={}){let{owner:n,repo:i}=C(t),o=q(r);if(o==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);if(!s)throw new Error("prUrl is required");let a=`${e?`${e}: `:"Linked PR: "}${s}`;return{ok:!!j(await k.handleToolCall("github_add_issue_comment",{owner:n,repo:i,number:o,body:a})).ok,via:"comment"}}};async function ce(r,s,e){await k.handleToolCall("github_reopen_issue",{owner:r,repo:s,number:e})}function q(r){if(r==null)return null;if(typeof r=="number")return r;let s=/(\d+)\s*$/.exec(String(r));return s?Number(s[1]):null}var Ye=(process.env.PLANE_API_URL||"https://api.plane.so/api/v1").replace(/\/+$/,""),We=process.env.PLANE_WORKSPACE_SLUG||"",Qe=process.env.PLANE_PROJECT_ID||"";function Ve(){let r=process.env.PLANE_API_KEY||process.env.PLANE_OAUTH_TOKEN;if(!r)throw new Error("Plane is not connected: set PLANE_API_KEY (personal access token).");return r}function R(r={}){let s=r.workspaceSlug||We,e=r.projectId||Qe;if(!s||!e)throw new Error("Plane scope missing: provide workspaceSlug + projectId (env PLANE_WORKSPACE_SLUG / PLANE_PROJECT_ID or per-call ctx).");return{workspaceSlug:s,projectId:e}}async function v(r,s={}){let e=`${Ye}${r}`;if(s.query&&Object.keys(s.query).length){let i=new URLSearchParams;for(let[a,c]of Object.entries(s.query))c!=null&&c!==""&&i.set(a,String(c));let o=i.toString();o&&(e+=(e.includes("?")?"&":"?")+o)}let t=await fetch(e,{method:s.method||"GET",headers:{"X-API-Key":Ve(),Accept:"application/json",...s.body?{"Content-Type":"application/json"}:{},...s.headers},body:s.body?JSON.stringify(s.body):void 0});if(!t.ok){let i=await t.text().catch(()=>"");throw new Error(`Plane API ${t.status}: ${i.slice(0,300)}`)}let n=await t.text().catch(()=>"");if(!n||!n.trim())return{};try{return JSON.parse(n)}catch{return{raw:n}}}var Ze={backlog:"todo",unstarted:"todo",started:"in_progress",completed:"done",cancelled:"done"},Xe=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i;function X(r){return r?r.name&&Xe.test(r.name)?"blocked":Ze[r.group]||"unknown":"unknown"}var pe=new Map,et=300*1e3;async function ye(r){let{workspaceSlug:s,projectId:e}=R(r),t=pe.get(e);if(t&&Date.now()-t.fetchedAt<et)return t.states;let n=await v(`/workspaces/${encodeURIComponent(s)}/projects/${encodeURIComponent(e)}/states/`,{query:{per_page:100}}),i=(n.results||n||[]).map(o=>({id:o.id,name:o.name,group:o.group,color:o.color}));return pe.set(e,{fetchedAt:Date.now(),states:i}),i}function Z(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function tt(r,s){let e=Z(s);if(!e)return null;let t=r.find(i=>Z(i.name)===e);if(t)return t;let n={todo:["todo","backlog","open","unstarted"],inprogress:["inprogress","started","doing","wip"],done:["done","completed","closed","resolved","cancelled","canceled"],blocked:["blocked","onhold","waiting"]};for(let[,i]of Object.entries(n)){if(!i.some(c=>Z(c)===e))continue;let o=e==="done"?"completed":e==="inprogress"?"started":"unstarted",a=r.find(c=>c.group===o);if(a)return a}return null}async function me(r,s){let t=(await ye(s).catch(()=>[])).find(c=>c.id===r.state)||null,{workspaceSlug:n,projectId:i}=R(s),o=s.projectIdentifier&&r.sequence_id!=null?`${s.projectIdentifier}-${r.sequence_id}`:r.sequence_id!=null?String(r.sequence_id):r.id,a=r.assignees||[];return{id:r.id,key:o,title:r.name||"",body:r.description_html||r.description_stripped||r.description||"",state:t?t.name:null,stateCategory:X(t),assignee:a.length?String(a[0]):null,url:s.baseWebUrl?`${s.baseWebUrl}/${n}/projects/${i}/issues/${r.id}`:null,_raw:r}}var ee={id:"plane",envKeys:["PLANE_API_KEY","PLANE_OAUTH_TOKEN","PLANE_API_URL","PLANE_WORKSPACE_SLUG","PLANE_PROJECT_ID"],planeFetch:v,toStateCategory:X,async listCandidates(r={}){let s=r.ctx||{},{workspaceSlug:e,projectId:t}=R(s),n={per_page:Math.min(Number(r.limit)||50,100),cursor:r.cursor};r.state&&(n.state=r.state),r.updatedAfter&&(n.updated_at__gte=r.updatedAfter);let o=(await v(`/workspaces/${encodeURIComponent(e)}/projects/${encodeURIComponent(t)}/work-items/`,{query:n})).results||[];return r.updatedAfter&&(o=o.filter(a=>String(a.updated_at)>String(r.updatedAfter))),Promise.all(o.map(a=>me(a,s)))},async getTicket(r,s={}){let{workspaceSlug:e,projectId:t}=R(s),n=await v(`/workspaces/${encodeURIComponent(e)}/projects/${encodeURIComponent(t)}/work-items/${encodeURIComponent(r)}/`);return!n||!n.id?null:me(n,s)},async getComments(r,s={}){let{workspaceSlug:e,projectId:t}=R(s);return((await v(`/workspaces/${encodeURIComponent(e)}/projects/${encodeURIComponent(t)}/work-items/${encodeURIComponent(r)}/comments/`,{query:{per_page:100}})).results||[]).map(o=>({id:o.id,author:o.actor||o.actor_detail?.display_name||"Unknown",body:o.comment_html||o.comment_stripped||"",createdAt:o.created_at||null,updatedAt:o.updated_at||null,_raw:o})).sort((o,a)=>String(a.createdAt).localeCompare(String(o.createdAt)))},async addComment(r,s,e={}){let{workspaceSlug:t,projectId:n}=R(e),o=/<[a-z][\s\S]*>/i.test(String(s||""))?String(s):`<p>${String(s||"")}</p>`,a=await v(`/workspaces/${encodeURIComponent(t)}/projects/${encodeURIComponent(n)}/work-items/${encodeURIComponent(r)}/comments/`,{method:"POST",body:{comment_html:o}});return{ok:!!a.id,id:a.id||null,_raw:a}},async transition(r,s,e={}){let{workspaceSlug:t,projectId:n}=R(e),i=await ye(e),o=tt(i,s);if(!o)return{ok:!1,error:`No Plane state matches "${s}" in this project`,availableStates:i.map(c=>({id:c.id,name:c.name,group:c.group}))};let a=await v(`/workspaces/${encodeURIComponent(t)}/projects/${encodeURIComponent(n)}/work-items/${encodeURIComponent(r)}/`,{method:"PATCH",body:{state:o.id}});return{ok:!!a.id,stateAfter:o.name,stateCategoryAfter:X(o),_raw:a}},async linkPullRequest(r,s,e,t={}){let n=e?`${e}: `:"Linked PR: ";return{ok:!!(await this.addComment(r,`<p>${n}<a href="${s}">${s}</a></p>`,t)).ok,via:"comment"}}};var rt=["todo","in_progress","done","blocked","unknown"];var fe={jira:F,linear:W,github:V,plane:ee},st="jira";function Tt(r){let s=String(r||process.env.TRACKER_PROVIDER||st).trim().toLowerCase(),e=fe[s];if(!e){let t=Object.keys(fe).join(", ");throw new Error(`Unknown tracker provider "${s}". Known providers: ${t}.`)}return e}export{st as DEFAULT_TRACKER_PROVIDER,fe as TRACKER_ADAPTERS,rt as TRACKER_STATE_CATEGORIES,Tt as getAdapter,V as githubAdapter,F as jiraAdapter,W as linearAdapter,ee as planeAdapter};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/skills",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
4
4
  "description": "Built-in skill definitions for Zibby test automation framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",