@zibby/skills 0.1.74 → 0.1.76
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/github.d.ts +1 -0
- package/dist/github.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +179 -158
- package/dist/linkedin.d.ts +36 -0
- package/dist/linkedin.js +5 -2
- package/dist/package.json +1 -1
- package/dist/report.d.ts +10 -10
- package/dist/socialCard.d.ts +89 -0
- package/dist/socialCard.js +19 -0
- package/dist/trackers/github-adapter.js +1 -1
- package/package.json +1 -1
package/dist/linkedin.d.ts
CHANGED
|
@@ -74,6 +74,24 @@ export function linkedinApi(path: any, opts?: {}, provider?: string): Promise<{
|
|
|
74
74
|
headers: Headers;
|
|
75
75
|
body: {};
|
|
76
76
|
}>;
|
|
77
|
+
/**
|
|
78
|
+
* Upload a LOCAL image file to LinkedIn's Images API and return its
|
|
79
|
+
* `urn:li:image:...` URN, ready to attach to a post via
|
|
80
|
+
* requestBody.content.media = { id: <urn>, altText }.
|
|
81
|
+
*
|
|
82
|
+
* Uses the SAME provider/token/gate as the post (resolveProviderToken):
|
|
83
|
+
* 1. initializeUpload — POST /rest/images?action=initializeUpload with
|
|
84
|
+
* { initializeUploadRequest: { owner: <author urn> } } (through linkedinApi,
|
|
85
|
+
* so it carries the versioned-API headers + the personal-tier gate). Reads
|
|
86
|
+
* value.uploadUrl + value.image from the response.
|
|
87
|
+
* 2. single-request upload — PUT the raw file bytes to uploadUrl with
|
|
88
|
+
* Authorization: Bearer <same provider token> + the image Content-Type.
|
|
89
|
+
* 3. return value.image (the image URN).
|
|
90
|
+
*
|
|
91
|
+
* Throws on any non-2xx / missing field — handleToolCall catches it and returns
|
|
92
|
+
* { ok:false, error } so a bad image can't crash the run or cause a post.
|
|
93
|
+
*/
|
|
94
|
+
export function uploadImage(provider: any, ownerUrn: any, imagePath: any, mimeType: any): Promise<any>;
|
|
77
95
|
export const PERSONAL_REFUSAL: "You haven't connected your own LinkedIn account \u2014 connect it at https://studio.zibby.dev/integrations (LinkedIn). For privacy, I can't post or act as anyone else's LinkedIn (including the project owner's) on your behalf.";
|
|
78
96
|
export namespace linkedinSkill {
|
|
79
97
|
let id: string;
|
|
@@ -108,6 +126,8 @@ export namespace linkedinSkill {
|
|
|
108
126
|
organizationUrn?: undefined;
|
|
109
127
|
text?: undefined;
|
|
110
128
|
visibility?: undefined;
|
|
129
|
+
imagePath?: undefined;
|
|
130
|
+
imageAltText?: undefined;
|
|
111
131
|
dry_run?: undefined;
|
|
112
132
|
};
|
|
113
133
|
required?: undefined;
|
|
@@ -135,6 +155,14 @@ export namespace linkedinSkill {
|
|
|
135
155
|
enum: string[];
|
|
136
156
|
description: string;
|
|
137
157
|
};
|
|
158
|
+
imagePath: {
|
|
159
|
+
type: string;
|
|
160
|
+
description: string;
|
|
161
|
+
};
|
|
162
|
+
imageAltText: {
|
|
163
|
+
type: string;
|
|
164
|
+
description: string;
|
|
165
|
+
};
|
|
138
166
|
dry_run: {
|
|
139
167
|
type: string;
|
|
140
168
|
description: string;
|
|
@@ -157,6 +185,14 @@ export namespace linkedinSkill {
|
|
|
157
185
|
enum: string[];
|
|
158
186
|
description: string;
|
|
159
187
|
};
|
|
188
|
+
imagePath: {
|
|
189
|
+
type: string;
|
|
190
|
+
description: string;
|
|
191
|
+
};
|
|
192
|
+
imageAltText: {
|
|
193
|
+
type: string;
|
|
194
|
+
description: string;
|
|
195
|
+
};
|
|
160
196
|
dry_run: {
|
|
161
197
|
type: string;
|
|
162
198
|
description: string;
|
package/dist/linkedin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{existsSync as
|
|
1
|
+
import{existsSync as L,readFileSync as w}from"fs";import{fileURLToPath as A}from"url";import{dirname as T,resolve as P}from"path";import{resolveIntegrationToken as y,clearTokenCache as N}from"@zibby/core/backend-client.js";function S(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let t=T(A(import.meta.url)),e=P(t,"..","bin","mcp-skill.mjs");return L(e)?e:null}function E(){let t=String(process.env.ZIBBY_INJECTED_LINKEDIN_TOKEN||"").trim();if(!t)return null;let e=String(process.env.ZIBBY_INJECTED_LINKEDIN_MEMBER_ID||"").trim();return{token:t,memberId:e}}function v(){return String(process.env.ZIBBY_CHAT_STRICT_PERSONAL||"").trim()==="1"}function O(){return String(process.env.ZIBBY_SENDER_IS_NON_OWNER||"").trim()==="1"}var R="You haven't connected your own LinkedIn account \u2014 connect it at https://studio.zibby.dev/integrations (LinkedIn). For privacy, I can't post or act as anyone else's LinkedIn (including the project owner's) on your behalf.";function f(){let t=E();if(t)return t;if(v()||O())throw new Error(R);return null}var x="202506",D="https://api.linkedin.com";function b(t){if(t==null)return null;let e=String(t).trim();if(!e)return null;let n=e.match(/urn:li:organization:(\d+)/i);return n?n[1]:/^\d+$/.test(e)?e:null}function _(t){if(!t)return"";if(t.localizedName)return String(t.localizedName);let e=t.name&&t.name.localized;if(e&&typeof e=="object"){let n=Object.values(e)[0];if(n)return String(n)}return""}function h(t,e){return t?typeof t.get=="function"?t.get(e):t[e]||t[e.toLowerCase()]||null:null}async function p(t,e={},n="linkedin_business"){let l=async()=>{let i;if(n==="linkedin_personal"){let s=f();s&&(i=s.token)}if(i||({token:i}=await y(n)),typeof i!="string"||!i)throw new Error("LinkedIn is not connected: no access token available. Connect LinkedIn in Integrations.");let a=t.startsWith("https://")?t:`${D}${t}`,o=await fetch(a,{method:e.method||"GET",headers:{Authorization:`Bearer ${i}`,"LinkedIn-Version":x,"X-Restli-Protocol-Version":"2.0.0",Accept:"application/json",...e.body?{"Content-Type":"application/json"}:{},...e.headers},body:e.body?JSON.stringify(e.body):void 0});if(!o.ok){let s=await o.text().catch(()=>"");throw new Error(`LinkedIn API ${o.status}: ${s.slice(0,300)}`)}let r=await o.text().catch(()=>""),u={};if(r&&r.trim())try{u=JSON.parse(r)}catch{u={raw:r}}return{status:o.status,headers:o.headers,body:u}};try{return await l()}catch(i){let a=String(i?.message||i||"").toLowerCase();if(!(a.includes("token")||a.includes("401")||a.includes("unauthorized")))throw i;return N(n),l()}}async function U(t){let e;if(t==="linkedin_personal"){let n=f();n&&(e=n.token)}if(e||({token:e}=await y(t)),typeof e!="string"||!e)throw new Error("LinkedIn is not connected: no access token available. Connect LinkedIn in Integrations.");return e}function B(t){switch(String(t||"").toLowerCase().match(/\.([a-z0-9]+)$/)?.[1]){case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"webp":return"image/webp";default:return"image/png"}}async function k(t,e,n,l){if(typeof n!="string"||!n.trim())throw new Error("imagePath (a local image file path) is required to upload an image");let{body:i}=await p("/rest/images?action=initializeUpload",{method:"POST",body:{initializeUploadRequest:{owner:e}}},t),a=i?.value?.uploadUrl,o=i?.value?.image;if(!a||!o)throw new Error(`LinkedIn image initializeUpload returned no uploadUrl/image (got: ${JSON.stringify(i).slice(0,200)})`);let r=w(n),u=await U(t),s=await fetch(a,{method:"PUT",headers:{Authorization:`Bearer ${u}`,"Content-Type":l||B(n)},body:r});if(!s.ok){let c=await s.text().catch(()=>"");throw new Error(`LinkedIn image upload ${s.status}: ${c.slice(0,300)}`)}return o}var j={id:"linkedin",serverName:"linkedin",allowedTools:["mcp__linkedin__*"],envKeys:[],description:"LinkedIn \u2014 (business) list admin Organizations + create DRAFT posts on a company Page, and (personal) PUBLISH a post to your own member profile feed",promptFragment:`## LinkedIn (connected)
|
|
2
2
|
You can post to LinkedIn two ways \u2014 an ORG company Page (business) and your own member PROFILE (personal). Each path needs its own LinkedIn integration connected.
|
|
3
3
|
|
|
4
4
|
Business (company Page) \u2014 DRAFT only:
|
|
@@ -8,7 +8,10 @@ Business (company Page) \u2014 DRAFT only:
|
|
|
8
8
|
Personal (your own profile) \u2014 PUBLISHES IMMEDIATELY:
|
|
9
9
|
- linkedin_publish_post: PUBLISH a post to your OWN member profile feed. Pass text (the post body) + optional visibility ('PUBLIC' default, or 'CONNECTIONS'). UNLIKE the org draft tool, this PUBLISHES the post immediately \u2014 LinkedIn has no DRAFT state for member profiles, so there is no human review step. Returns { postUrn }. Set dry_run:true to VALIDATE which member profile the post would publish to (and preview the text) WITHOUT publishing \u2014 nothing is posted; returns { dryRun, target, wouldPostAs, textPreview }. Use this to confirm the identity before an approved publish. (needs LinkedIn Personal connected)
|
|
10
10
|
|
|
11
|
+
Attaching an image (optional, both tools):
|
|
12
|
+
- Both linkedin_create_draft_post and linkedin_publish_post accept imagePath (a LOCAL image file path, e.g. a PNG returned by social_card_render) + optional imageAltText. When imagePath is set, the image is uploaded to LinkedIn's Images API (same connected account/token as the post) and attached to the post as its media. On a dry_run nothing is uploaded \u2014 the result just reports imageWouldAttach:true.
|
|
13
|
+
|
|
11
14
|
Notes:
|
|
12
15
|
- Org-page posts are ALWAYS created as a DRAFT; personal-profile posts are ALWAYS published live \u2014 choose the tool accordingly.
|
|
13
16
|
- PUBLISHING IS OUTWARD-FACING AND IRREVERSIBLE. linkedin_publish_post posts live to a real audience the instant you call it \u2014 there is no undo and no draft state for member profiles. Only call it after the human has EXPLICITLY approved publishing THIS specific text in THIS conversation. If you wrote or edited the text, show it and get an explicit "yes, publish" first; if you are unsure, HOLD/draft rather than publish. The org draft tool (linkedin_create_draft_post) is the safe default when a human still needs to review.
|
|
14
|
-
- If the relevant LinkedIn integration is not connected these tools return { ok:false, error }; treat that as "LinkedIn unavailable" and continue.`,resolve(){let t=
|
|
17
|
+
- If the relevant LinkedIn integration is not connected these tools return { ok:false, error }; treat that as "LinkedIn unavailable" and continue.`,resolve(){let t=S();if(!t)return{command:null,args:[],env:{},description:this.description};let e={};for(let n of["ZIBBY_INJECTED_LINKEDIN_TOKEN","ZIBBY_INJECTED_LINKEDIN_MEMBER_ID","ZIBBY_SENDER_IS_NON_OWNER","ZIBBY_CHAT_STRICT_PERSONAL"])process.env[n]&&(e[n]=process.env[n]);return{type:"stdio",command:"node",args:[t,"../dist/linkedin.js","linkedinSkill"],env:e,description:this.description,alwaysLoad:!0}},async handleToolCall(t,e){try{switch(t){case"linkedin_list_organizations":{let{body:n}=await p("/rest/organizationAcls?q=roleAssignee&role=ADMINISTRATOR&state=APPROVED",{},"linkedin_business"),l=Array.isArray(n.elements)?n.elements:[],i=[];for(let a of l){let o=a.organizationalTarget||a["organizationalTarget~"]||a.organization,r=b(o);if(!r)continue;let u="",s="";try{let c=(await p(`/rest/organizations/${r}`,{},"linkedin_business")).body;u=_(c),s=c.vanityName||""}catch{}i.push({id:r,urn:`urn:li:organization:${r}`,name:u,vanityName:s})}return JSON.stringify({ok:!0,count:i.length,organizations:i})}case"linkedin_create_draft_post":{let n=e?.organizationUrn||e?.organizationId||e?.organization||e?.orgId,l=b(n);if(!l)return JSON.stringify({ok:!1,error:"A valid organizationId or organizationUrn (urn:li:organization:{id}) is required"});let i=e?.text;if(typeof i!="string"||!i.trim())return JSON.stringify({ok:!1,error:"text (the post commentary) is required"});let a=e?.visibility?String(e.visibility).toUpperCase():"PUBLIC",o=`urn:li:organization:${l}`,r=typeof e?.imagePath=="string"?e.imagePath.trim():"",u=typeof e?.imageAltText=="string"?e.imageAltText:"";if(e?.dry_run===!0)try{let d="";try{let g=(await p(`/rest/organizations/${l}`,{},"linkedin_business")).body;d=_(g)}catch{}return JSON.stringify({dryRun:!0,target:"organization",wouldPostAs:{name:d,id:l,urn:o},visibility:a,textPreview:i,...r?{imageWouldAttach:!0,imagePath:r}:{},note:"DRY RUN \u2014 nothing was posted"})}catch(d){return JSON.stringify({dryRun:!0,ok:!1,error:d.message})}let s={author:o,commentary:i,visibility:a,distribution:{feedDistribution:"MAIN_FEED",targetEntities:[],thirdPartyDistributionChannels:[]},lifecycleState:"DRAFT",isReshareDisabledByAuthor:!1};if(r){let d=await k("linkedin_business",o,r);s.content={media:{id:d,altText:u||""}}}let c=await p("/rest/posts",{method:"POST",body:s},"linkedin_business"),m=h(c.headers,"x-restli-id")||h(c.headers,"x-linkedin-id")||c.body?.id||null;return JSON.stringify({ok:!0,postUrn:m,author:o,lifecycleState:"DRAFT",visibility:a,status:c.status})}case"linkedin_publish_post":{let n=f(),l=n?n.memberId:(await y("linkedin_personal")).memberId;if(!l)return JSON.stringify({ok:!1,error:"LinkedIn (personal) not connected or member id unavailable \u2014 reconnect LinkedIn Personal"});let i=e?.text;if(typeof i!="string"||!i.trim())return JSON.stringify({ok:!1,error:"text (the post body) is required"});let a=e?.visibility?String(e.visibility).toUpperCase():"PUBLIC",o=`urn:li:person:${l}`,r=typeof e?.imagePath=="string"?e.imagePath.trim():"",u=typeof e?.imageAltText=="string"?e.imageAltText:"";if(e?.dry_run===!0)try{let d=(await p("/v2/userinfo",{},"linkedin_personal")).body,g=d?.name||[d?.given_name,d?.family_name].filter(Boolean).join(" ")||"",I=d?.sub?String(d.sub):l;return JSON.stringify({dryRun:!0,target:"member",wouldPostAs:{name:g,id:I,urn:`urn:li:person:${I}`},visibility:a,textPreview:i,...r?{imageWouldAttach:!0,imagePath:r}:{},note:"DRY RUN \u2014 nothing was posted"})}catch(d){return JSON.stringify({dryRun:!0,ok:!1,error:d.message})}let s={author:o,commentary:i,visibility:a,distribution:{feedDistribution:"MAIN_FEED",targetEntities:[],thirdPartyDistributionChannels:[]},lifecycleState:"PUBLISHED",isReshareDisabledByAuthor:!1};if(r){let d=await k("linkedin_personal",o,r);s.content={media:{id:d,altText:u||""}}}let c=await p("/rest/posts",{method:"POST",body:s},"linkedin_personal"),m=h(c.headers,"x-restli-id")||h(c.headers,"x-linkedin-id")||c.body?.id||null;return JSON.stringify({ok:!0,postUrn:m,author:o,lifecycleState:"PUBLISHED",visibility:a,status:c.status})}default:return JSON.stringify({ok:!1,error:`Unknown tool: ${t}`})}}catch(n){return JSON.stringify({ok:!1,error:n.message})}},tools:[{name:"linkedin_list_organizations",description:"List the LinkedIn Organizations (company Pages) the authenticated member ADMINISTERS. Returns [{ id, urn, name, vanityName }]. Call this first to choose the author org for a draft post.",input_schema:{type:"object",properties:{}}},{name:"linkedin_create_draft_post",description:"Create a DRAFT post on a LinkedIn Organization (company Page). The post is created in DRAFT state (never published automatically) so a human can review and publish it in LinkedIn. Returns the created post URN. Optionally ATTACH an image: pass imagePath (a local PNG file path, e.g. one returned by social_card_render) and it is uploaded to LinkedIn and attached to the post. Set dry_run:true to VALIDATE which LinkedIn account/profile the post would go to (and preview the text) WITHOUT posting \u2014 nothing is published or uploaded (a set imagePath is reported as imageWouldAttach:true).",input_schema:{type:"object",properties:{organizationId:{type:"string",description:'The numeric organization id (e.g. "12345"). Alternative to organizationUrn.'},organizationUrn:{type:"string",description:'The organization URN, e.g. "urn:li:organization:12345". Alternative to organizationId.'},text:{type:"string",description:"The post commentary (the body text of the post)."},visibility:{type:"string",enum:["PUBLIC"],description:"Post visibility. Defaults to PUBLIC."},imagePath:{type:"string",description:"Optional. A LOCAL image file path (e.g. a PNG returned by social_card_render). When set, the image is uploaded to LinkedIn and attached to the post as its media. Not uploaded on a dry_run."},imageAltText:{type:"string",description:"Optional alt text for the attached image (accessibility). Only used when imagePath is set."},dry_run:{type:"boolean",description:"Set dry_run:true to VALIDATE which LinkedIn account/profile the post would go to (and preview the text) WITHOUT posting \u2014 nothing is published or uploaded. Returns { dryRun, target, wouldPostAs, visibility, textPreview, imageWouldAttach? }. Defaults to false."}},required:["text"]}},{name:"linkedin_publish_post",description:"PUBLISH a post to the authenticated member's OWN LinkedIn profile feed (personal). UNLIKE linkedin_create_draft_post (which only drafts on a company Page), this PUBLISHES the post IMMEDIATELY \u2014 LinkedIn has no DRAFT state for member profiles, so there is no human review step. Returns the created post URN. Requires the LinkedIn Personal integration connected. Optionally ATTACH an image: pass imagePath (a local PNG file path, e.g. one returned by social_card_render) and it is uploaded to LinkedIn and attached to the post. Set dry_run:true to VALIDATE which LinkedIn account/profile the post would go to (and preview the text) WITHOUT posting \u2014 nothing is published or uploaded (a set imagePath is reported as imageWouldAttach:true).",input_schema:{type:"object",properties:{text:{type:"string",description:"The post body (the commentary text of the post)."},visibility:{type:"string",enum:["PUBLIC","CONNECTIONS"],description:"Post visibility: PUBLIC (anyone) or CONNECTIONS (your connections only). Defaults to PUBLIC."},imagePath:{type:"string",description:"Optional. A LOCAL image file path (e.g. a PNG returned by social_card_render). When set, the image is uploaded to LinkedIn and attached to the post as its media. Not uploaded on a dry_run."},imageAltText:{type:"string",description:"Optional alt text for the attached image (accessibility). Only used when imagePath is set."},dry_run:{type:"boolean",description:"Set dry_run:true to VALIDATE which LinkedIn account/profile the post would go to (and preview the text) WITHOUT posting \u2014 nothing is published or uploaded. Returns { dryRun, target, wouldPostAs, visibility, textPreview, imageWouldAttach? }. Defaults to false."}},required:["text"]}}]};export{R as PERSONAL_REFUSAL,v as chatStrictPersonal,E as injectedPersonalToken,p as linkedinApi,j as linkedinSkill,b as parseOrgId,f as personalTierCredentialGate,O as senderIsNonOwner,k as uploadImage};
|
package/dist/package.json
CHANGED
package/dist/report.d.ts
CHANGED
|
@@ -170,13 +170,13 @@ export const reportObjectSchema: z.ZodObject<{
|
|
|
170
170
|
severity: z.ZodOptional<z.ZodEnum<["ok", "info", "warn", "critical"]>>;
|
|
171
171
|
}, "strip", z.ZodTypeAny, {
|
|
172
172
|
sub?: string;
|
|
173
|
-
label?: string;
|
|
174
173
|
value?: string;
|
|
174
|
+
label?: string;
|
|
175
175
|
severity?: "ok" | "info" | "warn" | "critical";
|
|
176
176
|
}, {
|
|
177
177
|
sub?: string;
|
|
178
|
-
label?: string;
|
|
179
178
|
value?: string;
|
|
179
|
+
label?: string;
|
|
180
180
|
severity?: "ok" | "info" | "warn" | "critical";
|
|
181
181
|
}>, "many">;
|
|
182
182
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -184,8 +184,8 @@ export const reportObjectSchema: z.ZodObject<{
|
|
|
184
184
|
kind?: "breakdown";
|
|
185
185
|
rows?: {
|
|
186
186
|
sub?: string;
|
|
187
|
-
label?: string;
|
|
188
187
|
value?: string;
|
|
188
|
+
label?: string;
|
|
189
189
|
severity?: "ok" | "info" | "warn" | "critical";
|
|
190
190
|
}[];
|
|
191
191
|
}, {
|
|
@@ -193,8 +193,8 @@ export const reportObjectSchema: z.ZodObject<{
|
|
|
193
193
|
kind?: "breakdown";
|
|
194
194
|
rows?: {
|
|
195
195
|
sub?: string;
|
|
196
|
-
label?: string;
|
|
197
196
|
value?: string;
|
|
197
|
+
label?: string;
|
|
198
198
|
severity?: "ok" | "info" | "warn" | "critical";
|
|
199
199
|
}[];
|
|
200
200
|
}>, z.ZodObject<{
|
|
@@ -231,8 +231,8 @@ export const reportObjectSchema: z.ZodObject<{
|
|
|
231
231
|
kind?: "breakdown";
|
|
232
232
|
rows?: {
|
|
233
233
|
sub?: string;
|
|
234
|
-
label?: string;
|
|
235
234
|
value?: string;
|
|
235
|
+
label?: string;
|
|
236
236
|
severity?: "ok" | "info" | "warn" | "critical";
|
|
237
237
|
}[];
|
|
238
238
|
} | {
|
|
@@ -261,8 +261,8 @@ export const reportObjectSchema: z.ZodObject<{
|
|
|
261
261
|
kind?: "breakdown";
|
|
262
262
|
rows?: {
|
|
263
263
|
sub?: string;
|
|
264
|
-
label?: string;
|
|
265
264
|
value?: string;
|
|
265
|
+
label?: string;
|
|
266
266
|
severity?: "ok" | "info" | "warn" | "critical";
|
|
267
267
|
}[];
|
|
268
268
|
} | {
|
|
@@ -282,7 +282,6 @@ export const reportObjectSchema: z.ZodObject<{
|
|
|
282
282
|
}>>;
|
|
283
283
|
}, "strip", z.ZodTypeAny, {
|
|
284
284
|
title?: string;
|
|
285
|
-
subtitle?: string;
|
|
286
285
|
headline?: {
|
|
287
286
|
summary?: string;
|
|
288
287
|
primary?: string;
|
|
@@ -292,6 +291,7 @@ export const reportObjectSchema: z.ZodObject<{
|
|
|
292
291
|
severity?: "ok" | "info" | "warn" | "critical";
|
|
293
292
|
};
|
|
294
293
|
};
|
|
294
|
+
subtitle?: string;
|
|
295
295
|
sections?: ({
|
|
296
296
|
title?: string;
|
|
297
297
|
values?: number[];
|
|
@@ -314,8 +314,8 @@ export const reportObjectSchema: z.ZodObject<{
|
|
|
314
314
|
kind?: "breakdown";
|
|
315
315
|
rows?: {
|
|
316
316
|
sub?: string;
|
|
317
|
-
label?: string;
|
|
318
317
|
value?: string;
|
|
318
|
+
label?: string;
|
|
319
319
|
severity?: "ok" | "info" | "warn" | "critical";
|
|
320
320
|
}[];
|
|
321
321
|
} | {
|
|
@@ -329,7 +329,6 @@ export const reportObjectSchema: z.ZodObject<{
|
|
|
329
329
|
};
|
|
330
330
|
}, {
|
|
331
331
|
title?: string;
|
|
332
|
-
subtitle?: string;
|
|
333
332
|
headline?: {
|
|
334
333
|
summary?: string;
|
|
335
334
|
primary?: string;
|
|
@@ -339,6 +338,7 @@ export const reportObjectSchema: z.ZodObject<{
|
|
|
339
338
|
severity?: "ok" | "info" | "warn" | "critical";
|
|
340
339
|
};
|
|
341
340
|
};
|
|
341
|
+
subtitle?: string;
|
|
342
342
|
sections?: ({
|
|
343
343
|
title?: string;
|
|
344
344
|
values?: number[];
|
|
@@ -361,8 +361,8 @@ export const reportObjectSchema: z.ZodObject<{
|
|
|
361
361
|
kind?: "breakdown";
|
|
362
362
|
rows?: {
|
|
363
363
|
sub?: string;
|
|
364
|
-
label?: string;
|
|
365
364
|
value?: string;
|
|
365
|
+
label?: string;
|
|
366
366
|
severity?: "ok" | "info" | "warn" | "critical";
|
|
367
367
|
}[];
|
|
368
368
|
} | {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export namespace socialCardSkill {
|
|
2
|
+
let id: string;
|
|
3
|
+
let serverName: string;
|
|
4
|
+
let allowedTools: string[];
|
|
5
|
+
let description: string;
|
|
6
|
+
let promptFragment: string;
|
|
7
|
+
function resolve({ sessionPath, nodeName }?: {}): {
|
|
8
|
+
command: any;
|
|
9
|
+
args: any[];
|
|
10
|
+
env: {};
|
|
11
|
+
description: string;
|
|
12
|
+
type?: undefined;
|
|
13
|
+
alwaysLoad?: undefined;
|
|
14
|
+
} | {
|
|
15
|
+
type: string;
|
|
16
|
+
command: string;
|
|
17
|
+
args: any[];
|
|
18
|
+
env: {
|
|
19
|
+
ZIBBY_NODE_SESSION_PATH: any;
|
|
20
|
+
ZIBBY_SESSION_PATH: any;
|
|
21
|
+
};
|
|
22
|
+
description: string;
|
|
23
|
+
alwaysLoad: boolean;
|
|
24
|
+
};
|
|
25
|
+
function handleToolCall(name: any, args: any): Promise<string>;
|
|
26
|
+
let tools: {
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
input_schema: {
|
|
30
|
+
type: string;
|
|
31
|
+
properties: {
|
|
32
|
+
headline: {
|
|
33
|
+
type: string;
|
|
34
|
+
description: string;
|
|
35
|
+
};
|
|
36
|
+
eyebrow: {
|
|
37
|
+
type: string;
|
|
38
|
+
description: string;
|
|
39
|
+
};
|
|
40
|
+
subhead: {
|
|
41
|
+
type: string;
|
|
42
|
+
description: string;
|
|
43
|
+
};
|
|
44
|
+
stat: {
|
|
45
|
+
type: string;
|
|
46
|
+
description: string;
|
|
47
|
+
};
|
|
48
|
+
footer: {
|
|
49
|
+
type: string;
|
|
50
|
+
description: string;
|
|
51
|
+
};
|
|
52
|
+
diagram: {
|
|
53
|
+
type: string;
|
|
54
|
+
items: {
|
|
55
|
+
type: string;
|
|
56
|
+
};
|
|
57
|
+
description: string;
|
|
58
|
+
};
|
|
59
|
+
theme: {
|
|
60
|
+
type: string;
|
|
61
|
+
enum: string[];
|
|
62
|
+
description: string;
|
|
63
|
+
};
|
|
64
|
+
accent: {
|
|
65
|
+
type: string;
|
|
66
|
+
description: string;
|
|
67
|
+
};
|
|
68
|
+
width: {
|
|
69
|
+
type: string;
|
|
70
|
+
description: string;
|
|
71
|
+
};
|
|
72
|
+
height: {
|
|
73
|
+
type: string;
|
|
74
|
+
description: string;
|
|
75
|
+
};
|
|
76
|
+
filename: {
|
|
77
|
+
type: string;
|
|
78
|
+
description: string;
|
|
79
|
+
};
|
|
80
|
+
output: {
|
|
81
|
+
type: string;
|
|
82
|
+
enum: string[];
|
|
83
|
+
description: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
required: string[];
|
|
87
|
+
};
|
|
88
|
+
}[];
|
|
89
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import{createRequire as ne}from"node:module";import{existsSync as G,mkdirSync as oe,writeFileSync as z}from"node:fs";import{dirname as Z,join as F,resolve as q}from"node:path";import{fileURLToPath as J}from"node:url";var re=ne(import.meta.url),C=null;function ie(){return C||(C=re("@resvg/resvg-js")),C}var K=1200,ae=627,se=4096,ce=320,le="#3b82f6",k="Noto Sans",de=3;function he(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let e=Z(J(import.meta.url)),t=q(e,"..","bin","mcp-skill.mjs");return G(t)?t:null}function fe(){let e=Z(J(import.meta.url)),t=q(e,"..","assets","fonts");return["NotoSans-Regular.ttf","NotoSans-Bold.ttf"].map(n=>F(t,n)).filter(n=>G(n))}function ue(){let e=process.env.ZIBBY_NODE_SESSION_PATH,t=process.env.ZIBBY_SESSION_PATH,n=e||(t?F(t,"social-card"):F(process.cwd(),".zibby","output","social-cards"));return oe(n,{recursive:!0}),n}function U(e,t){let n=Number(e);return Number.isFinite(n)?Math.max(ce,Math.min(se,Math.round(n))):t}function _(e){return String(e??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function pe(e){return typeof e!="string"?null:e.trim().replace(/\.(png|svg)$/i,"").replace(/[^a-zA-Z0-9._-]+/g,"-").replace(/^[.-]+|[.-]+$/g,"")||null}function ge(e,t){if(typeof e!="string")return t;let n=e.trim();return/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(n)?n:t}function X(e,t,n){return String(e).length*t*n}function E(e,t,n,h){let a=String(e).trim().split(/\s+/).filter(Boolean),o=[],r="";for(let i of a){let f=r?`${r} ${i}`:i;r&&X(f,n,h)>t?(o.push(r),r=i):r=f}return r&&o.push(r),o.length?o:[""]}function me(e){return e==="light"?{bg:"#ffffff",fg:"#0b0f14",muted:"#5b6673",pillText:"#0b0f14",checkFg:"#ffffff",divider:"#e2e6ea"}:{bg:"#0b0f14",fg:"#e9edf1",muted:"#8b98a5",pillText:"#e9edf1",checkFg:"#0b0f14",divider:"#22303c"}}function j(e,t,n,h,a){let o=(Array.isArray(e)?e:[]).map(l=>String(l??"").trim()).filter(Boolean).slice(0,de);if(o.length<2)return null;let r=24,i=54,f=26,m=90,y=17,b=o.map(l=>Math.max(96,X(l,r,.58)+f*2)),$=b.reduce((l,p)=>l+p,0)+m*(o.length-1),s=t-$/2,c=n+i/2,x=[];for(let l=0;l<o.length;l++){let p=b[l];if(x.push(`<rect x="${s.toFixed(1)}" y="${n}" width="${p.toFixed(1)}" height="${i}" rx="${i/2}" fill="${a}" fill-opacity="0.12" stroke="${a}" stroke-opacity="0.55" stroke-width="1.5"/>`,`<text x="${(s+p/2).toFixed(1)}" y="${(c+r*.35).toFixed(1)}" text-anchor="middle" font-family="${k}" font-size="${r}" font-weight="700" fill="${h.pillText}">${_(o[l])}</text>`),s+=p,l<o.length-1){let A=s,S=s+m,N=(A+S)/2;x.push(`<line x1="${A.toFixed(1)}" y1="${c}" x2="${S.toFixed(1)}" y2="${c}" stroke="${a}" stroke-opacity="0.55" stroke-width="2"/>`,`<circle cx="${N.toFixed(1)}" cy="${c}" r="${y}" fill="${a}"/>`,`<path d="M ${(N-8).toFixed(1)} ${c.toFixed(1)} l 5 5 l 9 -11" fill="none" stroke="${h.checkFg}" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>`),s=S}}return{svg:x.join(`
|
|
2
|
+
`),height:i}}function ye(e){let{width:t,height:n,theme:h,accent:a}=e,o=me(h),r=t/2,i=Math.round(t*.07),f=t-i*2,m=String(e.headline).trim(),y=e.eyebrow?String(e.eyebrow).trim().toUpperCase():"",b=e.subhead?String(e.subhead).trim():"",$=e.stat?String(e.stat).trim():"",s=e.footer?String(e.footer).trim():"",c=t/K,x=Math.round(22*c),l=Math.round(29*c),p=b?E(b,f,l,.52):[],A=Math.round(l*1.28),S=4,N=Math.round(26*c),T=Math.round(20*c),B=Math.round(24*c),D=Math.round(30*c),P=!!($||s),R=i,Q=P?Math.round(110*c):i,H=n-R-Q,M=j(e.diagram,r,0,o,a),W=(d,w)=>{let O=S+N;return y&&(O+=x+T),O+=w.length*Math.round(d*1.16),p.length&&(O+=B+p.length*A),M&&(O+=D+M.height),O},I=[76,66,58,50,44,38].map(d=>Math.round(d*c)),V=4,v=I[I.length-1],L=E(m,f,v,.6);for(let d of I){let w=E(m,f,d,.6);if(w.length<=V&&W(d,w)<=H){v=d,L=w;break}}let ee=Math.round(v*1.16),te=W(v,L),u=R+Math.max(0,(H-te)/2),g=[];g.push(`<rect x="0" y="0" width="${t}" height="${n}" fill="${o.bg}"/>`);let Y=Math.round(60*c);g.push(`<rect x="${(r-Y/2).toFixed(1)}" y="${u}" width="${Y}" height="${S}" rx="2" fill="${a}"/>`),u+=S+N,y&&(g.push(`<text x="${r}" y="${(u+x*.82).toFixed(1)}" text-anchor="middle" font-family="${k}" font-size="${x}" font-weight="700" letter-spacing="3" fill="${a}">${_(y)}</text>`),u+=x+T);for(let d of L)g.push(`<text x="${r}" y="${(u+v*.82).toFixed(1)}" text-anchor="middle" font-family="${k}" font-size="${v}" font-weight="700" fill="${o.fg}">${_(d)}</text>`),u+=ee;if(p.length){u+=B;for(let d of p)g.push(`<text x="${r}" y="${(u+l*.82).toFixed(1)}" text-anchor="middle" font-family="${k}" font-size="${l}" font-weight="400" fill="${o.muted}">${_(d)}</text>`),u+=A}if(M){u+=D;let d=j(e.diagram,r,u,o,a);d&&g.push(d.svg)}if(P){let d=Math.round(24*c),w=n-Math.round(46*c);s&&g.push(`<text x="${i}" y="${w}" text-anchor="start" font-family="${k}" font-size="${d}" font-weight="400" fill="${o.muted}">${_(s)}</text>`),$&&g.push(`<text x="${t-i}" y="${w}" text-anchor="end" font-family="${k}" font-size="${d}" font-weight="700" fill="${a}">${_($)}</text>`)}return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${n}" viewBox="0 0 ${t} ${n}">
|
|
3
|
+
${g.join(`
|
|
4
|
+
`)}
|
|
5
|
+
</svg>`}function be(e){let{Resvg:t}=ie();return new t(e,{font:{fontFiles:fe(),loadSystemFonts:!0,defaultFontFamily:k}}).render().asPng()}var ke={id:"social-card",serverName:"social_card",allowedTools:["mcp__social_card__*"],description:'Social card \u2014 render a branded LinkedIn "concept card" PNG locally (bold headline + eyebrow + optional stat/footer/diagram); nothing leaves the box',promptFragment:`## Social Card (branded concept card, local)
|
|
6
|
+
You can render a BRANDED concept card PNG with the social_card_render tool \u2014 the
|
|
7
|
+
clean, high-signal LinkedIn "concept card" style (bold headline + small uppercase
|
|
8
|
+
eyebrow + optional stat/footer + optional A\u2014\u2713\u2014B diagram). Give it STRUCTURED
|
|
9
|
+
fields that capture the ONE key idea of your post:
|
|
10
|
+
- headline (required): the big, bold line \u2014 the single takeaway.
|
|
11
|
+
- eyebrow: a short uppercase kicker (e.g. "MY WORKFLOW", "OPEN SOURCE").
|
|
12
|
+
- subhead: one supporting line under the headline.
|
|
13
|
+
- stat / footer: e.g. stat "11.8k stars", footer "Apache 2.0".
|
|
14
|
+
- diagram: 2-3 short labels rendered as a chain, e.g. ["Claude Code","Codex"].
|
|
15
|
+
- theme ('dark' default | 'light'), accent (hex).
|
|
16
|
+
It renders server-side to a PNG in the run's output folder and returns
|
|
17
|
+
{ ok:true, files:[{ path, format:'png', bytes }] }. Pass the returned \`path\` as
|
|
18
|
+
\`imagePath\` when you draft/publish a LinkedIn post to ATTACH the card as the
|
|
19
|
+
post image. No browser, no external service \u2014 the data never leaves the machine.`,resolve({sessionPath:e,nodeName:t}={}){let n=he();if(!n)return{command:null,args:[],env:{},description:this.description};let h={},a=e&&t?F(e,t):null;a&&(h.ZIBBY_NODE_SESSION_PATH=a),e&&(h.ZIBBY_SESSION_PATH=e);for(let o of["ZIBBY_NODE_SESSION_PATH","ZIBBY_SESSION_PATH"])!h[o]&&process.env[o]&&(h[o]=process.env[o]);return{type:"stdio",command:"node",args:[n,"../dist/socialCard.js","socialCardSkill"],env:h,description:this.description,alwaysLoad:!0}},async handleToolCall(e,t){if(e!=="social_card_render")return JSON.stringify({error:`Unknown tool: ${e}`});try{let n=t?.headline;if(typeof n!="string"||!n.trim())return JSON.stringify({error:"headline (the big bold line) is required and must be a non-empty string."});let h=U(t?.width,K),a=U(t?.height,ae),o=t?.theme==="light"?"light":"dark",r=ge(t?.accent,le),i;try{i=ye({width:h,height:a,theme:o,accent:r,headline:n,eyebrow:t?.eyebrow,subhead:t?.subhead,stat:t?.stat,footer:t?.footer,diagram:t?.diagram})}catch(s){return JSON.stringify({error:`Card layout failed: ${s.message}`})}let f;try{f=be(i)}catch(s){return JSON.stringify({error:`PNG rasterization failed: ${s.message}`})}let m=ue(),y=pe(t?.filename)||`social-card-${Date.now()}`,b=F(m,`${y}.png`);z(b,f);let $=[{path:b,format:"png",bytes:f.length}];if(t?.output==="both"||t?.output==="svg"){let s=F(m,`${y}.svg`);z(s,i,"utf-8"),$.push({path:s,format:"svg",bytes:Buffer.byteLength(i,"utf-8")})}return JSON.stringify({ok:!0,width:h,height:a,theme:o,files:$})}catch(n){return JSON.stringify({error:`social_card_render failed: ${n.message}`})}},tools:[{name:"social_card_render",description:'Render a BRANDED "concept card" PNG LOCALLY (no external service) from structured fields \u2014 the clean LinkedIn concept-card style: bold headline + small uppercase eyebrow + optional supporting subhead, stat, footer, and an A\u2014\u2713\u2014B diagram. Returns { ok:true, files:[{ path, format:"png", bytes }] }. Pass the returned `path` as `imagePath` to a LinkedIn post tool to attach it as the post image. Example: { "headline":"No more copy-paste between AI tools", "eyebrow":"MY WORKFLOW", "stat":"11.8k stars", "footer":"Apache 2.0", "diagram":["Claude Code","Codex"] }.',input_schema:{type:"object",properties:{headline:{type:"string",description:"REQUIRED. The big, bold line \u2014 the single key idea/takeaway. Word-wrapped + auto-sized."},eyebrow:{type:"string",description:'Small uppercase kicker above the headline (e.g. "MY WORKFLOW", "OPEN SOURCE"). Rendered uppercased in the accent color.'},subhead:{type:"string",description:"One supporting line under the headline (muted)."},stat:{type:"string",description:'Optional stat, shown bottom-right in the accent color (e.g. "11.8k stars", "3x faster").'},footer:{type:"string",description:'Optional footer, shown bottom-left (muted) (e.g. "Apache 2.0", a repo name).'},diagram:{type:"array",items:{type:"string"},description:'Optional 2-3 short labels rendered as a chain of pills joined by a checkmark (A \u2014\u2713\u2014 B), e.g. ["Claude Code","Codex"].'},theme:{type:"string",enum:["dark","light"],description:"Card theme (default 'dark' \u2014 near-black bg, off-white text)."},accent:{type:"string",description:'Accent hex color (e.g. "#f97316"). Defaults to a tasteful blue (#3b82f6).'},width:{type:"number",description:"Image width in px (default 1200 \u2014 LinkedIn 1.91:1 link image)."},height:{type:"number",description:"Image height in px (default 627)."},filename:{type:"string",description:"Optional file basename (no extension); defaults to social-card-<timestamp>."},output:{type:"string",enum:["png","both"],description:"Which file(s) to write (default 'png'; 'both' also writes the .svg)."}},required:["headline"]}}]};export{ke as socialCardSkill};
|
|
@@ -43,4 +43,4 @@ When user says "check out repo-name" or "clone repo-name":
|
|
|
43
43
|
When user just wants to "look at" or "read" files (not clone):
|
|
44
44
|
- Use github_get_file to read individual files via API`,resolve(){let p=z();if(!p)return{command:null,args:[],env:{},description:this.description};let s={};for(let t of this.envKeys)process.env[t]&&(s[t]=process.env[t]);return{type:"stdio",command:"node",args:[p,"../dist/github.js","githubSkill"],env:s,description:this.description,alwaysLoad:!0}},async handleToolCall(p,s){try{switch(p){case"github_search_issues":{let t=s.query;if(!t)return JSON.stringify({error:"query is required"});let r=await l(`/search/issues?q=${encodeURIComponent(t)}&per_page=${s.limit||20}`),n=(r.items||[]).map(e=>({number:e.number,title:e.title,state:e.state,repo:e.repository_url?.split("/").slice(-2).join("/"),url:e.html_url,user:e.user?.login,isPR:!!e.pull_request,labels:(e.labels||[]).map(i=>i.name),createdAt:e.created_at}));return JSON.stringify({total:r.total_count,items:n})}case"github_search_code":{let t=s.query;if(!t)return JSON.stringify({error:"query is required"});let r=s.repo?`+repo:${s.repo}`:"",n=s.language?`+language:${s.language}`:"",e=await l(`/search/code?q=${encodeURIComponent(t)}${r}${n}&per_page=${s.limit||15}`),i=(e.items||[]).map(o=>({name:o.name,path:o.path,repo:o.repository?.full_name,url:o.html_url,score:o.score}));return JSON.stringify({total:e.total_count,items:i})}case"github_get_pr":{let{owner:t,repo:r,number:n}=s;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${r}/pulls/${n}`);return JSON.stringify({number:e.number,title:e.title,state:e.state,merged:e.merged,body:e.body?.slice(0,5e3),user:e.user?.login,branch:e.head?.ref,headSha:e.head?.sha,base:e.base?.ref,changedFiles:e.changed_files,additions:e.additions,deletions:e.deletions,createdAt:e.created_at,mergedAt:e.merged_at,url:e.html_url,labels:(e.labels||[]).map(i=>i.name)})}case"github_get_pr_diff":{let{owner:t,repo:r,number:n}=s;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${r}/pulls/${n}`,{accept:"application/vnd.github.v3.diff",raw:!0}),i=e.length>15e3;return JSON.stringify({number:n,diff:i?e.slice(0,15e3):e,truncated:i,totalLength:e.length})}case"github_list_pr_files":{let{owner:t,repo:r,number:n}=s;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${r}/pulls/${n}/files?per_page=100`);return JSON.stringify({total:e.length,files:e.map(i=>({filename:i.filename,status:i.status,additions:i.additions,deletions:i.deletions,patch:i.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:t,repo:r,number:n}=s;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${r}/pulls/${n}/comments?per_page=50`),i=await l(`/repos/${t}/${r}/issues/${n}/comments?per_page=50`),o=[...e.map(a=>({type:"review",user:a.user?.login,body:a.body?.slice(0,1e3),path:a.path,line:a.line,createdAt:a.created_at})),...i.map(a=>({type:"issue",user:a.user?.login,body:a.body?.slice(0,1e3),createdAt:a.created_at}))].sort((a,d)=>new Date(a.createdAt)-new Date(d.createdAt));return JSON.stringify({total:o.length,comments:o})}case"github_get_review_thread":{let{owner:t,repo:r,number:n,commentId:e}=s||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, number, and commentId are required"});let i=await l(`/repos/${t}/${r}/pulls/comments/${e}`),o=i.in_reply_to_id||i.id,a=[];try{a=await l(`/repos/${t}/${r}/pulls/${n}/comments?per_page=100`)}catch{a=[i]}(!Array.isArray(a)||a.length===0)&&(a=[i]);let d=a.filter(m=>m.id===o||m.in_reply_to_id===o).sort((m,b)=>new Date(m.created_at)-new Date(b.created_at)),c=d.length?d:[i],u=c.find(m=>m.id===o)||c[0];return JSON.stringify({rootCommentId:o,path:u.path,line:u.line??u.original_line??null,side:u.side||"RIGHT",diffHunk:typeof u.diff_hunk=="string"?u.diff_hunk.slice(0,3e3):null,commitId:u.commit_id||u.original_commit_id||null,notes:c.map(m=>({id:m.id,user:m.user?.login,body:(m.body||"").slice(0,4e3),createdAt:m.created_at,isRoot:m.id===o,url:m.html_url}))})}case"github_reply_review_thread":{let{owner:t,repo:r,number:n,commentId:e,body:i}=s||{};if(!t||!r||!n||!e||!i)return JSON.stringify({error:"owner, repo, number, commentId, and body are required"});let o=await l(`/repos/${t}/${r}/pulls/${n}/comments/${e}/replies`,{method:"POST",body:{body:String(i)}});return JSON.stringify({ok:!0,id:o.id,url:o.html_url,inReplyTo:o.in_reply_to_id})}case"github_reply_issue_comment":{let{owner:t,repo:r,number:n,body:e}=s||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let i=await l(`/repos/${t}/${r}/issues/${n}/comments`,{method:"POST",body:{body:String(e)}});return JSON.stringify({ok:!0,id:i.id,url:i.html_url})}case"github_create_review":{let{owner:t,repo:r,number:n,body:e,event:i,comments:o}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let a=(i||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(a))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${i})`});let d=Array.isArray(o)?o.filter(m=>m&&m.path&&m.body&&(m.line!=null||m.position!=null)).map(m=>{let b={path:m.path,body:String(m.body)};return m.line!=null?(b.line=Number(m.line),b.side=m.side==="LEFT"?"LEFT":"RIGHT"):b.position=Number(m.position),b}):[];if(a!=="APPROVE"&&!e&&d.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let c={event:a};e&&(c.body=String(e)),d.length>0&&(c.comments=d);let u=await l(`/repos/${t}/${r}/pulls/${n}/reviews`,{method:"POST",body:c});return JSON.stringify({ok:!0,id:u.id,state:u.state,event:a,commentsPosted:d.length,url:u.html_url})}case"github_list_commits":{let{owner:t,repo:r,branch:n,path:e,limit:i}=s;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let o=`/repos/${t}/${r}/commits?per_page=${i||20}`;n&&(o+=`&sha=${encodeURIComponent(n)}`),e&&(o+=`&path=${encodeURIComponent(e)}`);let a=await l(o);return JSON.stringify({total:a.length,commits:a.map(d=>({sha:d.sha?.slice(0,8),fullSha:d.sha,message:d.commit?.message?.slice(0,300),author:d.commit?.author?.name,date:d.commit?.author?.date,url:d.html_url}))})}case"github_get_commit":{let{owner:t,repo:r,sha:n}=s;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and sha are required"});let e=await l(`/repos/${t}/${r}/commits/${n}`);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(i=>({filename:i.filename,status:i.status,additions:i.additions,deletions:i.deletions,patch:i.patch?.slice(0,3e3)}))})}case"github_get_file":{let{owner:t,repo:r,path:n,ref:e}=s;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and path are required"});let i=`/repos/${t}/${r}/contents/${encodeURIComponent(n)}`;e&&(i+=`?ref=${encodeURIComponent(e)}`);let o=await l(i);if(o.type!=="file")return Array.isArray(o)?JSON.stringify({type:"directory",path:n,entries:o.map(c=>({name:c.name,type:c.type,size:c.size,path:c.path}))}):JSON.stringify({error:`Not a file: ${o.type}`});let a=Buffer.from(o.content||"","base64").toString("utf-8"),d=a.length>2e4;return JSON.stringify({path:o.path,size:o.size,sha:o.sha?.slice(0,8),content:d?a.slice(0,2e4):a,truncated:d})}case"github_get_user":try{let t=await l("/installation/repositories?per_page=1");if(t.repositories&&t.repositories.length>0){let r=t.repositories[0],n=r.owner.login,e=r.owner.type,i=e==="Organization"?`/orgs/${n}`:`/users/${n}`,o=await l(i);return JSON.stringify({login:o.login,name:o.name||o.login,avatar:o.avatar_url,bio:o.bio||o.description,type:e,isOrg:e==="Organization",publicRepos:o.public_repos,message:"Showing GitHub App installation owner (GitHub Apps cannot access /user endpoint)"})}return JSON.stringify({error:"No repositories accessible to this GitHub App installation"})}catch(t){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${t.message})`})}case"github_list_orgs":try{let r=(await l("/installation/repositories?per_page=100")).repositories||[],n=new Map;for(let i of r)i.owner.type==="Organization"&&(n.has(i.owner.login)||n.set(i.owner.login,{login:i.owner.login,description:null,url:i.owner.url}));let e=Array.from(n.values());return JSON.stringify({count:e.length,orgs:e,message:"Extracted from accessible repositories (GitHub Apps cannot access /user/orgs directly)"})}catch(t){return JSON.stringify({error:`GitHub App cannot list orgs via /user/orgs. Error: ${t.message}`})}case"github_clone":{let h=function(w){let v=w.replace(/^~(?=$|\/|\\)/,b);return o(v)},{owner:t,repo:r,destination:n}=s;if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let{execSync:e}=await import("child_process"),{join:i,resolve:o}=await import("path"),{existsSync:a,mkdirSync:d}=await import("fs"),{homedir:c,platform:u}=await import("os"),{token:m}=await G("github"),b=c(),y=n?h(n):i(b,"zibby-repos"),f=i(y,r);if(d(y,{recursive:!0}),a(f))return JSON.stringify({error:`Directory ${f} already exists. Remove it first or use a different destination.`,existingPath:f});try{let w=`https://x-access-token:${m}@github.com/${t}/${r}.git`;e(`git clone ${w} "${f}"`,{stdio:"pipe"});let v=u()==="win32",g;return v?g=e(`dir "${f}"`,{encoding:"utf-8",shell:"cmd.exe"}):g=e(`ls -la "${f}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:f,message:`Cloned ${t}/${r} to ${f}`,contents:g.split(`
|
|
45
45
|
`).slice(0,30).join(`
|
|
46
|
-
`),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}=s;if(!t)return JSON.stringify({error:"query is required"});let n=await this.handleToolCall("github_list_repos",{limit:200},{}),e=JSON.parse(n);if(e.error)return JSON.stringify(e);let i=t.toLowerCase(),o=e.repos.filter(a=>a.name.toLowerCase().includes(i)||a.fullName.toLowerCase().includes(i)||a.description&&a.description.toLowerCase().includes(i));return JSON.stringify({query:t,count:o.length,repos:o.slice(0,r||20)})}case"github_list_repos":{let{owner:t,type:r,sort:n,direction:e,limit:i,query:o}=s,a=100,d=i||200,c=[],u=g=>({name:g.name,fullName:g.full_name,private:g.private,description:g.description,language:g.language,defaultBranch:g.default_branch,updatedAt:g.updated_at,stars:g.stargazers_count,url:g.html_url,fullPath:g.full_name,webUrl:g.html_url,visibility:g.visibility||(g.private?"private":"public")}),m=g=>{if(!o)return!0;let R=String(o).toLowerCase();return g.name&&g.name.toLowerCase().includes(R)||g.fullName&&g.fullName.toLowerCase().includes(R)||g.description&&g.description.toLowerCase().includes(R)};if(!t){let g=1,R=!0;for(;R&&c.length<d;){let A=`/installation/repositories?per_page=${a}&page=${g}`,E=(await l(A)).repositories||[];if(E.length===0)break;c=c.concat(E),R=E.length===a,g++}let O=c.map(u).filter(m),N=O.slice(0,d),x=O.length>N.length,T=N.filter(A=>A.private).length,q=N.filter(A=>!A.private).length;return JSON.stringify({count:N.length,repos:N,truncated:x,privateCount:T,publicCount:q,message:`Found ${T} private and ${q} public repos`})}let b=await l(`/orgs/${t}`).then(()=>!0).catch(()=>!1),h=1,y=!0;for(;y&&c.length<d;){let g;b?g=`/orgs/${t}/repos?per_page=${a}&page=${h}&type=${r||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`:g=`/users/${t}/repos?per_page=${a}&page=${h}&type=${r||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`;let R=await l(g),O=Array.isArray(R)?R:[];if(O.length===0)break;c=c.concat(O),y=O.length===a,h++}let f=c.map(u).filter(m),w=f.slice(0,d),v=f.length>w.length;return JSON.stringify({count:w.length,repos:w,truncated:v})}case"github_create_pr":{let{owner:t,repo:r,head:n,title:e}=s||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, head (source branch), and title are required"});let i=s.base;if(!i)try{i=(await l(`/repos/${t}/${r}`)).default_branch||"main"}catch{i="main"}let o={title:String(e),head:String(n),base:String(i),body:s.body?String(s.body):"",draft:!!s.draft};try{let a=await l(`/repos/${t}/${r}/pulls`,{method:"POST",body:o});return JSON.stringify({success:!0,pr_url:a.html_url,number:a.number,branch:n,base:i,repo:`${t}/${r}`,provider:"github",draft:!!a.draft,state:a.state})}catch(a){let d=String(a.message||a);if(/GitHub API 422/.test(d))return JSON.stringify({success:!1,branch:n,base:i,repo:`${t}/${r}`,provider:"github",skippedReason:d});throw a}}case"github_merge_pr":{let{owner:t,repo:r,number:n}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=s.mergeMethod||"squash";if(!["merge","squash","rebase"].includes(e))return JSON.stringify({error:`mergeMethod must be merge, squash, or rebase (got ${e})`});let i={merge_method:e};s.commitTitle&&(i.commit_title=String(s.commitTitle)),s.commitMessage&&(i.commit_message=String(s.commitMessage));try{let o=await l(`/repos/${t}/${r}/pulls/${n}/merge`,{method:"PUT",body:i});return JSON.stringify({success:!0,merged:!0,sha:o.sha,number:n,provider:"github"})}catch(o){let a=String(o.message||o);if(/GitHub API (405|409|404)/.test(a))return JSON.stringify({success:!1,number:n,provider:"github",skippedReason:a});throw o}}case"github_create_issue":{let{owner:t,repo:r,title:n,body:e}=s;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and title are required"});let i=await l(`/repos/${t}/${r}/issues`,{method:"POST",body:{title:n,body:e||""}});return JSON.stringify({number:i.number,url:i.html_url,title:i.title})}case"github_list_issues":{let{owner:t,repo:r,state:n,labels:e,since:i,assignee:o,sort:a,direction:d,limit:c}=s||{};if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let u=new URLSearchParams;u.set("state",n||"open"),u.set("per_page",String(c||30)),u.set("sort",a||"updated"),u.set("direction",d||"desc"),e&&u.set("labels",Array.isArray(e)?e.join(","):e),i&&u.set("since",i),o&&u.set("assignee",o);let m=await l(`/repos/${t}/${r}/issues?${u.toString()}`),b=(Array.isArray(m)?m:[]).filter(h=>!h.pull_request).map(h=>({number:h.number,title:h.title,state:h.state,labels:(h.labels||[]).map(y=>typeof y=="string"?y:y.name),assignee:h.assignee?.login||null,assignees:(h.assignees||[]).map(y=>y.login),user:h.user?.login,comments:h.comments,url:h.html_url,createdAt:h.created_at,updatedAt:h.updated_at}));return JSON.stringify({count:b.length,issues:b})}case"github_get_issue":{let{owner:t,repo:r,number:n}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${r}/issues/${n}`);return e.pull_request?JSON.stringify({error:`#${n} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:e.number,title:e.title,body:e.body||"",state:e.state,stateReason:e.state_reason||null,labels:(e.labels||[]).map(i=>typeof i=="string"?i:i.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(i=>i.login),user:e.user?.login,milestone:e.milestone?.title||null,comments:e.comments,url:e.html_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"github_get_issue_comments":{let{owner:t,repo:r,number:n,limit:e}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await l(`/repos/${t}/${r}/issues/${n}/comments?per_page=${e||100}`),o=(Array.isArray(i)?i:[]).map(a=>({id:a.id,user:a.user?.login,body:a.body||"",createdAt:a.created_at,updatedAt:a.updated_at,url:a.html_url}));return JSON.stringify({count:o.length,comments:o})}case"github_add_issue_comment":{let{owner:t,repo:r,number:n,body:e}=s||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let i=await l(`/repos/${t}/${r}/issues/${n}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:i.id,url:i.html_url})}case"github_close_issue":{let{owner:t,repo:r,number:n,stateReason:e}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i={state:"closed"};e&&(i.state_reason=e);let o=await l(`/repos/${t}/${r}/issues/${n}`,{method:"PATCH",body:i});return JSON.stringify({ok:!0,number:o.number,state:o.state,stateReason:o.state_reason||null,url:o.html_url})}case"github_reopen_issue":{let{owner:t,repo:r,number:n}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${r}/issues/${n}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:e.number,state:e.state,url:e.html_url})}case"github_label_issue":{let{owner:t,repo:r,number:n,labels:e,mode:i}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o=Array.isArray(e)?e:e?[e]:[];if(!o.length)return JSON.stringify({error:"labels (string or array) is required"});let a=i||"add";if(a==="set"){let c=await l(`/repos/${t}/${r}/issues/${n}`,{method:"PATCH",body:{labels:o}});return JSON.stringify({ok:!0,number:c.number,labels:(c.labels||[]).map(u=>typeof u=="string"?u:u.name)})}if(a==="remove"){for(let u of o)await l(`/repos/${t}/${r}/issues/${n}/labels/${encodeURIComponent(u)}`,{method:"DELETE"});let c=await l(`/repos/${t}/${r}/issues/${n}`);return JSON.stringify({ok:!0,number:c.number,labels:(c.labels||[]).map(u=>typeof u=="string"?u:u.name)})}let d=await l(`/repos/${t}/${r}/issues/${n}/labels`,{method:"POST",body:{labels:o}});return JSON.stringify({ok:!0,number:n,labels:(Array.isArray(d)?d:[]).map(c=>typeof c=="string"?c:c.name)})}default:return JSON.stringify({error:`Unknown tool: ${p}`})}}catch(t){return JSON.stringify({error:t.message})}},tools:[{name:"github_get_user",description:"Get the authenticated GitHub user profile and their organizations",input_schema:{type:"object",properties:{}}},{name:"github_list_orgs",description:"List GitHub organizations the authenticated user belongs to",input_schema:{type:"object",properties:{}}},{name:"github_list_repos",description:"List the repositories this token/installation can access (omit owner) \u2014 or a specific user/org's repos (pass owner). Use this to discover a RELATED repo worth cloning when a change's correctness depends on another accessible repo. Each repo carries a normalized { fullPath, name, webUrl, defaultBranch, visibility } shape (identical to gitlab_list_projects) alongside legacy fields, plus a truncated flag.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Org or user login. Omit to list every repo your token/installation can access."},query:{type:"string",description:"Optional term matched against repo name/full-name/description"},type:{type:"string",enum:["all","public","private","forks","sources","member"],description:"Filter by type (default: all)"},sort:{type:"string",enum:["created","updated","pushed","full_name"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max repos to return (default: 200, hard-capped at the fetch ceiling)"}}}},{name:"github_clone",description:'Clone a GitHub repository to the local filesystem. Use when user says "check out" or "clone" a repo.',input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner (user or org name)"},repo:{type:"string",description:"Repository name"},destination:{type:"string",description:"Destination directory. Accepts absolute paths, ~-prefixed paths, or relative names. Defaults to ~/zibby-repos/<repo>."}},required:["owner","repo"]}},{name:"github_search_repos",description:"Search accessible repositories by name or description. Use this when the user asks to find a specific repo.",input_schema:{type:"object",properties:{query:{type:"string",description:'Search term to match against repo name or description (e.g., "electron", "my-app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_issues",description:"Search GitHub issues and pull requests",input_schema:{type:"object",properties:{query:{type:"string",description:'GitHub search query (e.g. "SCRUM-123", "login bug repo:org/app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_code",description:"Search code across GitHub repositories by keyword",input_schema:{type:"object",properties:{query:{type:"string",description:'Code search query (e.g. "handleLogin", "class AuthService")'},repo:{type:"string",description:'Scope to a specific repo (e.g. "org/app"). Optional.'},language:{type:"string",description:'Filter by language (e.g. "javascript", "python"). Optional.'},limit:{type:"number",description:"Max results (default: 15)"}},required:["query"]}},{name:"github_get_pr",description:"Get details of a pull request \u2014 title, description, branch, stats",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_get_pr_diff",description:"Get the unified diff of a pull request \u2014 the actual code changes",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_files",description:"List files changed in a PR with per-file patches",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_comments",description:"Get all review and issue comments on a PR",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_get_review_thread",description:"Read a PR review-comment THREAD given any comment id in it: the root review comment + all its replies, plus the anchored diff context (file, line, the original diff hunk). Use this to understand a human's reply to a previous review comment before replying in-thread.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},commentId:{type:"number",description:"Any review-comment id in the thread (the root or any reply)"}},required:["owner","repo","number","commentId"]}},{name:"github_reply_review_thread",description:"Reply IN-THREAD to an existing PR review-comment thread (a conversational reply nested under the thread the human commented on \u2014 NOT a fresh full review). Pass any comment id in the thread.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},commentId:{type:"number",description:"Any review-comment id in the thread to reply to"},body:{type:"string",description:"The reply text (markdown)"}},required:["owner","repo","number","commentId","body"]}},{name:"github_reply_issue_comment",description:"Post a reply on a PR's top-level conversation (a new issue comment on the PR). Use when the human replied to a non-inline/summary comment rather than an inline review thread. Quote or @-mention for context since issue comments are not threaded.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},body:{type:"string",description:"The reply text (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_create_review",description:"Post a review on a pull request: a summary body plus optional inline comments anchored to file/line, with an event (COMMENT, APPROVE, or REQUEST_CHANGES). Use this to deliver a code review back to the PR.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},body:{type:"string",description:"The review summary (markdown). Shown as the top-level review comment."},event:{type:"string",enum:["COMMENT","APPROVE","REQUEST_CHANGES"],description:"Review verdict. Default COMMENT (no approval state). Use REQUEST_CHANGES for blocking issues."},comments:{type:"array",description:"Optional inline comments, each anchored to a changed line.",items:{type:"object",properties:{path:{type:"string",description:"File path as it appears in the diff"},line:{type:"number",description:"Line number in the file's NEW version (the right side of the diff)"},side:{type:"string",enum:["LEFT","RIGHT"],description:"RIGHT (new) or LEFT (old). Default RIGHT."},body:{type:"string",description:"The inline comment text (markdown)"}},required:["path","line","body"]}}},required:["owner","repo","number"]}},{name:"github_list_commits",description:"List 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_pr",description:"Open a pull request on GitHub (POST /repos/{owner}/{repo}/pulls). The head (source) branch must already be pushed. Returns the REAL pr_url from GitHub \u2014 never fabricate a PR url. Expected business outcomes (no commits between base and head, a PR already exists for this branch, base==head, missing head) return { success:false, skippedReason } rather than erroring.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},head:{type:"string",description:'Source branch to merge FROM (must already be pushed). For a cross-fork PR use "fork-owner:branch".'},base:{type:"string",description:"Target branch to merge INTO (default: the repo's default branch)"},title:{type:"string",description:"PR title"},body:{type:"string",description:"PR description (markdown)"},draft:{type:"boolean",description:"Open as a draft PR (default: false)"}},required:["owner","repo","head","title"]}},{name:"github_merge_pr",description:"Merge a pull request on GitHub (PUT /repos/{owner}/{repo}/pulls/{number}/merge). mergeMethod is merge | squash | rebase (default squash). Returns { success:true, merged:true, sha } with the REAL merge SHA from GitHub. Expected non-mergeable outcomes (405 = draft / failing checks / branch protection, 409 = head sha moved / conflict, 404 = not found) return { success:false, skippedReason } rather than erroring.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number to merge"},mergeMethod:{type:"string",enum:["merge","squash","rebase"],description:"How to merge (default: squash)"},commitTitle:{type:"string",description:"Title for the merge/squash commit (optional)"},commitMessage:{type:"string",description:"Body for the merge/squash commit (optional)"}},required:["owner","repo","number"]}},{name:"github_create_issue",description:"Create a GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},title:{type:"string",description:"Issue title"},body:{type:"string",description:"Issue body (markdown)"}},required:["owner","repo","title"]}},{name:"github_list_issues",description:"List issues in a repo (excludes pull requests). Filter by state, labels, and an updated-since cursor for polling.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},state:{type:"string",enum:["open","closed","all"],description:"Filter by state (default: open)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},since:{type:"string",description:"ISO-8601 timestamp; only issues updated at/after this (polling cursor)"},assignee:{type:"string",description:'Filter by assignee login, "none", or "*"'},sort:{type:"string",enum:["created","updated","comments"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30, max 100 per page)"}},required:["owner","repo"]}},{name:"github_get_issue",description:"Get a single GitHub issue with full detail (title, body, state, labels, assignee, url)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_get_issue_comments",description:"Get the comment thread on a GitHub issue (chronological)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},limit:{type:"number",description:"Max comments (default: 100)"}},required:["owner","repo","number"]}},{name:"github_add_issue_comment",description:"Add a comment to a GitHub issue. Also the way to record a PR link on an issue (post a markdown link).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},body:{type:"string",description:"Comment body (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_close_issue",description:"Close a GitHub issue. Optionally set the close reason (completed or not_planned).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},stateReason:{type:"string",enum:["completed","not_planned"],description:"Why the issue was closed (optional)"}},required:["owner","repo","number"]}},{name:"github_reopen_issue",description:"Reopen a closed GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_label_issue",description:"Add, set (replace all), or remove labels on a GitHub issue. Labels back state-like transitions on GitHub.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},labels:{type:"array",items:{type:"string"},description:"Label name(s)"},mode:{type:"string",enum:["add","set","remove"],description:"add appends, set replaces all, remove deletes (default: add)"}},required:["owner","repo","number","labels"]}}]};var L=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i,U=/\b(in[\s-]?progress|wip|doing|started|in[\s-]?review|review)\b/i,K=/\b(done|closed|complete|completed|resolved|fixed|merged|shipped)\b/i,W=/\b(todo|to[\s-]?do|open|backlog|reopen|new)\b/i,I="in progress",J="blocked";function j(p,s=[]){if(p==="closed")return"done";if(p!=="open")return"unknown";let t=(s||[]).map(String);return t.some(r=>L.test(r))?"blocked":t.some(r=>U.test(r))?"in_progress":"todo"}function $(p={}){let s=p.owner||process.env.GITHUB_OWNER,t=p.repo||process.env.GITHUB_REPO;if(!s||!t)throw new Error("GitHub scope missing: provide {owner, repo} via ctx or env GITHUB_OWNER / GITHUB_REPO.");return{owner:s,repo:t}}function S(p){let s=JSON.parse(p);if(s&&s.error)throw new Error(s.error);return s}function k(p,s={}){let t=p.labels||[],r=p.number,n=s.owner&&s.repo?`${s.owner}/${s.repo}#${r}`:`#${r}`;return{id:String(r),key:n,title:p.title||"",body:p.body||"",state:p.state||null,stateCategory:j(p.state,t),assignee:p.assignee||p.assignees&&p.assignees[0]||null,url:p.url||null,_raw:p}}var Q={id:"github",toStateCategory:j,toNeutral:k,IN_PROGRESS_LABEL:I,BLOCKED_LABEL:J,async listCandidates(p={}){let s=p.ctx||{},{owner:t,repo:r}=$(s);return(S(await _.handleToolCall("github_list_issues",{owner:t,repo:r,state:p.state||"open",labels:p.labels,since:p.updatedAfter,limit:p.limit})).issues||[]).map(e=>k(e,{owner:t,repo:r}))},async getTicket(p,s={}){let{owner:t,repo:r}=$(s),n=P(p);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);let e=JSON.parse(await _.handleToolCall("github_get_issue",{owner:t,repo:r,number:n}));return e.error?null:k(e,{owner:t,repo:r})},async getComments(p,s={}){let{owner:t,repo:r}=$(s),n=P(p);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);return(S(await _.handleToolCall("github_get_issue_comments",{owner:t,repo:r,number:n})).comments||[]).map(i=>({id:String(i.id),author:i.user||"Unknown",body:i.body||"",createdAt:i.createdAt||null,updatedAt:i.updatedAt||null,_raw:i})).sort((i,o)=>String(o.createdAt).localeCompare(String(i.createdAt)))},async addComment(p,s,t={}){let{owner:r,repo:n}=$(t),e=P(p);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);if(!s)throw new Error("body is required");let i=S(await _.handleToolCall("github_add_issue_comment",{owner:r,repo:n,number:e,body:s}));return{ok:!!i.ok,id:i.id?String(i.id):null}},async transition(p,s,t={}){let{owner:r,repo:n}=$(t),e=P(p);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);let i=String(s||"");if(K.test(i)){let o=S(await _.handleToolCall("github_close_issue",{owner:r,repo:n,number:e,stateReason:"completed"}));return{ok:!!o.ok,stateAfter:o.state||"closed",stateCategoryAfter:"done",_raw:o}}if(L.test(i)){await H(r,n,e);let o=S(await _.handleToolCall("github_label_issue",{owner:r,repo:n,number:e,labels:[J],mode:"add"}));return{ok:!!o.ok,stateAfter:"open",stateCategoryAfter:"blocked",via:"label",_raw:o}}if(U.test(i)){await H(r,n,e);let o=S(await _.handleToolCall("github_label_issue",{owner:r,repo:n,number:e,labels:[I],mode:"add"}));return{ok:!!o.ok,stateAfter:"open",stateCategoryAfter:"in_progress",via:"label",_raw:o}}if(W.test(i)){let o=S(await _.handleToolCall("github_reopen_issue",{owner:r,repo:n,number:e}));return{ok:!!o.ok,stateAfter:o.state||"open",stateCategoryAfter:"todo",_raw:o}}return{ok:!1,error:`GitHub issues have no "${s}" state. Representable targets: open/todo, in progress, blocked, done/closed.`}},async linkPullRequest(p,s,t,r={}){let{owner:n,repo:e}=$(r),i=P(p);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);if(!s)throw new Error("prUrl is required");let o=`${t?`${t}: `:"Linked PR: "}${s}`;return{ok:!!S(await _.handleToolCall("github_add_issue_comment",{owner:n,repo:e,number:i,body:o})).ok,via:"comment"}}};async function H(p,s,t){await _.handleToolCall("github_reopen_issue",{owner:p,repo:s,number:t})}function P(p){if(p==null)return null;if(typeof p=="number")return p;let s=/(\d+)\s*$/.exec(String(p));return s?Number(s[1]):null}var se=Q;export{se as default,Q as githubAdapter};
|
|
46
|
+
`),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}=s;if(!t)return JSON.stringify({error:"query is required"});let n=await this.handleToolCall("github_list_repos",{limit:200},{}),e=JSON.parse(n);if(e.error)return JSON.stringify(e);let i=t.toLowerCase(),o=e.repos.filter(a=>a.name.toLowerCase().includes(i)||a.fullName.toLowerCase().includes(i)||a.description&&a.description.toLowerCase().includes(i));return JSON.stringify({query:t,count:o.length,repos:o.slice(0,r||20)})}case"github_list_repos":{let{owner:t,type:r,sort:n,direction:e,limit:i,query:o}=s,a=100,d=i||200,c=[],u=g=>({name:g.name,fullName:g.full_name,private:g.private,description:g.description,language:g.language,defaultBranch:g.default_branch,updatedAt:g.updated_at,stars:g.stargazers_count,url:g.html_url,fullPath:g.full_name,webUrl:g.html_url,visibility:g.visibility||(g.private?"private":"public")}),m=g=>{if(!o)return!0;let R=String(o).toLowerCase();return g.name&&g.name.toLowerCase().includes(R)||g.fullName&&g.fullName.toLowerCase().includes(R)||g.description&&g.description.toLowerCase().includes(R)};if(!t){let g=1,R=!0;for(;R&&c.length<d;){let A=`/installation/repositories?per_page=${a}&page=${g}`,E=(await l(A)).repositories||[];if(E.length===0)break;c=c.concat(E),R=E.length===a,g++}let O=c.map(u).filter(m),N=O.slice(0,d),j=O.length>N.length,T=N.filter(A=>A.private).length,q=N.filter(A=>!A.private).length;return JSON.stringify({count:N.length,repos:N,truncated:j,privateCount:T,publicCount:q,message:`Found ${T} private and ${q} public repos`})}let b=await l(`/orgs/${t}`).then(()=>!0).catch(()=>!1),h=1,y=!0;for(;y&&c.length<d;){let g;b?g=`/orgs/${t}/repos?per_page=${a}&page=${h}&type=${r||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`:g=`/users/${t}/repos?per_page=${a}&page=${h}&type=${r||"all"}&sort=${n||"updated"}&direction=${e||"desc"}`;let R=await l(g),O=Array.isArray(R)?R:[];if(O.length===0)break;c=c.concat(O),y=O.length===a,h++}let f=c.map(u).filter(m),w=f.slice(0,d),v=f.length>w.length;return JSON.stringify({count:w.length,repos:w,truncated:v})}case"github_create_pr":{let{owner:t,repo:r,head:n,title:e}=s||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, head (source branch), and title are required"});let i=s.base;if(!i)try{i=(await l(`/repos/${t}/${r}`)).default_branch||"main"}catch{i="main"}let o={title:String(e),head:String(n),base:String(i),body:s.body?String(s.body):"",draft:!!s.draft};try{let a=await l(`/repos/${t}/${r}/pulls`,{method:"POST",body:o});return JSON.stringify({success:!0,pr_url:a.html_url,number:a.number,branch:n,base:i,repo:`${t}/${r}`,provider:"github",draft:!!a.draft,state:a.state})}catch(a){let d=String(a.message||a);if(/GitHub API 422/.test(d))return JSON.stringify({success:!1,branch:n,base:i,repo:`${t}/${r}`,provider:"github",skippedReason:d});throw a}}case"github_merge_pr":{let{owner:t,repo:r,number:n}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=s.mergeMethod||"squash";if(!["merge","squash","rebase"].includes(e))return JSON.stringify({error:`mergeMethod must be merge, squash, or rebase (got ${e})`});let i={merge_method:e};s.commitTitle&&(i.commit_title=String(s.commitTitle)),s.commitMessage&&(i.commit_message=String(s.commitMessage));try{let o=await l(`/repos/${t}/${r}/pulls/${n}/merge`,{method:"PUT",body:i});return JSON.stringify({success:!0,merged:!0,sha:o.sha,number:n,provider:"github"})}catch(o){let a=String(o.message||o);if(/GitHub API (405|409|404)/.test(a))return JSON.stringify({success:!1,number:n,provider:"github",skippedReason:a});throw o}}case"github_create_issue":{let{owner:t,repo:r,title:n,body:e}=s;if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and title are required"});let i=await l(`/repos/${t}/${r}/issues`,{method:"POST",body:{title:n,body:e||""}});return JSON.stringify({number:i.number,url:i.html_url,title:i.title})}case"github_list_issues":{let{owner:t,repo:r,state:n,labels:e,since:i,assignee:o,sort:a,direction:d,limit:c}=s||{};if(!t||!r)return JSON.stringify({error:"owner and repo are required"});let u=new URLSearchParams;u.set("state",n||"open"),u.set("per_page",String(c||30)),u.set("sort",a||"updated"),u.set("direction",d||"desc"),e&&u.set("labels",Array.isArray(e)?e.join(","):e),i&&u.set("since",i),o&&u.set("assignee",o);let m=await l(`/repos/${t}/${r}/issues?${u.toString()}`),b=(Array.isArray(m)?m:[]).filter(h=>!h.pull_request).map(h=>({number:h.number,title:h.title,state:h.state,labels:(h.labels||[]).map(y=>typeof y=="string"?y:y.name),assignee:h.assignee?.login||null,assignees:(h.assignees||[]).map(y=>y.login),user:h.user?.login,comments:h.comments,url:h.html_url,createdAt:h.created_at,updatedAt:h.updated_at}));return JSON.stringify({count:b.length,issues:b})}case"github_get_issue":{let{owner:t,repo:r,number:n}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${r}/issues/${n}`);return e.pull_request?JSON.stringify({error:`#${n} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:e.number,title:e.title,body:e.body||"",state:e.state,stateReason:e.state_reason||null,labels:(e.labels||[]).map(i=>typeof i=="string"?i:i.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(i=>i.login),user:e.user?.login,milestone:e.milestone?.title||null,comments:e.comments,url:e.html_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"github_get_issue_comments":{let{owner:t,repo:r,number:n,limit:e}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await l(`/repos/${t}/${r}/issues/${n}/comments?per_page=${e||100}`),o=(Array.isArray(i)?i:[]).map(a=>({id:a.id,user:a.user?.login,body:a.body||"",createdAt:a.created_at,updatedAt:a.updated_at,url:a.html_url}));return JSON.stringify({count:o.length,comments:o})}case"github_add_issue_comment":{let{owner:t,repo:r,number:n,body:e}=s||{};if(!t||!r||!n||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let i=await l(`/repos/${t}/${r}/issues/${n}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:i.id,url:i.html_url})}case"github_close_issue":{let{owner:t,repo:r,number:n,stateReason:e}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i={state:"closed"};e&&(i.state_reason=e);let o=await l(`/repos/${t}/${r}/issues/${n}`,{method:"PATCH",body:i});return JSON.stringify({ok:!0,number:o.number,state:o.state,stateReason:o.state_reason||null,url:o.html_url})}case"github_reopen_issue":{let{owner:t,repo:r,number:n}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${r}/issues/${n}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:e.number,state:e.state,url:e.html_url})}case"github_label_issue":{let{owner:t,repo:r,number:n,labels:e,mode:i}=s||{};if(!t||!r||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o=Array.isArray(e)?e:e?[e]:[];if(!o.length)return JSON.stringify({error:"labels (string or array) is required"});let a=i||"add";if(a==="set"){let c=await l(`/repos/${t}/${r}/issues/${n}`,{method:"PATCH",body:{labels:o}});return JSON.stringify({ok:!0,number:c.number,labels:(c.labels||[]).map(u=>typeof u=="string"?u:u.name)})}if(a==="remove"){for(let u of o)await l(`/repos/${t}/${r}/issues/${n}/labels/${encodeURIComponent(u)}`,{method:"DELETE"});let c=await l(`/repos/${t}/${r}/issues/${n}`);return JSON.stringify({ok:!0,number:c.number,labels:(c.labels||[]).map(u=>typeof u=="string"?u:u.name)})}let d=await l(`/repos/${t}/${r}/issues/${n}/labels`,{method:"POST",body:{labels:o}});return JSON.stringify({ok:!0,number:n,labels:(Array.isArray(d)?d:[]).map(c=>typeof c=="string"?c:c.name)})}default:return JSON.stringify({error:`Unknown tool: ${p}`})}}catch(t){return JSON.stringify({error:t.message})}},tools:[{name:"github_get_user",description:"Get the authenticated GitHub user profile and their organizations",input_schema:{type:"object",properties:{}}},{name:"github_list_orgs",description:"List GitHub organizations the authenticated user belongs to",input_schema:{type:"object",properties:{}}},{name:"github_list_repos",description:"List the repositories this token/installation can access (omit owner) \u2014 or a specific user/org's repos (pass owner). Use this to discover a RELATED repo worth cloning when a change's correctness depends on another accessible repo. Each repo carries a normalized { fullPath, name, webUrl, defaultBranch, visibility } shape (identical to gitlab_list_projects) alongside legacy fields, plus a truncated flag.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Org or user login. Omit to list every repo your token/installation can access."},query:{type:"string",description:"Optional term matched against repo name/full-name/description"},type:{type:"string",enum:["all","public","private","forks","sources","member"],description:"Filter by type (default: all)"},sort:{type:"string",enum:["created","updated","pushed","full_name"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max repos to return (default: 200, hard-capped at the fetch ceiling)"}}}},{name:"github_clone",description:'Clone a GitHub repository to the local filesystem. Use when user says "check out" or "clone" a repo.',input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner (user or org name)"},repo:{type:"string",description:"Repository name"},destination:{type:"string",description:"Destination directory. Accepts absolute paths, ~-prefixed paths, or relative names. Defaults to ~/zibby-repos/<repo>."}},required:["owner","repo"]}},{name:"github_search_repos",description:"Search accessible repositories by name or description. Use this when the user asks to find a specific repo.",input_schema:{type:"object",properties:{query:{type:"string",description:'Search term to match against repo name or description (e.g., "electron", "my-app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_issues",description:"Search GitHub issues and pull requests",input_schema:{type:"object",properties:{query:{type:"string",description:'GitHub search query (e.g. "SCRUM-123", "login bug repo:org/app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_code",description:"Search code across GitHub repositories by keyword",input_schema:{type:"object",properties:{query:{type:"string",description:'Code search query (e.g. "handleLogin", "class AuthService")'},repo:{type:"string",description:'Scope to a specific repo (e.g. "org/app"). Optional.'},language:{type:"string",description:'Filter by language (e.g. "javascript", "python"). Optional.'},limit:{type:"number",description:"Max results (default: 15)"}},required:["query"]}},{name:"github_get_pr",description:"Get details of a pull request \u2014 title, description, branch, stats",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_get_pr_diff",description:"Get the unified diff of a pull request \u2014 the actual code changes",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_files",description:"List files changed in a PR with per-file patches",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_comments",description:"Get all review and issue comments on a PR",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_get_review_thread",description:"Read a PR review-comment THREAD given any comment id in it: the root review comment + all its replies, plus the anchored diff context (file, line, the original diff hunk). Use this to understand a human's reply to a previous review comment before replying in-thread.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},commentId:{type:"number",description:"Any review-comment id in the thread (the root or any reply)"}},required:["owner","repo","number","commentId"]}},{name:"github_reply_review_thread",description:"Reply IN-THREAD to an existing PR review-comment thread (a conversational reply nested under the thread the human commented on \u2014 NOT a fresh full review). Pass any comment id in the thread.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},commentId:{type:"number",description:"Any review-comment id in the thread to reply to"},body:{type:"string",description:"The reply text (markdown)"}},required:["owner","repo","number","commentId","body"]}},{name:"github_reply_issue_comment",description:"Post a reply on a PR's top-level conversation (a new issue comment on the PR). Use when the human replied to a non-inline/summary comment rather than an inline review thread. Quote or @-mention for context since issue comments are not threaded.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},body:{type:"string",description:"The reply text (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_create_review",description:"Post a review on a pull request: a summary body plus optional inline comments anchored to file/line, with an event (COMMENT, APPROVE, or REQUEST_CHANGES). Use this to deliver a code review back to the PR.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},body:{type:"string",description:"The review summary (markdown). Shown as the top-level review comment."},event:{type:"string",enum:["COMMENT","APPROVE","REQUEST_CHANGES"],description:"Review verdict. Default COMMENT (no approval state). Use REQUEST_CHANGES for blocking issues."},comments:{type:"array",description:"Optional inline comments, each anchored to a changed line.",items:{type:"object",properties:{path:{type:"string",description:"File path as it appears in the diff"},line:{type:"number",description:"Line number in the file's NEW version (the right side of the diff)"},side:{type:"string",enum:["LEFT","RIGHT"],description:"RIGHT (new) or LEFT (old). Default RIGHT."},body:{type:"string",description:"The inline comment text (markdown)"}},required:["path","line","body"]}}},required:["owner","repo","number"]}},{name:"github_list_commits",description:"List 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_pr",description:"Open a pull request on GitHub (POST /repos/{owner}/{repo}/pulls). The head (source) branch must already be pushed. Returns the REAL pr_url from GitHub \u2014 never fabricate a PR url. Expected business outcomes (no commits between base and head, a PR already exists for this branch, base==head, missing head) return { success:false, skippedReason } rather than erroring.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},head:{type:"string",description:'Source branch to merge FROM (must already be pushed). For a cross-fork PR use "fork-owner:branch".'},base:{type:"string",description:"Target branch to merge INTO (default: the repo's default branch)"},title:{type:"string",description:"PR title"},body:{type:"string",description:"PR description (markdown)"},draft:{type:"boolean",description:"Open as a draft PR (default: false)"}},required:["owner","repo","head","title"]}},{name:"github_merge_pr",description:"Merge a pull request on GitHub (PUT /repos/{owner}/{repo}/pulls/{number}/merge). mergeMethod is merge | squash | rebase (default squash). Returns { success:true, merged:true, sha } with the REAL merge SHA from GitHub. Expected non-mergeable outcomes (405 = draft / failing checks / branch protection, 409 = head sha moved / conflict, 404 = not found) return { success:false, skippedReason } rather than erroring.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number to merge"},mergeMethod:{type:"string",enum:["merge","squash","rebase"],description:"How to merge (default: squash)"},commitTitle:{type:"string",description:"Title for the merge/squash commit (optional)"},commitMessage:{type:"string",description:"Body for the merge/squash commit (optional)"}},required:["owner","repo","number"]}},{name:"github_create_issue",description:"Create a GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},title:{type:"string",description:"Issue title"},body:{type:"string",description:"Issue body (markdown)"}},required:["owner","repo","title"]}},{name:"github_list_issues",description:"List issues in a repo (excludes pull requests). Filter by state, labels, and an updated-since cursor for polling.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},state:{type:"string",enum:["open","closed","all"],description:"Filter by state (default: open)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},since:{type:"string",description:"ISO-8601 timestamp; only issues updated at/after this (polling cursor)"},assignee:{type:"string",description:'Filter by assignee login, "none", or "*"'},sort:{type:"string",enum:["created","updated","comments"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30, max 100 per page)"}},required:["owner","repo"]}},{name:"github_get_issue",description:"Get a single GitHub issue with full detail (title, body, state, labels, assignee, url)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_get_issue_comments",description:"Get the comment thread on a GitHub issue (chronological)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},limit:{type:"number",description:"Max comments (default: 100)"}},required:["owner","repo","number"]}},{name:"github_add_issue_comment",description:"Add a comment to a GitHub issue. Also the way to record a PR link on an issue (post a markdown link).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},body:{type:"string",description:"Comment body (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_close_issue",description:"Close a GitHub issue. Optionally set the close reason (completed or not_planned).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},stateReason:{type:"string",enum:["completed","not_planned"],description:"Why the issue was closed (optional)"}},required:["owner","repo","number"]}},{name:"github_reopen_issue",description:"Reopen a closed GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_label_issue",description:"Add, set (replace all), or remove labels on a GitHub issue. Labels back state-like transitions on GitHub.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},labels:{type:"array",items:{type:"string"},description:"Label name(s)"},mode:{type:"string",enum:["add","set","remove"],description:"add appends, set replaces all, remove deletes (default: add)"}},required:["owner","repo","number","labels"]}}]};var L=/\b(blocked|on[\s-]?hold|waiting|stuck)\b/i,x=/\b(in[\s-]?progress|wip|doing|started|in[\s-]?review|review)\b/i,K=/\b(done|closed|complete|completed|resolved|fixed|merged|shipped)\b/i,W=/\b(todo|to[\s-]?do|open|backlog|reopen|new)\b/i,I="in progress",J="blocked";function U(p,s=[]){if(p==="closed")return"done";if(p!=="open")return"unknown";let t=(s||[]).map(String);return t.some(r=>L.test(r))?"blocked":t.some(r=>x.test(r))?"in_progress":"todo"}function $(p={}){let s=p.owner||process.env.GITHUB_OWNER,t=p.repo||process.env.GITHUB_REPO;if(!s||!t)throw new Error("GitHub scope missing: provide {owner, repo} via ctx or env GITHUB_OWNER / GITHUB_REPO.");return{owner:s,repo:t}}function S(p){let s=JSON.parse(p);if(s&&s.error)throw new Error(s.error);return s}function k(p,s={}){let t=p.labels||[],r=p.number,n=s.owner&&s.repo?`${s.owner}/${s.repo}#${r}`:`#${r}`;return{id:String(r),key:n,title:p.title||"",body:p.body||"",state:p.state||null,stateCategory:U(p.state,t),assignee:p.assignee||p.assignees&&p.assignees[0]||null,url:p.url||null,_raw:p}}var Q={id:"github",toStateCategory:U,toNeutral:k,IN_PROGRESS_LABEL:I,BLOCKED_LABEL:J,async listCandidates(p={}){let s=p.ctx||{},{owner:t,repo:r}=$(s);return(S(await _.handleToolCall("github_list_issues",{owner:t,repo:r,state:p.state||"open",labels:p.labels,since:p.updatedAfter,limit:p.limit})).issues||[]).map(e=>k(e,{owner:t,repo:r}))},async getTicket(p,s={}){let{owner:t,repo:r}=$(s),n=P(p);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);let e=JSON.parse(await _.handleToolCall("github_get_issue",{owner:t,repo:r,number:n}));return e.error?null:k(e,{owner:t,repo:r})},async getComments(p,s={}){let{owner:t,repo:r}=$(s),n=P(p);if(n==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);return(S(await _.handleToolCall("github_get_issue_comments",{owner:t,repo:r,number:n})).comments||[]).map(i=>({id:String(i.id),author:i.user||"Unknown",body:i.body||"",createdAt:i.createdAt||null,updatedAt:i.updatedAt||null,_raw:i})).sort((i,o)=>String(o.createdAt).localeCompare(String(i.createdAt)))},async addComment(p,s,t={}){let{owner:r,repo:n}=$(t),e=P(p);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);if(!s)throw new Error("body is required");let i=S(await _.handleToolCall("github_add_issue_comment",{owner:r,repo:n,number:e,body:s}));return{ok:!!i.ok,id:i.id?String(i.id):null}},async transition(p,s,t={}){let{owner:r,repo:n}=$(t),e=P(p);if(e==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);let i=String(s||"");if(K.test(i)){let o=S(await _.handleToolCall("github_close_issue",{owner:r,repo:n,number:e,stateReason:"completed"}));return{ok:!!o.ok,stateAfter:o.state||"closed",stateCategoryAfter:"done",_raw:o}}if(L.test(i)){await H(r,n,e);let o=S(await _.handleToolCall("github_label_issue",{owner:r,repo:n,number:e,labels:[J],mode:"add"}));return{ok:!!o.ok,stateAfter:"open",stateCategoryAfter:"blocked",via:"label",_raw:o}}if(x.test(i)){await H(r,n,e);let o=S(await _.handleToolCall("github_label_issue",{owner:r,repo:n,number:e,labels:[I],mode:"add"}));return{ok:!!o.ok,stateAfter:"open",stateCategoryAfter:"in_progress",via:"label",_raw:o}}if(W.test(i)){let o=S(await _.handleToolCall("github_reopen_issue",{owner:r,repo:n,number:e}));return{ok:!!o.ok,stateAfter:o.state||"open",stateCategoryAfter:"todo",_raw:o}}return{ok:!1,error:`GitHub issues have no "${s}" state. Representable targets: open/todo, in progress, blocked, done/closed.`}},async linkPullRequest(p,s,t,r={}){let{owner:n,repo:e}=$(r),i=P(p);if(i==null)throw new Error(`Cannot parse GitHub issue number from "${p}"`);if(!s)throw new Error("prUrl is required");let o=`${t?`${t}: `:"Linked PR: "}${s}`;return{ok:!!S(await _.handleToolCall("github_add_issue_comment",{owner:n,repo:e,number:i,body:o})).ok,via:"comment"}}};async function H(p,s,t){await _.handleToolCall("github_reopen_issue",{owner:p,repo:s,number:t})}function P(p){if(p==null)return null;if(typeof p=="number")return p;let s=/(\d+)\s*$/.exec(String(p));return s?Number(s[1]):null}var se=Q;export{se as default,Q as githubAdapter};
|