@zibby/skills 0.1.35 → 0.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/linear.d.ts CHANGED
@@ -26,6 +26,17 @@ export namespace linearSkill {
26
26
  LINEAR_API_URL: any;
27
27
  };
28
28
  description: string;
29
+ type?: undefined;
30
+ alwaysLoad?: undefined;
31
+ } | {
32
+ type: string;
33
+ command: string;
34
+ args: any[];
35
+ env: {
36
+ LINEAR_API_URL: any;
37
+ };
38
+ description: string;
39
+ alwaysLoad: boolean;
29
40
  };
30
41
  function handleToolCall(name: any, args: any): Promise<string>;
31
42
  let tools: ({
package/dist/linear.js CHANGED
@@ -1,4 +1,4 @@
1
- var b=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"}),v=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 N=process.env.LINEAR_API_URL||"https://api.linear.app/graphql";function w(){if(process.env.LINEAR_OAUTH_TOKEN)return`Bearer ${process.env.LINEAR_OAUTH_TOKEN}`;let l=process.env.LINEAR_API_KEY;if(!l)throw new Error("Linear is not connected: set LINEAR_API_KEY (personal API key) or LINEAR_OAUTH_TOKEN.");return l}async function f(l,i={}){let t=await fetch(N,{method:"POST",headers:{Authorization:w(),"Content-Type":"application/json"},body:JSON.stringify({query:l,variables:i})});if(!t.ok){let s=await t.text().catch(()=>"");throw new Error(`Linear API ${t.status}: ${s.slice(0,300)}`)}let e=await t.json().catch(()=>null);if(!e)throw new Error("Linear API returned a non-JSON body");if(Array.isArray(e.errors)&&e.errors.length){let s=e.errors.map(n=>n?.message||String(n)).join("; ");throw new Error(`Linear GraphQL error: ${s.slice(0,300)}`)}return e.data}function h(l){return String(l||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function k(l,i){let t=h(l),e=h(i);if(!t||!e)return 0;if(t===e)return 1;if(t.length===1||e.length===1)return t===e?1:0;let s=o=>{let c=new Map;for(let y=0;y<o.length-1;y++){let g=o.slice(y,y+2);c.set(g,(c.get(g)||0)+1)}return c},n=s(t),a=s(e),r=0,d=0,m=0;for(let o of n.values())d+=o;for(let o of a.values())m+=o;for(let[o,c]of n.entries())r+=Math.min(c,a.get(o)||0);return 2*r/Math.max(1,d+m)}function L(l,i){let t=Array.isArray(l)?l:[];if(!t.length)return{state:null,strategy:"no-states"};let e=h(i);if(!e)return{state:null,strategy:"no-target"};let s=t.find(r=>h(r.name)===e);if(s)return{state:s,strategy:"exact"};let n={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[r,d]of Object.entries(n)){if(!d.some(o=>h(o)===e))continue;let m=t.find(o=>o.type===r);if(m)return{state:m,strategy:"type-alias"}}let a=t.map(r=>({s:r,score:k(i,r.name)})).sort((r,d)=>d.score-r.score);return a[0]&&a[0].score>=.5?{state:a[0].s,strategy:"fuzzy"}:{state:null,strategy:"no-match"}}var S=`
1
+ import{existsSync as N}from"fs";import{fileURLToPath as w}from"url";import{dirname as L,resolve as k}from"path";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"}),$=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"}});function S(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let a=L(w(import.meta.url)),i=k(a,"..","bin","mcp-skill.mjs");return N(i)?i:null}var v=process.env.LINEAR_API_URL||"https://api.linear.app/graphql";function O(){if(process.env.LINEAR_OAUTH_TOKEN)return`Bearer ${process.env.LINEAR_OAUTH_TOKEN}`;let a=process.env.LINEAR_API_KEY;if(!a)throw new Error("Linear is not connected: set LINEAR_API_KEY (personal API key) or LINEAR_OAUTH_TOKEN.");return a}async function f(a,i={}){let t=await fetch(v,{method:"POST",headers:{Authorization:O(),"Content-Type":"application/json"},body:JSON.stringify({query:a,variables:i})});if(!t.ok){let s=await t.text().catch(()=>"");throw new Error(`Linear API ${t.status}: ${s.slice(0,300)}`)}let e=await t.json().catch(()=>null);if(!e)throw new Error("Linear API returned a non-JSON body");if(Array.isArray(e.errors)&&e.errors.length){let s=e.errors.map(n=>n?.message||String(n)).join("; ");throw new Error(`Linear GraphQL error: ${s.slice(0,300)}`)}return e.data}function h(a){return String(a||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function E(a,i){let t=h(a),e=h(i);if(!t||!e)return 0;if(t===e)return 1;if(t.length===1||e.length===1)return t===e?1:0;let s=d=>{let u=new Map;for(let y=0;y<d.length-1;y++){let g=d.slice(y,y+2);u.set(g,(u.get(g)||0)+1)}return u},n=s(t),r=s(e),o=0,l=0,m=0;for(let d of n.values())l+=d;for(let d of r.values())m+=d;for(let[d,u]of n.entries())o+=Math.min(u,r.get(d)||0);return 2*o/Math.max(1,l+m)}function T(a,i){let t=Array.isArray(a)?a:[];if(!t.length)return{state:null,strategy:"no-states"};let e=h(i);if(!e)return{state:null,strategy:"no-target"};let s=t.find(o=>h(o.name)===e);if(s)return{state:s,strategy:"exact"};let n={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[o,l]of Object.entries(n)){if(!l.some(d=>h(d)===e))continue;let m=t.find(d=>d.type===o);if(m)return{state:m,strategy:"type-alias"}}let r=t.map(o=>({s:o,score:E(i,o.name)})).sort((o,l)=>l.score-o.score);return r[0]&&r[0].score>=.5?{state:r[0].s,strategy:"fuzzy"}:{state:null,strategy:"no-match"}}var P=`
2
2
  id
3
3
  identifier
4
4
  number
@@ -12,7 +12,7 @@ var b=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab"
12
12
  assignee { id name displayName email }
13
13
  labels { nodes { id name color } }
14
14
  team { id key name }
15
- `,$={id:"linear",serverName:"linear",allowedTools:["mcp__linear__*"],requiresIntegration:b.LINEAR,envKeys:["LINEAR_API_KEY","LINEAR_OAUTH_TOKEN"],description:"Linear \u2014 issues, comments, workflow states (GraphQL API key)",promptFragment:`## Linear (connected)
15
+ `,U={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)
16
16
  You have direct access to the user's Linear workspace (GraphQL API). Tools:
17
17
 
18
18
  ### Discovery
@@ -30,32 +30,32 @@ You have direct access to the user's Linear workspace (GraphQL API). Tools:
30
30
 
31
31
  ### Notes
32
32
  - 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.
33
- - Issue identifier (ENG-123) and internal id (uuid) are both accepted by get/update tools.`,resolve(){let l={};for(let i of this.envKeys)process.env[i]&&(l[i]=process.env[i]);return process.env.LINEAR_API_URL&&(l.LINEAR_API_URL=process.env.LINEAR_API_URL),{command:null,args:[],env:l,description:this.description}},async handleToolCall(l,i){try{switch(l){case"linear_list_teams":{let e=(await f(`
33
+ - Issue identifier (ENG-123) and internal id (uuid) are both accepted by get/update tools.`,resolve(){let a={};for(let t of this.envKeys)process.env[t]&&(a[t]=process.env[t]);process.env.LINEAR_API_URL&&(a.LINEAR_API_URL=process.env.LINEAR_API_URL);let i=S();return i?{type:"stdio",command:"node",args:[i,"../dist/linear.js","linearSkill"],env:a,description:this.description,alwaysLoad:!0}:{command:null,args:[],env:a,description:this.description}},async handleToolCall(a,i){try{switch(a){case"linear_list_teams":{let e=(await f(`
34
34
  query Teams($first: Int) {
35
35
  teams(first: $first) {
36
36
  nodes { id key name description }
37
37
  }
38
38
  }
39
- `,{first:i?.limit||50}))?.teams?.nodes||[];return JSON.stringify({count:e.length,teams:e})}case"linear_list_states":{let{teamId:t,teamKey:e}=i||{},s=t;if(!s&&e&&(s=await _(e)),s){let d=(await f(`
39
+ `,{first:i?.limit||50}))?.teams?.nodes||[];return JSON.stringify({count:e.length,teams:e})}case"linear_list_states":{let{teamId:t,teamKey:e}=i||{},s=t;if(!s&&e&&(s=await b(e)),s){let l=(await f(`
40
40
  query States($teamId: String!) {
41
41
  team(id: $teamId) {
42
42
  id key name
43
43
  states { nodes { id name type color position } }
44
44
  }
45
45
  }
46
- `,{teamId:s}))?.team,m=(d?.states?.nodes||[]).slice().sort((o,c)=>(o.position||0)-(c.position||0));return JSON.stringify({team:d?{id:d.id,key:d.key,name:d.name}:null,count:m.length,states:m})}let a=(await f(`
46
+ `,{teamId:s}))?.team,m=(l?.states?.nodes||[]).slice().sort((d,u)=>(d.position||0)-(u.position||0));return JSON.stringify({team:l?{id:l.id,key:l.key,name:l.name}:null,count:m.length,states:m})}let r=(await f(`
47
47
  query AllStates($first: Int) {
48
48
  workflowStates(first: $first) {
49
49
  nodes { id name type color team { id key name } }
50
50
  }
51
51
  }
52
- `,{first:i?.limit||200}))?.workflowStates?.nodes||[];return JSON.stringify({scope:"workspace",count:a.length,states:a})}case"linear_list_labels":{let{teamId:t}=i||{},s=(await f(`
52
+ `,{first:i?.limit||200}))?.workflowStates?.nodes||[];return JSON.stringify({scope:"workspace",count:r.length,states:r})}case"linear_list_labels":{let{teamId:t}=i||{},s=(await f(`
53
53
  query Labels($first: Int, $filter: IssueLabelFilter) {
54
54
  issueLabels(first: $first, filter: $filter) {
55
55
  nodes { id name color team { id key } }
56
56
  }
57
57
  }
58
- `,{first:i?.limit||100,filter:t?{team:{id:{eq:t}}}:void 0}))?.issueLabels?.nodes||[];return JSON.stringify({count:s.length,labels:s})}case"linear_list_issues":{let{teamId:t,teamKey:e,stateId:s,stateName:n,label:a,assigneeId:r,updatedAfter:d,limit:m}=i||{},o={},c=t;!c&&e&&(c=await _(e)),c&&(o.team={id:{eq:c}}),s?o.state={id:{eq:s}}:n&&(o.state={name:{eqIgnoreCase:n}}),a&&(o.labels={name:{eqIgnoreCase:a}}),r&&(o.assignee={id:{eq:r}}),d&&(o.updatedAt={gt:d});let g=((await f(`
58
+ `,{first:i?.limit||100,filter:t?{team:{id:{eq:t}}}:void 0}))?.issueLabels?.nodes||[];return JSON.stringify({count:s.length,labels:s})}case"linear_list_issues":{let{teamId:t,teamKey:e,stateId:s,stateName:n,label:r,assigneeId:o,updatedAfter:l,limit:m}=i||{},d={},u=t;!u&&e&&(u=await b(e)),u&&(d.team={id:{eq:u}}),s?d.state={id:{eq:s}}:n&&(d.state={name:{eqIgnoreCase:n}}),r&&(d.labels={name:{eqIgnoreCase:r}}),o&&(d.assignee={id:{eq:o}}),l&&(d.updatedAt={gt:l});let g=((await f(`
59
59
  query Issues($first: Int, $filter: IssueFilter, $orderBy: PaginationOrderBy) {
60
60
  issues(first: $first, filter: $filter, orderBy: $orderBy) {
61
61
  nodes {
@@ -67,48 +67,48 @@ You have direct access to the user's Linear workspace (GraphQL API). Tools:
67
67
  }
68
68
  }
69
69
  }
70
- `,{first:m||30,filter:Object.keys(o).length?o:void 0,orderBy:"updatedAt"}))?.issues?.nodes||[]).map(u=>({id:u.id,identifier:u.identifier,number:u.number,title:u.title,url:u.url,priority:u.priority,state:u.state?.name,stateType:u.state?.type,assignee:u.assignee?.displayName||null,labels:(u.labels?.nodes||[]).map(p=>p.name),team:u.team?.key,createdAt:u.createdAt,updatedAt:u.updatedAt}));return JSON.stringify({count:g.length,issues:g})}case"linear_get_issue":{let t=i?.issueId||i?.identifier||i?.issueKey;if(!t)return JSON.stringify({error:"issueId or identifier is required"});let e=await I(t);return JSON.stringify(e?{id:e.id,identifier:e.identifier,number:e.number,title:e.title,description:e.description||"",url:e.url,priority:e.priority,state:e.state?.name,stateId:e.state?.id,stateType:e.state?.type,assignee:e.assignee?.displayName||e.assignee?.name||null,assigneeId:e.assignee?.id||null,labels:(e.labels?.nodes||[]).map(s=>s.name),team:e.team?{id:e.team.id,key:e.team.key,name:e.team.name}:null,createdAt:e.createdAt,updatedAt:e.updatedAt}:{error:`Issue not found: ${t}`})}case"linear_get_comments":{let t=i?.issueId||i?.identifier||i?.issueKey;if(!t)return JSON.stringify({error:"issueId or identifier is required"});let e=await I(t,`
70
+ `,{first:m||30,filter:Object.keys(d).length?d:void 0,orderBy:"updatedAt"}))?.issues?.nodes||[]).map(c=>({id:c.id,identifier:c.identifier,number:c.number,title:c.title,url:c.url,priority:c.priority,state:c.state?.name,stateType:c.state?.type,assignee:c.assignee?.displayName||null,labels:(c.labels?.nodes||[]).map(p=>p.name),team:c.team?.key,createdAt:c.createdAt,updatedAt:c.updatedAt}));return JSON.stringify({count:g.length,issues:g})}case"linear_get_issue":{let t=i?.issueId||i?.identifier||i?.issueKey;if(!t)return JSON.stringify({error:"issueId or identifier is required"});let e=await I(t);return JSON.stringify(e?{id:e.id,identifier:e.identifier,number:e.number,title:e.title,description:e.description||"",url:e.url,priority:e.priority,state:e.state?.name,stateId:e.state?.id,stateType:e.state?.type,assignee:e.assignee?.displayName||e.assignee?.name||null,assigneeId:e.assignee?.id||null,labels:(e.labels?.nodes||[]).map(s=>s.name),team:e.team?{id:e.team.id,key:e.team.key,name:e.team.name}:null,createdAt:e.createdAt,updatedAt:e.updatedAt}:{error:`Issue not found: ${t}`})}case"linear_get_comments":{let t=i?.issueId||i?.identifier||i?.issueKey;if(!t)return JSON.stringify({error:"issueId or identifier is required"});let e=await I(t,`
71
71
  id identifier
72
72
  comments(first: ${Number(i?.limit)||50}) {
73
73
  nodes { id body createdAt updatedAt user { id name displayName } }
74
74
  }
75
- `);if(!e)return JSON.stringify({error:`Issue not found: ${t}`});let s=(e.comments?.nodes||[]).map(n=>({id:n.id,author:n.user?.displayName||n.user?.name||"Unknown",body:n.body||"",createdAt:n.createdAt,updatedAt:n.updatedAt})).sort((n,a)=>String(a.createdAt).localeCompare(String(n.createdAt)));return JSON.stringify({count:s.length,issue:e.identifier,comments:s})}case"linear_add_comment":{let t=i?.issueId||i?.identifier||i?.issueKey,e=i?.body;if(!t||!e)return JSON.stringify({error:"issueId/identifier and body are required"});let s=await I(t,"id identifier");if(!s)return JSON.stringify({error:`Issue not found: ${t}`});let a=(await f(`
75
+ `);if(!e)return JSON.stringify({error:`Issue not found: ${t}`});let s=(e.comments?.nodes||[]).map(n=>({id:n.id,author:n.user?.displayName||n.user?.name||"Unknown",body:n.body||"",createdAt:n.createdAt,updatedAt:n.updatedAt})).sort((n,r)=>String(r.createdAt).localeCompare(String(n.createdAt)));return JSON.stringify({count:s.length,issue:e.identifier,comments:s})}case"linear_add_comment":{let t=i?.issueId||i?.identifier||i?.issueKey,e=i?.body;if(!t||!e)return JSON.stringify({error:"issueId/identifier and body are required"});let s=await I(t,"id identifier");if(!s)return JSON.stringify({error:`Issue not found: ${t}`});let r=(await f(`
76
76
  mutation AddComment($input: CommentCreateInput!) {
77
77
  commentCreate(input: $input) {
78
78
  success
79
79
  comment { id url createdAt }
80
80
  }
81
81
  }
82
- `,{input:{issueId:s.id,body:e}}))?.commentCreate;return JSON.stringify({ok:!!a?.success,commentId:a?.comment?.id,url:a?.comment?.url})}case"linear_update_state":{let t=i?.issueId||i?.identifier||i?.issueKey,{stateId:e,stateName:s,toStatus:n,status:a}=i||{};if(!t)return JSON.stringify({error:"issueId or identifier is required"});let r=await I(t,`
82
+ `,{input:{issueId:s.id,body:e}}))?.commentCreate;return JSON.stringify({ok:!!r?.success,commentId:r?.comment?.id,url:r?.comment?.url})}case"linear_update_state":{let t=i?.issueId||i?.identifier||i?.issueKey,{stateId:e,stateName:s,toStatus:n,status:r}=i||{};if(!t)return JSON.stringify({error:"issueId or identifier is required"});let o=await I(t,`
83
83
  id identifier
84
84
  state { id name type }
85
85
  team { id key states { nodes { id name type position } } }
86
- `);if(!r)return JSON.stringify({error:`Issue not found: ${t}`});let d=e,m=e?{strategy:"explicit-id"}:null;if(!d){let y=String(s||n||a||"").trim(),g=(r.team?.states?.nodes||[]).slice().sort((p,A)=>(p.position||0)-(A.position||0));if(!y)return JSON.stringify({ok:!1,error:"stateId or stateName/toStatus is required",issue:r.identifier,availableStates:g.map(p=>({id:p.id,name:p.name,type:p.type}))});let u=L(g,y);if(!u.state)return JSON.stringify({ok:!1,error:`No workflow state matches "${y}" in team ${r.team?.key}`,issue:r.identifier,availableStates:g.map(p=>({id:p.id,name:p.name,type:p.type}))});d=u.state.id,m={strategy:u.strategy,matchedName:u.state.name}}let c=(await f(`
86
+ `);if(!o)return JSON.stringify({error:`Issue not found: ${t}`});let l=e,m=e?{strategy:"explicit-id"}:null;if(!l){let y=String(s||n||r||"").trim(),g=(o.team?.states?.nodes||[]).slice().sort((p,A)=>(p.position||0)-(A.position||0));if(!y)return JSON.stringify({ok:!1,error:"stateId or stateName/toStatus is required",issue:o.identifier,availableStates:g.map(p=>({id:p.id,name:p.name,type:p.type}))});let c=T(g,y);if(!c.state)return JSON.stringify({ok:!1,error:`No workflow state matches "${y}" in team ${o.team?.key}`,issue:o.identifier,availableStates:g.map(p=>({id:p.id,name:p.name,type:p.type}))});l=c.state.id,m={strategy:c.strategy,matchedName:c.state.name}}let u=(await f(`
87
87
  mutation MoveIssue($id: String!, $input: IssueUpdateInput!) {
88
88
  issueUpdate(id: $id, input: $input) {
89
89
  success
90
90
  issue { id identifier state { id name type } }
91
91
  }
92
92
  }
93
- `,{id:r.id,input:{stateId:d}}))?.issueUpdate;return JSON.stringify({ok:!!c?.success,issue:c?.issue?.identifier||r.identifier,stateAfter:c?.issue?.state?.name||null,stateTypeAfter:c?.issue?.state?.type||null,resolution:m})}case"linear_link_attachment":{let t=i?.issueId||i?.identifier||i?.issueKey,{url:e,title:s,subtitle:n}=i||{};if(!t||!e)return JSON.stringify({error:"issueId/identifier and url are required"});let a=await I(t,"id identifier");if(!a)return JSON.stringify({error:`Issue not found: ${t}`});let d=(await f(`
93
+ `,{id:o.id,input:{stateId:l}}))?.issueUpdate;return JSON.stringify({ok:!!u?.success,issue:u?.issue?.identifier||o.identifier,stateAfter:u?.issue?.state?.name||null,stateTypeAfter:u?.issue?.state?.type||null,resolution:m})}case"linear_link_attachment":{let t=i?.issueId||i?.identifier||i?.issueKey,{url:e,title:s,subtitle:n}=i||{};if(!t||!e)return JSON.stringify({error:"issueId/identifier and url are required"});let r=await I(t,"id identifier");if(!r)return JSON.stringify({error:`Issue not found: ${t}`});let l=(await f(`
94
94
  mutation LinkAttachment($input: AttachmentCreateInput!) {
95
95
  attachmentCreate(input: $input) {
96
96
  success
97
97
  attachment { id url title }
98
98
  }
99
99
  }
100
- `,{input:{issueId:a.id,url:e,title:s||e,subtitle:n||void 0}}))?.attachmentCreate;return JSON.stringify({ok:!!d?.success,attachmentId:d?.attachment?.id,url:d?.attachment?.url})}default:return JSON.stringify({error:`Unknown tool: ${l}`})}}catch(t){return JSON.stringify({error:t.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 _(l){return(await f(`
100
+ `,{input:{issueId:r.id,url:e,title:s||e,subtitle:n||void 0}}))?.attachmentCreate;return JSON.stringify({ok:!!l?.success,attachmentId:l?.attachment?.id,url:l?.attachment?.url})}default:return JSON.stringify({error:`Unknown tool: ${a}`})}}catch(t){return JSON.stringify({error:t.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 b(a){return(await f(`
101
101
  query TeamByKey($filter: TeamFilter) {
102
102
  teams(first: 1, filter: $filter) { nodes { id key } }
103
103
  }
104
- `,{filter:{key:{eq:l}}}))?.teams?.nodes?.[0]?.id||null}async function I(l,i=S){let t=String(l).trim(),e=/^([A-Za-z][A-Za-z0-9]*)-(\d+)$/.exec(t);if(e){let n=e[1].toUpperCase(),a=Number(e[2]);return(await f(`
104
+ `,{filter:{key:{eq:a}}}))?.teams?.nodes?.[0]?.id||null}async function I(a,i=P){let t=String(a).trim(),e=/^([A-Za-z][A-Za-z0-9]*)-(\d+)$/.exec(t);if(e){let n=e[1].toUpperCase(),r=Number(e[2]);return(await f(`
105
105
  query IssueByIdentifier($filter: IssueFilter) {
106
106
  issues(first: 1, filter: $filter) {
107
107
  nodes { ${i} }
108
108
  }
109
109
  }
110
- `,{filter:{number:{eq:a},team:{key:{eq:n}}}}))?.issues?.nodes?.[0]||null}return(await f(`
110
+ `,{filter:{number:{eq:r},team:{key:{eq:n}}}}))?.issues?.nodes?.[0]||null}return(await f(`
111
111
  query IssueById($id: String!) {
112
112
  issue(id: $id) { ${i} }
113
113
  }
114
- `,{id:t}))?.issue||null}export{f as linearFetch,$ as linearSkill};
114
+ `,{id:t}))?.issue||null}export{f as linearFetch,U as linearSkill};
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/skills",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "description": "Built-in skill definitions for Zibby test automation framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -10,6 +10,7 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "default": "./dist/index.js"
12
12
  },
13
+ "./bin/mcp-skill.mjs": "./bin/mcp-skill.mjs",
13
14
  "./bin/mcp-sentry.mjs": "./bin/mcp-sentry.mjs",
14
15
  "./bin/mcp-lark.mjs": "./bin/mcp-lark.mjs",
15
16
  "./bin/mcp-slack.mjs": "./bin/mcp-slack.mjs",
@@ -1,4 +1,4 @@
1
- import{resolveIntegrationToken as C}from"@zibby/core/backend-client.js";var v=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",PLANE:"plane",LINEAR:"linear"}),j=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"}});async function d(a,o={}){let{token:t}=await C("github"),r=a.startsWith("https://")?a:`https://api.github.com${a}`,i={Authorization:`Bearer ${t}`,Accept:o.accept||"application/vnd.github.v3+json","User-Agent":"Zibby-App",...o.body?{"Content-Type":"application/json"}:{}},e=await fetch(r,{method:o.method||"GET",headers:i,body:o.body?JSON.stringify(o.body):void 0});if(!e.ok){let n=await e.text().catch(()=>"");throw new Error(`GitHub API ${e.status}: ${n.slice(0,300)}`)}return o.raw?e.text():e.json()}var _={id:"github",serverName:"github",allowedTools:["mcp__github__*"],requiresIntegration:v.GITHUB,envKeys:["GITHUB_TOKEN"],description:"GitHub \u2014 issues, PRs, commits, code search, file reading",promptFragment:`## GitHub (connected)
1
+ import{existsSync as J}from"fs";import{fileURLToPath as I}from"url";import{dirname as H,resolve as L}from"path";import{resolveIntegrationToken as C}from"@zibby/core/backend-client.js";var v=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",PLANE:"plane",LINEAR:"linear"}),B=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"}});function j(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let a=H(I(import.meta.url)),o=L(a,"..","bin","mcp-skill.mjs");return J(o)?o:null}async function d(a,o={}){let{token:t}=await C("github"),r=a.startsWith("https://")?a:`https://api.github.com${a}`,i={Authorization:`Bearer ${t}`,Accept:o.accept||"application/vnd.github.v3+json","User-Agent":"Zibby-App",...o.body?{"Content-Type":"application/json"}:{}},e=await fetch(r,{method:o.method||"GET",headers:i,body:o.body?JSON.stringify(o.body):void 0});if(!e.ok){let n=await e.text().catch(()=>"");throw new Error(`GitHub API ${e.status}: ${n.slice(0,300)}`)}return o.raw?e.text():e.json()}var _={id:"github",serverName:"github",allowedTools:["mcp__github__*"],requiresIntegration:v.GITHUB,envKeys:["GITHUB_TOKEN"],description:"GitHub \u2014 issues, PRs, commits, code search, file reading",promptFragment:`## GitHub (connected)
2
2
  You have access to the user's GitHub repositories. Available tools:
3
3
 
4
4
  ### Discovery
@@ -36,6 +36,6 @@ When user says "check out repo-name" or "clone repo-name":
36
36
  3. STOP. Do not offer to inspect files or ask what to do next.
37
37
 
38
38
  When user just wants to "look at" or "read" files (not clone):
39
- - Use github_get_file to read individual files via API`,resolve(){let a={};for(let o of this.envKeys)process.env[o]&&(a[o]=process.env[o]);return{command:"npx",args:["-y","@modelcontextprotocol/server-github@latest"],env:a}},async handleToolCall(a,o){try{switch(a){case"github_search_issues":{let t=o.query;if(!t)return JSON.stringify({error:"query is required"});let r=await d(`/search/issues?q=${encodeURIComponent(t)}&per_page=${o.limit||20}`),i=(r.items||[]).map(e=>({number:e.number,title:e.title,state:e.state,repo:e.repository_url?.split("/").slice(-2).join("/"),url:e.html_url,user:e.user?.login,isPR:!!e.pull_request,labels:(e.labels||[]).map(n=>n.name),createdAt:e.created_at}));return JSON.stringify({total:r.total_count,items:i})}case"github_search_code":{let t=o.query;if(!t)return JSON.stringify({error:"query is required"});let r=o.repo?`+repo:${o.repo}`:"",i=o.language?`+language:${o.language}`:"",e=await d(`/search/code?q=${encodeURIComponent(t)}${r}${i}&per_page=${o.limit||15}`),n=(e.items||[]).map(s=>({name:s.name,path:s.path,repo:s.repository?.full_name,url:s.html_url,score:s.score}));return JSON.stringify({total:e.total_count,items:n})}case"github_get_pr":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}`);return JSON.stringify({number:e.number,title:e.title,state:e.state,merged:e.merged,body:e.body?.slice(0,5e3),user:e.user?.login,branch:e.head?.ref,base:e.base?.ref,changedFiles:e.changed_files,additions:e.additions,deletions:e.deletions,createdAt:e.created_at,mergedAt:e.merged_at,url:e.html_url,labels:(e.labels||[]).map(n=>n.name)})}case"github_get_pr_diff":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}`,{accept:"application/vnd.github.v3.diff",raw:!0}),n=e.length>15e3;return JSON.stringify({number:i,diff:n?e.slice(0,15e3):e,truncated:n,totalLength:e.length})}case"github_list_pr_files":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}/files?per_page=100`);return JSON.stringify({total:e.length,files:e.map(n=>({filename:n.filename,status:n.status,additions:n.additions,deletions:n.deletions,patch:n.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}/comments?per_page=50`),n=await d(`/repos/${t}/${r}/issues/${i}/comments?per_page=50`),s=[...e.map(p=>({type:"review",user:p.user?.login,body:p.body?.slice(0,1e3),path:p.path,line:p.line,createdAt:p.created_at})),...n.map(p=>({type:"issue",user:p.user?.login,body:p.body?.slice(0,1e3),createdAt:p.created_at}))].sort((p,u)=>new Date(p.createdAt)-new Date(u.createdAt));return JSON.stringify({total:s.length,comments:s})}case"github_create_review":{let{owner:t,repo:r,number:i,body:e,event:n,comments:s}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let p=(n||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(p))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${n})`});let u=Array.isArray(s)?s.filter(g=>g&&g.path&&g.body&&(g.line!=null||g.position!=null)).map(g=>{let f={path:g.path,body:String(g.body)};return g.line!=null?(f.line=Number(g.line),f.side=g.side==="LEFT"?"LEFT":"RIGHT"):f.position=Number(g.position),f}):[];if(p!=="APPROVE"&&!e&&u.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let m={event:p};e&&(m.body=String(e)),u.length>0&&(m.comments=u);let c=await d(`/repos/${t}/${r}/pulls/${i}/reviews`,{method:"POST",body:m});return JSON.stringify({ok:!0,id:c.id,state:c.state,event:p,commentsPosted:u.length,url:c.html_url})}case"github_list_commits":{let{owner:t,repo:r,branch:i,path:e,limit:n}=o;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let s=`/repos/${t}/${r}/commits?per_page=${n||20}`;i&&(s+=`&sha=${encodeURIComponent(i)}`),e&&(s+=`&path=${encodeURIComponent(e)}`);let p=await d(s);return JSON.stringify({total:p.length,commits:p.map(u=>({sha:u.sha?.slice(0,8),fullSha:u.sha,message:u.commit?.message?.slice(0,300),author:u.commit?.author?.name,date:u.commit?.author?.date,url:u.html_url}))})}case"github_get_commit":{let{owner:t,repo:r,sha:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and sha are required"});let e=await d(`/repos/${t}/${r}/commits/${i}`);return JSON.stringify({sha:e.sha?.slice(0,8),message:e.commit?.message,author:e.commit?.author?.name,date:e.commit?.author?.date,stats:e.stats,files:(e.files||[]).map(n=>({filename:n.filename,status:n.status,additions:n.additions,deletions:n.deletions,patch:n.patch?.slice(0,3e3)}))})}case"github_get_file":{let{owner:t,repo:r,path:i,ref:e}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and path are required"});let n=`/repos/${t}/${r}/contents/${encodeURIComponent(i)}`;e&&(n+=`?ref=${encodeURIComponent(e)}`);let s=await d(n);if(s.type!=="file")return Array.isArray(s)?JSON.stringify({type:"directory",path:i,entries:s.map(m=>({name:m.name,type:m.type,size:m.size,path:m.path}))}):JSON.stringify({error:`Not a file: ${s.type}`});let p=Buffer.from(s.content||"","base64").toString("utf-8"),u=p.length>2e4;return JSON.stringify({path:s.path,size:s.size,sha:s.sha?.slice(0,8),content:u?p.slice(0,2e4):p,truncated:u})}case"github_get_user":try{let t=await d("/installation/repositories?per_page=1");if(t.repositories&&t.repositories.length>0){let r=t.repositories[0],i=r.owner.login,e=r.owner.type,n=e==="Organization"?`/orgs/${i}`:`/users/${i}`,s=await d(n);return JSON.stringify({login:s.login,name:s.name||s.login,avatar:s.avatar_url,bio:s.bio||s.description,type:e,isOrg:e==="Organization",publicRepos:s.public_repos,message:"Showing GitHub App installation owner (GitHub Apps cannot access /user endpoint)"})}return JSON.stringify({error:"No repositories accessible to this GitHub App installation"})}catch(t){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${t.message})`})}case"github_list_orgs":try{let r=(await d("/installation/repositories?per_page=100")).repositories||[],i=new Map;for(let n of r)n.owner.type==="Organization"&&(i.has(n.owner.login)||i.set(n.owner.login,{login:n.owner.login,description:null,url:n.owner.url}));let e=Array.from(i.values());return JSON.stringify({count:e.length,orgs:e,message:"Extracted from accessible repositories (GitHub Apps cannot access /user/orgs directly)"})}catch(t){return JSON.stringify({error:`GitHub App cannot list orgs via /user/orgs. Error: ${t.message}`})}case"github_clone":{let l=function(w){let R=w.replace(/^~(?=$|\/|\\)/,f);return s(R)},{owner:t,repo:r,destination:i}=o;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let{execSync:e}=await import("child_process"),{join:n,resolve:s}=await import("path"),{existsSync:p,mkdirSync:u}=await import("fs"),{homedir:m,platform:c}=await import("os"),{token:g}=await C("github"),f=m(),y=i?l(i):n(f,"zibby-repos"),h=n(y,r);if(u(y,{recursive:!0}),p(h))return JSON.stringify({error:`Directory ${h} already exists. Remove it first or use a different destination.`,existingPath:h});try{let w=`https://x-access-token:${g}@github.com/${t}/${r}.git`;e(`git clone ${w} "${h}"`,{stdio:"pipe"});let R=c()==="win32",b;return R?b=e(`dir "${h}"`,{encoding:"utf-8",shell:"cmd.exe"}):b=e(`ls -la "${h}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:h,message:`Cloned ${t}/${r} to ${h}`,contents:b.split(`
39
+ - Use github_get_file to read individual files via API`,resolve(){let a=j();if(!a)return{command:null,args:[],env:{},description:this.description};let o={};for(let t of this.envKeys)process.env[t]&&(o[t]=process.env[t]);return{type:"stdio",command:"node",args:[a,"../dist/github.js","githubSkill"],env:o,description:this.description,alwaysLoad:!0}},async handleToolCall(a,o){try{switch(a){case"github_search_issues":{let t=o.query;if(!t)return JSON.stringify({error:"query is required"});let r=await d(`/search/issues?q=${encodeURIComponent(t)}&per_page=${o.limit||20}`),i=(r.items||[]).map(e=>({number:e.number,title:e.title,state:e.state,repo:e.repository_url?.split("/").slice(-2).join("/"),url:e.html_url,user:e.user?.login,isPR:!!e.pull_request,labels:(e.labels||[]).map(n=>n.name),createdAt:e.created_at}));return JSON.stringify({total:r.total_count,items:i})}case"github_search_code":{let t=o.query;if(!t)return JSON.stringify({error:"query is required"});let r=o.repo?`+repo:${o.repo}`:"",i=o.language?`+language:${o.language}`:"",e=await d(`/search/code?q=${encodeURIComponent(t)}${r}${i}&per_page=${o.limit||15}`),n=(e.items||[]).map(s=>({name:s.name,path:s.path,repo:s.repository?.full_name,url:s.html_url,score:s.score}));return JSON.stringify({total:e.total_count,items:n})}case"github_get_pr":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}`);return JSON.stringify({number:e.number,title:e.title,state:e.state,merged:e.merged,body:e.body?.slice(0,5e3),user:e.user?.login,branch:e.head?.ref,base:e.base?.ref,changedFiles:e.changed_files,additions:e.additions,deletions:e.deletions,createdAt:e.created_at,mergedAt:e.merged_at,url:e.html_url,labels:(e.labels||[]).map(n=>n.name)})}case"github_get_pr_diff":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}`,{accept:"application/vnd.github.v3.diff",raw:!0}),n=e.length>15e3;return JSON.stringify({number:i,diff:n?e.slice(0,15e3):e,truncated:n,totalLength:e.length})}case"github_list_pr_files":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}/files?per_page=100`);return JSON.stringify({total:e.length,files:e.map(n=>({filename:n.filename,status:n.status,additions:n.additions,deletions:n.deletions,patch:n.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:t,repo:r,number:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/pulls/${i}/comments?per_page=50`),n=await d(`/repos/${t}/${r}/issues/${i}/comments?per_page=50`),s=[...e.map(p=>({type:"review",user:p.user?.login,body:p.body?.slice(0,1e3),path:p.path,line:p.line,createdAt:p.created_at})),...n.map(p=>({type:"issue",user:p.user?.login,body:p.body?.slice(0,1e3),createdAt:p.created_at}))].sort((p,u)=>new Date(p.createdAt)-new Date(u.createdAt));return JSON.stringify({total:s.length,comments:s})}case"github_create_review":{let{owner:t,repo:r,number:i,body:e,event:n,comments:s}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let p=(n||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(p))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${n})`});let u=Array.isArray(s)?s.filter(g=>g&&g.path&&g.body&&(g.line!=null||g.position!=null)).map(g=>{let f={path:g.path,body:String(g.body)};return g.line!=null?(f.line=Number(g.line),f.side=g.side==="LEFT"?"LEFT":"RIGHT"):f.position=Number(g.position),f}):[];if(p!=="APPROVE"&&!e&&u.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let m={event:p};e&&(m.body=String(e)),u.length>0&&(m.comments=u);let c=await d(`/repos/${t}/${r}/pulls/${i}/reviews`,{method:"POST",body:m});return JSON.stringify({ok:!0,id:c.id,state:c.state,event:p,commentsPosted:u.length,url:c.html_url})}case"github_list_commits":{let{owner:t,repo:r,branch:i,path:e,limit:n}=o;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let s=`/repos/${t}/${r}/commits?per_page=${n||20}`;i&&(s+=`&sha=${encodeURIComponent(i)}`),e&&(s+=`&path=${encodeURIComponent(e)}`);let p=await d(s);return JSON.stringify({total:p.length,commits:p.map(u=>({sha:u.sha?.slice(0,8),fullSha:u.sha,message:u.commit?.message?.slice(0,300),author:u.commit?.author?.name,date:u.commit?.author?.date,url:u.html_url}))})}case"github_get_commit":{let{owner:t,repo:r,sha:i}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and sha are required"});let e=await d(`/repos/${t}/${r}/commits/${i}`);return JSON.stringify({sha:e.sha?.slice(0,8),message:e.commit?.message,author:e.commit?.author?.name,date:e.commit?.author?.date,stats:e.stats,files:(e.files||[]).map(n=>({filename:n.filename,status:n.status,additions:n.additions,deletions:n.deletions,patch:n.patch?.slice(0,3e3)}))})}case"github_get_file":{let{owner:t,repo:r,path:i,ref:e}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and path are required"});let n=`/repos/${t}/${r}/contents/${encodeURIComponent(i)}`;e&&(n+=`?ref=${encodeURIComponent(e)}`);let s=await d(n);if(s.type!=="file")return Array.isArray(s)?JSON.stringify({type:"directory",path:i,entries:s.map(m=>({name:m.name,type:m.type,size:m.size,path:m.path}))}):JSON.stringify({error:`Not a file: ${s.type}`});let p=Buffer.from(s.content||"","base64").toString("utf-8"),u=p.length>2e4;return JSON.stringify({path:s.path,size:s.size,sha:s.sha?.slice(0,8),content:u?p.slice(0,2e4):p,truncated:u})}case"github_get_user":try{let t=await d("/installation/repositories?per_page=1");if(t.repositories&&t.repositories.length>0){let r=t.repositories[0],i=r.owner.login,e=r.owner.type,n=e==="Organization"?`/orgs/${i}`:`/users/${i}`,s=await d(n);return JSON.stringify({login:s.login,name:s.name||s.login,avatar:s.avatar_url,bio:s.bio||s.description,type:e,isOrg:e==="Organization",publicRepos:s.public_repos,message:"Showing GitHub App installation owner (GitHub Apps cannot access /user endpoint)"})}return JSON.stringify({error:"No repositories accessible to this GitHub App installation"})}catch(t){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${t.message})`})}case"github_list_orgs":try{let r=(await d("/installation/repositories?per_page=100")).repositories||[],i=new Map;for(let n of r)n.owner.type==="Organization"&&(i.has(n.owner.login)||i.set(n.owner.login,{login:n.owner.login,description:null,url:n.owner.url}));let e=Array.from(i.values());return JSON.stringify({count:e.length,orgs:e,message:"Extracted from accessible repositories (GitHub Apps cannot access /user/orgs directly)"})}catch(t){return JSON.stringify({error:`GitHub App cannot list orgs via /user/orgs. Error: ${t.message}`})}case"github_clone":{let l=function(w){let R=w.replace(/^~(?=$|\/|\\)/,f);return s(R)},{owner:t,repo:r,destination:i}=o;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let{execSync:e}=await import("child_process"),{join:n,resolve:s}=await import("path"),{existsSync:p,mkdirSync:u}=await import("fs"),{homedir:m,platform:c}=await import("os"),{token:g}=await C("github"),f=m(),y=i?l(i):n(f,"zibby-repos"),h=n(y,r);if(u(y,{recursive:!0}),p(h))return JSON.stringify({error:`Directory ${h} already exists. Remove it first or use a different destination.`,existingPath:h});try{let w=`https://x-access-token:${g}@github.com/${t}/${r}.git`;e(`git clone ${w} "${h}"`,{stdio:"pipe"});let R=c()==="win32",b;return R?b=e(`dir "${h}"`,{encoding:"utf-8",shell:"cmd.exe"}):b=e(`ls -la "${h}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:h,message:`Cloned ${t}/${r} to ${h}`,contents:b.split(`
40
40
  `).slice(0,30).join(`
41
- `),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(w){return JSON.stringify({error:`Clone failed: ${w.message}`})}}case"github_search_repos":{let{query:t,limit:r}=o;if(!t)return JSON.stringify({error:"query is required"});let i=await this.handleToolCall("github_list_repos",{limit:200},{}),e=JSON.parse(i);if(e.error)return JSON.stringify(e);let n=t.toLowerCase(),s=e.repos.filter(p=>p.name.toLowerCase().includes(n)||p.fullName.toLowerCase().includes(n)||p.description&&p.description.toLowerCase().includes(n));return JSON.stringify({query:t,count:s.length,repos:s.slice(0,r||20)})}case"github_list_repos":{let{owner:t,type:r,sort:i,direction:e,limit:n}=o,s=100,p=n||200,u=[];if(!t){let l=1,y=!0;for(;y&&u.length<p;){let b=`/installation/repositories?per_page=${s}&page=${l}`,N=(await d(b)).repositories||[];if(N.length===0)break;u=u.concat(N),y=N.length===s,l++}let h=u.slice(0,p).map(b=>({name:b.name,fullName:b.full_name,private:b.private,description:b.description,language:b.language,defaultBranch:b.default_branch,updatedAt:b.updated_at,stars:b.stargazers_count,url:b.html_url})),w=h.filter(b=>b.private).length,R=h.filter(b=>!b.private).length;return JSON.stringify({count:h.length,repos:h,privateCount:w,publicCount:R,message:`Found ${w} private and ${R} public repos`})}let m=await d(`/orgs/${t}`).then(()=>!0).catch(()=>!1),c=1,g=!0;for(;g&&u.length<p;){let l;m?l=`/orgs/${t}/repos?per_page=${s}&page=${c}&type=${r||"all"}&sort=${i||"updated"}&direction=${e||"desc"}`:l=`/users/${t}/repos?per_page=${s}&page=${c}&type=${r||"all"}&sort=${i||"updated"}&direction=${e||"desc"}`;let y=await d(l),h=Array.isArray(y)?y:[];if(h.length===0)break;u=u.concat(h),g=h.length===s,c++}let f=u.slice(0,p).map(l=>({name:l.name,fullName:l.full_name,private:l.private,description:l.description,language:l.language,defaultBranch:l.default_branch,updatedAt:l.updated_at,stars:l.stargazers_count,url:l.html_url}));return JSON.stringify({count:f.length,repos:f})}case"github_create_issue":{let{owner:t,repo:r,title:i,body:e}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and title are required"});let n=await d(`/repos/${t}/${r}/issues`,{method:"POST",body:{title:i,body:e||""}});return JSON.stringify({number:n.number,url:n.html_url,title:n.title})}case"github_list_issues":{let{owner:t,repo:r,state:i,labels:e,since:n,assignee:s,sort:p,direction:u,limit:m}=o||{};if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let c=new URLSearchParams;c.set("state",i||"open"),c.set("per_page",String(m||30)),c.set("sort",p||"updated"),c.set("direction",u||"desc"),e&&c.set("labels",Array.isArray(e)?e.join(","):e),n&&c.set("since",n),s&&c.set("assignee",s);let g=await d(`/repos/${t}/${r}/issues?${c.toString()}`),f=(Array.isArray(g)?g:[]).filter(l=>!l.pull_request).map(l=>({number:l.number,title:l.title,state:l.state,labels:(l.labels||[]).map(y=>typeof y=="string"?y:y.name),assignee:l.assignee?.login||null,assignees:(l.assignees||[]).map(y=>y.login),user:l.user?.login,comments:l.comments,url:l.html_url,createdAt:l.created_at,updatedAt:l.updated_at}));return JSON.stringify({count:f.length,issues:f})}case"github_get_issue":{let{owner:t,repo:r,number:i}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/issues/${i}`);return e.pull_request?JSON.stringify({error:`#${i} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:e.number,title:e.title,body:e.body||"",state:e.state,stateReason:e.state_reason||null,labels:(e.labels||[]).map(n=>typeof n=="string"?n:n.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(n=>n.login),user:e.user?.login,milestone:e.milestone?.title||null,comments:e.comments,url:e.html_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"github_get_issue_comments":{let{owner:t,repo:r,number:i,limit:e}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let n=await d(`/repos/${t}/${r}/issues/${i}/comments?per_page=${e||100}`),s=(Array.isArray(n)?n:[]).map(p=>({id:p.id,user:p.user?.login,body:p.body||"",createdAt:p.created_at,updatedAt:p.updated_at,url:p.html_url}));return JSON.stringify({count:s.length,comments:s})}case"github_add_issue_comment":{let{owner:t,repo:r,number:i,body:e}=o||{};if(!t||!r||!i||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let n=await d(`/repos/${t}/${r}/issues/${i}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:n.id,url:n.html_url})}case"github_close_issue":{let{owner:t,repo:r,number:i,stateReason:e}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let n={state:"closed"};e&&(n.state_reason=e);let s=await d(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:n});return JSON.stringify({ok:!0,number:s.number,state:s.state,stateReason:s.state_reason||null,url:s.html_url})}case"github_reopen_issue":{let{owner:t,repo:r,number:i}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:e.number,state:e.state,url:e.html_url})}case"github_label_issue":{let{owner:t,repo:r,number:i,labels:e,mode:n}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let s=Array.isArray(e)?e:e?[e]:[];if(!s.length)return JSON.stringify({error:"labels (string or array) is required"});let p=n||"add";if(p==="set"){let m=await d(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:{labels:s}});return JSON.stringify({ok:!0,number:m.number,labels:(m.labels||[]).map(c=>typeof c=="string"?c:c.name)})}if(p==="remove"){for(let c of s)await d(`/repos/${t}/${r}/issues/${i}/labels/${encodeURIComponent(c)}`,{method:"DELETE"});let m=await d(`/repos/${t}/${r}/issues/${i}`);return JSON.stringify({ok:!0,number:m.number,labels:(m.labels||[]).map(c=>typeof c=="string"?c:c.name)})}let u=await d(`/repos/${t}/${r}/issues/${i}/labels`,{method:"POST",body:{labels:s}});return JSON.stringify({ok:!0,number:i,labels:(Array.isArray(u)?u:[]).map(m=>typeof m=="string"?m:m.name)})}default:return JSON.stringify({error:`Unknown tool: ${a}`})}}catch(t){return JSON.stringify({error:t.message})}},tools:[{name:"github_get_user",description:"Get the authenticated GitHub user profile and their organizations",input_schema:{type:"object",properties:{}}},{name:"github_list_orgs",description:"List GitHub organizations the authenticated user belongs to",input_schema:{type:"object",properties:{}}},{name:"github_list_repos",description:"List repositories for a user or org. If no owner given, lists the authenticated user's repos.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Org or user login. Omit to list your own repos."},type:{type:"string",enum:["all","public","private","forks","sources","member"],description:"Filter by type (default: all)"},sort:{type:"string",enum:["created","updated","pushed","full_name"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max repos to return (default: 30)"}}}},{name:"github_clone",description:'Clone a GitHub repository to the local filesystem. Use when user says "check out" or "clone" a repo.',input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner (user or org name)"},repo:{type:"string",description:"Repository name"},destination:{type:"string",description:"Destination directory. Accepts absolute paths, ~-prefixed paths, or relative names. Defaults to ~/zibby-repos/<repo>."}},required:["owner","repo"]}},{name:"github_search_repos",description:"Search accessible repositories by name or description. Use this when the user asks to find a specific repo.",input_schema:{type:"object",properties:{query:{type:"string",description:'Search term to match against repo name or description (e.g., "electron", "my-app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_issues",description:"Search GitHub issues and pull requests",input_schema:{type:"object",properties:{query:{type:"string",description:'GitHub search query (e.g. "SCRUM-123", "login bug repo:org/app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_code",description:"Search code across GitHub repositories by keyword",input_schema:{type:"object",properties:{query:{type:"string",description:'Code search query (e.g. "handleLogin", "class AuthService")'},repo:{type:"string",description:'Scope to a specific repo (e.g. "org/app"). Optional.'},language:{type:"string",description:'Filter by language (e.g. "javascript", "python"). Optional.'},limit:{type:"number",description:"Max results (default: 15)"}},required:["query"]}},{name:"github_get_pr",description:"Get details of a pull request \u2014 title, description, branch, stats",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_get_pr_diff",description:"Get the unified diff of a pull request \u2014 the actual code changes",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_files",description:"List files changed in a PR with per-file patches",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_comments",description:"Get all review and issue comments on a PR",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_create_review",description:"Post a review on a pull request: a summary body plus optional inline comments anchored to file/line, with an event (COMMENT, APPROVE, or REQUEST_CHANGES). Use this to deliver a code review back to the PR.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},body:{type:"string",description:"The review summary (markdown). Shown as the top-level review comment."},event:{type:"string",enum:["COMMENT","APPROVE","REQUEST_CHANGES"],description:"Review verdict. Default COMMENT (no approval state). Use REQUEST_CHANGES for blocking issues."},comments:{type:"array",description:"Optional inline comments, each anchored to a changed line.",items:{type:"object",properties:{path:{type:"string",description:"File path as it appears in the diff"},line:{type:"number",description:"Line number in the file's NEW version (the right side of the diff)"},side:{type:"string",enum:["LEFT","RIGHT"],description:"RIGHT (new) or LEFT (old). Default RIGHT."},body:{type:"string",description:"The inline comment text (markdown)"}},required:["path","line","body"]}}},required:["owner","repo","number"]}},{name:"github_list_commits",description:"List recent commits on a branch, optionally filtered by file path",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},branch:{type:"string",description:"Branch name (default: repo default branch)"},path:{type:"string",description:"Filter commits touching this file path"},limit:{type:"number",description:"Max commits (default: 20)"}},required:["owner","repo"]}},{name:"github_get_commit",description:"Get details of a specific commit \u2014 message, stats, file diffs",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},sha:{type:"string",description:"Commit SHA (full or short)"}},required:["owner","repo","sha"]}},{name:"github_get_file",description:"Read a file (or list a directory) from a GitHub repo. Works on any branch/ref.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},path:{type:"string",description:'File or directory path (e.g. "src/auth/login.ts")'},ref:{type:"string",description:"Branch, tag, or commit SHA (default: repo default branch)"}},required:["owner","repo","path"]}},{name:"github_create_issue",description:"Create a GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},title:{type:"string",description:"Issue title"},body:{type:"string",description:"Issue body (markdown)"}},required:["owner","repo","title"]}},{name:"github_list_issues",description:"List issues in a repo (excludes pull requests). Filter by state, labels, and an updated-since cursor for polling.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},state:{type:"string",enum:["open","closed","all"],description:"Filter by state (default: open)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},since:{type:"string",description:"ISO-8601 timestamp; only issues updated at/after this (polling cursor)"},assignee:{type:"string",description:'Filter by assignee login, "none", or "*"'},sort:{type:"string",enum:["created","updated","comments"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30, max 100 per page)"}},required:["owner","repo"]}},{name:"github_get_issue",description:"Get a single GitHub issue with full detail (title, body, state, labels, assignee, url)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_get_issue_comments",description:"Get the comment thread on a GitHub issue (chronological)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},limit:{type:"number",description:"Max comments (default: 100)"}},required:["owner","repo","number"]}},{name:"github_add_issue_comment",description:"Add a comment to a GitHub issue. Also the way to record a PR link on an issue (post a markdown link).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},body:{type:"string",description:"Comment body (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_close_issue",description:"Close a GitHub issue. Optionally set the close reason (completed or not_planned).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},stateReason:{type:"string",enum:["completed","not_planned"],description:"Why the issue was closed (optional)"}},required:["owner","repo","number"]}},{name:"github_reopen_issue",description:"Reopen a closed GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_label_issue",description:"Add, set (replace all), or remove labels on a GitHub issue. Labels back state-like transitions on GitHub.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},labels:{type:"array",items:{type:"string"},description:"Label name(s)"},mode:{type:"string",enum:["add","set","remove"],description:"add appends, set replaces all, remove deletes (default: add)"}},required:["owner","repo","number","labels"]}}]};var T=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i,q=/\b(in[\s-]?progress|wip|doing|started|in[\s-]?review|review)\b/i,J=/\b(done|closed|complete|completed|resolved|fixed|merged|shipped)\b/i,I=/\b(todo|to[\s-]?do|open|backlog|reopen|new)\b/i,E="in progress",G="blocked";function k(a,o=[]){if(a==="closed")return"done";if(a!=="open")return"unknown";let t=(o||[]).map(String);return t.some(r=>T.test(r))?"blocked":t.some(r=>q.test(r))?"in_progress":"todo"}function $(a={}){let o=a.owner||process.env.GITHUB_OWNER,t=a.repo||process.env.GITHUB_REPO;if(!o||!t)throw new Error("GitHub scope missing: provide {owner, repo} via ctx or env GITHUB_OWNER / GITHUB_REPO.");return{owner:o,repo:t}}function S(a){let o=JSON.parse(a);if(o&&o.error)throw new Error(o.error);return o}function A(a,o={}){let t=a.labels||[],r=a.number,i=o.owner&&o.repo?`${o.owner}/${o.repo}#${r}`:`#${r}`;return{id:String(r),key:i,title:a.title||"",body:a.body||"",state:a.state||null,stateCategory:k(a.state,t),assignee:a.assignee||a.assignees&&a.assignees[0]||null,url:a.url||null,_raw:a}}var H={id:"github",toStateCategory:k,toNeutral:A,IN_PROGRESS_LABEL:E,BLOCKED_LABEL:G,async listCandidates(a={}){let o=a.ctx||{},{owner:t,repo:r}=$(o);return(S(await _.handleToolCall("github_list_issues",{owner:t,repo:r,state:a.state||"open",labels:a.labels,since:a.updatedAfter,limit:a.limit})).issues||[]).map(e=>A(e,{owner:t,repo:r}))},async getTicket(a,o={}){let{owner:t,repo:r}=$(o),i=O(a);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);let e=JSON.parse(await _.handleToolCall("github_get_issue",{owner:t,repo:r,number:i}));return e.error?null:A(e,{owner:t,repo:r})},async getComments(a,o={}){let{owner:t,repo:r}=$(o),i=O(a);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);return(S(await _.handleToolCall("github_get_issue_comments",{owner:t,repo:r,number:i})).comments||[]).map(n=>({id:String(n.id),author:n.user||"Unknown",body:n.body||"",createdAt:n.createdAt||null,updatedAt:n.updatedAt||null,_raw:n})).sort((n,s)=>String(s.createdAt).localeCompare(String(n.createdAt)))},async addComment(a,o,t={}){let{owner:r,repo:i}=$(t),e=O(a);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);if(!o)throw new Error("body is required");let n=S(await _.handleToolCall("github_add_issue_comment",{owner:r,repo:i,number:e,body:o}));return{ok:!!n.ok,id:n.id?String(n.id):null}},async transition(a,o,t={}){let{owner:r,repo:i}=$(t),e=O(a);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);let n=String(o||"");if(J.test(n)){let s=S(await _.handleToolCall("github_close_issue",{owner:r,repo:i,number:e,stateReason:"completed"}));return{ok:!!s.ok,stateAfter:s.state||"closed",stateCategoryAfter:"done",_raw:s}}if(T.test(n)){await P(r,i,e);let s=S(await _.handleToolCall("github_label_issue",{owner:r,repo:i,number:e,labels:[G],mode:"add"}));return{ok:!!s.ok,stateAfter:"open",stateCategoryAfter:"blocked",via:"label",_raw:s}}if(q.test(n)){await P(r,i,e);let s=S(await _.handleToolCall("github_label_issue",{owner:r,repo:i,number:e,labels:[E],mode:"add"}));return{ok:!!s.ok,stateAfter:"open",stateCategoryAfter:"in_progress",via:"label",_raw:s}}if(I.test(n)){let s=S(await _.handleToolCall("github_reopen_issue",{owner:r,repo:i,number:e}));return{ok:!!s.ok,stateAfter:s.state||"open",stateCategoryAfter:"todo",_raw:s}}return{ok:!1,error:`GitHub issues have no "${o}" state. Representable targets: open/todo, in progress, blocked, done/closed.`}},async linkPullRequest(a,o,t,r={}){let{owner:i,repo:e}=$(r),n=O(a);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);if(!o)throw new Error("prUrl is required");let s=`${t?`${t}: `:"Linked PR: "}${o}`;return{ok:!!S(await _.handleToolCall("github_add_issue_comment",{owner:i,repo:e,number:n,body:s})).ok,via:"comment"}}};async function P(a,o,t){await _.handleToolCall("github_reopen_issue",{owner:a,repo:o,number:t})}function O(a){if(a==null)return null;if(typeof a=="number")return a;let o=/(\d+)\s*$/.exec(String(a));return o?Number(o[1]):null}var z=H;export{z as default,H as githubAdapter};
41
+ `),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(w){return JSON.stringify({error:`Clone failed: ${w.message}`})}}case"github_search_repos":{let{query:t,limit:r}=o;if(!t)return JSON.stringify({error:"query is required"});let i=await this.handleToolCall("github_list_repos",{limit:200},{}),e=JSON.parse(i);if(e.error)return JSON.stringify(e);let n=t.toLowerCase(),s=e.repos.filter(p=>p.name.toLowerCase().includes(n)||p.fullName.toLowerCase().includes(n)||p.description&&p.description.toLowerCase().includes(n));return JSON.stringify({query:t,count:s.length,repos:s.slice(0,r||20)})}case"github_list_repos":{let{owner:t,type:r,sort:i,direction:e,limit:n}=o,s=100,p=n||200,u=[];if(!t){let l=1,y=!0;for(;y&&u.length<p;){let b=`/installation/repositories?per_page=${s}&page=${l}`,N=(await d(b)).repositories||[];if(N.length===0)break;u=u.concat(N),y=N.length===s,l++}let h=u.slice(0,p).map(b=>({name:b.name,fullName:b.full_name,private:b.private,description:b.description,language:b.language,defaultBranch:b.default_branch,updatedAt:b.updated_at,stars:b.stargazers_count,url:b.html_url})),w=h.filter(b=>b.private).length,R=h.filter(b=>!b.private).length;return JSON.stringify({count:h.length,repos:h,privateCount:w,publicCount:R,message:`Found ${w} private and ${R} public repos`})}let m=await d(`/orgs/${t}`).then(()=>!0).catch(()=>!1),c=1,g=!0;for(;g&&u.length<p;){let l;m?l=`/orgs/${t}/repos?per_page=${s}&page=${c}&type=${r||"all"}&sort=${i||"updated"}&direction=${e||"desc"}`:l=`/users/${t}/repos?per_page=${s}&page=${c}&type=${r||"all"}&sort=${i||"updated"}&direction=${e||"desc"}`;let y=await d(l),h=Array.isArray(y)?y:[];if(h.length===0)break;u=u.concat(h),g=h.length===s,c++}let f=u.slice(0,p).map(l=>({name:l.name,fullName:l.full_name,private:l.private,description:l.description,language:l.language,defaultBranch:l.default_branch,updatedAt:l.updated_at,stars:l.stargazers_count,url:l.html_url}));return JSON.stringify({count:f.length,repos:f})}case"github_create_issue":{let{owner:t,repo:r,title:i,body:e}=o;if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and title are required"});let n=await d(`/repos/${t}/${r}/issues`,{method:"POST",body:{title:i,body:e||""}});return JSON.stringify({number:n.number,url:n.html_url,title:n.title})}case"github_list_issues":{let{owner:t,repo:r,state:i,labels:e,since:n,assignee:s,sort:p,direction:u,limit:m}=o||{};if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let c=new URLSearchParams;c.set("state",i||"open"),c.set("per_page",String(m||30)),c.set("sort",p||"updated"),c.set("direction",u||"desc"),e&&c.set("labels",Array.isArray(e)?e.join(","):e),n&&c.set("since",n),s&&c.set("assignee",s);let g=await d(`/repos/${t}/${r}/issues?${c.toString()}`),f=(Array.isArray(g)?g:[]).filter(l=>!l.pull_request).map(l=>({number:l.number,title:l.title,state:l.state,labels:(l.labels||[]).map(y=>typeof y=="string"?y:y.name),assignee:l.assignee?.login||null,assignees:(l.assignees||[]).map(y=>y.login),user:l.user?.login,comments:l.comments,url:l.html_url,createdAt:l.created_at,updatedAt:l.updated_at}));return JSON.stringify({count:f.length,issues:f})}case"github_get_issue":{let{owner:t,repo:r,number:i}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/issues/${i}`);return e.pull_request?JSON.stringify({error:`#${i} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:e.number,title:e.title,body:e.body||"",state:e.state,stateReason:e.state_reason||null,labels:(e.labels||[]).map(n=>typeof n=="string"?n:n.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(n=>n.login),user:e.user?.login,milestone:e.milestone?.title||null,comments:e.comments,url:e.html_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"github_get_issue_comments":{let{owner:t,repo:r,number:i,limit:e}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let n=await d(`/repos/${t}/${r}/issues/${i}/comments?per_page=${e||100}`),s=(Array.isArray(n)?n:[]).map(p=>({id:p.id,user:p.user?.login,body:p.body||"",createdAt:p.created_at,updatedAt:p.updated_at,url:p.html_url}));return JSON.stringify({count:s.length,comments:s})}case"github_add_issue_comment":{let{owner:t,repo:r,number:i,body:e}=o||{};if(!t||!r||!i||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let n=await d(`/repos/${t}/${r}/issues/${i}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:n.id,url:n.html_url})}case"github_close_issue":{let{owner:t,repo:r,number:i,stateReason:e}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let n={state:"closed"};e&&(n.state_reason=e);let s=await d(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:n});return JSON.stringify({ok:!0,number:s.number,state:s.state,stateReason:s.state_reason||null,url:s.html_url})}case"github_reopen_issue":{let{owner:t,repo:r,number:i}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let e=await d(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:e.number,state:e.state,url:e.html_url})}case"github_label_issue":{let{owner:t,repo:r,number:i,labels:e,mode:n}=o||{};if(!t||!r||!i)return JSON.stringify({error:"owner, repo, and number are required"});let s=Array.isArray(e)?e:e?[e]:[];if(!s.length)return JSON.stringify({error:"labels (string or array) is required"});let p=n||"add";if(p==="set"){let m=await d(`/repos/${t}/${r}/issues/${i}`,{method:"PATCH",body:{labels:s}});return JSON.stringify({ok:!0,number:m.number,labels:(m.labels||[]).map(c=>typeof c=="string"?c:c.name)})}if(p==="remove"){for(let c of s)await d(`/repos/${t}/${r}/issues/${i}/labels/${encodeURIComponent(c)}`,{method:"DELETE"});let m=await d(`/repos/${t}/${r}/issues/${i}`);return JSON.stringify({ok:!0,number:m.number,labels:(m.labels||[]).map(c=>typeof c=="string"?c:c.name)})}let u=await d(`/repos/${t}/${r}/issues/${i}/labels`,{method:"POST",body:{labels:s}});return JSON.stringify({ok:!0,number:i,labels:(Array.isArray(u)?u:[]).map(m=>typeof m=="string"?m:m.name)})}default:return JSON.stringify({error:`Unknown tool: ${a}`})}}catch(t){return JSON.stringify({error:t.message})}},tools:[{name:"github_get_user",description:"Get the authenticated GitHub user profile and their organizations",input_schema:{type:"object",properties:{}}},{name:"github_list_orgs",description:"List GitHub organizations the authenticated user belongs to",input_schema:{type:"object",properties:{}}},{name:"github_list_repos",description:"List repositories for a user or org. If no owner given, lists the authenticated user's repos.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Org or user login. Omit to list your own repos."},type:{type:"string",enum:["all","public","private","forks","sources","member"],description:"Filter by type (default: all)"},sort:{type:"string",enum:["created","updated","pushed","full_name"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max repos to return (default: 30)"}}}},{name:"github_clone",description:'Clone a GitHub repository to the local filesystem. Use when user says "check out" or "clone" a repo.',input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner (user or org name)"},repo:{type:"string",description:"Repository name"},destination:{type:"string",description:"Destination directory. Accepts absolute paths, ~-prefixed paths, or relative names. Defaults to ~/zibby-repos/<repo>."}},required:["owner","repo"]}},{name:"github_search_repos",description:"Search accessible repositories by name or description. Use this when the user asks to find a specific repo.",input_schema:{type:"object",properties:{query:{type:"string",description:'Search term to match against repo name or description (e.g., "electron", "my-app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_issues",description:"Search GitHub issues and pull requests",input_schema:{type:"object",properties:{query:{type:"string",description:'GitHub search query (e.g. "SCRUM-123", "login bug repo:org/app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_code",description:"Search code across GitHub repositories by keyword",input_schema:{type:"object",properties:{query:{type:"string",description:'Code search query (e.g. "handleLogin", "class AuthService")'},repo:{type:"string",description:'Scope to a specific repo (e.g. "org/app"). Optional.'},language:{type:"string",description:'Filter by language (e.g. "javascript", "python"). Optional.'},limit:{type:"number",description:"Max results (default: 15)"}},required:["query"]}},{name:"github_get_pr",description:"Get details of a pull request \u2014 title, description, branch, stats",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_get_pr_diff",description:"Get the unified diff of a pull request \u2014 the actual code changes",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_files",description:"List files changed in a PR with per-file patches",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_comments",description:"Get all review and issue comments on a PR",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_create_review",description:"Post a review on a pull request: a summary body plus optional inline comments anchored to file/line, with an event (COMMENT, APPROVE, or REQUEST_CHANGES). Use this to deliver a code review back to the PR.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},body:{type:"string",description:"The review summary (markdown). Shown as the top-level review comment."},event:{type:"string",enum:["COMMENT","APPROVE","REQUEST_CHANGES"],description:"Review verdict. Default COMMENT (no approval state). Use REQUEST_CHANGES for blocking issues."},comments:{type:"array",description:"Optional inline comments, each anchored to a changed line.",items:{type:"object",properties:{path:{type:"string",description:"File path as it appears in the diff"},line:{type:"number",description:"Line number in the file's NEW version (the right side of the diff)"},side:{type:"string",enum:["LEFT","RIGHT"],description:"RIGHT (new) or LEFT (old). Default RIGHT."},body:{type:"string",description:"The inline comment text (markdown)"}},required:["path","line","body"]}}},required:["owner","repo","number"]}},{name:"github_list_commits",description:"List recent commits on a branch, optionally filtered by file path",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},branch:{type:"string",description:"Branch name (default: repo default branch)"},path:{type:"string",description:"Filter commits touching this file path"},limit:{type:"number",description:"Max commits (default: 20)"}},required:["owner","repo"]}},{name:"github_get_commit",description:"Get details of a specific commit \u2014 message, stats, file diffs",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},sha:{type:"string",description:"Commit SHA (full or short)"}},required:["owner","repo","sha"]}},{name:"github_get_file",description:"Read a file (or list a directory) from a GitHub repo. Works on any branch/ref.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},path:{type:"string",description:'File or directory path (e.g. "src/auth/login.ts")'},ref:{type:"string",description:"Branch, tag, or commit SHA (default: repo default branch)"}},required:["owner","repo","path"]}},{name:"github_create_issue",description:"Create a GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},title:{type:"string",description:"Issue title"},body:{type:"string",description:"Issue body (markdown)"}},required:["owner","repo","title"]}},{name:"github_list_issues",description:"List issues in a repo (excludes pull requests). Filter by state, labels, and an updated-since cursor for polling.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},state:{type:"string",enum:["open","closed","all"],description:"Filter by state (default: open)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},since:{type:"string",description:"ISO-8601 timestamp; only issues updated at/after this (polling cursor)"},assignee:{type:"string",description:'Filter by assignee login, "none", or "*"'},sort:{type:"string",enum:["created","updated","comments"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30, max 100 per page)"}},required:["owner","repo"]}},{name:"github_get_issue",description:"Get a single GitHub issue with full detail (title, body, state, labels, assignee, url)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_get_issue_comments",description:"Get the comment thread on a GitHub issue (chronological)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},limit:{type:"number",description:"Max comments (default: 100)"}},required:["owner","repo","number"]}},{name:"github_add_issue_comment",description:"Add a comment to a GitHub issue. Also the way to record a PR link on an issue (post a markdown link).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},body:{type:"string",description:"Comment body (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_close_issue",description:"Close a GitHub issue. Optionally set the close reason (completed or not_planned).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},stateReason:{type:"string",enum:["completed","not_planned"],description:"Why the issue was closed (optional)"}},required:["owner","repo","number"]}},{name:"github_reopen_issue",description:"Reopen a closed GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_label_issue",description:"Add, set (replace all), or remove labels on a GitHub issue. Labels back state-like transitions on GitHub.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},labels:{type:"array",items:{type:"string"},description:"Label name(s)"},mode:{type:"string",enum:["add","set","remove"],description:"add appends, set replaces all, remove deletes (default: add)"}},required:["owner","repo","number","labels"]}}]};var G=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i,q=/\b(in[\s-]?progress|wip|doing|started|in[\s-]?review|review)\b/i,U=/\b(done|closed|complete|completed|resolved|fixed|merged|shipped)\b/i,M=/\b(todo|to[\s-]?do|open|backlog|reopen|new)\b/i,E="in progress",P="blocked";function k(a,o=[]){if(a==="closed")return"done";if(a!=="open")return"unknown";let t=(o||[]).map(String);return t.some(r=>G.test(r))?"blocked":t.some(r=>q.test(r))?"in_progress":"todo"}function $(a={}){let o=a.owner||process.env.GITHUB_OWNER,t=a.repo||process.env.GITHUB_REPO;if(!o||!t)throw new Error("GitHub scope missing: provide {owner, repo} via ctx or env GITHUB_OWNER / GITHUB_REPO.");return{owner:o,repo:t}}function S(a){let o=JSON.parse(a);if(o&&o.error)throw new Error(o.error);return o}function A(a,o={}){let t=a.labels||[],r=a.number,i=o.owner&&o.repo?`${o.owner}/${o.repo}#${r}`:`#${r}`;return{id:String(r),key:i,title:a.title||"",body:a.body||"",state:a.state||null,stateCategory:k(a.state,t),assignee:a.assignee||a.assignees&&a.assignees[0]||null,url:a.url||null,_raw:a}}var x={id:"github",toStateCategory:k,toNeutral:A,IN_PROGRESS_LABEL:E,BLOCKED_LABEL:P,async listCandidates(a={}){let o=a.ctx||{},{owner:t,repo:r}=$(o);return(S(await _.handleToolCall("github_list_issues",{owner:t,repo:r,state:a.state||"open",labels:a.labels,since:a.updatedAfter,limit:a.limit})).issues||[]).map(e=>A(e,{owner:t,repo:r}))},async getTicket(a,o={}){let{owner:t,repo:r}=$(o),i=O(a);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);let e=JSON.parse(await _.handleToolCall("github_get_issue",{owner:t,repo:r,number:i}));return e.error?null:A(e,{owner:t,repo:r})},async getComments(a,o={}){let{owner:t,repo:r}=$(o),i=O(a);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);return(S(await _.handleToolCall("github_get_issue_comments",{owner:t,repo:r,number:i})).comments||[]).map(n=>({id:String(n.id),author:n.user||"Unknown",body:n.body||"",createdAt:n.createdAt||null,updatedAt:n.updatedAt||null,_raw:n})).sort((n,s)=>String(s.createdAt).localeCompare(String(n.createdAt)))},async addComment(a,o,t={}){let{owner:r,repo:i}=$(t),e=O(a);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);if(!o)throw new Error("body is required");let n=S(await _.handleToolCall("github_add_issue_comment",{owner:r,repo:i,number:e,body:o}));return{ok:!!n.ok,id:n.id?String(n.id):null}},async transition(a,o,t={}){let{owner:r,repo:i}=$(t),e=O(a);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);let n=String(o||"");if(U.test(n)){let s=S(await _.handleToolCall("github_close_issue",{owner:r,repo:i,number:e,stateReason:"completed"}));return{ok:!!s.ok,stateAfter:s.state||"closed",stateCategoryAfter:"done",_raw:s}}if(G.test(n)){await T(r,i,e);let s=S(await _.handleToolCall("github_label_issue",{owner:r,repo:i,number:e,labels:[P],mode:"add"}));return{ok:!!s.ok,stateAfter:"open",stateCategoryAfter:"blocked",via:"label",_raw:s}}if(q.test(n)){await T(r,i,e);let s=S(await _.handleToolCall("github_label_issue",{owner:r,repo:i,number:e,labels:[E],mode:"add"}));return{ok:!!s.ok,stateAfter:"open",stateCategoryAfter:"in_progress",via:"label",_raw:s}}if(M.test(n)){let s=S(await _.handleToolCall("github_reopen_issue",{owner:r,repo:i,number:e}));return{ok:!!s.ok,stateAfter:s.state||"open",stateCategoryAfter:"todo",_raw:s}}return{ok:!1,error:`GitHub issues have no "${o}" state. Representable targets: open/todo, in progress, blocked, done/closed.`}},async linkPullRequest(a,o,t,r={}){let{owner:i,repo:e}=$(r),n=O(a);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${a}"`);if(!o)throw new Error("prUrl is required");let s=`${t?`${t}: `:"Linked PR: "}${o}`;return{ok:!!S(await _.handleToolCall("github_add_issue_comment",{owner:i,repo:e,number:n,body:s})).ok,via:"comment"}}};async function T(a,o,t){await _.handleToolCall("github_reopen_issue",{owner:a,repo:o,number:t})}function O(a){if(a==null)return null;if(typeof a=="number")return a;let o=/(\d+)\s*$/.exec(String(a));return o?Number(o[1]):null}var X=x;export{X as default,x as githubAdapter};