@github-tools/sdk 1.6.0 → 1.8.0
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/README.md +150 -10
- package/dist/connect/eve.d.mts +17 -0
- package/dist/connect/eve.d.mts.map +1 -0
- package/dist/connect/eve.mjs +27 -0
- package/dist/connect/eve.mjs.map +1 -0
- package/dist/connect.d.mts +46 -0
- package/dist/connect.d.mts.map +1 -0
- package/dist/connect.mjs +22 -0
- package/dist/connect.mjs.map +1 -0
- package/dist/eve-B-LChKzS.mjs +526 -0
- package/dist/eve-B-LChKzS.mjs.map +1 -0
- package/dist/eve.d.mts +125 -0
- package/dist/eve.d.mts.map +1 -0
- package/dist/eve.mjs +3 -0
- package/dist/index-SZCaP-y9.d.mts +220 -0
- package/dist/index-SZCaP-y9.d.mts.map +1 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +3 -2
- package/dist/src-CfzZfU82.mjs +812 -0
- package/dist/src-CfzZfU82.mjs.map +1 -0
- package/dist/token-CW8lQBND.mjs +100 -0
- package/dist/token-CW8lQBND.mjs.map +1 -0
- package/dist/tool-types-C0kszIwd.d.mts +249 -0
- package/dist/tool-types-C0kszIwd.d.mts.map +1 -0
- package/dist/types-BTanS_dq.d.mts +49 -0
- package/dist/types-BTanS_dq.d.mts.map +1 -0
- package/dist/types-DOeq0Iia.d.mts +27 -0
- package/dist/types-DOeq0Iia.d.mts.map +1 -0
- package/dist/workflow.d.mts +53 -730
- package/dist/workflow.d.mts.map +1 -1
- package/dist/workflow.mjs +14 -74
- package/dist/workflow.mjs.map +1 -1
- package/dist/write-tools-Dx9LfYlU.mjs +1840 -0
- package/dist/write-tools-Dx9LfYlU.mjs.map +1 -0
- package/package.json +40 -8
- package/dist/index-ikP-LT-3.d.mts +0 -1634
- package/dist/index-ikP-LT-3.d.mts.map +0 -1
- package/dist/src--pAdGYqY.mjs +0 -1961
- package/dist/src--pAdGYqY.mjs.map +0 -1
|
@@ -0,0 +1,1840 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Octokit } from "octokit";
|
|
3
|
+
//#region src/client.ts
|
|
4
|
+
/** @see https://docs.github.com/en/rest/about-the-rest-api/api-versions */
|
|
5
|
+
const GITHUB_API_VERSION = "2026-03-10";
|
|
6
|
+
function createOctokit(token) {
|
|
7
|
+
const octokit = new Octokit({ auth: token });
|
|
8
|
+
octokit.hook.before("request", (options) => {
|
|
9
|
+
options.headers = {
|
|
10
|
+
...options.headers,
|
|
11
|
+
"X-GitHub-Api-Version": GITHUB_API_VERSION
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
return octokit;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/core/sha1.ts
|
|
18
|
+
/** SHA-1 hex digest without Node.js `crypto` (safe in workflow bundles). */
|
|
19
|
+
function sha1Hex(data) {
|
|
20
|
+
const words = new Uint32Array(80);
|
|
21
|
+
const bitLength = data.length * 8;
|
|
22
|
+
const padded = new Uint8Array(data.length + 9 + 63 >> 6 << 6);
|
|
23
|
+
padded.set(data);
|
|
24
|
+
padded[data.length] = 128;
|
|
25
|
+
const view = new DataView(padded.buffer);
|
|
26
|
+
view.setUint32(padded.length - 4, bitLength >>> 0, false);
|
|
27
|
+
view.setUint32(padded.length - 8, Math.floor(bitLength / 4294967296), false);
|
|
28
|
+
let h0 = 1732584193;
|
|
29
|
+
let h1 = 4023233417;
|
|
30
|
+
let h2 = 2562383102;
|
|
31
|
+
let h3 = 271733878;
|
|
32
|
+
let h4 = 3285377520;
|
|
33
|
+
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
34
|
+
for (let j = 0; j < 16; j++) words[j] = view.getUint32(offset + j * 4, false);
|
|
35
|
+
for (let j = 16; j < 80; j++) words[j] = rotl(words[j - 3] ^ words[j - 8] ^ words[j - 14] ^ words[j - 16], 1);
|
|
36
|
+
let a = h0;
|
|
37
|
+
let b = h1;
|
|
38
|
+
let c = h2;
|
|
39
|
+
let d = h3;
|
|
40
|
+
let e = h4;
|
|
41
|
+
for (let j = 0; j < 80; j++) {
|
|
42
|
+
let f;
|
|
43
|
+
let k;
|
|
44
|
+
if (j < 20) {
|
|
45
|
+
f = b & c | ~b & d;
|
|
46
|
+
k = 1518500249;
|
|
47
|
+
} else if (j < 40) {
|
|
48
|
+
f = b ^ c ^ d;
|
|
49
|
+
k = 1859775393;
|
|
50
|
+
} else if (j < 60) {
|
|
51
|
+
f = b & c | b & d | c & d;
|
|
52
|
+
k = 2400959708;
|
|
53
|
+
} else {
|
|
54
|
+
f = b ^ c ^ d;
|
|
55
|
+
k = 3395469782;
|
|
56
|
+
}
|
|
57
|
+
const temp = rotl(a, 5) + f + e + k + words[j] >>> 0;
|
|
58
|
+
e = d;
|
|
59
|
+
d = c;
|
|
60
|
+
c = rotl(b, 30);
|
|
61
|
+
b = a;
|
|
62
|
+
a = temp;
|
|
63
|
+
}
|
|
64
|
+
h0 = h0 + a >>> 0;
|
|
65
|
+
h1 = h1 + b >>> 0;
|
|
66
|
+
h2 = h2 + c >>> 0;
|
|
67
|
+
h3 = h3 + d >>> 0;
|
|
68
|
+
h4 = h4 + e >>> 0;
|
|
69
|
+
}
|
|
70
|
+
return [
|
|
71
|
+
h0,
|
|
72
|
+
h1,
|
|
73
|
+
h2,
|
|
74
|
+
h3,
|
|
75
|
+
h4
|
|
76
|
+
].map((word) => word.toString(16).padStart(8, "0")).join("");
|
|
77
|
+
}
|
|
78
|
+
function rotl(value, bits) {
|
|
79
|
+
return (value << bits | value >>> 32 - bits) >>> 0;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/core/git-blob-sha.ts
|
|
83
|
+
/** Compute the git blob SHA (SHA-1 of "blob {size}\\0{content}") for a given string. */
|
|
84
|
+
function gitBlobSha(content) {
|
|
85
|
+
const contentBytes = new TextEncoder().encode(content);
|
|
86
|
+
const header = new TextEncoder().encode(`blob ${contentBytes.length}\0`);
|
|
87
|
+
const payload = new Uint8Array(header.length + contentBytes.length);
|
|
88
|
+
payload.set(header);
|
|
89
|
+
payload.set(contentBytes, header.length);
|
|
90
|
+
return sha1Hex(payload);
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/core/repository.ts
|
|
94
|
+
const CREATE_COMMIT_ON_BRANCH_MUTATION = `
|
|
95
|
+
mutation CreateCommitOnBranch($input: CreateCommitOnBranchInput!) {
|
|
96
|
+
createCommitOnBranch(input: $input) { commit { oid url } }
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
var CreateCommitOnBranchError = class extends Error {
|
|
100
|
+
constructor(message, reason) {
|
|
101
|
+
super(message);
|
|
102
|
+
this.reason = reason;
|
|
103
|
+
this.name = "CreateCommitOnBranchError";
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
async function createCommitOnBranch(octokit, input) {
|
|
107
|
+
try {
|
|
108
|
+
const result = await octokit.graphql(CREATE_COMMIT_ON_BRANCH_MUTATION, { input: {
|
|
109
|
+
branch: {
|
|
110
|
+
repositoryNameWithOwner: `${input.owner}/${input.repo}`,
|
|
111
|
+
branchName: input.branch
|
|
112
|
+
},
|
|
113
|
+
expectedHeadOid: input.expectedHeadOid,
|
|
114
|
+
message: input.body ? {
|
|
115
|
+
headline: input.headline,
|
|
116
|
+
body: input.body
|
|
117
|
+
} : { headline: input.headline },
|
|
118
|
+
fileChanges: {
|
|
119
|
+
additions: input.additions,
|
|
120
|
+
deletions: input.deletions
|
|
121
|
+
}
|
|
122
|
+
} });
|
|
123
|
+
return {
|
|
124
|
+
commitSha: result.createCommitOnBranch.commit.oid,
|
|
125
|
+
commitUrl: result.createCommitOnBranch.commit.url
|
|
126
|
+
};
|
|
127
|
+
} catch (error) {
|
|
128
|
+
const err = error;
|
|
129
|
+
const types = new Set((err.errors ?? []).map((e) => e.type));
|
|
130
|
+
if (types.has("STALE_DATA")) throw new CreateCommitOnBranchError(err.message ?? "Stale data", "stale_data");
|
|
131
|
+
if (types.has("FORBIDDEN") || types.has("INSUFFICIENT_SCOPES") || err.status === 401 || err.status === 403) throw new CreateCommitOnBranchError(err.message ?? "Forbidden", "forbidden");
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function composeCommitMessage(message, coAuthors) {
|
|
136
|
+
if (!coAuthors?.length) return message;
|
|
137
|
+
const trailers = coAuthors.map(({ name, email }) => `Co-authored-by: ${name} <${email}>`).join("\n");
|
|
138
|
+
return message ? `${message}\n\n${trailers}` : trailers;
|
|
139
|
+
}
|
|
140
|
+
const getRepositoryInputSchema = z.object({
|
|
141
|
+
owner: z.string().describe("Repository owner (user or organization)"),
|
|
142
|
+
repo: z.string().describe("Repository name")
|
|
143
|
+
});
|
|
144
|
+
const getRepositoryDescription = "Get information about a GitHub repository including description, stars, forks, language, and default branch";
|
|
145
|
+
async function getRepositoryCore({ token, owner, repo }) {
|
|
146
|
+
const { data } = await createOctokit(token).rest.repos.get({
|
|
147
|
+
owner,
|
|
148
|
+
repo
|
|
149
|
+
});
|
|
150
|
+
return {
|
|
151
|
+
name: data.name,
|
|
152
|
+
fullName: data.full_name,
|
|
153
|
+
description: data.description,
|
|
154
|
+
url: data.html_url,
|
|
155
|
+
defaultBranch: data.default_branch,
|
|
156
|
+
stars: data.stargazers_count,
|
|
157
|
+
forks: data.forks_count,
|
|
158
|
+
openIssues: data.open_issues_count,
|
|
159
|
+
language: data.language,
|
|
160
|
+
private: data.private,
|
|
161
|
+
createdAt: data.created_at,
|
|
162
|
+
updatedAt: data.updated_at
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const listBranchesInputSchema = z.object({
|
|
166
|
+
owner: z.string().describe("Repository owner"),
|
|
167
|
+
repo: z.string().describe("Repository name"),
|
|
168
|
+
perPage: z.number().optional().default(30).describe("Number of branches to return (max 100)")
|
|
169
|
+
});
|
|
170
|
+
const listBranchesDescription = "List branches in a GitHub repository";
|
|
171
|
+
async function listBranchesCore({ token, owner, repo, perPage }) {
|
|
172
|
+
const { data } = await createOctokit(token).rest.repos.listBranches({
|
|
173
|
+
owner,
|
|
174
|
+
repo,
|
|
175
|
+
per_page: perPage
|
|
176
|
+
});
|
|
177
|
+
return data.map((branch) => ({
|
|
178
|
+
name: branch.name,
|
|
179
|
+
sha: branch.commit.sha,
|
|
180
|
+
protected: branch.protected
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
const getFileContentInputSchema = z.object({
|
|
184
|
+
owner: z.string().describe("Repository owner"),
|
|
185
|
+
repo: z.string().describe("Repository name"),
|
|
186
|
+
path: z.string().describe("Path to the file in the repository"),
|
|
187
|
+
ref: z.string().optional().describe("Branch, tag, or commit SHA (defaults to the default branch)")
|
|
188
|
+
});
|
|
189
|
+
const getFileContentDescription = "Get the content of a file from a GitHub repository";
|
|
190
|
+
async function getFileContentCore({ token, owner, repo, path, ref }) {
|
|
191
|
+
const { data } = await createOctokit(token).rest.repos.getContent({
|
|
192
|
+
owner,
|
|
193
|
+
repo,
|
|
194
|
+
path,
|
|
195
|
+
ref
|
|
196
|
+
});
|
|
197
|
+
if (Array.isArray(data)) return {
|
|
198
|
+
type: "directory",
|
|
199
|
+
entries: data.map((e) => ({
|
|
200
|
+
name: e.name,
|
|
201
|
+
type: e.type,
|
|
202
|
+
path: e.path
|
|
203
|
+
}))
|
|
204
|
+
};
|
|
205
|
+
if (data.type !== "file") return {
|
|
206
|
+
type: data.type,
|
|
207
|
+
path: data.path
|
|
208
|
+
};
|
|
209
|
+
const content = Buffer.from(data.content, "base64").toString("utf-8");
|
|
210
|
+
return {
|
|
211
|
+
type: "file",
|
|
212
|
+
path: data.path,
|
|
213
|
+
sha: data.sha,
|
|
214
|
+
size: data.size,
|
|
215
|
+
content
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
const createBranchInputSchema = z.object({
|
|
219
|
+
owner: z.string().describe("Repository owner"),
|
|
220
|
+
repo: z.string().describe("Repository name"),
|
|
221
|
+
branch: z.string().describe("Name for the new branch"),
|
|
222
|
+
from: z.string().optional().describe("Source branch name or commit SHA to branch from (defaults to the default branch)")
|
|
223
|
+
});
|
|
224
|
+
const createBranchDescription = "Create a new branch in a GitHub repository from an existing branch or commit SHA";
|
|
225
|
+
/** Idempotent when the branch already exists at the target SHA. Not idempotent otherwise. */
|
|
226
|
+
async function createBranchCore({ token, owner, repo, branch, from }) {
|
|
227
|
+
const octokit = createOctokit(token);
|
|
228
|
+
let sha = from;
|
|
229
|
+
if (!sha || !sha.match(/^[0-9a-f]{40}$/i)) {
|
|
230
|
+
const { data: ref } = await octokit.rest.git.getRef({
|
|
231
|
+
owner,
|
|
232
|
+
repo,
|
|
233
|
+
ref: `heads/${from || (await octokit.rest.repos.get({
|
|
234
|
+
owner,
|
|
235
|
+
repo
|
|
236
|
+
})).data.default_branch}`
|
|
237
|
+
});
|
|
238
|
+
sha = ref.object.sha;
|
|
239
|
+
}
|
|
240
|
+
try {
|
|
241
|
+
const { data: existingRef } = await octokit.rest.git.getRef({
|
|
242
|
+
owner,
|
|
243
|
+
repo,
|
|
244
|
+
ref: `heads/${branch}`
|
|
245
|
+
});
|
|
246
|
+
if (existingRef.object.sha === sha) return {
|
|
247
|
+
ref: existingRef.ref,
|
|
248
|
+
sha: existingRef.object.sha,
|
|
249
|
+
url: existingRef.url
|
|
250
|
+
};
|
|
251
|
+
} catch {}
|
|
252
|
+
const { data } = await octokit.rest.git.createRef({
|
|
253
|
+
owner,
|
|
254
|
+
repo,
|
|
255
|
+
ref: `refs/heads/${branch}`,
|
|
256
|
+
sha
|
|
257
|
+
});
|
|
258
|
+
return {
|
|
259
|
+
ref: data.ref,
|
|
260
|
+
sha: data.object.sha,
|
|
261
|
+
url: data.url
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
const forkRepositoryInputSchema = z.object({
|
|
265
|
+
owner: z.string().describe("Repository owner to fork from"),
|
|
266
|
+
repo: z.string().describe("Repository name to fork"),
|
|
267
|
+
organization: z.string().optional().describe("Organization to fork into (omit to fork to your personal account)"),
|
|
268
|
+
name: z.string().optional().describe("Name for the forked repository (defaults to the original name)")
|
|
269
|
+
});
|
|
270
|
+
const forkRepositoryDescription = "Fork a GitHub repository to the authenticated user account or a specified organization";
|
|
271
|
+
/** Not idempotent — each call may create another fork attempt. */
|
|
272
|
+
async function forkRepositoryCore({ token, owner, repo, organization, name }) {
|
|
273
|
+
const { data } = await createOctokit(token).rest.repos.createFork({
|
|
274
|
+
owner,
|
|
275
|
+
repo,
|
|
276
|
+
organization,
|
|
277
|
+
name
|
|
278
|
+
});
|
|
279
|
+
return {
|
|
280
|
+
name: data.name,
|
|
281
|
+
fullName: data.full_name,
|
|
282
|
+
url: data.html_url,
|
|
283
|
+
cloneUrl: data.clone_url,
|
|
284
|
+
sshUrl: data.ssh_url,
|
|
285
|
+
defaultBranch: data.default_branch,
|
|
286
|
+
private: data.private,
|
|
287
|
+
parent: data.parent ? {
|
|
288
|
+
fullName: data.parent.full_name,
|
|
289
|
+
url: data.parent.html_url
|
|
290
|
+
} : null
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
const createRepositoryInputSchema = z.object({
|
|
294
|
+
name: z.string().describe("Repository name"),
|
|
295
|
+
description: z.string().optional().describe("A short description of the repository"),
|
|
296
|
+
isPrivate: z.boolean().optional().default(false).describe("Whether the repository is private"),
|
|
297
|
+
autoInit: z.boolean().optional().default(false).describe("Create an initial commit with a README"),
|
|
298
|
+
gitignoreTemplate: z.string().optional().describe("Gitignore template to use (e.g. \"Node\", \"Python\")"),
|
|
299
|
+
licenseTemplate: z.string().optional().describe("License keyword (e.g. \"mit\", \"apache-2.0\")"),
|
|
300
|
+
org: z.string().optional().describe("Organization to create the repository in (omit for personal repo)")
|
|
301
|
+
});
|
|
302
|
+
const createRepositoryDescription = "Create a new GitHub repository for the authenticated user or a specified organization";
|
|
303
|
+
/** Not idempotent — each call creates a new repository. */
|
|
304
|
+
async function createRepositoryCore({ token, name, description, isPrivate, autoInit, gitignoreTemplate, licenseTemplate, org }) {
|
|
305
|
+
const octokit = createOctokit(token);
|
|
306
|
+
const params = {
|
|
307
|
+
name,
|
|
308
|
+
description,
|
|
309
|
+
private: isPrivate,
|
|
310
|
+
auto_init: autoInit,
|
|
311
|
+
gitignore_template: gitignoreTemplate,
|
|
312
|
+
license_template: licenseTemplate
|
|
313
|
+
};
|
|
314
|
+
const { data } = org ? await octokit.rest.repos.createInOrg({
|
|
315
|
+
org,
|
|
316
|
+
...params
|
|
317
|
+
}) : await octokit.rest.repos.createForAuthenticatedUser(params);
|
|
318
|
+
return {
|
|
319
|
+
name: data.name,
|
|
320
|
+
fullName: data.full_name,
|
|
321
|
+
description: data.description,
|
|
322
|
+
url: data.html_url,
|
|
323
|
+
cloneUrl: data.clone_url,
|
|
324
|
+
sshUrl: data.ssh_url,
|
|
325
|
+
defaultBranch: data.default_branch,
|
|
326
|
+
private: data.private,
|
|
327
|
+
createdAt: data.created_at
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
const createOrUpdateFileInputSchema = z.object({
|
|
331
|
+
owner: z.string().describe("Repository owner"),
|
|
332
|
+
repo: z.string().describe("Repository name"),
|
|
333
|
+
path: z.string().describe("Path to the file in the repository"),
|
|
334
|
+
message: z.string().describe("Commit message"),
|
|
335
|
+
content: z.string().describe("File content (plain text, will be base64-encoded automatically)"),
|
|
336
|
+
branch: z.string().optional().describe("Branch to commit to (defaults to the default branch)"),
|
|
337
|
+
sha: z.string().optional().describe("SHA of the file being replaced (required when updating an existing file)")
|
|
338
|
+
});
|
|
339
|
+
const createOrUpdateFileDescription = "Create or update a file in a GitHub repository. Provide the SHA when updating an existing file.";
|
|
340
|
+
/** Idempotent when updating with sha and content is unchanged. Not idempotent for new commits. */
|
|
341
|
+
async function createOrUpdateFileCore({ token, owner, repo, path, message, content, branch, sha, author, committer, coAuthors }) {
|
|
342
|
+
const octokit = createOctokit(token);
|
|
343
|
+
if (sha) {
|
|
344
|
+
const branchName = branch || (await octokit.rest.repos.get({
|
|
345
|
+
owner,
|
|
346
|
+
repo
|
|
347
|
+
})).data.default_branch;
|
|
348
|
+
try {
|
|
349
|
+
const { data: fileData } = await octokit.rest.repos.getContent({
|
|
350
|
+
owner,
|
|
351
|
+
repo,
|
|
352
|
+
path,
|
|
353
|
+
ref: branchName
|
|
354
|
+
});
|
|
355
|
+
if (!Array.isArray(fileData) && fileData.type === "file") {
|
|
356
|
+
if (Buffer.from(fileData.content, "base64").toString("utf-8") === content) return {
|
|
357
|
+
path: fileData.path,
|
|
358
|
+
sha: fileData.sha,
|
|
359
|
+
skipped: true,
|
|
360
|
+
message: "Content unchanged; no commit created"
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
} catch {}
|
|
364
|
+
}
|
|
365
|
+
if (!author && !committer) try {
|
|
366
|
+
const branchName = branch || (await octokit.rest.repos.get({
|
|
367
|
+
owner,
|
|
368
|
+
repo
|
|
369
|
+
})).data.default_branch;
|
|
370
|
+
const { data: ref } = await octokit.rest.git.getRef({
|
|
371
|
+
owner,
|
|
372
|
+
repo,
|
|
373
|
+
ref: `heads/${branchName}`
|
|
374
|
+
});
|
|
375
|
+
const [headline, ...rest] = composeCommitMessage(message, coAuthors).split("\n");
|
|
376
|
+
const body = rest.join("\n").replace(/^\n+/, "") || void 0;
|
|
377
|
+
const result = await createCommitOnBranch(octokit, {
|
|
378
|
+
owner,
|
|
379
|
+
repo,
|
|
380
|
+
branch: branchName,
|
|
381
|
+
expectedHeadOid: ref.object.sha,
|
|
382
|
+
headline,
|
|
383
|
+
body,
|
|
384
|
+
additions: [{
|
|
385
|
+
path,
|
|
386
|
+
contents: Buffer.from(content).toString("base64")
|
|
387
|
+
}]
|
|
388
|
+
});
|
|
389
|
+
return {
|
|
390
|
+
path,
|
|
391
|
+
sha: gitBlobSha(content),
|
|
392
|
+
commitSha: result.commitSha,
|
|
393
|
+
commitUrl: result.commitUrl
|
|
394
|
+
};
|
|
395
|
+
} catch (error) {
|
|
396
|
+
if (error instanceof CreateCommitOnBranchError && error.reason === "stale_data") throw error;
|
|
397
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
398
|
+
console.warn(`[github-tools] Signed commit failed, using REST API: ${msg}`);
|
|
399
|
+
}
|
|
400
|
+
const encoded = Buffer.from(content).toString("base64");
|
|
401
|
+
const finalMessage = composeCommitMessage(message, coAuthors);
|
|
402
|
+
const { data } = await octokit.rest.repos.createOrUpdateFileContents({
|
|
403
|
+
owner,
|
|
404
|
+
repo,
|
|
405
|
+
path,
|
|
406
|
+
message: finalMessage,
|
|
407
|
+
content: encoded,
|
|
408
|
+
branch,
|
|
409
|
+
sha,
|
|
410
|
+
author,
|
|
411
|
+
committer
|
|
412
|
+
});
|
|
413
|
+
return {
|
|
414
|
+
path: data.content?.path,
|
|
415
|
+
sha: data.content?.sha,
|
|
416
|
+
commitSha: data.commit.sha,
|
|
417
|
+
commitUrl: data.commit.html_url
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/core/model-output.ts
|
|
422
|
+
const MAX_PATCH_LENGTH = 4e3;
|
|
423
|
+
const MAX_CONTENT_LENGTH = 5e4;
|
|
424
|
+
function truncateText(text, maxLength) {
|
|
425
|
+
if (text.length <= maxLength) return text;
|
|
426
|
+
return `${text.slice(0, maxLength)}\n\n[truncated: ${text.length - maxLength} more characters]`;
|
|
427
|
+
}
|
|
428
|
+
function listPullRequestFilesToModelOutput({ output }) {
|
|
429
|
+
return {
|
|
430
|
+
type: "json",
|
|
431
|
+
value: output.map((file) => ({
|
|
432
|
+
...file,
|
|
433
|
+
patch: file.patch ? truncateText(file.patch, MAX_PATCH_LENGTH) : file.patch
|
|
434
|
+
}))
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function getCommitToModelOutput({ output }) {
|
|
438
|
+
const commit = output;
|
|
439
|
+
return {
|
|
440
|
+
type: "json",
|
|
441
|
+
value: {
|
|
442
|
+
...commit,
|
|
443
|
+
files: commit.files?.map((file) => ({
|
|
444
|
+
...file,
|
|
445
|
+
patch: file.patch ? truncateText(file.patch, MAX_PATCH_LENGTH) : file.patch
|
|
446
|
+
}))
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
function getFileContentToModelOutput({ output }) {
|
|
451
|
+
const result = output;
|
|
452
|
+
if ("content" in result && result.content.length > MAX_CONTENT_LENGTH) return {
|
|
453
|
+
type: "json",
|
|
454
|
+
value: {
|
|
455
|
+
...result,
|
|
456
|
+
content: truncateText(result.content, MAX_CONTENT_LENGTH)
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
return {
|
|
460
|
+
type: "json",
|
|
461
|
+
value: result
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/core/token.ts
|
|
466
|
+
const TOKEN_REQUIRED_ERROR = "GitHub token is required. Pass it as `token` or set the GITHUB_TOKEN environment variable.";
|
|
467
|
+
/**
|
|
468
|
+
* Normalizes a token string, async token provider, or `process.env.GITHUB_TOKEN`
|
|
469
|
+
* into a `() => Promise<string>` resolver.
|
|
470
|
+
*
|
|
471
|
+
* Throws immediately for static inputs when no token is available. Provider
|
|
472
|
+
* functions are validated lazily, each time the resolver is invoked.
|
|
473
|
+
*/
|
|
474
|
+
function createGithubTokenResolver(token) {
|
|
475
|
+
if (typeof token === "function") return async () => {
|
|
476
|
+
const resolvedToken = await token();
|
|
477
|
+
if (!resolvedToken) throw new Error(TOKEN_REQUIRED_ERROR);
|
|
478
|
+
return resolvedToken;
|
|
479
|
+
};
|
|
480
|
+
const resolvedToken = token || process.env.GITHUB_TOKEN;
|
|
481
|
+
if (!resolvedToken) throw new Error(TOKEN_REQUIRED_ERROR);
|
|
482
|
+
return async () => resolvedToken;
|
|
483
|
+
}
|
|
484
|
+
/** Resolves a {@link GithubTokenInput} to a token string. */
|
|
485
|
+
function resolveGithubToken(token) {
|
|
486
|
+
return createGithubTokenResolver(token)();
|
|
487
|
+
}
|
|
488
|
+
//#endregion
|
|
489
|
+
//#region src/core/pull-requests.ts
|
|
490
|
+
const listPullRequestsInputSchema = z.object({
|
|
491
|
+
owner: z.string().describe("Repository owner"),
|
|
492
|
+
repo: z.string().describe("Repository name"),
|
|
493
|
+
state: z.enum([
|
|
494
|
+
"open",
|
|
495
|
+
"closed",
|
|
496
|
+
"all"
|
|
497
|
+
]).optional().default("open").describe("Filter by state"),
|
|
498
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)")
|
|
499
|
+
});
|
|
500
|
+
const listPullRequestsDescription = "List pull requests for a GitHub repository";
|
|
501
|
+
async function listPullRequestsCore({ token, owner, repo, state, perPage }) {
|
|
502
|
+
const { data } = await createOctokit(token).rest.pulls.list({
|
|
503
|
+
owner,
|
|
504
|
+
repo,
|
|
505
|
+
state,
|
|
506
|
+
per_page: perPage
|
|
507
|
+
});
|
|
508
|
+
return data.map((pr) => ({
|
|
509
|
+
number: pr.number,
|
|
510
|
+
title: pr.title,
|
|
511
|
+
state: pr.state,
|
|
512
|
+
url: pr.html_url,
|
|
513
|
+
author: pr.user?.login,
|
|
514
|
+
branch: pr.head.ref,
|
|
515
|
+
base: pr.base.ref,
|
|
516
|
+
draft: pr.draft,
|
|
517
|
+
createdAt: pr.created_at,
|
|
518
|
+
updatedAt: pr.updated_at
|
|
519
|
+
}));
|
|
520
|
+
}
|
|
521
|
+
const getPullRequestInputSchema = z.object({
|
|
522
|
+
owner: z.string().describe("Repository owner"),
|
|
523
|
+
repo: z.string().describe("Repository name"),
|
|
524
|
+
pullNumber: z.number().describe("Pull request number")
|
|
525
|
+
});
|
|
526
|
+
const getPullRequestDescription = "Get detailed information about a specific pull request";
|
|
527
|
+
async function getPullRequestCore({ token, owner, repo, pullNumber }) {
|
|
528
|
+
const { data } = await createOctokit(token).rest.pulls.get({
|
|
529
|
+
owner,
|
|
530
|
+
repo,
|
|
531
|
+
pull_number: pullNumber
|
|
532
|
+
});
|
|
533
|
+
return {
|
|
534
|
+
number: data.number,
|
|
535
|
+
title: data.title,
|
|
536
|
+
body: data.body,
|
|
537
|
+
state: data.state,
|
|
538
|
+
url: data.html_url,
|
|
539
|
+
author: data.user?.login,
|
|
540
|
+
branch: data.head.ref,
|
|
541
|
+
base: data.base.ref,
|
|
542
|
+
draft: data.draft,
|
|
543
|
+
merged: data.merged,
|
|
544
|
+
mergeable: data.mergeable,
|
|
545
|
+
additions: data.additions,
|
|
546
|
+
deletions: data.deletions,
|
|
547
|
+
changedFiles: data.changed_files,
|
|
548
|
+
createdAt: data.created_at,
|
|
549
|
+
updatedAt: data.updated_at,
|
|
550
|
+
mergedAt: data.merged_at
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
const createPullRequestInputSchema = z.object({
|
|
554
|
+
owner: z.string().describe("Repository owner"),
|
|
555
|
+
repo: z.string().describe("Repository name"),
|
|
556
|
+
title: z.string().describe("Pull request title"),
|
|
557
|
+
body: z.string().optional().describe("Pull request description (supports Markdown)"),
|
|
558
|
+
head: z.string().describe("Branch containing the changes (format: branch or username:branch)"),
|
|
559
|
+
base: z.string().describe("Branch to merge into"),
|
|
560
|
+
draft: z.boolean().optional().default(false).describe("Create as draft pull request")
|
|
561
|
+
});
|
|
562
|
+
const createPullRequestDescription = "Create a new pull request in a GitHub repository";
|
|
563
|
+
/** Not idempotent — each call creates a new pull request. */
|
|
564
|
+
async function createPullRequestCore({ token, owner, repo, title, body, head, base, draft }) {
|
|
565
|
+
const { data } = await createOctokit(token).rest.pulls.create({
|
|
566
|
+
owner,
|
|
567
|
+
repo,
|
|
568
|
+
title,
|
|
569
|
+
body,
|
|
570
|
+
head,
|
|
571
|
+
base,
|
|
572
|
+
draft
|
|
573
|
+
});
|
|
574
|
+
return {
|
|
575
|
+
number: data.number,
|
|
576
|
+
title: data.title,
|
|
577
|
+
url: data.html_url,
|
|
578
|
+
state: data.state,
|
|
579
|
+
draft: data.draft,
|
|
580
|
+
branch: data.head.ref,
|
|
581
|
+
base: data.base.ref
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
const mergePullRequestInputSchema = z.object({
|
|
585
|
+
owner: z.string().describe("Repository owner"),
|
|
586
|
+
repo: z.string().describe("Repository name"),
|
|
587
|
+
pullNumber: z.number().describe("Pull request number"),
|
|
588
|
+
commitTitle: z.string().optional().describe("Title for the automatic merge commit"),
|
|
589
|
+
commitMessage: z.string().optional().describe("Extra detail to append to automatic commit message"),
|
|
590
|
+
mergeMethod: z.enum([
|
|
591
|
+
"merge",
|
|
592
|
+
"squash",
|
|
593
|
+
"rebase"
|
|
594
|
+
]).optional().default("merge").describe("Merge strategy")
|
|
595
|
+
});
|
|
596
|
+
const mergePullRequestDescription = "Merge a pull request";
|
|
597
|
+
/** Not idempotent — merging an already-merged PR returns an error from GitHub. */
|
|
598
|
+
async function mergePullRequestCore({ token, owner, repo, pullNumber, commitTitle, commitMessage, mergeMethod, coAuthors }) {
|
|
599
|
+
const octokit = createOctokit(token);
|
|
600
|
+
const finalMessage = composeCommitMessage(commitMessage ?? "", coAuthors) || void 0;
|
|
601
|
+
const { data } = await octokit.rest.pulls.merge({
|
|
602
|
+
owner,
|
|
603
|
+
repo,
|
|
604
|
+
pull_number: pullNumber,
|
|
605
|
+
commit_title: commitTitle,
|
|
606
|
+
commit_message: finalMessage,
|
|
607
|
+
merge_method: mergeMethod
|
|
608
|
+
});
|
|
609
|
+
return {
|
|
610
|
+
merged: data.merged,
|
|
611
|
+
message: data.message,
|
|
612
|
+
sha: data.sha
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
const addPullRequestCommentInputSchema = z.object({
|
|
616
|
+
owner: z.string().describe("Repository owner"),
|
|
617
|
+
repo: z.string().describe("Repository name"),
|
|
618
|
+
pullNumber: z.number().describe("Pull request number"),
|
|
619
|
+
body: z.string().describe("Comment text (supports Markdown)")
|
|
620
|
+
});
|
|
621
|
+
const addPullRequestCommentDescription = "Add a comment to a pull request";
|
|
622
|
+
/** Not idempotent — each call adds another comment. */
|
|
623
|
+
async function addPullRequestCommentCore({ token, owner, repo, pullNumber, body }) {
|
|
624
|
+
const { data } = await createOctokit(token).rest.issues.createComment({
|
|
625
|
+
owner,
|
|
626
|
+
repo,
|
|
627
|
+
issue_number: pullNumber,
|
|
628
|
+
body
|
|
629
|
+
});
|
|
630
|
+
return {
|
|
631
|
+
id: data.id,
|
|
632
|
+
url: data.html_url,
|
|
633
|
+
body: data.body,
|
|
634
|
+
author: data.user?.login,
|
|
635
|
+
createdAt: data.created_at
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
const listPullRequestFilesInputSchema = z.object({
|
|
639
|
+
owner: z.string().describe("Repository owner"),
|
|
640
|
+
repo: z.string().describe("Repository name"),
|
|
641
|
+
pullNumber: z.number().describe("Pull request number"),
|
|
642
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
643
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
644
|
+
});
|
|
645
|
+
const listPullRequestFilesDescription = "List files changed in a pull request, including diff status and patch content";
|
|
646
|
+
async function listPullRequestFilesCore({ token, owner, repo, pullNumber, perPage, page }) {
|
|
647
|
+
const { data } = await createOctokit(token).rest.pulls.listFiles({
|
|
648
|
+
owner,
|
|
649
|
+
repo,
|
|
650
|
+
pull_number: pullNumber,
|
|
651
|
+
per_page: perPage,
|
|
652
|
+
page
|
|
653
|
+
});
|
|
654
|
+
return data.map((file) => ({
|
|
655
|
+
filename: file.filename,
|
|
656
|
+
status: file.status,
|
|
657
|
+
additions: file.additions,
|
|
658
|
+
deletions: file.deletions,
|
|
659
|
+
changes: file.changes,
|
|
660
|
+
patch: file.patch
|
|
661
|
+
}));
|
|
662
|
+
}
|
|
663
|
+
const listPullRequestReviewsInputSchema = z.object({
|
|
664
|
+
owner: z.string().describe("Repository owner"),
|
|
665
|
+
repo: z.string().describe("Repository name"),
|
|
666
|
+
pullNumber: z.number().describe("Pull request number"),
|
|
667
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
668
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
669
|
+
});
|
|
670
|
+
const listPullRequestReviewsDescription = "List reviews on a pull request (approvals, change requests, and comments)";
|
|
671
|
+
async function listPullRequestReviewsCore({ token, owner, repo, pullNumber, perPage, page }) {
|
|
672
|
+
const { data } = await createOctokit(token).rest.pulls.listReviews({
|
|
673
|
+
owner,
|
|
674
|
+
repo,
|
|
675
|
+
pull_number: pullNumber,
|
|
676
|
+
per_page: perPage,
|
|
677
|
+
page
|
|
678
|
+
});
|
|
679
|
+
return data.map((review) => ({
|
|
680
|
+
id: review.id,
|
|
681
|
+
state: review.state,
|
|
682
|
+
body: review.body,
|
|
683
|
+
author: review.user?.login,
|
|
684
|
+
url: review.html_url,
|
|
685
|
+
submittedAt: review.submitted_at
|
|
686
|
+
}));
|
|
687
|
+
}
|
|
688
|
+
const createPullRequestReviewInputSchema = z.object({
|
|
689
|
+
owner: z.string().describe("Repository owner"),
|
|
690
|
+
repo: z.string().describe("Repository name"),
|
|
691
|
+
pullNumber: z.number().describe("Pull request number"),
|
|
692
|
+
body: z.string().optional().describe("Review body text (supports Markdown)"),
|
|
693
|
+
event: z.enum([
|
|
694
|
+
"APPROVE",
|
|
695
|
+
"REQUEST_CHANGES",
|
|
696
|
+
"COMMENT"
|
|
697
|
+
]).describe("Review action: approve, request changes, or comment"),
|
|
698
|
+
comments: z.array(z.object({
|
|
699
|
+
path: z.string().describe("File path relative to the repository root"),
|
|
700
|
+
body: z.string().describe("Inline comment text"),
|
|
701
|
+
line: z.number().optional().describe("Line number in the file to comment on"),
|
|
702
|
+
side: z.enum(["LEFT", "RIGHT"]).optional().describe("Which side of the diff to comment on (LEFT = base, RIGHT = head)")
|
|
703
|
+
})).optional().describe("Inline review comments on specific files and lines")
|
|
704
|
+
});
|
|
705
|
+
const createPullRequestReviewDescription = "Submit a pull request review — approve, request changes, or comment with optional inline comments on specific lines";
|
|
706
|
+
/** Not idempotent — each call submits a new review. */
|
|
707
|
+
async function createPullRequestReviewCore({ token, owner, repo, pullNumber, body, event, comments }) {
|
|
708
|
+
const { data } = await createOctokit(token).rest.pulls.createReview({
|
|
709
|
+
owner,
|
|
710
|
+
repo,
|
|
711
|
+
pull_number: pullNumber,
|
|
712
|
+
body,
|
|
713
|
+
event,
|
|
714
|
+
comments
|
|
715
|
+
});
|
|
716
|
+
return {
|
|
717
|
+
id: data.id,
|
|
718
|
+
state: data.state,
|
|
719
|
+
body: data.body,
|
|
720
|
+
url: data.html_url,
|
|
721
|
+
author: data.user?.login,
|
|
722
|
+
submittedAt: data.submitted_at
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
//#endregion
|
|
726
|
+
//#region src/core/issues.ts
|
|
727
|
+
const listIssuesInputSchema = z.object({
|
|
728
|
+
owner: z.string().describe("Repository owner"),
|
|
729
|
+
repo: z.string().describe("Repository name"),
|
|
730
|
+
state: z.enum([
|
|
731
|
+
"open",
|
|
732
|
+
"closed",
|
|
733
|
+
"all"
|
|
734
|
+
]).optional().default("open").describe("Filter by state"),
|
|
735
|
+
labels: z.string().optional().describe("Comma-separated list of label names to filter by"),
|
|
736
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)")
|
|
737
|
+
});
|
|
738
|
+
const listIssuesDescription = "List issues for a GitHub repository (excludes pull requests)";
|
|
739
|
+
async function listIssuesCore({ token, owner, repo, state, labels, perPage }) {
|
|
740
|
+
const { data } = await createOctokit(token).rest.issues.listForRepo({
|
|
741
|
+
owner,
|
|
742
|
+
repo,
|
|
743
|
+
state,
|
|
744
|
+
labels,
|
|
745
|
+
per_page: perPage
|
|
746
|
+
});
|
|
747
|
+
return data.filter((issue) => !issue.pull_request).map((issue) => ({
|
|
748
|
+
number: issue.number,
|
|
749
|
+
title: issue.title,
|
|
750
|
+
state: issue.state,
|
|
751
|
+
url: issue.html_url,
|
|
752
|
+
author: issue.user?.login,
|
|
753
|
+
labels: issue.labels.map((l) => typeof l === "string" ? l : l.name),
|
|
754
|
+
createdAt: issue.created_at,
|
|
755
|
+
updatedAt: issue.updated_at
|
|
756
|
+
}));
|
|
757
|
+
}
|
|
758
|
+
const getIssueInputSchema = z.object({
|
|
759
|
+
owner: z.string().describe("Repository owner"),
|
|
760
|
+
repo: z.string().describe("Repository name"),
|
|
761
|
+
issueNumber: z.number().describe("Issue number")
|
|
762
|
+
});
|
|
763
|
+
const getIssueDescription = "Get detailed information about a specific issue";
|
|
764
|
+
async function getIssueCore({ token, owner, repo, issueNumber }) {
|
|
765
|
+
const { data } = await createOctokit(token).rest.issues.get({
|
|
766
|
+
owner,
|
|
767
|
+
repo,
|
|
768
|
+
issue_number: issueNumber
|
|
769
|
+
});
|
|
770
|
+
return {
|
|
771
|
+
number: data.number,
|
|
772
|
+
title: data.title,
|
|
773
|
+
body: data.body,
|
|
774
|
+
state: data.state,
|
|
775
|
+
url: data.html_url,
|
|
776
|
+
author: data.user?.login,
|
|
777
|
+
assignees: data.assignees?.map((a) => a.login),
|
|
778
|
+
labels: data.labels.map((l) => typeof l === "string" ? l : l.name),
|
|
779
|
+
comments: data.comments,
|
|
780
|
+
createdAt: data.created_at,
|
|
781
|
+
updatedAt: data.updated_at,
|
|
782
|
+
closedAt: data.closed_at
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
const createIssueInputSchema = z.object({
|
|
786
|
+
owner: z.string().describe("Repository owner"),
|
|
787
|
+
repo: z.string().describe("Repository name"),
|
|
788
|
+
title: z.string().describe("Issue title"),
|
|
789
|
+
body: z.string().optional().describe("Issue description (supports Markdown)"),
|
|
790
|
+
labels: z.array(z.string()).optional().describe("Labels to apply to the issue"),
|
|
791
|
+
assignees: z.array(z.string()).optional().describe("GitHub usernames to assign to the issue")
|
|
792
|
+
});
|
|
793
|
+
const createIssueDescription = "Create a new issue in a GitHub repository";
|
|
794
|
+
/** Not idempotent — each call creates a new issue. */
|
|
795
|
+
async function createIssueCore({ token, owner, repo, title, body, labels, assignees }) {
|
|
796
|
+
const { data } = await createOctokit(token).rest.issues.create({
|
|
797
|
+
owner,
|
|
798
|
+
repo,
|
|
799
|
+
title,
|
|
800
|
+
body,
|
|
801
|
+
labels,
|
|
802
|
+
assignees
|
|
803
|
+
});
|
|
804
|
+
return {
|
|
805
|
+
number: data.number,
|
|
806
|
+
title: data.title,
|
|
807
|
+
url: data.html_url,
|
|
808
|
+
state: data.state,
|
|
809
|
+
labels: data.labels.map((l) => typeof l === "string" ? l : l.name)
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
const addIssueCommentInputSchema = z.object({
|
|
813
|
+
owner: z.string().describe("Repository owner"),
|
|
814
|
+
repo: z.string().describe("Repository name"),
|
|
815
|
+
issueNumber: z.number().describe("Issue number"),
|
|
816
|
+
body: z.string().describe("Comment text (supports Markdown)")
|
|
817
|
+
});
|
|
818
|
+
const addIssueCommentDescription = "Add a comment to a GitHub issue";
|
|
819
|
+
/** Not idempotent — each call adds another comment. */
|
|
820
|
+
async function addIssueCommentCore({ token, owner, repo, issueNumber, body }) {
|
|
821
|
+
const { data } = await createOctokit(token).rest.issues.createComment({
|
|
822
|
+
owner,
|
|
823
|
+
repo,
|
|
824
|
+
issue_number: issueNumber,
|
|
825
|
+
body
|
|
826
|
+
});
|
|
827
|
+
return {
|
|
828
|
+
id: data.id,
|
|
829
|
+
url: data.html_url,
|
|
830
|
+
body: data.body,
|
|
831
|
+
author: data.user?.login,
|
|
832
|
+
createdAt: data.created_at
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
const closeIssueInputSchema = z.object({
|
|
836
|
+
owner: z.string().describe("Repository owner"),
|
|
837
|
+
repo: z.string().describe("Repository name"),
|
|
838
|
+
issueNumber: z.number().describe("Issue number to close"),
|
|
839
|
+
stateReason: z.enum(["completed", "not_planned"]).optional().default("completed").describe("Reason for closing")
|
|
840
|
+
});
|
|
841
|
+
const closeIssueDescription = "Close an open GitHub issue";
|
|
842
|
+
/** Idempotent when the issue is already closed. */
|
|
843
|
+
async function closeIssueCore({ token, owner, repo, issueNumber, stateReason }) {
|
|
844
|
+
const octokit = createOctokit(token);
|
|
845
|
+
const { data: existing } = await octokit.rest.issues.get({
|
|
846
|
+
owner,
|
|
847
|
+
repo,
|
|
848
|
+
issue_number: issueNumber
|
|
849
|
+
});
|
|
850
|
+
if (existing.state === "closed") return {
|
|
851
|
+
number: existing.number,
|
|
852
|
+
title: existing.title,
|
|
853
|
+
state: existing.state,
|
|
854
|
+
url: existing.html_url,
|
|
855
|
+
closedAt: existing.closed_at
|
|
856
|
+
};
|
|
857
|
+
const { data } = await octokit.rest.issues.update({
|
|
858
|
+
owner,
|
|
859
|
+
repo,
|
|
860
|
+
issue_number: issueNumber,
|
|
861
|
+
state: "closed",
|
|
862
|
+
state_reason: stateReason
|
|
863
|
+
});
|
|
864
|
+
return {
|
|
865
|
+
number: data.number,
|
|
866
|
+
title: data.title,
|
|
867
|
+
state: data.state,
|
|
868
|
+
url: data.html_url,
|
|
869
|
+
closedAt: data.closed_at
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
const listLabelsInputSchema = z.object({
|
|
873
|
+
owner: z.string().describe("Repository owner"),
|
|
874
|
+
repo: z.string().describe("Repository name"),
|
|
875
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
876
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
877
|
+
});
|
|
878
|
+
const listLabelsDescription = "List labels available in a GitHub repository";
|
|
879
|
+
async function listLabelsCore({ token, owner, repo, perPage, page }) {
|
|
880
|
+
const { data } = await createOctokit(token).rest.issues.listLabelsForRepo({
|
|
881
|
+
owner,
|
|
882
|
+
repo,
|
|
883
|
+
per_page: perPage,
|
|
884
|
+
page
|
|
885
|
+
});
|
|
886
|
+
return data.map((label) => ({
|
|
887
|
+
name: label.name,
|
|
888
|
+
color: label.color,
|
|
889
|
+
description: label.description
|
|
890
|
+
}));
|
|
891
|
+
}
|
|
892
|
+
const addLabelsInputSchema = z.object({
|
|
893
|
+
owner: z.string().describe("Repository owner"),
|
|
894
|
+
repo: z.string().describe("Repository name"),
|
|
895
|
+
issueNumber: z.number().describe("Issue or pull request number"),
|
|
896
|
+
labels: z.array(z.string()).describe("Label names to add")
|
|
897
|
+
});
|
|
898
|
+
const addLabelsDescription = "Add labels to an issue or pull request";
|
|
899
|
+
/** Not idempotent — re-adding labels is a no-op on GitHub but still mutates. */
|
|
900
|
+
async function addLabelsCore({ token, owner, repo, issueNumber, labels }) {
|
|
901
|
+
const { data } = await createOctokit(token).rest.issues.addLabels({
|
|
902
|
+
owner,
|
|
903
|
+
repo,
|
|
904
|
+
issue_number: issueNumber,
|
|
905
|
+
labels
|
|
906
|
+
});
|
|
907
|
+
return data.map((label) => ({
|
|
908
|
+
name: label.name,
|
|
909
|
+
color: label.color,
|
|
910
|
+
description: label.description
|
|
911
|
+
}));
|
|
912
|
+
}
|
|
913
|
+
const removeLabelInputSchema = z.object({
|
|
914
|
+
owner: z.string().describe("Repository owner"),
|
|
915
|
+
repo: z.string().describe("Repository name"),
|
|
916
|
+
issueNumber: z.number().describe("Issue or pull request number"),
|
|
917
|
+
label: z.string().describe("Label name to remove")
|
|
918
|
+
});
|
|
919
|
+
const removeLabelDescription = "Remove a label from an issue or pull request";
|
|
920
|
+
/** Not idempotent — removing a missing label returns 404 from GitHub. */
|
|
921
|
+
async function removeLabelCore({ token, owner, repo, issueNumber, label }) {
|
|
922
|
+
await createOctokit(token).rest.issues.removeLabel({
|
|
923
|
+
owner,
|
|
924
|
+
repo,
|
|
925
|
+
issue_number: issueNumber,
|
|
926
|
+
name: label
|
|
927
|
+
});
|
|
928
|
+
return {
|
|
929
|
+
removed: true,
|
|
930
|
+
label,
|
|
931
|
+
issueNumber
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
//#endregion
|
|
935
|
+
//#region src/core/search.ts
|
|
936
|
+
const searchCodeInputSchema = z.object({
|
|
937
|
+
query: z.string().describe("Search query. Supports GitHub search qualifiers, e.g. \"useState repo:facebook/react\""),
|
|
938
|
+
perPage: z.number().optional().default(10).describe("Number of results to return (max 30)")
|
|
939
|
+
});
|
|
940
|
+
const searchCodeDescription = "Search for code in GitHub repositories. Use qualifiers like \"repo:owner/name\" to scope the search.";
|
|
941
|
+
async function searchCodeCore({ token, query, perPage }) {
|
|
942
|
+
const { data } = await createOctokit(token).rest.search.code({
|
|
943
|
+
q: query,
|
|
944
|
+
per_page: perPage
|
|
945
|
+
});
|
|
946
|
+
return {
|
|
947
|
+
totalCount: data.total_count,
|
|
948
|
+
items: data.items.map((item) => ({
|
|
949
|
+
name: item.name,
|
|
950
|
+
path: item.path,
|
|
951
|
+
url: item.html_url,
|
|
952
|
+
repository: item.repository.full_name,
|
|
953
|
+
sha: item.sha
|
|
954
|
+
}))
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
const searchRepositoriesInputSchema = z.object({
|
|
958
|
+
query: z.string().describe("Search query. Supports GitHub search qualifiers, e.g. \"nuxt language:typescript stars:>1000\""),
|
|
959
|
+
perPage: z.number().optional().default(10).describe("Number of results to return (max 30)"),
|
|
960
|
+
sort: z.enum([
|
|
961
|
+
"stars",
|
|
962
|
+
"forks",
|
|
963
|
+
"help-wanted-issues",
|
|
964
|
+
"updated"
|
|
965
|
+
]).optional().describe("Sort field"),
|
|
966
|
+
order: z.enum(["asc", "desc"]).optional().default("desc").describe("Sort order")
|
|
967
|
+
});
|
|
968
|
+
const searchRepositoriesDescription = "Search for GitHub repositories by keyword, topic, language, or other qualifiers";
|
|
969
|
+
async function searchRepositoriesCore({ token, query, perPage, sort, order }) {
|
|
970
|
+
const { data } = await createOctokit(token).rest.search.repos({
|
|
971
|
+
q: query,
|
|
972
|
+
per_page: perPage,
|
|
973
|
+
sort,
|
|
974
|
+
order
|
|
975
|
+
});
|
|
976
|
+
return {
|
|
977
|
+
totalCount: data.total_count,
|
|
978
|
+
items: data.items.map((repo) => ({
|
|
979
|
+
name: repo.name,
|
|
980
|
+
fullName: repo.full_name,
|
|
981
|
+
description: repo.description,
|
|
982
|
+
url: repo.html_url,
|
|
983
|
+
stars: repo.stargazers_count,
|
|
984
|
+
forks: repo.forks_count,
|
|
985
|
+
language: repo.language,
|
|
986
|
+
topics: repo.topics
|
|
987
|
+
}))
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
//#endregion
|
|
991
|
+
//#region src/core/commits.ts
|
|
992
|
+
const BLAME_QUERY = `
|
|
993
|
+
query ($owner: String!, $name: String!, $expression: String!, $path: String!) {
|
|
994
|
+
repository(owner: $owner, name: $name) {
|
|
995
|
+
object(expression: $expression) {
|
|
996
|
+
... on Commit {
|
|
997
|
+
oid
|
|
998
|
+
blame(path: $path) {
|
|
999
|
+
ranges {
|
|
1000
|
+
startingLine
|
|
1001
|
+
endingLine
|
|
1002
|
+
age
|
|
1003
|
+
commit {
|
|
1004
|
+
oid
|
|
1005
|
+
abbreviatedOid
|
|
1006
|
+
messageHeadline
|
|
1007
|
+
authoredDate
|
|
1008
|
+
url
|
|
1009
|
+
author {
|
|
1010
|
+
name
|
|
1011
|
+
email
|
|
1012
|
+
user {
|
|
1013
|
+
login
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
`;
|
|
1024
|
+
const listCommitsInputSchema = z.object({
|
|
1025
|
+
owner: z.string().describe("Repository owner"),
|
|
1026
|
+
repo: z.string().describe("Repository name"),
|
|
1027
|
+
path: z.string().optional().describe("Only commits containing this file path"),
|
|
1028
|
+
sha: z.string().optional().describe("Branch name or commit SHA to start listing from"),
|
|
1029
|
+
author: z.string().optional().describe("GitHub username or email to filter commits by"),
|
|
1030
|
+
since: z.string().optional().describe("Only commits after this date (ISO 8601 format)"),
|
|
1031
|
+
until: z.string().optional().describe("Only commits before this date (ISO 8601 format)"),
|
|
1032
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)")
|
|
1033
|
+
});
|
|
1034
|
+
const listCommitsDescription = "List commits for a GitHub repository. Filter by file path to see commits that touched a file. For line-by-line attribution at a given ref, use getBlame instead.";
|
|
1035
|
+
async function listCommitsCore({ token, owner, repo, path, sha, author, since, until, perPage }) {
|
|
1036
|
+
const { data } = await createOctokit(token).rest.repos.listCommits({
|
|
1037
|
+
owner,
|
|
1038
|
+
repo,
|
|
1039
|
+
path,
|
|
1040
|
+
sha,
|
|
1041
|
+
author,
|
|
1042
|
+
since,
|
|
1043
|
+
until,
|
|
1044
|
+
per_page: perPage
|
|
1045
|
+
});
|
|
1046
|
+
return data.map((commit) => ({
|
|
1047
|
+
sha: commit.sha,
|
|
1048
|
+
message: commit.commit.message,
|
|
1049
|
+
author: commit.commit.author?.name,
|
|
1050
|
+
authorLogin: commit.author?.login,
|
|
1051
|
+
date: commit.commit.author?.date,
|
|
1052
|
+
url: commit.html_url
|
|
1053
|
+
}));
|
|
1054
|
+
}
|
|
1055
|
+
const getCommitInputSchema = z.object({
|
|
1056
|
+
owner: z.string().describe("Repository owner"),
|
|
1057
|
+
repo: z.string().describe("Repository name"),
|
|
1058
|
+
ref: z.string().describe("Commit SHA, branch name, or tag")
|
|
1059
|
+
});
|
|
1060
|
+
const getCommitDescription = "Get detailed information about a specific commit, including the list of files changed with additions and deletions";
|
|
1061
|
+
async function getCommitCore({ token, owner, repo, ref }) {
|
|
1062
|
+
const { data } = await createOctokit(token).rest.repos.getCommit({
|
|
1063
|
+
owner,
|
|
1064
|
+
repo,
|
|
1065
|
+
ref
|
|
1066
|
+
});
|
|
1067
|
+
return {
|
|
1068
|
+
sha: data.sha,
|
|
1069
|
+
message: data.commit.message,
|
|
1070
|
+
author: data.commit.author?.name,
|
|
1071
|
+
authorLogin: data.author?.login,
|
|
1072
|
+
date: data.commit.author?.date,
|
|
1073
|
+
url: data.html_url,
|
|
1074
|
+
stats: data.stats ? {
|
|
1075
|
+
additions: data.stats.additions,
|
|
1076
|
+
deletions: data.stats.deletions,
|
|
1077
|
+
total: data.stats.total
|
|
1078
|
+
} : null,
|
|
1079
|
+
files: data.files?.map((file) => ({
|
|
1080
|
+
filename: file.filename,
|
|
1081
|
+
status: file.status,
|
|
1082
|
+
additions: file.additions,
|
|
1083
|
+
deletions: file.deletions,
|
|
1084
|
+
patch: file.patch
|
|
1085
|
+
}))
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
const getBlameInputSchema = z.object({
|
|
1089
|
+
owner: z.string().describe("Repository owner"),
|
|
1090
|
+
repo: z.string().describe("Repository name"),
|
|
1091
|
+
path: z.string().describe("Path to the file in the repository"),
|
|
1092
|
+
ref: z.string().optional().describe("Branch name, tag, or commit SHA (defaults to the repository default branch)"),
|
|
1093
|
+
line: z.number().int().positive().optional().describe("If set, only return blame ranges that include this line number"),
|
|
1094
|
+
lineStart: z.number().int().positive().optional().describe("When used with lineEnd, only return ranges overlapping this window"),
|
|
1095
|
+
lineEnd: z.number().int().positive().optional().describe("When used with lineStart, only return ranges overlapping this window")
|
|
1096
|
+
});
|
|
1097
|
+
const getBlameDescription = "Line-level git blame for a file at a commit-like ref (branch, tag, or SHA). Returns contiguous ranges mapping lines to the commits that last modified them — use this to see who introduced a line and when (GitHub GraphQL API).";
|
|
1098
|
+
async function getBlameCore({ token, owner, repo, path, ref, line, lineStart, lineEnd }) {
|
|
1099
|
+
const octokit = createOctokit(token);
|
|
1100
|
+
let expression = ref;
|
|
1101
|
+
if (!expression) {
|
|
1102
|
+
const { data } = await octokit.rest.repos.get({
|
|
1103
|
+
owner,
|
|
1104
|
+
repo
|
|
1105
|
+
});
|
|
1106
|
+
expression = data.default_branch;
|
|
1107
|
+
}
|
|
1108
|
+
const data = await octokit.graphql(BLAME_QUERY, {
|
|
1109
|
+
owner,
|
|
1110
|
+
name: repo,
|
|
1111
|
+
expression,
|
|
1112
|
+
path
|
|
1113
|
+
});
|
|
1114
|
+
if (!data.repository) return { error: `Repository not found: ${owner}/${repo}` };
|
|
1115
|
+
const obj = data.repository.object;
|
|
1116
|
+
if (!obj?.oid || !obj?.blame) return { error: `Ref "${expression}" did not resolve to a commit for this repository (or the path is invalid). Pass a branch name, tag, or full commit SHA.` };
|
|
1117
|
+
let ranges = obj.blame.ranges.map((r) => ({
|
|
1118
|
+
startingLine: r.startingLine,
|
|
1119
|
+
endingLine: r.endingLine,
|
|
1120
|
+
age: r.age,
|
|
1121
|
+
commit: {
|
|
1122
|
+
sha: r.commit.oid,
|
|
1123
|
+
abbreviatedSha: r.commit.abbreviatedOid,
|
|
1124
|
+
messageHeadline: r.commit.messageHeadline,
|
|
1125
|
+
authoredDate: r.commit.authoredDate,
|
|
1126
|
+
url: r.commit.url,
|
|
1127
|
+
authorName: r.commit.author?.name ?? null,
|
|
1128
|
+
authorEmail: r.commit.author?.email ?? null,
|
|
1129
|
+
authorLogin: r.commit.author?.user?.login ?? null
|
|
1130
|
+
}
|
|
1131
|
+
}));
|
|
1132
|
+
if (line != null) ranges = ranges.filter((r) => line >= r.startingLine && line <= r.endingLine);
|
|
1133
|
+
else if (lineStart != null || lineEnd != null) {
|
|
1134
|
+
const start = lineStart ?? 1;
|
|
1135
|
+
const end = lineEnd ?? Number.MAX_SAFE_INTEGER;
|
|
1136
|
+
ranges = ranges.filter((r) => r.endingLine >= start && r.startingLine <= end);
|
|
1137
|
+
}
|
|
1138
|
+
return {
|
|
1139
|
+
ref: expression,
|
|
1140
|
+
tipSha: obj.oid,
|
|
1141
|
+
path,
|
|
1142
|
+
rangeCount: ranges.length,
|
|
1143
|
+
ranges
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
//#endregion
|
|
1147
|
+
//#region src/core/gists.ts
|
|
1148
|
+
const listGistsInputSchema = z.object({
|
|
1149
|
+
username: z.string().optional().describe("GitHub username — omit to list your own gists"),
|
|
1150
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
1151
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
1152
|
+
});
|
|
1153
|
+
const listGistsDescription = "List gists for the authenticated user or a specific user";
|
|
1154
|
+
async function listGistsCore({ token, username, perPage, page }) {
|
|
1155
|
+
const octokit = createOctokit(token);
|
|
1156
|
+
const { data } = username ? await octokit.rest.gists.listForUser({
|
|
1157
|
+
username,
|
|
1158
|
+
per_page: perPage,
|
|
1159
|
+
page
|
|
1160
|
+
}) : await octokit.rest.gists.list({
|
|
1161
|
+
per_page: perPage,
|
|
1162
|
+
page
|
|
1163
|
+
});
|
|
1164
|
+
return data.map((gist) => ({
|
|
1165
|
+
id: gist.id,
|
|
1166
|
+
description: gist.description,
|
|
1167
|
+
public: gist.public,
|
|
1168
|
+
url: gist.html_url,
|
|
1169
|
+
files: Object.keys(gist.files ?? {}),
|
|
1170
|
+
owner: gist.owner?.login,
|
|
1171
|
+
comments: gist.comments,
|
|
1172
|
+
createdAt: gist.created_at,
|
|
1173
|
+
updatedAt: gist.updated_at
|
|
1174
|
+
}));
|
|
1175
|
+
}
|
|
1176
|
+
const getGistInputSchema = z.object({ gistId: z.string().describe("Gist ID") });
|
|
1177
|
+
const getGistDescription = "Get a gist by ID, including file contents";
|
|
1178
|
+
async function getGistCore({ token, gistId }) {
|
|
1179
|
+
const { data } = await createOctokit(token).rest.gists.get({ gist_id: gistId });
|
|
1180
|
+
return {
|
|
1181
|
+
id: data.id,
|
|
1182
|
+
description: data.description,
|
|
1183
|
+
public: data.public,
|
|
1184
|
+
url: data.html_url,
|
|
1185
|
+
owner: data.owner?.login,
|
|
1186
|
+
files: Object.values(data.files ?? {}).map((file) => ({
|
|
1187
|
+
filename: file?.filename,
|
|
1188
|
+
language: file?.language,
|
|
1189
|
+
size: file?.size,
|
|
1190
|
+
content: file?.content
|
|
1191
|
+
})),
|
|
1192
|
+
comments: data.comments,
|
|
1193
|
+
createdAt: data.created_at,
|
|
1194
|
+
updatedAt: data.updated_at
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
const listGistCommentsInputSchema = z.object({
|
|
1198
|
+
gistId: z.string().describe("Gist ID"),
|
|
1199
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
1200
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
1201
|
+
});
|
|
1202
|
+
const listGistCommentsDescription = "List comments on a gist";
|
|
1203
|
+
async function listGistCommentsCore({ token, gistId, perPage, page }) {
|
|
1204
|
+
const { data } = await createOctokit(token).rest.gists.listComments({
|
|
1205
|
+
gist_id: gistId,
|
|
1206
|
+
per_page: perPage,
|
|
1207
|
+
page
|
|
1208
|
+
});
|
|
1209
|
+
return data.map((comment) => ({
|
|
1210
|
+
id: comment.id,
|
|
1211
|
+
body: comment.body,
|
|
1212
|
+
author: comment.user?.login,
|
|
1213
|
+
url: comment.url,
|
|
1214
|
+
createdAt: comment.created_at,
|
|
1215
|
+
updatedAt: comment.updated_at
|
|
1216
|
+
}));
|
|
1217
|
+
}
|
|
1218
|
+
const createGistInputSchema = z.object({
|
|
1219
|
+
description: z.string().optional().describe("Gist description"),
|
|
1220
|
+
files: z.record(z.string(), z.object({ content: z.string().describe("File content") })).describe("Files to include, keyed by filename"),
|
|
1221
|
+
isPublic: z.boolean().optional().default(false).describe("Whether the gist is public")
|
|
1222
|
+
});
|
|
1223
|
+
const createGistDescription = "Create a new gist with one or more files";
|
|
1224
|
+
/** Not idempotent — each call creates a new gist. */
|
|
1225
|
+
async function createGistCore({ token, description, files, isPublic }) {
|
|
1226
|
+
const { data } = await createOctokit(token).rest.gists.create({
|
|
1227
|
+
description,
|
|
1228
|
+
files,
|
|
1229
|
+
public: isPublic
|
|
1230
|
+
});
|
|
1231
|
+
return {
|
|
1232
|
+
id: data.id,
|
|
1233
|
+
description: data.description,
|
|
1234
|
+
public: data.public,
|
|
1235
|
+
url: data.html_url,
|
|
1236
|
+
files: Object.keys(data.files ?? {}),
|
|
1237
|
+
owner: data.owner?.login
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
const updateGistInputSchema = z.object({
|
|
1241
|
+
gistId: z.string().describe("Gist ID"),
|
|
1242
|
+
description: z.string().optional().describe("New gist description"),
|
|
1243
|
+
files: z.record(z.string(), z.object({ content: z.string().describe("New file content") })).optional().describe("Files to add or update, keyed by filename"),
|
|
1244
|
+
filesToDelete: z.array(z.string()).optional().describe("Filenames to remove from the gist")
|
|
1245
|
+
});
|
|
1246
|
+
const updateGistDescription = "Update an existing gist — edit description, update files, or remove files";
|
|
1247
|
+
/** Not idempotent — each call applies a new revision. */
|
|
1248
|
+
async function updateGistCore({ token, gistId, description, files, filesToDelete }) {
|
|
1249
|
+
const octokit = createOctokit(token);
|
|
1250
|
+
const fileUpdates = {};
|
|
1251
|
+
if (files) Object.assign(fileUpdates, files);
|
|
1252
|
+
if (filesToDelete) for (const name of filesToDelete) fileUpdates[name] = null;
|
|
1253
|
+
const { data } = await octokit.rest.gists.update({
|
|
1254
|
+
gist_id: gistId,
|
|
1255
|
+
description,
|
|
1256
|
+
files: fileUpdates
|
|
1257
|
+
});
|
|
1258
|
+
return {
|
|
1259
|
+
id: data.id,
|
|
1260
|
+
description: data.description,
|
|
1261
|
+
url: data.html_url,
|
|
1262
|
+
files: Object.keys(data.files ?? {})
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
const deleteGistInputSchema = z.object({ gistId: z.string().describe("Gist ID to delete") });
|
|
1266
|
+
const deleteGistDescription = "Delete a gist permanently";
|
|
1267
|
+
/** Not idempotent — deleting an already-deleted gist returns 404 from GitHub. */
|
|
1268
|
+
async function deleteGistCore({ token, gistId }) {
|
|
1269
|
+
await createOctokit(token).rest.gists.delete({ gist_id: gistId });
|
|
1270
|
+
return {
|
|
1271
|
+
deleted: true,
|
|
1272
|
+
gistId
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
const createGistCommentInputSchema = z.object({
|
|
1276
|
+
gistId: z.string().describe("Gist ID"),
|
|
1277
|
+
body: z.string().describe("Comment text (supports Markdown)")
|
|
1278
|
+
});
|
|
1279
|
+
const createGistCommentDescription = "Add a comment to a gist";
|
|
1280
|
+
/** Not idempotent — each call adds another comment. */
|
|
1281
|
+
async function createGistCommentCore({ token, gistId, body }) {
|
|
1282
|
+
const { data } = await createOctokit(token).rest.gists.createComment({
|
|
1283
|
+
gist_id: gistId,
|
|
1284
|
+
body
|
|
1285
|
+
});
|
|
1286
|
+
return {
|
|
1287
|
+
id: data.id,
|
|
1288
|
+
url: data.url,
|
|
1289
|
+
body: data.body,
|
|
1290
|
+
author: data.user?.login,
|
|
1291
|
+
createdAt: data.created_at
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
//#endregion
|
|
1295
|
+
//#region src/core/workflows.ts
|
|
1296
|
+
const listWorkflowsInputSchema = z.object({
|
|
1297
|
+
owner: z.string().describe("Repository owner"),
|
|
1298
|
+
repo: z.string().describe("Repository name"),
|
|
1299
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
1300
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
1301
|
+
});
|
|
1302
|
+
const listWorkflowsDescription = "List GitHub Actions workflows in a repository";
|
|
1303
|
+
async function listWorkflowsCore({ token, owner, repo, perPage, page }) {
|
|
1304
|
+
const { data } = await createOctokit(token).rest.actions.listRepoWorkflows({
|
|
1305
|
+
owner,
|
|
1306
|
+
repo,
|
|
1307
|
+
per_page: perPage,
|
|
1308
|
+
page
|
|
1309
|
+
});
|
|
1310
|
+
return {
|
|
1311
|
+
totalCount: data.total_count,
|
|
1312
|
+
workflows: data.workflows.map((wf) => ({
|
|
1313
|
+
id: wf.id,
|
|
1314
|
+
name: wf.name,
|
|
1315
|
+
path: wf.path,
|
|
1316
|
+
state: wf.state,
|
|
1317
|
+
url: wf.html_url,
|
|
1318
|
+
createdAt: wf.created_at,
|
|
1319
|
+
updatedAt: wf.updated_at
|
|
1320
|
+
}))
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
const listWorkflowRunsInputSchema = z.object({
|
|
1324
|
+
owner: z.string().describe("Repository owner"),
|
|
1325
|
+
repo: z.string().describe("Repository name"),
|
|
1326
|
+
workflowId: z.union([z.string(), z.number()]).optional().describe("Workflow ID or filename (e.g. \"ci.yml\") to filter by"),
|
|
1327
|
+
branch: z.string().optional().describe("Branch name to filter by"),
|
|
1328
|
+
event: z.string().optional().describe("Event type to filter by (e.g. \"push\", \"pull_request\")"),
|
|
1329
|
+
status: z.enum([
|
|
1330
|
+
"completed",
|
|
1331
|
+
"action_required",
|
|
1332
|
+
"cancelled",
|
|
1333
|
+
"failure",
|
|
1334
|
+
"neutral",
|
|
1335
|
+
"skipped",
|
|
1336
|
+
"stale",
|
|
1337
|
+
"success",
|
|
1338
|
+
"timed_out",
|
|
1339
|
+
"in_progress",
|
|
1340
|
+
"queued",
|
|
1341
|
+
"requested",
|
|
1342
|
+
"waiting",
|
|
1343
|
+
"pending"
|
|
1344
|
+
]).optional().describe("Status to filter by"),
|
|
1345
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
1346
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
1347
|
+
});
|
|
1348
|
+
const listWorkflowRunsDescription = "List workflow runs for a repository, optionally filtered by workflow, branch, status, or event";
|
|
1349
|
+
async function listWorkflowRunsCore({ token, owner, repo, workflowId, branch, event, status, perPage, page }) {
|
|
1350
|
+
const octokit = createOctokit(token);
|
|
1351
|
+
const { data } = workflowId ? await octokit.rest.actions.listWorkflowRuns({
|
|
1352
|
+
owner,
|
|
1353
|
+
repo,
|
|
1354
|
+
workflow_id: workflowId,
|
|
1355
|
+
per_page: perPage,
|
|
1356
|
+
page,
|
|
1357
|
+
...branch && { branch },
|
|
1358
|
+
...event && { event },
|
|
1359
|
+
...status && { status }
|
|
1360
|
+
}) : await octokit.rest.actions.listWorkflowRunsForRepo({
|
|
1361
|
+
owner,
|
|
1362
|
+
repo,
|
|
1363
|
+
per_page: perPage,
|
|
1364
|
+
page,
|
|
1365
|
+
...branch && { branch },
|
|
1366
|
+
...event && { event },
|
|
1367
|
+
...status && { status }
|
|
1368
|
+
});
|
|
1369
|
+
return {
|
|
1370
|
+
totalCount: data.total_count,
|
|
1371
|
+
runs: data.workflow_runs.map((run) => ({
|
|
1372
|
+
id: run.id,
|
|
1373
|
+
name: run.name,
|
|
1374
|
+
status: run.status,
|
|
1375
|
+
conclusion: run.conclusion,
|
|
1376
|
+
branch: run.head_branch,
|
|
1377
|
+
event: run.event,
|
|
1378
|
+
url: run.html_url,
|
|
1379
|
+
actor: run.actor?.login,
|
|
1380
|
+
createdAt: run.created_at,
|
|
1381
|
+
updatedAt: run.updated_at,
|
|
1382
|
+
runNumber: run.run_number,
|
|
1383
|
+
runAttempt: run.run_attempt
|
|
1384
|
+
}))
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
const getWorkflowRunInputSchema = z.object({
|
|
1388
|
+
owner: z.string().describe("Repository owner"),
|
|
1389
|
+
repo: z.string().describe("Repository name"),
|
|
1390
|
+
runId: z.number().describe("Workflow run ID")
|
|
1391
|
+
});
|
|
1392
|
+
const getWorkflowRunDescription = "Get details of a specific workflow run including status, timing, and trigger info";
|
|
1393
|
+
async function getWorkflowRunCore({ token, owner, repo, runId }) {
|
|
1394
|
+
const { data } = await createOctokit(token).rest.actions.getWorkflowRun({
|
|
1395
|
+
owner,
|
|
1396
|
+
repo,
|
|
1397
|
+
run_id: runId
|
|
1398
|
+
});
|
|
1399
|
+
return {
|
|
1400
|
+
id: data.id,
|
|
1401
|
+
name: data.name,
|
|
1402
|
+
status: data.status,
|
|
1403
|
+
conclusion: data.conclusion,
|
|
1404
|
+
branch: data.head_branch,
|
|
1405
|
+
sha: data.head_sha,
|
|
1406
|
+
event: data.event,
|
|
1407
|
+
url: data.html_url,
|
|
1408
|
+
actor: data.actor?.login,
|
|
1409
|
+
runNumber: data.run_number,
|
|
1410
|
+
runAttempt: data.run_attempt,
|
|
1411
|
+
createdAt: data.created_at,
|
|
1412
|
+
updatedAt: data.updated_at,
|
|
1413
|
+
runStartedAt: data.run_started_at
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
const listWorkflowJobsInputSchema = z.object({
|
|
1417
|
+
owner: z.string().describe("Repository owner"),
|
|
1418
|
+
repo: z.string().describe("Repository name"),
|
|
1419
|
+
runId: z.number().describe("Workflow run ID"),
|
|
1420
|
+
filter: z.enum(["latest", "all"]).optional().default("latest").describe("Filter by the latest attempt or all attempts"),
|
|
1421
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
1422
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
1423
|
+
});
|
|
1424
|
+
const listWorkflowJobsDescription = "List jobs for a workflow run, including step-level status and timing";
|
|
1425
|
+
async function listWorkflowJobsCore({ token, owner, repo, runId, filter, perPage, page }) {
|
|
1426
|
+
const { data } = await createOctokit(token).rest.actions.listJobsForWorkflowRun({
|
|
1427
|
+
owner,
|
|
1428
|
+
repo,
|
|
1429
|
+
run_id: runId,
|
|
1430
|
+
filter,
|
|
1431
|
+
per_page: perPage,
|
|
1432
|
+
page
|
|
1433
|
+
});
|
|
1434
|
+
return {
|
|
1435
|
+
totalCount: data.total_count,
|
|
1436
|
+
jobs: data.jobs.map((job) => ({
|
|
1437
|
+
id: job.id,
|
|
1438
|
+
name: job.name,
|
|
1439
|
+
status: job.status,
|
|
1440
|
+
conclusion: job.conclusion,
|
|
1441
|
+
url: job.html_url,
|
|
1442
|
+
startedAt: job.started_at,
|
|
1443
|
+
completedAt: job.completed_at,
|
|
1444
|
+
runnerName: job.runner_name,
|
|
1445
|
+
steps: job.steps?.map((step) => ({
|
|
1446
|
+
name: step.name,
|
|
1447
|
+
status: step.status,
|
|
1448
|
+
conclusion: step.conclusion,
|
|
1449
|
+
number: step.number,
|
|
1450
|
+
startedAt: step.started_at,
|
|
1451
|
+
completedAt: step.completed_at
|
|
1452
|
+
}))
|
|
1453
|
+
}))
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
const triggerWorkflowInputSchema = z.object({
|
|
1457
|
+
owner: z.string().describe("Repository owner"),
|
|
1458
|
+
repo: z.string().describe("Repository name"),
|
|
1459
|
+
workflowId: z.union([z.string(), z.number()]).describe("Workflow ID or filename (e.g. \"deploy.yml\")"),
|
|
1460
|
+
ref: z.string().describe("Git ref (branch or tag) to run the workflow on"),
|
|
1461
|
+
inputs: z.record(z.string(), z.string()).optional().describe("Input parameters defined in the workflow_dispatch trigger")
|
|
1462
|
+
});
|
|
1463
|
+
const triggerWorkflowDescription = "Trigger a workflow via workflow_dispatch event";
|
|
1464
|
+
/** Not idempotent — each call starts a new workflow run. */
|
|
1465
|
+
async function triggerWorkflowCore({ token, owner, repo, workflowId, ref, inputs }) {
|
|
1466
|
+
await createOctokit(token).rest.actions.createWorkflowDispatch({
|
|
1467
|
+
owner,
|
|
1468
|
+
repo,
|
|
1469
|
+
workflow_id: workflowId,
|
|
1470
|
+
ref,
|
|
1471
|
+
inputs
|
|
1472
|
+
});
|
|
1473
|
+
return {
|
|
1474
|
+
triggered: true,
|
|
1475
|
+
workflowId,
|
|
1476
|
+
ref
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
const cancelWorkflowRunInputSchema = z.object({
|
|
1480
|
+
owner: z.string().describe("Repository owner"),
|
|
1481
|
+
repo: z.string().describe("Repository name"),
|
|
1482
|
+
runId: z.number().describe("Workflow run ID to cancel")
|
|
1483
|
+
});
|
|
1484
|
+
const cancelWorkflowRunDescription = "Cancel an in-progress workflow run";
|
|
1485
|
+
/** Not idempotent — cancelling an already-finished run is a no-op on GitHub but still mutates. */
|
|
1486
|
+
async function cancelWorkflowRunCore({ token, owner, repo, runId }) {
|
|
1487
|
+
await createOctokit(token).rest.actions.cancelWorkflowRun({
|
|
1488
|
+
owner,
|
|
1489
|
+
repo,
|
|
1490
|
+
run_id: runId
|
|
1491
|
+
});
|
|
1492
|
+
return {
|
|
1493
|
+
cancelled: true,
|
|
1494
|
+
runId
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
const rerunWorkflowRunInputSchema = z.object({
|
|
1498
|
+
owner: z.string().describe("Repository owner"),
|
|
1499
|
+
repo: z.string().describe("Repository name"),
|
|
1500
|
+
runId: z.number().describe("Workflow run ID to re-run"),
|
|
1501
|
+
onlyFailedJobs: z.boolean().optional().default(false).describe("Only re-run failed jobs instead of the entire workflow")
|
|
1502
|
+
});
|
|
1503
|
+
const rerunWorkflowRunDescription = "Re-run a workflow run, optionally only the failed jobs";
|
|
1504
|
+
/** Not idempotent — each call starts another run attempt. */
|
|
1505
|
+
async function rerunWorkflowRunCore({ token, owner, repo, runId, onlyFailedJobs }) {
|
|
1506
|
+
const octokit = createOctokit(token);
|
|
1507
|
+
if (onlyFailedJobs) await octokit.rest.actions.reRunWorkflowFailedJobs({
|
|
1508
|
+
owner,
|
|
1509
|
+
repo,
|
|
1510
|
+
run_id: runId
|
|
1511
|
+
});
|
|
1512
|
+
else await octokit.rest.actions.reRunWorkflow({
|
|
1513
|
+
owner,
|
|
1514
|
+
repo,
|
|
1515
|
+
run_id: runId
|
|
1516
|
+
});
|
|
1517
|
+
return {
|
|
1518
|
+
rerun: true,
|
|
1519
|
+
runId,
|
|
1520
|
+
onlyFailedJobs
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
1523
|
+
//#endregion
|
|
1524
|
+
//#region src/core/presets.ts
|
|
1525
|
+
/**
|
|
1526
|
+
* Predefined tool presets for common use cases.
|
|
1527
|
+
* Pass to {@link createGithubTools}, {@link createGithubAgent}, or {@link createDurableGithubAgent}.
|
|
1528
|
+
* Presets can be combined by passing an array.
|
|
1529
|
+
*/
|
|
1530
|
+
const PRESET_TOOLS = {
|
|
1531
|
+
/**
|
|
1532
|
+
* **Code review** — review pull requests and submit feedback.
|
|
1533
|
+
*
|
|
1534
|
+
* Tools: `getPullRequest`, `listPullRequests`, `listPullRequestFiles`, `listPullRequestReviews`,
|
|
1535
|
+
* `getFileContent`, `listCommits`, `getCommit`, `getBlame`, `getRepository`, `listBranches`,
|
|
1536
|
+
* `searchCode`, `addPullRequestComment`, `createPullRequestReview`.
|
|
1537
|
+
*
|
|
1538
|
+
* Agent prompt: optimized for thorough PR review with inline feedback.
|
|
1539
|
+
*/
|
|
1540
|
+
"code-review": [
|
|
1541
|
+
"getPullRequest",
|
|
1542
|
+
"listPullRequests",
|
|
1543
|
+
"listPullRequestFiles",
|
|
1544
|
+
"listPullRequestReviews",
|
|
1545
|
+
"getFileContent",
|
|
1546
|
+
"listCommits",
|
|
1547
|
+
"getCommit",
|
|
1548
|
+
"getBlame",
|
|
1549
|
+
"getRepository",
|
|
1550
|
+
"listBranches",
|
|
1551
|
+
"searchCode",
|
|
1552
|
+
"addPullRequestComment",
|
|
1553
|
+
"createPullRequestReview"
|
|
1554
|
+
],
|
|
1555
|
+
/**
|
|
1556
|
+
* **Issue triage** — manage and organize GitHub issues.
|
|
1557
|
+
*
|
|
1558
|
+
* Tools: `listIssues`, `getIssue`, `createIssue`, `addIssueComment`, `closeIssue`,
|
|
1559
|
+
* `listLabels`, `addLabels`, `removeLabel`, `getRepository`, `searchRepositories`, `searchCode`.
|
|
1560
|
+
*
|
|
1561
|
+
* Agent prompt: optimized for categorizing, labeling, and responding to issues.
|
|
1562
|
+
*/
|
|
1563
|
+
"issue-triage": [
|
|
1564
|
+
"listIssues",
|
|
1565
|
+
"getIssue",
|
|
1566
|
+
"createIssue",
|
|
1567
|
+
"addIssueComment",
|
|
1568
|
+
"closeIssue",
|
|
1569
|
+
"listLabels",
|
|
1570
|
+
"addLabels",
|
|
1571
|
+
"removeLabel",
|
|
1572
|
+
"getRepository",
|
|
1573
|
+
"searchRepositories",
|
|
1574
|
+
"searchCode"
|
|
1575
|
+
],
|
|
1576
|
+
/**
|
|
1577
|
+
* **CI operations** — monitor and manage GitHub Actions workflows.
|
|
1578
|
+
*
|
|
1579
|
+
* Tools: `getRepository`, `listBranches`, `listCommits`, `getCommit`,
|
|
1580
|
+
* `listWorkflows`, `listWorkflowRuns`, `getWorkflowRun`, `listWorkflowJobs`,
|
|
1581
|
+
* `triggerWorkflow`, `cancelWorkflowRun`, `rerunWorkflowRun`.
|
|
1582
|
+
*
|
|
1583
|
+
* Agent prompt: optimized for diagnosing CI failures and managing workflow runs.
|
|
1584
|
+
*/
|
|
1585
|
+
"ci-ops": [
|
|
1586
|
+
"getRepository",
|
|
1587
|
+
"listBranches",
|
|
1588
|
+
"listCommits",
|
|
1589
|
+
"getCommit",
|
|
1590
|
+
"listWorkflows",
|
|
1591
|
+
"listWorkflowRuns",
|
|
1592
|
+
"getWorkflowRun",
|
|
1593
|
+
"listWorkflowJobs",
|
|
1594
|
+
"triggerWorkflow",
|
|
1595
|
+
"cancelWorkflowRun",
|
|
1596
|
+
"rerunWorkflowRun"
|
|
1597
|
+
],
|
|
1598
|
+
/**
|
|
1599
|
+
* **Repository explorer** — read-only access to browse codebases.
|
|
1600
|
+
*
|
|
1601
|
+
* Tools: all read-only tools including repos, branches, PRs, issues, commits, blame,
|
|
1602
|
+
* search, gists, and workflows. No write operations.
|
|
1603
|
+
*
|
|
1604
|
+
* Agent prompt: optimized for answering questions about code structure and history.
|
|
1605
|
+
*/
|
|
1606
|
+
"repo-explorer": [
|
|
1607
|
+
"getRepository",
|
|
1608
|
+
"listBranches",
|
|
1609
|
+
"getFileContent",
|
|
1610
|
+
"listPullRequests",
|
|
1611
|
+
"getPullRequest",
|
|
1612
|
+
"listPullRequestFiles",
|
|
1613
|
+
"listPullRequestReviews",
|
|
1614
|
+
"listIssues",
|
|
1615
|
+
"getIssue",
|
|
1616
|
+
"listLabels",
|
|
1617
|
+
"listCommits",
|
|
1618
|
+
"getCommit",
|
|
1619
|
+
"getBlame",
|
|
1620
|
+
"searchCode",
|
|
1621
|
+
"searchRepositories",
|
|
1622
|
+
"listGists",
|
|
1623
|
+
"getGist",
|
|
1624
|
+
"listGistComments",
|
|
1625
|
+
"listWorkflows",
|
|
1626
|
+
"listWorkflowRuns",
|
|
1627
|
+
"getWorkflowRun",
|
|
1628
|
+
"listWorkflowJobs"
|
|
1629
|
+
],
|
|
1630
|
+
/**
|
|
1631
|
+
* **Maintainer** — full repository maintenance with all read and write tools.
|
|
1632
|
+
*
|
|
1633
|
+
* Tools: all 42 tools (same as omitting `preset`).
|
|
1634
|
+
*
|
|
1635
|
+
* Agent prompt: optimized for day-to-day repo maintenance with careful write operations.
|
|
1636
|
+
*/
|
|
1637
|
+
"maintainer": [
|
|
1638
|
+
"getRepository",
|
|
1639
|
+
"listBranches",
|
|
1640
|
+
"getFileContent",
|
|
1641
|
+
"createBranch",
|
|
1642
|
+
"forkRepository",
|
|
1643
|
+
"createRepository",
|
|
1644
|
+
"createOrUpdateFile",
|
|
1645
|
+
"listPullRequests",
|
|
1646
|
+
"getPullRequest",
|
|
1647
|
+
"listPullRequestFiles",
|
|
1648
|
+
"listPullRequestReviews",
|
|
1649
|
+
"createPullRequest",
|
|
1650
|
+
"mergePullRequest",
|
|
1651
|
+
"addPullRequestComment",
|
|
1652
|
+
"createPullRequestReview",
|
|
1653
|
+
"listIssues",
|
|
1654
|
+
"getIssue",
|
|
1655
|
+
"createIssue",
|
|
1656
|
+
"addIssueComment",
|
|
1657
|
+
"closeIssue",
|
|
1658
|
+
"listLabels",
|
|
1659
|
+
"addLabels",
|
|
1660
|
+
"removeLabel",
|
|
1661
|
+
"listCommits",
|
|
1662
|
+
"getCommit",
|
|
1663
|
+
"getBlame",
|
|
1664
|
+
"searchCode",
|
|
1665
|
+
"searchRepositories",
|
|
1666
|
+
"listGists",
|
|
1667
|
+
"getGist",
|
|
1668
|
+
"listGistComments",
|
|
1669
|
+
"createGist",
|
|
1670
|
+
"updateGist",
|
|
1671
|
+
"deleteGist",
|
|
1672
|
+
"createGistComment",
|
|
1673
|
+
"listWorkflows",
|
|
1674
|
+
"listWorkflowRuns",
|
|
1675
|
+
"getWorkflowRun",
|
|
1676
|
+
"listWorkflowJobs",
|
|
1677
|
+
"triggerWorkflow",
|
|
1678
|
+
"cancelWorkflowRun",
|
|
1679
|
+
"rerunWorkflowRun"
|
|
1680
|
+
]
|
|
1681
|
+
};
|
|
1682
|
+
/**
|
|
1683
|
+
* Resolve a preset (or array of presets) into the set of tool names it includes.
|
|
1684
|
+
*
|
|
1685
|
+
* @param preset - A single preset or array of presets to combine.
|
|
1686
|
+
* @returns A `Set` of tool names, or `null` when `preset` is falsy.
|
|
1687
|
+
*/
|
|
1688
|
+
function resolvePresetTools(preset) {
|
|
1689
|
+
if (!preset) return null;
|
|
1690
|
+
const presets = Array.isArray(preset) ? preset : [preset];
|
|
1691
|
+
const tools = /* @__PURE__ */ new Set();
|
|
1692
|
+
for (const p of presets) for (const t of PRESET_TOOLS[p]) tools.add(t);
|
|
1693
|
+
return tools;
|
|
1694
|
+
}
|
|
1695
|
+
//#endregion
|
|
1696
|
+
//#region src/core/tool-names.ts
|
|
1697
|
+
/**
|
|
1698
|
+
* All GitHub tool names available via {@link createGithubTools}.
|
|
1699
|
+
* Each key maps to its own string literal for IDE autocomplete and hover docs.
|
|
1700
|
+
*/
|
|
1701
|
+
const GITHUB_TOOL_NAMES = {
|
|
1702
|
+
/** Get information about a GitHub repository including description, stars, forks, language, and default branch. */
|
|
1703
|
+
getRepository: "getRepository",
|
|
1704
|
+
/** List branches in a GitHub repository. */
|
|
1705
|
+
listBranches: "listBranches",
|
|
1706
|
+
/** Get the content of a file from a GitHub repository. */
|
|
1707
|
+
getFileContent: "getFileContent",
|
|
1708
|
+
/** Create a new branch in a GitHub repository from an existing branch or commit SHA. Requires approval by default. */
|
|
1709
|
+
createBranch: "createBranch",
|
|
1710
|
+
/** Fork a GitHub repository to the authenticated user account or a specified organization. Requires approval by default. */
|
|
1711
|
+
forkRepository: "forkRepository",
|
|
1712
|
+
/** Create a new GitHub repository for the authenticated user or a specified organization. Requires approval by default. */
|
|
1713
|
+
createRepository: "createRepository",
|
|
1714
|
+
/** Create or update a file in a GitHub repository. Provide the SHA when updating an existing file. Requires approval by default. */
|
|
1715
|
+
createOrUpdateFile: "createOrUpdateFile",
|
|
1716
|
+
/** List pull requests for a GitHub repository. */
|
|
1717
|
+
listPullRequests: "listPullRequests",
|
|
1718
|
+
/** Get detailed information about a specific pull request. */
|
|
1719
|
+
getPullRequest: "getPullRequest",
|
|
1720
|
+
/** Create a new pull request in a GitHub repository. Requires approval by default. */
|
|
1721
|
+
createPullRequest: "createPullRequest",
|
|
1722
|
+
/** Merge a pull request. Requires approval by default. */
|
|
1723
|
+
mergePullRequest: "mergePullRequest",
|
|
1724
|
+
/** Add a comment to a pull request. Requires approval by default. */
|
|
1725
|
+
addPullRequestComment: "addPullRequestComment",
|
|
1726
|
+
/** List files changed in a pull request, including diff status and patch content. */
|
|
1727
|
+
listPullRequestFiles: "listPullRequestFiles",
|
|
1728
|
+
/** List reviews on a pull request (approvals, change requests, and comments). */
|
|
1729
|
+
listPullRequestReviews: "listPullRequestReviews",
|
|
1730
|
+
/** Submit a pull request review — approve, request changes, or comment with optional inline comments on specific lines. Requires approval by default. */
|
|
1731
|
+
createPullRequestReview: "createPullRequestReview",
|
|
1732
|
+
/** List issues for a GitHub repository (excludes pull requests). */
|
|
1733
|
+
listIssues: "listIssues",
|
|
1734
|
+
/** Get detailed information about a specific issue. */
|
|
1735
|
+
getIssue: "getIssue",
|
|
1736
|
+
/** Create a new issue in a GitHub repository. Requires approval by default. */
|
|
1737
|
+
createIssue: "createIssue",
|
|
1738
|
+
/** Add a comment to a GitHub issue. Requires approval by default. */
|
|
1739
|
+
addIssueComment: "addIssueComment",
|
|
1740
|
+
/** Close an open GitHub issue. Requires approval by default. */
|
|
1741
|
+
closeIssue: "closeIssue",
|
|
1742
|
+
/** List labels available in a GitHub repository. */
|
|
1743
|
+
listLabels: "listLabels",
|
|
1744
|
+
/** Add labels to an issue or pull request. Requires approval by default. */
|
|
1745
|
+
addLabels: "addLabels",
|
|
1746
|
+
/** Remove a label from an issue or pull request. Requires approval by default. */
|
|
1747
|
+
removeLabel: "removeLabel",
|
|
1748
|
+
/** Search for code in GitHub repositories. Use qualifiers like "repo:owner/name" to scope the search. */
|
|
1749
|
+
searchCode: "searchCode",
|
|
1750
|
+
/** Search for GitHub repositories by keyword, topic, language, or other qualifiers. */
|
|
1751
|
+
searchRepositories: "searchRepositories",
|
|
1752
|
+
/** List commits for a GitHub repository. Filter by file path to see commits that touched a file. For line-by-line attribution at a given ref, use getBlame instead. */
|
|
1753
|
+
listCommits: "listCommits",
|
|
1754
|
+
/** Get detailed information about a specific commit, including the list of files changed with additions and deletions. */
|
|
1755
|
+
getCommit: "getCommit",
|
|
1756
|
+
/** Line-level git blame for a file at a commit-like ref (branch, tag, or SHA). Returns contiguous ranges mapping lines to the commits that last modified them. */
|
|
1757
|
+
getBlame: "getBlame",
|
|
1758
|
+
/** List gists for the authenticated user or a specific user. */
|
|
1759
|
+
listGists: "listGists",
|
|
1760
|
+
/** Get a gist by ID, including file contents. */
|
|
1761
|
+
getGist: "getGist",
|
|
1762
|
+
/** List comments on a gist. */
|
|
1763
|
+
listGistComments: "listGistComments",
|
|
1764
|
+
/** Create a new gist with one or more files. Requires approval by default. */
|
|
1765
|
+
createGist: "createGist",
|
|
1766
|
+
/** Update an existing gist — edit description, update files, or remove files. Requires approval by default. */
|
|
1767
|
+
updateGist: "updateGist",
|
|
1768
|
+
/** Delete a gist permanently. Requires approval by default. */
|
|
1769
|
+
deleteGist: "deleteGist",
|
|
1770
|
+
/** Add a comment to a gist. Requires approval by default. */
|
|
1771
|
+
createGistComment: "createGistComment",
|
|
1772
|
+
/** List GitHub Actions workflows in a repository. */
|
|
1773
|
+
listWorkflows: "listWorkflows",
|
|
1774
|
+
/** List workflow runs for a repository, optionally filtered by workflow, branch, status, or event. */
|
|
1775
|
+
listWorkflowRuns: "listWorkflowRuns",
|
|
1776
|
+
/** Get details of a specific workflow run including status, timing, and trigger info. */
|
|
1777
|
+
getWorkflowRun: "getWorkflowRun",
|
|
1778
|
+
/** List jobs for a workflow run, including step-level status and timing. */
|
|
1779
|
+
listWorkflowJobs: "listWorkflowJobs",
|
|
1780
|
+
/** Trigger a workflow via workflow_dispatch event. Requires approval by default. */
|
|
1781
|
+
triggerWorkflow: "triggerWorkflow",
|
|
1782
|
+
/** Cancel an in-progress workflow run. Requires approval by default. */
|
|
1783
|
+
cancelWorkflowRun: "cancelWorkflowRun",
|
|
1784
|
+
/** Re-run a workflow run, optionally only the failed jobs. Requires approval by default. */
|
|
1785
|
+
rerunWorkflowRun: "rerunWorkflowRun"
|
|
1786
|
+
};
|
|
1787
|
+
const ALL_GITHUB_TOOL_NAMES = Object.values(GITHUB_TOOL_NAMES);
|
|
1788
|
+
//#endregion
|
|
1789
|
+
//#region src/core/write-tools.ts
|
|
1790
|
+
/**
|
|
1791
|
+
* Write tools that mutate GitHub state. All require user approval by default
|
|
1792
|
+
* unless overridden via {@link ApprovalConfig}.
|
|
1793
|
+
*/
|
|
1794
|
+
const GITHUB_WRITE_TOOLS = {
|
|
1795
|
+
/** Create a new branch in a GitHub repository from an existing branch or commit SHA. Requires approval by default. */
|
|
1796
|
+
createBranch: "createBranch",
|
|
1797
|
+
/** Fork a GitHub repository to the authenticated user account or a specified organization. Requires approval by default. */
|
|
1798
|
+
forkRepository: "forkRepository",
|
|
1799
|
+
/** Create a new GitHub repository for the authenticated user or a specified organization. Requires approval by default. */
|
|
1800
|
+
createRepository: "createRepository",
|
|
1801
|
+
/** Create or update a file in a GitHub repository. Requires approval by default. */
|
|
1802
|
+
createOrUpdateFile: "createOrUpdateFile",
|
|
1803
|
+
/** Create a new pull request in a GitHub repository. Requires approval by default. */
|
|
1804
|
+
createPullRequest: "createPullRequest",
|
|
1805
|
+
/** Merge a pull request. Requires approval by default. */
|
|
1806
|
+
mergePullRequest: "mergePullRequest",
|
|
1807
|
+
/** Add a comment to a pull request. Requires approval by default. */
|
|
1808
|
+
addPullRequestComment: "addPullRequestComment",
|
|
1809
|
+
/** Submit a pull request review with optional inline comments. Requires approval by default. */
|
|
1810
|
+
createPullRequestReview: "createPullRequestReview",
|
|
1811
|
+
/** Create a new issue in a GitHub repository. Requires approval by default. */
|
|
1812
|
+
createIssue: "createIssue",
|
|
1813
|
+
/** Add a comment to a GitHub issue. Requires approval by default. */
|
|
1814
|
+
addIssueComment: "addIssueComment",
|
|
1815
|
+
/** Close an open GitHub issue. Requires approval by default. */
|
|
1816
|
+
closeIssue: "closeIssue",
|
|
1817
|
+
/** Add labels to an issue or pull request. Requires approval by default. */
|
|
1818
|
+
addLabels: "addLabels",
|
|
1819
|
+
/** Remove a label from an issue or pull request. Requires approval by default. */
|
|
1820
|
+
removeLabel: "removeLabel",
|
|
1821
|
+
/** Create a new gist with one or more files. Requires approval by default. */
|
|
1822
|
+
createGist: "createGist",
|
|
1823
|
+
/** Update an existing gist. Requires approval by default. */
|
|
1824
|
+
updateGist: "updateGist",
|
|
1825
|
+
/** Delete a gist permanently. Requires approval by default. */
|
|
1826
|
+
deleteGist: "deleteGist",
|
|
1827
|
+
/** Add a comment to a gist. Requires approval by default. */
|
|
1828
|
+
createGistComment: "createGistComment",
|
|
1829
|
+
/** Trigger a workflow via workflow_dispatch event. Requires approval by default. */
|
|
1830
|
+
triggerWorkflow: "triggerWorkflow",
|
|
1831
|
+
/** Cancel an in-progress workflow run. Requires approval by default. */
|
|
1832
|
+
cancelWorkflowRun: "cancelWorkflowRun",
|
|
1833
|
+
/** Re-run a workflow run, optionally only the failed jobs. Requires approval by default. */
|
|
1834
|
+
rerunWorkflowRun: "rerunWorkflowRun"
|
|
1835
|
+
};
|
|
1836
|
+
Object.values(GITHUB_WRITE_TOOLS);
|
|
1837
|
+
//#endregion
|
|
1838
|
+
export { getCommitInputSchema as $, listPullRequestsInputSchema as $t, createGistCore as A, removeLabelCore as At, listGistCommentsDescription as B, createPullRequestReviewDescription as Bt, rerunWorkflowRunInputSchema as C, getRepositoryCore as Cn, getIssueInputSchema as Ct, createGistCommentCore as D, listBranchesDescription as Dn, listLabelsCore as Dt, triggerWorkflowInputSchema as E, listBranchesCore as En, listIssuesInputSchema as Et, deleteGistInputSchema as F, addPullRequestCommentInputSchema as Ft, updateGistCore as G, listPullRequestFilesCore as Gt, listGistsCore as H, getPullRequestCore as Ht, getGistCore as I, createPullRequestCore as It, getBlameCore as J, listPullRequestReviewsCore as Jt, updateGistDescription as K, listPullRequestFilesDescription as Kt, getGistDescription as L, createPullRequestDescription as Lt, createGistInputSchema as M, removeLabelInputSchema as Mt, deleteGistCore as N, addPullRequestCommentCore as Nt, createGistCommentDescription as O, listBranchesInputSchema as On, listLabelsDescription as Ot, deleteGistDescription as P, addPullRequestCommentDescription as Pt, getCommitDescription as Q, listPullRequestsDescription as Qt, getGistInputSchema as R, createPullRequestInputSchema as Rt, rerunWorkflowRunDescription as S, getFileContentInputSchema as Sn, getIssueDescription as St, triggerWorkflowDescription as T, getRepositoryInputSchema as Tn, listIssuesDescription as Tt, listGistsDescription as U, getPullRequestDescription as Ut, listGistCommentsInputSchema as V, createPullRequestReviewInputSchema as Vt, listGistsInputSchema as W, getPullRequestInputSchema as Wt, getBlameInputSchema as X, listPullRequestReviewsInputSchema as Xt, getBlameDescription as Y, listPullRequestReviewsDescription as Yt, getCommitCore as Z, listPullRequestsCore as Zt, listWorkflowRunsInputSchema as _, forkRepositoryCore as _n, closeIssueInputSchema as _t, resolvePresetTools as a, getCommitToModelOutput as an, searchCodeInputSchema as at, listWorkflowsInputSchema as b, getFileContentCore as bn, createIssueInputSchema as bt, cancelWorkflowRunInputSchema as c, createBranchCore as cn, searchRepositoriesInputSchema as ct, getWorkflowRunInputSchema as d, createOrUpdateFileCore as dn, addIssueCommentInputSchema as dt, mergePullRequestCore as en, listCommitsCore as et, listWorkflowJobsCore as f, createOrUpdateFileDescription as fn, addLabelsCore as ft, listWorkflowRunsDescription as g, createRepositoryInputSchema as gn, closeIssueDescription as gt, listWorkflowRunsCore as h, createRepositoryDescription as hn, closeIssueCore as ht, PRESET_TOOLS as i, resolveGithubToken as in, searchCodeDescription as it, createGistDescription as j, removeLabelDescription as jt, createGistCommentInputSchema as k, createOctokit as kn, listLabelsInputSchema as kt, getWorkflowRunCore as l, createBranchDescription as ln, addIssueCommentCore as lt, listWorkflowJobsInputSchema as m, createRepositoryCore as mn, addLabelsInputSchema as mt, ALL_GITHUB_TOOL_NAMES as n, mergePullRequestInputSchema as nn, listCommitsInputSchema as nt, cancelWorkflowRunCore as o, getFileContentToModelOutput as on, searchRepositoriesCore as ot, listWorkflowJobsDescription as p, createOrUpdateFileInputSchema as pn, addLabelsDescription as pt, updateGistInputSchema as q, listPullRequestFilesInputSchema as qt, GITHUB_TOOL_NAMES as r, createGithubTokenResolver as rn, searchCodeCore as rt, cancelWorkflowRunDescription as s, listPullRequestFilesToModelOutput as sn, searchRepositoriesDescription as st, GITHUB_WRITE_TOOLS as t, mergePullRequestDescription as tn, listCommitsDescription as tt, getWorkflowRunDescription as u, createBranchInputSchema as un, addIssueCommentDescription as ut, listWorkflowsCore as v, forkRepositoryDescription as vn, createIssueCore as vt, triggerWorkflowCore as w, getRepositoryDescription as wn, listIssuesCore as wt, rerunWorkflowRunCore as x, getFileContentDescription as xn, getIssueCore as xt, listWorkflowsDescription as y, forkRepositoryInputSchema as yn, createIssueDescription as yt, listGistCommentsCore as z, createPullRequestReviewCore as zt };
|
|
1839
|
+
|
|
1840
|
+
//# sourceMappingURL=write-tools-Dx9LfYlU.mjs.map
|