@zibby/skills 0.2.2 → 0.2.4
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/chat-notify.js +2 -2
- package/dist/chatProgress.js +2 -2
- package/dist/datasetStore.js +2 -2
- package/dist/discord.js +1 -1
- package/dist/figma.js +1 -1
- package/dist/git-write.js +9 -9
- package/dist/git.d.ts +23 -0
- package/dist/git.js +2 -2
- package/dist/github.js +5 -5
- package/dist/gitlab.js +3 -3
- package/dist/googleDocs.js +1 -1
- package/dist/index.js +95 -95
- package/dist/jira.js +1 -1
- package/dist/lark.js +1 -1
- package/dist/larkDocs.js +1 -1
- package/dist/linear.js +1 -1
- package/dist/linkedin.js +1 -1
- package/dist/notion.js +1 -1
- package/dist/package.json +2 -2
- package/dist/plane.js +1 -1
- package/dist/sentry.js +1 -1
- package/dist/slack.js +1 -1
- package/dist/trackers/github-adapter.js +5 -5
- package/dist/trackers/index.js +6 -6
- package/dist/trackers/jira-adapter.js +1 -1
- package/dist/trackers/linear-adapter.js +1 -1
- package/docs/self-host/backup-restore.md +4 -3
- package/docs/self-host/custom-sidecars.md +136 -0
- package/package.json +2 -2
package/dist/jira.js
CHANGED
|
@@ -16,7 +16,7 @@ ${"#".repeat(i)} ${r.trim()}
|
|
|
16
16
|
${r}
|
|
17
17
|
`):e.push(r)}return e.join("").replace(/\n{3,}/g,`
|
|
18
18
|
|
|
19
|
-
`)}function k(c){return String(c||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function N(c){return k(c).replace(/[a-z0-9]+/g,"")}function I(c,n){let e=k(c),t=k(n);if(!e||!t)return 0;if(e===t)return 1;if(e.length===1||t.length===1)return e===t?1:0;let r=p=>{let d=new Map;for(let m=0;m<p.length-1;m++){let g=p.slice(m,m+2);d.set(g,(d.get(g)||0)+1)}return d},i=r(e),o=r(t),s=0,a=0,u=0;for(let p of i.values())a+=p;for(let p of o.values())u+=p;for(let[p,d]of i.entries()){let m=o.get(p)||0;s+=Math.min(d,m)}return 2*s/Math.max(1,a+u)}function b(c){return String(c||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function x(c,n=[]){let e=Array.isArray(n)?n:[];if(e.length===0)return{requested:c||null,resolved:null,strategy:"none"};let t=e.filter(s=>!s.subtask),r=t.length>0?t:e,i=b(c);if(i){let s=r.find(p=>b(p.name)===i);if(s)return{requested:c,resolved:s,strategy:"exact"};let a={task:["task","\u4EFB\u52A1","\u4E8B\u9879","to do","todo"],story:["story","\u7528\u6237\u6545\u4E8B","\u9700\u6C42"],bug:["bug","\u7F3A\u9677","\u95EE\u9898"],improvement:["improvement","\u4F18\u5316","\u6539\u8FDB"],epic:["epic","\u53F2\u8BD7"]};for(let p of Object.values(a)){if(!p.some(m=>b(m)===i))continue;let d=r.find(m=>p.some(g=>b(g)===b(m.name)));if(d)return{requested:c,resolved:d,strategy:"alias"}}let u=r.map(p=>({t:p,score:I(c,p.name)})).sort((p,d)=>d.score-p.score);if(u[0]&&u[0].score>=.5)return{requested:c,resolved:u[0].t,strategy:"fuzzy"}}let o=["task","story","bug","improvement","epic"];for(let s of o){let a=r.find(u=>b(u.name)===s);if(a)return{requested:c||null,resolved:a,strategy:"default-preferred"}}return{requested:c||null,resolved:r[0],strategy:"default-first"}}async function A(c){let n=`projectKeys=${encodeURIComponent(c)}&expand=projects.issuetypes`,e=await f(`/rest/api/3/issue/createmeta?${n}`),t=Array.isArray(e?.projects)?e.projects:[],i=t.find(s=>String(s?.key||"").toUpperCase()===String(c||"").toUpperCase())||t[0]||null;return(Array.isArray(i?.issuetypes)?i.issuetypes:[]).map(s=>({id:s.id,name:s.name,subtask:!!s.subtask,description:s.description||null}))}async function R(c,n){if(!c)throw new Error("projectKey is required");let e="sprint is not EMPTY";n==="active"?e="sprint in openSprints()":n==="closed"?e="sprint in closedSprints()":n==="future"&&(e="sprint in futureSprints()");let t=`project = ${c} AND ${e} ORDER BY updated DESC`,r=`jql=${encodeURIComponent(t)}&maxResults=100&fields=customfield_10020`,i=await f(`/rest/api/3/search/jql?${r}`),o=new Map;for(let s of i.issues||[])for(let a of s.fields?.customfield_10020||[])a&&!o.has(a.id)&&o.set(a.id,{id:a.id,name:a.name,state:a.state,boardId:a.boardId||null,startDate:a.startDate||null,endDate:a.endDate||null,goal:a.goal||null});return[...o.values()].sort((s,a)=>{let u={active:0,future:1,closed:2},p=(u[s.state]??3)-(u[a.state]??3);return p!==0?p:String(a.startDate||"").localeCompare(String(s.startDate||""))})}function D(c,{sprintId:n,sprintName:e,target:t}={}){let r=Array.isArray(c)?c:[];if(!r.length)return{sprint:null,selectedBy:"none"};if(n!=null&&String(n).trim()!=="")return{sprint:r.find(s=>String(s.id)===String(n))||null,selectedBy:"id"};if(e&&String(e).trim()){let o=String(e).trim(),s=r.find(u=>String(u.name||"").toLowerCase()===o.toLowerCase());if(s)return{sprint:s,selectedBy:"name-exact"};let a=r.map(u=>({s:u,score:I(o,u.name||"")})).sort((u,p)=>p.score-u.score);return a[0]&&a[0].score>=.5?{sprint:a[0].s,selectedBy:"name-fuzzy"}:{sprint:null,selectedBy:"name-none"}}let i=String(t||"current").trim().toLowerCase();return i==="active"||i==="current"||i==="latest"?{sprint:r[0],selectedBy:i}:{sprint:r[0],selectedBy:"default"}}function E(c,n){let e=c?.fields?.customfield_10020;return Array.isArray(e)?e.some(t=>String(t?.id)===String(n)):!1}async function B({issueKey:c,projectKey:n,sprintId:e,attempts:t=3,delayMs:r=450}){let i=[];for(let o=0;o<t;o++){try{let s=`project = ${n} AND key = ${c} AND sprint = ${e}`,a=`jql=${encodeURIComponent(s)}&maxResults=1&fields=key,status`,u=await f(`/rest/api/3/search/jql?${a}`);if(Number(u?.total||0)>0)return i.push({attempt:o+1,jql:!0,issueField:null}),{ok:!0,method:"jql",traces:i};let d=await f(`/rest/api/3/issue/${c}?fields=customfield_10020,status`),m=E(d,e);if(i.push({attempt:o+1,jql:!1,issueField:m}),m)return{ok:!0,method:"issue_field",traces:i}}catch(s){i.push({attempt:o+1,error:String(s?.message||s)})}o<t-1&&await new Promise(s=>setTimeout(s,r))}return{ok:!1,method:"none",traces:i}}async function w({issueKey:c,projectKey:n,sprintId:e,sprintName:t,target:r}){if(!c)return{ok:!1,error:"issueKey is required"};let i=n;if(!i&&(i=(await f(`/rest/api/3/issue/${c}?fields=project`))?.fields?.project?.key||null,!i))return{ok:!1,error:`Could not resolve project for ${c}`};let o=await R(i,"active");if(!o.length)return{ok:!1,error:`No assignable active sprint found for project ${i}`};let{sprint:s,selectedBy:a}=D(o,{sprintId:e,sprintName:t,target:r});if(!s)return{ok:!1,error:`No matching sprint found in ${i}`,requested:{sprintId:e??null,sprintName:t??null,target:r??"current"},availableSprints:o.map(d=>({id:d.id,name:d.name,state:d.state}))};await f(`/rest/api/3/issue/${c}`,{method:"PUT",body:{fields:{customfield_10020:Number(s.id)}}});let u=await B({issueKey:c,projectKey:i,sprintId:s.id}),p=u.ok;return{ok:p,issueKey:c,projectKey:i,sprintId:s.id,sprintName:s.name,selectedBy:a,verifiedBy:u.method,verified:p,verificationTrace:u.traces,warning:p?null:`Sprint assignment attempted but verification did not find ${c} in sprint ${s.id}`}}async function f(c,n={}){let e=async()=>{let{token:t,cloudId:r}=await T("jira");if(typeof t!="string"||!t)throw new Error(`Invalid jira token type: ${typeof t}`);if(!r)throw new Error("Invalid jira cloudId: missing");let i=`https://api.atlassian.com/ex/jira/${r}${c}`,o=await fetch(i,{method:n.method||"GET",headers:{Authorization:`Bearer ${t}`,Accept:"application/json",...n.body?{"Content-Type":"application/json"}:{},...n.headers},body:n.body?JSON.stringify(n.body):void 0});if(!o.ok){let a=await o.text().catch(()=>"");throw new Error(`Jira API ${o.status}: ${a.slice(0,300)}`)}let s=await o.text().catch(()=>"");if(!s||!s.trim())return{};try{return JSON.parse(s)}catch{return{raw:s}}};try{return await e()}catch(t){let r=String(t?.message||t||"").toLowerCase();if(!(r.includes("token")||r.includes("401")||r.includes("403")||r.includes("substring")))throw t;return $("jira"),e()}}var z={id:"jira",serverName:"jira",allowedTools:["mcp__jira__*"],requiresIntegration:O.JIRA,envKeys:["ATLASSIAN_ACCESS_TOKEN","ATLASSIAN_CLOUD_ID"],description:"Zibby Jira MCP Server (OAuth Bearer)",promptFragment:`## Jira
|
|
19
|
+
`)}function k(c){return String(c||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function N(c){return k(c).replace(/[a-z0-9]+/g,"")}function I(c,n){let e=k(c),t=k(n);if(!e||!t)return 0;if(e===t)return 1;if(e.length===1||t.length===1)return e===t?1:0;let r=p=>{let d=new Map;for(let m=0;m<p.length-1;m++){let g=p.slice(m,m+2);d.set(g,(d.get(g)||0)+1)}return d},i=r(e),o=r(t),s=0,a=0,u=0;for(let p of i.values())a+=p;for(let p of o.values())u+=p;for(let[p,d]of i.entries()){let m=o.get(p)||0;s+=Math.min(d,m)}return 2*s/Math.max(1,a+u)}function b(c){return String(c||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function x(c,n=[]){let e=Array.isArray(n)?n:[];if(e.length===0)return{requested:c||null,resolved:null,strategy:"none"};let t=e.filter(s=>!s.subtask),r=t.length>0?t:e,i=b(c);if(i){let s=r.find(p=>b(p.name)===i);if(s)return{requested:c,resolved:s,strategy:"exact"};let a={task:["task","\u4EFB\u52A1","\u4E8B\u9879","to do","todo"],story:["story","\u7528\u6237\u6545\u4E8B","\u9700\u6C42"],bug:["bug","\u7F3A\u9677","\u95EE\u9898"],improvement:["improvement","\u4F18\u5316","\u6539\u8FDB"],epic:["epic","\u53F2\u8BD7"]};for(let p of Object.values(a)){if(!p.some(m=>b(m)===i))continue;let d=r.find(m=>p.some(g=>b(g)===b(m.name)));if(d)return{requested:c,resolved:d,strategy:"alias"}}let u=r.map(p=>({t:p,score:I(c,p.name)})).sort((p,d)=>d.score-p.score);if(u[0]&&u[0].score>=.5)return{requested:c,resolved:u[0].t,strategy:"fuzzy"}}let o=["task","story","bug","improvement","epic"];for(let s of o){let a=r.find(u=>b(u.name)===s);if(a)return{requested:c||null,resolved:a,strategy:"default-preferred"}}return{requested:c||null,resolved:r[0],strategy:"default-first"}}async function A(c){let n=`projectKeys=${encodeURIComponent(c)}&expand=projects.issuetypes`,e=await f(`/rest/api/3/issue/createmeta?${n}`),t=Array.isArray(e?.projects)?e.projects:[],i=t.find(s=>String(s?.key||"").toUpperCase()===String(c||"").toUpperCase())||t[0]||null;return(Array.isArray(i?.issuetypes)?i.issuetypes:[]).map(s=>({id:s.id,name:s.name,subtask:!!s.subtask,description:s.description||null}))}async function R(c,n){if(!c)throw new Error("projectKey is required");let e="sprint is not EMPTY";n==="active"?e="sprint in openSprints()":n==="closed"?e="sprint in closedSprints()":n==="future"&&(e="sprint in futureSprints()");let t=`project = ${c} AND ${e} ORDER BY updated DESC`,r=`jql=${encodeURIComponent(t)}&maxResults=100&fields=customfield_10020`,i=await f(`/rest/api/3/search/jql?${r}`),o=new Map;for(let s of i.issues||[])for(let a of s.fields?.customfield_10020||[])a&&!o.has(a.id)&&o.set(a.id,{id:a.id,name:a.name,state:a.state,boardId:a.boardId||null,startDate:a.startDate||null,endDate:a.endDate||null,goal:a.goal||null});return[...o.values()].sort((s,a)=>{let u={active:0,future:1,closed:2},p=(u[s.state]??3)-(u[a.state]??3);return p!==0?p:String(a.startDate||"").localeCompare(String(s.startDate||""))})}function D(c,{sprintId:n,sprintName:e,target:t}={}){let r=Array.isArray(c)?c:[];if(!r.length)return{sprint:null,selectedBy:"none"};if(n!=null&&String(n).trim()!=="")return{sprint:r.find(s=>String(s.id)===String(n))||null,selectedBy:"id"};if(e&&String(e).trim()){let o=String(e).trim(),s=r.find(u=>String(u.name||"").toLowerCase()===o.toLowerCase());if(s)return{sprint:s,selectedBy:"name-exact"};let a=r.map(u=>({s:u,score:I(o,u.name||"")})).sort((u,p)=>p.score-u.score);return a[0]&&a[0].score>=.5?{sprint:a[0].s,selectedBy:"name-fuzzy"}:{sprint:null,selectedBy:"name-none"}}let i=String(t||"current").trim().toLowerCase();return i==="active"||i==="current"||i==="latest"?{sprint:r[0],selectedBy:i}:{sprint:r[0],selectedBy:"default"}}function E(c,n){let e=c?.fields?.customfield_10020;return Array.isArray(e)?e.some(t=>String(t?.id)===String(n)):!1}async function B({issueKey:c,projectKey:n,sprintId:e,attempts:t=3,delayMs:r=450}){let i=[];for(let o=0;o<t;o++){try{let s=`project = ${n} AND key = ${c} AND sprint = ${e}`,a=`jql=${encodeURIComponent(s)}&maxResults=1&fields=key,status`,u=await f(`/rest/api/3/search/jql?${a}`);if(Number(u?.total||0)>0)return i.push({attempt:o+1,jql:!0,issueField:null}),{ok:!0,method:"jql",traces:i};let d=await f(`/rest/api/3/issue/${c}?fields=customfield_10020,status`),m=E(d,e);if(i.push({attempt:o+1,jql:!1,issueField:m}),m)return{ok:!0,method:"issue_field",traces:i}}catch(s){i.push({attempt:o+1,error:String(s?.message||s)})}o<t-1&&await new Promise(s=>setTimeout(s,r))}return{ok:!1,method:"none",traces:i}}async function w({issueKey:c,projectKey:n,sprintId:e,sprintName:t,target:r}){if(!c)return{ok:!1,error:"issueKey is required"};let i=n;if(!i&&(i=(await f(`/rest/api/3/issue/${c}?fields=project`))?.fields?.project?.key||null,!i))return{ok:!1,error:`Could not resolve project for ${c}`};let o=await R(i,"active");if(!o.length)return{ok:!1,error:`No assignable active sprint found for project ${i}`};let{sprint:s,selectedBy:a}=D(o,{sprintId:e,sprintName:t,target:r});if(!s)return{ok:!1,error:`No matching sprint found in ${i}`,requested:{sprintId:e??null,sprintName:t??null,target:r??"current"},availableSprints:o.map(d=>({id:d.id,name:d.name,state:d.state}))};await f(`/rest/api/3/issue/${c}`,{method:"PUT",body:{fields:{customfield_10020:Number(s.id)}}});let u=await B({issueKey:c,projectKey:i,sprintId:s.id}),p=u.ok;return{ok:p,issueKey:c,projectKey:i,sprintId:s.id,sprintName:s.name,selectedBy:a,verifiedBy:u.method,verified:p,verificationTrace:u.traces,warning:p?null:`Sprint assignment attempted but verification did not find ${c} in sprint ${s.id}`}}async function f(c,n={}){let e=async()=>{let{token:t,cloudId:r}=await T("jira");if(typeof t!="string"||!t)throw new Error(`Invalid jira token type: ${typeof t}`);if(!r)throw new Error("Invalid jira cloudId: missing");let i=`https://api.atlassian.com/ex/jira/${r}${c}`,o=await fetch(i,{method:n.method||"GET",headers:{Authorization:`Bearer ${t}`,Accept:"application/json",...n.body?{"Content-Type":"application/json"}:{},...n.headers},body:n.body?JSON.stringify(n.body):void 0});if(!o.ok){let a=await o.text().catch(()=>"");throw new Error(`Jira API ${o.status}: ${a.slice(0,300)}`)}let s=await o.text().catch(()=>"");if(!s||!s.trim())return{};try{return JSON.parse(s)}catch{return{raw:s}}};try{return await e()}catch(t){let r=String(t?.message||t||"").toLowerCase();if(!(r.includes("token")||r.includes("401")||r.includes("403")||r.includes("substring")))throw t;return $("jira"),e()}}var z={id:"jira",serverName:"jira",allowedTools:["mcp__jira__*"],requiresIntegration:O.JIRA,envKeys:["ATLASSIAN_ACCESS_TOKEN","ATLASSIAN_CLOUD_ID"],description:"Zibby Jira MCP Server (OAuth Bearer)",promptFragment:`## Jira
|
|
20
20
|
You have direct access to the user's Jira. Use these tools proactively:
|
|
21
21
|
|
|
22
22
|
### Issue tools
|
package/dist/lark.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{existsSync as y}from"fs";import{fileURLToPath as f}from"url";import{dirname as k,resolve as b}from"path";import{resolveIntegrationToken as v}from"@zibby/core/backend-client.js";var u=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),T=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});function I(){if(process.env.MCP_LARK_PATH)return process.env.MCP_LARK_PATH;let i=k(f(import.meta.url)),e=b(i,"..","bin","mcp-lark.mjs");return y(e)?e:null}var S=6e3*1e3,p=null;async function N(){let{appId:i,appSecret:e,host:t}=await v("lark");if(p&&p.appId===i&&p.expiresAt>Date.now())return{token:p.token,host:t};let n=await(await fetch(`${t}/open-apis/auth/v3/tenant_access_token/internal`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({app_id:i,app_secret:e})})).json();if(n.code!==0)throw new Error(`Lark tenant_access_token failed: ${n.msg||n.code}`);return p={token:n.tenant_access_token,expiresAt:Date.now()+S,appId:i},{token:n.tenant_access_token,host:t}}async function _(i,e,t={}){let{token:a,host:n}=await N(),r=`${n}${e}`,m={method:i,headers:{Authorization:`Bearer ${a}`,"Content-Type":"application/json; charset=utf-8"}};i!=="GET"&&(m.body=JSON.stringify(t));let c=await(await fetch(r,m)).json();if(c.code!==0)throw new Error(`Lark API ${e} error: ${c.msg||c.code}`);return c.data||{}}function g(i){return JSON.stringify({text:i})}function O(i){return!i||typeof i!="string"||i.startsWith("oc_")?"chat_id":i.startsWith("ou_")?"open_id":i.startsWith("on_")?"union_id":i.startsWith("cli_")?"app_id":i.includes("@")?"email":"chat_id"}var x={id:"lark",serverName:"lark",allowedTools:["mcp__lark__*"],requiresIntegration:u.LARK,description:"Lark / Feishu messaging \u2014 send messages and reply in threads.",envKeys:[],promptFragment:`## Lark
|
|
1
|
+
import{existsSync as y}from"fs";import{fileURLToPath as f}from"url";import{dirname as k,resolve as b}from"path";import{resolveIntegrationToken as v}from"@zibby/core/backend-client.js";var u=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),T=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});function I(){if(process.env.MCP_LARK_PATH)return process.env.MCP_LARK_PATH;let i=k(f(import.meta.url)),e=b(i,"..","bin","mcp-lark.mjs");return y(e)?e:null}var S=6e3*1e3,p=null;async function N(){let{appId:i,appSecret:e,host:t}=await v("lark");if(p&&p.appId===i&&p.expiresAt>Date.now())return{token:p.token,host:t};let n=await(await fetch(`${t}/open-apis/auth/v3/tenant_access_token/internal`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({app_id:i,app_secret:e})})).json();if(n.code!==0)throw new Error(`Lark tenant_access_token failed: ${n.msg||n.code}`);return p={token:n.tenant_access_token,expiresAt:Date.now()+S,appId:i},{token:n.tenant_access_token,host:t}}async function _(i,e,t={}){let{token:a,host:n}=await N(),r=`${n}${e}`,m={method:i,headers:{Authorization:`Bearer ${a}`,"Content-Type":"application/json; charset=utf-8"}};i!=="GET"&&(m.body=JSON.stringify(t));let c=await(await fetch(r,m)).json();if(c.code!==0)throw new Error(`Lark API ${e} error: ${c.msg||c.code}`);return c.data||{}}function g(i){return JSON.stringify({text:i})}function O(i){return!i||typeof i!="string"||i.startsWith("oc_")?"chat_id":i.startsWith("ou_")?"open_id":i.startsWith("on_")?"union_id":i.startsWith("cli_")?"app_id":i.includes("@")?"email":"chat_id"}var x={id:"lark",serverName:"lark",allowedTools:["mcp__lark__*"],requiresIntegration:u.LARK,description:"Lark / Feishu messaging \u2014 send messages and reply in threads.",envKeys:[],promptFragment:`## Lark
|
|
2
2
|
You can send messages and replies on Lark. Use:
|
|
3
3
|
- lark_send_message: post a message to a chat, user, or DM
|
|
4
4
|
- lark_reply: reply to an existing message (threaded)
|
package/dist/larkDocs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import{existsSync as v,statSync as A,readFileSync as R}from"fs";import{fileURLToPath as P}from"url";import{basename as E,dirname as U,resolve as $}from"path";import{resolveIntegrationToken as D}from"@zibby/core/backend-client.js";var x=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),K=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});function j(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let t=U(P(import.meta.url)),e=$(t,"..","bin","mcp-skill.mjs");return v(e)?e:null}var L=2e4,w=50,C=10*1024*1024,J=6e3*1e3,h=null;async function O(){let{appId:t,appSecret:e,host:n}=await D("lark");if(h&&h.appId===t&&h.expiresAt>Date.now())return{token:h.token,host:n};let o=await(await fetch(`${n}/open-apis/auth/v3/tenant_access_token/internal`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({app_id:t,app_secret:e})})).json();if(o.code!==0)throw new Error(`Lark tenant_access_token failed: ${o.msg||o.code}`);return h={token:o.tenant_access_token,expiresAt:Date.now()+J,appId:t},{token:o.tenant_access_token,host:n}}async function l(t,e,n){let{token:r,host:o}=await O(),i={method:t,headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json; charset=utf-8"}};t!=="GET"&&n!==void 0&&(i.body=JSON.stringify(n));let a=await(await fetch(`${o}${e}`,i)).json();if(a.code!==0)throw new Error(`Lark Docx API ${e} error: ${a.msg||a.code}`);return{data:a.data||{},host:o}}function f(t,e){return String(t||"").includes("feishu")?`https://feishu.cn/docx/${e}`:`https://www.larksuite.com/docx/${e}`}function m(t){if(!t||typeof t!="string")return null;let e=t.trim();if(!e)return null;let n=e.match(/\/(docx|wiki)\/([A-Za-z0-9]+)/);return n?{type:n[1],token:n[2]}:/^[A-Za-z0-9]{10,}$/.test(e)?{type:"docx",token:e}:null}async function k(t){let e=typeof t=="string"?m(t):t;if(!e)throw new Error("A valid Lark doc id or URL is required");if(e.type==="docx")return e.token;let{data:n}=await l("GET",`/open-apis/wiki/v2/spaces/get_node?token=${encodeURIComponent(e.token)}`),r=n?.node||{};if(r.obj_type!=="docx"||!r.obj_token)throw new Error(`Wiki node is not a docx document (obj_type=${r.obj_type||"unknown"})`);return r.obj_token}function b(t){let e=String(t??"").replace(/\r\n/g,`
|
|
2
2
|
`),n=[];for(let r of e.split(`
|
|
3
|
-
`)){let o=r.replace(/\s+$/,"");if(!o.trim())continue;let i=/^(#{1,3})\s+(.*)$/.exec(o),s=/^\s*[-*]\s+(.*)$/.exec(o),a=/^\s*\d+[.)]\s+(.*)$/.exec(o),c,d,p;if(i){let u=i[1].length;c=`heading${u}`,d=2+u,p=i[2]}else s?(c="bullet",d=12,p=s[1]):a?(c="ordered",d=13,p=a[1]):(c="text",d=2,p=o);n.push({block_type:d,[c]:{elements:[{text_run:{content:p}}],style:{}}})}return n}function y(t){let e=typeof t?.markdown=="string"?t.markdown:null,n=typeof t?.text=="string"?t.text:null;return e??n}async function S(t,e){let n;for(let r=0;r<e.length;r+=w){let o=e.slice(r,r+w);n=(await l("POST",`/open-apis/docx/v1/documents/${t}/blocks/${t}/children?document_revision_id=-1`,{children:o})).host}return n}function F(t){let e=typeof t=="string"?t.trim():"";if(!e)throw new Error("imagePath is required");if(!v(e)||!A(e).isFile())throw new Error(`imagePath not found (or not a file): ${e}`);if(!/\.(png|jpe?g)$/i.test(e))throw new Error("imagePath must be a .png or .jpg/.jpeg file");let n=R(e);if(n.length>C)throw new Error(`image is ${(n.length/(1024*1024)).toFixed(1)}MB \u2014 max 10MB`);return n}async function q({fileName:t,parentNode:e,bytes:n}){let{token:r,host:o}=await O(),i=new FormData;i.set("file_name",t),i.set("parent_type","docx_image"),i.set("parent_node",e),i.set("size",String(n.length)),i.set("file",new Blob([n]),t);let a=await(await fetch(`${o}/open-apis/drive/v1/medias/upload_all`,{method:"POST",headers:{Authorization:`Bearer ${r}`},body:i})).json();if(a.code!==0)throw new Error(`Lark media upload_all error: ${a.msg||a.code}`);let c=a.data?.file_token;if(!c)throw new Error("Lark media upload_all returned no file_token");return c}var B="docx",G=50;function T(t){return[{type:"text_run",text_run:{text:String(t??"")}}]}function M(t){return Array.isArray(t)?t.map(e=>e?.text_run?.text??e?.docs_link?.url??(e?.person?`@${e.person.user_id||""}`:"")).join(""):""}function H(t){let e=Array.isArray(t?.reply_list?.replies)?t.reply_list.replies:[];return{commentId:t?.comment_id||"",resolved:!!t?.is_solved,replies:e.map(n=>({replyId:n?.reply_id||"",author:n?.user_id||"",text:M(n?.content?.elements),createTime:n?.create_time||""}))}}function I(t){return typeof t?.fileType=="string"&&t.fileType.trim()?t.fileType.trim():B}var V={id:"lark-docs",serverName:"larkdocs",allowedTools:["mcp__larkdocs__*"],requiresIntegration:x.LARK,description:"Lark / Feishu Docs \u2014 read, create, append, and insert images into Lark documents (docx).",envKeys:[],promptFragment:`## Lark Docs
|
|
3
|
+
`)){let o=r.replace(/\s+$/,"");if(!o.trim())continue;let i=/^(#{1,3})\s+(.*)$/.exec(o),s=/^\s*[-*]\s+(.*)$/.exec(o),a=/^\s*\d+[.)]\s+(.*)$/.exec(o),c,d,p;if(i){let u=i[1].length;c=`heading${u}`,d=2+u,p=i[2]}else s?(c="bullet",d=12,p=s[1]):a?(c="ordered",d=13,p=a[1]):(c="text",d=2,p=o);n.push({block_type:d,[c]:{elements:[{text_run:{content:p}}],style:{}}})}return n}function y(t){let e=typeof t?.markdown=="string"?t.markdown:null,n=typeof t?.text=="string"?t.text:null;return e??n}async function S(t,e){let n;for(let r=0;r<e.length;r+=w){let o=e.slice(r,r+w);n=(await l("POST",`/open-apis/docx/v1/documents/${t}/blocks/${t}/children?document_revision_id=-1`,{children:o})).host}return n}function F(t){let e=typeof t=="string"?t.trim():"";if(!e)throw new Error("imagePath is required");if(!v(e)||!A(e).isFile())throw new Error(`imagePath not found (or not a file): ${e}`);if(!/\.(png|jpe?g)$/i.test(e))throw new Error("imagePath must be a .png or .jpg/.jpeg file");let n=R(e);if(n.length>C)throw new Error(`image is ${(n.length/(1024*1024)).toFixed(1)}MB \u2014 max 10MB`);return n}async function q({fileName:t,parentNode:e,bytes:n}){let{token:r,host:o}=await O(),i=new FormData;i.set("file_name",t),i.set("parent_type","docx_image"),i.set("parent_node",e),i.set("size",String(n.length)),i.set("file",new Blob([n]),t);let a=await(await fetch(`${o}/open-apis/drive/v1/medias/upload_all`,{method:"POST",headers:{Authorization:`Bearer ${r}`},body:i})).json();if(a.code!==0)throw new Error(`Lark media upload_all error: ${a.msg||a.code}`);let c=a.data?.file_token;if(!c)throw new Error("Lark media upload_all returned no file_token");return c}var B="docx",G=50;function T(t){return[{type:"text_run",text_run:{text:String(t??"")}}]}function M(t){return Array.isArray(t)?t.map(e=>e?.text_run?.text??e?.docs_link?.url??(e?.person?`@${e.person.user_id||""}`:"")).join(""):""}function H(t){let e=Array.isArray(t?.reply_list?.replies)?t.reply_list.replies:[];return{commentId:t?.comment_id||"",resolved:!!t?.is_solved,replies:e.map(n=>({replyId:n?.reply_id||"",author:n?.user_id||"",text:M(n?.content?.elements),createTime:n?.create_time||""}))}}function I(t){return typeof t?.fileType=="string"&&t.fileType.trim()?t.fileType.trim():B}var V={id:"lark-docs",serverName:"larkdocs",allowedTools:["mcp__larkdocs__*"],requiresIntegration:x.LARK,description:"Lark / Feishu Docs \u2014 read, create, append, and insert images into Lark documents (docx).",envKeys:[],promptFragment:`## Lark Docs
|
|
4
4
|
You can read, create, and append Lark/Feishu documents (docx). This reuses the same connected Lark app as messaging.
|
|
5
5
|
- larkdoc_get: pass a Lark doc id OR a full doc URL (a /docx/ or /wiki/ link); returns { ok, documentId, title, url, text } where text is the doc as plain text (truncated to ~20k chars). Use it as reference context.
|
|
6
6
|
- larkdoc_create: create a new doc from a title + markdown/text (#/##/### headings, - bullets, 1. ordered supported); returns { ok, documentId, url }. Share the url.
|
package/dist/linear.js
CHANGED
|
@@ -12,7 +12,7 @@ import{existsSync as N}from"fs";import{fileURLToPath as k}from"url";import{dirna
|
|
|
12
12
|
assignee { id name displayName email }
|
|
13
13
|
labels { nodes { id name color } }
|
|
14
14
|
team { id key name }
|
|
15
|
-
`,C={id:"linear",serverName:"linear",allowedTools:["mcp__linear__*"],requiresIntegration:h.LINEAR,envKeys:["LINEAR_API_KEY","LINEAR_OAUTH_TOKEN"],description:"Linear \u2014 issues, comments, workflow states (GraphQL API key)",promptFragment:`## Linear
|
|
15
|
+
`,C={id:"linear",serverName:"linear",allowedTools:["mcp__linear__*"],requiresIntegration:h.LINEAR,envKeys:["LINEAR_API_KEY","LINEAR_OAUTH_TOKEN"],description:"Linear \u2014 issues, comments, workflow states (GraphQL API key)",promptFragment:`## Linear
|
|
16
16
|
You have direct access to the user's Linear workspace (GraphQL API). Tools:
|
|
17
17
|
|
|
18
18
|
### Discovery
|
package/dist/linkedin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{existsSync as L,readFileSync as w}from"fs";import{fileURLToPath as A}from"url";import{dirname as T,resolve as P}from"path";import{resolveIntegrationToken as y,clearTokenCache as N}from"@zibby/core/backend-client.js";function S(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let t=T(A(import.meta.url)),e=P(t,"..","bin","mcp-skill.mjs");return L(e)?e:null}function E(){let t=String(process.env.ZIBBY_INJECTED_LINKEDIN_TOKEN||"").trim();if(!t)return null;let e=String(process.env.ZIBBY_INJECTED_LINKEDIN_MEMBER_ID||"").trim();return{token:t,memberId:e}}function v(){return String(process.env.ZIBBY_CHAT_STRICT_PERSONAL||"").trim()==="1"}function O(){return String(process.env.ZIBBY_SENDER_IS_NON_OWNER||"").trim()==="1"}var R="You haven't connected your own LinkedIn account \u2014 connect it at https://studio.zibby.dev/integrations (LinkedIn). For privacy, I can't post or act as anyone else's LinkedIn (including the project owner's) on your behalf.";function f(){let t=E();if(t)return t;if(v()||O())throw new Error(R);return null}var x="202506",D="https://api.linkedin.com";function b(t){if(t==null)return null;let e=String(t).trim();if(!e)return null;let n=e.match(/urn:li:organization:(\d+)/i);return n?n[1]:/^\d+$/.test(e)?e:null}function _(t){if(!t)return"";if(t.localizedName)return String(t.localizedName);let e=t.name&&t.name.localized;if(e&&typeof e=="object"){let n=Object.values(e)[0];if(n)return String(n)}return""}function h(t,e){return t?typeof t.get=="function"?t.get(e):t[e]||t[e.toLowerCase()]||null:null}async function p(t,e={},n="linkedin_business"){let l=async()=>{let i;if(n==="linkedin_personal"){let s=f();s&&(i=s.token)}if(i||({token:i}=await y(n)),typeof i!="string"||!i)throw new Error("LinkedIn is not connected: no access token available. Connect LinkedIn in Integrations.");let a=t.startsWith("https://")?t:`${D}${t}`,o=await fetch(a,{method:e.method||"GET",headers:{Authorization:`Bearer ${i}`,"LinkedIn-Version":x,"X-Restli-Protocol-Version":"2.0.0",Accept:"application/json",...e.body?{"Content-Type":"application/json"}:{},...e.headers},body:e.body?JSON.stringify(e.body):void 0});if(!o.ok){let s=await o.text().catch(()=>"");throw new Error(`LinkedIn API ${o.status}: ${s.slice(0,300)}`)}let r=await o.text().catch(()=>""),u={};if(r&&r.trim())try{u=JSON.parse(r)}catch{u={raw:r}}return{status:o.status,headers:o.headers,body:u}};try{return await l()}catch(i){let a=String(i?.message||i||"").toLowerCase();if(!(a.includes("token")||a.includes("401")||a.includes("unauthorized")))throw i;return N(n),l()}}async function U(t){let e;if(t==="linkedin_personal"){let n=f();n&&(e=n.token)}if(e||({token:e}=await y(t)),typeof e!="string"||!e)throw new Error("LinkedIn is not connected: no access token available. Connect LinkedIn in Integrations.");return e}function B(t){switch(String(t||"").toLowerCase().match(/\.([a-z0-9]+)$/)?.[1]){case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"webp":return"image/webp";default:return"image/png"}}async function k(t,e,n,l){if(typeof n!="string"||!n.trim())throw new Error("imagePath (a local image file path) is required to upload an image");let{body:i}=await p("/rest/images?action=initializeUpload",{method:"POST",body:{initializeUploadRequest:{owner:e}}},t),a=i?.value?.uploadUrl,o=i?.value?.image;if(!a||!o)throw new Error(`LinkedIn image initializeUpload returned no uploadUrl/image (got: ${JSON.stringify(i).slice(0,200)})`);let r=w(n),u=await U(t),s=await fetch(a,{method:"PUT",headers:{Authorization:`Bearer ${u}`,"Content-Type":l||B(n)},body:r});if(!s.ok){let c=await s.text().catch(()=>"");throw new Error(`LinkedIn image upload ${s.status}: ${c.slice(0,300)}`)}return o}var j={id:"linkedin",serverName:"linkedin",allowedTools:["mcp__linkedin__*"],envKeys:[],description:"LinkedIn \u2014 (business) list admin Organizations + create DRAFT posts on a company Page, and (personal) PUBLISH a post to your own member profile feed",promptFragment:`## LinkedIn
|
|
1
|
+
import{existsSync as L,readFileSync as w}from"fs";import{fileURLToPath as A}from"url";import{dirname as T,resolve as P}from"path";import{resolveIntegrationToken as y,clearTokenCache as N}from"@zibby/core/backend-client.js";function S(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let t=T(A(import.meta.url)),e=P(t,"..","bin","mcp-skill.mjs");return L(e)?e:null}function E(){let t=String(process.env.ZIBBY_INJECTED_LINKEDIN_TOKEN||"").trim();if(!t)return null;let e=String(process.env.ZIBBY_INJECTED_LINKEDIN_MEMBER_ID||"").trim();return{token:t,memberId:e}}function v(){return String(process.env.ZIBBY_CHAT_STRICT_PERSONAL||"").trim()==="1"}function O(){return String(process.env.ZIBBY_SENDER_IS_NON_OWNER||"").trim()==="1"}var R="You haven't connected your own LinkedIn account \u2014 connect it at https://studio.zibby.dev/integrations (LinkedIn). For privacy, I can't post or act as anyone else's LinkedIn (including the project owner's) on your behalf.";function f(){let t=E();if(t)return t;if(v()||O())throw new Error(R);return null}var x="202506",D="https://api.linkedin.com";function b(t){if(t==null)return null;let e=String(t).trim();if(!e)return null;let n=e.match(/urn:li:organization:(\d+)/i);return n?n[1]:/^\d+$/.test(e)?e:null}function _(t){if(!t)return"";if(t.localizedName)return String(t.localizedName);let e=t.name&&t.name.localized;if(e&&typeof e=="object"){let n=Object.values(e)[0];if(n)return String(n)}return""}function h(t,e){return t?typeof t.get=="function"?t.get(e):t[e]||t[e.toLowerCase()]||null:null}async function p(t,e={},n="linkedin_business"){let l=async()=>{let i;if(n==="linkedin_personal"){let s=f();s&&(i=s.token)}if(i||({token:i}=await y(n)),typeof i!="string"||!i)throw new Error("LinkedIn is not connected: no access token available. Connect LinkedIn in Integrations.");let a=t.startsWith("https://")?t:`${D}${t}`,o=await fetch(a,{method:e.method||"GET",headers:{Authorization:`Bearer ${i}`,"LinkedIn-Version":x,"X-Restli-Protocol-Version":"2.0.0",Accept:"application/json",...e.body?{"Content-Type":"application/json"}:{},...e.headers},body:e.body?JSON.stringify(e.body):void 0});if(!o.ok){let s=await o.text().catch(()=>"");throw new Error(`LinkedIn API ${o.status}: ${s.slice(0,300)}`)}let r=await o.text().catch(()=>""),u={};if(r&&r.trim())try{u=JSON.parse(r)}catch{u={raw:r}}return{status:o.status,headers:o.headers,body:u}};try{return await l()}catch(i){let a=String(i?.message||i||"").toLowerCase();if(!(a.includes("token")||a.includes("401")||a.includes("unauthorized")))throw i;return N(n),l()}}async function U(t){let e;if(t==="linkedin_personal"){let n=f();n&&(e=n.token)}if(e||({token:e}=await y(t)),typeof e!="string"||!e)throw new Error("LinkedIn is not connected: no access token available. Connect LinkedIn in Integrations.");return e}function B(t){switch(String(t||"").toLowerCase().match(/\.([a-z0-9]+)$/)?.[1]){case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"webp":return"image/webp";default:return"image/png"}}async function k(t,e,n,l){if(typeof n!="string"||!n.trim())throw new Error("imagePath (a local image file path) is required to upload an image");let{body:i}=await p("/rest/images?action=initializeUpload",{method:"POST",body:{initializeUploadRequest:{owner:e}}},t),a=i?.value?.uploadUrl,o=i?.value?.image;if(!a||!o)throw new Error(`LinkedIn image initializeUpload returned no uploadUrl/image (got: ${JSON.stringify(i).slice(0,200)})`);let r=w(n),u=await U(t),s=await fetch(a,{method:"PUT",headers:{Authorization:`Bearer ${u}`,"Content-Type":l||B(n)},body:r});if(!s.ok){let c=await s.text().catch(()=>"");throw new Error(`LinkedIn image upload ${s.status}: ${c.slice(0,300)}`)}return o}var j={id:"linkedin",serverName:"linkedin",allowedTools:["mcp__linkedin__*"],envKeys:[],description:"LinkedIn \u2014 (business) list admin Organizations + create DRAFT posts on a company Page, and (personal) PUBLISH a post to your own member profile feed",promptFragment:`## LinkedIn
|
|
2
2
|
You can post to LinkedIn two ways \u2014 an ORG company Page (business) and your own member PROFILE (personal). Each path needs its own LinkedIn integration connected.
|
|
3
3
|
|
|
4
4
|
Business (company Page) \u2014 DRAFT only:
|
package/dist/notion.js
CHANGED
|
@@ -4,7 +4,7 @@ ${s()}
|
|
|
4
4
|
`)}async function S(i,e,t){let n=[],o,r=0;do{if(t.used>=h)break;let s=new URLSearchParams({page_size:"100"});o&&s.set("start_cursor",o);let a=await p(`/blocks/${i}/children?${s.toString()}`),d=Array.isArray(a.results)?a.results:[];for(let c of d){let l="";c.has_children&&(l=await S(c.id,e+1,t));let m=M(c,e,l);if(m&&(n.push(m),t.used+=m.length+1),t.used>=h)break}o=a.has_more?a.next_cursor:void 0,r+=1}while(o&&r<D);return n.join(`
|
|
5
5
|
`)}function w(i){let e=i?.properties||{};for(let t of Object.values(e))if(t?.type==="title"){let n=g(t.title).trim();if(n)return n}return""}function f(i){let e=String(i??"");if(!e)return[{type:"text",text:{content:""}}];let t=[];for(let n=0;n<e.length;n+=2e3)t.push({type:"text",text:{content:e.slice(n,n+2e3)}});return t}function G(i){return{id:i?.id||"",discussionId:i?.discussion_id||"",text:g(i?.rich_text).trim(),author:i?.created_by?.id||"",createdTime:i?.created_time||""}}function F(i){if(!i||!i.type)return"";switch(i.type){case"title":return g(i.title).trim();case"rich_text":return g(i.rich_text).trim();case"number":return i.number==null?"":String(i.number);case"select":return i.select?.name||"";case"status":return i.status?.name||"";case"multi_select":return(i.multi_select||[]).map(t=>t.name).join(", ");case"checkbox":return i.checkbox?"true":"false";case"url":return i.url||"";case"email":return i.email||"";case"phone_number":return i.phone_number||"";case"date":return i.date?.start||"";case"people":return(i.people||[]).map(t=>t.name||t.id).join(", ");default:return""}}function y(i){return`https://www.notion.so/${String(i||"").replace(/-/g,"")}`}function H(i){let e=String(i??"").replace(/\r\n/g,`
|
|
6
6
|
`),t=[];for(let n of e.split(`
|
|
7
|
-
`)){let o=n.replace(/\s+$/,"");if(!o.trim())continue;let r=/^(#{1,3})\s+(.*)$/.exec(o),s=/^\s*[-*]\s+(.*)$/.exec(o),a=/^\s*\d+[.)]\s+(.*)$/.exec(o),d,c;r?(d=`heading_${r[1].length}`,c=r[2]):s?(d="bulleted_list_item",c=s[1]):a?(d="numbered_list_item",c=a[1]):(d="paragraph",c=o),t.push({object:"block",type:d,[d]:{rich_text:f(c)}})}return t}function x(i){return Array.isArray(i?.blocks)&&i.blocks.length?i.blocks.slice(0,N):typeof i?.markdown=="string"&&i.markdown.trim()?H(i.markdown).slice(0,N):null}async function P(i,e){for(let t=0;t<e.length;t+=b)await p(`/blocks/${i}/children`,{method:"PATCH",body:{children:e.slice(t,t+b)}})}function z(i){let e=typeof i=="string"?i.trim():"";if(!e)throw new Error("imagePath is required");if(!R(e)||!A(e).isFile())throw new Error(`imagePath not found (or not a file): ${e}`);if(!/\.(png|jpe?g)$/i.test(e))throw new Error("imagePath must be a .png or .jpg/.jpeg file");let t=L(e);if(t.length>J)throw new Error(`image is ${(t.length/(1024*1024)).toFixed(1)}MB \u2014 max 20MB (Notion single_part upload cap)`);return t}async function K(i){let e=z(i),t=U(i.trim()),n=/\.png$/i.test(t)?"image/png":"image/jpeg",r=(await p("/file_uploads",{method:"POST",body:{mode:"single_part",filename:t}}))?.id;if(!r)throw new Error("Notion file upload create returned no id");let s=new FormData;return s.set("file",new Blob([e],{type:n}),t),await p(`/file_uploads/${r}/send`,{method:"POST",formData:s}),r}var te={id:"notion",serverName:"notion",allowedTools:["mcp__notion__*"],requiresIntegration:_.NOTION,description:"Notion \u2014 read pages/databases as context + create pages, append blocks, and insert images",promptFragment:`## Notion
|
|
7
|
+
`)){let o=n.replace(/\s+$/,"");if(!o.trim())continue;let r=/^(#{1,3})\s+(.*)$/.exec(o),s=/^\s*[-*]\s+(.*)$/.exec(o),a=/^\s*\d+[.)]\s+(.*)$/.exec(o),d,c;r?(d=`heading_${r[1].length}`,c=r[2]):s?(d="bulleted_list_item",c=s[1]):a?(d="numbered_list_item",c=a[1]):(d="paragraph",c=o),t.push({object:"block",type:d,[d]:{rich_text:f(c)}})}return t}function x(i){return Array.isArray(i?.blocks)&&i.blocks.length?i.blocks.slice(0,N):typeof i?.markdown=="string"&&i.markdown.trim()?H(i.markdown).slice(0,N):null}async function P(i,e){for(let t=0;t<e.length;t+=b)await p(`/blocks/${i}/children`,{method:"PATCH",body:{children:e.slice(t,t+b)}})}function z(i){let e=typeof i=="string"?i.trim():"";if(!e)throw new Error("imagePath is required");if(!R(e)||!A(e).isFile())throw new Error(`imagePath not found (or not a file): ${e}`);if(!/\.(png|jpe?g)$/i.test(e))throw new Error("imagePath must be a .png or .jpg/.jpeg file");let t=L(e);if(t.length>J)throw new Error(`image is ${(t.length/(1024*1024)).toFixed(1)}MB \u2014 max 20MB (Notion single_part upload cap)`);return t}async function K(i){let e=z(i),t=U(i.trim()),n=/\.png$/i.test(t)?"image/png":"image/jpeg",r=(await p("/file_uploads",{method:"POST",body:{mode:"single_part",filename:t}}))?.id;if(!r)throw new Error("Notion file upload create returned no id");let s=new FormData;return s.set("file",new Blob([e],{type:n}),t),await p(`/file_uploads/${r}/send`,{method:"POST",formData:s}),r}var te={id:"notion",serverName:"notion",allowedTools:["mcp__notion__*"],requiresIntegration:_.NOTION,description:"Notion \u2014 read pages/databases as context + create pages, append blocks, and insert images",promptFragment:`## Notion
|
|
8
8
|
You can read Notion content as context AND write to Notion (create pages, append blocks, insert images).
|
|
9
9
|
- notion_get_page: pass a Notion page id OR a full Notion URL; returns { id, title, url, text } where text is the page flattened to markdown (truncated to ~20k chars). Use the text as reference context.
|
|
10
10
|
- notion_query_database: pass a database id/URL; returns a small list of rows ({ id, title, url, props }). Use to find a specific page, then notion_get_page it.
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zibby/skills",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Built-in skill definitions for the Zibby agent-workflow framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"dependencies": {
|
|
116
116
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
117
117
|
"@resvg/resvg-js": "^2.6.2",
|
|
118
|
-
"@zibby/agent-workflow": "^0.
|
|
118
|
+
"@zibby/agent-workflow": "^0.6.1",
|
|
119
119
|
"@zibby/bin-oxlint": "^1.73.0",
|
|
120
120
|
"@zibby/bin-semgrep": "^1.169.0",
|
|
121
121
|
"@zibby/skill-ids": "^0.2.0",
|
package/dist/plane.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var i=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),t=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},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 r={id:"plane",serverName:"plane",allowedTools:["mcp__plane__*"],requiresIntegration:i.PLANE,envKeys:["PLANE_API_KEY","PLANE_WORKSPACE_SLUG","PLANE_BASE_URL"],description:"Plane \u2014 projects, work items, cycles, modules, epics, comments (official MCP, API key)",tools:[],promptFragment:`## Plane
|
|
1
|
+
var i=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),t=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},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 r={id:"plane",serverName:"plane",allowedTools:["mcp__plane__*"],requiresIntegration:i.PLANE,envKeys:["PLANE_API_KEY","PLANE_WORKSPACE_SLUG","PLANE_BASE_URL"],description:"Plane \u2014 projects, work items, cycles, modules, epics, comments (official MCP, API key)",tools:[],promptFragment:`## Plane
|
|
2
2
|
You have direct access to the user's Plane workspace via the official Plane MCP server. All Plane tools are available under the mcp__plane__* namespace \u2014 use them proactively to read and write projects, work items (issues), cycles, modules, epics, sub-issues, comments, labels, states, pages, and workspace data.
|
|
3
3
|
|
|
4
4
|
- List/get projects and work items, then create/update/delete or search work items as needed.
|
package/dist/sentry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{existsSync as h}from"fs";import{fileURLToPath as _}from"url";import{dirname as S,resolve as I}from"path";import{resolveIntegrationToken as c}from"@zibby/core/backend-client.js";var l=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),P=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});function f(){if(process.env.MCP_SENTRY_PATH)return process.env.MCP_SENTRY_PATH;let n=S(_(import.meta.url)),e=I(n,"..","bin","mcp-sentry.mjs");return h(e)?e:null}function d(n){return(n||process.env.SENTRY_URL||"https://sentry.io").trim().replace(/\/+$/,"")}function m(n){let e=n||process.env.SENTRY_ORG;if(!e)throw new Error('Sentry organization not resolved \u2014 reconnect Sentry, or set SENTRY_ORG (self-hosted; the default org slug is "sentry").');return e}async function g(n,e={}){let{token:t,organizationSlug:s,baseUrl:i}=await c("sentry"),r=`${d(i)}/api/0/organizations/${m(s)}${n}`,o={method:e.method||"GET",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}};e.body!=null&&(o.body=typeof e.body=="string"?e.body:JSON.stringify(e.body));let a=await fetch(r,o);if(!a.ok){let u=await a.text().catch(()=>"");throw new Error(`Sentry API ${a.status}: ${u.slice(0,300)}`)}return a.json()}async function w(){return g("/projects/?per_page=50")}async function k({query:n="is:unresolved",sort:e="date",project:t,limit:s=25}={}){let i=`/issues/?query=${encodeURIComponent(n)}&sort=${e}&per_page=${s}`;return t&&(i+=`&project=${encodeURIComponent(t)}`),g(i)}async function p(n){let e=String(n??"").trim();if(!e)throw new Error("resolveSentryIssueId: issueRef is required");if(/^\d+$/.test(e))return e;let{token:t,organizationSlug:s,baseUrl:i}=await c("sentry"),r=await fetch(`${d(i)}/api/0/organizations/${m(s)}/shortids/${encodeURIComponent(e)}/`,{headers:{Authorization:`Bearer ${t}`}});if(!r.ok){let u=await r.text().catch(()=>"");throw new Error(`Sentry API ${r.status} resolving shortId "${e}": ${u.slice(0,200)}`)}let o=await r.json(),a=o.groupId||o.group&&o.group.id;if(!a)throw new Error(`Sentry shortId "${e}" did not resolve to a numeric issue id`);return String(a)}async function b(n){if(!n)throw new Error("sentryGetIssue: issueId is required");let e=await p(n),{token:t,baseUrl:s}=await c("sentry"),i=await fetch(`${d(s)}/api/0/issues/${e}/`,{headers:{Authorization:`Bearer ${t}`}});if(!i.ok){let r=await i.text().catch(()=>"");throw new Error(`Sentry API ${i.status}: ${r.slice(0,300)}`)}return i.json()}async function v(n,e={}){if(!n)throw new Error("sentryUpdateIssue: issueId is required");let t={};for(let a of["status","statusDetails","assignedTo","isBookmarked","hasSeen"])e[a]!==void 0&&(t[a]=e[a]);if(Object.keys(t).length===0)throw new Error("sentryUpdateIssue: nothing to update (pass status / statusDetails / assignedTo / isBookmarked / hasSeen)");let s=await p(n),{token:i,baseUrl:r}=await c("sentry"),o=await fetch(`${d(r)}/api/0/issues/${s}/`,{method:"PUT",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"},body:JSON.stringify(t)});if(!o.ok){let a=await o.text().catch(()=>"");throw o.status===403?new Error(`Sentry API 403 updating issue ${n}: ${a.slice(0,200)}. The connected Sentry integration likely lacks the \`event:write\` scope \u2014 reconnect Sentry with write access to let Zibby resolve/comment on issues.`):new Error(`Sentry API ${o.status} updating issue ${n}: ${a.slice(0,300)}`)}return o.json()}async function N(n,e){if(!n)throw new Error("sentryAddComment: issueId is required");if(!e||!String(e).trim())throw new Error("sentryAddComment: text is required");let t=await p(n),{token:s,baseUrl:i}=await c("sentry"),r=await fetch(`${d(i)}/api/0/issues/${t}/comments/`,{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify({text:String(e)})});if(!r.ok){let o=await r.text().catch(()=>"");throw r.status===403?new Error(`Sentry API 403 commenting on issue ${n}: ${o.slice(0,200)}. The connected Sentry integration likely lacks the \`event:write\` scope \u2014 reconnect Sentry with write access.`):new Error(`Sentry API ${r.status} commenting on issue ${n}: ${o.slice(0,300)}`)}return r.json()}var y={id:"sentry",serverName:"sentry",allowedTools:["mcp__sentry__*"],requiresIntegration:l.SENTRY,description:"Sentry error tracking \u2014 projects, issues, events",envKeys:[],tools:[],promptFragment:`## Sentry
|
|
1
|
+
import{existsSync as h}from"fs";import{fileURLToPath as _}from"url";import{dirname as S,resolve as I}from"path";import{resolveIntegrationToken as c}from"@zibby/core/backend-client.js";var l=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),P=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});function f(){if(process.env.MCP_SENTRY_PATH)return process.env.MCP_SENTRY_PATH;let n=S(_(import.meta.url)),e=I(n,"..","bin","mcp-sentry.mjs");return h(e)?e:null}function d(n){return(n||process.env.SENTRY_URL||"https://sentry.io").trim().replace(/\/+$/,"")}function m(n){let e=n||process.env.SENTRY_ORG;if(!e)throw new Error('Sentry organization not resolved \u2014 reconnect Sentry, or set SENTRY_ORG (self-hosted; the default org slug is "sentry").');return e}async function g(n,e={}){let{token:t,organizationSlug:s,baseUrl:i}=await c("sentry"),r=`${d(i)}/api/0/organizations/${m(s)}${n}`,o={method:e.method||"GET",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}};e.body!=null&&(o.body=typeof e.body=="string"?e.body:JSON.stringify(e.body));let a=await fetch(r,o);if(!a.ok){let u=await a.text().catch(()=>"");throw new Error(`Sentry API ${a.status}: ${u.slice(0,300)}`)}return a.json()}async function w(){return g("/projects/?per_page=50")}async function k({query:n="is:unresolved",sort:e="date",project:t,limit:s=25}={}){let i=`/issues/?query=${encodeURIComponent(n)}&sort=${e}&per_page=${s}`;return t&&(i+=`&project=${encodeURIComponent(t)}`),g(i)}async function p(n){let e=String(n??"").trim();if(!e)throw new Error("resolveSentryIssueId: issueRef is required");if(/^\d+$/.test(e))return e;let{token:t,organizationSlug:s,baseUrl:i}=await c("sentry"),r=await fetch(`${d(i)}/api/0/organizations/${m(s)}/shortids/${encodeURIComponent(e)}/`,{headers:{Authorization:`Bearer ${t}`}});if(!r.ok){let u=await r.text().catch(()=>"");throw new Error(`Sentry API ${r.status} resolving shortId "${e}": ${u.slice(0,200)}`)}let o=await r.json(),a=o.groupId||o.group&&o.group.id;if(!a)throw new Error(`Sentry shortId "${e}" did not resolve to a numeric issue id`);return String(a)}async function b(n){if(!n)throw new Error("sentryGetIssue: issueId is required");let e=await p(n),{token:t,baseUrl:s}=await c("sentry"),i=await fetch(`${d(s)}/api/0/issues/${e}/`,{headers:{Authorization:`Bearer ${t}`}});if(!i.ok){let r=await i.text().catch(()=>"");throw new Error(`Sentry API ${i.status}: ${r.slice(0,300)}`)}return i.json()}async function v(n,e={}){if(!n)throw new Error("sentryUpdateIssue: issueId is required");let t={};for(let a of["status","statusDetails","assignedTo","isBookmarked","hasSeen"])e[a]!==void 0&&(t[a]=e[a]);if(Object.keys(t).length===0)throw new Error("sentryUpdateIssue: nothing to update (pass status / statusDetails / assignedTo / isBookmarked / hasSeen)");let s=await p(n),{token:i,baseUrl:r}=await c("sentry"),o=await fetch(`${d(r)}/api/0/issues/${s}/`,{method:"PUT",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"},body:JSON.stringify(t)});if(!o.ok){let a=await o.text().catch(()=>"");throw o.status===403?new Error(`Sentry API 403 updating issue ${n}: ${a.slice(0,200)}. The connected Sentry integration likely lacks the \`event:write\` scope \u2014 reconnect Sentry with write access to let Zibby resolve/comment on issues.`):new Error(`Sentry API ${o.status} updating issue ${n}: ${a.slice(0,300)}`)}return o.json()}async function N(n,e){if(!n)throw new Error("sentryAddComment: issueId is required");if(!e||!String(e).trim())throw new Error("sentryAddComment: text is required");let t=await p(n),{token:s,baseUrl:i}=await c("sentry"),r=await fetch(`${d(i)}/api/0/issues/${t}/comments/`,{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify({text:String(e)})});if(!r.ok){let o=await r.text().catch(()=>"");throw r.status===403?new Error(`Sentry API 403 commenting on issue ${n}: ${o.slice(0,200)}. The connected Sentry integration likely lacks the \`event:write\` scope \u2014 reconnect Sentry with write access.`):new Error(`Sentry API ${r.status} commenting on issue ${n}: ${o.slice(0,300)}`)}return r.json()}var y={id:"sentry",serverName:"sentry",allowedTools:["mcp__sentry__*"],requiresIntegration:l.SENTRY,description:"Sentry error tracking \u2014 projects, issues, events",envKeys:[],tools:[],promptFragment:`## Sentry
|
|
2
2
|
You have access to the user's Sentry. Use these tools:
|
|
3
3
|
- sentry_list_projects: List projects in the organization
|
|
4
4
|
- sentry_list_issues: List errors/issues (supports Sentry search query, project filter, sort)
|
package/dist/slack.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{existsSync as h}from"fs";import{fileURLToPath as g}from"url";import{dirname as k,resolve as f}from"path";import{resolveIntegrationToken as y}from"@zibby/core/backend-client.js";var _=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),S=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});function b(){if(process.env.MCP_SLACK_PATH)return process.env.MCP_SLACK_PATH;let a=k(g(import.meta.url)),t=f(a,"..","bin","mcp-slack.mjs");return h(t)?t:null}async function n(a,t={}){let{token:e}=await y("slack"),i=["conversations.list","users.list","users.profile.get","users.lookupByEmail","usergroups.list","usergroups.users.list","conversations.history","conversations.replies"].includes(a),c=`https://slack.com/api/${a}`,o={Authorization:`Bearer ${e}`},d;if(i){let s=new URLSearchParams(t).toString();s&&(c+=`?${s}`)}else o["Content-Type"]="application/json; charset=utf-8",d=JSON.stringify(t);let r=await(await fetch(c,{method:i?"GET":"POST",headers:o,body:d})).json();if(!r.ok)throw new Error(`Slack API error: ${r.error}`);return r}var w={id:"slack",serverName:"slack",allowedTools:["mcp__slack__*"],requiresIntegration:_.SLACK,envKeys:["SLACK_BOT_TOKEN","SLACK_TEAM_ID"],description:"Slack MCP Server",promptFragment:`## Slack
|
|
1
|
+
import{existsSync as h}from"fs";import{fileURLToPath as g}from"url";import{dirname as k,resolve as f}from"path";import{resolveIntegrationToken as y}from"@zibby/core/backend-client.js";var _=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),S=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});function b(){if(process.env.MCP_SLACK_PATH)return process.env.MCP_SLACK_PATH;let a=k(g(import.meta.url)),t=f(a,"..","bin","mcp-slack.mjs");return h(t)?t:null}async function n(a,t={}){let{token:e}=await y("slack"),i=["conversations.list","users.list","users.profile.get","users.lookupByEmail","usergroups.list","usergroups.users.list","conversations.history","conversations.replies"].includes(a),c=`https://slack.com/api/${a}`,o={Authorization:`Bearer ${e}`},d;if(i){let s=new URLSearchParams(t).toString();s&&(c+=`?${s}`)}else o["Content-Type"]="application/json; charset=utf-8",d=JSON.stringify(t);let r=await(await fetch(c,{method:i?"GET":"POST",headers:o,body:d})).json();if(!r.ok)throw new Error(`Slack API error: ${r.error}`);return r}var w={id:"slack",serverName:"slack",allowedTools:["mcp__slack__*"],requiresIntegration:_.SLACK,envKeys:["SLACK_BOT_TOKEN","SLACK_TEAM_ID"],description:"Slack MCP Server",promptFragment:`## Slack
|
|
2
2
|
You have access to the user's Slack workspace. Use these tools:
|
|
3
3
|
- slack_list_channels, slack_post_message, slack_reply_to_thread
|
|
4
4
|
- slack_add_reaction, slack_get_channel_history, slack_get_thread_replies
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{existsSync as X}from"fs";import{fileURLToPath as ee}from"url";import{dirname as te,resolve as re}from"path";import{resolveIntegrationToken as j}from"@zibby/core/backend-client.js";var
|
|
1
|
+
import{existsSync as X}from"fs";import{fileURLToPath as ee}from"url";import{dirname as te,resolve as re}from"path";import{resolveIntegrationToken as j}from"@zibby/core/backend-client.js";var I=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),pe=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},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 ue,execSync as de}from"child_process";import{existsSync as ge,mkdirSync as he,readdirSync as ye,statSync as be,readFileSync as fe}from"fs";import{resolve as we,join as Se,basename as Re}from"path";function G(p,o,t,r,i="clone"){try{p(`git -C "${o}" remote set-url origin "${t}"`,{stdio:"pipe"})}catch(e){let n=String(e?.message||e);r&&(n=n.split(r).join("***")),console.error(`[${i}] WARNING: failed to strip token from .git/config: ${n}`)}}import Q from"crypto";var q=/<!--\s*zbfp:([a-f0-9]{8,20})\s*-->/i,L=/<!--\s*zbreview-summary\s*-->/i;function Y(p){return String(p||"").replace(q,"").replace(L,"").replace(/\b(?:lines?|L)\s*#?\d+(?:\s*[-–]\s*\d+)?/gi,"").replace(/[`*_>#~]/g,"").replace(/\s+/g," ").trim().toLowerCase().slice(0,400)}function V(p,o){return Q.createHash("sha256").update(`${String(p||"")}\0${Y(o)}`).digest("hex").slice(0,12)}function Z(p){return`
|
|
2
2
|
|
|
3
|
-
<!-- zbfp:${p} -->`}var
|
|
3
|
+
<!-- zbfp:${p} -->`}var x=`
|
|
4
4
|
|
|
5
|
-
<!-- zbreview-summary -->`;function H(p){let o=q.exec(String(p||""));return o?o[1].toLowerCase():null}function J(p){return
|
|
5
|
+
<!-- zbreview-summary -->`;function H(p){let o=q.exec(String(p||""));return o?o[1].toLowerCase():null}function J(p){return L.test(String(p||""))}function U(p,o){let t=new Set([...o||[]].map(e=>String(e).toLowerCase())),r=[],i=0;for(let e of Array.isArray(p)?p:[]){if(!e||!e.body)continue;let n=V(e.path,e.body);if(t.has(n)){i+=1;continue}t.add(n),r.push({...e,_fp:n,body:`${String(e.body)}${Z(n)}`})}return{toPost:r,skipped:i}}function ne(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let p=te(ee(import.meta.url)),o=re(p,"..","bin","mcp-skill.mjs");return X(o)?o:null}async function u(p,o={}){let{token:t}=await j("github"),r=p.startsWith("https://")?p:`https://api.github.com${p}`,i={Authorization:`Bearer ${t}`,Accept:o.accept||"application/vnd.github.v3+json","User-Agent":"Zibby-App",...o.body?{"Content-Type":"application/json"}:{}},e=await fetch(r,{method:o.method||"GET",headers:i,body:o.body?JSON.stringify(o.body):void 0});if(!e.ok){let n=await e.text().catch(()=>"");throw new Error(`GitHub API ${e.status}: ${n.slice(0,300)}`)}return o.raw?e.text():e.json()}var R={id:"github",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 p=ie();if(!p)return{command:null,args:[],env:{},description:this.description};let o={};for(let t of this.envKeys)process.env[t]&&(o[t]=process.env[t]);return{type:"stdio",command:"node",args:[p,"../dist/github.js","githubSkill"],env:o,description:this.description,alwaysLoad:!0}},async handleToolCall(p,o){try{switch(p){case"github_search_issues":{let t=o.query;if(!t)return JSON.stringify({error:"query is required"});let r=await u(`/search/issues?q=${encodeURIComponent(t)}&per_page=${o.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=o.query;if(!t)return JSON.stringify({error:"query is required"});let r=o.repo?`+repo:${o.repo}`:"",n=o.language?`+language:${o.language}`:"",e=await u(`/search/code?q=${encodeURIComponent(t)}${r}${n}&per_page=${o.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}=o;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}=o;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}=o;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}=o;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(a=>({type:"review",user:a.user?.login,body:a.body?.slice(0,1e3),path:a.path,line:a.line,createdAt:a.created_at})),...i.map(a=>({type:"issue",user:a.user?.login,body:a.body?.slice(0,1e3),createdAt:a.created_at}))].sort((a,g)=>new Date(a.createdAt)-new Date(g.createdAt));return JSON.stringify({total:s.length,comments:s})}case"github_get_review_thread":{let{owner:t,repo:r,number:n,commentId:e}=o||{};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,a=[];try{a=await u(`/repos/${t}/${r}/pulls/${n}/comments?per_page=100`)}catch{a=[i]}(!Array.isArray(a)||a.length===0)&&(a=[i]);let g=a.filter(h=>h.id===s||h.in_reply_to_id===s).sort((h,y)=>new Date(h.created_at)-new Date(y.created_at)),d=g.length?g:[i],l=d.find(h=>h.id===s)||d[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:d.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}=o||{};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}=o||{};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}=o||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let a=(i||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(a))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${i})`});let g=Array.isArray(s)?s.filter(m=>m&&m.path&&m.body&&(m.line!=null||m.position!=null)).map(m=>{let c={path:m.path,body:String(m.body)};return m.line!=null?(c.line=Number(m.line),c.side=m.side==="LEFT"?"LEFT":"RIGHT"):c.position=Number(m.position),c}):[];if(a!=="APPROVE"&&!e&&g.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 m=1;m<=20;m+=1){let c=await u(`/repos/${t}/${r}/pulls/${n}/comments?per_page=100&page=${m}`);if(!Array.isArray(c)||c.length===0)break;for(let f of c){let $=H(f.body);$&&d.add($)}if(c.length<100)break}for(let m=1;m<=20&&l==null;m+=1){let c=await u(`/repos/${t}/${r}/issues/${n}/comments?per_page=100&page=${m}`);if(!Array.isArray(c)||c.length===0)break;for(let f of c)if(J(f.body)){l=f.id;break}if(c.length<100)break}}catch{}let h=!1,y=!1;if(e){let m=`${String(e)}${L}`;try{l!=null?(await u(`/repos/${t}/${r}/issues/comments/${l}`,{method:"PATCH",body:{body:m}}),h=!0):await u(`/repos/${t}/${r}/issues/${n}/comments`,{method:"POST",body:{body:m}}),y=!0}catch{}}let{toPost:b,skipped:w}=U(g,d),_=b.map(({_fp:m,...c})=>c),S=null;if(_.length>0||a==="APPROVE"||a==="REQUEST_CHANGES"){let m={event:a};_.length>0&&(m.comments=_),_.length===0&&a==="REQUEST_CHANGES"&&(m.body="Changes requested \u2014 see the review summary comment."),S=await u(`/repos/${t}/${r}/pulls/${n}/reviews`,{method:"POST",body:m})}return JSON.stringify({ok:!0,id:S?S.id:void 0,state:S?S.state:void 0,event:a,notePosted:y,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:a,page:g}=o;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(g)||1}`;n&&(l+=`&sha=${encodeURIComponent(n)}`),e&&(l+=`&path=${encodeURIComponent(e)}`),s&&(l+=`&since=${encodeURIComponent(s)}`),a&&(l+=`&until=${encodeURIComponent(a)}`);let h=await u(l);return JSON.stringify({total:h.length,page:Number(g)||1,hasMore:h.length>=d,commits:h.map(y=>({sha:y.sha?.slice(0,8),fullSha:y.sha,message:y.commit?.message?.slice(0,300),author:y.commit?.author?.name,authorEmail:y.commit?.author?.email,date:y.commit?.author?.date,url:y.html_url}))})}case"github_get_commit":{let{owner:t,repo:r,sha:n,includePrs:e}=o;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 a=await u(`/repos/${t}/${r}/commits/${n}/pulls`);s=(Array.isArray(a)?a:[]).map(g=>({number:g.number,title:g.title,state:g.state,merged:!!g.merged_at,webUrl:g.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(a=>({filename:a.filename,status:a.status,additions:a.additions,deletions:a.deletions,patch:a.patch?.slice(0,3e3)})),...s?{pullRequests:s}:{}})}case"github_get_file":{let{owner:t,repo:r,path:n,ref:e}=o;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(d=>({name:d.name,type:d.type,size:d.size,path:d.path}))}):JSON.stringify({error:`Not a file: ${s.type}`});let a=Buffer.from(s.content||"","base64").toString("utf-8"),g=a.length>2e4;return JSON.stringify({path:s.path,size:s.size,sha:s.sha?.slice(0,8),content:g?a.slice(0,2e4):a,truncated:g})}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 b=function(m){let c=m.replace(/^~(?=$|\/|\\)/,y);return s(c)},{owner:t,repo:r,destination:n}=o;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:a,mkdirSync:g}=await import("fs"),{homedir:d,platform:l}=await import("os"),{token:h}=await j("github"),y=d(),w=n?b(n):i(y,"zibby-repos"),_=i(w,r);if(g(w,{recursive:!0}),a(_))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 m=`https://github.com/${t}/${r}.git`;I(e,_,m,h,"github_clone");let c=l()==="win32",f;return c?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 p=ne();if(!p)return{command:null,args:[],env:{},description:this.description};let o={};for(let t of this.envKeys)process.env[t]&&(o[t]=process.env[t]);return{type:"stdio",command:"node",args:[p,"../dist/github.js","githubSkill"],env:o,description:this.description,alwaysLoad:!0}},async handleToolCall(p,o){try{switch(p){case"github_search_issues":{let t=o.query;if(!t)return JSON.stringify({error:"query is required"});let r=await u(`/search/issues?q=${encodeURIComponent(t)}&per_page=${o.limit||20}`),i=(r.items||[]).map(e=>({number:e.number,title:e.title,state:e.state,repo:e.repository_url?.split("/").slice(-2).join("/"),url:e.html_url,user:e.user?.login,isPR:!!e.pull_request,labels:(e.labels||[]).map(n=>n.name),createdAt:e.created_at}));return JSON.stringify({total:r.total_count,items:i})}case"github_search_code":{let t=o.query;if(!t)return JSON.stringify({error:"query is required"});let r=o.repo?`+repo:${o.repo}`:"",i=o.language?`+language:${o.language}`:"",e=await u(`/search/code?q=${encodeURIComponent(t)}${r}${i}&per_page=${o.limit||15}`),n=(e.items||[]).map(s=>({name:s.name,path:s.path,repo:s.repository?.full_name,url:s.html_url,score:s.score}));return JSON.stringify({total:e.total_count,items:n})}case"github_get_pr":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/pulls/${i}`);return JSON.stringify({number:e.number,title:e.title,state:e.state,merged:e.merged,body:e.body?.slice(0,5e3),user:e.user?.login,branch:e.head?.ref,headSha:e.head?.sha,base:e.base?.ref,changedFiles:e.changed_files,additions:e.additions,deletions:e.deletions,createdAt:e.created_at,mergedAt:e.merged_at,url:e.html_url,labels:(e.labels||[]).map(n=>n.name)})}case"github_get_pr_diff":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/pulls/${i}`,{accept:"application/vnd.github.v3.diff",raw:!0}),n=e.length>15e3;return JSON.stringify({number:i,diff:n?e.slice(0,15e3):e,truncated:n,totalLength:e.length})}case"github_list_pr_files":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/pulls/${i}/files?per_page=100`);return JSON.stringify({total:e.length,files:e.map(n=>({filename:n.filename,status:n.status,additions:n.additions,deletions:n.deletions,patch:n.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/pulls/${i}/comments?per_page=50`),n=await u(`/repos/${t}/${r}/issues/${i}/comments?per_page=50`),s=[...e.map(a=>({type:"review",user:a.user?.login,body:a.body?.slice(0,1e3),path:a.path,line:a.line,createdAt:a.created_at})),...n.map(a=>({type:"issue",user:a.user?.login,body:a.body?.slice(0,1e3),createdAt:a.created_at}))].sort((a,g)=>new Date(a.createdAt)-new Date(g.createdAt));return JSON.stringify({total:s.length,comments:s})}case"github_get_review_thread":{let{owner:t,repo:r,number:i,commentId:e}=o||{};if(!t||!r||!i||!e)return JSON.stringify({error:"owner, repo, number, and commentId are required"});let n=await u(`/repos/${t}/${r}/pulls/comments/${e}`),s=n.in_reply_to_id||n.id,a=[];try{a=await u(`/repos/${t}/${r}/pulls/${i}/comments?per_page=100`)}catch{a=[n]}(!Array.isArray(a)||a.length===0)&&(a=[n]);let g=a.filter(h=>h.id===s||h.in_reply_to_id===s).sort((h,b)=>new Date(h.created_at)-new Date(b.created_at)),d=g.length?g:[n],l=d.find(h=>h.id===s)||d[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:d.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:i,commentId:e,body:n}=o||{};if(!t||!r||!i||!e||!n)return JSON.stringify({error:"owner, repo, number, commentId, and body are required"});let s=await u(`/repos/${t}/${r}/pulls/${i}/comments/${e}/replies`,{method:"POST",body:{body:String(n)}});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:i,body:e}=o||{};if(!t||!r||!i||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let n=await u(`/repos/${t}/${r}/issues/${i}/comments`,{method:"POST",body:{body:String(e)}});return JSON.stringify({ok:!0,id:n.id,url:n.html_url})}case"github_create_review":{let{owner:t,repo:r,number:i,body:e,event:n,comments:s}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let a=(n||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(a))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${n})`});let g=Array.isArray(s)?s.filter(m=>m&&m.path&&m.body&&(m.line!=null||m.position!=null)).map(m=>{let c={path:m.path,body:String(m.body)};return m.line!=null?(c.line=Number(m.line),c.side=m.side==="LEFT"?"LEFT":"RIGHT"):c.position=Number(m.position),c}):[];if(a!=="APPROVE"&&!e&&g.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 m=1;m<=20;m+=1){let c=await u(`/repos/${t}/${r}/pulls/${i}/comments?per_page=100&page=${m}`);if(!Array.isArray(c)||c.length===0)break;for(let f of c){let $=H(f.body);$&&d.add($)}if(c.length<100)break}for(let m=1;m<=20&&l==null;m+=1){let c=await u(`/repos/${t}/${r}/issues/${i}/comments?per_page=100&page=${m}`);if(!Array.isArray(c)||c.length===0)break;for(let f of c)if(J(f.body)){l=f.id;break}if(c.length<100)break}}catch{}let h=!1,b=!1;if(e){let m=`${String(e)}${x}`;try{l!=null?(await u(`/repos/${t}/${r}/issues/comments/${l}`,{method:"PATCH",body:{body:m}}),h=!0):await u(`/repos/${t}/${r}/issues/${i}/comments`,{method:"POST",body:{body:m}}),b=!0}catch{}}let{toPost:y,skipped:w}=U(g,d),_=y.map(({_fp:m,...c})=>c),S=null;if(_.length>0||a==="APPROVE"||a==="REQUEST_CHANGES"){let m={event:a};_.length>0&&(m.comments=_),_.length===0&&a==="REQUEST_CHANGES"&&(m.body="Changes requested \u2014 see the review summary comment."),S=await u(`/repos/${t}/${r}/pulls/${i}/reviews`,{method:"POST",body:m})}return JSON.stringify({ok:!0,id:S?S.id:void 0,state:S?S.state:void 0,event:a,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:i,path:e,limit:n,since:s,until:a,page:g}=o;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let d=Math.min(Number(n)||20,100),l=`/repos/${t}/${r}/commits?per_page=${d}&page=${Number(g)||1}`;i&&(l+=`&sha=${encodeURIComponent(i)}`),e&&(l+=`&path=${encodeURIComponent(e)}`),s&&(l+=`&since=${encodeURIComponent(s)}`),a&&(l+=`&until=${encodeURIComponent(a)}`);let h=await u(l);return JSON.stringify({total:h.length,page:Number(g)||1,hasMore:h.length>=d,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:i,includePrs:e}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and sha are required"});let n=await u(`/repos/${t}/${r}/commits/${i}`),s;if(e)try{let a=await u(`/repos/${t}/${r}/commits/${i}/pulls`);s=(Array.isArray(a)?a:[]).map(g=>({number:g.number,title:g.title,state:g.state,merged:!!g.merged_at,webUrl:g.html_url}))}catch{s=[]}return JSON.stringify({sha:n.sha?.slice(0,8),message:n.commit?.message,author:n.commit?.author?.name,date:n.commit?.author?.date,stats:n.stats,files:(n.files||[]).map(a=>({filename:a.filename,status:a.status,additions:a.additions,deletions:a.deletions,patch:a.patch?.slice(0,3e3)})),...s?{pullRequests:s}:{}})}case"github_get_file":{let{owner:t,repo:r,path:i,ref:e}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and path are required"});let n=`/repos/${t}/${r}/contents/${encodeURIComponent(i)}`;e&&(n+=`?ref=${encodeURIComponent(e)}`);let s=await u(n);if(s.type!=="file")return Array.isArray(s)?JSON.stringify({type:"directory",path:i,entries:s.map(d=>({name:d.name,type:d.type,size:d.size,path:d.path}))}):JSON.stringify({error:`Not a file: ${s.type}`});let a=Buffer.from(s.content||"","base64").toString("utf-8"),g=a.length>2e4;return JSON.stringify({path:s.path,size:s.size,sha:s.sha?.slice(0,8),content:g?a.slice(0,2e4):a,truncated:g})}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],i=r.owner.login,e=r.owner.type,n=e==="Organization"?`/orgs/${i}`:`/users/${i}`,s=await u(n);return JSON.stringify({login:s.login,name:s.name||s.login,avatar:s.avatar_url,bio:s.bio||s.description,type:e,isOrg:e==="Organization",publicRepos:s.public_repos,message:"Showing GitHub App installation owner (GitHub Apps cannot access /user endpoint)"})}return JSON.stringify({error:"No repositories accessible to this GitHub App installation"})}catch(t){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${t.message})`})}case"github_list_orgs":try{let r=(await u("/installation/repositories?per_page=100")).repositories||[],i=new Map;for(let n of r)n.owner.type==="Organization"&&(i.has(n.owner.login)||i.set(n.owner.login,{login:n.owner.login,description:null,url:n.owner.url}));let e=Array.from(i.values());return JSON.stringify({count:e.length,orgs:e,message:"Extracted from accessible repositories (GitHub Apps cannot access /user/orgs directly)"})}catch(t){return JSON.stringify({error:`GitHub App cannot list orgs via /user/orgs. Error: ${t.message}`})}case"github_clone":{let y=function(m){let c=m.replace(/^~(?=$|\/|\\)/,b);return s(c)},{owner:t,repo:r,destination:i}=o;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let{execSync:e}=await import("child_process"),{join:n,resolve:s}=await import("path"),{existsSync:a,mkdirSync:g}=await import("fs"),{homedir:d,platform:l}=await import("os"),{token:h}=await j("github"),b=d(),w=i?y(i):n(b,"zibby-repos"),_=n(w,r);if(g(w,{recursive:!0}),a(_))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 m=`https://github.com/${t}/${r}.git`;G(e,_,m,h,"github_clone");let c=l()==="win32",f;return c?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(`
|
|
49
49
|
`).slice(0,30).join(`
|
|
50
|
-
`),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(m){let f=String(m.message||m).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}=o;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(a=>a.name.toLowerCase().includes(i)||a.fullName.toLowerCase().includes(i)||a.description&&a.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}=o,a=100,g=i||200,d=[],l=c=>({name:c.name,fullName:c.full_name,private:c.private,description:c.description,language:c.language,defaultBranch:c.default_branch,updatedAt:c.updated_at,stars:c.stargazers_count,url:c.html_url,fullPath:c.full_name,webUrl:c.html_url,visibility:c.visibility||(c.private?"private":"public")}),h=c=>{if(!s)return!0;let f=String(s).toLowerCase();return c.name&&c.name.toLowerCase().includes(f)||c.fullName&&c.fullName.toLowerCase().includes(f)||c.description&&c.description.toLowerCase().includes(f)};if(!t){let c=1,f=!0;for(;f&&d.length<g;){let N=`/installation/repositories?per_page=${a}&page=${c}`,P=(await u(N)).repositories||[];if(P.length===0)break;d=d.concat(P),f=P.length===a,c++}let $=d.map(l).filter(h),k=$.slice(0,g),W=$.length>k.length,T=k.filter(N=>N.private).length,C=k.filter(N=>!N.private).length;return JSON.stringify({count:k.length,repos:k,truncated:W,privateCount:T,publicCount:C,message:`Found ${T} private and ${C} public repos`})}let y=await u(`/orgs/${t}`).then(()=>!0).catch(()=>!1),b=1,w=!0;for(;w&&d.length<g;){let c;y?c=`/orgs/${t}/repos?per_page=${a}&page=${b}&type=${r||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`:c=`/users/${t}/repos?per_page=${a}&page=${b}&type=${r||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`;let f=await u(c),$=Array.isArray(f)?f:[];if($.length===0)break;d=d.concat($),w=$.length===a,b++}let _=d.map(l).filter(h),S=_.slice(0,g),m=_.length>S.length;return JSON.stringify({count:S.length,repos:S,truncated:m})}case"github_create_pr":{let{owner:t,repo:r,head:n,title:e}=o||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, head (source branch), and title are required"});let i=o.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:o.body?String(o.body):"",draft:!!o.draft};try{let a=await u(`/repos/${t}/${r}/pulls`,{method:"POST",body:s});return JSON.stringify({success:!0,pr_url:a.html_url,number:a.number,branch:n,base:i,repo:`${t}/${r}`,provider:"github",draft:!!a.draft,state:a.state})}catch(a){let g=String(a.message||a);if(/GitHub API 422/.test(g))return JSON.stringify({success:!1,branch:n,base:i,repo:`${t}/${r}`,provider:"github",skippedReason:g});throw a}}case"github_merge_pr":{let{owner:t,repo:r,number:n}=o||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=o.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};o.commitTitle&&(i.commit_title=String(o.commitTitle)),o.commitMessage&&(i.commit_message=String(o.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 a=String(s.message||s);if(/GitHub API (405|409|404)/.test(a))return JSON.stringify({success:!1,number:n,provider:"github",skippedReason:a});throw s}}case"github_create_issue":{let{owner:t,repo:r,title:n,body:e}=o;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:a,direction:g,limit:d}=o||{};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",a||"updated"),l.set("direction",g||"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()}`),y=(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:y.length,issues:y})}case"github_get_issue":{let{owner:t,repo:r,number:n}=o||{};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}=o||{};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(a=>({id:a.id,user:a.user?.login,body:a.body||"",createdAt:a.created_at,updatedAt:a.updated_at,url:a.html_url}));return JSON.stringify({count:s.length,comments:s})}case"github_add_issue_comment":{let{owner:t,repo:r,number:n,body:e}=o||{};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}=o||{};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}=o||{};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}=o||{};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 a=i||"add";if(a==="set"){let d=await u(`/repos/${t}/${r}/issues/${n}`,{method:"PATCH",body:{labels:s}});return JSON.stringify({ok:!0,number:d.number,labels:(d.labels||[]).map(l=>typeof l=="string"?l:l.name)})}if(a==="remove"){for(let l of s)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 g=await u(`/repos/${t}/${r}/issues/${n}/labels`,{method:"POST",body:{labels:s}});return JSON.stringify({ok:!0,number:n,labels:(Array.isArray(g)?g:[]).map(d=>typeof d=="string"?d:d.name)})}default:return JSON.stringify({error:`Unknown tool: ${p}`})}}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"]}}]};var F=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i,z=/\b(in[\s-]?progress|wip|doing|started|in[\s-]?review|review)\b/i,ne=/\b(done|closed|complete|completed|resolved|fixed|merged|shipped)\b/i,oe=/\b(todo|to[\s-]?do|open|backlog|reopen|new)\b/i,M="in progress",D="blocked";function K(p,o=[]){if(p==="closed")return"done";if(p!=="open")return"unknown";let t=(o||[]).map(String);return t.some(r=>F.test(r))?"blocked":t.some(r=>z.test(r))?"in_progress":"todo"}function v(p={}){let o=p.owner||process.env.GITHUB_OWNER,t=p.repo||process.env.GITHUB_REPO;if(!o||!t)throw new Error("GitHub scope missing: provide {owner, repo} via ctx or env GITHUB_OWNER / GITHUB_REPO.");return{owner:o,repo:t}}function O(p){let o=JSON.parse(p);if(o&&o.error)throw new Error(o.error);return o}function E(p,o={}){let t=p.labels||[],r=p.number,n=o.owner&&o.repo?`${o.owner}/${o.repo}#${r}`:`#${r}`;return{id:String(r),key:n,title:p.title||"",body:p.body||"",state:p.state||null,stateCategory:K(p.state,t),assignee:p.assignee||p.assignees&&p.assignees[0]||null,url:p.url||null,_raw:p}}var se={id:"github",toStateCategory:K,toNeutral:E,IN_PROGRESS_LABEL:M,BLOCKED_LABEL:D,async listCandidates(p={}){let o=p.ctx||{},{owner:t,repo:r}=v(o);return(O(await R.handleToolCall("github_list_issues",{owner:t,repo:r,state:p.state||"open",labels:p.labels,since:p.updatedAfter,limit:p.limit})).issues||[]).map(e=>E(e,{owner:t,repo:r}))},async getTicket(p,o={}){let{owner:t,repo:r}=v(o),n=A(p);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);let e=JSON.parse(await R.handleToolCall("github_get_issue",{owner:t,repo:r,number:n}));return e.error?null:E(e,{owner:t,repo:r})},async getComments(p,o={}){let{owner:t,repo:r}=v(o),n=A(p);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);return(O(await R.handleToolCall("github_get_issue_comments",{owner:t,repo:r,number:n})).comments||[]).map(i=>({id:String(i.id),author:i.user||"Unknown",body:i.body||"",createdAt:i.createdAt||null,updatedAt:i.updatedAt||null,_raw:i})).sort((i,s)=>String(s.createdAt).localeCompare(String(i.createdAt)))},async addComment(p,o,t={}){let{owner:r,repo:n}=v(t),e=A(p);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);if(!o)throw new Error("body is required");let i=O(await R.handleToolCall("github_add_issue_comment",{owner:r,repo:n,number:e,body:o}));return{ok:!!i.ok,id:i.id?String(i.id):null}},async transition(p,o,t={}){let{owner:r,repo:n}=v(t),e=A(p);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);let i=String(o||"");if(ne.test(i)){let s=O(await R.handleToolCall("github_close_issue",{owner:r,repo:n,number:e,stateReason:"completed"}));return{ok:!!s.ok,stateAfter:s.state||"closed",stateCategoryAfter:"done",_raw:s}}if(F.test(i)){await B(r,n,e);let s=O(await R.handleToolCall("github_label_issue",{owner:r,repo:n,number:e,labels:[D],mode:"add"}));return{ok:!!s.ok,stateAfter:"open",stateCategoryAfter:"blocked",via:"label",_raw:s}}if(z.test(i)){await B(r,n,e);let s=O(await R.handleToolCall("github_label_issue",{owner:r,repo:n,number:e,labels:[M],mode:"add"}));return{ok:!!s.ok,stateAfter:"open",stateCategoryAfter:"in_progress",via:"label",_raw:s}}if(oe.test(i)){let s=O(await R.handleToolCall("github_reopen_issue",{owner:r,repo:n,number:e}));return{ok:!!s.ok,stateAfter:s.state||"open",stateCategoryAfter:"todo",_raw:s}}return{ok:!1,error:`GitHub issues have no "${o}" state. Representable targets: open/todo, in progress, blocked, done/closed.`}},async linkPullRequest(p,o,t,r={}){let{owner:n,repo:e}=v(r),i=A(p);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);if(!o)throw new Error("prUrl is required");let s=`${t?`${t}: `:"Linked PR: "}${o}`;return{ok:!!O(await R.handleToolCall("github_add_issue_comment",{owner:n,repo:e,number:i,body:s})).ok,via:"comment"}}};async function B(p,o,t){await R.handleToolCall("github_reopen_issue",{owner:p,repo:o,number:t})}function A(p){if(p==null)return null;if(typeof p=="number")return p;let o=/(\d+)\s*$/.exec(String(p));return o?Number(o[1]):null}var qe=se;export{qe as default,se as githubAdapter};
|
|
50
|
+
`),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(m){let f=String(m.message||m).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}=o;if(!t)return JSON.stringify({error:"query is required"});let i=await this.handleToolCall("github_list_repos",{limit:200},{}),e=JSON.parse(i);if(e.error)return JSON.stringify(e);let n=t.toLowerCase(),s=e.repos.filter(a=>a.name.toLowerCase().includes(n)||a.fullName.toLowerCase().includes(n)||a.description&&a.description.toLowerCase().includes(n));return JSON.stringify({query:t,count:s.length,repos:s.slice(0,r||20)})}case"github_list_repos":{let{owner:t,type:r,sort:i,direction:e,limit:n,query:s}=o,a=100,g=n||200,d=[],l=c=>({name:c.name,fullName:c.full_name,private:c.private,description:c.description,language:c.language,defaultBranch:c.default_branch,updatedAt:c.updated_at,stars:c.stargazers_count,url:c.html_url,fullPath:c.full_name,webUrl:c.html_url,visibility:c.visibility||(c.private?"private":"public")}),h=c=>{if(!s)return!0;let f=String(s).toLowerCase();return c.name&&c.name.toLowerCase().includes(f)||c.fullName&&c.fullName.toLowerCase().includes(f)||c.description&&c.description.toLowerCase().includes(f)};if(!t){let c=1,f=!0;for(;f&&d.length<g;){let k=`/installation/repositories?per_page=${a}&page=${c}`,P=(await u(k)).repositories||[];if(P.length===0)break;d=d.concat(P),f=P.length===a,c++}let $=d.map(l).filter(h),N=$.slice(0,g),W=$.length>N.length,T=N.filter(k=>k.private).length,C=N.filter(k=>!k.private).length;return JSON.stringify({count:N.length,repos:N,truncated:W,privateCount:T,publicCount:C,message:`Found ${T} private and ${C} public repos`})}let b=await u(`/orgs/${t}`).then(()=>!0).catch(()=>!1),y=1,w=!0;for(;w&&d.length<g;){let c;b?c=`/orgs/${t}/repos?per_page=${a}&page=${y}&type=${r||"all"}&sort=${i||"updated"}&direction=${e||"desc"}`:c=`/users/${t}/repos?per_page=${a}&page=${y}&type=${r||"all"}&sort=${i||"updated"}&direction=${e||"desc"}`;let f=await u(c),$=Array.isArray(f)?f:[];if($.length===0)break;d=d.concat($),w=$.length===a,y++}let _=d.map(l).filter(h),S=_.slice(0,g),m=_.length>S.length;return JSON.stringify({count:S.length,repos:S,truncated:m})}case"github_create_pr":{let{owner:t,repo:r,head:i,title:e}=o||{};if(!t||!r||!i||!e)return JSON.stringify({error:"owner, repo, head (source branch), and title are required"});let n=o.base;if(!n)try{n=(await u(`/repos/${t}/${r}`)).default_branch||"main"}catch{n="main"}let s={title:String(e),head:String(i),base:String(n),body:o.body?String(o.body):"",draft:!!o.draft};try{let a=await u(`/repos/${t}/${r}/pulls`,{method:"POST",body:s});return JSON.stringify({success:!0,pr_url:a.html_url,number:a.number,branch:i,base:n,repo:`${t}/${r}`,provider:"github",draft:!!a.draft,state:a.state})}catch(a){let g=String(a.message||a);if(/GitHub API 422/.test(g))return JSON.stringify({success:!1,branch:i,base:n,repo:`${t}/${r}`,provider:"github",skippedReason:g});throw a}}case"github_merge_pr":{let{owner:t,repo:r,number:i}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=o.mergeMethod||"squash";if(!["merge","squash","rebase"].includes(e))return JSON.stringify({error:`mergeMethod must be merge, squash, or rebase (got ${e})`});let n={merge_method:e};o.commitTitle&&(n.commit_title=String(o.commitTitle)),o.commitMessage&&(n.commit_message=String(o.commitMessage));try{let s=await u(`/repos/${t}/${r}/pulls/${i}/merge`,{method:"PUT",body:n});return JSON.stringify({success:!0,merged:!0,sha:s.sha,number:i,provider:"github"})}catch(s){let a=String(s.message||s);if(/GitHub API (405|409|404)/.test(a))return JSON.stringify({success:!1,number:i,provider:"github",skippedReason:a});throw s}}case"github_create_issue":{let{owner:t,repo:r,title:i,body:e}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and title are required"});let n=await u(`/repos/${t}/${r}/issues`,{method:"POST",body:{title:i,body:e||""}});return JSON.stringify({number:n.number,url:n.html_url,title:n.title})}case"github_list_issues":{let{owner:t,repo:r,state:i,labels:e,since:n,assignee:s,sort:a,direction:g,limit:d}=o||{};if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let l=new URLSearchParams;l.set("state",i||"open"),l.set("per_page",String(d||30)),l.set("sort",a||"updated"),l.set("direction",g||"desc"),e&&l.set("labels",Array.isArray(e)?e.join(","):e),n&&l.set("since",n),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:i}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/issues/${i}`);return e.pull_request?JSON.stringify({error:`#${i} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:e.number,title:e.title,body:e.body||"",state:e.state,stateReason:e.state_reason||null,labels:(e.labels||[]).map(n=>typeof n=="string"?n:n.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(n=>n.login),user:e.user?.login,milestone:e.milestone?.title||null,comments:e.comments,url:e.html_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"github_get_issue_comments":{let{owner:t,repo:r,number:i,limit:e}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let n=await u(`/repos/${t}/${r}/issues/${i}/comments?per_page=${e||100}`),s=(Array.isArray(n)?n:[]).map(a=>({id:a.id,user:a.user?.login,body:a.body||"",createdAt:a.created_at,updatedAt:a.updated_at,url:a.html_url}));return JSON.stringify({count:s.length,comments:s})}case"github_add_issue_comment":{let{owner:t,repo:r,number:i,body:e}=o||{};if(!t||!r||!i||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let n=await u(`/repos/${t}/${r}/issues/${i}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:n.id,url:n.html_url})}case"github_close_issue":{let{owner:t,repo:r,number:i,stateReason:e}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let n={state:"closed"};e&&(n.state_reason=e);let s=await u(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:n});return JSON.stringify({ok:!0,number:s.number,state:s.state,stateReason:s.state_reason||null,url:s.html_url})}case"github_reopen_issue":{let{owner:t,repo:r,number:i}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await u(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:e.number,state:e.state,url:e.html_url})}case"github_label_issue":{let{owner:t,repo:r,number:i,labels:e,mode:n}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let s=Array.isArray(e)?e:e?[e]:[];if(!s.length)return JSON.stringify({error:"labels (string or array) is required"});let a=n||"add";if(a==="set"){let d=await u(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:{labels:s}});return JSON.stringify({ok:!0,number:d.number,labels:(d.labels||[]).map(l=>typeof l=="string"?l:l.name)})}if(a==="remove"){for(let l of s)await u(`/repos/${t}/${r}/issues/${i}/labels/${encodeURIComponent(l)}`,{method:"DELETE"});let d=await u(`/repos/${t}/${r}/issues/${i}`);return JSON.stringify({ok:!0,number:d.number,labels:(d.labels||[]).map(l=>typeof l=="string"?l:l.name)})}let g=await u(`/repos/${t}/${r}/issues/${i}/labels`,{method:"POST",body:{labels:s}});return JSON.stringify({ok:!0,number:i,labels:(Array.isArray(g)?g:[]).map(d=>typeof d=="string"?d:d.name)})}default:return JSON.stringify({error:`Unknown tool: ${p}`})}}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"]}}]};var F=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i,z=/\b(in[\s-]?progress|wip|doing|started|in[\s-]?review|review)\b/i,ie=/\b(done|closed|complete|completed|resolved|fixed|merged|shipped)\b/i,oe=/\b(todo|to[\s-]?do|open|backlog|reopen|new)\b/i,M="in progress",D="blocked";function K(p,o=[]){if(p==="closed")return"done";if(p!=="open")return"unknown";let t=(o||[]).map(String);return t.some(r=>F.test(r))?"blocked":t.some(r=>z.test(r))?"in_progress":"todo"}function v(p={}){let o=p.owner||process.env.GITHUB_OWNER,t=p.repo||process.env.GITHUB_REPO;if(!o||!t)throw new Error("GitHub scope missing: provide {owner, repo} via ctx or env GITHUB_OWNER / GITHUB_REPO.");return{owner:o,repo:t}}function O(p){let o=JSON.parse(p);if(o&&o.error)throw new Error(o.error);return o}function E(p,o={}){let t=p.labels||[],r=p.number,i=o.owner&&o.repo?`${o.owner}/${o.repo}#${r}`:`#${r}`;return{id:String(r),key:i,title:p.title||"",body:p.body||"",state:p.state||null,stateCategory:K(p.state,t),assignee:p.assignee||p.assignees&&p.assignees[0]||null,url:p.url||null,_raw:p}}var se={id:"github",toStateCategory:K,toNeutral:E,IN_PROGRESS_LABEL:M,BLOCKED_LABEL:D,async listCandidates(p={}){let o=p.ctx||{},{owner:t,repo:r}=v(o);return(O(await R.handleToolCall("github_list_issues",{owner:t,repo:r,state:p.state||"open",labels:p.labels,since:p.updatedAfter,limit:p.limit})).issues||[]).map(e=>E(e,{owner:t,repo:r}))},async getTicket(p,o={}){let{owner:t,repo:r}=v(o),i=A(p);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);let e=JSON.parse(await R.handleToolCall("github_get_issue",{owner:t,repo:r,number:i}));return e.error?null:E(e,{owner:t,repo:r})},async getComments(p,o={}){let{owner:t,repo:r}=v(o),i=A(p);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);return(O(await R.handleToolCall("github_get_issue_comments",{owner:t,repo:r,number:i})).comments||[]).map(n=>({id:String(n.id),author:n.user||"Unknown",body:n.body||"",createdAt:n.createdAt||null,updatedAt:n.updatedAt||null,_raw:n})).sort((n,s)=>String(s.createdAt).localeCompare(String(n.createdAt)))},async addComment(p,o,t={}){let{owner:r,repo:i}=v(t),e=A(p);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);if(!o)throw new Error("body is required");let n=O(await R.handleToolCall("github_add_issue_comment",{owner:r,repo:i,number:e,body:o}));return{ok:!!n.ok,id:n.id?String(n.id):null}},async transition(p,o,t={}){let{owner:r,repo:i}=v(t),e=A(p);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);let n=String(o||"");if(ie.test(n)){let s=O(await R.handleToolCall("github_close_issue",{owner:r,repo:i,number:e,stateReason:"completed"}));return{ok:!!s.ok,stateAfter:s.state||"closed",stateCategoryAfter:"done",_raw:s}}if(F.test(n)){await B(r,i,e);let s=O(await R.handleToolCall("github_label_issue",{owner:r,repo:i,number:e,labels:[D],mode:"add"}));return{ok:!!s.ok,stateAfter:"open",stateCategoryAfter:"blocked",via:"label",_raw:s}}if(z.test(n)){await B(r,i,e);let s=O(await R.handleToolCall("github_label_issue",{owner:r,repo:i,number:e,labels:[M],mode:"add"}));return{ok:!!s.ok,stateAfter:"open",stateCategoryAfter:"in_progress",via:"label",_raw:s}}if(oe.test(n)){let s=O(await R.handleToolCall("github_reopen_issue",{owner:r,repo:i,number:e}));return{ok:!!s.ok,stateAfter:s.state||"open",stateCategoryAfter:"todo",_raw:s}}return{ok:!1,error:`GitHub issues have no "${o}" state. Representable targets: open/todo, in progress, blocked, done/closed.`}},async linkPullRequest(p,o,t,r={}){let{owner:i,repo:e}=v(r),n=A(p);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);if(!o)throw new Error("prUrl is required");let s=`${t?`${t}: `:"Linked PR: "}${o}`;return{ok:!!O(await R.handleToolCall("github_add_issue_comment",{owner:i,repo:e,number:n,body:s})).ok,via:"comment"}}};async function B(p,o,t){await R.handleToolCall("github_reopen_issue",{owner:p,repo:o,number:t})}function A(p){if(p==null)return null;if(typeof p=="number")return p;let o=/(\d+)\s*$/.exec(String(p));return o?Number(o[1]):null}var qe=se;export{qe as default,se as githubAdapter};
|