@zibby/skills 0.1.38 → 0.1.40

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.
@@ -1,22 +1,22 @@
1
- import{createRequire as ge}from"module";import{resolveIntegrationToken as he,clearTokenCache as be}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",PLANE:"plane",LINEAR:"linear"}),it=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"}});var _e=ge(import.meta.url);function we(){if(process.env.MCP_JIRA_PATH)return process.env.MCP_JIRA_PATH;try{return _e.resolve("@zibby/mcp-jira/index.js")}catch{return null}}var Se=new Set(["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","rule","table","tableRow","tableCell","tableHeader","mediaSingle","panel"]);function Ae(r,s){if(!s||!s.length)return r;let e=r;for(let t of s)t.type==="strong"?e=`**${e}**`:t.type==="em"?e=`_${e}_`:t.type==="code"?e=`\`${e}\``:t.type==="strike"?e=`~~${e}~~`:t.type==="link"&&t.attrs?.href&&(e=`[${e}](${t.attrs.href})`);return e}function J(r,s=0){if(!Array.isArray(r))return"";let e=[];for(let t of r){if(t.type==="text"){e.push(Ae(t.text||"",t.marks));continue}if(t.type==="hardBreak"){e.push(`
1
+ import{createRequire as Ae}from"module";import{resolveIntegrationToken as ke,clearTokenCache as Ie}from"@zibby/core/backend-client.js";var T=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",PLANE:"plane",LINEAR:"linear",FIGMA:"figma"}),dt=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"}});var ve=Ae(import.meta.url);function Re(){if(process.env.MCP_JIRA_PATH)return process.env.MCP_JIRA_PATH;try{return ve.resolve("@zibby/mcp-jira/index.js")}catch{return null}}var Ne=new Set(["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","rule","table","tableRow","tableCell","tableHeader","mediaSingle","panel"]);function je(r,s){if(!s||!s.length)return r;let e=r;for(let t of s)t.type==="strong"?e=`**${e}**`:t.type==="em"?e=`_${e}_`:t.type==="code"?e=`\`${e}\``:t.type==="strike"?e=`~~${e}~~`:t.type==="link"&&t.attrs?.href&&(e=`[${e}](${t.attrs.href})`);return e}function K(r,s=0){if(!Array.isArray(r))return"";let e=[];for(let t of r){if(t.type==="text"){e.push(je(t.text||"",t.marks));continue}if(t.type==="hardBreak"){e.push(`
2
2
  `);continue}if(t.type==="rule"){e.push(`
3
3
  ---
4
- `);continue}let n=t.content?J(t.content,s+1):"";if(t.type==="listItem")e.push(n);else if(t.type==="bulletList"){let i=(t.content||[]).map(o=>`- ${J(o.content||[],s+1).trim()}`);e.push(`
4
+ `);continue}let n=t.content?K(t.content,s+1):"";if(t.type==="listItem")e.push(n);else if(t.type==="bulletList"){let i=(t.content||[]).map(o=>`- ${K(o.content||[],s+1).trim()}`);e.push(`
5
5
  ${i.join(`
6
6
  `)}
7
- `)}else if(t.type==="orderedList"){let i=(t.content||[]).map((o,a)=>`${a+1}. ${J(o.content||[],s+1).trim()}`);e.push(`
7
+ `)}else if(t.type==="orderedList"){let i=(t.content||[]).map((o,a)=>`${a+1}. ${K(o.content||[],s+1).trim()}`);e.push(`
8
8
  ${i.join(`
9
9
  `)}
10
10
  `)}else if(t.type==="heading"){let i=t.attrs?.level||2;e.push(`
11
11
 
12
12
  ${"#".repeat(i)} ${n.trim()}
13
13
 
14
- `)}else Se.has(t.type)?e.push(`
14
+ `)}else Ne.has(t.type)?e.push(`
15
15
 
16
16
  ${n}
17
17
  `):e.push(n)}return e.join("").replace(/\n{3,}/g,`
18
18
 
19
- `)}function O(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function G(r){return O(r).replace(/[a-z0-9]+/g,"")}function x(r,s){let e=O(r),t=O(s);if(!e||!t)return 0;if(e===t)return 1;if(e.length===1||t.length===1)return e===t?1:0;let n=u=>{let p=new Map;for(let m=0;m<u.length-1;m++){let g=u.slice(m,m+2);p.set(g,(p.get(g)||0)+1)}return p},i=n(e),o=n(t),a=0,c=0,d=0;for(let u of i.values())c+=u;for(let u of o.values())d+=u;for(let[u,p]of i.entries()){let m=o.get(u)||0;a+=Math.min(p,m)}return 2*a/Math.max(1,c+d)}function I(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function ke(r,s=[]){let e=Array.isArray(s)?s:[];if(e.length===0)return{requested:r||null,resolved:null,strategy:"none"};let t=e.filter(a=>!a.subtask),n=t.length>0?t:e,i=I(r);if(i){let a=n.find(u=>I(u.name)===i);if(a)return{requested:r,resolved:a,strategy:"exact"};let c={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 u of Object.values(c)){if(!u.some(m=>I(m)===i))continue;let p=n.find(m=>u.some(g=>I(g)===I(m.name)));if(p)return{requested:r,resolved:p,strategy:"alias"}}let d=n.map(u=>({t:u,score:x(r,u.name)})).sort((u,p)=>p.score-u.score);if(d[0]&&d[0].score>=.5)return{requested:r,resolved:d[0].t,strategy:"fuzzy"}}let o=["task","story","bug","improvement","epic"];for(let a of o){let c=n.find(d=>I(d.name)===a);if(c)return{requested:r||null,resolved:c,strategy:"default-preferred"}}return{requested:r||null,resolved:n[0],strategy:"default-first"}}async function re(r){let s=`projectKeys=${encodeURIComponent(r)}&expand=projects.issuetypes`,e=await _(`/rest/api/3/issue/createmeta?${s}`),t=Array.isArray(e?.projects)?e.projects:[],i=t.find(a=>String(a?.key||"").toUpperCase()===String(r||"").toUpperCase())||t[0]||null;return(Array.isArray(i?.issuetypes)?i.issuetypes:[]).map(a=>({id:a.id,name:a.name,subtask:!!a.subtask,description:a.description||null}))}async function se(r,s){if(!r)throw new Error("projectKey is required");let e="sprint is not EMPTY";s==="active"?e="sprint in openSprints()":s==="closed"?e="sprint in closedSprints()":s==="future"&&(e="sprint in futureSprints()");let t=`project = ${r} AND ${e} ORDER BY updated DESC`,n=`jql=${encodeURIComponent(t)}&maxResults=100&fields=customfield_10020`,i=await _(`/rest/api/3/search/jql?${n}`),o=new Map;for(let a of i.issues||[])for(let c of a.fields?.customfield_10020||[])c&&!o.has(c.id)&&o.set(c.id,{id:c.id,name:c.name,state:c.state,boardId:c.boardId||null,startDate:c.startDate||null,endDate:c.endDate||null,goal:c.goal||null});return[...o.values()].sort((a,c)=>{let d={active:0,future:1,closed:2},u=(d[a.state]??3)-(d[c.state]??3);return u!==0?u:String(c.startDate||"").localeCompare(String(a.startDate||""))})}function Ie(r,{sprintId:s,sprintName:e,target:t}={}){let n=Array.isArray(r)?r:[];if(!n.length)return{sprint:null,selectedBy:"none"};if(s!=null&&String(s).trim()!=="")return{sprint:n.find(a=>String(a.id)===String(s))||null,selectedBy:"id"};if(e&&String(e).trim()){let o=String(e).trim(),a=n.find(d=>String(d.name||"").toLowerCase()===o.toLowerCase());if(a)return{sprint:a,selectedBy:"name-exact"};let c=n.map(d=>({s:d,score:x(o,d.name||"")})).sort((d,u)=>u.score-d.score);return c[0]&&c[0].score>=.5?{sprint:c[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:n[0],selectedBy:i}:{sprint:n[0],selectedBy:"default"}}function Ne(r,s){let e=r?.fields?.customfield_10020;return Array.isArray(e)?e.some(t=>String(t?.id)===String(s)):!1}async function je({issueKey:r,projectKey:s,sprintId:e,attempts:t=3,delayMs:n=450}){let i=[];for(let o=0;o<t;o++){try{let a=`project = ${s} AND key = ${r} AND sprint = ${e}`,c=`jql=${encodeURIComponent(a)}&maxResults=1&fields=key,status`,d=await _(`/rest/api/3/search/jql?${c}`);if(Number(d?.total||0)>0)return i.push({attempt:o+1,jql:!0,issueField:null}),{ok:!0,method:"jql",traces:i};let p=await _(`/rest/api/3/issue/${r}?fields=customfield_10020,status`),m=Ne(p,e);if(i.push({attempt:o+1,jql:!1,issueField:m}),m)return{ok:!0,method:"issue_field",traces:i}}catch(a){i.push({attempt:o+1,error:String(a?.message||a)})}o<t-1&&await new Promise(a=>setTimeout(a,n))}return{ok:!1,method:"none",traces:i}}async function K({issueKey:r,projectKey:s,sprintId:e,sprintName:t,target:n}){if(!r)return{ok:!1,error:"issueKey is required"};let i=s;if(!i&&(i=(await _(`/rest/api/3/issue/${r}?fields=project`))?.fields?.project?.key||null,!i))return{ok:!1,error:`Could not resolve project for ${r}`};let o=await se(i,"active");if(!o.length)return{ok:!1,error:`No assignable active sprint found for project ${i}`};let{sprint:a,selectedBy:c}=Ie(o,{sprintId:e,sprintName:t,target:n});if(!a)return{ok:!1,error:`No matching sprint found in ${i}`,requested:{sprintId:e??null,sprintName:t??null,target:n??"current"},availableSprints:o.map(p=>({id:p.id,name:p.name,state:p.state}))};await _(`/rest/api/3/issue/${r}`,{method:"PUT",body:{fields:{customfield_10020:Number(a.id)}}});let d=await je({issueKey:r,projectKey:i,sprintId:a.id}),u=d.ok;return{ok:u,issueKey:r,projectKey:i,sprintId:a.id,sprintName:a.name,selectedBy:c,verifiedBy:d.method,verified:u,verificationTrace:d.traces,warning:u?null:`Sprint assignment attempted but verification did not find ${r} in sprint ${a.id}`}}async function _(r,s={}){let e=async()=>{let{token:t,cloudId:n}=await he("jira");if(typeof t!="string"||!t)throw new Error(`Invalid jira token type: ${typeof t}`);if(!n)throw new Error("Invalid jira cloudId: missing");let i=`https://api.atlassian.com/ex/jira/${n}${r}`,o=await fetch(i,{method:s.method||"GET",headers:{Authorization:`Bearer ${t}`,Accept:"application/json",...s.body?{"Content-Type":"application/json"}:{},...s.headers},body:s.body?JSON.stringify(s.body):void 0});if(!o.ok){let c=await o.text().catch(()=>"");throw new Error(`Jira API ${o.status}: ${c.slice(0,300)}`)}let a=await o.text().catch(()=>"");if(!a||!a.trim())return{};try{return JSON.parse(a)}catch{return{raw:a}}};try{return await e()}catch(t){let n=String(t?.message||t||"").toLowerCase();if(!(n.includes("token")||n.includes("401")||n.includes("403")||n.includes("substring")))throw t;return be("jira"),e()}}var E={id:"jira",serverName:"jira",allowedTools:["mcp__jira__*"],requiresIntegration:$.JIRA,envKeys:["ATLASSIAN_ACCESS_TOKEN","ATLASSIAN_CLOUD_ID"],description:"Zibby Jira MCP Server (OAuth Bearer)",promptFragment:`## Jira (connected)
19
+ `)}function E(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function M(r){return E(r).replace(/[a-z0-9]+/g,"")}function D(r,s){let e=E(r),t=E(s);if(!e||!t)return 0;if(e===t)return 1;if(e.length===1||t.length===1)return e===t?1:0;let n=l=>{let u=new Map;for(let m=0;m<l.length-1;m++){let y=l.slice(m,m+2);u.set(y,(u.get(y)||0)+1)}return u},i=n(e),o=n(t),a=0,c=0,d=0;for(let l of i.values())c+=l;for(let l of o.values())d+=l;for(let[l,u]of i.entries()){let m=o.get(l)||0;a+=Math.min(u,m)}return 2*a/Math.max(1,c+d)}function v(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function $e(r,s=[]){let e=Array.isArray(s)?s:[];if(e.length===0)return{requested:r||null,resolved:null,strategy:"none"};let t=e.filter(a=>!a.subtask),n=t.length>0?t:e,i=v(r);if(i){let a=n.find(l=>v(l.name)===i);if(a)return{requested:r,resolved:a,strategy:"exact"};let c={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 l of Object.values(c)){if(!l.some(m=>v(m)===i))continue;let u=n.find(m=>l.some(y=>v(y)===v(m.name)));if(u)return{requested:r,resolved:u,strategy:"alias"}}let d=n.map(l=>({t:l,score:D(r,l.name)})).sort((l,u)=>u.score-l.score);if(d[0]&&d[0].score>=.5)return{requested:r,resolved:d[0].t,strategy:"fuzzy"}}let o=["task","story","bug","improvement","epic"];for(let a of o){let c=n.find(d=>v(d.name)===a);if(c)return{requested:r||null,resolved:c,strategy:"default-preferred"}}return{requested:r||null,resolved:n[0],strategy:"default-first"}}async function ae(r){let s=`projectKeys=${encodeURIComponent(r)}&expand=projects.issuetypes`,e=await _(`/rest/api/3/issue/createmeta?${s}`),t=Array.isArray(e?.projects)?e.projects:[],i=t.find(a=>String(a?.key||"").toUpperCase()===String(r||"").toUpperCase())||t[0]||null;return(Array.isArray(i?.issuetypes)?i.issuetypes:[]).map(a=>({id:a.id,name:a.name,subtask:!!a.subtask,description:a.description||null}))}async function ce(r,s){if(!r)throw new Error("projectKey is required");let e="sprint is not EMPTY";s==="active"?e="sprint in openSprints()":s==="closed"?e="sprint in closedSprints()":s==="future"&&(e="sprint in futureSprints()");let t=`project = ${r} AND ${e} ORDER BY updated DESC`,n=`jql=${encodeURIComponent(t)}&maxResults=100&fields=customfield_10020`,i=await _(`/rest/api/3/search/jql?${n}`),o=new Map;for(let a of i.issues||[])for(let c of a.fields?.customfield_10020||[])c&&!o.has(c.id)&&o.set(c.id,{id:c.id,name:c.name,state:c.state,boardId:c.boardId||null,startDate:c.startDate||null,endDate:c.endDate||null,goal:c.goal||null});return[...o.values()].sort((a,c)=>{let d={active:0,future:1,closed:2},l=(d[a.state]??3)-(d[c.state]??3);return l!==0?l:String(c.startDate||"").localeCompare(String(a.startDate||""))})}function Oe(r,{sprintId:s,sprintName:e,target:t}={}){let n=Array.isArray(r)?r:[];if(!n.length)return{sprint:null,selectedBy:"none"};if(s!=null&&String(s).trim()!=="")return{sprint:n.find(a=>String(a.id)===String(s))||null,selectedBy:"id"};if(e&&String(e).trim()){let o=String(e).trim(),a=n.find(d=>String(d.name||"").toLowerCase()===o.toLowerCase());if(a)return{sprint:a,selectedBy:"name-exact"};let c=n.map(d=>({s:d,score:D(o,d.name||"")})).sort((d,l)=>l.score-d.score);return c[0]&&c[0].score>=.5?{sprint:c[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:n[0],selectedBy:i}:{sprint:n[0],selectedBy:"default"}}function Te(r,s){let e=r?.fields?.customfield_10020;return Array.isArray(e)?e.some(t=>String(t?.id)===String(s)):!1}async function Ee({issueKey:r,projectKey:s,sprintId:e,attempts:t=3,delayMs:n=450}){let i=[];for(let o=0;o<t;o++){try{let a=`project = ${s} AND key = ${r} AND sprint = ${e}`,c=`jql=${encodeURIComponent(a)}&maxResults=1&fields=key,status`,d=await _(`/rest/api/3/search/jql?${c}`);if(Number(d?.total||0)>0)return i.push({attempt:o+1,jql:!0,issueField:null}),{ok:!0,method:"jql",traces:i};let u=await _(`/rest/api/3/issue/${r}?fields=customfield_10020,status`),m=Te(u,e);if(i.push({attempt:o+1,jql:!1,issueField:m}),m)return{ok:!0,method:"issue_field",traces:i}}catch(a){i.push({attempt:o+1,error:String(a?.message||a)})}o<t-1&&await new Promise(a=>setTimeout(a,n))}return{ok:!1,method:"none",traces:i}}async function B({issueKey:r,projectKey:s,sprintId:e,sprintName:t,target:n}){if(!r)return{ok:!1,error:"issueKey is required"};let i=s;if(!i&&(i=(await _(`/rest/api/3/issue/${r}?fields=project`))?.fields?.project?.key||null,!i))return{ok:!1,error:`Could not resolve project for ${r}`};let o=await ce(i,"active");if(!o.length)return{ok:!1,error:`No assignable active sprint found for project ${i}`};let{sprint:a,selectedBy:c}=Oe(o,{sprintId:e,sprintName:t,target:n});if(!a)return{ok:!1,error:`No matching sprint found in ${i}`,requested:{sprintId:e??null,sprintName:t??null,target:n??"current"},availableSprints:o.map(u=>({id:u.id,name:u.name,state:u.state}))};await _(`/rest/api/3/issue/${r}`,{method:"PUT",body:{fields:{customfield_10020:Number(a.id)}}});let d=await Ee({issueKey:r,projectKey:i,sprintId:a.id}),l=d.ok;return{ok:l,issueKey:r,projectKey:i,sprintId:a.id,sprintName:a.name,selectedBy:c,verifiedBy:d.method,verified:l,verificationTrace:d.traces,warning:l?null:`Sprint assignment attempted but verification did not find ${r} in sprint ${a.id}`}}async function _(r,s={}){let e=async()=>{let{token:t,cloudId:n}=await ke("jira");if(typeof t!="string"||!t)throw new Error(`Invalid jira token type: ${typeof t}`);if(!n)throw new Error("Invalid jira cloudId: missing");let i=`https://api.atlassian.com/ex/jira/${n}${r}`,o=await fetch(i,{method:s.method||"GET",headers:{Authorization:`Bearer ${t}`,Accept:"application/json",...s.body?{"Content-Type":"application/json"}:{},...s.headers},body:s.body?JSON.stringify(s.body):void 0});if(!o.ok){let c=await o.text().catch(()=>"");throw new Error(`Jira API ${o.status}: ${c.slice(0,300)}`)}let a=await o.text().catch(()=>"");if(!a||!a.trim())return{};try{return JSON.parse(a)}catch{return{raw:a}}};try{return await e()}catch(t){let n=String(t?.message||t||"").toLowerCase();if(!(n.includes("token")||n.includes("401")||n.includes("403")||n.includes("substring")))throw t;return Ie("jira"),e()}}var q={id:"jira",serverName:"jira",allowedTools:["mcp__jira__*"],requiresIntegration:T.JIRA,envKeys:["ATLASSIAN_ACCESS_TOKEN","ATLASSIAN_CLOUD_ID"],description:"Zibby Jira MCP Server (OAuth Bearer)",promptFragment:`## Jira (connected)
20
20
  You have direct access to the user's Jira. Use these tools proactively:
21
21
 
22
22
  ### Issue tools
@@ -66,9 +66,9 @@ When user asks to move/transition ticket status:
66
66
  3. Pick the correct transition from returned list (match by "to" status name, not guesswork), then call jira_transition_issue with transitionId.
67
67
  4. Call jira_get_issue(issueKey) to verify final status before claiming success.
68
68
  5. If target wording differs (e.g. \u5DF2\u7ECF\u9A8C\u6536 vs \u5DF2\u9A8C\u6536), try toStatus first; only ask user to confirm when no reasonable match exists.
69
- 6. IMPORTANT: When target is clear, complete transition + verification in SAME turn. Do NOT stop after listing options.`,resolve(){let r=we();if(!r)return null;let s={};for(let e of this.envKeys)process.env[e]&&(s[e]=process.env[e]);return process.env.ATLASSIAN_INSTANCE_URL&&(s.ATLASSIAN_INSTANCE_URL=process.env.ATLASSIAN_INSTANCE_URL),{command:"node",args:[r],env:s,description:this.description}},async handleToolCall(r,s){try{switch(r){case"jira_list_projects":{let e=await _("/rest/api/3/project"),t=(Array.isArray(e)?e:[]).map(n=>({id:n.id,key:n.key,name:n.name,style:n.style}));return JSON.stringify({count:t.length,projects:t})}case"jira_list_statuses":{let{projectKey:e}=s||{};if(e){let i=await _(`/rest/api/3/project/${encodeURIComponent(e)}/statuses`),o=Array.isArray(i)?i:[],a=new Map;for(let d of o)for(let u of d.statuses||[])u?.id&&(a.has(u.id)||a.set(u.id,{id:u.id,name:u.name,category:u.statusCategory?.name||null}));let c=[...a.values()].sort((d,u)=>String(d.name).localeCompare(String(u.name)));return JSON.stringify({scope:"project",projectKey:e,count:c.length,statuses:c})}let t=await _("/rest/api/3/status"),n=(Array.isArray(t)?t:[]).map(i=>({id:i.id,name:i.name,category:i.statusCategory?.name||null})).sort((i,o)=>String(i.name).localeCompare(String(o.name)));return JSON.stringify({scope:"global",count:n.length,statuses:n})}case"jira_list_issue_types":{let{projectKey:e}=s||{};if(!e)return JSON.stringify({error:"projectKey is required"});let t=await re(e);return JSON.stringify({projectKey:e,count:t.length,issueTypes:t})}case"jira_search":{let e=s.jql||"",t=s.maxResults||20;e.replace(/\s*ORDER\s+BY\s+.*/i,"").trim()||(e=`created >= -365d ${e}`.trim());let i=`jql=${encodeURIComponent(e)}&maxResults=${t}&fields=summary,status,assignee,priority,updated,issuetype,project`,a=((await _(`/rest/api/3/search/jql?${i}`)).issues||[]).map(c=>({key:c.key,project:c.fields?.project?.key,summary:c.fields?.summary,status:c.fields?.status?.name,assignee:c.fields?.assignee?.displayName||"Unassigned",priority:c.fields?.priority?.name,type:c.fields?.issuetype?.name}));return JSON.stringify({count:a.length,issues:a})}case"jira_get_issue":{let e=s.issueKey;if(!e)return JSON.stringify({error:"issueKey is required"});let t=await _(`/rest/api/3/issue/${e}`);return JSON.stringify({key:t.key,project:t.fields?.project?.key,summary:t.fields?.summary,description:t.fields?.description,status:t.fields?.status?.name,assignee:t.fields?.assignee?.displayName||"Unassigned",priority:t.fields?.priority?.name,type:t.fields?.issuetype?.name,labels:t.fields?.labels,created:t.fields?.created,updated:t.fields?.updated})}case"jira_create_issue":{let{projectKey:e,summary:t,issueType:n,description:i,priority:o,labels:a,assigneeId:c,moveToSprint:d,moveToActiveSprint:u,sprintId:p,sprintName:m,target:g}=s;if(!e||!t)return JSON.stringify({error:"projectKey and summary are required"});let l={requested:n||null,resolved:null,strategy:"none"},y=[];try{y=await re(e),l=ke(n,y)}catch{}let f={project:{key:e},summary:t,issuetype:l?.resolved?.id?{id:l.resolved.id}:{name:n||"Task"}};i&&(f.description={type:"doc",version:1,content:[{type:"paragraph",content:[{type:"text",text:i}]}]}),o&&(f.priority={name:o}),a?.length&&(f.labels=a),c&&(f.assignee={id:c});let S=await _("/rest/api/3/issue",{method:"POST",body:{fields:f}}),w={ok:!0,key:S.key,id:S.id,self:S.self};return l?.resolved&&(w.issueType=l.resolved.name,w.issueTypeResolution=l.strategy,l.strategy!=="exact"&&l.requested&&I(l.requested)!==I(l.resolved.name)&&(w.issueTypeWarning=`Requested "${l.requested}" is not available in ${e}; used "${l.resolved.name}" instead.`)),y.length>0&&(w.availableIssueTypes=y.map(b=>b.name)),(d||u)&&(w.sprintMove=await K({issueKey:S.key,projectKey:e,sprintId:p,sprintName:m,target:g})),JSON.stringify(w)}case"jira_list_sprints":{let{projectKey:e,state:t}=s,n=await se(e,t);return JSON.stringify({count:n.length,sprints:n})}case"jira_move_to_active_sprint":{let{issueKey:e,projectKey:t,sprintId:n,sprintName:i,target:o}=s||{},a=await K({issueKey:e,projectKey:t,sprintId:n,sprintName:i,target:o||"current"});return JSON.stringify(a)}case"jira_move_issue_to_sprint":{let{issueKey:e,projectKey:t,sprintId:n,sprintName:i,target:o}=s||{},a=await K({issueKey:e,projectKey:t,sprintId:n,sprintName:i,target:o});return JSON.stringify(a)}case"jira_get_sprint_issues":{let{sprintName:e,sprintId:t,projectKey:n,status:i,maxResults:o}=s;if(!e&&!t)return JSON.stringify({error:"sprintName or sprintId is required"});let a=o||50,c=t?`sprint = ${t}`:`sprint = "${e}"`,d=n?`project = ${n} AND `:"",u=i?` AND status = "${i}"`:"",p=`${d}${c}${u} ORDER BY status ASC, priority DESC`,m=`jql=${encodeURIComponent(p)}&maxResults=${a}&fields=summary,status,assignee,priority,issuetype,project`,g=await _(`/rest/api/3/search/jql?${m}`),l=(g.issues||[]).map(f=>({key:f.key,project:f.fields?.project?.key,summary:f.fields?.summary,status:f.fields?.status?.name,assignee:f.fields?.assignee?.displayName||"Unassigned",priority:f.fields?.priority?.name,type:f.fields?.issuetype?.name})),y={};for(let f of l)y[f.status]=(y[f.status]||0)+1;return JSON.stringify({count:l.length,total:g.total||l.length,statusCounts:y,issues:l})}case"jira_get_comments":{let{issueKey:e,maxResults:t}=s;if(!e)return JSON.stringify({error:"issueKey is required"});let i=await _(`/rest/api/3/issue/${e}/comment?maxResults=${t||50}&orderBy=-created`),o=(i.comments||[]).map(a=>{let c="";return a.body?.content&&(c=J(a.body.content)),{id:a.id,author:a.author?.displayName||"Unknown",body:c,created:a.created,updated:a.updated}});return JSON.stringify({count:o.length,total:i.total||o.length,comments:o})}case"jira_add_comment":{let{issueKey:e,body:t}=s;return!e||!t?JSON.stringify({error:"issueKey and body are required"}):(await _(`/rest/api/3/issue/${e}/comment`,{method:"POST",body:{body:{type:"doc",version:1,content:[{type:"paragraph",content:[{type:"text",text:t}]}]}}}),JSON.stringify({ok:!0,issueKey:e}))}case"jira_edit_issue":{let{issueKey:e,fields:t}=s;return!e||!t?JSON.stringify({error:"issueKey and fields are required"}):(await _(`/rest/api/3/issue/${e}`,{method:"PUT",body:{fields:t}}),JSON.stringify({ok:!0,issueKey:e}))}case"jira_transition_issue":{let{issueKey:e,transitionId:t,toStatus:n,statusName:i,status:o}=s;if(!e)return JSON.stringify({error:"issueKey is required"});let a=String(n||i||o||"").trim();if(!t&&!a){let p=((await _(`/rest/api/3/issue/${e}/transitions`)).transitions||[]).map(m=>({id:m.id,name:m.name,to:m.to?.name}));return JSON.stringify({ok:!1,error:"transitionId or toStatus is required",issueKey:e,availableTransitions:p})}let c=t;if(!c){let p=(await _(`/rest/api/3/issue/${e}/transitions`)).transitions||[],m=O(a),g=p.find(l=>O(l?.name||"")===m||O(l?.to?.name||"")===m);if(!g){let l=G(a);l.length>=2&&(g=p.find(y=>{let f=G(y?.name||""),S=G(y?.to?.name||""),w=f.length>=2&&(f.includes(l)||l.includes(f)),b=S.length>=2&&(S.includes(l)||l.includes(S));return w||b}))}if(!g){let l=p.map(w=>{let b=x(a,w?.name||""),te=x(a,w?.to?.name||"");return{t:w,score:Math.max(b,te)}}).sort((w,b)=>b.score-w.score),y=l[0],f=l[1];y&&y.score>=.45&&(!f||y.score-f.score>=.12)&&(g=y.t)}if(!g?.id)return JSON.stringify({ok:!1,error:`No transition matches target status: "${a}"`,issueKey:e,availableTransitions:p.map(l=>({id:l.id,name:l.name,to:l.to?.name}))});c=g.id}await _(`/rest/api/3/issue/${e}/transitions`,{method:"POST",body:{transition:{id:c}}});let d=await _(`/rest/api/3/issue/${e}?fields=status`);return JSON.stringify({ok:!0,issueKey:e,transitionId:c,statusAfter:d?.fields?.status?.name||null})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"jira_list_projects",description:"List all Jira projects accessible to the user",input_schema:{type:"object",properties:{}}},{name:"jira_list_statuses",description:"List Jira statuses. Use projectKey to get statuses applicable in that project workflow.",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Optional project key (e.g. PROJ). If omitted, returns global status catalog."}}}},{name:"jira_list_issue_types",description:"List issue types allowed for issue creation in the given project.",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Project key, e.g. PROJ"}},required:["projectKey"]}},{name:"jira_search",description:"Search Jira issues using JQL",input_schema:{type:"object",properties:{jql:{type:"string",description:'JQL query string, e.g. "project = PROJ AND status = Open"'},maxResults:{type:"number",description:"Max results to return (default 20)"}},required:["jql"]}},{name:"jira_get_issue",description:"Get details of a specific Jira issue",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"}},required:["issueKey"]}},{name:"jira_create_issue",description:"Create a new Jira issue",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Project key, e.g. PROJ"},summary:{type:"string",description:"Issue title/summary"},issueType:{type:"string",description:"Issue type (default: Task). Common: Task, Bug, Story, Epic"},description:{type:"string",description:"Issue description (plain text)"},priority:{type:"string",description:"Priority name, e.g. High, Medium, Low"},labels:{type:"array",items:{type:"string"},description:"Array of label strings"},assigneeId:{type:"string",description:"Atlassian account ID to assign to"},moveToSprint:{type:"boolean",description:"If true, move created issue to a sprint and verify."},moveToActiveSprint:{type:"boolean",description:"Backward-compatible alias for moveToSprint."},sprintId:{type:"number",description:"Optional sprint id for placement."},sprintName:{type:"string",description:"Optional sprint name for placement."},target:{type:"string",description:"Placement target when sprintId/sprintName omitted: current|active|latest (default: current)."}},required:["projectKey","summary"]}},{name:"jira_list_sprints",description:"List sprints for a Jira project (returns sprint names, IDs, states, dates)",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Project key, e.g. PROJ"},state:{type:"string",description:"Filter: active, closed, future. Omit for all."}},required:["projectKey"]}},{name:"jira_get_sprint_issues",description:"Get all issues in a sprint, optionally filtered by status column name",input_schema:{type:"object",properties:{sprintName:{type:"string",description:"Sprint name (from jira_list_sprints). Use this OR sprintId."},sprintId:{type:"number",description:"Sprint ID (from jira_list_sprints). Use this OR sprintName."},projectKey:{type:"string",description:"Project key to scope the search (optional)"},status:{type:"string",description:'Filter by status name (e.g. "\u8FDB\u884C\u4E2D", "\u6D4B\u8BD5", "Done")'},maxResults:{type:"number",description:"Max issues to return (default 50)"}}}},{name:"jira_move_to_active_sprint",description:"Backward-compatible alias: move issue to sprint target and verify membership.",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},projectKey:{type:"string",description:"Optional project key. If omitted, inferred from issue."},sprintId:{type:"number",description:"Optional sprint id."},sprintName:{type:"string",description:"Optional sprint name."},target:{type:"string",description:"Target when sprintId/sprintName omitted: current|active|latest (default: current)."}},required:["issueKey"]}},{name:"jira_move_issue_to_sprint",description:"Move an issue to a sprint by id/name/target and verify membership.",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},projectKey:{type:"string",description:"Optional project key. If omitted, inferred from issue."},sprintId:{type:"number",description:"Optional sprint id."},sprintName:{type:"string",description:"Optional sprint name."},target:{type:"string",description:"Target when sprintId/sprintName omitted: current|active|latest (default: current)."}},required:["issueKey"]}},{name:"jira_get_comments",description:"Get comments on a Jira issue (newest first)",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},maxResults:{type:"number",description:"Max comments to return (default 50)"}},required:["issueKey"]}},{name:"jira_add_comment",description:"Add a comment to a Jira issue",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},body:{type:"string",description:"Comment text (plain text)"}},required:["issueKey","body"]}},{name:"jira_edit_issue",description:"Update fields on a Jira issue (summary, story points, labels, priority)",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},fields:{type:"object",description:"Object of field names to values",additionalProperties:!0}},required:["issueKey","fields"]}},{name:"jira_transition_issue",description:"Move a Jira issue to a different status. Always pass toStatus when user gave a target; only pass issueKey alone when you explicitly need to list transitions.",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},transitionId:{type:"string",description:"Transition ID to perform (optional if toStatus is provided)"},toStatus:{type:"string",description:'Target status/column name (e.g. "\u5DF2\u7ECF\u9A8C\u6536", "Done", "In Progress"). If provided, tool resolves matching transition automatically.'}},required:["issueKey"]}}]};var ve={new:"todo",indeterminate:"in_progress",done:"done"},Re=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i;function H(r){if(!r)return"unknown";if(r.name&&Re.test(r.name))return"blocked";let s=r.statusCategory?.key;return ve[s]||"unknown"}function B(r){if(!r)return"";if(Array.isArray(r))return r.map(B).join("");if(r.type==="text")return r.text||"";if(r.type==="hardBreak"||r.type==="rule")return`
70
- `;let s=r.content?B(r.content):"";return/^(paragraph|heading|listItem|blockquote|codeBlock|panel)$/.test(r.type)&&(s+=`
71
- `),s}function D(r,s){let e=r.fields||{},t=e.status||null,n=null;if(r.self&&r.key)try{n=`${new URL(r.self).origin}/browse/${r.key}`}catch{n=null}return!n&&s&&r.key&&(n=`${String(s).replace(/\/+$/,"")}/browse/${r.key}`),{id:String(r.id??r.key??""),key:r.key,title:e.summary||"",body:typeof e.description=="string"?e.description:B(e.description?.content).trim(),state:t?.name||null,stateCategory:H(t),assignee:e.assignee?.displayName||null,url:n,_raw:r}}function M(r){let s=JSON.parse(r);if(s&&s.error)throw new Error(s.error);return s}var F={id:"jira",toStateCategory:H,toNeutral:D,async listCandidates(r={}){let s=r.query||"";if(!s.trim()){let i=[];if(r.state&&i.push(`status = "${r.state}"`),r.labels){let o=Array.isArray(r.labels)?r.labels:[r.labels];for(let a of o)i.push(`labels = "${a}"`)}r.updatedAfter&&i.push(`updated >= "${r.updatedAfter}"`),s=i.length?`${i.join(" AND ")} ORDER BY updated DESC`:"ORDER BY updated DESC"}let e=Number(r.limit)||30,t=`jql=${encodeURIComponent(s)}&maxResults=${e}&fields=summary,description,status,assignee,labels,project,updated,created`;return((await _(`/rest/api/3/search/jql?${t}`)).issues||[]).map(i=>D(i))},async getTicket(r){if(!r)throw new Error("key is required");let s=await _(`/rest/api/3/issue/${encodeURIComponent(r)}`);return!s||!s.key?null:D(s)},async getComments(r){if(!r)throw new Error("key is required");return(M(await E.handleToolCall("jira_get_comments",{issueKey:r})).comments||[]).map(e=>({id:String(e.id),author:e.author||"Unknown",body:e.body||"",createdAt:e.created||null,updatedAt:e.updated||null,_raw:e}))},async addComment(r,s){if(!r||!s)throw new Error("key and body are required");return{ok:!!M(await E.handleToolCall("jira_add_comment",{issueKey:r,body:s})).ok,id:null}},async transition(r,s){if(!r)throw new Error("key is required");let e=JSON.parse(await E.handleToolCall("jira_transition_issue",{issueKey:r,toStatus:s}));if(!e.ok)return{ok:!1,error:e.error||"transition failed",_raw:e};let t=e.statusAfter||null;return{ok:!0,stateAfter:t,stateCategoryAfter:H(t?{name:t}:null),_raw:e}},async linkPullRequest(r,s,e){if(!r||!s)throw new Error("key and prUrl are required");try{return await _(`/rest/api/3/issue/${encodeURIComponent(r)}/remotelink`,{method:"POST",body:{object:{url:s,title:e||s,icon:{url16x16:"https://github.com/favicon.ico",title:"GitHub"}}}}),{ok:!0,via:"remotelink"}}catch(t){let n=`${e?`${e}: `:"Linked PR: "}${s}`;return{ok:!!M(await E.handleToolCall("jira_add_comment",{issueKey:r,body:n})).ok,via:"comment",error:String(t?.message||t)}}}};import{existsSync as $e}from"fs";import{fileURLToPath as Oe}from"url";import{dirname as Ce,resolve as Ee}from"path";function Te(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let r=Ce(Oe(import.meta.url)),s=Ee(r,"..","bin","mcp-skill.mjs");return $e(s)?s:null}var Pe=process.env.LINEAR_API_URL||"https://api.linear.app/graphql";function Le(){if(process.env.LINEAR_OAUTH_TOKEN)return`Bearer ${process.env.LINEAR_OAUTH_TOKEN}`;let r=process.env.LINEAR_API_KEY;if(!r)throw new Error("Linear is not connected: set LINEAR_API_KEY (personal API key) or LINEAR_OAUTH_TOKEN.");return r}async function A(r,s={}){let e=await fetch(Pe,{method:"POST",headers:{Authorization:Le(),"Content-Type":"application/json"},body:JSON.stringify({query:r,variables:s})});if(!e.ok){let n=await e.text().catch(()=>"");throw new Error(`Linear API ${e.status}: ${n.slice(0,300)}`)}let t=await e.json().catch(()=>null);if(!t)throw new Error("Linear API returned a non-JSON body");if(Array.isArray(t.errors)&&t.errors.length){let n=t.errors.map(i=>i?.message||String(i)).join("; ");throw new Error(`Linear GraphQL error: ${n.slice(0,300)}`)}return t.data}function P(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function qe(r,s){let e=P(r),t=P(s);if(!e||!t)return 0;if(e===t)return 1;if(e.length===1||t.length===1)return e===t?1:0;let n=u=>{let p=new Map;for(let m=0;m<u.length-1;m++){let g=u.slice(m,m+2);p.set(g,(p.get(g)||0)+1)}return p},i=n(e),o=n(t),a=0,c=0,d=0;for(let u of i.values())c+=u;for(let u of o.values())d+=u;for(let[u,p]of i.entries())a+=Math.min(p,o.get(u)||0);return 2*a/Math.max(1,c+d)}function Je(r,s){let e=Array.isArray(r)?r:[];if(!e.length)return{state:null,strategy:"no-states"};let t=P(s);if(!t)return{state:null,strategy:"no-target"};let n=e.find(a=>P(a.name)===t);if(n)return{state:n,strategy:"exact"};let i={backlog:["backlog"],unstarted:["todo","unstarted","open"],started:["inprogress","started","doing","wip"],completed:["done","completed","closed","resolved","fixed"],canceled:["canceled","cancelled","wontfix","won'tfix"],triage:["triage"]};for(let[a,c]of Object.entries(i)){if(!c.some(u=>P(u)===t))continue;let d=e.find(u=>u.type===a);if(d)return{state:d,strategy:"type-alias"}}let o=e.map(a=>({s:a,score:qe(s,a.name)})).sort((a,c)=>c.score-a.score);return o[0]&&o[0].score>=.5?{state:o[0].s,strategy:"fuzzy"}:{state:null,strategy:"no-match"}}var xe=`
69
+ 6. IMPORTANT: When target is clear, complete transition + verification in SAME turn. Do NOT stop after listing options.`,resolve(){let r=Re();if(!r)return null;let s={};for(let e of this.envKeys)process.env[e]&&(s[e]=process.env[e]);return process.env.ATLASSIAN_INSTANCE_URL&&(s.ATLASSIAN_INSTANCE_URL=process.env.ATLASSIAN_INSTANCE_URL),{command:"node",args:[r],env:s,description:this.description}},async handleToolCall(r,s){try{switch(r){case"jira_list_projects":{let e=await _("/rest/api/3/project"),t=(Array.isArray(e)?e:[]).map(n=>({id:n.id,key:n.key,name:n.name,style:n.style}));return JSON.stringify({count:t.length,projects:t})}case"jira_list_statuses":{let{projectKey:e}=s||{};if(e){let i=await _(`/rest/api/3/project/${encodeURIComponent(e)}/statuses`),o=Array.isArray(i)?i:[],a=new Map;for(let d of o)for(let l of d.statuses||[])l?.id&&(a.has(l.id)||a.set(l.id,{id:l.id,name:l.name,category:l.statusCategory?.name||null}));let c=[...a.values()].sort((d,l)=>String(d.name).localeCompare(String(l.name)));return JSON.stringify({scope:"project",projectKey:e,count:c.length,statuses:c})}let t=await _("/rest/api/3/status"),n=(Array.isArray(t)?t:[]).map(i=>({id:i.id,name:i.name,category:i.statusCategory?.name||null})).sort((i,o)=>String(i.name).localeCompare(String(o.name)));return JSON.stringify({scope:"global",count:n.length,statuses:n})}case"jira_list_issue_types":{let{projectKey:e}=s||{};if(!e)return JSON.stringify({error:"projectKey is required"});let t=await ae(e);return JSON.stringify({projectKey:e,count:t.length,issueTypes:t})}case"jira_search":{let e=s.jql||"",t=s.maxResults||20;e.replace(/\s*ORDER\s+BY\s+.*/i,"").trim()||(e=`created >= -365d ${e}`.trim());let i=`jql=${encodeURIComponent(e)}&maxResults=${t}&fields=summary,status,assignee,priority,updated,issuetype,project`,a=((await _(`/rest/api/3/search/jql?${i}`)).issues||[]).map(c=>({key:c.key,project:c.fields?.project?.key,summary:c.fields?.summary,status:c.fields?.status?.name,assignee:c.fields?.assignee?.displayName||"Unassigned",priority:c.fields?.priority?.name,type:c.fields?.issuetype?.name}));return JSON.stringify({count:a.length,issues:a})}case"jira_get_issue":{let e=s.issueKey;if(!e)return JSON.stringify({error:"issueKey is required"});let t=await _(`/rest/api/3/issue/${e}`);return JSON.stringify({key:t.key,project:t.fields?.project?.key,summary:t.fields?.summary,description:t.fields?.description,status:t.fields?.status?.name,assignee:t.fields?.assignee?.displayName||"Unassigned",priority:t.fields?.priority?.name,type:t.fields?.issuetype?.name,labels:t.fields?.labels,created:t.fields?.created,updated:t.fields?.updated})}case"jira_create_issue":{let{projectKey:e,summary:t,issueType:n,description:i,priority:o,labels:a,assigneeId:c,moveToSprint:d,moveToActiveSprint:l,sprintId:u,sprintName:m,target:y}=s;if(!e||!t)return JSON.stringify({error:"projectKey and summary are required"});let p={requested:n||null,resolved:null,strategy:"none"},f=[];try{f=await ae(e),p=$e(n,f)}catch{}let h={project:{key:e},summary:t,issuetype:p?.resolved?.id?{id:p.resolved.id}:{name:n||"Task"}};i&&(h.description={type:"doc",version:1,content:[{type:"paragraph",content:[{type:"text",text:i}]}]}),o&&(h.priority={name:o}),a?.length&&(h.labels=a),c&&(h.assignee={id:c});let S=await _("/rest/api/3/issue",{method:"POST",body:{fields:h}}),w={ok:!0,key:S.key,id:S.id,self:S.self};return p?.resolved&&(w.issueType=p.resolved.name,w.issueTypeResolution=p.strategy,p.strategy!=="exact"&&p.requested&&v(p.requested)!==v(p.resolved.name)&&(w.issueTypeWarning=`Requested "${p.requested}" is not available in ${e}; used "${p.resolved.name}" instead.`)),f.length>0&&(w.availableIssueTypes=f.map(g=>g.name)),(d||l)&&(w.sprintMove=await B({issueKey:S.key,projectKey:e,sprintId:u,sprintName:m,target:y})),JSON.stringify(w)}case"jira_list_sprints":{let{projectKey:e,state:t}=s,n=await ce(e,t);return JSON.stringify({count:n.length,sprints:n})}case"jira_move_to_active_sprint":{let{issueKey:e,projectKey:t,sprintId:n,sprintName:i,target:o}=s||{},a=await B({issueKey:e,projectKey:t,sprintId:n,sprintName:i,target:o||"current"});return JSON.stringify(a)}case"jira_move_issue_to_sprint":{let{issueKey:e,projectKey:t,sprintId:n,sprintName:i,target:o}=s||{},a=await B({issueKey:e,projectKey:t,sprintId:n,sprintName:i,target:o});return JSON.stringify(a)}case"jira_get_sprint_issues":{let{sprintName:e,sprintId:t,projectKey:n,status:i,maxResults:o}=s;if(!e&&!t)return JSON.stringify({error:"sprintName or sprintId is required"});let a=o||50,c=t?`sprint = ${t}`:`sprint = "${e}"`,d=n?`project = ${n} AND `:"",l=i?` AND status = "${i}"`:"",u=`${d}${c}${l} ORDER BY status ASC, priority DESC`,m=`jql=${encodeURIComponent(u)}&maxResults=${a}&fields=summary,status,assignee,priority,issuetype,project`,y=await _(`/rest/api/3/search/jql?${m}`),p=(y.issues||[]).map(h=>({key:h.key,project:h.fields?.project?.key,summary:h.fields?.summary,status:h.fields?.status?.name,assignee:h.fields?.assignee?.displayName||"Unassigned",priority:h.fields?.priority?.name,type:h.fields?.issuetype?.name})),f={};for(let h of p)f[h.status]=(f[h.status]||0)+1;return JSON.stringify({count:p.length,total:y.total||p.length,statusCounts:f,issues:p})}case"jira_get_comments":{let{issueKey:e,maxResults:t}=s;if(!e)return JSON.stringify({error:"issueKey is required"});let i=await _(`/rest/api/3/issue/${e}/comment?maxResults=${t||50}&orderBy=-created`),o=(i.comments||[]).map(a=>{let c="";return a.body?.content&&(c=K(a.body.content)),{id:a.id,author:a.author?.displayName||"Unknown",body:c,created:a.created,updated:a.updated}});return JSON.stringify({count:o.length,total:i.total||o.length,comments:o})}case"jira_add_comment":{let{issueKey:e,body:t}=s;return!e||!t?JSON.stringify({error:"issueKey and body are required"}):(await _(`/rest/api/3/issue/${e}/comment`,{method:"POST",body:{body:{type:"doc",version:1,content:[{type:"paragraph",content:[{type:"text",text:t}]}]}}}),JSON.stringify({ok:!0,issueKey:e}))}case"jira_edit_issue":{let{issueKey:e,fields:t}=s;return!e||!t?JSON.stringify({error:"issueKey and fields are required"}):(await _(`/rest/api/3/issue/${e}`,{method:"PUT",body:{fields:t}}),JSON.stringify({ok:!0,issueKey:e}))}case"jira_transition_issue":{let{issueKey:e,transitionId:t,toStatus:n,statusName:i,status:o}=s;if(!e)return JSON.stringify({error:"issueKey is required"});let a=String(n||i||o||"").trim();if(!t&&!a){let u=((await _(`/rest/api/3/issue/${e}/transitions`)).transitions||[]).map(m=>({id:m.id,name:m.name,to:m.to?.name}));return JSON.stringify({ok:!1,error:"transitionId or toStatus is required",issueKey:e,availableTransitions:u})}let c=t;if(!c){let u=(await _(`/rest/api/3/issue/${e}/transitions`)).transitions||[],m=E(a),y=u.find(p=>E(p?.name||"")===m||E(p?.to?.name||"")===m);if(!y){let p=M(a);p.length>=2&&(y=u.find(f=>{let h=M(f?.name||""),S=M(f?.to?.name||""),w=h.length>=2&&(h.includes(p)||p.includes(h)),g=S.length>=2&&(S.includes(p)||p.includes(S));return w||g}))}if(!y){let p=u.map(w=>{let g=D(a,w?.name||""),A=D(a,w?.to?.name||"");return{t:w,score:Math.max(g,A)}}).sort((w,g)=>g.score-w.score),f=p[0],h=p[1];f&&f.score>=.45&&(!h||f.score-h.score>=.12)&&(y=f.t)}if(!y?.id)return JSON.stringify({ok:!1,error:`No transition matches target status: "${a}"`,issueKey:e,availableTransitions:u.map(p=>({id:p.id,name:p.name,to:p.to?.name}))});c=y.id}await _(`/rest/api/3/issue/${e}/transitions`,{method:"POST",body:{transition:{id:c}}});let d=await _(`/rest/api/3/issue/${e}?fields=status`);return JSON.stringify({ok:!0,issueKey:e,transitionId:c,statusAfter:d?.fields?.status?.name||null})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"jira_list_projects",description:"List all Jira projects accessible to the user",input_schema:{type:"object",properties:{}}},{name:"jira_list_statuses",description:"List Jira statuses. Use projectKey to get statuses applicable in that project workflow.",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Optional project key (e.g. PROJ). If omitted, returns global status catalog."}}}},{name:"jira_list_issue_types",description:"List issue types allowed for issue creation in the given project.",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Project key, e.g. PROJ"}},required:["projectKey"]}},{name:"jira_search",description:"Search Jira issues using JQL",input_schema:{type:"object",properties:{jql:{type:"string",description:'JQL query string, e.g. "project = PROJ AND status = Open"'},maxResults:{type:"number",description:"Max results to return (default 20)"}},required:["jql"]}},{name:"jira_get_issue",description:"Get details of a specific Jira issue",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"}},required:["issueKey"]}},{name:"jira_create_issue",description:"Create a new Jira issue",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Project key, e.g. PROJ"},summary:{type:"string",description:"Issue title/summary"},issueType:{type:"string",description:"Issue type (default: Task). Common: Task, Bug, Story, Epic"},description:{type:"string",description:"Issue description (plain text)"},priority:{type:"string",description:"Priority name, e.g. High, Medium, Low"},labels:{type:"array",items:{type:"string"},description:"Array of label strings"},assigneeId:{type:"string",description:"Atlassian account ID to assign to"},moveToSprint:{type:"boolean",description:"If true, move created issue to a sprint and verify."},moveToActiveSprint:{type:"boolean",description:"Backward-compatible alias for moveToSprint."},sprintId:{type:"number",description:"Optional sprint id for placement."},sprintName:{type:"string",description:"Optional sprint name for placement."},target:{type:"string",description:"Placement target when sprintId/sprintName omitted: current|active|latest (default: current)."}},required:["projectKey","summary"]}},{name:"jira_list_sprints",description:"List sprints for a Jira project (returns sprint names, IDs, states, dates)",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Project key, e.g. PROJ"},state:{type:"string",description:"Filter: active, closed, future. Omit for all."}},required:["projectKey"]}},{name:"jira_get_sprint_issues",description:"Get all issues in a sprint, optionally filtered by status column name",input_schema:{type:"object",properties:{sprintName:{type:"string",description:"Sprint name (from jira_list_sprints). Use this OR sprintId."},sprintId:{type:"number",description:"Sprint ID (from jira_list_sprints). Use this OR sprintName."},projectKey:{type:"string",description:"Project key to scope the search (optional)"},status:{type:"string",description:'Filter by status name (e.g. "\u8FDB\u884C\u4E2D", "\u6D4B\u8BD5", "Done")'},maxResults:{type:"number",description:"Max issues to return (default 50)"}}}},{name:"jira_move_to_active_sprint",description:"Backward-compatible alias: move issue to sprint target and verify membership.",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},projectKey:{type:"string",description:"Optional project key. If omitted, inferred from issue."},sprintId:{type:"number",description:"Optional sprint id."},sprintName:{type:"string",description:"Optional sprint name."},target:{type:"string",description:"Target when sprintId/sprintName omitted: current|active|latest (default: current)."}},required:["issueKey"]}},{name:"jira_move_issue_to_sprint",description:"Move an issue to a sprint by id/name/target and verify membership.",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},projectKey:{type:"string",description:"Optional project key. If omitted, inferred from issue."},sprintId:{type:"number",description:"Optional sprint id."},sprintName:{type:"string",description:"Optional sprint name."},target:{type:"string",description:"Target when sprintId/sprintName omitted: current|active|latest (default: current)."}},required:["issueKey"]}},{name:"jira_get_comments",description:"Get comments on a Jira issue (newest first)",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},maxResults:{type:"number",description:"Max comments to return (default 50)"}},required:["issueKey"]}},{name:"jira_add_comment",description:"Add a comment to a Jira issue",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},body:{type:"string",description:"Comment text (plain text)"}},required:["issueKey","body"]}},{name:"jira_edit_issue",description:"Update fields on a Jira issue (summary, story points, labels, priority)",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},fields:{type:"object",description:"Object of field names to values",additionalProperties:!0}},required:["issueKey","fields"]}},{name:"jira_transition_issue",description:"Move a Jira issue to a different status. Always pass toStatus when user gave a target; only pass issueKey alone when you explicitly need to list transitions.",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},transitionId:{type:"string",description:"Transition ID to perform (optional if toStatus is provided)"},toStatus:{type:"string",description:'Target status/column name (e.g. "\u5DF2\u7ECF\u9A8C\u6536", "Done", "In Progress"). If provided, tool resolves matching transition automatically.'}},required:["issueKey"]}}]};var Ce={new:"todo",indeterminate:"in_progress",done:"done"},Pe=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i;function Y(r){if(!r)return"unknown";if(r.name&&Pe.test(r.name))return"blocked";let s=r.statusCategory?.key;return Ce[s]||"unknown"}function W(r){if(!r)return"";if(Array.isArray(r))return r.map(W).join("");if(r.type==="text")return r.text||"";if(r.type==="hardBreak"||r.type==="rule")return`
70
+ `;let s=r.content?W(r.content):"";return/^(paragraph|heading|listItem|blockquote|codeBlock|panel)$/.test(r.type)&&(s+=`
71
+ `),s}function F(r,s){let e=r.fields||{},t=e.status||null,n=null;if(r.self&&r.key)try{n=`${new URL(r.self).origin}/browse/${r.key}`}catch{n=null}return!n&&s&&r.key&&(n=`${String(s).replace(/\/+$/,"")}/browse/${r.key}`),{id:String(r.id??r.key??""),key:r.key,title:e.summary||"",body:typeof e.description=="string"?e.description:W(e.description?.content).trim(),state:t?.name||null,stateCategory:Y(t),assignee:e.assignee?.displayName||null,url:n,_raw:r}}function z(r){let s=JSON.parse(r);if(s&&s.error)throw new Error(s.error);return s}var Q={id:"jira",toStateCategory:Y,toNeutral:F,async listCandidates(r={}){let s=r.query||"";if(!s.trim()){let i=[];if(r.state&&i.push(`status = "${r.state}"`),r.labels){let o=Array.isArray(r.labels)?r.labels:[r.labels];for(let a of o)i.push(`labels = "${a}"`)}r.updatedAfter&&i.push(`updated >= "${r.updatedAfter}"`),s=i.length?`${i.join(" AND ")} ORDER BY updated DESC`:"ORDER BY updated DESC"}let e=Number(r.limit)||30,t=`jql=${encodeURIComponent(s)}&maxResults=${e}&fields=summary,description,status,assignee,labels,project,updated,created`;return((await _(`/rest/api/3/search/jql?${t}`)).issues||[]).map(i=>F(i))},async getTicket(r){if(!r)throw new Error("key is required");let s=await _(`/rest/api/3/issue/${encodeURIComponent(r)}`);return!s||!s.key?null:F(s)},async getComments(r){if(!r)throw new Error("key is required");return(z(await q.handleToolCall("jira_get_comments",{issueKey:r})).comments||[]).map(e=>({id:String(e.id),author:e.author||"Unknown",body:e.body||"",createdAt:e.created||null,updatedAt:e.updated||null,_raw:e}))},async addComment(r,s){if(!r||!s)throw new Error("key and body are required");return{ok:!!z(await q.handleToolCall("jira_add_comment",{issueKey:r,body:s})).ok,id:null}},async transition(r,s){if(!r)throw new Error("key is required");let e=JSON.parse(await q.handleToolCall("jira_transition_issue",{issueKey:r,toStatus:s}));if(!e.ok)return{ok:!1,error:e.error||"transition failed",_raw:e};let t=e.statusAfter||null;return{ok:!0,stateAfter:t,stateCategoryAfter:Y(t?{name:t}:null),_raw:e}},async linkPullRequest(r,s,e){if(!r||!s)throw new Error("key and prUrl are required");try{return await _(`/rest/api/3/issue/${encodeURIComponent(r)}/remotelink`,{method:"POST",body:{object:{url:s,title:e||s,icon:{url16x16:"https://github.com/favicon.ico",title:"GitHub"}}}}),{ok:!0,via:"remotelink"}}catch(t){let n=`${e?`${e}: `:"Linked PR: "}${s}`;return{ok:!!z(await q.handleToolCall("jira_add_comment",{issueKey:r,body:n})).ok,via:"comment",error:String(t?.message||t)}}}};import{existsSync as Le}from"fs";import{fileURLToPath as qe}from"url";import{dirname as Je,resolve as xe}from"path";function Ue(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let r=Je(qe(import.meta.url)),s=xe(r,"..","bin","mcp-skill.mjs");return Le(s)?s:null}var Ge=process.env.LINEAR_API_URL||"https://api.linear.app/graphql";function Ke(){if(process.env.LINEAR_OAUTH_TOKEN)return`Bearer ${process.env.LINEAR_OAUTH_TOKEN}`;let r=process.env.LINEAR_API_KEY;if(!r)throw new Error("Linear is not connected: set LINEAR_API_KEY (personal API key) or LINEAR_OAUTH_TOKEN.");return r}async function k(r,s={}){let e=await fetch(Ge,{method:"POST",headers:{Authorization:Ke(),"Content-Type":"application/json"},body:JSON.stringify({query:r,variables:s})});if(!e.ok){let n=await e.text().catch(()=>"");throw new Error(`Linear API ${e.status}: ${n.slice(0,300)}`)}let t=await e.json().catch(()=>null);if(!t)throw new Error("Linear API returned a non-JSON body");if(Array.isArray(t.errors)&&t.errors.length){let n=t.errors.map(i=>i?.message||String(i)).join("; ");throw new Error(`Linear GraphQL error: ${n.slice(0,300)}`)}return t.data}function x(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function De(r,s){let e=x(r),t=x(s);if(!e||!t)return 0;if(e===t)return 1;if(e.length===1||t.length===1)return e===t?1:0;let n=l=>{let u=new Map;for(let m=0;m<l.length-1;m++){let y=l.slice(m,m+2);u.set(y,(u.get(y)||0)+1)}return u},i=n(e),o=n(t),a=0,c=0,d=0;for(let l of i.values())c+=l;for(let l of o.values())d+=l;for(let[l,u]of i.entries())a+=Math.min(u,o.get(l)||0);return 2*a/Math.max(1,c+d)}function He(r,s){let e=Array.isArray(r)?r:[];if(!e.length)return{state:null,strategy:"no-states"};let t=x(s);if(!t)return{state:null,strategy:"no-target"};let n=e.find(a=>x(a.name)===t);if(n)return{state:n,strategy:"exact"};let i={backlog:["backlog"],unstarted:["todo","unstarted","open"],started:["inprogress","started","doing","wip"],completed:["done","completed","closed","resolved","fixed"],canceled:["canceled","cancelled","wontfix","won'tfix"],triage:["triage"]};for(let[a,c]of Object.entries(i)){if(!c.some(l=>x(l)===t))continue;let d=e.find(l=>l.type===a);if(d)return{state:d,strategy:"type-alias"}}let o=e.map(a=>({s:a,score:De(s,a.name)})).sort((a,c)=>c.score-a.score);return o[0]&&o[0].score>=.5?{state:o[0].s,strategy:"fuzzy"}:{state:null,strategy:"no-match"}}var Me=`
72
72
  id
73
73
  identifier
74
74
  number
@@ -82,7 +82,7 @@ When user asks to move/transition ticket status:
82
82
  assignee { id name displayName email }
83
83
  labels { nodes { id name color } }
84
84
  team { id key name }
85
- `,N={id:"linear",serverName:"linear",allowedTools:["mcp__linear__*"],requiresIntegration:$.LINEAR,envKeys:["LINEAR_API_KEY","LINEAR_OAUTH_TOKEN"],description:"Linear \u2014 issues, comments, workflow states (GraphQL API key)",promptFragment:`## Linear (connected)
85
+ `,R={id:"linear",serverName:"linear",allowedTools:["mcp__linear__*"],requiresIntegration:T.LINEAR,envKeys:["LINEAR_API_KEY","LINEAR_OAUTH_TOKEN"],description:"Linear \u2014 issues, comments, workflow states (GraphQL API key)",promptFragment:`## Linear (connected)
86
86
  You have direct access to the user's Linear workspace (GraphQL API). Tools:
87
87
 
88
88
  ### Discovery
@@ -100,32 +100,32 @@ You have direct access to the user's Linear workspace (GraphQL API). Tools:
100
100
 
101
101
  ### Notes
102
102
  - Always resolve a team first when you need states or want to create/move issues by state name \u2014 states only make sense within their team.
103
- - Issue identifier (ENG-123) and internal id (uuid) are both accepted by get/update tools.`,resolve(){let r={};for(let e of this.envKeys)process.env[e]&&(r[e]=process.env[e]);process.env.LINEAR_API_URL&&(r.LINEAR_API_URL=process.env.LINEAR_API_URL);let s=Te();return s?{type:"stdio",command:"node",args:[s,"../dist/linear.js","linearSkill"],env:r,description:this.description,alwaysLoad:!0}:{command:null,args:[],env:r,description:this.description}},async handleToolCall(r,s){try{switch(r){case"linear_list_teams":{let t=(await A(`
103
+ - Issue identifier (ENG-123) and internal id (uuid) are both accepted by get/update tools.`,resolve(){let r={};for(let e of this.envKeys)process.env[e]&&(r[e]=process.env[e]);process.env.LINEAR_API_URL&&(r.LINEAR_API_URL=process.env.LINEAR_API_URL);let s=Ue();return s?{type:"stdio",command:"node",args:[s,"../dist/linear.js","linearSkill"],env:r,description:this.description,alwaysLoad:!0}:{command:null,args:[],env:r,description:this.description}},async handleToolCall(r,s){try{switch(r){case"linear_list_teams":{let t=(await k(`
104
104
  query Teams($first: Int) {
105
105
  teams(first: $first) {
106
106
  nodes { id key name description }
107
107
  }
108
108
  }
109
- `,{first:s?.limit||50}))?.teams?.nodes||[];return JSON.stringify({count:t.length,teams:t})}case"linear_list_states":{let{teamId:e,teamKey:t}=s||{},n=e;if(!n&&t&&(n=await ie(t)),n){let c=(await A(`
109
+ `,{first:s?.limit||50}))?.teams?.nodes||[];return JSON.stringify({count:t.length,teams:t})}case"linear_list_states":{let{teamId:e,teamKey:t}=s||{},n=e;if(!n&&t&&(n=await le(t)),n){let c=(await k(`
110
110
  query States($teamId: String!) {
111
111
  team(id: $teamId) {
112
112
  id key name
113
113
  states { nodes { id name type color position } }
114
114
  }
115
115
  }
116
- `,{teamId:n}))?.team,d=(c?.states?.nodes||[]).slice().sort((u,p)=>(u.position||0)-(p.position||0));return JSON.stringify({team:c?{id:c.id,key:c.key,name:c.name}:null,count:d.length,states:d})}let o=(await A(`
116
+ `,{teamId:n}))?.team,d=(c?.states?.nodes||[]).slice().sort((l,u)=>(l.position||0)-(u.position||0));return JSON.stringify({team:c?{id:c.id,key:c.key,name:c.name}:null,count:d.length,states:d})}let o=(await k(`
117
117
  query AllStates($first: Int) {
118
118
  workflowStates(first: $first) {
119
119
  nodes { id name type color team { id key name } }
120
120
  }
121
121
  }
122
- `,{first:s?.limit||200}))?.workflowStates?.nodes||[];return JSON.stringify({scope:"workspace",count:o.length,states:o})}case"linear_list_labels":{let{teamId:e}=s||{},n=(await A(`
122
+ `,{first:s?.limit||200}))?.workflowStates?.nodes||[];return JSON.stringify({scope:"workspace",count:o.length,states:o})}case"linear_list_labels":{let{teamId:e}=s||{},n=(await k(`
123
123
  query Labels($first: Int, $filter: IssueLabelFilter) {
124
124
  issueLabels(first: $first, filter: $filter) {
125
125
  nodes { id name color team { id key } }
126
126
  }
127
127
  }
128
- `,{first:s?.limit||100,filter:e?{team:{id:{eq:e}}}:void 0}))?.issueLabels?.nodes||[];return JSON.stringify({count:n.length,labels:n})}case"linear_list_issues":{let{teamId:e,teamKey:t,stateId:n,stateName:i,label:o,assigneeId:a,updatedAfter:c,limit:d}=s||{},u={},p=e;!p&&t&&(p=await ie(t)),p&&(u.team={id:{eq:p}}),n?u.state={id:{eq:n}}:i&&(u.state={name:{eqIgnoreCase:i}}),o&&(u.labels={name:{eqIgnoreCase:o}}),a&&(u.assignee={id:{eq:a}}),c&&(u.updatedAt={gt:c});let g=((await A(`
128
+ `,{first:s?.limit||100,filter:e?{team:{id:{eq:e}}}:void 0}))?.issueLabels?.nodes||[];return JSON.stringify({count:n.length,labels:n})}case"linear_list_issues":{let{teamId:e,teamKey:t,stateId:n,stateName:i,label:o,assigneeId:a,updatedAfter:c,limit:d}=s||{},l={},u=e;!u&&t&&(u=await le(t)),u&&(l.team={id:{eq:u}}),n?l.state={id:{eq:n}}:i&&(l.state={name:{eqIgnoreCase:i}}),o&&(l.labels={name:{eqIgnoreCase:o}}),a&&(l.assignee={id:{eq:a}}),c&&(l.updatedAt={gt:c});let y=((await k(`
129
129
  query Issues($first: Int, $filter: IssueFilter, $orderBy: PaginationOrderBy) {
130
130
  issues(first: $first, filter: $filter, orderBy: $orderBy) {
131
131
  nodes {
@@ -137,55 +137,55 @@ You have direct access to the user's Linear workspace (GraphQL API). Tools:
137
137
  }
138
138
  }
139
139
  }
140
- `,{first:d||30,filter:Object.keys(u).length?u:void 0,orderBy:"updatedAt"}))?.issues?.nodes||[]).map(l=>({id:l.id,identifier:l.identifier,number:l.number,title:l.title,url:l.url,priority:l.priority,state:l.state?.name,stateType:l.state?.type,assignee:l.assignee?.displayName||null,labels:(l.labels?.nodes||[]).map(y=>y.name),team:l.team?.key,createdAt:l.createdAt,updatedAt:l.updatedAt}));return JSON.stringify({count:g.length,issues:g})}case"linear_get_issue":{let e=s?.issueId||s?.identifier||s?.issueKey;if(!e)return JSON.stringify({error:"issueId or identifier is required"});let t=await T(e);return JSON.stringify(t?{id:t.id,identifier:t.identifier,number:t.number,title:t.title,description:t.description||"",url:t.url,priority:t.priority,state:t.state?.name,stateId:t.state?.id,stateType:t.state?.type,assignee:t.assignee?.displayName||t.assignee?.name||null,assigneeId:t.assignee?.id||null,labels:(t.labels?.nodes||[]).map(n=>n.name),team:t.team?{id:t.team.id,key:t.team.key,name:t.team.name}:null,createdAt:t.createdAt,updatedAt:t.updatedAt}:{error:`Issue not found: ${e}`})}case"linear_get_comments":{let e=s?.issueId||s?.identifier||s?.issueKey;if(!e)return JSON.stringify({error:"issueId or identifier is required"});let t=await T(e,`
140
+ `,{first:d||30,filter:Object.keys(l).length?l:void 0,orderBy:"updatedAt"}))?.issues?.nodes||[]).map(p=>({id:p.id,identifier:p.identifier,number:p.number,title:p.title,url:p.url,priority:p.priority,state:p.state?.name,stateType:p.state?.type,assignee:p.assignee?.displayName||null,labels:(p.labels?.nodes||[]).map(f=>f.name),team:p.team?.key,createdAt:p.createdAt,updatedAt:p.updatedAt}));return JSON.stringify({count:y.length,issues:y})}case"linear_get_issue":{let e=s?.issueId||s?.identifier||s?.issueKey;if(!e)return JSON.stringify({error:"issueId or identifier is required"});let t=await J(e);return JSON.stringify(t?{id:t.id,identifier:t.identifier,number:t.number,title:t.title,description:t.description||"",url:t.url,priority:t.priority,state:t.state?.name,stateId:t.state?.id,stateType:t.state?.type,assignee:t.assignee?.displayName||t.assignee?.name||null,assigneeId:t.assignee?.id||null,labels:(t.labels?.nodes||[]).map(n=>n.name),team:t.team?{id:t.team.id,key:t.team.key,name:t.team.name}:null,createdAt:t.createdAt,updatedAt:t.updatedAt}:{error:`Issue not found: ${e}`})}case"linear_get_comments":{let e=s?.issueId||s?.identifier||s?.issueKey;if(!e)return JSON.stringify({error:"issueId or identifier is required"});let t=await J(e,`
141
141
  id identifier
142
142
  comments(first: ${Number(s?.limit)||50}) {
143
143
  nodes { id body createdAt updatedAt user { id name displayName } }
144
144
  }
145
- `);if(!t)return JSON.stringify({error:`Issue not found: ${e}`});let n=(t.comments?.nodes||[]).map(i=>({id:i.id,author:i.user?.displayName||i.user?.name||"Unknown",body:i.body||"",createdAt:i.createdAt,updatedAt:i.updatedAt})).sort((i,o)=>String(o.createdAt).localeCompare(String(i.createdAt)));return JSON.stringify({count:n.length,issue:t.identifier,comments:n})}case"linear_add_comment":{let e=s?.issueId||s?.identifier||s?.issueKey,t=s?.body;if(!e||!t)return JSON.stringify({error:"issueId/identifier and body are required"});let n=await T(e,"id identifier");if(!n)return JSON.stringify({error:`Issue not found: ${e}`});let o=(await A(`
145
+ `);if(!t)return JSON.stringify({error:`Issue not found: ${e}`});let n=(t.comments?.nodes||[]).map(i=>({id:i.id,author:i.user?.displayName||i.user?.name||"Unknown",body:i.body||"",createdAt:i.createdAt,updatedAt:i.updatedAt})).sort((i,o)=>String(o.createdAt).localeCompare(String(i.createdAt)));return JSON.stringify({count:n.length,issue:t.identifier,comments:n})}case"linear_add_comment":{let e=s?.issueId||s?.identifier||s?.issueKey,t=s?.body;if(!e||!t)return JSON.stringify({error:"issueId/identifier and body are required"});let n=await J(e,"id identifier");if(!n)return JSON.stringify({error:`Issue not found: ${e}`});let o=(await k(`
146
146
  mutation AddComment($input: CommentCreateInput!) {
147
147
  commentCreate(input: $input) {
148
148
  success
149
149
  comment { id url createdAt }
150
150
  }
151
151
  }
152
- `,{input:{issueId:n.id,body:t}}))?.commentCreate;return JSON.stringify({ok:!!o?.success,commentId:o?.comment?.id,url:o?.comment?.url})}case"linear_update_state":{let e=s?.issueId||s?.identifier||s?.issueKey,{stateId:t,stateName:n,toStatus:i,status:o}=s||{};if(!e)return JSON.stringify({error:"issueId or identifier is required"});let a=await T(e,`
152
+ `,{input:{issueId:n.id,body:t}}))?.commentCreate;return JSON.stringify({ok:!!o?.success,commentId:o?.comment?.id,url:o?.comment?.url})}case"linear_update_state":{let e=s?.issueId||s?.identifier||s?.issueKey,{stateId:t,stateName:n,toStatus:i,status:o}=s||{};if(!e)return JSON.stringify({error:"issueId or identifier is required"});let a=await J(e,`
153
153
  id identifier
154
154
  state { id name type }
155
155
  team { id key states { nodes { id name type position } } }
156
- `);if(!a)return JSON.stringify({error:`Issue not found: ${e}`});let c=t,d=t?{strategy:"explicit-id"}:null;if(!c){let m=String(n||i||o||"").trim(),g=(a.team?.states?.nodes||[]).slice().sort((y,f)=>(y.position||0)-(f.position||0));if(!m)return JSON.stringify({ok:!1,error:"stateId or stateName/toStatus is required",issue:a.identifier,availableStates:g.map(y=>({id:y.id,name:y.name,type:y.type}))});let l=Je(g,m);if(!l.state)return JSON.stringify({ok:!1,error:`No workflow state matches "${m}" in team ${a.team?.key}`,issue:a.identifier,availableStates:g.map(y=>({id:y.id,name:y.name,type:y.type}))});c=l.state.id,d={strategy:l.strategy,matchedName:l.state.name}}let p=(await A(`
156
+ `);if(!a)return JSON.stringify({error:`Issue not found: ${e}`});let c=t,d=t?{strategy:"explicit-id"}:null;if(!c){let m=String(n||i||o||"").trim(),y=(a.team?.states?.nodes||[]).slice().sort((f,h)=>(f.position||0)-(h.position||0));if(!m)return JSON.stringify({ok:!1,error:"stateId or stateName/toStatus is required",issue:a.identifier,availableStates:y.map(f=>({id:f.id,name:f.name,type:f.type}))});let p=He(y,m);if(!p.state)return JSON.stringify({ok:!1,error:`No workflow state matches "${m}" in team ${a.team?.key}`,issue:a.identifier,availableStates:y.map(f=>({id:f.id,name:f.name,type:f.type}))});c=p.state.id,d={strategy:p.strategy,matchedName:p.state.name}}let u=(await k(`
157
157
  mutation MoveIssue($id: String!, $input: IssueUpdateInput!) {
158
158
  issueUpdate(id: $id, input: $input) {
159
159
  success
160
160
  issue { id identifier state { id name type } }
161
161
  }
162
162
  }
163
- `,{id:a.id,input:{stateId:c}}))?.issueUpdate;return JSON.stringify({ok:!!p?.success,issue:p?.issue?.identifier||a.identifier,stateAfter:p?.issue?.state?.name||null,stateTypeAfter:p?.issue?.state?.type||null,resolution:d})}case"linear_link_attachment":{let e=s?.issueId||s?.identifier||s?.issueKey,{url:t,title:n,subtitle:i}=s||{};if(!e||!t)return JSON.stringify({error:"issueId/identifier and url are required"});let o=await T(e,"id identifier");if(!o)return JSON.stringify({error:`Issue not found: ${e}`});let c=(await A(`
163
+ `,{id:a.id,input:{stateId:c}}))?.issueUpdate;return JSON.stringify({ok:!!u?.success,issue:u?.issue?.identifier||a.identifier,stateAfter:u?.issue?.state?.name||null,stateTypeAfter:u?.issue?.state?.type||null,resolution:d})}case"linear_link_attachment":{let e=s?.issueId||s?.identifier||s?.issueKey,{url:t,title:n,subtitle:i}=s||{};if(!e||!t)return JSON.stringify({error:"issueId/identifier and url are required"});let o=await J(e,"id identifier");if(!o)return JSON.stringify({error:`Issue not found: ${e}`});let c=(await k(`
164
164
  mutation LinkAttachment($input: AttachmentCreateInput!) {
165
165
  attachmentCreate(input: $input) {
166
166
  success
167
167
  attachment { id url title }
168
168
  }
169
169
  }
170
- `,{input:{issueId:o.id,url:t,title:n||t,subtitle:i||void 0}}))?.attachmentCreate;return JSON.stringify({ok:!!c?.success,attachmentId:c?.attachment?.id,url:c?.attachment?.url})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"linear_list_teams",description:"List Linear teams (id, key, name). Needed to scope workflow states and issue queries.",input_schema:{type:"object",properties:{limit:{type:"number",description:"Max teams (default: 50)"}}}},{name:"linear_list_states",description:"List a team's workflow states (id, name, type: backlog|unstarted|started|completed|canceled|triage). Linear states are PER-TEAM. Omit team to list all states across the workspace.",input_schema:{type:"object",properties:{teamId:{type:"string",description:"Team uuid"},teamKey:{type:"string",description:"Team key (e.g. ENG); resolved to an id if teamId omitted"},limit:{type:"number",description:"Max states when listing workspace-wide (default: 200)"}}}},{name:"linear_list_labels",description:"List issue labels, optionally scoped to a team.",input_schema:{type:"object",properties:{teamId:{type:"string",description:"Optional team uuid to scope labels"},limit:{type:"number",description:"Max labels (default: 100)"}}}},{name:"linear_list_issues",description:"List/poll Linear issues filtered by team, state, label, assignee, and an updatedAfter cursor. Returns newest-updated first.",input_schema:{type:"object",properties:{teamId:{type:"string",description:"Team uuid"},teamKey:{type:"string",description:"Team key (e.g. ENG); resolved if teamId omitted"},stateId:{type:"string",description:"Filter by workflow state uuid"},stateName:{type:"string",description:"Filter by state name (case-insensitive)"},label:{type:"string",description:"Filter by label name (case-insensitive)"},assigneeId:{type:"string",description:"Filter by assignee uuid"},updatedAfter:{type:"string",description:"ISO-8601 timestamp; only issues updated after this (polling cursor)"},limit:{type:"number",description:"Max issues (default: 30)"}}}},{name:"linear_get_issue",description:"Get a single Linear issue by identifier (e.g. ENG-123) or internal uuid \u2014 title, description, state, labels, assignee, url.",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"}}}},{name:"linear_get_comments",description:"Get comments on a Linear issue (newest first).",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},limit:{type:"number",description:"Max comments (default: 50)"}}}},{name:"linear_add_comment",description:"Add a comment to a Linear issue (markdown supported).",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},body:{type:"string",description:"Comment body (markdown)"}},required:["body"]}},{name:"linear_update_state",description:"Move a Linear issue to a different workflow state. Pass a state NAME (toStatus/stateName) and the tool resolves it to the issue's team's matching state id (exact -> type-alias -> fuzzy), or pass stateId directly. Linear has no transitions \u2014 this sets the state.",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},stateId:{type:"string",description:"Target workflow state uuid (skips name resolution)"},stateName:{type:"string",description:'Target state name (e.g. "In Progress", "Done")'},toStatus:{type:"string",description:"Alias for stateName"}}}},{name:"linear_link_attachment",description:"Attach a URL (e.g. a GitHub PR) to a Linear issue via native attachments. Use this for PR links; fall back to linear_add_comment if it fails.",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},url:{type:"string",description:"The URL to attach (e.g. a PR link)"},title:{type:"string",description:"Attachment title (defaults to the URL)"},subtitle:{type:"string",description:"Optional attachment subtitle"}},required:["url"]}}]};async function ie(r){return(await A(`
170
+ `,{input:{issueId:o.id,url:t,title:n||t,subtitle:i||void 0}}))?.attachmentCreate;return JSON.stringify({ok:!!c?.success,attachmentId:c?.attachment?.id,url:c?.attachment?.url})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"linear_list_teams",description:"List Linear teams (id, key, name). Needed to scope workflow states and issue queries.",input_schema:{type:"object",properties:{limit:{type:"number",description:"Max teams (default: 50)"}}}},{name:"linear_list_states",description:"List a team's workflow states (id, name, type: backlog|unstarted|started|completed|canceled|triage). Linear states are PER-TEAM. Omit team to list all states across the workspace.",input_schema:{type:"object",properties:{teamId:{type:"string",description:"Team uuid"},teamKey:{type:"string",description:"Team key (e.g. ENG); resolved to an id if teamId omitted"},limit:{type:"number",description:"Max states when listing workspace-wide (default: 200)"}}}},{name:"linear_list_labels",description:"List issue labels, optionally scoped to a team.",input_schema:{type:"object",properties:{teamId:{type:"string",description:"Optional team uuid to scope labels"},limit:{type:"number",description:"Max labels (default: 100)"}}}},{name:"linear_list_issues",description:"List/poll Linear issues filtered by team, state, label, assignee, and an updatedAfter cursor. Returns newest-updated first.",input_schema:{type:"object",properties:{teamId:{type:"string",description:"Team uuid"},teamKey:{type:"string",description:"Team key (e.g. ENG); resolved if teamId omitted"},stateId:{type:"string",description:"Filter by workflow state uuid"},stateName:{type:"string",description:"Filter by state name (case-insensitive)"},label:{type:"string",description:"Filter by label name (case-insensitive)"},assigneeId:{type:"string",description:"Filter by assignee uuid"},updatedAfter:{type:"string",description:"ISO-8601 timestamp; only issues updated after this (polling cursor)"},limit:{type:"number",description:"Max issues (default: 30)"}}}},{name:"linear_get_issue",description:"Get a single Linear issue by identifier (e.g. ENG-123) or internal uuid \u2014 title, description, state, labels, assignee, url.",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"}}}},{name:"linear_get_comments",description:"Get comments on a Linear issue (newest first).",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},limit:{type:"number",description:"Max comments (default: 50)"}}}},{name:"linear_add_comment",description:"Add a comment to a Linear issue (markdown supported).",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},body:{type:"string",description:"Comment body (markdown)"}},required:["body"]}},{name:"linear_update_state",description:"Move a Linear issue to a different workflow state. Pass a state NAME (toStatus/stateName) and the tool resolves it to the issue's team's matching state id (exact -> type-alias -> fuzzy), or pass stateId directly. Linear has no transitions \u2014 this sets the state.",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},stateId:{type:"string",description:"Target workflow state uuid (skips name resolution)"},stateName:{type:"string",description:'Target state name (e.g. "In Progress", "Done")'},toStatus:{type:"string",description:"Alias for stateName"}}}},{name:"linear_link_attachment",description:"Attach a URL (e.g. a GitHub PR) to a Linear issue via native attachments. Use this for PR links; fall back to linear_add_comment if it fails.",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},url:{type:"string",description:"The URL to attach (e.g. a PR link)"},title:{type:"string",description:"Attachment title (defaults to the URL)"},subtitle:{type:"string",description:"Optional attachment subtitle"}},required:["url"]}}]};async function le(r){return(await k(`
171
171
  query TeamByKey($filter: TeamFilter) {
172
172
  teams(first: 1, filter: $filter) { nodes { id key } }
173
173
  }
174
- `,{filter:{key:{eq:r}}}))?.teams?.nodes?.[0]?.id||null}async function T(r,s=xe){let e=String(r).trim(),t=/^([A-Za-z][A-Za-z0-9]*)-(\d+)$/.exec(e);if(t){let i=t[1].toUpperCase(),o=Number(t[2]);return(await A(`
174
+ `,{filter:{key:{eq:r}}}))?.teams?.nodes?.[0]?.id||null}async function J(r,s=Me){let e=String(r).trim(),t=/^([A-Za-z][A-Za-z0-9]*)-(\d+)$/.exec(e);if(t){let i=t[1].toUpperCase(),o=Number(t[2]);return(await k(`
175
175
  query IssueByIdentifier($filter: IssueFilter) {
176
176
  issues(first: 1, filter: $filter) {
177
177
  nodes { ${s} }
178
178
  }
179
179
  }
180
- `,{filter:{number:{eq:o},team:{key:{eq:i}}}}))?.issues?.nodes?.[0]||null}return(await A(`
180
+ `,{filter:{number:{eq:o},team:{key:{eq:i}}}}))?.issues?.nodes?.[0]||null}return(await k(`
181
181
  query IssueById($id: String!) {
182
182
  issue(id: $id) { ${s} }
183
183
  }
184
- `,{id:e}))?.issue||null}var Ue={triage:"todo",backlog:"todo",unstarted:"todo",started:"in_progress",completed:"done",canceled:"done"},Ge=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i;function Y(r){return r?r.name&&Ge.test(r.name)?"blocked":Ue[r.type]||"unknown":"unknown"}function L(r){let s=JSON.parse(r);if(s&&s.error)throw new Error(s.error);return s}function z(r){let s=r.state||null,e=r.stateType||null;return{id:String(r.id||r.identifier||""),key:r.identifier||String(r.id||""),title:r.title||"",body:r.description||"",state:s,stateCategory:Y(s?{name:s,type:e}:null),assignee:r.assignee||null,url:r.url||null,_raw:r}}var W={id:"linear",toStateCategory:Y,toNeutral:z,async listCandidates(r={}){let s=r.ctx||{},e={teamId:s.teamId,teamKey:s.teamKey,stateName:r.state,label:Array.isArray(r.labels)?r.labels[0]:r.labels,assigneeId:s.assigneeId,updatedAfter:r.updatedAfter,limit:r.limit};return(L(await N.handleToolCall("linear_list_issues",e)).issues||[]).map(z)},async getTicket(r){if(!r)throw new Error("key is required");let s=JSON.parse(await N.handleToolCall("linear_get_issue",{identifier:r}));return s.error?null:z(s)},async getComments(r){if(!r)throw new Error("key is required");return(L(await N.handleToolCall("linear_get_comments",{identifier:r})).comments||[]).map(e=>({id:String(e.id),author:e.author||"Unknown",body:e.body||"",createdAt:e.createdAt||null,updatedAt:e.updatedAt||null,_raw:e}))},async addComment(r,s){if(!r||!s)throw new Error("key and body are required");let e=L(await N.handleToolCall("linear_add_comment",{identifier:r,body:s}));return{ok:!!e.ok,id:e.commentId||null}},async transition(r,s){if(!r)throw new Error("key is required");let e=JSON.parse(await N.handleToolCall("linear_update_state",{identifier:r,toStatus:s}));if(!e.ok)return{ok:!1,error:e.error||"state update failed",_raw:e};let t=e.stateAfter||null;return{ok:!0,stateAfter:t,stateCategoryAfter:Y(t?{name:t,type:e.stateTypeAfter}:null),_raw:e}},async linkPullRequest(r,s,e){if(!r||!s)throw new Error("key and prUrl are required");try{if(L(await N.handleToolCall("linear_link_attachment",{identifier:r,url:s,title:e||s})).ok)return{ok:!0,via:"attachment"};throw new Error("attachmentCreate returned ok:false")}catch(t){let n=`${e?`${e}: `:"Linked PR: "}${s}`;return{ok:!!L(await N.handleToolCall("linear_add_comment",{identifier:r,body:n})).ok,via:"comment",error:String(t?.message||t)}}}};import{existsSync as Ke}from"fs";import{fileURLToPath as De}from"url";import{dirname as Me,resolve as He}from"path";import{resolveIntegrationToken as ne}from"@zibby/core/backend-client.js";function Be(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let r=Me(De(import.meta.url)),s=He(r,"..","bin","mcp-skill.mjs");return Ke(s)?s:null}async function h(r,s={}){let{token:e}=await ne("github"),t=r.startsWith("https://")?r:`https://api.github.com${r}`,n={Authorization:`Bearer ${e}`,Accept:s.accept||"application/vnd.github.v3+json","User-Agent":"Zibby-App",...s.body?{"Content-Type":"application/json"}:{}},i=await fetch(t,{method:s.method||"GET",headers:n,body:s.body?JSON.stringify(s.body):void 0});if(!i.ok){let o=await i.text().catch(()=>"");throw new Error(`GitHub API ${i.status}: ${o.slice(0,300)}`)}return s.raw?i.text():i.json()}var k={id:"github",serverName:"github",allowedTools:["mcp__github__*"],requiresIntegration:$.GITHUB,envKeys:["GITHUB_TOKEN"],description:"GitHub \u2014 issues, PRs, commits, code search, file reading",promptFragment:`## GitHub (connected)
184
+ `,{id:e}))?.issue||null}var Be={triage:"todo",backlog:"todo",unstarted:"todo",started:"in_progress",completed:"done",canceled:"done"},Fe=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i;function Z(r){return r?r.name&&Fe.test(r.name)?"blocked":Be[r.type]||"unknown":"unknown"}function U(r){let s=JSON.parse(r);if(s&&s.error)throw new Error(s.error);return s}function V(r){let s=r.state||null,e=r.stateType||null;return{id:String(r.id||r.identifier||""),key:r.identifier||String(r.id||""),title:r.title||"",body:r.description||"",state:s,stateCategory:Z(s?{name:s,type:e}:null),assignee:r.assignee||null,url:r.url||null,_raw:r}}var X={id:"linear",toStateCategory:Z,toNeutral:V,async listCandidates(r={}){let s=r.ctx||{},e={teamId:s.teamId,teamKey:s.teamKey,stateName:r.state,label:Array.isArray(r.labels)?r.labels[0]:r.labels,assigneeId:s.assigneeId,updatedAfter:r.updatedAfter,limit:r.limit};return(U(await R.handleToolCall("linear_list_issues",e)).issues||[]).map(V)},async getTicket(r){if(!r)throw new Error("key is required");let s=JSON.parse(await R.handleToolCall("linear_get_issue",{identifier:r}));return s.error?null:V(s)},async getComments(r){if(!r)throw new Error("key is required");return(U(await R.handleToolCall("linear_get_comments",{identifier:r})).comments||[]).map(e=>({id:String(e.id),author:e.author||"Unknown",body:e.body||"",createdAt:e.createdAt||null,updatedAt:e.updatedAt||null,_raw:e}))},async addComment(r,s){if(!r||!s)throw new Error("key and body are required");let e=U(await R.handleToolCall("linear_add_comment",{identifier:r,body:s}));return{ok:!!e.ok,id:e.commentId||null}},async transition(r,s){if(!r)throw new Error("key is required");let e=JSON.parse(await R.handleToolCall("linear_update_state",{identifier:r,toStatus:s}));if(!e.ok)return{ok:!1,error:e.error||"state update failed",_raw:e};let t=e.stateAfter||null;return{ok:!0,stateAfter:t,stateCategoryAfter:Z(t?{name:t,type:e.stateTypeAfter}:null),_raw:e}},async linkPullRequest(r,s,e){if(!r||!s)throw new Error("key and prUrl are required");try{if(U(await R.handleToolCall("linear_link_attachment",{identifier:r,url:s,title:e||s})).ok)return{ok:!0,via:"attachment"};throw new Error("attachmentCreate returned ok:false")}catch(t){let n=`${e?`${e}: `:"Linked PR: "}${s}`;return{ok:!!U(await R.handleToolCall("linear_add_comment",{identifier:r,body:n})).ok,via:"comment",error:String(t?.message||t)}}}};import{existsSync as ze}from"fs";import{fileURLToPath as Ye}from"url";import{dirname as We,resolve as Qe}from"path";import{resolveIntegrationToken as ue}from"@zibby/core/backend-client.js";function Ve(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let r=We(Ye(import.meta.url)),s=Qe(r,"..","bin","mcp-skill.mjs");return ze(s)?s:null}async function b(r,s={}){let{token:e}=await ue("github"),t=r.startsWith("https://")?r:`https://api.github.com${r}`,n={Authorization:`Bearer ${e}`,Accept:s.accept||"application/vnd.github.v3+json","User-Agent":"Zibby-App",...s.body?{"Content-Type":"application/json"}:{}},i=await fetch(t,{method:s.method||"GET",headers:n,body:s.body?JSON.stringify(s.body):void 0});if(!i.ok){let o=await i.text().catch(()=>"");throw new Error(`GitHub API ${i.status}: ${o.slice(0,300)}`)}return s.raw?i.text():i.json()}var I={id:"github",serverName:"github",allowedTools:["mcp__github__*"],requiresIntegration:T.GITHUB,envKeys:["GITHUB_TOKEN"],description:"GitHub \u2014 issues, PRs, commits, code search, file reading",promptFragment:`## GitHub (connected)
185
185
  You have access to the user's GitHub repositories. Available tools:
186
186
 
187
187
  ### Discovery
188
- - github_list_repos: Lists ALL accessible repos (personal + orgs, private + public, up to 200 repos)
188
+ - github_list_repos: Lists ALL accessible repos (personal + orgs, private + public, up to 200 repos). Use to find a RELATED repo worth cloning for cross-repo context.
189
189
  - github_search_repos: Search for a specific repo by name (e.g., "electron", "my-app")
190
190
  - github_get_user: Get authenticated user's profile
191
191
  - github_list_orgs: List organizations with accessible repos
@@ -203,6 +203,9 @@ You have access to the user's GitHub repositories. Available tools:
203
203
  - github_get_pr_diff: Get PR diff
204
204
  - github_list_pr_files: List PR changed files
205
205
  - github_list_pr_comments: Get PR comments
206
+ - github_get_review_thread: Read a review-comment THREAD (root + replies) with its diff context, given any comment id in it
207
+ - github_reply_review_thread: Reply IN-THREAD to an existing review-comment thread (conversational reply, not a new review)
208
+ - github_reply_issue_comment: Reply on the PR's top-level conversation (for non-inline/summary comments)
206
209
  - github_create_review: Post a review on a PR \u2014 a summary body plus optional inline comments on specific file/line positions, with an event (COMMENT, APPROVE, or REQUEST_CHANGES)
207
210
  - github_create_issue: Create new issue
208
211
  - github_list_issues: List issues in a repo (filter by state/labels/since cursor) \u2014 excludes PRs
@@ -219,6 +222,6 @@ When user says "check out repo-name" or "clone repo-name":
219
222
  3. STOP. Do not offer to inspect files or ask what to do next.
220
223
 
221
224
  When user just wants to "look at" or "read" files (not clone):
222
- - Use github_get_file to read individual files via API`,resolve(){let r=Be();if(!r)return{command:null,args:[],env:{},description:this.description};let s={};for(let e of this.envKeys)process.env[e]&&(s[e]=process.env[e]);return{type:"stdio",command:"node",args:[r,"../dist/github.js","githubSkill"],env:s,description:this.description,alwaysLoad:!0}},async handleToolCall(r,s){try{switch(r){case"github_search_issues":{let e=s.query;if(!e)return JSON.stringify({error:"query is required"});let t=await h(`/search/issues?q=${encodeURIComponent(e)}&per_page=${s.limit||20}`),n=(t.items||[]).map(i=>({number:i.number,title:i.title,state:i.state,repo:i.repository_url?.split("/").slice(-2).join("/"),url:i.html_url,user:i.user?.login,isPR:!!i.pull_request,labels:(i.labels||[]).map(o=>o.name),createdAt:i.created_at}));return JSON.stringify({total:t.total_count,items:n})}case"github_search_code":{let e=s.query;if(!e)return JSON.stringify({error:"query is required"});let t=s.repo?`+repo:${s.repo}`:"",n=s.language?`+language:${s.language}`:"",i=await h(`/search/code?q=${encodeURIComponent(e)}${t}${n}&per_page=${s.limit||15}`),o=(i.items||[]).map(a=>({name:a.name,path:a.path,repo:a.repository?.full_name,url:a.html_url,score:a.score}));return JSON.stringify({total:i.total_count,items:o})}case"github_get_pr":{let{owner:e,repo:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/pulls/${n}`);return JSON.stringify({number:i.number,title:i.title,state:i.state,merged:i.merged,body:i.body?.slice(0,5e3),user:i.user?.login,branch:i.head?.ref,headSha:i.head?.sha,base:i.base?.ref,changedFiles:i.changed_files,additions:i.additions,deletions:i.deletions,createdAt:i.created_at,mergedAt:i.merged_at,url:i.html_url,labels:(i.labels||[]).map(o=>o.name)})}case"github_get_pr_diff":{let{owner:e,repo:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/pulls/${n}`,{accept:"application/vnd.github.v3.diff",raw:!0}),o=i.length>15e3;return JSON.stringify({number:n,diff:o?i.slice(0,15e3):i,truncated:o,totalLength:i.length})}case"github_list_pr_files":{let{owner:e,repo:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/pulls/${n}/files?per_page=100`);return JSON.stringify({total:i.length,files:i.map(o=>({filename:o.filename,status:o.status,additions:o.additions,deletions:o.deletions,patch:o.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:e,repo:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/pulls/${n}/comments?per_page=50`),o=await h(`/repos/${e}/${t}/issues/${n}/comments?per_page=50`),a=[...i.map(c=>({type:"review",user:c.user?.login,body:c.body?.slice(0,1e3),path:c.path,line:c.line,createdAt:c.created_at})),...o.map(c=>({type:"issue",user:c.user?.login,body:c.body?.slice(0,1e3),createdAt:c.created_at}))].sort((c,d)=>new Date(c.createdAt)-new Date(d.createdAt));return JSON.stringify({total:a.length,comments:a})}case"github_create_review":{let{owner:e,repo:t,number:n,body:i,event:o,comments:a}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let c=(o||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(c))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${o})`});let d=Array.isArray(a)?a.filter(m=>m&&m.path&&m.body&&(m.line!=null||m.position!=null)).map(m=>{let g={path:m.path,body:String(m.body)};return m.line!=null?(g.line=Number(m.line),g.side=m.side==="LEFT"?"LEFT":"RIGHT"):g.position=Number(m.position),g}):[];if(c!=="APPROVE"&&!i&&d.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let u={event:c};i&&(u.body=String(i)),d.length>0&&(u.comments=d);let p=await h(`/repos/${e}/${t}/pulls/${n}/reviews`,{method:"POST",body:u});return JSON.stringify({ok:!0,id:p.id,state:p.state,event:c,commentsPosted:d.length,url:p.html_url})}case"github_list_commits":{let{owner:e,repo:t,branch:n,path:i,limit:o}=s;if(!e||!t)return JSON.stringify({error:"owner and repo are required"});let a=`/repos/${e}/${t}/commits?per_page=${o||20}`;n&&(a+=`&sha=${encodeURIComponent(n)}`),i&&(a+=`&path=${encodeURIComponent(i)}`);let c=await h(a);return JSON.stringify({total:c.length,commits:c.map(d=>({sha:d.sha?.slice(0,8),fullSha:d.sha,message:d.commit?.message?.slice(0,300),author:d.commit?.author?.name,date:d.commit?.author?.date,url:d.html_url}))})}case"github_get_commit":{let{owner:e,repo:t,sha:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and sha are required"});let i=await h(`/repos/${e}/${t}/commits/${n}`);return JSON.stringify({sha:i.sha?.slice(0,8),message:i.commit?.message,author:i.commit?.author?.name,date:i.commit?.author?.date,stats:i.stats,files:(i.files||[]).map(o=>({filename:o.filename,status:o.status,additions:o.additions,deletions:o.deletions,patch:o.patch?.slice(0,3e3)}))})}case"github_get_file":{let{owner:e,repo:t,path:n,ref:i}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and path are required"});let o=`/repos/${e}/${t}/contents/${encodeURIComponent(n)}`;i&&(o+=`?ref=${encodeURIComponent(i)}`);let a=await h(o);if(a.type!=="file")return Array.isArray(a)?JSON.stringify({type:"directory",path:n,entries:a.map(u=>({name:u.name,type:u.type,size:u.size,path:u.path}))}):JSON.stringify({error:`Not a file: ${a.type}`});let c=Buffer.from(a.content||"","base64").toString("utf-8"),d=c.length>2e4;return JSON.stringify({path:a.path,size:a.size,sha:a.sha?.slice(0,8),content:d?c.slice(0,2e4):c,truncated:d})}case"github_get_user":try{let e=await h("/installation/repositories?per_page=1");if(e.repositories&&e.repositories.length>0){let t=e.repositories[0],n=t.owner.login,i=t.owner.type,o=i==="Organization"?`/orgs/${n}`:`/users/${n}`,a=await h(o);return JSON.stringify({login:a.login,name:a.name||a.login,avatar:a.avatar_url,bio:a.bio||a.description,type:i,isOrg:i==="Organization",publicRepos:a.public_repos,message:"Showing GitHub App installation owner (GitHub Apps cannot access /user endpoint)"})}return JSON.stringify({error:"No repositories accessible to this GitHub App installation"})}catch(e){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${e.message})`})}case"github_list_orgs":try{let t=(await h("/installation/repositories?per_page=100")).repositories||[],n=new Map;for(let o of t)o.owner.type==="Organization"&&(n.has(o.owner.login)||n.set(o.owner.login,{login:o.owner.login,description:null,url:o.owner.url}));let i=Array.from(n.values());return JSON.stringify({count:i.length,orgs:i,message:"Extracted from accessible repositories (GitHub Apps cannot access /user/orgs directly)"})}catch(e){return JSON.stringify({error:`GitHub App cannot list orgs via /user/orgs. Error: ${e.message}`})}case"github_clone":{let l=function(S){let w=S.replace(/^~(?=$|\/|\\)/,g);return a(w)},{owner:e,repo:t,destination:n}=s;if(!e||!t)return JSON.stringify({error:"owner and repo are required"});let{execSync:i}=await import("child_process"),{join:o,resolve:a}=await import("path"),{existsSync:c,mkdirSync:d}=await import("fs"),{homedir:u,platform:p}=await import("os"),{token:m}=await ne("github"),g=u(),y=n?l(n):o(g,"zibby-repos"),f=o(y,t);if(d(y,{recursive:!0}),c(f))return JSON.stringify({error:`Directory ${f} already exists. Remove it first or use a different destination.`,existingPath:f});try{let S=`https://x-access-token:${m}@github.com/${e}/${t}.git`;i(`git clone ${S} "${f}"`,{stdio:"pipe"});let w=p()==="win32",b;return w?b=i(`dir "${f}"`,{encoding:"utf-8",shell:"cmd.exe"}):b=i(`ls -la "${f}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:f,message:`Cloned ${e}/${t} to ${f}`,contents:b.split(`
225
+ - Use github_get_file to read individual files via API`,resolve(){let r=Ve();if(!r)return{command:null,args:[],env:{},description:this.description};let s={};for(let e of this.envKeys)process.env[e]&&(s[e]=process.env[e]);return{type:"stdio",command:"node",args:[r,"../dist/github.js","githubSkill"],env:s,description:this.description,alwaysLoad:!0}},async handleToolCall(r,s){try{switch(r){case"github_search_issues":{let e=s.query;if(!e)return JSON.stringify({error:"query is required"});let t=await b(`/search/issues?q=${encodeURIComponent(e)}&per_page=${s.limit||20}`),n=(t.items||[]).map(i=>({number:i.number,title:i.title,state:i.state,repo:i.repository_url?.split("/").slice(-2).join("/"),url:i.html_url,user:i.user?.login,isPR:!!i.pull_request,labels:(i.labels||[]).map(o=>o.name),createdAt:i.created_at}));return JSON.stringify({total:t.total_count,items:n})}case"github_search_code":{let e=s.query;if(!e)return JSON.stringify({error:"query is required"});let t=s.repo?`+repo:${s.repo}`:"",n=s.language?`+language:${s.language}`:"",i=await b(`/search/code?q=${encodeURIComponent(e)}${t}${n}&per_page=${s.limit||15}`),o=(i.items||[]).map(a=>({name:a.name,path:a.path,repo:a.repository?.full_name,url:a.html_url,score:a.score}));return JSON.stringify({total:i.total_count,items:o})}case"github_get_pr":{let{owner:e,repo:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await b(`/repos/${e}/${t}/pulls/${n}`);return JSON.stringify({number:i.number,title:i.title,state:i.state,merged:i.merged,body:i.body?.slice(0,5e3),user:i.user?.login,branch:i.head?.ref,headSha:i.head?.sha,base:i.base?.ref,changedFiles:i.changed_files,additions:i.additions,deletions:i.deletions,createdAt:i.created_at,mergedAt:i.merged_at,url:i.html_url,labels:(i.labels||[]).map(o=>o.name)})}case"github_get_pr_diff":{let{owner:e,repo:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await b(`/repos/${e}/${t}/pulls/${n}`,{accept:"application/vnd.github.v3.diff",raw:!0}),o=i.length>15e3;return JSON.stringify({number:n,diff:o?i.slice(0,15e3):i,truncated:o,totalLength:i.length})}case"github_list_pr_files":{let{owner:e,repo:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await b(`/repos/${e}/${t}/pulls/${n}/files?per_page=100`);return JSON.stringify({total:i.length,files:i.map(o=>({filename:o.filename,status:o.status,additions:o.additions,deletions:o.deletions,patch:o.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:e,repo:t,number:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await b(`/repos/${e}/${t}/pulls/${n}/comments?per_page=50`),o=await b(`/repos/${e}/${t}/issues/${n}/comments?per_page=50`),a=[...i.map(c=>({type:"review",user:c.user?.login,body:c.body?.slice(0,1e3),path:c.path,line:c.line,createdAt:c.created_at})),...o.map(c=>({type:"issue",user:c.user?.login,body:c.body?.slice(0,1e3),createdAt:c.created_at}))].sort((c,d)=>new Date(c.createdAt)-new Date(d.createdAt));return JSON.stringify({total:a.length,comments:a})}case"github_get_review_thread":{let{owner:e,repo:t,number:n,commentId:i}=s||{};if(!e||!t||!n||!i)return JSON.stringify({error:"owner, repo, number, and commentId are required"});let o=await b(`/repos/${e}/${t}/pulls/comments/${i}`),a=o.in_reply_to_id||o.id,c=[];try{c=await b(`/repos/${e}/${t}/pulls/${n}/comments?per_page=100`)}catch{c=[o]}(!Array.isArray(c)||c.length===0)&&(c=[o]);let d=c.filter(m=>m.id===a||m.in_reply_to_id===a).sort((m,y)=>new Date(m.created_at)-new Date(y.created_at)),l=d.length?d:[o],u=l.find(m=>m.id===a)||l[0];return JSON.stringify({rootCommentId:a,path:u.path,line:u.line??u.original_line??null,side:u.side||"RIGHT",diffHunk:typeof u.diff_hunk=="string"?u.diff_hunk.slice(0,3e3):null,commitId:u.commit_id||u.original_commit_id||null,notes:l.map(m=>({id:m.id,user:m.user?.login,body:(m.body||"").slice(0,4e3),createdAt:m.created_at,isRoot:m.id===a,url:m.html_url}))})}case"github_reply_review_thread":{let{owner:e,repo:t,number:n,commentId:i,body:o}=s||{};if(!e||!t||!n||!i||!o)return JSON.stringify({error:"owner, repo, number, commentId, and body are required"});let a=await b(`/repos/${e}/${t}/pulls/${n}/comments/${i}/replies`,{method:"POST",body:{body:String(o)}});return JSON.stringify({ok:!0,id:a.id,url:a.html_url,inReplyTo:a.in_reply_to_id})}case"github_reply_issue_comment":{let{owner:e,repo:t,number:n,body:i}=s||{};if(!e||!t||!n||!i)return JSON.stringify({error:"owner, repo, number, and body are required"});let o=await b(`/repos/${e}/${t}/issues/${n}/comments`,{method:"POST",body:{body:String(i)}});return JSON.stringify({ok:!0,id:o.id,url:o.html_url})}case"github_create_review":{let{owner:e,repo:t,number:n,body:i,event:o,comments:a}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let c=(o||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(c))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${o})`});let d=Array.isArray(a)?a.filter(m=>m&&m.path&&m.body&&(m.line!=null||m.position!=null)).map(m=>{let y={path:m.path,body:String(m.body)};return m.line!=null?(y.line=Number(m.line),y.side=m.side==="LEFT"?"LEFT":"RIGHT"):y.position=Number(m.position),y}):[];if(c!=="APPROVE"&&!i&&d.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let l={event:c};i&&(l.body=String(i)),d.length>0&&(l.comments=d);let u=await b(`/repos/${e}/${t}/pulls/${n}/reviews`,{method:"POST",body:l});return JSON.stringify({ok:!0,id:u.id,state:u.state,event:c,commentsPosted:d.length,url:u.html_url})}case"github_list_commits":{let{owner:e,repo:t,branch:n,path:i,limit:o}=s;if(!e||!t)return JSON.stringify({error:"owner and repo are required"});let a=`/repos/${e}/${t}/commits?per_page=${o||20}`;n&&(a+=`&sha=${encodeURIComponent(n)}`),i&&(a+=`&path=${encodeURIComponent(i)}`);let c=await b(a);return JSON.stringify({total:c.length,commits:c.map(d=>({sha:d.sha?.slice(0,8),fullSha:d.sha,message:d.commit?.message?.slice(0,300),author:d.commit?.author?.name,date:d.commit?.author?.date,url:d.html_url}))})}case"github_get_commit":{let{owner:e,repo:t,sha:n}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and sha are required"});let i=await b(`/repos/${e}/${t}/commits/${n}`);return JSON.stringify({sha:i.sha?.slice(0,8),message:i.commit?.message,author:i.commit?.author?.name,date:i.commit?.author?.date,stats:i.stats,files:(i.files||[]).map(o=>({filename:o.filename,status:o.status,additions:o.additions,deletions:o.deletions,patch:o.patch?.slice(0,3e3)}))})}case"github_get_file":{let{owner:e,repo:t,path:n,ref:i}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and path are required"});let o=`/repos/${e}/${t}/contents/${encodeURIComponent(n)}`;i&&(o+=`?ref=${encodeURIComponent(i)}`);let a=await b(o);if(a.type!=="file")return Array.isArray(a)?JSON.stringify({type:"directory",path:n,entries:a.map(l=>({name:l.name,type:l.type,size:l.size,path:l.path}))}):JSON.stringify({error:`Not a file: ${a.type}`});let c=Buffer.from(a.content||"","base64").toString("utf-8"),d=c.length>2e4;return JSON.stringify({path:a.path,size:a.size,sha:a.sha?.slice(0,8),content:d?c.slice(0,2e4):c,truncated:d})}case"github_get_user":try{let e=await b("/installation/repositories?per_page=1");if(e.repositories&&e.repositories.length>0){let t=e.repositories[0],n=t.owner.login,i=t.owner.type,o=i==="Organization"?`/orgs/${n}`:`/users/${n}`,a=await b(o);return JSON.stringify({login:a.login,name:a.name||a.login,avatar:a.avatar_url,bio:a.bio||a.description,type:i,isOrg:i==="Organization",publicRepos:a.public_repos,message:"Showing GitHub App installation owner (GitHub Apps cannot access /user endpoint)"})}return JSON.stringify({error:"No repositories accessible to this GitHub App installation"})}catch(e){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${e.message})`})}case"github_list_orgs":try{let t=(await b("/installation/repositories?per_page=100")).repositories||[],n=new Map;for(let o of t)o.owner.type==="Organization"&&(n.has(o.owner.login)||n.set(o.owner.login,{login:o.owner.login,description:null,url:o.owner.url}));let i=Array.from(n.values());return JSON.stringify({count:i.length,orgs:i,message:"Extracted from accessible repositories (GitHub Apps cannot access /user/orgs directly)"})}catch(e){return JSON.stringify({error:`GitHub App cannot list orgs via /user/orgs. Error: ${e.message}`})}case"github_clone":{let p=function(S){let w=S.replace(/^~(?=$|\/|\\)/,y);return a(w)},{owner:e,repo:t,destination:n}=s;if(!e||!t)return JSON.stringify({error:"owner and repo are required"});let{execSync:i}=await import("child_process"),{join:o,resolve:a}=await import("path"),{existsSync:c,mkdirSync:d}=await import("fs"),{homedir:l,platform:u}=await import("os"),{token:m}=await ue("github"),y=l(),f=n?p(n):o(y,"zibby-repos"),h=o(f,t);if(d(f,{recursive:!0}),c(h))return JSON.stringify({error:`Directory ${h} already exists. Remove it first or use a different destination.`,existingPath:h});try{let S=`https://x-access-token:${m}@github.com/${e}/${t}.git`;i(`git clone ${S} "${h}"`,{stdio:"pipe"});let w=u()==="win32",g;return w?g=i(`dir "${h}"`,{encoding:"utf-8",shell:"cmd.exe"}):g=i(`ls -la "${h}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:h,message:`Cloned ${e}/${t} to ${h}`,contents:g.split(`
223
226
  `).slice(0,30).join(`
224
- `),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(S){return JSON.stringify({error:`Clone failed: ${S.message}`})}}case"github_search_repos":{let{query:e,limit:t}=s;if(!e)return JSON.stringify({error:"query is required"});let n=await this.handleToolCall("github_list_repos",{limit:200},{}),i=JSON.parse(n);if(i.error)return JSON.stringify(i);let o=e.toLowerCase(),a=i.repos.filter(c=>c.name.toLowerCase().includes(o)||c.fullName.toLowerCase().includes(o)||c.description&&c.description.toLowerCase().includes(o));return JSON.stringify({query:e,count:a.length,repos:a.slice(0,t||20)})}case"github_list_repos":{let{owner:e,type:t,sort:n,direction:i,limit:o}=s,a=100,c=o||200,d=[];if(!e){let l=1,y=!0;for(;y&&d.length<c;){let b=`/installation/repositories?per_page=${a}&page=${l}`,U=(await h(b)).repositories||[];if(U.length===0)break;d=d.concat(U),y=U.length===a,l++}let f=d.slice(0,c).map(b=>({name:b.name,fullName:b.full_name,private:b.private,description:b.description,language:b.language,defaultBranch:b.default_branch,updatedAt:b.updated_at,stars:b.stargazers_count,url:b.html_url})),S=f.filter(b=>b.private).length,w=f.filter(b=>!b.private).length;return JSON.stringify({count:f.length,repos:f,privateCount:S,publicCount:w,message:`Found ${S} private and ${w} public repos`})}let u=await h(`/orgs/${e}`).then(()=>!0).catch(()=>!1),p=1,m=!0;for(;m&&d.length<c;){let l;u?l=`/orgs/${e}/repos?per_page=${a}&page=${p}&type=${t||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`:l=`/users/${e}/repos?per_page=${a}&page=${p}&type=${t||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`;let y=await h(l),f=Array.isArray(y)?y:[];if(f.length===0)break;d=d.concat(f),m=f.length===a,p++}let g=d.slice(0,c).map(l=>({name:l.name,fullName:l.full_name,private:l.private,description:l.description,language:l.language,defaultBranch:l.default_branch,updatedAt:l.updated_at,stars:l.stargazers_count,url:l.html_url}));return JSON.stringify({count:g.length,repos:g})}case"github_create_issue":{let{owner:e,repo:t,title:n,body:i}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and title are required"});let o=await h(`/repos/${e}/${t}/issues`,{method:"POST",body:{title:n,body:i||""}});return JSON.stringify({number:o.number,url:o.html_url,title:o.title})}case"github_list_issues":{let{owner:e,repo:t,state:n,labels:i,since:o,assignee:a,sort:c,direction:d,limit:u}=s||{};if(!e||!t)return JSON.stringify({error:"owner and repo are required"});let p=new URLSearchParams;p.set("state",n||"open"),p.set("per_page",String(u||30)),p.set("sort",c||"updated"),p.set("direction",d||"desc"),i&&p.set("labels",Array.isArray(i)?i.join(","):i),o&&p.set("since",o),a&&p.set("assignee",a);let m=await h(`/repos/${e}/${t}/issues?${p.toString()}`),g=(Array.isArray(m)?m:[]).filter(l=>!l.pull_request).map(l=>({number:l.number,title:l.title,state:l.state,labels:(l.labels||[]).map(y=>typeof y=="string"?y:y.name),assignee:l.assignee?.login||null,assignees:(l.assignees||[]).map(y=>y.login),user:l.user?.login,comments:l.comments,url:l.html_url,createdAt:l.created_at,updatedAt:l.updated_at}));return JSON.stringify({count:g.length,issues:g})}case"github_get_issue":{let{owner:e,repo:t,number:n}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/issues/${n}`);return i.pull_request?JSON.stringify({error:`#${n} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:i.number,title:i.title,body:i.body||"",state:i.state,stateReason:i.state_reason||null,labels:(i.labels||[]).map(o=>typeof o=="string"?o:o.name),assignee:i.assignee?.login||null,assignees:(i.assignees||[]).map(o=>o.login),user:i.user?.login,milestone:i.milestone?.title||null,comments:i.comments,url:i.html_url,createdAt:i.created_at,updatedAt:i.updated_at,closedAt:i.closed_at})}case"github_get_issue_comments":{let{owner:e,repo:t,number:n,limit:i}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o=await h(`/repos/${e}/${t}/issues/${n}/comments?per_page=${i||100}`),a=(Array.isArray(o)?o:[]).map(c=>({id:c.id,user:c.user?.login,body:c.body||"",createdAt:c.created_at,updatedAt:c.updated_at,url:c.html_url}));return JSON.stringify({count:a.length,comments:a})}case"github_add_issue_comment":{let{owner:e,repo:t,number:n,body:i}=s||{};if(!e||!t||!n||!i)return JSON.stringify({error:"owner, repo, number, and body are required"});let o=await h(`/repos/${e}/${t}/issues/${n}/comments`,{method:"POST",body:{body:i}});return JSON.stringify({ok:!0,id:o.id,url:o.html_url})}case"github_close_issue":{let{owner:e,repo:t,number:n,stateReason:i}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o={state:"closed"};i&&(o.state_reason=i);let a=await h(`/repos/${e}/${t}/issues/${n}`,{method:"PATCH",body:o});return JSON.stringify({ok:!0,number:a.number,state:a.state,stateReason:a.state_reason||null,url:a.html_url})}case"github_reopen_issue":{let{owner:e,repo:t,number:n}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await h(`/repos/${e}/${t}/issues/${n}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:i.number,state:i.state,url:i.html_url})}case"github_label_issue":{let{owner:e,repo:t,number:n,labels:i,mode:o}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let a=Array.isArray(i)?i:i?[i]:[];if(!a.length)return JSON.stringify({error:"labels (string or array) is required"});let c=o||"add";if(c==="set"){let u=await h(`/repos/${e}/${t}/issues/${n}`,{method:"PATCH",body:{labels:a}});return JSON.stringify({ok:!0,number:u.number,labels:(u.labels||[]).map(p=>typeof p=="string"?p:p.name)})}if(c==="remove"){for(let p of a)await h(`/repos/${e}/${t}/issues/${n}/labels/${encodeURIComponent(p)}`,{method:"DELETE"});let u=await h(`/repos/${e}/${t}/issues/${n}`);return JSON.stringify({ok:!0,number:u.number,labels:(u.labels||[]).map(p=>typeof p=="string"?p:p.name)})}let d=await h(`/repos/${e}/${t}/issues/${n}/labels`,{method:"POST",body:{labels:a}});return JSON.stringify({ok:!0,number:n,labels:(Array.isArray(d)?d:[]).map(u=>typeof u=="string"?u:u.name)})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"github_get_user",description:"Get the authenticated GitHub user profile and their organizations",input_schema:{type:"object",properties:{}}},{name:"github_list_orgs",description:"List GitHub organizations the authenticated user belongs to",input_schema:{type:"object",properties:{}}},{name:"github_list_repos",description:"List repositories for a user or org. If no owner given, lists the authenticated user's repos.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Org or user login. Omit to list your own repos."},type:{type:"string",enum:["all","public","private","forks","sources","member"],description:"Filter by type (default: all)"},sort:{type:"string",enum:["created","updated","pushed","full_name"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max repos to return (default: 30)"}}}},{name:"github_clone",description:'Clone a GitHub repository to the local filesystem. Use when user says "check out" or "clone" a repo.',input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner (user or org name)"},repo:{type:"string",description:"Repository name"},destination:{type:"string",description:"Destination directory. Accepts absolute paths, ~-prefixed paths, or relative names. Defaults to ~/zibby-repos/<repo>."}},required:["owner","repo"]}},{name:"github_search_repos",description:"Search accessible repositories by name or description. Use this when the user asks to find a specific repo.",input_schema:{type:"object",properties:{query:{type:"string",description:'Search term to match against repo name or description (e.g., "electron", "my-app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_issues",description:"Search GitHub issues and pull requests",input_schema:{type:"object",properties:{query:{type:"string",description:'GitHub search query (e.g. "SCRUM-123", "login bug repo:org/app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_code",description:"Search code across GitHub repositories by keyword",input_schema:{type:"object",properties:{query:{type:"string",description:'Code search query (e.g. "handleLogin", "class AuthService")'},repo:{type:"string",description:'Scope to a specific repo (e.g. "org/app"). Optional.'},language:{type:"string",description:'Filter by language (e.g. "javascript", "python"). Optional.'},limit:{type:"number",description:"Max results (default: 15)"}},required:["query"]}},{name:"github_get_pr",description:"Get details of a pull request \u2014 title, description, branch, stats",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_get_pr_diff",description:"Get the unified diff of a pull request \u2014 the actual code changes",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_files",description:"List files changed in a PR with per-file patches",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_comments",description:"Get all review and issue comments on a PR",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_create_review",description:"Post a review on a pull request: a summary body plus optional inline comments anchored to file/line, with an event (COMMENT, APPROVE, or REQUEST_CHANGES). Use this to deliver a code review back to the PR.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},body:{type:"string",description:"The review summary (markdown). Shown as the top-level review comment."},event:{type:"string",enum:["COMMENT","APPROVE","REQUEST_CHANGES"],description:"Review verdict. Default COMMENT (no approval state). Use REQUEST_CHANGES for blocking issues."},comments:{type:"array",description:"Optional inline comments, each anchored to a changed line.",items:{type:"object",properties:{path:{type:"string",description:"File path as it appears in the diff"},line:{type:"number",description:"Line number in the file's NEW version (the right side of the diff)"},side:{type:"string",enum:["LEFT","RIGHT"],description:"RIGHT (new) or LEFT (old). Default RIGHT."},body:{type:"string",description:"The inline comment text (markdown)"}},required:["path","line","body"]}}},required:["owner","repo","number"]}},{name:"github_list_commits",description:"List recent commits on a branch, optionally filtered by file path",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},branch:{type:"string",description:"Branch name (default: repo default branch)"},path:{type:"string",description:"Filter commits touching this file path"},limit:{type:"number",description:"Max commits (default: 20)"}},required:["owner","repo"]}},{name:"github_get_commit",description:"Get details of a specific commit \u2014 message, stats, file diffs",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},sha:{type:"string",description:"Commit SHA (full or short)"}},required:["owner","repo","sha"]}},{name:"github_get_file",description:"Read a file (or list a directory) from a GitHub repo. Works on any branch/ref.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},path:{type:"string",description:'File or directory path (e.g. "src/auth/login.ts")'},ref:{type:"string",description:"Branch, tag, or commit SHA (default: repo default branch)"}},required:["owner","repo","path"]}},{name:"github_create_issue",description:"Create a GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},title:{type:"string",description:"Issue title"},body:{type:"string",description:"Issue body (markdown)"}},required:["owner","repo","title"]}},{name:"github_list_issues",description:"List issues in a repo (excludes pull requests). Filter by state, labels, and an updated-since cursor for polling.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},state:{type:"string",enum:["open","closed","all"],description:"Filter by state (default: open)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},since:{type:"string",description:"ISO-8601 timestamp; only issues updated at/after this (polling cursor)"},assignee:{type:"string",description:'Filter by assignee login, "none", or "*"'},sort:{type:"string",enum:["created","updated","comments"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30, max 100 per page)"}},required:["owner","repo"]}},{name:"github_get_issue",description:"Get a single GitHub issue with full detail (title, body, state, labels, assignee, url)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_get_issue_comments",description:"Get the comment thread on a GitHub issue (chronological)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},limit:{type:"number",description:"Max comments (default: 100)"}},required:["owner","repo","number"]}},{name:"github_add_issue_comment",description:"Add a comment to a GitHub issue. Also the way to record a PR link on an issue (post a markdown link).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},body:{type:"string",description:"Comment body (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_close_issue",description:"Close a GitHub issue. Optionally set the close reason (completed or not_planned).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},stateReason:{type:"string",enum:["completed","not_planned"],description:"Why the issue was closed (optional)"}},required:["owner","repo","number"]}},{name:"github_reopen_issue",description:"Reopen a closed GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_label_issue",description:"Add, set (replace all), or remove labels on a GitHub issue. Labels back state-like transitions on GitHub.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},labels:{type:"array",items:{type:"string"},description:"Label name(s)"},mode:{type:"string",enum:["add","set","remove"],description:"add appends, set replaces all, remove deletes (default: add)"}},required:["owner","repo","number","labels"]}}]};var ue=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i,le=/\b(in[\s-]?progress|wip|doing|started|in[\s-]?review|review)\b/i,Fe=/\b(done|closed|complete|completed|resolved|fixed|merged|shipped)\b/i,ze=/\b(todo|to[\s-]?do|open|backlog|reopen|new)\b/i,oe="in progress",ae="blocked";function de(r,s=[]){if(r==="closed")return"done";if(r!=="open")return"unknown";let e=(s||[]).map(String);return e.some(t=>ue.test(t))?"blocked":e.some(t=>le.test(t))?"in_progress":"todo"}function C(r={}){let s=r.owner||process.env.GITHUB_OWNER,e=r.repo||process.env.GITHUB_REPO;if(!s||!e)throw new Error("GitHub scope missing: provide {owner, repo} via ctx or env GITHUB_OWNER / GITHUB_REPO.");return{owner:s,repo:e}}function j(r){let s=JSON.parse(r);if(s&&s.error)throw new Error(s.error);return s}function Q(r,s={}){let e=r.labels||[],t=r.number,n=s.owner&&s.repo?`${s.owner}/${s.repo}#${t}`:`#${t}`;return{id:String(t),key:n,title:r.title||"",body:r.body||"",state:r.state||null,stateCategory:de(r.state,e),assignee:r.assignee||r.assignees&&r.assignees[0]||null,url:r.url||null,_raw:r}}var V={id:"github",toStateCategory:de,toNeutral:Q,IN_PROGRESS_LABEL:oe,BLOCKED_LABEL:ae,async listCandidates(r={}){let s=r.ctx||{},{owner:e,repo:t}=C(s);return(j(await k.handleToolCall("github_list_issues",{owner:e,repo:t,state:r.state||"open",labels:r.labels,since:r.updatedAfter,limit:r.limit})).issues||[]).map(i=>Q(i,{owner:e,repo:t}))},async getTicket(r,s={}){let{owner:e,repo:t}=C(s),n=q(r);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);let i=JSON.parse(await k.handleToolCall("github_get_issue",{owner:e,repo:t,number:n}));return i.error?null:Q(i,{owner:e,repo:t})},async getComments(r,s={}){let{owner:e,repo:t}=C(s),n=q(r);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);return(j(await k.handleToolCall("github_get_issue_comments",{owner:e,repo:t,number:n})).comments||[]).map(o=>({id:String(o.id),author:o.user||"Unknown",body:o.body||"",createdAt:o.createdAt||null,updatedAt:o.updatedAt||null,_raw:o})).sort((o,a)=>String(a.createdAt).localeCompare(String(o.createdAt)))},async addComment(r,s,e={}){let{owner:t,repo:n}=C(e),i=q(r);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);if(!s)throw new Error("body is required");let o=j(await k.handleToolCall("github_add_issue_comment",{owner:t,repo:n,number:i,body:s}));return{ok:!!o.ok,id:o.id?String(o.id):null}},async transition(r,s,e={}){let{owner:t,repo:n}=C(e),i=q(r);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);let o=String(s||"");if(Fe.test(o)){let a=j(await k.handleToolCall("github_close_issue",{owner:t,repo:n,number:i,stateReason:"completed"}));return{ok:!!a.ok,stateAfter:a.state||"closed",stateCategoryAfter:"done",_raw:a}}if(ue.test(o)){await ce(t,n,i);let a=j(await k.handleToolCall("github_label_issue",{owner:t,repo:n,number:i,labels:[ae],mode:"add"}));return{ok:!!a.ok,stateAfter:"open",stateCategoryAfter:"blocked",via:"label",_raw:a}}if(le.test(o)){await ce(t,n,i);let a=j(await k.handleToolCall("github_label_issue",{owner:t,repo:n,number:i,labels:[oe],mode:"add"}));return{ok:!!a.ok,stateAfter:"open",stateCategoryAfter:"in_progress",via:"label",_raw:a}}if(ze.test(o)){let a=j(await k.handleToolCall("github_reopen_issue",{owner:t,repo:n,number:i}));return{ok:!!a.ok,stateAfter:a.state||"open",stateCategoryAfter:"todo",_raw:a}}return{ok:!1,error:`GitHub issues have no "${s}" state. Representable targets: open/todo, in progress, blocked, done/closed.`}},async linkPullRequest(r,s,e,t={}){let{owner:n,repo:i}=C(t),o=q(r);if(o==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);if(!s)throw new Error("prUrl is required");let a=`${e?`${e}: `:"Linked PR: "}${s}`;return{ok:!!j(await k.handleToolCall("github_add_issue_comment",{owner:n,repo:i,number:o,body:a})).ok,via:"comment"}}};async function ce(r,s,e){await k.handleToolCall("github_reopen_issue",{owner:r,repo:s,number:e})}function q(r){if(r==null)return null;if(typeof r=="number")return r;let s=/(\d+)\s*$/.exec(String(r));return s?Number(s[1]):null}var Ye=(process.env.PLANE_API_URL||"https://api.plane.so/api/v1").replace(/\/+$/,""),We=process.env.PLANE_WORKSPACE_SLUG||"",Qe=process.env.PLANE_PROJECT_ID||"";function Ve(){let r=process.env.PLANE_API_KEY||process.env.PLANE_OAUTH_TOKEN;if(!r)throw new Error("Plane is not connected: set PLANE_API_KEY (personal access token).");return r}function R(r={}){let s=r.workspaceSlug||We,e=r.projectId||Qe;if(!s||!e)throw new Error("Plane scope missing: provide workspaceSlug + projectId (env PLANE_WORKSPACE_SLUG / PLANE_PROJECT_ID or per-call ctx).");return{workspaceSlug:s,projectId:e}}async function v(r,s={}){let e=`${Ye}${r}`;if(s.query&&Object.keys(s.query).length){let i=new URLSearchParams;for(let[a,c]of Object.entries(s.query))c!=null&&c!==""&&i.set(a,String(c));let o=i.toString();o&&(e+=(e.includes("?")?"&":"?")+o)}let t=await fetch(e,{method:s.method||"GET",headers:{"X-API-Key":Ve(),Accept:"application/json",...s.body?{"Content-Type":"application/json"}:{},...s.headers},body:s.body?JSON.stringify(s.body):void 0});if(!t.ok){let i=await t.text().catch(()=>"");throw new Error(`Plane API ${t.status}: ${i.slice(0,300)}`)}let n=await t.text().catch(()=>"");if(!n||!n.trim())return{};try{return JSON.parse(n)}catch{return{raw:n}}}var Ze={backlog:"todo",unstarted:"todo",started:"in_progress",completed:"done",cancelled:"done"},Xe=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i;function X(r){return r?r.name&&Xe.test(r.name)?"blocked":Ze[r.group]||"unknown":"unknown"}var pe=new Map,et=300*1e3;async function ye(r){let{workspaceSlug:s,projectId:e}=R(r),t=pe.get(e);if(t&&Date.now()-t.fetchedAt<et)return t.states;let n=await v(`/workspaces/${encodeURIComponent(s)}/projects/${encodeURIComponent(e)}/states/`,{query:{per_page:100}}),i=(n.results||n||[]).map(o=>({id:o.id,name:o.name,group:o.group,color:o.color}));return pe.set(e,{fetchedAt:Date.now(),states:i}),i}function Z(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function tt(r,s){let e=Z(s);if(!e)return null;let t=r.find(i=>Z(i.name)===e);if(t)return t;let n={todo:["todo","backlog","open","unstarted"],inprogress:["inprogress","started","doing","wip"],done:["done","completed","closed","resolved","cancelled","canceled"],blocked:["blocked","onhold","waiting"]};for(let[,i]of Object.entries(n)){if(!i.some(c=>Z(c)===e))continue;let o=e==="done"?"completed":e==="inprogress"?"started":"unstarted",a=r.find(c=>c.group===o);if(a)return a}return null}async function me(r,s){let t=(await ye(s).catch(()=>[])).find(c=>c.id===r.state)||null,{workspaceSlug:n,projectId:i}=R(s),o=s.projectIdentifier&&r.sequence_id!=null?`${s.projectIdentifier}-${r.sequence_id}`:r.sequence_id!=null?String(r.sequence_id):r.id,a=r.assignees||[];return{id:r.id,key:o,title:r.name||"",body:r.description_html||r.description_stripped||r.description||"",state:t?t.name:null,stateCategory:X(t),assignee:a.length?String(a[0]):null,url:s.baseWebUrl?`${s.baseWebUrl}/${n}/projects/${i}/issues/${r.id}`:null,_raw:r}}var ee={id:"plane",envKeys:["PLANE_API_KEY","PLANE_OAUTH_TOKEN","PLANE_API_URL","PLANE_WORKSPACE_SLUG","PLANE_PROJECT_ID"],planeFetch:v,toStateCategory:X,async listCandidates(r={}){let s=r.ctx||{},{workspaceSlug:e,projectId:t}=R(s),n={per_page:Math.min(Number(r.limit)||50,100),cursor:r.cursor};r.state&&(n.state=r.state),r.updatedAfter&&(n.updated_at__gte=r.updatedAfter);let o=(await v(`/workspaces/${encodeURIComponent(e)}/projects/${encodeURIComponent(t)}/work-items/`,{query:n})).results||[];return r.updatedAfter&&(o=o.filter(a=>String(a.updated_at)>String(r.updatedAfter))),Promise.all(o.map(a=>me(a,s)))},async getTicket(r,s={}){let{workspaceSlug:e,projectId:t}=R(s),n=await v(`/workspaces/${encodeURIComponent(e)}/projects/${encodeURIComponent(t)}/work-items/${encodeURIComponent(r)}/`);return!n||!n.id?null:me(n,s)},async getComments(r,s={}){let{workspaceSlug:e,projectId:t}=R(s);return((await v(`/workspaces/${encodeURIComponent(e)}/projects/${encodeURIComponent(t)}/work-items/${encodeURIComponent(r)}/comments/`,{query:{per_page:100}})).results||[]).map(o=>({id:o.id,author:o.actor||o.actor_detail?.display_name||"Unknown",body:o.comment_html||o.comment_stripped||"",createdAt:o.created_at||null,updatedAt:o.updated_at||null,_raw:o})).sort((o,a)=>String(a.createdAt).localeCompare(String(o.createdAt)))},async addComment(r,s,e={}){let{workspaceSlug:t,projectId:n}=R(e),o=/<[a-z][\s\S]*>/i.test(String(s||""))?String(s):`<p>${String(s||"")}</p>`,a=await v(`/workspaces/${encodeURIComponent(t)}/projects/${encodeURIComponent(n)}/work-items/${encodeURIComponent(r)}/comments/`,{method:"POST",body:{comment_html:o}});return{ok:!!a.id,id:a.id||null,_raw:a}},async transition(r,s,e={}){let{workspaceSlug:t,projectId:n}=R(e),i=await ye(e),o=tt(i,s);if(!o)return{ok:!1,error:`No Plane state matches "${s}" in this project`,availableStates:i.map(c=>({id:c.id,name:c.name,group:c.group}))};let a=await v(`/workspaces/${encodeURIComponent(t)}/projects/${encodeURIComponent(n)}/work-items/${encodeURIComponent(r)}/`,{method:"PATCH",body:{state:o.id}});return{ok:!!a.id,stateAfter:o.name,stateCategoryAfter:X(o),_raw:a}},async linkPullRequest(r,s,e,t={}){let n=e?`${e}: `:"Linked PR: ";return{ok:!!(await this.addComment(r,`<p>${n}<a href="${s}">${s}</a></p>`,t)).ok,via:"comment"}}};var rt=["todo","in_progress","done","blocked","unknown"];var fe={jira:F,linear:W,github:V,plane:ee},st="jira";function Tt(r){let s=String(r||process.env.TRACKER_PROVIDER||st).trim().toLowerCase(),e=fe[s];if(!e){let t=Object.keys(fe).join(", ");throw new Error(`Unknown tracker provider "${s}". Known providers: ${t}.`)}return e}export{st as DEFAULT_TRACKER_PROVIDER,fe as TRACKER_ADAPTERS,rt as TRACKER_STATE_CATEGORIES,Tt as getAdapter,V as githubAdapter,F as jiraAdapter,W as linearAdapter,ee as planeAdapter};
227
+ `),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(S){return JSON.stringify({error:`Clone failed: ${S.message}`})}}case"github_search_repos":{let{query:e,limit:t}=s;if(!e)return JSON.stringify({error:"query is required"});let n=await this.handleToolCall("github_list_repos",{limit:200},{}),i=JSON.parse(n);if(i.error)return JSON.stringify(i);let o=e.toLowerCase(),a=i.repos.filter(c=>c.name.toLowerCase().includes(o)||c.fullName.toLowerCase().includes(o)||c.description&&c.description.toLowerCase().includes(o));return JSON.stringify({query:e,count:a.length,repos:a.slice(0,t||20)})}case"github_list_repos":{let{owner:e,type:t,sort:n,direction:i,limit:o,query:a}=s,c=100,d=o||200,l=[],u=g=>({name:g.name,fullName:g.full_name,private:g.private,description:g.description,language:g.language,defaultBranch:g.default_branch,updatedAt:g.updated_at,stars:g.stargazers_count,url:g.html_url,fullPath:g.full_name,webUrl:g.html_url,visibility:g.visibility||(g.private?"private":"public")}),m=g=>{if(!a)return!0;let A=String(a).toLowerCase();return g.name&&g.name.toLowerCase().includes(A)||g.fullName&&g.fullName.toLowerCase().includes(A)||g.description&&g.description.toLowerCase().includes(A)};if(!e){let g=1,A=!0;for(;A&&l.length<d;){let L=`/installation/repositories?per_page=${c}&page=${g}`,H=(await b(L)).repositories||[];if(H.length===0)break;l=l.concat(H),A=H.length===c,g++}let O=l.map(u).filter(m),P=O.slice(0,d),Se=O.length>P.length,ne=P.filter(L=>L.private).length,oe=P.filter(L=>!L.private).length;return JSON.stringify({count:P.length,repos:P,truncated:Se,privateCount:ne,publicCount:oe,message:`Found ${ne} private and ${oe} public repos`})}let y=await b(`/orgs/${e}`).then(()=>!0).catch(()=>!1),p=1,f=!0;for(;f&&l.length<d;){let g;y?g=`/orgs/${e}/repos?per_page=${c}&page=${p}&type=${t||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`:g=`/users/${e}/repos?per_page=${c}&page=${p}&type=${t||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`;let A=await b(g),O=Array.isArray(A)?A:[];if(O.length===0)break;l=l.concat(O),f=O.length===c,p++}let h=l.map(u).filter(m),S=h.slice(0,d),w=h.length>S.length;return JSON.stringify({count:S.length,repos:S,truncated:w})}case"github_create_issue":{let{owner:e,repo:t,title:n,body:i}=s;if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and title are required"});let o=await b(`/repos/${e}/${t}/issues`,{method:"POST",body:{title:n,body:i||""}});return JSON.stringify({number:o.number,url:o.html_url,title:o.title})}case"github_list_issues":{let{owner:e,repo:t,state:n,labels:i,since:o,assignee:a,sort:c,direction:d,limit:l}=s||{};if(!e||!t)return JSON.stringify({error:"owner and repo are required"});let u=new URLSearchParams;u.set("state",n||"open"),u.set("per_page",String(l||30)),u.set("sort",c||"updated"),u.set("direction",d||"desc"),i&&u.set("labels",Array.isArray(i)?i.join(","):i),o&&u.set("since",o),a&&u.set("assignee",a);let m=await b(`/repos/${e}/${t}/issues?${u.toString()}`),y=(Array.isArray(m)?m:[]).filter(p=>!p.pull_request).map(p=>({number:p.number,title:p.title,state:p.state,labels:(p.labels||[]).map(f=>typeof f=="string"?f:f.name),assignee:p.assignee?.login||null,assignees:(p.assignees||[]).map(f=>f.login),user:p.user?.login,comments:p.comments,url:p.html_url,createdAt:p.created_at,updatedAt:p.updated_at}));return JSON.stringify({count:y.length,issues:y})}case"github_get_issue":{let{owner:e,repo:t,number:n}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await b(`/repos/${e}/${t}/issues/${n}`);return i.pull_request?JSON.stringify({error:`#${n} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:i.number,title:i.title,body:i.body||"",state:i.state,stateReason:i.state_reason||null,labels:(i.labels||[]).map(o=>typeof o=="string"?o:o.name),assignee:i.assignee?.login||null,assignees:(i.assignees||[]).map(o=>o.login),user:i.user?.login,milestone:i.milestone?.title||null,comments:i.comments,url:i.html_url,createdAt:i.created_at,updatedAt:i.updated_at,closedAt:i.closed_at})}case"github_get_issue_comments":{let{owner:e,repo:t,number:n,limit:i}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o=await b(`/repos/${e}/${t}/issues/${n}/comments?per_page=${i||100}`),a=(Array.isArray(o)?o:[]).map(c=>({id:c.id,user:c.user?.login,body:c.body||"",createdAt:c.created_at,updatedAt:c.updated_at,url:c.html_url}));return JSON.stringify({count:a.length,comments:a})}case"github_add_issue_comment":{let{owner:e,repo:t,number:n,body:i}=s||{};if(!e||!t||!n||!i)return JSON.stringify({error:"owner, repo, number, and body are required"});let o=await b(`/repos/${e}/${t}/issues/${n}/comments`,{method:"POST",body:{body:i}});return JSON.stringify({ok:!0,id:o.id,url:o.html_url})}case"github_close_issue":{let{owner:e,repo:t,number:n,stateReason:i}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o={state:"closed"};i&&(o.state_reason=i);let a=await b(`/repos/${e}/${t}/issues/${n}`,{method:"PATCH",body:o});return JSON.stringify({ok:!0,number:a.number,state:a.state,stateReason:a.state_reason||null,url:a.html_url})}case"github_reopen_issue":{let{owner:e,repo:t,number:n}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await b(`/repos/${e}/${t}/issues/${n}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:i.number,state:i.state,url:i.html_url})}case"github_label_issue":{let{owner:e,repo:t,number:n,labels:i,mode:o}=s||{};if(!e||!t||!n)return JSON.stringify({error:"owner, repo, and number are required"});let a=Array.isArray(i)?i:i?[i]:[];if(!a.length)return JSON.stringify({error:"labels (string or array) is required"});let c=o||"add";if(c==="set"){let l=await b(`/repos/${e}/${t}/issues/${n}`,{method:"PATCH",body:{labels:a}});return JSON.stringify({ok:!0,number:l.number,labels:(l.labels||[]).map(u=>typeof u=="string"?u:u.name)})}if(c==="remove"){for(let u of a)await b(`/repos/${e}/${t}/issues/${n}/labels/${encodeURIComponent(u)}`,{method:"DELETE"});let l=await b(`/repos/${e}/${t}/issues/${n}`);return JSON.stringify({ok:!0,number:l.number,labels:(l.labels||[]).map(u=>typeof u=="string"?u:u.name)})}let d=await b(`/repos/${e}/${t}/issues/${n}/labels`,{method:"POST",body:{labels:a}});return JSON.stringify({ok:!0,number:n,labels:(Array.isArray(d)?d:[]).map(l=>typeof l=="string"?l:l.name)})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"github_get_user",description:"Get the authenticated GitHub user profile and their organizations",input_schema:{type:"object",properties:{}}},{name:"github_list_orgs",description:"List GitHub organizations the authenticated user belongs to",input_schema:{type:"object",properties:{}}},{name:"github_list_repos",description:"List 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 recent commits on a branch, optionally filtered by file path",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},branch:{type:"string",description:"Branch name (default: repo default branch)"},path:{type:"string",description:"Filter commits touching this file path"},limit:{type:"number",description:"Max commits (default: 20)"}},required:["owner","repo"]}},{name:"github_get_commit",description:"Get details of a specific commit \u2014 message, stats, file diffs",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},sha:{type:"string",description:"Commit SHA (full or short)"}},required:["owner","repo","sha"]}},{name:"github_get_file",description:"Read a file (or list a directory) from a GitHub repo. Works on any branch/ref.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},path:{type:"string",description:'File or directory path (e.g. "src/auth/login.ts")'},ref:{type:"string",description:"Branch, tag, or commit SHA (default: repo default branch)"}},required:["owner","repo","path"]}},{name:"github_create_issue",description:"Create a GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},title:{type:"string",description:"Issue title"},body:{type:"string",description:"Issue body (markdown)"}},required:["owner","repo","title"]}},{name:"github_list_issues",description:"List issues in a repo (excludes pull requests). Filter by state, labels, and an updated-since cursor for polling.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},state:{type:"string",enum:["open","closed","all"],description:"Filter by state (default: open)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},since:{type:"string",description:"ISO-8601 timestamp; only issues updated at/after this (polling cursor)"},assignee:{type:"string",description:'Filter by assignee login, "none", or "*"'},sort:{type:"string",enum:["created","updated","comments"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30, max 100 per page)"}},required:["owner","repo"]}},{name:"github_get_issue",description:"Get a single GitHub issue with full detail (title, body, state, labels, assignee, url)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_get_issue_comments",description:"Get the comment thread on a GitHub issue (chronological)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},limit:{type:"number",description:"Max comments (default: 100)"}},required:["owner","repo","number"]}},{name:"github_add_issue_comment",description:"Add a comment to a GitHub issue. Also the way to record a PR link on an issue (post a markdown link).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},body:{type:"string",description:"Comment body (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_close_issue",description:"Close a GitHub issue. Optionally set the close reason (completed or not_planned).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},stateReason:{type:"string",enum:["completed","not_planned"],description:"Why the issue was closed (optional)"}},required:["owner","repo","number"]}},{name:"github_reopen_issue",description:"Reopen a closed GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_label_issue",description:"Add, set (replace all), or remove labels on a GitHub issue. Labels back state-like transitions on GitHub.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},labels:{type:"array",items:{type:"string"},description:"Label name(s)"},mode:{type:"string",enum:["add","set","remove"],description:"add appends, set replaces all, remove deletes (default: add)"}},required:["owner","repo","number","labels"]}}]};var ye=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i,fe=/\b(in[\s-]?progress|wip|doing|started|in[\s-]?review|review)\b/i,Ze=/\b(done|closed|complete|completed|resolved|fixed|merged|shipped)\b/i,Xe=/\b(todo|to[\s-]?do|open|backlog|reopen|new)\b/i,de="in progress",pe="blocked";function ge(r,s=[]){if(r==="closed")return"done";if(r!=="open")return"unknown";let e=(s||[]).map(String);return e.some(t=>ye.test(t))?"blocked":e.some(t=>fe.test(t))?"in_progress":"todo"}function C(r={}){let s=r.owner||process.env.GITHUB_OWNER,e=r.repo||process.env.GITHUB_REPO;if(!s||!e)throw new Error("GitHub scope missing: provide {owner, repo} via ctx or env GITHUB_OWNER / GITHUB_REPO.");return{owner:s,repo:e}}function N(r){let s=JSON.parse(r);if(s&&s.error)throw new Error(s.error);return s}function ee(r,s={}){let e=r.labels||[],t=r.number,n=s.owner&&s.repo?`${s.owner}/${s.repo}#${t}`:`#${t}`;return{id:String(t),key:n,title:r.title||"",body:r.body||"",state:r.state||null,stateCategory:ge(r.state,e),assignee:r.assignee||r.assignees&&r.assignees[0]||null,url:r.url||null,_raw:r}}var te={id:"github",toStateCategory:ge,toNeutral:ee,IN_PROGRESS_LABEL:de,BLOCKED_LABEL:pe,async listCandidates(r={}){let s=r.ctx||{},{owner:e,repo:t}=C(s);return(N(await I.handleToolCall("github_list_issues",{owner:e,repo:t,state:r.state||"open",labels:r.labels,since:r.updatedAfter,limit:r.limit})).issues||[]).map(i=>ee(i,{owner:e,repo:t}))},async getTicket(r,s={}){let{owner:e,repo:t}=C(s),n=G(r);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);let i=JSON.parse(await I.handleToolCall("github_get_issue",{owner:e,repo:t,number:n}));return i.error?null:ee(i,{owner:e,repo:t})},async getComments(r,s={}){let{owner:e,repo:t}=C(s),n=G(r);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);return(N(await I.handleToolCall("github_get_issue_comments",{owner:e,repo:t,number:n})).comments||[]).map(o=>({id:String(o.id),author:o.user||"Unknown",body:o.body||"",createdAt:o.createdAt||null,updatedAt:o.updatedAt||null,_raw:o})).sort((o,a)=>String(a.createdAt).localeCompare(String(o.createdAt)))},async addComment(r,s,e={}){let{owner:t,repo:n}=C(e),i=G(r);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);if(!s)throw new Error("body is required");let o=N(await I.handleToolCall("github_add_issue_comment",{owner:t,repo:n,number:i,body:s}));return{ok:!!o.ok,id:o.id?String(o.id):null}},async transition(r,s,e={}){let{owner:t,repo:n}=C(e),i=G(r);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);let o=String(s||"");if(Ze.test(o)){let a=N(await I.handleToolCall("github_close_issue",{owner:t,repo:n,number:i,stateReason:"completed"}));return{ok:!!a.ok,stateAfter:a.state||"closed",stateCategoryAfter:"done",_raw:a}}if(ye.test(o)){await me(t,n,i);let a=N(await I.handleToolCall("github_label_issue",{owner:t,repo:n,number:i,labels:[pe],mode:"add"}));return{ok:!!a.ok,stateAfter:"open",stateCategoryAfter:"blocked",via:"label",_raw:a}}if(fe.test(o)){await me(t,n,i);let a=N(await I.handleToolCall("github_label_issue",{owner:t,repo:n,number:i,labels:[de],mode:"add"}));return{ok:!!a.ok,stateAfter:"open",stateCategoryAfter:"in_progress",via:"label",_raw:a}}if(Xe.test(o)){let a=N(await I.handleToolCall("github_reopen_issue",{owner:t,repo:n,number:i}));return{ok:!!a.ok,stateAfter:a.state||"open",stateCategoryAfter:"todo",_raw:a}}return{ok:!1,error:`GitHub issues have no "${s}" state. Representable targets: open/todo, in progress, blocked, done/closed.`}},async linkPullRequest(r,s,e,t={}){let{owner:n,repo:i}=C(t),o=G(r);if(o==null)throw new Error(`Cannot parse GitHub issue number from "${r}"`);if(!s)throw new Error("prUrl is required");let a=`${e?`${e}: `:"Linked PR: "}${s}`;return{ok:!!N(await I.handleToolCall("github_add_issue_comment",{owner:n,repo:i,number:o,body:a})).ok,via:"comment"}}};async function me(r,s,e){await I.handleToolCall("github_reopen_issue",{owner:r,repo:s,number:e})}function G(r){if(r==null)return null;if(typeof r=="number")return r;let s=/(\d+)\s*$/.exec(String(r));return s?Number(s[1]):null}var et=(process.env.PLANE_API_URL||"https://api.plane.so/api/v1").replace(/\/+$/,""),tt=process.env.PLANE_WORKSPACE_SLUG||"",rt=process.env.PLANE_PROJECT_ID||"";function st(){let r=process.env.PLANE_API_KEY||process.env.PLANE_OAUTH_TOKEN;if(!r)throw new Error("Plane is not connected: set PLANE_API_KEY (personal access token).");return r}function $(r={}){let s=r.workspaceSlug||tt,e=r.projectId||rt;if(!s||!e)throw new Error("Plane scope missing: provide workspaceSlug + projectId (env PLANE_WORKSPACE_SLUG / PLANE_PROJECT_ID or per-call ctx).");return{workspaceSlug:s,projectId:e}}async function j(r,s={}){let e=`${et}${r}`;if(s.query&&Object.keys(s.query).length){let i=new URLSearchParams;for(let[a,c]of Object.entries(s.query))c!=null&&c!==""&&i.set(a,String(c));let o=i.toString();o&&(e+=(e.includes("?")?"&":"?")+o)}let t=await fetch(e,{method:s.method||"GET",headers:{"X-API-Key":st(),Accept:"application/json",...s.body?{"Content-Type":"application/json"}:{},...s.headers},body:s.body?JSON.stringify(s.body):void 0});if(!t.ok){let i=await t.text().catch(()=>"");throw new Error(`Plane API ${t.status}: ${i.slice(0,300)}`)}let n=await t.text().catch(()=>"");if(!n||!n.trim())return{};try{return JSON.parse(n)}catch{return{raw:n}}}var it={backlog:"todo",unstarted:"todo",started:"in_progress",completed:"done",cancelled:"done"},nt=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i;function se(r){return r?r.name&&nt.test(r.name)?"blocked":it[r.group]||"unknown":"unknown"}var he=new Map,ot=300*1e3;async function _e(r){let{workspaceSlug:s,projectId:e}=$(r),t=he.get(e);if(t&&Date.now()-t.fetchedAt<ot)return t.states;let n=await j(`/workspaces/${encodeURIComponent(s)}/projects/${encodeURIComponent(e)}/states/`,{query:{per_page:100}}),i=(n.results||n||[]).map(o=>({id:o.id,name:o.name,group:o.group,color:o.color}));return he.set(e,{fetchedAt:Date.now(),states:i}),i}function re(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function at(r,s){let e=re(s);if(!e)return null;let t=r.find(i=>re(i.name)===e);if(t)return t;let n={todo:["todo","backlog","open","unstarted"],inprogress:["inprogress","started","doing","wip"],done:["done","completed","closed","resolved","cancelled","canceled"],blocked:["blocked","onhold","waiting"]};for(let[,i]of Object.entries(n)){if(!i.some(c=>re(c)===e))continue;let o=e==="done"?"completed":e==="inprogress"?"started":"unstarted",a=r.find(c=>c.group===o);if(a)return a}return null}async function be(r,s){let t=(await _e(s).catch(()=>[])).find(c=>c.id===r.state)||null,{workspaceSlug:n,projectId:i}=$(s),o=s.projectIdentifier&&r.sequence_id!=null?`${s.projectIdentifier}-${r.sequence_id}`:r.sequence_id!=null?String(r.sequence_id):r.id,a=r.assignees||[];return{id:r.id,key:o,title:r.name||"",body:r.description_html||r.description_stripped||r.description||"",state:t?t.name:null,stateCategory:se(t),assignee:a.length?String(a[0]):null,url:s.baseWebUrl?`${s.baseWebUrl}/${n}/projects/${i}/issues/${r.id}`:null,_raw:r}}var ie={id:"plane",envKeys:["PLANE_API_KEY","PLANE_OAUTH_TOKEN","PLANE_API_URL","PLANE_WORKSPACE_SLUG","PLANE_PROJECT_ID"],planeFetch:j,toStateCategory:se,async listCandidates(r={}){let s=r.ctx||{},{workspaceSlug:e,projectId:t}=$(s),n={per_page:Math.min(Number(r.limit)||50,100),cursor:r.cursor};r.state&&(n.state=r.state),r.updatedAfter&&(n.updated_at__gte=r.updatedAfter);let o=(await j(`/workspaces/${encodeURIComponent(e)}/projects/${encodeURIComponent(t)}/work-items/`,{query:n})).results||[];return r.updatedAfter&&(o=o.filter(a=>String(a.updated_at)>String(r.updatedAfter))),Promise.all(o.map(a=>be(a,s)))},async getTicket(r,s={}){let{workspaceSlug:e,projectId:t}=$(s),n=await j(`/workspaces/${encodeURIComponent(e)}/projects/${encodeURIComponent(t)}/work-items/${encodeURIComponent(r)}/`);return!n||!n.id?null:be(n,s)},async getComments(r,s={}){let{workspaceSlug:e,projectId:t}=$(s);return((await j(`/workspaces/${encodeURIComponent(e)}/projects/${encodeURIComponent(t)}/work-items/${encodeURIComponent(r)}/comments/`,{query:{per_page:100}})).results||[]).map(o=>({id:o.id,author:o.actor||o.actor_detail?.display_name||"Unknown",body:o.comment_html||o.comment_stripped||"",createdAt:o.created_at||null,updatedAt:o.updated_at||null,_raw:o})).sort((o,a)=>String(a.createdAt).localeCompare(String(o.createdAt)))},async addComment(r,s,e={}){let{workspaceSlug:t,projectId:n}=$(e),o=/<[a-z][\s\S]*>/i.test(String(s||""))?String(s):`<p>${String(s||"")}</p>`,a=await j(`/workspaces/${encodeURIComponent(t)}/projects/${encodeURIComponent(n)}/work-items/${encodeURIComponent(r)}/comments/`,{method:"POST",body:{comment_html:o}});return{ok:!!a.id,id:a.id||null,_raw:a}},async transition(r,s,e={}){let{workspaceSlug:t,projectId:n}=$(e),i=await _e(e),o=at(i,s);if(!o)return{ok:!1,error:`No Plane state matches "${s}" in this project`,availableStates:i.map(c=>({id:c.id,name:c.name,group:c.group}))};let a=await j(`/workspaces/${encodeURIComponent(t)}/projects/${encodeURIComponent(n)}/work-items/${encodeURIComponent(r)}/`,{method:"PATCH",body:{state:o.id}});return{ok:!!a.id,stateAfter:o.name,stateCategoryAfter:se(o),_raw:a}},async linkPullRequest(r,s,e,t={}){let n=e?`${e}: `:"Linked PR: ";return{ok:!!(await this.addComment(r,`<p>${n}<a href="${s}">${s}</a></p>`,t)).ok,via:"comment"}}};var ct=["todo","in_progress","done","blocked","unknown"];var we={jira:Q,linear:X,github:te,plane:ie},lt="jira";function Gt(r){let s=String(r||process.env.TRACKER_PROVIDER||lt).trim().toLowerCase(),e=we[s];if(!e){let t=Object.keys(we).join(", ");throw new Error(`Unknown tracker provider "${s}". Known providers: ${t}.`)}return e}export{lt as DEFAULT_TRACKER_PROVIDER,we as TRACKER_ADAPTERS,ct as TRACKER_STATE_CATEGORIES,Gt as getAdapter,te as githubAdapter,Q as jiraAdapter,X as linearAdapter,ie as planeAdapter};