@zibby/skills 2.0.8 → 2.0.9
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.js +1 -1
- package/dist/chartRender.js +1 -1
- package/dist/chat-notify.js +3 -3
- package/dist/chatProgress.js +3 -3
- package/dist/code-scan.js +1 -1
- package/dist/codeStats.js +2 -2
- package/dist/codebaseMemory.js +1 -1
- package/dist/discord.js +1 -1
- package/dist/figma.js +1 -1
- package/dist/gbrain.js +2 -2
- package/dist/git-write.js +9 -9
- package/dist/github.js +5 -5
- package/dist/gitlab.js +1 -1
- package/dist/googleDocs.js +1 -1
- package/dist/hubspot.js +1 -1
- package/dist/index.js +130 -130
- package/dist/jira.js +7 -7
- package/dist/kvMemory.js +1 -1
- package/dist/lark.js +1 -1
- package/dist/larkAttendance.js +1 -1
- package/dist/larkDocs.js +1 -1
- package/dist/linear.js +1 -1
- package/dist/linkedin.js +2 -2
- package/dist/notion.js +3 -3
- package/dist/opendesign.js +2 -2
- package/dist/package.json +4 -4
- package/dist/reportCheck.js +1 -1
- package/dist/sentry.js +2 -2
- package/dist/slack.js +1 -1
- package/dist/socialCard.js +1 -1
- package/dist/trackers/github-adapter.js +5 -5
- package/dist/trackers/index.js +33 -33
- package/dist/trackers/jira-adapter.js +7 -7
- package/dist/trackers/linear-adapter.js +3 -3
- package/dist/vikunja.js +1 -1
- package/package.json +4 -4
package/dist/github.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{existsSync as
|
|
1
|
+
import{existsSync as Z}from"fs";import{fileURLToPath as X}from"url";import{dirname as ee,resolve as te}from"path";import{resolveIntegrationToken as H}from"@zibby/core/backend-client.js";var I=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"}),ie=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 Chat",connectPath:"/integrations?provider=lark"},lark_docs:{id:"lark_docs",name:"Lark App",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 se,execSync as ae}from"child_process";import{existsSync as ce,mkdirSync as le,readdirSync as ue,statSync as de,readFileSync as me}from"fs";import{resolve as he,join as ye,basename as be}from"path";function L(c,a,t,r,n="clone"){try{c(`git -C "${a}" remote set-url origin "${t}"`,{stdio:"pipe"})}catch(e){let i=String(e?.message||e);r&&(i=i.split(r).join("***")),console.error(`[${n}] WARNING: failed to strip token from .git/config: ${i}`)}}import D from"crypto";var C=/<!--\s*zbfp:([a-f0-9]{8,20})\s*-->/i,x=/<!--\s*zbreview-summary\s*-->/i;function F(c){return String(c||"").replace(C,"").replace(x,"").replace(/\b(?:lines?|L)\s*#?\d+(?:\s*[-–]\s*\d+)?/gi,"").replace(/[`*_>#~]/g,"").replace(/\s+/g," ").trim().toLowerCase().slice(0,400)}function K(c,a){return D.createHash("sha256").update(`${String(c||"")}\0${F(a)}`).digest("hex").slice(0,12)}function B(c){return`
|
|
2
2
|
|
|
3
|
-
<!-- zbfp:${c} -->`}var
|
|
3
|
+
<!-- zbfp:${c} -->`}var M=`
|
|
4
4
|
|
|
5
|
-
<!-- zbreview-summary -->`;function
|
|
5
|
+
<!-- zbreview-summary -->`;function q(c){let a=C.exec(String(c||""));return a?a[1].toLowerCase():null}function G(c){return x.test(String(c||""))}function U(c,a){let t=new Set([...a||[]].map(e=>String(e).toLowerCase())),r=[],n=0;for(let e of Array.isArray(c)?c:[]){if(!e||!e.body)continue;let i=K(e.path,e.body);if(t.has(i)){n+=1;continue}t.add(i),r.push({...e,_fp:i,body:`${String(e.body)}${B(i)}`})}return{toPost:r,skipped:n}}var v={api:{knob:"SKILL_API_TIMEOUT_MS",fallback:3e4},transfer:{knob:"SKILL_TRANSFER_TIMEOUT_MS",fallback:12e4},job:{knob:"SKILL_JOB_TIMEOUT_MS",fallback:3e5}};function z(c,a,t=process.env){let r=Number(t?.[c]);return Number.isFinite(r)&&r>0?Math.min(6e5,Math.max(1e3,Math.floor(r))):a}function W(c="api",a=process.env){let t=v[c]||v.api;return z(t.knob,t.fallback,a)}function Q(c){return c?.name==="TimeoutError"||c?.name==="AbortError"}function V(c){try{return new URL(String(c?.url??c)).host||"unknown host"}catch{return"unknown host"}}function Y(c,a){if(!c)return a;let t=new AbortController,r=i=>{t.signal.aborted||t.abort(i)},n=()=>r(c.reason),e=()=>r(a.reason);return t.signal.addEventListener("abort",()=>{c.removeEventListener("abort",n),a.removeEventListener("abort",e)},{once:!0}),c.aborted?r(c.reason):a.aborted?r(a.reason):(c.addEventListener("abort",n,{once:!0}),a.addEventListener("abort",e,{once:!0})),t.signal}async function J(c,a={},t={}){let r=t.kind||"api",n=(v[r]||v.api).knob,e=t.timeoutMs?Math.min(6e5,Math.max(1e3,Math.floor(t.timeoutMs))):W(r),i=a?.signal;if(i?.aborted)throw i.reason??new DOMException("This operation was aborted","AbortError");let o=AbortSignal.timeout(e),s=Y(i,o);try{return await fetch(c,{...a,signal:s})}catch(m){throw o.aborted&&Q(m)?new Error(`${t.what||"request"} TIMED OUT after ${e}ms against ${V(c)} (${n})`):m}}function re(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let c=ee(X(import.meta.url)),a=te(c,"..","bin","mcp-skill.mjs");return Z(a)?a:null}async function u(c,a={}){let{token:t}=await H("github"),r=c.startsWith("https://")?c:`https://api.github.com${c}`,n={Authorization:`Bearer ${t}`,Accept:a.accept||"application/vnd.github.v3+json","User-Agent":"Zibby-App",...a.body?{"Content-Type":"application/json"}:{}},e=await J(r,{method:a.method||"GET",headers:n,body:a.body?JSON.stringify(a.body):void 0},{kind:"api",what:`GitHub ${a.method||"GET"} ${c}`});if(!e.ok){let i=await e.text().catch(()=>""),o=new Error(`GitHub API ${e.status}: ${i.slice(0,300)}`);throw o.status=e.status,o}return a.raw?e.text():e.json()}var Ee={id:"github",callsBackend:!0,serverName:"github",allowedTools:["mcp__github__*"],requiresIntegration:I.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 c=X();if(!c)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:[c,"../dist/github.js","githubSkill"],env:a,description:this.description,alwaysLoad:!0}},async handleToolCall(c,a){try{switch(c){case"github_search_issues":{let t=a.query;if(!t)return JSON.stringify({error:"query is required"});let r=await u(`/search/issues?q=${encodeURIComponent(t)}&per_page=${a.limit||20}`),n=(r.items||[]).map(e=>({number:e.number,title:e.title,state:e.state,repo:e.repository_url?.split("/").slice(-2).join("/"),url:e.html_url,user:e.user?.login,isPR:!!e.pull_request,labels:(e.labels||[]).map(i=>i.name),createdAt:e.created_at}));return JSON.stringify({total:r.total_count,items:n})}case"github_search_code":{let t=a.query;if(!t)return JSON.stringify({error:"query is required"});let r=a.repo?`+repo:${a.repo}`:"",n=a.language?`+language:${a.language}`:"",e=await u(`/search/code?q=${encodeURIComponent(t)}${r}${n}&per_page=${a.limit||15}`),i=(e.items||[]).map(s=>({name:s.name,path:s.path,repo:s.repository?.full_name,url:s.html_url,score:s.score}));return JSON.stringify({total:e.total_count,items:i})}case"github_get_pr":{let{owner:t,repo:r,number:n}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/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(i=>i.name)})}case"github_get_pr_diff":{let{owner:t,repo:r,number:n}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/pulls/${n}`,{accept:"application/vnd.github.v3.diff",raw:!0}),i=e.length>15e3;return JSON.stringify({number:n,diff:i?e.slice(0,15e3):e,truncated:i,totalLength:e.length})}case"github_list_pr_files":{let{owner:t,repo:r,number:n}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/pulls/${n}/files?per_page=100`);return JSON.stringify({total:e.length,files:e.map(i=>({filename:i.filename,status:i.status,additions:i.additions,deletions:i.deletions,patch:i.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:t,repo:r,number:n}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/pulls/${n}/comments?per_page=50`),i=await u(`/repos/${t}/${r}/issues/${n}/comments?per_page=50`),s=[...e.map(o=>({type:"review",user:o.user?.login,body:o.body?.slice(0,1e3),path:o.path,line:o.line,createdAt:o.created_at})),...i.map(o=>({type:"issue",user:o.user?.login,body:o.body?.slice(0,1e3),createdAt:o.created_at}))].sort((o,d)=>new Date(o.createdAt)-new Date(d.createdAt));return JSON.stringify({total:s.length,comments:s})}case"github_get_review_thread":{let{owner:t,repo:r,number:n,commentId:e}=a||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, number, and commentId are required"});let i=await u(`/repos/${t}/${r}/pulls/comments/${e}`),s=i.in_reply_to_id||i.id,o=[];try{o=await u(`/repos/${t}/${r}/pulls/${n}/comments?per_page=100`)}catch{o=[i]}(!Array.isArray(o)||o.length===0)&&(o=[i]);let d=o.filter(h=>h.id===s||h.in_reply_to_id===s).sort((h,b)=>new Date(h.created_at)-new Date(b.created_at)),m=d.length?d:[i],l=m.find(h=>h.id===s)||m[0];return JSON.stringify({rootCommentId:s,path:l.path,line:l.line??l.original_line??null,side:l.side||"RIGHT",diffHunk:typeof l.diff_hunk=="string"?l.diff_hunk.slice(0,3e3):null,commitId:l.commit_id||l.original_commit_id||null,notes:m.map(h=>({id:h.id,user:h.user?.login,body:(h.body||"").slice(0,4e3),createdAt:h.created_at,isRoot:h.id===s,url:h.html_url}))})}case"github_reply_review_thread":{let{owner:t,repo:r,number:n,commentId:e,body:i}=a||{};if(!t||!r||!n||!e||!i)return JSON.stringify({error:"owner, repo, number, commentId, and body are required"});let s=await u(`/repos/${t}/${r}/pulls/${n}/comments/${e}/replies`,{method:"POST",body:{body:String(i)}});return JSON.stringify({ok:!0,id:s.id,url:s.html_url,inReplyTo:s.in_reply_to_id})}case"github_reply_issue_comment":{let{owner:t,repo:r,number:n,body:e}=a||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let i=await u(`/repos/${t}/${r}/issues/${n}/comments`,{method:"POST",body:{body:String(e)}});return JSON.stringify({ok:!0,id:i.id,url:i.html_url})}case"github_create_review":{let{owner:t,repo:r,number:n,body:e,event:i,comments:s}=a||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o=(i||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(o))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${i})`});let d=Array.isArray(s)?s.filter(g=>g&&g.path&&g.body&&(g.line!=null||g.position!=null)).map(g=>{let p={path:g.path,body:String(g.body)};return g.line!=null?(p.line=Number(g.line),p.side=g.side==="LEFT"?"LEFT":"RIGHT"):p.position=Number(g.position),p}):[];if(o!=="APPROVE"&&!e&&d.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let m=new Set,l=null;try{for(let g=1;g<=20;g+=1){let p=await u(`/repos/${t}/${r}/pulls/${n}/comments?per_page=100&page=${g}`);if(!Array.isArray(p)||p.length===0)break;for(let f of p){let R=C(f.body);R&&m.add(R)}if(p.length<100)break}for(let g=1;g<=20&&l==null;g+=1){let p=await u(`/repos/${t}/${r}/issues/${n}/comments?per_page=100&page=${g}`);if(!Array.isArray(p)||p.length===0)break;for(let f of p)if(x(f.body)){l=f.id;break}if(p.length<100)break}}catch{}let h=!1,b=!1;if(e){let g=`${String(e)}${L}`;try{l!=null?(await u(`/repos/${t}/${r}/issues/comments/${l}`,{method:"PATCH",body:{body:g}}),h=!0):await u(`/repos/${t}/${r}/issues/${n}/comments`,{method:"POST",body:{body:g}}),b=!0}catch{}}let{toPost:y,skipped:w}=M(d,m),_=y.map(({_fp:g,...p})=>p),S=null;if(_.length>0||o==="APPROVE"||o==="REQUEST_CHANGES"){let g={event:o};_.length>0&&(g.comments=_),_.length===0&&o==="REQUEST_CHANGES"&&(g.body="Changes requested \u2014 see the review summary comment."),S=await u(`/repos/${t}/${r}/pulls/${n}/reviews`,{method:"POST",body:g})}return JSON.stringify({ok:!0,id:S?S.id:void 0,state:S?S.state:void 0,event:o,notePosted:b,summaryUpdated:h,commentsPosted:_.length,inlineSkipped:w||void 0,url:S?S.html_url:void 0})}case"github_list_commits":{let{owner:t,repo:r,branch:n,path:e,limit:i,since:s,until:o,page:d}=a;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let m=Math.min(Number(i)||20,100),l=`/repos/${t}/${r}/commits?per_page=${m}&page=${Number(d)||1}`;n&&(l+=`&sha=${encodeURIComponent(n)}`),e&&(l+=`&path=${encodeURIComponent(e)}`),s&&(l+=`&since=${encodeURIComponent(s)}`),o&&(l+=`&until=${encodeURIComponent(o)}`);let h=await u(l);return JSON.stringify({total:h.length,page:Number(d)||1,hasMore:h.length>=m,commits:h.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:r,sha:n,includePrs:e}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and sha are required"});let i=await u(`/repos/${t}/${r}/commits/${n}`),s;if(e)try{let o=await u(`/repos/${t}/${r}/commits/${n}/pulls`);s=(Array.isArray(o)?o:[]).map(d=>({number:d.number,title:d.title,state:d.state,merged:!!d.merged_at,webUrl:d.html_url}))}catch{s=[]}return JSON.stringify({sha:i.sha?.slice(0,8),message:i.commit?.message,author:i.commit?.author?.name,date:i.commit?.author?.date,stats:i.stats,files:(i.files||[]).map(o=>({filename:o.filename,status:o.status,additions:o.additions,deletions:o.deletions,patch:o.patch?.slice(0,3e3)})),...s?{pullRequests:s}:{}})}case"github_get_file":{let{owner:t,repo:r,path:n,ref:e}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and path are required"});let i=`/repos/${t}/${r}/contents/${encodeURIComponent(n)}`;e&&(i+=`?ref=${encodeURIComponent(e)}`);let s=await u(i);if(s.type!=="file")return Array.isArray(s)?JSON.stringify({type:"directory",path:n,entries:s.map(m=>({name:m.name,type:m.type,size:m.size,path:m.path}))}):JSON.stringify({error:`Not a file: ${s.type}`});let o=Buffer.from(s.content||"","base64").toString("utf-8"),d=o.length>2e4;return JSON.stringify({path:s.path,size:s.size,sha:s.sha?.slice(0,8),content:d?o.slice(0,2e4):o,truncated:d})}case"github_get_user":try{let t=await u("/installation/repositories?per_page=1");if(t.repositories&&t.repositories.length>0){let r=t.repositories[0],n=r.owner.login,e=r.owner.type,i=e==="Organization"?`/orgs/${n}`:`/users/${n}`,s=await u(i);return JSON.stringify({login:s.login,name:s.name||s.login,avatar:s.avatar_url,bio:s.bio||s.description,type:e,isOrg:e==="Organization",publicRepos:s.public_repos,message:"Showing GitHub App installation owner (GitHub Apps cannot access /user endpoint)"})}return JSON.stringify({error:"No repositories accessible to this GitHub App installation"})}catch(t){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${t.message})`})}case"github_list_orgs":try{let r=(await u("/installation/repositories?per_page=100")).repositories||[],n=new Map;for(let i of r)i.owner.type==="Organization"&&(n.has(i.owner.login)||n.set(i.owner.login,{login:i.owner.login,description:null,url:i.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(g){let p=g.replace(/^~(?=$|\/|\\)/,b);return s(p)},{owner:t,repo:r,destination:n}=a;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let{execSync:e}=await import("child_process"),{join:i,resolve:s}=await import("path"),{existsSync:o,mkdirSync:d}=await import("fs"),{homedir:m,platform:l}=await import("os"),{token:h}=await G("github"),b=m(),w=n?y(n):i(b,"zibby-repos"),_=i(w,r);if(d(w,{recursive:!0}),o(_))return JSON.stringify({error:`Directory ${_} already exists. Remove it first or use a different destination.`,existingPath:_});let S=`https://x-access-token:${h}@github.com/${t}/${r}.git`;try{e(`git clone ${S} "${_}"`,{stdio:"pipe"});let g=`https://github.com/${t}/${r}.git`;E(e,_,g,h,"github_clone");let p=l()==="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}/${r} to ${_}`,contents:f.split(`
|
|
48
|
+
- Use github_get_file to read individual files via API`,resolve(){let c=re();if(!c)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:[c,"../dist/github.js","githubSkill"],env:a,description:this.description}},async handleToolCall(c,a){try{switch(c){case"github_search_issues":{let t=a.query;if(!t)return JSON.stringify({error:"query is required"});let r=await u(`/search/issues?q=${encodeURIComponent(t)}&per_page=${a.limit||20}`),n=(r.items||[]).map(e=>({number:e.number,title:e.title,state:e.state,repo:e.repository_url?.split("/").slice(-2).join("/"),url:e.html_url,user:e.user?.login,isPR:!!e.pull_request,labels:(e.labels||[]).map(i=>i.name),createdAt:e.created_at}));return JSON.stringify({total:r.total_count,items:n})}case"github_search_code":{let t=a.query;if(!t)return JSON.stringify({error:"query is required"});let r=a.repo?`+repo:${a.repo}`:"",n=a.language?`+language:${a.language}`:"",e=await u(`/search/code?q=${encodeURIComponent(t)}${r}${n}&per_page=${a.limit||15}`),i=(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:i})}case"github_get_pr":{let{owner:t,repo:r,number:n}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/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(i=>i.name)})}case"github_get_pr_diff":{let{owner:t,repo:r,number:n}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/pulls/${n}`,{accept:"application/vnd.github.v3.diff",raw:!0}),i=e.length>15e3;return JSON.stringify({number:n,diff:i?e.slice(0,15e3):e,truncated:i,totalLength:e.length})}case"github_list_pr_files":{let{owner:t,repo:r,number:n}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/pulls/${n}/files?per_page=100`);return JSON.stringify({total:e.length,files:e.map(i=>({filename:i.filename,status:i.status,additions:i.additions,deletions:i.deletions,patch:i.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:t,repo:r,number:n}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/pulls/${n}/comments?per_page=50`),i=await u(`/repos/${t}/${r}/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})),...i.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:r,number:n,commentId:e}=a||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, number, and commentId are required"});let i=await u(`/repos/${t}/${r}/pulls/comments/${e}`),o=i.in_reply_to_id||i.id,s=[];try{s=await u(`/repos/${t}/${r}/pulls/${n}/comments?per_page=100`)}catch{s=[i]}(!Array.isArray(s)||s.length===0)&&(s=[i]);let m=s.filter(h=>h.id===o||h.in_reply_to_id===o).sort((h,f)=>new Date(h.created_at)-new Date(f.created_at)),d=m.length?m:[i],l=d.find(h=>h.id===o)||d[0];return JSON.stringify({rootCommentId:o,path:l.path,line:l.line??l.original_line??null,side:l.side||"RIGHT",diffHunk:typeof l.diff_hunk=="string"?l.diff_hunk.slice(0,3e3):null,commitId:l.commit_id||l.original_commit_id||null,notes:d.map(h=>({id:h.id,user:h.user?.login,body:(h.body||"").slice(0,4e3),createdAt:h.created_at,isRoot:h.id===o,url:h.html_url}))})}case"github_reply_review_thread":{let{owner:t,repo:r,number:n,commentId:e,body:i}=a||{};if(!t||!r||!n||!e||!i)return JSON.stringify({error:"owner, repo, number, commentId, and body are required"});let o=await u(`/repos/${t}/${r}/pulls/${n}/comments/${e}/replies`,{method:"POST",body:{body:String(i)}});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:r,number:n,body:e}=a||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let i=await u(`/repos/${t}/${r}/issues/${n}/comments`,{method:"POST",body:{body:String(e)}});return JSON.stringify({ok:!0,id:i.id,url:i.html_url})}case"github_create_review":{let{owner:t,repo:r,number:n,body:e,event:i,comments:o}=a||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let s=(i||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(s))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${i})`});let m=Array.isArray(o)?o.filter(g=>g&&g.path&&g.body&&(g.line!=null||g.position!=null)).map(g=>{let p={path:g.path,body:String(g.body)};return g.line!=null?(p.line=Number(g.line),p.side=g.side==="LEFT"?"LEFT":"RIGHT"):p.position=Number(g.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 d=new Set,l=null;try{for(let g=1;g<=20;g+=1){let p=await u(`/repos/${t}/${r}/pulls/${n}/comments?per_page=100&page=${g}`);if(!Array.isArray(p)||p.length===0)break;for(let y of p){let R=q(y.body);R&&d.add(R)}if(p.length<100)break}for(let g=1;g<=20&&l==null;g+=1){let p=await u(`/repos/${t}/${r}/issues/${n}/comments?per_page=100&page=${g}`);if(!Array.isArray(p)||p.length===0)break;for(let y of p)if(G(y.body)){l=y.id;break}if(p.length<100)break}}catch{}let h=!1,f=!1;if(e){let g=`${String(e)}${M}`;try{l!=null?(await u(`/repos/${t}/${r}/issues/comments/${l}`,{method:"PATCH",body:{body:g}}),h=!0):await u(`/repos/${t}/${r}/issues/${n}/comments`,{method:"POST",body:{body:g}}),f=!0}catch{}}let{toPost:b,skipped:w}=U(m,d),_=b.map(({_fp:g,...p})=>p),S=null;if(_.length>0||s==="APPROVE"||s==="REQUEST_CHANGES"){let g={event:s};_.length>0&&(g.comments=_),_.length===0&&s==="REQUEST_CHANGES"&&(g.body="Changes requested \u2014 see the review summary comment."),S=await u(`/repos/${t}/${r}/pulls/${n}/reviews`,{method:"POST",body:g})}return JSON.stringify({ok:!0,id:S?S.id:void 0,state:S?S.state:void 0,event:s,notePosted:f,summaryUpdated:h,commentsPosted:_.length,inlineSkipped:w||void 0,url:S?S.html_url:void 0})}case"github_list_commits":{let{owner:t,repo:r,branch:n,path:e,limit:i,since:o,until:s,page:m}=a;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let d=Math.min(Number(i)||20,100),l=`/repos/${t}/${r}/commits?per_page=${d}&page=${Number(m)||1}`;n&&(l+=`&sha=${encodeURIComponent(n)}`),e&&(l+=`&path=${encodeURIComponent(e)}`),o&&(l+=`&since=${encodeURIComponent(o)}`),s&&(l+=`&until=${encodeURIComponent(s)}`);let h=await u(l);return JSON.stringify({total:h.length,page:Number(m)||1,hasMore:h.length>=d,commits:h.map(f=>({sha:f.sha?.slice(0,8),fullSha:f.sha,message:f.commit?.message?.slice(0,300),author:f.commit?.author?.name,authorEmail:f.commit?.author?.email,date:f.commit?.author?.date,url:f.html_url}))})}case"github_get_commit":{let{owner:t,repo:r,sha:n,includePrs:e}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and sha are required"});let i=await u(`/repos/${t}/${r}/commits/${n}`),o;if(e)try{let s=await u(`/repos/${t}/${r}/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:i.sha?.slice(0,8),message:i.commit?.message,author:i.commit?.author?.name,date:i.commit?.author?.date,stats:i.stats,files:(i.files||[]).map(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:r,path:n,ref:e}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and path are required"});let i=`/repos/${t}/${r}/contents/${encodeURIComponent(n)}`;e&&(i+=`?ref=${encodeURIComponent(e)}`);let o=await u(i);if(o.type!=="file")return Array.isArray(o)?JSON.stringify({type:"directory",path:n,entries:o.map(d=>({name:d.name,type:d.type,size:d.size,path:d.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 u("/installation/repositories?per_page=1");if(t.repositories&&t.repositories.length>0){let r=t.repositories[0],n=r.owner.login,e=r.owner.type,i=e==="Organization"?`/orgs/${n}`:`/users/${n}`,o=await u(i);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 r=(await u("/installation/repositories?per_page=100")).repositories||[],n=new Map;for(let i of r)i.owner.type==="Organization"&&(n.has(i.owner.login)||n.set(i.owner.login,{login:i.owner.login,description:null,url:i.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 b=function(g){let p=g.replace(/^~(?=$|\/|\\)/,f);return o(p)},{owner:t,repo:r,destination:n}=a;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let{execSync:e}=await import("child_process"),{join:i,resolve:o}=await import("path"),{existsSync:s,mkdirSync:m}=await import("fs"),{homedir:d,platform:l}=await import("os"),{token:h}=await H("github"),f=d(),w=n?b(n):i(f,"zibby-repos"),_=i(w,r);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:${h}@github.com/${t}/${r}.git`;try{e(`git clone ${S} "${_}"`,{stdio:"pipe"});let g=`https://github.com/${t}/${r}.git`;L(e,_,g,h,"github_clone");let p=l()==="win32",y;return p?y=e(`dir "${_}"`,{encoding:"utf-8",shell:"cmd.exe"}):y=e(`ls -la "${_}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:_,message:`Cloned ${t}/${r} to ${_}`,contents:y.split(`
|
|
49
49
|
`).slice(0,30).join(`
|
|
50
|
-
`),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(g){let f=String(g.message||g).split(h).join("***").replace(/x-access-token:[^@]*@/g,"x-access-token:***@");return JSON.stringify({error:`Clone failed: ${f}`})}}case"github_search_repos":{let{query:t,limit:r}=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 i=t.toLowerCase(),s=e.repos.filter(o=>o.name.toLowerCase().includes(i)||o.fullName.toLowerCase().includes(i)||o.description&&o.description.toLowerCase().includes(i));return JSON.stringify({query:t,count:s.length,repos:s.slice(0,r||20)})}case"github_list_repos":{let{owner:t,type:r,sort:n,direction:e,limit:i,query:s}=a,o=100,d=i||200,m=[],l=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")}),h=p=>{if(!s)return!0;let f=String(s).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&&m.length<d;){let $=`/installation/repositories?per_page=${o}&page=${p}`,v=(await u($)).repositories||[];if(v.length===0)break;m=m.concat(v),f=v.length===o,p++}let R=m.map(l).filter(h),O=R.slice(0,d),U=R.length>O.length,N=O.filter($=>$.private).length,A=O.filter($=>!$.private).length;return JSON.stringify({count:O.length,repos:O,truncated:U,privateCount:N,publicCount:A,message:`Found ${N} private and ${A} public repos`})}let b=await u(`/orgs/${t}`).then(()=>!0).catch(()=>!1),y=1,w=!0;for(;w&&m.length<d;){let p;b?p=`/orgs/${t}/repos?per_page=${o}&page=${y}&type=${r||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`:p=`/users/${t}/repos?per_page=${o}&page=${y}&type=${r||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`;let f=await u(p),R=Array.isArray(f)?f:[];if(R.length===0)break;m=m.concat(R),w=R.length===o,y++}let _=m.map(l).filter(h),S=_.slice(0,d),g=_.length>S.length;return JSON.stringify({count:S.length,repos:S,truncated:g})}case"github_create_pr":{let{owner:t,repo:r,head:n,title:e}=a||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, head (source branch), and title are required"});let i=a.base;if(!i)try{i=(await u(`/repos/${t}/${r}`)).default_branch||"main"}catch{i="main"}let s={title:String(e),head:String(n),base:String(i),body:a.body?String(a.body):"",draft:!!a.draft};try{let o=await u(`/repos/${t}/${r}/pulls`,{method:"POST",body:s});return JSON.stringify({success:!0,pr_url:o.html_url,number:o.number,branch:n,base:i,repo:`${t}/${r}`,provider:"github",draft:!!o.draft,state:o.state})}catch(o){let d=String(o.message||o);if(/GitHub API 422/.test(d))return JSON.stringify({success:!1,branch:n,base:i,repo:`${t}/${r}`,provider:"github",skippedReason:d});throw o}}case"github_merge_pr":{let{owner:t,repo:r,number:n}=a||{};if(!t||!r||!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 i={merge_method:e};a.commitTitle&&(i.commit_title=String(a.commitTitle)),a.commitMessage&&(i.commit_message=String(a.commitMessage));try{let s=await u(`/repos/${t}/${r}/pulls/${n}/merge`,{method:"PUT",body:i});return JSON.stringify({success:!0,merged:!0,sha:s.sha,number:n,provider:"github"})}catch(s){let o=String(s.message||s);if(/GitHub API (405|409|404)/.test(o))return JSON.stringify({success:!1,number:n,provider:"github",skippedReason:o});throw s}}case"github_create_issue":{let{owner:t,repo:r,title:n,body:e}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and title are required"});let i=await u(`/repos/${t}/${r}/issues`,{method:"POST",body:{title:n,body:e||""}});return JSON.stringify({number:i.number,url:i.html_url,title:i.title})}case"github_list_issues":{let{owner:t,repo:r,state:n,labels:e,since:i,assignee:s,sort:o,direction:d,limit:m}=a||{};if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let l=new URLSearchParams;l.set("state",n||"open"),l.set("per_page",String(m||30)),l.set("sort",o||"updated"),l.set("direction",d||"desc"),e&&l.set("labels",Array.isArray(e)?e.join(","):e),i&&l.set("since",i),s&&l.set("assignee",s);let h=await u(`/repos/${t}/${r}/issues?${l.toString()}`),b=(Array.isArray(h)?h:[]).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:r,number:n}=a||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/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(i=>typeof i=="string"?i:i.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(i=>i.login),user:e.user?.login,milestone:e.milestone?.title||null,comments:e.comments,url:e.html_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"github_get_issue_comments":{let{owner:t,repo:r,number:n,limit:e}=a||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await u(`/repos/${t}/${r}/issues/${n}/comments?per_page=${e||100}`),s=(Array.isArray(i)?i:[]).map(o=>({id:o.id,user:o.user?.login,body:o.body||"",createdAt:o.created_at,updatedAt:o.updated_at,url:o.html_url}));return JSON.stringify({count:s.length,comments:s})}case"github_add_issue_comment":{let{owner:t,repo:r,number:n,body:e}=a||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let i=await u(`/repos/${t}/${r}/issues/${n}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:i.id,url:i.html_url})}case"github_close_issue":{let{owner:t,repo:r,number:n,stateReason:e}=a||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i={state:"closed"};e&&(i.state_reason=e);let s=await u(`/repos/${t}/${r}/issues/${n}`,{method:"PATCH",body:i});return JSON.stringify({ok:!0,number:s.number,state:s.state,stateReason:s.state_reason||null,url:s.html_url})}case"github_reopen_issue":{let{owner:t,repo:r,number:n}=a||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/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:r,number:n,labels:e,mode:i}=a||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let s=Array.isArray(e)?e:e?[e]:[];if(!s.length)return JSON.stringify({error:"labels (string or array) is required"});let o=i||"add";if(o==="set"){let m=await u(`/repos/${t}/${r}/issues/${n}`,{method:"PATCH",body:{labels:s}});return JSON.stringify({ok:!0,number:m.number,labels:(m.labels||[]).map(l=>typeof l=="string"?l:l.name)})}if(o==="remove"){for(let l of s)await u(`/repos/${t}/${r}/issues/${n}/labels/${encodeURIComponent(l)}`,{method:"DELETE"});let m=await u(`/repos/${t}/${r}/issues/${n}`);return JSON.stringify({ok:!0,number:m.number,labels:(m.labels||[]).map(l=>typeof l=="string"?l:l.name)})}let d=await u(`/repos/${t}/${r}/issues/${n}/labels`,{method:"POST",body:{labels:s}});return JSON.stringify({ok:!0,number:n,labels:(Array.isArray(d)?d:[]).map(m=>typeof m=="string"?m:m.name)})}default:return JSON.stringify({error:`Unknown tool: ${c}`})}}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{u as ghFetch,Ae as githubSkill};
|
|
50
|
+
`),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(g){let y=String(g.message||g).split(h).join("***").replace(/x-access-token:[^@]*@/g,"x-access-token:***@");return JSON.stringify({error:`Clone failed: ${y}`})}}case"github_search_repos":{let{query:t,limit:r}=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 i=t.toLowerCase(),o=e.repos.filter(s=>s.name.toLowerCase().includes(i)||s.fullName.toLowerCase().includes(i)||s.description&&s.description.toLowerCase().includes(i));return JSON.stringify({query:t,count:o.length,repos:o.slice(0,r||20)})}case"github_list_repos":{let{owner:t,type:r,sort:n,direction:e,limit:i,query:o}=a,s=100,m=i||200,d=[],l=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")}),h=p=>{if(!o)return!0;let y=String(o).toLowerCase();return p.name&&p.name.toLowerCase().includes(y)||p.fullName&&p.fullName.toLowerCase().includes(y)||p.description&&p.description.toLowerCase().includes(y)};if(!t){let p=1,y=!0,R=!1;for(;y&&d.length<m;){let $=`/installation/repositories?per_page=${s}&page=${p}`,O;try{O=await u($)}catch(A){if((A?.status===401||A?.status===403)&&p===1){R=!0;break}throw A}let N=O.repositories||[];if(N.length===0)break;d=d.concat(N),y=N.length===s,p++}if(R)for(p=1,y=!0;y&&d.length<m;){let $=await u(`/user/repos?per_page=${s}&page=${p}&affiliation=owner,collaborator,organization_member&sort=${n||"updated"}&direction=${e||"desc"}`),O=Array.isArray($)?$:[];if(O.length===0)break;d=d.concat(O),y=O.length===s,p++}let T=d.map(l).filter(h),k=T.slice(0,m),j=T.length>k.length,E=k.filter($=>$.private).length,P=k.filter($=>!$.private).length;return JSON.stringify({count:k.length,repos:k,truncated:j,privateCount:E,publicCount:P,message:`Found ${E} private and ${P} public repos`})}let f=await u(`/orgs/${t}`).then(()=>!0).catch(()=>!1),b=1,w=!0;for(;w&&d.length<m;){let p;f?p=`/orgs/${t}/repos?per_page=${s}&page=${b}&type=${r||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`:p=`/users/${t}/repos?per_page=${s}&page=${b}&type=${r||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`;let y=await u(p),R=Array.isArray(y)?y:[];if(R.length===0)break;d=d.concat(R),w=R.length===s,b++}let _=d.map(l).filter(h),S=_.slice(0,m),g=_.length>S.length;return JSON.stringify({count:S.length,repos:S,truncated:g})}case"github_create_pr":{let{owner:t,repo:r,head:n,title:e}=a||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, head (source branch), and title are required"});let i=a.base;if(!i)try{i=(await u(`/repos/${t}/${r}`)).default_branch||"main"}catch{i="main"}let o={title:String(e),head:String(n),base:String(i),body:a.body?String(a.body):"",draft:!!a.draft};try{let s=await u(`/repos/${t}/${r}/pulls`,{method:"POST",body:o});return JSON.stringify({success:!0,pr_url:s.html_url,number:s.number,branch:n,base:i,repo:`${t}/${r}`,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:i,repo:`${t}/${r}`,provider:"github",skippedReason:m});throw s}}case"github_merge_pr":{let{owner:t,repo:r,number:n}=a||{};if(!t||!r||!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 i={merge_method:e};a.commitTitle&&(i.commit_title=String(a.commitTitle)),a.commitMessage&&(i.commit_message=String(a.commitMessage));try{let o=await u(`/repos/${t}/${r}/pulls/${n}/merge`,{method:"PUT",body:i});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:r,title:n,body:e}=a;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and title are required"});let i=await u(`/repos/${t}/${r}/issues`,{method:"POST",body:{title:n,body:e||""}});return JSON.stringify({number:i.number,url:i.html_url,title:i.title})}case"github_list_issues":{let{owner:t,repo:r,state:n,labels:e,since:i,assignee:o,sort:s,direction:m,limit:d}=a||{};if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let l=new URLSearchParams;l.set("state",n||"open"),l.set("per_page",String(d||30)),l.set("sort",s||"updated"),l.set("direction",m||"desc"),e&&l.set("labels",Array.isArray(e)?e.join(","):e),i&&l.set("since",i),o&&l.set("assignee",o);let h=await u(`/repos/${t}/${r}/issues?${l.toString()}`),f=(Array.isArray(h)?h:[]).filter(b=>!b.pull_request).map(b=>({number:b.number,title:b.title,state:b.state,labels:(b.labels||[]).map(w=>typeof w=="string"?w:w.name),assignee:b.assignee?.login||null,assignees:(b.assignees||[]).map(w=>w.login),user:b.user?.login,comments:b.comments,url:b.html_url,createdAt:b.created_at,updatedAt:b.updated_at}));return JSON.stringify({count:f.length,issues:f})}case"github_get_issue":{let{owner:t,repo:r,number:n}=a||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/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(i=>typeof i=="string"?i:i.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(i=>i.login),user:e.user?.login,milestone:e.milestone?.title||null,comments:e.comments,url:e.html_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"github_get_issue_comments":{let{owner:t,repo:r,number:n,limit:e}=a||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await u(`/repos/${t}/${r}/issues/${n}/comments?per_page=${e||100}`),o=(Array.isArray(i)?i:[]).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:r,number:n,body:e}=a||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let i=await u(`/repos/${t}/${r}/issues/${n}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:i.id,url:i.html_url})}case"github_close_issue":{let{owner:t,repo:r,number:n,stateReason:e}=a||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i={state:"closed"};e&&(i.state_reason=e);let o=await u(`/repos/${t}/${r}/issues/${n}`,{method:"PATCH",body:i});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:r,number:n}=a||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/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:r,number:n,labels:e,mode:i}=a||{};if(!t||!r||!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=i||"add";if(s==="set"){let d=await u(`/repos/${t}/${r}/issues/${n}`,{method:"PATCH",body:{labels:o}});return JSON.stringify({ok:!0,number:d.number,labels:(d.labels||[]).map(l=>typeof l=="string"?l:l.name)})}if(s==="remove"){for(let l of o)await u(`/repos/${t}/${r}/issues/${n}/labels/${encodeURIComponent(l)}`,{method:"DELETE"});let d=await u(`/repos/${t}/${r}/issues/${n}`);return JSON.stringify({ok:!0,number:d.number,labels:(d.labels||[]).map(l=>typeof l=="string"?l:l.name)})}let m=await u(`/repos/${t}/${r}/issues/${n}/labels`,{method:"POST",body:{labels:o}});return JSON.stringify({ok:!0,number:n,labels:(Array.isArray(m)?m:[]).map(d=>typeof d=="string"?d:d.name)})}default:return JSON.stringify({error:`Unknown tool: ${c}`})}}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{u as ghFetch,Ee as githubSkill};
|
package/dist/gitlab.js
CHANGED
|
@@ -30,4 +30,4 @@ You have access to the user's GitLab projects via the REST API (cloud gitlab.com
|
|
|
30
30
|
|
|
31
31
|
### Notes
|
|
32
32
|
- A code-review flow is: gitlab_get_mr (context + diff_refs) \u2192 gitlab_get_mr_changes (the diff) \u2192 gitlab_post_mr_discussion per inline finding \u2192 gitlab_post_mr_note for the summary.
|
|
33
|
-
- If an inline position is rejected by GitLab (bad line anchor), fall back to gitlab_post_mr_note with the file/line in the text.`,resolve(){let s=se();if(!s)return{command:null,args:[],env:{},description:this.description};let r={};for(let t of this.envKeys)process.env[t]&&(r[t]=process.env[t]);return{type:"stdio",command:"node",args:[s,"../dist/gitlab.js","gitlabSkill"],env:r,description:this.description,alwaysLoad:!0}},async handleToolCall(s,r){try{let t=T(),n=D(),e=null;if(n){let o=le(r);if(o){let{path:i,instance:d}=await pe(o,t);if(!K(n,i)||t&&!d)return JSON.stringify({error:`Repository "${i||o}" is not available to this project. This project's agents may only use: ${[...n].join(", ")}. An owner changes this in Project Settings \u2192 Repository access.`,allowedRepos:[...n]});e=d}}return e?await R.run(e,()=>J(s,r)):await J(s,r)}catch(t){return JSON.stringify({error:t.message})}},tools:[{name:"gitlab_list_projects",description:"List the GitLab projects this token can access (the projects you are a member of), optionally filtered by a search query. Use this to discover a RELATED project worth cloning when a change's correctness depends on another accessible repo. Returns a normalized list of { fullPath, name, webUrl, defaultBranch, visibility } and a truncated flag.",input_schema:{type:"object",properties:{query:{type:"string",description:"Optional search term matched against project name/path"},limit:{type:"number",description:"Max projects (default 50, hard max 200)"}}}},{name:"gitlab_clone",description:"Clone a GitLab repository locally (shallow) so you can read code OUTSIDE the MR diff \u2014 callers of a changed symbol, shared types/contracts, an existing util, or a cross-repo dependency. Auto-authenticates with the connected GitLab token. After cloning, use Grep/Glob/Read on the returned path. Clone SPARINGLY \u2014 only when the change's correctness depends on code beyond the diff.",input_schema:{type:"object",properties:{projectPath:{type:"string",description:'Full project path, e.g. "group/subgroup/repo" (preferred).'},projectId:{type:"string",description:"Alternatively a numeric project id (resolved to its path via the API)."},branch:{type:"string",description:"Branch to clone (default: the repo default branch)."},destination:{type:"string",description:"Destination dir (default: <workspace>/.zibby/repos/<repo>)."}}}},{name:"gitlab_create_mr",description:"Open a merge request on GitLab (POST /projects/{id}/merge_requests). The source_branch must already be pushed. Returns the REAL pr_url (the MR web_url) from GitLab \u2014 never fabricate it. Expected business outcomes (no changes between branches, an MR already exists, source==target) return { success:false, skippedReason } rather than erroring.",input_schema:{type:"object",properties:{project:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},source_branch:{type:"string",description:"Source branch to merge FROM (must already be pushed)"},target_branch:{type:"string",description:"Target branch to merge INTO (default: the project's default branch)"},title:{type:"string",description:"MR title"},description:{type:"string",description:"MR description (markdown)"}},required:["project","source_branch","title"]}},{name:"gitlab_accept_mr",description:"Accept (merge) a merge request on GitLab (PUT /projects/{id}/merge_requests/{iid}/merge). Optional squash, mergeCommitMessage, mergeWhenPipelineSucceeds. Returns { success:true, merged:true, sha } with the REAL merge_commit_sha from GitLab. Expected non-mergeable outcomes (405/406 = not mergeable / WIP / conflicts / pipeline not done, 404 = not found) return { success:false, skippedReason } rather than erroring.",input_schema:{type:"object",properties:{project:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},iid:{type:"number",description:"Merge request iid (the per-project MR number in the URL)"},squash:{type:"boolean",description:"Squash the MR commits into one on merge (optional)"},mergeCommitMessage:{type:"string",description:"Custom merge commit message (optional)"},mergeWhenPipelineSucceeds:{type:"boolean",description:"Merge automatically once the pipeline succeeds (optional)"}},required:["project","iid"]}},{name:"gitlab_get_mr",description:"Get a GitLab merge request \u2014 title, description, branches, state, author, web url, and diff_refs (needed to anchor inline review comments).",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},iid:{type:"number",description:"Merge request iid (the per-project MR number in the URL)"}},required:["projectId","iid"]}},{name:"gitlab_get_mr_changes",description:"Get the changed files of a GitLab merge request with per-file diffs \u2014 the actual code changes to review. Also returns diff_refs for inline comments.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},iid:{type:"number",description:"Merge request iid"}},required:["projectId","iid"]}},{name:"gitlab_list_commits",description:"List a project's repository commits (the commit HISTORY \u2014 not MRs), optionally bounded by since/until ISO dates and a ref/branch, with per-commit stats (additions/deletions). Paginated: keep calling with page+1 while hasMore is true. This is the ONLY correct way to enumerate commits in a date window \u2014 gitlab_clone is shallow (depth 1) and its git log shows just one commit.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},since:{type:"string",description:'Only commits after this ISO-8601 date/time (inclusive), e.g. "2026-01-01T00:00:00Z"'},until:{type:"string",description:'Only commits before this ISO-8601 date/time, e.g. "2026-07-01T00:00:00Z"'},refName:{type:"string",description:"Branch/tag to list (defaults to the default branch)"},page:{type:"number",description:"Page number, 1-based (default 1)"},perPage:{type:"number",description:"Commits per page, max 100 (default 50)"},withStats:{type:"boolean",description:"Include per-commit additions/deletions stats (default true)"}},required:["projectId"]}},{name:"gitlab_get_commit",description:"Get ONE commit's full detail \u2014 message, author, timestamps, stats, and (by default) its per-file diffs (each capped at 3000 chars) \u2014 so you can judge the nature/complexity of the change. Use after gitlab_list_commits.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},sha:{type:"string",description:"The commit sha (full or short)"},includeDiff:{type:"boolean",description:"Include per-file diffs (default true; set false for metadata-only)"},includeMrs:{type:"boolean",description:"Also return the merge request(s) containing this commit ({iid,title,state,webUrl}) \u2014 the evidence link for contribution records (default false)"}},required:["projectId","sha"]}},{name:"gitlab_list_mrs",description:"List a GitLab project's merge requests, filtered by state and other criteria. Returns newest-updated first.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},state:{type:"string",enum:["opened","closed","merged","locked","all"],description:"Filter by state (default: opened)"},targetBranch:{type:"string",description:"Filter by target branch"},sourceBranch:{type:"string",description:"Filter by source branch"},authorUsername:{type:"string",description:"Filter by author username"},labels:{type:"array",items:{type:"string"},description:"Only MRs carrying ALL of these labels"},search:{type:"string",description:"Search title and description"},orderBy:{type:"string",enum:["created_at","updated_at","title"],description:"Sort field (default: updated_at)"},sort:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max MRs (default: 20)"}},required:["projectId"]}},{name:"gitlab_list_mr_notes",description:"List the discussion notes on a GitLab merge request (chronological).",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},limit:{type:"number",description:"Max notes (default 50)"}},required:["projectId","iid"]}},{name:"gitlab_post_mr_note",description:"Post a general (non-inline) comment on a GitLab merge request. Use for a review summary or a top-level remark.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},body:{type:"string",description:"Comment body (markdown)"}},required:["projectId","iid","body"]}},{name:"gitlab_post_mr_discussion",description:"Post an INLINE review comment anchored to a file + line in a GitLab merge request diff. Provide newLine (added/changed line) or oldLine (removed/context line). Pass diffRefs from gitlab_get_mr/gitlab_get_mr_changes, or omit to have the tool fetch them. If the line anchor is rejected, fall back to gitlab_post_mr_note.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},path:{type:"string",description:"New file path as it appears in the diff"},oldPath:{type:"string",description:"Old file path (defaults to path)"},newLine:{type:"number",description:"Line number in the NEW version of the file (for added/changed lines)"},oldLine:{type:"number",description:"Line number in the OLD version (for removed/context lines)"},body:{type:"string",description:"The inline comment text (markdown)"},diffRefs:{type:"object",description:"The MR diff_refs ({ base_sha, start_sha, head_sha }) from gitlab_get_mr. Omit and the tool fetches them."}},required:["projectId","iid","path","body"]}},{name:"gitlab_create_mr_review",description:"Post a full review on a GitLab merge request in one call: a summary note plus optional inline comments anchored to file/line in the diff. Convenience wrapper over gitlab_post_mr_note + gitlab_post_mr_discussion.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},body:{type:"string",description:"The review summary (markdown). Posted as a top-level MR note."},diffRefs:{type:"object",description:"The MR diff_refs ({ base_sha, start_sha, head_sha }) from gitlab_get_mr \u2014 required to anchor inline comments. Omit and the tool fetches them."},comments:{type:"array",description:"Optional inline comments, each anchored to a changed line in a file.",items:{type:"object",properties:{path:{type:"string",description:"New file path as it appears in the diff"},oldPath:{type:"string",description:"Old file path (defaults to path)"},newLine:{type:"number",description:"Line number in the NEW version of the file (for added/changed lines)"},oldLine:{type:"number",description:"Line number in the OLD version (for removed/context lines)"},body:{type:"string",description:"The inline comment text (markdown)"}},required:["path","body"]}}},required:["projectId","iid"]}},{name:"gitlab_get_discussion",description:"Read a single GitLab merge-request DISCUSSION (thread) by its discussion id: all notes in order plus the diff position (file + line) it is anchored to. Use this to understand a human's reply to a previous review discussion before replying in-thread.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},discussionId:{type:"string",description:"The discussion id (from the Note Hook payload or gitlab_list_mr_notes)"}},required:["projectId","iid","discussionId"]}},{name:"gitlab_reply_discussion",description:"Reply IN-THREAD to an existing GitLab merge-request discussion (a conversational reply appended to the SAME thread \u2014 NOT a fresh review). Use after gitlab_get_discussion to answer a human's reply to a review comment.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},discussionId:{type:"string",description:"The discussion id to reply to"},body:{type:"string",description:"The reply text (markdown)"}},required:["projectId","iid","discussionId","body"]}},{name:"gitlab_list_issues",description:"List a GitLab project's issues, filtered by state, labels, and an updatedAfter polling cursor. Returns newest-updated first.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},state:{type:"string",enum:["opened","closed","all"],description:"Filter by state (default: opened)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},assigneeUsername:{type:"string",description:"Filter by assignee username"},authorUsername:{type:"string",description:"Filter by author username"},updatedAfter:{type:"string",description:"ISO-8601 timestamp; only issues updated after this (polling cursor)"},search:{type:"string",description:"Search title and description"},orderBy:{type:"string",enum:["created_at","updated_at"],description:"Sort field (default: updated_at)"},sort:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30)"}},required:["projectId"]}},{name:"gitlab_get_issue",description:"Get a single GitLab issue with full detail (title, description, state, labels, assignees, web url).",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Issue iid (the per-project issue number in the URL)"}},required:["projectId","iid"]}},{name:"gitlab_add_issue_comment",description:"Add a comment to a GitLab issue. Also the way to record an MR link on a ticket (post a markdown link).",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Issue iid"},body:{type:"string",description:"Comment body (markdown)"}},required:["projectId","iid","body"]}}]};export{qe as gitlabSkill,m as glFetch};
|
|
33
|
+
- If an inline position is rejected by GitLab (bad line anchor), fall back to gitlab_post_mr_note with the file/line in the text.`,resolve(){let s=se();if(!s)return{command:null,args:[],env:{},description:this.description};let r={};for(let t of this.envKeys)process.env[t]&&(r[t]=process.env[t]);return{type:"stdio",command:"node",args:[s,"../dist/gitlab.js","gitlabSkill"],env:r,description:this.description}},async handleToolCall(s,r){try{let t=T(),n=D(),e=null;if(n){let o=le(r);if(o){let{path:i,instance:d}=await pe(o,t);if(!K(n,i)||t&&!d)return JSON.stringify({error:`Repository "${i||o}" is not available to this project. This project's agents may only use: ${[...n].join(", ")}. An owner changes this in Project Settings \u2192 Repository access.`,allowedRepos:[...n]});e=d}}return e?await R.run(e,()=>J(s,r)):await J(s,r)}catch(t){return JSON.stringify({error:t.message})}},tools:[{name:"gitlab_list_projects",description:"List the GitLab projects this token can access (the projects you are a member of), optionally filtered by a search query. Use this to discover a RELATED project worth cloning when a change's correctness depends on another accessible repo. Returns a normalized list of { fullPath, name, webUrl, defaultBranch, visibility } and a truncated flag.",input_schema:{type:"object",properties:{query:{type:"string",description:"Optional search term matched against project name/path"},limit:{type:"number",description:"Max projects (default 50, hard max 200)"}}}},{name:"gitlab_clone",description:"Clone a GitLab repository locally (shallow) so you can read code OUTSIDE the MR diff \u2014 callers of a changed symbol, shared types/contracts, an existing util, or a cross-repo dependency. Auto-authenticates with the connected GitLab token. After cloning, use Grep/Glob/Read on the returned path. Clone SPARINGLY \u2014 only when the change's correctness depends on code beyond the diff.",input_schema:{type:"object",properties:{projectPath:{type:"string",description:'Full project path, e.g. "group/subgroup/repo" (preferred).'},projectId:{type:"string",description:"Alternatively a numeric project id (resolved to its path via the API)."},branch:{type:"string",description:"Branch to clone (default: the repo default branch)."},destination:{type:"string",description:"Destination dir (default: <workspace>/.zibby/repos/<repo>)."}}}},{name:"gitlab_create_mr",description:"Open a merge request on GitLab (POST /projects/{id}/merge_requests). The source_branch must already be pushed. Returns the REAL pr_url (the MR web_url) from GitLab \u2014 never fabricate it. Expected business outcomes (no changes between branches, an MR already exists, source==target) return { success:false, skippedReason } rather than erroring.",input_schema:{type:"object",properties:{project:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},source_branch:{type:"string",description:"Source branch to merge FROM (must already be pushed)"},target_branch:{type:"string",description:"Target branch to merge INTO (default: the project's default branch)"},title:{type:"string",description:"MR title"},description:{type:"string",description:"MR description (markdown)"}},required:["project","source_branch","title"]}},{name:"gitlab_accept_mr",description:"Accept (merge) a merge request on GitLab (PUT /projects/{id}/merge_requests/{iid}/merge). Optional squash, mergeCommitMessage, mergeWhenPipelineSucceeds. Returns { success:true, merged:true, sha } with the REAL merge_commit_sha from GitLab. Expected non-mergeable outcomes (405/406 = not mergeable / WIP / conflicts / pipeline not done, 404 = not found) return { success:false, skippedReason } rather than erroring.",input_schema:{type:"object",properties:{project:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},iid:{type:"number",description:"Merge request iid (the per-project MR number in the URL)"},squash:{type:"boolean",description:"Squash the MR commits into one on merge (optional)"},mergeCommitMessage:{type:"string",description:"Custom merge commit message (optional)"},mergeWhenPipelineSucceeds:{type:"boolean",description:"Merge automatically once the pipeline succeeds (optional)"}},required:["project","iid"]}},{name:"gitlab_get_mr",description:"Get a GitLab merge request \u2014 title, description, branches, state, author, web url, and diff_refs (needed to anchor inline review comments).",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},iid:{type:"number",description:"Merge request iid (the per-project MR number in the URL)"}},required:["projectId","iid"]}},{name:"gitlab_get_mr_changes",description:"Get the changed files of a GitLab merge request with per-file diffs \u2014 the actual code changes to review. Also returns diff_refs for inline comments.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},iid:{type:"number",description:"Merge request iid"}},required:["projectId","iid"]}},{name:"gitlab_list_commits",description:"List a project's repository commits (the commit HISTORY \u2014 not MRs), optionally bounded by since/until ISO dates and a ref/branch, with per-commit stats (additions/deletions). Paginated: keep calling with page+1 while hasMore is true. This is the ONLY correct way to enumerate commits in a date window \u2014 gitlab_clone is shallow (depth 1) and its git log shows just one commit.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},since:{type:"string",description:'Only commits after this ISO-8601 date/time (inclusive), e.g. "2026-01-01T00:00:00Z"'},until:{type:"string",description:'Only commits before this ISO-8601 date/time, e.g. "2026-07-01T00:00:00Z"'},refName:{type:"string",description:"Branch/tag to list (defaults to the default branch)"},page:{type:"number",description:"Page number, 1-based (default 1)"},perPage:{type:"number",description:"Commits per page, max 100 (default 50)"},withStats:{type:"boolean",description:"Include per-commit additions/deletions stats (default true)"}},required:["projectId"]}},{name:"gitlab_get_commit",description:"Get ONE commit's full detail \u2014 message, author, timestamps, stats, and (by default) its per-file diffs (each capped at 3000 chars) \u2014 so you can judge the nature/complexity of the change. Use after gitlab_list_commits.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},sha:{type:"string",description:"The commit sha (full or short)"},includeDiff:{type:"boolean",description:"Include per-file diffs (default true; set false for metadata-only)"},includeMrs:{type:"boolean",description:"Also return the merge request(s) containing this commit ({iid,title,state,webUrl}) \u2014 the evidence link for contribution records (default false)"}},required:["projectId","sha"]}},{name:"gitlab_list_mrs",description:"List a GitLab project's merge requests, filtered by state and other criteria. Returns newest-updated first.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},state:{type:"string",enum:["opened","closed","merged","locked","all"],description:"Filter by state (default: opened)"},targetBranch:{type:"string",description:"Filter by target branch"},sourceBranch:{type:"string",description:"Filter by source branch"},authorUsername:{type:"string",description:"Filter by author username"},labels:{type:"array",items:{type:"string"},description:"Only MRs carrying ALL of these labels"},search:{type:"string",description:"Search title and description"},orderBy:{type:"string",enum:["created_at","updated_at","title"],description:"Sort field (default: updated_at)"},sort:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max MRs (default: 20)"}},required:["projectId"]}},{name:"gitlab_list_mr_notes",description:"List the discussion notes on a GitLab merge request (chronological).",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},limit:{type:"number",description:"Max notes (default 50)"}},required:["projectId","iid"]}},{name:"gitlab_post_mr_note",description:"Post a general (non-inline) comment on a GitLab merge request. Use for a review summary or a top-level remark.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},body:{type:"string",description:"Comment body (markdown)"}},required:["projectId","iid","body"]}},{name:"gitlab_post_mr_discussion",description:"Post an INLINE review comment anchored to a file + line in a GitLab merge request diff. Provide newLine (added/changed line) or oldLine (removed/context line). Pass diffRefs from gitlab_get_mr/gitlab_get_mr_changes, or omit to have the tool fetch them. If the line anchor is rejected, fall back to gitlab_post_mr_note.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},path:{type:"string",description:"New file path as it appears in the diff"},oldPath:{type:"string",description:"Old file path (defaults to path)"},newLine:{type:"number",description:"Line number in the NEW version of the file (for added/changed lines)"},oldLine:{type:"number",description:"Line number in the OLD version (for removed/context lines)"},body:{type:"string",description:"The inline comment text (markdown)"},diffRefs:{type:"object",description:"The MR diff_refs ({ base_sha, start_sha, head_sha }) from gitlab_get_mr. Omit and the tool fetches them."}},required:["projectId","iid","path","body"]}},{name:"gitlab_create_mr_review",description:"Post a full review on a GitLab merge request in one call: a summary note plus optional inline comments anchored to file/line in the diff. Convenience wrapper over gitlab_post_mr_note + gitlab_post_mr_discussion.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},body:{type:"string",description:"The review summary (markdown). Posted as a top-level MR note."},diffRefs:{type:"object",description:"The MR diff_refs ({ base_sha, start_sha, head_sha }) from gitlab_get_mr \u2014 required to anchor inline comments. Omit and the tool fetches them."},comments:{type:"array",description:"Optional inline comments, each anchored to a changed line in a file.",items:{type:"object",properties:{path:{type:"string",description:"New file path as it appears in the diff"},oldPath:{type:"string",description:"Old file path (defaults to path)"},newLine:{type:"number",description:"Line number in the NEW version of the file (for added/changed lines)"},oldLine:{type:"number",description:"Line number in the OLD version (for removed/context lines)"},body:{type:"string",description:"The inline comment text (markdown)"}},required:["path","body"]}}},required:["projectId","iid"]}},{name:"gitlab_get_discussion",description:"Read a single GitLab merge-request DISCUSSION (thread) by its discussion id: all notes in order plus the diff position (file + line) it is anchored to. Use this to understand a human's reply to a previous review discussion before replying in-thread.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},discussionId:{type:"string",description:"The discussion id (from the Note Hook payload or gitlab_list_mr_notes)"}},required:["projectId","iid","discussionId"]}},{name:"gitlab_reply_discussion",description:"Reply IN-THREAD to an existing GitLab merge-request discussion (a conversational reply appended to the SAME thread \u2014 NOT a fresh review). Use after gitlab_get_discussion to answer a human's reply to a review comment.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},discussionId:{type:"string",description:"The discussion id to reply to"},body:{type:"string",description:"The reply text (markdown)"}},required:["projectId","iid","discussionId","body"]}},{name:"gitlab_list_issues",description:"List a GitLab project's issues, filtered by state, labels, and an updatedAfter polling cursor. Returns newest-updated first.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},state:{type:"string",enum:["opened","closed","all"],description:"Filter by state (default: opened)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},assigneeUsername:{type:"string",description:"Filter by assignee username"},authorUsername:{type:"string",description:"Filter by author username"},updatedAfter:{type:"string",description:"ISO-8601 timestamp; only issues updated after this (polling cursor)"},search:{type:"string",description:"Search title and description"},orderBy:{type:"string",enum:["created_at","updated_at"],description:"Sort field (default: updated_at)"},sort:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30)"}},required:["projectId"]}},{name:"gitlab_get_issue",description:"Get a single GitLab issue with full detail (title, description, state, labels, assignees, web url).",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Issue iid (the per-project issue number in the URL)"}},required:["projectId","iid"]}},{name:"gitlab_add_issue_comment",description:"Add a comment to a GitLab issue. Also the way to record an MR link on a ticket (post a markdown link).",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Issue iid"},body:{type:"string",description:"Comment body (markdown)"}},required:["projectId","iid","body"]}}]};export{qe as gitlabSkill,m as glFetch};
|
package/dist/googleDocs.js
CHANGED
|
@@ -18,5 +18,5 @@ Docs access is PER-USER: each teammate connects their OWN Google account (Integr
|
|
|
18
18
|
- gdocs_insert_image: append a LOCAL image file (png/jpg, \u22645MB) to the end of a doc \u2014 pass { documentId, imagePath, width?, height? } (width/height in PT, optional). The image is uploaded to the user's Drive and made link-readable (anyone with the link) so Docs can render it. Returns { ok, documentId, fileId, url }.
|
|
19
19
|
- gdocs_get: read a doc back as plain text (works for app-created/user-picked docs only; to read an arbitrary pre-existing doc the user must PICK it once first via the Google Picker \u2014 drive.file has no access to un-picked files).
|
|
20
20
|
- gdocs_list_created: list the Google Docs visible to this app (drive.file \u2192 only docs it created or the user picked).
|
|
21
|
-
These tools return { ok:false, error } on failure \u2014 treat an unavailable Google connection as "cannot deliver to Docs" and report it rather than blocking the task.`,resolve(){let n=Y();if(!n)return null;let e={};for(let t of["PROJECT_API_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV","ZIBBY_INJECTED_GOOGLE_TOKEN","ZIBBY_INJECTED_GOOGLE_EMAIL","ZIBBY_SENDER_IS_NON_OWNER","ZIBBY_CHAT_STRICT_PERSONAL"])process.env[t]&&(e[t]=process.env[t]);return{type:"stdio",command:"node",args:[n,"../dist/googleDocs.js","googleDocsSkill"],env:e,description:this.description
|
|
21
|
+
These tools return { ok:false, error } on failure \u2014 treat an unavailable Google connection as "cannot deliver to Docs" and report it rather than blocking the task.`,resolve(){let n=Y();if(!n)return null;let e={};for(let t of["PROJECT_API_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV","ZIBBY_INJECTED_GOOGLE_TOKEN","ZIBBY_INJECTED_GOOGLE_EMAIL","ZIBBY_SENDER_IS_NON_OWNER","ZIBBY_CHAT_STRICT_PERSONAL"])process.env[t]&&(e[t]=process.env[t]);return{type:"stdio",command:"node",args:[n,"../dist/googleDocs.js","googleDocsSkill"],env:e,description:this.description}},async handleToolCall(n,e){try{switch(n){case"gdocs_create_doc":{let t=typeof e?.title=="string"&&e.title.trim()?e.title.trim():null;if(!t)return JSON.stringify({ok:!1,error:"title is required"});let r=(await p(`${h}/documents`,{method:"POST",body:{title:t}}))?.documentId;if(!r)return JSON.stringify({ok:!1,error:"Google Docs create returned no documentId"});let i=L(e);if(i&&i.trim()){let{requests:a}=N(i,1);a.length&&await p(`${h}/documents/${r}:batchUpdate`,{method:"POST",body:{requests:a}})}return JSON.stringify({ok:!0,documentId:r,title:t,url:y(r)})}case"gdocs_append":{let t=T(e?.documentId||e?.url||e?.id);if(!t)return JSON.stringify({ok:!1,error:"A valid Google Docs documentId or URL is required"});let o=L(e);if(!o||!o.trim())return JSON.stringify({ok:!1,error:"markdown or text content is required"});let i=(await p(`${h}/documents/${t}`))?.body,a=Array.isArray(i?.content)?i.content:[],l=a.length&&a[a.length-1].endIndex||2,c=Math.max(1,l-1),d=[],s=c;c>1&&(d.push({insertText:{location:{index:c},text:`
|
|
22
22
|
`}}),s=c+1);let u=N(o,s);return d.push(...u.requests),await p(`${h}/documents/${t}:batchUpdate`,{method:"POST",body:{requests:d}}),JSON.stringify({ok:!0,documentId:t,url:y(t)})}case"gdocs_insert_image":{let t=T(e?.documentId||e?.url||e?.id);if(!t)return JSON.stringify({ok:!1,error:"A valid Google Docs documentId or URL is required"});if(!e?.imagePath||typeof e.imagePath!="string"||!e.imagePath.trim())return JSON.stringify({ok:!1,error:"imagePath is required"});let{bytes:o,fileName:r,mimeType:i}=oe(e.imagePath),{rawBody:a,contentType:l}=re({name:r,mimeType:i},o,i),d=(await p(`${H}/files?uploadType=multipart&fields=id`,{method:"POST",rawBody:a,contentType:l}))?.id;if(!d)return JSON.stringify({ok:!1,error:"Drive upload returned no file id"});await p(`${x}/files/${d}/permissions`,{method:"POST",body:{role:"reader",type:"anyone"}});let s=await p(`${h}/documents/${t}`),u=Array.isArray(s?.body?.content)?s.body.content:[],_=u.length&&u[u.length-1].endIndex||2,f={location:{index:Math.max(1,_-1)},uri:`https://drive.google.com/uc?export=download&id=${d}`},g=Number(e?.width),m=Number(e?.height);return(Number.isFinite(g)&&g>0||Number.isFinite(m)&&m>0)&&(f.objectSize={...Number.isFinite(g)&&g>0?{width:{magnitude:g,unit:"PT"}}:{},...Number.isFinite(m)&&m>0?{height:{magnitude:m,unit:"PT"}}:{}}),await p(`${h}/documents/${t}:batchUpdate`,{method:"POST",body:{requests:[{insertInlineImage:f}]}}),JSON.stringify({ok:!0,documentId:t,fileId:d,url:y(t)})}case"gdocs_get":{let t=T(e?.documentId||e?.url||e?.id);if(!t)return JSON.stringify({ok:!1,error:"A valid Google Docs documentId or URL is required"});let o=await p(`${h}/documents/${t}`),r=ne(o?.body);return JSON.stringify({ok:!0,documentId:t,title:o?.title||"",url:y(t),text:r,...r.length>=w?{truncated:!0}:{}})}case"gdocs_list_created":{let t=new URLSearchParams({q:"'me' in owners and mimeType='application/vnd.google-apps.document' and trashed=false",fields:"files(id,name,modifiedTime,webViewLink)",pageSize:String(Q),orderBy:"modifiedTime desc"}),o=await p(`${x}/files?${t.toString()}`),r=(Array.isArray(o?.files)?o.files:[]).map(i=>({documentId:i.id,title:i.name,modifiedTime:i.modifiedTime,url:i.webViewLink||y(i.id)}));return JSON.stringify({ok:!0,count:r.length,files:r})}default:return JSON.stringify({ok:!1,error:`Unknown tool: ${n}`})}}catch(t){return JSON.stringify({ok:!1,error:t.message})}},tools:[{name:"gdocs_create_doc",description:"Create a new Google Doc with a title and optional content (markdown: #/##/### headings, - bullets, 1. numbered lists, **bold**, [links](url), `code`; or plain text). Returns { ok, documentId, url } \u2014 share the url with the user.",input_schema:{type:"object",properties:{title:{type:"string",description:"Document title."},markdown:{type:"string",description:"Document body as markdown (preferred)."},text:{type:"string",description:"Document body as plain text (used when markdown is absent)."}},required:["title"]}},{name:"gdocs_append",description:"Append markdown/text content to the END of an existing Google Doc. Only works on docs this app created or the user explicitly picked (drive.file scope). Accepts a documentId or a full docs.google.com URL. Returns { ok, documentId, url }.",input_schema:{type:"object",properties:{documentId:{type:"string",description:"Google Docs documentId OR a full https://docs.google.com/document/d/... URL."},markdown:{type:"string",description:"Content to append, as markdown (preferred)."},text:{type:"string",description:"Content to append, as plain text (used when markdown is absent)."}},required:["documentId"]}},{name:"gdocs_insert_image",description:"Append a LOCAL image file (png/jpg, max 5MB) to the END of an existing Google Doc. The image is uploaded to the user's Drive, made link-readable (role reader / type anyone \u2014 required: the Docs API only renders publicly fetchable image URIs, <2KB URI length, image <50MB and <25 megapixels), then inserted inline. Optional width/height in points (PT). Returns { ok, documentId, fileId, url }.",input_schema:{type:"object",properties:{documentId:{type:"string",description:"Google Docs documentId OR a full https://docs.google.com/document/d/... URL."},imagePath:{type:"string",description:"Local filesystem path to a .png or .jpg/.jpeg image (max 5MB)."},width:{type:"number",description:"Optional display width in points (PT)."},height:{type:"number",description:"Optional display height in points (PT)."}},required:["documentId","imagePath"]}},{name:"gdocs_get",description:"Read a Google Doc back as plain text (truncated to ~20k chars). The drive.file scope grants access ONLY to docs this app created or the user explicitly picked; to read an arbitrary pre-existing doc the user must PICK it once first via the Google Picker (drive.file cannot see un-picked files). Returns { ok, documentId, title, url, text }.",input_schema:{type:"object",properties:{documentId:{type:"string",description:"Google Docs documentId OR a full https://docs.google.com/document/d/... URL."}},required:["documentId"]}},{name:"gdocs_list_created",description:"List the Google Docs visible to this integration, newest first (max 25). NOTE: under the drive.file scope this lists ONLY docs the app created or the user explicitly picked \u2014 it is NOT a full Drive search. Returns { ok, count, files:[{ documentId, title, modifiedTime, url }] }.",input_schema:{type:"object",properties:{}}}]};export{X as NON_OWNER_REFUSAL,W as chatStrictPersonal,ne as extractPlainText,p as googleApi,me as googleDocsSkill,z as injectedGoogleToken,N as markdownToRequests,T as parseDocId,te as parseInlineMarkdown,V as senderIsNonOwner};
|
package/dist/hubspot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as O}from"fs";import{fileURLToPath as j}from"url";import{dirname as N,resolve as k}from"path";import{resolveIntegrationToken as v}from"@zibby/core/backend-client.js";var m=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"}),E=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 Chat",connectPath:"/integrations?provider=lark"},lark_docs:{id:"lark_docs",name:"Lark App",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"}});var b={api:{knob:"SKILL_API_TIMEOUT_MS",fallback:3e4},transfer:{knob:"SKILL_TRANSFER_TIMEOUT_MS",fallback:12e4},job:{knob:"SKILL_JOB_TIMEOUT_MS",fallback:3e5}};function g(o,i,e=process.env){let t=Number(e?.[o]);return Number.isFinite(t)&&t>0?Math.min(6e5,Math.max(1e3,Math.floor(t))):i}function _(o="api",i=process.env){let e=b[o]||b.api;return g(e.knob,e.fallback,i)}function T(o){return o?.name==="TimeoutError"||o?.name==="AbortError"}function I(o){try{return new URL(String(o?.url??o)).host||"unknown host"}catch{return"unknown host"}}function S(o,i){if(!o)return i;let e=new AbortController,t=s=>{e.signal.aborted||e.abort(s)},n=()=>t(o.reason),r=()=>t(i.reason);return e.signal.addEventListener("abort",()=>{o.removeEventListener("abort",n),i.removeEventListener("abort",r)},{once:!0}),o.aborted?t(o.reason):i.aborted?t(i.reason):(o.addEventListener("abort",n,{once:!0}),i.addEventListener("abort",r,{once:!0})),e.signal}async function y(o,i={},e={}){let t=e.kind||"api",n=(b[t]||b.api).knob,r=e.timeoutMs?Math.min(6e5,Math.max(1e3,Math.floor(e.timeoutMs))):_(t),s=i?.signal;if(s?.aborted)throw s.reason??new DOMException("This operation was aborted","AbortError");let a=AbortSignal.timeout(r),p=S(s,a);try{return await fetch(o,{...i,signal:p})}catch(u){throw a.aborted&&T(u)?new Error(`${e.what||"request"} TIMED OUT after ${r}ms against ${I(o)} (${n})`):u}}function R(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let o=N(j(import.meta.url)),i=k(o,"..","bin","mcp-skill.mjs");return O(i)?i:null}async function c(o,i={}){let{token:e}=await v("hubspot");if(!e)throw new Error("HubSpot not connected \u2014 Connect HubSpot in Integrations.");let t=o.startsWith("https://")?o:`https://api.hubapi.com${o}`,n={Authorization:`Bearer ${e}`,Accept:"application/json",...i.body?{"Content-Type":"application/json"}:{}},r=await y(t,{method:i.method||"GET",headers:n,body:i.body?JSON.stringify(i.body):void 0},{kind:"api",what:`HubSpot ${i.method||"GET"} ${o}`});if(!r.ok){let a=await r.text().catch(()=>""),p=r.status===401||r.status===403?" \u2014 token invalid/expired or missing the required Private App scope for this object":"";throw new Error(`HubSpot API ${r.status}${p}: ${a.slice(0,300)}`)}let s=await r.text().catch(()=>"");if(!s)return{};try{return JSON.parse(s)}catch{return{raw:s}}}function d(o){return typeof o!="string"?null:o.trim()||null}function h(o,i={}){let e=new URLSearchParams;if(o!=null){let n=Array.isArray(o)?o.join(","):String(o);n&&e.set("properties",n)}for(let[n,r]of Object.entries(i))r!=null&&r!==""&&e.set(n,String(r));let t=e.toString();return t?`?${t}`:""}var l="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.",q={id:"hubspot",callsBackend:!0,serverName:"hubspot",allowedTools:["mcp__hubspot__*"],requiresIntegration:m.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 o=R();if(!o)return{command:null,args:[],env:{},description:this.description};let i={};for(let e of this.envKeys)process.env[e]&&(i[e]=process.env[e]);return{type:"stdio",command:"node",args:[o,"../dist/hubspot.js","hubspotSkill"],env:i,description:this.description,alwaysLoad:!0}},async handleToolCall(o,i){try{let e=i||{};switch(o){case"hubspot_whoami":{let t=await c("/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 r=((await c(`/crm/v3/properties/${encodeURIComponent(t)}`)).results||[]).map(s=>({name:s.name,label:s.label,type:s.type,fieldType:s.fieldType}));return JSON.stringify({objectType:t,count:r.length,properties:r})}case"hubspot_search":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});let r={limit:Number.isFinite(Number(e.limit))&&Number(e.limit)>0?Math.trunc(Number(e.limit)):20};e.query&&(r.query=String(e.query)),Array.isArray(e.filters)&&e.filters.length&&(r.filterGroups=[{filters:e.filters}]),e.properties!=null&&(r.properties=Array.isArray(e.properties)?e.properties:String(e.properties).split(",").map(a=>a.trim()).filter(Boolean));let s=await c(`/crm/v3/objects/${encodeURIComponent(t)}/search`,{method:"POST",body:r});return JSON.stringify({total:s.total??(s.results?s.results.length:0),results:(s.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 n=h(e.properties,{associations:e.associations}),r=await c(`/crm/v3/objects/${encodeURIComponent(t)}/${encodeURIComponent(e.id)}${n}`);return JSON.stringify({id:r.id,properties:r.properties,...r.associations?{associations:r.associations}:{}})}case"hubspot_list_objects":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});let n=Number.isFinite(Number(e.limit))&&Number(e.limit)>0?Math.trunc(Number(e.limit)):20,r=h(e.properties,{limit:n,after:e.after}),s=await c(`/crm/v3/objects/${encodeURIComponent(t)}${r}`);return JSON.stringify({results:(s.results||[]).map(a=>({id:a.id,properties:a.properties})),paging:s.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 n=await c(`/crm/v3/objects/${encodeURIComponent(t)}`,{method:"POST",body:{properties:e.properties}});return JSON.stringify({id:n.id,properties:n.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 n=await c(`/crm/v3/objects/${encodeURIComponent(t)}/${encodeURIComponent(e.id)}`,{method:"PATCH",body:{properties:e.properties}});return JSON.stringify({id:n.id,properties:n.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 n=await c("/crm/v3/objects/notes",{method:"POST",body:{properties:{hs_note_body:e.body,hs_timestamp:t}}}),r=n.id,s=[["contacts",e.contactId],["companies",e.companyId],["deals",e.dealId],["tickets",e.ticketId]].filter(([,p])=>p!=null&&p!==""),a=[];for(let[p,u]of s)try{await c(`/crm/v4/objects/notes/${encodeURIComponent(r)}/associations/default/${p}/${encodeURIComponent(u)}`,{method:"PUT"}),a.push({toType:p,toId:String(u)})}catch(f){a.push({toType:p,toId:String(u),error:f.message})}return JSON.stringify({id:r,properties:n.properties,associatedTo:a})}case"hubspot_associate":{let t=d(e.fromType),n=d(e.toType);return!t||!e.fromId||!n||!e.toId?JSON.stringify({error:"fromType, fromId, toType and toId are all required"}):(await c(`/crm/v4/objects/${encodeURIComponent(t)}/${encodeURIComponent(e.fromId)}/associations/default/${encodeURIComponent(n)}/${encodeURIComponent(e.toId)}`,{method:"PUT"}),JSON.stringify({ok:!0}))}default:return JSON.stringify({error:`Unknown tool: ${o}`})}}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:l}},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:l},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:l},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:l},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:l},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:l},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{q as hubspotSkill};
|
|
1
|
+
import{existsSync as O}from"fs";import{fileURLToPath as j}from"url";import{dirname as N,resolve as k}from"path";import{resolveIntegrationToken as v}from"@zibby/core/backend-client.js";var m=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"}),E=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 Chat",connectPath:"/integrations?provider=lark"},lark_docs:{id:"lark_docs",name:"Lark App",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"}});var b={api:{knob:"SKILL_API_TIMEOUT_MS",fallback:3e4},transfer:{knob:"SKILL_TRANSFER_TIMEOUT_MS",fallback:12e4},job:{knob:"SKILL_JOB_TIMEOUT_MS",fallback:3e5}};function g(o,i,e=process.env){let t=Number(e?.[o]);return Number.isFinite(t)&&t>0?Math.min(6e5,Math.max(1e3,Math.floor(t))):i}function _(o="api",i=process.env){let e=b[o]||b.api;return g(e.knob,e.fallback,i)}function T(o){return o?.name==="TimeoutError"||o?.name==="AbortError"}function I(o){try{return new URL(String(o?.url??o)).host||"unknown host"}catch{return"unknown host"}}function S(o,i){if(!o)return i;let e=new AbortController,t=s=>{e.signal.aborted||e.abort(s)},n=()=>t(o.reason),r=()=>t(i.reason);return e.signal.addEventListener("abort",()=>{o.removeEventListener("abort",n),i.removeEventListener("abort",r)},{once:!0}),o.aborted?t(o.reason):i.aborted?t(i.reason):(o.addEventListener("abort",n,{once:!0}),i.addEventListener("abort",r,{once:!0})),e.signal}async function y(o,i={},e={}){let t=e.kind||"api",n=(b[t]||b.api).knob,r=e.timeoutMs?Math.min(6e5,Math.max(1e3,Math.floor(e.timeoutMs))):_(t),s=i?.signal;if(s?.aborted)throw s.reason??new DOMException("This operation was aborted","AbortError");let a=AbortSignal.timeout(r),p=S(s,a);try{return await fetch(o,{...i,signal:p})}catch(u){throw a.aborted&&T(u)?new Error(`${e.what||"request"} TIMED OUT after ${r}ms against ${I(o)} (${n})`):u}}function R(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let o=N(j(import.meta.url)),i=k(o,"..","bin","mcp-skill.mjs");return O(i)?i:null}async function c(o,i={}){let{token:e}=await v("hubspot");if(!e)throw new Error("HubSpot not connected \u2014 Connect HubSpot in Integrations.");let t=o.startsWith("https://")?o:`https://api.hubapi.com${o}`,n={Authorization:`Bearer ${e}`,Accept:"application/json",...i.body?{"Content-Type":"application/json"}:{}},r=await y(t,{method:i.method||"GET",headers:n,body:i.body?JSON.stringify(i.body):void 0},{kind:"api",what:`HubSpot ${i.method||"GET"} ${o}`});if(!r.ok){let a=await r.text().catch(()=>""),p=r.status===401||r.status===403?" \u2014 token invalid/expired or missing the required Private App scope for this object":"";throw new Error(`HubSpot API ${r.status}${p}: ${a.slice(0,300)}`)}let s=await r.text().catch(()=>"");if(!s)return{};try{return JSON.parse(s)}catch{return{raw:s}}}function d(o){return typeof o!="string"?null:o.trim()||null}function h(o,i={}){let e=new URLSearchParams;if(o!=null){let n=Array.isArray(o)?o.join(","):String(o);n&&e.set("properties",n)}for(let[n,r]of Object.entries(i))r!=null&&r!==""&&e.set(n,String(r));let t=e.toString();return t?`?${t}`:""}var l="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.",q={id:"hubspot",callsBackend:!0,serverName:"hubspot",allowedTools:["mcp__hubspot__*"],requiresIntegration:m.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 o=R();if(!o)return{command:null,args:[],env:{},description:this.description};let i={};for(let e of this.envKeys)process.env[e]&&(i[e]=process.env[e]);return{type:"stdio",command:"node",args:[o,"../dist/hubspot.js","hubspotSkill"],env:i,description:this.description}},async handleToolCall(o,i){try{let e=i||{};switch(o){case"hubspot_whoami":{let t=await c("/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 r=((await c(`/crm/v3/properties/${encodeURIComponent(t)}`)).results||[]).map(s=>({name:s.name,label:s.label,type:s.type,fieldType:s.fieldType}));return JSON.stringify({objectType:t,count:r.length,properties:r})}case"hubspot_search":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});let r={limit:Number.isFinite(Number(e.limit))&&Number(e.limit)>0?Math.trunc(Number(e.limit)):20};e.query&&(r.query=String(e.query)),Array.isArray(e.filters)&&e.filters.length&&(r.filterGroups=[{filters:e.filters}]),e.properties!=null&&(r.properties=Array.isArray(e.properties)?e.properties:String(e.properties).split(",").map(a=>a.trim()).filter(Boolean));let s=await c(`/crm/v3/objects/${encodeURIComponent(t)}/search`,{method:"POST",body:r});return JSON.stringify({total:s.total??(s.results?s.results.length:0),results:(s.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 n=h(e.properties,{associations:e.associations}),r=await c(`/crm/v3/objects/${encodeURIComponent(t)}/${encodeURIComponent(e.id)}${n}`);return JSON.stringify({id:r.id,properties:r.properties,...r.associations?{associations:r.associations}:{}})}case"hubspot_list_objects":{let t=d(e.objectType);if(!t)return JSON.stringify({error:"objectType is required"});let n=Number.isFinite(Number(e.limit))&&Number(e.limit)>0?Math.trunc(Number(e.limit)):20,r=h(e.properties,{limit:n,after:e.after}),s=await c(`/crm/v3/objects/${encodeURIComponent(t)}${r}`);return JSON.stringify({results:(s.results||[]).map(a=>({id:a.id,properties:a.properties})),paging:s.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 n=await c(`/crm/v3/objects/${encodeURIComponent(t)}`,{method:"POST",body:{properties:e.properties}});return JSON.stringify({id:n.id,properties:n.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 n=await c(`/crm/v3/objects/${encodeURIComponent(t)}/${encodeURIComponent(e.id)}`,{method:"PATCH",body:{properties:e.properties}});return JSON.stringify({id:n.id,properties:n.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 n=await c("/crm/v3/objects/notes",{method:"POST",body:{properties:{hs_note_body:e.body,hs_timestamp:t}}}),r=n.id,s=[["contacts",e.contactId],["companies",e.companyId],["deals",e.dealId],["tickets",e.ticketId]].filter(([,p])=>p!=null&&p!==""),a=[];for(let[p,u]of s)try{await c(`/crm/v4/objects/notes/${encodeURIComponent(r)}/associations/default/${p}/${encodeURIComponent(u)}`,{method:"PUT"}),a.push({toType:p,toId:String(u)})}catch(f){a.push({toType:p,toId:String(u),error:f.message})}return JSON.stringify({id:r,properties:n.properties,associatedTo:a})}case"hubspot_associate":{let t=d(e.fromType),n=d(e.toType);return!t||!e.fromId||!n||!e.toId?JSON.stringify({error:"fromType, fromId, toType and toId are all required"}):(await c(`/crm/v4/objects/${encodeURIComponent(t)}/${encodeURIComponent(e.fromId)}/associations/default/${encodeURIComponent(n)}/${encodeURIComponent(e.toId)}`,{method:"PUT"}),JSON.stringify({ok:!0}))}default:return JSON.stringify({error:`Unknown tool: ${o}`})}}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:l}},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:l},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:l},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:l},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:l},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:l},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{q as hubspotSkill};
|