@zibby/skills 0.2.13 → 0.2.15
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/artifact.d.ts +2 -0
- package/dist/artifact.js +37 -11
- package/dist/chat-notify.js +3 -3
- package/dist/chatProgress.js +4 -4
- package/dist/discord.js +3 -3
- package/dist/figma.js +2 -2
- package/dist/git-write.js +1 -1
- package/dist/github.js +4 -4
- package/dist/gitlab.js +3 -3
- package/dist/googleDocs.js +3 -3
- package/dist/hubspot.js +1 -1
- package/dist/index.js +147 -121
- package/dist/integrations.d.ts +6 -0
- package/dist/integrations.js +1 -1
- package/dist/jira.js +3 -3
- package/dist/lark.js +2 -2
- package/dist/larkDocs.d.ts +8 -7
- package/dist/larkDocs.js +3 -3
- package/dist/linear.js +3 -3
- package/dist/llm-billing.js +1 -1
- package/dist/notion.js +4 -4
- package/dist/opendesign.js +2 -2
- package/dist/package.json +1 -1
- package/dist/plane.js +1 -1
- package/dist/sentry.js +2 -2
- package/dist/slack.js +1 -1
- package/dist/trackers/github-adapter.js +1 -1
- package/dist/trackers/index.js +1 -1
- package/dist/trackers/jira-adapter.js +2 -2
- package/dist/trackers/linear-adapter.js +1 -1
- package/dist/vikunja.js +1 -1
- package/package.json +1 -1
package/dist/git-write.js
CHANGED
|
@@ -8,7 +8,7 @@ When your task needs repository context you don't have yet:
|
|
|
8
8
|
1. Clone the relevant repo with git_checkout
|
|
9
9
|
2. Use git_explore to understand the project structure
|
|
10
10
|
3. Use shell commands (grep, cat) to read specific files for deeper understanding
|
|
11
|
-
4. Use GitHub/GitLab skills to read related PRs and commits when history matters`,resolve(){return null},async handleToolCall(c,n,e){let i=e?.options?.workspace||process.cwd();try{switch(c){case"git_checkout":return await ge(n,i);case"git_list_repos":return be(n,i);case"git_explore":return fe(n,i);default:return JSON.stringify({error:`Unknown tool: ${c}`})}}catch(r){return JSON.stringify({error:he(r.message)})}},tools:[{name:"git_checkout",description:"Clone a git repository locally (or pull latest if already cloned). Auto-authenticates with GitHub/GitLab tokens if available.",input_schema:{type:"object",properties:{url:{type:"string",description:'Repository URL (e.g. "https://github.com/org/repo" or "org/repo" shorthand for GitHub)'},branch:{type:"string",description:"Branch to checkout (default: repo default branch)"},shallow:{type:"boolean",description:"Shallow clone with depth 1 (default: true, faster)"},name:{type:"string",description:"Local directory name override (default: repo name from URL)"}},required:["url"]}},{name:"git_list_repos",description:"List locally cloned repositories",input_schema:{type:"object",properties:{}}},{name:"git_explore",description:"Quick structural overview of a cloned repo: key files, package.json info, directory tree (top 2 levels), detected framework/language",input_schema:{type:"object",properties:{repo:{type:"string",description:"Repo name (as listed by git_list_repos)"},depth:{type:"number",description:"Directory tree depth (default: 2)"}},required:["repo"]}}]};async function ge(c,n){let{url:e,branch:i,shallow:r=!0,name:t}=c;!e.includes("://")&&!e.startsWith("git@")&&(e=`https://github.com/${e}`);let s=t||me(e.replace(/\.git$/,"")),a=F(n,K);le(a,{recursive:!0});let o=$(a,s),l=e,d=process.env.GITHUB_TOKEN,u=process.env.GITLAB_TOKEN,p=process.env.GITLAB_URL;if(Y(e,"github.com")&&d)l=V(e,"x-access-token",d);else if(u&&p)try{let b=new URL(p).host;Y(e,b)&&(l=V(e,"oauth2",u))}catch{}if(v($(o,".git"))){let b=i?`git -C "${o}" fetch "${l}" ${i} && git -C "${o}" checkout ${i} && git -C "${o}" merge --ff-only FETCH_HEAD`:`git -C "${o}" pull "${l}"`;await L(b,n);let w=await L(`git -C "${o}" log -1 --format="%h %s"`,n);return JSON.stringify({action:"updated",repo:s,path:o,branch:i||"default",head:w})}let m=["git","clone"];r&&m.push("--depth","1"),i&&m.push("--branch",i),m.push(`"${l}"`,`"${o}"`),await L(m.join(" "),n),P(pe,o,e,d||u,"git_checkout");let y=await L(`git -C "${o}" log -1 --format="%h %s"`,n);return JSON.stringify({action:"cloned",repo:s,path:o,branch:i||"default",shallow:r,head:y})}function be(c,n){let e=F(n,K);if(!v(e))return JSON.stringify({repos:[],message:"No repos cloned yet"});let i=[];for(let r of Q(e,{withFileTypes:!0})){if(!r.isDirectory())continue;let t=$(e,r.name);if(!v($(t,".git")))continue;let s=de(t);i.push({name:r.name,path:t,lastModified:s.mtime.toISOString()})}return JSON.stringify({repos:i,total:i.length,directory:e})}function fe(c,n){let{repo:e,depth:i=2}=c,r=F(n,K,e);if(!v(r))return JSON.stringify({error:`Repo not found: ${e}. Run git_checkout first.`});let t={repo:e,path:r},s=$(r,"package.json");if(v(s))try{let m=JSON.parse(ue(s,"utf-8"));t.packageJson={name:m.name,version:m.version,scripts:m.scripts?Object.keys(m.scripts):[],dependencies:m.dependencies?Object.keys(m.dependencies).slice(0,30):[],devDependencies:m.devDependencies?Object.keys(m.devDependencies).slice(0,20):[]},m.dependencies?.react?t.framework="React":m.dependencies?.next?t.framework="Next.js":m.dependencies?.vue?t.framework="Vue":m.dependencies?.angular?t.framework="Angular":m.dependencies?.express?t.framework="Express":m.dependencies?.fastify&&(t.framework="Fastify")}catch{}let a=$(r,"pyproject.toml");v(a)&&(t.language="Python");let o=$(r,"go.mod");v(o)&&(t.language="Go");let l=$(r,"Cargo.toml");v(l)&&(t.language="Rust"),v(s)&&(t.language=t.language||"JavaScript/TypeScript");let d=[];function u(m,y,b){if(b>i)return;let w;try{w=Q(m,{withFileTypes:!0})}catch{return}let f=w.filter(h=>!h.name.startsWith(".")&&h.name!=="node_modules"&&h.name!=="__pycache__"&&h.name!=="dist"&&h.name!=="build"&&h.name!==".git").sort((h,g)=>h.isDirectory()!==g.isDirectory()?h.isDirectory()?-1:1:h.name.localeCompare(g.name));for(let h of f){let g=h.isDirectory();d.push(`${y}${g?"\u{1F4C1}":"\u{1F4C4}"} ${h.name}`),g&&b<i&&u($(m,h.name),`${y} `,b+1)}}u(r,"",1),t.tree=d.slice(0,80),d.length>80&&(t.treeTruncated=!0);let p=["README.md","README.rst","src/App.tsx","src/App.jsx","src/App.js","src/routes.tsx","src/routes.js","app/routes.tsx","app/routes.js","src/index.tsx","src/index.ts","src/main.tsx","src/main.ts","pages/_app.tsx","pages/_app.js","app/layout.tsx","docker-compose.yml","Dockerfile",".env.example"];return t.keyFilesFound=p.filter(m=>v($(r,m))),JSON.stringify(t)}import{existsSync as Re}from"fs";import{fileURLToPath as Ae}from"url";import{dirname as Oe,resolve as ve}from"path";import{resolveIntegrationToken as ee}from"@zibby/core/backend-client.js";var k=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",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",VIKUNJA:"vikunja",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),Fe=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"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},vikunja:{id:"vikunja",name:"Vikunja",connectPath:"/integrations?provider=vikunja"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});import ye from"crypto";var Z=/<!--\s*zbfp:([a-f0-9]{8,20})\s*-->/i,X=/<!--\s*zbreview-summary\s*-->/i;function _e(c){return String(c||"").replace(Z,"").replace(X,"").replace(/\b(?:lines?|L)\s*#?\d+(?:\s*[-–]\s*\d+)?/gi,"").replace(/[`*_>#~]/g,"").replace(/\s+/g," ").trim().toLowerCase().slice(0,400)}function we(c,n){return ye.createHash("sha256").update(`${String(c||"")}\0${_e(n)}`).digest("hex").slice(0,12)}function Se(c){return`
|
|
11
|
+
4. Use GitHub/GitLab skills to read related PRs and commits when history matters`,resolve(){return null},async handleToolCall(c,n,e){let i=e?.options?.workspace||process.cwd();try{switch(c){case"git_checkout":return await ge(n,i);case"git_list_repos":return be(n,i);case"git_explore":return fe(n,i);default:return JSON.stringify({error:`Unknown tool: ${c}`})}}catch(r){return JSON.stringify({error:he(r.message)})}},tools:[{name:"git_checkout",description:"Clone a git repository locally (or pull latest if already cloned). Auto-authenticates with GitHub/GitLab tokens if available.",input_schema:{type:"object",properties:{url:{type:"string",description:'Repository URL (e.g. "https://github.com/org/repo" or "org/repo" shorthand for GitHub)'},branch:{type:"string",description:"Branch to checkout (default: repo default branch)"},shallow:{type:"boolean",description:"Shallow clone with depth 1 (default: true, faster)"},name:{type:"string",description:"Local directory name override (default: repo name from URL)"}},required:["url"]}},{name:"git_list_repos",description:"List locally cloned repositories",input_schema:{type:"object",properties:{}}},{name:"git_explore",description:"Quick structural overview of a cloned repo: key files, package.json info, directory tree (top 2 levels), detected framework/language",input_schema:{type:"object",properties:{repo:{type:"string",description:"Repo name (as listed by git_list_repos)"},depth:{type:"number",description:"Directory tree depth (default: 2)"}},required:["repo"]}}]};async function ge(c,n){let{url:e,branch:i,shallow:r=!0,name:t}=c;!e.includes("://")&&!e.startsWith("git@")&&(e=`https://github.com/${e}`);let s=t||me(e.replace(/\.git$/,"")),a=F(n,K);le(a,{recursive:!0});let o=$(a,s),l=e,d=process.env.GITHUB_TOKEN,u=process.env.GITLAB_TOKEN,p=process.env.GITLAB_URL;if(Y(e,"github.com")&&d)l=V(e,"x-access-token",d);else if(u&&p)try{let b=new URL(p).host;Y(e,b)&&(l=V(e,"oauth2",u))}catch{}if(v($(o,".git"))){let b=i?`git -C "${o}" fetch "${l}" ${i} && git -C "${o}" checkout ${i} && git -C "${o}" merge --ff-only FETCH_HEAD`:`git -C "${o}" pull "${l}"`;await L(b,n);let w=await L(`git -C "${o}" log -1 --format="%h %s"`,n);return JSON.stringify({action:"updated",repo:s,path:o,branch:i||"default",head:w})}let m=["git","clone"];r&&m.push("--depth","1"),i&&m.push("--branch",i),m.push(`"${l}"`,`"${o}"`),await L(m.join(" "),n),P(pe,o,e,d||u,"git_checkout");let y=await L(`git -C "${o}" log -1 --format="%h %s"`,n);return JSON.stringify({action:"cloned",repo:s,path:o,branch:i||"default",shallow:r,head:y})}function be(c,n){let e=F(n,K);if(!v(e))return JSON.stringify({repos:[],message:"No repos cloned yet"});let i=[];for(let r of Q(e,{withFileTypes:!0})){if(!r.isDirectory())continue;let t=$(e,r.name);if(!v($(t,".git")))continue;let s=de(t);i.push({name:r.name,path:t,lastModified:s.mtime.toISOString()})}return JSON.stringify({repos:i,total:i.length,directory:e})}function fe(c,n){let{repo:e,depth:i=2}=c,r=F(n,K,e);if(!v(r))return JSON.stringify({error:`Repo not found: ${e}. Run git_checkout first.`});let t={repo:e,path:r},s=$(r,"package.json");if(v(s))try{let m=JSON.parse(ue(s,"utf-8"));t.packageJson={name:m.name,version:m.version,scripts:m.scripts?Object.keys(m.scripts):[],dependencies:m.dependencies?Object.keys(m.dependencies).slice(0,30):[],devDependencies:m.devDependencies?Object.keys(m.devDependencies).slice(0,20):[]},m.dependencies?.react?t.framework="React":m.dependencies?.next?t.framework="Next.js":m.dependencies?.vue?t.framework="Vue":m.dependencies?.angular?t.framework="Angular":m.dependencies?.express?t.framework="Express":m.dependencies?.fastify&&(t.framework="Fastify")}catch{}let a=$(r,"pyproject.toml");v(a)&&(t.language="Python");let o=$(r,"go.mod");v(o)&&(t.language="Go");let l=$(r,"Cargo.toml");v(l)&&(t.language="Rust"),v(s)&&(t.language=t.language||"JavaScript/TypeScript");let d=[];function u(m,y,b){if(b>i)return;let w;try{w=Q(m,{withFileTypes:!0})}catch{return}let f=w.filter(h=>!h.name.startsWith(".")&&h.name!=="node_modules"&&h.name!=="__pycache__"&&h.name!=="dist"&&h.name!=="build"&&h.name!==".git").sort((h,g)=>h.isDirectory()!==g.isDirectory()?h.isDirectory()?-1:1:h.name.localeCompare(g.name));for(let h of f){let g=h.isDirectory();d.push(`${y}${g?"\u{1F4C1}":"\u{1F4C4}"} ${h.name}`),g&&b<i&&u($(m,h.name),`${y} `,b+1)}}u(r,"",1),t.tree=d.slice(0,80),d.length>80&&(t.treeTruncated=!0);let p=["README.md","README.rst","src/App.tsx","src/App.jsx","src/App.js","src/routes.tsx","src/routes.js","app/routes.tsx","app/routes.js","src/index.tsx","src/index.ts","src/main.tsx","src/main.ts","pages/_app.tsx","pages/_app.js","app/layout.tsx","docker-compose.yml","Dockerfile",".env.example"];return t.keyFilesFound=p.filter(m=>v($(r,m))),JSON.stringify(t)}import{existsSync as Re}from"fs";import{fileURLToPath as Ae}from"url";import{dirname as Oe,resolve as ve}from"path";import{resolveIntegrationToken as ee}from"@zibby/core/backend-client.js";var k=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",LARK_DOCS:"lark_docs",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",VIKUNJA:"vikunja",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),Fe=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"},lark_docs:{id:"lark_docs",name:"Lark Docs",connectPath:"/integrations?provider=lark_docs"},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"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},vikunja:{id:"vikunja",name:"Vikunja",connectPath:"/integrations?provider=vikunja"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});import ye from"crypto";var Z=/<!--\s*zbfp:([a-f0-9]{8,20})\s*-->/i,X=/<!--\s*zbreview-summary\s*-->/i;function _e(c){return String(c||"").replace(Z,"").replace(X,"").replace(/\b(?:lines?|L)\s*#?\d+(?:\s*[-–]\s*\d+)?/gi,"").replace(/[`*_>#~]/g,"").replace(/\s+/g," ").trim().toLowerCase().slice(0,400)}function we(c,n){return ye.createHash("sha256").update(`${String(c||"")}\0${_e(n)}`).digest("hex").slice(0,12)}function Se(c){return`
|
|
12
12
|
|
|
13
13
|
<!-- zbfp:${c} -->`}var q=`
|
|
14
14
|
|
package/dist/github.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{existsSync as M}from"fs";import{fileURLToPath as D}from"url";import{dirname as F,resolve as B}from"path";import{resolveIntegrationToken as
|
|
1
|
+
import{existsSync as M}from"fs";import{fileURLToPath as D}from"url";import{dirname as F,resolve as B}from"path";import{resolveIntegrationToken as L}from"@zibby/core/backend-client.js";var A=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",LARK_DOCS:"lark_docs",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",VIKUNJA:"vikunja",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),Q=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"},lark_docs:{id:"lark_docs",name:"Lark Docs",connectPath:"/integrations?provider=lark_docs"},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"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},vikunja:{id:"vikunja",name:"Vikunja",connectPath:"/integrations?provider=vikunja"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});import{spawn as Y,execSync as Z}from"child_process";import{existsSync as ee,mkdirSync as te,readdirSync as re,statSync as ie,readFileSync as ne}from"fs";import{resolve as oe,join as ae,basename as pe}from"path";function P(h,a,t,i,n="clone"){try{h(`git -C "${a}" remote set-url origin "${t}"`,{stdio:"pipe"})}catch(e){let r=String(e?.message||e);i&&(r=r.split(i).join("***")),console.error(`[${n}] WARNING: failed to strip token from .git/config: ${r}`)}}import J from"crypto";var T=/<!--\s*zbfp:([a-f0-9]{8,20})\s*-->/i,E=/<!--\s*zbreview-summary\s*-->/i;function H(h){return String(h||"").replace(T,"").replace(E,"").replace(/\b(?:lines?|L)\s*#?\d+(?:\s*[-–]\s*\d+)?/gi,"").replace(/[`*_>#~]/g,"").replace(/\s+/g," ").trim().toLowerCase().slice(0,400)}function U(h,a){return J.createHash("sha256").update(`${String(h||"")}\0${H(a)}`).digest("hex").slice(0,12)}function j(h){return`
|
|
2
2
|
|
|
3
3
|
<!-- zbfp:${h} -->`}var I=`
|
|
4
4
|
|
|
5
|
-
<!-- zbreview-summary -->`;function C(h){let a=T.exec(String(h||""));return a?a[1].toLowerCase():null}function q(h){return E.test(String(h||""))}function G(h,a){let t=new Set([...a||[]].map(e=>String(e).toLowerCase())),i=[],n=0;for(let e of Array.isArray(h)?h:[]){if(!e||!e.body)continue;let r=U(e.path,e.body);if(t.has(r)){n+=1;continue}t.add(r),i.push({...e,_fp:r,body:`${String(e.body)}${j(r)}`})}return{toPost:i,skipped:n}}function z(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let h=F(D(import.meta.url)),a=B(h,"..","bin","mcp-skill.mjs");return M(a)?a:null}async function l(h,a={}){let{token:t}=await
|
|
5
|
+
<!-- zbreview-summary -->`;function C(h){let a=T.exec(String(h||""));return a?a[1].toLowerCase():null}function q(h){return E.test(String(h||""))}function G(h,a){let t=new Set([...a||[]].map(e=>String(e).toLowerCase())),i=[],n=0;for(let e of Array.isArray(h)?h:[]){if(!e||!e.body)continue;let r=U(e.path,e.body);if(t.has(r)){n+=1;continue}t.add(r),i.push({...e,_fp:r,body:`${String(e.body)}${j(r)}`})}return{toPost:i,skipped:n}}function z(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let h=F(D(import.meta.url)),a=B(h,"..","bin","mcp-skill.mjs");return M(a)?a:null}async function l(h,a={}){let{token:t}=await L("github"),i=h.startsWith("https://")?h:`https://api.github.com${h}`,n={Authorization:`Bearer ${t}`,Accept:a.accept||"application/vnd.github.v3+json","User-Agent":"Zibby-App",...a.body?{"Content-Type":"application/json"}:{}},e=await fetch(i,{method:a.method||"GET",headers:n,body:a.body?JSON.stringify(a.body):void 0});if(!e.ok){let r=await e.text().catch(()=>"");throw new Error(`GitHub API ${e.status}: ${r.slice(0,300)}`)}return a.raw?e.text():e.json()}var _e={id:"github",callsBackend:!0,serverName:"github",allowedTools:["mcp__github__*"],requiresIntegration:A.GITHUB,envKeys:["GITHUB_TOKEN","PROJECT_API_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV"],description:"GitHub \u2014 issues, PRs, commits, code search, file reading",promptFragment:`## GitHub
|
|
6
6
|
You have access to the user's GitHub repositories. Available tools:
|
|
7
7
|
|
|
8
8
|
### Discovery
|
|
@@ -45,6 +45,6 @@ When user says "check out repo-name" or "clone repo-name":
|
|
|
45
45
|
3. STOP. Do not offer to inspect files or ask what to do next.
|
|
46
46
|
|
|
47
47
|
When user just wants to "look at" or "read" files (not clone):
|
|
48
|
-
- Use github_get_file to read individual files via API`,resolve(){let h=z();if(!h)return{command:null,args:[],env:{},description:this.description};let a={};for(let t of this.envKeys)process.env[t]&&(a[t]=process.env[t]);return{type:"stdio",command:"node",args:[h,"../dist/github.js","githubSkill"],env:a,description:this.description,alwaysLoad:!0}},async handleToolCall(h,a){try{switch(h){case"github_search_issues":{let t=a.query;if(!t)return JSON.stringify({error:"query is required"});let i=await l(`/search/issues?q=${encodeURIComponent(t)}&per_page=${a.limit||20}`),n=(i.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(r=>r.name),createdAt:e.created_at}));return JSON.stringify({total:i.total_count,items:n})}case"github_search_code":{let t=a.query;if(!t)return JSON.stringify({error:"query is required"});let i=a.repo?`+repo:${a.repo}`:"",n=a.language?`+language:${a.language}`:"",e=await l(`/search/code?q=${encodeURIComponent(t)}${i}${n}&per_page=${a.limit||15}`),r=(e.items||[]).map(o=>({name:o.name,path:o.path,repo:o.repository?.full_name,url:o.html_url,score:o.score}));return JSON.stringify({total:e.total_count,items:r})}case"github_get_pr":{let{owner:t,repo:i,number:n}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/pulls/${n}`);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(r=>r.name)})}case"github_get_pr_diff":{let{owner:t,repo:i,number:n}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/pulls/${n}`,{accept:"application/vnd.github.v3.diff",raw:!0}),r=e.length>15e3;return JSON.stringify({number:n,diff:r?e.slice(0,15e3):e,truncated:r,totalLength:e.length})}case"github_list_pr_files":{let{owner:t,repo:i,number:n}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/pulls/${n}/files?per_page=100`);return JSON.stringify({total:e.length,files:e.map(r=>({filename:r.filename,status:r.status,additions:r.additions,deletions:r.deletions,patch:r.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:t,repo:i,number:n}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/pulls/${n}/comments?per_page=50`),r=await l(`/repos/${t}/${i}/issues/${n}/comments?per_page=50`),o=[...e.map(s=>({type:"review",user:s.user?.login,body:s.body?.slice(0,1e3),path:s.path,line:s.line,createdAt:s.created_at})),...r.map(s=>({type:"issue",user:s.user?.login,body:s.body?.slice(0,1e3),createdAt:s.created_at}))].sort((s,m)=>new Date(s.createdAt)-new Date(m.createdAt));return JSON.stringify({total:o.length,comments:o})}case"github_get_review_thread":{let{owner:t,repo:i,number:n,commentId:e}=a||{};if(!t||!i||!n||!e)return JSON.stringify({error:"owner, repo, number, and commentId are required"});let r=await l(`/repos/${t}/${i}/pulls/comments/${e}`),o=r.in_reply_to_id||r.id,s=[];try{s=await l(`/repos/${t}/${i}/pulls/${n}/comments?per_page=100`)}catch{s=[r]}(!Array.isArray(s)||s.length===0)&&(s=[r]);let m=s.filter(g=>g.id===o||g.in_reply_to_id===o).sort((g,b)=>new Date(g.created_at)-new Date(b.created_at)),u=m.length?m:[r],c=u.find(g=>g.id===o)||u[0];return JSON.stringify({rootCommentId:o,path:c.path,line:c.line??c.original_line??null,side:c.side||"RIGHT",diffHunk:typeof c.diff_hunk=="string"?c.diff_hunk.slice(0,3e3):null,commitId:c.commit_id||c.original_commit_id||null,notes:u.map(g=>({id:g.id,user:g.user?.login,body:(g.body||"").slice(0,4e3),createdAt:g.created_at,isRoot:g.id===o,url:g.html_url}))})}case"github_reply_review_thread":{let{owner:t,repo:i,number:n,commentId:e,body:r}=a||{};if(!t||!i||!n||!e||!r)return JSON.stringify({error:"owner, repo, number, commentId, and body are required"});let o=await l(`/repos/${t}/${i}/pulls/${n}/comments/${e}/replies`,{method:"POST",body:{body:String(r)}});return JSON.stringify({ok:!0,id:o.id,url:o.html_url,inReplyTo:o.in_reply_to_id})}case"github_reply_issue_comment":{let{owner:t,repo:i,number:n,body:e}=a||{};if(!t||!i||!n||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let r=await l(`/repos/${t}/${i}/issues/${n}/comments`,{method:"POST",body:{body:String(e)}});return JSON.stringify({ok:!0,id:r.id,url:r.html_url})}case"github_create_review":{let{owner:t,repo:i,number:n,body:e,event:r,comments:o}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let s=(r||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(s))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${r})`});let m=Array.isArray(o)?o.filter(d=>d&&d.path&&d.body&&(d.line!=null||d.position!=null)).map(d=>{let p={path:d.path,body:String(d.body)};return d.line!=null?(p.line=Number(d.line),p.side=d.side==="LEFT"?"LEFT":"RIGHT"):p.position=Number(d.position),p}):[];if(s!=="APPROVE"&&!e&&m.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let u=new Set,c=null;try{for(let d=1;d<=20;d+=1){let p=await l(`/repos/${t}/${i}/pulls/${n}/comments?per_page=100&page=${d}`);if(!Array.isArray(p)||p.length===0)break;for(let f of p){let R=C(f.body);R&&u.add(R)}if(p.length<100)break}for(let d=1;d<=20&&c==null;d+=1){let p=await l(`/repos/${t}/${i}/issues/${n}/comments?per_page=100&page=${d}`);if(!Array.isArray(p)||p.length===0)break;for(let f of p)if(q(f.body)){c=f.id;break}if(p.length<100)break}}catch{}let g=!1,b=!1;if(e){let d=`${String(e)}${I}`;try{c!=null?(await l(`/repos/${t}/${i}/issues/comments/${c}`,{method:"PATCH",body:{body:d}}),g=!0):await l(`/repos/${t}/${i}/issues/${n}/comments`,{method:"POST",body:{body:d}}),b=!0}catch{}}let{toPost:y,skipped:w}=G(m,u),_=y.map(({_fp:d,...p})=>p),S=null;if(_.length>0||s==="APPROVE"||s==="REQUEST_CHANGES"){let d={event:s};_.length>0&&(d.comments=_),_.length===0&&s==="REQUEST_CHANGES"&&(d.body="Changes requested \u2014 see the review summary comment."),S=await l(`/repos/${t}/${i}/pulls/${n}/reviews`,{method:"POST",body:d})}return JSON.stringify({ok:!0,id:S?S.id:void 0,state:S?S.state:void 0,event:s,notePosted:b,summaryUpdated:g,commentsPosted:_.length,inlineSkipped:w||void 0,url:S?S.html_url:void 0})}case"github_list_commits":{let{owner:t,repo:i,branch:n,path:e,limit:r,since:o,until:s,page:m}=a;if(!t||!i)return JSON.stringify({error:"owner and repo are required"});let u=Math.min(Number(r)||20,100),c=`/repos/${t}/${i}/commits?per_page=${u}&page=${Number(m)||1}`;n&&(c+=`&sha=${encodeURIComponent(n)}`),e&&(c+=`&path=${encodeURIComponent(e)}`),o&&(c+=`&since=${encodeURIComponent(o)}`),s&&(c+=`&until=${encodeURIComponent(s)}`);let g=await l(c);return JSON.stringify({total:g.length,page:Number(m)||1,hasMore:g.length>=u,commits:g.map(b=>({sha:b.sha?.slice(0,8),fullSha:b.sha,message:b.commit?.message?.slice(0,300),author:b.commit?.author?.name,authorEmail:b.commit?.author?.email,date:b.commit?.author?.date,url:b.html_url}))})}case"github_get_commit":{let{owner:t,repo:i,sha:n,includePrs:e}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and sha are required"});let r=await l(`/repos/${t}/${i}/commits/${n}`),o;if(e)try{let s=await l(`/repos/${t}/${i}/commits/${n}/pulls`);o=(Array.isArray(s)?s:[]).map(m=>({number:m.number,title:m.title,state:m.state,merged:!!m.merged_at,webUrl:m.html_url}))}catch{o=[]}return JSON.stringify({sha:r.sha?.slice(0,8),message:r.commit?.message,author:r.commit?.author?.name,date:r.commit?.author?.date,stats:r.stats,files:(r.files||[]).map(s=>({filename:s.filename,status:s.status,additions:s.additions,deletions:s.deletions,patch:s.patch?.slice(0,3e3)})),...o?{pullRequests:o}:{}})}case"github_get_file":{let{owner:t,repo:i,path:n,ref:e}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and path are required"});let r=`/repos/${t}/${i}/contents/${encodeURIComponent(n)}`;e&&(r+=`?ref=${encodeURIComponent(e)}`);let o=await l(r);if(o.type!=="file")return Array.isArray(o)?JSON.stringify({type:"directory",path:n,entries:o.map(u=>({name:u.name,type:u.type,size:u.size,path:u.path}))}):JSON.stringify({error:`Not a file: ${o.type}`});let s=Buffer.from(o.content||"","base64").toString("utf-8"),m=s.length>2e4;return JSON.stringify({path:o.path,size:o.size,sha:o.sha?.slice(0,8),content:m?s.slice(0,2e4):s,truncated:m})}case"github_get_user":try{let t=await l("/installation/repositories?per_page=1");if(t.repositories&&t.repositories.length>0){let i=t.repositories[0],n=i.owner.login,e=i.owner.type,r=e==="Organization"?`/orgs/${n}`:`/users/${n}`,o=await l(r);return JSON.stringify({login:o.login,name:o.name||o.login,avatar:o.avatar_url,bio:o.bio||o.description,type:e,isOrg:e==="Organization",publicRepos:o.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 i=(await l("/installation/repositories?per_page=100")).repositories||[],n=new Map;for(let r of i)r.owner.type==="Organization"&&(n.has(r.owner.login)||n.set(r.owner.login,{login:r.owner.login,description:null,url:r.owner.url}));let e=Array.from(n.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 y=function(d){let p=d.replace(/^~(?=$|\/|\\)/,b);return o(p)},{owner:t,repo:i,destination:n}=a;if(!t||!i)return JSON.stringify({error:"owner and repo are required"});let{execSync:e}=await import("child_process"),{join:r,resolve:o}=await import("path"),{existsSync:s,mkdirSync:m}=await import("fs"),{homedir:u,platform:c}=await import("os"),{token:g}=await x("github"),b=u(),w=n?y(n):r(b,"zibby-repos"),_=r(w,i);if(m(w,{recursive:!0}),s(_))return JSON.stringify({error:`Directory ${_} already exists. Remove it first or use a different destination.`,existingPath:_});let S=`https://x-access-token:${g}@github.com/${t}/${i}.git`;try{e(`git clone ${S} "${_}"`,{stdio:"pipe"});let d=`https://github.com/${t}/${i}.git`;P(e,_,d,g,"github_clone");let p=c()==="win32",f;return p?f=e(`dir "${_}"`,{encoding:"utf-8",shell:"cmd.exe"}):f=e(`ls -la "${_}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:_,message:`Cloned ${t}/${i} to ${_}`,contents:f.split(`
|
|
48
|
+
- Use github_get_file to read individual files via API`,resolve(){let h=z();if(!h)return{command:null,args:[],env:{},description:this.description};let a={};for(let t of this.envKeys)process.env[t]&&(a[t]=process.env[t]);return{type:"stdio",command:"node",args:[h,"../dist/github.js","githubSkill"],env:a,description:this.description,alwaysLoad:!0}},async handleToolCall(h,a){try{switch(h){case"github_search_issues":{let t=a.query;if(!t)return JSON.stringify({error:"query is required"});let i=await l(`/search/issues?q=${encodeURIComponent(t)}&per_page=${a.limit||20}`),n=(i.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(r=>r.name),createdAt:e.created_at}));return JSON.stringify({total:i.total_count,items:n})}case"github_search_code":{let t=a.query;if(!t)return JSON.stringify({error:"query is required"});let i=a.repo?`+repo:${a.repo}`:"",n=a.language?`+language:${a.language}`:"",e=await l(`/search/code?q=${encodeURIComponent(t)}${i}${n}&per_page=${a.limit||15}`),r=(e.items||[]).map(o=>({name:o.name,path:o.path,repo:o.repository?.full_name,url:o.html_url,score:o.score}));return JSON.stringify({total:e.total_count,items:r})}case"github_get_pr":{let{owner:t,repo:i,number:n}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/pulls/${n}`);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(r=>r.name)})}case"github_get_pr_diff":{let{owner:t,repo:i,number:n}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/pulls/${n}`,{accept:"application/vnd.github.v3.diff",raw:!0}),r=e.length>15e3;return JSON.stringify({number:n,diff:r?e.slice(0,15e3):e,truncated:r,totalLength:e.length})}case"github_list_pr_files":{let{owner:t,repo:i,number:n}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/pulls/${n}/files?per_page=100`);return JSON.stringify({total:e.length,files:e.map(r=>({filename:r.filename,status:r.status,additions:r.additions,deletions:r.deletions,patch:r.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:t,repo:i,number:n}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/pulls/${n}/comments?per_page=50`),r=await l(`/repos/${t}/${i}/issues/${n}/comments?per_page=50`),o=[...e.map(s=>({type:"review",user:s.user?.login,body:s.body?.slice(0,1e3),path:s.path,line:s.line,createdAt:s.created_at})),...r.map(s=>({type:"issue",user:s.user?.login,body:s.body?.slice(0,1e3),createdAt:s.created_at}))].sort((s,m)=>new Date(s.createdAt)-new Date(m.createdAt));return JSON.stringify({total:o.length,comments:o})}case"github_get_review_thread":{let{owner:t,repo:i,number:n,commentId:e}=a||{};if(!t||!i||!n||!e)return JSON.stringify({error:"owner, repo, number, and commentId are required"});let r=await l(`/repos/${t}/${i}/pulls/comments/${e}`),o=r.in_reply_to_id||r.id,s=[];try{s=await l(`/repos/${t}/${i}/pulls/${n}/comments?per_page=100`)}catch{s=[r]}(!Array.isArray(s)||s.length===0)&&(s=[r]);let m=s.filter(g=>g.id===o||g.in_reply_to_id===o).sort((g,b)=>new Date(g.created_at)-new Date(b.created_at)),u=m.length?m:[r],c=u.find(g=>g.id===o)||u[0];return JSON.stringify({rootCommentId:o,path:c.path,line:c.line??c.original_line??null,side:c.side||"RIGHT",diffHunk:typeof c.diff_hunk=="string"?c.diff_hunk.slice(0,3e3):null,commitId:c.commit_id||c.original_commit_id||null,notes:u.map(g=>({id:g.id,user:g.user?.login,body:(g.body||"").slice(0,4e3),createdAt:g.created_at,isRoot:g.id===o,url:g.html_url}))})}case"github_reply_review_thread":{let{owner:t,repo:i,number:n,commentId:e,body:r}=a||{};if(!t||!i||!n||!e||!r)return JSON.stringify({error:"owner, repo, number, commentId, and body are required"});let o=await l(`/repos/${t}/${i}/pulls/${n}/comments/${e}/replies`,{method:"POST",body:{body:String(r)}});return JSON.stringify({ok:!0,id:o.id,url:o.html_url,inReplyTo:o.in_reply_to_id})}case"github_reply_issue_comment":{let{owner:t,repo:i,number:n,body:e}=a||{};if(!t||!i||!n||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let r=await l(`/repos/${t}/${i}/issues/${n}/comments`,{method:"POST",body:{body:String(e)}});return JSON.stringify({ok:!0,id:r.id,url:r.html_url})}case"github_create_review":{let{owner:t,repo:i,number:n,body:e,event:r,comments:o}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let s=(r||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(s))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${r})`});let m=Array.isArray(o)?o.filter(d=>d&&d.path&&d.body&&(d.line!=null||d.position!=null)).map(d=>{let p={path:d.path,body:String(d.body)};return d.line!=null?(p.line=Number(d.line),p.side=d.side==="LEFT"?"LEFT":"RIGHT"):p.position=Number(d.position),p}):[];if(s!=="APPROVE"&&!e&&m.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let u=new Set,c=null;try{for(let d=1;d<=20;d+=1){let p=await l(`/repos/${t}/${i}/pulls/${n}/comments?per_page=100&page=${d}`);if(!Array.isArray(p)||p.length===0)break;for(let f of p){let R=C(f.body);R&&u.add(R)}if(p.length<100)break}for(let d=1;d<=20&&c==null;d+=1){let p=await l(`/repos/${t}/${i}/issues/${n}/comments?per_page=100&page=${d}`);if(!Array.isArray(p)||p.length===0)break;for(let f of p)if(q(f.body)){c=f.id;break}if(p.length<100)break}}catch{}let g=!1,b=!1;if(e){let d=`${String(e)}${I}`;try{c!=null?(await l(`/repos/${t}/${i}/issues/comments/${c}`,{method:"PATCH",body:{body:d}}),g=!0):await l(`/repos/${t}/${i}/issues/${n}/comments`,{method:"POST",body:{body:d}}),b=!0}catch{}}let{toPost:y,skipped:w}=G(m,u),_=y.map(({_fp:d,...p})=>p),S=null;if(_.length>0||s==="APPROVE"||s==="REQUEST_CHANGES"){let d={event:s};_.length>0&&(d.comments=_),_.length===0&&s==="REQUEST_CHANGES"&&(d.body="Changes requested \u2014 see the review summary comment."),S=await l(`/repos/${t}/${i}/pulls/${n}/reviews`,{method:"POST",body:d})}return JSON.stringify({ok:!0,id:S?S.id:void 0,state:S?S.state:void 0,event:s,notePosted:b,summaryUpdated:g,commentsPosted:_.length,inlineSkipped:w||void 0,url:S?S.html_url:void 0})}case"github_list_commits":{let{owner:t,repo:i,branch:n,path:e,limit:r,since:o,until:s,page:m}=a;if(!t||!i)return JSON.stringify({error:"owner and repo are required"});let u=Math.min(Number(r)||20,100),c=`/repos/${t}/${i}/commits?per_page=${u}&page=${Number(m)||1}`;n&&(c+=`&sha=${encodeURIComponent(n)}`),e&&(c+=`&path=${encodeURIComponent(e)}`),o&&(c+=`&since=${encodeURIComponent(o)}`),s&&(c+=`&until=${encodeURIComponent(s)}`);let g=await l(c);return JSON.stringify({total:g.length,page:Number(m)||1,hasMore:g.length>=u,commits:g.map(b=>({sha:b.sha?.slice(0,8),fullSha:b.sha,message:b.commit?.message?.slice(0,300),author:b.commit?.author?.name,authorEmail:b.commit?.author?.email,date:b.commit?.author?.date,url:b.html_url}))})}case"github_get_commit":{let{owner:t,repo:i,sha:n,includePrs:e}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and sha are required"});let r=await l(`/repos/${t}/${i}/commits/${n}`),o;if(e)try{let s=await l(`/repos/${t}/${i}/commits/${n}/pulls`);o=(Array.isArray(s)?s:[]).map(m=>({number:m.number,title:m.title,state:m.state,merged:!!m.merged_at,webUrl:m.html_url}))}catch{o=[]}return JSON.stringify({sha:r.sha?.slice(0,8),message:r.commit?.message,author:r.commit?.author?.name,date:r.commit?.author?.date,stats:r.stats,files:(r.files||[]).map(s=>({filename:s.filename,status:s.status,additions:s.additions,deletions:s.deletions,patch:s.patch?.slice(0,3e3)})),...o?{pullRequests:o}:{}})}case"github_get_file":{let{owner:t,repo:i,path:n,ref:e}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and path are required"});let r=`/repos/${t}/${i}/contents/${encodeURIComponent(n)}`;e&&(r+=`?ref=${encodeURIComponent(e)}`);let o=await l(r);if(o.type!=="file")return Array.isArray(o)?JSON.stringify({type:"directory",path:n,entries:o.map(u=>({name:u.name,type:u.type,size:u.size,path:u.path}))}):JSON.stringify({error:`Not a file: ${o.type}`});let s=Buffer.from(o.content||"","base64").toString("utf-8"),m=s.length>2e4;return JSON.stringify({path:o.path,size:o.size,sha:o.sha?.slice(0,8),content:m?s.slice(0,2e4):s,truncated:m})}case"github_get_user":try{let t=await l("/installation/repositories?per_page=1");if(t.repositories&&t.repositories.length>0){let i=t.repositories[0],n=i.owner.login,e=i.owner.type,r=e==="Organization"?`/orgs/${n}`:`/users/${n}`,o=await l(r);return JSON.stringify({login:o.login,name:o.name||o.login,avatar:o.avatar_url,bio:o.bio||o.description,type:e,isOrg:e==="Organization",publicRepos:o.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 i=(await l("/installation/repositories?per_page=100")).repositories||[],n=new Map;for(let r of i)r.owner.type==="Organization"&&(n.has(r.owner.login)||n.set(r.owner.login,{login:r.owner.login,description:null,url:r.owner.url}));let e=Array.from(n.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 y=function(d){let p=d.replace(/^~(?=$|\/|\\)/,b);return o(p)},{owner:t,repo:i,destination:n}=a;if(!t||!i)return JSON.stringify({error:"owner and repo are required"});let{execSync:e}=await import("child_process"),{join:r,resolve:o}=await import("path"),{existsSync:s,mkdirSync:m}=await import("fs"),{homedir:u,platform:c}=await import("os"),{token:g}=await L("github"),b=u(),w=n?y(n):r(b,"zibby-repos"),_=r(w,i);if(m(w,{recursive:!0}),s(_))return JSON.stringify({error:`Directory ${_} already exists. Remove it first or use a different destination.`,existingPath:_});let S=`https://x-access-token:${g}@github.com/${t}/${i}.git`;try{e(`git clone ${S} "${_}"`,{stdio:"pipe"});let d=`https://github.com/${t}/${i}.git`;P(e,_,d,g,"github_clone");let p=c()==="win32",f;return p?f=e(`dir "${_}"`,{encoding:"utf-8",shell:"cmd.exe"}):f=e(`ls -la "${_}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:_,message:`Cloned ${t}/${i} to ${_}`,contents:f.split(`
|
|
49
49
|
`).slice(0,30).join(`
|
|
50
|
-
`),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(d){let f=String(d.message||d).split(g).join("***").replace(/x-access-token:[^@]*@/g,"x-access-token:***@");return JSON.stringify({error:`Clone failed: ${f}`})}}case"github_search_repos":{let{query:t,limit:i}=a;if(!t)return JSON.stringify({error:"query is required"});let n=await this.handleToolCall("github_list_repos",{limit:200},{}),e=JSON.parse(n);if(e.error)return JSON.stringify(e);let r=t.toLowerCase(),o=e.repos.filter(s=>s.name.toLowerCase().includes(r)||s.fullName.toLowerCase().includes(r)||s.description&&s.description.toLowerCase().includes(r));return JSON.stringify({query:t,count:o.length,repos:o.slice(0,i||20)})}case"github_list_repos":{let{owner:t,type:i,sort:n,direction:e,limit:r,query:o}=a,s=100,m=r||200,u=[],c=p=>({name:p.name,fullName:p.full_name,private:p.private,description:p.description,language:p.language,defaultBranch:p.default_branch,updatedAt:p.updated_at,stars:p.stargazers_count,url:p.html_url,fullPath:p.full_name,webUrl:p.html_url,visibility:p.visibility||(p.private?"private":"public")}),g=p=>{if(!o)return!0;let f=String(o).toLowerCase();return p.name&&p.name.toLowerCase().includes(f)||p.fullName&&p.fullName.toLowerCase().includes(f)||p.description&&p.description.toLowerCase().includes(f)};if(!t){let p=1,f=!0;for(;f&&u.length<m;){let O=`/installation/repositories?per_page=${s}&page=${p}`,v=(await l(O)).repositories||[];if(v.length===0)break;u=u.concat(v),f=v.length===s,p++}let R=u.map(c).filter(g),$=R.slice(0,m),L=R.length>$.length,N=$.filter(O=>O.private).length,k=$.filter(O=>!O.private).length;return JSON.stringify({count:$.length,repos:$,truncated:L,privateCount:N,publicCount:k,message:`Found ${N} private and ${k} public repos`})}let b=await l(`/orgs/${t}`).then(()=>!0).catch(()=>!1),y=1,w=!0;for(;w&&u.length<m;){let p;b?p=`/orgs/${t}/repos?per_page=${s}&page=${y}&type=${i||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`:p=`/users/${t}/repos?per_page=${s}&page=${y}&type=${i||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`;let f=await l(p),R=Array.isArray(f)?f:[];if(R.length===0)break;u=u.concat(R),w=R.length===s,y++}let _=u.map(c).filter(g),S=_.slice(0,m),d=_.length>S.length;return JSON.stringify({count:S.length,repos:S,truncated:d})}case"github_create_pr":{let{owner:t,repo:i,head:n,title:e}=a||{};if(!t||!i||!n||!e)return JSON.stringify({error:"owner, repo, head (source branch), and title are required"});let r=a.base;if(!r)try{r=(await l(`/repos/${t}/${i}`)).default_branch||"main"}catch{r="main"}let o={title:String(e),head:String(n),base:String(r),body:a.body?String(a.body):"",draft:!!a.draft};try{let s=await l(`/repos/${t}/${i}/pulls`,{method:"POST",body:o});return JSON.stringify({success:!0,pr_url:s.html_url,number:s.number,branch:n,base:r,repo:`${t}/${i}`,provider:"github",draft:!!s.draft,state:s.state})}catch(s){let m=String(s.message||s);if(/GitHub API 422/.test(m))return JSON.stringify({success:!1,branch:n,base:r,repo:`${t}/${i}`,provider:"github",skippedReason:m});throw s}}case"github_merge_pr":{let{owner:t,repo:i,number:n}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=a.mergeMethod||"squash";if(!["merge","squash","rebase"].includes(e))return JSON.stringify({error:`mergeMethod must be merge, squash, or rebase (got ${e})`});let r={merge_method:e};a.commitTitle&&(r.commit_title=String(a.commitTitle)),a.commitMessage&&(r.commit_message=String(a.commitMessage));try{let o=await l(`/repos/${t}/${i}/pulls/${n}/merge`,{method:"PUT",body:r});return JSON.stringify({success:!0,merged:!0,sha:o.sha,number:n,provider:"github"})}catch(o){let s=String(o.message||o);if(/GitHub API (405|409|404)/.test(s))return JSON.stringify({success:!1,number:n,provider:"github",skippedReason:s});throw o}}case"github_create_issue":{let{owner:t,repo:i,title:n,body:e}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and title are required"});let r=await l(`/repos/${t}/${i}/issues`,{method:"POST",body:{title:n,body:e||""}});return JSON.stringify({number:r.number,url:r.html_url,title:r.title})}case"github_list_issues":{let{owner:t,repo:i,state:n,labels:e,since:r,assignee:o,sort:s,direction:m,limit:u}=a||{};if(!t||!i)return JSON.stringify({error:"owner and repo are required"});let c=new URLSearchParams;c.set("state",n||"open"),c.set("per_page",String(u||30)),c.set("sort",s||"updated"),c.set("direction",m||"desc"),e&&c.set("labels",Array.isArray(e)?e.join(","):e),r&&c.set("since",r),o&&c.set("assignee",o);let g=await l(`/repos/${t}/${i}/issues?${c.toString()}`),b=(Array.isArray(g)?g:[]).filter(y=>!y.pull_request).map(y=>({number:y.number,title:y.title,state:y.state,labels:(y.labels||[]).map(w=>typeof w=="string"?w:w.name),assignee:y.assignee?.login||null,assignees:(y.assignees||[]).map(w=>w.login),user:y.user?.login,comments:y.comments,url:y.html_url,createdAt:y.created_at,updatedAt:y.updated_at}));return JSON.stringify({count:b.length,issues:b})}case"github_get_issue":{let{owner:t,repo:i,number:n}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/issues/${n}`);return e.pull_request?JSON.stringify({error:`#${n} 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(r=>typeof r=="string"?r:r.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(r=>r.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:i,number:n,limit:e}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let r=await l(`/repos/${t}/${i}/issues/${n}/comments?per_page=${e||100}`),o=(Array.isArray(r)?r:[]).map(s=>({id:s.id,user:s.user?.login,body:s.body||"",createdAt:s.created_at,updatedAt:s.updated_at,url:s.html_url}));return JSON.stringify({count:o.length,comments:o})}case"github_add_issue_comment":{let{owner:t,repo:i,number:n,body:e}=a||{};if(!t||!i||!n||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let r=await l(`/repos/${t}/${i}/issues/${n}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:r.id,url:r.html_url})}case"github_close_issue":{let{owner:t,repo:i,number:n,stateReason:e}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let r={state:"closed"};e&&(r.state_reason=e);let o=await l(`/repos/${t}/${i}/issues/${n}`,{method:"PATCH",body:r});return JSON.stringify({ok:!0,number:o.number,state:o.state,stateReason:o.state_reason||null,url:o.html_url})}case"github_reopen_issue":{let{owner:t,repo:i,number:n}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/issues/${n}`,{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:i,number:n,labels:e,mode:r}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o=Array.isArray(e)?e:e?[e]:[];if(!o.length)return JSON.stringify({error:"labels (string or array) is required"});let s=r||"add";if(s==="set"){let u=await l(`/repos/${t}/${i}/issues/${n}`,{method:"PATCH",body:{labels:o}});return JSON.stringify({ok:!0,number:u.number,labels:(u.labels||[]).map(c=>typeof c=="string"?c:c.name)})}if(s==="remove"){for(let c of o)await l(`/repos/${t}/${i}/issues/${n}/labels/${encodeURIComponent(c)}`,{method:"DELETE"});let u=await l(`/repos/${t}/${i}/issues/${n}`);return JSON.stringify({ok:!0,number:u.number,labels:(u.labels||[]).map(c=>typeof c=="string"?c:c.name)})}let m=await l(`/repos/${t}/${i}/issues/${n}/labels`,{method:"POST",body:{labels:o}});return JSON.stringify({ok:!0,number:n,labels:(Array.isArray(m)?m:[]).map(u=>typeof u=="string"?u:u.name)})}default:return JSON.stringify({error:`Unknown tool: ${h}`})}}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 the repositories this token/installation can access (omit owner) \u2014 or a specific user/org's repos (pass owner). Use this to discover a RELATED repo worth cloning when a change's correctness depends on another accessible repo. Each repo carries a normalized { fullPath, name, webUrl, defaultBranch, visibility } shape (identical to gitlab_list_projects) alongside legacy fields, plus a truncated flag.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Org or user login. Omit to list every repo your token/installation can access."},query:{type:"string",description:"Optional term matched against repo name/full-name/description"},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: 200, hard-capped at the fetch ceiling)"}}}},{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_get_review_thread",description:"Read a PR review-comment THREAD given any comment id in it: the root review comment + all its replies, plus the anchored diff context (file, line, the original diff hunk). Use this to understand a human's reply to a previous review comment before replying in-thread.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},commentId:{type:"number",description:"Any review-comment id in the thread (the root or any reply)"}},required:["owner","repo","number","commentId"]}},{name:"github_reply_review_thread",description:"Reply IN-THREAD to an existing PR review-comment thread (a conversational reply nested under the thread the human commented on \u2014 NOT a fresh full review). Pass any comment id in the thread.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},commentId:{type:"number",description:"Any review-comment id in the thread to reply to"},body:{type:"string",description:"The reply text (markdown)"}},required:["owner","repo","number","commentId","body"]}},{name:"github_reply_issue_comment",description:"Post a reply on a PR's top-level conversation (a new issue comment on the PR). Use when the human replied to a non-inline/summary comment rather than an inline review thread. Quote or @-mention for context since issue comments are not threaded.",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 reply text (markdown)"}},required:["owner","repo","number","body"]}},{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 commits on a branch \u2014 optionally bounded by since/until ISO dates (date-window listing) and paginated (keep calling with page+1 while hasMore is true). 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:"Commits per page, max 100 (default: 20)"},since:{type:"string",description:'Only commits after this ISO-8601 date/time, e.g. "2026-01-01T00:00:00Z"'},until:{type:"string",description:"Only commits before this ISO-8601 date/time"},page:{type:"number",description:"Page number, 1-based (default 1)"}},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)"},includePrs:{type:"boolean",description:"Also return the pull request(s) containing this commit ({number,title,state,merged,webUrl}) \u2014 the evidence link for contribution records (default false)"}},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_pr",description:"Open a pull request on GitHub (POST /repos/{owner}/{repo}/pulls). The head (source) branch must already be pushed. Returns the REAL pr_url from GitHub \u2014 never fabricate a PR url. Expected business outcomes (no commits between base and head, a PR already exists for this branch, base==head, missing head) return { success:false, skippedReason } rather than erroring.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},head:{type:"string",description:'Source branch to merge FROM (must already be pushed). For a cross-fork PR use "fork-owner:branch".'},base:{type:"string",description:"Target branch to merge INTO (default: the repo's default branch)"},title:{type:"string",description:"PR title"},body:{type:"string",description:"PR description (markdown)"},draft:{type:"boolean",description:"Open as a draft PR (default: false)"}},required:["owner","repo","head","title"]}},{name:"github_merge_pr",description:"Merge a pull request on GitHub (PUT /repos/{owner}/{repo}/pulls/{number}/merge). mergeMethod is merge | squash | rebase (default squash). Returns { success:true, merged:true, sha } with the REAL merge SHA from GitHub. Expected non-mergeable outcomes (405 = draft / failing checks / branch protection, 409 = head sha moved / conflict, 404 = not found) return { success:false, skippedReason } rather than erroring.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number to merge"},mergeMethod:{type:"string",enum:["merge","squash","rebase"],description:"How to merge (default: squash)"},commitTitle:{type:"string",description:"Title for the merge/squash commit (optional)"},commitMessage:{type:"string",description:"Body for the merge/squash commit (optional)"}},required:["owner","repo","number"]}},{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"]}}]};export{l as ghFetch,_e as githubSkill};
|
|
50
|
+
`),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(d){let f=String(d.message||d).split(g).join("***").replace(/x-access-token:[^@]*@/g,"x-access-token:***@");return JSON.stringify({error:`Clone failed: ${f}`})}}case"github_search_repos":{let{query:t,limit:i}=a;if(!t)return JSON.stringify({error:"query is required"});let n=await this.handleToolCall("github_list_repos",{limit:200},{}),e=JSON.parse(n);if(e.error)return JSON.stringify(e);let r=t.toLowerCase(),o=e.repos.filter(s=>s.name.toLowerCase().includes(r)||s.fullName.toLowerCase().includes(r)||s.description&&s.description.toLowerCase().includes(r));return JSON.stringify({query:t,count:o.length,repos:o.slice(0,i||20)})}case"github_list_repos":{let{owner:t,type:i,sort:n,direction:e,limit:r,query:o}=a,s=100,m=r||200,u=[],c=p=>({name:p.name,fullName:p.full_name,private:p.private,description:p.description,language:p.language,defaultBranch:p.default_branch,updatedAt:p.updated_at,stars:p.stargazers_count,url:p.html_url,fullPath:p.full_name,webUrl:p.html_url,visibility:p.visibility||(p.private?"private":"public")}),g=p=>{if(!o)return!0;let f=String(o).toLowerCase();return p.name&&p.name.toLowerCase().includes(f)||p.fullName&&p.fullName.toLowerCase().includes(f)||p.description&&p.description.toLowerCase().includes(f)};if(!t){let p=1,f=!0;for(;f&&u.length<m;){let O=`/installation/repositories?per_page=${s}&page=${p}`,v=(await l(O)).repositories||[];if(v.length===0)break;u=u.concat(v),f=v.length===s,p++}let R=u.map(c).filter(g),$=R.slice(0,m),x=R.length>$.length,N=$.filter(O=>O.private).length,k=$.filter(O=>!O.private).length;return JSON.stringify({count:$.length,repos:$,truncated:x,privateCount:N,publicCount:k,message:`Found ${N} private and ${k} public repos`})}let b=await l(`/orgs/${t}`).then(()=>!0).catch(()=>!1),y=1,w=!0;for(;w&&u.length<m;){let p;b?p=`/orgs/${t}/repos?per_page=${s}&page=${y}&type=${i||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`:p=`/users/${t}/repos?per_page=${s}&page=${y}&type=${i||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`;let f=await l(p),R=Array.isArray(f)?f:[];if(R.length===0)break;u=u.concat(R),w=R.length===s,y++}let _=u.map(c).filter(g),S=_.slice(0,m),d=_.length>S.length;return JSON.stringify({count:S.length,repos:S,truncated:d})}case"github_create_pr":{let{owner:t,repo:i,head:n,title:e}=a||{};if(!t||!i||!n||!e)return JSON.stringify({error:"owner, repo, head (source branch), and title are required"});let r=a.base;if(!r)try{r=(await l(`/repos/${t}/${i}`)).default_branch||"main"}catch{r="main"}let o={title:String(e),head:String(n),base:String(r),body:a.body?String(a.body):"",draft:!!a.draft};try{let s=await l(`/repos/${t}/${i}/pulls`,{method:"POST",body:o});return JSON.stringify({success:!0,pr_url:s.html_url,number:s.number,branch:n,base:r,repo:`${t}/${i}`,provider:"github",draft:!!s.draft,state:s.state})}catch(s){let m=String(s.message||s);if(/GitHub API 422/.test(m))return JSON.stringify({success:!1,branch:n,base:r,repo:`${t}/${i}`,provider:"github",skippedReason:m});throw s}}case"github_merge_pr":{let{owner:t,repo:i,number:n}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=a.mergeMethod||"squash";if(!["merge","squash","rebase"].includes(e))return JSON.stringify({error:`mergeMethod must be merge, squash, or rebase (got ${e})`});let r={merge_method:e};a.commitTitle&&(r.commit_title=String(a.commitTitle)),a.commitMessage&&(r.commit_message=String(a.commitMessage));try{let o=await l(`/repos/${t}/${i}/pulls/${n}/merge`,{method:"PUT",body:r});return JSON.stringify({success:!0,merged:!0,sha:o.sha,number:n,provider:"github"})}catch(o){let s=String(o.message||o);if(/GitHub API (405|409|404)/.test(s))return JSON.stringify({success:!1,number:n,provider:"github",skippedReason:s});throw o}}case"github_create_issue":{let{owner:t,repo:i,title:n,body:e}=a;if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and title are required"});let r=await l(`/repos/${t}/${i}/issues`,{method:"POST",body:{title:n,body:e||""}});return JSON.stringify({number:r.number,url:r.html_url,title:r.title})}case"github_list_issues":{let{owner:t,repo:i,state:n,labels:e,since:r,assignee:o,sort:s,direction:m,limit:u}=a||{};if(!t||!i)return JSON.stringify({error:"owner and repo are required"});let c=new URLSearchParams;c.set("state",n||"open"),c.set("per_page",String(u||30)),c.set("sort",s||"updated"),c.set("direction",m||"desc"),e&&c.set("labels",Array.isArray(e)?e.join(","):e),r&&c.set("since",r),o&&c.set("assignee",o);let g=await l(`/repos/${t}/${i}/issues?${c.toString()}`),b=(Array.isArray(g)?g:[]).filter(y=>!y.pull_request).map(y=>({number:y.number,title:y.title,state:y.state,labels:(y.labels||[]).map(w=>typeof w=="string"?w:w.name),assignee:y.assignee?.login||null,assignees:(y.assignees||[]).map(w=>w.login),user:y.user?.login,comments:y.comments,url:y.html_url,createdAt:y.created_at,updatedAt:y.updated_at}));return JSON.stringify({count:b.length,issues:b})}case"github_get_issue":{let{owner:t,repo:i,number:n}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/issues/${n}`);return e.pull_request?JSON.stringify({error:`#${n} 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(r=>typeof r=="string"?r:r.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(r=>r.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:i,number:n,limit:e}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let r=await l(`/repos/${t}/${i}/issues/${n}/comments?per_page=${e||100}`),o=(Array.isArray(r)?r:[]).map(s=>({id:s.id,user:s.user?.login,body:s.body||"",createdAt:s.created_at,updatedAt:s.updated_at,url:s.html_url}));return JSON.stringify({count:o.length,comments:o})}case"github_add_issue_comment":{let{owner:t,repo:i,number:n,body:e}=a||{};if(!t||!i||!n||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let r=await l(`/repos/${t}/${i}/issues/${n}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:r.id,url:r.html_url})}case"github_close_issue":{let{owner:t,repo:i,number:n,stateReason:e}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let r={state:"closed"};e&&(r.state_reason=e);let o=await l(`/repos/${t}/${i}/issues/${n}`,{method:"PATCH",body:r});return JSON.stringify({ok:!0,number:o.number,state:o.state,stateReason:o.state_reason||null,url:o.html_url})}case"github_reopen_issue":{let{owner:t,repo:i,number:n}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/issues/${n}`,{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:i,number:n,labels:e,mode:r}=a||{};if(!t||!i||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o=Array.isArray(e)?e:e?[e]:[];if(!o.length)return JSON.stringify({error:"labels (string or array) is required"});let s=r||"add";if(s==="set"){let u=await l(`/repos/${t}/${i}/issues/${n}`,{method:"PATCH",body:{labels:o}});return JSON.stringify({ok:!0,number:u.number,labels:(u.labels||[]).map(c=>typeof c=="string"?c:c.name)})}if(s==="remove"){for(let c of o)await l(`/repos/${t}/${i}/issues/${n}/labels/${encodeURIComponent(c)}`,{method:"DELETE"});let u=await l(`/repos/${t}/${i}/issues/${n}`);return JSON.stringify({ok:!0,number:u.number,labels:(u.labels||[]).map(c=>typeof c=="string"?c:c.name)})}let m=await l(`/repos/${t}/${i}/issues/${n}/labels`,{method:"POST",body:{labels:o}});return JSON.stringify({ok:!0,number:n,labels:(Array.isArray(m)?m:[]).map(u=>typeof u=="string"?u:u.name)})}default:return JSON.stringify({error:`Unknown tool: ${h}`})}}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 the repositories this token/installation can access (omit owner) \u2014 or a specific user/org's repos (pass owner). Use this to discover a RELATED repo worth cloning when a change's correctness depends on another accessible repo. Each repo carries a normalized { fullPath, name, webUrl, defaultBranch, visibility } shape (identical to gitlab_list_projects) alongside legacy fields, plus a truncated flag.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Org or user login. Omit to list every repo your token/installation can access."},query:{type:"string",description:"Optional term matched against repo name/full-name/description"},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: 200, hard-capped at the fetch ceiling)"}}}},{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_get_review_thread",description:"Read a PR review-comment THREAD given any comment id in it: the root review comment + all its replies, plus the anchored diff context (file, line, the original diff hunk). Use this to understand a human's reply to a previous review comment before replying in-thread.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},commentId:{type:"number",description:"Any review-comment id in the thread (the root or any reply)"}},required:["owner","repo","number","commentId"]}},{name:"github_reply_review_thread",description:"Reply IN-THREAD to an existing PR review-comment thread (a conversational reply nested under the thread the human commented on \u2014 NOT a fresh full review). Pass any comment id in the thread.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},commentId:{type:"number",description:"Any review-comment id in the thread to reply to"},body:{type:"string",description:"The reply text (markdown)"}},required:["owner","repo","number","commentId","body"]}},{name:"github_reply_issue_comment",description:"Post a reply on a PR's top-level conversation (a new issue comment on the PR). Use when the human replied to a non-inline/summary comment rather than an inline review thread. Quote or @-mention for context since issue comments are not threaded.",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 reply text (markdown)"}},required:["owner","repo","number","body"]}},{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 commits on a branch \u2014 optionally bounded by since/until ISO dates (date-window listing) and paginated (keep calling with page+1 while hasMore is true). 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:"Commits per page, max 100 (default: 20)"},since:{type:"string",description:'Only commits after this ISO-8601 date/time, e.g. "2026-01-01T00:00:00Z"'},until:{type:"string",description:"Only commits before this ISO-8601 date/time"},page:{type:"number",description:"Page number, 1-based (default 1)"}},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)"},includePrs:{type:"boolean",description:"Also return the pull request(s) containing this commit ({number,title,state,merged,webUrl}) \u2014 the evidence link for contribution records (default false)"}},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_pr",description:"Open a pull request on GitHub (POST /repos/{owner}/{repo}/pulls). The head (source) branch must already be pushed. Returns the REAL pr_url from GitHub \u2014 never fabricate a PR url. Expected business outcomes (no commits between base and head, a PR already exists for this branch, base==head, missing head) return { success:false, skippedReason } rather than erroring.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},head:{type:"string",description:'Source branch to merge FROM (must already be pushed). For a cross-fork PR use "fork-owner:branch".'},base:{type:"string",description:"Target branch to merge INTO (default: the repo's default branch)"},title:{type:"string",description:"PR title"},body:{type:"string",description:"PR description (markdown)"},draft:{type:"boolean",description:"Open as a draft PR (default: false)"}},required:["owner","repo","head","title"]}},{name:"github_merge_pr",description:"Merge a pull request on GitHub (PUT /repos/{owner}/{repo}/pulls/{number}/merge). mergeMethod is merge | squash | rebase (default squash). Returns { success:true, merged:true, sha } with the REAL merge SHA from GitHub. Expected non-mergeable outcomes (405 = draft / failing checks / branch protection, 409 = head sha moved / conflict, 404 = not found) return { success:false, skippedReason } rather than erroring.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number to merge"},mergeMethod:{type:"string",enum:["merge","squash","rebase"],description:"How to merge (default: squash)"},commitTitle:{type:"string",description:"Title for the merge/squash commit (optional)"},commitMessage:{type:"string",description:"Body for the merge/squash commit (optional)"}},required:["owner","repo","number"]}},{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"]}}]};export{l as ghFetch,_e as githubSkill};
|
package/dist/gitlab.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import{existsSync as K}from"fs";import{AsyncLocalStorage as W}from"async_hooks";import{fileURLToPath as z}from"url";import{dirname as Y,resolve as V}from"path";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",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",VIKUNJA:"vikunja",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),ne=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"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},vikunja:{id:"vikunja",name:"Vikunja",connectPath:"/integrations?provider=vikunja"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});import{spawn as ce,execSync as de}from"child_process";import{existsSync as pe,mkdirSync as ue,readdirSync as he,statSync as me,readFileSync as ge}from"fs";import{resolve as
|
|
1
|
+
import{existsSync as K}from"fs";import{AsyncLocalStorage as W}from"async_hooks";import{fileURLToPath as z}from"url";import{dirname as Y,resolve as V}from"path";var v=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",LARK_DOCS:"lark_docs",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",VIKUNJA:"vikunja",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),ne=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"},lark_docs:{id:"lark_docs",name:"Lark Docs",connectPath:"/integrations?provider=lark_docs"},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"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},vikunja:{id:"vikunja",name:"Vikunja",connectPath:"/integrations?provider=vikunja"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});import{spawn as ce,execSync as de}from"child_process";import{existsSync as pe,mkdirSync as ue,readdirSync as he,statSync as me,readFileSync as ge}from"fs";import{resolve as _e,join as ye,basename as be}from"path";function T(o,i,t,s,e="clone"){try{o(`git -C "${i}" remote set-url origin "${t}"`,{stdio:"pipe"})}catch(n){let r=String(n?.message||n);s&&(r=r.split(s).join("***")),console.error(`[${e}] WARNING: failed to strip token from .git/config: ${r}`)}}import J from"crypto";var k=/<!--\s*zbfp:([a-f0-9]{8,20})\s*-->/i,P=/<!--\s*zbreview-summary\s*-->/i;function D(o){return String(o||"").replace(k,"").replace(P,"").replace(/\b(?:lines?|L)\s*#?\d+(?:\s*[-–]\s*\d+)?/gi,"").replace(/[`*_>#~]/g,"").replace(/\s+/g," ").trim().toLowerCase().slice(0,400)}function H(o,i){return J.createHash("sha256").update(`${String(o||"")}\0${D(i)}`).digest("hex").slice(0,12)}function F(o){return`
|
|
2
2
|
|
|
3
3
|
<!-- zbfp:${o} -->`}var $=`
|
|
4
4
|
|
|
5
|
-
<!-- zbreview-summary -->`;function G(o){let i=
|
|
5
|
+
<!-- zbreview-summary -->`;function G(o){let i=k.exec(String(o||""));return i?i[1].toLowerCase():null}function E(o){return P.test(String(o||""))}function q(o,i){let t=new Set([...i||[]].map(n=>String(n).toLowerCase())),s=[],e=0;for(let n of Array.isArray(o)?o:[]){if(!n||!n.body)continue;let r=H(n.path,n.body);if(t.has(r)){e+=1;continue}t.add(r),s.push({...n,_fp:r,body:`${String(n.body)}${F(r)}`})}return{toPost:s,skipped:e}}function Z(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let o=Y(z(import.meta.url)),i=V(o,"..","bin","mcp-skill.mjs");return K(i)?i:null}function A(o){return String(o??"").trim().replace(/^\/+|\/+$/g,"").toLowerCase()}var L=null;function Q(o){let i;try{i=JSON.parse(o)}catch{throw new Error("GITLAB_INSTANCES is set but is not valid JSON. Expected an array of { host, token, repos: [...] }.")}if(!Array.isArray(i)||i.length===0)throw new Error("GITLAB_INSTANCES must be a non-empty JSON array of { host, token, repos: [...] }.");let t=[],s=new Map;return i.forEach((e,n)=>{let r=e&&typeof e.host=="string"?e.host.trim().replace(/\/+$/,""):"",d=e&&typeof e.token=="string"?e.token.trim():"",c=e&&Array.isArray(e.repos)?e.repos:null;if(!r)throw new Error(`GITLAB_INSTANCES[${n}] is missing "host".`);if(!d)throw new Error(`GITLAB_INSTANCES[${n}] (${r}) is missing "token".`);if(!c||c.length===0)throw new Error(`GITLAB_INSTANCES[${n}] (${r}) declares no "repos" \u2014 an entry that routes nothing is a config error, not an empty selection.`);let l=r.replace(/\/api\/v\d+$/,""),p=new Set;for(let g of c){let a=A(g);if(!a)continue;let f=s.get(a);if(f!==void 0&&f!==n)throw new Error(`GITLAB_INSTANCES claims "${a}" on more than one server (${t[f].webHost} and ${l}). A repo path must name exactly one server.`);s.set(a,n),p.add(a)}if(p.size===0)throw new Error(`GITLAB_INSTANCES[${n}] (${r}) declares no usable "repos".`);t.push({webHost:l,apiBase:/\/api\/v\d+$/.test(r)?r:`${l}/api/v4`,token:d,repos:p})}),t}function R(){let o=process.env.GITLAB_INSTANCES;if(typeof o!="string"||!o.trim())return null;if(L&&L.raw===o)return L.value;let i=Q(o);return L={raw:o,value:i},i}var N=new W,X="GitLab: this call was not routed to a connected server. With GITLAB_INSTANCES set, every call must name a project one of the declared servers owns.";function O(){let o=N.getStore();if(o)return o;if(R())throw new Error(X);return null}function ee(){let o=O();if(o)return o.apiBase;let i=process.env.GITLAB_API_URL;if(i)return i.replace(/\/+$/,"");let t=(process.env.GITLAB_URL||process.env.GITLAB_INSTANCE_URL||"https://gitlab.com").trim().replace(/\/+$/,"");return/\/api\/v\d+$/.test(t)?t:`${t}/api/v4`}function te(){let o=O();if(o)return{"PRIVATE-TOKEN":o.token};if(process.env.GITLAB_OAUTH_TOKEN)return{Authorization:`Bearer ${process.env.GITLAB_OAUTH_TOKEN}`};let i=process.env.GITLAB_TOKEN;if(!i)throw new Error("GitLab is not connected: set GITLAB_TOKEN (personal/project access token, api scope) or GITLAB_OAUTH_TOKEN.");return{"PRIVATE-TOKEN":i}}async function m(o,i={}){let t=/^https?:\/\//.test(o)?o:`${ee()}${o}`,s={Accept:"application/json","User-Agent":"Zibby-App",...te(),...i.body?{"Content-Type":"application/json"}:{}},e=await fetch(t,{method:i.method||"GET",headers:s,body:i.body?JSON.stringify(i.body):void 0});if(!e.ok){let n=await e.text().catch(()=>"");throw new Error(`GitLab API ${e.status}: ${n.slice(0,300)}`)}return i.raw?e.text():e.json()}function U(){let o=O();if(o)return o.webHost;let i=process.env.GITLAB_API_URL;return(process.env.GITLAB_URL||process.env.GITLAB_INSTANCE_URL||(i?i.replace(/\/api\/v\d+\/?$/,""):"")||"https://gitlab.com").trim().replace(/\/+$/,"").replace(/\/api\/v\d+$/,"")}function re(){let o=O();return o?o.token:process.env.GITLAB_OAUTH_TOKEN||process.env.GITLAB_TOKEN||null}function _(o){let i=String(o);return/^\d+$/.test(i)?i:encodeURIComponent(i)}function M(){let o=R();if(o){let s=new Set;for(let e of o)for(let n of e.repos)s.add(n);return s}let i=process.env.GITLAB_ALLOWED_REPOS;if(typeof i!="string"||!i.trim())return null;let t=new Set(i.split(",").map(A).filter(Boolean));return t.size?t:null}function B(o,i){if(!o)return!0;let t=A(i);return t!==""&&o.has(t)}function ie(o){if(!o||typeof o!="object")return null;for(let i of["projectPath","projectId","project","repo","repoPath"]){let t=o[i];if(t!=null&&String(t).trim()!=="")return String(t).trim()}return null}async function x(o){if(!/^\d+$/.test(o))return o;try{let i=await m(`/projects/${_(o)}`);return i&&i.path_with_namespace||null}catch{return null}}async function se(o,i){if(!i)return{path:await x(o),instance:null};if(!/^\d+$/.test(o)){let s=A(o);return{path:o,instance:i.find(e=>e.repos.has(s))||null}}let t=null;for(let s of i){let e=await N.run(s,()=>x(o));if(e&&(t===null&&(t=e),s.repos.has(A(e))))return{path:e,instance:s}}return{path:t,instance:null}}async function C(o,i){switch(o){case"gitlab_clone":{let{projectPath:t,projectId:s,destination:e,branch:n}=i||{},r=t&&String(t).trim();if(!r&&s!=null&&(/^\d+$/.test(String(s))?r=(await m(`/projects/${_(s)}`))?.path_with_namespace:r=String(s).trim()),!r)return JSON.stringify({error:'projectPath (e.g. "group/repo") or a numeric projectId is required'});let d=re();if(!d)return JSON.stringify({error:"GitLab is not connected (no token to authenticate the clone)."});let{execSync:c}=await import("child_process"),{join:l,resolve:p}=await import("path"),{existsSync:g,mkdirSync:a}=await import("fs"),f=e?p(e):p(process.cwd(),".zibby","repos"),y=r.split("/").filter(Boolean).pop(),u=l(f,y);if(a(f,{recursive:!0}),g(u))return JSON.stringify({success:!0,path:u,message:`Already cloned at ${u}`,alreadyCloned:!0});let w=U().replace(/^https?:\/\//,""),h=U().startsWith("http://")?"http":"https",b=`${h}://oauth2:${d}@${w}/${r}.git`,S=n?`--branch "${String(n).replace(/"/g,"")}" `:"";try{c(`git clone --depth 1 ${S}${b} "${u}"`,{stdio:"pipe",env:{...process.env,GIT_TERMINAL_PROMPT:"0"}});let j=`${h}://${w}/${r}.git`;T(c,u,j,d,"gitlab_clone");let I=c(`ls -la "${u}"`,{encoding:"utf-8"});return JSON.stringify({success:!0,path:u,message:`Cloned ${r} to ${u}`,contents:I.split(`
|
|
6
6
|
`).slice(0,30).join(`
|
|
7
|
-
`)})}catch(j){let I=String(j.message||j).split(d).join("***").replace(/oauth2:[^@]*@/g,"oauth2:***@");return JSON.stringify({error:`Clone failed: ${I}`})}}case"gitlab_create_mr":{let t=i?.project??i?.projectId,s=i?.source_branch??i?.sourceBranch,{title:e}=i||{};if(!t||!s||!e)return JSON.stringify({error:'project (id or "group/repo" path), source_branch, and title are required'});let n=y(t),r=i?.target_branch??i?.targetBranch;if(!r)try{r=(await m(`/projects/${n}`)).default_branch||"main"}catch{r="main"}let d={source_branch:String(s),target_branch:String(r),title:String(e),description:i?.description?String(i.description):""};try{let c=await m(`/projects/${n}/merge_requests`,{method:"POST",body:d});return JSON.stringify({success:!0,pr_url:c.web_url,number:c.iid,branch:d.source_branch,targetBranch:d.target_branch,project:String(t),provider:"gitlab",state:c.state})}catch(c){let l=String(c.message||c);if(/GitLab API (409|400)/.test(l))return JSON.stringify({success:!1,branch:d.source_branch,targetBranch:d.target_branch,project:String(t),provider:"gitlab",skippedReason:l});throw c}}case"gitlab_accept_mr":{let t=i?.project??i?.projectId,{iid:s}=i||{};if(!t||!s)return JSON.stringify({error:'project (id or "group/repo" path) and iid are required'});let e=y(t),n={};i.squash!=null&&(n.squash=!!i.squash),i.mergeCommitMessage&&(n.merge_commit_message=String(i.mergeCommitMessage)),i.mergeWhenPipelineSucceeds!=null&&(n.merge_when_pipeline_succeeds=!!i.mergeWhenPipelineSucceeds);try{let r=await m(`/projects/${e}/merge_requests/${s}/merge`,{method:"PUT",body:n});return JSON.stringify({success:!0,merged:!0,sha:r.merge_commit_sha??r.sha??null,iid:r.iid??s,project:String(t),provider:"gitlab",state:r.state})}catch(r){let d=String(r.message||r);if(/GitLab API (405|406|404)/.test(d))return JSON.stringify({success:!1,iid:s,project:String(t),provider:"gitlab",skippedReason:d});throw r}}case"gitlab_get_mr":{let{projectId:t,iid:s}=i||{};if(!t||!s)return JSON.stringify({error:"projectId and iid are required"});let e=await m(`/projects/${y(t)}/merge_requests/${s}`);return JSON.stringify({iid:e.iid,projectId:e.project_id,title:e.title,description:(e.description||"").slice(0,5e3),state:e.state,author:e.author?.username,sourceBranch:e.source_branch,targetBranch:e.target_branch,draft:e.draft??e.work_in_progress??!1,mergeStatus:e.merge_status,changesCount:e.changes_count,labels:Array.isArray(e.labels)?e.labels:[],webUrl:e.web_url,createdAt:e.created_at,updatedAt:e.updated_at,mergedAt:e.merged_at,diffRefs:e.diff_refs||null})}case"gitlab_get_mr_changes":{let{projectId:t,iid:s}=i||{};if(!t||!s)return JSON.stringify({error:"projectId and iid are required"});let e=await m(`/projects/${y(t)}/merge_requests/${s}/changes`),n=Array.isArray(e.changes)?e.changes:[];return JSON.stringify({iid:e.iid,total:n.length,diffRefs:e.diff_refs||null,files:n.map(r=>({oldPath:r.old_path,newPath:r.new_path,newFile:!!r.new_file,deletedFile:!!r.deleted_file,renamedFile:!!r.renamed_file,diff:typeof r.diff=="string"?r.diff.slice(0,3e3):""}))})}case"gitlab_list_commits":{let{projectId:t,since:s,until:e,refName:n,page:r,perPage:d,withStats:c}=i||{};if(!t)return JSON.stringify({error:"projectId is required"});let l=new URLSearchParams;l.set("per_page",String(Math.min(Number(d)||50,100))),l.set("page",String(Number(r)||1)),s&&l.set("since",s),e&&l.set("until",e),n&&l.set("ref_name",n),c!==!1&&l.set("with_stats","true");let p=await m(`/projects/${y(t)}/repository/commits?${l.toString()}`),g=(Array.isArray(p)?p:[]).map(a=>({id:a.id,shortId:a.short_id,title:a.title,authorName:a.author_name,authorEmail:a.author_email,authoredDate:a.authored_date,committedDate:a.committed_date,parentIds:Array.isArray(a.parent_ids)?a.parent_ids:[],stats:a.stats||null}));return JSON.stringify({page:Number(r)||1,count:g.length,hasMore:g.length>=Math.min(Number(d)||50,100),commits:g})}case"gitlab_get_commit":{let{projectId:t,sha:s,includeDiff:e,includeMrs:n}=i||{};if(!t||!s)return JSON.stringify({error:"projectId and sha are required"});let r=await m(`/projects/${y(t)}/repository/commits/${encodeURIComponent(s)}`),d;if(n)try{let l=await m(`/projects/${y(t)}/repository/commits/${encodeURIComponent(s)}/merge_requests`);d=(Array.isArray(l)?l:[]).map(p=>({iid:p.iid,title:p.title,state:p.state,webUrl:p.web_url}))}catch{d=[]}let c;if(e!==!1){let l=await m(`/projects/${y(t)}/repository/commits/${encodeURIComponent(s)}/diff`);c=(Array.isArray(l)?l:[]).map(p=>({oldPath:p.old_path,newPath:p.new_path,newFile:!!p.new_file,deletedFile:!!p.deleted_file,renamedFile:!!p.renamed_file,diff:typeof p.diff=="string"?p.diff.slice(0,3e3):""}))}return JSON.stringify({id:r.id,shortId:r.short_id,title:r.title,message:typeof r.message=="string"?r.message.slice(0,2e3):"",authorName:r.author_name,authorEmail:r.author_email,authoredDate:r.authored_date,committedDate:r.committed_date,parentIds:Array.isArray(r.parent_ids)?r.parent_ids:[],stats:r.stats||null,webUrl:r.web_url,...c?{filesChanged:c.length,files:c}:{},...d?{mergeRequests:d}:{}})}case"gitlab_list_mrs":{let{projectId:t,state:s,targetBranch:e,sourceBranch:n,authorUsername:r,labels:d,search:c,sort:l,orderBy:p,limit:g}=i||{};if(!t)return JSON.stringify({error:"projectId is required"});let a=new URLSearchParams;a.set("state",s||"opened"),a.set("per_page",String(g||20)),a.set("order_by",p||"updated_at"),a.set("sort",l||"desc"),e&&a.set("target_branch",e),n&&a.set("source_branch",n),r&&a.set("author_username",r),d&&a.set("labels",Array.isArray(d)?d.join(","):d),c&&a.set("search",c);let f=await m(`/projects/${y(t)}/merge_requests?${a.toString()}`),_=(Array.isArray(f)?f:[]).map(u=>({iid:u.iid,title:u.title,state:u.state,author:u.author?.username,sourceBranch:u.source_branch,targetBranch:u.target_branch,draft:u.draft??u.work_in_progress??!1,labels:Array.isArray(u.labels)?u.labels:[],webUrl:u.web_url,createdAt:u.created_at,updatedAt:u.updated_at}));return JSON.stringify({count:_.length,mergeRequests:_})}case"gitlab_list_mr_notes":{let{projectId:t,iid:s,limit:e}=i||{};if(!t||!s)return JSON.stringify({error:"projectId and iid are required"});let n=await m(`/projects/${y(t)}/merge_requests/${s}/notes?per_page=${e||50}&sort=asc&order_by=created_at`);return JSON.stringify({total:Array.isArray(n)?n.length:0,notes:(Array.isArray(n)?n:[]).map(r=>({id:r.id,author:r.author?.username,body:(r.body||"").slice(0,1e3),system:!!r.system,createdAt:r.created_at}))})}case"gitlab_post_mr_note":{let{projectId:t,iid:s,body:e}=i||{};if(!t||!s||!e)return JSON.stringify({error:"projectId, iid, and body are required"});let n=await m(`/projects/${y(t)}/merge_requests/${s}/notes`,{method:"POST",body:{body:String(e)}});return JSON.stringify({ok:!0,id:n.id,createdAt:n.created_at})}case"gitlab_post_mr_discussion":{let{projectId:t,iid:s,path:e,oldPath:n,newLine:r,oldLine:d,body:c}=i||{};if(!t||!s||!e||!c)return JSON.stringify({error:"projectId, iid, path, and body are required"});if(r==null&&d==null)return JSON.stringify({error:"newLine (added/changed line) or oldLine (removed/context line) is required to anchor an inline comment"});let l=y(t),p=i.diffRefs||null;if(p||(p=(await m(`/projects/${l}/merge_requests/${s}`)).diff_refs||null),!p||!p.head_sha)return JSON.stringify({error:"could not resolve diff_refs for this MR \u2014 cannot anchor an inline comment. Use gitlab_post_mr_note instead."});let g={base_sha:p.base_sha,start_sha:p.start_sha,head_sha:p.head_sha,position_type:"text",new_path:e,old_path:n||e};r!=null&&(g.new_line=Number(r)),d!=null&&(g.old_line=Number(d));try{let a=await m(`/projects/${l}/merge_requests/${s}/discussions`,{method:"POST",body:{body:String(c),position:g}});return JSON.stringify({ok:!0,discussionId:a.id})}catch(a){return JSON.stringify({ok:!1,error:`inline anchor rejected (${a.message}). The line must be part of the MR diff. Fall back to gitlab_post_mr_note with the file/line in the text.`})}}case"gitlab_create_mr_review":{let{projectId:t,iid:s,body:e,comments:n}=i||{};if(!t||!s)return JSON.stringify({error:"projectId and iid are required"});let r=y(t),d=Array.isArray(n)?n.filter(h=>h&&h.path&&h.body&&(h.newLine!=null||h.oldLine!=null)):[];if(!e&&d.length===0)return JSON.stringify({error:"a review needs a body and/or inline comments"});let c=i.diffRefs||null;d.length>0&&!c&&(c=(await m(`/projects/${r}/merge_requests/${s}`)).diff_refs||null);let l=new Set,p=null;try{for(let h=1;h<=20;h+=1){let b=await m(`/projects/${r}/merge_requests/${s}/discussions?per_page=100&page=${h}`);if(!Array.isArray(b)||b.length===0)break;for(let S of b)for(let j of S.notes||[]){let I=G(j.body);I&&l.add(I),p==null&&E(j.body)&&(p=j.id)}if(b.length<100)break}}catch{}let g=!1,a=!1;if(e){let h=`${String(e)}${$}`;try{p!=null?(await m(`/projects/${r}/merge_requests/${s}/notes/${p}`,{method:"PUT",body:{body:h}}),a=!0):await m(`/projects/${r}/merge_requests/${s}/notes`,{method:"POST",body:{body:h}}),g=!0}catch{await m(`/projects/${r}/merge_requests/${s}/notes`,{method:"POST",body:{body:h}}),g=!0}}let{toPost:f,skipped:_}=q(d,l),u=0,w=[];if(f.length>0&&c)for(let h of f){let b={base_sha:c.base_sha,start_sha:c.start_sha,head_sha:c.head_sha,position_type:"text",new_path:h.path,old_path:h.oldPath||h.path};h.newLine!=null&&(b.new_line=Number(h.newLine)),h.oldLine!=null&&(b.old_line=Number(h.oldLine));try{await m(`/projects/${r}/merge_requests/${s}/discussions`,{method:"POST",body:{body:String(h.body),position:b}}),u+=1}catch(S){w.push(`${h.path}:${h.newLine??h.oldLine} \u2014 ${S.message}`)}}else f.length>0&&!c&&w.push("no diff_refs available \u2014 inline comments skipped (pass diffRefs from gitlab_get_mr)");return JSON.stringify({ok:!0,notePosted:g,summaryUpdated:a,inlinePosted:u,inlineSkipped:_||void 0,inlineErrors:w.length?w:void 0})}case"gitlab_get_discussion":{let{projectId:t,iid:s,discussionId:e}=i||{};if(!t||!s||!e)return JSON.stringify({error:"projectId, iid, and discussionId are required"});let n=await m(`/projects/${y(t)}/merge_requests/${s}/discussions/${encodeURIComponent(e)}`),r=Array.isArray(n.notes)?n.notes:[],d=r.find(l=>l.position)||null,c=d?d.position:null;return JSON.stringify({discussionId:n.id,individualNote:!!n.individual_note,path:c&&(c.new_path||c.old_path)||null,newLine:c?c.new_line??null:null,oldLine:c?c.old_line??null:null,diffRefs:c?{base_sha:c.base_sha,start_sha:c.start_sha,head_sha:c.head_sha}:null,notes:r.map(l=>({id:l.id,author:l.author?.username,body:(l.body||"").slice(0,4e3),system:!!l.system,createdAt:l.created_at}))})}case"gitlab_reply_discussion":{let{projectId:t,iid:s,discussionId:e,body:n}=i||{};if(!t||!s||!e||!n)return JSON.stringify({error:"projectId, iid, discussionId, and body are required"});let r=await m(`/projects/${y(t)}/merge_requests/${s}/discussions/${encodeURIComponent(e)}/notes`,{method:"POST",body:{body:String(n)}});return JSON.stringify({ok:!0,id:r.id,createdAt:r.created_at})}case"gitlab_list_projects":{let{query:t,limit:s}=i||{},e=Math.min(Number(s)>0?Number(s):50,200),n=new URLSearchParams;n.set("membership","true"),n.set("simple","true"),n.set("order_by","last_activity_at"),n.set("sort","desc"),n.set("per_page",String(Math.min(e+1,100))),t&&n.set("search",String(t));let r=async()=>{let a=await m(`/projects?${n.toString()}`);return Array.isArray(a)?a:[]},d=R(),c=M(),l=[];for(let a of d||[null]){let f=a?await N.run(a,r):await r();for(let _ of f)B(a?a.repos:c,_&&_.path_with_namespace)&&l.push({p:_,host:a?a.webHost:null})}let p=l.length>e,g=l.slice(0,e).map(({p:a,host:f})=>({fullPath:a.path_with_namespace,name:a.name,webUrl:a.web_url,defaultBranch:a.default_branch||null,visibility:a.visibility||null,...f?{host:f}:{}}));return JSON.stringify({count:g.length,truncated:p,projects:g})}case"gitlab_list_issues":{let{projectId:t,state:s,labels:e,assigneeUsername:n,authorUsername:r,updatedAfter:d,search:c,sort:l,orderBy:p,limit:g}=i||{};if(!t)return JSON.stringify({error:"projectId is required"});let a=new URLSearchParams;a.set("state",s||"opened"),a.set("per_page",String(g||30)),a.set("order_by",p||"updated_at"),a.set("sort",l||"desc"),e&&a.set("labels",Array.isArray(e)?e.join(","):e),n&&a.set("assignee_username",n),r&&a.set("author_username",r),d&&a.set("updated_after",d),c&&a.set("search",c);let f=await m(`/projects/${y(t)}/issues?${a.toString()}`),_=(Array.isArray(f)?f:[]).map(u=>({iid:u.iid,title:u.title,state:u.state,labels:Array.isArray(u.labels)?u.labels:[],author:u.author?.username,assignees:(u.assignees||[]).map(w=>w.username),userNotesCount:u.user_notes_count,webUrl:u.web_url,createdAt:u.created_at,updatedAt:u.updated_at}));return JSON.stringify({count:_.length,issues:_})}case"gitlab_get_issue":{let{projectId:t,iid:s}=i||{};if(!t||!s)return JSON.stringify({error:"projectId and iid are required"});let e=await m(`/projects/${y(t)}/issues/${s}`);return JSON.stringify({iid:e.iid,projectId:e.project_id,title:e.title,description:(e.description||"").slice(0,5e3),state:e.state,labels:Array.isArray(e.labels)?e.labels:[],author:e.author?.username,assignees:(e.assignees||[]).map(n=>n.username),milestone:e.milestone?.title||null,webUrl:e.web_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"gitlab_add_issue_comment":{let{projectId:t,iid:s,body:e}=i||{};if(!t||!s||!e)return JSON.stringify({error:"projectId, iid, and body are required"});let n=await m(`/projects/${y(t)}/issues/${s}/notes`,{method:"POST",body:{body:String(e)}});return JSON.stringify({ok:!0,id:n.id,createdAt:n.created_at})}default:return JSON.stringify({error:`Unknown tool: ${o}`})}}var Te={id:"gitlab",callsBackend:!0,serverName:"gitlab",allowedTools:["mcp__gitlab__*"],requiresIntegration:v.GITLAB,envKeys:["GITLAB_TOKEN","GITLAB_OAUTH_TOKEN","GITLAB_URL","GITLAB_INSTANCE_URL","GITLAB_API_URL","GITLAB_ALLOWED_REPOS","GITLAB_INSTANCES","PROJECT_API_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV"],description:"GitLab \u2014 merge requests, diffs, MR reviews/discussions, issues",promptFragment:`## GitLab
|
|
7
|
+
`)})}catch(j){let I=String(j.message||j).split(d).join("***").replace(/oauth2:[^@]*@/g,"oauth2:***@");return JSON.stringify({error:`Clone failed: ${I}`})}}case"gitlab_create_mr":{let t=i?.project??i?.projectId,s=i?.source_branch??i?.sourceBranch,{title:e}=i||{};if(!t||!s||!e)return JSON.stringify({error:'project (id or "group/repo" path), source_branch, and title are required'});let n=_(t),r=i?.target_branch??i?.targetBranch;if(!r)try{r=(await m(`/projects/${n}`)).default_branch||"main"}catch{r="main"}let d={source_branch:String(s),target_branch:String(r),title:String(e),description:i?.description?String(i.description):""};try{let c=await m(`/projects/${n}/merge_requests`,{method:"POST",body:d});return JSON.stringify({success:!0,pr_url:c.web_url,number:c.iid,branch:d.source_branch,targetBranch:d.target_branch,project:String(t),provider:"gitlab",state:c.state})}catch(c){let l=String(c.message||c);if(/GitLab API (409|400)/.test(l))return JSON.stringify({success:!1,branch:d.source_branch,targetBranch:d.target_branch,project:String(t),provider:"gitlab",skippedReason:l});throw c}}case"gitlab_accept_mr":{let t=i?.project??i?.projectId,{iid:s}=i||{};if(!t||!s)return JSON.stringify({error:'project (id or "group/repo" path) and iid are required'});let e=_(t),n={};i.squash!=null&&(n.squash=!!i.squash),i.mergeCommitMessage&&(n.merge_commit_message=String(i.mergeCommitMessage)),i.mergeWhenPipelineSucceeds!=null&&(n.merge_when_pipeline_succeeds=!!i.mergeWhenPipelineSucceeds);try{let r=await m(`/projects/${e}/merge_requests/${s}/merge`,{method:"PUT",body:n});return JSON.stringify({success:!0,merged:!0,sha:r.merge_commit_sha??r.sha??null,iid:r.iid??s,project:String(t),provider:"gitlab",state:r.state})}catch(r){let d=String(r.message||r);if(/GitLab API (405|406|404)/.test(d))return JSON.stringify({success:!1,iid:s,project:String(t),provider:"gitlab",skippedReason:d});throw r}}case"gitlab_get_mr":{let{projectId:t,iid:s}=i||{};if(!t||!s)return JSON.stringify({error:"projectId and iid are required"});let e=await m(`/projects/${_(t)}/merge_requests/${s}`);return JSON.stringify({iid:e.iid,projectId:e.project_id,title:e.title,description:(e.description||"").slice(0,5e3),state:e.state,author:e.author?.username,sourceBranch:e.source_branch,targetBranch:e.target_branch,draft:e.draft??e.work_in_progress??!1,mergeStatus:e.merge_status,changesCount:e.changes_count,labels:Array.isArray(e.labels)?e.labels:[],webUrl:e.web_url,createdAt:e.created_at,updatedAt:e.updated_at,mergedAt:e.merged_at,diffRefs:e.diff_refs||null})}case"gitlab_get_mr_changes":{let{projectId:t,iid:s}=i||{};if(!t||!s)return JSON.stringify({error:"projectId and iid are required"});let e=await m(`/projects/${_(t)}/merge_requests/${s}/changes`),n=Array.isArray(e.changes)?e.changes:[];return JSON.stringify({iid:e.iid,total:n.length,diffRefs:e.diff_refs||null,files:n.map(r=>({oldPath:r.old_path,newPath:r.new_path,newFile:!!r.new_file,deletedFile:!!r.deleted_file,renamedFile:!!r.renamed_file,diff:typeof r.diff=="string"?r.diff.slice(0,3e3):""}))})}case"gitlab_list_commits":{let{projectId:t,since:s,until:e,refName:n,page:r,perPage:d,withStats:c}=i||{};if(!t)return JSON.stringify({error:"projectId is required"});let l=new URLSearchParams;l.set("per_page",String(Math.min(Number(d)||50,100))),l.set("page",String(Number(r)||1)),s&&l.set("since",s),e&&l.set("until",e),n&&l.set("ref_name",n),c!==!1&&l.set("with_stats","true");let p=await m(`/projects/${_(t)}/repository/commits?${l.toString()}`),g=(Array.isArray(p)?p:[]).map(a=>({id:a.id,shortId:a.short_id,title:a.title,authorName:a.author_name,authorEmail:a.author_email,authoredDate:a.authored_date,committedDate:a.committed_date,parentIds:Array.isArray(a.parent_ids)?a.parent_ids:[],stats:a.stats||null}));return JSON.stringify({page:Number(r)||1,count:g.length,hasMore:g.length>=Math.min(Number(d)||50,100),commits:g})}case"gitlab_get_commit":{let{projectId:t,sha:s,includeDiff:e,includeMrs:n}=i||{};if(!t||!s)return JSON.stringify({error:"projectId and sha are required"});let r=await m(`/projects/${_(t)}/repository/commits/${encodeURIComponent(s)}`),d;if(n)try{let l=await m(`/projects/${_(t)}/repository/commits/${encodeURIComponent(s)}/merge_requests`);d=(Array.isArray(l)?l:[]).map(p=>({iid:p.iid,title:p.title,state:p.state,webUrl:p.web_url}))}catch{d=[]}let c;if(e!==!1){let l=await m(`/projects/${_(t)}/repository/commits/${encodeURIComponent(s)}/diff`);c=(Array.isArray(l)?l:[]).map(p=>({oldPath:p.old_path,newPath:p.new_path,newFile:!!p.new_file,deletedFile:!!p.deleted_file,renamedFile:!!p.renamed_file,diff:typeof p.diff=="string"?p.diff.slice(0,3e3):""}))}return JSON.stringify({id:r.id,shortId:r.short_id,title:r.title,message:typeof r.message=="string"?r.message.slice(0,2e3):"",authorName:r.author_name,authorEmail:r.author_email,authoredDate:r.authored_date,committedDate:r.committed_date,parentIds:Array.isArray(r.parent_ids)?r.parent_ids:[],stats:r.stats||null,webUrl:r.web_url,...c?{filesChanged:c.length,files:c}:{},...d?{mergeRequests:d}:{}})}case"gitlab_list_mrs":{let{projectId:t,state:s,targetBranch:e,sourceBranch:n,authorUsername:r,labels:d,search:c,sort:l,orderBy:p,limit:g}=i||{};if(!t)return JSON.stringify({error:"projectId is required"});let a=new URLSearchParams;a.set("state",s||"opened"),a.set("per_page",String(g||20)),a.set("order_by",p||"updated_at"),a.set("sort",l||"desc"),e&&a.set("target_branch",e),n&&a.set("source_branch",n),r&&a.set("author_username",r),d&&a.set("labels",Array.isArray(d)?d.join(","):d),c&&a.set("search",c);let f=await m(`/projects/${_(t)}/merge_requests?${a.toString()}`),y=(Array.isArray(f)?f:[]).map(u=>({iid:u.iid,title:u.title,state:u.state,author:u.author?.username,sourceBranch:u.source_branch,targetBranch:u.target_branch,draft:u.draft??u.work_in_progress??!1,labels:Array.isArray(u.labels)?u.labels:[],webUrl:u.web_url,createdAt:u.created_at,updatedAt:u.updated_at}));return JSON.stringify({count:y.length,mergeRequests:y})}case"gitlab_list_mr_notes":{let{projectId:t,iid:s,limit:e}=i||{};if(!t||!s)return JSON.stringify({error:"projectId and iid are required"});let n=await m(`/projects/${_(t)}/merge_requests/${s}/notes?per_page=${e||50}&sort=asc&order_by=created_at`);return JSON.stringify({total:Array.isArray(n)?n.length:0,notes:(Array.isArray(n)?n:[]).map(r=>({id:r.id,author:r.author?.username,body:(r.body||"").slice(0,1e3),system:!!r.system,createdAt:r.created_at}))})}case"gitlab_post_mr_note":{let{projectId:t,iid:s,body:e}=i||{};if(!t||!s||!e)return JSON.stringify({error:"projectId, iid, and body are required"});let n=await m(`/projects/${_(t)}/merge_requests/${s}/notes`,{method:"POST",body:{body:String(e)}});return JSON.stringify({ok:!0,id:n.id,createdAt:n.created_at})}case"gitlab_post_mr_discussion":{let{projectId:t,iid:s,path:e,oldPath:n,newLine:r,oldLine:d,body:c}=i||{};if(!t||!s||!e||!c)return JSON.stringify({error:"projectId, iid, path, and body are required"});if(r==null&&d==null)return JSON.stringify({error:"newLine (added/changed line) or oldLine (removed/context line) is required to anchor an inline comment"});let l=_(t),p=i.diffRefs||null;if(p||(p=(await m(`/projects/${l}/merge_requests/${s}`)).diff_refs||null),!p||!p.head_sha)return JSON.stringify({error:"could not resolve diff_refs for this MR \u2014 cannot anchor an inline comment. Use gitlab_post_mr_note instead."});let g={base_sha:p.base_sha,start_sha:p.start_sha,head_sha:p.head_sha,position_type:"text",new_path:e,old_path:n||e};r!=null&&(g.new_line=Number(r)),d!=null&&(g.old_line=Number(d));try{let a=await m(`/projects/${l}/merge_requests/${s}/discussions`,{method:"POST",body:{body:String(c),position:g}});return JSON.stringify({ok:!0,discussionId:a.id})}catch(a){return JSON.stringify({ok:!1,error:`inline anchor rejected (${a.message}). The line must be part of the MR diff. Fall back to gitlab_post_mr_note with the file/line in the text.`})}}case"gitlab_create_mr_review":{let{projectId:t,iid:s,body:e,comments:n}=i||{};if(!t||!s)return JSON.stringify({error:"projectId and iid are required"});let r=_(t),d=Array.isArray(n)?n.filter(h=>h&&h.path&&h.body&&(h.newLine!=null||h.oldLine!=null)):[];if(!e&&d.length===0)return JSON.stringify({error:"a review needs a body and/or inline comments"});let c=i.diffRefs||null;d.length>0&&!c&&(c=(await m(`/projects/${r}/merge_requests/${s}`)).diff_refs||null);let l=new Set,p=null;try{for(let h=1;h<=20;h+=1){let b=await m(`/projects/${r}/merge_requests/${s}/discussions?per_page=100&page=${h}`);if(!Array.isArray(b)||b.length===0)break;for(let S of b)for(let j of S.notes||[]){let I=G(j.body);I&&l.add(I),p==null&&E(j.body)&&(p=j.id)}if(b.length<100)break}}catch{}let g=!1,a=!1;if(e){let h=`${String(e)}${$}`;try{p!=null?(await m(`/projects/${r}/merge_requests/${s}/notes/${p}`,{method:"PUT",body:{body:h}}),a=!0):await m(`/projects/${r}/merge_requests/${s}/notes`,{method:"POST",body:{body:h}}),g=!0}catch{await m(`/projects/${r}/merge_requests/${s}/notes`,{method:"POST",body:{body:h}}),g=!0}}let{toPost:f,skipped:y}=q(d,l),u=0,w=[];if(f.length>0&&c)for(let h of f){let b={base_sha:c.base_sha,start_sha:c.start_sha,head_sha:c.head_sha,position_type:"text",new_path:h.path,old_path:h.oldPath||h.path};h.newLine!=null&&(b.new_line=Number(h.newLine)),h.oldLine!=null&&(b.old_line=Number(h.oldLine));try{await m(`/projects/${r}/merge_requests/${s}/discussions`,{method:"POST",body:{body:String(h.body),position:b}}),u+=1}catch(S){w.push(`${h.path}:${h.newLine??h.oldLine} \u2014 ${S.message}`)}}else f.length>0&&!c&&w.push("no diff_refs available \u2014 inline comments skipped (pass diffRefs from gitlab_get_mr)");return JSON.stringify({ok:!0,notePosted:g,summaryUpdated:a,inlinePosted:u,inlineSkipped:y||void 0,inlineErrors:w.length?w:void 0})}case"gitlab_get_discussion":{let{projectId:t,iid:s,discussionId:e}=i||{};if(!t||!s||!e)return JSON.stringify({error:"projectId, iid, and discussionId are required"});let n=await m(`/projects/${_(t)}/merge_requests/${s}/discussions/${encodeURIComponent(e)}`),r=Array.isArray(n.notes)?n.notes:[],d=r.find(l=>l.position)||null,c=d?d.position:null;return JSON.stringify({discussionId:n.id,individualNote:!!n.individual_note,path:c&&(c.new_path||c.old_path)||null,newLine:c?c.new_line??null:null,oldLine:c?c.old_line??null:null,diffRefs:c?{base_sha:c.base_sha,start_sha:c.start_sha,head_sha:c.head_sha}:null,notes:r.map(l=>({id:l.id,author:l.author?.username,body:(l.body||"").slice(0,4e3),system:!!l.system,createdAt:l.created_at}))})}case"gitlab_reply_discussion":{let{projectId:t,iid:s,discussionId:e,body:n}=i||{};if(!t||!s||!e||!n)return JSON.stringify({error:"projectId, iid, discussionId, and body are required"});let r=await m(`/projects/${_(t)}/merge_requests/${s}/discussions/${encodeURIComponent(e)}/notes`,{method:"POST",body:{body:String(n)}});return JSON.stringify({ok:!0,id:r.id,createdAt:r.created_at})}case"gitlab_list_projects":{let{query:t,limit:s}=i||{},e=Math.min(Number(s)>0?Number(s):50,200),n=new URLSearchParams;n.set("membership","true"),n.set("simple","true"),n.set("order_by","last_activity_at"),n.set("sort","desc"),n.set("per_page",String(Math.min(e+1,100))),t&&n.set("search",String(t));let r=async()=>{let a=await m(`/projects?${n.toString()}`);return Array.isArray(a)?a:[]},d=R(),c=M(),l=[];for(let a of d||[null]){let f=a?await N.run(a,r):await r();for(let y of f)B(a?a.repos:c,y&&y.path_with_namespace)&&l.push({p:y,host:a?a.webHost:null})}let p=l.length>e,g=l.slice(0,e).map(({p:a,host:f})=>({fullPath:a.path_with_namespace,name:a.name,webUrl:a.web_url,defaultBranch:a.default_branch||null,visibility:a.visibility||null,...f?{host:f}:{}}));return JSON.stringify({count:g.length,truncated:p,projects:g})}case"gitlab_list_issues":{let{projectId:t,state:s,labels:e,assigneeUsername:n,authorUsername:r,updatedAfter:d,search:c,sort:l,orderBy:p,limit:g}=i||{};if(!t)return JSON.stringify({error:"projectId is required"});let a=new URLSearchParams;a.set("state",s||"opened"),a.set("per_page",String(g||30)),a.set("order_by",p||"updated_at"),a.set("sort",l||"desc"),e&&a.set("labels",Array.isArray(e)?e.join(","):e),n&&a.set("assignee_username",n),r&&a.set("author_username",r),d&&a.set("updated_after",d),c&&a.set("search",c);let f=await m(`/projects/${_(t)}/issues?${a.toString()}`),y=(Array.isArray(f)?f:[]).map(u=>({iid:u.iid,title:u.title,state:u.state,labels:Array.isArray(u.labels)?u.labels:[],author:u.author?.username,assignees:(u.assignees||[]).map(w=>w.username),userNotesCount:u.user_notes_count,webUrl:u.web_url,createdAt:u.created_at,updatedAt:u.updated_at}));return JSON.stringify({count:y.length,issues:y})}case"gitlab_get_issue":{let{projectId:t,iid:s}=i||{};if(!t||!s)return JSON.stringify({error:"projectId and iid are required"});let e=await m(`/projects/${_(t)}/issues/${s}`);return JSON.stringify({iid:e.iid,projectId:e.project_id,title:e.title,description:(e.description||"").slice(0,5e3),state:e.state,labels:Array.isArray(e.labels)?e.labels:[],author:e.author?.username,assignees:(e.assignees||[]).map(n=>n.username),milestone:e.milestone?.title||null,webUrl:e.web_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"gitlab_add_issue_comment":{let{projectId:t,iid:s,body:e}=i||{};if(!t||!s||!e)return JSON.stringify({error:"projectId, iid, and body are required"});let n=await m(`/projects/${_(t)}/issues/${s}/notes`,{method:"POST",body:{body:String(e)}});return JSON.stringify({ok:!0,id:n.id,createdAt:n.created_at})}default:return JSON.stringify({error:`Unknown tool: ${o}`})}}var Te={id:"gitlab",callsBackend:!0,serverName:"gitlab",allowedTools:["mcp__gitlab__*"],requiresIntegration:v.GITLAB,envKeys:["GITLAB_TOKEN","GITLAB_OAUTH_TOKEN","GITLAB_URL","GITLAB_INSTANCE_URL","GITLAB_API_URL","GITLAB_ALLOWED_REPOS","GITLAB_INSTANCES","PROJECT_API_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV"],description:"GitLab \u2014 merge requests, diffs, MR reviews/discussions, issues",promptFragment:`## GitLab
|
|
8
8
|
You have access to the user's GitLab projects via the REST API (cloud gitlab.com OR self-hosted). A "merge request" (MR) is GitLab's pull request. An MR is addressed by a PROJECT (numeric id OR full path like "group/repo") and an \`iid\` (the per-project MR number shown in the URL). For projects, prefer the full path form ("group/subgroup/repo") \u2014 it's what users have. Available tools:
|
|
9
9
|
|
|
10
10
|
### Discovery
|
package/dist/googleDocs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{existsSync as
|
|
1
|
+
import{existsSync as v,statSync as P,readFileSync as R}from"fs";import{fileURLToPath as D}from"url";import{basename as L,dirname as G,resolve as B}from"path";import{resolveIntegrationToken as C,clearTokenCache as $}from"@zibby/core/backend-client.js";var T=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",LARK_DOCS:"lark_docs",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",VIKUNJA:"vikunja",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),X=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"},lark_docs:{id:"lark_docs",name:"Lark Docs",connectPath:"/integrations?provider=lark_docs"},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"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},vikunja:{id:"vikunja",name:"Vikunja",connectPath:"/integrations?provider=vikunja"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});function j(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let n=G(D(import.meta.url)),e=B(n,"..","bin","mcp-skill.mjs");return v(e)?e:null}var h="https://docs.googleapis.com/v1",N="https://www.googleapis.com/drive/v3",U="https://www.googleapis.com/upload/drive/v3",J=5*1024*1024;function M(){let n=String(process.env.ZIBBY_INJECTED_GOOGLE_TOKEN||"").trim();if(!n)return null;let e=String(process.env.ZIBBY_INJECTED_GOOGLE_EMAIL||"").trim();return{token:n,email:e}}function q(){return String(process.env.ZIBBY_SENDER_IS_NON_OWNER||"").trim()==="1"}function F(){return String(process.env.ZIBBY_CHAT_STRICT_PERSONAL||"").trim()==="1"}var Y="You haven't connected your own Google account \u2014 connect it at https://studio.zibby.dev/integrations (Google Docs). For privacy, I can't use anyone else's Google (including the project owner's) on your behalf.",S=2e4,K=25;function w(n){if(!n||typeof n!="string")return null;let e=n.trim(),t=e.match(/\/document\/(?:u\/\d+\/)?d\/([a-zA-Z0-9_-]+)/);return t?t[1]:/^[a-zA-Z0-9_-]{20,}$/.test(e)?e:null}async function H(){let n,e=M();if(e)n=e.token;else{if(F()||q())throw new Error(Y);({token:n}=await C("google"))}if(typeof n!="string"||!n)throw new Error(`Invalid google token type: ${typeof n}`);return n}async function p(n,e={}){let t=async()=>{let i=await H(),o=await fetch(n,{method:e.method||"GET",headers:{Authorization:`Bearer ${i}`,Accept:"application/json",...e.rawBody&&e.contentType?{"Content-Type":e.contentType}:e.body?{"Content-Type":"application/json"}:{},...e.headers},body:e.rawBody?e.rawBody:e.body?JSON.stringify(e.body):void 0});if(!o.ok){let a=await o.text().catch(()=>"");throw new Error(`Google API ${o.status}: ${a.slice(0,300)}`)}let r=await o.text().catch(()=>"");if(!r||!r.trim())return{};try{return JSON.parse(r)}catch{return{raw:r}}};try{return await t()}catch(i){let o=String(i?.message||i||"").toLowerCase();if(!(o.includes("token")||o.includes("401")||o.includes("unauthorized")))throw i;return $("google"),t()}}function Z(n){let e=[],t="",i=0;for(;i<n.length;){let o=/^\[([^\]]+)\]\(([^)\s]+)\)/.exec(n.slice(i));if(o){e.push({start:t.length,end:t.length+o[1].length,link:o[2]}),t+=o[1],i+=o[0].length;continue}let r=/^\*\*([^*]+)\*\*/.exec(n.slice(i));if(r){e.push({start:t.length,end:t.length+r[1].length,bold:!0}),t+=r[1],i+=r[0].length;continue}let a=/^`([^`]+)`/.exec(n.slice(i));if(a){e.push({start:t.length,end:t.length+a[1].length,code:!0}),t+=a[1],i+=a[0].length;continue}t+=n[i],i+=1}return{text:t,styles:e}}function x(n,e){let t=String(n??"").replace(/\r\n/g,`
|
|
2
2
|
`);if(!t.trim())return{requests:[],endIndex:e};let i=t.split(`
|
|
3
|
-
`),o="",r=[],a=[];for(let s of i){let c=s,I=null,_=null,f=/^(#{1,3})\s+(.*)$/.exec(c),g=/^\s*[-*]\s+(.*)$/.exec(c),m=/^\s*\d+[.)]\s+(.*)$/.exec(c);f?(I=`HEADING_${f[1].length}`,c=f[2]):g?(_="BULLET_DISC_CIRCLE_SQUARE",c=g[1]):m&&(_="NUMBERED_DECIMAL_ALPHA_ROMAN",c=m[1]);let{text:
|
|
4
|
-
`,r.push({start:
|
|
3
|
+
`),o="",r=[],a=[];for(let s of i){let c=s,I=null,_=null,f=/^(#{1,3})\s+(.*)$/.exec(c),g=/^\s*[-*]\s+(.*)$/.exec(c),m=/^\s*\d+[.)]\s+(.*)$/.exec(c);f?(I=`HEADING_${f[1].length}`,c=f[2]):g?(_="BULLET_DISC_CIRCLE_SQUARE",c=g[1]):m&&(_="NUMBERED_DECIMAL_ALPHA_ROMAN",c=m[1]);let{text:E,styles:A}=Z(c),k=e+o.length;for(let b of A)a.push({...b,start:k+b.start,end:k+b.end});o+=`${E}
|
|
4
|
+
`,r.push({start:k,end:e+o.length,named:I,bullet:_})}if(!o)return{requests:[],endIndex:e};let u=[{insertText:{location:{index:e},text:o}}];for(let s of r)s.named&&u.push({updateParagraphStyle:{range:{startIndex:s.start,endIndex:s.end},paragraphStyle:{namedStyleType:s.named},fields:"namedStyleType"}});let d=null,l=()=>{d&&(u.push({createParagraphBullets:{range:{startIndex:d.start,endIndex:d.end},bulletPreset:d.preset}}),d=null)};for(let s of r)s.bullet?d&&d.preset===s.bullet?d.end=s.end:(l(),d={start:s.start,end:s.end,preset:s.bullet}):l();l();for(let s of a)s.end<=s.start||(s.bold?u.push({updateTextStyle:{range:{startIndex:s.start,endIndex:s.end},textStyle:{bold:!0},fields:"bold"}}):s.link?u.push({updateTextStyle:{range:{startIndex:s.start,endIndex:s.end},textStyle:{link:{url:s.link}},fields:"link"}}):s.code&&u.push({updateTextStyle:{range:{startIndex:s.start,endIndex:s.end},textStyle:{weightedFontFamily:{fontFamily:"Courier New"}},fields:"weightedFontFamily"}}));return{requests:u,endIndex:e+o.length}}function z(n){let e="",t=i=>{for(let o of Array.isArray(i)?i:[]){if(e.length>=S)return;if(o.paragraph)for(let r of o.paragraph.elements||[])e+=r?.textRun?.content||"";else if(o.table)for(let r of o.table.tableRows||[])for(let a of r.tableCells||[])t(a.content);else o.tableOfContents&&t(o.tableOfContents.content)}};return t(n?.content),e.slice(0,S)}var y=n=>`https://docs.google.com/document/d/${n}/edit`;function V(n){let e=typeof n=="string"?n.trim():"";if(!e)throw new Error("imagePath is required");if(!v(e)||!P(e).isFile())throw new Error(`imagePath not found (or not a file): ${e}`);if(!/\.(png|jpe?g)$/i.test(e))throw new Error("imagePath must be a .png or .jpg/.jpeg file");let t=R(e);if(t.length>J)throw new Error(`image is ${(t.length/(1024*1024)).toFixed(1)}MB \u2014 max 5MB (Drive multipart upload cap)`);return{bytes:t,fileName:L(e),mimeType:/\.png$/i.test(e)?"image/png":"image/jpeg"}}function W(n,e,t){let i=`zibby-gdocs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;return{rawBody:Buffer.concat([Buffer.from(`--${i}\r
|
|
5
5
|
Content-Type: application/json; charset=UTF-8\r
|
|
6
6
|
\r
|
|
7
7
|
${JSON.stringify(n)}\r
|
package/dist/hubspot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as h}from"fs";import{fileURLToPath as g}from"url";import{dirname as f,resolve as _}from"path";import{resolveIntegrationToken as T}from"@zibby/core/backend-client.js";var y=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",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",VIKUNJA:"vikunja",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),I=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"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},vikunja:{id:"vikunja",name:"Vikunja",connectPath:"/integrations?provider=vikunja"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});function j(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let i=f(g(import.meta.url)),s=_(i,"..","bin","mcp-skill.mjs");return h(s)?s:null}async function p(i,s={}){let{token:e}=await T("hubspot");if(!e)throw new Error("HubSpot not connected \u2014 Connect HubSpot in Integrations.");let t=i.startsWith("https://")?i:`https://api.hubapi.com${i}`,r={Authorization:`Bearer ${e}`,Accept:"application/json",...s.body?{"Content-Type":"application/json"}:{}},o=await fetch(t,{method:s.method||"GET",headers:r,body:s.body?JSON.stringify(s.body):void 0});if(!o.ok){let a=await o.text().catch(()=>""),c=o.status===401||o.status===403?" \u2014 token invalid/expired or missing the required Private App scope for this object":"";throw new Error(`HubSpot API ${o.status}${c}: ${a.slice(0,300)}`)}let n=await o.text().catch(()=>"");if(!n)return{};try{return JSON.parse(n)}catch{return{raw:n}}}function d(i){return typeof i!="string"?null:i.trim()||null}function m(i,s={}){let e=new URLSearchParams;if(i!=null){let r=Array.isArray(i)?i.join(","):String(i);r&&e.set("properties",r)}for(let[r,o]of Object.entries(s))o!=null&&o!==""&&e.set(r,String(o));let t=e.toString();return t?`?${t}`:""}var u="The CRM object type \u2014 one of the common values `contacts`, `companies`, `deals`, `tickets`, `notes`, `tasks`, `feedback_submissions` (customer feedback: NPS/CSAT/CES), or any custom object name/id.",R={id:"hubspot",callsBackend:!0,serverName:"hubspot",allowedTools:["mcp__hubspot__*"],requiresIntegration:y.HUBSPOT,envKeys:["PROJECT_API_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV"],description:"HubSpot CRM \u2014 search/read/create/update contacts, companies, deals, tickets, notes and feedback submissions via the HubSpot REST API.",promptFragment:"## HubSpot CRM\nYou have access to the user's HubSpot CRM via the HubSpot REST API (OAuth \u2014 the user connects HubSpot in Integrations; the token is resolved and auto-refreshed for you). The connected app grants the CRM scopes for the objects you touch.\n\nHubSpot's object model is **uniform** \u2014 nearly every tool takes an `objectType` (`contacts`, `companies`, `deals`, `tickets`, `notes`, `tasks`, `feedback_submissions`, or a custom object). Records are `{ id, properties }`; you set/read named properties.\n\n**Before you create/update/search, call `hubspot_list_properties` to learn the valid property names for that object type** (they're not guessable). `feedback_submissions` is where NPS/CSAT/CES customer-feedback survey responses live.\n\n### Identity\n- hubspot_whoami: Confirm the token works \u2014 returns the portal (hub) id, account type, time zone, UI domain.\n\n### Schema\n- hubspot_list_properties: List the defined properties (name, label, type, fieldType) for an objectType. Do this first so you use real property names.\n\n### Read\n- hubspot_search: Search an objectType by full-text `query` OR structured `filters` (array of {propertyName, operator, value}). Returns { total, results:[{id, properties}] }.\n- hubspot_get_object: Fetch one record by id (optionally selecting specific properties).\n- hubspot_list_objects: Page through all records of an objectType (limit + after cursor).\n\n### Write\n- hubspot_create_object: Create a record from a `properties` object.\n- hubspot_update_object: Patch a record's `properties` by id.\n- hubspot_create_note: Convenience \u2014 log a note (hs_note_body) and optionally associate it to a contact/company/deal/ticket.\n- hubspot_associate: Associate two records (fromType/fromId \u2194 toType/toId) with the default association type.",resolve(){let i=j();if(!i)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:[i,"../dist/hubspot.js","hubspotSkill"],env:s,description:this.description,alwaysLoad:!0}},async handleToolCall(i,s){try{let e=s||{};switch(i){case"hubspot_whoami":{let t=await p("/account-info/v3/details");return JSON.stringify({portalId:t.portalId,accountType:t.accountType,timeZone:t.timeZone,uiDomain:t.uiDomain,companyCurrency:t.companyCurrency})}case"hubspot_list_properties":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required (e.g. contacts, companies, deals, tickets, feedback_submissions)"});let o=((await p(`/crm/v3/properties/${encodeURIComponent(t)}`)).results||[]).map(n=>({name:n.name,label:n.label,type:n.type,fieldType:n.fieldType}));return JSON.stringify({objectType:t,count:o.length,properties:o})}case"hubspot_search":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});let o={limit:Number.isFinite(Number(e.limit))&&Number(e.limit)>0?Math.trunc(Number(e.limit)):20};e.query&&(o.query=String(e.query)),Array.isArray(e.filters)&&e.filters.length&&(o.filterGroups=[{filters:e.filters}]),e.properties!=null&&(o.properties=Array.isArray(e.properties)?e.properties:String(e.properties).split(",").map(a=>a.trim()).filter(Boolean));let n=await p(`/crm/v3/objects/${encodeURIComponent(t)}/search`,{method:"POST",body:o});return JSON.stringify({total:n.total??(n.results?n.results.length:0),results:(n.results||[]).map(a=>({id:a.id,properties:a.properties}))})}case"hubspot_get_object":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});if(!e.id)return JSON.stringify({error:"id is required"});let r=m(e.properties,{associations:e.associations}),o=await p(`/crm/v3/objects/${encodeURIComponent(t)}/${encodeURIComponent(e.id)}${r}`);return JSON.stringify({id:o.id,properties:o.properties,...o.associations?{associations:o.associations}:{}})}case"hubspot_list_objects":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});let r=Number.isFinite(Number(e.limit))&&Number(e.limit)>0?Math.trunc(Number(e.limit)):20,o=m(e.properties,{limit:r,after:e.after}),n=await p(`/crm/v3/objects/${encodeURIComponent(t)}${o}`);return JSON.stringify({results:(n.results||[]).map(a=>({id:a.id,properties:a.properties})),paging:n.paging||null})}case"hubspot_create_object":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});if(!e.properties||typeof e.properties!="object"||Array.isArray(e.properties))return JSON.stringify({error:"properties is required (an object of { propertyName: value } \u2014 call hubspot_list_properties first for valid names)"});let r=await p(`/crm/v3/objects/${encodeURIComponent(t)}`,{method:"POST",body:{properties:e.properties}});return JSON.stringify({id:r.id,properties:r.properties})}case"hubspot_update_object":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});if(!e.id)return JSON.stringify({error:"id is required"});if(!e.properties||typeof e.properties!="object"||Array.isArray(e.properties))return JSON.stringify({error:"properties is required (an object of { propertyName: value })"});let r=await p(`/crm/v3/objects/${encodeURIComponent(t)}/${encodeURIComponent(e.id)}`,{method:"PATCH",body:{properties:e.properties}});return JSON.stringify({id:r.id,properties:r.properties})}case"hubspot_create_note":{if(!e.body||typeof e.body!="string")return JSON.stringify({error:"body is required (the note text)"});let t=typeof e.timestamp=="string"&&e.timestamp?e.timestamp:null;if(!t)try{t=new Date().toISOString()}catch{t=null}if(!t)return JSON.stringify({error:"timestamp is required (pass an ISO 8601 string, e.g. 2026-01-01T00:00:00.000Z)"});let r=await p("/crm/v3/objects/notes",{method:"POST",body:{properties:{hs_note_body:e.body,hs_timestamp:t}}}),o=r.id,n=[["contacts",e.contactId],["companies",e.companyId],["deals",e.dealId],["tickets",e.ticketId]].filter(([,c])=>c!=null&&c!==""),a=[];for(let[c,l]of n)try{await p(`/crm/v4/objects/notes/${encodeURIComponent(o)}/associations/default/${c}/${encodeURIComponent(l)}`,{method:"PUT"}),a.push({toType:c,toId:String(l)})}catch(b){a.push({toType:c,toId:String(l),error:b.message})}return JSON.stringify({id:o,properties:r.properties,associatedTo:a})}case"hubspot_associate":{let t=d(e.fromType),r=d(e.toType);return!t||!e.fromId||!r||!e.toId?JSON.stringify({error:"fromType, fromId, toType and toId are all required"}):(await p(`/crm/v4/objects/${encodeURIComponent(t)}/${encodeURIComponent(e.fromId)}/associations/default/${encodeURIComponent(r)}/${encodeURIComponent(e.toId)}`,{method:"PUT"}),JSON.stringify({ok:!0}))}default:return JSON.stringify({error:`Unknown tool: ${i}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"hubspot_whoami",description:"Confirm the HubSpot token works: returns the portal (hub) id, account type, time zone and UI domain.",input_schema:{type:"object",properties:{}}},{name:"hubspot_list_properties",description:"List the defined properties (name, label, type, fieldType) for a CRM object type. Call this FIRST so you use valid property names when creating/updating/searching.",input_schema:{type:"object",properties:{objectType:{type:"string",description:u}},required:["objectType"]}},{name:"hubspot_search",description:"Search a CRM object type. Pass a full-text `query` OR structured `filters` (array of {propertyName, operator, value}, e.g. operator EQ/CONTAINS_TOKEN/GT/\u2026). Returns { total, results:[{id, properties}] }.",input_schema:{type:"object",properties:{objectType:{type:"string",description:u},query:{type:"string",description:"Optional full-text search string."},filters:{type:"array",description:"Optional structured filters (ANDed). Each: { propertyName, operator, value }. Operators: EQ, NEQ, LT, LTE, GT, GTE, CONTAINS_TOKEN, HAS_PROPERTY, IN, \u2026",items:{type:"object",properties:{propertyName:{type:"string"},operator:{type:"string"},value:{type:"string"}}}},properties:{type:"array",items:{type:"string"},description:"Optional: property names to return on each result."},limit:{type:"number",description:"Max results (default 20)."}},required:["objectType"]}},{name:"hubspot_get_object",description:"Fetch one CRM record by id. Returns { id, properties }.",input_schema:{type:"object",properties:{objectType:{type:"string",description:u},id:{type:"string",description:"The record id."},properties:{type:"array",items:{type:"string"},description:"Optional: specific property names to return."},associations:{type:"string",description:'Optional: comma-separated object types to also return associations for (e.g. "companies,deals").'}},required:["objectType","id"]}},{name:"hubspot_list_objects",description:"Page through records of a CRM object type. Returns { results, paging } \u2014 pass paging.next.after back as `after` for the next page.",input_schema:{type:"object",properties:{objectType:{type:"string",description:u},properties:{type:"array",items:{type:"string"},description:"Optional: property names to return on each record."},limit:{type:"number",description:"Page size (default 20)."},after:{type:"string",description:"Optional paging cursor from a previous response (paging.next.after)."}},required:["objectType"]}},{name:"hubspot_create_object",description:"Create a CRM record. Pass `properties` as an object of { propertyName: value } (call hubspot_list_properties first for valid names). Returns { id, properties }.",input_schema:{type:"object",properties:{objectType:{type:"string",description:u},properties:{type:"object",description:"Object of { propertyName: value } to set on the new record."}},required:["objectType","properties"]}},{name:"hubspot_update_object",description:"Update (PATCH) a CRM record by id. Pass `properties` as an object of { propertyName: value }. Returns { id, properties }.",input_schema:{type:"object",properties:{objectType:{type:"string",description:u},id:{type:"string",description:"The record id to update."},properties:{type:"object",description:"Object of { propertyName: value } to change."}},required:["objectType","id","properties"]}},{name:"hubspot_create_note",description:"Log a note (hs_note_body) and optionally associate it to a contact/company/deal/ticket. Returns { id, associatedTo }.",input_schema:{type:"object",properties:{body:{type:"string",description:"The note text (stored as hs_note_body)."},contactId:{type:"string",description:"Optional: associate the note to this contact id."},companyId:{type:"string",description:"Optional: associate the note to this company id."},dealId:{type:"string",description:"Optional: associate the note to this deal id."},ticketId:{type:"string",description:"Optional: associate the note to this ticket id."},timestamp:{type:"string",description:"Optional ISO 8601 timestamp for the note (defaults to now)."}},required:["body"]}},{name:"hubspot_associate",description:"Associate two CRM records with the default association type (e.g. a contact to a company). Returns { ok:true }.",input_schema:{type:"object",properties:{fromType:{type:"string",description:"Source object type (e.g. contacts)."},fromId:{type:"string",description:"Source record id."},toType:{type:"string",description:"Target object type (e.g. companies)."},toId:{type:"string",description:"Target record id."}},required:["fromType","fromId","toType","toId"]}}]};export{R as hubspotSkill};
|
|
1
|
+
import{existsSync as h}from"fs";import{fileURLToPath as g}from"url";import{dirname as f,resolve as _}from"path";import{resolveIntegrationToken as T}from"@zibby/core/backend-client.js";var y=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",LARK_DOCS:"lark_docs",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",VIKUNJA:"vikunja",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),I=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"},lark_docs:{id:"lark_docs",name:"Lark Docs",connectPath:"/integrations?provider=lark_docs"},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"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},vikunja:{id:"vikunja",name:"Vikunja",connectPath:"/integrations?provider=vikunja"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});function j(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let i=f(g(import.meta.url)),s=_(i,"..","bin","mcp-skill.mjs");return h(s)?s:null}async function p(i,s={}){let{token:e}=await T("hubspot");if(!e)throw new Error("HubSpot not connected \u2014 Connect HubSpot in Integrations.");let t=i.startsWith("https://")?i:`https://api.hubapi.com${i}`,r={Authorization:`Bearer ${e}`,Accept:"application/json",...s.body?{"Content-Type":"application/json"}:{}},o=await fetch(t,{method:s.method||"GET",headers:r,body:s.body?JSON.stringify(s.body):void 0});if(!o.ok){let a=await o.text().catch(()=>""),c=o.status===401||o.status===403?" \u2014 token invalid/expired or missing the required Private App scope for this object":"";throw new Error(`HubSpot API ${o.status}${c}: ${a.slice(0,300)}`)}let n=await o.text().catch(()=>"");if(!n)return{};try{return JSON.parse(n)}catch{return{raw:n}}}function d(i){return typeof i!="string"?null:i.trim()||null}function m(i,s={}){let e=new URLSearchParams;if(i!=null){let r=Array.isArray(i)?i.join(","):String(i);r&&e.set("properties",r)}for(let[r,o]of Object.entries(s))o!=null&&o!==""&&e.set(r,String(o));let t=e.toString();return t?`?${t}`:""}var u="The CRM object type \u2014 one of the common values `contacts`, `companies`, `deals`, `tickets`, `notes`, `tasks`, `feedback_submissions` (customer feedback: NPS/CSAT/CES), or any custom object name/id.",R={id:"hubspot",callsBackend:!0,serverName:"hubspot",allowedTools:["mcp__hubspot__*"],requiresIntegration:y.HUBSPOT,envKeys:["PROJECT_API_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV"],description:"HubSpot CRM \u2014 search/read/create/update contacts, companies, deals, tickets, notes and feedback submissions via the HubSpot REST API.",promptFragment:"## HubSpot CRM\nYou have access to the user's HubSpot CRM via the HubSpot REST API (OAuth \u2014 the user connects HubSpot in Integrations; the token is resolved and auto-refreshed for you). The connected app grants the CRM scopes for the objects you touch.\n\nHubSpot's object model is **uniform** \u2014 nearly every tool takes an `objectType` (`contacts`, `companies`, `deals`, `tickets`, `notes`, `tasks`, `feedback_submissions`, or a custom object). Records are `{ id, properties }`; you set/read named properties.\n\n**Before you create/update/search, call `hubspot_list_properties` to learn the valid property names for that object type** (they're not guessable). `feedback_submissions` is where NPS/CSAT/CES customer-feedback survey responses live.\n\n### Identity\n- hubspot_whoami: Confirm the token works \u2014 returns the portal (hub) id, account type, time zone, UI domain.\n\n### Schema\n- hubspot_list_properties: List the defined properties (name, label, type, fieldType) for an objectType. Do this first so you use real property names.\n\n### Read\n- hubspot_search: Search an objectType by full-text `query` OR structured `filters` (array of {propertyName, operator, value}). Returns { total, results:[{id, properties}] }.\n- hubspot_get_object: Fetch one record by id (optionally selecting specific properties).\n- hubspot_list_objects: Page through all records of an objectType (limit + after cursor).\n\n### Write\n- hubspot_create_object: Create a record from a `properties` object.\n- hubspot_update_object: Patch a record's `properties` by id.\n- hubspot_create_note: Convenience \u2014 log a note (hs_note_body) and optionally associate it to a contact/company/deal/ticket.\n- hubspot_associate: Associate two records (fromType/fromId \u2194 toType/toId) with the default association type.",resolve(){let i=j();if(!i)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:[i,"../dist/hubspot.js","hubspotSkill"],env:s,description:this.description,alwaysLoad:!0}},async handleToolCall(i,s){try{let e=s||{};switch(i){case"hubspot_whoami":{let t=await p("/account-info/v3/details");return JSON.stringify({portalId:t.portalId,accountType:t.accountType,timeZone:t.timeZone,uiDomain:t.uiDomain,companyCurrency:t.companyCurrency})}case"hubspot_list_properties":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required (e.g. contacts, companies, deals, tickets, feedback_submissions)"});let o=((await p(`/crm/v3/properties/${encodeURIComponent(t)}`)).results||[]).map(n=>({name:n.name,label:n.label,type:n.type,fieldType:n.fieldType}));return JSON.stringify({objectType:t,count:o.length,properties:o})}case"hubspot_search":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});let o={limit:Number.isFinite(Number(e.limit))&&Number(e.limit)>0?Math.trunc(Number(e.limit)):20};e.query&&(o.query=String(e.query)),Array.isArray(e.filters)&&e.filters.length&&(o.filterGroups=[{filters:e.filters}]),e.properties!=null&&(o.properties=Array.isArray(e.properties)?e.properties:String(e.properties).split(",").map(a=>a.trim()).filter(Boolean));let n=await p(`/crm/v3/objects/${encodeURIComponent(t)}/search`,{method:"POST",body:o});return JSON.stringify({total:n.total??(n.results?n.results.length:0),results:(n.results||[]).map(a=>({id:a.id,properties:a.properties}))})}case"hubspot_get_object":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});if(!e.id)return JSON.stringify({error:"id is required"});let r=m(e.properties,{associations:e.associations}),o=await p(`/crm/v3/objects/${encodeURIComponent(t)}/${encodeURIComponent(e.id)}${r}`);return JSON.stringify({id:o.id,properties:o.properties,...o.associations?{associations:o.associations}:{}})}case"hubspot_list_objects":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});let r=Number.isFinite(Number(e.limit))&&Number(e.limit)>0?Math.trunc(Number(e.limit)):20,o=m(e.properties,{limit:r,after:e.after}),n=await p(`/crm/v3/objects/${encodeURIComponent(t)}${o}`);return JSON.stringify({results:(n.results||[]).map(a=>({id:a.id,properties:a.properties})),paging:n.paging||null})}case"hubspot_create_object":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});if(!e.properties||typeof e.properties!="object"||Array.isArray(e.properties))return JSON.stringify({error:"properties is required (an object of { propertyName: value } \u2014 call hubspot_list_properties first for valid names)"});let r=await p(`/crm/v3/objects/${encodeURIComponent(t)}`,{method:"POST",body:{properties:e.properties}});return JSON.stringify({id:r.id,properties:r.properties})}case"hubspot_update_object":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});if(!e.id)return JSON.stringify({error:"id is required"});if(!e.properties||typeof e.properties!="object"||Array.isArray(e.properties))return JSON.stringify({error:"properties is required (an object of { propertyName: value })"});let r=await p(`/crm/v3/objects/${encodeURIComponent(t)}/${encodeURIComponent(e.id)}`,{method:"PATCH",body:{properties:e.properties}});return JSON.stringify({id:r.id,properties:r.properties})}case"hubspot_create_note":{if(!e.body||typeof e.body!="string")return JSON.stringify({error:"body is required (the note text)"});let t=typeof e.timestamp=="string"&&e.timestamp?e.timestamp:null;if(!t)try{t=new Date().toISOString()}catch{t=null}if(!t)return JSON.stringify({error:"timestamp is required (pass an ISO 8601 string, e.g. 2026-01-01T00:00:00.000Z)"});let r=await p("/crm/v3/objects/notes",{method:"POST",body:{properties:{hs_note_body:e.body,hs_timestamp:t}}}),o=r.id,n=[["contacts",e.contactId],["companies",e.companyId],["deals",e.dealId],["tickets",e.ticketId]].filter(([,c])=>c!=null&&c!==""),a=[];for(let[c,l]of n)try{await p(`/crm/v4/objects/notes/${encodeURIComponent(o)}/associations/default/${c}/${encodeURIComponent(l)}`,{method:"PUT"}),a.push({toType:c,toId:String(l)})}catch(b){a.push({toType:c,toId:String(l),error:b.message})}return JSON.stringify({id:o,properties:r.properties,associatedTo:a})}case"hubspot_associate":{let t=d(e.fromType),r=d(e.toType);return!t||!e.fromId||!r||!e.toId?JSON.stringify({error:"fromType, fromId, toType and toId are all required"}):(await p(`/crm/v4/objects/${encodeURIComponent(t)}/${encodeURIComponent(e.fromId)}/associations/default/${encodeURIComponent(r)}/${encodeURIComponent(e.toId)}`,{method:"PUT"}),JSON.stringify({ok:!0}))}default:return JSON.stringify({error:`Unknown tool: ${i}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"hubspot_whoami",description:"Confirm the HubSpot token works: returns the portal (hub) id, account type, time zone and UI domain.",input_schema:{type:"object",properties:{}}},{name:"hubspot_list_properties",description:"List the defined properties (name, label, type, fieldType) for a CRM object type. Call this FIRST so you use valid property names when creating/updating/searching.",input_schema:{type:"object",properties:{objectType:{type:"string",description:u}},required:["objectType"]}},{name:"hubspot_search",description:"Search a CRM object type. Pass a full-text `query` OR structured `filters` (array of {propertyName, operator, value}, e.g. operator EQ/CONTAINS_TOKEN/GT/\u2026). Returns { total, results:[{id, properties}] }.",input_schema:{type:"object",properties:{objectType:{type:"string",description:u},query:{type:"string",description:"Optional full-text search string."},filters:{type:"array",description:"Optional structured filters (ANDed). Each: { propertyName, operator, value }. Operators: EQ, NEQ, LT, LTE, GT, GTE, CONTAINS_TOKEN, HAS_PROPERTY, IN, \u2026",items:{type:"object",properties:{propertyName:{type:"string"},operator:{type:"string"},value:{type:"string"}}}},properties:{type:"array",items:{type:"string"},description:"Optional: property names to return on each result."},limit:{type:"number",description:"Max results (default 20)."}},required:["objectType"]}},{name:"hubspot_get_object",description:"Fetch one CRM record by id. Returns { id, properties }.",input_schema:{type:"object",properties:{objectType:{type:"string",description:u},id:{type:"string",description:"The record id."},properties:{type:"array",items:{type:"string"},description:"Optional: specific property names to return."},associations:{type:"string",description:'Optional: comma-separated object types to also return associations for (e.g. "companies,deals").'}},required:["objectType","id"]}},{name:"hubspot_list_objects",description:"Page through records of a CRM object type. Returns { results, paging } \u2014 pass paging.next.after back as `after` for the next page.",input_schema:{type:"object",properties:{objectType:{type:"string",description:u},properties:{type:"array",items:{type:"string"},description:"Optional: property names to return on each record."},limit:{type:"number",description:"Page size (default 20)."},after:{type:"string",description:"Optional paging cursor from a previous response (paging.next.after)."}},required:["objectType"]}},{name:"hubspot_create_object",description:"Create a CRM record. Pass `properties` as an object of { propertyName: value } (call hubspot_list_properties first for valid names). Returns { id, properties }.",input_schema:{type:"object",properties:{objectType:{type:"string",description:u},properties:{type:"object",description:"Object of { propertyName: value } to set on the new record."}},required:["objectType","properties"]}},{name:"hubspot_update_object",description:"Update (PATCH) a CRM record by id. Pass `properties` as an object of { propertyName: value }. Returns { id, properties }.",input_schema:{type:"object",properties:{objectType:{type:"string",description:u},id:{type:"string",description:"The record id to update."},properties:{type:"object",description:"Object of { propertyName: value } to change."}},required:["objectType","id","properties"]}},{name:"hubspot_create_note",description:"Log a note (hs_note_body) and optionally associate it to a contact/company/deal/ticket. Returns { id, associatedTo }.",input_schema:{type:"object",properties:{body:{type:"string",description:"The note text (stored as hs_note_body)."},contactId:{type:"string",description:"Optional: associate the note to this contact id."},companyId:{type:"string",description:"Optional: associate the note to this company id."},dealId:{type:"string",description:"Optional: associate the note to this deal id."},ticketId:{type:"string",description:"Optional: associate the note to this ticket id."},timestamp:{type:"string",description:"Optional ISO 8601 timestamp for the note (defaults to now)."}},required:["body"]}},{name:"hubspot_associate",description:"Associate two CRM records with the default association type (e.g. a contact to a company). Returns { ok:true }.",input_schema:{type:"object",properties:{fromType:{type:"string",description:"Source object type (e.g. contacts)."},fromId:{type:"string",description:"Source record id."},toType:{type:"string",description:"Target object type (e.g. companies)."},toId:{type:"string",description:"Target record id."}},required:["fromType","fromId","toType","toId"]}}]};export{R as hubspotSkill};
|